2a3d780347
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>
56 lines
2.0 KiB
Markdown
56 lines
2.0 KiB
Markdown
---
|
|
name: find_unused_functions
|
|
kind: function
|
|
lang: go
|
|
domain: infra
|
|
version: "1.0.0"
|
|
purity: impure
|
|
signature: "func FindUnusedFunctions(registryRoot string) ([]UnusedFunction, error)"
|
|
description: "Abre registry.db y retorna todas las funciones que no son referenciadas por ninguna otra funcion, app ni analisis. Util para detectar candidatas a deprecar o eliminar (fn doctor unused)."
|
|
tags: [doctor, registry, unused, cleanup]
|
|
uses_functions: []
|
|
uses_types: []
|
|
returns: []
|
|
returns_optional: false
|
|
error_type: "error_go_core"
|
|
imports:
|
|
- "database/sql"
|
|
- "encoding/json"
|
|
- "fmt"
|
|
- "strings"
|
|
- "time"
|
|
- "github.com/mattn/go-sqlite3"
|
|
params:
|
|
- name: registryRoot
|
|
desc: "Ruta absoluta a la raiz del registry (directorio que contiene registry.db)."
|
|
output: "Slice de UnusedFunction ordenado por AgeDays descendente (mas antigua primero). Cada entrada incluye ID, Name, Lang, Domain, Tags (JSON array como string) y AgeDays (dias desde updated_at)."
|
|
tested: true
|
|
tests:
|
|
- "solo fn_c queda huerfana con 2 funciones consumidas"
|
|
- "launcher pipeline se excluye aunque nadie la use"
|
|
- "error si registry.db no existe"
|
|
test_file_path: "functions/infra/find_unused_functions_test.go"
|
|
file_path: "functions/infra/find_unused_functions.go"
|
|
---
|
|
|
|
## Ejemplo
|
|
|
|
```go
|
|
unused, err := FindUnusedFunctions("/home/lucas/fn_registry")
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
for _, u := range unused {
|
|
fmt.Printf("%s (%s/%s) — %d dias sin uso\n", u.ID, u.Lang, u.Domain, u.AgeDays)
|
|
}
|
|
```
|
|
|
|
## Notas
|
|
|
|
- Recorre `uses_functions` en tres tablas: `functions`, `apps` y `analysis`.
|
|
- Pipelines con tag `launcher` se excluyen: son endpoints intencionales aunque nadie los llame.
|
|
- Pipelines sin tag `launcher` y sin consumidor SÍ aparecen — son candidatos igual.
|
|
- Los tipos no se incluyen (eso es responsabilidad de otra funcion).
|
|
- El campo `Tags` retornado es el JSON array crudo (ej. `["deprecated","core"]`) para que el caller pueda filtrar por tag sin deserializar en esta funcion.
|
|
- `AgeDays` se calcula con `time.Parse(time.RFC3339, updated_at)`.
|