@opengsd/gsd-core 1.5.0-rc.3 → 1.5.0-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/agents/gsd-advisor-researcher.md +1 -1
- package/agents/gsd-assumptions-analyzer.md +1 -1
- package/agents/gsd-code-fixer.md +1 -1
- package/agents/gsd-code-reviewer.md +1 -1
- package/agents/gsd-codebase-mapper.md +1 -1
- package/agents/gsd-debugger.md +1 -1
- package/agents/gsd-doc-writer.md +1 -1
- package/agents/gsd-eval-auditor.md +1 -1
- package/agents/gsd-executor.md +1 -1
- package/agents/gsd-integration-checker.md +1 -1
- package/agents/gsd-nyquist-auditor.md +1 -0
- package/agents/gsd-phase-researcher.md +1 -1
- package/agents/gsd-plan-checker.md +1 -1
- package/agents/gsd-planner.md +1 -1
- package/agents/gsd-project-researcher.md +1 -1
- package/agents/gsd-research-synthesizer.md +1 -1
- package/agents/gsd-roadmapper.md +55 -2
- package/agents/gsd-security-auditor.md +1 -0
- package/agents/gsd-ui-auditor.md +1 -1
- package/agents/gsd-ui-checker.md +1 -1
- package/agents/gsd-ui-researcher.md +1 -1
- package/agents/gsd-verifier.md +13 -2
- package/bin/install.js +36 -57
- package/commands/gsd/progress.md +2 -1
- package/gemini-extension.json +1 -1
- package/gsd-core/bin/gsd-tools.cjs +167 -3
- package/gsd-core/bin/lib/active-workstream-store.cjs +6 -0
- package/gsd-core/bin/lib/capability-state.cjs +97 -3
- package/gsd-core/bin/lib/capability-writer.cjs +354 -0
- package/gsd-core/bin/lib/config.cjs +80 -24
- package/gsd-core/bin/lib/edge-probe.cjs +25 -2
- package/gsd-core/bin/lib/frontmatter.cjs +53 -1
- package/gsd-core/bin/lib/git-base-branch.cjs +194 -0
- package/gsd-core/bin/lib/init.cjs +28 -6
- package/gsd-core/bin/lib/install-profiles.cjs +55 -0
- package/gsd-core/bin/lib/installer-migration-report.cjs +1 -0
- package/gsd-core/bin/lib/phase.cjs +28 -12
- package/gsd-core/bin/lib/plan-drift-guard.cjs +117 -0
- package/gsd-core/bin/lib/probe-core.cjs +117 -1
- package/gsd-core/bin/lib/roadmap-parser.cjs +13 -3
- package/gsd-core/bin/lib/runtime-artifact-conversion.cjs +246 -0
- package/gsd-core/bin/lib/runtime-artifact-layout.cjs +34 -2
- package/gsd-core/bin/lib/state.cjs +240 -59
- package/gsd-core/bin/lib/verify.cjs +73 -4
- package/gsd-core/bin/lib/worktree-safety.cjs +2 -1
- package/gsd-core/references/edge-probe.md +11 -0
- package/gsd-core/references/prohibition-probe-fixtures/01-streak-reminder/expected.json +14 -0
- package/gsd-core/references/prohibition-probe-fixtures/02-clean-utility/expected.json +4 -0
- package/gsd-core/references/prohibition-probe-fixtures/03-multi-prohibition/expected.json +32 -0
- package/gsd-core/references/prohibition-probe.md +248 -0
- package/gsd-core/templates/spec.md +14 -0
- package/gsd-core/workflows/complete-milestone.md +1 -5
- package/gsd-core/workflows/execute-phase.md +4 -3
- package/gsd-core/workflows/execute-plan.md +21 -6
- package/gsd-core/workflows/help/modes/full.md +4 -0
- package/gsd-core/workflows/next.md +50 -2
- package/gsd-core/workflows/pause-work.md +7 -1
- package/gsd-core/workflows/plan-phase.md +2 -0
- package/gsd-core/workflows/plan-review-convergence.md +14 -4
- package/gsd-core/workflows/pr-branch.md +4 -2
- package/gsd-core/workflows/quick.md +3 -2
- package/gsd-core/workflows/resume-project.md +17 -1
- package/gsd-core/workflows/settings.md +27 -1
- package/gsd-core/workflows/ship.md +1 -5
- package/gsd-core/workflows/spec-phase.md +75 -0
- package/gsd-core/workflows/verify-phase.md +14 -4
- package/hooks/dist/gsd-ensure-canonical-path.js +305 -0
- package/hooks/dist/gsd-statusline.js +1 -1
- package/hooks/dist/managed-hooks-registry.cjs +1 -0
- package/hooks/gsd-ensure-canonical-path.js +305 -0
- package/hooks/gsd-statusline.js +1 -1
- package/hooks/hooks.json +1 -0
- package/hooks/managed-hooks-registry.cjs +1 -0
- package/package.json +3 -3
- package/scripts/build-hooks.js +7 -0
- package/scripts/changeset/new.cjs +17 -3
- package/scripts/fix-slash-commands.cjs +15 -3
- package/scripts/gen-capability-registry.cjs +14 -1
- package/scripts/lint-allow-test-rule-refs.allowlist.json +2 -1
- package/scripts/lint-test-file-count.allowlist.json +6 -0
- package/scripts/mutation-matrix.cjs +108 -7
- package/scripts/pr-target-policy.cjs +63 -0
- package/scripts/research-profiles.cjs +5 -5
- package/scripts/run-tests.cjs +107 -6
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Capability Writer — ADR-1213 write-side inverse of capability-state resolver.
|
|
4
|
+
*
|
|
5
|
+
* Exports:
|
|
6
|
+
* setCapabilityState(cwd, runtimeConfigDir, desired, opts?)
|
|
7
|
+
* → { capabilities: CapabilityStateEntry[], warnings: string[] }
|
|
8
|
+
* cmdCapabilitySet(cwd, runtimeConfigDir, capId, options, raw)
|
|
9
|
+
*
|
|
10
|
+
* Projection rules (three axes: install, surface, config):
|
|
11
|
+
* - enabled axis: mutates .gsd-surface.json via readSurface/writeSurface
|
|
12
|
+
* - gates axis: mutates .planning/config.json via setConfigValues (batched)
|
|
13
|
+
* - materialize: optionally calls applySurface to write skill files
|
|
14
|
+
* - re-resolve: always calls resolveCapabilityRuntimeState for the return value
|
|
15
|
+
*
|
|
16
|
+
* Dependencies (leaf modules only — no circular risk):
|
|
17
|
+
* - ./core.cjs (output, error)
|
|
18
|
+
* - ./capability-state.cjs (resolveCapabilityRuntimeState, _resolveManifest, _resolveCommandsGsdDir)
|
|
19
|
+
* - ./surface.cjs (readSurface, writeSurface, applySurface)
|
|
20
|
+
* - ./install-profiles.cjs (readActiveProfile)
|
|
21
|
+
* - ./config.cjs (setConfigValues)
|
|
22
|
+
* - ./runtime-artifact-layout.cjs (resolveRuntimeArtifactLayout)
|
|
23
|
+
* - capability-registry.cjs (loaded at call time)
|
|
24
|
+
*/
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
26
|
+
const core = require("./core.cjs");
|
|
27
|
+
const { output: coreOutput, error: coreError } = core;
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
29
|
+
const capabilityStateMod = require("./capability-state.cjs");
|
|
30
|
+
const { resolveCapabilityRuntimeState, _resolveManifest, _resolveCommandsGsdDir } = capabilityStateMod;
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
32
|
+
const surfaceMod = require("./surface.cjs");
|
|
33
|
+
const { readSurface, writeSurface, applySurface } = surfaceMod;
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
35
|
+
const installProfilesMod = require("./install-profiles.cjs");
|
|
36
|
+
const { readActiveProfile } = installProfilesMod;
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
38
|
+
const configMod = require("./config.cjs");
|
|
39
|
+
const { setConfigValues } = configMod;
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
41
|
+
const planningWorkspaceMod = require("./planning-workspace.cjs");
|
|
42
|
+
const { planningDir } = planningWorkspaceMod;
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
44
|
+
const nodefs = require("fs");
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
46
|
+
const nodepath = require("path");
|
|
47
|
+
// ─── Implementation ───────────────────────────────────────────────────────────
|
|
48
|
+
/**
|
|
49
|
+
* Write-side capability state mutator.
|
|
50
|
+
*
|
|
51
|
+
* Applies desired capability state changes (enabled axis via surface, gates
|
|
52
|
+
* axis via config) then re-resolves and returns the full capability state.
|
|
53
|
+
*
|
|
54
|
+
* Control flow:
|
|
55
|
+
* 1. RESOLVE BEFORE STATE: call resolveCapabilityRuntimeState once to get the
|
|
56
|
+
* canonical runtimeConfigDir and current capability state.
|
|
57
|
+
* 2. VALIDATION PASS (no writes): validate each desired entry against the
|
|
58
|
+
* registry and `before` state; collect errors and warnings.
|
|
59
|
+
* 3. If errors → return early with before.capabilities (no writes performed).
|
|
60
|
+
* 4. APPLY PASS: compute new surface state, writeSurface once if changed,
|
|
61
|
+
* setConfigValues once for gate writes; materialize if opts provided.
|
|
62
|
+
* 5. RE-RESOLVE: call resolveCapabilityRuntimeState again to get final state.
|
|
63
|
+
* 6. POST CHECKS: enabled=true but not-surfaced (not-in-profile) error;
|
|
64
|
+
* present-but-dead warning; append resolver warnings.
|
|
65
|
+
* 7. Return { capabilities: after.capabilities, warnings, errors }.
|
|
66
|
+
*/
|
|
67
|
+
function setCapabilityState(cwd, runtimeConfigDir, desired, opts) {
|
|
68
|
+
const warnings = [];
|
|
69
|
+
const errors = [];
|
|
70
|
+
// ── Step 1: Resolve BEFORE state once ────────────────────────────────────
|
|
71
|
+
const before = resolveCapabilityRuntimeState(cwd, runtimeConfigDir);
|
|
72
|
+
const resolvedConfigDir = before.runtimeConfigDir;
|
|
73
|
+
// ── Load registry ─────────────────────────────────────────────────────────
|
|
74
|
+
const registry = before.registry;
|
|
75
|
+
const capabilitiesMap = (registry['capabilities'] && typeof registry['capabilities'] === 'object' && !Array.isArray(registry['capabilities'])
|
|
76
|
+
? registry['capabilities']
|
|
77
|
+
: {});
|
|
78
|
+
// ── Step 2: VALIDATION PASS (no writes) ──────────────────────────────────
|
|
79
|
+
// Accumulate all valid gate writes and surface deltas.
|
|
80
|
+
// If ANY error is found, we will return early without writing anything.
|
|
81
|
+
const pendingGateWrites = [];
|
|
82
|
+
// surface-delta accumulators: ids to add to / remove from disabledClusters
|
|
83
|
+
const idsToDisable = [];
|
|
84
|
+
const idsToEnable = [];
|
|
85
|
+
// Track which ids need surface loading (have skills + explicit enabled flag)
|
|
86
|
+
let needsSurface = false;
|
|
87
|
+
for (const entry of desired) {
|
|
88
|
+
const { id, enabled, gates } = entry;
|
|
89
|
+
// Validate capability id
|
|
90
|
+
if (!Object.prototype.hasOwnProperty.call(capabilitiesMap, id)) {
|
|
91
|
+
errors.push(`unknown capability: "${id}"`);
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const capObj = capabilitiesMap[id];
|
|
95
|
+
const skillsRaw = capObj['skills'];
|
|
96
|
+
const skills = Array.isArray(skillsRaw)
|
|
97
|
+
? skillsRaw.filter((s) => typeof s === 'string')
|
|
98
|
+
: [];
|
|
99
|
+
const configDef = (capObj['config'] && typeof capObj['config'] === 'object' && !Array.isArray(capObj['config'])
|
|
100
|
+
? capObj['config']
|
|
101
|
+
: {});
|
|
102
|
+
// ── Validate gate keys / values ──────────────────────────────────────────
|
|
103
|
+
if (gates !== undefined) {
|
|
104
|
+
for (const [key, val] of Object.entries(gates)) {
|
|
105
|
+
if (!Object.prototype.hasOwnProperty.call(configDef, key)) {
|
|
106
|
+
errors.push(`unknown gate key "${key}" for capability "${id}"`);
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (typeof val !== 'boolean') {
|
|
110
|
+
errors.push(`gate value for "${key}" must be boolean, got ${typeof val}`);
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
pendingGateWrites.push({ keyPath: key, value: val });
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// ── Validate enabled axis ────────────────────────────────────────────────
|
|
117
|
+
if (enabled !== undefined) {
|
|
118
|
+
if (skills.length === 0) {
|
|
119
|
+
// Advisory only — no surface effect possible
|
|
120
|
+
warnings.push(`capability "${id}" owns no skills; 'enabled' has no surface effect — use gates to toggle its hooks`);
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
// Install-floor check: cannot enable a capability whose skills are not installed
|
|
124
|
+
if (enabled === true) {
|
|
125
|
+
const beforeEntry = before.capabilities.find((c) => c.id === id);
|
|
126
|
+
if (beforeEntry && beforeEntry.installed === false) {
|
|
127
|
+
errors.push(`cannot enable "${id}": its skills are not in the install profile`);
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
needsSurface = true;
|
|
132
|
+
if (enabled === false) {
|
|
133
|
+
idsToDisable.push(id);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
idsToEnable.push(id);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// ── Fix D: Pre-validate config.json parseability before any write ────────
|
|
141
|
+
// If there are pending gate writes, attempt to read and parse the target
|
|
142
|
+
// config.json BEFORE writing anything. A malformed file would cause
|
|
143
|
+
// setConfigValues to error() mid-operation leaving a partial write.
|
|
144
|
+
if (pendingGateWrites.length > 0) {
|
|
145
|
+
try {
|
|
146
|
+
const configJsonPath = nodepath.join(planningDir(cwd), 'config.json');
|
|
147
|
+
if (nodefs.existsSync(configJsonPath)) {
|
|
148
|
+
const raw = nodefs.readFileSync(configJsonPath, 'utf-8');
|
|
149
|
+
try {
|
|
150
|
+
JSON.parse(raw);
|
|
151
|
+
}
|
|
152
|
+
catch (parseErr) {
|
|
153
|
+
const msg = parseErr instanceof Error ? parseErr.message : String(parseErr);
|
|
154
|
+
errors.push(`config.json is malformed: ${msg}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
// Cannot read the file path — not an error (e.g. planningDir env-var issue); let setConfigValues handle it
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// ── Step 3: Early return on validation errors ────────────────────────────
|
|
163
|
+
if (errors.length > 0) {
|
|
164
|
+
return {
|
|
165
|
+
capabilities: before.capabilities,
|
|
166
|
+
warnings,
|
|
167
|
+
errors,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
// ── Step 4: APPLY PASS ────────────────────────────────────────────────────
|
|
171
|
+
// ── Surface writes ────────────────────────────────────────────────────────
|
|
172
|
+
if (needsSurface && (idsToDisable.length > 0 || idsToEnable.length > 0)) {
|
|
173
|
+
const existing = readSurface(resolvedConfigDir);
|
|
174
|
+
let pendingSurface = existing ?? {
|
|
175
|
+
baseProfile: readActiveProfile(resolvedConfigDir) ?? 'full',
|
|
176
|
+
disabledClusters: [],
|
|
177
|
+
explicitAdds: [],
|
|
178
|
+
explicitRemoves: [],
|
|
179
|
+
};
|
|
180
|
+
let surfaceChanged = false;
|
|
181
|
+
for (const id of idsToDisable) {
|
|
182
|
+
// Add id to disabledClusters (dedupe)
|
|
183
|
+
if (!pendingSurface.disabledClusters.includes(id)) {
|
|
184
|
+
pendingSurface = {
|
|
185
|
+
...pendingSurface,
|
|
186
|
+
disabledClusters: [...pendingSurface.disabledClusters, id],
|
|
187
|
+
};
|
|
188
|
+
surfaceChanged = true;
|
|
189
|
+
}
|
|
190
|
+
// Fix A: explicitAdds contains SKILL STEMS, not capability ids.
|
|
191
|
+
// Remove the capability's skill stems from explicitAdds so that
|
|
192
|
+
// resolveSurface does not re-add those skills after the cluster disable.
|
|
193
|
+
const capObjForDisable = capabilitiesMap[id];
|
|
194
|
+
const skillsRawForDisable = capObjForDisable?.['skills'];
|
|
195
|
+
const skillStemsForDisable = Array.isArray(skillsRawForDisable)
|
|
196
|
+
? skillsRawForDisable.filter((s) => typeof s === 'string')
|
|
197
|
+
: [];
|
|
198
|
+
const newExplicitAdds = pendingSurface.explicitAdds.filter((x) => !skillStemsForDisable.includes(x));
|
|
199
|
+
if (newExplicitAdds.length !== pendingSurface.explicitAdds.length) {
|
|
200
|
+
pendingSurface = { ...pendingSurface, explicitAdds: newExplicitAdds };
|
|
201
|
+
surfaceChanged = true;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
for (const id of idsToEnable) {
|
|
205
|
+
// Remove id from disabledClusters
|
|
206
|
+
if (pendingSurface.disabledClusters.includes(id)) {
|
|
207
|
+
pendingSurface = {
|
|
208
|
+
...pendingSurface,
|
|
209
|
+
disabledClusters: pendingSurface.disabledClusters.filter((x) => x !== id),
|
|
210
|
+
};
|
|
211
|
+
surfaceChanged = true;
|
|
212
|
+
}
|
|
213
|
+
// Fix A (enable branch): also remove the capability's skill stems from
|
|
214
|
+
// explicitRemoves so that resolveSurface does not subtract those skills.
|
|
215
|
+
// Do NOT add anything to explicitAdds — a cap that was only in explicitAdds
|
|
216
|
+
// and was disabled is caught by the post-check below.
|
|
217
|
+
const capObjForEnable = capabilitiesMap[id];
|
|
218
|
+
const skillsRawForEnable = capObjForEnable?.['skills'];
|
|
219
|
+
const skillStemsForEnable = Array.isArray(skillsRawForEnable)
|
|
220
|
+
? skillsRawForEnable.filter((s) => typeof s === 'string')
|
|
221
|
+
: [];
|
|
222
|
+
const newExplicitRemoves = pendingSurface.explicitRemoves.filter((x) => !skillStemsForEnable.includes(x));
|
|
223
|
+
if (newExplicitRemoves.length !== pendingSurface.explicitRemoves.length) {
|
|
224
|
+
pendingSurface = { ...pendingSurface, explicitRemoves: newExplicitRemoves };
|
|
225
|
+
surfaceChanged = true;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if (surfaceChanged) {
|
|
229
|
+
writeSurface(resolvedConfigDir, pendingSurface);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
// ── Config writes (once, batched) ─────────────────────────────────────────
|
|
233
|
+
if (pendingGateWrites.length > 0) {
|
|
234
|
+
setConfigValues(cwd, pendingGateWrites);
|
|
235
|
+
}
|
|
236
|
+
// ── Materialize (optional) ────────────────────────────────────────────────
|
|
237
|
+
if (opts?.materialize) {
|
|
238
|
+
const { runtime, scope } = opts.materialize;
|
|
239
|
+
try {
|
|
240
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
241
|
+
const runtimeArtifactLayout = require('./runtime-artifact-layout.cjs');
|
|
242
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
243
|
+
const layout = runtimeArtifactLayout.resolveRuntimeArtifactLayout(runtime, resolvedConfigDir, scope);
|
|
244
|
+
const commandsGsdDir = _resolveCommandsGsdDir();
|
|
245
|
+
const manifest = _resolveManifest(commandsGsdDir, resolvedConfigDir);
|
|
246
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
247
|
+
applySurface(resolvedConfigDir, layout, manifest, undefined, registry);
|
|
248
|
+
}
|
|
249
|
+
catch (err) {
|
|
250
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
251
|
+
// Fix C: materialise was explicitly requested — a failure is an error (non-zero exit),
|
|
252
|
+
// not merely advisory.
|
|
253
|
+
errors.push(`materialize failed: ${msg}`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
// ── Step 5: RE-RESOLVE ────────────────────────────────────────────────────
|
|
257
|
+
const after = resolveCapabilityRuntimeState(cwd, resolvedConfigDir);
|
|
258
|
+
// ── Step 6: POST CHECKS ───────────────────────────────────────────────────
|
|
259
|
+
// Check: desired enabled=true but not actually enabled after write
|
|
260
|
+
// (catches the not-in-profile / not-surfaced silent no-op case).
|
|
261
|
+
// The install-floor case (installed===false) was already caught in validation.
|
|
262
|
+
for (const entry of desired) {
|
|
263
|
+
if (entry.enabled === true) {
|
|
264
|
+
const afterCap = after.capabilities.find((c) => c.id === entry.id);
|
|
265
|
+
if (afterCap && afterCap.enabled !== true) {
|
|
266
|
+
errors.push(`cannot enable "${entry.id}": not in the active surface/profile (widen the profile or use /gsd:surface enable)`);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
// Fix B: desired enabled=false — assert it is actually disabled after write.
|
|
270
|
+
// Prevents "off means off" silent failures (e.g. explicitAdds containing the
|
|
271
|
+
// cap's skill stems re-adds them after the cluster disable).
|
|
272
|
+
if (entry.enabled === false) {
|
|
273
|
+
const afterCap = after.capabilities.find((c) => c.id === entry.id);
|
|
274
|
+
if (afterCap && afterCap.enabled !== false) {
|
|
275
|
+
errors.push(`failed to disable "${entry.id}": still surfaced after write`);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
// Check: present-but-dead — SCOPED to touched (desired) capabilities only.
|
|
280
|
+
const desiredIds = new Set(desired.map((d) => d.id));
|
|
281
|
+
for (const cap of after.capabilities) {
|
|
282
|
+
if (!desiredIds.has(cap.id))
|
|
283
|
+
continue;
|
|
284
|
+
if (cap.enabled === true &&
|
|
285
|
+
cap.hooks.length > 0 &&
|
|
286
|
+
cap.hooks.every((h) => !h.configured)) {
|
|
287
|
+
warnings.push(`capability "${cap.id}" is surfaced but every hook is gated off — did you mean enabled:false?`);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
// Append resolver's own warnings
|
|
291
|
+
for (const w of after.warnings) {
|
|
292
|
+
warnings.push(w);
|
|
293
|
+
}
|
|
294
|
+
return {
|
|
295
|
+
capabilities: after.capabilities,
|
|
296
|
+
warnings,
|
|
297
|
+
errors,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* CLI command entry point for `gsd-tools capability set`.
|
|
302
|
+
*
|
|
303
|
+
* Builds one DesiredCapability from the provided options, calls setCapabilityState,
|
|
304
|
+
* then prints the result. When raw=true emits JSON; else emits a human summary.
|
|
305
|
+
* Warnings are always printed to stderr.
|
|
306
|
+
*/
|
|
307
|
+
function cmdCapabilitySet(cwd, runtimeConfigDir, capId, options, raw) {
|
|
308
|
+
const desired = [
|
|
309
|
+
{
|
|
310
|
+
id: capId,
|
|
311
|
+
...(options.enabled !== undefined ? { enabled: options.enabled } : {}),
|
|
312
|
+
...(options.gates ? { gates: options.gates } : {}),
|
|
313
|
+
},
|
|
314
|
+
];
|
|
315
|
+
const opts = options.runtime
|
|
316
|
+
? { materialize: { runtime: options.runtime, scope: options.scope ?? 'global' } }
|
|
317
|
+
: undefined;
|
|
318
|
+
const result = setCapabilityState(cwd, runtimeConfigDir, desired, opts);
|
|
319
|
+
if (raw) {
|
|
320
|
+
// Raw mode: emit JSON to stdout including errors; exit non-zero if errors present.
|
|
321
|
+
// Do NOT print human stderr lines — raw consumers parse the JSON.
|
|
322
|
+
coreOutput({ capabilities: result.capabilities, warnings: result.warnings, errors: result.errors }, true);
|
|
323
|
+
if (result.errors.length > 0) {
|
|
324
|
+
process.exit(1);
|
|
325
|
+
}
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
// Human mode: print warnings and errors to stderr (non-fatally for warnings).
|
|
329
|
+
for (const w of result.warnings) {
|
|
330
|
+
process.stderr.write(`capability set: warning: ${w}\n`);
|
|
331
|
+
}
|
|
332
|
+
for (const e of result.errors) {
|
|
333
|
+
process.stderr.write(`capability set: error: ${e}\n`);
|
|
334
|
+
}
|
|
335
|
+
// Exit non-zero if any errors (hard failures — requested action was not realized).
|
|
336
|
+
if (result.errors.length > 0) {
|
|
337
|
+
coreError(`capability set: ${String(result.errors.length)} error(s) — see above`);
|
|
338
|
+
return; // unreachable — coreError calls process.exit(1)
|
|
339
|
+
}
|
|
340
|
+
// Human-readable summary: focus on the target capability
|
|
341
|
+
const cap = result.capabilities.find((c) => c.id === capId);
|
|
342
|
+
if (!cap) {
|
|
343
|
+
const msg = `capability "${capId}" not found in registry`;
|
|
344
|
+
coreOutput(msg, false, msg);
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
const activeHooks = cap.hooks.filter((h) => h.active).length;
|
|
348
|
+
const summary = `capability ${capId}: enabled=${String(cap.enabled)}, surfaced=${String(cap.surfaced)}, installed=${String(cap.installed)}, activeHooks=${String(activeHooks)}/${String(cap.hooks.length)}`;
|
|
349
|
+
coreOutput({ id: cap.id, enabled: cap.enabled, surfaced: cap.surfaced, installed: cap.installed, warnings: result.warnings.length > 0 ? result.warnings : undefined }, false, summary);
|
|
350
|
+
}
|
|
351
|
+
module.exports = {
|
|
352
|
+
setCapabilityState,
|
|
353
|
+
cmdCapabilitySet,
|
|
354
|
+
};
|
|
@@ -368,6 +368,42 @@ function cmdConfigEnsureSection(cwd, raw) {
|
|
|
368
368
|
output(ensureConfigFileResult, raw, 'exists');
|
|
369
369
|
}
|
|
370
370
|
}
|
|
371
|
+
/**
|
|
372
|
+
* Shared helper: write a single key-path into an in-memory config object.
|
|
373
|
+
*
|
|
374
|
+
* Prototype-pollution guard: reject dangerous segments via inline literal
|
|
375
|
+
* comparisons on the exact key used to index `current`, immediately before
|
|
376
|
+
* each write. The inline comparison is the barrier CodeQL's
|
|
377
|
+
* js/prototype-pollution-utility query recognises — the previous Set-based
|
|
378
|
+
* pre-loop check was functionally correct but not traced through, so
|
|
379
|
+
* code-scanning alert #26 kept firing. Behaviour is unchanged from #663.
|
|
380
|
+
*
|
|
381
|
+
* Returns the previous value at the leaf key (undefined if absent).
|
|
382
|
+
* Never writes to disk — callers handle persistence.
|
|
383
|
+
* Calls error() (process.exit(1)) on prototype-pollution attempts.
|
|
384
|
+
*/
|
|
385
|
+
function _setNestedValue(config, keyPath, parsedValue) {
|
|
386
|
+
const keys = keyPath.split('.');
|
|
387
|
+
let current = config;
|
|
388
|
+
for (let i = 0; i < keys.length - 1; i++) {
|
|
389
|
+
const key = keys[i];
|
|
390
|
+
if (key === '__proto__' || key === 'prototype' || key === 'constructor') {
|
|
391
|
+
error('Invalid config key (prototype pollution guard): ' + keyPath, ERROR_REASON.CONFIG_PARSE_FAILED);
|
|
392
|
+
}
|
|
393
|
+
const existingChild = current[key];
|
|
394
|
+
if (existingChild === undefined || existingChild === null || typeof existingChild !== 'object' || Array.isArray(existingChild)) {
|
|
395
|
+
current[key] = {};
|
|
396
|
+
}
|
|
397
|
+
current = current[key];
|
|
398
|
+
}
|
|
399
|
+
const lastKey = keys[keys.length - 1];
|
|
400
|
+
if (lastKey === '__proto__' || lastKey === 'prototype' || lastKey === 'constructor') {
|
|
401
|
+
error('Invalid config key (prototype pollution guard): ' + keyPath, ERROR_REASON.CONFIG_PARSE_FAILED);
|
|
402
|
+
}
|
|
403
|
+
const previousValue = current[lastKey];
|
|
404
|
+
current[lastKey] = parsedValue;
|
|
405
|
+
return previousValue;
|
|
406
|
+
}
|
|
371
407
|
/**
|
|
372
408
|
* Sets a value in the config file, allowing nested values via dot notation (e.g.,
|
|
373
409
|
* "workflow.research").
|
|
@@ -388,35 +424,52 @@ function setConfigValue(cwd, keyPath, parsedValue) {
|
|
|
388
424
|
catch (err) {
|
|
389
425
|
error('Failed to read config.json: ' + err.message, ERROR_REASON.CONFIG_PARSE_FAILED);
|
|
390
426
|
}
|
|
391
|
-
|
|
392
|
-
//
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
427
|
+
const previousValue = _setNestedValue(config, keyPath, parsedValue);
|
|
428
|
+
// Write back
|
|
429
|
+
try {
|
|
430
|
+
(0, shell_command_projection_cjs_1.platformWriteSync)(configPath, JSON.stringify(config, null, 2));
|
|
431
|
+
return { updated: true, key: keyPath, value: parsedValue, previousValue };
|
|
432
|
+
}
|
|
433
|
+
catch (err) {
|
|
434
|
+
error('Failed to write config.json: ' + err.message);
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Batched sibling of setConfigValue: apply multiple key-path writes in a
|
|
440
|
+
* single load → set-all → write cycle inside ONE withPlanningLock call.
|
|
441
|
+
*
|
|
442
|
+
* Returns { updated: true, results: SetConfigValueResult[] } on success.
|
|
443
|
+
* An empty entries array is a no-op and returns { updated: false, results: [] }.
|
|
444
|
+
*
|
|
445
|
+
* Prototype-pollution guards are enforced per entry (identical inline-literal
|
|
446
|
+
* guards as setConfigValue — CodeQL barrier requirement).
|
|
447
|
+
*/
|
|
448
|
+
function setConfigValues(cwd, entries) {
|
|
449
|
+
if (entries.length === 0) {
|
|
450
|
+
return { updated: false, results: [] };
|
|
451
|
+
}
|
|
452
|
+
const configPath = node_path_1.default.join(planningDir(cwd), 'config.json');
|
|
453
|
+
return withPlanningLock(cwd, () => {
|
|
454
|
+
// Load existing config or start with empty object
|
|
455
|
+
let config = {};
|
|
456
|
+
try {
|
|
457
|
+
if (node_fs_1.default.existsSync(configPath)) {
|
|
458
|
+
config = JSON.parse(node_fs_1.default.readFileSync(configPath, 'utf-8'));
|
|
407
459
|
}
|
|
408
|
-
current = current[key];
|
|
409
460
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
error('Invalid config key (prototype pollution guard): ' + keyPath, ERROR_REASON.CONFIG_PARSE_FAILED);
|
|
461
|
+
catch (err) {
|
|
462
|
+
error('Failed to read config.json: ' + err.message, ERROR_REASON.CONFIG_PARSE_FAILED);
|
|
413
463
|
}
|
|
414
|
-
const
|
|
415
|
-
|
|
416
|
-
|
|
464
|
+
const results = [];
|
|
465
|
+
for (const entry of entries) {
|
|
466
|
+
const previousValue = _setNestedValue(config, entry.keyPath, entry.value);
|
|
467
|
+
results.push({ updated: true, key: entry.keyPath, value: entry.value, previousValue });
|
|
468
|
+
}
|
|
469
|
+
// Write back once for all entries
|
|
417
470
|
try {
|
|
418
471
|
(0, shell_command_projection_cjs_1.platformWriteSync)(configPath, JSON.stringify(config, null, 2));
|
|
419
|
-
return { updated: true,
|
|
472
|
+
return { updated: true, results };
|
|
420
473
|
}
|
|
421
474
|
catch (err) {
|
|
422
475
|
error('Failed to write config.json: ' + err.message);
|
|
@@ -734,4 +787,7 @@ module.exports = {
|
|
|
734
787
|
cmdConfigNewProject,
|
|
735
788
|
cmdConfigPath,
|
|
736
789
|
cmdMigrateConfig,
|
|
790
|
+
// Exported for programmatic use by capability-writer and tests
|
|
791
|
+
setConfigValue,
|
|
792
|
+
setConfigValues,
|
|
737
793
|
};
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* edges, and (via probe-core) merges author resolutions into a coverage report.
|
|
20
20
|
*/
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.EDGE_VALIDATORS = exports.TAXONOMY = exports.VALID_SHAPES = exports.SHAPE_CUES = void 0;
|
|
22
|
+
exports.EDGE_VALIDATORS = exports.UNCLASSIFIED_CATEGORY = exports.TAXONOMY = exports.VALID_SHAPES = exports.SHAPE_CUES = void 0;
|
|
23
23
|
exports.classifyShape = classifyShape;
|
|
24
24
|
exports.applicableCategories = applicableCategories;
|
|
25
25
|
exports.validateRequirement = validateRequirement;
|
|
@@ -74,8 +74,15 @@ function applicableCategories(shapes) {
|
|
|
74
74
|
* taxonomy; both verification tiers require a non-empty `resolution` (an explicit AC's text
|
|
75
75
|
* or a backstop note) so plan-phase has a criterion to lift.
|
|
76
76
|
*/
|
|
77
|
+
/**
|
|
78
|
+
* Pseudo-category for a requirement whose prose matched NO shape cue (#1110). It is a soft
|
|
79
|
+
* "review manually" signal, NOT a 9th taxonomy category: it stays out of `TAXONOMY` (the closed
|
|
80
|
+
* eight) and only joins `EDGE_VALIDATORS.categories` so `analyzeCoverage` accepts the item.
|
|
81
|
+
*/
|
|
82
|
+
exports.UNCLASSIFIED_CATEGORY = 'unclassified';
|
|
83
|
+
const UNCLASSIFIED_PROBE = 'unclassified — review manually';
|
|
77
84
|
exports.EDGE_VALIDATORS = {
|
|
78
|
-
categories: exports.TAXONOMY.map((c) => c.id),
|
|
85
|
+
categories: [...exports.TAXONOMY.map((c) => c.id), exports.UNCLASSIFIED_CATEGORY],
|
|
79
86
|
verification: ['explicit', 'backstop'],
|
|
80
87
|
requiredFieldsByVerification: { explicit: ['resolution'], backstop: ['resolution'] },
|
|
81
88
|
};
|
|
@@ -126,6 +133,22 @@ function proposeEdges(requirement) {
|
|
|
126
133
|
}
|
|
127
134
|
else {
|
|
128
135
|
shapes = classifyShape(requirement.text);
|
|
136
|
+
if (shapes.length === 0) {
|
|
137
|
+
// Prose present but no shape cue matched. Do NOT silently drop it (#1110): an
|
|
138
|
+
// edge-relevant requirement whose phrasing missed every cue would otherwise vanish from
|
|
139
|
+
// coverage with no signal — the exact blind spot this probe exists to catch. Surface ONE
|
|
140
|
+
// soft, dismissible "unclassified — review manually" candidate. The explicit `shapes: []`
|
|
141
|
+
// opt-out (handled above) stays silent — that is the author's deliberate "no edge surface".
|
|
142
|
+
return [{
|
|
143
|
+
requirement_id: requirement.id,
|
|
144
|
+
category: exports.UNCLASSIFIED_CATEGORY,
|
|
145
|
+
status: 'unresolved',
|
|
146
|
+
verification: null,
|
|
147
|
+
resolution: null,
|
|
148
|
+
reason: null,
|
|
149
|
+
probe: UNCLASSIFIED_PROBE,
|
|
150
|
+
}];
|
|
151
|
+
}
|
|
129
152
|
}
|
|
130
153
|
return applicableCategories(shapes).map((catId) => {
|
|
131
154
|
const cat = exports.TAXONOMY.find((c) => c.id === catId);
|
|
@@ -202,13 +202,60 @@ function reconstructFrontmatter(obj) {
|
|
|
202
202
|
return lines.join('\n');
|
|
203
203
|
}
|
|
204
204
|
function spliceFrontmatter(content, newObj) {
|
|
205
|
-
const yamlStr = reconstructFrontmatter(newObj);
|
|
206
205
|
const match = content.match(/^---\r?\n[\s\S]+?\r?\n---/);
|
|
207
206
|
if (match) {
|
|
207
|
+
// Identity-preservation (additive, lossless round-trip): `reconstructFrontmatter` is a
|
|
208
|
+
// deliberately lossy serializer — it cannot faithfully re-emit nested object-list items
|
|
209
|
+
// (e.g. must_haves.artifacts / must_haves.prohibitions, whose items are `{ path, provides }`
|
|
210
|
+
// / `{ statement, status, … }` maps). When the caller is writing back a value that is
|
|
211
|
+
// STRUCTURALLY UNCHANGED from the original parse (the canonical CRUD round-trip and the
|
|
212
|
+
// #644 prohibition schema round-trip both do this), regenerating from the lossy object would
|
|
213
|
+
// silently mangle those blocks. Detect that case by deep-equality against a re-parse of the
|
|
214
|
+
// original frontmatter and preserve the ORIGINAL raw text verbatim — a true no-op splice.
|
|
215
|
+
// This touches neither the parser (`extractFrontmatter`) nor `parseMustHavesBlock`; it only
|
|
216
|
+
// makes the existing splice faithful when nothing changed. A genuine mutation (different
|
|
217
|
+
// object) still flows through `reconstructFrontmatter` exactly as before.
|
|
218
|
+
try {
|
|
219
|
+
if (frontmatterDeepEqual(extractFrontmatter(content), newObj)) {
|
|
220
|
+
return content;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
catch {
|
|
224
|
+
/* fall through to regeneration on any comparison hiccup */
|
|
225
|
+
}
|
|
226
|
+
const yamlStr = reconstructFrontmatter(newObj);
|
|
208
227
|
return `---\n${yamlStr}\n---` + content.slice(match[0].length);
|
|
209
228
|
}
|
|
229
|
+
const yamlStr = reconstructFrontmatter(newObj);
|
|
210
230
|
return `---\n${yamlStr}\n---\n\n` + content;
|
|
211
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* Structural deep-equality for two parsed frontmatter objects. Order-sensitive for arrays
|
|
234
|
+
* (YAML lists are ordered), key-order-insensitive for objects. Used only by `spliceFrontmatter`
|
|
235
|
+
* to recognize a no-op write-back; intentionally narrow (handles the string / string[] /
|
|
236
|
+
* nested-object shapes `extractFrontmatter` produces).
|
|
237
|
+
*/
|
|
238
|
+
function frontmatterDeepEqual(a, b) {
|
|
239
|
+
if (a === b)
|
|
240
|
+
return true;
|
|
241
|
+
if (a == null || b == null)
|
|
242
|
+
return a === b;
|
|
243
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
244
|
+
if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length)
|
|
245
|
+
return false;
|
|
246
|
+
return a.every((v, i) => frontmatterDeepEqual(v, b[i]));
|
|
247
|
+
}
|
|
248
|
+
if (typeof a === 'object' && typeof b === 'object') {
|
|
249
|
+
const ao = a;
|
|
250
|
+
const bo = b;
|
|
251
|
+
const ak = Object.keys(ao);
|
|
252
|
+
const bk = Object.keys(bo);
|
|
253
|
+
if (ak.length !== bk.length)
|
|
254
|
+
return false;
|
|
255
|
+
return ak.every((k) => Object.prototype.hasOwnProperty.call(bo, k) && frontmatterDeepEqual(ao[k], bo[k]));
|
|
256
|
+
}
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
212
259
|
function parseMustHavesBlock(content, blockName) {
|
|
213
260
|
// Extract a specific block from must_haves in raw frontmatter YAML
|
|
214
261
|
// Handles 3-level nesting: must_haves > artifacts/key_links > [{path, provides, ...}]
|
|
@@ -431,6 +478,11 @@ function cmdFrontmatterValidate(cwd, filePath, schemaName, raw) {
|
|
|
431
478
|
}
|
|
432
479
|
module.exports = {
|
|
433
480
|
extractFrontmatter,
|
|
481
|
+
// Additive alias (#644 prohibition-probe schema contract): the probe round-trip seam reads a
|
|
482
|
+
// frontmatter object via `parseFrontmatter` (the name the contract test pins). It is the SAME
|
|
483
|
+
// function as `extractFrontmatter` — a bare-object parse with no behavior change — exposed under
|
|
484
|
+
// the alias so the prohibition schema round-trip and any future caller can use the canonical name.
|
|
485
|
+
parseFrontmatter: extractFrontmatter,
|
|
434
486
|
reconstructFrontmatter,
|
|
435
487
|
spliceFrontmatter,
|
|
436
488
|
parseMustHavesBlock,
|