@saulwade/swl-ses 2.2.3 → 2.3.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.
Files changed (66) hide show
  1. package/CLAUDE.md +4 -4
  2. package/README.md +3 -3
  3. package/agentes/arquitecto-swl.md +1 -1
  4. package/agentes/auto-evolucion-swl.md +908 -908
  5. package/agentes/backend-csharp-swl.md +1 -1
  6. package/agentes/backend-go-swl.md +1 -1
  7. package/agentes/backend-java-swl.md +1 -1
  8. package/agentes/backend-rust-swl.md +1 -1
  9. package/agentes/evals/orquestador-swl.evals.json +1 -1
  10. package/agentes/implementador-swl.md +2 -2
  11. package/agentes/llm-apps-swl.md +1 -1
  12. package/agentes/orquestador-swl.md +7 -7
  13. package/agentes/pagos-swl.md +1 -1
  14. package/agentes/perfilador-usuario-swl.md +321 -321
  15. package/agentes/planificador-swl.md +1 -1
  16. package/agentes/producto-prd-swl.md +1 -1
  17. package/agentes/revisor-seguridad-swl.md +1 -1
  18. package/agentes/sre-swl.md +1 -1
  19. package/comandos/swl/aprobar-plan.md +146 -141
  20. package/comandos/swl/release.md +45 -8
  21. package/comandos/swl/status.md +343 -333
  22. package/comandos/swl/verificar.md +817 -817
  23. package/habilidades/compactacion-contexto/SKILL.md +3 -3
  24. package/habilidades/contenedores-docker/SKILL.md +3 -1
  25. package/habilidades/context-builder/SKILL.md +4 -4
  26. package/habilidades/control-profundidad/SKILL.md +5 -5
  27. package/habilidades/ejecutar-fase/SKILL.md +564 -541
  28. package/habilidades/extractor-de-aprendizajes/SKILL.md +3 -3
  29. package/habilidades/guardrail-semantico/SKILL.md +1 -1
  30. package/habilidades/harness-claude-code/SKILL.md +305 -305
  31. package/habilidades/meta-skills-estandar/recursos/skills-as-agents.md +1 -1
  32. package/habilidades/planear-fase/SKILL.md +15 -1
  33. package/habilidades/proceso-debate-adversarial/SKILL.md +191 -164
  34. package/habilidades/prompt-engineering/SKILL.md +5 -5
  35. package/habilidades/release-semver/SKILL.md +4 -1
  36. package/habilidades/tdd-workflow/SKILL.md +33 -1
  37. package/habilidades/workflow-claude-code/SKILL.md +6 -6
  38. package/hooks/captura-acciones-post.js +151 -0
  39. package/hooks/captura-acciones-session.js +155 -0
  40. package/hooks/lib/briefing.js +512 -474
  41. package/hooks/lib/captura-acciones.js +392 -0
  42. package/hooks/lib/context-builder.js +2 -2
  43. package/hooks/lib/model-router.js +1 -1
  44. package/hooks/lib/token-estimator.js +2 -0
  45. package/hooks/linea-estado.js +7 -5
  46. package/llms.txt +29 -29
  47. package/manifiestos/canonical-hashes.json +1964 -1310
  48. package/manifiestos/hooks-config.json +18 -0
  49. package/manifiestos/modulos.json +4 -0
  50. package/manifiestos/skills-lock.json +1282 -1282
  51. package/package.json +93 -93
  52. package/plugin.json +371 -371
  53. package/reglas/git-coauthor.md +100 -100
  54. package/reglas/memoria-consolidada.md +41 -0
  55. package/reglas/pruebas.md +15 -0
  56. package/reglas/seguridad-agentes.md +66 -0
  57. package/schemas/agent-frontmatter.schema.json +294 -294
  58. package/schemas/instinct.schema.json +161 -152
  59. package/scripts/bootstrap-instintos.js +25 -7
  60. package/scripts/lib/claude-sessions.js +1 -0
  61. package/scripts/lib/gitignore-manifest.js +44 -11
  62. package/scripts/lib/skill-metrics.js +41 -1
  63. package/scripts/lib/tool-cost-analyzer.js +1 -0
  64. package/scripts/publicar.js +34 -85
  65. package/scripts/verificar-trazabilidad.js +329 -298
  66. package/scripts/vendor/claude-usage/__pycache__/scanner.cpython-314.pyc +0 -0
