feat: externalize apps/analysis to Gitea repos, add analysis table

- Migration 007: repo_url on apps table + analysis table with FTS5
- Analysis struct, parser, CRUD, validation, hash computation
- Selective purge: remote-only apps/analysis preserved across fn index
- CLI: fn app list/clone/pull, fn analysis list/clone/pull
- search/show/list now include analysis results
- Apps removed from git tracking (content lives in Gitea repos)
- .gitkeep for apps/ and analysis/ dirs
- Bash functions: jupyter analysis pipeline, shell utilities
- Browser domain: CDP functions moved from infra to browser

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-01 04:23:51 +02:00
parent 722f29b71b
commit bf1efb2099
111 changed files with 2766 additions and 5043 deletions
@@ -0,0 +1,63 @@
---
name: init_jupyter_analysis
kind: pipeline
lang: bash
domain: pipelines
version: "1.0.0"
purity: impure
signature: "init_jupyter_analysis(nombre: string, [...paquetes_extra: string]) -> void"
description: "Inicializa un analisis Jupyter completo en analysis/{nombre}/ con venv, paquetes, launcher, MCP y reglas para agentes Claude. Acepta paquetes extra opcionales."
tags: [jupyter, analysis, setup, pipeline, bash, launcher]
uses_functions:
- assert_command_exists_bash_shell
- find_free_port_bash_shell
- init_uv_venv_bash_infra
- uv_add_packages_bash_infra
- write_jupyter_launcher_bash_infra
- write_mcp_jupyter_config_bash_infra
- write_claude_jupyter_rules_bash_infra
- write_jupyter_registry_kernel_bash_infra
uses_types: []
returns: []
returns_optional: false
error_type: "error_go_core"
imports: []
tested: false
tests: []
test_file_path: ""
file_path: "bash/functions/pipelines/init_jupyter_analysis.sh"
---
## Ejemplo
```bash
# Analisis basico
./init_jupyter_analysis.sh finanzas
# Con paquetes extra
./init_jupyter_analysis.sh duckdb polars duckdb
./init_jupyter_analysis.sh ml scikit-learn torch
# Via fn run
fn run init_jupyter_analysis finanzas
fn run init_jupyter_analysis ml scikit-learn torch
```
## Flujo
1. `assert_command_exists` — verifica que uv o python3 estan disponibles
2. Crea estructura `analysis/{nombre}/notebooks/` y `analysis/{nombre}/data/`
3. `init_uv_venv` — crea venv en `analysis/{nombre}/.venv/`
4. `uv_add_packages` — instala jupyter, jupyterlab, jupyter-collaboration, jupyter-mcp-server, pandas, numpy, matplotlib + extras
5. `write_jupyter_launcher` — genera `run-jupyter-lab.sh` con modo colaborativo
6. `find_free_port` + `write_mcp_jupyter_config` — detecta puerto libre y genera `.mcp.json`
7. `write_claude_jupyter_rules` — genera `.claude/CLAUDE.md` con reglas de agente
8. `write_jupyter_registry_kernel` — genera IPython startup con `fn_query`, `fn_search`, `fn_code` y acceso a `python/functions/`
## Notas
Cada analisis es independiente (propio venv, propio Jupyter, propio MCP). Mismo patron que `apps/` pero para exploraciones no reutilizables.
El pipeline usa `set -euo pipefail` — cualquier fallo detiene la ejecucion.
Paquetes base siempre incluidos: jupyter, jupyterlab, jupyter-collaboration, jupyter-mcp-server, pandas, numpy, matplotlib. Los paquetes extra se añaden a estos.
@@ -0,0 +1,123 @@
#!/usr/bin/env bash
# init_jupyter_analysis
# ----------------------
# Inicializa un analisis Jupyter completo en analysis/{nombre}/.
# Compone: assert_command_exists + find_free_port + init_uv_venv +
# uv_add_packages + write_jupyter_launcher +
# write_mcp_jupyter_config + write_claude_jupyter_rules +
# write_jupyter_registry_kernel
#
# USO:
# ./init_jupyter_analysis.sh <nombre> [paquetes_extra...]
#
# EJEMPLOS:
# ./init_jupyter_analysis.sh finanzas
# ./init_jupyter_analysis.sh duckdb polars duckdb
# ./init_jupyter_analysis.sh ml scikit-learn torch
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REGISTRY_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
# Source funciones atomicas
source "$REGISTRY_ROOT/bash/functions/shell/assert_command_exists.sh"
source "$REGISTRY_ROOT/bash/functions/shell/find_free_port.sh"
source "$REGISTRY_ROOT/bash/functions/infra/init_uv_venv.sh"
source "$REGISTRY_ROOT/bash/functions/infra/uv_add_packages.sh"
source "$REGISTRY_ROOT/bash/functions/infra/write_jupyter_launcher.sh"
source "$REGISTRY_ROOT/bash/functions/infra/write_mcp_jupyter_config.sh"
source "$REGISTRY_ROOT/bash/functions/infra/write_claude_jupyter_rules.sh"
source "$REGISTRY_ROOT/bash/functions/infra/write_jupyter_registry_kernel.sh"
# ── Argumentos ──────────────────────────────────────────────
NOMBRE="${1:-}"
if [ -z "$NOMBRE" ]; then
echo "Uso: $0 <nombre> [paquetes_extra...]" >&2
echo " Ejemplo: $0 finanzas polars" >&2
exit 1
fi
shift
EXTRA_PACKAGES=("$@")
ANALYSIS_DIR="${REGISTRY_ROOT}/analysis/${NOMBRE}"
echo ""
echo "════════════════════════════════════════════════════════════"
echo " INIT JUPYTER ANALYSIS: ${NOMBRE}"
echo " Directorio: ${ANALYSIS_DIR}"
echo "════════════════════════════════════════════════════════════"
echo ""
# ── 1. Verificar herramientas ───────────────────────────────
echo "[1/8] Verificando herramientas..."
assert_command_exists uv || assert_command_exists python3
echo " OK"
# ── 2. Crear estructura de carpetas ─────────────────────────
echo "[2/8] Creando estructura..."
mkdir -p "$ANALYSIS_DIR/notebooks" "$ANALYSIS_DIR/data"
echo " ${ANALYSIS_DIR}/notebooks/"
echo " ${ANALYSIS_DIR}/data/"
# ── 3. Crear venv ───────────────────────────────────────────
echo "[3/8] Inicializando venv..."
venv_path=$(init_uv_venv "$ANALYSIS_DIR")
echo " $venv_path"
# ── 4. Instalar paquetes ────────────────────────────────────
echo "[4/8] Instalando paquetes..."
BASE_PACKAGES=(jupyter jupyterlab jupyter-collaboration jupyter-mcp-server pandas numpy matplotlib)
ALL_PACKAGES=("${BASE_PACKAGES[@]}" "${EXTRA_PACKAGES[@]}")
uv_add_packages "$ANALYSIS_DIR" "${ALL_PACKAGES[@]}"
echo " Instalados: ${ALL_PACKAGES[*]}"
# ── 5. Generar launcher ─────────────────────────────────────
echo "[5/8] Generando launcher..."
launcher=$(write_jupyter_launcher "$ANALYSIS_DIR")
echo " $launcher"
# ── 6. Configurar MCP ───────────────────────────────────────
echo "[6/8] Configurando MCP..."
port=$(find_free_port 8888 8899)
mcp_config=$(write_mcp_jupyter_config "$ANALYSIS_DIR" "$port")
echo " $mcp_config (puerto: $port)"
# ── 7. Reglas para agentes ──────────────────────────────────
echo "[7/8] Escribiendo reglas Claude..."
rules=$(write_claude_jupyter_rules "$ANALYSIS_DIR")
echo " $rules"
# ── 8. Kernel startup con acceso al registry ────────────────
echo "[8/8] Configurando kernel con acceso al registry..."
kernel_startup=$(write_jupyter_registry_kernel "$ANALYSIS_DIR")
echo " $kernel_startup"
# ── Resumen ─────────────────────────────────────────────────
echo ""
echo "════════════════════════════════════════════════════════════"
echo " ANALISIS '${NOMBRE}' LISTO"
echo "════════════════════════════════════════════════════════════"
echo ""
echo " Pasos siguientes:"
echo ""
echo " 1. En otra terminal:"
echo " cd ${ANALYSIS_DIR} && ./run-jupyter-lab.sh"
echo ""
echo " 2. Abrir Claude en el analisis:"
echo " cd ${ANALYSIS_DIR} && claude"
echo ""
echo " 3. Abrir en navegador: http://localhost:${port}"
echo ""
echo " FN_REGISTRY_ROOT=${REGISTRY_ROOT}"
echo ""