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:
@@ -0,0 +1,61 @@
|
||||
---
|
||||
name: pc_locations_drift
|
||||
kind: function
|
||||
lang: go
|
||||
domain: infra
|
||||
version: "1.0.0"
|
||||
purity: impure
|
||||
signature: "func PcLocationsDrift(registryRoot string, pcID string) ([]LocationDrift, error)"
|
||||
description: "Compara la tabla pc_locations contra el estado real del disco para el PC actual. Detecta tres tipos de drift: carpetas activas que no existen, entradas missing cuya carpeta reaparece, y artefactos indexados en disco sin fila en pc_locations."
|
||||
tags: [doctor, sync, pc_locations, drift]
|
||||
uses_functions: []
|
||||
uses_types: []
|
||||
returns: []
|
||||
returns_optional: false
|
||||
error_type: "error_go_core"
|
||||
imports:
|
||||
- "bufio"
|
||||
- "database/sql"
|
||||
- "fmt"
|
||||
- "os"
|
||||
- "path/filepath"
|
||||
- "strings"
|
||||
- "github.com/mattn/go-sqlite3"
|
||||
tested: true
|
||||
tests:
|
||||
- "active entry whose folder is missing reports missing_on_disk"
|
||||
- "active entry with existing folder reports no drift"
|
||||
- "missing entry whose folder reappears reports status_should_be_active"
|
||||
- "indexed app on disk without pc_locations row reports untracked_on_disk"
|
||||
test_file_path: "functions/infra/pc_locations_drift_test.go"
|
||||
file_path: "functions/infra/pc_locations_drift.go"
|
||||
params:
|
||||
- name: registryRoot
|
||||
desc: "Ruta absoluta a la raiz del registry (donde vive registry.db)."
|
||||
- name: pcID
|
||||
desc: "Identificador del PC (ej: 'home-wsl'). Si vacio, se lee de la primera linea no vacia de ~/.fn_pc."
|
||||
output: "Slice de LocationDrift con todos los discrepancias encontradas. Vacio si no hay drift. Error solo si no se puede abrir registry.db."
|
||||
---
|
||||
|
||||
## Ejemplo
|
||||
|
||||
```go
|
||||
drifts, err := PcLocationsDrift("/home/lucas/fn_registry", "")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
for _, d := range drifts {
|
||||
fmt.Printf("[%s] %s/%s -> %s\n", d.Issue, d.EntityType, d.EntityID, d.DirPath)
|
||||
}
|
||||
```
|
||||
|
||||
## Notas
|
||||
|
||||
Read-only — nunca modifica la BD ni el disco. Util como paso inicial de `fn doctor sync`.
|
||||
|
||||
La funcion `readFnPC` es compartida en el paquete infra (lee `~/.fn_pc` ignorando lineas vacias y comentarios con `#`).
|
||||
|
||||
Tipos de issue reportados:
|
||||
- `missing_on_disk`: entrada `active` cuya carpeta no existe → sugerir cambiar status a `missing`
|
||||
- `status_should_be_active`: entrada `missing` cuya carpeta existe → sugerir cambiar status a `active`
|
||||
- `untracked_on_disk`: artefacto indexado con carpeta en disco pero sin fila en `pc_locations` → sugerir insertar
|
||||
Reference in New Issue
Block a user