feat: cierra issues 0050 y 0052 + commands automáticos
- 0050: jupyter_exec reescrito sin Y.js (REST + KernelClient). Bug raíz adicional: HEAD /api/contents da 405 → cambiado a GET. 9 tests (5 unit + 4 e2e). - 0052: footprint_aurgi cerrado. Bug fix en setup_geo_stack_docker_pipeline (verify aborta si compose up falla; nombre de contenedor incorrecto). - Nueva primitiva docker_container_running_py_infra (7 tests). - /full-git-push y /full-git-pull pasan a modo automático: auto-commit + push sin preguntar, aborta solo si detecta secrets. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,17 +3,17 @@ name: jupyter_exec
|
||||
kind: function
|
||||
lang: py
|
||||
domain: notebook
|
||||
version: "1.0.0"
|
||||
version: "2.0.0"
|
||||
purity: impure
|
||||
signature: "jupyter_append_execute(notebook_path: str, code: str, server_url: str, token: str) -> dict"
|
||||
description: "Ejecuta codigo en kernels de Jupyter via WebSocket. Tres modos: append (añade celda al notebook y la ejecuta), cell (ejecuta celda existente por indice), kernel (ejecuta en el kernel sin tocar ningun notebook)."
|
||||
description: "Ejecuta codigo en kernels de Jupyter via REST + WebSocket clasico al kernel. Tres modos: append (añade celda y ejecuta), cell (ejecuta celda existente), kernel (ejecuta sin tocar notebook). NO usa el canal colaborativo Y.js."
|
||||
tags: [jupyter, notebook, kernel, websocket, execution, cells]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports: [jupyter_kernel_client, jupyter_nbmodel_client]
|
||||
imports: [jupyter_kernel_client, urllib, json, uuid]
|
||||
params:
|
||||
- name: notebook_path
|
||||
desc: "Ruta relativa al notebook"
|
||||
@@ -24,9 +24,18 @@ params:
|
||||
- name: token
|
||||
desc: "Token de autenticación (default vacío)"
|
||||
output: "Dict con cell_index y outputs del código ejecutado, o resultados del kernel"
|
||||
tested: false
|
||||
tests: []
|
||||
test_file_path: ""
|
||||
tested: true
|
||||
tests:
|
||||
- "test_notebook_exists_uses_get_not_head"
|
||||
- "test_notebook_exists_returns_false_on_404"
|
||||
- "test_create_notebook_skips_when_exists"
|
||||
- "test_new_code_cell_has_required_fields"
|
||||
- "test_extract_outputs_handles_streams_and_results"
|
||||
- "e2e: test_e2e_append_executes_and_persists"
|
||||
- "e2e: test_e2e_append_twice_increments_index"
|
||||
- "e2e: test_e2e_cell_executes_existing"
|
||||
- "e2e: test_e2e_kernel_mode"
|
||||
test_file_path: "python/functions/notebook/tests/test_jupyter_exec.py"
|
||||
file_path: "python/functions/notebook/jupyter_exec.py"
|
||||
---
|
||||
|
||||
@@ -34,9 +43,9 @@ file_path: "python/functions/notebook/jupyter_exec.py"
|
||||
|
||||
### `jupyter_append_execute(notebook_path, code, server_url, token)`
|
||||
|
||||
Añade una celda de codigo al final del notebook y la ejecuta. Usa el protocolo
|
||||
colaborativo de Jupyter, por lo que tanto el agente como el usuario ven la celda
|
||||
y su output en tiempo real en JupyterLab.
|
||||
Añade una celda de codigo al final del notebook, la ejecuta en el kernel y persiste
|
||||
celda + outputs a disco via REST `/api/contents`. Jupyter Lab detecta el cambio y lo
|
||||
refleja en el browser.
|
||||
|
||||
```python
|
||||
from notebook.jupyter_exec import jupyter_append_execute
|
||||
@@ -52,23 +61,18 @@ result = jupyter_append_execute(
|
||||
|
||||
### `jupyter_execute_cell(notebook_path, cell_index, server_url, token)`
|
||||
|
||||
Ejecuta una celda existente del notebook por su indice (0-based).
|
||||
Ejecuta una celda existente por indice (0-based) y persiste sus outputs.
|
||||
|
||||
```python
|
||||
from notebook.jupyter_exec import jupyter_execute_cell
|
||||
|
||||
result = jupyter_execute_cell("notebooks/analisis.ipynb", 3)
|
||||
# {"cell_index": 3, "outputs": ["42"]}
|
||||
```
|
||||
|
||||
### `jupyter_kernel_execute(code, server_url, token)`
|
||||
|
||||
Ejecuta codigo directamente en el kernel sin modificar ningun notebook. Util para
|
||||
consultas rapidas, inspeccion de variables o verificacion de estado del kernel.
|
||||
Ejecuta codigo directo en el kernel sin tocar ningun notebook.
|
||||
|
||||
```python
|
||||
from notebook.jupyter_exec import jupyter_kernel_execute
|
||||
|
||||
result = jupyter_kernel_execute("len(df)")
|
||||
# {"outputs": ["1500"], "status": "ok"}
|
||||
```
|
||||
@@ -76,13 +80,8 @@ result = jupyter_kernel_execute("len(df)")
|
||||
## CLI
|
||||
|
||||
```bash
|
||||
# Añadir celda y ejecutar
|
||||
python -m notebook.jupyter_exec append notebooks/mi.ipynb "print('hola')" --server http://localhost:8888 --token mytoken
|
||||
|
||||
# Ejecutar celda existente
|
||||
python -m notebook.jupyter_exec cell notebooks/mi.ipynb 2 --server http://localhost:8888
|
||||
|
||||
# Ejecutar en kernel directamente
|
||||
python -m notebook.jupyter_exec append notebooks/mi.ipynb "print('hola')"
|
||||
python -m notebook.jupyter_exec cell notebooks/mi.ipynb 2
|
||||
python -m notebook.jupyter_exec kernel "x = 42; print(x)"
|
||||
```
|
||||
|
||||
@@ -96,12 +95,15 @@ Output siempre JSON. En error retorna `{"error": "..."}` por stderr con exit cod
|
||||
| display_data / execute_result | `data.text/plain` |
|
||||
| error | `traceback` (joined con `\n`) |
|
||||
|
||||
## Notas
|
||||
## Notas (v2.0.0 — fix Issue 0050)
|
||||
|
||||
- Las funciones `append` y `cell` son async internamente; las publicas usan `asyncio.run()`.
|
||||
- `jupyter_kernel_execute` es sincrona directamente porque `KernelClient.execute` es bloqueante.
|
||||
- **Bypassa el canal colaborativo Y.js**. Usa REST `/api/contents` para leer/escribir
|
||||
celdas y `KernelClient` (websocket clasico al kernel) para ejecutar. Robusto frente
|
||||
a versiones nuevas de `jupyter-collaboration` que rompian `NbModelClient`.
|
||||
- **Trade-off**: las celdas/outputs se persisten a disco, no se sincronizan en
|
||||
tiempo real via Y.js. Jupyter Lab detecta el cambio en el filesystem y lo refleja
|
||||
(puede pedir 'Revert to disk' segun version).
|
||||
- `_notebook_exists` usa `GET /api/contents?content=0` (HEAD devuelve 405 en Jupyter Server).
|
||||
- **Auto-init**: `jupyter_append_execute` crea el notebook si no existe y arranca una
|
||||
sesion con kernel si no hay ninguna activa para ese notebook.
|
||||
- El token puede ser cadena vacia si el servidor tiene autenticacion deshabilitada.
|
||||
- `NbModelClient` requiere que el servidor tenga habilitado el endpoint colaborativo (`/api/collaboration/`), disponible en JupyterLab >= 4 con `jupyter-collaboration` instalado.
|
||||
- **Auto-init**: `jupyter_append_execute` crea el notebook automaticamente si no existe (via REST PUT /api/contents) y arranca una sesion con kernel si no hay ninguna activa para ese notebook (via POST /api/sessions). No es necesario abrir el notebook manualmente en el navegador.
|
||||
- **Auto-session**: `jupyter_execute_cell` tambien garantiza que exista una sesion con kernel antes de ejecutar.
|
||||
- **Fix Issue 006**: `jupyter_execute_cell` normaliza la celda antes de ejecutar. Las celdas creadas manualmente (no via la UI de Jupyter) pueden carecer de `outputs` o `execution_count` en el modelo CRDT, lo que causaba `KeyError: 'outputs'` dentro de `execute_cell` al hacer `del ycell["outputs"][:]`. El fix lee la celda con `nb[cell_index]`, detecta los campos faltantes, y reemplaza la celda via `nb[cell_index] = _normalize_code_cell(cell)` — que usa `set_cell` internamente para re-crear el mapa CRDT completo preservando el source original.
|
||||
|
||||
Reference in New Issue
Block a user