@saulwade/swl-ses 2.5.2 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +194 -192
- package/README.md +600 -600
- package/agentes/auto-evolucion-swl.md +27 -3
- package/bin/swl-ses.js +32 -6
- package/comandos/swl/actualizar.md +174 -174
- package/comandos/swl/adoptar-proyecto.md +265 -265
- package/comandos/swl/aprender.md +836 -823
- package/comandos/swl/aprobar-plan.md +146 -146
- package/comandos/swl/auditar-deps.md +134 -134
- package/comandos/swl/autoresearch.md +264 -264
- package/comandos/swl/ayuda.md +224 -224
- package/comandos/swl/brainstorm.md +51 -51
- package/comandos/swl/briefing.md +119 -119
- package/comandos/swl/checkpoint.md +325 -325
- package/comandos/swl/claudemd.md +234 -234
- package/comandos/swl/compactar.md +310 -310
- package/comandos/swl/configurar-ci.md +235 -235
- package/comandos/swl/contexto.md +110 -110
- package/comandos/swl/contribuir.md +233 -233
- package/comandos/swl/crear-skill.md +292 -292
- package/comandos/swl/cron.md +194 -194
- package/comandos/swl/deuda-codigo.md +97 -97
- package/comandos/swl/discutir-fase.md +169 -169
- package/comandos/swl/ejecutar-fase.md +233 -233
- package/comandos/swl/evaluar-skill.md +520 -505
- package/comandos/swl/evolucion-continua.md +73 -0
- package/comandos/swl/evolucionar.md +267 -254
- package/comandos/swl/exportar-vault.md +583 -583
- package/comandos/swl/fix.md +118 -118
- package/comandos/swl/gateway.md +158 -158
- package/comandos/swl/inbox.md +116 -116
- package/comandos/swl/instalar.md +220 -220
- package/comandos/swl/instintos.md +86 -86
- package/comandos/swl/mapear-codebase.md +312 -312
- package/comandos/swl/mcp-status.md +175 -175
- package/comandos/swl/modelo.md +100 -100
- package/comandos/swl/nemesis.md +433 -433
- package/comandos/swl/notificaciones.md +299 -299
- package/comandos/swl/nuevo-proyecto.md +251 -251
- package/comandos/swl/planear-fase.md +263 -263
- package/comandos/swl/plugins.md +256 -256
- package/comandos/swl/predecir.md +169 -169
- package/comandos/swl/reflect-skills.md +125 -125
- package/comandos/swl/release.md +450 -450
- package/comandos/swl/revisar-impacto.md +201 -201
- package/comandos/swl/revisar.md +330 -330
- package/comandos/swl/seguridad.md +189 -189
- package/comandos/swl/sesiones.md +200 -200
- package/comandos/swl/skill-search.md +113 -113
- package/comandos/swl/status.md +343 -343
- package/comandos/swl/verificar.md +817 -817
- package/comandos/swl/wiki.md +620 -620
- package/gateway/cron/jobs.example.json +12 -0
- package/habilidades/auto-evolucion-protocolo/SKILL.md +294 -276
- package/habilidades/autoresearch/SKILL.md +3 -2
- package/habilidades/benchmark-memoria/SKILL.md +7 -7
- package/habilidades/changelog-generator/SKILL.md +174 -174
- package/habilidades/changelog-generator/scripts/parse-commits.js +2 -1
- package/habilidades/checkpoints-verificacion/SKILL.md +6 -0
- package/habilidades/context-builder/SKILL.md +4 -0
- package/habilidades/doubt-driven-review/SKILL.md +207 -191
- package/habilidades/drift-detection/SKILL.md +6 -1
- package/habilidades/ejecutar-fase/SKILL.md +6 -6
- package/habilidades/eval-framework/SKILL.md +8 -3
- package/habilidades/harness-claude-code/SKILL.md +314 -308
- package/habilidades/infra-github-actions/SKILL.md +4 -3
- package/habilidades/instalar-sistema/SKILL.md +227 -223
- package/habilidades/memoria-busqueda/SKILL.md +31 -39
- package/habilidades/planear-fase/SKILL.md +358 -350
- package/habilidades/proceso-ddia-fundamentos/SKILL.md +3 -2
- package/habilidades/release-semver/SKILL.md +4 -2
- package/habilidades/swl-claudemd/SKILL.md +6 -7
- package/habilidades/swl-dashboard/SKILL.md +11 -43
- package/habilidades/tdd-workflow/SKILL.md +749 -744
- package/habilidades/validacion-ci-sistema/SKILL.md +1 -1
- package/hooks/agente-lifecycle.js +2 -1
- package/hooks/aiisms-detector.js +13 -4
- package/hooks/audit-trail.js +2 -1
- package/hooks/auto-consolidacion.js +2 -1
- package/hooks/captura-acciones-post.js +2 -1
- package/hooks/captura-acciones-session.js +2 -1
- package/hooks/captura-feedback-usuario.js +3 -2
- package/hooks/claudemd-bloat-detector.js +12 -3
- package/hooks/claudemd-duplicacion-detector.js +13 -3
- package/hooks/contexto-iteracion.js +2 -1
- package/hooks/degradacion-instintos.js +2 -1
- package/hooks/extraccion-aprendizajes.js +109 -15
- package/hooks/grafo-contexto.js +2 -1
- package/hooks/guardrail-modelo.js +2 -1
- package/hooks/inbox-aviso.js +2 -1
- package/hooks/inyeccion-contexto.js +2 -1
- package/hooks/lib/agent-matcher.js +2 -1
- package/hooks/lib/agent-routing.js +2 -1
- package/hooks/lib/autonomia.js +5 -3
- package/hooks/lib/captura-acciones.js +2 -1
- package/hooks/lib/consolidation-lock.js +21 -10
- package/hooks/lib/etapa-auto-evolucion.js +10 -4
- package/hooks/lib/etapa-metricas.js +2 -1
- package/hooks/lib/etapa-perfil-usuario.js +20 -4
- package/hooks/lib/evolution-tracker.js +2 -1
- package/hooks/lib/gateway-notify.js +193 -179
- package/hooks/lib/loop-telemetry.js +5 -4
- package/hooks/lib/mcp-health.js +2 -1
- package/hooks/lib/memory-search.js +4 -0
- package/hooks/lib/merkle-audit.js +58 -6
- package/hooks/lib/nudge-tracker.js +2 -1
- package/hooks/lib/otlp-exporter.js +2 -1
- package/hooks/lib/propose-step.js +3 -2
- package/hooks/lib/raiz-proyecto.js +102 -0
- package/hooks/lib/run-log.js +2 -1
- package/hooks/lib/singleton-guard.js +218 -27
- package/hooks/lib/telegram-cliente.js +17 -8
- package/hooks/preservar-estado-pre-compact.js +2 -1
- package/hooks/proteccion-rutas.js +59 -3
- package/hooks/registro-turnos.js +2 -1
- package/hooks/resumen-sesion.js +2 -1
- package/hooks/risk-scoring.js +2 -1
- package/hooks/rotar-audit-auto.js +46 -20
- package/hooks/session-briefing.js +127 -1
- package/hooks/spec-gate.js +2 -1
- package/hooks/sugerir-contribuir.js +6 -3
- package/hooks/sugerir-regenerar-inventario.js +3 -2
- package/hooks/tdd-gate.js +2 -1
- package/hooks/telemetria-agentes.js +2 -1
- package/hooks/telemetria-skill-routing.js +2 -1
- package/hooks/tracking-costos.js +4 -3
- package/hooks/validar-formato-post-subagente.js +2 -1
- package/hooks/validar-intent-spec.js +2 -1
- package/hooks/validar-memoria-hook.js +13 -3
- package/hooks/validar-planning-paths.js +2 -1
- package/instintos/.backups/perfil-usuario.yaml.2026-07-10-165128.bak +53 -0
- package/instintos/.backups/proyecto.yaml.2026-07-10-165128.bak +372 -0
- package/instintos/perfil-usuario.yaml +506 -3
- package/instintos/proyecto.yaml +78 -0
- package/llms.txt +2 -2
- package/manifiestos/canonical-hashes.json +664 -2
- package/manifiestos/modulos.json +19 -14
- package/manifiestos/planning-paths.json +1 -0
- package/manifiestos/skills-lock.json +53 -53
- package/package.json +2 -3
- package/plugin.json +2 -2
- package/scripts/actualizar.js +3 -0
- package/scripts/auditar-clases-conocidas.js +32 -4
- package/scripts/benchmark-memoria.js +1 -0
- package/scripts/cli/autonomia.js +23 -0
- package/scripts/cli/benchmark-memoria.js +37 -0
- package/scripts/cli/ciclo-autonomo.js +73 -0
- package/scripts/cli/ciclo-fase-b.js +102 -0
- package/scripts/cli/guardrail-metrics.js +39 -0
- package/scripts/cli/loop-telemetry.js +4 -2
- package/scripts/cli/memoria-search.js +69 -0
- package/scripts/cli/nudge-accionar.js +39 -0
- package/scripts/cli/run-eval.js +38 -0
- package/scripts/cli/run-skill-evals.js +13 -2
- package/scripts/derivar-feature-list.js +15 -14
- package/scripts/desinstalar.js +11 -0
- package/scripts/doctor.js +24 -10
- package/scripts/instalador.js +106 -7
- package/scripts/lib/activar-hooks-proyecto.js +116 -0
- package/scripts/lib/auditar-invocaciones-comandos.js +96 -6
- package/scripts/lib/ciclo-autonomo/candidatos.js +174 -0
- package/scripts/lib/ciclo-autonomo/config.js +165 -0
- package/scripts/lib/ciclo-autonomo/drenador-feedback.js +174 -0
- package/scripts/lib/ciclo-autonomo/fallback.js +77 -0
- package/scripts/lib/ciclo-autonomo/guard-convivencia.js +139 -0
- package/scripts/lib/ciclo-autonomo/higiene-nudges.js +112 -0
- package/scripts/lib/ciclo-autonomo/index.js +301 -0
- package/scripts/lib/ciclo-autonomo/lock.js +124 -0
- package/scripts/lib/ciclo-autonomo/presupuesto.js +122 -0
- package/scripts/lib/ciclo-autonomo/puente-degradacion.js +240 -0
- package/scripts/lib/ciclo-autonomo/runner-fase-b.js +248 -0
- package/scripts/lib/ciclo-autonomo/writer-instintos.js +190 -0
- package/scripts/lib/ciclo-autonomo/yaml-instintos.js +535 -0
- package/scripts/lib/estado.js +9 -0
- package/scripts/lib/evidencia-valor.js +1 -1
- package/scripts/lib/gitignore-manifest.js +8 -1
- package/scripts/lib/hooks-settings.js +45 -0
- package/scripts/rotar-audit-logs.js +48 -2
- package/scripts/run-eval.js +1 -0
- package/scripts/run-skill-evals.js +287 -8
- package/scripts/smoke-test.js +16 -8
- package/scripts/tui/pantallas/install-wizard.js +403 -347
- package/scripts/validar.js +40 -1
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* activar-hooks-proyecto.js — Camino "solo hooks" (DT-HOOKS-SOLO-PROYECTO).
|
|
5
|
+
*
|
|
6
|
+
* Registra en el `.claude/settings.json` del PROYECTO los hooks del scope
|
|
7
|
+
* GLOBAL ya instalado, sin copiar ningún componente. Cierra el dilema del
|
|
8
|
+
* install local: los hooks solo funcionan registrados a nivel proyecto
|
|
9
|
+
* (ADR-0009), pero el install local completo duplica agentes/comandos en la
|
|
10
|
+
* UI de Claude Code (lee ambos scopes). Con este camino:
|
|
11
|
+
*
|
|
12
|
+
* - Los comandos del settings apuntan con ruta ABSOLUTA al hooks/ global
|
|
13
|
+
* (esGlobal: true en registrarHooks) → cero archivos copiados.
|
|
14
|
+
* - `swl-ses update` del global refresca los hooks de TODOS los proyectos
|
|
15
|
+
* activados así, gratis (apuntan a los mismos archivos).
|
|
16
|
+
* - Hooks externos (no-SWL) del settings del proyecto se preservan
|
|
17
|
+
* (garantía de registrarHooks).
|
|
18
|
+
*
|
|
19
|
+
* Uso: `swl-ses install --target claude --solo-hooks` (en la raíz del
|
|
20
|
+
* proyecto). Requiere instalación global previa del runtime.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const fs = require('fs');
|
|
24
|
+
const path = require('path');
|
|
25
|
+
|
|
26
|
+
const RUNTIMES_SOPORTADOS = new Set(['claude', 'openclaude']);
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {object} opciones
|
|
30
|
+
* @param {string} [opciones.target='claude'] Runtime (claude|openclaude — formato de settings de Claude Code)
|
|
31
|
+
* @param {string} [opciones.dirProyecto=cwd] Raíz del proyecto destino
|
|
32
|
+
* @param {string} [opciones.hooksDirGlobal] Override del hooks/ global (tests)
|
|
33
|
+
* @param {object} [opciones.deps] Inyección para tests: { registrarHooks, registrarOptimizaciones, cargarHooksConfig, scopesReales, obtenerRuntime }
|
|
34
|
+
* @returns {{ok: boolean, error?: string, settingsPath?: string, hooksDirGlobal?: string, registrados?: number, preservados?: number}}
|
|
35
|
+
*/
|
|
36
|
+
function activarHooksProyecto(opciones = {}) {
|
|
37
|
+
const target = opciones.target || 'claude';
|
|
38
|
+
if (!RUNTIMES_SOPORTADOS.has(target)) {
|
|
39
|
+
return { ok: false, error: `--solo-hooks soporta por ahora targets con settings formato Claude Code (claude, openclaude); recibido: "${target}".` };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const deps = opciones.deps || {};
|
|
43
|
+
const hs = require('./hooks-settings');
|
|
44
|
+
const registrarHooks = deps.registrarHooks || hs.registrarHooks;
|
|
45
|
+
const registrarOptimizaciones = deps.registrarOptimizaciones || hs.registrarOptimizaciones;
|
|
46
|
+
const cargarHooksConfig = deps.cargarHooksConfig || hs.cargarHooksConfig;
|
|
47
|
+
|
|
48
|
+
// 1. Localizar el hooks/ del scope GLOBAL del runtime.
|
|
49
|
+
let hooksDirGlobal = opciones.hooksDirGlobal;
|
|
50
|
+
if (!hooksDirGlobal) {
|
|
51
|
+
try {
|
|
52
|
+
const dr = require('./detectar-runtime');
|
|
53
|
+
const obtenerRuntime = deps.obtenerRuntime || dr.obtenerRuntime;
|
|
54
|
+
const scopesReales = deps.scopesReales || dr.scopesReales;
|
|
55
|
+
const runtime = obtenerRuntime(target);
|
|
56
|
+
const global = scopesReales(runtime).find(s => s.esGlobal);
|
|
57
|
+
if (!global) return { ok: false, error: `No se pudo resolver el scope global del runtime "${target}".` };
|
|
58
|
+
hooksDirGlobal = path.join(global.dir, 'hooks');
|
|
59
|
+
} catch (err) {
|
|
60
|
+
return { ok: false, error: `No se pudo detectar el runtime "${target}": ${err.message}` };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (!fs.existsSync(hooksDirGlobal)) {
|
|
64
|
+
return { ok: false, error: `No hay instalación global con hooks en ${hooksDirGlobal}. Instala primero el global: npx -y @saulwade/swl-ses@latest install --target ${target} --global --perfil completo` };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// 2. Hooks disponibles = archivos del global ∩ hooks-config del paquete.
|
|
68
|
+
const hooksConfig = cargarHooksConfig();
|
|
69
|
+
const hookFiles = fs.readdirSync(hooksDirGlobal)
|
|
70
|
+
.filter(f => f.endsWith('.js') && hooksConfig[f]);
|
|
71
|
+
if (hookFiles.length === 0) {
|
|
72
|
+
return { ok: false, error: `El hooks/ global (${hooksDirGlobal}) no contiene hooks reconocidos por hooks-config.json — instalación global corrupta o muy antigua; corre update primero.` };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 3. Registrar en el settings.json del PROYECTO, apuntando al global.
|
|
76
|
+
const dirProyecto = opciones.dirProyecto || process.cwd();
|
|
77
|
+
const dirClaude = path.join(dirProyecto, '.claude');
|
|
78
|
+
fs.mkdirSync(dirClaude, { recursive: true });
|
|
79
|
+
const settingsPath = path.join(dirClaude, 'settings.json');
|
|
80
|
+
|
|
81
|
+
const r = registrarHooks({
|
|
82
|
+
settingsPath,
|
|
83
|
+
hooksDir: hooksDirGlobal,
|
|
84
|
+
esGlobal: true, // semántica: comandos con ruta ABSOLUTA al hooksDir (que es el global)
|
|
85
|
+
hookFiles,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
let optimizaciones = 0;
|
|
89
|
+
try {
|
|
90
|
+
const opt = registrarOptimizaciones(settingsPath);
|
|
91
|
+
optimizaciones = (opt && opt.registradas) || 0;
|
|
92
|
+
} catch { /* opcional — no bloquea la activación */ }
|
|
93
|
+
|
|
94
|
+
// 4. Sembrar el .gitignore del proyecto: encender la telemetría hace que
|
|
95
|
+
// los hooks ESCRIBAN (.planning/METRICAS.md, audit*.jsonl, evolution/...)
|
|
96
|
+
// — sin la sección swl-ses esos archivos runtime aparecen como cambios
|
|
97
|
+
// pendientes en el editor del usuario (caso real sistema-verificacion-oic,
|
|
98
|
+
// 2026-07-10: 19 archivos sin trackear tras activar hooks).
|
|
99
|
+
let gitignorePath = null;
|
|
100
|
+
try {
|
|
101
|
+
const { actualizarGitignore } = deps.gitignoreManifest || require('./gitignore-manifest');
|
|
102
|
+
gitignorePath = actualizarGitignore(dirProyecto);
|
|
103
|
+
} catch { /* no bloquea la activación — se reporta null */ }
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
ok: true,
|
|
107
|
+
settingsPath,
|
|
108
|
+
hooksDirGlobal,
|
|
109
|
+
registrados: r.registrados,
|
|
110
|
+
preservados: r.preservados,
|
|
111
|
+
optimizaciones,
|
|
112
|
+
gitignorePath,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
module.exports = { activarHooksProyecto, RUNTIMES_SOPORTADOS };
|
|
@@ -87,17 +87,107 @@ function auditarInvocacionesComandos(comandosDir) {
|
|
|
87
87
|
return { ok: violaciones.length === 0, violaciones, escaneados };
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
// Skills que corren SOLO en el repo madre (host-only declarado en su propio
|
|
91
|
+
// frontmatter/cuerpo): sus `node scripts/...` son legítimos porque el CWD ES
|
|
92
|
+
// el repo (DT-PATHS-DESTINO, cierre 2026-07-10).
|
|
93
|
+
const SKILLS_SOLO_MADRE = new Set([
|
|
94
|
+
'doc-sync',
|
|
95
|
+
'release-semver',
|
|
96
|
+
'validacion-ci-sistema',
|
|
97
|
+
]);
|
|
98
|
+
|
|
99
|
+
// Lenguajes de fence que se auditan en skills: solo instrucciones ejecutables
|
|
100
|
+
// de shell. Los bloques js/javascript documentan APIs de módulos (referencia,
|
|
101
|
+
// no comandos a ejecutar downstream) y llevan su clarificador de layout.
|
|
102
|
+
const LENGUAJES_EJECUTABLES = new Set(['', 'bash', 'sh', 'shell']);
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Igual que auditarInvocacionesComandos pero sobre habilidades/<skill>/SKILL.md.
|
|
106
|
+
* Solo audita fences ejecutables (bash/sh/shell/sin lenguaje).
|
|
107
|
+
* @param {string} [habilidadesDir]
|
|
108
|
+
* @returns {{ok:boolean, violaciones:Array<{comando:string,linea:number,texto:string,patron:string}>, escaneados:number}}
|
|
109
|
+
*/
|
|
110
|
+
function auditarInvocacionesSkills(habilidadesDir) {
|
|
111
|
+
const dir = habilidadesDir || path.join(__dirname, '..', '..', 'habilidades');
|
|
112
|
+
const violaciones = [];
|
|
113
|
+
let escaneados = 0;
|
|
114
|
+
|
|
115
|
+
let skills;
|
|
116
|
+
try {
|
|
117
|
+
skills = fs.readdirSync(dir, { withFileTypes: true })
|
|
118
|
+
.filter((d) => d.isDirectory())
|
|
119
|
+
.map((d) => d.name);
|
|
120
|
+
} catch {
|
|
121
|
+
return { ok: true, violaciones, escaneados: 0 };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
for (const skill of skills) {
|
|
125
|
+
if (SKILLS_SOLO_MADRE.has(skill)) continue;
|
|
126
|
+
const ruta = path.join(dir, skill, 'SKILL.md');
|
|
127
|
+
let contenido;
|
|
128
|
+
try {
|
|
129
|
+
contenido = fs.readFileSync(ruta, 'utf8');
|
|
130
|
+
} catch {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
escaneados++;
|
|
134
|
+
|
|
135
|
+
const lineas = contenido.split('\n');
|
|
136
|
+
let dentroCodigo = false;
|
|
137
|
+
let lenguaje = '';
|
|
138
|
+
let marcadores = 0;
|
|
139
|
+
|
|
140
|
+
for (let i = 0; i < lineas.length; i++) {
|
|
141
|
+
const linea = lineas[i];
|
|
142
|
+
const fence = linea.match(/^\s*```\s*(\S*)/);
|
|
143
|
+
if (fence) {
|
|
144
|
+
marcadores++;
|
|
145
|
+
dentroCodigo = !dentroCodigo;
|
|
146
|
+
lenguaje = dentroCodigo ? fence[1].toLowerCase() : '';
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (!dentroCodigo || !LENGUAJES_EJECUTABLES.has(lenguaje)) continue;
|
|
150
|
+
for (const { re, desc } of PATRONES) {
|
|
151
|
+
if (re.test(linea)) {
|
|
152
|
+
violaciones.push({
|
|
153
|
+
comando: `habilidades/${skill}/SKILL.md`,
|
|
154
|
+
linea: i + 1,
|
|
155
|
+
texto: linea.trim(),
|
|
156
|
+
patron: desc,
|
|
157
|
+
});
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// Fences desbalanceados (conteo impar de ```): el toggle booleano quedó
|
|
163
|
+
// invertido para el resto del archivo y pudo silenciar violaciones reales.
|
|
164
|
+
// Se reporta como violación para que el scan NO termine en verde falso.
|
|
165
|
+
if (marcadores % 2 !== 0) {
|
|
166
|
+
violaciones.push({
|
|
167
|
+
comando: `habilidades/${skill}/SKILL.md`,
|
|
168
|
+
linea: 0,
|
|
169
|
+
texto: `${marcadores} marcadores \`\`\` (impar) — fence sin cerrar o anidado`,
|
|
170
|
+
patron: 'fences desbalanceados (el scan de invocaciones pudo quedar ciego)',
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return { ok: violaciones.length === 0, violaciones, escaneados };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
module.exports = { auditarInvocacionesComandos, auditarInvocacionesSkills, SELF_DEV, SKILLS_SOLO_MADRE };
|
|
91
179
|
|
|
92
180
|
if (require.main === module) {
|
|
93
181
|
const r = auditarInvocacionesComandos();
|
|
94
|
-
|
|
95
|
-
|
|
182
|
+
const rs = auditarInvocacionesSkills();
|
|
183
|
+
if (r.ok && rs.ok) {
|
|
184
|
+
console.log(`[OK] invocaciones-comandos — ${r.escaneados} comandos + ${rs.escaneados} skills user-facing sin rutas relativas al proyecto`);
|
|
96
185
|
process.exit(0);
|
|
97
186
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
187
|
+
const todas = [...r.violaciones, ...rs.violaciones];
|
|
188
|
+
console.error(`[FALLA] invocaciones-comandos — ${todas.length} invocación(es) relativa(s) al proyecto en componentes user-facing:`);
|
|
189
|
+
for (const v of todas) {
|
|
190
|
+
console.error(` ${v.comando}:${v.linea} [${v.patron}] ${v.texto}`);
|
|
101
191
|
}
|
|
102
192
|
console.error('\nUsa el patrón cross-scope (docs/invocacion-cli-cross-scope.md): swl-ses <sub> / npx ... <sub> / node scripts/cli/<sub>.js');
|
|
103
193
|
process.exit(1);
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* candidatos.js — Detector determinista de candidatos a Fase B del ciclo
|
|
5
|
+
* autónomo (Fase 22, T-02, ADR-0042 gate G-B, REQ-22-01).
|
|
6
|
+
*
|
|
7
|
+
* Tres fuentes deterministas, SIN invocar LLM:
|
|
8
|
+
* 1. Instintos con `candidato_global:true` en `instintos/proyecto.yaml`
|
|
9
|
+
* (via `yaml-instintos.leerInstintos`, tolerante a archivo ausente).
|
|
10
|
+
* 2. Nudges `kind:'auto-evolucion'` no accionados con evidencia
|
|
11
|
+
* (`data.diagnosis` o `data.razon` en {fallos, loop}) leídos de
|
|
12
|
+
* `evolution/nudges.jsonl`.
|
|
13
|
+
* 3. Skills fríos vía `require('../skill-metrics').skillsStale` (require
|
|
14
|
+
* tolerante → `[]` si la lib no resuelve en el destino de instalación).
|
|
15
|
+
*
|
|
16
|
+
* Persiste SOLO los candidatos nuevos (dedupe por `id`, releyendo el jsonl
|
|
17
|
+
* previo con tolerancia por línea) en `evolution/candidatos-fase-b.jsonl`.
|
|
18
|
+
* Una corrida sin candidatos nuevos NO escribe el archivo (ni lo crea si no
|
|
19
|
+
* existía). Zero-deps, CommonJS.
|
|
20
|
+
*
|
|
21
|
+
* @module scripts/lib/ciclo-autonomo/candidatos
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const fs = require('fs');
|
|
25
|
+
const path = require('path');
|
|
26
|
+
const { leerInstintos } = require('./yaml-instintos');
|
|
27
|
+
|
|
28
|
+
const RUTA_INSTINTOS_RELATIVA = path.join('instintos', 'proyecto.yaml');
|
|
29
|
+
const RUTA_NUDGES_RELATIVA = path.join('.planning', 'evolution', 'nudges.jsonl');
|
|
30
|
+
const RUTA_CANDIDATOS_RELATIVA = path.join('.planning', 'evolution', 'candidatos-fase-b.jsonl');
|
|
31
|
+
|
|
32
|
+
/** Razones de nudge `auto-evolucion` que cuentan como evidencia suficiente. */
|
|
33
|
+
const RAZONES_CON_EVIDENCIA = new Set(['fallos', 'loop']);
|
|
34
|
+
|
|
35
|
+
/** Lee un JSONL con tolerancia por línea: línea corrupta se descarta, nunca crashea. */
|
|
36
|
+
function leerJsonlTolerante(ruta) {
|
|
37
|
+
let crudo;
|
|
38
|
+
try {
|
|
39
|
+
crudo = fs.readFileSync(ruta, 'utf8');
|
|
40
|
+
} catch (_) {
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
return crudo.split(/\r\n|\n/)
|
|
44
|
+
.filter((linea) => linea.trim() !== '')
|
|
45
|
+
.map((linea) => {
|
|
46
|
+
try {
|
|
47
|
+
return JSON.parse(linea);
|
|
48
|
+
} catch (_) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
.filter(Boolean);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Fuente 1: instintos con `candidato_global:true` en instintos/proyecto.yaml. */
|
|
56
|
+
function candidatosDeInstintos(baseDir, ts) {
|
|
57
|
+
const ruta = path.join(baseDir, RUTA_INSTINTOS_RELATIVA);
|
|
58
|
+
let datos;
|
|
59
|
+
try {
|
|
60
|
+
datos = leerInstintos(ruta);
|
|
61
|
+
} catch (_) {
|
|
62
|
+
return []; // archivo ausente o YAML corrupto: sin candidatos de esta fuente
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return (datos.instintos || [])
|
|
66
|
+
.filter((instinto) => instinto.candidato_global === true)
|
|
67
|
+
.map((instinto) => ({
|
|
68
|
+
id: `instinto:${instinto.id}`,
|
|
69
|
+
fuente: 'instinto-global',
|
|
70
|
+
ref: { id: instinto.id, pattern: instinto.pattern || null },
|
|
71
|
+
ts,
|
|
72
|
+
origen: 'ciclo-autonomo',
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Fuente 2: nudges `kind:'auto-evolucion'` no accionados con evidencia. */
|
|
77
|
+
function candidatosDeNudges(baseDir, ts) {
|
|
78
|
+
const ruta = path.join(baseDir, RUTA_NUDGES_RELATIVA);
|
|
79
|
+
|
|
80
|
+
return leerJsonlTolerante(ruta)
|
|
81
|
+
.filter((nudge) => nudge && nudge.kind === 'auto-evolucion' && nudge.accionado !== true)
|
|
82
|
+
.filter((nudge) => {
|
|
83
|
+
const data = nudge.data || {};
|
|
84
|
+
return Boolean(data.diagnosis) || RAZONES_CON_EVIDENCIA.has(data.razon);
|
|
85
|
+
})
|
|
86
|
+
.map((nudge) => ({
|
|
87
|
+
id: `nudge:${nudge.id}`,
|
|
88
|
+
fuente: 'evolucion-agente',
|
|
89
|
+
ref: {
|
|
90
|
+
target: nudge.target || null,
|
|
91
|
+
razon: (nudge.data || {}).razon || null,
|
|
92
|
+
tieneDiagnosis: Boolean((nudge.data || {}).diagnosis),
|
|
93
|
+
},
|
|
94
|
+
ts,
|
|
95
|
+
origen: 'ciclo-autonomo',
|
|
96
|
+
}));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Fuente 3: skills fríos vía skill-metrics.skillsStale (require tolerante → []). */
|
|
100
|
+
function candidatosDeSkillsFrios(baseDir, ahora, ts) {
|
|
101
|
+
let skillsStale;
|
|
102
|
+
try {
|
|
103
|
+
({ skillsStale } = require('../skill-metrics'));
|
|
104
|
+
} catch (_) {
|
|
105
|
+
return []; // lib no distribuida en este destino: sin candidatos de esta fuente
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
let frios;
|
|
109
|
+
try {
|
|
110
|
+
frios = skillsStale(baseDir, ahora);
|
|
111
|
+
} catch (_) {
|
|
112
|
+
return [];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return (frios || []).map((frio) => ({
|
|
116
|
+
id: `skill:${frio.skill}`,
|
|
117
|
+
fuente: 'skill-stale',
|
|
118
|
+
ref: { skill: frio.skill, diasInactivo: frio.diasInactivo },
|
|
119
|
+
ts,
|
|
120
|
+
origen: 'ciclo-autonomo',
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Ids ya persistidos en `candidatos-fase-b.jsonl` (dedupe, tolerante por línea). */
|
|
125
|
+
function idsConocidos(baseDir) {
|
|
126
|
+
const ruta = path.join(baseDir, RUTA_CANDIDATOS_RELATIVA);
|
|
127
|
+
return new Set(leerJsonlTolerante(ruta).map((entrada) => entrada.id).filter(Boolean));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Append de los candidatos nuevos (dedupe ya aplicado por el caller); no-op si viene vacío. */
|
|
131
|
+
function persistirNuevos(baseDir, nuevos) {
|
|
132
|
+
if (nuevos.length === 0) return;
|
|
133
|
+
|
|
134
|
+
const ruta = path.join(baseDir, RUTA_CANDIDATOS_RELATIVA);
|
|
135
|
+
const dir = path.dirname(ruta);
|
|
136
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
137
|
+
|
|
138
|
+
const lineas = nuevos.map((candidato) => JSON.stringify(candidato)).join('\n') + '\n';
|
|
139
|
+
fs.appendFileSync(ruta, lineas);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Detecta candidatos a Fase B desde las tres fuentes deterministas y
|
|
144
|
+
* persiste (dedupe por id) SOLO los nuevos en `evolution/candidatos-fase-b.jsonl`.
|
|
145
|
+
* Tolerante a la ausencia de cualquier fuente — nunca crashea.
|
|
146
|
+
*
|
|
147
|
+
* @param {string} baseDir - Directorio raíz del proyecto.
|
|
148
|
+
* @param {{ahora?: Date}} [opciones]
|
|
149
|
+
* @returns {{nuevos: number, total: number, candidatos: object[]}}
|
|
150
|
+
*/
|
|
151
|
+
function detectar(baseDir, { ahora } = {}) {
|
|
152
|
+
const momento = ahora || new Date();
|
|
153
|
+
const ts = momento.toISOString();
|
|
154
|
+
|
|
155
|
+
const candidatos = [
|
|
156
|
+
...candidatosDeInstintos(baseDir, ts),
|
|
157
|
+
...candidatosDeNudges(baseDir, ts),
|
|
158
|
+
...candidatosDeSkillsFrios(baseDir, momento, ts),
|
|
159
|
+
];
|
|
160
|
+
|
|
161
|
+
const conocidos = idsConocidos(baseDir);
|
|
162
|
+
const vistos = new Set();
|
|
163
|
+
const nuevosCandidatos = candidatos.filter((candidato) => {
|
|
164
|
+
if (conocidos.has(candidato.id) || vistos.has(candidato.id)) return false;
|
|
165
|
+
vistos.add(candidato.id);
|
|
166
|
+
return true;
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
persistirNuevos(baseDir, nuevosCandidatos);
|
|
170
|
+
|
|
171
|
+
return { nuevos: nuevosCandidatos.length, total: candidatos.length, candidatos };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
module.exports = { detectar };
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Loader/writer de `.planning/evolution/ciclo-config.json` — schema del
|
|
5
|
+
* motor determinista de aprendizaje (Fase 21, ADR-0041/ADR-0042, Nivel 0).
|
|
6
|
+
*
|
|
7
|
+
* Opt-OUT estricto (decisión del usuario 2026-07-10, reformula la regla de
|
|
8
|
+
* negocio 1 de la Fase 21): el motor NACE ENCENDIDO — "un ciclo que exige
|
|
9
|
+
* encendido es un ciclo muerto en downstream". Kill-switch doble:
|
|
10
|
+
* `habilitado:false` en el config (vía `/swl:evolucion-continua off`) o
|
|
11
|
+
* `SWL_CICLO_AUTONOMO=0` por sesión. Esta lib solo expone el predicado
|
|
12
|
+
* `estaHabilitado()`; el único punto que lo consulta para decidir si
|
|
13
|
+
* ejecutar es el orquestador (T-07, `index.js`) — las libs de sub-fase
|
|
14
|
+
* (writer, drenador, puente) son puras y no consultan config.
|
|
15
|
+
*
|
|
16
|
+
* Zero-deps, CommonJS.
|
|
17
|
+
*
|
|
18
|
+
* @module scripts/lib/ciclo-autonomo/config
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const fs = require('fs');
|
|
22
|
+
const path = require('path');
|
|
23
|
+
const { atomicWriteJSON } = require('../../../hooks/lib/atomic-write');
|
|
24
|
+
|
|
25
|
+
/** Ruta relativa del archivo de config dentro del baseDir del proyecto. */
|
|
26
|
+
const CONFIG_RELATIVA = path.join('.planning', 'evolution', 'ciclo-config.json');
|
|
27
|
+
|
|
28
|
+
/** Valores aceptados para el campo `credencial` (dual: cuenta Claude o API key). */
|
|
29
|
+
const CREDENCIALES_VALIDAS = new Set(['cuenta', 'api-key']);
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Defaults del schema completo. Los campos LLM (`presupuesto_usd_mes`,
|
|
33
|
+
* `tope_mutaciones_corrida`) nacieron reservados en Fase 21 y se consumen a
|
|
34
|
+
* partir de Fase 22. Los campos `fase_b_habilitada`, `last_run_fase_b`,
|
|
35
|
+
* `gasto_mes`, `mes` y `pausado_por_presupuesto` son propios de Fase 22
|
|
36
|
+
* (headless plumbing, ADR-0042 gate G-B): `fase_b_habilitada` nace en `true`
|
|
37
|
+
* —kill-switch separado del motor, coherente con el opt-out estricto general
|
|
38
|
+
* (default encendido)—; `gasto_mes`/`mes` llevan el contador de presupuesto
|
|
39
|
+
* del mes en curso (clave `mes` en formato `YYYY-MM` local); `mes:null`
|
|
40
|
+
* fuerza el primer `registrarGasto` a inicializar el mes actual.
|
|
41
|
+
*/
|
|
42
|
+
const DEFAULTS = Object.freeze({
|
|
43
|
+
habilitado: true,
|
|
44
|
+
credencial: 'cuenta',
|
|
45
|
+
presupuesto_usd_mes: 10,
|
|
46
|
+
tope_mutaciones_corrida: 3,
|
|
47
|
+
last_run: null,
|
|
48
|
+
ultima_corrida: null,
|
|
49
|
+
fase_b_habilitada: true,
|
|
50
|
+
last_run_fase_b: null,
|
|
51
|
+
gasto_mes: 0,
|
|
52
|
+
mes: null,
|
|
53
|
+
pausado_por_presupuesto: false,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Resuelve la ruta absoluta del archivo de config para un baseDir dado.
|
|
58
|
+
*
|
|
59
|
+
* @param {string} baseDir - Directorio raíz del proyecto (normalmente cwd).
|
|
60
|
+
* @returns {string} Ruta absoluta a `ciclo-config.json`.
|
|
61
|
+
*/
|
|
62
|
+
function rutaConfig(baseDir) {
|
|
63
|
+
return path.join(baseDir, CONFIG_RELATIVA);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Normaliza el campo `credencial`: valor fuera del dominio válido cae a
|
|
68
|
+
* "cuenta" sin lanzar error — un config corrupto o editado a mano nunca
|
|
69
|
+
* debe crashear al motor.
|
|
70
|
+
*
|
|
71
|
+
* @param {*} valor - Valor crudo leído de disco o de un patch.
|
|
72
|
+
* @returns {"cuenta"|"api-key"}
|
|
73
|
+
*/
|
|
74
|
+
function normalizarCredencial(valor) {
|
|
75
|
+
return CREDENCIALES_VALIDAS.has(valor) ? valor : 'cuenta';
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Lee el config del disco y lo mergea con los defaults del schema.
|
|
80
|
+
*
|
|
81
|
+
* Tolerante a archivo ausente (proyecto nunca habilitó el ciclo) y a JSON
|
|
82
|
+
* corrupto (config editado a mano incorrectamente) — en ambos casos cae
|
|
83
|
+
* a los defaults en vez de lanzar.
|
|
84
|
+
*
|
|
85
|
+
* @param {string} baseDir - Directorio raíz del proyecto.
|
|
86
|
+
* @returns {object} Config completo con todos los campos del schema.
|
|
87
|
+
*/
|
|
88
|
+
function leerConfig(baseDir) {
|
|
89
|
+
const ruta = rutaConfig(baseDir);
|
|
90
|
+
let crudo = {};
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
const contenido = fs.readFileSync(ruta, 'utf8');
|
|
94
|
+
crudo = JSON.parse(contenido);
|
|
95
|
+
} catch (_) {
|
|
96
|
+
// Archivo ausente o JSON corrupto: se opera con los defaults.
|
|
97
|
+
crudo = {};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const mergeado = { ...DEFAULTS, ...crudo };
|
|
101
|
+
mergeado.credencial = normalizarCredencial(mergeado.credencial);
|
|
102
|
+
return mergeado;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Escribe un patch sobre el config existente (merge, no overwrite) y lo
|
|
107
|
+
* persiste de forma atómica. Crea `.planning/evolution/` si falta.
|
|
108
|
+
*
|
|
109
|
+
* @param {string} baseDir - Directorio raíz del proyecto.
|
|
110
|
+
* @param {object} patch - Campos a actualizar; el resto se preserva.
|
|
111
|
+
* @returns {object} Config final ya escrito a disco.
|
|
112
|
+
*/
|
|
113
|
+
function escribirConfig(baseDir, patch) {
|
|
114
|
+
const actual = leerConfig(baseDir);
|
|
115
|
+
const siguiente = { ...actual, ...patch };
|
|
116
|
+
siguiente.credencial = normalizarCredencial(siguiente.credencial);
|
|
117
|
+
|
|
118
|
+
const ruta = rutaConfig(baseDir);
|
|
119
|
+
const dir = path.dirname(ruta);
|
|
120
|
+
if (!fs.existsSync(dir)) {
|
|
121
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
atomicWriteJSON(ruta, siguiente);
|
|
125
|
+
return siguiente;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Predicado de encendido del ciclo autónomo — opt-OUT estricto (decisión
|
|
130
|
+
* del usuario 2026-07-10): el motor nace ENCENDIDO; se apaga con
|
|
131
|
+
* `habilitado:false` en el config (`/swl:evolucion-continua off`) o con
|
|
132
|
+
* `SWL_CICLO_AUTONOMO=0` por sesión. `SWL_CICLO_AUTONOMO=1` fuerza el
|
|
133
|
+
* encendido por encima de un `off` en disco (override operacional en
|
|
134
|
+
* CI/cron sin tocar el archivo).
|
|
135
|
+
*
|
|
136
|
+
* @param {string} baseDir - Directorio raíz del proyecto.
|
|
137
|
+
* @returns {boolean}
|
|
138
|
+
*/
|
|
139
|
+
function estaHabilitado(baseDir) {
|
|
140
|
+
if (process.env.SWL_CICLO_AUTONOMO === '0') return false;
|
|
141
|
+
if (process.env.SWL_CICLO_AUTONOMO === '1') return true;
|
|
142
|
+
return leerConfig(baseDir).habilitado !== false;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Predicado de encendido de la Fase B (detector + runner headless,
|
|
147
|
+
* Fase 22) — kill-switch separado del motor general, pero SUBORDINADO a él
|
|
148
|
+
* (regla de negocio 1: motor apagado ⇒ Fase B apagada, sin excepción). Fase B
|
|
149
|
+
* no agrega variable de entorno propia: hereda `SWL_CICLO_AUTONOMO` a través
|
|
150
|
+
* de `estaHabilitado`.
|
|
151
|
+
*
|
|
152
|
+
* @param {string} baseDir - Directorio raíz del proyecto.
|
|
153
|
+
* @returns {boolean}
|
|
154
|
+
*/
|
|
155
|
+
function estaFaseBHabilitada(baseDir) {
|
|
156
|
+
if (!estaHabilitado(baseDir)) return false;
|
|
157
|
+
return leerConfig(baseDir).fase_b_habilitada !== false;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
module.exports = {
|
|
161
|
+
estaHabilitado,
|
|
162
|
+
estaFaseBHabilitada,
|
|
163
|
+
leerConfig,
|
|
164
|
+
escribirConfig,
|
|
165
|
+
};
|