@saulwade/swl-ses 1.4.1 → 1.5.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.
Files changed (136) hide show
  1. package/CLAUDE.md +3 -3
  2. package/README.md +561 -560
  3. package/agentes/nemesis-auditor-swl.md +161 -161
  4. package/bin/swl-mcp-server.js +49 -22
  5. package/bin/swl-ses.js +74 -0
  6. package/comandos/swl/.evolved.json +22 -22
  7. package/comandos/swl/contribuir.md +233 -233
  8. package/comandos/swl/ejecutar-fase.md +33 -4
  9. package/comandos/swl/metricas.md +72 -0
  10. package/comandos/swl/nemesis.md +122 -122
  11. package/gateway/lib/event-channel.js +191 -191
  12. package/habilidades/backend-production-resilience/SKILL.md +288 -288
  13. package/habilidades/benchmark-memoria/SKILL.md +186 -186
  14. package/habilidades/diagrama-arquitectura/assets/template.html +276 -276
  15. package/habilidades/discutir-fase/SKILL.md +50 -2
  16. package/habilidades/doubt-driven-review/SKILL.md +171 -171
  17. package/habilidades/doubt-driven-review/recursos/EXAMPLES.md +130 -130
  18. package/habilidades/ejecutar-task-iterativo/SKILL.md +278 -0
  19. package/habilidades/eval-framework/SKILL.md +212 -212
  20. package/habilidades/feynman-auditor-swl/SKILL.md +123 -123
  21. package/habilidades/feynman-auditor-swl/recursos/preguntas-language-agnostic.md +108 -108
  22. package/habilidades/harness-claude-code/SKILL.md +299 -299
  23. package/habilidades/infra-github-actions/SKILL.md +166 -166
  24. package/habilidades/legacy-code-rescue/SKILL.md +267 -267
  25. package/habilidades/manejo-errores/.evolved.json +8 -8
  26. package/habilidades/meta-skills-estandar/recursos/convencion-examples.md +93 -93
  27. package/habilidades/meta-skills-estandar/recursos/skills-as-agents.md +163 -163
  28. package/habilidades/patrones-python/SKILL.md +229 -229
  29. package/habilidades/patrones-python/recursos/patrones-avanzados.md +469 -469
  30. package/habilidades/planear-fase/SKILL.md +319 -319
  31. package/habilidades/protocolo-revision-swl/SKILL.md +276 -0
  32. package/habilidades/release-semver/.evolved.json +8 -8
  33. package/habilidades/state-inconsistency-auditor-swl/SKILL.md +166 -166
  34. package/habilidades/state-inconsistency-auditor-swl/recursos/coupled-state-patterns.md +147 -147
  35. package/habilidades/testing-python/SKILL.md +340 -340
  36. package/habilidades/verificar-trabajo/SKILL.md +49 -5
  37. package/habilidades/web-fetcher-routing/SKILL.md +75 -75
  38. package/hooks/claudemd-bloat-detector.js +161 -161
  39. package/hooks/lib/agent-routing.js +107 -107
  40. package/hooks/lib/auto-consolidator.js +335 -335
  41. package/hooks/lib/error-classifier.js +308 -308
  42. package/hooks/lib/merkle-audit.js +96 -96
  43. package/hooks/lib/provenance-tracker.js +191 -191
  44. package/hooks/lib/rate-limit-tracker.js +253 -253
  45. package/hooks/lib/resource-quota.js +122 -122
  46. package/hooks/lib/retry-jitter.js +165 -165
  47. package/hooks/lib/security-net.js +201 -201
  48. package/hooks/lib/skill-auditor.js +588 -588
  49. package/hooks/lib/sync-status.js +228 -228
  50. package/hooks/lib/taint-tracker.js +107 -107
  51. package/hooks/lib/text-similarity.js +241 -241
  52. package/hooks/lib/toon-compressor.js +245 -245
  53. package/hooks/registro-turnos.js +209 -209
  54. package/hooks/sugerir-regenerar-inventario.js +170 -170
  55. package/hooks/validar-formato-post-subagente.js +140 -140
  56. package/hooks/validar-memoria-hook.js +218 -218
  57. package/instintos/prompt-appendices.yaml +57 -57
  58. package/manifiestos/agent-output-schemas.json +57 -57
  59. package/manifiestos/modulos.json +1321 -1262
  60. package/manifiestos/perfiles.json +2 -1
  61. package/manifiestos/skills-lock.json +1114 -1114
  62. package/package.json +3 -3
  63. package/plantillas/auditor-veto-template.md +105 -105
  64. package/plantillas/github-workflows/README.md +47 -47
  65. package/plantillas/github-workflows/release-please.yml +44 -44
  66. package/plantillas/github-workflows/swl-ci.yml +107 -107
  67. package/plantillas/github-workflows/swl-security.yml +51 -51
  68. package/plugin.json +351 -343
  69. package/reglas/analisis-previo-tareas-grandes.md +172 -172
  70. package/reglas/arreglar-al-detectar.md +147 -147
  71. package/reglas/fragmentos-compartidos.md +152 -152
  72. package/reglas/harness-claude-code.md +213 -213
  73. package/reglas/usar-context7.md +226 -226
  74. package/schemas/diary-entry.schema.json +80 -80
  75. package/scripts/audit-tools/audit-history.js +330 -330
  76. package/scripts/audit-tools/bundle-tracker.js +290 -290
  77. package/scripts/audit-tools/canary-monitor.js +352 -352
  78. package/scripts/audit-tools/code-profiler.js +605 -605
  79. package/scripts/audit-tools/dep-doctor.js +320 -320
  80. package/scripts/audit-tools/env-validator.js +206 -206
  81. package/scripts/audit-tools/lib/fs-walk.js +48 -48
  82. package/scripts/audit-tools/lib/output.js +23 -23
  83. package/scripts/audit-tools/migration-checker.js +392 -392
  84. package/scripts/audit-tools/pentest-scanner.js +1436 -1436
  85. package/scripts/benchmark-memoria.js +167 -167
  86. package/scripts/configurar-branch-protection.js +418 -418
  87. package/scripts/derivar-feature-list.js +489 -0
  88. package/scripts/detectar-aprendizajes-duplicados.js +151 -151
  89. package/scripts/doctor.js +31 -4
  90. package/scripts/field-report.js +199 -199
  91. package/scripts/generar-checklists-consolidados.js +273 -273
  92. package/scripts/generar-inventario.js +420 -420
  93. package/scripts/generar-matriz-lenguajes.js +271 -271
  94. package/scripts/instalador.js +56 -5
  95. package/scripts/lib/artefactos-python.js +43 -43
  96. package/scripts/lib/benchmark-metrics.js +160 -160
  97. package/scripts/lib/budget-enforcer.js +252 -252
  98. package/scripts/lib/configurar-ci.js +380 -380
  99. package/scripts/lib/contadores-inventario.js +217 -217
  100. package/scripts/lib/detectar-runtime.js +75 -9
  101. package/scripts/lib/detectar-stack-detallado.js +307 -307
  102. package/scripts/lib/diary-entry.js +234 -234
  103. package/scripts/lib/estado.js +13 -1
  104. package/scripts/lib/eval-metrics-store.js +218 -218
  105. package/scripts/lib/eval-quality.js +171 -171
  106. package/scripts/lib/eval-schemas.js +144 -144
  107. package/scripts/lib/eval-self-correct.js +106 -106
  108. package/scripts/lib/eval-validator.js +185 -185
  109. package/scripts/lib/expandir-targets.js +71 -0
  110. package/scripts/lib/jaccard-similarity.js +98 -98
  111. package/scripts/lib/longmemeval-runner.js +125 -125
  112. package/scripts/lib/manifiestos.js +42 -1
  113. package/scripts/lib/npm-version.js +261 -261
  114. package/scripts/lib/paquetes-conocidos.js +50 -50
  115. package/scripts/lib/parsear-opciones.js +3 -0
  116. package/scripts/lib/prompt-builder.js +264 -264
  117. package/scripts/lib/rrf-fusion.js +175 -175
  118. package/scripts/lib/scoring-instintos.js +277 -277
  119. package/scripts/lib/semantic-search.js +252 -252
  120. package/scripts/lib/toml-merge.js +204 -0
  121. package/scripts/lib/transformadores/base.js +43 -9
  122. package/scripts/lib/transformadores/codex.js +375 -115
  123. package/scripts/lib/transformadores/cursor.js +359 -0
  124. package/scripts/lib/transformadores/index.js +2 -0
  125. package/scripts/limpiar-artefactos-python.js +131 -131
  126. package/scripts/mcp-server/README.md +122 -80
  127. package/scripts/mcp-server/auth.js +105 -0
  128. package/scripts/mcp-server/cache.js +106 -0
  129. package/scripts/mcp-server/handlers.js +386 -206
  130. package/scripts/mcp-server/telemetry.js +78 -0
  131. package/scripts/migrar-csv-a-array.js +168 -168
  132. package/scripts/migrar-fase-dominio.js +201 -201
  133. package/scripts/publicar.js +511 -511
  134. package/scripts/run-eval.js +141 -141
  135. package/scripts/validar-manifest.js +231 -195
  136. package/scripts/validar-userland-vacio.js +110 -110
