feat: añadir script run-jupyter-lab.sh y detección de Jupyter activo
- 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 <noreply@anthropic.com>
This commit is contained in:
@@ -31,7 +31,7 @@ Buscar archivos `.ipynb` en:
|
|||||||
find [ruta] -name "*.ipynb" -type f 2>/dev/null | head -5
|
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**
|
**2a. Verificar que MCP está configurado con kernel compartido**
|
||||||
- Comprobar si existe `.claude/settings.local.json` con configuración de jupyter
|
- 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
|
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
|
```bash
|
||||||
source .venv/bin/activate 2>/dev/null || true
|
source .venv/bin/activate 2>/dev/null || true
|
||||||
jupyter lab --no-browser --NotebookApp.token='' --NotebookApp.password='' --NotebookApp.disable_check_xsrf=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
|
### 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)
|
- `--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
|
- `--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
|
```bash
|
||||||
mkdir -p notebooks
|
mkdir -p notebooks
|
||||||
```
|
```
|
||||||
|
|
||||||
**3h. Iniciar Jupyter via MCP**
|
**3i. Iniciar Jupyter via MCP**
|
||||||
```bash
|
```bash
|
||||||
source .venv/bin/activate
|
source .venv/bin/activate
|
||||||
jupyter lab --no-browser --NotebookApp.token='' --NotebookApp.password='' --NotebookApp.disable_check_xsrf=True
|
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
|
### 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
|
2. Abrir el navegador en http://localhost:8888
|
||||||
3. Abrir o crear el notebook deseado
|
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)
|
### 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
|
- **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
|
- **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`
|
- Si el proyecto ya tiene `pyproject.toml`, no ejecuta `uv init`
|
||||||
- La configuración MCP se guarda en `.claude/settings.local.json` del proyecto
|
- 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
|
- El servidor MCP permite a Claude crear, editar y ejecutar celdas de notebooks
|
||||||
|
|||||||
Reference in New Issue
Block a user