@saulwade/swl-ses 1.9.0 → 2.1.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 +196 -196
- package/README.md +579 -579
- package/agentes/_propose-step.md +90 -0
- package/agentes/accesibilidad-wcag-swl.md +3 -3
- package/agentes/auto-evolucion-swl.md +908 -908
- package/agentes/disenador-ui-swl.md +6 -5
- package/agentes/frontend-angular-swl.md +2 -2
- package/agentes/frontend-css-swl.md +2 -2
- package/agentes/frontend-react-swl.md +4 -4
- package/agentes/frontend-swl.md +6 -6
- package/agentes/implementador-swl.md +2 -0
- package/agentes/investigador-ux-swl.md +5 -5
- package/agentes/orquestador-swl.md +9 -7
- package/agentes/perfilador-usuario-swl.md +321 -308
- package/agentes/producto-prd-swl.md +1 -1
- package/agentes/red-team-swl.md +218 -218
- package/agentes/tdd-qa-swl.md +17 -1
- package/bin/swl-ses.js +1 -1
- package/comandos/swl/actualizar.md +1 -1
- package/comandos/swl/aprender.md +2 -2
- package/comandos/swl/aprobar-plan.md +153 -0
- package/comandos/swl/ayuda.md +3 -3
- package/comandos/swl/briefing.md +122 -0
- package/comandos/swl/compactar.md +29 -2
- package/comandos/swl/discutir-fase.md +23 -2
- package/comandos/swl/ejecutar-fase.md +59 -6
- package/comandos/swl/evolucionar.md +1 -1
- package/comandos/swl/inbox.md +1 -1
- package/comandos/swl/instalar.md +1 -1
- package/comandos/swl/nemesis.md +1 -1
- package/comandos/swl/planear-fase.md +19 -1
- package/comandos/swl/plugins.md +1 -1
- package/comandos/swl/release.md +47 -1
- package/comandos/swl/status.md +348 -0
- package/comandos/swl/verificar.md +27 -1
- package/habilidades/ai-runtime-security/SKILL.md +1 -1
- package/habilidades/auto-evolucion-protocolo/SKILL.md +276 -276
- package/habilidades/benchmark-memoria/SKILL.md +1 -1
- package/habilidades/calidad-contract-testing/SKILL.md +165 -0
- package/habilidades/changelog-generator/SKILL.md +9 -2
- package/habilidades/changelog-generator/scripts/parse-commits.js +13 -1
- package/habilidades/diagrama-arquitectura/SKILL.md +1 -1
- package/habilidades/drift-detection/SKILL.md +179 -179
- package/habilidades/ejecutar-fase/SKILL.md +541 -468
- package/habilidades/estructura-proyecto-claude/SKILL.md +17 -14
- package/habilidades/estructura-proyecto-claude/recursos/configuracion-y-extensiones.md +34 -23
- package/habilidades/estructura-proyecto-claude/recursos/frontmatter-y-hooks-referencia.md +70 -53
- package/habilidades/estructura-proyecto-claude/recursos/mcp-json-template.json +57 -77
- package/habilidades/extractor-de-aprendizajes/SKILL.md +9 -5
- package/habilidades/harness-claude-code/SKILL.md +10 -7
- package/{reglas/harness-claude-code.md → habilidades/harness-claude-code/recursos/disciplina-harness-regla.md} +2 -2
- package/habilidades/instalar-sistema/SKILL.md +3 -3
- package/habilidades/meta-skills-estandar/recursos/frameworks-seguridad.md +1 -1
- package/habilidades/perfil-usuario/SKILL.md +200 -200
- package/habilidades/planear-fase/SKILL.md +26 -4
- package/habilidades/proceso-ddia-fundamentos/SKILL.md +1 -1
- package/habilidades/proceso-ddia-streaming/SKILL.md +4 -4
- package/habilidades/proceso-debate-adversarial/SKILL.md +2 -2
- package/habilidades/protocolo-revision-swl/SKILL.md +1 -1
- package/habilidades/seguridad-skills-ia/SKILL.md +1 -1
- package/habilidades/swl-claudemd/SKILL.md +50 -210
- package/habilidades/swl-claudemd/recursos/contrato-aprender.md +83 -0
- package/habilidades/swl-claudemd/recursos/duplicacion-reglas-globales.md +85 -0
- package/habilidades/swl-claudemd/recursos/plantillas-init.md +94 -0
- package/habilidades/swl-dashboard/SKILL.md +9 -9
- package/habilidades/swl-revisar-impacto/SKILL.md +1 -1
- package/habilidades/tdd-workflow/SKILL.md +715 -673
- package/habilidades/validacion-ci-sistema/SKILL.md +20 -4
- package/hooks/calidad-pre-commit.js +344 -3
- package/hooks/check-update.js +39 -1
- package/hooks/ciclo-evolucion-subagente.js +26 -0
- package/hooks/ciclo-evolucion.js +26 -0
- package/hooks/extraccion-aprendizajes.js +13 -0
- package/hooks/lib/autonomia.js +208 -0
- package/hooks/lib/briefing.js +474 -0
- package/hooks/lib/ciclo-evolucion.js +47 -0
- package/hooks/{auto-evolucion.js → lib/etapa-auto-evolucion.js} +701 -700
- package/hooks/{metricas-evolucion.js → lib/etapa-metricas.js} +388 -376
- package/hooks/{actualizar-perfil-usuario.js → lib/etapa-perfil-usuario.js} +376 -364
- package/hooks/lib/evolution-tracker.js +24 -3
- package/hooks/lib/propose-step.js +357 -0
- package/hooks/session-briefing.js +98 -0
- package/hooks/spec-gate.js +211 -0
- package/hooks/tdd-gate.js +241 -0
- package/hooks/telemetria-skill-routing.js +100 -0
- package/hooks/validar-intent-spec.js +30 -10
- package/instintos/autonomia.yaml +27 -0
- package/llms.txt +6 -6
- package/manifiestos/hooks-config.json +44 -17
- package/manifiestos/modulos.json +40 -15
- package/manifiestos/skills-lock.json +64 -57
- package/package.json +93 -93
- package/plugin.json +371 -375
- package/reglas/accesibilidad.md +10 -0
- package/reglas/analizar-directorios-antes-de-escribir.md +228 -0
- package/reglas/api-diseno.md +9 -0
- package/reglas/auditorias-documentales-estructurales.md +7 -0
- package/reglas/cloud-infra.md +8 -0
- package/reglas/consultar-vault-primero.md +195 -0
- package/reglas/debatir-antes-de-aceptar.md +158 -0
- package/reglas/fragmentos-compartidos.md +5 -0
- package/reglas/git-coauthor.md +100 -0
- package/reglas/gobernanza.md +4 -4
- package/reglas/hooks.md +6 -0
- package/reglas/intent-engineering.md +4 -0
- package/reglas/markitdown.md +8 -0
- package/reglas/memoria-consolidada.md +1 -1
- package/reglas/monitor-ci.md +309 -0
- package/reglas/patrones.md +6 -0
- package/reglas/registro-componentes-nuevos.md +39 -2
- package/reglas/seguridad-agentes.md +1 -1
- package/reglas/sesiones-paralelas.md +180 -0
- package/reglas/skills-estandar.md +6 -0
- package/reglas/testing.md +7 -0
- package/reglas/tests-cleanup.md +4 -0
- package/reglas/usar-code-review-graph.md +155 -0
- package/reglas/usar-sistema-swl.md +1 -1
- package/reglas/verificar-citas-normativas.md +548 -0
- package/scripts/instalador.js +52 -6
- package/scripts/lib/ci-reader.js +193 -0
- package/scripts/lib/detectar-host-swl.js +175 -0
- package/scripts/lib/evidencia-release.js +322 -0
- package/scripts/lib/gate-hooks-requires.js +249 -0
- package/scripts/lib/gate-licencias.js +212 -0
- package/scripts/lib/git-metricas.js +257 -0
- package/scripts/lib/gitignore-manifest.js +29 -1
- package/scripts/lib/metricas-dora.js +204 -0
- package/scripts/lib/plan-lock.js +275 -0
- package/scripts/migrar-fase-dominio.js +0 -1
- package/scripts/tui/ejecutores.js +1 -1
- package/scripts/validar-manifest.js +92 -1
- package/scripts/verificar-evolucion.js +54 -4
- package/scripts/verificar-release.js +102 -0
- package/scripts/verificar-trazabilidad.js +298 -0
- package/agentes/ux-disenador-swl.md +0 -503
- package/comandos/swl/dashboard.md +0 -146
- package/comandos/swl/evolucion-estado.md +0 -191
- package/comandos/swl/metricas.md +0 -376
- package/comandos/swl/salud.md +0 -481
- package/reglas/arquitectura.evolved.json +0 -7
- package/reglas/seguridad.evolved.json +0 -7
- package/reglas/verificar-citas-temporales.md +0 -139
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* gate-hooks-requires.js
|
|
5
|
+
*
|
|
6
|
+
* Gate de release: cruza los `require()` relativos de los hooks DISTRIBUIDOS
|
|
7
|
+
* (`hooks/**` registrados en `manifiestos/modulos.json`) que apuntan a
|
|
8
|
+
* `scripts/**`, y verifica que cada lib objetivo — incluidas sus dependencias
|
|
9
|
+
* TRANSITIVAS — esté registrada en `modulos.json` y cubierta en todos los
|
|
10
|
+
* perfiles que instalan el hook.
|
|
11
|
+
*
|
|
12
|
+
* Cierra la clase de bug del caso check-update (2026-06-12): el hook requería
|
|
13
|
+
* `scripts/lib/npm-version.js` (que a su vez requería `paquetes-conocidos.js`),
|
|
14
|
+
* ninguna estaba en módulo alguno, y el wrapper de settings.json traga
|
|
15
|
+
* MODULE_NOT_FOUND → el hook murió en silencio en TODA instalación destino
|
|
16
|
+
* desde su creación. Misma familia que `ejecutarGateBinImports` (bin/ vs
|
|
17
|
+
* `package.json#files`), en el eje instalador→destino.
|
|
18
|
+
*
|
|
19
|
+
* Hallazgos (todos bloqueantes — un hook distribuido con dependencia rota es
|
|
20
|
+
* un artefacto roto para el usuario del paquete):
|
|
21
|
+
* - `lib-inexistente`: el require apunta a un archivo que no existe en repo.
|
|
22
|
+
* - `no-registrada`: la lib existe pero no está en ningún módulo.
|
|
23
|
+
* - `sin-cobertura`: la lib está en módulo(s), pero algún perfil instala
|
|
24
|
+
* el módulo del hook sin ningún módulo de la lib.
|
|
25
|
+
*
|
|
26
|
+
* Los hooks NO registrados en modulos.json se ignoran: no se distribuyen, su
|
|
27
|
+
* require solo corre en el repo madre donde scripts/ existe completo.
|
|
28
|
+
*
|
|
29
|
+
* Funciones puras zero-deps + entrypoint CLI `--json`.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
const fs = require('node:fs');
|
|
33
|
+
const path = require('node:path');
|
|
34
|
+
|
|
35
|
+
const RE_REQUIRE_RELATIVO = /require\(\s*['"](\.\.?\/[^'"]+)['"]\s*\)/g;
|
|
36
|
+
const MAX_PROFUNDIDAD_TRANSITIVA = 10;
|
|
37
|
+
|
|
38
|
+
/** Extrae las rutas de los require() relativos de un código fuente. */
|
|
39
|
+
function extraerRequiresRelativos(codigo) {
|
|
40
|
+
const out = [];
|
|
41
|
+
let m;
|
|
42
|
+
RE_REQUIRE_RELATIVO.lastIndex = 0;
|
|
43
|
+
while ((m = RE_REQUIRE_RELATIVO.exec(codigo)) !== null) out.push(m[1]);
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Resuelve un require relativo desde un archivo (ruta repo-relativa posix) a
|
|
49
|
+
* una ruta repo-relativa del objetivo, restringida a `scripts/`.
|
|
50
|
+
* @returns {string|null} 'scripts/lib/x.js' o null si no cae en scripts/.
|
|
51
|
+
*/
|
|
52
|
+
function resolverObjetivoScripts(archivoRel, requireRel, baseDir) {
|
|
53
|
+
const dir = path.posix.dirname(archivoRel.split(path.sep).join('/'));
|
|
54
|
+
let objetivo = path.posix.normalize(path.posix.join(dir, requireRel));
|
|
55
|
+
if (!objetivo.startsWith('scripts/')) return null;
|
|
56
|
+
// Resolución estilo Node: exacto → +.js → /index.js
|
|
57
|
+
const candidatos = objetivo.endsWith('.js')
|
|
58
|
+
? [objetivo]
|
|
59
|
+
: [objetivo, objetivo + '.js', objetivo + '/index.js'];
|
|
60
|
+
for (const c of candidatos) {
|
|
61
|
+
if (fs.existsSync(path.join(baseDir, c))) return c;
|
|
62
|
+
}
|
|
63
|
+
// No existe: devolver el candidato .js canónico para reportar lib-inexistente.
|
|
64
|
+
return objetivo.endsWith('.js') ? objetivo : objetivo + '.js';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Expande una lib de scripts/ a su cierre transitivo de requires relativos
|
|
69
|
+
* que permanezcan dentro de scripts/.
|
|
70
|
+
* @returns {string[]} rutas repo-relativas (incluye la lib raíz).
|
|
71
|
+
*/
|
|
72
|
+
function expandirTransitivas(baseDir, libRel, _vistos, _prof = 0) {
|
|
73
|
+
const vistos = _vistos || new Set();
|
|
74
|
+
if (vistos.has(libRel) || _prof > MAX_PROFUNDIDAD_TRANSITIVA) return [...vistos];
|
|
75
|
+
vistos.add(libRel);
|
|
76
|
+
let codigo = null;
|
|
77
|
+
try {
|
|
78
|
+
codigo = fs.readFileSync(path.join(baseDir, libRel), 'utf8');
|
|
79
|
+
} catch {
|
|
80
|
+
return [...vistos]; // inexistente: se reporta como hallazgo aguas arriba
|
|
81
|
+
}
|
|
82
|
+
for (const req of extraerRequiresRelativos(codigo)) {
|
|
83
|
+
const objetivo = resolverObjetivoScripts(libRel, req, baseDir);
|
|
84
|
+
if (objetivo) expandirTransitivas(baseDir, objetivo, vistos, _prof + 1);
|
|
85
|
+
}
|
|
86
|
+
return [...vistos];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Mapa archivo repo-relativo → array de nombres de módulo que lo declaran. */
|
|
90
|
+
function _mapaArchivoModulos(modulos) {
|
|
91
|
+
const mapa = new Map();
|
|
92
|
+
for (const [nombre, mod] of Object.entries(modulos)) {
|
|
93
|
+
for (const archivo of mod.archivos || []) {
|
|
94
|
+
if (!mapa.has(archivo)) mapa.set(archivo, []);
|
|
95
|
+
mapa.get(archivo).push(nombre);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return mapa;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Lista recursiva de archivos .js bajo hooks/ (repo-relativos posix). */
|
|
102
|
+
function _listarHooks(baseDir) {
|
|
103
|
+
const out = [];
|
|
104
|
+
const raiz = path.join(baseDir, 'hooks');
|
|
105
|
+
function walk(dir, rel) {
|
|
106
|
+
let entradas;
|
|
107
|
+
try {
|
|
108
|
+
entradas = fs.readdirSync(dir, { withFileTypes: true });
|
|
109
|
+
} catch {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
for (const e of entradas) {
|
|
113
|
+
const r = rel ? `${rel}/${e.name}` : e.name;
|
|
114
|
+
if (e.isDirectory()) walk(path.join(dir, e.name), r);
|
|
115
|
+
else if (e.isFile() && e.name.endsWith('.js')) out.push(`hooks/${r}`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
walk(raiz, '');
|
|
119
|
+
return out;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Evalúa los requires hooks→scripts contra modulos.json + perfiles.json.
|
|
124
|
+
* @returns {{disponible:boolean, hooksDistribuidos?:number, dependencias?:Array,
|
|
125
|
+
* hallazgos?:Array, error?:string}}
|
|
126
|
+
*/
|
|
127
|
+
function evaluarHooksRequires(baseDir = process.cwd(), opts = {}) {
|
|
128
|
+
let modulos, perfiles;
|
|
129
|
+
try {
|
|
130
|
+
modulos = (opts.modulos ||
|
|
131
|
+
JSON.parse(fs.readFileSync(path.join(baseDir, 'manifiestos', 'modulos.json'), 'utf8')).modulos);
|
|
132
|
+
const p = opts.perfiles ||
|
|
133
|
+
JSON.parse(fs.readFileSync(path.join(baseDir, 'manifiestos', 'perfiles.json'), 'utf8'));
|
|
134
|
+
perfiles = p.perfiles || p;
|
|
135
|
+
} catch (err) {
|
|
136
|
+
return { disponible: false, error: 'manifiestos ilegibles: ' + err.message };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const mapa = _mapaArchivoModulos(modulos);
|
|
140
|
+
const hooks = _listarHooks(baseDir).filter((h) => mapa.has(h)); // solo distribuidos
|
|
141
|
+
|
|
142
|
+
const dependencias = [];
|
|
143
|
+
const hallazgos = [];
|
|
144
|
+
|
|
145
|
+
for (const hook of hooks) {
|
|
146
|
+
let codigo;
|
|
147
|
+
try {
|
|
148
|
+
codigo = fs.readFileSync(path.join(baseDir, hook), 'utf8');
|
|
149
|
+
} catch {
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
const modulosHook = mapa.get(hook);
|
|
153
|
+
|
|
154
|
+
const objetivosDirectos = new Set();
|
|
155
|
+
for (const req of extraerRequiresRelativos(codigo)) {
|
|
156
|
+
const objetivo = resolverObjetivoScripts(hook, req, baseDir);
|
|
157
|
+
if (objetivo) objetivosDirectos.add(objetivo);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Cierre transitivo de cada objetivo directo.
|
|
161
|
+
const objetivos = new Set();
|
|
162
|
+
for (const o of objetivosDirectos) {
|
|
163
|
+
for (const t of expandirTransitivas(baseDir, o)) objetivos.add(t);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
for (const lib of [...objetivos].sort()) {
|
|
167
|
+
const existe = fs.existsSync(path.join(baseDir, lib));
|
|
168
|
+
const modulosLib = mapa.get(lib) || [];
|
|
169
|
+
const dep = { hook, lib, modulosHook, modulosLib, ok: true };
|
|
170
|
+
|
|
171
|
+
if (!existe) {
|
|
172
|
+
dep.ok = false;
|
|
173
|
+
hallazgos.push({
|
|
174
|
+
tipo: 'lib-inexistente',
|
|
175
|
+
hook,
|
|
176
|
+
lib,
|
|
177
|
+
detalle: `${hook} requiere ${lib} pero el archivo no existe en el repo`,
|
|
178
|
+
});
|
|
179
|
+
} else if (modulosLib.length === 0) {
|
|
180
|
+
dep.ok = false;
|
|
181
|
+
hallazgos.push({
|
|
182
|
+
tipo: 'no-registrada',
|
|
183
|
+
hook,
|
|
184
|
+
lib,
|
|
185
|
+
detalle:
|
|
186
|
+
`${hook} (módulo ${modulosHook.join(',')}) requiere ${lib} que NO está ` +
|
|
187
|
+
`en ningún módulo de modulos.json — el hook morirá en silencio en el destino`,
|
|
188
|
+
});
|
|
189
|
+
} else {
|
|
190
|
+
// Cobertura: todo perfil que instala el hook debe instalar la lib.
|
|
191
|
+
const perfilesSinLib = [];
|
|
192
|
+
for (const [nombrePerfil, perfil] of Object.entries(perfiles)) {
|
|
193
|
+
const mods = perfil.modulos || [];
|
|
194
|
+
const instalaHook = modulosHook.some((m) => mods.includes(m));
|
|
195
|
+
const instalaLib = modulosLib.some((m) => mods.includes(m));
|
|
196
|
+
if (instalaHook && !instalaLib) perfilesSinLib.push(nombrePerfil);
|
|
197
|
+
}
|
|
198
|
+
if (perfilesSinLib.length > 0) {
|
|
199
|
+
dep.ok = false;
|
|
200
|
+
dep.perfilesSinLib = perfilesSinLib;
|
|
201
|
+
hallazgos.push({
|
|
202
|
+
tipo: 'sin-cobertura',
|
|
203
|
+
hook,
|
|
204
|
+
lib,
|
|
205
|
+
detalle:
|
|
206
|
+
`${lib} (módulo ${modulosLib.join(',')}) no llega a los perfiles que ` +
|
|
207
|
+
`instalan ${hook}: ${perfilesSinLib.join(', ')}`,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
dependencias.push(dep);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return {
|
|
216
|
+
disponible: true,
|
|
217
|
+
hooksDistribuidos: hooks.length,
|
|
218
|
+
dependencias,
|
|
219
|
+
hallazgos,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
module.exports = {
|
|
224
|
+
evaluarHooksRequires,
|
|
225
|
+
extraerRequiresRelativos,
|
|
226
|
+
resolverObjetivoScripts,
|
|
227
|
+
expandirTransitivas,
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
// Entrypoint CLI: node scripts/lib/gate-hooks-requires.js [--json] [baseDir]
|
|
231
|
+
if (!require.main || require.main === module) {
|
|
232
|
+
const args = process.argv.slice(2);
|
|
233
|
+
const json = args.includes('--json');
|
|
234
|
+
const baseDir = args.find((a) => !a.startsWith('--')) || process.cwd();
|
|
235
|
+
const r = evaluarHooksRequires(baseDir);
|
|
236
|
+
|
|
237
|
+
if (json) {
|
|
238
|
+
process.stdout.write(JSON.stringify(r, null, 2) + '\n');
|
|
239
|
+
} else if (!r.disponible) {
|
|
240
|
+
process.stdout.write(`Gate hooks-requires no disponible: ${r.error}\n`);
|
|
241
|
+
} else {
|
|
242
|
+
process.stdout.write(
|
|
243
|
+
`Hooks distribuidos analizados: ${r.hooksDistribuidos} | ` +
|
|
244
|
+
`dependencias hooks→scripts: ${r.dependencias.length} | hallazgos: ${r.hallazgos.length}\n`
|
|
245
|
+
);
|
|
246
|
+
for (const h of r.hallazgos) process.stdout.write(` [${h.tipo}] ${h.detalle}\n`);
|
|
247
|
+
}
|
|
248
|
+
process.exit(r.disponible && r.hallazgos && r.hallazgos.length > 0 ? 1 : 0);
|
|
249
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* gate-licencias.js — Clasificación de licencias del árbol runtime (Fase 14, ADR-0038).
|
|
5
|
+
*
|
|
6
|
+
* Gate de cadena de suministro: detecta licencias copyleft contaminantes en las
|
|
7
|
+
* dependencias de producción antes de un release. Zero-dependencies — lee
|
|
8
|
+
* `package-lock.json` (v3) y clasifica cada dependencia prod contra listas SPDX.
|
|
9
|
+
*
|
|
10
|
+
* Modo de uso en /swl:release: WARN-ONLY (D-14-02). Reporta hallazgos pero NUNCA
|
|
11
|
+
* bloquea el release en v1 — la promoción a blocking exigiría calibración + ADR
|
|
12
|
+
* posterior (mismo patrón que los gates G0/G2/G3).
|
|
13
|
+
*
|
|
14
|
+
* Clasificación de expresiones SPDX:
|
|
15
|
+
* - OR → el consumidor ELIGE un término → clasifica por el MEJOR (menos restrictivo).
|
|
16
|
+
* - AND → ambos términos APLICAN → clasifica por el PEOR (más restrictivo).
|
|
17
|
+
*
|
|
18
|
+
* Severidad (de menor a mayor restricción): permisiva < débil < fuerte; "desconocida"
|
|
19
|
+
* es categoría propia (metadata ausente o no catalogada), no un error.
|
|
20
|
+
*
|
|
21
|
+
* Origen: Fase 14 — cadena de suministro en release (P4, ADR-0038).
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const fs = require('fs');
|
|
25
|
+
const path = require('path');
|
|
26
|
+
|
|
27
|
+
// Listas SPDX (normalizadas a mayúsculas). El matching es por PREFIJO de la
|
|
28
|
+
// familia para tolerar variantes `-only` / `-or-later` (ej. GPL-3.0-or-later).
|
|
29
|
+
const FAMILIAS_FUERTES = ['GPL', 'AGPL', 'SSPL', 'OSL', 'EUPL', 'CDDL'];
|
|
30
|
+
const FAMILIAS_DEBILES = ['LGPL', 'MPL', 'EPL', 'CPL', 'MS-RL'];
|
|
31
|
+
const PERMISIVAS = new Set([
|
|
32
|
+
'MIT', 'ISC', 'APACHE-2.0', 'APACHE 2.0', 'BSD', 'BSD-2-CLAUSE', 'BSD-3-CLAUSE',
|
|
33
|
+
'0BSD', 'UNLICENSE', 'CC0-1.0', 'WTFPL', 'BLUEOAK-1.0.0', 'ZLIB', 'PYTHON-2.0',
|
|
34
|
+
'APACHE-2.0 WITH LLVM-EXCEPTION',
|
|
35
|
+
]);
|
|
36
|
+
|
|
37
|
+
// Orden de severidad para resolver expresiones OR/AND. NOTA: `desconocida: 0`
|
|
38
|
+
// NO es un grado ordinal de copyleft — es categoría especial. En `clasificarExprOr`
|
|
39
|
+
// las "desconocidas" se filtran ANTES del reduce cuando hay algún término
|
|
40
|
+
// catalogado, por lo que su valor 0 nunca contamina la elección del mejor/peor.
|
|
41
|
+
const SEVERIDAD = { desconocida: 0, permisiva: 1, debil: 2, fuerte: 3 };
|
|
42
|
+
|
|
43
|
+
// Cota de profundidad de recursión para licencias anidadas (array de arrays);
|
|
44
|
+
// un package.json malicioso con anidamiento profundo no debe tumbar la auditoría.
|
|
45
|
+
const MAX_PROFUNDIDAD_LICENCIA = 10;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Normaliza un identificador de licencia simple (sin operadores) a su clasificación.
|
|
49
|
+
* @param {string} idRaw
|
|
50
|
+
* @returns {'fuerte'|'debil'|'permisiva'|'desconocida'}
|
|
51
|
+
*/
|
|
52
|
+
function clasificarSimple(idRaw) {
|
|
53
|
+
if (typeof idRaw !== 'string') return 'desconocida';
|
|
54
|
+
const id = idRaw.trim().toUpperCase().replace(/^\(/, '').replace(/\)$/, '').trim();
|
|
55
|
+
if (!id) return 'desconocida';
|
|
56
|
+
// Familias copyleft por prefijo (cubre -ONLY / -OR-LATER / versiones).
|
|
57
|
+
for (const fam of FAMILIAS_FUERTES) {
|
|
58
|
+
if (id === fam || id.startsWith(fam + '-') || id.startsWith(fam + ' ')) return 'fuerte';
|
|
59
|
+
}
|
|
60
|
+
for (const fam of FAMILIAS_DEBILES) {
|
|
61
|
+
if (id === fam || id.startsWith(fam + '-') || id.startsWith(fam + ' ')) return 'debil';
|
|
62
|
+
}
|
|
63
|
+
if (PERMISIVAS.has(id)) return 'permisiva';
|
|
64
|
+
return 'desconocida';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Clasifica una licencia npm: string SPDX (con OR/AND), objeto legacy {type},
|
|
69
|
+
* arreglo legacy de objetos, o ausente.
|
|
70
|
+
*
|
|
71
|
+
* @param {string|object|Array|undefined|null} valor
|
|
72
|
+
* @param {number} [_depth=0] profundidad interna de recursión (cota anti-DoS)
|
|
73
|
+
* @returns {'fuerte'|'debil'|'permisiva'|'desconocida'}
|
|
74
|
+
*/
|
|
75
|
+
function clasificarLicencia(valor, _depth = 0) {
|
|
76
|
+
if (valor == null) return 'desconocida';
|
|
77
|
+
if (_depth > MAX_PROFUNDIDAD_LICENCIA) return 'desconocida'; // anidamiento abusivo
|
|
78
|
+
|
|
79
|
+
// Objeto legacy { type: 'MIT' }
|
|
80
|
+
if (typeof valor === 'object' && !Array.isArray(valor)) {
|
|
81
|
+
return clasificarLicencia(valor.type, _depth + 1);
|
|
82
|
+
}
|
|
83
|
+
// Arreglo legacy [{ type }] → tratar como OR (el consumidor elige)
|
|
84
|
+
if (Array.isArray(valor)) {
|
|
85
|
+
const cls = valor.map((v) => clasificarLicencia(v && v.type ? v.type : v, _depth + 1));
|
|
86
|
+
return cls.reduce((mejor, c) => (SEVERIDAD[c] < SEVERIDAD[mejor] ? c : mejor), 'fuerte');
|
|
87
|
+
}
|
|
88
|
+
if (typeof valor !== 'string') return 'desconocida';
|
|
89
|
+
|
|
90
|
+
const expr = valor.trim();
|
|
91
|
+
if (!expr) return 'desconocida';
|
|
92
|
+
|
|
93
|
+
// Expresión AND: ambas aplican → el PEOR término manda.
|
|
94
|
+
if (/\bAND\b/i.test(expr)) {
|
|
95
|
+
const partes = expr.replace(/[()]/g, ' ').split(/\bAND\b/i).map((s) => s.trim()).filter(Boolean);
|
|
96
|
+
return partes
|
|
97
|
+
.map((p) => clasificarExprOr(p))
|
|
98
|
+
.reduce((peor, c) => (SEVERIDAD[c] > SEVERIDAD[peor] ? c : peor), 'desconocida');
|
|
99
|
+
}
|
|
100
|
+
return clasificarExprOr(expr);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Resuelve una expresión que puede contener OR (el MEJOR término manda) o un
|
|
105
|
+
* identificador simple.
|
|
106
|
+
* @param {string} expr
|
|
107
|
+
* @returns {'fuerte'|'debil'|'permisiva'|'desconocida'}
|
|
108
|
+
*/
|
|
109
|
+
function clasificarExprOr(expr) {
|
|
110
|
+
if (/\bOR\b/i.test(expr)) {
|
|
111
|
+
const partes = expr.replace(/[()]/g, ' ').split(/\bOR\b/i).map((s) => s.trim()).filter(Boolean);
|
|
112
|
+
// mejor = menor severidad, pero ignorando "desconocida" si hay algo catalogado
|
|
113
|
+
const clasifs = partes.map((p) => clasificarSimple(p));
|
|
114
|
+
const catalogadas = clasifs.filter((c) => c !== 'desconocida');
|
|
115
|
+
const pool = catalogadas.length ? catalogadas : clasifs;
|
|
116
|
+
return pool.reduce((mejor, c) => (SEVERIDAD[c] < SEVERIDAD[mejor] ? c : mejor), 'fuerte');
|
|
117
|
+
}
|
|
118
|
+
return clasificarSimple(expr);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Resuelve la licencia de un paquete: primero el campo del lockfile, con fallback
|
|
123
|
+
* al package.json instalado en node_modules/<ruta>.
|
|
124
|
+
*
|
|
125
|
+
* @param {string} baseDir
|
|
126
|
+
* @param {string} rutaNodeModules clave del lockfile, ej. "node_modules/foo"
|
|
127
|
+
* @param {object} entradaLock
|
|
128
|
+
* @returns {string|object|undefined}
|
|
129
|
+
*/
|
|
130
|
+
function resolverLicencia(baseDir, rutaNodeModules, entradaLock) {
|
|
131
|
+
if (entradaLock && entradaLock.license != null) return entradaLock.license;
|
|
132
|
+
if (entradaLock && entradaLock.licenses != null) return entradaLock.licenses; // legacy array
|
|
133
|
+
// Fallback: leer el package.json instalado.
|
|
134
|
+
try {
|
|
135
|
+
const pkgPath = path.join(baseDir, rutaNodeModules, 'package.json');
|
|
136
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
137
|
+
return pkg.license != null ? pkg.license : pkg.licenses;
|
|
138
|
+
} catch {
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Evalúa las licencias del árbol de producción a partir de package-lock.json.
|
|
145
|
+
* Excluye entradas marcadas `dev: true` y la raíz "".
|
|
146
|
+
*
|
|
147
|
+
* @param {string} baseDir raíz del proyecto (contiene package-lock.json)
|
|
148
|
+
* @returns {{hallazgos: Array<{paquete:string, version:string, licencia:string, clasificacion:string}>, resumen: {fuerte:number, debil:number, permisiva:number, desconocida:number}}}
|
|
149
|
+
*/
|
|
150
|
+
function evaluarLicencias(baseDir) {
|
|
151
|
+
const resumen = { fuerte: 0, debil: 0, permisiva: 0, desconocida: 0 };
|
|
152
|
+
const hallazgos = [];
|
|
153
|
+
|
|
154
|
+
const lockPath = path.join(baseDir, 'package-lock.json');
|
|
155
|
+
let lock;
|
|
156
|
+
try {
|
|
157
|
+
lock = JSON.parse(fs.readFileSync(lockPath, 'utf8'));
|
|
158
|
+
} catch (err) {
|
|
159
|
+
// Sin lockfile (ENOENT) → resultado vacío, no es error. Pero un lockfile
|
|
160
|
+
// corrupto (SyntaxError) o sin permisos (EACCES) SÍ se propaga: enmascararlo
|
|
161
|
+
// como "sin deps copyleft" daría un falso OK. El caller (verificar-release)
|
|
162
|
+
// lo captura y reporta como gate "no disponible".
|
|
163
|
+
if (err.code === 'ENOENT') return { hallazgos, resumen };
|
|
164
|
+
throw err;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const packages = lock.packages || {};
|
|
168
|
+
for (const [ruta, entrada] of Object.entries(packages)) {
|
|
169
|
+
if (!ruta || !ruta.startsWith('node_modules/')) continue; // raíz "" y workspaces fuera
|
|
170
|
+
if (entrada && entrada.dev) continue; // solo árbol prod
|
|
171
|
+
const licValor = resolverLicencia(baseDir, ruta, entrada);
|
|
172
|
+
const clasificacion = clasificarLicencia(licValor);
|
|
173
|
+
const licenciaStr = typeof licValor === 'string'
|
|
174
|
+
? licValor
|
|
175
|
+
: (licValor && licValor.type) ? licValor.type
|
|
176
|
+
: (licValor == null ? '(ninguna)' : JSON.stringify(licValor));
|
|
177
|
+
hallazgos.push({
|
|
178
|
+
paquete: ruta.replace(/^node_modules\//, '').replace(/\/node_modules\//g, ' > '),
|
|
179
|
+
version: (entrada && entrada.version) || '?',
|
|
180
|
+
licencia: licenciaStr,
|
|
181
|
+
clasificacion,
|
|
182
|
+
});
|
|
183
|
+
resumen[clasificacion]++;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return { hallazgos, resumen };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// --- CLI ---------------------------------------------------------------------
|
|
190
|
+
|
|
191
|
+
if (require.main === module) {
|
|
192
|
+
const res = evaluarLicencias(process.cwd());
|
|
193
|
+
console.log('Gate de licencias (árbol prod):');
|
|
194
|
+
console.log(` permisiva: ${res.resumen.permisiva} | débil: ${res.resumen.debil} | fuerte: ${res.resumen.fuerte} | desconocida: ${res.resumen.desconocida}`);
|
|
195
|
+
const alertas = res.hallazgos.filter((h) => h.clasificacion !== 'permisiva');
|
|
196
|
+
if (alertas.length) {
|
|
197
|
+
console.log('\nHallazgos no permisivos (WARN — no bloquea el release):');
|
|
198
|
+
for (const h of alertas) {
|
|
199
|
+
console.log(` [${h.clasificacion.toUpperCase()}] ${h.paquete}@${h.version} — ${h.licencia}`);
|
|
200
|
+
}
|
|
201
|
+
} else {
|
|
202
|
+
console.log(' Todas las dependencias de producción son permisivas.');
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
module.exports = {
|
|
207
|
+
clasificarLicencia,
|
|
208
|
+
evaluarLicencias,
|
|
209
|
+
resolverLicencia,
|
|
210
|
+
FAMILIAS_FUERTES,
|
|
211
|
+
FAMILIAS_DEBILES,
|
|
212
|
+
};
|