feat: mejorar init-jupyter con kernel compartido para colaboración
- Añadir configuración --start-new-runtime false por defecto - Documentar flujo de trabajo colaborativo con Jupyter Lab - Permitir ver ejecuciones de Claude en tiempo real en el notebook - Añadir instrucciones para conectar a kernel específico Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
name: init-jupyter
|
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]
|
argument-hint: [ruta-proyecto]
|
||||||
disable-model-invocation: true
|
disable-model-invocation: true
|
||||||
user-invocable: 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.
|
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
|
## Flujo de decisión
|
||||||
|
|
||||||
### 1. Detectar notebooks existentes
|
### 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
|
### 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
|
- 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**
|
**2b. Verificar que jupyter-mcp-server está instalado**
|
||||||
```bash
|
```bash
|
||||||
@@ -71,19 +79,26 @@ uv add jupyter jupyter-collaboration
|
|||||||
uv tool install jupyter-mcp-server
|
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`:
|
Crear o actualizar `.claude/settings.local.json`:
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"mcpServers": {
|
"mcpServers": {
|
||||||
"jupyter": {
|
"jupyter": {
|
||||||
"command": "jupyter-mcp-server",
|
"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)
|
**3g. Crear carpeta notebooks** (opcional)
|
||||||
```bash
|
```bash
|
||||||
mkdir -p notebooks
|
mkdir -p notebooks
|
||||||
@@ -107,10 +122,53 @@ jupyter lab --no-browser --NotebookApp.token='' --NotebookApp.password='' --Note
|
|||||||
/init-jupyter ~/proyectos/mi-analisis
|
/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
|
## Notas importantes
|
||||||
|
|
||||||
- **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
|
||||||
- Si detecta notebooks existentes, NO reinicializa el proyecto, solo inicia Jupyter
|
- Si detecta notebooks existentes, NO reinicializa el proyecto, solo 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
|
||||||
|
- **jupyter-collaboration** ya está incluido en las dependencias para sincronización en tiempo real
|
||||||
|
|||||||
Reference in New Issue
Block a user