@saulwade/swl-ses 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +196 -196
- package/README.md +579 -579
- package/agentes/_propose-step.md +90 -0
- package/agentes/implementador-swl.md +2 -0
- package/agentes/orquestador-swl.md +2 -0
- package/agentes/perfilador-usuario-swl.md +14 -1
- package/bin/swl-ses.js +64 -1
- package/comandos/swl/adoptar-proyecto.md +258 -255
- package/comandos/swl/aprender.md +828 -840
- package/comandos/swl/aprobar-plan.md +26 -37
- package/comandos/swl/autoresearch.md +12 -14
- package/comandos/swl/briefing.md +119 -0
- package/comandos/swl/checkpoint.md +10 -15
- package/comandos/swl/claudemd.md +239 -234
- package/comandos/swl/compactar.md +29 -2
- package/comandos/swl/configurar-ci.md +20 -19
- package/comandos/swl/cron.md +10 -12
- package/comandos/swl/discutir-fase.md +8 -5
- package/comandos/swl/ejecutar-fase.md +15 -2
- package/comandos/swl/evolucionar.md +6 -11
- package/comandos/swl/inbox.md +10 -10
- package/comandos/swl/modelo.md +7 -9
- package/comandos/swl/notificaciones.md +19 -116
- package/comandos/swl/nuevo-proyecto.md +205 -205
- package/comandos/swl/planear-fase.md +5 -3
- package/comandos/swl/release.md +46 -0
- package/comandos/swl/status.md +333 -279
- package/comandos/swl/verificar.md +817 -812
- package/habilidades/changelog-generator/scripts/parse-commits.js +6 -4
- package/habilidades/ejecutar-fase/SKILL.md +541 -518
- package/habilidades/planear-fase/SKILL.md +3 -2
- package/habilidades/swl-claudemd/SKILL.md +10 -6
- package/habilidades/tdd-workflow/SKILL.md +715 -713
- package/habilidades/validacion-ci-sistema/SKILL.md +17 -1
- package/hooks/calidad-pre-commit.js +5 -1
- package/hooks/check-update.js +39 -1
- package/hooks/lib/autonomia.js +208 -0
- package/hooks/lib/briefing.js +474 -0
- package/hooks/lib/propose-step.js +358 -0
- package/hooks/session-briefing.js +98 -0
- package/hooks/telemetria-skill-routing.js +100 -0
- package/instintos/autonomia.yaml +27 -0
- package/llms.txt +4 -4
- package/manifiestos/hooks-config.json +18 -0
- package/manifiestos/modulos.json +25 -3
- package/manifiestos/skills-lock.json +17 -17
- package/package.json +93 -93
- package/plugin.json +371 -371
- package/reglas/analizar-directorios-antes-de-escribir.md +228 -0
- package/reglas/consultar-vault-primero.md +195 -0
- package/reglas/debatir-antes-de-aceptar.md +158 -0
- package/reglas/git-coauthor.md +100 -0
- package/reglas/monitor-ci.md +309 -0
- package/reglas/registro-componentes-nuevos.md +38 -10
- package/reglas/sesiones-paralelas.md +180 -0
- package/reglas/usar-code-review-graph.md +155 -0
- package/reglas/verificar-citas-normativas.md +548 -0
- package/scripts/auditar-claudemd.js +38 -0
- package/scripts/cli/aprobar-plan.js +73 -0
- package/scripts/cli/briefing.js +23 -0
- package/scripts/cli/ciclo-evolucion.js +26 -0
- package/scripts/cli/configurar-ci.js +40 -0
- package/scripts/cli/derivar-feature-list.js +25 -0
- package/scripts/cli/detectar-host.js +27 -0
- package/scripts/cli/diary-entry.js +69 -0
- package/scripts/cli/execution-state.js +18 -0
- package/scripts/cli/gateway-notify.js +41 -0
- package/scripts/cli/liberar-fase.js +42 -0
- package/scripts/cli/loop-telemetry.js +125 -0
- package/scripts/cli/mark-evolved.js +56 -0
- package/scripts/cli/metricas-dora.js +26 -0
- package/scripts/cli/near-duplicate.js +55 -0
- package/scripts/cli/notificaciones.js +123 -0
- package/scripts/cli/propose-step.js +29 -0
- package/scripts/cli/schedule-parse.js +19 -0
- package/scripts/cli/sugerir-modelo.js +20 -0
- package/scripts/cli/verificar-plan.js +36 -0
- package/scripts/cli/verificar-trazabilidad.js +35 -0
- package/scripts/derivar-feature-list.js +1 -0
- package/scripts/instalador.js +52 -6
- package/scripts/lib/auditar-invocaciones-comandos.js +104 -0
- package/scripts/lib/ci-reader.js +193 -0
- package/scripts/lib/detectar-host-swl.js +175 -0
- package/scripts/lib/evidencia-release.js +322 -0
- package/scripts/lib/gate-hooks-requires.js +249 -0
- package/scripts/lib/gate-licencias.js +212 -0
- package/scripts/lib/git-metricas.js +257 -0
- package/scripts/lib/metricas-dora.js +204 -0
- package/scripts/lib/resolver-plan-fase.js +37 -0
- package/scripts/tui/ejecutores.js +1 -1
- package/scripts/validar-manifest.js +92 -1
- package/scripts/validar.js +13 -0
- package/scripts/verificar-evolucion.js +54 -4
- package/scripts/verificar-release.js +102 -0
- package/scripts/verificar-trazabilidad.js +12 -6
- package/reglas/arquitectura.evolved.json +0 -7
- package/reglas/seguridad.evolved.json +0 -7
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Subcomando `swl-ses aprobar-plan --fase=N` — parte determinista del gate G1.
|
|
5
|
+
*
|
|
6
|
+
* Reemplaza los `node -e "require('./scripts/lib/plan-lock')"` y
|
|
7
|
+
* `require('./hooks/lib/atomic-write')` que el slash command /swl:aprobar-plan
|
|
8
|
+
* tenía inline — rutas relativas al proyecto que se rompían en instalaciones
|
|
9
|
+
* downstream (ver docs/invocacion-cli-cross-scope.md).
|
|
10
|
+
*
|
|
11
|
+
* Hace: firma el PLAN (SHA256 → .planning/locks/0N-PLAN.md.lock), lo verifica,
|
|
12
|
+
* y escribe .planning/locks/fase-activa.json (gate G0). El HITL (confirmación,
|
|
13
|
+
* transición de frontmatter, REQ×T) lo sigue manejando el prompt del comando.
|
|
14
|
+
*
|
|
15
|
+
* Uso: swl-ses aprobar-plan --fase=N [--plan=<ruta>] [--aprobado-por="texto"]
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const path = require('node:path');
|
|
19
|
+
const { firmarPlan, verificarPlan } = require('../lib/plan-lock');
|
|
20
|
+
const { atomicWriteJSON } = require('../../hooks/lib/atomic-write');
|
|
21
|
+
const { resolverPlanPath } = require('../lib/resolver-plan-fase');
|
|
22
|
+
|
|
23
|
+
function aprobarPlan(opciones = {}) {
|
|
24
|
+
opciones = opciones || {};
|
|
25
|
+
const planPath = resolverPlanPath(opciones);
|
|
26
|
+
if (!planPath) {
|
|
27
|
+
console.error('Uso: swl-ses aprobar-plan --fase=N [--plan=<ruta>] [--aprobado-por="texto"]');
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const firmadoPor = opciones['aprobado-por'] || opciones.aprobado_por || 'swl:aprobar-plan';
|
|
32
|
+
const firma = firmarPlan(planPath, { firmadoPor });
|
|
33
|
+
if (!firma.ok) {
|
|
34
|
+
console.error(`[aprobar-plan] no se pudo firmar el PLAN: ${firma.motivo}`);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const ver = verificarPlan(planPath);
|
|
39
|
+
const numero =
|
|
40
|
+
opciones.fase != null && opciones.fase !== true ? Number(opciones.fase) : null;
|
|
41
|
+
const locksDir = path.dirname(firma.lockPath);
|
|
42
|
+
const faseActivaPath = path.join(locksDir, 'fase-activa.json');
|
|
43
|
+
|
|
44
|
+
atomicWriteJSON(faseActivaPath, {
|
|
45
|
+
numero,
|
|
46
|
+
planPath,
|
|
47
|
+
sha256: firma.sha256,
|
|
48
|
+
aprobadoEn: new Date().toISOString(),
|
|
49
|
+
aprobadoPor: opciones['aprobado-por'] || opciones.aprobado_por || 'usuario via /swl:aprobar-plan',
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
console.log(
|
|
53
|
+
JSON.stringify(
|
|
54
|
+
{
|
|
55
|
+
ok: true,
|
|
56
|
+
planPath,
|
|
57
|
+
sha256: firma.sha256,
|
|
58
|
+
lockPath: firma.lockPath,
|
|
59
|
+
modo: ver.modo,
|
|
60
|
+
faseActiva: faseActivaPath,
|
|
61
|
+
},
|
|
62
|
+
null,
|
|
63
|
+
2
|
|
64
|
+
)
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
module.exports = aprobarPlan;
|
|
69
|
+
|
|
70
|
+
if (require.main === module) {
|
|
71
|
+
const { parsearOpciones } = require('../lib/parsear-opciones');
|
|
72
|
+
aprobarPlan(parsearOpciones(process.argv.slice(2)));
|
|
73
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Wrapper CLI `swl-ses briefing` — recolecta las señales baratas del briefing
|
|
5
|
+
* (adr-vencido, deuda-trigger, nudges-pendientes, gate-calibracion,
|
|
6
|
+
* continue-here) y las imprime sin tope. Reemplaza el inline
|
|
7
|
+
* `require('./hooks/lib/briefing.js')` relativo al proyecto (roto downstream;
|
|
8
|
+
* ver docs/invocacion-cli-cross-scope.md).
|
|
9
|
+
*
|
|
10
|
+
* Uso: swl-ses briefing
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const b = require('../../hooks/lib/briefing.js');
|
|
14
|
+
|
|
15
|
+
function briefingCli() {
|
|
16
|
+
const items = b.recolectarTodo(process.cwd(), new Date());
|
|
17
|
+
for (const it of items) {
|
|
18
|
+
console.log('— [' + it.categoria + '] ' + it.titulo + ' → ' + it.accion);
|
|
19
|
+
}
|
|
20
|
+
if (items.length === 0) console.log('(sin señales baratas)');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = briefingCli;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Wrapper CLI `swl-ses ciclo-evolucion` — regenera las métricas de evolución
|
|
5
|
+
* (.planning/evolution/metricas.json) ejecutando la sub-etapa Stop del ciclo.
|
|
6
|
+
* Reemplaza `echo '{}' | node hooks/ciclo-evolucion.js` relativo al proyecto
|
|
7
|
+
* (roto downstream; ver docs/invocacion-cli-cross-scope.md).
|
|
8
|
+
*
|
|
9
|
+
* Uso: swl-ses ciclo-evolucion
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const cicloEvolucion = require('../../hooks/lib/ciclo-evolucion');
|
|
13
|
+
|
|
14
|
+
function cicloEvolucionCli() {
|
|
15
|
+
try {
|
|
16
|
+
cicloEvolucion.ejecutarStop('{}');
|
|
17
|
+
console.log('[ciclo-evolucion] métricas de evolución regeneradas');
|
|
18
|
+
} catch (e) {
|
|
19
|
+
// A diferencia del hook (que nunca bloquea el harness), el CLI sí debe
|
|
20
|
+
// distinguir fallo de éxito para el caller: stderr + exit code != 0.
|
|
21
|
+
console.error('[ciclo-evolucion] no se pudo regenerar: ' + e.message);
|
|
22
|
+
process.exitCode = 1;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = cicloEvolucionCli;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Wrapper CLI `swl-ses configurar-ci <op>` — gestiona los workflows CI/CD de SWL
|
|
5
|
+
* en el proyecto actual. Reemplaza los inline `require('./scripts/lib/configurar-ci')`
|
|
6
|
+
* relativos al proyecto (rotos downstream; ver docs/invocacion-cli-cross-scope.md).
|
|
7
|
+
*
|
|
8
|
+
* Ops (todas imprimen el resultado como JSON para que el comando lo inspeccione):
|
|
9
|
+
* init [--no-security] [--no-ci] [--with-release-please] [--dry-run] [--force]
|
|
10
|
+
* status (default)
|
|
11
|
+
* uninstall [--confirmar]
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const ci = require('../lib/configurar-ci');
|
|
15
|
+
|
|
16
|
+
function configurarCi(opciones = {}) {
|
|
17
|
+
const op = (opciones._args && opciones._args[0]) || opciones.op || 'status';
|
|
18
|
+
|
|
19
|
+
if (op === 'init') {
|
|
20
|
+
const r = ci.init({
|
|
21
|
+
withSecurity: !opciones['no-security'],
|
|
22
|
+
withCi: !opciones['no-ci'],
|
|
23
|
+
withReleasePlease: !!opciones['with-release-please'],
|
|
24
|
+
dryRun: !!opciones['dry-run'],
|
|
25
|
+
force: !!opciones.force,
|
|
26
|
+
});
|
|
27
|
+
console.log(JSON.stringify(r, null, 2));
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (op === 'uninstall') {
|
|
32
|
+
const r = ci.uninstall({ confirmar: !!opciones.confirmar });
|
|
33
|
+
console.log(JSON.stringify(r, null, 2));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
console.log(JSON.stringify(ci.status(), null, 2));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
module.exports = configurarCi;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Wrapper CLI `swl-ses derivar-feature-list` — genera .planning/feature-list.json
|
|
5
|
+
* desde HOJA-RUTA.md. Reemplaza `node scripts/derivar-feature-list.js` relativo
|
|
6
|
+
* al proyecto (roto downstream; ver docs/invocacion-cli-cross-scope.md).
|
|
7
|
+
*
|
|
8
|
+
* Uso: swl-ses derivar-feature-list [--check] (--check: exit 2 si hay drift)
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const { main } = require('../derivar-feature-list.js');
|
|
12
|
+
|
|
13
|
+
function derivarFeatureList(opciones = {}) {
|
|
14
|
+
const args = ['node', 'derivar-feature-list'];
|
|
15
|
+
if (opciones && opciones.check) args.push('--check');
|
|
16
|
+
const argvOriginal = process.argv;
|
|
17
|
+
process.argv = args;
|
|
18
|
+
try {
|
|
19
|
+
return main();
|
|
20
|
+
} finally {
|
|
21
|
+
process.argv = argvOriginal;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports = derivarFeatureList;
|
|
@@ -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;
|