specbox 6.36.0 → 6.38.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/hooks/app-docs-fragment.mjs +119 -0
- package/hooks/commit-spec-guard.mjs +27 -8
- package/hooks/context-budget-guard.mjs +82 -46
- package/hooks/freeform-fragment.mjs +6 -8
- package/hooks/hooks-history.json +39 -7
- package/hooks/hooks-manifest.json +16 -8
- package/hooks/lib/config.mjs +24 -1
- package/hooks/lib/enforcement-events.mjs +74 -0
- package/hooks/lib/enforcement-policy.mjs +8 -3
- package/hooks/lib/prd-locate.mjs +72 -0
- package/hooks/lib/reservation-probe.mjs +92 -0
- package/hooks/lib/roadmap.mjs +77 -0
- package/hooks/lib/uc-state.mjs +170 -0
- package/hooks/prd-sync-guard.mjs +131 -0
- package/hooks/settings-hooks.json +21 -0
- package/hooks/spec-guard.mjs +36 -50
- package/hooks/uc-lifecycle-guard.mjs +31 -20
- package/hooks/uc-state-marker.mjs +57 -0
- package/package.json +1 -1
|
@@ -138,6 +138,12 @@
|
|
|
138
138
|
"command": "node .claude/hooks/commit-spec-guard.mjs",
|
|
139
139
|
"timeout": 10
|
|
140
140
|
},
|
|
141
|
+
{
|
|
142
|
+
"type": "command",
|
|
143
|
+
"if": "Bash(*gh pr merge*)",
|
|
144
|
+
"command": "node .claude/hooks/prd-sync-guard.mjs",
|
|
145
|
+
"timeout": 20
|
|
146
|
+
},
|
|
141
147
|
{
|
|
142
148
|
"type": "command",
|
|
143
149
|
"if": "Bash(*git commit*)",
|
|
@@ -222,6 +228,11 @@
|
|
|
222
228
|
"type": "command",
|
|
223
229
|
"command": "node .claude/hooks/freeform-fragment.mjs",
|
|
224
230
|
"timeout": 15
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
"type": "command",
|
|
234
|
+
"command": "node .claude/hooks/app-docs-fragment.mjs",
|
|
235
|
+
"timeout": 5
|
|
225
236
|
}
|
|
226
237
|
]
|
|
227
238
|
},
|
|
@@ -244,6 +255,16 @@
|
|
|
244
255
|
"type": "command",
|
|
245
256
|
"command": "node .claude/hooks/freeform-fragment.mjs",
|
|
246
257
|
"timeout": 15
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
"type": "command",
|
|
261
|
+
"command": "node .claude/hooks/uc-state-marker.mjs",
|
|
262
|
+
"timeout": 5
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
"type": "command",
|
|
266
|
+
"command": "node .claude/hooks/app-docs-fragment.mjs",
|
|
267
|
+
"timeout": 5
|
|
247
268
|
}
|
|
248
269
|
]
|
|
249
270
|
},
|
package/hooks/spec-guard.mjs
CHANGED
|
@@ -14,53 +14,16 @@
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
import { execFileSync } from 'node:child_process';
|
|
17
|
-
import { readStdin, fileExists, fileAge, git } from './lib/utils.mjs';
|
|
17
|
+
import { readStdin, fileExists, fileAge, git, readJsonFile } from './lib/utils.mjs';
|
|
18
18
|
import { blockWith, noteWith } from './lib/output.mjs';
|
|
19
19
|
import { dirname, isAbsolute } from 'node:path';
|
|
20
20
|
import { getProjectConfig, getActiveUC, getActiveUCReservation, getStaleUC } from './lib/config.mjs';
|
|
21
21
|
import { decideNativeReservation } from './lib/native-reservation-revalidate.mjs';
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
* so the cache is trusted [AC-21]. Online conflicts are surfaced for AC-22.
|
|
28
|
-
*
|
|
29
|
-
* Endpoint: GET /api/native/reservation-status?uc_id=...
|
|
30
|
-
* Expected response: { uc_id, reservation: { developer_id } | null }
|
|
31
|
-
*
|
|
32
|
-
* Wire-protocol compat (v5.35-v5.36): if the MCP returns the legacy shape
|
|
33
|
-
* { uc_id, claim: {…} | null } we pass `claim` through too, and the pure
|
|
34
|
-
* decision module accepts both. UC-612 removes the fallback in v5.37.0.
|
|
35
|
-
*/
|
|
36
|
-
function probeNativeReservation(reservation) {
|
|
37
|
-
const mcpUrl = process.env.SPECBOX_ENGINE_MCP_URL || process.env.DEV_ENGINE_MCP_URL || '';
|
|
38
|
-
if (!mcpUrl) return { reachable: false };
|
|
39
|
-
try {
|
|
40
|
-
const url = `${mcpUrl.replace(/\/$/, '')}/api/native/reservation-status`;
|
|
41
|
-
const out = execFileSync(
|
|
42
|
-
'curl',
|
|
43
|
-
[
|
|
44
|
-
'-fsS', '--max-time', '3',
|
|
45
|
-
'-L', // follow redirects so a server still serving the legacy URL
|
|
46
|
-
// with a 301 to /reservation-status works transparently
|
|
47
|
-
'-G', url,
|
|
48
|
-
'--data-urlencode', `uc_id=${reservation.ucId}`,
|
|
49
|
-
],
|
|
50
|
-
{ encoding: 'utf8', timeout: 4000, stdio: ['ignore', 'pipe', 'ignore'] },
|
|
51
|
-
);
|
|
52
|
-
const data = JSON.parse(out);
|
|
53
|
-
return {
|
|
54
|
-
reachable: true,
|
|
55
|
-
reservation: data.reservation ?? null,
|
|
56
|
-
// Forward the legacy `claim` field too so the pure decision module
|
|
57
|
-
// can fall back if the server has not yet upgraded.
|
|
58
|
-
claim: data.claim ?? undefined,
|
|
59
|
-
};
|
|
60
|
-
} catch {
|
|
61
|
-
return { reachable: false };
|
|
62
|
-
}
|
|
63
|
-
}
|
|
22
|
+
// UC-12217: la reserva se revisa con la tool get_uc_reservation (identidad del dispositivo, 3 s).
|
|
23
|
+
// Antes era un curl a /api/native/reservation-status, que el servidor no tiene: fallaba siempre,
|
|
24
|
+
// se daba la caché por buena y el bloqueo por reserva perdida no saltaba nunca.
|
|
25
|
+
import { probeReservation, shouldNoteOffline } from './lib/reservation-probe.mjs';
|
|
26
|
+
import { leerPolitica, modoDe } from './lib/enforcement-policy.mjs';
|
|
64
27
|
|
|
65
28
|
const input = readStdin();
|
|
66
29
|
|
|
@@ -98,7 +61,7 @@ if (isAbsolute(filePath)) {
|
|
|
98
61
|
}
|
|
99
62
|
|
|
100
63
|
// --- Check if project is spec-driven ---
|
|
101
|
-
const { boardId, backendType, isSpecDriven } = getProjectConfig();
|
|
64
|
+
const { boardId, backendType, isSpecDriven, recognizedBy, freeformRoot } = getProjectConfig();
|
|
102
65
|
|
|
103
66
|
// If no board and no backend configured → not spec-driven, allow
|
|
104
67
|
if (!isSpecDriven) {
|
|
@@ -109,11 +72,26 @@ if (!isSpecDriven) {
|
|
|
109
72
|
const currentBranch = git('branch --show-current');
|
|
110
73
|
|
|
111
74
|
if (currentBranch === 'main' || currentBranch === 'master') {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
75
|
+
// UC-12215: misma regla que commit-spec-guard con la medida commit_on_main. Los proyectos de
|
|
76
|
+
// siempre conservan el bloqueo; los reconocidos por primera vez toman el modo del tablero
|
|
77
|
+
// («warn» salvo que una persona lo cambie); lo que puso una persona manda.
|
|
78
|
+
const politica = await leerPolitica({ root: process.cwd(), backendType, boardId, trackingDir: freeformRoot });
|
|
79
|
+
const puesto = politica.explicitas?.includes('commit_on_main');
|
|
80
|
+
const modo = puesto || recognizedBy !== 'legacy' ? modoDe(politica, 'commit_on_main') : 'block';
|
|
81
|
+
if (modo === 'block') {
|
|
82
|
+
blockWith(`SPEC GUARD: código escrito en ${currentBranch}`, [
|
|
83
|
+
`Fichero: ${filePath}`,
|
|
84
|
+
'Es un proyecto spec-driven: el código va en una rama de la UC, nunca en main ni en master.',
|
|
85
|
+
'La escritura ya está hecha. Antes de seguir: git checkout -b feature/{uc}-{nombre} (los cambios se van contigo).',
|
|
86
|
+
]);
|
|
87
|
+
}
|
|
88
|
+
if (modo === 'warn') {
|
|
89
|
+
noteWith('PostToolUse', `SPEC GUARD: código escrito en ${currentBranch}`, [
|
|
90
|
+
`Fichero: ${filePath}`,
|
|
91
|
+
'En un proyecto spec-driven el código va en una rama de la UC. La medida commit_on_main está en «warn»: sigue, pero conviene moverlo:',
|
|
92
|
+
'git checkout -b feature/{uc}-{nombre} (los cambios se van contigo).',
|
|
93
|
+
]);
|
|
94
|
+
}
|
|
117
95
|
}
|
|
118
96
|
|
|
119
97
|
// --- Spec-driven project: verify active UC ---
|
|
@@ -125,7 +103,15 @@ if (activeUC) {
|
|
|
125
103
|
// dev [AC-22].
|
|
126
104
|
const reservation = getActiveUCReservation();
|
|
127
105
|
if (reservation) {
|
|
128
|
-
const
|
|
106
|
+
const projectId = readJsonFile('.quality/active_uc.json')?.board_id || boardId;
|
|
107
|
+
const probe = await probeReservation({ root: process.cwd(), projectId, reservation });
|
|
108
|
+
const decision = decideNativeReservation(reservation, probe);
|
|
109
|
+
if (decision.reason === 'offline-cache-trusted' && shouldNoteOffline(process.cwd())) {
|
|
110
|
+
noteWith('PostToolUse', 'SPEC GUARD: reserva sin comprobar con el tablero', [
|
|
111
|
+
`UC: ${reservation.ucId} · no se pudo preguntar al tablero (${probe.why || 'sin respuesta'}).`,
|
|
112
|
+
'Se usa la reserva guardada en .quality/active_uc.json; se vuelve a comprobar en la siguiente escritura.',
|
|
113
|
+
]);
|
|
114
|
+
}
|
|
129
115
|
if (!decision.allow) {
|
|
130
116
|
const actual = decision.conflict?.actual;
|
|
131
117
|
blockWith('SPEC GUARD: la reserva de la UC ya no es tuya', [
|
|
@@ -6,6 +6,11 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Also warns if mark_ac_batch hasn't been called (no ACs marked).
|
|
8
8
|
*
|
|
9
|
+
* UC-12206: los ficheros que mira (.quality/evidence/<feature>/ac_marked.json y
|
|
10
|
+
* uc_moved_to_review.json) los escribe el hook uc-state-marker con lo que devuelven mark_ac_batch y
|
|
11
|
+
* move_uc; antes no los escribía nadie y el aviso salía en cada push. El aviso nombra lo que falta:
|
|
12
|
+
* los criterios sin marcar (con los de la UC que guarda el marcador) o la UC fuera de revisión.
|
|
13
|
+
*
|
|
9
14
|
* v5.19.0 — Compliance Enforcement
|
|
10
15
|
*/
|
|
11
16
|
|
|
@@ -47,32 +52,38 @@ if (!activeUC) {
|
|
|
47
52
|
process.exit(0);
|
|
48
53
|
}
|
|
49
54
|
|
|
50
|
-
const feature = activeUC.feature;
|
|
55
|
+
const feature = activeUC.feature || activeUC.ucId;
|
|
51
56
|
const warnings = [];
|
|
52
57
|
|
|
53
|
-
//
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
// Los escribe el hook uc-state-marker con lo que devuelven mark_ac_batch y move_uc (UC-12206).
|
|
59
|
+
const evidenceDir = `.quality/evidence/${String(feature).replace(/[^A-Za-z0-9._-]/g, '_')}`;
|
|
60
|
+
|
|
61
|
+
// Check 1: criterios sin marcar como cumplidos.
|
|
62
|
+
const marked = readJsonFile(`${evidenceDir}/ac_marked.json`);
|
|
63
|
+
const audit = readJsonFile(`${evidenceDir}/audit.json`);
|
|
64
|
+
const marker = readJsonFile('.quality/active_uc.json') || {};
|
|
65
|
+
const acIds = Array.isArray(marker.ac_ids) ? marker.ac_ids : [];
|
|
66
|
+
if (!marked && !audit?.ac_results) {
|
|
67
|
+
warnings.push(
|
|
68
|
+
'Criterios sin marcar: no consta ningún mark_ac_batch de esta UC, así que el board no dice cuáles se cumplen.' +
|
|
69
|
+
(acIds.length ? ` Faltan ${acIds.join(', ')}.` : '')
|
|
70
|
+
);
|
|
71
|
+
} else if (marked) {
|
|
72
|
+
const passed = new Set(Array.isArray(marked.passed) ? marked.passed : []);
|
|
73
|
+
const missing = acIds.filter((id) => !passed.has(id));
|
|
74
|
+
const failed = Array.isArray(marked.failed) ? marked.failed : [];
|
|
75
|
+
if (missing.length) {
|
|
76
|
+
warnings.push(`Criterios sin marcar como cumplidos: ${missing.join(', ')}.`);
|
|
77
|
+
} else if (failed.length) {
|
|
78
|
+
warnings.push(`Criterios marcados como no cumplidos: ${failed.join(', ')}.`);
|
|
65
79
|
}
|
|
66
80
|
}
|
|
67
81
|
|
|
68
|
-
// Check 2:
|
|
69
|
-
|
|
70
|
-
const moveMarkerFile = `${evidenceDir}/uc_moved_to_review.json`;
|
|
71
|
-
if (!fileExists(moveMarkerFile)) {
|
|
82
|
+
// Check 2: la UC fuera de revisión.
|
|
83
|
+
if (!fileExists(`${evidenceDir}/uc_moved_to_review.json`)) {
|
|
72
84
|
warnings.push(
|
|
73
|
-
`UC
|
|
74
|
-
|
|
75
|
-
'The board must reflect the current state.'
|
|
85
|
+
`UC fuera de revisión: ${activeUC.ucId} no se ha movido a «review». ` +
|
|
86
|
+
'Llama a move_uc(board_id, uc_id, "review") antes o después de abrir la PR.'
|
|
76
87
|
);
|
|
77
88
|
}
|
|
78
89
|
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* uc-state-marker.mjs — PostToolUse de las tools de SpecBox: el estado de la UC queda en el proyecto (UC-12216).
|
|
4
|
+
*
|
|
5
|
+
* Con el MCP remoto, `start_uc` no puede escribir .quality/active_uc.json en el disco del proyecto:
|
|
6
|
+
* lo devuelve como `active_uc_marker` y este hook lo escribe. `complete_uc` y `release_uc` lo borran
|
|
7
|
+
* si es de esa UC. Con el MCP local el servidor ya lo escribe; repetirlo deja el mismo fichero.
|
|
8
|
+
*
|
|
9
|
+
* UC-12206: también deja lo que mira uc-lifecycle-guard al hacer push: ac_marked.json tras
|
|
10
|
+
* mark_ac_batch (criterios cumplidos y no cumplidos) y uc_moved_to_review.json tras move_uc a
|
|
11
|
+
* revisión; el marcador guarda los criterios de la UC para saber cuáles faltan.
|
|
12
|
+
*
|
|
13
|
+
* Nunca bloquea ni escribe al agente: si no puede, se calla.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { execFileSync } from 'node:child_process';
|
|
17
|
+
import { parseToolName } from './lib/freeform-fragment.mjs';
|
|
18
|
+
import { acIdsFrom, clearMarker, isError, markerFrom, recordMarkedAcs, recordMove, writeMarker } from './lib/uc-state.mjs';
|
|
19
|
+
import { readHookInput } from './lib/utils.mjs';
|
|
20
|
+
|
|
21
|
+
const { event, toolName, toolInput, cwd, payload } = readHookInput();
|
|
22
|
+
const parsed = parseToolName(toolName);
|
|
23
|
+
if (event !== 'PostToolUse' || !parsed) process.exit(0);
|
|
24
|
+
|
|
25
|
+
const root = (() => {
|
|
26
|
+
try {
|
|
27
|
+
return (
|
|
28
|
+
execFileSync('git', ['-C', cwd, 'rev-parse', '--show-toplevel'], {
|
|
29
|
+
encoding: 'utf-8',
|
|
30
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
31
|
+
}).trim() || cwd
|
|
32
|
+
);
|
|
33
|
+
} catch {
|
|
34
|
+
return cwd;
|
|
35
|
+
}
|
|
36
|
+
})();
|
|
37
|
+
|
|
38
|
+
const response = payload.tool_response;
|
|
39
|
+
try {
|
|
40
|
+
if (parsed.tool === 'start_uc') {
|
|
41
|
+
const marker = markerFrom(response);
|
|
42
|
+
if (marker) {
|
|
43
|
+
const acIds = acIdsFrom(response);
|
|
44
|
+
writeMarker(root, acIds.length ? { ...marker, ac_ids: acIds } : marker);
|
|
45
|
+
recordMove(root, marker.uc_id, 'in_progress'); // la UC vuelve a estar en curso
|
|
46
|
+
}
|
|
47
|
+
} else if (parsed.tool === 'mark_ac_batch') {
|
|
48
|
+
if (!isError(response) && toolInput.uc_id) recordMarkedAcs(root, toolInput.uc_id, response);
|
|
49
|
+
} else if (parsed.tool === 'move_uc') {
|
|
50
|
+
if (!isError(response) && toolInput.uc_id) recordMove(root, toolInput.uc_id, toolInput.target);
|
|
51
|
+
} else if (parsed.tool === 'complete_uc' || parsed.tool === 'release_uc') {
|
|
52
|
+
if (!isError(response)) clearMarker(root, toolInput.uc_id);
|
|
53
|
+
}
|
|
54
|
+
} catch {
|
|
55
|
+
// el marcador es una ayuda para los hooks: nunca la razón de que falle una tool
|
|
56
|
+
}
|
|
57
|
+
process.exit(0);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "specbox",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.38.0",
|
|
4
4
|
"description": "Conecta este ordenador a SpecBox sin copiar tokens (specbox login, status y logout) y actualiza los hooks del proyecto sin pisar los tuyos (specbox hooks).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|