specbox 6.36.0 → 6.37.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 +94 -0
- package/hooks/commit-spec-guard.mjs +27 -8
- package/hooks/hooks-history.json +25 -5
- package/hooks/hooks-manifest.json +11 -6
- package/hooks/lib/config.mjs +24 -1
- package/hooks/lib/enforcement-policy.mjs +8 -3
- 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/settings-hooks.json +10 -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
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* app-docs-fragment.mjs — PostToolUse: la zona «roadmap» de app_prd.md sigue al tablero (UC-12203).
|
|
4
|
+
*
|
|
5
|
+
* Tras complete_uc, move_uc, add_uc, delete_uc y mark_ac_batch el servidor devuelve
|
|
6
|
+
* `app_docs_sync.roadmap_body` (el cuerpo de la zona calculado con el tablero). Este hook lo escribe
|
|
7
|
+
* en doc/app/app_prd.md del repositorio que lo tiene: el orquestador en un proyecto multirepo (el
|
|
8
|
+
* satélite no guarda copia). Con FreeForm por fragmentos (`render: "client"`) calcula el mismo
|
|
9
|
+
* cuerpo con su items.json.
|
|
10
|
+
*
|
|
11
|
+
* Solo escribe si ese repositorio está en su rama principal (main o master): la zona sale del
|
|
12
|
+
* tablero, así que en una rama de trabajo se deja para el siguiente cambio en main y dos ramas no
|
|
13
|
+
* chocan al fusionar. Oculta el cuerpo de la respuesta que ve el modelo. Nunca bloquea.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { execFileSync } from 'node:child_process';
|
|
17
|
+
import { existsSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
18
|
+
import { isAbsolute, join, resolve } from 'node:path';
|
|
19
|
+
import { parseToolName, withoutFields } from './lib/freeform-fragment.mjs';
|
|
20
|
+
import { readHookInput } from './lib/utils.mjs';
|
|
21
|
+
import { render, replaceZone, rowsFromItems } from './lib/roadmap.mjs';
|
|
22
|
+
import { topObject } from './lib/uc-state.mjs';
|
|
23
|
+
|
|
24
|
+
const TOOLS = new Set(['complete_uc', 'move_uc', 'add_uc', 'delete_uc', 'mark_ac_batch']);
|
|
25
|
+
const DOC = join('doc', 'app', 'app_prd.md');
|
|
26
|
+
|
|
27
|
+
const { event, toolName, cwd, payload } = readHookInput();
|
|
28
|
+
const parsed = parseToolName(toolName);
|
|
29
|
+
if (event !== 'PostToolUse' || !parsed || !TOOLS.has(parsed.tool)) process.exit(0);
|
|
30
|
+
|
|
31
|
+
const git = (dir, args) => {
|
|
32
|
+
try {
|
|
33
|
+
return execFileSync('git', ['-C', dir, ...args], { encoding: 'utf-8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
|
|
34
|
+
} catch {
|
|
35
|
+
return '';
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const readJson = (path) => {
|
|
39
|
+
try {
|
|
40
|
+
return JSON.parse(readFileSync(path, 'utf-8'));
|
|
41
|
+
} catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const root = git(cwd, ['rev-parse', '--show-toplevel']) || cwd;
|
|
47
|
+
const response = payload.tool_response;
|
|
48
|
+
const sync = topObject(response)?.app_docs_sync;
|
|
49
|
+
if (!sync || sync.ok !== true || sync.zone !== 'roadmap') process.exit(0);
|
|
50
|
+
|
|
51
|
+
// El repositorio que guarda el canon: el orquestador en un satélite multirepo.
|
|
52
|
+
const settings = readJson(join(root, '.claude', 'settings.local.json')) || {};
|
|
53
|
+
const projectConfig = readJson(join(root, '.claude', 'project-config.json')) || {};
|
|
54
|
+
const mr = settings.multirepo || projectConfig.multirepo;
|
|
55
|
+
const canonRoot =
|
|
56
|
+
mr?.enabled && mr?.role === 'satellite' && mr?.orchestrator
|
|
57
|
+
? isAbsolute(mr.orchestrator) ? mr.orchestrator : resolve(root, mr.orchestrator)
|
|
58
|
+
: root;
|
|
59
|
+
const docPath = join(canonRoot, DOC);
|
|
60
|
+
|
|
61
|
+
const hide = () => {
|
|
62
|
+
if (typeof sync.roadmap_body !== 'string') return;
|
|
63
|
+
process.stdout.write(
|
|
64
|
+
JSON.stringify({ hookSpecificOutput: { hookEventName: 'PostToolUse', updatedToolOutput: withoutFields(response, ['roadmap_body']) } }),
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
const branch = git(canonRoot, ['branch', '--show-current']);
|
|
70
|
+
if (!existsSync(docPath) || !['main', 'master'].includes(branch)) {
|
|
71
|
+
hide();
|
|
72
|
+
process.exit(0);
|
|
73
|
+
}
|
|
74
|
+
let body = typeof sync.roadmap_body === 'string' ? sync.roadmap_body : null;
|
|
75
|
+
if (body == null && sync.render === 'client') {
|
|
76
|
+
const tracking = settings.specbox?.freeform_root_absolute;
|
|
77
|
+
const itemsPath = join(typeof tracking === 'string' && isAbsolute(tracking) ? tracking : join(root, 'doc', 'tracking'), 'items.json');
|
|
78
|
+
const items = readJson(itemsPath);
|
|
79
|
+
if (Array.isArray(items)) body = render(rowsFromItems(items));
|
|
80
|
+
}
|
|
81
|
+
if (body != null) {
|
|
82
|
+
const current = readFileSync(docPath, 'utf-8');
|
|
83
|
+
const next = replaceZone(current, 'roadmap', body);
|
|
84
|
+
if (next != null && next !== current) {
|
|
85
|
+
const tmp = `${docPath}.${process.pid}.tmp`;
|
|
86
|
+
writeFileSync(tmp, next, 'utf-8');
|
|
87
|
+
renameSync(tmp, docPath);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
} catch {
|
|
91
|
+
// el canon es una ayuda: nunca la razón de que falle una tool
|
|
92
|
+
}
|
|
93
|
+
hide();
|
|
94
|
+
process.exit(0);
|
|
@@ -3,7 +3,12 @@
|
|
|
3
3
|
* commit-spec-guard.mjs — PreToolUse hook for `git commit`
|
|
4
4
|
*
|
|
5
5
|
* BLOCKING (exit 2, before the commit exists):
|
|
6
|
-
* 1. Commit on main/master in a spec-driven project
|
|
6
|
+
* 1. Commit on main/master in a spec-driven project, with the EP-20 measure `commit_on_main`
|
|
7
|
+
* in «block» (UC-12215): a project recognized by its usual configuration (first-level keys)
|
|
8
|
+
* keeps the block it always had; one recognized for the first time by the `specbox` block of
|
|
9
|
+
* settings.local.json takes the board's mode, «warn» unless a person changed it. A mode a
|
|
10
|
+
* person set with set_enforcement_mode wins in both cases. In «warn» it is a note; in «off»,
|
|
11
|
+
* nothing.
|
|
7
12
|
* NOTE to the agent (additionalContext, the commit goes ahead):
|
|
8
13
|
* 2. No active UC.
|
|
9
14
|
* 3. No checkpoint saved for the active feature.
|
|
@@ -19,6 +24,7 @@
|
|
|
19
24
|
import { readHookInput, gitDirForCommand, git, fileExists, readJsonFile } from './lib/utils.mjs';
|
|
20
25
|
import { getProjectConfig } from './lib/config.mjs';
|
|
21
26
|
import { blockWith, noteWith } from './lib/output.mjs';
|
|
27
|
+
import { leerPolitica, modoDe } from './lib/enforcement-policy.mjs';
|
|
22
28
|
|
|
23
29
|
const { toolInput, cwd } = readHookInput();
|
|
24
30
|
const command = String(toolInput.command || '');
|
|
@@ -29,19 +35,32 @@ try {
|
|
|
29
35
|
process.exit(0);
|
|
30
36
|
}
|
|
31
37
|
|
|
32
|
-
const { boardId, isSpecDriven } = getProjectConfig();
|
|
38
|
+
const { boardId, backendType, isSpecDriven, recognizedBy, freeformRoot } = getProjectConfig();
|
|
33
39
|
if (!isSpecDriven) process.exit(0);
|
|
34
40
|
|
|
41
|
+
const notes = [];
|
|
35
42
|
const branch = git('branch --show-current');
|
|
36
43
|
if (branch === 'main' || branch === 'master') {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
44
|
+
// UC-12215: el modo de commit_on_main. Lo que puso una persona manda; si no, los proyectos de
|
|
45
|
+
// siempre conservan el bloqueo y los reconocidos por primera vez toman el modo del tablero.
|
|
46
|
+
const politica = await leerPolitica({ root: process.cwd(), backendType, boardId, trackingDir: freeformRoot });
|
|
47
|
+
const puesto = politica.explicitas?.includes('commit_on_main');
|
|
48
|
+
const modo = puesto || recognizedBy !== 'legacy' ? modoDe(politica, 'commit_on_main') : 'block';
|
|
49
|
+
if (modo === 'block') {
|
|
50
|
+
blockWith(`COMMIT BLOQUEADO: no se hace commit en ${branch}`, [
|
|
51
|
+
'Es un proyecto spec-driven: el trabajo va en una rama de la UC, nunca en main ni en master.',
|
|
52
|
+
'Para seguir: git checkout -b feature/{uc}-{nombre} (los cambios se van contigo) y haz el commit ahí.',
|
|
53
|
+
]);
|
|
54
|
+
}
|
|
55
|
+
if (modo === 'warn') {
|
|
56
|
+
notes.push(
|
|
57
|
+
`- Commit en ${branch}: en un proyecto spec-driven el trabajo va en una rama de la UC. La medida commit_on_main ` +
|
|
58
|
+
'está en «warn», así que el commit se hace. Para que bloquee: set_enforcement_mode(measure="commit_on_main", mode="block").',
|
|
59
|
+
);
|
|
60
|
+
}
|
|
41
61
|
}
|
|
42
62
|
|
|
43
|
-
const
|
|
44
|
-
const activeUC = fileExists('.quality/active_uc.json') ? readJsonFile('.quality/active_uc.json') : null;
|
|
63
|
+
const activeUC =fileExists('.quality/active_uc.json') ? readJsonFile('.quality/active_uc.json') : null;
|
|
45
64
|
if (!activeUC) {
|
|
46
65
|
notes.push(`- No hay UC activa (board ${boardId}): llama a start_uc antes de implementar y a mark_ac_batch al terminar.`);
|
|
47
66
|
} else if (activeUC.feature && !fileExists(`.quality/evidence/${activeUC.feature}/checkpoint.json`)) {
|
package/hooks/hooks-history.json
CHANGED
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
],
|
|
13
13
|
"commit-spec-guard.mjs": [
|
|
14
14
|
"0437bacef5d022512c37d3636bc4a9112b6bb0b13421ba35b3bb77a6eb82d900",
|
|
15
|
-
"b8d79538f6627cb19a224399770a439b4e11cd70ee5c61673dfd6ed59a939395"
|
|
15
|
+
"b8d79538f6627cb19a224399770a439b4e11cd70ee5c61673dfd6ed59a939395",
|
|
16
|
+
"08564e245b86f0e2db189da296db5c54add735bef6930591069cb7699be118c0"
|
|
16
17
|
],
|
|
17
18
|
"context-budget-guard.mjs": [
|
|
18
19
|
"9714985624215ca43f78536b47254dde8f49bb56396a8c4c40740c5fb36a69dd",
|
|
@@ -57,7 +58,8 @@
|
|
|
57
58
|
"317eabaed8dead40f3d55e642b7465a3ba4e884523e0ae7b933e197153fc6f95"
|
|
58
59
|
],
|
|
59
60
|
"lib/config.mjs": [
|
|
60
|
-
"bef622d06108aa64ec3c2d0edd1b1c82ad442476a1257b271c81838813ff1d57"
|
|
61
|
+
"bef622d06108aa64ec3c2d0edd1b1c82ad442476a1257b271c81838813ff1d57",
|
|
62
|
+
"a4458d02037cbba952a8f2240549859195788307c95b434e6fd9faa1a1591b85"
|
|
61
63
|
],
|
|
62
64
|
"lib/design-gaps.mjs": [
|
|
63
65
|
"d356d695d7afbafdc6fc420ed66603f11aa523be245bbd7a717d141a4a00701e"
|
|
@@ -140,7 +142,8 @@
|
|
|
140
142
|
"spec-guard.mjs": [
|
|
141
143
|
"8dccc74b4cf1986497c1db3b32ec52a5a842267e1ce3372b3d6fc10ba0c402e8",
|
|
142
144
|
"3a0d19ecaf523d5bd220f1ba88902e43e56caa700f115a9d8b276e48b576a5da",
|
|
143
|
-
"3524703693ef53fa3f4f9282b7bfc857ff89ce60212724526b1ed4a1fcd12563"
|
|
145
|
+
"3524703693ef53fa3f4f9282b7bfc857ff89ce60212724526b1ed4a1fcd12563",
|
|
146
|
+
"202257a18636597e7a9d1860d8ae160d7e51f9e8b5ccd539c3a5f49543bdbab7"
|
|
144
147
|
],
|
|
145
148
|
"stripe-safety-guard.mjs": [
|
|
146
149
|
"fd38c72e91c0e74ecb7dc8ccc0fa9a5f9aaa1ceeac583d13f342503f098f718a",
|
|
@@ -149,7 +152,8 @@
|
|
|
149
152
|
"uc-lifecycle-guard.mjs": [
|
|
150
153
|
"e5c31e58db639bd304faf244fd3c4ccecfc854beba2182ae6d940f52afc28808",
|
|
151
154
|
"beca70f275b1974d6609ae47f9acdbc0842d3c21e01fe9852d3a7e536f501103",
|
|
152
|
-
"2bedf19d5e36d13dff6d8cd95855ca2b5a7f47d662cc3a554c3e2f80ede199fd"
|
|
155
|
+
"2bedf19d5e36d13dff6d8cd95855ca2b5a7f47d662cc3a554c3e2f80ede199fd",
|
|
156
|
+
"606c4397200ffbc3b2c89c9af68c340692e6d48f6c792da1d6531b5215fb16e9"
|
|
153
157
|
],
|
|
154
158
|
"design-review-gate.mjs": [
|
|
155
159
|
"b2cc1ba81578102fdab4e559f8f4e8a0c37be41df75ef7ef4f531d766c1362d0"
|
|
@@ -182,6 +186,22 @@
|
|
|
182
186
|
"b05b7d9fe747524c7157c8c67979951affa234d771d3bdd038c9b58cc315f174"
|
|
183
187
|
],
|
|
184
188
|
"lib/enforcement-policy.mjs": [
|
|
185
|
-
"3fe25cc63c99d8afbc4dac8a34e142c44bd2d594efa89979993a97b8f48fe688"
|
|
189
|
+
"3fe25cc63c99d8afbc4dac8a34e142c44bd2d594efa89979993a97b8f48fe688",
|
|
190
|
+
"eed32e2ed08206d6ed22e47a0f61fb9230198376b03fab0be7fe3f54b0c2478a"
|
|
191
|
+
],
|
|
192
|
+
"app-docs-fragment.mjs": [
|
|
193
|
+
"65b82476af664547e732ed0966b07f0126a1b85dbb7f71bfef29b7c04d1115c8"
|
|
194
|
+
],
|
|
195
|
+
"lib/reservation-probe.mjs": [
|
|
196
|
+
"44566d2a92eb145a4a7252cfca8081e2101dc101bbc13faa77da8fa35b06dff0"
|
|
197
|
+
],
|
|
198
|
+
"lib/roadmap.mjs": [
|
|
199
|
+
"0ff30f9d5707c89b8b43406e76f4870a39dd4f787221c32310ef6f9040879d8a"
|
|
200
|
+
],
|
|
201
|
+
"lib/uc-state.mjs": [
|
|
202
|
+
"699786c91e83ad5b35b42f0ef812728e951be28a12ae0c037d1790795adc9e90"
|
|
203
|
+
],
|
|
204
|
+
"uc-state-marker.mjs": [
|
|
205
|
+
"7c649407416f3837196c9cf8a0caf44b8aeead7e2da9eda55ee5526972630cb2"
|
|
186
206
|
]
|
|
187
207
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "6.
|
|
2
|
+
"version": "6.37.0",
|
|
3
3
|
"files": {
|
|
4
|
+
"app-docs-fragment.mjs": "65b82476af664547e732ed0966b07f0126a1b85dbb7f71bfef29b7c04d1115c8",
|
|
4
5
|
"app-docs-sync-guard.mjs": "71f09545b57c143b013c2e532366bfdd1e1a2ae49c7644c9e12e2ab5324d03d3",
|
|
5
6
|
"branch-guard.mjs": "2185062de5f8672236a957a1ee4e7a6057c656a105bf886685f9e7bf8025c215",
|
|
6
7
|
"checkpoint-freshness-guard.mjs": "b8b6f438b6943568682776177bdac6b778df4c464e3317eb2385ed2b1b6afa96",
|
|
7
|
-
"commit-spec-guard.mjs": "
|
|
8
|
+
"commit-spec-guard.mjs": "08564e245b86f0e2db189da296db5c54add735bef6930591069cb7699be118c0",
|
|
8
9
|
"context-budget-guard.mjs": "9f6f489967ca0093266decdee0880dd1bf08eff8b8fb89d51ffc1d7b8f50cde3",
|
|
9
10
|
"design-gate.mjs": "fef11c431c2f70218a3eca97c255c10585de0dbcfef1d4ec26fad0d4702a8dbb",
|
|
10
11
|
"design-review-gate.mjs": "b2cc1ba81578102fdab4e559f8f4e8a0c37be41df75ef7ef4f531d766c1362d0",
|
|
@@ -27,15 +28,16 @@
|
|
|
27
28
|
"read-tracker.mjs": "5a22248f9d39dcc5c71abb6e2c49b8d7be3860f399023ad59f3c50e92917c298",
|
|
28
29
|
"session-heartbeat.mjs": "6aece1e95c2ef4dcb7e0f7699f5d1e75537857b863b34be108ed0fe67112781a",
|
|
29
30
|
"session-start.mjs": "0f49298cec92141c9aa1748784080d0fd630643ab5827ae4313dab3036eee78c",
|
|
30
|
-
"spec-guard.mjs": "
|
|
31
|
+
"spec-guard.mjs": "202257a18636597e7a9d1860d8ae160d7e51f9e8b5ccd539c3a5f49543bdbab7",
|
|
31
32
|
"stripe-safety-guard.mjs": "5d7c0a9524657fe47e6ec4ea0eeb055d238f133eeac488c145cb1d5ae88b96de",
|
|
32
|
-
"uc-lifecycle-guard.mjs": "
|
|
33
|
+
"uc-lifecycle-guard.mjs": "606c4397200ffbc3b2c89c9af68c340692e6d48f6c792da1d6531b5215fb16e9",
|
|
34
|
+
"uc-state-marker.mjs": "7c649407416f3837196c9cf8a0caf44b8aeead7e2da9eda55ee5526972630cb2",
|
|
33
35
|
"lib/app-spec-zones.mjs": "b05b7d9fe747524c7157c8c67979951affa234d771d3bdd038c9b58cc315f174",
|
|
34
36
|
"lib/autopilot.mjs": "317eabaed8dead40f3d55e642b7465a3ba4e884523e0ae7b933e197153fc6f95",
|
|
35
|
-
"lib/config.mjs": "
|
|
37
|
+
"lib/config.mjs": "a4458d02037cbba952a8f2240549859195788307c95b434e6fd9faa1a1591b85",
|
|
36
38
|
"lib/decisiones.mjs": "6bed3bd37320b6d87f4c77fcac27ed55a6b37776d84a0d4eb2d9cab0c474a520",
|
|
37
39
|
"lib/design-gaps.mjs": "d356d695d7afbafdc6fc420ed66603f11aa523be245bbd7a717d141a4a00701e",
|
|
38
|
-
"lib/enforcement-policy.mjs": "
|
|
40
|
+
"lib/enforcement-policy.mjs": "eed32e2ed08206d6ed22e47a0f61fb9230198376b03fab0be7fe3f54b0c2478a",
|
|
39
41
|
"lib/execution-context.mjs": "953eb7ec86f6893288df4e76c9c63c737c8e8ba4e337271402ce5eaca00330fa",
|
|
40
42
|
"lib/freeform-fragment.mjs": "23be71af8423bf8fa48dc8519734ff2bef084523a33ece555e4f96bb52bc3141",
|
|
41
43
|
"lib/freeform-path.mjs": "9ea85781821ae911873d1dbd13d58811a6c88e50480d2b3b378725ce2872be0c",
|
|
@@ -47,7 +49,10 @@
|
|
|
47
49
|
"lib/native-reservation-revalidate.mjs": "1b394e8eb5d01480b71ac0976d636814483891e9f862edd5ac0216ac0128b023",
|
|
48
50
|
"lib/output.mjs": "a568c736917720349b2b2527eb5b480bb11059a9253f81473f5b5c2c164b04bc",
|
|
49
51
|
"lib/ownership-map.mjs": "21946608331a39e8c76eb2ba3860b5ebb351aa154f31801e768703bc4ae66b9a",
|
|
52
|
+
"lib/reservation-probe.mjs": "44566d2a92eb145a4a7252cfca8081e2101dc101bbc13faa77da8fa35b06dff0",
|
|
53
|
+
"lib/roadmap.mjs": "0ff30f9d5707c89b8b43406e76f4870a39dd4f787221c32310ef6f9040879d8a",
|
|
50
54
|
"lib/token-counter.mjs": "ca637273dcf731c7a951f28b8307d13de06d311cf85741ef56c4e3df9eaa231e",
|
|
55
|
+
"lib/uc-state.mjs": "699786c91e83ad5b35b42f0ef812728e951be28a12ae0c037d1790795adc9e90",
|
|
51
56
|
"lib/utils.mjs": "4c21939aac114a11a68e2519d5d99f7f0bf482f08af0dc9e51ac715cc93ddfa2"
|
|
52
57
|
}
|
|
53
58
|
}
|
package/hooks/lib/config.mjs
CHANGED
|
@@ -7,17 +7,26 @@ import { readJsonFile, fileAge } from './utils.mjs';
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Read project configuration from .claude/project-config.json and .claude/settings.local.json.
|
|
10
|
-
* Returns { boardId, backendType, orchestratorRoot, isSpecDriven }.
|
|
10
|
+
* Returns { boardId, backendType, orchestratorRoot, isSpecDriven, recognizedBy, freeformRoot }.
|
|
11
11
|
*
|
|
12
12
|
* Multi-repo support (v5.20):
|
|
13
13
|
* If the project declares multirepo.role = "satellite" with an orchestrator path,
|
|
14
14
|
* orchestratorRoot resolves to that path. Otherwise defaults to '.' (current repo).
|
|
15
15
|
* Hooks that need cross-repo paths (design-gate, e2e-gate) use orchestratorRoot.
|
|
16
|
+
*
|
|
17
|
+
* UC-12215: `onboard_project` and the VS Code extension write the backend inside the `specbox`
|
|
18
|
+
* block of settings.local.json (`specbox.backend_type`), which the hooks did not read: those
|
|
19
|
+
* projects were not spec-driven for spec-guard, commit-spec-guard and uc-lifecycle-guard.
|
|
20
|
+
* `recognizedBy` says how the project was recognized: 'legacy' (first-level keys, as always) or
|
|
21
|
+
* 'specbox' (only the `specbox` block). A hook that blocks uses it so that a project recognized for
|
|
22
|
+
* the first time starts in «warn» (the EP-20 coexistence rule, UC-12212), not blocked.
|
|
16
23
|
*/
|
|
17
24
|
export function getProjectConfig() {
|
|
18
25
|
let boardId = '';
|
|
19
26
|
let backendType = '';
|
|
20
27
|
let orchestratorRoot = '.';
|
|
28
|
+
let recognizedBy = '';
|
|
29
|
+
let freeformRoot = '';
|
|
21
30
|
|
|
22
31
|
for (const configFile of ['.claude/project-config.json', '.claude/settings.local.json']) {
|
|
23
32
|
const config = readJsonFile(configFile);
|
|
@@ -36,12 +45,26 @@ export function getProjectConfig() {
|
|
|
36
45
|
orchestratorRoot = mr.orchestrator;
|
|
37
46
|
}
|
|
38
47
|
}
|
|
48
|
+
if (boardId || backendType) recognizedBy = 'legacy';
|
|
49
|
+
|
|
50
|
+
// UC-12215: the `specbox` block of settings.local.json (what onboard_project writes).
|
|
51
|
+
const specbox = readJsonFile('.claude/settings.local.json')?.specbox;
|
|
52
|
+
if (specbox && typeof specbox === 'object') {
|
|
53
|
+
if (!backendType && typeof specbox.backend_type === 'string') backendType = specbox.backend_type;
|
|
54
|
+
if (!boardId) {
|
|
55
|
+
boardId = specbox.board_id || specbox.trello_board_id || specbox.project_id || specbox.native_project_id || '';
|
|
56
|
+
}
|
|
57
|
+
if (typeof specbox.freeform_root_absolute === 'string') freeformRoot = specbox.freeform_root_absolute;
|
|
58
|
+
if (!recognizedBy && (boardId || backendType)) recognizedBy = 'specbox';
|
|
59
|
+
}
|
|
39
60
|
|
|
40
61
|
return {
|
|
41
62
|
boardId,
|
|
42
63
|
backendType,
|
|
43
64
|
orchestratorRoot,
|
|
44
65
|
isSpecDriven: !!(boardId || backendType),
|
|
66
|
+
recognizedBy,
|
|
67
|
+
freeformRoot,
|
|
45
68
|
};
|
|
46
69
|
}
|
|
47
70
|
|
|
@@ -37,6 +37,7 @@ export const MEASURES = {
|
|
|
37
37
|
drift_gate: 'warn',
|
|
38
38
|
impact_radius: 'warn',
|
|
39
39
|
contract_first: 'warn',
|
|
40
|
+
commit_on_main: 'warn',
|
|
40
41
|
};
|
|
41
42
|
|
|
42
43
|
/** El modo de cada medida a partir de lo guardado (o null), como effective_policy del servidor. */
|
|
@@ -44,13 +45,17 @@ export function modosDe(raw, backendType) {
|
|
|
44
45
|
const origin = raw && (raw.origin === 'new' || raw.origin === 'existing') ? raw.origin : 'existing';
|
|
45
46
|
const guardadas = raw && typeof raw.measures === 'object' && raw.measures ? raw.measures : {};
|
|
46
47
|
const modos = {};
|
|
48
|
+
const explicitas = [];
|
|
47
49
|
for (const [clave, nuevo] of Object.entries(MEASURES)) {
|
|
48
50
|
const entrada = guardadas[clave];
|
|
49
|
-
|
|
51
|
+
const guardada = !!entrada && MODES.includes(entrada.mode);
|
|
52
|
+
let modo = guardada ? entrada.mode : origin === 'new' ? nuevo : 'warn';
|
|
50
53
|
if (CAPPED_BACKENDS.has(backendType) && modo === 'block') modo = 'warn';
|
|
51
54
|
modos[clave] = modo;
|
|
55
|
+
// UC-12215: la puso una persona (no es el valor por defecto del tablero).
|
|
56
|
+
if (guardada && entrada.source !== 'default') explicitas.push(clave);
|
|
52
57
|
}
|
|
53
|
-
return { origin, backendType, modos };
|
|
58
|
+
return { origin, backendType, modos, explicitas };
|
|
54
59
|
}
|
|
55
60
|
|
|
56
61
|
/** El modo de una medida en una política leída con leerPolitica («warn» si no la conoce). */
|
|
@@ -120,7 +125,7 @@ export async function leerPolitica({
|
|
|
120
125
|
const policy = {
|
|
121
126
|
origin: r.policy.origin,
|
|
122
127
|
measures: Object.fromEntries(
|
|
123
|
-
Object.entries(r.policy.measures || {}).map(([k, v]) => [k, { mode: v?.mode }]),
|
|
128
|
+
Object.entries(r.policy.measures || {}).map(([k, v]) => [k, { mode: v?.mode, source: v?.source }]),
|
|
124
129
|
),
|
|
125
130
|
};
|
|
126
131
|
try {
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* lib/reservation-probe.mjs — spec-guard pregunta al tablero quién tiene la reserva (UC-12217).
|
|
3
|
+
*
|
|
4
|
+
* Antes pedía GET /api/native/reservation-status, que el servidor no tiene: fallaba siempre, se daba
|
|
5
|
+
* la caché por buena y el bloqueo por reserva perdida no saltaba nunca. Ahora llama a la tool de
|
|
6
|
+
* solo lectura `get_uc_reservation` con la identidad del dispositivo (`llamarTool`, tope de 3 s).
|
|
7
|
+
*
|
|
8
|
+
* - Una respuesta confirmada se guarda 60 s en .quality/reservation_check.json para no preguntar en
|
|
9
|
+
* cada escritura.
|
|
10
|
+
* - Sin credencial, sin red o sin respuesta: `reachable: false` (se usa la reserva guardada) y una
|
|
11
|
+
* nota como mucho cada 10 minutos.
|
|
12
|
+
* Nunca lanza.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
16
|
+
import { dirname, join } from 'node:path';
|
|
17
|
+
import { cabecerasDelDispositivo, URL_POR_DEFECTO } from './heartbeat-send.mjs';
|
|
18
|
+
import { llamarTool } from './mcp-client.mjs';
|
|
19
|
+
|
|
20
|
+
export const CHECK_FILE = join('.quality', 'reservation_check.json');
|
|
21
|
+
export const CONFIRMED_MS = 60_000;
|
|
22
|
+
export const OFFLINE_NOTE_MS = 10 * 60_000;
|
|
23
|
+
|
|
24
|
+
function readState(root) {
|
|
25
|
+
try {
|
|
26
|
+
return JSON.parse(readFileSync(join(root, CHECK_FILE), 'utf-8')) || {};
|
|
27
|
+
} catch {
|
|
28
|
+
return {};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function writeState(root, state) {
|
|
33
|
+
try {
|
|
34
|
+
const path = join(root, CHECK_FILE);
|
|
35
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
36
|
+
writeFileSync(path, `${JSON.stringify(state)}\n`);
|
|
37
|
+
} catch {
|
|
38
|
+
// sin caché, la próxima escritura vuelve a preguntar
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* { reachable, reservation?, why? } para la reserva guardada `{ ucId, developerId }` del proyecto.
|
|
44
|
+
* `why` explica por qué no se pudo comprobar (para la nota).
|
|
45
|
+
*/
|
|
46
|
+
export async function probeReservation({
|
|
47
|
+
root = process.cwd(),
|
|
48
|
+
projectId,
|
|
49
|
+
reservation,
|
|
50
|
+
env = process.env,
|
|
51
|
+
fetchImpl = fetch,
|
|
52
|
+
cabeceras,
|
|
53
|
+
ahora = Date.now(),
|
|
54
|
+
topeMs = 3000,
|
|
55
|
+
} = {}) {
|
|
56
|
+
if (!projectId || !reservation?.ucId) return { reachable: false, why: 'el marcador no dice de qué proyecto es' };
|
|
57
|
+
const state = readState(root);
|
|
58
|
+
const ok = state.confirmed;
|
|
59
|
+
if (ok && ok.uc_id === reservation.ucId && ok.developer_id === reservation.developerId && ahora - ok.at < CONFIRMED_MS) {
|
|
60
|
+
return { reachable: true, reservation: { developer_id: ok.developer_id }, cached: true };
|
|
61
|
+
}
|
|
62
|
+
if (env.SPECBOX_RESERVATION_CHECK === 'off') return { reachable: false, why: 'la comprobación está apagada' };
|
|
63
|
+
const url = env.SPECBOX_MCP_URL || env.SPECBOX_ENGINE_MCP_URL || URL_POR_DEFECTO;
|
|
64
|
+
try {
|
|
65
|
+
const h = cabeceras ?? (await cabecerasDelDispositivo({ ...env, CLAUDE_CODE_MCP_SERVER_URL: url }));
|
|
66
|
+
if (!h.Authorization) return { reachable: false, why: 'este equipo no tiene credencial de SpecBox' };
|
|
67
|
+
const r = await llamarTool({
|
|
68
|
+
url,
|
|
69
|
+
cabeceras: h,
|
|
70
|
+
nombre: 'get_uc_reservation',
|
|
71
|
+
args: { uc_id: reservation.ucId, project_id: projectId },
|
|
72
|
+
topeMs,
|
|
73
|
+
fetchImpl,
|
|
74
|
+
});
|
|
75
|
+
if (!r?.success) return { reachable: false, why: `el tablero no la devolvió (${r?.code || 'sin código'})` };
|
|
76
|
+
const remote = r.reservation ?? null;
|
|
77
|
+
if (remote?.developer_id === reservation.developerId) {
|
|
78
|
+
writeState(root, { ...state, confirmed: { uc_id: reservation.ucId, developer_id: remote.developer_id, at: ahora } });
|
|
79
|
+
}
|
|
80
|
+
return { reachable: true, reservation: remote };
|
|
81
|
+
} catch {
|
|
82
|
+
return { reachable: false, why: 'sin red o sin respuesta en 3 s' };
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** True si toca dar la nota de «no se pudo comprobar» (como mucho cada 10 minutos); la apunta. */
|
|
87
|
+
export function shouldNoteOffline(root = process.cwd(), ahora = Date.now()) {
|
|
88
|
+
const state = readState(root);
|
|
89
|
+
if (typeof state.offline_note_at === 'number' && ahora - state.offline_note_at < OFFLINE_NOTE_MS) return false;
|
|
90
|
+
writeState(root, { ...state, offline_note_at: ahora });
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* lib/roadmap.mjs — la zona «roadmap» de app_prd.md con lo que dice el tablero (UC-12203).
|
|
3
|
+
*
|
|
4
|
+
* Copia de `server/app_docs/roadmap.py` para FreeForm por fragmentos: el servidor no ve el tablero
|
|
5
|
+
* entero y el hook calcula el mismo cuerpo con su items.json. tests/test_app_docs_roadmap.py compara
|
|
6
|
+
* las dos salidas. `replaceZone` reemplaza el cuerpo como `replace_zone_body` (por líneas, sin tocar
|
|
7
|
+
* los marcadores ni lo de fuera).
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const US_PREFIX = /^\[?US-\d+[a-z]?\]?\s*[:—–-]?\s*/;
|
|
11
|
+
const US_ID = /^\[?(US-\d+[a-z]?)/;
|
|
12
|
+
const US_NUMBER = /^US-(\d+)/;
|
|
13
|
+
|
|
14
|
+
function title(name, usId) {
|
|
15
|
+
const text = usId ? String(name || '').trim().replace(US_PREFIX, '') : String(name || '').trim();
|
|
16
|
+
return text.split(/\s+/).filter(Boolean).join(' ').replace(/\|/g, '\\|');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function order(a, b) {
|
|
20
|
+
const na = US_NUMBER.exec(a.us_id);
|
|
21
|
+
const nb = US_NUMBER.exec(b.us_id);
|
|
22
|
+
const ka = na ? Number(na[1]) : 1e9;
|
|
23
|
+
const kb = nb ? Number(nb[1]) : 1e9;
|
|
24
|
+
if (ka !== kb) return ka - kb;
|
|
25
|
+
return a.us_id < b.us_id ? -1 : a.us_id > b.us_id ? 1 : 0;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const has = (item, label) => Array.isArray(item?.labels) && item.labels.includes(label);
|
|
29
|
+
|
|
30
|
+
/** Una fila por historia no archivada: id, título, estado y UC hechas/total (sin archivadas). */
|
|
31
|
+
export function rowsFromItems(items) {
|
|
32
|
+
const stories = new Map();
|
|
33
|
+
for (const item of items || []) {
|
|
34
|
+
if (!has(item, 'US') || item.state === 'archived') continue;
|
|
35
|
+
const usId = item.meta?.us_id || US_ID.exec(item.name || '')?.[1] || '';
|
|
36
|
+
if (usId) stories.set(item.id, { us_id: usId, title: title(item.name, usId), state: item.state || '', done: 0, total: 0 });
|
|
37
|
+
}
|
|
38
|
+
for (const item of items || []) {
|
|
39
|
+
if (!has(item, 'UC') || item.state === 'archived' || !stories.has(item.parent_id)) continue;
|
|
40
|
+
const row = stories.get(item.parent_id);
|
|
41
|
+
row.total += 1;
|
|
42
|
+
if (item.state === 'done') row.done += 1;
|
|
43
|
+
}
|
|
44
|
+
return [...stories.values()].sort(order);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** El cuerpo de la zona; mismo texto que `render` del servidor. */
|
|
48
|
+
export function render(rows) {
|
|
49
|
+
const out = [
|
|
50
|
+
'## 5. Roadmap de US',
|
|
51
|
+
'',
|
|
52
|
+
'> Esta zona la mantiene el engine con lo que dice el tablero: se regenera tras complete_uc, ' +
|
|
53
|
+
'move_uc, add_uc, delete_uc y mark_ac_batch. No la edites a mano.',
|
|
54
|
+
'',
|
|
55
|
+
'| US | Título | Estado | UCs |',
|
|
56
|
+
'|----|--------|--------|-----|',
|
|
57
|
+
];
|
|
58
|
+
if (!rows.length) out.push('| (sin historias) | | | |');
|
|
59
|
+
for (const r of rows) out.push(`| ${r.us_id} | ${r.title} | ${r.state} | ${r.done}/${r.total} |`);
|
|
60
|
+
return out.join('\n');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const START = (id) => new RegExp(`<!--\\s*@specbox:zone start\\b[^>]*\\bid=["']${id}["'][^>]*-->`);
|
|
64
|
+
const END = /<!--\s*@specbox:zone end\s*-->/;
|
|
65
|
+
|
|
66
|
+
/** `content` con el cuerpo de la zona `zoneId` cambiado por `body`, o null si no tiene esa zona. */
|
|
67
|
+
export function replaceZone(content, zoneId, body) {
|
|
68
|
+
const lines = String(content).split('\n');
|
|
69
|
+
const trailing = String(content).endsWith('\n');
|
|
70
|
+
if (trailing) lines.pop();
|
|
71
|
+
const start = lines.findIndex((l) => START(zoneId).test(l));
|
|
72
|
+
if (start < 0) return null;
|
|
73
|
+
const end = lines.findIndex((l, i) => i > start && END.test(l));
|
|
74
|
+
if (end < 0) return null;
|
|
75
|
+
const rebuilt = [...lines.slice(0, start + 1), ...(body ? body.split('\n') : []), ...lines.slice(end)];
|
|
76
|
+
return rebuilt.join('\n') + (trailing ? '\n' : '');
|
|
77
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* lib/uc-state.mjs — lo que el estado de una UC deja en el proyecto (UC-12216).
|
|
3
|
+
*
|
|
4
|
+
* Con el MCP remoto el servidor no ve el disco del proyecto: `start_uc` devuelve el marcador de UC
|
|
5
|
+
* activa (`active_uc_marker`) y el hook uc-state-marker lo escribe en .quality/active_uc.json, que
|
|
6
|
+
* leen spec-guard, commit-spec-guard y uc-lifecycle-guard. Funciones puras y una escritura atómica.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
10
|
+
import { dirname, join } from 'node:path';
|
|
11
|
+
|
|
12
|
+
export const MARKER_FILE = join('.quality', 'active_uc.json');
|
|
13
|
+
const UC_ID = /^UC-\d{1,6}[a-z]?$/;
|
|
14
|
+
|
|
15
|
+
function parse(text) {
|
|
16
|
+
try {
|
|
17
|
+
return JSON.parse(text);
|
|
18
|
+
} catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** El primer valor de `key` dentro de una respuesta MCP, tenga la forma que tenga. */
|
|
24
|
+
export function findValue(response, key, depth = 0) {
|
|
25
|
+
if (depth > 6 || response == null) return undefined;
|
|
26
|
+
if (typeof response === 'string') {
|
|
27
|
+
const text = response.trim();
|
|
28
|
+
return text.startsWith('{') || text.startsWith('[') ? findValue(parse(text), key, depth + 1) : undefined;
|
|
29
|
+
}
|
|
30
|
+
if (Array.isArray(response)) {
|
|
31
|
+
for (const part of response) {
|
|
32
|
+
const found = findValue(part, key, depth + 1);
|
|
33
|
+
if (found !== undefined) return found;
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
if (typeof response === 'object') {
|
|
38
|
+
if (key in response) return response[key];
|
|
39
|
+
for (const value of Object.values(response)) {
|
|
40
|
+
const found = findValue(value, key, depth + 1);
|
|
41
|
+
if (found !== undefined) return found;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** El objeto de primer nivel de una respuesta MCP: structuredContent, el texto JSON o el propio objeto. */
|
|
48
|
+
export function topObject(response, depth = 0) {
|
|
49
|
+
if (depth > 4 || response == null) return null;
|
|
50
|
+
if (typeof response === 'string') {
|
|
51
|
+
const text = response.trim();
|
|
52
|
+
return text.startsWith('{') || text.startsWith('[') ? topObject(parse(text), depth + 1) : null;
|
|
53
|
+
}
|
|
54
|
+
if (Array.isArray(response)) {
|
|
55
|
+
for (const part of response) {
|
|
56
|
+
const found = topObject(part?.type === 'text' ? part.text : part, depth + 1);
|
|
57
|
+
if (found) return found;
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
if (typeof response === 'object') {
|
|
62
|
+
if (response.structuredContent && typeof response.structuredContent === 'object') return response.structuredContent;
|
|
63
|
+
if (Array.isArray(response.content)) return topObject(response.content, depth + 1);
|
|
64
|
+
if (response.isError === true) return { error: 'isError' };
|
|
65
|
+
return response;
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** True si la respuesta es un error de la tool (no hay nada que apuntar). Solo mira el primer nivel. */
|
|
71
|
+
export function isError(response) {
|
|
72
|
+
const top = topObject(response);
|
|
73
|
+
if (!top) return true; // sin respuesta legible no se toca nada
|
|
74
|
+
const error = top.error;
|
|
75
|
+
return (error !== undefined && error !== null && error !== false && error !== '') || top.success === false;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** El marcador que hay que escribir tras start_uc, o null si la respuesta no trae uno válido. */
|
|
79
|
+
export function markerFrom(response) {
|
|
80
|
+
if (isError(response)) return null;
|
|
81
|
+
const marker = topObject(response)?.active_uc_marker;
|
|
82
|
+
if (!marker || typeof marker !== 'object' || !UC_ID.test(String(marker.uc_id || ''))) return null;
|
|
83
|
+
return marker;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function writeAtomic(path, content) {
|
|
87
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
88
|
+
const tmp = `${path}.${process.pid}.tmp`;
|
|
89
|
+
writeFileSync(tmp, content, 'utf-8');
|
|
90
|
+
renameSync(tmp, path);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Escribe el marcador de UC activa en `root`. Devuelve la ruta escrita. */
|
|
94
|
+
export function writeMarker(root, marker) {
|
|
95
|
+
const path = join(root, MARKER_FILE);
|
|
96
|
+
writeAtomic(path, `${JSON.stringify(marker, null, 2)}\n`);
|
|
97
|
+
return path;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Borra el marcador si es de `ucId` (o si no dice de qué UC es). Devuelve true si lo borró. */
|
|
101
|
+
export function clearMarker(root, ucId) {
|
|
102
|
+
const path = join(root, MARKER_FILE);
|
|
103
|
+
if (!existsSync(path)) return false;
|
|
104
|
+
const current = parse(readFileSync(path, 'utf-8'));
|
|
105
|
+
if (current?.uc_id && ucId && current.uc_id !== ucId) return false; // es de otra UC: se queda
|
|
106
|
+
unlinkSync(path);
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// ── Lo que mira uc-lifecycle-guard al hacer push (UC-12206) ─────────────
|
|
111
|
+
|
|
112
|
+
export const AC_MARKED = 'ac_marked.json';
|
|
113
|
+
export const MOVED_TO_REVIEW = 'uc_moved_to_review.json';
|
|
114
|
+
|
|
115
|
+
/** Los id de los criterios de la UC según la respuesta de start_uc (para saber cuáles faltan). */
|
|
116
|
+
export function acIdsFrom(response) {
|
|
117
|
+
const acs = topObject(response)?.acceptance_criteria;
|
|
118
|
+
return Array.isArray(acs) ? acs.map((a) => String(a?.id || a?.ac_id || '')).filter(Boolean) : [];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** El marcador de UC activa del proyecto, o null. */
|
|
122
|
+
export function readMarker(root) {
|
|
123
|
+
const path = join(root, MARKER_FILE);
|
|
124
|
+
return existsSync(path) ? parse(readFileSync(path, 'utf-8')) : null;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** La carpeta de evidencia de una UC: la `feature` del marcador si es la activa; si no, su id. */
|
|
128
|
+
export function evidenceDir(root, ucId) {
|
|
129
|
+
const marker = readMarker(root);
|
|
130
|
+
const feature = marker?.uc_id === ucId && marker.feature ? marker.feature : ucId;
|
|
131
|
+
return join(root, '.quality', 'evidence', String(feature).replace(/[^A-Za-z0-9._-]/g, '_'));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Suma a ac_marked.json lo que marcó mark_ac_batch: los criterios cumplidos y los no cumplidos.
|
|
136
|
+
* Un criterio que pasa después de haber fallado sale de los no cumplidos.
|
|
137
|
+
*/
|
|
138
|
+
export function recordMarkedAcs(root, ucId, response, now = new Date().toISOString()) {
|
|
139
|
+
const details = topObject(response)?.details;
|
|
140
|
+
if (!Array.isArray(details)) return null;
|
|
141
|
+
const path = join(evidenceDir(root, ucId), AC_MARKED);
|
|
142
|
+
const before = existsSync(path) ? parse(readFileSync(path, 'utf-8')) || {} : {};
|
|
143
|
+
const passed = new Set(Array.isArray(before.passed) ? before.passed : []);
|
|
144
|
+
const failed = new Set(Array.isArray(before.failed) ? before.failed : []);
|
|
145
|
+
for (const d of details) {
|
|
146
|
+
const id = String(d?.ac_id || '');
|
|
147
|
+
if (!id) continue;
|
|
148
|
+
if (d.passed) {
|
|
149
|
+
passed.add(id);
|
|
150
|
+
failed.delete(id);
|
|
151
|
+
} else {
|
|
152
|
+
failed.add(id);
|
|
153
|
+
passed.delete(id);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const out = { uc_id: ucId, passed: [...passed].sort(), failed: [...failed].sort(), at: now };
|
|
157
|
+
writeAtomic(path, `${JSON.stringify(out, null, 2)}\n`);
|
|
158
|
+
return out;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** move_uc: a revisión deja uc_moved_to_review.json; a cualquier otro estado lo quita. */
|
|
162
|
+
export function recordMove(root, ucId, target, now = new Date().toISOString()) {
|
|
163
|
+
const path = join(evidenceDir(root, ucId), MOVED_TO_REVIEW);
|
|
164
|
+
if (target === 'review') {
|
|
165
|
+
writeAtomic(path, `${JSON.stringify({ uc_id: ucId, at: now }, null, 2)}\n`);
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
if (existsSync(path)) unlinkSync(path);
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
@@ -244,6 +244,16 @@
|
|
|
244
244
|
"type": "command",
|
|
245
245
|
"command": "node .claude/hooks/freeform-fragment.mjs",
|
|
246
246
|
"timeout": 15
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
"type": "command",
|
|
250
|
+
"command": "node .claude/hooks/uc-state-marker.mjs",
|
|
251
|
+
"timeout": 5
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
"type": "command",
|
|
255
|
+
"command": "node .claude/hooks/app-docs-fragment.mjs",
|
|
256
|
+
"timeout": 5
|
|
247
257
|
}
|
|
248
258
|
]
|
|
249
259
|
},
|
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.37.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": {
|