@@ -1,195 +1,231 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- /**
5
- * Gate de sincronización manifiestos ↔ disco.
6
- *
7
- * Verifica que cada archivo de componente presente en disco esté declarado
8
- * en manifiestos/modulos.json (fuente de verdad del instalador). Atrapa el
9
- * bug recurrente "archivo existe en el repo pero el instalador no lo copia
10
- * al destino" que causó v5.7.3 (check-update.js) y v5.7.4 (adoptar-proyecto.md,
11
- * contribuir.md).
12
- *
13
- * Convenciones del manifest (validadas vs disco):
14
- * agentes/X.md → declarado como 'agentes/X.md'
15
- * comandos/swl/X.md → declarado como 'comandos/swl/X.md'
16
- * habilidades/X/SKILL.md → declarado como 'habilidades/X' (solo el dir)
17
- * hooks/X.js (ejecutable) → declarado como 'hooks/X.js' + hooks-config.json
18
- * reglas/**.md → declarado como 'reglas/<path>.md'
19
- * schemas/X.json → declarado como 'schemas/X.json'
20
- *
21
- * Exclusiones intencionales:
22
- * hooks/lib/ — helpers internos; se declaran solo las libs que un hook
23
- * copiado necesita en su módulo. No van 1:1 con disco.
24
- * scripts/ — herramientas de desarrollo, no componentes distribuibles.
25
- * schemas/ — definiciones JSON Schema para validación interna del repo;
26
- * no se copian al destino (los runtimes no las leen).
27
- *
28
- * Exit codes: 0 OK, 1 faltan declaraciones.
29
- *
30
- * Uso: node scripts/validar-manifest.js [--json]
31
- */
32
-
33
- const fs = require('fs');
34
- const path = require('path');
35
-
36
- const RAIZ = path.resolve(__dirname, '..');
37
- const MODULOS_PATH = path.join(RAIZ, 'manifiestos', 'modulos.json');
38
- const HOOKS_CONFIG_PATH = path.join(RAIZ, 'manifiestos', 'hooks-config.json');
39
-
40
- const salidaJson = process.argv.includes('--json');
41
- const errores = [];
42
-
43
- function log(msg) { if (!salidaJson) console.log(msg); }
44
-
45
- function recolectarDeclarados(modulos) {
46
- const declarados = new Set();
47
- for (const mod of Object.values(modulos.modulos || {})) {
48
- for (const archivo of mod.archivos || []) {
49
- declarados.add(archivo);
50
- }
51
- }
52
- return declarados;
53
- }
54
-
55
- function listarArchivos(dirRel, extension, recursivo = false) {
56
- const base = path.join(RAIZ, dirRel);
57
- if (!fs.existsSync(base)) return [];
58
- const resultado = [];
59
- function caminar(actual) {
60
- for (const entrada of fs.readdirSync(actual, { withFileTypes: true })) {
61
- const abs = path.join(actual, entrada.name);
62
- if (entrada.isDirectory() && recursivo) {
63
- caminar(abs);
64
- } else if (entrada.isFile() && entrada.name.endsWith(extension)) {
65
- resultado.push(path.relative(RAIZ, abs).replace(/\\/g, '/'));
66
- }
67
- }
68
- }
69
- caminar(base);
70
- return resultado;
71
- }
72
-
73
- function listarDirectoriosHabilidades() {
74
- const base = path.join(RAIZ, 'habilidades');
75
- if (!fs.existsSync(base)) return [];
76
- const dirs = [];
77
- for (const entrada of fs.readdirSync(base, { withFileTypes: true })) {
78
- if (!entrada.isDirectory()) continue;
79
- // Solo directorios que tienen SKILL.md son habilidades válidas
80
- if (fs.existsSync(path.join(base, entrada.name, 'SKILL.md'))) {
81
- dirs.push(`habilidades/${entrada.name}`);
82
- }
83
- }
84
- return dirs;
85
- }
86
-
87
- function verificarCategoria(etiqueta, archivosDisco, declarados) {
88
- const faltantes = archivosDisco.filter(a => !declarados.has(a));
89
- if (faltantes.length === 0) {
90
- log(` [OK] ${etiqueta}: ${archivosDisco.length}/${archivosDisco.length} declarados`);
91
- return true;
92
- }
93
- log(` [FALLA] ${etiqueta}: ${faltantes.length} sin declarar en modulos.json`);
94
- for (const f of faltantes) {
95
- log(` → ${f}`);
96
- errores.push({ categoria: etiqueta, archivo: f, tipo: 'no_declarado_modulos' });
97
- }
98
- return false;
99
- }
100
-
101
- function verificarHooksEjecutablesEnConfig(archivosHooks, hooksConfig) {
102
- // hooks-config.json tiene la estructura { hooks: { "nombre.js": { event, matcher, ... } } }
103
- const hooks = hooksConfig.hooks || hooksConfig;
104
- const declaradosConfig = new Set(Object.keys(hooks));
105
- const faltantes = archivosHooks.filter(a => {
106
- const nombre = path.basename(a);
107
- return !declaradosConfig.has(nombre);
108
- });
109
- if (faltantes.length === 0) {
110
- log(` [OK] hooks-config.json: ${archivosHooks.length}/${archivosHooks.length} hooks ejecutables registrados`);
111
- return true;
112
- }
113
- log(` [FALLA] hooks-config.json: ${faltantes.length} hook(s) sin declarar`);
114
- for (const f of faltantes) {
115
- log(` → ${f}`);
116
- errores.push({ categoria: 'hooks-config.json', archivo: f, tipo: 'no_declarado_hooks_config' });
117
- }
118
- return false;
119
- }
120
-
121
- function verificarDeclarados1a1ExistenEnDisco(declarados) {
122
- // Caso inverso: declarados en manifest pero no presentes en disco
123
- const rotos = [];
124
- for (const decl of declarados) {
125
- // Habilidades son directorios
126
- if (decl.startsWith('habilidades/') && !decl.includes('/SKILL.md')) {
127
- const absDir = path.join(RAIZ, decl);
128
- const skillMd = path.join(absDir, 'SKILL.md');
129
- if (!fs.existsSync(skillMd)) rotos.push(decl);
130
- continue;
131
- }
132
- const abs = path.join(RAIZ, decl);
133
- if (!fs.existsSync(abs)) rotos.push(decl);
134
- }
135
- if (rotos.length === 0) {
136
- log(` [OK] Referencias en modulos.json: ${declarados.size}/${declarados.size} existen en disco`);
137
- return true;
138
- }
139
- log(` [FALLA] modulos.json: ${rotos.length} ruta(s) rotas (declaradas pero no existen)`);
140
- for (const r of rotos) {
141
- log(` ${r}`);
142
- errores.push({ categoria: 'modulos.json', archivo: r, tipo: 'declarado_no_existe' });
143
- }
144
- return false;
145
- }
146
-
147
- function main() {
148
- log('Validación de sincronización manifiestos ↔ disco\n');
149
-
150
- const modulos = JSON.parse(fs.readFileSync(MODULOS_PATH, 'utf-8'));
151
- const hooksConfig = JSON.parse(fs.readFileSync(HOOKS_CONFIG_PATH, 'utf-8'));
152
- const declarados = recolectarDeclarados(modulos);
153
-
154
- const hooksEjecutables = listarArchivos('hooks', '.js').filter(a => !a.startsWith('hooks/lib/'));
155
-
156
- const categorias = [
157
- { etiqueta: 'comandos/swl/', archivos: listarArchivos('comandos/swl', '.md') },
158
- { etiqueta: 'hooks/ (ejecutables)', archivos: hooksEjecutables },
159
- { etiqueta: 'agentes/', archivos: listarArchivos('agentes', '.md') },
160
- { etiqueta: 'habilidades/ (dirs)', archivos: listarDirectoriosHabilidades() },
161
- { etiqueta: 'reglas/', archivos: listarArchivos('reglas', '.md', true) },
162
- ];
163
-
164
- let todoOk = true;
165
- for (const cat of categorias) {
166
- const ok = verificarCategoria(cat.etiqueta, cat.archivos, declarados);
167
- if (!ok) todoOk = false;
168
- }
169
-
170
- const hooksOk = verificarHooksEjecutablesEnConfig(hooksEjecutables, hooksConfig);
171
- if (!hooksOk) todoOk = false;
172
-
173
- const inversoOk = verificarDeclarados1a1ExistenEnDisco(declarados);
174
- if (!inversoOk) todoOk = false;
175
-
176
- log('');
177
- if (todoOk) {
178
- log('✓ Todos los manifiestos están sincronizados con el disco.');
179
- } else {
180
- log(`✗ ${errores.length} problema(s) de sincronización.`);
181
- log('');
182
- log(' Cómo corregir:');
183
- log(' - "no_declarado_modulos": agregar la ruta al módulo apropiado en manifiestos/modulos.json');
184
- log(' - "no_declarado_hooks_config": registrar el hook en manifiestos/hooks-config.json');
185
- log(' - "declarado_no_existe": eliminar la ruta de modulos.json (archivo borrado) o crear el archivo');
186
- }
187
-
188
- if (salidaJson) {
189
- console.log(JSON.stringify({ ok: todoOk, totalErrores: errores.length, errores }, null, 2));
190
- }
191
-
192
- process.exit(todoOk ? 0 : 1);
193
- }
194
-
195
- main();
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ /**
5
+ * Gate de sincronización manifiestos ↔ disco.
6
+ *
7
+ * Verifica que cada archivo de componente presente en disco esté declarado
8
+ * en manifiestos/modulos.json (fuente de verdad del instalador). Atrapa el
9
+ * bug recurrente "archivo existe en el repo pero el instalador no lo copia
10
+ * al destino" que causó v5.7.3 (check-update.js) y v5.7.4 (adoptar-proyecto.md,
11
+ * contribuir.md).
12
+ *
13
+ * Convenciones del manifest (validadas vs disco):
14
+ * agentes/X.md → declarado como 'agentes/X.md'
15
+ * comandos/swl/X.md → declarado como 'comandos/swl/X.md'
16
+ * habilidades/X/SKILL.md → declarado como 'habilidades/X' (solo el dir)
17
+ * hooks/X.js (ejecutable) → declarado como 'hooks/X.js' + hooks-config.json
18
+ * reglas/**.md → declarado como 'reglas/<path>.md'
19
+ * schemas/X.json → declarado como 'schemas/X.json'
20
+ *
21
+ * Exclusiones intencionales:
22
+ * hooks/lib/ — helpers internos; se declaran solo las libs que un hook
23
+ * copiado necesita en su módulo. No van 1:1 con disco.
24
+ * scripts/ — herramientas de desarrollo, no componentes distribuibles.
25
+ * schemas/ — definiciones JSON Schema para validación interna del repo;
26
+ * no se copian al destino (los runtimes no las leen).
27
+ *
28
+ * Exit codes: 0 OK, 1 faltan declaraciones.
29
+ *
30
+ * Uso: node scripts/validar-manifest.js [--json]
31
+ */
32
+
33
+ const fs = require('fs');
34
+ const path = require('path');
35
+
36
+ const RAIZ = path.resolve(__dirname, '..');
37
+ const MODULOS_PATH = path.join(RAIZ, 'manifiestos', 'modulos.json');
38
+ const HOOKS_CONFIG_PATH = path.join(RAIZ, 'manifiestos', 'hooks-config.json');
39
+ const PERFILES_PATH = path.join(RAIZ, 'manifiestos', 'perfiles.json');
40
+
41
+ const salidaJson = process.argv.includes('--json');
42
+ const errores = [];
43
+
44
+ function log(msg) { if (!salidaJson) console.log(msg); }
45
+
46
+ function recolectarDeclarados(modulos) {
47
+ const declarados = new Set();
48
+ for (const mod of Object.values(modulos.modulos || {})) {
49
+ for (const archivo of mod.archivos || []) {
50
+ declarados.add(archivo);
51
+ }
52
+ }
53
+ return declarados;
54
+ }
55
+
56
+ function listarArchivos(dirRel, extension, recursivo = false) {
57
+ const base = path.join(RAIZ, dirRel);
58
+ if (!fs.existsSync(base)) return [];
59
+ const resultado = [];
60
+ function caminar(actual) {
61
+ for (const entrada of fs.readdirSync(actual, { withFileTypes: true })) {
62
+ const abs = path.join(actual, entrada.name);
63
+ if (entrada.isDirectory() && recursivo) {
64
+ caminar(abs);
65
+ } else if (entrada.isFile() && entrada.name.endsWith(extension)) {
66
+ resultado.push(path.relative(RAIZ, abs).replace(/\\/g, '/'));
67
+ }
68
+ }
69
+ }
70
+ caminar(base);
71
+ return resultado;
72
+ }
73
+
74
+ function listarDirectoriosHabilidades() {
75
+ const base = path.join(RAIZ, 'habilidades');
76
+ if (!fs.existsSync(base)) return [];
77
+ const dirs = [];
78
+ for (const entrada of fs.readdirSync(base, { withFileTypes: true })) {
79
+ if (!entrada.isDirectory()) continue;
80
+ // Solo directorios que tienen SKILL.md son habilidades válidas
81
+ if (fs.existsSync(path.join(base, entrada.name, 'SKILL.md'))) {
82
+ dirs.push(`habilidades/${entrada.name}`);
83
+ }
84
+ }
85
+ return dirs;
86
+ }
87
+
88
+ function verificarCategoria(etiqueta, archivosDisco, declarados) {
89
+ const faltantes = archivosDisco.filter(a => !declarados.has(a));
90
+ if (faltantes.length === 0) {
91
+ log(` [OK] ${etiqueta}: ${archivosDisco.length}/${archivosDisco.length} declarados`);
92
+ return true;
93
+ }
94
+ log(` [FALLA] ${etiqueta}: ${faltantes.length} sin declarar en modulos.json`);
95
+ for (const f of faltantes) {
96
+ log(` → ${f}`);
97
+ errores.push({ categoria: etiqueta, archivo: f, tipo: 'no_declarado_modulos' });
98
+ }
99
+ return false;
100
+ }
101
+
102
+ function verificarHooksEjecutablesEnConfig(archivosHooks, hooksConfig) {
103
+ // hooks-config.json tiene la estructura { hooks: { "nombre.js": { event, matcher, ... } } }
104
+ const hooks = hooksConfig.hooks || hooksConfig;
105
+ const declaradosConfig = new Set(Object.keys(hooks));
106
+ const faltantes = archivosHooks.filter(a => {
107
+ const nombre = path.basename(a);
108
+ return !declaradosConfig.has(nombre);
109
+ });
110
+ if (faltantes.length === 0) {
111
+ log(` [OK] hooks-config.json: ${archivosHooks.length}/${archivosHooks.length} hooks ejecutables registrados`);
112
+ return true;
113
+ }
114
+ log(` [FALLA] hooks-config.json: ${faltantes.length} hook(s) sin declarar`);
115
+ for (const f of faltantes) {
116
+ log(` → ${f}`);
117
+ errores.push({ categoria: 'hooks-config.json', archivo: f, tipo: 'no_declarado_hooks_config' });
118
+ }
119
+ return false;
120
+ }
121
+
122
+ function verificarModulosReferenciadosPorPerfil(modulos, perfiles) {
123
+ // Cada módulo declarado en modulos.json DEBE estar referenciado por al menos un perfil
124
+ // O marcado explícitamente como `opt_in: true` (feature opcional, no incluida en perfiles).
125
+ // De lo contrario, el instalador nunca copia sus archivos al destino aunque viajen en el tarball.
126
+ // Bug histórico: v1.4.1 publicó 'auditoria-profunda' (Opción C) pero quedó huérfano del perfil
127
+ // 'completo' los 16 archivos del módulo viajaban en el tarball pero el instalador los ignoraba.
128
+ // Solución: agregar al perfil. Para opt-in declarativo: campo `opt_in: true` en el módulo.
129
+ const todosLosModulos = modulos.modulos || {};
130
+ const referenciados = new Set();
131
+ for (const perfil of Object.values(perfiles.perfiles || {})) {
132
+ for (const modId of perfil.modulos || []) {
133
+ referenciados.add(modId);
134
+ }
135
+ }
136
+ const huerfanos = Object.entries(todosLosModulos)
137
+ .filter(([id, mod]) => !referenciados.has(id) && !mod.opt_in)
138
+ .map(([id]) => id);
139
+ const declarados = Object.keys(todosLosModulos);
140
+ if (huerfanos.length === 0) {
141
+ log(` [OK] perfiles.json: ${declarados.length}/${declarados.length} módulos referenciados por algún perfil`);
142
+ return true;
143
+ }
144
+ log(` [FALLA] perfiles.json: ${huerfanos.length} módulo(s) huérfano(s) (declarados en modulos.json pero sin perfil)`);
145
+ for (const h of huerfanos) {
146
+ log(` → ${h}`);
147
+ errores.push({ categoria: 'perfiles.json', archivo: h, tipo: 'modulo_huerfano_sin_perfil' });
148
+ }
149
+ return false;
150
+ }
151
+
152
+ function verificarDeclarados1a1ExistenEnDisco(declarados) {
153
+ // Caso inverso: declarados en manifest pero no presentes en disco
154
+ const rotos = [];
155
+ for (const decl of declarados) {
156
+ // Habilidades son directorios
157
+ if (decl.startsWith('habilidades/') && !decl.includes('/SKILL.md')) {
158
+ const absDir = path.join(RAIZ, decl);
159
+ const skillMd = path.join(absDir, 'SKILL.md');
160
+ if (!fs.existsSync(skillMd)) rotos.push(decl);
161
+ continue;
162
+ }
163
+ const abs = path.join(RAIZ, decl);
164
+ if (!fs.existsSync(abs)) rotos.push(decl);
165
+ }
166
+ if (rotos.length === 0) {
167
+ log(` [OK] Referencias en modulos.json: ${declarados.size}/${declarados.size} existen en disco`);
168
+ return true;
169
+ }
170
+ log(` [FALLA] modulos.json: ${rotos.length} ruta(s) rotas (declaradas pero no existen)`);
171
+ for (const r of rotos) {
172
+ log(` → ${r}`);
173
+ errores.push({ categoria: 'modulos.json', archivo: r, tipo: 'declarado_no_existe' });
174
+ }
175
+ return false;
176
+ }
177
+
178
+ function main() {
179
+ log('Validación de sincronización manifiestos ↔ disco\n');
180
+
181
+ const modulos = JSON.parse(fs.readFileSync(MODULOS_PATH, 'utf-8'));
182
+ const hooksConfig = JSON.parse(fs.readFileSync(HOOKS_CONFIG_PATH, 'utf-8'));
183
+ const perfiles = JSON.parse(fs.readFileSync(PERFILES_PATH, 'utf-8'));
184
+ const declarados = recolectarDeclarados(modulos);
185
+
186
+ const hooksEjecutables = listarArchivos('hooks', '.js').filter(a => !a.startsWith('hooks/lib/'));
187
+
188
+ const categorias = [
189
+ { etiqueta: 'comandos/swl/', archivos: listarArchivos('comandos/swl', '.md') },
190
+ { etiqueta: 'hooks/ (ejecutables)', archivos: hooksEjecutables },
191
+ { etiqueta: 'agentes/', archivos: listarArchivos('agentes', '.md') },
192
+ { etiqueta: 'habilidades/ (dirs)', archivos: listarDirectoriosHabilidades() },
193
+ { etiqueta: 'reglas/', archivos: listarArchivos('reglas', '.md', true) },
194
+ ];
195
+
196
+ let todoOk = true;
197
+ for (const cat of categorias) {
198
+ const ok = verificarCategoria(cat.etiqueta, cat.archivos, declarados);
199
+ if (!ok) todoOk = false;
200
+ }
201
+
202
+ const hooksOk = verificarHooksEjecutablesEnConfig(hooksEjecutables, hooksConfig);
203
+ if (!hooksOk) todoOk = false;
204
+
205
+ const perfilOk = verificarModulosReferenciadosPorPerfil(modulos, perfiles);
206
+ if (!perfilOk) todoOk = false;
207
+
208
+ const inversoOk = verificarDeclarados1a1ExistenEnDisco(declarados);
209
+ if (!inversoOk) todoOk = false;
210
+
211
+ log('');
212
+ if (todoOk) {
213
+ log('✓ Todos los manifiestos están sincronizados con el disco.');
214
+ } else {
215
+ log(`✗ ${errores.length} problema(s) de sincronización.`);
216
+ log('');
217
+ log(' Cómo corregir:');
218
+ log(' - "no_declarado_modulos": agregar la ruta al módulo apropiado en manifiestos/modulos.json');
219
+ log(' - "no_declarado_hooks_config": registrar el hook en manifiestos/hooks-config.json');
220
+ log(' - "modulo_huerfano_sin_perfil": agregar el módulo al array `modulos` de al menos un perfil en manifiestos/perfiles.json');
221
+ log(' - "declarado_no_existe": eliminar la ruta de modulos.json (archivo borrado) o crear el archivo');
222
+ }
223
+
224
+ if (salidaJson) {
225
+ console.log(JSON.stringify({ ok: todoOk, totalErrores: errores.length, errores }, null, 2));
226
+ }
227
+
228
+ process.exit(todoOk ? 0 : 1);
229
+ }
230
+
231
+ main();