gsd-pi 2.28.0-dev.853dfc5 → 2.28.0-dev.a3afd44
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/dist/resource-loader.js +80 -8
- package/dist/resources/extensions/gsd/auto-verification.ts +41 -7
- package/dist/resources/extensions/gsd/auto.ts +2 -2
- package/dist/resources/extensions/gsd/tests/verification-evidence.test.ts +26 -24
- package/dist/resources/extensions/gsd/tests/verification-gate.test.ts +136 -7
- package/dist/resources/extensions/gsd/types.ts +1 -0
- package/dist/resources/extensions/gsd/verification-evidence.ts +2 -0
- package/dist/resources/extensions/gsd/verification-gate.ts +13 -2
- package/package.json +1 -1
- package/packages/pi-coding-agent/dist/core/system-prompt.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/system-prompt.js +10 -0
- package/packages/pi-coding-agent/dist/core/system-prompt.js.map +1 -1
- package/packages/pi-coding-agent/scripts/copy-assets.cjs +39 -8
- package/packages/pi-coding-agent/src/core/system-prompt.ts +11 -0
- package/src/resources/extensions/gsd/auto-verification.ts +41 -7
- package/src/resources/extensions/gsd/auto.ts +2 -2
- package/src/resources/extensions/gsd/tests/verification-evidence.test.ts +26 -24
- package/src/resources/extensions/gsd/tests/verification-gate.test.ts +136 -7
- package/src/resources/extensions/gsd/types.ts +1 -0
- package/src/resources/extensions/gsd/verification-evidence.ts +2 -0
- package/src/resources/extensions/gsd/verification-gate.ts +13 -2
package/dist/resource-loader.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DefaultResourceLoader } from '@gsd/pi-coding-agent';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
2
3
|
import { homedir } from 'node:os';
|
|
3
|
-
import { chmodSync, cpSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { chmodSync, copyFileSync, cpSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
4
5
|
import { dirname, join, relative, resolve } from 'node:path';
|
|
5
6
|
import { fileURLToPath } from 'node:url';
|
|
6
7
|
import { compareSemver } from './update-check.js';
|
|
@@ -41,7 +42,11 @@ function getBundledGsdVersion() {
|
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
function writeManagedResourceManifest(agentDir) {
|
|
44
|
-
const manifest = {
|
|
45
|
+
const manifest = {
|
|
46
|
+
gsdVersion: getBundledGsdVersion(),
|
|
47
|
+
syncedAt: Date.now(),
|
|
48
|
+
contentHash: computeResourceFingerprint(),
|
|
49
|
+
};
|
|
45
50
|
writeFileSync(getManagedResourceManifestPath(agentDir), JSON.stringify(manifest));
|
|
46
51
|
}
|
|
47
52
|
export function readManagedResourceVersion(agentDir) {
|
|
@@ -53,6 +58,44 @@ export function readManagedResourceVersion(agentDir) {
|
|
|
53
58
|
return null;
|
|
54
59
|
}
|
|
55
60
|
}
|
|
61
|
+
function readManagedResourceManifest(agentDir) {
|
|
62
|
+
try {
|
|
63
|
+
return JSON.parse(readFileSync(getManagedResourceManifestPath(agentDir), 'utf-8'));
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Computes a lightweight content fingerprint of the bundled resources directory.
|
|
71
|
+
*
|
|
72
|
+
* Walks all files under resourcesDir and hashes their relative paths + sizes.
|
|
73
|
+
* This catches same-version content changes (npm link dev workflow, hotfixes
|
|
74
|
+
* within a release) without the cost of reading every file's contents.
|
|
75
|
+
*
|
|
76
|
+
* ~1ms for a typical resources tree (~100 files) — just stat calls, no reads.
|
|
77
|
+
*/
|
|
78
|
+
function computeResourceFingerprint() {
|
|
79
|
+
const entries = [];
|
|
80
|
+
collectFileEntries(resourcesDir, resourcesDir, entries);
|
|
81
|
+
entries.sort();
|
|
82
|
+
return createHash('sha256').update(entries.join('\n')).digest('hex').slice(0, 16);
|
|
83
|
+
}
|
|
84
|
+
function collectFileEntries(dir, root, out) {
|
|
85
|
+
if (!existsSync(dir))
|
|
86
|
+
return;
|
|
87
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
88
|
+
const fullPath = join(dir, entry.name);
|
|
89
|
+
if (entry.isDirectory()) {
|
|
90
|
+
collectFileEntries(fullPath, root, out);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
const rel = relative(root, fullPath);
|
|
94
|
+
const size = statSync(fullPath).size;
|
|
95
|
+
out.push(`${rel}:${size}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
56
99
|
export function getNewerManagedResourceVersion(agentDir, currentVersion) {
|
|
57
100
|
const managedVersion = readManagedResourceVersion(agentDir);
|
|
58
101
|
if (!managedVersion) {
|
|
@@ -111,10 +154,34 @@ function syncResourceDir(srcDir, destDir) {
|
|
|
111
154
|
rmSync(target, { recursive: true, force: true });
|
|
112
155
|
}
|
|
113
156
|
}
|
|
114
|
-
|
|
157
|
+
try {
|
|
158
|
+
cpSync(srcDir, destDir, { recursive: true, force: true });
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
// Fallback for Windows paths with non-ASCII characters where cpSync
|
|
162
|
+
// fails with the \\?\ extended-length prefix (#1178).
|
|
163
|
+
copyDirRecursive(srcDir, destDir);
|
|
164
|
+
}
|
|
115
165
|
makeTreeWritable(destDir);
|
|
116
166
|
}
|
|
117
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Recursive directory copy using copyFileSync — workaround for cpSync failures
|
|
170
|
+
* on Windows paths containing non-ASCII characters (#1178).
|
|
171
|
+
*/
|
|
172
|
+
function copyDirRecursive(src, dest) {
|
|
173
|
+
mkdirSync(dest, { recursive: true });
|
|
174
|
+
for (const entry of readdirSync(src, { withFileTypes: true })) {
|
|
175
|
+
const srcPath = join(src, entry.name);
|
|
176
|
+
const destPath = join(dest, entry.name);
|
|
177
|
+
if (entry.isDirectory()) {
|
|
178
|
+
copyDirRecursive(srcPath, destPath);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
copyFileSync(srcPath, destPath);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
118
185
|
/**
|
|
119
186
|
* Syncs all bundled resources to agentDir (~/.gsd/agent/) on every launch.
|
|
120
187
|
*
|
|
@@ -132,12 +199,17 @@ function syncResourceDir(srcDir, destDir) {
|
|
|
132
199
|
*/
|
|
133
200
|
export function initResources(agentDir) {
|
|
134
201
|
mkdirSync(agentDir, { recursive: true });
|
|
135
|
-
// Skip the full copy when
|
|
136
|
-
//
|
|
202
|
+
// Skip the full copy when both version AND content fingerprint match.
|
|
203
|
+
// Version-only checks miss same-version content changes (npm link dev workflow,
|
|
204
|
+
// hotfixes within a release). The content hash catches those at ~1ms cost.
|
|
137
205
|
const currentVersion = getBundledGsdVersion();
|
|
138
|
-
const
|
|
139
|
-
if (
|
|
140
|
-
|
|
206
|
+
const manifest = readManagedResourceManifest(agentDir);
|
|
207
|
+
if (manifest && manifest.gsdVersion === currentVersion) {
|
|
208
|
+
// Version matches — check content fingerprint for same-version staleness.
|
|
209
|
+
const currentHash = computeResourceFingerprint();
|
|
210
|
+
if (manifest.contentHash && manifest.contentHash === currentHash) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
141
213
|
}
|
|
142
214
|
syncResourceDir(bundledExtensionsDir, join(agentDir, 'extensions'));
|
|
143
215
|
syncResourceDir(join(resourcesDir, 'agents'), join(agentDir, 'agents'));
|
|
@@ -105,19 +105,39 @@ export async function runPostUnitVerification(
|
|
|
105
105
|
const completionKey = `${s.currentUnit.type}/${s.currentUnit.id}`;
|
|
106
106
|
|
|
107
107
|
if (result.checks.length > 0) {
|
|
108
|
-
const
|
|
109
|
-
const
|
|
108
|
+
const blockingChecks = result.checks.filter(c => c.blocking);
|
|
109
|
+
const advisoryChecks = result.checks.filter(c => !c.blocking);
|
|
110
|
+
const blockingPassCount = blockingChecks.filter(c => c.exitCode === 0).length;
|
|
111
|
+
const advisoryFailCount = advisoryChecks.filter(c => c.exitCode !== 0).length;
|
|
112
|
+
|
|
110
113
|
if (result.passed) {
|
|
111
|
-
|
|
114
|
+
let msg = blockingChecks.length > 0
|
|
115
|
+
? `Verification gate: ${blockingPassCount}/${blockingChecks.length} blocking checks passed`
|
|
116
|
+
: `Verification gate: passed (no blocking checks)`;
|
|
117
|
+
if (advisoryFailCount > 0) {
|
|
118
|
+
msg += ` (${advisoryFailCount} advisory warning${advisoryFailCount > 1 ? "s" : ""})`;
|
|
119
|
+
}
|
|
120
|
+
ctx.ui.notify(msg);
|
|
121
|
+
// Log advisory warnings to stderr for visibility
|
|
122
|
+
if (advisoryFailCount > 0) {
|
|
123
|
+
const advisoryFailures = advisoryChecks.filter(c => c.exitCode !== 0);
|
|
124
|
+
process.stderr.write(`verification-gate: ${advisoryFailCount} advisory (non-blocking) failure(s)\n`);
|
|
125
|
+
for (const f of advisoryFailures) {
|
|
126
|
+
process.stderr.write(` [advisory] ${f.command} exited ${f.exitCode}\n`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
112
129
|
} else {
|
|
113
|
-
const
|
|
114
|
-
const failNames =
|
|
130
|
+
const blockingFailures = blockingChecks.filter(c => c.exitCode !== 0);
|
|
131
|
+
const failNames = blockingFailures.map(f => f.command).join(", ");
|
|
115
132
|
ctx.ui.notify(`Verification gate: FAILED — ${failNames}`);
|
|
116
|
-
process.stderr.write(`verification-gate: ${
|
|
117
|
-
for (const f of
|
|
133
|
+
process.stderr.write(`verification-gate: ${blockingFailures.length}/${blockingChecks.length} blocking checks failed\n`);
|
|
134
|
+
for (const f of blockingFailures) {
|
|
118
135
|
process.stderr.write(` ${f.command} exited ${f.exitCode}\n`);
|
|
119
136
|
if (f.stderr) process.stderr.write(` stderr: ${f.stderr.slice(0, 500)}\n`);
|
|
120
137
|
}
|
|
138
|
+
if (advisoryFailCount > 0) {
|
|
139
|
+
process.stderr.write(`verification-gate: ${advisoryFailCount} additional advisory (non-blocking) failure(s)\n`);
|
|
140
|
+
}
|
|
121
141
|
}
|
|
122
142
|
}
|
|
123
143
|
|
|
@@ -155,6 +175,20 @@ export async function runPostUnitVerification(
|
|
|
155
175
|
s.verificationRetryCount.delete(s.currentUnit.id);
|
|
156
176
|
s.pendingVerificationRetry = null;
|
|
157
177
|
return "continue";
|
|
178
|
+
} else if (result.discoverySource === "package-json") {
|
|
179
|
+
// Auto-discovered checks from package.json may fail on pre-existing errors
|
|
180
|
+
// that the current task didn't introduce. Don't trigger the retry loop —
|
|
181
|
+
// log a warning and let the task proceed (#1186).
|
|
182
|
+
process.stderr.write(
|
|
183
|
+
`verification-gate: auto-discovered checks failed (source: package-json) — treating as advisory, not blocking\n`,
|
|
184
|
+
);
|
|
185
|
+
ctx.ui.notify(
|
|
186
|
+
`Verification: auto-discovered checks failed (pre-existing errors likely). Continuing without retry.`,
|
|
187
|
+
"warning",
|
|
188
|
+
);
|
|
189
|
+
s.verificationRetryCount.delete(s.currentUnit.id);
|
|
190
|
+
s.pendingVerificationRetry = null;
|
|
191
|
+
return "continue";
|
|
158
192
|
} else if (autoFixEnabled && attempt + 1 <= maxRetries) {
|
|
159
193
|
const nextAttempt = attempt + 1;
|
|
160
194
|
s.verificationRetryCount.set(s.currentUnit.id, nextAttempt);
|
|
@@ -1212,7 +1212,7 @@ async function dispatchNextUnit(
|
|
|
1212
1212
|
try { process.chdir(s.basePath); } catch { /* best-effort */ }
|
|
1213
1213
|
}
|
|
1214
1214
|
}
|
|
1215
|
-
} else if (s.currentMilestoneId && !isInAutoWorktree(s.basePath) && getIsolationMode()
|
|
1215
|
+
} else if (s.currentMilestoneId && !isInAutoWorktree(s.basePath) && getIsolationMode() === "branch") {
|
|
1216
1216
|
try {
|
|
1217
1217
|
const currentBranch = getCurrentBranch(s.basePath);
|
|
1218
1218
|
const milestoneBranch = autoWorktreeBranch(s.currentMilestoneId);
|
|
@@ -1314,7 +1314,7 @@ async function dispatchNextUnit(
|
|
|
1314
1314
|
try { process.chdir(s.basePath); } catch { /* best-effort */ }
|
|
1315
1315
|
}
|
|
1316
1316
|
}
|
|
1317
|
-
} else if (s.currentMilestoneId && !isInAutoWorktree(s.basePath) && getIsolationMode()
|
|
1317
|
+
} else if (s.currentMilestoneId && !isInAutoWorktree(s.basePath) && getIsolationMode() === "branch") {
|
|
1318
1318
|
try {
|
|
1319
1319
|
const currentBranch = getCurrentBranch(s.basePath);
|
|
1320
1320
|
const milestoneBranch = autoWorktreeBranch(s.currentMilestoneId);
|
|
@@ -58,6 +58,7 @@ test("verification-evidence: writeVerificationJSON writes correct JSON shape", (
|
|
|
58
58
|
stdout: "all good",
|
|
59
59
|
stderr: "",
|
|
60
60
|
durationMs: 2340,
|
|
61
|
+
blocking: true,
|
|
61
62
|
},
|
|
62
63
|
],
|
|
63
64
|
});
|
|
@@ -105,9 +106,9 @@ test("verification-evidence: writeVerificationJSON maps exitCode to verdict corr
|
|
|
105
106
|
const result = makeResult({
|
|
106
107
|
passed: false,
|
|
107
108
|
checks: [
|
|
108
|
-
{ command: "lint", exitCode: 0, stdout: "", stderr: "", durationMs: 100 },
|
|
109
|
-
{ command: "test", exitCode: 1, stdout: "", stderr: "fail", durationMs: 200 },
|
|
110
|
-
{ command: "audit", exitCode: 2, stdout: "", stderr: "err", durationMs: 300 },
|
|
109
|
+
{ command: "lint", exitCode: 0, stdout: "", stderr: "", durationMs: 100, blocking: true },
|
|
110
|
+
{ command: "test", exitCode: 1, stdout: "", stderr: "fail", durationMs: 200, blocking: true },
|
|
111
|
+
{ command: "audit", exitCode: 2, stdout: "", stderr: "err", durationMs: 300, blocking: true },
|
|
111
112
|
],
|
|
112
113
|
});
|
|
113
114
|
|
|
@@ -133,6 +134,7 @@ test("verification-evidence: writeVerificationJSON excludes stdout/stderr from o
|
|
|
133
134
|
stdout: "hello\n",
|
|
134
135
|
stderr: "some warning",
|
|
135
136
|
durationMs: 50,
|
|
137
|
+
blocking: true,
|
|
136
138
|
},
|
|
137
139
|
],
|
|
138
140
|
});
|
|
@@ -181,8 +183,8 @@ test("verification-evidence: writeVerificationJSON uses optional unitId when pro
|
|
|
181
183
|
test("verification-evidence: formatEvidenceTable returns markdown table with correct columns", () => {
|
|
182
184
|
const result = makeResult({
|
|
183
185
|
checks: [
|
|
184
|
-
{ command: "npm run typecheck", exitCode: 0, stdout: "", stderr: "", durationMs: 2340 },
|
|
185
|
-
{ command: "npm run lint", exitCode: 1, stdout: "", stderr: "err", durationMs: 1100 },
|
|
186
|
+
{ command: "npm run typecheck", exitCode: 0, stdout: "", stderr: "", durationMs: 2340, blocking: true },
|
|
187
|
+
{ command: "npm run lint", exitCode: 1, stdout: "", stderr: "err", durationMs: 1100, blocking: true },
|
|
186
188
|
],
|
|
187
189
|
});
|
|
188
190
|
|
|
@@ -214,9 +216,9 @@ test("verification-evidence: formatEvidenceTable returns no-checks message for e
|
|
|
214
216
|
test("verification-evidence: formatEvidenceTable formats duration as seconds with 1 decimal", () => {
|
|
215
217
|
const result = makeResult({
|
|
216
218
|
checks: [
|
|
217
|
-
{ command: "fast", exitCode: 0, stdout: "", stderr: "", durationMs: 150 },
|
|
218
|
-
{ command: "slow", exitCode: 0, stdout: "", stderr: "", durationMs: 2340 },
|
|
219
|
-
{ command: "zero", exitCode: 0, stdout: "", stderr: "", durationMs: 0 },
|
|
219
|
+
{ command: "fast", exitCode: 0, stdout: "", stderr: "", durationMs: 150, blocking: true },
|
|
220
|
+
{ command: "slow", exitCode: 0, stdout: "", stderr: "", durationMs: 2340, blocking: true },
|
|
221
|
+
{ command: "zero", exitCode: 0, stdout: "", stderr: "", durationMs: 0, blocking: true },
|
|
220
222
|
],
|
|
221
223
|
});
|
|
222
224
|
|
|
@@ -230,8 +232,8 @@ test("verification-evidence: formatEvidenceTable uses ✅/❌ emoji for pass/fai
|
|
|
230
232
|
const result = makeResult({
|
|
231
233
|
passed: false,
|
|
232
234
|
checks: [
|
|
233
|
-
{ command: "pass-cmd", exitCode: 0, stdout: "", stderr: "", durationMs: 100 },
|
|
234
|
-
{ command: "fail-cmd", exitCode: 1, stdout: "", stderr: "", durationMs: 200 },
|
|
235
|
+
{ command: "pass-cmd", exitCode: 0, stdout: "", stderr: "", durationMs: 100, blocking: true },
|
|
236
|
+
{ command: "fail-cmd", exitCode: 1, stdout: "", stderr: "", durationMs: 200, blocking: true },
|
|
235
237
|
],
|
|
236
238
|
});
|
|
237
239
|
|
|
@@ -335,8 +337,8 @@ test("verification-evidence: integration — VerificationResult → JSON → tab
|
|
|
335
337
|
const result = makeResult({
|
|
336
338
|
passed: false,
|
|
337
339
|
checks: [
|
|
338
|
-
{ command: "npm run typecheck", exitCode: 0, stdout: "ok", stderr: "", durationMs: 1500 },
|
|
339
|
-
{ command: "npm run test:unit", exitCode: 1, stdout: "", stderr: "1 failed", durationMs: 3200 },
|
|
340
|
+
{ command: "npm run typecheck", exitCode: 0, stdout: "ok", stderr: "", durationMs: 1500, blocking: true },
|
|
341
|
+
{ command: "npm run test:unit", exitCode: 1, stdout: "", stderr: "1 failed", durationMs: 3200, blocking: true },
|
|
340
342
|
],
|
|
341
343
|
discoverySource: "package-json",
|
|
342
344
|
});
|
|
@@ -390,7 +392,7 @@ test("verification-evidence: writeVerificationJSON with retryAttempt and maxRetr
|
|
|
390
392
|
const result = makeResult({
|
|
391
393
|
passed: false,
|
|
392
394
|
checks: [
|
|
393
|
-
{ command: "npm run lint", exitCode: 1, stdout: "", stderr: "error", durationMs: 300 },
|
|
395
|
+
{ command: "npm run lint", exitCode: 1, stdout: "", stderr: "error", durationMs: 300, blocking: true },
|
|
394
396
|
],
|
|
395
397
|
});
|
|
396
398
|
|
|
@@ -415,7 +417,7 @@ test("verification-evidence: writeVerificationJSON without retry params omits re
|
|
|
415
417
|
const result = makeResult({
|
|
416
418
|
passed: true,
|
|
417
419
|
checks: [
|
|
418
|
-
{ command: "npm run test", exitCode: 0, stdout: "ok", stderr: "", durationMs: 100 },
|
|
420
|
+
{ command: "npm run test", exitCode: 0, stdout: "ok", stderr: "", durationMs: 100, blocking: true },
|
|
419
421
|
],
|
|
420
422
|
});
|
|
421
423
|
|
|
@@ -441,7 +443,7 @@ test("verification-evidence: writeVerificationJSON includes runtimeErrors when p
|
|
|
441
443
|
const result = makeResult({
|
|
442
444
|
passed: false,
|
|
443
445
|
checks: [
|
|
444
|
-
{ command: "npm run test", exitCode: 0, stdout: "ok", stderr: "", durationMs: 100 },
|
|
446
|
+
{ command: "npm run test", exitCode: 0, stdout: "ok", stderr: "", durationMs: 100, blocking: true },
|
|
445
447
|
],
|
|
446
448
|
runtimeErrors: [
|
|
447
449
|
{ source: "bg-shell", severity: "crash", message: "Server crashed", blocking: true },
|
|
@@ -473,7 +475,7 @@ test("verification-evidence: writeVerificationJSON omits runtimeErrors when abse
|
|
|
473
475
|
const result = makeResult({
|
|
474
476
|
passed: true,
|
|
475
477
|
checks: [
|
|
476
|
-
{ command: "npm run lint", exitCode: 0, stdout: "", stderr: "", durationMs: 50 },
|
|
478
|
+
{ command: "npm run lint", exitCode: 0, stdout: "", stderr: "", durationMs: 50, blocking: true },
|
|
477
479
|
],
|
|
478
480
|
});
|
|
479
481
|
|
|
@@ -512,7 +514,7 @@ test("verification-evidence: formatEvidenceTable appends runtime errors section"
|
|
|
512
514
|
const result = makeResult({
|
|
513
515
|
passed: false,
|
|
514
516
|
checks: [
|
|
515
|
-
{ command: "npm run test", exitCode: 0, stdout: "", stderr: "", durationMs: 100 },
|
|
517
|
+
{ command: "npm run test", exitCode: 0, stdout: "", stderr: "", durationMs: 100, blocking: true },
|
|
516
518
|
],
|
|
517
519
|
runtimeErrors: [
|
|
518
520
|
{ source: "bg-shell", severity: "crash", message: "Server crashed with SIGKILL", blocking: true },
|
|
@@ -537,7 +539,7 @@ test("verification-evidence: formatEvidenceTable omits runtime errors section wh
|
|
|
537
539
|
const result = makeResult({
|
|
538
540
|
passed: true,
|
|
539
541
|
checks: [
|
|
540
|
-
{ command: "npm run lint", exitCode: 0, stdout: "", stderr: "", durationMs: 200 },
|
|
542
|
+
{ command: "npm run lint", exitCode: 0, stdout: "", stderr: "", durationMs: 200, blocking: true },
|
|
541
543
|
],
|
|
542
544
|
});
|
|
543
545
|
|
|
@@ -552,7 +554,7 @@ test("verification-evidence: formatEvidenceTable truncates runtime error message
|
|
|
552
554
|
const result = makeResult({
|
|
553
555
|
passed: false,
|
|
554
556
|
checks: [
|
|
555
|
-
{ command: "npm run test", exitCode: 0, stdout: "", stderr: "", durationMs: 100 },
|
|
557
|
+
{ command: "npm run test", exitCode: 0, stdout: "", stderr: "", durationMs: 100, blocking: true },
|
|
556
558
|
],
|
|
557
559
|
runtimeErrors: [
|
|
558
560
|
{ source: "bg-shell", severity: "error", message: longMessage, blocking: false },
|
|
@@ -598,7 +600,7 @@ test("verification-evidence: writeVerificationJSON includes auditWarnings when p
|
|
|
598
600
|
const result = makeResult({
|
|
599
601
|
passed: true,
|
|
600
602
|
checks: [
|
|
601
|
-
{ command: "npm run test", exitCode: 0, stdout: "ok", stderr: "", durationMs: 100 },
|
|
603
|
+
{ command: "npm run test", exitCode: 0, stdout: "ok", stderr: "", durationMs: 100, blocking: true },
|
|
602
604
|
],
|
|
603
605
|
auditWarnings: SAMPLE_AUDIT_WARNINGS,
|
|
604
606
|
});
|
|
@@ -627,7 +629,7 @@ test("verification-evidence: writeVerificationJSON omits auditWarnings when abse
|
|
|
627
629
|
const result = makeResult({
|
|
628
630
|
passed: true,
|
|
629
631
|
checks: [
|
|
630
|
-
{ command: "npm run lint", exitCode: 0, stdout: "", stderr: "", durationMs: 50 },
|
|
632
|
+
{ command: "npm run lint", exitCode: 0, stdout: "", stderr: "", durationMs: 50, blocking: true },
|
|
631
633
|
],
|
|
632
634
|
});
|
|
633
635
|
|
|
@@ -666,7 +668,7 @@ test("verification-evidence: formatEvidenceTable appends audit warnings section"
|
|
|
666
668
|
const result = makeResult({
|
|
667
669
|
passed: true,
|
|
668
670
|
checks: [
|
|
669
|
-
{ command: "npm run test", exitCode: 0, stdout: "", stderr: "", durationMs: 100 },
|
|
671
|
+
{ command: "npm run test", exitCode: 0, stdout: "", stderr: "", durationMs: 100, blocking: true },
|
|
670
672
|
],
|
|
671
673
|
auditWarnings: SAMPLE_AUDIT_WARNINGS,
|
|
672
674
|
});
|
|
@@ -689,7 +691,7 @@ test("verification-evidence: formatEvidenceTable omits audit warnings section wh
|
|
|
689
691
|
const result = makeResult({
|
|
690
692
|
passed: true,
|
|
691
693
|
checks: [
|
|
692
|
-
{ command: "npm run lint", exitCode: 0, stdout: "", stderr: "", durationMs: 200 },
|
|
694
|
+
{ command: "npm run lint", exitCode: 0, stdout: "", stderr: "", durationMs: 200, blocking: true },
|
|
693
695
|
],
|
|
694
696
|
});
|
|
695
697
|
|
|
@@ -705,7 +707,7 @@ test("verification-evidence: integration — VerificationResult with auditWarnin
|
|
|
705
707
|
const result = makeResult({
|
|
706
708
|
passed: true,
|
|
707
709
|
checks: [
|
|
708
|
-
{ command: "npm run typecheck", exitCode: 0, stdout: "ok", stderr: "", durationMs: 1500 },
|
|
710
|
+
{ command: "npm run typecheck", exitCode: 0, stdout: "ok", stderr: "", durationMs: 1500, blocking: true },
|
|
709
711
|
],
|
|
710
712
|
auditWarnings: [
|
|
711
713
|
{
|
|
@@ -581,7 +581,7 @@ test("formatFailureContext: formats a single failure with command, exit code, st
|
|
|
581
581
|
const result: import("../types.ts").VerificationResult = {
|
|
582
582
|
passed: false,
|
|
583
583
|
checks: [
|
|
584
|
-
{ command: "npm run lint", exitCode: 1, stdout: "", stderr: "error: unused var", durationMs: 500 },
|
|
584
|
+
{ command: "npm run lint", exitCode: 1, stdout: "", stderr: "error: unused var", durationMs: 500, blocking: true },
|
|
585
585
|
],
|
|
586
586
|
discoverySource: "preference",
|
|
587
587
|
timestamp: Date.now(),
|
|
@@ -598,9 +598,9 @@ test("formatFailureContext: formats multiple failures", () => {
|
|
|
598
598
|
const result: import("../types.ts").VerificationResult = {
|
|
599
599
|
passed: false,
|
|
600
600
|
checks: [
|
|
601
|
-
{ command: "npm run lint", exitCode: 1, stdout: "", stderr: "lint error", durationMs: 100 },
|
|
602
|
-
{ command: "npm run test", exitCode: 2, stdout: "", stderr: "test failure", durationMs: 200 },
|
|
603
|
-
{ command: "npm run typecheck", exitCode: 0, stdout: "ok", stderr: "", durationMs: 50 },
|
|
601
|
+
{ command: "npm run lint", exitCode: 1, stdout: "", stderr: "lint error", durationMs: 100, blocking: true },
|
|
602
|
+
{ command: "npm run test", exitCode: 2, stdout: "", stderr: "test failure", durationMs: 200, blocking: true },
|
|
603
|
+
{ command: "npm run typecheck", exitCode: 0, stdout: "ok", stderr: "", durationMs: 50, blocking: true },
|
|
604
604
|
],
|
|
605
605
|
discoverySource: "preference",
|
|
606
606
|
timestamp: Date.now(),
|
|
@@ -619,7 +619,7 @@ test("formatFailureContext: truncates stderr longer than 2000 chars", () => {
|
|
|
619
619
|
const result: import("../types.ts").VerificationResult = {
|
|
620
620
|
passed: false,
|
|
621
621
|
checks: [
|
|
622
|
-
{ command: "big-err", exitCode: 1, stdout: "", stderr: longStderr, durationMs: 100 },
|
|
622
|
+
{ command: "big-err", exitCode: 1, stdout: "", stderr: longStderr, durationMs: 100, blocking: true },
|
|
623
623
|
],
|
|
624
624
|
discoverySource: "preference",
|
|
625
625
|
timestamp: Date.now(),
|
|
@@ -634,8 +634,8 @@ test("formatFailureContext: returns empty string when all checks pass", () => {
|
|
|
634
634
|
const result: import("../types.ts").VerificationResult = {
|
|
635
635
|
passed: true,
|
|
636
636
|
checks: [
|
|
637
|
-
{ command: "npm run lint", exitCode: 0, stdout: "ok", stderr: "", durationMs: 100 },
|
|
638
|
-
{ command: "npm run test", exitCode: 0, stdout: "ok", stderr: "", durationMs: 200 },
|
|
637
|
+
{ command: "npm run lint", exitCode: 0, stdout: "ok", stderr: "", durationMs: 100, blocking: true },
|
|
638
|
+
{ command: "npm run test", exitCode: 0, stdout: "ok", stderr: "", durationMs: 200, blocking: true },
|
|
639
639
|
],
|
|
640
640
|
discoverySource: "preference",
|
|
641
641
|
timestamp: Date.now(),
|
|
@@ -663,6 +663,7 @@ test("formatFailureContext: caps total output at 10,000 chars", () => {
|
|
|
663
663
|
stdout: "",
|
|
664
664
|
stderr: "e".repeat(1000), // 1000 chars each, 20 * ~1050 (with formatting) > 10,000
|
|
665
665
|
durationMs: 100,
|
|
666
|
+
blocking: true,
|
|
666
667
|
});
|
|
667
668
|
}
|
|
668
669
|
const result: import("../types.ts").VerificationResult = {
|
|
@@ -1077,3 +1078,131 @@ test("dependency-audit: subdirectory package.json does not trigger audit", () =>
|
|
|
1077
1078
|
assert.equal(npmAuditCalled, false, "subdirectory dependency files should not trigger audit");
|
|
1078
1079
|
assert.deepStrictEqual(result, []);
|
|
1079
1080
|
});
|
|
1081
|
+
|
|
1082
|
+
// ─── Non-Blocking Discovery Tests ────────────────────────────────────────────
|
|
1083
|
+
|
|
1084
|
+
test("non-blocking: package-json discovered commands failing → result.passed is still true", () => {
|
|
1085
|
+
const tmp = makeTempDir("vg-nb-pkg-fail");
|
|
1086
|
+
try {
|
|
1087
|
+
writeFileSync(
|
|
1088
|
+
join(tmp, "package.json"),
|
|
1089
|
+
JSON.stringify({ scripts: { lint: "eslint .", test: "vitest" } }),
|
|
1090
|
+
);
|
|
1091
|
+
// These commands will fail because eslint/vitest don't exist in the temp dir
|
|
1092
|
+
const result = runVerificationGate({
|
|
1093
|
+
basePath: tmp,
|
|
1094
|
+
unitId: "T01",
|
|
1095
|
+
cwd: tmp,
|
|
1096
|
+
// No preference commands — discovery falls through to package.json
|
|
1097
|
+
});
|
|
1098
|
+
assert.equal(result.discoverySource, "package-json");
|
|
1099
|
+
assert.ok(result.checks.length > 0, "should have discovered package.json checks");
|
|
1100
|
+
assert.equal(result.passed, true, "package-json failures should not block the gate");
|
|
1101
|
+
for (const check of result.checks) {
|
|
1102
|
+
assert.equal(check.blocking, false, "package-json checks should be non-blocking");
|
|
1103
|
+
}
|
|
1104
|
+
} finally {
|
|
1105
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
1106
|
+
}
|
|
1107
|
+
});
|
|
1108
|
+
|
|
1109
|
+
test("non-blocking: preference commands failing → result.passed is false", () => {
|
|
1110
|
+
const tmp = makeTempDir("vg-nb-pref-fail");
|
|
1111
|
+
try {
|
|
1112
|
+
const result = runVerificationGate({
|
|
1113
|
+
basePath: tmp,
|
|
1114
|
+
unitId: "T01",
|
|
1115
|
+
cwd: tmp,
|
|
1116
|
+
preferenceCommands: ["sh -c 'exit 1'"],
|
|
1117
|
+
});
|
|
1118
|
+
assert.equal(result.discoverySource, "preference");
|
|
1119
|
+
assert.equal(result.passed, false, "preference failures should block the gate");
|
|
1120
|
+
assert.equal(result.checks[0].blocking, true, "preference checks should be blocking");
|
|
1121
|
+
} finally {
|
|
1122
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
1123
|
+
}
|
|
1124
|
+
});
|
|
1125
|
+
|
|
1126
|
+
test("non-blocking: task-plan commands failing → result.passed is false", () => {
|
|
1127
|
+
const tmp = makeTempDir("vg-nb-tp-fail");
|
|
1128
|
+
try {
|
|
1129
|
+
const result = runVerificationGate({
|
|
1130
|
+
basePath: tmp,
|
|
1131
|
+
unitId: "T01",
|
|
1132
|
+
cwd: tmp,
|
|
1133
|
+
taskPlanVerify: "sh -c 'exit 1'",
|
|
1134
|
+
});
|
|
1135
|
+
assert.equal(result.discoverySource, "task-plan");
|
|
1136
|
+
assert.equal(result.passed, false, "task-plan failures should block the gate");
|
|
1137
|
+
assert.equal(result.checks[0].blocking, true, "task-plan checks should be blocking");
|
|
1138
|
+
} finally {
|
|
1139
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
1140
|
+
}
|
|
1141
|
+
});
|
|
1142
|
+
|
|
1143
|
+
test("non-blocking: blocking field is set correctly based on discovery source", () => {
|
|
1144
|
+
const tmp = makeTempDir("vg-nb-field");
|
|
1145
|
+
try {
|
|
1146
|
+
// preference → blocking
|
|
1147
|
+
const prefResult = runVerificationGate({
|
|
1148
|
+
basePath: tmp,
|
|
1149
|
+
unitId: "T01",
|
|
1150
|
+
cwd: tmp,
|
|
1151
|
+
preferenceCommands: ["echo ok"],
|
|
1152
|
+
});
|
|
1153
|
+
assert.equal(prefResult.checks[0].blocking, true);
|
|
1154
|
+
|
|
1155
|
+
// task-plan → blocking
|
|
1156
|
+
const tpResult = runVerificationGate({
|
|
1157
|
+
basePath: tmp,
|
|
1158
|
+
unitId: "T01",
|
|
1159
|
+
cwd: tmp,
|
|
1160
|
+
taskPlanVerify: "echo ok",
|
|
1161
|
+
});
|
|
1162
|
+
assert.equal(tpResult.checks[0].blocking, true);
|
|
1163
|
+
|
|
1164
|
+
// package-json → non-blocking
|
|
1165
|
+
writeFileSync(
|
|
1166
|
+
join(tmp, "package.json"),
|
|
1167
|
+
JSON.stringify({ scripts: { test: "echo ok" } }),
|
|
1168
|
+
);
|
|
1169
|
+
const pkgResult = runVerificationGate({
|
|
1170
|
+
basePath: tmp,
|
|
1171
|
+
unitId: "T01",
|
|
1172
|
+
cwd: tmp,
|
|
1173
|
+
});
|
|
1174
|
+
assert.equal(pkgResult.checks[0].blocking, false);
|
|
1175
|
+
} finally {
|
|
1176
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
1177
|
+
}
|
|
1178
|
+
});
|
|
1179
|
+
|
|
1180
|
+
test("non-blocking: formatFailureContext only includes blocking failures", () => {
|
|
1181
|
+
const result: import("../types.ts").VerificationResult = {
|
|
1182
|
+
passed: true,
|
|
1183
|
+
checks: [
|
|
1184
|
+
{ command: "npm run lint", exitCode: 1, stdout: "", stderr: "lint warning", durationMs: 100, blocking: false },
|
|
1185
|
+
{ command: "npm run test", exitCode: 1, stdout: "", stderr: "test error", durationMs: 200, blocking: true },
|
|
1186
|
+
{ command: "npm run typecheck", exitCode: 1, stdout: "", stderr: "type error", durationMs: 50, blocking: false },
|
|
1187
|
+
],
|
|
1188
|
+
discoverySource: "preference",
|
|
1189
|
+
timestamp: Date.now(),
|
|
1190
|
+
};
|
|
1191
|
+
const output = formatFailureContext(result);
|
|
1192
|
+
assert.ok(output.includes("`npm run test`"), "should include blocking failure");
|
|
1193
|
+
assert.ok(!output.includes("npm run lint"), "should not include non-blocking failure");
|
|
1194
|
+
assert.ok(!output.includes("npm run typecheck"), "should not include non-blocking failure");
|
|
1195
|
+
});
|
|
1196
|
+
|
|
1197
|
+
test("non-blocking: formatFailureContext returns empty when only non-blocking failures exist", () => {
|
|
1198
|
+
const result: import("../types.ts").VerificationResult = {
|
|
1199
|
+
passed: true,
|
|
1200
|
+
checks: [
|
|
1201
|
+
{ command: "npm run lint", exitCode: 1, stdout: "", stderr: "lint warning", durationMs: 100, blocking: false },
|
|
1202
|
+
{ command: "npm run test", exitCode: 1, stdout: "", stderr: "test warning", durationMs: 200, blocking: false },
|
|
1203
|
+
],
|
|
1204
|
+
discoverySource: "package-json",
|
|
1205
|
+
timestamp: Date.now(),
|
|
1206
|
+
};
|
|
1207
|
+
assert.equal(formatFailureContext(result), "", "should return empty when only non-blocking failures");
|
|
1208
|
+
});
|
|
@@ -55,6 +55,7 @@ export interface VerificationCheck {
|
|
|
55
55
|
stdout: string;
|
|
56
56
|
stderr: string;
|
|
57
57
|
durationMs: number;
|
|
58
|
+
blocking: boolean; // true for preference/task-plan sources, false for package-json (advisory only)
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
/** A runtime error captured from bg-shell processes or browser console */
|
|
@@ -20,6 +20,7 @@ export interface EvidenceCheckJSON {
|
|
|
20
20
|
exitCode: number;
|
|
21
21
|
durationMs: number;
|
|
22
22
|
verdict: "pass" | "fail";
|
|
23
|
+
blocking: boolean;
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
export interface RuntimeErrorJSON {
|
|
@@ -80,6 +81,7 @@ export function writeVerificationJSON(
|
|
|
80
81
|
exitCode: check.exitCode,
|
|
81
82
|
durationMs: check.durationMs,
|
|
82
83
|
verdict: check.exitCode === 0 ? "pass" : "fail",
|
|
84
|
+
blocking: check.blocking,
|
|
83
85
|
})),
|
|
84
86
|
...(retryAttempt !== undefined ? { retryAttempt } : {}),
|
|
85
87
|
...(maxRetries !== undefined ? { maxRetries } : {}),
|
|
@@ -112,7 +112,9 @@ const MAX_FAILURE_CONTEXT_CHARS = 10_000;
|
|
|
112
112
|
* Returns an empty string when all checks pass or the checks array is empty.
|
|
113
113
|
*/
|
|
114
114
|
export function formatFailureContext(result: VerificationResult): string {
|
|
115
|
-
|
|
115
|
+
// Only include blocking failures in retry context — non-blocking (advisory) failures
|
|
116
|
+
// should not be injected into retry prompts to avoid noise pollution.
|
|
117
|
+
const failures = result.checks.filter((c) => c.exitCode !== 0 && c.blocking);
|
|
116
118
|
if (failures.length === 0) return "";
|
|
117
119
|
|
|
118
120
|
const blocks: string[] = [];
|
|
@@ -256,6 +258,10 @@ export function runVerificationGate(options: RunVerificationGateOptions): Verifi
|
|
|
256
258
|
};
|
|
257
259
|
}
|
|
258
260
|
|
|
261
|
+
// Commands from preference and task-plan sources are blocking;
|
|
262
|
+
// package-json discovered commands are advisory (non-blocking).
|
|
263
|
+
const blocking = source === "preference" || source === "task-plan";
|
|
264
|
+
|
|
259
265
|
const checks: VerificationCheck[] = [];
|
|
260
266
|
|
|
261
267
|
for (const command of commands) {
|
|
@@ -291,11 +297,16 @@ export function runVerificationGate(options: RunVerificationGateOptions): Verifi
|
|
|
291
297
|
stdout: truncate(result.stdout, MAX_OUTPUT_BYTES),
|
|
292
298
|
stderr,
|
|
293
299
|
durationMs,
|
|
300
|
+
blocking,
|
|
294
301
|
});
|
|
295
302
|
}
|
|
296
303
|
|
|
304
|
+
// Gate passes if all blocking checks pass (non-blocking failures are advisory)
|
|
305
|
+
const blockingChecks = checks.filter(c => c.blocking);
|
|
306
|
+
const passed = blockingChecks.length === 0 || blockingChecks.every(c => c.exitCode === 0);
|
|
307
|
+
|
|
297
308
|
return {
|
|
298
|
-
passed
|
|
309
|
+
passed,
|
|
299
310
|
checks,
|
|
300
311
|
discoverySource: source,
|
|
301
312
|
timestamp,
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"system-prompt.d.ts","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAyB,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAchE,MAAM,WAAW,wBAAwB;IACxC,+CAA+C;IAC/C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qEAAqE;IACrE,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,qFAAqF;IACrF,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,uCAAuC;IACvC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,YAAY,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACxD,yBAAyB;IACzB,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;CACjB;AAED,kEAAkE;AAClE,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,wBAA6B,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"system-prompt.d.ts","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAyB,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAchE,MAAM,WAAW,wBAAwB;IACxC,+CAA+C;IAC/C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qEAAqE;IACrE,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,qFAAqF;IACrF,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,uCAAuC;IACvC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,YAAY,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACxD,yBAAyB;IACzB,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;CACjB;AAED,kEAAkE;AAClE,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,wBAA6B,GAAG,MAAM,CA4MhF"}
|