feat(doctor): add fn doctor CLI + 14 functions for system management

Adds `fn doctor` read-only diagnostic command with subcommands artefacts,
services, sync, uses-functions, unused, and --json flag for agents.
Each subcommand wraps a registry function in functions/infra/.

New functions:
- artefact_doctor, services_status, pc_locations_drift,
  audit_uses_functions, find_unused_functions (Go diagnostics)
- backup_sqlite_db, rotate_backups, wait_for_http, wait_for_port,
  port_kill, tail_journal, pre_commit_hook_install (bash utilities)
- notify_telegram (Go HTTP)
- backup_all pipeline (tag launcher)

Plus prior session leftovers (scan_secrets_in_dirty, append_diary_entry,
git utilities, http_session_cookie_middleware, compile/full-git pipelines).

Fixes pc_locations_drift filepath.Join bug with absolute dir_path.
Documents fn doctor in CLAUDE.md, .claude/rules/fn_doctor.md (rule 23),
docs/architecture.md, CHANGELOG.md (2026-05-07), and diary entry.

First fn doctor uses-functions run found drift in 7/12 apps (deuda
para sincronizar app.md con imports reales).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-07 01:42:10 +02:00
parent c0e0ceadd8
commit 625569485f
77 changed files with 6511 additions and 534 deletions
+50
View File
@@ -0,0 +1,50 @@
---
name: wait_for_http
kind: function
lang: bash
domain: infra
version: "1.0.0"
purity: impure
signature: "wait_for_http <url> [timeout_seconds] [interval_seconds]"
description: "Hace polling a una URL HTTP/HTTPS hasta recibir respuesta 2xx o agotar el timeout. Util en deploys, post-restart de servicios y smoke tests."
tags: [http, wait, poll, health, deploy, smoke-test]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: "error_go_core"
imports: []
params:
- name: url
desc: "URL completa del endpoint a sondear (debe empezar por http:// o https://)"
- name: timeout_seconds
desc: "Tiempo maximo de espera en segundos. Default: 30"
- name: interval_seconds
desc: "Intervalo entre intentos en segundos. Default: 1"
output: "stdout: 'OK <url> (<elapsed>s)' al primer 2xx. stderr: linea de progreso por intento y mensaje TIMEOUT si se agota. Exit 0=ok, 1=timeout, 2=URL invalida, 5=curl no instalado."
tested: false
tests: []
test_file_path: ""
file_path: "bash/functions/infra/wait_for_http.sh"
---
## Ejemplo
```bash
source bash/functions/infra/wait_for_http.sh
# Esperar hasta 60 segundos con sondeo cada 2 segundos
wait_for_http https://api.example.com/health 60 2
# Uso tipico en un pipeline de deploy
wait_for_http http://localhost:8080/health || { echo "servicio no arranco"; exit 1; }
```
## Notas
Acepta cualquier codigo 2xx (200, 201, 204...) como OK. Los codigos 3xx se tratan como "no listo" — el servicio debe responder directamente con 2xx, no redirigir.
curl se invoca con `--max-time 5` para no bloquear el loop si la conexion tarda. Los errores de curl (DNS, conexion rechazada) se tratan como "no listo" y el loop continua.
Salida de progreso va a stderr para no contaminar pipelines que capturen stdout.
---