@duckmind/dm-darwin-x64 0.43.4 → 0.43.8
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/dm +0 -0
- package/extensions/.dm-extensions.json +241 -49
- package/extensions/dm-9router-ext/package.json +2 -19
- package/extensions/dm-9router-ext/src/index.js +5 -0
- package/extensions/dm-ask-user/index.js +10 -0
- package/extensions/dm-ask-user/package.json +1 -21
- package/extensions/dm-cli-anything/package.json +0 -6
- package/extensions/dm-context/package.json +2 -12
- package/extensions/dm-context/src/context.js +1 -0
- package/extensions/dm-context/src/index.js +7 -0
- package/extensions/dm-context/src/utils.js +1 -0
- package/extensions/dm-cua/package.json +0 -7
- package/extensions/dm-fff/package.json +1 -28
- package/extensions/dm-fff/src/index.js +15 -0
- package/extensions/dm-fff/src/query.js +1 -0
- package/extensions/dm-goal/package.json +2 -31
- package/extensions/dm-goal/src/goal.js +43 -0
- package/extensions/dm-grill-me/index.js +174 -0
- package/extensions/dm-grill-me/package.json +1 -26
- package/extensions/dm-image2/package.json +0 -7
- package/extensions/dm-subagents/package.json +1 -32
- package/extensions/dm-subagents/src/agents/agent-management.js +37 -0
- package/extensions/dm-subagents/src/agents/agent-memory.js +6 -0
- package/extensions/dm-subagents/src/agents/agent-scope.js +1 -0
- package/extensions/dm-subagents/src/agents/agent-selection.js +1 -0
- package/extensions/dm-subagents/src/agents/agent-serializer.js +7 -0
- package/extensions/dm-subagents/src/agents/agents.js +11 -0
- package/extensions/dm-subagents/src/agents/chain-serializer.js +12 -0
- package/extensions/dm-subagents/src/agents/frontmatter.js +6 -0
- package/extensions/dm-subagents/src/agents/identity.js +1 -0
- package/extensions/dm-subagents/src/agents/proactive-skills.js +1 -0
- package/extensions/dm-subagents/src/agents/skills.js +6 -0
- package/extensions/dm-subagents/src/extension/config.js +2 -0
- package/extensions/dm-subagents/src/extension/control-notices.js +4 -0
- package/extensions/dm-subagents/src/extension/doctor.js +16 -0
- package/extensions/dm-subagents/src/extension/fanout-child.js +231 -0
- package/extensions/dm-subagents/src/extension/index.js +367 -0
- package/extensions/dm-subagents/src/extension/rpc.js +8 -0
- package/extensions/dm-subagents/src/extension/schemas.js +1 -0
- package/extensions/dm-subagents/src/extension/{tool-description.ts → tool-description.js} +6 -126
- package/extensions/dm-subagents/src/intercom/intercom-bridge.js +13 -0
- package/extensions/dm-subagents/src/intercom/native-supervisor-channel.js +5 -0
- package/extensions/dm-subagents/src/intercom/result-intercom.js +3 -0
- package/extensions/dm-subagents/src/profiles/profiles.js +3 -0
- package/extensions/dm-subagents/src/runs/background/async-execution.js +46 -0
- package/extensions/dm-subagents/src/runs/background/async-job-tracker.js +14 -0
- package/extensions/dm-subagents/src/runs/background/async-resume.js +8 -0
- package/extensions/dm-subagents/src/runs/background/async-status.js +12 -0
- package/extensions/dm-subagents/src/runs/background/chain-append.js +2 -0
- package/extensions/dm-subagents/src/runs/background/chain-root-attachment.js +1 -0
- package/extensions/dm-subagents/src/runs/background/completion-batcher.js +1 -0
- package/extensions/dm-subagents/src/runs/background/completion-dedupe.js +1 -0
- package/extensions/dm-subagents/src/runs/background/control-channel.js +1 -0
- package/extensions/dm-subagents/src/runs/background/fleet-view.js +17 -0
- package/extensions/dm-subagents/src/runs/background/notify.js +3 -0
- package/extensions/dm-subagents/src/runs/background/parallel-groups.js +1 -0
- package/extensions/dm-subagents/src/runs/background/result-watcher.js +8 -0
- package/extensions/dm-subagents/src/runs/background/run-id-resolver.js +4 -0
- package/extensions/dm-subagents/src/runs/background/run-status.js +23 -0
- package/extensions/dm-subagents/src/runs/background/scheduled-runs.js +4 -0
- package/extensions/dm-subagents/src/runs/background/stale-run-reconciler.js +11 -0
- package/extensions/dm-subagents/src/runs/background/subagent-runner.js +78 -0
- package/extensions/dm-subagents/src/runs/background/top-level-async.js +1 -0
- package/extensions/dm-subagents/src/runs/background/wait.js +11 -0
- package/extensions/dm-subagents/src/runs/foreground/chain-clarify.js +12 -0
- package/extensions/dm-subagents/src/runs/foreground/chain-execution.js +102 -0
- package/extensions/dm-subagents/src/runs/foreground/execution.js +51 -0
- package/extensions/dm-subagents/src/runs/foreground/subagent-executor.js +228 -0
- package/extensions/dm-subagents/src/runs/shared/acceptance.js +3 -0
- package/extensions/dm-subagents/src/runs/shared/chain-outputs.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/completion-guard.js +3 -0
- package/extensions/dm-subagents/src/runs/shared/dm-args.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/dm-spawn.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/dynamic-fanout.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/long-running-guard.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/mcp-direct-tool-allowlist.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/model-fallback.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/model-scope.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/nested-events.js +8 -0
- package/extensions/dm-subagents/src/runs/shared/nested-path.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/nested-render.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/parallel-utils.js +5 -0
- package/extensions/dm-subagents/src/runs/shared/run-history.js +5 -0
- package/extensions/dm-subagents/src/runs/shared/single-output.js +14 -0
- package/extensions/dm-subagents/src/runs/shared/structured-output.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/subagent-control.js +5 -0
- package/extensions/dm-subagents/src/runs/shared/subagent-prompt-runtime.js +22 -0
- package/extensions/dm-subagents/src/runs/shared/tool-budget.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/turn-budget.js +7 -0
- package/extensions/dm-subagents/src/runs/shared/workflow-graph.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/worktree.js +3 -0
- package/extensions/dm-subagents/src/shared/artifacts.js +2 -0
- package/extensions/dm-subagents/src/shared/atomic-json.js +1 -0
- package/extensions/dm-subagents/src/shared/child-transcript.js +5 -0
- package/extensions/dm-subagents/src/shared/file-coalescer.js +1 -0
- package/extensions/dm-subagents/src/shared/fork-context.js +6 -0
- package/extensions/dm-subagents/src/shared/formatters.js +9 -0
- package/extensions/dm-subagents/src/shared/jsonl-writer.js +2 -0
- package/extensions/dm-subagents/src/shared/model-info.js +1 -0
- package/extensions/dm-subagents/src/shared/post-exit-stdio-guard.js +1 -0
- package/extensions/dm-subagents/src/shared/session-identity.js +1 -0
- package/extensions/dm-subagents/src/shared/session-tokens.js +2 -0
- package/extensions/dm-subagents/src/shared/settings.js +23 -0
- package/extensions/dm-subagents/src/shared/status-format.js +1 -0
- package/extensions/dm-subagents/src/shared/types.js +8 -0
- package/extensions/dm-subagents/src/shared/utils.js +2 -0
- package/extensions/dm-subagents/src/slash/prompt-template-bridge.js +1 -0
- package/extensions/dm-subagents/src/slash/prompt-workflows.js +7 -0
- package/extensions/dm-subagents/src/slash/slash-bridge.js +1 -0
- package/extensions/dm-subagents/src/slash/slash-commands.js +38 -0
- package/extensions/dm-subagents/src/slash/slash-live-state.js +6 -0
- package/extensions/dm-subagents/src/tui/render-helpers.js +1 -0
- package/extensions/dm-subagents/src/tui/render.js +4 -0
- package/extensions/dm-tasks/package.json +1 -30
- package/extensions/dm-tasks/src/auto-clear.js +1 -0
- package/extensions/dm-tasks/src/index.js +212 -0
- package/extensions/dm-tasks/src/process-tracker.js +1 -0
- package/extensions/dm-tasks/src/task-store.js +1 -0
- package/extensions/dm-tasks/src/tasks-config.js +1 -0
- package/extensions/dm-tasks/src/types.js +0 -0
- package/extensions/dm-tasks/src/ui/settings-menu.js +1 -0
- package/extensions/dm-tasks/src/ui/task-widget.js +1 -0
- package/extensions/dm-usage/index.js +9 -0
- package/extensions/dm-usage/package.json +1 -18
- package/extensions/greedysearch-dm/index.js +20 -0
- package/extensions/greedysearch-dm/package.json +1 -22
- package/extensions/greedysearch-dm/src/formatters/results.js +8 -0
- package/extensions/greedysearch-dm/src/formatters/sources.js +1 -0
- package/extensions/greedysearch-dm/src/formatters/synthesis.js +1 -0
- package/extensions/greedysearch-dm/src/tools/greedy-search-handler.js +20 -0
- package/extensions/greedysearch-dm/src/tools/shared.js +9 -0
- package/extensions/greedysearch-dm/src/types.js +0 -0
- package/extensions/greedysearch-dm/src/utils/helpers.js +1 -0
- package/package.json +1 -1
- package/extensions/dm-9router-ext/src/index.ts +0 -541
- package/extensions/dm-ask-user/index.ts +0 -857
- package/extensions/dm-context/src/context.ts +0 -158
- package/extensions/dm-context/src/index.ts +0 -439
- package/extensions/dm-context/src/utils.ts +0 -6
- package/extensions/dm-fff/src/index.ts +0 -1023
- package/extensions/dm-fff/src/query.ts +0 -87
- package/extensions/dm-goal/src/goal.ts +0 -1073
- package/extensions/dm-grill-me/index.ts +0 -1085
- package/extensions/dm-subagents/src/agents/agent-management.ts +0 -1052
- package/extensions/dm-subagents/src/agents/agent-memory.ts +0 -254
- package/extensions/dm-subagents/src/agents/agent-scope.ts +0 -6
- package/extensions/dm-subagents/src/agents/agent-selection.ts +0 -25
- package/extensions/dm-subagents/src/agents/agent-serializer.ts +0 -121
- package/extensions/dm-subagents/src/agents/agents.ts +0 -1553
- package/extensions/dm-subagents/src/agents/chain-serializer.ts +0 -277
- package/extensions/dm-subagents/src/agents/frontmatter.ts +0 -93
- package/extensions/dm-subagents/src/agents/identity.ts +0 -30
- package/extensions/dm-subagents/src/agents/proactive-skills.ts +0 -191
- package/extensions/dm-subagents/src/agents/skills.ts +0 -729
- package/extensions/dm-subagents/src/extension/config.ts +0 -39
- package/extensions/dm-subagents/src/extension/control-notices.ts +0 -92
- package/extensions/dm-subagents/src/extension/doctor.ts +0 -214
- package/extensions/dm-subagents/src/extension/fanout-child.ts +0 -172
- package/extensions/dm-subagents/src/extension/index.ts +0 -656
- package/extensions/dm-subagents/src/extension/rpc.ts +0 -369
- package/extensions/dm-subagents/src/extension/schemas.ts +0 -309
- package/extensions/dm-subagents/src/intercom/intercom-bridge.ts +0 -180
- package/extensions/dm-subagents/src/intercom/native-supervisor-channel.ts +0 -519
- package/extensions/dm-subagents/src/intercom/result-intercom.ts +0 -377
- package/extensions/dm-subagents/src/profiles/profiles.ts +0 -637
- package/extensions/dm-subagents/src/runs/background/async-execution.ts +0 -1065
- package/extensions/dm-subagents/src/runs/background/async-job-tracker.ts +0 -441
- package/extensions/dm-subagents/src/runs/background/async-resume.ts +0 -391
- package/extensions/dm-subagents/src/runs/background/async-status.ts +0 -395
- package/extensions/dm-subagents/src/runs/background/chain-append.ts +0 -282
- package/extensions/dm-subagents/src/runs/background/chain-root-attachment.ts +0 -191
- package/extensions/dm-subagents/src/runs/background/completion-batcher.ts +0 -166
- package/extensions/dm-subagents/src/runs/background/completion-dedupe.ts +0 -63
- package/extensions/dm-subagents/src/runs/background/control-channel.ts +0 -332
- package/extensions/dm-subagents/src/runs/background/fleet-view.ts +0 -515
- package/extensions/dm-subagents/src/runs/background/notify.ts +0 -225
- package/extensions/dm-subagents/src/runs/background/parallel-groups.ts +0 -45
- package/extensions/dm-subagents/src/runs/background/result-watcher.ts +0 -315
- package/extensions/dm-subagents/src/runs/background/run-id-resolver.ts +0 -84
- package/extensions/dm-subagents/src/runs/background/run-status.ts +0 -434
- package/extensions/dm-subagents/src/runs/background/scheduled-runs.ts +0 -514
- package/extensions/dm-subagents/src/runs/background/stale-run-reconciler.ts +0 -368
- package/extensions/dm-subagents/src/runs/background/subagent-runner.ts +0 -3171
- package/extensions/dm-subagents/src/runs/background/top-level-async.ts +0 -13
- package/extensions/dm-subagents/src/runs/background/wait.ts +0 -353
- package/extensions/dm-subagents/src/runs/foreground/chain-clarify.ts +0 -1333
- package/extensions/dm-subagents/src/runs/foreground/chain-execution.ts +0 -1313
- package/extensions/dm-subagents/src/runs/foreground/execution.ts +0 -1239
- package/extensions/dm-subagents/src/runs/foreground/subagent-executor.ts +0 -3613
- package/extensions/dm-subagents/src/runs/shared/acceptance.ts +0 -879
- package/extensions/dm-subagents/src/runs/shared/chain-outputs.ts +0 -116
- package/extensions/dm-subagents/src/runs/shared/completion-guard.ts +0 -147
- package/extensions/dm-subagents/src/runs/shared/dm-args.ts +0 -271
- package/extensions/dm-subagents/src/runs/shared/dm-spawn.ts +0 -147
- package/extensions/dm-subagents/src/runs/shared/dynamic-fanout.ts +0 -295
- package/extensions/dm-subagents/src/runs/shared/long-running-guard.ts +0 -175
- package/extensions/dm-subagents/src/runs/shared/mcp-direct-tool-allowlist.ts +0 -365
- package/extensions/dm-subagents/src/runs/shared/model-fallback.ts +0 -292
- package/extensions/dm-subagents/src/runs/shared/model-scope.ts +0 -128
- package/extensions/dm-subagents/src/runs/shared/nested-events.ts +0 -908
- package/extensions/dm-subagents/src/runs/shared/nested-path.ts +0 -52
- package/extensions/dm-subagents/src/runs/shared/nested-render.ts +0 -115
- package/extensions/dm-subagents/src/runs/shared/parallel-utils.ts +0 -198
- package/extensions/dm-subagents/src/runs/shared/run-history.ts +0 -60
- package/extensions/dm-subagents/src/runs/shared/single-output.ts +0 -180
- package/extensions/dm-subagents/src/runs/shared/structured-output.ts +0 -77
- package/extensions/dm-subagents/src/runs/shared/subagent-control.ts +0 -223
- package/extensions/dm-subagents/src/runs/shared/subagent-prompt-runtime.ts +0 -342
- package/extensions/dm-subagents/src/runs/shared/tool-budget.ts +0 -74
- package/extensions/dm-subagents/src/runs/shared/turn-budget.ts +0 -52
- package/extensions/dm-subagents/src/runs/shared/workflow-graph.ts +0 -206
- package/extensions/dm-subagents/src/runs/shared/worktree.ts +0 -600
- package/extensions/dm-subagents/src/shared/artifacts.ts +0 -113
- package/extensions/dm-subagents/src/shared/atomic-json.ts +0 -86
- package/extensions/dm-subagents/src/shared/child-transcript.ts +0 -212
- package/extensions/dm-subagents/src/shared/file-coalescer.ts +0 -40
- package/extensions/dm-subagents/src/shared/fork-context.ts +0 -194
- package/extensions/dm-subagents/src/shared/formatters.ts +0 -133
- package/extensions/dm-subagents/src/shared/jsonl-writer.ts +0 -81
- package/extensions/dm-subagents/src/shared/model-info.ts +0 -78
- package/extensions/dm-subagents/src/shared/post-exit-stdio-guard.ts +0 -85
- package/extensions/dm-subagents/src/shared/session-identity.ts +0 -10
- package/extensions/dm-subagents/src/shared/session-tokens.ts +0 -44
- package/extensions/dm-subagents/src/shared/settings.ts +0 -450
- package/extensions/dm-subagents/src/shared/status-format.ts +0 -49
- package/extensions/dm-subagents/src/shared/types.ts +0 -1257
- package/extensions/dm-subagents/src/shared/utils.ts +0 -554
- package/extensions/dm-subagents/src/slash/prompt-template-bridge.ts +0 -420
- package/extensions/dm-subagents/src/slash/prompt-workflows.ts +0 -330
- package/extensions/dm-subagents/src/slash/slash-bridge.ts +0 -176
- package/extensions/dm-subagents/src/slash/slash-commands.ts +0 -1296
- package/extensions/dm-subagents/src/slash/slash-live-state.ts +0 -292
- package/extensions/dm-subagents/src/tui/render-helpers.ts +0 -80
- package/extensions/dm-subagents/src/tui/render.ts +0 -1748
- package/extensions/dm-tasks/src/auto-clear.ts +0 -91
- package/extensions/dm-tasks/src/index.ts +0 -1145
- package/extensions/dm-tasks/src/process-tracker.ts +0 -140
- package/extensions/dm-tasks/src/task-store.ts +0 -305
- package/extensions/dm-tasks/src/tasks-config.ts +0 -23
- package/extensions/dm-tasks/src/types.ts +0 -40
- package/extensions/dm-tasks/src/ui/settings-menu.ts +0 -100
- package/extensions/dm-tasks/src/ui/task-widget.ts +0 -265
- package/extensions/dm-usage/index.ts +0 -1718
- package/extensions/greedysearch-dm/index.ts +0 -177
- package/extensions/greedysearch-dm/src/formatters/results.ts +0 -163
- package/extensions/greedysearch-dm/src/formatters/sources.ts +0 -116
- package/extensions/greedysearch-dm/src/formatters/synthesis.ts +0 -87
- package/extensions/greedysearch-dm/src/tools/greedy-search-handler.ts +0 -370
- package/extensions/greedysearch-dm/src/tools/shared.ts +0 -187
- package/extensions/greedysearch-dm/src/types.ts +0 -110
- package/extensions/greedysearch-dm/src/utils/helpers.ts +0 -40
|
@@ -1,879 +0,0 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
2
|
-
import { spawnSync } from "node:child_process";
|
|
3
|
-
import * as fs from "node:fs";
|
|
4
|
-
import * as path from "node:path";
|
|
5
|
-
import type {
|
|
6
|
-
AcceptanceConfig,
|
|
7
|
-
AcceptanceEvidenceKind,
|
|
8
|
-
AcceptanceInput,
|
|
9
|
-
AcceptanceLedger,
|
|
10
|
-
AcceptanceLevel,
|
|
11
|
-
AcceptanceReport,
|
|
12
|
-
AcceptanceRuntimeCheck,
|
|
13
|
-
AcceptanceReviewResult,
|
|
14
|
-
AcceptanceVerifyCommand,
|
|
15
|
-
AcceptanceVerifyResult,
|
|
16
|
-
ResolvedAcceptanceConfig,
|
|
17
|
-
ResolvedAcceptanceGate,
|
|
18
|
-
SingleResult,
|
|
19
|
-
SubagentRunMode,
|
|
20
|
-
} from "../../shared/types.ts";
|
|
21
|
-
|
|
22
|
-
const LEVEL_RANK: Record<Exclude<AcceptanceLevel, "auto">, number> = {
|
|
23
|
-
none: 0,
|
|
24
|
-
attested: 1,
|
|
25
|
-
checked: 2,
|
|
26
|
-
verified: 3,
|
|
27
|
-
reviewed: 4,
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const VALID_LEVELS = new Set<AcceptanceLevel>(["auto", "none", "attested", "checked", "verified", "reviewed"]);
|
|
31
|
-
const VALID_EVIDENCE = new Set<AcceptanceEvidenceKind>([
|
|
32
|
-
"changed-files",
|
|
33
|
-
"tests-added",
|
|
34
|
-
"commands-run",
|
|
35
|
-
"validation-output",
|
|
36
|
-
"residual-risks",
|
|
37
|
-
"no-staged-files",
|
|
38
|
-
"diff-summary",
|
|
39
|
-
"review-findings",
|
|
40
|
-
"manual-notes",
|
|
41
|
-
]);
|
|
42
|
-
const ACCEPTANCE_CONFIG_KEYS = new Set(["level", "criteria", "evidence", "verify", "review", "stopRules", "reason"]);
|
|
43
|
-
const ACCEPTANCE_GATE_KEYS = new Set(["id", "must", "evidence", "severity"]);
|
|
44
|
-
const ACCEPTANCE_VERIFY_KEYS = new Set(["id", "command", "timeoutMs", "cwd", "env", "allowFailure"]);
|
|
45
|
-
const ACCEPTANCE_REVIEW_KEYS = new Set(["agent", "focus", "required"]);
|
|
46
|
-
|
|
47
|
-
function normalizeLevel(level: AcceptanceLevel | undefined): Exclude<AcceptanceLevel, "auto"> | "auto" {
|
|
48
|
-
return level ?? "auto";
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function unique<T>(items: T[]): T[] {
|
|
52
|
-
return [...new Set(items)];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function requiredEvidenceForLevel(level: Exclude<AcceptanceLevel, "auto">): AcceptanceEvidenceKind[] {
|
|
56
|
-
switch (level) {
|
|
57
|
-
case "none":
|
|
58
|
-
return [];
|
|
59
|
-
case "attested":
|
|
60
|
-
return ["manual-notes", "residual-risks"];
|
|
61
|
-
case "checked":
|
|
62
|
-
return ["changed-files", "tests-added", "commands-run", "residual-risks", "no-staged-files"];
|
|
63
|
-
case "verified":
|
|
64
|
-
case "reviewed":
|
|
65
|
-
return ["changed-files", "tests-added", "commands-run", "validation-output", "residual-risks", "no-staged-files"];
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function inferLevel(input: {
|
|
70
|
-
agentName: string;
|
|
71
|
-
task?: string;
|
|
72
|
-
mode?: SubagentRunMode;
|
|
73
|
-
async?: boolean;
|
|
74
|
-
dynamic?: boolean;
|
|
75
|
-
dynamicGroup?: boolean;
|
|
76
|
-
}): { level: Exclude<AcceptanceLevel, "auto">; reasons: string[]; criteria: string[]; evidence: AcceptanceEvidenceKind[]; review?: { agent?: string; required?: boolean } } {
|
|
77
|
-
const agent = input.agentName.toLowerCase();
|
|
78
|
-
const task = input.task?.toLowerCase() ?? "";
|
|
79
|
-
const reasons: string[] = [];
|
|
80
|
-
const readOnlyAgent = /\b(?:reviewer|scout|context-builder|researcher|analyst)\b/.test(agent);
|
|
81
|
-
const readOnlyTask = /\b(?:read[- ]only|review[- ]only|do not edit|don't edit|no edits|without edits|inspect|summari[sz]e)\b/.test(task);
|
|
82
|
-
const writeTask = /\b(?:fix|implement|update|write|edit|modify|migrate|release|security|delete|remove|refactor|commit)\b/.test(task)
|
|
83
|
-
|| /\bworker\b/.test(agent);
|
|
84
|
-
const risky = Boolean(input.async && writeTask)
|
|
85
|
-
|| Boolean(input.dynamic)
|
|
86
|
-
|| Boolean(input.dynamicGroup)
|
|
87
|
-
|| /\b(?:release|migration|migrate|security|data[- ]loss|destructive|post-review|fix pass)\b/.test(task);
|
|
88
|
-
|
|
89
|
-
if (risky) {
|
|
90
|
-
reasons.push(input.async ? "async write-capable or risky run" : "risky write-capable run");
|
|
91
|
-
if (input.dynamic || input.dynamicGroup) reasons.push("dynamic fanout context");
|
|
92
|
-
return {
|
|
93
|
-
level: "reviewed",
|
|
94
|
-
reasons,
|
|
95
|
-
criteria: ["Implement the requested change without widening scope", "Return evidence sufficient for an independent acceptance review"],
|
|
96
|
-
evidence: requiredEvidenceForLevel("reviewed"),
|
|
97
|
-
review: { agent: "reviewer", required: true },
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
if (writeTask && !readOnlyTask) {
|
|
101
|
-
reasons.push("write-capable worker/task");
|
|
102
|
-
return {
|
|
103
|
-
level: "checked",
|
|
104
|
-
reasons,
|
|
105
|
-
criteria: ["Implement the requested change without widening scope"],
|
|
106
|
-
evidence: requiredEvidenceForLevel("checked"),
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
if (readOnlyAgent || readOnlyTask) {
|
|
110
|
-
reasons.push(readOnlyAgent ? "read-only/reviewer-style agent" : "read-only task wording");
|
|
111
|
-
return {
|
|
112
|
-
level: "attested",
|
|
113
|
-
reasons,
|
|
114
|
-
criteria: ["Return concrete findings with file paths and severity when applicable"],
|
|
115
|
-
evidence: ["review-findings", "residual-risks"],
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
reasons.push("default lightweight attestation");
|
|
119
|
-
return {
|
|
120
|
-
level: "attested",
|
|
121
|
-
reasons,
|
|
122
|
-
criteria: ["Return a concise result and residual risks when applicable"],
|
|
123
|
-
evidence: ["manual-notes", "residual-risks"],
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export function normalizeAcceptanceInput(input: AcceptanceInput | undefined): AcceptanceConfig {
|
|
128
|
-
if (input === undefined || input === "auto") return { level: "auto" };
|
|
129
|
-
if (input === false) return { level: "none", reason: "disabled by deprecated false shorthand" };
|
|
130
|
-
if (typeof input === "string") return { level: input };
|
|
131
|
-
return { ...input };
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function explicitAcceptanceCanDisable(explicit: AcceptanceConfig): boolean {
|
|
135
|
-
return explicit.level === "none" && typeof explicit.reason === "string" && explicit.reason.trim().length > 0;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export function validateAcceptanceInput(input: unknown, pathLabel = "acceptance"): string[] {
|
|
139
|
-
const errors: string[] = [];
|
|
140
|
-
if (input === undefined) return errors;
|
|
141
|
-
if (input === false) return errors;
|
|
142
|
-
if (typeof input === "string") {
|
|
143
|
-
if (!VALID_LEVELS.has(input as AcceptanceLevel)) errors.push(`${pathLabel} has invalid level '${input}'.`);
|
|
144
|
-
return errors;
|
|
145
|
-
}
|
|
146
|
-
if (!input || typeof input !== "object" || Array.isArray(input)) {
|
|
147
|
-
errors.push(`${pathLabel} must be a string level, false, or an object.`);
|
|
148
|
-
return errors;
|
|
149
|
-
}
|
|
150
|
-
const value = input as Record<string, unknown>;
|
|
151
|
-
for (const key of Object.keys(value)) {
|
|
152
|
-
if (!ACCEPTANCE_CONFIG_KEYS.has(key)) errors.push(`${pathLabel}.${key} is not supported.`);
|
|
153
|
-
}
|
|
154
|
-
if (value.level !== undefined && (typeof value.level !== "string" || !VALID_LEVELS.has(value.level as AcceptanceLevel))) {
|
|
155
|
-
errors.push(`${pathLabel}.level must be one of auto, none, attested, checked, verified, reviewed.`);
|
|
156
|
-
}
|
|
157
|
-
if (value.level === "none" && (typeof value.reason !== "string" || !value.reason.trim())) {
|
|
158
|
-
errors.push(`${pathLabel}.reason is required when level is none.`);
|
|
159
|
-
}
|
|
160
|
-
if (value.reason !== undefined && typeof value.reason !== "string") errors.push(`${pathLabel}.reason must be a string.`);
|
|
161
|
-
if (value.criteria !== undefined && !Array.isArray(value.criteria)) errors.push(`${pathLabel}.criteria must be an array.`);
|
|
162
|
-
if (Array.isArray(value.criteria)) {
|
|
163
|
-
for (const [index, criterion] of value.criteria.entries()) {
|
|
164
|
-
if (typeof criterion === "string") continue;
|
|
165
|
-
const criterionPath = `${pathLabel}.criteria[${index}]`;
|
|
166
|
-
if (!criterion || typeof criterion !== "object" || Array.isArray(criterion)) {
|
|
167
|
-
errors.push(`${criterionPath} must be a string or an object.`);
|
|
168
|
-
continue;
|
|
169
|
-
}
|
|
170
|
-
const gate = criterion as Record<string, unknown>;
|
|
171
|
-
for (const key of Object.keys(gate)) {
|
|
172
|
-
if (!ACCEPTANCE_GATE_KEYS.has(key)) errors.push(`${criterionPath}.${key} is not supported.`);
|
|
173
|
-
}
|
|
174
|
-
if (typeof gate.id !== "string" || !gate.id.trim()) errors.push(`${criterionPath}.id is required.`);
|
|
175
|
-
if (typeof gate.must !== "string" || !gate.must.trim()) errors.push(`${criterionPath}.must is required.`);
|
|
176
|
-
if (gate.evidence !== undefined && !Array.isArray(gate.evidence)) errors.push(`${criterionPath}.evidence must be an array.`);
|
|
177
|
-
if (Array.isArray(gate.evidence)) {
|
|
178
|
-
for (const [evidenceIndex, item] of gate.evidence.entries()) {
|
|
179
|
-
if (typeof item !== "string" || !VALID_EVIDENCE.has(item as AcceptanceEvidenceKind)) {
|
|
180
|
-
errors.push(`${criterionPath}.evidence[${evidenceIndex}] is not a supported evidence kind.`);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
if (gate.severity !== undefined && gate.severity !== "required" && gate.severity !== "recommended") {
|
|
185
|
-
errors.push(`${criterionPath}.severity must be required or recommended.`);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
if (Array.isArray(value.evidence)) {
|
|
190
|
-
for (const [index, item] of value.evidence.entries()) {
|
|
191
|
-
if (typeof item !== "string" || !VALID_EVIDENCE.has(item as AcceptanceEvidenceKind)) {
|
|
192
|
-
errors.push(`${pathLabel}.evidence[${index}] is not a supported evidence kind.`);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
} else if (value.evidence !== undefined) {
|
|
196
|
-
errors.push(`${pathLabel}.evidence must be an array.`);
|
|
197
|
-
}
|
|
198
|
-
if (value.verify !== undefined && !Array.isArray(value.verify)) errors.push(`${pathLabel}.verify must be an array.`);
|
|
199
|
-
if (Array.isArray(value.verify)) {
|
|
200
|
-
for (const [index, command] of value.verify.entries()) {
|
|
201
|
-
if (!command || typeof command !== "object" || Array.isArray(command)) {
|
|
202
|
-
errors.push(`${pathLabel}.verify[${index}] must be an object.`);
|
|
203
|
-
continue;
|
|
204
|
-
}
|
|
205
|
-
const cmd = command as Record<string, unknown>;
|
|
206
|
-
for (const key of Object.keys(cmd)) {
|
|
207
|
-
if (!ACCEPTANCE_VERIFY_KEYS.has(key)) errors.push(`${pathLabel}.verify[${index}].${key} is not supported.`);
|
|
208
|
-
}
|
|
209
|
-
if (typeof cmd.id !== "string" || !cmd.id.trim()) errors.push(`${pathLabel}.verify[${index}].id is required.`);
|
|
210
|
-
if (typeof cmd.command !== "string" || !cmd.command.trim()) errors.push(`${pathLabel}.verify[${index}].command is required.`);
|
|
211
|
-
if (cmd.timeoutMs !== undefined && (typeof cmd.timeoutMs !== "number" || !Number.isInteger(cmd.timeoutMs) || cmd.timeoutMs < 1)) {
|
|
212
|
-
errors.push(`${pathLabel}.verify[${index}].timeoutMs must be an integer >= 1.`);
|
|
213
|
-
}
|
|
214
|
-
if (cmd.cwd !== undefined && typeof cmd.cwd !== "string") errors.push(`${pathLabel}.verify[${index}].cwd must be a string.`);
|
|
215
|
-
if (cmd.env !== undefined) {
|
|
216
|
-
if (!cmd.env || typeof cmd.env !== "object" || Array.isArray(cmd.env)) {
|
|
217
|
-
errors.push(`${pathLabel}.verify[${index}].env must be an object.`);
|
|
218
|
-
} else {
|
|
219
|
-
for (const [envKey, envValue] of Object.entries(cmd.env as Record<string, unknown>)) {
|
|
220
|
-
if (typeof envValue !== "string") errors.push(`${pathLabel}.verify[${index}].env.${envKey} must be a string.`);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
if (cmd.allowFailure !== undefined && typeof cmd.allowFailure !== "boolean") {
|
|
225
|
-
errors.push(`${pathLabel}.verify[${index}].allowFailure must be a boolean.`);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
if (value.review !== undefined && value.review !== false) {
|
|
230
|
-
if (!value.review || typeof value.review !== "object" || Array.isArray(value.review)) {
|
|
231
|
-
errors.push(`${pathLabel}.review must be false or an object.`);
|
|
232
|
-
} else {
|
|
233
|
-
const review = value.review as Record<string, unknown>;
|
|
234
|
-
for (const key of Object.keys(review)) {
|
|
235
|
-
if (!ACCEPTANCE_REVIEW_KEYS.has(key)) errors.push(`${pathLabel}.review.${key} is not supported.`);
|
|
236
|
-
}
|
|
237
|
-
if (review.agent !== undefined && typeof review.agent !== "string") errors.push(`${pathLabel}.review.agent must be a string.`);
|
|
238
|
-
if (review.focus !== undefined && typeof review.focus !== "string") errors.push(`${pathLabel}.review.focus must be a string.`);
|
|
239
|
-
if (review.required !== undefined && typeof review.required !== "boolean") errors.push(`${pathLabel}.review.required must be a boolean.`);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
if (value.stopRules !== undefined && !Array.isArray(value.stopRules)) errors.push(`${pathLabel}.stopRules must be an array.`);
|
|
243
|
-
if (Array.isArray(value.stopRules)) {
|
|
244
|
-
for (const [index, item] of value.stopRules.entries()) {
|
|
245
|
-
if (typeof item !== "string") errors.push(`${pathLabel}.stopRules[${index}] must be a string.`);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
return errors;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
function normalizeCriteria(criteria: Array<string | { id?: string; must?: string; evidence?: AcceptanceEvidenceKind[]; severity?: "required" | "recommended" }> | undefined, evidence: AcceptanceEvidenceKind[]): ResolvedAcceptanceGate[] {
|
|
252
|
-
return (criteria ?? []).map((criterion, index) => {
|
|
253
|
-
if (typeof criterion === "string") {
|
|
254
|
-
return { id: `criterion-${index + 1}`, must: criterion, evidence, severity: "required" };
|
|
255
|
-
}
|
|
256
|
-
return {
|
|
257
|
-
id: criterion.id?.trim() || `criterion-${index + 1}`,
|
|
258
|
-
must: criterion.must ?? "",
|
|
259
|
-
evidence: criterion.evidence?.filter((item) => VALID_EVIDENCE.has(item)) ?? evidence,
|
|
260
|
-
severity: criterion.severity ?? "required",
|
|
261
|
-
};
|
|
262
|
-
}).filter((criterion) => criterion.must.trim());
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
export function resolveEffectiveAcceptance(input: {
|
|
266
|
-
explicit?: AcceptanceInput;
|
|
267
|
-
agentName: string;
|
|
268
|
-
task?: string;
|
|
269
|
-
mode?: SubagentRunMode;
|
|
270
|
-
async?: boolean;
|
|
271
|
-
dynamic?: boolean;
|
|
272
|
-
dynamicGroup?: boolean;
|
|
273
|
-
}): ResolvedAcceptanceConfig {
|
|
274
|
-
const explicit = normalizeAcceptanceInput(input.explicit);
|
|
275
|
-
const inferred = inferLevel(input);
|
|
276
|
-
const explicitLevel = normalizeLevel(explicit.level);
|
|
277
|
-
const level = explicitAcceptanceCanDisable(explicit)
|
|
278
|
-
? "none"
|
|
279
|
-
: explicitLevel === "auto"
|
|
280
|
-
? inferred.level
|
|
281
|
-
: (LEVEL_RANK[explicitLevel] >= LEVEL_RANK[inferred.level] ? explicitLevel : inferred.level);
|
|
282
|
-
const evidence = unique([...(level === inferred.level ? inferred.evidence : requiredEvidenceForLevel(level)), ...(explicit.evidence ?? [])]);
|
|
283
|
-
const criteria = normalizeCriteria(
|
|
284
|
-
(explicit.criteria?.length ? explicit.criteria : inferred.criteria) as Array<string | { id?: string; must?: string; evidence?: AcceptanceEvidenceKind[]; severity?: "required" | "recommended" }>,
|
|
285
|
-
evidence,
|
|
286
|
-
);
|
|
287
|
-
let review = explicit.review !== undefined ? explicit.review : inferred.review;
|
|
288
|
-
if (level === "reviewed" && explicitLevel !== "auto" && explicitLevel !== "reviewed" && explicit.review === undefined && review && review !== false) {
|
|
289
|
-
review = { ...review, required: false };
|
|
290
|
-
}
|
|
291
|
-
return {
|
|
292
|
-
level,
|
|
293
|
-
explicit: input.explicit !== undefined,
|
|
294
|
-
inferredReason: inferred.reasons,
|
|
295
|
-
criteria,
|
|
296
|
-
evidence,
|
|
297
|
-
verify: explicit.verify ?? [],
|
|
298
|
-
review,
|
|
299
|
-
stopRules: explicit.stopRules ?? [],
|
|
300
|
-
reason: explicit.reason,
|
|
301
|
-
};
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
export function formatAcceptancePrompt(acceptance: ResolvedAcceptanceConfig): string {
|
|
305
|
-
if (acceptance.level === "none") return "";
|
|
306
|
-
const lines = [
|
|
307
|
-
"",
|
|
308
|
-
"## Acceptance Contract",
|
|
309
|
-
`Acceptance level: ${acceptance.level}`,
|
|
310
|
-
"Completion is not accepted from prose alone. End with a structured acceptance report.",
|
|
311
|
-
"",
|
|
312
|
-
"Criteria:",
|
|
313
|
-
...(acceptance.criteria.length ? acceptance.criteria.map((criterion) => `- ${criterion.id}: ${criterion.must}`) : ["- Return the requested result."]),
|
|
314
|
-
"",
|
|
315
|
-
`Required evidence: ${acceptance.evidence.join(", ") || "none"}`,
|
|
316
|
-
];
|
|
317
|
-
if (acceptance.verify.length > 0) {
|
|
318
|
-
lines.push("", "Runtime verification commands configured by parent:");
|
|
319
|
-
for (const command of acceptance.verify) lines.push(`- ${command.id}: ${command.command}`);
|
|
320
|
-
}
|
|
321
|
-
if (acceptance.review && acceptance.review !== false) {
|
|
322
|
-
lines.push("", `Review gate: ${acceptance.review.required === false ? "optional" : "required"}${acceptance.review.agent ? ` by ${acceptance.review.agent}` : ""}.`);
|
|
323
|
-
if (acceptance.review.focus) lines.push(`Review focus: ${acceptance.review.focus}`);
|
|
324
|
-
}
|
|
325
|
-
if (acceptance.stopRules.length > 0) {
|
|
326
|
-
lines.push("", "Stop rules:", ...acceptance.stopRules.map((rule) => `- ${rule}`));
|
|
327
|
-
}
|
|
328
|
-
lines.push(
|
|
329
|
-
"",
|
|
330
|
-
"Finish with a fenced JSON block tagged `acceptance-report` in this shape:",
|
|
331
|
-
"Use empty arrays when no items apply; array fields contain strings unless object entries are shown.",
|
|
332
|
-
"```acceptance-report",
|
|
333
|
-
JSON.stringify({
|
|
334
|
-
criteriaSatisfied: [{ id: "criterion-1", status: "satisfied", evidence: "specific proof" }],
|
|
335
|
-
changedFiles: ["src/file.ts"],
|
|
336
|
-
testsAddedOrUpdated: ["test/file.test.ts"],
|
|
337
|
-
commandsRun: [{ command: "command", result: "passed", summary: "short result" }],
|
|
338
|
-
validationOutput: ["validation output or concise summary"],
|
|
339
|
-
residualRisks: ["none"],
|
|
340
|
-
noStagedFiles: true,
|
|
341
|
-
diffSummary: "short description of the diff",
|
|
342
|
-
reviewFindings: ["blocker: file.ts:12 - issue found, or no blockers"],
|
|
343
|
-
manualNotes: "anything else the parent should know",
|
|
344
|
-
}, null, 2),
|
|
345
|
-
"```",
|
|
346
|
-
);
|
|
347
|
-
return lines.join("\n");
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
function extractBalancedJson(text: string, start: number): string | undefined {
|
|
351
|
-
let depth = 0;
|
|
352
|
-
let inString = false;
|
|
353
|
-
let escaped = false;
|
|
354
|
-
for (let i = start; i < text.length; i++) {
|
|
355
|
-
const char = text[i]!;
|
|
356
|
-
if (inString) {
|
|
357
|
-
if (escaped) escaped = false;
|
|
358
|
-
else if (char === "\\") escaped = true;
|
|
359
|
-
else if (char === "\"") inString = false;
|
|
360
|
-
continue;
|
|
361
|
-
}
|
|
362
|
-
if (char === "\"") {
|
|
363
|
-
inString = true;
|
|
364
|
-
continue;
|
|
365
|
-
}
|
|
366
|
-
if (char === "{") depth++;
|
|
367
|
-
if (char === "}") {
|
|
368
|
-
depth--;
|
|
369
|
-
if (depth === 0) return text.slice(start, i + 1);
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
return undefined;
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
function unwrapAcceptanceReport(value: unknown): unknown {
|
|
376
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return value;
|
|
377
|
-
const record = value as { acceptance?: unknown; "acceptance-report"?: unknown };
|
|
378
|
-
if ("acceptance" in record) return record.acceptance;
|
|
379
|
-
if ("acceptance-report" in record) return record["acceptance-report"];
|
|
380
|
-
return value;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
function isCommandsRunArray(value: unknown): value is NonNullable<AcceptanceReport["commandsRun"]> {
|
|
384
|
-
return Array.isArray(value) && value.every((item) => {
|
|
385
|
-
if (!item || typeof item !== "object" || Array.isArray(item)) return false;
|
|
386
|
-
const command = item as { command?: unknown; result?: unknown; summary?: unknown };
|
|
387
|
-
return typeof command.command === "string"
|
|
388
|
-
&& (command.result === "passed" || command.result === "failed" || command.result === "not-run")
|
|
389
|
-
&& typeof command.summary === "string";
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
function hasGenericAcceptanceReportSignal(value: unknown): boolean {
|
|
394
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
395
|
-
const record = value as Record<string, unknown>;
|
|
396
|
-
return "criteriaSatisfied" in record && (
|
|
397
|
-
isStringArray(record.changedFiles)
|
|
398
|
-
|| isStringArray(record.testsAddedOrUpdated)
|
|
399
|
-
|| isCommandsRunArray(record.commandsRun)
|
|
400
|
-
|| isStringArray(record.validationOutput)
|
|
401
|
-
|| isStringArray(record.residualRisks)
|
|
402
|
-
|| typeof record.noStagedFiles === "boolean"
|
|
403
|
-
|| typeof record.diffSummary === "string"
|
|
404
|
-
|| isStringArray(record.reviewFindings)
|
|
405
|
-
|| typeof record.manualNotes === "string"
|
|
406
|
-
);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
function parseReportJson(body: string): unknown {
|
|
410
|
-
const trimmed = body.trim();
|
|
411
|
-
try {
|
|
412
|
-
return JSON.parse(trimmed) as unknown;
|
|
413
|
-
} catch (error) {
|
|
414
|
-
const jsonStart = trimmed.indexOf("{");
|
|
415
|
-
if (jsonStart > 0) {
|
|
416
|
-
const json = extractBalancedJson(trimmed, jsonStart);
|
|
417
|
-
if (json) return JSON.parse(json) as unknown;
|
|
418
|
-
}
|
|
419
|
-
throw error;
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
function fencedBlocks(output: string, tag: string): string[] {
|
|
424
|
-
return [...output.matchAll(new RegExp(`\`\`\`${tag}\\s*\\n([\\s\\S]*?)\`\`\``, "gi"))]
|
|
425
|
-
.map((match) => match[1]?.trim())
|
|
426
|
-
.filter((value): value is string => Boolean(value));
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
function validationPathLabelForWrapper(value: unknown): string {
|
|
430
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return "";
|
|
431
|
-
const record = value as Record<string, unknown>;
|
|
432
|
-
if ("acceptance" in record) return "acceptance";
|
|
433
|
-
if ("acceptance-report" in record) return "acceptance-report";
|
|
434
|
-
return "";
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
function parseAcceptanceReportBody(body: string): { report?: AcceptanceReport; errors: string[] } {
|
|
438
|
-
const parsed = parseReportJson(body);
|
|
439
|
-
const report = unwrapAcceptanceReport(parsed);
|
|
440
|
-
return validateAcceptanceReport(report, validationPathLabelForWrapper(parsed));
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
function parseGenericJsonAcceptanceReportBody(body: string): AcceptanceReport | undefined {
|
|
444
|
-
const parsed = parseReportJson(body);
|
|
445
|
-
const report = unwrapAcceptanceReport(parsed);
|
|
446
|
-
const validation = validateAcceptanceReport(report);
|
|
447
|
-
if (!validation.report) return undefined;
|
|
448
|
-
return hasGenericAcceptanceReportSignal(validation.report) ? validation.report : undefined;
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
export function parseAcceptanceReport(output: string): { report?: AcceptanceReport; error?: string } {
|
|
452
|
-
const fenced = fencedBlocks(output, "acceptance-report");
|
|
453
|
-
const parseErrors: string[] = [];
|
|
454
|
-
for (const body of fenced) {
|
|
455
|
-
try {
|
|
456
|
-
const validation = parseAcceptanceReportBody(body);
|
|
457
|
-
if (validation.report) return { report: validation.report };
|
|
458
|
-
parseErrors.push(`Invalid acceptance-report: ${validation.errors.join("; ")}`);
|
|
459
|
-
} catch (error) {
|
|
460
|
-
parseErrors.push(error instanceof Error ? error.message : String(error));
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
if (parseErrors.length > 0) return { error: `Failed to parse acceptance-report: ${parseErrors.join("; ")}` };
|
|
464
|
-
for (const body of fencedBlocks(output, "(?:json|jsonc|json5)")) {
|
|
465
|
-
try {
|
|
466
|
-
const report = parseGenericJsonAcceptanceReportBody(body);
|
|
467
|
-
if (report) return { report };
|
|
468
|
-
} catch {
|
|
469
|
-
// Ignore unrelated or malformed generic JSON fences; only explicit
|
|
470
|
-
// acceptance-report fences should turn parse failures into blockers.
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
const markerIndex = output.search(/ACCEPTANCE_REPORT\s*:/i);
|
|
474
|
-
if (markerIndex !== -1) {
|
|
475
|
-
const jsonStart = output.indexOf("{", markerIndex);
|
|
476
|
-
if (jsonStart !== -1) {
|
|
477
|
-
const json = extractBalancedJson(output, jsonStart);
|
|
478
|
-
if (json) {
|
|
479
|
-
try {
|
|
480
|
-
const parsed = JSON.parse(json) as unknown;
|
|
481
|
-
const report = unwrapAcceptanceReport(parsed);
|
|
482
|
-
const validation = validateAcceptanceReport(report, validationPathLabelForWrapper(parsed));
|
|
483
|
-
if (validation.report) return { report: validation.report };
|
|
484
|
-
return { error: `Failed to parse acceptance-report: Invalid acceptance-report: ${validation.errors.join("; ")}` };
|
|
485
|
-
} catch (error) {
|
|
486
|
-
return { error: error instanceof Error ? error.message : String(error) };
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
return { error: "Structured acceptance report not found." };
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
export function stripAcceptanceReport(output: string): string {
|
|
495
|
-
const trailingFencePattern = /\n?```(acceptance-report|json|jsonc|json5)\s*\n([\s\S]*?)```\s*/gi;
|
|
496
|
-
let trailingFence: { index: number; tag: string; body: string } | undefined;
|
|
497
|
-
for (const match of output.matchAll(trailingFencePattern)) {
|
|
498
|
-
const end = (match.index ?? 0) + match[0].length;
|
|
499
|
-
if (output.slice(end).trim().length === 0 && match[1] && match[2]) {
|
|
500
|
-
trailingFence = { index: match.index ?? 0, tag: match[1].toLowerCase(), body: match[2] };
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
if (trailingFence) {
|
|
504
|
-
if (trailingFence.tag === "acceptance-report") return output.slice(0, trailingFence.index).trimEnd();
|
|
505
|
-
try {
|
|
506
|
-
if (parseGenericJsonAcceptanceReportBody(trailingFence.body)) return output.slice(0, trailingFence.index).trimEnd();
|
|
507
|
-
} catch {
|
|
508
|
-
// Leave unrelated or malformed generic JSON fences visible.
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
return output
|
|
512
|
-
.replace(/\n?```acceptance-report\s*\n[\s\S]*?```\s*$/i, "")
|
|
513
|
-
.replace(/\n?ACCEPTANCE_REPORT\s*:\s*\{[\s\S]*\}\s*$/i, "")
|
|
514
|
-
.trimEnd();
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
function isStringArray(value: unknown): value is string[] {
|
|
518
|
-
return Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
function pathFor(base: string, segment: string): string {
|
|
522
|
-
return base ? `${base}.${segment}` : segment;
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
function describeValidationValue(value: unknown): string {
|
|
526
|
-
if (value === undefined) return "missing";
|
|
527
|
-
if (value === null) return "null";
|
|
528
|
-
if (Array.isArray(value)) return "array";
|
|
529
|
-
if (typeof value === "object") return "object";
|
|
530
|
-
if (typeof value === "string") {
|
|
531
|
-
const short = value.length > 80 ? `${value.slice(0, 77)}...` : value;
|
|
532
|
-
return JSON.stringify(short);
|
|
533
|
-
}
|
|
534
|
-
return `${typeof value} ${String(value)}`;
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
function pushTypeError(errors: string[], pathLabel: string, expected: string, value: unknown): void {
|
|
538
|
-
errors.push(`${pathLabel}: expected ${expected}; got ${describeValidationValue(value)}`);
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
function validateStringArrayField(errors: string[], value: unknown, pathLabel: string): void {
|
|
542
|
-
if (!Array.isArray(value)) {
|
|
543
|
-
pushTypeError(errors, pathLabel, "string[]", value);
|
|
544
|
-
return;
|
|
545
|
-
}
|
|
546
|
-
for (const [index, item] of value.entries()) {
|
|
547
|
-
if (typeof item !== "string") pushTypeError(errors, `${pathLabel}[${index}]`, "string", item);
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
function validateAcceptanceReport(value: unknown, pathLabel = ""): { report?: AcceptanceReport; errors: string[] } {
|
|
552
|
-
const errors: string[] = [];
|
|
553
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
554
|
-
pushTypeError(errors, pathLabel || "acceptance-report", "object", value);
|
|
555
|
-
return { errors };
|
|
556
|
-
}
|
|
557
|
-
const report = value as AcceptanceReport;
|
|
558
|
-
if (report.criteriaSatisfied !== undefined) {
|
|
559
|
-
if (!Array.isArray(report.criteriaSatisfied)) {
|
|
560
|
-
pushTypeError(errors, pathFor(pathLabel, "criteriaSatisfied"), "array", report.criteriaSatisfied);
|
|
561
|
-
} else {
|
|
562
|
-
for (const [index, item] of report.criteriaSatisfied.entries()) {
|
|
563
|
-
const itemPath = `${pathFor(pathLabel, "criteriaSatisfied")}[${index}]`;
|
|
564
|
-
if (!item || typeof item !== "object" || Array.isArray(item)) {
|
|
565
|
-
pushTypeError(errors, itemPath, "object", item);
|
|
566
|
-
continue;
|
|
567
|
-
}
|
|
568
|
-
const criterion = item as { id?: unknown; status?: unknown; evidence?: unknown };
|
|
569
|
-
if (criterion.id !== undefined && typeof criterion.id !== "string") pushTypeError(errors, `${itemPath}.id`, "string", criterion.id);
|
|
570
|
-
if (criterion.status !== "satisfied" && criterion.status !== "not-satisfied" && criterion.status !== "not-applicable") {
|
|
571
|
-
pushTypeError(errors, `${itemPath}.status`, "one of \"satisfied\", \"not-satisfied\", \"not-applicable\"", criterion.status);
|
|
572
|
-
}
|
|
573
|
-
if (typeof criterion.evidence !== "string" || !criterion.evidence.trim()) pushTypeError(errors, `${itemPath}.evidence`, "non-empty string", criterion.evidence);
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
if (report.changedFiles !== undefined) validateStringArrayField(errors, report.changedFiles, pathFor(pathLabel, "changedFiles"));
|
|
578
|
-
if (report.testsAddedOrUpdated !== undefined) validateStringArrayField(errors, report.testsAddedOrUpdated, pathFor(pathLabel, "testsAddedOrUpdated"));
|
|
579
|
-
if (report.commandsRun !== undefined) {
|
|
580
|
-
if (!Array.isArray(report.commandsRun)) {
|
|
581
|
-
pushTypeError(errors, pathFor(pathLabel, "commandsRun"), "array", report.commandsRun);
|
|
582
|
-
} else {
|
|
583
|
-
for (const [index, item] of report.commandsRun.entries()) {
|
|
584
|
-
const itemPath = `${pathFor(pathLabel, "commandsRun")}[${index}]`;
|
|
585
|
-
if (!item || typeof item !== "object" || Array.isArray(item)) {
|
|
586
|
-
pushTypeError(errors, itemPath, "object", item);
|
|
587
|
-
continue;
|
|
588
|
-
}
|
|
589
|
-
const command = item as { command?: unknown; result?: unknown; summary?: unknown };
|
|
590
|
-
if (typeof command.command !== "string" || !command.command.trim()) pushTypeError(errors, `${itemPath}.command`, "non-empty string", command.command);
|
|
591
|
-
if (command.result !== "passed" && command.result !== "failed" && command.result !== "not-run") {
|
|
592
|
-
pushTypeError(errors, `${itemPath}.result`, "one of \"passed\", \"failed\", \"not-run\"", command.result);
|
|
593
|
-
}
|
|
594
|
-
if (typeof command.summary !== "string") pushTypeError(errors, `${itemPath}.summary`, "string", command.summary);
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
if (report.validationOutput !== undefined) validateStringArrayField(errors, report.validationOutput, pathFor(pathLabel, "validationOutput"));
|
|
599
|
-
if (report.residualRisks !== undefined) validateStringArrayField(errors, report.residualRisks, pathFor(pathLabel, "residualRisks"));
|
|
600
|
-
if (report.noStagedFiles !== undefined && typeof report.noStagedFiles !== "boolean") pushTypeError(errors, pathFor(pathLabel, "noStagedFiles"), "boolean", report.noStagedFiles);
|
|
601
|
-
if (report.diffSummary !== undefined && typeof report.diffSummary !== "string") pushTypeError(errors, pathFor(pathLabel, "diffSummary"), "string", report.diffSummary);
|
|
602
|
-
if (report.reviewFindings !== undefined) validateStringArrayField(errors, report.reviewFindings, pathFor(pathLabel, "reviewFindings"));
|
|
603
|
-
if (report.manualNotes !== undefined && typeof report.manualNotes !== "string") pushTypeError(errors, pathFor(pathLabel, "manualNotes"), "string", report.manualNotes);
|
|
604
|
-
if (report.notes !== undefined && typeof report.notes !== "string") pushTypeError(errors, pathFor(pathLabel, "notes"), "string", report.notes);
|
|
605
|
-
if (errors.length > 0) return { errors };
|
|
606
|
-
const hasReportField = report.criteriaSatisfied !== undefined
|
|
607
|
-
|| report.changedFiles !== undefined
|
|
608
|
-
|| report.testsAddedOrUpdated !== undefined
|
|
609
|
-
|| report.commandsRun !== undefined
|
|
610
|
-
|| report.validationOutput !== undefined
|
|
611
|
-
|| report.residualRisks !== undefined
|
|
612
|
-
|| report.noStagedFiles !== undefined
|
|
613
|
-
|| report.diffSummary !== undefined
|
|
614
|
-
|| report.manualNotes !== undefined
|
|
615
|
-
|| report.notes !== undefined
|
|
616
|
-
|| report.reviewFindings !== undefined;
|
|
617
|
-
return hasReportField
|
|
618
|
-
? { report, errors }
|
|
619
|
-
: { errors: [`${pathLabel || "acceptance-report"}: expected at least one acceptance report field`] };
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
function checkCriteriaSatisfied(criteria: ResolvedAcceptanceGate[], report: AcceptanceReport): AcceptanceRuntimeCheck[] {
|
|
623
|
-
const reports = new Map((report.criteriaSatisfied ?? []).filter((item) => item.id).map((item) => [item.id!, item]));
|
|
624
|
-
return criteria.filter((criterion) => criterion.severity !== "recommended").map((criterion) => {
|
|
625
|
-
const item = reports.get(criterion.id);
|
|
626
|
-
if (!item) return { id: `criterion:${criterion.id}`, status: "failed", message: `Required criterion '${criterion.id}' was not reported.` };
|
|
627
|
-
if (item.status !== "satisfied") return { id: `criterion:${criterion.id}`, status: "failed", message: `Required criterion '${criterion.id}' was reported as ${item.status}.` };
|
|
628
|
-
return { id: `criterion:${criterion.id}`, status: "passed", message: `Required criterion '${criterion.id}' satisfied.` };
|
|
629
|
-
});
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
function reportEvidencePresent(report: AcceptanceReport, kind: AcceptanceEvidenceKind): boolean {
|
|
633
|
-
switch (kind) {
|
|
634
|
-
case "changed-files": return isStringArray(report.changedFiles) && report.changedFiles.length > 0;
|
|
635
|
-
case "tests-added": return isStringArray(report.testsAddedOrUpdated) && report.testsAddedOrUpdated.length > 0;
|
|
636
|
-
case "commands-run": return Array.isArray(report.commandsRun) && report.commandsRun.length > 0;
|
|
637
|
-
case "validation-output": return isStringArray(report.validationOutput) && report.validationOutput.length > 0;
|
|
638
|
-
case "residual-risks": return isStringArray(report.residualRisks);
|
|
639
|
-
case "no-staged-files": return report.noStagedFiles === true;
|
|
640
|
-
case "diff-summary": return typeof report.diffSummary === "string" && report.diffSummary.trim().length > 0;
|
|
641
|
-
case "review-findings": return isStringArray(report.reviewFindings);
|
|
642
|
-
case "manual-notes": return Boolean((report.manualNotes ?? report.notes)?.trim());
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
function checkNoStagedFiles(cwd: string): AcceptanceRuntimeCheck {
|
|
647
|
-
const result = spawnSync("git", ["status", "--short"], { cwd, encoding: "utf-8" });
|
|
648
|
-
if (result.status !== 0) {
|
|
649
|
-
return { id: "no-staged-files", status: "not-applicable", message: "git status unavailable; no staged-files check skipped" };
|
|
650
|
-
}
|
|
651
|
-
const staged = result.stdout.split(/\r?\n/).filter((line) => line.length >= 2 && line[0] !== " " && line[0] !== "?");
|
|
652
|
-
return staged.length === 0
|
|
653
|
-
? { id: "no-staged-files", status: "passed", message: "No staged files detected." }
|
|
654
|
-
: { id: "no-staged-files", status: "failed", message: `Staged files present: ${staged.join(", ")}` };
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
function runStructuralChecks(acceptance: ResolvedAcceptanceConfig, report: AcceptanceReport, cwd: string): AcceptanceRuntimeCheck[] {
|
|
658
|
-
const checks: AcceptanceRuntimeCheck[] = [];
|
|
659
|
-
for (const kind of acceptance.evidence) {
|
|
660
|
-
const present = reportEvidencePresent(report, kind);
|
|
661
|
-
checks.push({
|
|
662
|
-
id: `evidence:${kind}`,
|
|
663
|
-
status: present ? "passed" : "failed",
|
|
664
|
-
message: present ? `${kind} evidence present.` : `${kind} evidence missing from child report.`,
|
|
665
|
-
});
|
|
666
|
-
}
|
|
667
|
-
if (acceptance.evidence.includes("no-staged-files")) checks.push(checkNoStagedFiles(cwd));
|
|
668
|
-
return checks;
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
function trimOutput(value: string): string | undefined {
|
|
672
|
-
const trimmed = value.trim();
|
|
673
|
-
if (!trimmed) return undefined;
|
|
674
|
-
return trimmed.length > 12_000 ? `${trimmed.slice(0, 12_000)}\n...[truncated]` : trimmed;
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
function uniqueStrings(items: Array<string | undefined>): string[] {
|
|
678
|
-
return unique(items.map((item) => item?.trim()).filter((item): item is string => Boolean(item)));
|
|
679
|
-
}
|
|
680
|
-
|
|
681
|
-
export function aggregateAcceptanceReport(input: {
|
|
682
|
-
results: Array<Pick<SingleResult, "agent" | "acceptance" | "error" | "exitCode">>;
|
|
683
|
-
notes?: string;
|
|
684
|
-
}): AcceptanceReport {
|
|
685
|
-
const childReports = input.results.map((result) => result.acceptance?.childReport).filter((report): report is AcceptanceReport => Boolean(report));
|
|
686
|
-
const blockers = input.results.filter((result) => result.exitCode !== 0 || result.acceptance?.status === "rejected");
|
|
687
|
-
const successfulChildren = input.results.length > 0 && blockers.length === 0;
|
|
688
|
-
return {
|
|
689
|
-
criteriaSatisfied: [
|
|
690
|
-
{ id: "criterion-1", status: successfulChildren ? "satisfied" : "not-satisfied", evidence: successfulChildren ? `All ${input.results.length} dynamic child run(s) completed without child or acceptance blockers.` : "Dynamic fanout produced no accepted child evidence." },
|
|
691
|
-
{ id: "criterion-2", status: successfulChildren ? "satisfied" : "not-satisfied", evidence: successfulChildren ? "Collected child acceptance evidence for aggregate review." : "Dynamic fanout produced no aggregate review evidence." },
|
|
692
|
-
...input.results.map((result, index) => ({
|
|
693
|
-
id: `child-${index + 1}`,
|
|
694
|
-
status: result.exitCode === 0 && result.acceptance?.status !== "rejected" ? "satisfied" : "not-satisfied",
|
|
695
|
-
evidence: `${result.agent}: acceptance ${result.acceptance?.status ?? "unreported"}${result.error ? ` (${result.error})` : ""}`,
|
|
696
|
-
})),
|
|
697
|
-
],
|
|
698
|
-
changedFiles: uniqueStrings(childReports.flatMap((report) => report.changedFiles ?? [])),
|
|
699
|
-
testsAddedOrUpdated: uniqueStrings(childReports.flatMap((report) => report.testsAddedOrUpdated ?? [])),
|
|
700
|
-
commandsRun: childReports.flatMap((report) => report.commandsRun ?? []),
|
|
701
|
-
validationOutput: uniqueStrings(childReports.flatMap((report) => report.validationOutput ?? [])),
|
|
702
|
-
residualRisks: uniqueStrings([
|
|
703
|
-
...childReports.flatMap((report) => report.residualRisks ?? []),
|
|
704
|
-
...blockers.map((result) => `${result.agent}: ${result.error ?? "child or acceptance gate failed"}`),
|
|
705
|
-
]),
|
|
706
|
-
noStagedFiles: childReports.length > 0 && childReports.every((report) => report.noStagedFiles === true),
|
|
707
|
-
reviewFindings: uniqueStrings(childReports.flatMap((report) => report.reviewFindings ?? [])),
|
|
708
|
-
manualNotes: input.notes ?? `Aggregated acceptance evidence from ${input.results.length} dynamic fanout child run(s).`,
|
|
709
|
-
notes: input.notes,
|
|
710
|
-
};
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
function runVerifyCommand(command: AcceptanceVerifyCommand, defaultCwd: string, options: { signal?: AbortSignal; abortMessage?: string } = {}): Promise<AcceptanceVerifyResult> {
|
|
714
|
-
return new Promise((resolve) => {
|
|
715
|
-
const startedAt = Date.now();
|
|
716
|
-
const cwd = command.cwd ? path.resolve(defaultCwd, command.cwd) : defaultCwd;
|
|
717
|
-
let stdout = "";
|
|
718
|
-
let stderr = "";
|
|
719
|
-
let timedOut = false;
|
|
720
|
-
let settled = false;
|
|
721
|
-
let hardKill: NodeJS.Timeout | undefined;
|
|
722
|
-
const child = spawn(command.command, {
|
|
723
|
-
cwd,
|
|
724
|
-
env: { ...process.env, ...(command.env ?? {}) },
|
|
725
|
-
shell: true,
|
|
726
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
727
|
-
windowsHide: true,
|
|
728
|
-
});
|
|
729
|
-
const finish = (result: Omit<AcceptanceVerifyResult, "id" | "command" | "cwd" | "durationMs">) => {
|
|
730
|
-
if (settled) return;
|
|
731
|
-
settled = true;
|
|
732
|
-
clearTimeout(timeout);
|
|
733
|
-
if (hardKill) clearTimeout(hardKill);
|
|
734
|
-
options.signal?.removeEventListener("abort", abortVerification);
|
|
735
|
-
resolve({
|
|
736
|
-
id: command.id,
|
|
737
|
-
command: command.command,
|
|
738
|
-
cwd,
|
|
739
|
-
durationMs: Date.now() - startedAt,
|
|
740
|
-
...result,
|
|
741
|
-
});
|
|
742
|
-
};
|
|
743
|
-
const abortVerification = () => {
|
|
744
|
-
if (settled || timedOut) return;
|
|
745
|
-
timedOut = true;
|
|
746
|
-
child.kill("SIGTERM");
|
|
747
|
-
hardKill = setTimeout(() => {
|
|
748
|
-
child.kill("SIGKILL");
|
|
749
|
-
finish({
|
|
750
|
-
exitCode: null,
|
|
751
|
-
status: "timed-out",
|
|
752
|
-
stdout: trimOutput(stdout),
|
|
753
|
-
stderr: trimOutput(stderr || options.abortMessage || "Acceptance verification timed out."),
|
|
754
|
-
});
|
|
755
|
-
}, 1000);
|
|
756
|
-
hardKill.unref?.();
|
|
757
|
-
};
|
|
758
|
-
const timeout = setTimeout(abortVerification, command.timeoutMs ?? 120_000);
|
|
759
|
-
timeout.unref?.();
|
|
760
|
-
if (options.signal?.aborted) abortVerification();
|
|
761
|
-
else options.signal?.addEventListener("abort", abortVerification, { once: true });
|
|
762
|
-
child.stdout.on("data", (chunk: Buffer) => {
|
|
763
|
-
stdout += chunk.toString();
|
|
764
|
-
});
|
|
765
|
-
child.stderr.on("data", (chunk: Buffer) => {
|
|
766
|
-
stderr += chunk.toString();
|
|
767
|
-
});
|
|
768
|
-
child.on("close", (exitCode) => {
|
|
769
|
-
const passed = exitCode === 0 && !timedOut;
|
|
770
|
-
finish({
|
|
771
|
-
exitCode,
|
|
772
|
-
status: timedOut ? "timed-out" : passed ? "passed" : command.allowFailure ? "allowed-failure" : "failed",
|
|
773
|
-
stdout: trimOutput(stdout),
|
|
774
|
-
stderr: trimOutput(stderr || (timedOut ? options.abortMessage ?? "" : "")),
|
|
775
|
-
});
|
|
776
|
-
});
|
|
777
|
-
child.on("error", (error) => {
|
|
778
|
-
finish({
|
|
779
|
-
exitCode: timedOut ? null : 1,
|
|
780
|
-
status: timedOut ? "timed-out" : command.allowFailure ? "allowed-failure" : "failed",
|
|
781
|
-
stderr: timedOut ? trimOutput(stderr || options.abortMessage || "Acceptance verification timed out.") : error instanceof Error ? error.message : String(error),
|
|
782
|
-
});
|
|
783
|
-
});
|
|
784
|
-
});
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
export async function evaluateAcceptance(input: {
|
|
788
|
-
acceptance: ResolvedAcceptanceConfig;
|
|
789
|
-
output: string;
|
|
790
|
-
cwd: string;
|
|
791
|
-
report?: AcceptanceReport;
|
|
792
|
-
reviewResult?: AcceptanceReviewResult;
|
|
793
|
-
signal?: AbortSignal;
|
|
794
|
-
abortMessage?: string;
|
|
795
|
-
}): Promise<AcceptanceLedger> {
|
|
796
|
-
const acceptance = input.acceptance;
|
|
797
|
-
const ledger: AcceptanceLedger = {
|
|
798
|
-
status: acceptance.level === "none" ? "not-required" : "claimed",
|
|
799
|
-
explicit: acceptance.explicit,
|
|
800
|
-
effectiveAcceptance: acceptance,
|
|
801
|
-
inferredReason: acceptance.inferredReason,
|
|
802
|
-
criteria: acceptance.criteria,
|
|
803
|
-
runtimeChecks: [],
|
|
804
|
-
verifyRuns: [],
|
|
805
|
-
};
|
|
806
|
-
if (acceptance.level === "none") return ledger;
|
|
807
|
-
|
|
808
|
-
const parsed = input.report ? { report: input.report } : parseAcceptanceReport(input.output);
|
|
809
|
-
if (parsed.report) {
|
|
810
|
-
ledger.childReport = parsed.report;
|
|
811
|
-
ledger.status = "attested";
|
|
812
|
-
} else {
|
|
813
|
-
ledger.childReportParseError = parsed.error;
|
|
814
|
-
ledger.runtimeChecks.push({ id: "attestation", status: "failed", message: parsed.error ?? "Structured acceptance report missing." });
|
|
815
|
-
ledger.status = "rejected";
|
|
816
|
-
return ledger;
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
if (LEVEL_RANK[acceptance.level] >= LEVEL_RANK.checked) {
|
|
820
|
-
ledger.runtimeChecks = [
|
|
821
|
-
...checkCriteriaSatisfied(acceptance.criteria, parsed.report),
|
|
822
|
-
...runStructuralChecks(acceptance, parsed.report, input.cwd),
|
|
823
|
-
];
|
|
824
|
-
if (ledger.runtimeChecks.some((check) => check.status === "failed")) {
|
|
825
|
-
ledger.status = "rejected";
|
|
826
|
-
return ledger;
|
|
827
|
-
}
|
|
828
|
-
ledger.status = "checked";
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
if (LEVEL_RANK[acceptance.level] >= LEVEL_RANK.verified && (acceptance.level === "verified" || acceptance.verify.length > 0)) {
|
|
832
|
-
if (acceptance.level === "verified" && acceptance.verify.length === 0) {
|
|
833
|
-
ledger.runtimeChecks.push({ id: "verification-config", status: "failed", message: "verified acceptance requires runtime verify commands." });
|
|
834
|
-
ledger.status = "rejected";
|
|
835
|
-
return ledger;
|
|
836
|
-
}
|
|
837
|
-
ledger.verifyRuns = [];
|
|
838
|
-
for (const command of acceptance.verify) {
|
|
839
|
-
ledger.verifyRuns.push(await runVerifyCommand(command, input.cwd, { signal: input.signal, abortMessage: input.abortMessage }));
|
|
840
|
-
if (input.signal?.aborted) break;
|
|
841
|
-
}
|
|
842
|
-
if (ledger.verifyRuns.some((run) => run.status === "failed" || run.status === "timed-out")) {
|
|
843
|
-
ledger.status = "rejected";
|
|
844
|
-
return ledger;
|
|
845
|
-
}
|
|
846
|
-
ledger.status = "verified";
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
if (acceptance.level === "reviewed") {
|
|
850
|
-
if (input.reviewResult) {
|
|
851
|
-
ledger.reviewResult = input.reviewResult;
|
|
852
|
-
ledger.status = input.reviewResult.status === "no-blockers" ? "reviewed" : "rejected";
|
|
853
|
-
} else {
|
|
854
|
-
const optionalReview = acceptance.review && acceptance.review !== false && acceptance.review.required === false;
|
|
855
|
-
ledger.reviewResult = {
|
|
856
|
-
status: "needs-parent-decision",
|
|
857
|
-
findings: [{
|
|
858
|
-
severity: acceptance.explicit && !optionalReview ? "blocker" : "non-blocking",
|
|
859
|
-
issue: "Reviewed acceptance requires an independent reviewer result.",
|
|
860
|
-
rationale: "The run cannot be marked reviewed from child evidence alone.",
|
|
861
|
-
}],
|
|
862
|
-
};
|
|
863
|
-
if (acceptance.review === false || (acceptance.explicit && !optionalReview)) ledger.status = "rejected";
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
return ledger;
|
|
868
|
-
}
|
|
869
|
-
|
|
870
|
-
export function acceptanceFailureMessage(ledger: AcceptanceLedger): string | undefined {
|
|
871
|
-
if (ledger.status !== "rejected") return undefined;
|
|
872
|
-
const failedCheck = ledger.runtimeChecks.find((check) => check.status === "failed");
|
|
873
|
-
if (failedCheck) return `Acceptance rejected: ${failedCheck.message}`;
|
|
874
|
-
const failedVerify = ledger.verifyRuns.find((run) => run.status === "failed" || run.status === "timed-out");
|
|
875
|
-
if (failedVerify) return `Acceptance verification '${failedVerify.id}' ${failedVerify.status}.`;
|
|
876
|
-
if (ledger.reviewResult?.status === "needs-parent-decision") return "Acceptance review required but no automatic reviewer result is available.";
|
|
877
|
-
if (ledger.reviewResult?.status === "blockers") return "Acceptance review found blockers.";
|
|
878
|
-
return "Acceptance rejected.";
|
|
879
|
-
}
|