@saulwade/swl-ses 1.5.2 → 1.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.
@@ -0,0 +1,187 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Pantalla Welcome de la TUI de swl-ses.
5
+ *
6
+ * Diseño:
7
+ * - Logo ASCII centrado en la parte superior
8
+ * - Tabla de runtimes detectados (nombre, scope, versión instalada, estado)
9
+ * - Pie con atajos: Enter continuar / Esc salir
10
+ *
11
+ * No-TTY: imprime versión texto plano y retorna { continuar: true } inmediatamente.
12
+ */
13
+
14
+ const path = require('path');
15
+
16
+ const render = require('../lib/render');
17
+ const teclas = require('../lib/teclas');
18
+ const { colores, semantico, iconos } = require('../lib/colores');
19
+
20
+ // Logo en caracteres ASCII art compactos (5 líneas)
21
+ const LOGO = [
22
+ ' ███████ ██ ██ ██ ███████ ███████ ███████ ',
23
+ ' ██ ██ ██ ██ ██ ██ ██ ',
24
+ ' ███████ ██ █ ██ ██ ███████ █████ ███████ ',
25
+ ' ██ ██ ███ ██ ██ ██ ██ ██ ',
26
+ ' ███████ ███ ███ ███████ ███████ ███████ ███████ ',
27
+ ];
28
+
29
+ const SUBTITULO = 'Sistema de ingeniería de software auto-evolutivo multi-runtime';
30
+
31
+ /**
32
+ * Detecta runtimes instalados leyendo desde scripts/lib/detectar-runtime.
33
+ * No falla si la lib no está disponible — devuelve array vacío.
34
+ */
35
+ function detectarInstalaciones() {
36
+ let detectarRuntimes;
37
+ let cargarEstado;
38
+ try {
39
+ ({ detectarRuntimes } = require('../../lib/detectar-runtime'));
40
+ ({ cargarEstado } = require('../../lib/estado'));
41
+ } catch (_) {
42
+ return [];
43
+ }
44
+
45
+ const runtimes = detectarRuntimes();
46
+ const filas = [];
47
+ for (const runtime of runtimes) {
48
+ const dirs = [
49
+ { ruta: runtime.global, scope: 'global' },
50
+ { ruta: path.resolve(runtime.local), scope: 'proyecto' },
51
+ ];
52
+ for (const { ruta, scope } of dirs) {
53
+ try {
54
+ const estado = cargarEstado(ruta);
55
+ if (!estado) continue;
56
+ filas.push({
57
+ runtime: runtime.nombre,
58
+ scope,
59
+ version: estado.versionSistema || 'desconocida',
60
+ perfil: estado.perfil || '-',
61
+ componentes: estado.componentesInstalados?.length || 0,
62
+ });
63
+ } catch (_) {
64
+ // ignorar errores de lectura
65
+ }
66
+ }
67
+ }
68
+ return filas;
69
+ }
70
+
71
+ /**
72
+ * Pinta el contenido completo de la pantalla. Idempotente — se puede invocar
73
+ * múltiples veces (resize, re-render).
74
+ */
75
+ function _renderizar(filas, version) {
76
+ render.limpiarPantalla();
77
+ const { cols, rows } = render.obtenerDimensiones();
78
+
79
+ // Logo centrado
80
+ const filaLogo = 2;
81
+ for (let i = 0; i < LOGO.length; i++) {
82
+ const linea = LOGO[i];
83
+ const colLogo = Math.max(1, Math.floor((cols - linea.length) / 2));
84
+ render.escribirEn(filaLogo + i, colLogo, semantico.titulo(linea));
85
+ }
86
+
87
+ // Subtítulo + versión
88
+ const filaSub = filaLogo + LOGO.length + 1;
89
+ const subFinal = `${SUBTITULO} ${colores.dim('v' + version)}`;
90
+ const colSub = Math.max(1, Math.floor((cols - render.anchoVisual(subFinal)) / 2));
91
+ render.escribirEn(filaSub, colSub, subFinal);
92
+
93
+ // Tabla de runtimes detectados
94
+ const filaTabla = filaSub + 3;
95
+ if (filas.length === 0) {
96
+ const mensaje = colores.dim('No se detectaron instalaciones SWL en este equipo.');
97
+ const colMsg = Math.max(1, Math.floor((cols - render.anchoVisual(mensaje)) / 2));
98
+ render.escribirEn(filaTabla, colMsg, mensaje);
99
+ } else {
100
+ render.escribirEn(filaTabla - 1, 4, semantico.enfasis('Instalaciones detectadas:'));
101
+ const cabecera =
102
+ render.rellenarDer(colores.dim('Runtime'), 14) +
103
+ render.rellenarDer(colores.dim('Scope'), 10) +
104
+ render.rellenarDer(colores.dim('Versión'), 12) +
105
+ render.rellenarDer(colores.dim('Perfil'), 18) +
106
+ colores.dim('Componentes');
107
+ render.escribirEn(filaTabla, 4, cabecera);
108
+
109
+ filas.slice(0, rows - filaTabla - 4).forEach((f, i) => {
110
+ const estado = f.version === version
111
+ ? semantico.exito(iconos.check)
112
+ : semantico.warn(iconos.warn);
113
+ const linea =
114
+ render.rellenarDer(`${estado} ${f.runtime}`, 14) +
115
+ render.rellenarDer(f.scope, 10) +
116
+ render.rellenarDer('v' + f.version, 12) +
117
+ render.rellenarDer(f.perfil, 18) +
118
+ colores.cyan(String(f.componentes));
119
+ render.escribirEn(filaTabla + 1 + i, 4, linea);
120
+ });
121
+ }
122
+
123
+ // Mensaje central de continuación
124
+ const filaCont = rows - 4;
125
+ const mensaje = `Presiona ${semantico.cursor('Enter')} para continuar al menú principal o ${semantico.cursor('Esc')} para salir.`;
126
+ const colCont = Math.max(1, Math.floor((cols - render.anchoVisual(mensaje)) / 2));
127
+ render.escribirEn(filaCont, colCont, mensaje);
128
+
129
+ // Pie con atajos
130
+ render.dibujarPiePagina([
131
+ ['Enter', 'continuar'],
132
+ ['Esc', 'salir'],
133
+ ]);
134
+ }
135
+
136
+ /**
137
+ * Muestra la pantalla Welcome y espera input del usuario.
138
+ *
139
+ * @returns {Promise<{ continuar: boolean, instalaciones: Array }>}
140
+ */
141
+ function mostrarWelcome() {
142
+ const version = require('../../../package.json').version;
143
+ const filas = detectarInstalaciones();
144
+
145
+ return new Promise((resolve) => {
146
+ // Modo no-TTY: salida texto plano sin esperar input
147
+ if (!render.ES_TTY || !process.stdin.isTTY) {
148
+ console.log('');
149
+ console.log(` swl-ses v${version}`);
150
+ console.log(` ${SUBTITULO}`);
151
+ console.log('');
152
+ if (filas.length > 0) {
153
+ console.log(' Instalaciones detectadas:');
154
+ for (const f of filas) {
155
+ console.log(` ${f.runtime} (${f.scope}): v${f.version}, perfil ${f.perfil}`);
156
+ }
157
+ } else {
158
+ console.log(' No se detectaron instalaciones SWL.');
159
+ }
160
+ console.log('');
161
+ resolve({ continuar: true, instalaciones: filas });
162
+ return;
163
+ }
164
+
165
+ render.iniciarModoTui();
166
+ _renderizar(filas, version);
167
+
168
+ // Re-renderizar en resize
169
+ const onResize = () => _renderizar(filas, version);
170
+ process.stdout.on('resize', onResize);
171
+
172
+ const teclado = teclas.crearTeclado();
173
+
174
+ function finalizar(continuar) {
175
+ teclado.desactivar();
176
+ process.stdout.removeListener('resize', onResize);
177
+ render.salirModoTui();
178
+ resolve({ continuar, instalaciones: filas });
179
+ }
180
+
181
+ teclado.on('return', () => finalizar(true));
182
+ teclado.on('escape', () => finalizar(false));
183
+ teclado.activar();
184
+ });
185
+ }
186
+
187
+ module.exports = { mostrarWelcome, detectarInstalaciones, LOGO, SUBTITULO };
@@ -0,0 +1,425 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ /**
5
+ * scripts/verificar-docs-vs-codigo.js
6
+ *
7
+ * Verificador automatizado de drift entre documentación y estado real del
8
+ * proyecto. Pensado para correr en CI tras un release o cuando se modifican
9
+ * componentes del sistema.
10
+ *
11
+ * Checks implementados:
12
+ *
13
+ * 1. CONTADORES: INVENTARIO.md vs disco
14
+ * Verifica que los contadores (agentes, skills, comandos, hooks, reglas)
15
+ * reportados en INVENTARIO.md, README.md, AGENTS.md, MANUAL_USO.md,
16
+ * package.json#description y plugin.json#description coincidan con lo
17
+ * que existe en disco.
18
+ *
19
+ * 2. COMANDOS: comandos/swl/*.md vs COMANDOS.md y MANUAL_USO.md
20
+ * Cada comando con archivo en comandos/swl/ debe mencionarse en
21
+ * COMANDOS.md (al menos una vez como /swl:<nombre>) y en MANUAL_USO.md
22
+ * (al menos una sección dedicada).
23
+ *
24
+ * 3. FLAGS críticos: parser vs docs
25
+ * Si parsear-opciones.js declara una flag como booleana, debe aparecer
26
+ * en bin/swl-ses.js --help y en COMANDOS.md tabla de opciones.
27
+ *
28
+ * 4. VERSIONES: package.json vs encabezados de docs
29
+ * Las primeras líneas de CLAUDE.md, README.md, AGENTS.md, COMANDOS.md,
30
+ * MANUAL_USO.md, INSTALACION.md deben mencionar la versión de
31
+ * package.json.
32
+ *
33
+ * 5. TUI: scripts/tui/pantallas/*.js vs docs
34
+ * Cada pantalla del TUI (welcome, menu-principal, install-wizard,
35
+ * update-wizard, uninstall-wizard, inspect, progreso, resumen) debe
36
+ * tener al menos una mención en MANUAL_USO.md.
37
+ *
38
+ * Exit codes:
39
+ * 0 — todos los checks pasan
40
+ * 1 — hay drift en al menos un check obligatorio
41
+ * 2 — error de invocación
42
+ *
43
+ * Uso:
44
+ * node scripts/verificar-docs-vs-codigo.js [--check N] [--quiet]
45
+ *
46
+ * --check N Ejecuta solo el check N (1-5). Sin flag: todos.
47
+ * --quiet Suprime el output de checks que pasan; solo reporta fallas.
48
+ */
49
+
50
+ const fs = require('fs');
51
+ const path = require('path');
52
+
53
+ const RAIZ = path.resolve(__dirname, '..');
54
+
55
+ // ── helpers ───────────────────────────────────────────────────────────────────
56
+
57
+ function leerArchivo(rel) {
58
+ try {
59
+ return fs.readFileSync(path.join(RAIZ, rel), 'utf-8');
60
+ } catch (_) {
61
+ return null;
62
+ }
63
+ }
64
+
65
+ function contarEntradasDirectorio(dir, opts = {}) {
66
+ const dirAbs = path.join(RAIZ, dir);
67
+ if (!fs.existsSync(dirAbs)) return 0;
68
+ const entradas = fs.readdirSync(dirAbs, { withFileTypes: true });
69
+ if (opts.dirsOnly) return entradas.filter(e => e.isDirectory()).length;
70
+ if (opts.filesOnly) {
71
+ return entradas.filter(e => e.isFile() && (!opts.ext || e.name.endsWith(opts.ext))).length;
72
+ }
73
+ return entradas.length;
74
+ }
75
+
76
+ function contarHooksEjecutables() {
77
+ const dirAbs = path.join(RAIZ, 'hooks');
78
+ if (!fs.existsSync(dirAbs)) return 0;
79
+ return fs.readdirSync(dirAbs)
80
+ .filter(n => n.endsWith('.js') && !n.startsWith('_'))
81
+ .length;
82
+ }
83
+
84
+ function contarReglasMd() {
85
+ const dirAbs = path.join(RAIZ, 'reglas');
86
+ if (!fs.existsSync(dirAbs)) return 0;
87
+ // Cuenta archivos .md en raíz de reglas/ + subdirectorios por lenguaje
88
+ let total = 0;
89
+ function recurse(d) {
90
+ for (const e of fs.readdirSync(d, { withFileTypes: true })) {
91
+ if (e.isDirectory() && !e.name.startsWith('_')) recurse(path.join(d, e.name));
92
+ else if (e.isFile() && e.name.endsWith('.md') && !e.name.startsWith('_')) total++;
93
+ }
94
+ }
95
+ recurse(dirAbs);
96
+ return total;
97
+ }
98
+
99
+ // ── reporting ─────────────────────────────────────────────────────────────────
100
+
101
+ const COLOR_OK = '\x1b[32m';
102
+ const COLOR_FAIL = '\x1b[31m';
103
+ const COLOR_WARN = '\x1b[33m';
104
+ const COLOR_DIM = '\x1b[2m';
105
+ const COLOR_RESET = '\x1b[0m';
106
+ const tty = !!process.stdout.isTTY;
107
+ const c = (color, txt) => (tty ? `${color}${txt}${COLOR_RESET}` : txt);
108
+
109
+ const opts = (() => {
110
+ const args = process.argv.slice(2);
111
+ const checkIdx = args.indexOf('--check');
112
+ return {
113
+ only: checkIdx >= 0 ? parseInt(args[checkIdx + 1], 10) : null,
114
+ quiet: args.includes('--quiet'),
115
+ };
116
+ })();
117
+
118
+ const resultados = [];
119
+
120
+ function reportar(check, etiqueta, ok, detalle) {
121
+ resultados.push({ check, etiqueta, ok, detalle });
122
+ if (ok && opts.quiet) return;
123
+ const mark = ok ? c(COLOR_OK, '[OK]') : c(COLOR_FAIL, '[FAIL]');
124
+ console.log(` ${mark} check #${check} — ${etiqueta}`);
125
+ if (detalle && !opts.quiet) {
126
+ for (const linea of String(detalle).split('\n')) {
127
+ console.log(` ${c(COLOR_DIM, linea)}`);
128
+ }
129
+ } else if (detalle && !ok) {
130
+ for (const linea of String(detalle).split('\n')) {
131
+ console.log(` ${linea}`);
132
+ }
133
+ }
134
+ }
135
+
136
+ // ── Check 1: contadores ──────────────────────────────────────────────────────
137
+
138
+ function check1Contadores() {
139
+ if (opts.only && opts.only !== 1) return;
140
+ console.log(c(COLOR_DIM, '\n[1] Contadores: INVENTARIO.md / README.md / docs vs disco'));
141
+
142
+ const real = {
143
+ agentes: contarEntradasDirectorio('agentes', { filesOnly: true, ext: '.md' })
144
+ - (fs.existsSync(path.join(RAIZ, 'agentes', 'README.md')) ? 1 : 0),
145
+ skills: contarEntradasDirectorio('habilidades', { dirsOnly: true }),
146
+ comandos: contarEntradasDirectorio('comandos/swl', { filesOnly: true, ext: '.md' }),
147
+ reglas: contarReglasMd(),
148
+ hooks: contarHooksEjecutables(),
149
+ };
150
+
151
+ // Corregir agentes: descartar archivos `_*.md` (fragmentos compartidos)
152
+ const dirAgentes = path.join(RAIZ, 'agentes');
153
+ real.agentes = fs.readdirSync(dirAgentes)
154
+ .filter(n => n.endsWith('.md') && !n.startsWith('_') && n !== 'README.md')
155
+ .length;
156
+
157
+ // Cargar lo que dicen los manifiestos canónicos. INVENTARIO.md usa una
158
+ // tabla del tipo `| Agentes SWL | 60 |` así que extraemos por fila.
159
+ const inventario = leerArchivo('INVENTARIO.md') || '';
160
+ const extraerCelda = (regex) => {
161
+ const m = inventario.match(regex);
162
+ return m ? Number(m[1]) : null;
163
+ };
164
+ const declarado = {
165
+ agentes: extraerCelda(/\|\s*Agentes[^|]*\|\s*(\d+)\s*\|/i),
166
+ skills: extraerCelda(/\|\s*Habilidades[^|]*\|\s*(\d+)\s*\|/i)
167
+ || extraerCelda(/\|\s*Skills[^|]*\|\s*(\d+)\s*\|/i),
168
+ comandos: extraerCelda(/\|\s*Comandos[^|]*\|\s*(\d+)\s*\|/i),
169
+ reglas: (() => {
170
+ // INVENTARIO.md separa "Reglas base" + "Reglas por lenguaje".
171
+ const base = extraerCelda(/\|\s*Reglas base[^|]*\|\s*(\d+)\s*\|/i) || 0;
172
+ const lang = extraerCelda(/\|\s*Reglas por lenguaje[^|]*\|\s*(\d+)\s*\|/i) || 0;
173
+ const total = extraerCelda(/\|\s*Reglas\s*\|\s*(\d+)\s*\|/i);
174
+ if (total) return total;
175
+ if (base + lang > 0) return base + lang;
176
+ return null;
177
+ })(),
178
+ hooks: extraerCelda(/\|\s*Hooks\s*\|\s*(\d+)\s*\|/i),
179
+ };
180
+
181
+ for (const cat of Object.keys(real)) {
182
+ if (declarado[cat] == null) {
183
+ reportar(1, `INVENTARIO.md no declara ${cat}`, false,
184
+ `Real en disco: ${real[cat]}; INVENTARIO.md no incluye un patrón "(\\d+) ${cat}"`);
185
+ } else if (Number(declarado[cat]) === real[cat]) {
186
+ reportar(1, `INVENTARIO.md ${cat}: ${real[cat]}`, true);
187
+ } else {
188
+ reportar(1, `INVENTARIO.md ${cat} drift`, false,
189
+ `Real en disco: ${real[cat]}; INVENTARIO.md declara: ${declarado[cat]}`);
190
+ }
191
+ }
192
+ }
193
+
194
+ // ── Check 2: comandos/swl/*.md vs docs ──────────────────────────────────────
195
+
196
+ function check2Comandos() {
197
+ if (opts.only && opts.only !== 2) return;
198
+ console.log(c(COLOR_DIM, '\n[2] Comandos /swl:* en disco vs COMANDOS.md y MANUAL_USO.md'));
199
+
200
+ const dirAbs = path.join(RAIZ, 'comandos/swl');
201
+ if (!fs.existsSync(dirAbs)) {
202
+ reportar(2, 'comandos/swl/ no existe', false, 'Directorio faltante');
203
+ return;
204
+ }
205
+
206
+ const archivos = fs.readdirSync(dirAbs)
207
+ .filter(n => n.endsWith('.md') && !n.startsWith('_') && n !== 'README.md');
208
+
209
+ const comandosMd = leerArchivo('COMANDOS.md') || '';
210
+ const manualUsoMd = leerArchivo('MANUAL_USO.md') || '';
211
+
212
+ // Check #2 reporta WARN (no FAIL) cuando un comando no está en docs.
213
+ // Razón: la deuda de documentación granular por comando es preexistente
214
+ // y resolverla está fuera del scope del verificador. El verificador
215
+ // marca los gaps para que se vayan cerrando incrementalmente.
216
+ let pendientes = 0;
217
+ let documentados = 0;
218
+ const sinDocumentar = [];
219
+ for (const archivo of archivos) {
220
+ const nombre = archivo.replace(/\.md$/, '');
221
+ const refSlash = `/swl:${nombre}`;
222
+ const enComandos = comandosMd.includes(refSlash);
223
+ const enManual = manualUsoMd.includes(refSlash);
224
+ if (!enComandos || !enManual) {
225
+ pendientes++;
226
+ const faltas = [];
227
+ if (!enComandos) faltas.push('COMANDOS.md');
228
+ if (!enManual) faltas.push('MANUAL_USO.md');
229
+ sinDocumentar.push(`${refSlash} (falta en ${faltas.join(' + ')})`);
230
+ } else {
231
+ documentados++;
232
+ }
233
+ }
234
+
235
+ if (pendientes === 0) {
236
+ reportar(2, `${archivos.length} comandos /swl:* documentados en COMANDOS.md y MANUAL_USO.md`, true);
237
+ } else {
238
+ // WARN consolidado: no falla el verificador pero lista los gaps
239
+ const colorWarn = tty ? COLOR_WARN : '';
240
+ const mark = tty ? `${COLOR_WARN}[WARN]${COLOR_RESET}` : '[WARN]';
241
+ console.log(` ${mark} check #2 — ${pendientes} comandos sin documentar (de ${archivos.length} en disco)`);
242
+ if (!opts.quiet) {
243
+ for (const item of sinDocumentar) {
244
+ console.log(` ${c(COLOR_DIM, '- ' + item)}`);
245
+ }
246
+ console.log(` ${c(COLOR_DIM, '(WARN no falla el verificador; documentar incremental)')}`);
247
+ }
248
+ // Marca como OK porque es WARN, no FAIL — la deuda es preexistente
249
+ resultados.push({ check: 2, etiqueta: `${documentados}/${archivos.length} comandos documentados`, ok: true, detalle: null });
250
+ }
251
+ }
252
+
253
+ // ── Check 3: flags booleanas vs docs ────────────────────────────────────────
254
+
255
+ function check3Flags() {
256
+ if (opts.only && opts.only !== 3) return;
257
+ console.log(c(COLOR_DIM, '\n[3] Flags booleanas del parser vs bin --help y COMANDOS.md'));
258
+
259
+ const parser = leerArchivo('scripts/lib/parsear-opciones.js') || '';
260
+ const binHelp = leerArchivo('bin/swl-ses.js') || '';
261
+ const comandosMd = leerArchivo('COMANDOS.md') || '';
262
+
263
+ // Extraer las booleanas del parser (busca el array BOOLEANAS)
264
+ const matchBool = parser.match(/const BOOLEANAS\s*=\s*\[([\s\S]*?)\];/);
265
+ if (!matchBool) {
266
+ reportar(3, 'parsear-opciones.js no exporta BOOLEANAS', false,
267
+ 'No se encontró el array BOOLEANAS en el parser');
268
+ return;
269
+ }
270
+
271
+ const booleanas = (matchBool[1].match(/['"]([^'"]+)['"]/g) || [])
272
+ .map(s => s.replace(/['"]/g, ''))
273
+ .filter(b => !['simular', 'forzar'].includes(b)); // alias en español ya cubiertos
274
+
275
+ // Flags críticas que SÍ deben estar documentadas (subset)
276
+ const criticas = ['tui', 'no-tui', 'with-mcp', 'all-langs', 'force', 'dry-run', 'global'];
277
+
278
+ let fallas = 0;
279
+ for (const flag of criticas) {
280
+ if (!booleanas.includes(flag)) {
281
+ // Si la flag no está en el parser tampoco; eso es señalable pero no fail aquí
282
+ continue;
283
+ }
284
+ const enBinHelp = binHelp.includes(`--${flag}`);
285
+ const enComandosMd = comandosMd.includes(`--${flag}`);
286
+ if (!enBinHelp || !enComandosMd) {
287
+ fallas++;
288
+ const faltas = [];
289
+ if (!enBinHelp) faltas.push('bin/swl-ses.js (--help)');
290
+ if (!enComandosMd) faltas.push('COMANDOS.md');
291
+ reportar(3, `Flag --${flag} sin documentar en ${faltas.join(' + ')}`, false,
292
+ `Parser la declara como booleana pero falta en docs`);
293
+ }
294
+ }
295
+ if (fallas === 0) {
296
+ reportar(3, `${criticas.length} flags críticas documentadas en bin --help y COMANDOS.md`, true);
297
+ }
298
+ }
299
+
300
+ // ── Check 4: versiones ──────────────────────────────────────────────────────
301
+
302
+ function check4Versiones() {
303
+ if (opts.only && opts.only !== 4) return;
304
+ console.log(c(COLOR_DIM, '\n[4] Versión de package.json vs encabezados de docs'));
305
+
306
+ let version;
307
+ try {
308
+ version = require(path.join(RAIZ, 'package.json')).version;
309
+ } catch (_) {
310
+ reportar(4, 'package.json no parsea', false);
311
+ return;
312
+ }
313
+
314
+ const docs = ['CLAUDE.md', 'README.md', 'AGENTS.md', 'COMANDOS.md', 'MANUAL_USO.md', 'INSTALACION.md'];
315
+ let fallas = 0;
316
+ for (const doc of docs) {
317
+ const contenido = leerArchivo(doc);
318
+ if (!contenido) {
319
+ fallas++;
320
+ reportar(4, `${doc} no se puede leer`, false);
321
+ continue;
322
+ }
323
+ const primeraLinea = contenido.split('\n')[0] || '';
324
+ if (!primeraLinea.includes(version)) {
325
+ fallas++;
326
+ reportar(4, `${doc} encabezado sin v${version}`, false,
327
+ `Primera línea: "${primeraLinea.slice(0, 100)}"`);
328
+ }
329
+ }
330
+ if (fallas === 0) {
331
+ reportar(4, `Encabezados de ${docs.length} docs consistentes con v${version}`, true);
332
+ }
333
+ }
334
+
335
+ // ── Check 5: pantallas TUI ───────────────────────────────────────────────────
336
+
337
+ function check5Tui() {
338
+ if (opts.only && opts.only !== 5) return;
339
+ console.log(c(COLOR_DIM, '\n[5] Pantallas TUI vs menciones en MANUAL_USO.md'));
340
+
341
+ const dirAbs = path.join(RAIZ, 'scripts/tui/pantallas');
342
+ if (!fs.existsSync(dirAbs)) {
343
+ // Si no hay TUI (pre-v1.6.0), saltar el check sin fallar
344
+ reportar(5, 'scripts/tui/pantallas/ no existe (TUI no instalado)', true);
345
+ return;
346
+ }
347
+
348
+ const pantallas = fs.readdirSync(dirAbs)
349
+ .filter(n => n.endsWith('.js'))
350
+ .map(n => n.replace(/\.js$/, ''));
351
+
352
+ const manualUsoMd = (leerArchivo('MANUAL_USO.md') || '').toLowerCase();
353
+
354
+ // Mapeo de nombre de archivo a término que debe aparecer en docs
355
+ const terminos = {
356
+ 'welcome': ['welcome', 'bienvenida'],
357
+ 'menu-principal': ['menú principal', 'menu principal'],
358
+ 'install-wizard': ['wizard install', 'install wizard', 'wizard de instalación', 'instalador tui'],
359
+ 'update-wizard': ['wizard update', 'update wizard', 'wizard de actualización'],
360
+ 'uninstall-wizard': ['uninstall', 'desinstal'],
361
+ 'inspect': ['inspect'],
362
+ 'progreso': ['progreso', 'barra de progreso'],
363
+ 'resumen': ['resumen', 'pantalla resumen'],
364
+ };
365
+
366
+ let fallas = 0;
367
+ for (const pantalla of pantallas) {
368
+ const expectedTerms = terminos[pantalla];
369
+ if (!expectedTerms) continue; // archivo no es una pantalla documentable
370
+ const algunoPresente = expectedTerms.some(t => manualUsoMd.includes(t.toLowerCase()));
371
+ if (!algunoPresente) {
372
+ fallas++;
373
+ reportar(5, `Pantalla "${pantalla}" sin mención en MANUAL_USO.md`, false,
374
+ `Esperaba al menos uno de: ${expectedTerms.join(', ')}`);
375
+ }
376
+ }
377
+ if (fallas === 0) {
378
+ const documentables = Object.keys(terminos).length;
379
+ reportar(5, `${documentables} pantallas TUI mencionadas en MANUAL_USO.md`, true);
380
+ }
381
+ }
382
+
383
+ // ── main ──────────────────────────────────────────────────────────────────────
384
+
385
+ function main() {
386
+ console.log(c(COLOR_DIM, 'Verificador docs-vs-código — swl-ses\n' + '═'.repeat(60)));
387
+
388
+ check1Contadores();
389
+ check2Comandos();
390
+ check3Flags();
391
+ check4Versiones();
392
+ check5Tui();
393
+
394
+ const fails = resultados.filter(r => !r.ok).length;
395
+ const total = resultados.length;
396
+
397
+ console.log('\n' + '─'.repeat(60));
398
+ if (fails === 0) {
399
+ console.log(c(COLOR_OK, `✓ ${total} checks OK — docs alineadas con código`));
400
+ process.exit(0);
401
+ } else {
402
+ console.log(c(COLOR_FAIL, `✗ ${fails}/${total} checks con drift`));
403
+ console.log(c(COLOR_DIM, 'Revisa los hallazgos arriba. Las menciones marcadas FAIL deben'));
404
+ console.log(c(COLOR_DIM, 'actualizarse antes del próximo merge.'));
405
+ process.exit(1);
406
+ }
407
+ }
408
+
409
+ if (require.main === module) {
410
+ try {
411
+ main();
412
+ } catch (err) {
413
+ console.error(c(COLOR_FAIL, `Error de ejecución: ${err.message}`));
414
+ if (process.env.SWL_DEBUG) console.error(err.stack);
415
+ process.exit(2);
416
+ }
417
+ }
418
+
419
+ module.exports = {
420
+ check1Contadores,
421
+ check2Comandos,
422
+ check3Flags,
423
+ check4Versiones,
424
+ check5Tui,
425
+ };