@@ -0,0 +1,151 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ /**
5
+ * Hook: captura-acciones-post.js
6
+ * Tipo: PostToolUse (todas las herramientas)
7
+ *
8
+ * Pobla el estado que el hook SessionStart (`captura-acciones-session.js`)
9
+ * consumirá para detectar señales de acción del usuario (Fase 17):
10
+ * - `git commit` del agente → registra el SHA en agent-commits.jsonl
11
+ * (base para detectar revert/reset; sin co-author, regla git-coauthor.md).
12
+ * - `Write`/`Edit`/`MultiEdit` → registra el hash del archivo en
13
+ * agent-writes-index.json (base para detectar edición neta del usuario).
14
+ * - `Read` de un archivo que el agente escribió cuyo contenido en disco
15
+ * difiere → encola `edicion-manual` en caliente (REQ-17-03).
16
+ *
17
+ * Zero-deps salvo la lib `captura-acciones`. Opt-out unificado
18
+ * SWL_CAPTURAR_FEEDBACK=0. Exit 0 SIEMPRE; nunca bloquea ni muestra al modelo.
19
+ */
20
+
21
+ const fs = require('fs');
22
+ const path = require('path');
23
+ const { execFileSync } = require('child_process');
24
+
25
+ // Require con fallback dual: el instalador aplana `hooks/lib/X.js → <hooks>/X.js`.
26
+ // (Idioma compartido con session-briefing.js/propose-step.js; no se extrae a lib
27
+ // porque cargar esa lib requeriría a su vez el mismo fallback — paradoja de
28
+ // bootstrap del aplanado.)
29
+ function requireDual(nombre) {
30
+ try {
31
+ return require(`./lib/${nombre}`);
32
+ } catch (e1) {
33
+ if (e1 && e1.code !== 'MODULE_NOT_FOUND') throw e1;
34
+ return require(`./${nombre}`);
35
+ }
36
+ }
37
+
38
+ let lib;
39
+ try {
40
+ lib = requireDual('captura-acciones');
41
+ } catch (_) {
42
+ lib = null;
43
+ }
44
+
45
+ // Preview crudo amplio: se pasa a encolarAccion para que la sanitización corra
46
+ // sobre el texto íntegro (un bloque PEM cabe) ANTES del truncado final a
47
+ // MAX_EVIDENCIA_LEN. Pre-truncar aquí derrotaría el patrón PEM (sec BAJA-2).
48
+ const PREVIEW_RAW = 4096;
49
+
50
+ /**
51
+ * Convierte una ruta (abs o rel) a relativa POSIX respecto a baseDir; null si
52
+ * escapa. Guard léxico (path.relative): rechaza `..` y rutas absolutas. NO
53
+ * resuelve symlinks — la defensa real es la sanitización + el confinamiento por
54
+ * índice + que el contenido se trata como dato (nunca se ejecuta); aceptable
55
+ * para tooling de dev donde el usuario es dueño del repo (sec BAJA-3).
56
+ */
57
+ function relPosix(baseDir, filePath) {
58
+ if (!filePath) return null;
59
+ const abs = path.isAbsolute(filePath) ? filePath : path.resolve(baseDir, filePath);
60
+ const rel = path.relative(baseDir, abs);
61
+ if (!rel || rel.startsWith('..') || path.isAbsolute(rel)) return null;
62
+ return rel.split(path.sep).join('/');
63
+ }
64
+
65
+ function _leer(baseDir, rel) {
66
+ try {
67
+ return fs.readFileSync(path.resolve(baseDir, rel), 'utf8');
68
+ } catch (_) {
69
+ return null;
70
+ }
71
+ }
72
+
73
+ /** (a) git commit del agente → registrar SHA. */
74
+ function _manejarCommit(input, sessionId, baseDir) {
75
+ if (typeof input.command !== 'string' || !/\bgit\s+commit\b/.test(input.command)) return;
76
+ let sha = '';
77
+ try {
78
+ sha = execFileSync('git', ['rev-parse', 'HEAD'], { cwd: baseDir, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
79
+ } catch (_) {
80
+ sha = '';
81
+ }
82
+ if (sha) lib.registrarCommitAgente(baseDir, { sessionId, sha });
83
+ }
84
+
85
+ /** (b) Write/Edit/MultiEdit → registrar hash del archivo tras la escritura. */
86
+ function _manejarEscritura(input, sessionId, baseDir) {
87
+ const rel = relPosix(baseDir, input.file_path);
88
+ if (!rel) return;
89
+ const contenido = _leer(baseDir, rel);
90
+ if (contenido === null) return;
91
+ lib.registrarEscrituraAgente(baseDir, rel, contenido, { sessionId });
92
+ }
93
+
94
+ /** (c) Read de archivo escrito por el agente cuyo contenido difiere → edición manual. */
95
+ function _manejarLectura(input, sessionId, baseDir) {
96
+ const rel = relPosix(baseDir, input.file_path);
97
+ if (!rel) return;
98
+ const indice = lib.leerIndiceWrites(baseDir);
99
+ if (!indice[rel]) return;
100
+ const contenido = _leer(baseDir, rel);
101
+ if (contenido === null) return;
102
+ if (lib.detectarEdicionManual(rel, contenido, indice)) {
103
+ lib.encolarAccion(baseDir, {
104
+ accion: 'edicion-manual',
105
+ archivo: rel,
106
+ evidencia: contenido.slice(0, PREVIEW_RAW),
107
+ sessionId,
108
+ });
109
+ }
110
+ }
111
+
112
+ /**
113
+ * Procesa un evento PostToolUse. Orquesta los 3 handlers según la herramienta.
114
+ * @param {object} data payload del hook (tool_name, tool_input, session_id...)
115
+ * @param {string} baseDir raíz del proyecto.
116
+ */
117
+ function procesarTurno(data, baseDir) {
118
+ if (process.env.SWL_CAPTURAR_FEEDBACK === '0') return;
119
+ if (!lib || !data) return;
120
+ const toolName = String(data.tool_name || data.tool?.name || '');
121
+ if (!toolName) return;
122
+ const sessionId = String(data.session_id || 'default');
123
+ const input = data.tool_input || data.tool?.input || {};
124
+ try {
125
+ if (toolName === 'Bash') {
126
+ _manejarCommit(input, sessionId, baseDir);
127
+ } else if (toolName === 'Write' || toolName === 'Edit' || toolName === 'MultiEdit') {
128
+ if (input.file_path) _manejarEscritura(input, sessionId, baseDir);
129
+ } else if (toolName === 'Read') {
130
+ if (input.file_path) _manejarLectura(input, sessionId, baseDir);
131
+ }
132
+ } catch (_) {
133
+ /* nunca bloquear */
134
+ }
135
+ }
136
+
137
+ // Listeners de stdin SOLO en modo CLI (evita colgar la suite de tests).
138
+ if (require.main === module) {
139
+ let inputRaw = '';
140
+ process.stdin.on('data', (c) => { inputRaw += c; });
141
+ process.stdin.on('end', () => {
142
+ try {
143
+ const data = JSON.parse(inputRaw);
144
+ procesarTurno(data, process.cwd());
145
+ } catch (_) {
146
+ /* silencioso */
147
+ }
148
+ });
149
+ } else {
150
+ module.exports = { procesarTurno, relPosix };
151
+ }
@@ -0,0 +1,155 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ /**
5
+ * Hook: captura-acciones-session.js
6
+ * Tipo: SessionStart
7
+ *
8
+ * Al abrir sesión en un repo git con `.planning/`, contrasta el git real contra
9
+ * los índices que pobló `captura-acciones-post.js` (PostToolUse) para detectar
10
+ * señales de ACCIÓN del usuario ocurridas fuera de sesión (Fase 17):
11
+ * - revert/reset de commits del agente (SHA registrado ausente del historial),
12
+ * - edición neta de archivos que el agente escribió (hash en disco ≠ registrado),
13
+ * - rechazo de plan (PLAN en borrador sin lock G1 con fase cerrada),
14
+ * - override de veredicto (VERIFICACION no-aprobatoria — caso determinista).
15
+ *
16
+ * Encola en el mismo `feedback-queue.jsonl` con `tipo:"accion"`. A diferencia
17
+ * del briefing (Fase 12), este hook NO emite `additionalContext`: solo persiste
18
+ * señales (alcance Fase 17 = capturar + telemetría). Zero-deps salvo la lib.
19
+ * Opt-out SWL_CAPTURAR_FEEDBACK=0. Skip si no hay repo git (REQ-17-11). Exit 0.
20
+ */
21
+
22
+ const fs = require('fs');
23
+ const path = require('path');
24
+ const { execFileSync } = require('child_process');
25
+
26
+ // Require dual: el instalador aplana `hooks/lib/X.js → <hooks>/X.js`. (Idioma
27
+ // compartido; no se extrae a lib por la paradoja de bootstrap del aplanado.)
28
+ function requireDual(nombre) {
29
+ try {
30
+ return require(`./lib/${nombre}`);
31
+ } catch (e1) {
32
+ if (e1 && e1.code !== 'MODULE_NOT_FOUND') throw e1;
33
+ return require(`./${nombre}`);
34
+ }
35
+ }
36
+
37
+ let lib;
38
+ try {
39
+ lib = requireDual('captura-acciones');
40
+ } catch (_) {
41
+ lib = null;
42
+ }
43
+
44
+ const PREVIEW_RAW = 4096; // ver nota en captura-acciones-post.js (no derrotar PEM)
45
+ const SHA_PREFIX_LEN = 12; // < 32 chars: no dispara PATRONES_REDACT[0] del sanitizador
46
+ const MAX_LOG = 2000; // horizonte de git log; el agente no registra commits previos a ~5 años
47
+
48
+ function esRepoGit(baseDir) {
49
+ try {
50
+ execFileSync('git', ['rev-parse', '--is-inside-work-tree'], { cwd: baseDir, stdio: 'ignore' });
51
+ return true;
52
+ } catch (_) {
53
+ return false;
54
+ }
55
+ }
56
+
57
+ function historialShas(baseDir) {
58
+ try {
59
+ return execFileSync('git', ['log', `--max-count=${MAX_LOG}`, '--format=%H'], { cwd: baseDir, encoding: 'utf8' })
60
+ .split(/\r?\n/)
61
+ .filter(Boolean);
62
+ } catch (_) {
63
+ return [];
64
+ }
65
+ }
66
+
67
+ /** (1) Revert/reset de commits del agente — REQ-17-01. */
68
+ function _encolarReverts(baseDir) {
69
+ const reverts = lib.detectarRevert(lib.leerCommitsAgente(baseDir), historialShas(baseDir));
70
+ for (const sha of reverts) {
71
+ lib.encolarAccion(baseDir, { accion: 'revert', evidencia: `commit ${sha.slice(0, SHA_PREFIX_LEN)} ausente del historial actual` });
72
+ }
73
+ return reverts.length;
74
+ }
75
+
76
+ /** (2) Edición neta de archivos escritos por el agente — REQ-17-02. */
77
+ function _encolarEdicionesNetas(baseDir) {
78
+ const indice = lib.leerIndiceWrites(baseDir);
79
+ const hashActual = {};
80
+ for (const rel of Object.keys(indice)) {
81
+ try {
82
+ hashActual[rel] = lib.hashContenido(fs.readFileSync(path.resolve(baseDir, rel), 'utf8'));
83
+ } catch (_) {
84
+ /* archivo borrado/ilegible → detectarEdicionNeta lo ignora */
85
+ }
86
+ }
87
+ const netas = lib.detectarEdicionNeta(indice, hashActual);
88
+ for (const rel of netas) {
89
+ let ev = '';
90
+ try {
91
+ ev = fs.readFileSync(path.resolve(baseDir, rel), 'utf8').slice(0, PREVIEW_RAW);
92
+ } catch (_) {
93
+ /* sin evidencia */
94
+ }
95
+ lib.encolarAccion(baseDir, { accion: 'edicion-manual', archivo: rel, evidencia: ev });
96
+ }
97
+ return netas.length;
98
+ }
99
+
100
+ /** (3) Rechazo de plan — REQ-17-04. */
101
+ function _encolarPlanesRechazados(baseDir) {
102
+ const señales = lib.detectarPlanRechazado(baseDir);
103
+ for (const s of señales) {
104
+ lib.encolarAccion(baseDir, { accion: 'plan-rechazado', archivo: s.archivo, evidencia: `plan de fase ${s.fase} en borrador sin lock G1` });
105
+ }
106
+ return señales.length;
107
+ }
108
+
109
+ /** (4) Override de veredicto — REQ-17-05 (caso determinista). */
110
+ function _encolarVeredictosOverride(baseDir) {
111
+ const señales = lib.detectarVeredictoOverride(baseDir);
112
+ for (const s of señales) {
113
+ lib.encolarAccion(baseDir, { accion: 'veredicto-override', archivo: s.archivo, evidencia: `veredicto ${s.veredicto} en ${s.archivo}` });
114
+ }
115
+ return señales.length;
116
+ }
117
+
118
+ /**
119
+ * Inspecciona el repo y encola las señales de acción detectadas.
120
+ * @param {string} baseDir raíz del proyecto.
121
+ * @returns {{encolados:number, skip?:string}}
122
+ */
123
+ function inspeccionar(baseDir) {
124
+ if (process.env.SWL_CAPTURAR_FEEDBACK === '0') return { skip: 'opt-out', encolados: 0 };
125
+ if (!lib) return { skip: 'no-lib', encolados: 0 };
126
+ if (!esRepoGit(baseDir)) return { skip: 'no-git', encolados: 0 }; // REQ-17-11
127
+ if (!fs.existsSync(path.join(baseDir, '.planning'))) return { skip: 'no-planning', encolados: 0 };
128
+
129
+ let n = 0;
130
+ try {
131
+ n += _encolarReverts(baseDir);
132
+ n += _encolarEdicionesNetas(baseDir);
133
+ n += _encolarPlanesRechazados(baseDir);
134
+ n += _encolarVeredictosOverride(baseDir);
135
+ } catch (_) {
136
+ /* nunca bloquear */
137
+ }
138
+ return { encolados: n };
139
+ }
140
+
141
+ // Listeners de stdin SOLO en modo CLI.
142
+ if (require.main === module) {
143
+ let inputRaw = '';
144
+ process.stdin.on('data', (c) => { inputRaw += c; });
145
+ process.stdin.on('end', () => {
146
+ try {
147
+ inspeccionar(process.cwd());
148
+ } catch (_) {
149
+ /* silencioso: el hook nunca bloquea la sesión */
150
+ }
151
+ // No emite additionalContext: solo persiste señales (alcance Fase 17).
152
+ });
153
+ } else {
154
+ module.exports = { inspeccionar, esRepoGit, historialShas };
155
+ }