From 00fbe6fe212c930cb2df58d84085960f7d893941 Mon Sep 17 00:00:00 2001 From: Egutierrez Date: Wed, 25 Mar 2026 22:07:22 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20a=C3=B1adir=20script=20run-jupyter-lab.?= =?UTF-8?q?sh=20y=20detecci=C3=B3n=20de=20Jupyter=20activo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Crear script run-jupyter-lab.sh automáticamente en proyectos - Detectar si Jupyter ya está corriendo antes de arrancarlo - Usuario puede gestionar Jupyter manualmente, Claude se adapta - Documentar dos opciones de flujo de trabajo colaborativo Co-Authored-By: Claude Opus 4.5 --- .claude/skills/init-jupyter/SKILL.md | 74 +++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 8 deletions(-) diff --git a/.claude/skills/init-jupyter/SKILL.md b/.claude/skills/init-jupyter/SKILL.md index f98e127..3d41164 100644 --- a/.claude/skills/init-jupyter/SKILL.md +++ b/.claude/skills/init-jupyter/SKILL.md @@ -31,7 +31,7 @@ Buscar archivos `.ipynb` en: find [ruta] -name "*.ipynb" -type f 2>/dev/null | head -5 ``` -### 2. Si HAY notebooks existentes → Iniciar directamente +### 2. Si HAY notebooks existentes → Conectar o Iniciar **2a. Verificar que MCP está configurado con kernel compartido** - Comprobar si existe `.claude/settings.local.json` con configuración de jupyter @@ -43,13 +43,30 @@ find [ruta] -name "*.ipynb" -type f 2>/dev/null | head -5 which jupyter-mcp-server || uv tool install jupyter-mcp-server ``` -**2c. Iniciar Jupyter via MCP** +**2c. Verificar si el script run-jupyter-lab.sh existe** +- Si no existe, crearlo (ver paso 3g) + +**2d. Detectar si Jupyter ya está corriendo** +```bash +# Verificar si hay un servidor Jupyter activo en el puerto esperado +curl -s http://localhost:8888/api/status 2>/dev/null && echo "Jupyter activo" || echo "Jupyter no detectado" +``` + +**2e. Si Jupyter YA está corriendo:** +- **NO arrancarlo de nuevo** +- Informar al usuario: "Jupyter Lab detectado en http://localhost:8888" +- Claude puede conectarse directamente via MCP al kernel existente +- El usuario tiene libertad total para gestionar Jupyter manualmente + +**2f. Si Jupyter NO está corriendo:** +- Preguntar al usuario si quiere que Claude lo arranque o prefiere hacerlo manualmente con `./run-jupyter-lab.sh` +- Si el usuario quiere arrancarlo: ```bash source .venv/bin/activate 2>/dev/null || true jupyter lab --no-browser --NotebookApp.token='' --NotebookApp.password='' --NotebookApp.disable_check_xsrf=True ``` -**2d. Informar al usuario** que Jupyter está corriendo y puede usar las herramientas MCP de Jupyter desde Claude. +**2g. Informar al usuario** que puede usar las herramientas MCP de Jupyter desde Claude. ### 3. Si NO hay notebooks → Inicializar proyecto completo @@ -99,12 +116,41 @@ Crear o actualizar `.claude/settings.local.json`: - `--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) +**3g. Crear script `run-jupyter-lab.sh`** + +Crear un script ejecutable para que el usuario pueda arrancar Jupyter manualmente: +```bash +cat > run-jupyter-lab.sh << 'SCRIPT' +#!/bin/bash +# Script para iniciar Jupyter Lab con configuración de colaboración +# El usuario puede arrancarlo manualmente y Claude se conectará al kernel existente + +PORT=${1:-8888} + +source .venv/bin/activate 2>/dev/null || true + +echo "Iniciando Jupyter Lab en puerto $PORT..." +echo "Abre http://localhost:$PORT en tu navegador" +echo "" +echo "Claude se conectará automáticamente al kernel cuando abras un notebook." + +jupyter lab \ + --port=$PORT \ + --no-browser \ + --NotebookApp.token='' \ + --NotebookApp.password='' \ + --NotebookApp.disable_check_xsrf=True \ + --ServerApp.allow_origin='*' +SCRIPT +chmod +x run-jupyter-lab.sh +``` + +**3h. Crear carpeta notebooks** (opcional) ```bash mkdir -p notebooks ``` -**3h. Iniciar Jupyter via MCP** +**3i. Iniciar Jupyter via MCP** ```bash source .venv/bin/activate jupyter lab --no-browser --NotebookApp.token='' --NotebookApp.password='' --NotebookApp.disable_check_xsrf=True @@ -136,10 +182,19 @@ jupyter lab --no-browser --NotebookApp.token='' --NotebookApp.password='' --Note ### Pasos para colaborar -1. Ejecutar `/init-jupyter` para iniciar Jupyter Lab +**Opción A - Usuario arranca Jupyter manualmente (recomendado):** +1. Ejecutar `./run-jupyter-lab.sh` (o `./run-jupyter-lab.sh 8889` para otro puerto) 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 +4. Ejecutar `/init-jupyter` - Claude detectará Jupyter y se conectará al kernel existente +5. **Claude ya puede ejecutar celdas** y el usuario verá las ejecuciones en su Jupyter Lab + +**Opción B - Claude arranca Jupyter:** +1. Ejecutar `/init-jupyter` +2. Si no hay Jupyter corriendo, Claude lo arrancará +3. Abrir el navegador en http://localhost:8888 +4. Abrir o crear el notebook deseado +5. **Claude ya puede ejecutar celdas** ### Obtener kernel ID específico (opcional) @@ -167,7 +222,10 @@ Y configurar MCP con ese kernel específico: - **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 +- **Script `run-jupyter-lab.sh`**: Se crea automáticamente para que el usuario pueda arrancar Jupyter cuando quiera +- **Detección automática**: Claude detecta si Jupyter ya está corriendo y no lo arranca de nuevo +- **Libertad del usuario**: El usuario puede gestionar Jupyter manualmente, Claude se adapta +- Si detecta notebooks existentes, NO reinicializa el proyecto, solo conecta o 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