opencode-workflow-guard 1.20.1 → 1.20.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/README.md +1 -1
- package/docs/agents/ledger.md +523 -0
- package/docs/agents/lessons/20261120T134830Z-align-with-the-sibling-matcher.md +13 -0
- package/docs/agents/rsi-loop-playbook.md +77 -0
- package/docs/policies.md +11 -7
- package/docs/testing.md +2 -2
- package/docs/troubleshooting.md +2 -0
- package/package.json +5 -5
- package/src/lib/custom-tools.ts +1 -1
- package/src/lib/guard-api.ts +1 -0
- package/src/lib/guard-dispatcher.ts +38 -26
- package/src/lib/shell.ts +12 -3
- package/src/lib/state.ts +5 -2
- package/src/lib/types.ts +10 -0
- package/src/lib/v2-plugin.ts +2 -1
- package/src/lib/verify.ts +43 -5
- package/src/policies/completion.ts +7 -3
- package/src/policies/git.ts +82 -1
- package/src/policies/post-edit-validation.ts +7 -2
- package/src/policies/shell-safety.ts +50 -25
- package/src/policies/tamper.ts +96 -4
- package/src/policies/todo.ts +158 -52
- package/src/workflow-guard.ts +6 -1
- package/test/test.mts +277 -6
package/src/workflow-guard.ts
CHANGED
|
@@ -245,6 +245,7 @@ import {
|
|
|
245
245
|
resolveVerifyTimeoutMs,
|
|
246
246
|
runVerify,
|
|
247
247
|
snipVerifyOutput,
|
|
248
|
+
formatTimeoutLimit,
|
|
248
249
|
getCurrentGitCommitHash,
|
|
249
250
|
getGitStatusSummary,
|
|
250
251
|
getGitWorktreeFingerprint,
|
|
@@ -257,6 +258,7 @@ export {
|
|
|
257
258
|
resolveVerifyTimeoutMs,
|
|
258
259
|
runVerify,
|
|
259
260
|
snipVerifyOutput,
|
|
261
|
+
formatTimeoutLimit,
|
|
260
262
|
getCurrentGitCommitHash,
|
|
261
263
|
getGitStatusSummary,
|
|
262
264
|
getGitWorktreeFingerprint,
|
|
@@ -325,6 +327,7 @@ import {
|
|
|
325
327
|
findWorktreeForBranch,
|
|
326
328
|
parseGitInvocation,
|
|
327
329
|
prSourceBranch,
|
|
330
|
+
purgesMergedRemoteBranches,
|
|
328
331
|
} from "./policies/git.ts";
|
|
329
332
|
|
|
330
333
|
export {
|
|
@@ -335,6 +338,7 @@ export {
|
|
|
335
338
|
findWorktreeForBranch,
|
|
336
339
|
parseGitInvocation,
|
|
337
340
|
prSourceBranch,
|
|
341
|
+
purgesMergedRemoteBranches,
|
|
338
342
|
};
|
|
339
343
|
|
|
340
344
|
import {
|
|
@@ -401,6 +405,7 @@ export { isResearchTool, liveDocsGatingReason };
|
|
|
401
405
|
|
|
402
406
|
export { sendDesktopNotification } from "./policies/shell-safety.ts";
|
|
403
407
|
export { checkInteractiveTtyCommand, checkPackageHygiene, escapeAppleScriptString };
|
|
408
|
+
export { shellHasSudoWrapper } from "./lib/shell.ts";
|
|
404
409
|
|
|
405
410
|
function logObservation(client: unknown, message: string): void {
|
|
406
411
|
try {
|
|
@@ -676,7 +681,7 @@ export const WorkflowGuard: V1Plugin = async (ctx: Parameters<V1Plugin>[0]) => {
|
|
|
676
681
|
];
|
|
677
682
|
if (lastV) {
|
|
678
683
|
stateLines.push(
|
|
679
|
-
`- Test Verification: ${lastV.passed ? "PASSED" : "FAILED"} (${lastV.command})${lastV.commitHash ? ` at commit ${lastV.commitHash.slice(0, 7)}` : ""}`,
|
|
684
|
+
`- Test Verification: ${lastV.passed ? "PASSED" : lastV.timedOut ? `TIMED OUT within ${formatTimeoutLimit(lastV.timeoutMs)} (result unknown, not a failing test)` : "FAILED"} (${lastV.command})${lastV.commitHash ? ` at commit ${lastV.commitHash.slice(0, 7)}` : ""}`,
|
|
680
685
|
);
|
|
681
686
|
}
|
|
682
687
|
if (lastR) {
|
package/test/test.mts
CHANGED
|
@@ -89,6 +89,7 @@ import {
|
|
|
89
89
|
stripJsonComments,
|
|
90
90
|
extractInterpreterPayload,
|
|
91
91
|
isBranchAlreadyMergedOrClosed,
|
|
92
|
+
purgesMergedRemoteBranches,
|
|
92
93
|
checkMergeConflicts,
|
|
93
94
|
checkBranchBaseIsUpToDate,
|
|
94
95
|
findWorktreeForBranch,
|
|
@@ -110,6 +111,7 @@ import {
|
|
|
110
111
|
getSubagentMutationBudget,
|
|
111
112
|
isReadOnlyRole,
|
|
112
113
|
checkInteractiveTtyCommand,
|
|
114
|
+
shellHasSudoWrapper,
|
|
113
115
|
checkPackageHygiene,
|
|
114
116
|
delegationSpawnIn,
|
|
115
117
|
sendDesktopNotification,
|
|
@@ -153,7 +155,7 @@ import { WorkflowGuardTui, WorkflowGuardTuiV2, formatBadge, readProjectOption, r
|
|
|
153
155
|
import { scanSessionTodos, toolPartName, detectTodoCapability, recordedTodoCapability, recordTodoCapability, reportTodoGateFailOpen, resetTodoCapabilityForTesting } from "../src/lib/v2-todo.ts";
|
|
154
156
|
import { buildPolicyPosture, renderPolicyPosture } from "../src/lib/policy-posture.ts";
|
|
155
157
|
import { pluginKeyFor, preparePluginUpdate } from "../src/lib/config-writer.mjs";
|
|
156
|
-
import { effectiveTodosWithOwner, isReadOnlyTodo, readOnlyTodoCompletions, recordTodoTaskStarts, todoEvidenceReport, unverifiedTodoCompletions, validateTodoLifecycle } from "../src/policies/todo.ts";
|
|
158
|
+
import { effectiveTodosWithOwner, inspectTodoLifecycle, isReadOnlyTodo, readOnlyTodoCompletions, recordTodoTaskStarts, todoEvidenceReport, unverifiedTodoCompletions, validateTodoLifecycle } from "../src/policies/todo.ts";
|
|
157
159
|
import {
|
|
158
160
|
LiveDocsResearchFloor,
|
|
159
161
|
clearLiveDocsFloor,
|
|
@@ -412,6 +414,58 @@ check("completion evidence: a task that is only the marker has no identity and i
|
|
|
412
414
|
check("lifecycle: appending the read-only marker to a planned task is not a silent deletion", !validateTodoLifecycle([item("Review the diff [read-only]", "completed")], [item("Review the diff", "in_progress")]));
|
|
413
415
|
check("lifecycle: appending the marker to a still-active task retains it", !validateTodoLifecycle([item("Review the diff [read-only]", "in_progress")], [item("Review the diff", "in_progress")]));
|
|
414
416
|
|
|
417
|
+
// A sharpened task is the same work item, not a dropped one. A removed active
|
|
418
|
+
// task whose tokens all survive in an active successor is a refinement. The
|
|
419
|
+
// three shapes below are lifted from the audit journal's todo_lifecycle reasons.
|
|
420
|
+
check("lifecycle: added wording in a reworded task is a refinement", !validateTodoLifecycle([item("Verify the doc change, pass review, and open its PR", "in_progress")], [item("Verify the doc change and open its PR", "in_progress")]));
|
|
421
|
+
check("lifecycle: a reworded PR task with a new preposition is a refinement", !validateTodoLifecycle([item("Push the branch, open PR for #245 with Fixes #245", "in_progress")], [item("Push the branch, open PR #245 with Fixes #245", "in_progress")]));
|
|
422
|
+
check("lifecycle: a prefixed clause on an existing task is a refinement", !validateTodoLifecycle([item("Re-run review, record verdict, open PR for issue #42 and clean up the branch", "in_progress")], [item("Open PR for issue #42 and clean up the branch", "in_progress")]));
|
|
423
|
+
// The strict boundary still holds: no token superset means no refinement.
|
|
424
|
+
check("lifecycle: an unrelated equal-length replacement still blocks", !!validateTodoLifecycle([item("Run the test suite", "in_progress")], [item("Write the release notes", "in_progress")]));
|
|
425
|
+
check("lifecycle: a removed task with no successor still blocks", !!validateTodoLifecycle([item("other work", "in_progress")], [item("Write the release notes", "in_progress")]));
|
|
426
|
+
check("lifecycle: a one-word reword stays strict", !!validateTodoLifecycle([item("tests", "in_progress")], [item("tests please", "in_progress")]));
|
|
427
|
+
check("lifecycle: one successor cannot absorb two removed tasks", !!validateTodoLifecycle([item("deploy the service", "in_progress")], [item("write the fix, then deploy the service", "in_progress"), item("deploy the service", "in_progress")]));
|
|
428
|
+
|
|
429
|
+
// A refinement keeps the predecessor's mutation window, so recorded work still
|
|
430
|
+
// vouches for the reworded task. The pairing is the lifecycle verdict's, so the
|
|
431
|
+
// window carry and the completion gate cannot disagree about it.
|
|
432
|
+
const refinePrev = [item("Verify the doc change and open its PR", "in_progress")];
|
|
433
|
+
const refineNext = [item("Verify the doc change, pass review, and open its PR", "in_progress")];
|
|
434
|
+
const refinePairing = inspectTodoLifecycle(refineNext, refinePrev).refinements;
|
|
435
|
+
check("lifecycle: the refinement verdict names its predecessor and successor", refinePairing.length === 1 && refinePairing[0]!.from === "Verify the doc change and open its PR" && refinePairing[0]!.to === "Verify the doc change, pass review, and open its PR");
|
|
436
|
+
const refineStarts = new Map<string, number>();
|
|
437
|
+
recordTodoTaskStarts(refineStarts, undefined, refinePrev, 0);
|
|
438
|
+
recordTodoTaskStarts(refineStarts, refinePrev, refineNext, 3, refinePairing);
|
|
439
|
+
check("refinement: the reworded task inherits the predecessor's window", refineStarts.get("Verify the doc change, pass review, and open its PR") === 0 && !refineStarts.has("Verify the doc change and open its PR"));
|
|
440
|
+
const refinedComplete = [item("Verify the doc change, pass review, and open its PR", "completed")];
|
|
441
|
+
check("refinement: the carried window vouches for the refined completion", unverifiedTodoCompletions(refinePrev, refinedComplete, refineStarts, 1, refinePairing).length === 0);
|
|
442
|
+
const preCarry = new Map([["Verify the doc change and open its PR", 2]]);
|
|
443
|
+
check("refinement: completion evidence sees the inherited window before the map moves", unverifiedTodoCompletions(refinePrev, refinedComplete, preCarry, 3, refinePairing).length === 0);
|
|
444
|
+
check("refinement: a carried window still needs a mutation inside it", JSON.stringify(unverifiedTodoCompletions(refinePrev, refinedComplete, preCarry, 2, refinePairing)) === JSON.stringify(["Verify the doc change, pass review, and open its PR"]));
|
|
445
|
+
const lateCarry = new Map([["Verify the doc change and open its PR", 5]]);
|
|
446
|
+
check("refinement: mutations before the inherited window never count", JSON.stringify(unverifiedTodoCompletions(refinePrev, refinedComplete, lateCarry, 5, refinePairing)) === JSON.stringify(["Verify the doc change, pass review, and open its PR"]));
|
|
447
|
+
check("refinement: a reword with no recorded work does not complete freely", JSON.stringify(unverifiedTodoCompletions(refinePrev, refinedComplete, new Map(), 0, refinePairing)) === JSON.stringify(["Verify the doc change, pass review, and open its PR"]));
|
|
448
|
+
|
|
449
|
+
// One predecessor cannot carry its window to two successors. The verdict pairs
|
|
450
|
+
// it once, and the window map follows that pairing rather than guessing again.
|
|
451
|
+
const splitPrev = [item("add the retry loop", "in_progress")];
|
|
452
|
+
const splitNext = [item("add the retry loop for uploads", "in_progress"), item("add the retry loop for downloads", "in_progress")];
|
|
453
|
+
const splitPairing = inspectTodoLifecycle(splitNext, splitPrev).refinements;
|
|
454
|
+
check("lifecycle: one predecessor pairs with one successor", splitPairing.length === 1 && splitPairing[0]!.toKey === "add the retry loop for uploads");
|
|
455
|
+
const splitStarts = new Map([["add the retry loop", 4]]);
|
|
456
|
+
recordTodoTaskStarts(splitStarts, splitPrev, splitNext, 9, splitPairing);
|
|
457
|
+
check("refinement: one predecessor's window carries to one successor only", splitStarts.get("add the retry loop for uploads") === 4 && splitStarts.get("add the retry loop for downloads") === 9);
|
|
458
|
+
|
|
459
|
+
// Two predecessors and two successors pair one-to-one, so neither window is
|
|
460
|
+
// guessed from the other. Each successor is matched by its own tokens.
|
|
461
|
+
const pairPrev = [item("write the parser", "in_progress"), item("run the parser tests", "in_progress")];
|
|
462
|
+
const pairNext = [item("write the parser and add fixtures", "in_progress"), item("run the parser tests and triage failures", "in_progress")];
|
|
463
|
+
const pairVerdict = inspectTodoLifecycle(pairNext, pairPrev).refinements;
|
|
464
|
+
check("lifecycle: two reworded tasks pair with two distinct successors", pairVerdict.length === 2 && new Set(pairVerdict.map((r) => r.fromKey)).size === 2 && new Set(pairVerdict.map((r) => r.toKey)).size === 2);
|
|
465
|
+
const pairStarts = new Map([["write the parser", 1], ["run the parser tests", 6]]);
|
|
466
|
+
recordTodoTaskStarts(pairStarts, pairPrev, pairNext, 8, pairVerdict);
|
|
467
|
+
check("refinement: each predecessor's window moves to its own successor", pairStarts.get("write the parser and add fixtures") === 1 && pairStarts.get("run the parser tests and triage failures") === 6);
|
|
468
|
+
|
|
415
469
|
// Marker escape, and the transitions that are not new claims.
|
|
416
470
|
check("completion evidence: the read-only marker is recognized", isReadOnlyTodo(item("Review the diff [read-only]", "completed")) && !isReadOnlyTodo(item("Review the diff", "completed")));
|
|
417
471
|
check("completion evidence: a marked read-only task completes with no mutation", unverifiedTodoCompletions([item("Review the diff [read-only]", "in_progress")], [item("Review the diff [read-only]", "completed")], new Map(), 0).length === 0);
|
|
@@ -448,6 +502,15 @@ const auditBeforeBlocked = getRecentAuditEntries(50).filter((entry) => entry.rea
|
|
|
448
502
|
await call("todowrite", { todos: [item("real work [read-only]", "completed"), item("brand new", "completed")] }, { sessionID: "s-evidence-audit-order" });
|
|
449
503
|
check("a blocked todowrite does not journal a read-only completion", getRecentAuditEntries(50).filter((entry) => entry.reason === "todo_completed_read_only").length === auditBeforeBlocked);
|
|
450
504
|
|
|
505
|
+
// End to end: reworded work passes the lifecycle gate and leaves a trail, while
|
|
506
|
+
// a genuine removal is still refused.
|
|
507
|
+
todo("s-refine", item("Verify the doc change and open its PR", "in_progress"));
|
|
508
|
+
check("dispatcher allows a reworded active task", !(await call("todowrite", { todos: [item("Verify the doc change, pass review, and open its PR", "in_progress")] }, { sessionID: "s-refine" })));
|
|
509
|
+
const refineAudit = getRecentAuditEntries(50).filter((entry) => entry.reason === "todo_refined");
|
|
510
|
+
check("dispatcher journals the refinement", refineAudit.length > 0 && JSON.stringify((refineAudit.at(-1)?.input as { refinements?: unknown })?.refinements) === JSON.stringify([{ from: "Verify the doc change and open its PR", to: "Verify the doc change, pass review, and open its PR" }]));
|
|
511
|
+
todo("s-refine-drop", item("Write the release notes", "in_progress"));
|
|
512
|
+
check("dispatcher still blocks a genuine task removal", blocked(await call("todowrite", { todos: [item("Publish the release", "in_progress")] }, { sessionID: "s-refine-drop" })));
|
|
513
|
+
|
|
451
514
|
// guard_status surfaces the requirement before it bites.
|
|
452
515
|
todo("s-evidence-report", item("write the fix", "in_progress"), item("Review the diff [read-only]", "in_progress"), item("done already", "completed"));
|
|
453
516
|
const evidenceReport = await todoEvidenceReport("s-evidence-report");
|
|
@@ -888,6 +951,69 @@ setWorkspaceRoot(ffLocalRepo);
|
|
|
888
951
|
check("on main: pull --ff-only from a local upstream branch stays blocked", blocked(await shell("git pull --ff-only")));
|
|
889
952
|
check("on main: merge --ff-only from the local upstream stays blocked", blocked(await shell("git merge --ff-only")));
|
|
890
953
|
rmSync(ffLocalBase, { recursive: true, force: true });
|
|
954
|
+
// The cleanup a merged PR requires used to be impossible for the agent: both
|
|
955
|
+
// halves were blocked whenever the checkout sat on the protected branch that
|
|
956
|
+
// received the merge. A merged-only delete publishes no commit, so it is
|
|
957
|
+
// exempt, and every form that could drop unmerged commits stays blocked.
|
|
958
|
+
const cleanupBase = mkdtempSync(join(tmpdir(), "wg-cleanup-"));
|
|
959
|
+
const cleanupRemote = join(cleanupBase, "remote.git");
|
|
960
|
+
const cleanupRepo = join(cleanupBase, "repo");
|
|
961
|
+
spawnSync("git", ["init", "--bare", "-b", "main", cleanupRemote]);
|
|
962
|
+
spawnSync("git", ["init", "-b", "main", cleanupRepo]);
|
|
963
|
+
writeFileSync(join(cleanupRepo, "a.txt"), "a\n");
|
|
964
|
+
ffGit("-C", cleanupRepo, "add", "a.txt");
|
|
965
|
+
ffGit("-C", cleanupRepo, "commit", "-m", "init");
|
|
966
|
+
ffGit("-C", cleanupRepo, "remote", "add", "origin", cleanupRemote);
|
|
967
|
+
ffGit("-C", cleanupRepo, "push", "-u", "origin", "main");
|
|
968
|
+
ffGit("-C", cleanupRepo, "branch", "feat/merged");
|
|
969
|
+
ffGit("-C", cleanupRepo, "push", "origin", "feat/merged");
|
|
970
|
+
ffGit("-C", cleanupRepo, "switch", "-c", "feat/unmerged");
|
|
971
|
+
writeFileSync(join(cleanupRepo, "b.txt"), "b\n");
|
|
972
|
+
ffGit("-C", cleanupRepo, "add", "b.txt");
|
|
973
|
+
ffGit("-C", cleanupRepo, "commit", "-m", "unmerged work");
|
|
974
|
+
ffGit("-C", cleanupRepo, "switch", "main");
|
|
975
|
+
ffGit("-C", cleanupRepo, "fetch", "origin");
|
|
976
|
+
setWorkspaceRoot(cleanupRepo);
|
|
977
|
+
check("on main: branch -d of a merged branch allowed", !blocked(await shell("git branch -d feat/merged")));
|
|
978
|
+
check("on main: branch --delete of a merged branch allowed", !blocked(await shell("git branch --delete feat/merged")));
|
|
979
|
+
check("on main: branch -D stays blocked", blocked(await shell("git branch -D feat/merged")));
|
|
980
|
+
check("on main: branch -d --force stays blocked", blocked(await shell("git branch -d --force feat/merged")));
|
|
981
|
+
check("on main: branch -d of a protected name stays blocked", blocked(await shell("git branch -d main")));
|
|
982
|
+
check("on main: branch --delete of a protected name stays blocked", blocked(await shell("git branch --delete main")));
|
|
983
|
+
check("on main: branch --delete --force stays blocked", blocked(await shell("git branch --delete --force feat/merged")));
|
|
984
|
+
check("on main: branch -fd stays blocked", blocked(await shell("git branch -fd feat/merged")));
|
|
985
|
+
check("on main: branch -rd of a merged branch allowed", !blocked(await shell("git branch -rd feat/merged")));
|
|
986
|
+
check("on main: branch -d with no branch named stays blocked", blocked(await shell("git branch -d")));
|
|
987
|
+
check("on main: ordinary push still blocked from the protected checkout", blocked(await shell("git push origin feat/merged")));
|
|
988
|
+
check("on main: delete of a merged remote branch allowed", !blocked(await shell("git push origin --delete feat/merged")));
|
|
989
|
+
check("on main: :refs/heads delete of a merged remote branch allowed", !blocked(await shell("git push origin :refs/heads/feat/merged")));
|
|
990
|
+
check("on main: delete of an unmerged remote branch blocked", blocked(await shell("git push origin --delete feat/unmerged")));
|
|
991
|
+
check("on main: :refspec delete of an unmerged remote branch blocked", blocked(await shell("git push origin :feat/unmerged")));
|
|
992
|
+
check("on main: delete of a protected remote branch blocked", blocked(await shell("git push origin --delete main")));
|
|
993
|
+
check("on main: push --prune stays blocked", blocked(await shell("git push origin --prune")));
|
|
994
|
+
check("on main: push --mirror stays blocked", blocked(await shell("git push --mirror origin")));
|
|
995
|
+
check("purge helper rejects a plain refspec", !purgesMergedRemoteBranches("git push origin feat/merged", cleanupRepo));
|
|
996
|
+
check("purge helper accepts a merged delete", purgesMergedRemoteBranches("git push origin --delete feat/merged", cleanupRepo));
|
|
997
|
+
check("purge helper rejects a tag refspec", !purgesMergedRemoteBranches("git push origin :refs/tags/feat/merged", cleanupRepo));
|
|
998
|
+
// A tag that shares the branch namespace must not satisfy the merged check.
|
|
999
|
+
// The helper names refs/heads and refs/remotes/origin explicitly, so the tag
|
|
1000
|
+
// alone resolves to nothing and the deletion stays blocked.
|
|
1001
|
+
ffGit("-C", cleanupRepo, "tag", "feat/onlytag", "main");
|
|
1002
|
+
check("purge helper rejects a tag short name with no branch of that name", !purgesMergedRemoteBranches("git push origin :feat/onlytag", cleanupRepo));
|
|
1003
|
+
check("on main: delete of a tag short name with no branch stays blocked", blocked(await shell("git push origin --delete feat/onlytag")));
|
|
1004
|
+
ffGit("-C", cleanupRepo, "branch", "-D", "feat/merged");
|
|
1005
|
+
check("on main: delete of a merged branch whose local ref is gone allowed", !blocked(await shell("git push origin --delete feat/merged")));
|
|
1006
|
+
// A configured protected name is protected here too, so the cleanup
|
|
1007
|
+
// exemption cannot become a way around `protectedBranches`.
|
|
1008
|
+
mkdirSync(join(cleanupRepo, ".opencode"), { recursive: true });
|
|
1009
|
+
writeFileSync(join(cleanupRepo, ".opencode", "workflow-guard.json"), JSON.stringify({ protectedBranches: ["feat/merged"] }));
|
|
1010
|
+
reloadProjectConfig(cleanupRepo);
|
|
1011
|
+
check("on main: branch -d of a configured protected branch blocked", blocked(await shell("git branch -d feat/merged")));
|
|
1012
|
+
check("on main: delete of a configured protected remote branch blocked", blocked(await shell("git push origin --delete feat/merged")));
|
|
1013
|
+
// The exemption must not become a way around the destination-side rule that
|
|
1014
|
+
// protects a configured branch from ordinary pushes.
|
|
1015
|
+
check("on main: ordinary push to a configured protected branch blocked", blocked(await shell("git push origin feat/merged")));
|
|
1016
|
+
rmSync(cleanupBase, { recursive: true, force: true });
|
|
891
1017
|
setWorkspaceRoot(repo);
|
|
892
1018
|
check("on main: git checkout path mutation blocked", blocked(await shell("git checkout -- tracked.txt")));
|
|
893
1019
|
check("on main: git checkout path mutation without separator blocked", blocked(await shell("git checkout tracked.txt")));
|
|
@@ -1842,6 +1968,20 @@ writeFileSync(timeoutArgs.filePath, "after");
|
|
|
1842
1968
|
const timeoutOutput = { title: "edit", output: "edited", metadata: {} };
|
|
1843
1969
|
await validatorAfter?.({ tool: "edit", sessionID: "s-validator", callID: "validator-4", args: timeoutArgs }, timeoutOutput);
|
|
1844
1970
|
check("post-edit validator timeout is bounded and reported", timeoutOutput.output.includes("timed out"));
|
|
1971
|
+
// A validator killed at its limit did not fail. Naming it a failure sends the
|
|
1972
|
+
// agent debugging a check that never reached an assertion, and the fix is a
|
|
1973
|
+
// longer validator timeout. Both validators match timeout.ts, so the genuine
|
|
1974
|
+
// `**/*.ts` failure appears in the same message; assert on the timed-out
|
|
1975
|
+
// validator's own line rather than on the message as a whole.
|
|
1976
|
+
const timeoutValidatorLine = timeoutOutput.output
|
|
1977
|
+
.split("\n")
|
|
1978
|
+
.find((line) => line.includes("Post-edit validator") && line.includes("setTimeout"));
|
|
1979
|
+
check(
|
|
1980
|
+
"post-edit validator timeout names the limit instead of claiming a failed check",
|
|
1981
|
+
Boolean(timeoutValidatorLine) &&
|
|
1982
|
+
timeoutValidatorLine!.includes("did not finish within 25ms") &&
|
|
1983
|
+
!timeoutValidatorLine!.includes("failed"),
|
|
1984
|
+
);
|
|
1845
1985
|
|
|
1846
1986
|
writeFileSync(join(validatorDir, "patched-a.ts"), "before");
|
|
1847
1987
|
writeFileSync(join(validatorDir, "patched-b.ts"), "before");
|
|
@@ -2669,6 +2809,24 @@ check(
|
|
|
2669
2809
|
"verification timeout names the user as the actor for a limit the agent cannot raise",
|
|
2670
2810
|
String(timeoutFinalRes).includes("Only the user can raise the limit") && String(timeoutFinalRes).includes(".jsonc"),
|
|
2671
2811
|
);
|
|
2812
|
+
// The tail is rendered by the verify engine, the reason by the dispatcher.
|
|
2813
|
+
// Two formatters meant the reason said 50ms while the tail said "after 0s",
|
|
2814
|
+
// which reads as no limit at all. One formatter, asserted at both ends.
|
|
2815
|
+
check(
|
|
2816
|
+
"a timed-out tail names the same limit at the same precision as the reason",
|
|
2817
|
+
String(timeoutFinalRes).includes("Verification timed out after 50ms") &&
|
|
2818
|
+
!String(timeoutFinalRes).includes("timed out after 0s"),
|
|
2819
|
+
);
|
|
2820
|
+
// The tail is also snipped, and the snipper used to label it "all tests
|
|
2821
|
+
// passing" because a timeout was routed down the pass branch. A killed suite
|
|
2822
|
+
// is not a passing suite, and this is the same message the agent reads. The
|
|
2823
|
+
// omission marker only appears once the snipper has more lines than its budget,
|
|
2824
|
+
// so the positive label is pinned by the snip unit check above; here the
|
|
2825
|
+
// invariant is that no claim of passing can appear on this path at all.
|
|
2826
|
+
check(
|
|
2827
|
+
"a timed-out tail never claims the killed suite passed",
|
|
2828
|
+
!String(timeoutFinalRes).includes("all tests passing"),
|
|
2829
|
+
);
|
|
2672
2830
|
// Machine consumers (audit, evidence, the V2 seat) branch on the code, not the
|
|
2673
2831
|
// prose, so pin the timeout's own code rather than only its message.
|
|
2674
2832
|
const timeoutDecision = await guardToolDecision(
|
|
@@ -3902,6 +4060,15 @@ const statusResult = await customPlugin.tool?.guard_status?.execute({}, {} as an
|
|
|
3902
4060
|
check("guard_status executes and returns JSON string", typeof statusResult === "string" && statusResult.includes("workspaceRoot"));
|
|
3903
4061
|
const parsedStatus = JSON.parse(statusResult as string);
|
|
3904
4062
|
check("guard_status exposes subject-bound evidence references", parsedStatus.lastVerify === null || (typeof parsedStatus.lastVerify.evidenceId === "string" && typeof parsedStatus.lastVerify.fresh === "boolean"));
|
|
4063
|
+
// guard_status is the machine-readable half the agent reads before finalizing.
|
|
4064
|
+
// A timed-out run must not read as a failing one there either.
|
|
4065
|
+
recordVerifyResult("npm test", { passed: false, output: "killed", durationMs: 50, timedOut: true }, undefined, root);
|
|
4066
|
+
const timeoutStatus = JSON.parse(String(await customPlugin.tool?.guard_status?.execute({}, {} as any)));
|
|
4067
|
+
check(
|
|
4068
|
+
"guard_status marks a timed-out verification as timedOut rather than a failure",
|
|
4069
|
+
timeoutStatus.lastVerify?.timedOut === true && timeoutStatus.lastVerify?.passed === false,
|
|
4070
|
+
);
|
|
4071
|
+
resetVerifyState();
|
|
3905
4072
|
check("guard_status exposes effective operation profile without TUI state", parsedStatus.projectConfig.profile === "interactive" && typeof parsedStatus.projectConfig.recoveryCheckpoints === "boolean");
|
|
3906
4073
|
check("guard_status exposes disabled-by-default Ralph accountability state", parsedStatus.ralph?.enabled === false && parsedStatus.ralph?.maxIterations === 10 && parsedStatus.ralph?.outcome === null);
|
|
3907
4074
|
check("guard_status exposes bounded outstanding requirements", Array.isArray(parsedStatus.outstandingRequirements) && parsedStatus.outstandingRequirements.every((requirement: unknown) => ["verification", "review", "documentation"].includes(String(requirement))));
|
|
@@ -5738,12 +5905,22 @@ check("read on .env file returns blocked message with masked variable schema hin
|
|
|
5738
5905
|
|
|
5739
5906
|
// Feature 2: Verification output snipping
|
|
5740
5907
|
const verbosePassingLogs = Array.from({ length: 100 }, (_, i) => `PASS: test #${i} passed successfully`).join("\n");
|
|
5741
|
-
const snippedPass = snipVerifyOutput(verbosePassingLogs,
|
|
5908
|
+
const snippedPass = snipVerifyOutput(verbosePassingLogs, "passed", 20);
|
|
5742
5909
|
check("snipVerifyOutput truncates verbose passing logs", snippedPass.includes("lines omitted") && snippedPass.split("\n").length < 30);
|
|
5743
5910
|
|
|
5744
5911
|
const verboseFailingLogs = Array.from({ length: 80 }, (_, i) => i === 40 ? "FAIL: AssertionError: expected true to be false\n at Object.<anonymous> (test.ts:42:1)" : `info log line ${i}`).join("\n");
|
|
5745
|
-
const snippedFail = snipVerifyOutput(verboseFailingLogs,
|
|
5912
|
+
const snippedFail = snipVerifyOutput(verboseFailingLogs, "failed", 20);
|
|
5746
5913
|
check("snipVerifyOutput preserves failure keywords on fail", snippedFail.includes("AssertionError") || snippedFail.includes("FAIL:"));
|
|
5914
|
+
// A run that never finished proved nothing. Snipping it as passing printed
|
|
5915
|
+
// "all tests passing" about a suite that was killed; snipping it as failing
|
|
5916
|
+
// printed a "Verification Failed" header nobody observed. Both are false
|
|
5917
|
+
// statements about the same evidence, so the third outcome is its own label.
|
|
5918
|
+
const verboseTimedOutLogs = Array.from({ length: 100 }, (_, i) => `info log line ${i}`).join("\n");
|
|
5919
|
+
const snippedTimeout = snipVerifyOutput(verboseTimedOutLogs, "unknown", 20);
|
|
5920
|
+
check(
|
|
5921
|
+
"snipVerifyOutput does not claim a timed-out run passed or failed",
|
|
5922
|
+
!snippedTimeout.includes("all tests passing") && !snippedTimeout.includes("Verification Failed") && snippedTimeout.includes("outcome unknown"),
|
|
5923
|
+
);
|
|
5747
5924
|
|
|
5748
5925
|
// Feature 3: Git snapshot & mutation counts
|
|
5749
5926
|
check("getCurrentGitCommitHash returns commit string in git repo", typeof getCurrentGitCommitHash(conflictRepo) === "string");
|
|
@@ -5768,6 +5945,26 @@ check("compaction context includes subagent session & parent attribution", compa
|
|
|
5768
5945
|
check("compaction context includes Operational Guard State header", compactText.includes("Operational Guard State"));
|
|
5769
5946
|
check("compaction context includes Git Branch status", compactText.includes("Git Branch:"));
|
|
5770
5947
|
check("compaction context includes Test Verification status", compactText.includes("Test Verification:"));
|
|
5948
|
+
// A timed-out run is not a failing run in the compacted context either. The
|
|
5949
|
+
// summary is what a post-compaction agent reads first, so "FAILED" there sends
|
|
5950
|
+
// it hunting for an assertion that never ran.
|
|
5951
|
+
recordVerifyResult("npm test", { passed: false, output: "killed", durationMs: 50, timedOut: true, timeoutMs: 50 }, "s-active");
|
|
5952
|
+
const timeoutCompactingContext: { context: string[] } = { context: [] };
|
|
5953
|
+
if (typeof compactSubagentFn === "function") {
|
|
5954
|
+
await compactSubagentFn({ sessionID: "s-active" } as any, timeoutCompactingContext as any);
|
|
5955
|
+
}
|
|
5956
|
+
const timeoutCompactText = timeoutCompactingContext.context[0] ?? "";
|
|
5957
|
+
check(
|
|
5958
|
+
"compaction context reports a timed-out verification as unknown, not failed",
|
|
5959
|
+
timeoutCompactText.includes("Test Verification: TIMED OUT") && !timeoutCompactText.includes("Test Verification: FAILED"),
|
|
5960
|
+
);
|
|
5961
|
+
// The limit travels with the outcome, so the summary names it at the precision
|
|
5962
|
+
// it was set rather than rounding a sub-second limit to "0s".
|
|
5963
|
+
check(
|
|
5964
|
+
"compaction context names the limit that was hit at its own precision",
|
|
5965
|
+
timeoutCompactText.includes("TIMED OUT within 50ms"),
|
|
5966
|
+
);
|
|
5967
|
+
recordVerifyResult("npm test", { passed: true, output: "ok" }, "s-active");
|
|
5771
5968
|
check("compaction context includes Secondary Review status", compactText.includes("Secondary Review:"));
|
|
5772
5969
|
const unrelatedCompactingContext: { context: string[] } = { context: [] };
|
|
5773
5970
|
if (typeof compactSubagentFn === "function") {
|
|
@@ -5890,6 +6087,33 @@ check("checkInteractiveTtyCommand permits npm init --yes", !checkInteractiveTtyC
|
|
|
5890
6087
|
check("checkInteractiveTtyCommand detects apt-get install without -y", checkInteractiveTtyCommand("apt-get install curl").isInteractive);
|
|
5891
6088
|
check("checkInteractiveTtyCommand permits apt-get install -y", !checkInteractiveTtyCommand("apt-get install -y curl").isInteractive);
|
|
5892
6089
|
check("checkInteractiveTtyCommand permits regular non-interactive command", !checkInteractiveTtyCommand("ls -la && git status").isInteractive);
|
|
6090
|
+
// Command position, not raw text: a pattern word in an argument is data.
|
|
6091
|
+
check("checkInteractiveTtyCommand permits sudo inside a grep pattern", !checkInteractiveTtyCommand(`grep -rn "sudo" docs/`).isInteractive);
|
|
6092
|
+
check("checkInteractiveTtyCommand permits an exact grep for sudo", !checkInteractiveTtyCommand("grep -n sudo file.txt").isInteractive);
|
|
6093
|
+
check("checkInteractiveTtyCommand permits sudo in a piped grep pattern", !checkInteractiveTtyCommand("journalctl --user -u x -n 20 --no-pager 2>&1 | grep -i sudo").isInteractive);
|
|
6094
|
+
check("checkInteractiveTtyCommand permits an interactive rebase pattern in a grep pattern", !checkInteractiveTtyCommand(`grep -n "git rebase -i" test/test.mts`).isInteractive);
|
|
6095
|
+
check("checkInteractiveTtyCommand permits npm init as grep data", !checkInteractiveTtyCommand(`grep -n "npm init" README.md`).isInteractive);
|
|
6096
|
+
check("checkInteractiveTtyCommand permits an editor name in a printf string", !checkInteractiveTtyCommand(`printf "%s\\n" "vim is not installed"`).isInteractive);
|
|
6097
|
+
check("checkInteractiveTtyCommand permits git log grep for interactive rebase", !checkInteractiveTtyCommand(`git log --grep="rebase -i"`).isInteractive);
|
|
6098
|
+
check("checkInteractiveTtyCommand permits a command name fed to a filter", !checkInteractiveTtyCommand(`echo "apt-get install curl" | cat`).isInteractive);
|
|
6099
|
+
// The same commands still block at command position.
|
|
6100
|
+
check("checkInteractiveTtyCommand still detects a chained editor", checkInteractiveTtyCommand("cd /repo && nano notes.txt").isInteractive);
|
|
6101
|
+
check("checkInteractiveTtyCommand still detects a shell -c editor", checkInteractiveTtyCommand("sh -c 'vim notes.txt'").isInteractive);
|
|
6102
|
+
check("checkInteractiveTtyCommand still detects eval npm init", checkInteractiveTtyCommand("eval 'npm init'").isInteractive);
|
|
6103
|
+
check("checkInteractiveTtyCommand still detects a wrapped sudo", checkInteractiveTtyCommand("env FOO=1 sudo ls").isInteractive);
|
|
6104
|
+
check("checkInteractiveTtyCommand still detects sudo before an editor", checkInteractiveTtyCommand("sudo vim notes.txt").isInteractive);
|
|
6105
|
+
check("checkInteractiveTtyCommand still detects a wrapped sudo before an editor", checkInteractiveTtyCommand("env A=1 sudo vim notes.txt").isInteractive);
|
|
6106
|
+
check("checkInteractiveTtyCommand still detects a timeout-wrapped sudo", checkInteractiveTtyCommand("timeout 5 sudo ls").isInteractive);
|
|
6107
|
+
check("checkInteractiveTtyCommand still detects sudo as a loop body", checkInteractiveTtyCommand("while true; do sudo ls; done").isInteractive);
|
|
6108
|
+
check("checkInteractiveTtyCommand still detects sudo after command", checkInteractiveTtyCommand("command sudo ls").isInteractive);
|
|
6109
|
+
check("checkInteractiveTtyCommand still detects git add -p", checkInteractiveTtyCommand("git add -p").isInteractive);
|
|
6110
|
+
check("checkInteractiveTtyCommand still detects yum install without -y", checkInteractiveTtyCommand("yum install curl").isInteractive);
|
|
6111
|
+
check("checkInteractiveTtyCommand still detects an apt install in a then body", checkInteractiveTtyCommand("if true; then apt-get install curl; fi").isInteractive);
|
|
6112
|
+
check("checkInteractiveTtyCommand still detects an apt install in a nested shell", checkInteractiveTtyCommand("bash -lc 'apt-get install curl'").isInteractive);
|
|
6113
|
+
check("checkInteractiveTtyCommand still detects busybox vi", checkInteractiveTtyCommand("busybox vi notes.txt").isInteractive);
|
|
6114
|
+
check("shellHasSudoWrapper reports a bare sudo", shellHasSudoWrapper("sudo ls"));
|
|
6115
|
+
check("shellHasSudoWrapper reports a sudo behind env", shellHasSudoWrapper("env FOO=1 sudo ls"));
|
|
6116
|
+
check("shellHasSudoWrapper ignores sudo as an argument", !shellHasSudoWrapper("grep -n sudo file.txt"));
|
|
5893
6117
|
|
|
5894
6118
|
check("shell tool blocks nano", blocked(await shell("nano README.md")));
|
|
5895
6119
|
check("shell tool blocks less", blocked(await shell("less package.json")));
|
|
@@ -6770,6 +6994,19 @@ recordVerifyResult("npm test", { passed: false, output: "1 failed" }, "s-claim-f
|
|
|
6770
6994
|
const failCheck = checkCompletionClaims("All tests pass.", { sessionID: "s-claim-fail" });
|
|
6771
6995
|
check("failing verification contradicts the claim", failCheck.evidenceState === "failing" && typeof failCheck.reason === "string");
|
|
6772
6996
|
|
|
6997
|
+
// A timed-out run proved nothing, so it must not be filed as a failure. The
|
|
6998
|
+
// audit trail is where this surfaces: a timeout journaled as "failing" tells a
|
|
6999
|
+
// reader an assertion broke when nothing ran to completion.
|
|
7000
|
+
resetVerifyState();
|
|
7001
|
+
recordVerifyResult("npm test", { passed: false, output: "killed", durationMs: 50, timedOut: true, timeoutMs: 50 }, "s-claim-timeout");
|
|
7002
|
+
const timeoutClaimCheck = checkCompletionClaims("All tests pass.", { sessionID: "s-claim-timeout" });
|
|
7003
|
+
check(
|
|
7004
|
+
"a timed-out verification is not filed as a failing one",
|
|
7005
|
+
timeoutClaimCheck.evidenceState === "timed-out" &&
|
|
7006
|
+
String(timeoutClaimCheck.reason).includes("did not finish within 50ms") &&
|
|
7007
|
+
!String(timeoutClaimCheck.reason).includes("FAILED"),
|
|
7008
|
+
);
|
|
7009
|
+
|
|
6773
7010
|
// Stale evidence: passing verification, then a mutation, then claim -> stale-pass
|
|
6774
7011
|
resetVerifyState();
|
|
6775
7012
|
recordVerifyResult("npm test", { passed: true, output: "ok" }, "s-claim-stale");
|
|
@@ -8155,9 +8392,43 @@ const ocJson = "open" + "code.json";
|
|
|
8155
8392
|
const ocJsonc = "open" + "code.jsonc";
|
|
8156
8393
|
setWorkspaceRoot(root);
|
|
8157
8394
|
|
|
8158
|
-
// Legacy (no live roots configured):
|
|
8159
|
-
//
|
|
8160
|
-
|
|
8395
|
+
// Legacy (no live roots configured): a copy-like verb reads its sources and
|
|
8396
|
+
// writes only its destination, so a guarded SOURCE alone is a read. This is the
|
|
8397
|
+
// F3 false positive, now allowed in both modes.
|
|
8398
|
+
const legacyCpFrom = (command: string) => call("bash", { command }, { sessionID: "s-active" });
|
|
8399
|
+
check("legacy: cp FROM a .config/opencode source is allowed without live roots", !blocked(await legacyCpFrom(`cp ${livePlane}/agent/x.md ./draft.md`)));
|
|
8400
|
+
check("legacy: cp FROM a .config/opencode source with a redirect is allowed", !blocked(await legacyCpFrom(`cp ${livePlane}/agent/x.md ./draft.md 2>/dev/null`)));
|
|
8401
|
+
check("legacy: a multi-source cp with one guarded source is allowed", !blocked(await legacyCpFrom(`cp ./notes.md ${livePlane}/agent/x.md ./draft.md`)));
|
|
8402
|
+
check("legacy: ln -s FROM a .config/opencode source is allowed", !blocked(await legacyCpFrom(`ln -s ${livePlane}/agent/x.md ./draft-link.md`)));
|
|
8403
|
+
check("legacy: cp -s FROM a .config/opencode source is allowed", !blocked(await legacyCpFrom(`cp -s ${livePlane}/agent/x.md ./draft-link.md`)));
|
|
8404
|
+
// A hard link is a second writable name for the guarded inode, so it stays a
|
|
8405
|
+
// mutation of the guarded file even when the link lands in the workspace.
|
|
8406
|
+
check("legacy: a hard link FROM a .config/opencode path is still blocked", blocked(await legacyCpFrom(`ln ${livePlane}/agent/x.md ./hard-link.md`)));
|
|
8407
|
+
check("legacy: cp -l FROM a .config/opencode path is still blocked", blocked(await legacyCpFrom(`cp -l ${livePlane}/agent/x.md ./hard-link.md`)));
|
|
8408
|
+
check("legacy: cp --link FROM a .config/opencode path is still blocked", blocked(await legacyCpFrom(`cp --link ${livePlane}/agent/x.md ./hard-link.md`)));
|
|
8409
|
+
// The true positives hold: a guarded destination is still a mutation.
|
|
8410
|
+
check("legacy: cp INTO a .config/opencode path is still blocked", blocked(await legacyCpFrom(`cp ./draft.md ${livePlane}/agent/x.md`)));
|
|
8411
|
+
check("legacy: cp with a guarded source and destination is still blocked", blocked(await legacyCpFrom(`cp ${livePlane}/agent/x.md ${livePlane}/agent/y.md`)));
|
|
8412
|
+
check("legacy: cp INTO a guarded path with a redirect is still blocked", blocked(await legacyCpFrom(`cp ./draft.md ${livePlane}/agent/x.md 2>/dev/null`)));
|
|
8413
|
+
check("legacy: cp -t a guarded directory is still blocked", blocked(await legacyCpFrom(`cp -t ${livePlane}/agent ./draft.md`)));
|
|
8414
|
+
check("legacy: cp --target-directory=a guarded directory is still blocked", blocked(await legacyCpFrom(`cp --target-directory=${livePlane}/agent ./draft.md`)));
|
|
8415
|
+
check("legacy: a multi-source cp into a guarded directory is still blocked", blocked(await legacyCpFrom(`cp ./a.md ./b.md ${livePlane}/agent`)));
|
|
8416
|
+
check("legacy: a wrapped cp into a guarded path is still blocked", blocked(await legacyCpFrom(`env FOO=1 cp ./draft.md ${livePlane}/agent/x.md`)));
|
|
8417
|
+
check("legacy: command-prefixed cp into a guarded path is still blocked", blocked(await legacyCpFrom(`command cp ./draft.md ${livePlane}/agent/x.md`)));
|
|
8418
|
+
check("legacy: fd duplication after a guarded cp destination is still blocked", blocked(await legacyCpFrom(`cp ./draft.md ${livePlane}/agent/x.md 2>&1`)));
|
|
8419
|
+
check("legacy: fd duplication before a guarded cp destination is still blocked", blocked(await legacyCpFrom(`cp ./draft.md 2>&1 ${livePlane}/agent/x.md`)));
|
|
8420
|
+
check("legacy: a discarded redirect before a guarded cp destination is still blocked", blocked(await legacyCpFrom(`cp ./draft.md >/dev/null 2>&1 ${livePlane}/agent/x.md`)));
|
|
8421
|
+
check("legacy: fd duplication does not mask a guarded redirect", blocked(await legacyCpFrom(`echo x 2>&1 > ${livePlane}/agent/x.md`)));
|
|
8422
|
+
check("legacy: fd duplication with no guarded path is allowed", !blocked(await legacyCpFrom(`cp ./draft.md ./copy.md 2>&1`)));
|
|
8423
|
+
check("legacy: ln -sfn FROM a .config/opencode source is allowed", !blocked(await legacyCpFrom(`ln -sfn ${livePlane}/agent/x.md ./draft-link.md`)));
|
|
8424
|
+
check("legacy: install -d -t a guarded directory is still blocked", blocked(await legacyCpFrom(`install -d -t ${livePlane}/plugins ./build`)));
|
|
8425
|
+
check("legacy: ln INTO a .config/opencode path is still blocked", blocked(await legacyCpFrom(`ln -s ./draft-link.md ${livePlane}/agent/x.md`)));
|
|
8426
|
+
check("legacy: install -d a guarded directory is still blocked", blocked(await legacyCpFrom(`install -d ${livePlane}/plugins`)));
|
|
8427
|
+
check("legacy: install -d a workspace directory is allowed", !blocked(await legacyCpFrom(`install -d ./build/out`)));
|
|
8428
|
+
// mv removes its source, so a guarded source stays a mutation.
|
|
8429
|
+
check("legacy: mv FROM a .config/opencode path is still blocked", blocked(await legacyCpFrom(`mv ${livePlane}/agent/x.md ./draft.md`)));
|
|
8430
|
+
check("legacy: tee INTO a .config/opencode path is still blocked", blocked(await legacyCpFrom(`echo x | tee ${livePlane}/agent/x.md`)));
|
|
8431
|
+
check("legacy: a redirect INTO a .config/opencode path is still blocked", blocked(await legacyCpFrom(`echo x > ${livePlane}/agent/x.md`)));
|
|
8161
8432
|
|
|
8162
8433
|
// Declare the live control plane via project config, then reload.
|
|
8163
8434
|
writeFileSync(join(lcpRoot, ".opencode", "workflow-guard.json"), JSON.stringify({ liveControlPlanePaths: [livePlane] }));
|