@saulwade/swl-ses 1.3.1 → 1.3.3
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 +199 -199
- package/README.md +1 -1
- package/bin/swl-ses.js +77 -5
- package/comandos/swl/aprender.md +1 -1
- package/comandos/swl/claudemd.md +141 -136
- package/comandos/swl/configurar-ci.md +227 -227
- package/comandos/swl/evolucion-estado.md +1 -1
- package/comandos/swl/evolucionar.md +3 -3
- package/comandos/swl/inbox.md +1 -1
- package/comandos/swl/reflect-skills.md +1 -1
- package/comandos/swl/salud.md +7 -7
- package/comandos/swl/skill-search.md +4 -4
- package/manifiestos/perfiles.json +2 -1
- package/manifiestos/skills-lock.json +1093 -1093
- package/package.json +87 -87
- package/plugin.json +343 -343
- package/scripts/auditar-claudemd.js +297 -297
- package/scripts/bootstrap-instintos.js +1 -1
- package/scripts/cli/audit-agents-gaps.js +36 -0
- package/scripts/cli/audit-claudemd.js +43 -0
- package/scripts/cli/audit-coverage-frameworks.js +39 -0
- package/scripts/cli/bootstrap-instincts.js +38 -0
- package/scripts/cli/configure-branch-protection.js +42 -0
- package/scripts/cli/generate-skills-lock.js +31 -0
- package/scripts/cli/inbox-tmux-inject.js +49 -0
- package/scripts/cli/reflect-skills.js +40 -0
- package/scripts/cli/run-skill-evals.js +47 -0
- package/scripts/cli/skill-discovery.js +38 -0
- package/scripts/cli/verify-evolution.js +36 -0
- package/scripts/generar-skills-lock.js +190 -190
- package/scripts/inbox-tmux-inject.js +6 -0
- package/scripts/lib/autostart-windows.js +51 -28
- package/scripts/lib/skill-discovery.js +11 -3
- package/scripts/verificar-evolucion.js +1 -1
|
@@ -1,297 +1,297 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* scripts/auditar-claudemd.js
|
|
6
|
-
*
|
|
7
|
-
* Auditor del archivo CLAUDE.md según best practices Anthropic (ADR-0016).
|
|
8
|
-
*
|
|
9
|
-
* Verifica:
|
|
10
|
-
* - Existencia del archivo (en ./ o en .claude/)
|
|
11
|
-
* - Líneas totales (umbral SWL_CLAUDEMD_MAX_LINES, default 200)
|
|
12
|
-
* - Bullets/párrafos monolíticos (umbral SWL_CLAUDEMD_MAX_BULLET_CHARS, default 1000)
|
|
13
|
-
* - Presencia de secciones canónicas (Stack, Comandos, Code style, Conventions, @references)
|
|
14
|
-
* - Uso de @references (al menos 1 si el archivo supera 80 líneas)
|
|
15
|
-
* - Placeholders sin reemplazar ([TBD], [TODO], [COMPLETAR])
|
|
16
|
-
*
|
|
17
|
-
* Uso:
|
|
18
|
-
* node scripts/auditar-claudemd.js [ruta] # Audita CLAUDE.md (default: ./)
|
|
19
|
-
* node scripts/auditar-claudemd.js --json # Salida JSON
|
|
20
|
-
* node scripts/auditar-claudemd.js --strict # exit 1 si veredicto != OK
|
|
21
|
-
*
|
|
22
|
-
* Exit codes:
|
|
23
|
-
* 0 — OK o WARN (veredicto consultivo)
|
|
24
|
-
* 1 — ERROR (no existe / placeholders / faltan secciones críticas) o --strict + WARN
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
const fs = require('fs');
|
|
28
|
-
const path = require('path');
|
|
29
|
-
|
|
30
|
-
// ─── Config ───────────────────────────────────────────────────────────────
|
|
31
|
-
const MAX_LINES = parseInt(process.env.SWL_CLAUDEMD_MAX_LINES, 10) || 200;
|
|
32
|
-
const MAX_BULLET_CHARS =
|
|
33
|
-
parseInt(process.env.SWL_CLAUDEMD_MAX_BULLET_CHARS, 10) || 1000;
|
|
34
|
-
|
|
35
|
-
const SECCIONES_CANONICAS = [
|
|
36
|
-
{ nombre: 'Stack', regex: /^##\s+Stack/m },
|
|
37
|
-
{ nombre: 'Comandos', regex: /^##\s+Comandos/m },
|
|
38
|
-
{ nombre: 'Code style', regex: /^##\s+(Code\s+style|Estilo\s+de\s+código)/im },
|
|
39
|
-
{ nombre: 'Conventions', regex: /^##\s+(Conventions|Convenciones)/im },
|
|
40
|
-
];
|
|
41
|
-
|
|
42
|
-
const PLACEHOLDERS = /\[(TBD|TODO|COMPLETAR|PENDIENTE|XXX|FIXME)\]/g;
|
|
43
|
-
|
|
44
|
-
// ─── Auditoría ────────────────────────────────────────────────────────────
|
|
45
|
-
|
|
46
|
-
function ubicarClaudeMd(dir = process.cwd()) {
|
|
47
|
-
const candidatos = [
|
|
48
|
-
path.join(dir, 'CLAUDE.md'),
|
|
49
|
-
path.join(dir, '.claude', 'CLAUDE.md'),
|
|
50
|
-
];
|
|
51
|
-
for (const c of candidatos) {
|
|
52
|
-
if (fs.existsSync(c)) return c;
|
|
53
|
-
}
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function auditar(rutaClaudeMd) {
|
|
58
|
-
if (!rutaClaudeMd || !fs.existsSync(rutaClaudeMd)) {
|
|
59
|
-
return {
|
|
60
|
-
veredicto: 'ERROR',
|
|
61
|
-
ruta: rutaClaudeMd,
|
|
62
|
-
hallazgos: [{
|
|
63
|
-
severidad: 'ERROR',
|
|
64
|
-
mensaje: 'CLAUDE.md no existe en el directorio de trabajo',
|
|
65
|
-
sugerencia: 'Ejecuta `/swl:claudemd init-project` para generarlo',
|
|
66
|
-
}],
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const contenido = fs.readFileSync(rutaClaudeMd, 'utf8');
|
|
71
|
-
const lineas = contenido.split('\n');
|
|
72
|
-
const hallazgos = [];
|
|
73
|
-
|
|
74
|
-
// 1. Líneas totales
|
|
75
|
-
if (lineas.length > MAX_LINES) {
|
|
76
|
-
hallazgos.push({
|
|
77
|
-
severidad: 'WARN',
|
|
78
|
-
regla: 'tamano-total',
|
|
79
|
-
mensaje: `CLAUDE.md tiene ${lineas.length} líneas (umbral: ${MAX_LINES})`,
|
|
80
|
-
sugerencia: 'Extraer secciones grandes a archivos `@`-referenciados (ej. `@docs/variables-entorno.md`)',
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// 2. Bullets/párrafos monolíticos
|
|
85
|
-
const bulletsMonoliticos = detectarBulletsGigantes(contenido);
|
|
86
|
-
for (const b of bulletsMonoliticos) {
|
|
87
|
-
hallazgos.push({
|
|
88
|
-
severidad: 'WARN',
|
|
89
|
-
regla: 'bullet-gigante',
|
|
90
|
-
mensaje: `Bullet/párrafo en línea ${b.linea} tiene ${b.chars} chars (umbral: ${MAX_BULLET_CHARS})`,
|
|
91
|
-
sugerencia: 'Convertir a tabla, lista jerárquica o extraer a archivo separado',
|
|
92
|
-
preview: b.preview,
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// 3. Secciones canónicas
|
|
97
|
-
const seccionesAusentes = SECCIONES_CANONICAS.filter(s => !s.regex.test(contenido));
|
|
98
|
-
if (seccionesAusentes.length > 0) {
|
|
99
|
-
const nombres = seccionesAusentes.map(s => s.nombre).join(', ');
|
|
100
|
-
hallazgos.push({
|
|
101
|
-
severidad: 'WARN',
|
|
102
|
-
regla: 'secciones-canonicas',
|
|
103
|
-
mensaje: `Faltan secciones canónicas Anthropic: ${nombres}`,
|
|
104
|
-
sugerencia: `Agregar las secciones faltantes (ver \`/swl:claudemd refactor\` para template)`,
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// 4. @references si el archivo es grande
|
|
109
|
-
if (lineas.length > 80) {
|
|
110
|
-
const tieneAtReferences = /@[a-zA-Z][a-zA-Z0-9_\-./]+\.md/.test(contenido);
|
|
111
|
-
if (!tieneAtReferences) {
|
|
112
|
-
hallazgos.push({
|
|
113
|
-
severidad: 'WARN',
|
|
114
|
-
regla: 'sin-at-references',
|
|
115
|
-
mensaje: 'Archivo grande (>80 líneas) sin @references a docs externos',
|
|
116
|
-
sugerencia: 'Usar `@docs/...md` o `@.planning/...md` para enlazar contenido en lugar de duplicarlo',
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// 5. Placeholders sin reemplazar
|
|
122
|
-
const matches = [...contenido.matchAll(PLACEHOLDERS)];
|
|
123
|
-
if (matches.length > 0) {
|
|
124
|
-
hallazgos.push({
|
|
125
|
-
severidad: 'ERROR',
|
|
126
|
-
regla: 'placeholders',
|
|
127
|
-
mensaje: `${matches.length} placeholder(s) sin reemplazar: ${[...new Set(matches.map(m => m[0]))].join(', ')}`,
|
|
128
|
-
sugerencia: 'Reemplazar todos los placeholders antes de commitear',
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// ─── Veredicto ───────────────────────────────────────────────────────────
|
|
133
|
-
const tieneError = hallazgos.some(h => h.severidad === 'ERROR');
|
|
134
|
-
const tieneWarn = hallazgos.some(h => h.severidad === 'WARN');
|
|
135
|
-
const veredicto = tieneError ? 'ERROR' : tieneWarn ? 'WARN' : 'OK';
|
|
136
|
-
|
|
137
|
-
return {
|
|
138
|
-
veredicto,
|
|
139
|
-
ruta: rutaClaudeMd,
|
|
140
|
-
metricas: {
|
|
141
|
-
lineas: lineas.length,
|
|
142
|
-
bytes: contenido.length,
|
|
143
|
-
umbral_lineas: MAX_LINES,
|
|
144
|
-
umbral_bullet_chars: MAX_BULLET_CHARS,
|
|
145
|
-
secciones_presentes: SECCIONES_CANONICAS.filter(s => s.regex.test(contenido)).map(s => s.nombre),
|
|
146
|
-
secciones_ausentes: seccionesAusentes.map(s => s.nombre),
|
|
147
|
-
tiene_at_references: /@[a-zA-Z][a-zA-Z0-9_\-./]+\.md/.test(contenido),
|
|
148
|
-
},
|
|
149
|
-
hallazgos,
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Detecta bullets/párrafos cuyo contenido excede MAX_BULLET_CHARS.
|
|
155
|
-
* Un "bullet" es una línea que empieza con `-` o `*` (ignorando indentación).
|
|
156
|
-
* Un "párrafo" es bloque de texto contiguo sin línea vacía.
|
|
157
|
-
*/
|
|
158
|
-
function detectarBulletsGigantes(contenido) {
|
|
159
|
-
const lineas = contenido.split('\n');
|
|
160
|
-
const gigantes = [];
|
|
161
|
-
let buffer = '';
|
|
162
|
-
let lineaInicio = 0;
|
|
163
|
-
let dentroDeBullet = false;
|
|
164
|
-
let dentroDeCodeFence = false;
|
|
165
|
-
|
|
166
|
-
const flush = () => {
|
|
167
|
-
if (buffer.length > MAX_BULLET_CHARS) {
|
|
168
|
-
gigantes.push({
|
|
169
|
-
linea: lineaInicio + 1,
|
|
170
|
-
chars: buffer.length,
|
|
171
|
-
preview: buffer.slice(0, 100) + (buffer.length > 100 ? '…' : ''),
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
buffer = '';
|
|
175
|
-
dentroDeBullet = false;
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
for (let i = 0; i < lineas.length; i++) {
|
|
179
|
-
const linea = lineas[i];
|
|
180
|
-
|
|
181
|
-
// Skipear bloques de código (no son bullets)
|
|
182
|
-
if (/^\s*```/.test(linea)) {
|
|
183
|
-
flush();
|
|
184
|
-
dentroDeCodeFence = !dentroDeCodeFence;
|
|
185
|
-
continue;
|
|
186
|
-
}
|
|
187
|
-
if (dentroDeCodeFence) continue;
|
|
188
|
-
|
|
189
|
-
// Skipear tablas Markdown (líneas que empiezan con `|`):
|
|
190
|
-
// las tablas son grandes por naturaleza y no son "bullets monolíticos"
|
|
191
|
-
if (/^\s*\|/.test(linea)) {
|
|
192
|
-
flush();
|
|
193
|
-
continue;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// Línea vacía termina el bullet/párrafo actual
|
|
197
|
-
if (/^\s*$/.test(linea)) {
|
|
198
|
-
flush();
|
|
199
|
-
continue;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// Header termina el buffer
|
|
203
|
-
if (/^#/.test(linea)) {
|
|
204
|
-
flush();
|
|
205
|
-
continue;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// Inicio de nuevo bullet
|
|
209
|
-
if (/^\s*[-*+]\s/.test(linea)) {
|
|
210
|
-
flush();
|
|
211
|
-
lineaInicio = i;
|
|
212
|
-
buffer = linea;
|
|
213
|
-
dentroDeBullet = true;
|
|
214
|
-
continue;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// Continuación: si estamos en bullet, acumular; si no, párrafo
|
|
218
|
-
if (dentroDeBullet) {
|
|
219
|
-
buffer += '\n' + linea;
|
|
220
|
-
} else {
|
|
221
|
-
if (buffer === '') lineaInicio = i;
|
|
222
|
-
buffer += (buffer ? '\n' : '') + linea;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
flush();
|
|
226
|
-
return gigantes;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// ─── CLI ──────────────────────────────────────────────────────────────────
|
|
230
|
-
|
|
231
|
-
function imprimirReporte(resultado) {
|
|
232
|
-
const colorVeredicto = {
|
|
233
|
-
OK: '\x1b[32m', // verde
|
|
234
|
-
WARN: '\x1b[33m', // amarillo
|
|
235
|
-
ERROR: '\x1b[31m', // rojo
|
|
236
|
-
};
|
|
237
|
-
const reset = '\x1b[0m';
|
|
238
|
-
|
|
239
|
-
console.log(`\n${colorVeredicto[resultado.veredicto]}=== AUDITORÍA CLAUDE.md ===${reset}`);
|
|
240
|
-
console.log(`Veredicto: ${colorVeredicto[resultado.veredicto]}${resultado.veredicto}${reset}`);
|
|
241
|
-
console.log(`Ruta: ${resultado.ruta || '(no encontrado)'}\n`);
|
|
242
|
-
|
|
243
|
-
if (resultado.metricas) {
|
|
244
|
-
const m = resultado.metricas;
|
|
245
|
-
console.log(`Métricas:`);
|
|
246
|
-
console.log(` - Líneas: ${m.lineas} / ${m.umbral_lineas}`);
|
|
247
|
-
console.log(` - Secciones canónicas presentes: ${m.secciones_presentes.length}/4 (${m.secciones_presentes.join(', ') || 'ninguna'})`);
|
|
248
|
-
if (m.secciones_ausentes.length > 0) {
|
|
249
|
-
console.log(` - Secciones ausentes: ${m.secciones_ausentes.join(', ')}`);
|
|
250
|
-
}
|
|
251
|
-
console.log(` - @references: ${m.tiene_at_references ? 'sí' : 'no'}`);
|
|
252
|
-
console.log('');
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
if (resultado.hallazgos.length === 0) {
|
|
256
|
-
console.log('Sin hallazgos. CLAUDE.md cumple best practices Anthropic.\n');
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
console.log(`Hallazgos (${resultado.hallazgos.length}):\n`);
|
|
261
|
-
for (const h of resultado.hallazgos) {
|
|
262
|
-
const color = colorVeredicto[h.severidad] || '';
|
|
263
|
-
console.log(` ${color}[${h.severidad}]${reset} ${h.mensaje}`);
|
|
264
|
-
if (h.sugerencia) console.log(` → ${h.sugerencia}`);
|
|
265
|
-
if (h.preview) console.log(` Preview: ${h.preview}`);
|
|
266
|
-
console.log('');
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
function main() {
|
|
271
|
-
const args = process.argv.slice(2);
|
|
272
|
-
const flagJson = args.includes('--json');
|
|
273
|
-
const flagStrict = args.includes('--strict');
|
|
274
|
-
const rutaArg = args.find(a => !a.startsWith('--'));
|
|
275
|
-
|
|
276
|
-
const ruta = rutaArg
|
|
277
|
-
? path.resolve(rutaArg)
|
|
278
|
-
: ubicarClaudeMd();
|
|
279
|
-
|
|
280
|
-
const resultado = auditar(ruta);
|
|
281
|
-
|
|
282
|
-
if (flagJson) {
|
|
283
|
-
console.log(JSON.stringify(resultado, null, 2));
|
|
284
|
-
} else {
|
|
285
|
-
imprimirReporte(resultado);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
if (resultado.veredicto === 'ERROR') process.exit(1);
|
|
289
|
-
if (flagStrict && resultado.veredicto === 'WARN') process.exit(1);
|
|
290
|
-
process.exit(0);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
if (require.main === module) {
|
|
294
|
-
main();
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
module.exports = { auditar, ubicarClaudeMd, detectarBulletsGigantes, MAX_LINES, MAX_BULLET_CHARS };
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* scripts/auditar-claudemd.js
|
|
6
|
+
*
|
|
7
|
+
* Auditor del archivo CLAUDE.md según best practices Anthropic (ADR-0016).
|
|
8
|
+
*
|
|
9
|
+
* Verifica:
|
|
10
|
+
* - Existencia del archivo (en ./ o en .claude/)
|
|
11
|
+
* - Líneas totales (umbral SWL_CLAUDEMD_MAX_LINES, default 200)
|
|
12
|
+
* - Bullets/párrafos monolíticos (umbral SWL_CLAUDEMD_MAX_BULLET_CHARS, default 1000)
|
|
13
|
+
* - Presencia de secciones canónicas (Stack, Comandos, Code style, Conventions, @references)
|
|
14
|
+
* - Uso de @references (al menos 1 si el archivo supera 80 líneas)
|
|
15
|
+
* - Placeholders sin reemplazar ([TBD], [TODO], [COMPLETAR])
|
|
16
|
+
*
|
|
17
|
+
* Uso:
|
|
18
|
+
* node scripts/auditar-claudemd.js [ruta] # Audita CLAUDE.md (default: ./)
|
|
19
|
+
* node scripts/auditar-claudemd.js --json # Salida JSON
|
|
20
|
+
* node scripts/auditar-claudemd.js --strict # exit 1 si veredicto != OK
|
|
21
|
+
*
|
|
22
|
+
* Exit codes:
|
|
23
|
+
* 0 — OK o WARN (veredicto consultivo)
|
|
24
|
+
* 1 — ERROR (no existe / placeholders / faltan secciones críticas) o --strict + WARN
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
const fs = require('fs');
|
|
28
|
+
const path = require('path');
|
|
29
|
+
|
|
30
|
+
// ─── Config ───────────────────────────────────────────────────────────────
|
|
31
|
+
const MAX_LINES = parseInt(process.env.SWL_CLAUDEMD_MAX_LINES, 10) || 200;
|
|
32
|
+
const MAX_BULLET_CHARS =
|
|
33
|
+
parseInt(process.env.SWL_CLAUDEMD_MAX_BULLET_CHARS, 10) || 1000;
|
|
34
|
+
|
|
35
|
+
const SECCIONES_CANONICAS = [
|
|
36
|
+
{ nombre: 'Stack', regex: /^##\s+Stack/m },
|
|
37
|
+
{ nombre: 'Comandos', regex: /^##\s+Comandos/m },
|
|
38
|
+
{ nombre: 'Code style', regex: /^##\s+(Code\s+style|Estilo\s+de\s+código)/im },
|
|
39
|
+
{ nombre: 'Conventions', regex: /^##\s+(Conventions|Convenciones)/im },
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
const PLACEHOLDERS = /\[(TBD|TODO|COMPLETAR|PENDIENTE|XXX|FIXME)\]/g;
|
|
43
|
+
|
|
44
|
+
// ─── Auditoría ────────────────────────────────────────────────────────────
|
|
45
|
+
|
|
46
|
+
function ubicarClaudeMd(dir = process.cwd()) {
|
|
47
|
+
const candidatos = [
|
|
48
|
+
path.join(dir, 'CLAUDE.md'),
|
|
49
|
+
path.join(dir, '.claude', 'CLAUDE.md'),
|
|
50
|
+
];
|
|
51
|
+
for (const c of candidatos) {
|
|
52
|
+
if (fs.existsSync(c)) return c;
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function auditar(rutaClaudeMd) {
|
|
58
|
+
if (!rutaClaudeMd || !fs.existsSync(rutaClaudeMd)) {
|
|
59
|
+
return {
|
|
60
|
+
veredicto: 'ERROR',
|
|
61
|
+
ruta: rutaClaudeMd,
|
|
62
|
+
hallazgos: [{
|
|
63
|
+
severidad: 'ERROR',
|
|
64
|
+
mensaje: 'CLAUDE.md no existe en el directorio de trabajo',
|
|
65
|
+
sugerencia: 'Ejecuta `/swl:claudemd init-project` para generarlo',
|
|
66
|
+
}],
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const contenido = fs.readFileSync(rutaClaudeMd, 'utf8');
|
|
71
|
+
const lineas = contenido.split('\n');
|
|
72
|
+
const hallazgos = [];
|
|
73
|
+
|
|
74
|
+
// 1. Líneas totales
|
|
75
|
+
if (lineas.length > MAX_LINES) {
|
|
76
|
+
hallazgos.push({
|
|
77
|
+
severidad: 'WARN',
|
|
78
|
+
regla: 'tamano-total',
|
|
79
|
+
mensaje: `CLAUDE.md tiene ${lineas.length} líneas (umbral: ${MAX_LINES})`,
|
|
80
|
+
sugerencia: 'Extraer secciones grandes a archivos `@`-referenciados (ej. `@docs/variables-entorno.md`)',
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 2. Bullets/párrafos monolíticos
|
|
85
|
+
const bulletsMonoliticos = detectarBulletsGigantes(contenido);
|
|
86
|
+
for (const b of bulletsMonoliticos) {
|
|
87
|
+
hallazgos.push({
|
|
88
|
+
severidad: 'WARN',
|
|
89
|
+
regla: 'bullet-gigante',
|
|
90
|
+
mensaje: `Bullet/párrafo en línea ${b.linea} tiene ${b.chars} chars (umbral: ${MAX_BULLET_CHARS})`,
|
|
91
|
+
sugerencia: 'Convertir a tabla, lista jerárquica o extraer a archivo separado',
|
|
92
|
+
preview: b.preview,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// 3. Secciones canónicas
|
|
97
|
+
const seccionesAusentes = SECCIONES_CANONICAS.filter(s => !s.regex.test(contenido));
|
|
98
|
+
if (seccionesAusentes.length > 0) {
|
|
99
|
+
const nombres = seccionesAusentes.map(s => s.nombre).join(', ');
|
|
100
|
+
hallazgos.push({
|
|
101
|
+
severidad: 'WARN',
|
|
102
|
+
regla: 'secciones-canonicas',
|
|
103
|
+
mensaje: `Faltan secciones canónicas Anthropic: ${nombres}`,
|
|
104
|
+
sugerencia: `Agregar las secciones faltantes (ver \`/swl:claudemd refactor\` para template)`,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// 4. @references si el archivo es grande
|
|
109
|
+
if (lineas.length > 80) {
|
|
110
|
+
const tieneAtReferences = /@[a-zA-Z][a-zA-Z0-9_\-./]+\.md/.test(contenido);
|
|
111
|
+
if (!tieneAtReferences) {
|
|
112
|
+
hallazgos.push({
|
|
113
|
+
severidad: 'WARN',
|
|
114
|
+
regla: 'sin-at-references',
|
|
115
|
+
mensaje: 'Archivo grande (>80 líneas) sin @references a docs externos',
|
|
116
|
+
sugerencia: 'Usar `@docs/...md` o `@.planning/...md` para enlazar contenido en lugar de duplicarlo',
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// 5. Placeholders sin reemplazar
|
|
122
|
+
const matches = [...contenido.matchAll(PLACEHOLDERS)];
|
|
123
|
+
if (matches.length > 0) {
|
|
124
|
+
hallazgos.push({
|
|
125
|
+
severidad: 'ERROR',
|
|
126
|
+
regla: 'placeholders',
|
|
127
|
+
mensaje: `${matches.length} placeholder(s) sin reemplazar: ${[...new Set(matches.map(m => m[0]))].join(', ')}`,
|
|
128
|
+
sugerencia: 'Reemplazar todos los placeholders antes de commitear',
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// ─── Veredicto ───────────────────────────────────────────────────────────
|
|
133
|
+
const tieneError = hallazgos.some(h => h.severidad === 'ERROR');
|
|
134
|
+
const tieneWarn = hallazgos.some(h => h.severidad === 'WARN');
|
|
135
|
+
const veredicto = tieneError ? 'ERROR' : tieneWarn ? 'WARN' : 'OK';
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
veredicto,
|
|
139
|
+
ruta: rutaClaudeMd,
|
|
140
|
+
metricas: {
|
|
141
|
+
lineas: lineas.length,
|
|
142
|
+
bytes: contenido.length,
|
|
143
|
+
umbral_lineas: MAX_LINES,
|
|
144
|
+
umbral_bullet_chars: MAX_BULLET_CHARS,
|
|
145
|
+
secciones_presentes: SECCIONES_CANONICAS.filter(s => s.regex.test(contenido)).map(s => s.nombre),
|
|
146
|
+
secciones_ausentes: seccionesAusentes.map(s => s.nombre),
|
|
147
|
+
tiene_at_references: /@[a-zA-Z][a-zA-Z0-9_\-./]+\.md/.test(contenido),
|
|
148
|
+
},
|
|
149
|
+
hallazgos,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Detecta bullets/párrafos cuyo contenido excede MAX_BULLET_CHARS.
|
|
155
|
+
* Un "bullet" es una línea que empieza con `-` o `*` (ignorando indentación).
|
|
156
|
+
* Un "párrafo" es bloque de texto contiguo sin línea vacía.
|
|
157
|
+
*/
|
|
158
|
+
function detectarBulletsGigantes(contenido) {
|
|
159
|
+
const lineas = contenido.split('\n');
|
|
160
|
+
const gigantes = [];
|
|
161
|
+
let buffer = '';
|
|
162
|
+
let lineaInicio = 0;
|
|
163
|
+
let dentroDeBullet = false;
|
|
164
|
+
let dentroDeCodeFence = false;
|
|
165
|
+
|
|
166
|
+
const flush = () => {
|
|
167
|
+
if (buffer.length > MAX_BULLET_CHARS) {
|
|
168
|
+
gigantes.push({
|
|
169
|
+
linea: lineaInicio + 1,
|
|
170
|
+
chars: buffer.length,
|
|
171
|
+
preview: buffer.slice(0, 100) + (buffer.length > 100 ? '…' : ''),
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
buffer = '';
|
|
175
|
+
dentroDeBullet = false;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
for (let i = 0; i < lineas.length; i++) {
|
|
179
|
+
const linea = lineas[i];
|
|
180
|
+
|
|
181
|
+
// Skipear bloques de código (no son bullets)
|
|
182
|
+
if (/^\s*```/.test(linea)) {
|
|
183
|
+
flush();
|
|
184
|
+
dentroDeCodeFence = !dentroDeCodeFence;
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
if (dentroDeCodeFence) continue;
|
|
188
|
+
|
|
189
|
+
// Skipear tablas Markdown (líneas que empiezan con `|`):
|
|
190
|
+
// las tablas son grandes por naturaleza y no son "bullets monolíticos"
|
|
191
|
+
if (/^\s*\|/.test(linea)) {
|
|
192
|
+
flush();
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Línea vacía termina el bullet/párrafo actual
|
|
197
|
+
if (/^\s*$/.test(linea)) {
|
|
198
|
+
flush();
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Header termina el buffer
|
|
203
|
+
if (/^#/.test(linea)) {
|
|
204
|
+
flush();
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Inicio de nuevo bullet
|
|
209
|
+
if (/^\s*[-*+]\s/.test(linea)) {
|
|
210
|
+
flush();
|
|
211
|
+
lineaInicio = i;
|
|
212
|
+
buffer = linea;
|
|
213
|
+
dentroDeBullet = true;
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Continuación: si estamos en bullet, acumular; si no, párrafo
|
|
218
|
+
if (dentroDeBullet) {
|
|
219
|
+
buffer += '\n' + linea;
|
|
220
|
+
} else {
|
|
221
|
+
if (buffer === '') lineaInicio = i;
|
|
222
|
+
buffer += (buffer ? '\n' : '') + linea;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
flush();
|
|
226
|
+
return gigantes;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// ─── CLI ──────────────────────────────────────────────────────────────────
|
|
230
|
+
|
|
231
|
+
function imprimirReporte(resultado) {
|
|
232
|
+
const colorVeredicto = {
|
|
233
|
+
OK: '\x1b[32m', // verde
|
|
234
|
+
WARN: '\x1b[33m', // amarillo
|
|
235
|
+
ERROR: '\x1b[31m', // rojo
|
|
236
|
+
};
|
|
237
|
+
const reset = '\x1b[0m';
|
|
238
|
+
|
|
239
|
+
console.log(`\n${colorVeredicto[resultado.veredicto]}=== AUDITORÍA CLAUDE.md ===${reset}`);
|
|
240
|
+
console.log(`Veredicto: ${colorVeredicto[resultado.veredicto]}${resultado.veredicto}${reset}`);
|
|
241
|
+
console.log(`Ruta: ${resultado.ruta || '(no encontrado)'}\n`);
|
|
242
|
+
|
|
243
|
+
if (resultado.metricas) {
|
|
244
|
+
const m = resultado.metricas;
|
|
245
|
+
console.log(`Métricas:`);
|
|
246
|
+
console.log(` - Líneas: ${m.lineas} / ${m.umbral_lineas}`);
|
|
247
|
+
console.log(` - Secciones canónicas presentes: ${m.secciones_presentes.length}/4 (${m.secciones_presentes.join(', ') || 'ninguna'})`);
|
|
248
|
+
if (m.secciones_ausentes.length > 0) {
|
|
249
|
+
console.log(` - Secciones ausentes: ${m.secciones_ausentes.join(', ')}`);
|
|
250
|
+
}
|
|
251
|
+
console.log(` - @references: ${m.tiene_at_references ? 'sí' : 'no'}`);
|
|
252
|
+
console.log('');
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (resultado.hallazgos.length === 0) {
|
|
256
|
+
console.log('Sin hallazgos. CLAUDE.md cumple best practices Anthropic.\n');
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
console.log(`Hallazgos (${resultado.hallazgos.length}):\n`);
|
|
261
|
+
for (const h of resultado.hallazgos) {
|
|
262
|
+
const color = colorVeredicto[h.severidad] || '';
|
|
263
|
+
console.log(` ${color}[${h.severidad}]${reset} ${h.mensaje}`);
|
|
264
|
+
if (h.sugerencia) console.log(` → ${h.sugerencia}`);
|
|
265
|
+
if (h.preview) console.log(` Preview: ${h.preview}`);
|
|
266
|
+
console.log('');
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function main() {
|
|
271
|
+
const args = process.argv.slice(2);
|
|
272
|
+
const flagJson = args.includes('--json');
|
|
273
|
+
const flagStrict = args.includes('--strict');
|
|
274
|
+
const rutaArg = args.find(a => !a.startsWith('--'));
|
|
275
|
+
|
|
276
|
+
const ruta = rutaArg
|
|
277
|
+
? path.resolve(rutaArg)
|
|
278
|
+
: ubicarClaudeMd();
|
|
279
|
+
|
|
280
|
+
const resultado = auditar(ruta);
|
|
281
|
+
|
|
282
|
+
if (flagJson) {
|
|
283
|
+
console.log(JSON.stringify(resultado, null, 2));
|
|
284
|
+
} else {
|
|
285
|
+
imprimirReporte(resultado);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (resultado.veredicto === 'ERROR') process.exit(1);
|
|
289
|
+
if (flagStrict && resultado.veredicto === 'WARN') process.exit(1);
|
|
290
|
+
process.exit(0);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (require.main === module) {
|
|
294
|
+
main();
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
module.exports = { auditar, ubicarClaudeMd, detectarBulletsGigantes, main, MAX_LINES, MAX_BULLET_CHARS };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Wrapper CLI para `swl-ses audit-agents-gaps`.
|
|
5
|
+
*
|
|
6
|
+
* Audita gaps de metadata defensiva en agentes (Exclusion Clauses, fragments,
|
|
7
|
+
* frontmatter completo). El script standalone NO exporta main, ejecuta en
|
|
8
|
+
* top-level. Wrapper hace require() directo con argv manipulado.
|
|
9
|
+
*
|
|
10
|
+
* Flags soportadas:
|
|
11
|
+
* --resumen → output resumen compacto
|
|
12
|
+
* --json → output JSON estructurado
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const path = require('path');
|
|
16
|
+
|
|
17
|
+
function auditAgentsGaps(opciones) {
|
|
18
|
+
const args = [];
|
|
19
|
+
if (opciones && opciones.resumen) args.push('--resumen');
|
|
20
|
+
if (opciones && opciones.json) args.push('--json');
|
|
21
|
+
if (opciones && Array.isArray(opciones._args)) {
|
|
22
|
+
args.push(...opciones._args);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const argvOriginal = process.argv;
|
|
26
|
+
process.argv = ['node', 'auditar-agentes-gaps.js', ...args];
|
|
27
|
+
try {
|
|
28
|
+
const ruta = path.resolve(__dirname, '..', 'auditar-agentes-gaps.js');
|
|
29
|
+
delete require.cache[ruta];
|
|
30
|
+
require(ruta);
|
|
31
|
+
} finally {
|
|
32
|
+
process.argv = argvOriginal;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = auditAgentsGaps;
|