specbox 6.35.0 → 6.36.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.
|
@@ -15,15 +15,28 @@
|
|
|
15
15
|
* Never blocks a call: when it cannot act it stays silent and the call goes as
|
|
16
16
|
* the model wrote it. A failed merge exits 2 with what was not saved; the
|
|
17
17
|
* fragment stays in .quality/freeform-fragments/ for recovery.
|
|
18
|
+
*
|
|
19
|
+
* The EP-20 policy (UC-12212): the policy tools get doc/tracking/policy.json as
|
|
20
|
+
* `policy_content` (and the git author as `actor`); what set_enforcement_mode and
|
|
21
|
+
* skip_enforcement return is written back. A new board from setup_board writes
|
|
22
|
+
* the policy only when the project has none. UC-12213: set_enforcement_mode and
|
|
23
|
+
* get_enforcement_impact also get items.json (`board_content`) and the blocks
|
|
24
|
+
* (`events_content`); the `event_line` of skip_enforcement and
|
|
25
|
+
* record_enforcement_event is appended to doc/tracking/enforcement_events.jsonl.
|
|
18
26
|
*/
|
|
19
27
|
|
|
20
28
|
import { execFileSync } from 'node:child_process';
|
|
21
|
-
import { existsSync, readFileSync, unlinkSync } from 'node:fs';
|
|
22
|
-
import { isAbsolute, join } from 'node:path';
|
|
29
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync, unlinkSync } from 'node:fs';
|
|
30
|
+
import { dirname, isAbsolute, join } from 'node:path';
|
|
23
31
|
import { isRemoteMcp } from './lib/freeform-path.mjs';
|
|
24
32
|
import {
|
|
25
33
|
CONTENT_TOOLS,
|
|
34
|
+
POLICY_BOARD_TOOLS,
|
|
35
|
+
POLICY_EVENT_TOOLS,
|
|
36
|
+
POLICY_TOOLS,
|
|
37
|
+
POLICY_WRITERS,
|
|
26
38
|
buildItemsContent,
|
|
39
|
+
extractField,
|
|
27
40
|
extractItemsContent,
|
|
28
41
|
mergeFragment,
|
|
29
42
|
parseToolName,
|
|
@@ -37,7 +50,8 @@ import { readHookInput } from './lib/utils.mjs';
|
|
|
37
50
|
|
|
38
51
|
const { event, toolName, toolInput, cwd, payload } = readHookInput();
|
|
39
52
|
const parsed = parseToolName(toolName);
|
|
40
|
-
|
|
53
|
+
const isPolicyTool = !!parsed && POLICY_TOOLS.has(parsed.tool);
|
|
54
|
+
if (!parsed || !(CONTENT_TOOLS.has(parsed.tool) || isPolicyTool) || !payload.tool_use_id) process.exit(0);
|
|
41
55
|
|
|
42
56
|
const root = (() => {
|
|
43
57
|
try {
|
|
@@ -57,13 +71,94 @@ const trackingDir =
|
|
|
57
71
|
? settings.freeform_root_absolute
|
|
58
72
|
: join(root, 'doc', 'tracking');
|
|
59
73
|
const itemsPath = join(trackingDir, 'items.json');
|
|
74
|
+
const policyPath = join(trackingDir, 'policy.json');
|
|
75
|
+
const eventsPath = join(trackingDir, 'enforcement_events.jsonl');
|
|
60
76
|
const stateDir = join(root, '.quality', 'freeform-fragments');
|
|
61
77
|
const pending = pendingPath(stateDir, payload.tool_use_id);
|
|
62
78
|
|
|
79
|
+
if (isPolicyTool) {
|
|
80
|
+
if (event === 'PreToolUse') prePolicy();
|
|
81
|
+
else if (event === 'PostToolUse') postPolicy();
|
|
82
|
+
process.exit(0);
|
|
83
|
+
}
|
|
63
84
|
if (event === 'PreToolUse') pre();
|
|
64
85
|
else if (event === 'PostToolUse') post();
|
|
65
86
|
process.exit(0);
|
|
66
87
|
|
|
88
|
+
function gitAuthor() {
|
|
89
|
+
try {
|
|
90
|
+
return execFileSync('git', ['-C', root, 'config', 'user.name'], {
|
|
91
|
+
encoding: 'utf-8',
|
|
92
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
93
|
+
}).trim();
|
|
94
|
+
} catch {
|
|
95
|
+
return '';
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function prePolicy() {
|
|
100
|
+
if (typeof toolInput.policy_content === 'string') return; // explicit content wins
|
|
101
|
+
const read = (path) => (existsSync(path) ? readFileSync(path, 'utf-8') : '');
|
|
102
|
+
const updatedInput = { ...toolInput, policy_content: read(policyPath) };
|
|
103
|
+
if (POLICY_BOARD_TOOLS.has(parsed.tool)) {
|
|
104
|
+
// UC-12213: the impact report needs the open UCs and the blocks of the last days.
|
|
105
|
+
if (typeof toolInput.board_content !== 'string') updatedInput.board_content = read(itemsPath) || '[]';
|
|
106
|
+
if (typeof toolInput.events_content !== 'string') updatedInput.events_content = read(eventsPath);
|
|
107
|
+
}
|
|
108
|
+
const author = gitAuthor();
|
|
109
|
+
if (author && !toolInput.actor) updatedInput.actor = author.slice(0, 80);
|
|
110
|
+
process.stdout.write(JSON.stringify({ hookSpecificOutput: { hookEventName: 'PreToolUse', updatedInput } }));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function postPolicy() {
|
|
114
|
+
const response = payload.tool_response;
|
|
115
|
+
const notes = [];
|
|
116
|
+
try {
|
|
117
|
+
const line = POLICY_EVENT_TOOLS.has(parsed.tool) ? extractField(response, 'event_line') : null;
|
|
118
|
+
if (line != null) {
|
|
119
|
+
JSON.parse(line);
|
|
120
|
+
mkdirSync(dirname(eventsPath), { recursive: true });
|
|
121
|
+
appendFileSync(eventsPath, `${line}\n`, 'utf-8');
|
|
122
|
+
notes.push(`el registro en ${eventsPath.replace(`${root}/`, '')}`);
|
|
123
|
+
}
|
|
124
|
+
const content = POLICY_WRITERS.has(parsed.tool) ? extractField(response, 'policy_content') : null;
|
|
125
|
+
if (content != null) {
|
|
126
|
+
JSON.parse(content);
|
|
127
|
+
writeAtomic(policyPath, content.endsWith('\n') ? content : `${content}\n`);
|
|
128
|
+
notes.unshift(`la política en ${policyPath.replace(`${root}/`, '')}`);
|
|
129
|
+
}
|
|
130
|
+
} catch (err) {
|
|
131
|
+
process.stderr.write(
|
|
132
|
+
`SpecBox freeform-fragment: no se pudo guardar lo que devolvió ${parsed.tool} (${err.message}). ` +
|
|
133
|
+
'Repite la llamada antes de seguir.\n',
|
|
134
|
+
);
|
|
135
|
+
process.exit(2);
|
|
136
|
+
}
|
|
137
|
+
const visible = ['policy_content', 'event_line'].some((k) => extractField(response, k) != null);
|
|
138
|
+
if (!visible && notes.length === 0) return; // a read without anything to hide, or an error
|
|
139
|
+
writeHidden(response, notes.length ? `SpecBox: guardado ${notes.join(' y ')}. No lo escribas a mano.` : null);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function writeHidden(response, note) {
|
|
143
|
+
const out = { hookEventName: 'PostToolUse', updatedToolOutput: withoutItemsContent(response) };
|
|
144
|
+
if (note) out.additionalContext = note;
|
|
145
|
+
process.stdout.write(JSON.stringify({ hookSpecificOutput: out }));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** setup_board of a new board: the policy with origin «new», only if the project has none. */
|
|
149
|
+
function savePolicyOfNewBoard(response) {
|
|
150
|
+
if (parsed.tool !== 'setup_board' || existsSync(policyPath)) return false;
|
|
151
|
+
const content = extractField(response, 'policy_content');
|
|
152
|
+
if (content == null) return false;
|
|
153
|
+
try {
|
|
154
|
+
JSON.parse(content);
|
|
155
|
+
writeAtomic(policyPath, content.endsWith('\n') ? content : `${content}\n`);
|
|
156
|
+
return true;
|
|
157
|
+
} catch {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
67
162
|
function pre() {
|
|
68
163
|
const raw = existsSync(itemsPath) ? readFileSync(itemsPath, 'utf-8') : '[]';
|
|
69
164
|
const items = parseJson(raw);
|
|
@@ -121,6 +216,7 @@ function post() {
|
|
|
121
216
|
unlinkSync(pending);
|
|
122
217
|
return merged.length - local.length;
|
|
123
218
|
});
|
|
219
|
+
const policySaved = savePolicyOfNewBoard(response);
|
|
124
220
|
process.stdout.write(
|
|
125
221
|
JSON.stringify({
|
|
126
222
|
hookSpecificOutput: {
|
|
@@ -129,6 +225,7 @@ function post() {
|
|
|
129
225
|
additionalContext:
|
|
130
226
|
`SpecBox: el tablero ya está guardado en ${itemsPath.replace(`${root}/`, '')}` +
|
|
131
227
|
(changes ? ` (${changes > 0 ? '+' : ''}${changes} elementos)` : '') +
|
|
228
|
+
(policySaved ? `, con su política en ${policyPath.replace(`${root}/`, '')}` : '') +
|
|
132
229
|
'. No lo escribas a mano.',
|
|
133
230
|
},
|
|
134
231
|
}),
|
package/hooks/hooks-history.json
CHANGED
|
@@ -170,13 +170,18 @@
|
|
|
170
170
|
"6aece1e95c2ef4dcb7e0f7699f5d1e75537857b863b34be108ed0fe67112781a"
|
|
171
171
|
],
|
|
172
172
|
"freeform-fragment.mjs": [
|
|
173
|
-
"fcb1fc9a1494c1c63870bdec08368bf3c815b1372e220a6311535b0431c86061"
|
|
173
|
+
"fcb1fc9a1494c1c63870bdec08368bf3c815b1372e220a6311535b0431c86061",
|
|
174
|
+
"c8c507e2bd1bfa11f681a70b0f236bbc0d23447140ee4424a25533669beb17b4"
|
|
174
175
|
],
|
|
175
176
|
"lib/freeform-fragment.mjs": [
|
|
176
177
|
"d30a15b495cf18cad571e8582b4ce943a75aa4ad8efc5fa11e22420b505dad12",
|
|
177
|
-
"344f1d55608ec6f39696e6c01a58b7a8f11428887445e153ee5e5d2085a209a1"
|
|
178
|
+
"344f1d55608ec6f39696e6c01a58b7a8f11428887445e153ee5e5d2085a209a1",
|
|
179
|
+
"23be71af8423bf8fa48dc8519734ff2bef084523a33ece555e4f96bb52bc3141"
|
|
178
180
|
],
|
|
179
181
|
"lib/app-spec-zones.mjs": [
|
|
180
182
|
"b05b7d9fe747524c7157c8c67979951affa234d771d3bdd038c9b58cc315f174"
|
|
183
|
+
],
|
|
184
|
+
"lib/enforcement-policy.mjs": [
|
|
185
|
+
"3fe25cc63c99d8afbc4dac8a34e142c44bd2d594efa89979993a97b8f48fe688"
|
|
181
186
|
]
|
|
182
187
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "6.
|
|
2
|
+
"version": "6.36.0",
|
|
3
3
|
"files": {
|
|
4
4
|
"app-docs-sync-guard.mjs": "71f09545b57c143b013c2e532366bfdd1e1a2ae49c7644c9e12e2ab5324d03d3",
|
|
5
5
|
"branch-guard.mjs": "2185062de5f8672236a957a1ee4e7a6057c656a105bf886685f9e7bf8025c215",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"design-system-gate.mjs": "419018cadb3e0a4fe0def1c423fed7013b76b2f121312acadbc99fc8e30b8ff5",
|
|
12
12
|
"e2e-gate.mjs": "02e239816cb429f76034088a5370f63a08facce01b4ffd52b338a66acf13028d",
|
|
13
13
|
"file-ownership-guard.mjs": "d8a84370766966cce70b76811de9dd150d170a79c4cb7b9e6b120cfad86a6932",
|
|
14
|
-
"freeform-fragment.mjs": "
|
|
14
|
+
"freeform-fragment.mjs": "c8c507e2bd1bfa11f681a70b0f236bbc0d23447140ee4424a25533669beb17b4",
|
|
15
15
|
"freeform-path-guard.mjs": "9ded19e96b0738de5aaf43a97eaa1d88ecd3b341efd432c0b32eb312c4bf5e0a",
|
|
16
16
|
"healing-budget-guard.mjs": "c49c6c34f99545e4009ad88ed9f7eef737e35ce39c11a05d41ad8f976ffae09f",
|
|
17
17
|
"implement-checkpoint.mjs": "f3f219779a1ac4108bc3aabcc7311e9135d9c7795c126a2b5d659e743f5a5a64",
|
|
@@ -35,8 +35,9 @@
|
|
|
35
35
|
"lib/config.mjs": "bef622d06108aa64ec3c2d0edd1b1c82ad442476a1257b271c81838813ff1d57",
|
|
36
36
|
"lib/decisiones.mjs": "6bed3bd37320b6d87f4c77fcac27ed55a6b37776d84a0d4eb2d9cab0c474a520",
|
|
37
37
|
"lib/design-gaps.mjs": "d356d695d7afbafdc6fc420ed66603f11aa523be245bbd7a717d141a4a00701e",
|
|
38
|
+
"lib/enforcement-policy.mjs": "3fe25cc63c99d8afbc4dac8a34e142c44bd2d594efa89979993a97b8f48fe688",
|
|
38
39
|
"lib/execution-context.mjs": "953eb7ec86f6893288df4e76c9c63c737c8e8ba4e337271402ce5eaca00330fa",
|
|
39
|
-
"lib/freeform-fragment.mjs": "
|
|
40
|
+
"lib/freeform-fragment.mjs": "23be71af8423bf8fa48dc8519734ff2bef084523a33ece555e4f96bb52bc3141",
|
|
40
41
|
"lib/freeform-path.mjs": "9ea85781821ae911873d1dbd13d58811a6c88e50480d2b3b378725ce2872be0c",
|
|
41
42
|
"lib/handoff-builder.mjs": "2f7ffd554484d9560f525ab2548c240bac65b23bbe6eb8907e64c66bd818e22d",
|
|
42
43
|
"lib/heartbeat-send.mjs": "739d4fe4b573e99fffdad2252a75cb7dcf18526dda72f1db6cff25b16f76383a",
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* lib/enforcement-policy.mjs — el modo de cada medida de EP-20 visto desde los hooks (US-122 · UC-12212).
|
|
3
|
+
*
|
|
4
|
+
* Los hooks y el servidor leen el mismo modo del tablero:
|
|
5
|
+
*
|
|
6
|
+
* - FreeForm: doc/tracking/policy.json, el mismo fichero que el servidor recibe en `policy_content`
|
|
7
|
+
* (MCP remoto) o lee del disco (MCP local).
|
|
8
|
+
* - native: la tool `get_enforcement_policy` con la identidad del dispositivo; la respuesta se guarda
|
|
9
|
+
* en .quality/enforcement_policy.json durante 10 minutos. Sin red se usa la última copia y, sin
|
|
10
|
+
* copia, «warn».
|
|
11
|
+
* - Trello y Plane: «warn» como máximo, como en el servidor.
|
|
12
|
+
*
|
|
13
|
+
* Un tablero sin política es uno que ya existía: todo en «warn». El catálogo es el de
|
|
14
|
+
* server/coordination/enforcement.py; tests/test_enforcement.py comprueba que coinciden.
|
|
15
|
+
* Nunca lanza: una política que no se puede leer se trata como «warn».
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
19
|
+
import { dirname, join } from 'node:path';
|
|
20
|
+
import { cabecerasDelDispositivo, URL_POR_DEFECTO } from './heartbeat-send.mjs';
|
|
21
|
+
import { llamarTool } from './mcp-client.mjs';
|
|
22
|
+
|
|
23
|
+
export const MODES = ['off', 'warn', 'block'];
|
|
24
|
+
export const CAPPED_BACKENDS = new Set(['trello', 'plane']);
|
|
25
|
+
export const CACHE_MS = 10 * 60 * 1000;
|
|
26
|
+
export const CACHE_FILE = join('.quality', 'enforcement_policy.json');
|
|
27
|
+
|
|
28
|
+
/** Clave → modo de un proyecto nuevo. Mismo orden y valores que MEASURES en el servidor. */
|
|
29
|
+
export const MEASURES = {
|
|
30
|
+
context_budget: 'warn',
|
|
31
|
+
spec_in_pr: 'warn',
|
|
32
|
+
spec_quality: 'warn',
|
|
33
|
+
pending_decisions: 'warn',
|
|
34
|
+
closing_evidence: 'warn',
|
|
35
|
+
independent_review: 'warn',
|
|
36
|
+
ac_approval: 'warn',
|
|
37
|
+
drift_gate: 'warn',
|
|
38
|
+
impact_radius: 'warn',
|
|
39
|
+
contract_first: 'warn',
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/** El modo de cada medida a partir de lo guardado (o null), como effective_policy del servidor. */
|
|
43
|
+
export function modosDe(raw, backendType) {
|
|
44
|
+
const origin = raw && (raw.origin === 'new' || raw.origin === 'existing') ? raw.origin : 'existing';
|
|
45
|
+
const guardadas = raw && typeof raw.measures === 'object' && raw.measures ? raw.measures : {};
|
|
46
|
+
const modos = {};
|
|
47
|
+
for (const [clave, nuevo] of Object.entries(MEASURES)) {
|
|
48
|
+
const entrada = guardadas[clave];
|
|
49
|
+
let modo = entrada && MODES.includes(entrada.mode) ? entrada.mode : origin === 'new' ? nuevo : 'warn';
|
|
50
|
+
if (CAPPED_BACKENDS.has(backendType) && modo === 'block') modo = 'warn';
|
|
51
|
+
modos[clave] = modo;
|
|
52
|
+
}
|
|
53
|
+
return { origin, backendType, modos };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** El modo de una medida en una política leída con leerPolitica («warn» si no la conoce). */
|
|
57
|
+
export function modoDe(politica, medida) {
|
|
58
|
+
const modo = politica?.modos?.[medida];
|
|
59
|
+
return MODES.includes(modo) ? modo : 'warn';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function leerJson(ruta) {
|
|
63
|
+
try {
|
|
64
|
+
return JSON.parse(readFileSync(ruta, 'utf-8'));
|
|
65
|
+
} catch {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** La política native de la caché si es de este proyecto (y su edad), o null. */
|
|
71
|
+
function deLaCache(root, proyecto) {
|
|
72
|
+
const copia = leerJson(join(root, CACHE_FILE));
|
|
73
|
+
if (!copia || copia.project_id !== proyecto || typeof copia.fetched_at !== 'number') return null;
|
|
74
|
+
return copia;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* La política del proyecto: { origin, backendType, modos, fuente }.
|
|
79
|
+
* `fuente` dice de dónde salió: policy.json, tablero, caché, caché antigua o por defecto.
|
|
80
|
+
*/
|
|
81
|
+
export async function leerPolitica({
|
|
82
|
+
root = process.cwd(),
|
|
83
|
+
backendType = '',
|
|
84
|
+
boardId = '',
|
|
85
|
+
trackingDir = '',
|
|
86
|
+
env = process.env,
|
|
87
|
+
fetchImpl = fetch,
|
|
88
|
+
cabeceras,
|
|
89
|
+
ahora = Date.now(),
|
|
90
|
+
topeMs = 2500,
|
|
91
|
+
} = {}) {
|
|
92
|
+
if (CAPPED_BACKENDS.has(backendType)) return { ...modosDe(null, backendType), fuente: 'por defecto' };
|
|
93
|
+
|
|
94
|
+
if (backendType === 'freeform') {
|
|
95
|
+
const ruta = join(trackingDir || join(root, 'doc', 'tracking'), 'policy.json');
|
|
96
|
+
const raw = existsSync(ruta) ? leerJson(ruta) : null;
|
|
97
|
+
return { ...modosDe(raw, backendType), fuente: raw ? 'policy.json' : 'por defecto' };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (backendType !== 'native' || !boardId) return { ...modosDe(null, backendType), fuente: 'por defecto' };
|
|
101
|
+
|
|
102
|
+
const copia = deLaCache(root, boardId);
|
|
103
|
+
if (copia && ahora - copia.fetched_at < CACHE_MS) return { ...modosDe(copia.policy, 'native'), fuente: 'caché' };
|
|
104
|
+
|
|
105
|
+
if (env.SPECBOX_ENFORCEMENT_POLICY !== 'off') {
|
|
106
|
+
try {
|
|
107
|
+
const url = env.SPECBOX_MCP_URL || URL_POR_DEFECTO;
|
|
108
|
+
const h = cabeceras ?? (await cabecerasDelDispositivo({ ...env, CLAUDE_CODE_MCP_SERVER_URL: url }));
|
|
109
|
+
if (h.Authorization) {
|
|
110
|
+
const r = await llamarTool({
|
|
111
|
+
url,
|
|
112
|
+
cabeceras: h,
|
|
113
|
+
nombre: 'get_enforcement_policy',
|
|
114
|
+
args: { board_id: boardId },
|
|
115
|
+
topeMs,
|
|
116
|
+
fetchImpl,
|
|
117
|
+
});
|
|
118
|
+
if (r?.success && r.policy) {
|
|
119
|
+
// Se guarda lo que el servidor considera guardado: origen y modo de cada medida.
|
|
120
|
+
const policy = {
|
|
121
|
+
origin: r.policy.origin,
|
|
122
|
+
measures: Object.fromEntries(
|
|
123
|
+
Object.entries(r.policy.measures || {}).map(([k, v]) => [k, { mode: v?.mode }]),
|
|
124
|
+
),
|
|
125
|
+
};
|
|
126
|
+
try {
|
|
127
|
+
const destino = join(root, CACHE_FILE);
|
|
128
|
+
mkdirSync(dirname(destino), { recursive: true });
|
|
129
|
+
writeFileSync(destino, `${JSON.stringify({ project_id: boardId, fetched_at: ahora, policy }, null, 2)}\n`);
|
|
130
|
+
} catch {
|
|
131
|
+
// sin caché la próxima vez se vuelve a preguntar
|
|
132
|
+
}
|
|
133
|
+
return { ...modosDe(policy, 'native'), fuente: 'tablero' };
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
} catch {
|
|
137
|
+
// sin red o con el tablero caído: la última copia o «warn»
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (copia) return { ...modosDe(copia.policy, 'native'), fuente: 'caché antigua' };
|
|
141
|
+
return { ...modosDe(null, 'native'), fuente: 'por defecto' };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** El texto de un aviso o de un bloqueo de una medida: medida, motivo y cómo seguir (AC-06). */
|
|
145
|
+
export function textoDeMedida({ medida, modo, motivo, comoSeguir }) {
|
|
146
|
+
const que = modo === 'block' ? 'SpecBox detuvo la operación' : 'Aviso de SpecBox';
|
|
147
|
+
return `${que} por la medida ${medida}. Motivo: ${motivo} Cómo seguir: ${comoSeguir}`;
|
|
148
|
+
}
|
|
@@ -326,52 +326,76 @@ export function mergeFragment(local, sent, returned) {
|
|
|
326
326
|
|
|
327
327
|
// ── The tool's answer ──────────────────────────────────────────────────
|
|
328
328
|
|
|
329
|
-
/** The `
|
|
330
|
-
export function
|
|
329
|
+
/** The string field `key` inside an MCP tool response, whatever its shape. */
|
|
330
|
+
export function extractField(response, key, depth = 0) {
|
|
331
331
|
if (depth > 6 || response == null) return null;
|
|
332
332
|
if (typeof response === 'string') {
|
|
333
333
|
const text = response.trim();
|
|
334
|
-
return text.startsWith('{') ?
|
|
334
|
+
return text.startsWith('{') ? extractField(safeJson(text), key, depth + 1) : null;
|
|
335
335
|
}
|
|
336
336
|
if (Array.isArray(response)) {
|
|
337
337
|
for (const part of response) {
|
|
338
|
-
const found =
|
|
338
|
+
const found = extractField(part, key, depth + 1);
|
|
339
339
|
if (found != null) return found;
|
|
340
340
|
}
|
|
341
341
|
return null;
|
|
342
342
|
}
|
|
343
343
|
if (typeof response === 'object') {
|
|
344
|
-
if (typeof response
|
|
344
|
+
if (typeof response[key] === 'string') return response[key];
|
|
345
345
|
for (const value of Object.values(response)) {
|
|
346
|
-
const found =
|
|
346
|
+
const found = extractField(value, key, depth + 1);
|
|
347
347
|
if (found != null) return found;
|
|
348
348
|
}
|
|
349
349
|
}
|
|
350
350
|
return null;
|
|
351
351
|
}
|
|
352
352
|
|
|
353
|
-
/** The same response without any `
|
|
354
|
-
export function
|
|
353
|
+
/** The same response without any field in `keys` (what the model needs to see). */
|
|
354
|
+
export function withoutFields(response, keys, depth = 0) {
|
|
355
355
|
if (depth > 6 || response == null) return response;
|
|
356
356
|
if (typeof response === 'string') {
|
|
357
357
|
const text = response.trim();
|
|
358
358
|
if (!text.startsWith('{')) return response;
|
|
359
359
|
const parsed = safeJson(text);
|
|
360
|
-
if (parsed == null ||
|
|
361
|
-
return JSON.stringify(
|
|
360
|
+
if (parsed == null || keys.every((k) => extractField(parsed, k) == null)) return response;
|
|
361
|
+
return JSON.stringify(withoutFields(parsed, keys, depth + 1));
|
|
362
362
|
}
|
|
363
|
-
if (Array.isArray(response)) return response.map((part) =>
|
|
363
|
+
if (Array.isArray(response)) return response.map((part) => withoutFields(part, keys, depth + 1));
|
|
364
364
|
if (typeof response === 'object') {
|
|
365
365
|
const out = {};
|
|
366
366
|
for (const [key, value] of Object.entries(response)) {
|
|
367
|
-
if (key
|
|
368
|
-
out[key] =
|
|
367
|
+
if (keys.includes(key)) continue;
|
|
368
|
+
out[key] = withoutFields(value, keys, depth + 1);
|
|
369
369
|
}
|
|
370
370
|
return out;
|
|
371
371
|
}
|
|
372
372
|
return response;
|
|
373
373
|
}
|
|
374
374
|
|
|
375
|
+
/** The `items_content` string inside an MCP tool response, whatever its shape. */
|
|
376
|
+
export function extractItemsContent(response) {
|
|
377
|
+
return extractField(response, 'items_content');
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/** The same response without any `items_content` (nor `policy_content` or `event_line`, UC-12212/12213). */
|
|
381
|
+
export function withoutItemsContent(response) {
|
|
382
|
+
return withoutFields(response, ['items_content', 'policy_content', 'event_line']);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// ── The EP-20 policy, doc/tracking/policy.json (UC-12212) ─────────────
|
|
386
|
+
|
|
387
|
+
/** The tools that read or change the policy: they get the file as `policy_content`. */
|
|
388
|
+
export const POLICY_TOOLS = new Set([
|
|
389
|
+
'get_enforcement_policy', 'set_enforcement_mode', 'skip_enforcement',
|
|
390
|
+
'get_enforcement_impact', 'record_enforcement_event',
|
|
391
|
+
]);
|
|
392
|
+
/** Of those, the ones whose answer is the new file. */
|
|
393
|
+
export const POLICY_WRITERS = new Set(['set_enforcement_mode', 'skip_enforcement']);
|
|
394
|
+
/** The ones that measure the board: they also get items.json and the events (UC-12213). */
|
|
395
|
+
export const POLICY_BOARD_TOOLS = new Set(['set_enforcement_mode', 'get_enforcement_impact']);
|
|
396
|
+
/** The ones whose answer carries an `event_line` for doc/tracking/enforcement_events.jsonl. */
|
|
397
|
+
export const POLICY_EVENT_TOOLS = new Set(['skip_enforcement', 'record_enforcement_event']);
|
|
398
|
+
|
|
375
399
|
// ── Files: pending calls, the lock and atomic writes ───────────────────
|
|
376
400
|
|
|
377
401
|
function sleep(ms) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "specbox",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.36.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": {
|