@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.
- package/CLAUDE.md +1 -1
- package/README.md +19 -2
- package/bin/swl-ses.js +49 -7
- package/hooks/extraccion-aprendizajes.js +11 -0
- package/manifiestos/skills-lock.json +46 -18
- package/package.json +4 -3
- package/plugin.json +3 -1
- package/scripts/desinstalar.js +105 -24
- package/scripts/instalador.js +55 -4
- package/scripts/lib/parsear-opciones.js +3 -0
- package/scripts/lib/ui.js +148 -22
- package/scripts/tui/componentes/selector-multi.js +189 -0
- package/scripts/tui/componentes/selector-unico.js +158 -0
- package/scripts/tui/ejecutores.js +375 -0
- package/scripts/tui/index.js +162 -0
- package/scripts/tui/lib/colores.js +129 -0
- package/scripts/tui/lib/render.js +264 -0
- package/scripts/tui/lib/teclas.js +113 -0
- package/scripts/tui/pantallas/inspect.js +173 -0
- package/scripts/tui/pantallas/install-wizard.js +334 -0
- package/scripts/tui/pantallas/menu-principal.js +52 -0
- package/scripts/tui/pantallas/progreso.js +274 -0
- package/scripts/tui/pantallas/resumen.js +132 -0
- package/scripts/tui/pantallas/uninstall-wizard.js +208 -0
- package/scripts/tui/pantallas/update-wizard.js +232 -0
- package/scripts/tui/pantallas/welcome.js +187 -0
- package/scripts/verificar-docs-vs-codigo.js +425 -0
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Ejecutores TUI — conectan los wizards con scripts/instalador.js y
|
|
5
|
+
* scripts/actualizar.js a través del callback `onProgress`.
|
|
6
|
+
*
|
|
7
|
+
* Diseño:
|
|
8
|
+
* - El wizard devuelve un plan (opciones del instalador).
|
|
9
|
+
* - Se crea la pantalla Progreso con las categorías esperadas.
|
|
10
|
+
* - Se invoca al instalador con onProgress conectado a la pantalla.
|
|
11
|
+
* - Al terminar, se cierra Progreso y se muestra Resumen.
|
|
12
|
+
*
|
|
13
|
+
* Las funciones son async y devuelven el resultado de la operación
|
|
14
|
+
* (sin tirar excepciones — los errores quedan en el objeto resultado).
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const path = require('path');
|
|
18
|
+
|
|
19
|
+
const { crearProgreso } = require('./pantallas/progreso');
|
|
20
|
+
const { mostrarResumen } = require('./pantallas/resumen');
|
|
21
|
+
|
|
22
|
+
const RAIZ_PKG = path.resolve(__dirname, '..', '..');
|
|
23
|
+
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
// Categorías que tracker el progreso. Total es estimación inicial — el
|
|
26
|
+
// instalador puede emitir set-total para corregirlo si la cifra exacta
|
|
27
|
+
// se conoce solo en runtime (depende del perfil).
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
|
|
30
|
+
function _categoriasDesdeOpciones(opciones) {
|
|
31
|
+
// Para los totales reales se podrían leer manifiestos. Por simplicidad,
|
|
32
|
+
// empezamos con totales nominales del proyecto y se ajustan con set-total
|
|
33
|
+
// si el instalador los provee.
|
|
34
|
+
return [
|
|
35
|
+
{ nombre: 'agentes', etiqueta: 'Agentes', total: 0 },
|
|
36
|
+
{ nombre: 'habilidades', etiqueta: 'Skills', total: 0 },
|
|
37
|
+
{ nombre: 'comandos', etiqueta: 'Comandos', total: 0 },
|
|
38
|
+
{ nombre: 'reglas', etiqueta: 'Reglas', total: 0 },
|
|
39
|
+
{ nombre: 'hooks', etiqueta: 'Hooks', total: 0 },
|
|
40
|
+
{ nombre: 'schemas', etiqueta: 'Schemas', total: 0 },
|
|
41
|
+
{ nombre: 'plantillas', etiqueta: 'Plantillas', total: 0 },
|
|
42
|
+
];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function _calcularTotalesDelPlan(opciones) {
|
|
46
|
+
// Calcula el total estimado leyendo manifiestos/perfiles.json + modulos.json
|
|
47
|
+
// mediante resolverPerfil, que devuelve { perfil, modulos, archivos, warnings }.
|
|
48
|
+
try {
|
|
49
|
+
const { resolverPerfil } = require('../lib/manifiestos');
|
|
50
|
+
const resolucion = resolverPerfil(opciones.profile || 'core', {});
|
|
51
|
+
if (!resolucion || !Array.isArray(resolucion.archivos)) return {};
|
|
52
|
+
const totales = {};
|
|
53
|
+
for (const archivo of resolucion.archivos) {
|
|
54
|
+
const tipo = archivo.tipo || 'otros';
|
|
55
|
+
totales[tipo] = (totales[tipo] || 0) + 1;
|
|
56
|
+
}
|
|
57
|
+
return totales;
|
|
58
|
+
} catch (_) {
|
|
59
|
+
return {};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ---------------------------------------------------------------------------
|
|
64
|
+
// Ejecutar Install
|
|
65
|
+
// ---------------------------------------------------------------------------
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Ejecuta el install con UI de progreso conectada.
|
|
69
|
+
*
|
|
70
|
+
* @param {object} opciones - resultado del wizard Install (target, profile, global, etc.)
|
|
71
|
+
* @returns {Promise<{ ok, totales, error? }>}
|
|
72
|
+
*/
|
|
73
|
+
async function ejecutarInstall(opciones) {
|
|
74
|
+
const categorias = _categoriasDesdeOpciones(opciones);
|
|
75
|
+
const totalesEstimados = _calcularTotalesDelPlan(opciones);
|
|
76
|
+
for (const cat of categorias) {
|
|
77
|
+
if (totalesEstimados[cat.nombre]) cat.total = totalesEstimados[cat.nombre];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const ctrl = crearProgreso({
|
|
81
|
+
titulo: `Instalando perfil "${opciones.profile}" en ${opciones.target} (${opciones.global ? 'global' : 'proyecto'})`,
|
|
82
|
+
categorias,
|
|
83
|
+
verbose: !!opciones.verbose,
|
|
84
|
+
});
|
|
85
|
+
ctrl.iniciar();
|
|
86
|
+
|
|
87
|
+
let resultadoInstalador = null;
|
|
88
|
+
let error = null;
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
const install = require('../instalador');
|
|
92
|
+
const fn = typeof install === 'function' ? install : install.install;
|
|
93
|
+
resultadoInstalador = await fn({
|
|
94
|
+
...opciones,
|
|
95
|
+
onProgress: (evento) => ctrl.onEvento(evento),
|
|
96
|
+
});
|
|
97
|
+
ctrl.finalizar({
|
|
98
|
+
ok: true,
|
|
99
|
+
mensaje: opciones.dry_run
|
|
100
|
+
? 'Dry-run completado (no se modificaron archivos)'
|
|
101
|
+
: 'Instalación completada con éxito',
|
|
102
|
+
});
|
|
103
|
+
} catch (e) {
|
|
104
|
+
error = e;
|
|
105
|
+
ctrl.finalizar({
|
|
106
|
+
ok: false,
|
|
107
|
+
mensaje: `Error: ${e.message}`,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
await ctrl.esperarSalida();
|
|
112
|
+
|
|
113
|
+
// Resumen
|
|
114
|
+
const tabla = [
|
|
115
|
+
['Runtime', opciones.target],
|
|
116
|
+
['Perfil', opciones.profile],
|
|
117
|
+
['Scope', opciones.global ? 'global' : 'proyecto'],
|
|
118
|
+
];
|
|
119
|
+
if (opciones.with_mcp) tabla.push(['MCP', 'configurado']);
|
|
120
|
+
if (opciones.dry_run) tabla.push(['Modo', 'dry-run (sin escribir)']);
|
|
121
|
+
if (opciones.stacks?.length > 0) tabla.push(['Stacks', opciones.stacks.join(', ')]);
|
|
122
|
+
|
|
123
|
+
await mostrarResumen({
|
|
124
|
+
operacion: 'install',
|
|
125
|
+
ok: !error,
|
|
126
|
+
tituloPrincipal: error ? 'Falló la instalación' : 'Instalación completada',
|
|
127
|
+
mensajeFinal: error ? error.message : undefined,
|
|
128
|
+
tabla,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
return {
|
|
132
|
+
ok: !error,
|
|
133
|
+
error: error ? error.message : null,
|
|
134
|
+
resultado: resultadoInstalador,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// ---------------------------------------------------------------------------
|
|
139
|
+
// Ejecutar Update
|
|
140
|
+
// ---------------------------------------------------------------------------
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Ejecuta el update con UI de progreso. Itera por cada runtime+scope del
|
|
144
|
+
* plan, llamando al instalador con force=true y onProgress conectado.
|
|
145
|
+
*
|
|
146
|
+
* @param {object} planUpdate - resultado del wizard Update
|
|
147
|
+
* @returns {Promise<{ ok, actualizados, errores }>}
|
|
148
|
+
*/
|
|
149
|
+
async function ejecutarUpdate(planUpdate) {
|
|
150
|
+
const { plan, versionPaquete, verbose } = planUpdate;
|
|
151
|
+
const categorias = _categoriasDesdeOpciones({});
|
|
152
|
+
|
|
153
|
+
const ctrl = crearProgreso({
|
|
154
|
+
titulo: `Actualizando ${plan.runtimes.length} runtime(s) a v${versionPaquete}`,
|
|
155
|
+
categorias,
|
|
156
|
+
verbose: !!verbose,
|
|
157
|
+
});
|
|
158
|
+
ctrl.iniciar();
|
|
159
|
+
|
|
160
|
+
let actualizados = 0;
|
|
161
|
+
const errores = [];
|
|
162
|
+
|
|
163
|
+
const install = require('../instalador');
|
|
164
|
+
const fn = typeof install === 'function' ? install : install.install;
|
|
165
|
+
|
|
166
|
+
for (const runtime of plan.runtimes) {
|
|
167
|
+
ctrl.onEvento({
|
|
168
|
+
tipo: 'log',
|
|
169
|
+
linea: `→ Actualizando ${runtime.runtimeNombre} (${runtime.scope})...`,
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
try {
|
|
173
|
+
await fn({
|
|
174
|
+
target: runtime.runtimeId,
|
|
175
|
+
profile: runtime.perfil,
|
|
176
|
+
global: runtime.esGlobal,
|
|
177
|
+
force: true,
|
|
178
|
+
versionAnterior: runtime.version,
|
|
179
|
+
versionActual: versionPaquete,
|
|
180
|
+
onProgress: (evento) => ctrl.onEvento(evento),
|
|
181
|
+
});
|
|
182
|
+
actualizados++;
|
|
183
|
+
ctrl.onEvento({
|
|
184
|
+
tipo: 'log',
|
|
185
|
+
linea: ` ✓ ${runtime.runtimeNombre} (${runtime.scope}) actualizado`,
|
|
186
|
+
});
|
|
187
|
+
} catch (e) {
|
|
188
|
+
errores.push({ runtime: runtime.id, error: e.message });
|
|
189
|
+
ctrl.onEvento({
|
|
190
|
+
tipo: 'log',
|
|
191
|
+
linea: ` ✗ ${runtime.runtimeNombre}: ${e.message}`,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const ok = errores.length === 0;
|
|
197
|
+
ctrl.finalizar({
|
|
198
|
+
ok,
|
|
199
|
+
mensaje: ok
|
|
200
|
+
? `${actualizados} runtime(s) actualizado(s)`
|
|
201
|
+
: `${actualizados} ok, ${errores.length} con error`,
|
|
202
|
+
});
|
|
203
|
+
await ctrl.esperarSalida();
|
|
204
|
+
|
|
205
|
+
const tabla = [
|
|
206
|
+
['Versión objetivo', `v${versionPaquete}`],
|
|
207
|
+
['Runtimes en plan', String(plan.runtimes.length)],
|
|
208
|
+
['Actualizados', String(actualizados)],
|
|
209
|
+
['Errores', String(errores.length)],
|
|
210
|
+
['Categorías', plan.categorias.join(', ')],
|
|
211
|
+
];
|
|
212
|
+
|
|
213
|
+
await mostrarResumen({
|
|
214
|
+
operacion: 'update',
|
|
215
|
+
ok,
|
|
216
|
+
tituloPrincipal: ok ? 'Actualización completada' : 'Actualización con errores',
|
|
217
|
+
mensajeFinal: errores.length > 0
|
|
218
|
+
? `${errores.length} runtime(s) fallaron — revisa los logs`
|
|
219
|
+
: undefined,
|
|
220
|
+
tabla,
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
return { ok, actualizados, errores };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// ---------------------------------------------------------------------------
|
|
227
|
+
// Ejecutar Uninstall (TUI completo, Fase 5)
|
|
228
|
+
// ---------------------------------------------------------------------------
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Ejecuta el uninstall con UI de progreso. Itera por cada instalación del
|
|
232
|
+
* plan invocando scripts/desinstalar.js con onProgress conectado.
|
|
233
|
+
*
|
|
234
|
+
* @param {object} planUninstall - resultado del wizard Uninstall
|
|
235
|
+
* @returns {Promise<{ ok, totalEliminados, totalBloques, errores }>}
|
|
236
|
+
*/
|
|
237
|
+
async function ejecutarUninstall(planUninstall) {
|
|
238
|
+
if (!planUninstall || !planUninstall.plan) {
|
|
239
|
+
// Sin plan (caller no pasó datos del wizard) — devolver pendiente
|
|
240
|
+
await mostrarResumen({
|
|
241
|
+
operacion: 'uninstall',
|
|
242
|
+
ok: false,
|
|
243
|
+
tituloPrincipal: 'Uninstall sin plan',
|
|
244
|
+
mensajeFinal: 'Falta el resultado del wizard. Llama ejecutarUninstall(planUninstall) con el plan completo.',
|
|
245
|
+
tabla: [],
|
|
246
|
+
});
|
|
247
|
+
return { ok: false, pendiente: true };
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const { seleccionadas } = planUninstall.plan;
|
|
251
|
+
|
|
252
|
+
const { crearProgreso: crear } = require('./pantallas/progreso');
|
|
253
|
+
const ctrl = crear({
|
|
254
|
+
titulo: `Desinstalando ${seleccionadas.length} instalación(es) SWL`,
|
|
255
|
+
categorias: [
|
|
256
|
+
{ nombre: 'archivos-eliminados', etiqueta: 'Archivos', total: 0 },
|
|
257
|
+
{ nombre: 'bloques-limpiados', etiqueta: 'Bloques', total: 0 },
|
|
258
|
+
{ nombre: 'hooks-quitados', etiqueta: 'Hooks', total: 0 },
|
|
259
|
+
],
|
|
260
|
+
verbose: !!planUninstall.verbose,
|
|
261
|
+
});
|
|
262
|
+
ctrl.iniciar();
|
|
263
|
+
|
|
264
|
+
let totalEliminados = 0;
|
|
265
|
+
let totalBloques = 0;
|
|
266
|
+
let totalHooks = 0;
|
|
267
|
+
const errores = [];
|
|
268
|
+
|
|
269
|
+
const uninstall = require('../desinstalar');
|
|
270
|
+
|
|
271
|
+
for (const inst of seleccionadas) {
|
|
272
|
+
ctrl.onEvento({
|
|
273
|
+
tipo: 'log',
|
|
274
|
+
linea: `→ Desinstalando ${inst.runtimeNombre} (${inst.scope})...`,
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
try {
|
|
278
|
+
const resultado = uninstall({
|
|
279
|
+
target: inst.runtimeId,
|
|
280
|
+
global: inst.esGlobal,
|
|
281
|
+
onProgress: (evento) => {
|
|
282
|
+
// Mapear eventos del desinstalador a categorías de la pantalla
|
|
283
|
+
if (evento.tipo === 'archivo-eliminado') {
|
|
284
|
+
ctrl.onEvento({
|
|
285
|
+
tipo: 'archivo-copiado', // re-usa el contador de progreso
|
|
286
|
+
componente: 'archivos-eliminados',
|
|
287
|
+
archivo: evento.archivo,
|
|
288
|
+
});
|
|
289
|
+
} else if (evento.tipo === 'bloque-eliminado') {
|
|
290
|
+
ctrl.onEvento({
|
|
291
|
+
tipo: 'archivo-copiado',
|
|
292
|
+
componente: 'bloques-limpiados',
|
|
293
|
+
archivo: evento.archivo,
|
|
294
|
+
});
|
|
295
|
+
} else if (evento.tipo === 'hooks-desregistrados') {
|
|
296
|
+
for (let i = 0; i < evento.cuenta; i++) {
|
|
297
|
+
ctrl.onEvento({
|
|
298
|
+
tipo: 'archivo-copiado',
|
|
299
|
+
componente: 'hooks-quitados',
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
} else if (evento.tipo === 'log') {
|
|
303
|
+
ctrl.onEvento(evento);
|
|
304
|
+
} else if (evento.tipo === 'error') {
|
|
305
|
+
ctrl.onEvento({
|
|
306
|
+
tipo: 'log',
|
|
307
|
+
linea: ` ✗ ${evento.archivo || ''}: ${evento.mensaje}`,
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
},
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
totalEliminados += resultado.eliminados || 0;
|
|
314
|
+
totalBloques += resultado.bloquesEliminados || 0;
|
|
315
|
+
totalHooks += resultado.hooksDesregistrados || 0;
|
|
316
|
+
|
|
317
|
+
ctrl.onEvento({
|
|
318
|
+
tipo: 'log',
|
|
319
|
+
linea: ` ✓ ${inst.runtimeNombre} (${inst.scope}) limpiado`,
|
|
320
|
+
});
|
|
321
|
+
} catch (e) {
|
|
322
|
+
errores.push({ instalacion: inst.id, error: e.message });
|
|
323
|
+
ctrl.onEvento({
|
|
324
|
+
tipo: 'log',
|
|
325
|
+
linea: ` ✗ ${inst.runtimeNombre}: ${e.message}`,
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const ok = errores.length === 0;
|
|
331
|
+
ctrl.finalizar({
|
|
332
|
+
ok,
|
|
333
|
+
mensaje: ok
|
|
334
|
+
? `${totalEliminados} archivos eliminados, ${totalBloques} bloques limpiados`
|
|
335
|
+
: `${errores.length} instalación(es) con error`,
|
|
336
|
+
});
|
|
337
|
+
await ctrl.esperarSalida();
|
|
338
|
+
|
|
339
|
+
const tabla = [
|
|
340
|
+
['Instalaciones procesadas', String(seleccionadas.length)],
|
|
341
|
+
['Archivos eliminados', String(totalEliminados)],
|
|
342
|
+
['Bloques CLAUDE.md limpiados', String(totalBloques)],
|
|
343
|
+
['Hooks desregistrados', String(totalHooks)],
|
|
344
|
+
];
|
|
345
|
+
if (errores.length > 0) {
|
|
346
|
+
tabla.push(['Errores', String(errores.length)]);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
await mostrarResumen({
|
|
350
|
+
operacion: 'uninstall',
|
|
351
|
+
ok,
|
|
352
|
+
tituloPrincipal: ok ? 'Desinstalación completada' : 'Desinstalación con errores',
|
|
353
|
+
mensajeFinal: ok
|
|
354
|
+
? '_userland/ y APRENDIZAJES.md fueron preservados.'
|
|
355
|
+
: 'Algunas instalaciones fallaron — revisa el log.',
|
|
356
|
+
tabla,
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
return {
|
|
360
|
+
ok,
|
|
361
|
+
totalEliminados,
|
|
362
|
+
totalBloques,
|
|
363
|
+
totalHooks,
|
|
364
|
+
errores,
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
module.exports = {
|
|
369
|
+
ejecutarInstall,
|
|
370
|
+
ejecutarUpdate,
|
|
371
|
+
ejecutarUninstall,
|
|
372
|
+
// exports para tests
|
|
373
|
+
_calcularTotalesDelPlan,
|
|
374
|
+
_categoriasDesdeOpciones,
|
|
375
|
+
};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Entry point del TUI de swl-ses.
|
|
5
|
+
*
|
|
6
|
+
* Flujo:
|
|
7
|
+
* 1. Welcome (pantalla de bienvenida + detección de instalaciones)
|
|
8
|
+
* 2. Menú principal (Install / Update / Inspect / Uninstall)
|
|
9
|
+
* 3. Wizard correspondiente
|
|
10
|
+
* 4. Ejecución con UI de progreso
|
|
11
|
+
* 5. Resumen final
|
|
12
|
+
* 6. Vuelve al menú principal (a menos que el usuario haya hecho Esc en el menú)
|
|
13
|
+
*
|
|
14
|
+
* En no-TTY, el TUI se desactiva automáticamente — cada pantalla devuelve
|
|
15
|
+
* un valor por defecto sin esperar input. Los caller deben detectar esa
|
|
16
|
+
* salida y caer al CLI clásico si quieren UX interactivo.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const { mostrarWelcome } = require('./pantallas/welcome');
|
|
20
|
+
const { mostrarMenuPrincipal } = require('./pantallas/menu-principal');
|
|
21
|
+
const { ejecutarWizardInstall } = require('./pantallas/install-wizard');
|
|
22
|
+
const { ejecutarWizardUpdate } = require('./pantallas/update-wizard');
|
|
23
|
+
const { ejecutarWizardUninstall } = require('./pantallas/uninstall-wizard');
|
|
24
|
+
const { ejecutarInspect } = require('./pantallas/inspect');
|
|
25
|
+
const { ejecutarInstall, ejecutarUpdate, ejecutarUninstall } = require('./ejecutores');
|
|
26
|
+
const { mostrarResumen } = require('./pantallas/resumen');
|
|
27
|
+
const render = require('./lib/render');
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Lanza el flujo TUI completo. Devuelve cuando el usuario sale del menú
|
|
31
|
+
* principal con Esc.
|
|
32
|
+
*
|
|
33
|
+
* @param {object} [opciones]
|
|
34
|
+
* @param {string} [opciones.operacionInicial] - si está dado, salta el menú
|
|
35
|
+
* e inicia directamente en esa operación ('install' | 'update' | etc.)
|
|
36
|
+
* @returns {Promise<{ ok, motivo?, ultimaOperacion? }>}
|
|
37
|
+
*/
|
|
38
|
+
async function iniciarTui(opciones = {}) {
|
|
39
|
+
// Detección defensiva: si no hay TTY, no entrar al flujo interactivo
|
|
40
|
+
if (!render.ES_TTY || !process.stdin.isTTY) {
|
|
41
|
+
return { ok: false, motivo: 'no-tty', mensaje: 'TUI requiere terminal interactiva' };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// 1. Welcome (a menos que se haya pedido saltar)
|
|
45
|
+
if (!opciones.saltarWelcome) {
|
|
46
|
+
const w = await mostrarWelcome();
|
|
47
|
+
if (!w.continuar) {
|
|
48
|
+
return { ok: true, motivo: 'usuario-salio-welcome' };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 2. Loop principal: menú → operación → vuelve al menú
|
|
53
|
+
let ultimaOperacion = null;
|
|
54
|
+
while (true) {
|
|
55
|
+
let operacion = opciones.operacionInicial;
|
|
56
|
+
opciones.operacionInicial = null; // solo aplica la primera vez
|
|
57
|
+
|
|
58
|
+
if (!operacion) {
|
|
59
|
+
operacion = await mostrarMenuPrincipal();
|
|
60
|
+
if (!operacion) {
|
|
61
|
+
return { ok: true, motivo: 'usuario-salio-menu', ultimaOperacion };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
ultimaOperacion = operacion;
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
await _ejecutarOperacion(operacion);
|
|
69
|
+
} catch (e) {
|
|
70
|
+
// Mostrar error como pantalla de resumen y continuar
|
|
71
|
+
await mostrarResumen({
|
|
72
|
+
operacion,
|
|
73
|
+
ok: false,
|
|
74
|
+
tituloPrincipal: `Error en operación "${operacion}"`,
|
|
75
|
+
mensajeFinal: e.message,
|
|
76
|
+
tabla: [['Tipo de error', e.name || 'Error']],
|
|
77
|
+
proximosPasos: [
|
|
78
|
+
'Revisa los logs anteriores',
|
|
79
|
+
'Intenta de nuevo desde el menú',
|
|
80
|
+
'Si el error persiste: swl-ses doctor',
|
|
81
|
+
],
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// ---------------------------------------------------------------------------
|
|
88
|
+
// Despacho de operaciones
|
|
89
|
+
// ---------------------------------------------------------------------------
|
|
90
|
+
|
|
91
|
+
async function _ejecutarOperacion(operacion) {
|
|
92
|
+
switch (operacion) {
|
|
93
|
+
case 'install':
|
|
94
|
+
return _flujoInstall();
|
|
95
|
+
case 'update':
|
|
96
|
+
return _flujoUpdate();
|
|
97
|
+
case 'inspect':
|
|
98
|
+
return ejecutarInspect();
|
|
99
|
+
case 'uninstall':
|
|
100
|
+
return _flujoUninstall();
|
|
101
|
+
default:
|
|
102
|
+
throw new Error(`Operación no soportada: ${operacion}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async function _flujoInstall() {
|
|
107
|
+
const w = await ejecutarWizardInstall();
|
|
108
|
+
if (!w.exito) {
|
|
109
|
+
if (w.cancelado) return { ok: true, cancelado: true };
|
|
110
|
+
if (w.error) {
|
|
111
|
+
await mostrarResumen({
|
|
112
|
+
operacion: 'install',
|
|
113
|
+
ok: false,
|
|
114
|
+
tituloPrincipal: 'No se pudo iniciar la instalación',
|
|
115
|
+
mensajeFinal: w.error,
|
|
116
|
+
tabla: [],
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
return { ok: false };
|
|
120
|
+
}
|
|
121
|
+
return ejecutarInstall(w.opciones);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async function _flujoUpdate() {
|
|
125
|
+
const w = await ejecutarWizardUpdate();
|
|
126
|
+
if (!w.exito) {
|
|
127
|
+
if (w.cancelado) return { ok: true, cancelado: true };
|
|
128
|
+
if (w.error || w.vacio) {
|
|
129
|
+
await mostrarResumen({
|
|
130
|
+
operacion: 'update',
|
|
131
|
+
ok: false,
|
|
132
|
+
tituloPrincipal: w.vacio ? 'Nada que actualizar' : 'No se pudo iniciar la actualización',
|
|
133
|
+
mensajeFinal: w.error || 'Selección vacía',
|
|
134
|
+
tabla: [],
|
|
135
|
+
proximosPasos: w.sugerencia ? [w.sugerencia] : [],
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
return { ok: false };
|
|
139
|
+
}
|
|
140
|
+
return ejecutarUpdate(w);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async function _flujoUninstall() {
|
|
144
|
+
const w = await ejecutarWizardUninstall();
|
|
145
|
+
if (!w.exito) {
|
|
146
|
+
if (w.cancelado) return { ok: true, cancelado: true };
|
|
147
|
+
if (w.error || w.vacio) {
|
|
148
|
+
await mostrarResumen({
|
|
149
|
+
operacion: 'uninstall',
|
|
150
|
+
ok: false,
|
|
151
|
+
tituloPrincipal: w.vacio ? 'Nada seleccionado para desinstalar' : 'No se pudo iniciar la desinstalación',
|
|
152
|
+
mensajeFinal: w.error,
|
|
153
|
+
tabla: [],
|
|
154
|
+
proximosPasos: w.sugerencia ? [w.sugerencia] : [],
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
return { ok: false };
|
|
158
|
+
}
|
|
159
|
+
return ejecutarUninstall(w);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
module.exports = { iniciarTui };
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Paleta de colores ANSI para la TUI de swl-ses.
|
|
5
|
+
* Zero-deps. Respeta NO_COLOR. Detecta TTY.
|
|
6
|
+
*
|
|
7
|
+
* Diseño: las funciones siempre devuelven string. Si no hay color, devuelven
|
|
8
|
+
* el texto sin modificar — para que el caller pueda concatenar sin checks.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const SOPORTA_COLOR = !process.env.NO_COLOR && process.stdout.isTTY;
|
|
12
|
+
|
|
13
|
+
function _wrap(codigo, texto) {
|
|
14
|
+
return SOPORTA_COLOR ? `\x1b[${codigo}m${texto}\x1b[0m` : String(texto);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const colores = {
|
|
18
|
+
// Texto
|
|
19
|
+
negro: (t) => _wrap('30', t),
|
|
20
|
+
rojo: (t) => _wrap('31', t),
|
|
21
|
+
verde: (t) => _wrap('32', t),
|
|
22
|
+
amarillo: (t) => _wrap('33', t),
|
|
23
|
+
azul: (t) => _wrap('34', t),
|
|
24
|
+
magenta: (t) => _wrap('35', t),
|
|
25
|
+
cyan: (t) => _wrap('36', t),
|
|
26
|
+
blanco: (t) => _wrap('37', t),
|
|
27
|
+
gris: (t) => _wrap('90', t),
|
|
28
|
+
|
|
29
|
+
// Brillantes
|
|
30
|
+
rojoBr: (t) => _wrap('91', t),
|
|
31
|
+
verdeBr: (t) => _wrap('92', t),
|
|
32
|
+
amarilloBr: (t) => _wrap('93', t),
|
|
33
|
+
azulBr: (t) => _wrap('94', t),
|
|
34
|
+
cyanBr: (t) => _wrap('96', t),
|
|
35
|
+
|
|
36
|
+
// Estilos
|
|
37
|
+
negrita: (t) => _wrap('1', t),
|
|
38
|
+
dim: (t) => _wrap('2', t),
|
|
39
|
+
italica: (t) => _wrap('3', t),
|
|
40
|
+
subrayado: (t) => _wrap('4', t),
|
|
41
|
+
invertido: (t) => _wrap('7', t),
|
|
42
|
+
|
|
43
|
+
// Fondos
|
|
44
|
+
fondoAzul: (t) => _wrap('44', t),
|
|
45
|
+
fondoCyan: (t) => _wrap('46', t),
|
|
46
|
+
fondoGris: (t) => _wrap('100', t),
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// Semánticos (para usar en lugar de colores directos)
|
|
50
|
+
const semantico = {
|
|
51
|
+
exito: colores.verde,
|
|
52
|
+
error: colores.rojo,
|
|
53
|
+
warn: colores.amarillo,
|
|
54
|
+
info: colores.cyan,
|
|
55
|
+
hint: colores.dim,
|
|
56
|
+
enfasis: colores.negrita,
|
|
57
|
+
titulo: (t) => colores.negrita(colores.cyan(t)),
|
|
58
|
+
cursor: colores.cyanBr,
|
|
59
|
+
badge: (t) => colores.invertido(` ${t} `),
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// Iconos con fallback ASCII
|
|
63
|
+
const iconos = SOPORTA_COLOR ? {
|
|
64
|
+
check: '✓',
|
|
65
|
+
cross: '✗',
|
|
66
|
+
warn: '⚠',
|
|
67
|
+
arrow: '→',
|
|
68
|
+
star: '★',
|
|
69
|
+
info: 'ℹ',
|
|
70
|
+
punto: '•',
|
|
71
|
+
cursor: '❯',
|
|
72
|
+
cajaVacia: '○',
|
|
73
|
+
cajaLlena: '◉',
|
|
74
|
+
flechaArriba: '↑',
|
|
75
|
+
flechaAbajo: '↓',
|
|
76
|
+
} : {
|
|
77
|
+
check: '[OK]',
|
|
78
|
+
cross: '[X]',
|
|
79
|
+
warn: '[!]',
|
|
80
|
+
arrow: '->',
|
|
81
|
+
star: '*',
|
|
82
|
+
info: '[i]',
|
|
83
|
+
punto: '-',
|
|
84
|
+
cursor: '>',
|
|
85
|
+
cajaVacia: '[ ]',
|
|
86
|
+
cajaLlena: '[x]',
|
|
87
|
+
flechaArriba: '^',
|
|
88
|
+
flechaAbajo: 'v',
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// Caracteres de borde de caja (Unicode rounded fallback ASCII)
|
|
92
|
+
const borde = SOPORTA_COLOR ? {
|
|
93
|
+
// Borde rounded
|
|
94
|
+
esquinaSupIzq: '╭',
|
|
95
|
+
esquinaSupDer: '╮',
|
|
96
|
+
esquinaInfIzq: '╰',
|
|
97
|
+
esquinaInfDer: '╯',
|
|
98
|
+
horizontal: '─',
|
|
99
|
+
vertical: '│',
|
|
100
|
+
cruz: '┼',
|
|
101
|
+
tSup: '┬',
|
|
102
|
+
tInf: '┴',
|
|
103
|
+
tIzq: '├',
|
|
104
|
+
tDer: '┤',
|
|
105
|
+
|
|
106
|
+
// Borde doble (para énfasis)
|
|
107
|
+
dbHorizontal: '═',
|
|
108
|
+
dbVertical: '║',
|
|
109
|
+
dbEsqSupIzq: '╔',
|
|
110
|
+
dbEsqSupDer: '╗',
|
|
111
|
+
dbEsqInfIzq: '╚',
|
|
112
|
+
dbEsqInfDer: '╝',
|
|
113
|
+
} : {
|
|
114
|
+
esquinaSupIzq: '+', esquinaSupDer: '+',
|
|
115
|
+
esquinaInfIzq: '+', esquinaInfDer: '+',
|
|
116
|
+
horizontal: '-', vertical: '|',
|
|
117
|
+
cruz: '+', tSup: '+', tInf: '+', tIzq: '+', tDer: '+',
|
|
118
|
+
dbHorizontal: '=', dbVertical: '|',
|
|
119
|
+
dbEsqSupIzq: '+', dbEsqSupDer: '+',
|
|
120
|
+
dbEsqInfIzq: '+', dbEsqInfDer: '+',
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
module.exports = {
|
|
124
|
+
SOPORTA_COLOR,
|
|
125
|
+
colores,
|
|
126
|
+
semantico,
|
|
127
|
+
iconos,
|
|
128
|
+
borde,
|
|
129
|
+
};
|