@saulwade/swl-ses 2.1.0 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/CLAUDE.md +199 -196
  2. package/README.md +597 -579
  3. package/agentes/arquitecto-swl.md +0 -5
  4. package/agentes/backend-python-swl.md +0 -5
  5. package/agentes/implementador-swl.md +0 -5
  6. package/agentes/nemesis-auditor-swl.md +0 -5
  7. package/agentes/orquestador-swl.md +0 -5
  8. package/agentes/planificador-swl.md +0 -5
  9. package/agentes/revisor-codigo-swl.md +0 -5
  10. package/bin/swl-ses.js +63 -0
  11. package/comandos/swl/adoptar-proyecto.md +12 -14
  12. package/comandos/swl/aprender.md +30 -47
  13. package/comandos/swl/aprobar-plan.md +23 -35
  14. package/comandos/swl/autoresearch.md +12 -14
  15. package/comandos/swl/briefing.md +5 -8
  16. package/comandos/swl/checkpoint.md +10 -15
  17. package/comandos/swl/claudemd.md +12 -12
  18. package/comandos/swl/configurar-ci.md +20 -19
  19. package/comandos/swl/cron.md +10 -12
  20. package/comandos/swl/ejecutar-fase.md +10 -8
  21. package/comandos/swl/evolucionar.md +6 -11
  22. package/comandos/swl/inbox.md +10 -10
  23. package/comandos/swl/modelo.md +7 -9
  24. package/comandos/swl/notificaciones.md +19 -116
  25. package/comandos/swl/nuevo-proyecto.md +9 -14
  26. package/comandos/swl/release.md +19 -5
  27. package/comandos/swl/revisar-impacto.md +0 -5
  28. package/comandos/swl/status.md +333 -348
  29. package/comandos/swl/verificar.md +817 -813
  30. package/habilidades/agent-browser/SKILL.md +0 -5
  31. package/habilidades/angular-moderno/SKILL.md +0 -5
  32. package/habilidades/api-rest-diseno/SKILL.md +0 -5
  33. package/habilidades/aprendizaje-continuo/SKILL.md +0 -5
  34. package/habilidades/auth-patrones/SKILL.md +0 -5
  35. package/habilidades/build-errors-nextjs/SKILL.md +0 -5
  36. package/habilidades/changelog-generator/SKILL.md +174 -179
  37. package/habilidades/checklist-seguridad/SKILL.md +0 -5
  38. package/habilidades/contenedores-docker/SKILL.md +0 -5
  39. package/habilidades/datos-etl/SKILL.md +0 -5
  40. package/habilidades/doc-sync/SKILL.md +0 -5
  41. package/habilidades/extractor-de-aprendizajes/SKILL.md +0 -5
  42. package/habilidades/fastapi-experto/SKILL.md +0 -5
  43. package/habilidades/frontend-avanzado/SKILL.md +0 -5
  44. package/habilidades/iam-secretos/SKILL.md +0 -5
  45. package/habilidades/manejo-errores/SKILL.md +0 -5
  46. package/habilidades/mapear-codebase/SKILL.md +0 -5
  47. package/habilidades/meta-skills-estandar/SKILL.md +0 -5
  48. package/habilidades/monitoring-alertas/SKILL.md +0 -5
  49. package/habilidades/nextjs-experto/SKILL.md +0 -5
  50. package/habilidades/nextjs-testing/SKILL.md +0 -5
  51. package/habilidades/node-experto/SKILL.md +0 -5
  52. package/habilidades/orquestacion-async/SKILL.md +0 -5
  53. package/habilidades/patrones-python/SKILL.md +227 -232
  54. package/habilidades/planear-fase/SKILL.md +336 -341
  55. package/habilidades/postgresql-experto/SKILL.md +0 -5
  56. package/habilidades/prevencion-sobreingenieria/SKILL.md +0 -5
  57. package/habilidades/protocolo-revision-swl/SKILL.md +0 -5
  58. package/habilidades/react-experto/SKILL.md +0 -5
  59. package/habilidades/release-semver/SKILL.md +0 -5
  60. package/habilidades/swl-claudemd/SKILL.md +10 -11
  61. package/habilidades/tdd-workflow/SKILL.md +710 -715
  62. package/habilidades/testing-python/SKILL.md +335 -340
  63. package/habilidades/verificar-trabajo/SKILL.md +0 -5
  64. package/hooks/lib/evolution-tracker.js +191 -35
  65. package/hooks/lib/propose-step.js +1 -0
  66. package/llms.txt +1 -1
  67. package/manifiestos/canonical-hashes.json +656 -0
  68. package/manifiestos/modulos.json +3 -0
  69. package/manifiestos/skills-lock.json +71 -71
  70. package/package.json +1 -1
  71. package/plugin.json +1 -1
  72. package/scripts/auditar-claudemd.js +38 -0
  73. package/scripts/cli/aprobar-plan.js +73 -0
  74. package/scripts/cli/briefing.js +23 -0
  75. package/scripts/cli/ciclo-evolucion.js +26 -0
  76. package/scripts/cli/configurar-ci.js +40 -0
  77. package/scripts/cli/derivar-feature-list.js +25 -0
  78. package/scripts/cli/detectar-host.js +27 -0
  79. package/scripts/cli/diary-entry.js +69 -0
  80. package/scripts/cli/execution-state.js +18 -0
  81. package/scripts/cli/gateway-notify.js +41 -0
  82. package/scripts/cli/liberar-fase.js +42 -0
  83. package/scripts/cli/loop-telemetry.js +125 -0
  84. package/scripts/cli/mark-evolved.js +56 -0
  85. package/scripts/cli/metricas-dora.js +26 -0
  86. package/scripts/cli/near-duplicate.js +55 -0
  87. package/scripts/cli/notificaciones.js +123 -0
  88. package/scripts/cli/propose-step.js +29 -0
  89. package/scripts/cli/schedule-parse.js +19 -0
  90. package/scripts/cli/sugerir-modelo.js +20 -0
  91. package/scripts/cli/verificar-plan.js +36 -0
  92. package/scripts/cli/verificar-trazabilidad.js +35 -0
  93. package/scripts/derivar-feature-list.js +1 -0
  94. package/scripts/generar-canonical-hashes.js +147 -0
  95. package/scripts/instalador.js +126 -53
  96. package/scripts/lib/audit-evolved.js +71 -0
  97. package/scripts/lib/auditar-invocaciones-comandos.js +104 -0
  98. package/scripts/lib/canonical-hash.js +94 -0
  99. package/scripts/lib/evolved-fuente.js +138 -0
  100. package/scripts/lib/resolver-plan-fase.js +37 -0
  101. package/scripts/remediar-evolved-instaladas.js +239 -0
  102. package/scripts/validar.js +27 -0
  103. package/scripts/verificar-evolucion.js +36 -0
  104. package/scripts/verificar-release.js +33 -0
  105. package/scripts/verificar-trazabilidad.js +1 -1
  106. package/agentes/.evolved.json +0 -9
  107. package/comandos/swl/.evolved.json +0 -23
  108. package/habilidades/auth-patrones/.evolved.json +0 -9
  109. package/habilidades/extractor-de-aprendizajes/.evolved.json +0 -9
  110. package/habilidades/instalar-sistema/.evolved.json +0 -9
  111. package/habilidades/manejo-errores/.evolved.json +0 -9
  112. package/habilidades/node-experto/.evolved.json +0 -9
  113. package/habilidades/release-semver/.evolved.json +0 -9
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Wrapper CLI `swl-ses detectar-host` — determina si el CWD es el repo host de
5
+ * SWL o un proyecto consumidor. Reemplaza `node scripts/lib/detectar-host-swl.js`
6
+ * relativo al proyecto (roto downstream; ver docs/invocacion-cli-cross-scope.md).
7
+ *
8
+ * Uso: swl-ses detectar-host [--json]
9
+ */
10
+
11
+ const { detectarHostSwl } = require('../lib/detectar-host-swl');
12
+
13
+ function detectarHost(opciones = {}) {
14
+ const r = detectarHostSwl(process.cwd());
15
+ if (opciones && opciones.json) {
16
+ console.log(JSON.stringify(r, null, 2));
17
+ return;
18
+ }
19
+ if (r.esHost) {
20
+ console.log(`[host] ${r.razon}`);
21
+ } else {
22
+ console.log(`[consumidor] ${r.razon}`);
23
+ for (const s of r.sugerencias) console.log(` - ${s}`);
24
+ }
25
+ }
26
+
27
+ module.exports = detectarHost;
@@ -0,0 +1,69 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Wrapper CLI `swl-ses diary-entry` — construye y persiste una entrada de diario
5
+ * de sesión en .planning/sessions/diary/<id>.json. Reemplaza el inline
6
+ * `require('./scripts/lib/diary-entry')` relativo al proyecto (roto downstream;
7
+ * ver docs/invocacion-cli-cross-scope.md).
8
+ *
9
+ * Entrada: objeto JSON por stdin (o --json='{...}') con la forma:
10
+ * {
11
+ * "sessionId": "...", "agent": "orquestador-swl",
12
+ * "accomplishments": ["..."], "decisions": ["..."],
13
+ * "learnings": ["..."], "challenges": ["..."],
14
+ * "sourceAgents": ["implementador-swl"], "tags": ["..."]
15
+ * }
16
+ *
17
+ * Imprime la ruta del archivo escrito. Uso:
18
+ * echo '{"sessionId":"s1","agent":"orquestador-swl"}' | swl-ses diary-entry
19
+ */
20
+
21
+ const fs = require('node:fs');
22
+ const path = require('node:path');
23
+ const diary = require('../lib/diary-entry');
24
+ const { atomicWriteSync } = require('../../hooks/lib/atomic-write');
25
+
26
+ function diaryEntry(opciones = {}) {
27
+ let raw = opciones.json;
28
+ if (!raw && !process.stdin.isTTY) {
29
+ try {
30
+ raw = fs.readFileSync(0, 'utf8');
31
+ } catch (e) {
32
+ // No degradar en silencio: avisar que stdin fue ilegible antes del fallback.
33
+ console.error('[diary-entry] aviso: stdin ilegible (' + e.code + ')');
34
+ raw = '';
35
+ }
36
+ }
37
+ let input;
38
+ try {
39
+ input = JSON.parse(raw || '{}');
40
+ } catch (e) {
41
+ console.error('Error: JSON inválido: ' + e.message);
42
+ process.exitCode = 1;
43
+ return;
44
+ }
45
+
46
+ let entry = diary.createDiary({ sessionId: input.sessionId, agent: input.agent });
47
+ for (const a of input.accomplishments || []) entry = diary.addAccomplishment(entry, a);
48
+ for (const d of input.decisions || []) entry = diary.addDecision(entry, d);
49
+ for (const c of input.challenges || []) entry = diary.addChallenge(entry, c);
50
+ for (const l of input.learnings || []) entry = diary.addLearning(entry, l);
51
+ for (const tg of input.tags || []) entry = diary.addTag(entry, tg);
52
+ for (const sa of input.sourceAgents || []) entry = diary.addSourceAgent(entry, sa);
53
+ entry = diary.closeDiary(entry);
54
+
55
+ const val = diary.validateDiary(entry);
56
+ if (!val.valid) {
57
+ console.error('Error de validación: ' + val.errors.join('; '));
58
+ process.exitCode = 1;
59
+ return;
60
+ }
61
+
62
+ const dir = path.join(process.cwd(), '.planning', 'sessions', 'diary');
63
+ fs.mkdirSync(dir, { recursive: true });
64
+ const dest = path.join(dir, entry.id + '.json');
65
+ atomicWriteSync(dest, diary.serializeDiary(entry));
66
+ console.log(dest);
67
+ }
68
+
69
+ module.exports = diaryEntry;
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Wrapper CLI `swl-ses execution-state` — imprime el resumen estructurado del
5
+ * estado de ejecución (.planning/execution-state.json). Reemplaza el inline
6
+ * `require('./hooks/lib/execution-state')` relativo al proyecto (roto downstream;
7
+ * ver docs/invocacion-cli-cross-scope.md).
8
+ *
9
+ * Uso: swl-ses execution-state
10
+ */
11
+
12
+ const es = require('../../hooks/lib/execution-state');
13
+
14
+ function executionState() {
15
+ console.log(es.formatearResumen(process.cwd()));
16
+ }
17
+
18
+ module.exports = executionState;
@@ -0,0 +1,41 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Wrapper CLI `swl-ses gateway-notify` — encola una notificación de vuelta al
5
+ * canal origen del gateway (Telegram, Discord). Reemplaza el inline
6
+ * `require('./hooks/lib/gateway-notify')` relativo al proyecto (roto downstream;
7
+ * ver docs/invocacion-cli-cross-scope.md).
8
+ *
9
+ * Uso: swl-ses gateway-notify --texto="✅ ..." [--tipo=custom] [--to=telegram]
10
+ * [--reply-to=<chatId>]
11
+ */
12
+
13
+ const { notificarGateway } = require('../../hooks/lib/gateway-notify');
14
+
15
+ function gatewayNotify(opciones = {}) {
16
+ if (!opciones.texto) {
17
+ console.error('Error: falta --texto="mensaje"');
18
+ process.exitCode = 1;
19
+ return;
20
+ }
21
+ // --reply-to debe ser un chatId numérico: evita redirigir la notificación a
22
+ // un chat arbitrario cuando el flag se sintetiza desde input no confiable.
23
+ if (opciones['reply-to'] !== undefined && !/^-?\d+$/.test(String(opciones['reply-to']))) {
24
+ console.error('Error: --reply-to debe ser un chatId numérico');
25
+ process.exitCode = 1;
26
+ return;
27
+ }
28
+ const params = { tipo: opciones.tipo || 'custom', texto: opciones.texto };
29
+ if (opciones.to) params.to = opciones.to;
30
+ if (opciones['reply-to'] !== undefined) params.payload = { replyTo: opciones['reply-to'] };
31
+
32
+ const r = notificarGateway(params);
33
+ if (r === false) {
34
+ console.log(JSON.stringify({ ok: false, motivo: 'gateway deshabilitado o tipo no habilitado' }, null, 2));
35
+ process.exitCode = 1;
36
+ return;
37
+ }
38
+ console.log(JSON.stringify(r ?? { ok: true }, null, 2));
39
+ }
40
+
41
+ module.exports = gatewayNotify;
@@ -0,0 +1,42 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Subcomando `swl-ses liberar-fase` — cierra el gate G0 borrando
5
+ * .planning/locks/fase-activa.json. Lo usa /swl:ejecutar-fase al terminar una
6
+ * fase para que spec-gate.js vuelva a advertir si se reanuda trabajo.
7
+ *
8
+ * Reemplaza el `node -e "...unlinkSync('.planning/locks/fase-activa.json')"`
9
+ * inline (relativo al proyecto). Busca el archivo ascendiendo desde el CWD para
10
+ * funcionar aunque el comando se ejecute desde un subdirectorio.
11
+ *
12
+ * Uso: swl-ses liberar-fase
13
+ */
14
+
15
+ const fs = require('node:fs');
16
+ const path = require('node:path');
17
+
18
+ function liberarFase(opciones = {}) {
19
+ let dir = (opciones && opciones.cwd) || process.cwd();
20
+ let target = null;
21
+ while (dir !== path.dirname(dir)) {
22
+ const cand = path.join(dir, '.planning', 'locks', 'fase-activa.json');
23
+ if (fs.existsSync(cand)) {
24
+ target = cand;
25
+ break;
26
+ }
27
+ dir = path.dirname(dir);
28
+ }
29
+
30
+ if (target) {
31
+ fs.unlinkSync(target);
32
+ console.log(JSON.stringify({ ok: true, liberado: target }));
33
+ } else {
34
+ console.log(
35
+ JSON.stringify({ ok: true, liberado: null, motivo: 'sin fase activa que liberar' })
36
+ );
37
+ }
38
+ }
39
+
40
+ module.exports = liberarFase;
41
+
42
+ if (require.main === module) liberarFase();
@@ -0,0 +1,125 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Wrapper CLI `swl-ses loop-telemetry <op>` — telemetría de loops iterativos.
5
+ * Reemplaza los inline `require('./hooks/lib/loop-telemetry')` relativos al
6
+ * proyecto (rotos downstream; ver docs/invocacion-cli-cross-scope.md).
7
+ *
8
+ * Ops:
9
+ * iniciar --tipo=X [--direccion=higher_is_better] [--config='{json}'] → imprime dir
10
+ * registrar --dir=D --iteracion=N --metrica=M [--delta=D] [--estado=keep]
11
+ * [--descripcion="..."]
12
+ * handoff --dir=D --source=X --status=Y [--findings='[json]'] [--config='{json}']
13
+ * listar (default) — resumen de las últimas 10 corridas
14
+ */
15
+
16
+ const fs = require('node:fs');
17
+ const path = require('node:path');
18
+ const lt = require('../../hooks/lib/loop-telemetry');
19
+
20
+ // Parseo no degradante: si el flag está presente pero su JSON es inválido,
21
+ // reporta y devuelve {ok:false} en vez de silenciar a fallback (anti-fallback
22
+ // silencioso). El fallback solo aplica cuando el flag está ausente.
23
+ function parseJSON(v, fallback, flagName) {
24
+ if (v === undefined) return { ok: true, val: fallback };
25
+ try {
26
+ return { ok: true, val: JSON.parse(v) };
27
+ } catch (e) {
28
+ console.error(`[loop-telemetry] --${flagName} JSON inválido: ${e.message}`);
29
+ return { ok: false };
30
+ }
31
+ }
32
+
33
+ function requireDir(opciones) {
34
+ if (!opciones.dir) {
35
+ console.error('Error: falta --dir=<ruta>');
36
+ process.exitCode = 1;
37
+ return false;
38
+ }
39
+ return true;
40
+ }
41
+
42
+ function loopTelemetry(opciones = {}) {
43
+ const op = (opciones._args && opciones._args[0]) || opciones.op || 'listar';
44
+
45
+ if (op === 'iniciar') {
46
+ const config = parseJSON(opciones.config, {}, 'config');
47
+ if (!config.ok) {
48
+ process.exitCode = 1;
49
+ return;
50
+ }
51
+ const r = lt.iniciarCorrida({
52
+ tipo: opciones.tipo,
53
+ direccion: opciones.direccion || 'higher_is_better',
54
+ config: config.val,
55
+ });
56
+ console.log(r.dir);
57
+ return;
58
+ }
59
+
60
+ if (op === 'registrar') {
61
+ if (!requireDir(opciones)) return;
62
+ const fila = {
63
+ iteracion: Number(opciones.iteracion),
64
+ metrica: Number(opciones.metrica),
65
+ estado: opciones.estado || 'keep',
66
+ descripcion: opciones.descripcion || '',
67
+ };
68
+ if (opciones.delta !== undefined) fila.delta = Number(opciones.delta);
69
+ lt.registrarIteracion(opciones.dir, fila);
70
+ console.log('[loop-telemetry] iteración registrada en ' + opciones.dir);
71
+ return;
72
+ }
73
+
74
+ if (op === 'handoff') {
75
+ if (!requireDir(opciones)) return;
76
+ const findings = parseJSON(opciones.findings, [], 'findings');
77
+ const config = parseJSON(opciones.config, {}, 'config');
78
+ if (!findings.ok || !config.ok) {
79
+ process.exitCode = 1;
80
+ return;
81
+ }
82
+ lt.escribirHandoff(opciones.dir, {
83
+ source: opciones.source,
84
+ status: opciones.status,
85
+ findings: findings.val,
86
+ config: config.val,
87
+ });
88
+ console.log('[loop-telemetry] handoff escrito en ' + opciones.dir);
89
+ return;
90
+ }
91
+
92
+ // listar (default)
93
+ const base = path.join(process.cwd(), lt.DIR_LOOPS);
94
+ let dirs = [];
95
+ try {
96
+ dirs = fs
97
+ .readdirSync(base)
98
+ .map((d) => path.join(base, d))
99
+ .filter((d) => fs.statSync(d).isDirectory());
100
+ } catch {
101
+ /* sin directorio de loops */
102
+ }
103
+ if (dirs.length === 0) {
104
+ console.log('(sin corridas de loops registradas)');
105
+ return;
106
+ }
107
+ for (const dir of dirs.sort().slice(-10)) {
108
+ try {
109
+ const t = lt.analizarTrayectoria(dir);
110
+ const h = lt.leerHandoff(dir);
111
+ console.log(
112
+ path.basename(dir) +
113
+ ' | iters: ' + t.totalIteraciones +
114
+ ' | keep/revert: ' + t.keeps + '/' + t.reverts +
115
+ ' | métrica: ' + t.metricaInicial + ' → ' + t.metricaFinal +
116
+ ' | plateau: ' + (t.plateau ? 'SÍ' : 'no') +
117
+ ' | status: ' + (h ? h.status : 'en curso')
118
+ );
119
+ } catch (e) {
120
+ console.log(path.basename(dir) + ' | (ilegible: ' + e.message + ')');
121
+ }
122
+ }
123
+ }
124
+
125
+ module.exports = loopTelemetry;
@@ -0,0 +1,56 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Wrapper CLI `swl-ses mark-evolved` — marca un componente SWL como evolucionado
5
+ * (frontmatter evolved: true + metadatos). Reemplaza el inline
6
+ * `require('./hooks/lib/evolution-tracker')` relativo al proyecto (roto
7
+ * downstream; ver docs/invocacion-cli-cross-scope.md).
8
+ *
9
+ * Uso: swl-ses mark-evolved <ruta> [--from=VER] [--by=aprender]
10
+ * [--note="..."] [--rounds=N] [--score="A% → B%"]
11
+ */
12
+
13
+ const path = require('node:path');
14
+ const { markAsEvolved } = require('../../hooks/lib/evolution-tracker');
15
+
16
+ function markEvolved(opciones = {}) {
17
+ const ruta = (opciones._args && opciones._args[0]) || opciones.ruta;
18
+ if (!ruta) {
19
+ console.error('Error: falta <ruta> del archivo a marcar');
20
+ process.exitCode = 1;
21
+ return;
22
+ }
23
+ // Guard anti path-traversal: la ruta debe resolver dentro del proyecto actual
24
+ // y ser un componente del sistema (.md/.json). Evita sobrescribir archivos
25
+ // arbitrarios con frontmatter si el flag se sintetiza desde input no confiable.
26
+ const cwd = process.cwd();
27
+ const resuelta = path.resolve(cwd, ruta);
28
+ if (resuelta !== cwd && !resuelta.startsWith(cwd + path.sep)) {
29
+ console.error('Error: la ruta debe estar dentro del proyecto actual');
30
+ process.exitCode = 1;
31
+ return;
32
+ }
33
+ if (!/\.(md|json)$/i.test(resuelta)) {
34
+ console.error('Error: solo se pueden marcar componentes .md o .json');
35
+ process.exitCode = 1;
36
+ return;
37
+ }
38
+ let from = opciones.from;
39
+ if (!from) {
40
+ try {
41
+ from = require(path.resolve(process.cwd(), 'package.json')).version;
42
+ } catch {
43
+ from = undefined;
44
+ }
45
+ }
46
+ const meta = { from, by: opciones.by || 'aprender' };
47
+ if (opciones.note) meta.note = opciones.note;
48
+ if (opciones.rounds) meta.rounds = Number(opciones.rounds);
49
+ if (opciones.score) meta.score = opciones.score;
50
+
51
+ const r = markAsEvolved(ruta, meta);
52
+ console.log(r.marked ? 'Marcado como evolucionado' : 'Error: ' + r.error);
53
+ if (!r.marked) process.exitCode = 1;
54
+ }
55
+
56
+ module.exports = markEvolved;
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Wrapper CLI `swl-ses metricas-dora` — calcula métricas DORA del repo actual.
5
+ * Reemplaza `node scripts/lib/metricas-dora.js` relativo al proyecto (roto
6
+ * downstream; ver docs/invocacion-cli-cross-scope.md).
7
+ *
8
+ * Uso: swl-ses metricas-dora [--json] [--dias=N]
9
+ */
10
+
11
+ const { calcularDora, persistir } = require('../lib/metricas-dora');
12
+
13
+ function metricasDora(opciones = {}) {
14
+ const dias = Number(opciones.dias);
15
+ const ventanaDias = Math.max(1, Math.min(365, Number.isFinite(dias) && dias > 0 ? dias : 30));
16
+ const baseDir = process.cwd();
17
+ const dora = calcularDora(baseDir, { ventanaDias });
18
+ try {
19
+ persistir(baseDir, dora);
20
+ } catch {
21
+ /* persistencia best-effort: no romper el informe si el disco falla */
22
+ }
23
+ console.log(JSON.stringify(dora, null, 2));
24
+ }
25
+
26
+ module.exports = metricasDora;
@@ -0,0 +1,55 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Wrapper CLI `swl-ses near-duplicate` — detecta si un aprendizaje nuevo es
5
+ * duplicado cercano de los existentes en APRENDIZAJES.md. Reemplaza el inline
6
+ * `require('./hooks/lib/fingerprint-id')` relativo al proyecto (roto downstream;
7
+ * ver docs/invocacion-cli-cross-scope.md).
8
+ *
9
+ * Uso: swl-ses near-duplicate --texto="..." [--archivo=ruta] [--threshold=0.6]
10
+ * echo "texto..." | swl-ses near-duplicate [--archivo=ruta]
11
+ */
12
+
13
+ const fs = require('node:fs');
14
+ const path = require('node:path');
15
+ const { isNearDuplicate } = require('../../hooks/lib/fingerprint-id');
16
+
17
+ function nearDuplicate(opciones = {}) {
18
+ const archivo = opciones.archivo || '.planning/APRENDIZAJES.md';
19
+ let nuevo = opciones.texto;
20
+ if (!nuevo && !process.stdin.isTTY) {
21
+ try {
22
+ nuevo = fs.readFileSync(0, 'utf8');
23
+ } catch {
24
+ nuevo = '';
25
+ }
26
+ }
27
+ if (!nuevo) {
28
+ console.error('Error: falta --texto="..." o entrada por stdin');
29
+ process.exitCode = 1;
30
+ return;
31
+ }
32
+ // Guard anti path-traversal: --archivo debe resolver dentro del proyecto.
33
+ const cwd = process.cwd();
34
+ const resuelta = path.resolve(cwd, archivo);
35
+ if (resuelta !== cwd && !resuelta.startsWith(cwd + path.sep)) {
36
+ console.error('Error: --archivo debe estar dentro del proyecto actual');
37
+ process.exitCode = 1;
38
+ return;
39
+ }
40
+ let existentes = [];
41
+ try {
42
+ existentes = fs.readFileSync(resuelta, 'utf8').split(/^## /m).filter(Boolean);
43
+ } catch (e) {
44
+ // Sin archivo de aprendizajes legible: avisar (no degradar en silencio) y
45
+ // tratar todo como único.
46
+ if (e.code !== 'ENOENT') console.error('[near-duplicate] aviso: ' + e.code);
47
+ }
48
+ const t = Number(opciones.threshold);
49
+ const threshold = Number.isFinite(t) && t > 0 ? t : 0.6;
50
+
51
+ const r = isNearDuplicate(nuevo, existentes, threshold);
52
+ console.log(r.nearDuplicate ? 'DUPLICADO (sim=' + r.similarity + ')' : 'ÚNICO');
53
+ }
54
+
55
+ module.exports = nearDuplicate;
@@ -0,0 +1,123 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Wrapper CLI `swl-ses notificaciones <op>` — gestiona las notificaciones
5
+ * Telegram y su bot daemon. Reemplaza los inline
6
+ * `require('./scripts/lib/notificaciones-telegram')` relativos al proyecto
7
+ * (rotos downstream; ver docs/invocacion-cli-cross-scope.md). Encapsula también
8
+ * el formato de salida que antes vivía en el comando.
9
+ *
10
+ * Ops:
11
+ * init (requiere TTY) bot-start
12
+ * status bot-stop
13
+ * disable [--purge] bot-status
14
+ * repair bot-restart
15
+ * bot-enable-autostart
16
+ * bot-disable-autostart
17
+ */
18
+
19
+ const nt = require('../lib/notificaciones-telegram');
20
+
21
+ function imprimirStatus() {
22
+ const s = nt.status();
23
+ const botS = nt.botStatus();
24
+ const autostartLabel =
25
+ process.platform === 'win32'
26
+ ? 'Scheduled Task'
27
+ : process.platform === 'linux'
28
+ ? 'systemd --user'
29
+ : 'LaunchAgent';
30
+ const mudos = s.proyectosSilenciados.length
31
+ ? s.proyectosSilenciados.join(', ')
32
+ : 'ninguno';
33
+ console.log('');
34
+ console.log('Notificaciones Telegram — estado actual');
35
+ console.log(' .env: ', s.envExiste ? 'existe' : 'no existe');
36
+ console.log(' token: ', s.tokenConfigurado ? 'configurado' : 'no configurado');
37
+ console.log(
38
+ ' chat_id: ',
39
+ s.chatIdConfigurado ? 'configurado (' + s.chatIdParcial + ')' : 'no configurado'
40
+ );
41
+ console.log(' proyectos mudos: ', mudos);
42
+ console.log(' bot daemon: ', botS.activo ? 'activo (PID ' + botS.pid + ')' : 'detenido');
43
+ console.log(' autostart: usar /swl:notificaciones bot enable-autostart (' + autostartLabel + ')');
44
+ console.log('');
45
+ }
46
+
47
+ function imprimirBotStatus() {
48
+ const r = nt.botStatus();
49
+ console.log('');
50
+ console.log('Bot daemon — estado actual');
51
+ console.log(' activo:', r.activo ? 'sí' : 'no');
52
+ console.log(' pid: ', r.pid !== null ? r.pid : 'n/a');
53
+ console.log('');
54
+ }
55
+
56
+ function reportarOk(prefijo, r, mensajeDefault) {
57
+ if (r.ok) {
58
+ console.log('[' + prefijo + ']', r.mensaje || mensajeDefault);
59
+ } else {
60
+ console.error('[' + prefijo + '] Error:', r.error);
61
+ process.exitCode = 1;
62
+ }
63
+ }
64
+
65
+ // Tabla de dispatch de los ops del bot daemon: [prefijo, fn, mensajeDefault].
66
+ const BOT_OPS = {
67
+ 'bot-start': ['bot', () => nt.botStart(), 'Bot iniciado.'],
68
+ 'bot-stop': ['bot', () => nt.botStop(), 'Bot detenido.'],
69
+ 'bot-restart': ['bot', () => nt.botRestart(), 'Bot reiniciado.'],
70
+ 'bot-enable-autostart': ['autostart', () => nt.botEnableAutostart(), 'Autostart habilitado.'],
71
+ 'bot-disable-autostart': ['autostart', () => nt.botDisableAutostart(), 'Autostart deshabilitado.'],
72
+ };
73
+
74
+ async function notificaciones(opciones = {}) {
75
+ const op = (opciones._args && opciones._args[0]) || opciones.op || 'status';
76
+
77
+ if (BOT_OPS[op]) {
78
+ const [prefijo, fn, msg] = BOT_OPS[op];
79
+ reportarOk(prefijo, fn(), msg);
80
+ return;
81
+ }
82
+
83
+ switch (op) {
84
+ case 'init': {
85
+ if (!process.stdin.isTTY) {
86
+ console.log('Este subcomando requiere entrada interactiva (TTY).');
87
+ console.log('Ejecuta desde tu terminal:');
88
+ console.log(' swl-ses notificaciones init');
89
+ console.log('O usa el instalador:');
90
+ console.log(' npx -y @saulwade/swl-ses@latest install');
91
+ return;
92
+ }
93
+ const r = await nt.init({ esTty: true });
94
+ console.log('[resultado]', r.resultado, r.detalle || '');
95
+ if (r.resultado === 'error') process.exitCode = 1;
96
+ return;
97
+ }
98
+ case 'status':
99
+ imprimirStatus();
100
+ return;
101
+ case 'disable': {
102
+ const r = nt.disable({ confirmar: true, conservarEnv: !opciones.purge });
103
+ console.log('[resultado]', r.resultado, r.detalle || '');
104
+ if (r.resultado === 'error') process.exitCode = 1;
105
+ return;
106
+ }
107
+ case 'repair': {
108
+ const r = await nt.repair();
109
+ console.log('[repair]', r.resultado, r.detalle || '');
110
+ if (r.resultado === 'error') process.exitCode = 1;
111
+ return;
112
+ }
113
+ case 'bot-status':
114
+ imprimirBotStatus();
115
+ return;
116
+ default:
117
+ console.error('Op desconocida: ' + op);
118
+ console.error('Ops: init|status|disable|repair|bot-start|bot-stop|bot-status|bot-restart|bot-enable-autostart|bot-disable-autostart');
119
+ process.exitCode = 1;
120
+ }
121
+ }
122
+
123
+ module.exports = notificaciones;
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Wrapper CLI para `swl-ses propose-step` — anexo propositivo del RESUMEN de
5
+ * fase (ADR-0037). Envuelve hooks/lib/propose-step.js (que lee process.argv).
6
+ *
7
+ * Reemplaza el `node hooks/lib/propose-step.js --rango=...` relativo al proyecto
8
+ * que /swl:ejecutar-fase invocaba — roto downstream (ver
9
+ * docs/invocacion-cli-cross-scope.md).
10
+ *
11
+ * Uso: swl-ses propose-step --rango=<base>..HEAD (opt-out SWL_PROPOSE=0)
12
+ */
13
+
14
+ const { main } = require('../../hooks/lib/propose-step.js');
15
+
16
+ function proposeStep(opciones = {}) {
17
+ opciones = opciones || {};
18
+ const args = ['node', 'propose-step'];
19
+ if (opciones.rango) args.push(`--rango=${opciones.rango}`);
20
+ const argvOriginal = process.argv;
21
+ process.argv = args;
22
+ try {
23
+ return main(process.argv);
24
+ } finally {
25
+ process.argv = argvOriginal;
26
+ }
27
+ }
28
+
29
+ module.exports = proposeStep;
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Wrapper CLI `swl-ses schedule-parse` — parsea una frase en inglés a expresión
5
+ * cron. Reemplaza el inline `require('./scripts/lib/schedule-parser')` relativo
6
+ * al proyecto (roto downstream; ver docs/invocacion-cli-cross-scope.md).
7
+ *
8
+ * Uso: swl-ses schedule-parse "every morning at 9am"
9
+ */
10
+
11
+ const { parseNaturalSchedule } = require('../lib/schedule-parser');
12
+
13
+ function scheduleParse(opciones = {}) {
14
+ const frase =
15
+ (opciones._args && opciones._args.join(' ')) || opciones.texto || '';
16
+ console.log(JSON.stringify(parseNaturalSchedule(frase), null, 2));
17
+ }
18
+
19
+ module.exports = scheduleParse;
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Wrapper CLI `swl-ses sugerir-modelo` — evalúa la complejidad de una tarea y
5
+ * sugiere el modelo (opus/sonnet/haiku). Reemplaza el inline
6
+ * `require('./hooks/lib/model-router.js')` relativo al proyecto (roto downstream;
7
+ * ver docs/invocacion-cli-cross-scope.md).
8
+ *
9
+ * Uso: swl-ses sugerir-modelo "<descripción de la tarea>"
10
+ */
11
+
12
+ const { sugerirModelo } = require('../../hooks/lib/model-router.js');
13
+
14
+ function sugerirModeloCli(opciones = {}) {
15
+ const desc =
16
+ (opciones._args && opciones._args.join(' ')) || opciones.desc || '';
17
+ console.log(JSON.stringify(sugerirModelo(desc), null, 2));
18
+ }
19
+
20
+ module.exports = sugerirModeloCli;