diff --git a/.claude/skills/init-jupyter/SKILL.md b/.claude/skills/init-jupyter/SKILL.md index 0ab26d5..f98e127 100644 --- a/.claude/skills/init-jupyter/SKILL.md +++ b/.claude/skills/init-jupyter/SKILL.md @@ -1,6 +1,6 @@ --- name: init-jupyter -description: Inicializa o inicia Jupyter Lab via MCP. Detecta notebooks existentes automáticamente. +description: Inicializa o inicia Jupyter Lab via MCP con kernel compartido. Detecta notebooks existentes automáticamente. argument-hint: [ruta-proyecto] disable-model-invocation: true user-invocable: true @@ -11,6 +11,13 @@ allowed-tools: Bash, Read, Write, Edit, Glob Este skill gestiona entornos Jupyter Lab integrados con Claude via MCP. Detecta automáticamente si ya existe un proyecto configurado. +## Modo de Colaboración (Kernel Compartido) + +**IMPORTANTE**: Para que las ejecuciones de Claude sean visibles en Jupyter Lab, se debe usar el **mismo kernel** que el notebook abierto. Esto permite: +- Ver las ejecuciones de Claude en tiempo real en Jupyter Lab +- Compartir variables y estado entre Claude y el usuario +- Colaboración real entre ambos en el mismo notebook + ## Flujo de decisión ### 1. Detectar notebooks existentes @@ -26,9 +33,10 @@ find [ruta] -name "*.ipynb" -type f 2>/dev/null | head -5 ### 2. Si HAY notebooks existentes → Iniciar directamente -**2a. Verificar que MCP está configurado** +**2a. Verificar que MCP está configurado con kernel compartido** - Comprobar si existe `.claude/settings.local.json` con configuración de jupyter -- Si no existe, crearlo (ver paso 6 del flujo de inicialización) +- Verificar que incluye `--start-new-runtime false` para colaboración +- Si no existe o falta la configuración, crearlo (ver paso 3f) **2b. Verificar que jupyter-mcp-server está instalado** ```bash @@ -71,19 +79,26 @@ uv add jupyter jupyter-collaboration uv tool install jupyter-mcp-server ``` -**3f. Configurar MCP para Claude** +**3f. Configurar MCP para Claude (con kernel compartido)** Crear o actualizar `.claude/settings.local.json`: ```json { "mcpServers": { "jupyter": { "command": "jupyter-mcp-server", - "args": [] + "args": [ + "--jupyter-url", "http://localhost:8888", + "--start-new-runtime", "false" + ] } } } ``` +**Parámetros clave:** +- `--jupyter-url`: URL del servidor Jupyter (por defecto localhost:8888) +- `--start-new-runtime false`: **CRÍTICO** - Conecta al kernel existente en lugar de crear uno nuevo + **3g. Crear carpeta notebooks** (opcional) ```bash mkdir -p notebooks @@ -107,10 +122,53 @@ jupyter lab --no-browser --NotebookApp.token='' --NotebookApp.password='' --Note /init-jupyter ~/proyectos/mi-analisis ``` +## Flujo de trabajo colaborativo (Kernel Compartido) + +### Cómo funciona la colaboración + +1. **Usuario inicia Jupyter Lab** (via este skill) +2. **Usuario abre un notebook** en Jupyter Lab → se inicia un kernel +3. **Claude se conecta al MISMO kernel** via MCP con `--start-new-runtime false` +4. **Ambos comparten**: + - El mismo estado de variables + - El mismo historial de ejecución + - Las salidas son visibles para ambos en tiempo real + +### Pasos para colaborar + +1. Ejecutar `/init-jupyter` para iniciar Jupyter Lab +2. Abrir el navegador en http://localhost:8888 +3. Abrir o crear el notebook deseado +4. **Claude ya puede ejecutar celdas** y el usuario verá las ejecuciones en su Jupyter Lab + +### Obtener kernel ID específico (opcional) + +Si hay múltiples kernels corriendo, puedes obtener el ID del kernel activo: +```bash +curl -s http://localhost:8888/api/kernels | jq '.[0].id' +``` + +Y configurar MCP con ese kernel específico: +```json +{ + "mcpServers": { + "jupyter": { + "command": "jupyter-mcp-server", + "args": [ + "--jupyter-url", "http://localhost:8888", + "--runtime-id", "KERNEL_ID_AQUI" + ] + } + } +} +``` + ## Notas importantes - **Siempre usa MCP**: Jupyter se ejecuta siempre de forma que Claude pueda interactuar via MCP +- **Kernel compartido por defecto**: Con `--start-new-runtime false`, Claude usa el kernel existente - Si detecta notebooks existentes, NO reinicializa el proyecto, solo inicia Jupyter - Si el proyecto ya tiene `pyproject.toml`, no ejecuta `uv init` - La configuración MCP se guarda en `.claude/settings.local.json` del proyecto - El servidor MCP permite a Claude crear, editar y ejecutar celdas de notebooks +- **jupyter-collaboration** ya está incluido en las dependencias para sincronización en tiempo real