@oyasmi/pipiclaw 0.9.3-beta.5 → 0.9.3

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.
Files changed (144) hide show
  1. package/README.en.md +1 -1
  2. package/README.md +1 -1
  3. package/dist/agent/channel-runner.d.ts +4 -8
  4. package/dist/agent/channel-runner.js +14 -34
  5. package/dist/agent/job-manager.d.ts +12 -0
  6. package/dist/agent/job-manager.js +42 -1
  7. package/dist/agent/prompt/sections.js +2 -2
  8. package/dist/agent/runner-factory.d.ts +2 -2
  9. package/dist/agent/types.d.ts +11 -7
  10. package/dist/channel/channel-index.d.ts +9 -2
  11. package/dist/channel/channel-index.js +25 -6
  12. package/dist/channel/project-scope-store.d.ts +20 -0
  13. package/dist/channel/project-scope-store.js +22 -7
  14. package/dist/commands/catalog.js +6 -12
  15. package/dist/events/event-commands.js +2 -2
  16. package/dist/events/events.d.ts +51 -30
  17. package/dist/events/events.js +70 -98
  18. package/dist/memory/journal.d.ts +2 -3
  19. package/dist/memory/journal.js +2 -3
  20. package/dist/memory/maintenance-tuning.d.ts +0 -1
  21. package/dist/memory/maintenance-tuning.js +0 -1
  22. package/dist/memory/scheduler.js +8 -16
  23. package/dist/memory/search.js +2 -3
  24. package/dist/memory/session-search.js +3 -9
  25. package/dist/memory/store.d.ts +1 -1
  26. package/dist/memory/store.js +9 -1
  27. package/dist/memory/task-digest.js +10 -11
  28. package/dist/memory/tombstones.js +2 -4
  29. package/dist/models/provider-login.d.ts +1 -1
  30. package/dist/models/provider-login.js +1 -1
  31. package/dist/playbooks/agent-delegation.md +6 -6
  32. package/dist/playbooks/background-jobs.md +1 -1
  33. package/dist/playbooks/event-scheduling.md +22 -13
  34. package/dist/playbooks/memory-and-learning.md +2 -2
  35. package/dist/playbooks/outbound-media.md +1 -1
  36. package/dist/playbooks/runtime-orientation.md +3 -3
  37. package/dist/playbooks/task-lead.md +82 -0
  38. package/dist/runtime/bootstrap.js +94 -187
  39. package/dist/runtime/durable-dispatch.js +30 -3
  40. package/dist/runtime/report-commands.d.ts +30 -0
  41. package/dist/runtime/report-commands.js +71 -0
  42. package/dist/runtime/subagent-commands.js +1 -1
  43. package/dist/runtime/task-commands.d.ts +0 -8
  44. package/dist/runtime/task-commands.js +48 -85
  45. package/dist/runtime/task-driver.d.ts +15 -10
  46. package/dist/runtime/task-driver.js +36 -41
  47. package/dist/runtime/task-migration.d.ts +23 -29
  48. package/dist/runtime/task-migration.js +364 -183
  49. package/dist/runtime/task-spawn.d.ts +24 -0
  50. package/dist/runtime/task-spawn.js +49 -0
  51. package/dist/runtime/task-wake.d.ts +33 -46
  52. package/dist/runtime/task-wake.js +15 -90
  53. package/dist/security/network.js +44 -9
  54. package/dist/settings.d.ts +1 -8
  55. package/dist/settings.js +1 -8
  56. package/dist/subagents/discovery.js +3 -15
  57. package/dist/subagents/external/run.d.ts +3 -1
  58. package/dist/subagents/external/run.js +2 -20
  59. package/dist/subagents/external/settlement.d.ts +4 -16
  60. package/dist/subagents/external/settlement.js +16 -67
  61. package/dist/subagents/runs.d.ts +15 -29
  62. package/dist/subagents/runs.js +70 -158
  63. package/dist/subagents/tool.d.ts +20 -4
  64. package/dist/subagents/tool.js +63 -87
  65. package/dist/subagents/verification-outcome.d.ts +13 -19
  66. package/dist/subagents/verification-outcome.js +8 -22
  67. package/dist/subagents/workspace-summary.d.ts +8 -0
  68. package/dist/subagents/workspace-summary.js +29 -0
  69. package/dist/tasks/board.d.ts +43 -0
  70. package/dist/tasks/board.js +134 -0
  71. package/dist/tasks/brief.d.ts +10 -5
  72. package/dist/tasks/brief.js +78 -26
  73. package/dist/tasks/budget.d.ts +13 -14
  74. package/dist/tasks/budget.js +21 -40
  75. package/dist/tasks/contract-input.d.ts +19 -0
  76. package/dist/tasks/contract-input.js +55 -0
  77. package/dist/tasks/create.d.ts +17 -0
  78. package/dist/tasks/create.js +36 -0
  79. package/dist/tasks/frontmatter.d.ts +20 -27
  80. package/dist/tasks/frontmatter.js +18 -31
  81. package/dist/tasks/ledger.d.ts +61 -117
  82. package/dist/tasks/ledger.js +78 -223
  83. package/dist/tasks/log.d.ts +62 -35
  84. package/dist/tasks/log.js +51 -29
  85. package/dist/tasks/session-path.d.ts +3 -3
  86. package/dist/tasks/session-path.js +4 -5
  87. package/dist/tasks/store.d.ts +27 -28
  88. package/dist/tasks/store.js +89 -83
  89. package/dist/tasks/ticket.d.ts +33 -66
  90. package/dist/tasks/ticket.js +31 -120
  91. package/dist/tasks/work-log.d.ts +20 -0
  92. package/dist/tasks/work-log.js +42 -0
  93. package/dist/tools/bash.d.ts +1 -1
  94. package/dist/tools/bash.js +1 -1
  95. package/dist/tools/event-manage.d.ts +16 -2
  96. package/dist/tools/event-manage.js +30 -12
  97. package/dist/tools/index.d.ts +5 -3
  98. package/dist/tools/index.js +5 -5
  99. package/dist/tools/registry.d.ts +6 -4
  100. package/dist/tools/registry.js +1 -4
  101. package/dist/tools/subagent-manage.js +4 -2
  102. package/dist/tools/task-manage/create.js +11 -27
  103. package/dist/tools/task-manage/lifecycle.d.ts +6 -7
  104. package/dist/tools/task-manage/lifecycle.js +23 -106
  105. package/dist/tools/task-manage/log-view.d.ts +3 -2
  106. package/dist/tools/task-manage/log-view.js +6 -6
  107. package/dist/tools/task-manage/schema.d.ts +10 -30
  108. package/dist/tools/task-manage/schema.js +33 -49
  109. package/dist/tools/task-manage/shared.d.ts +35 -42
  110. package/dist/tools/task-manage/shared.js +53 -192
  111. package/dist/tools/task-manage/step-end.d.ts +6 -6
  112. package/dist/tools/task-manage/step-end.js +61 -98
  113. package/dist/tools/task-manage/types.d.ts +8 -9
  114. package/dist/tools/task-manage.js +5 -5
  115. package/dist/tui/app.js +11 -38
  116. package/dist/tui/commands.d.ts +18 -8
  117. package/dist/tui/commands.js +2 -9
  118. package/dist/tui/turn-controller.d.ts +2 -14
  119. package/dist/tui/turn-controller.js +1 -17
  120. package/dist/web/client.js +9 -1
  121. package/examples/sub-agents/README.md +7 -4
  122. package/examples/sub-agents/agents/codex-flash.md +2 -2
  123. package/examples/sub-agents/agents/codex-high.md +1 -1
  124. package/examples/sub-agents/agents/codex-main.md +1 -1
  125. package/examples/sub-agents/agents/codex-review.md +23 -0
  126. package/examples/sub-agents/roles/verifier.md +1 -1
  127. package/package.json +1 -1
  128. package/dist/memory/maintenance-migration.d.ts +0 -5
  129. package/dist/memory/maintenance-migration.js +0 -91
  130. package/dist/memory/migrate.d.ts +0 -15
  131. package/dist/memory/migrate.js +0 -364
  132. package/dist/playbooks/task-loop.md +0 -90
  133. package/dist/tasks/artifact-subject.d.ts +0 -40
  134. package/dist/tasks/artifact-subject.js +0 -334
  135. package/dist/tasks/cycle.d.ts +0 -48
  136. package/dist/tasks/cycle.js +0 -94
  137. package/dist/tasks/rounds.d.ts +0 -41
  138. package/dist/tasks/rounds.js +0 -53
  139. package/dist/tasks/task-events.d.ts +0 -6
  140. package/dist/tasks/task-events.js +0 -14
  141. package/dist/tasks/task-schedule.d.ts +0 -18
  142. package/dist/tasks/task-schedule.js +0 -50
  143. package/dist/tasks/verification.d.ts +0 -114
  144. package/dist/tasks/verification.js +0 -226
@@ -1,114 +0,0 @@
1
- import type { WorkspaceSubjectHashOptions } from "./artifact-subject.js";
2
- export type VerificationVerdict = "pass" | "fail";
3
- export type VerificationSubjectMode = "legacy-head" | "base-relative";
4
- /**
5
- * A verifier's verdict, recorded on disk beside the task (spec 036, D6).
6
- *
7
- * This file is the anti-self-certification core: the task Markdown is writable by the agent's
8
- * own write/edit tools, so a hand-written `status: "passed"` proves nothing. Every field here
9
- * is re-checked at `complete`, which is why the set is exactly the fields something reads —
10
- * `agent`, `model` and `outputHash` were stored and strictly validated but never once
11
- * consulted, so they are gone.
12
- */
13
- export interface VerificationAttestation {
14
- version: 1;
15
- runId: string;
16
- taskId: string;
17
- verdict: VerificationVerdict;
18
- checkedAt: string;
19
- bodyHash: string;
20
- evidence: string;
21
- workspaceChanged: boolean;
22
- /** Git subject that the verifier actually inspected. */
23
- subjectHash?: string;
24
- /**
25
- * The checkout `subjectHash` was computed in. Recorded so `verify` and `complete` recompute the
26
- * subject where the verifier looked, not wherever the daemon happens to be running: a
27
- * sub-agent may be pointed at another checkout via `workingDirectory`, and comparing that
28
- * verdict against the daemon's own cwd would either fail closed forever or — worse — compare
29
- * a PASS against an unrelated repository. Absent on attestations written before this field.
30
- */
31
- subjectDir?: string;
32
- /**
33
- * New attestations use a fixed base commit and compare the current content relative to it. The
34
- * old field-less form is the legacy HEAD-sensitive subject and is retained for compatibility.
35
- */
36
- subjectMode?: VerificationSubjectMode;
37
- /** Commit recorded before the verifier started, for `subjectMode: "base-relative"`. */
38
- subjectBaseCommit?: string;
39
- /** Untracked paths, plus ignored non-transient paths, present at verification start; existing
40
- * paths remain protected even when new files under the explicit transient-artifact scope are
41
- * allowed. Ignored paths inside that explicit scope are treated as generated at every snapshot. */
42
- subjectBaselineUntrackedPaths?: string[];
43
- /**
44
- * `enforced` — a built-in verifier that could not write at all: write/edit are structurally
45
- * removed before it runs, and its role declared no `bash` either (a real gate). `advisory` —
46
- * every other shape: an external verifier (spec 040, D9), whose tools cannot be removed so the
47
- * verdict rests on the target CLI's own sandbox flag plus the workspace hash, and a built-in
48
- * verifier that kept `bash`, which can write files just as well as `write` can. Defaults to
49
- * `enforced` for attestations written before this field existed — every verifier was built-in
50
- * and this distinction did not exist then.
51
- */
52
- verificationStrength: "enforced" | "advisory";
53
- }
54
- /**
55
- * Trusted context supplied by a task consumer from the persisted sub-agent run record. The
56
- * attestation file is evidence, not the authority for which checkout was verified.
57
- */
58
- export interface VerificationAttestationReadOptions {
59
- trustedWorkingDirectory?: string;
60
- }
61
- export declare function verificationDir(channelDir: string): string;
62
- export declare function verificationAttestationPath(channelDir: string, runId: string): string;
63
- export declare function parseVerificationVerdict(output: string): VerificationVerdict | undefined;
64
- /** Translate an attestation's subject metadata into the hash options used by verify/close. */
65
- export declare function getVerificationSubjectHashOptions(attestation: Pick<VerificationAttestation, "subjectMode" | "subjectBaseCommit" | "subjectBaselineUntrackedPaths">): WorkspaceSubjectHashOptions | undefined;
66
- export declare function writeVerificationAttestation(channelDir: string, input: Omit<VerificationAttestation, "version" | "bodyHash">): Promise<VerificationAttestation>;
67
- export declare function readVerificationAttestation(channelDir: string, runId: string, options?: VerificationAttestationReadOptions): Promise<VerificationAttestation>;
68
- /**
69
- * Everything `task_verify` used to check before it would import an attestation (spec 051, D7).
70
- *
71
- * The checks are unchanged; only the caller moved. Importing a verifier's verdict is bookkeeping
72
- * the runtime already has the facts for at settlement, so it happens there — but it must still
73
- * fail closed, because the task Markdown is agent-writable and proves nothing on its own (spec
74
- * 040's threat model). Returns the reason it is not acceptable, or `undefined` when it is.
75
- */
76
- export declare function attestationRejectionReason(input: {
77
- channelDir: string;
78
- taskId: string;
79
- runId: string;
80
- taskBody: string;
81
- trustedWorkingDirectory?: string;
82
- fallbackWorkingDirectory?: string;
83
- }): Promise<string | undefined>;
84
- /**
85
- * How a cycle's rework rounds are consumed when deciding whether a task may close (spec 051, D7).
86
- *
87
- * Recording a round at settlement proved the attestation *then*. It cannot prove it *now*: the
88
- * task Markdown and the workspace are both agent-writable between the verifier's PASS and the
89
- * close, so a contract edit or a further code change after the PASS would sail through a check
90
- * that only asks "did a PASS ever land in this cycle". That was the shape of the hole — both
91
- * close entry points asked exactly that.
92
- *
93
- * Two rules, deliberately simple:
94
- * - The candidate is the cycle's *last* round, not any PASS in it. A later FAIL is newer evidence
95
- * about the same artifact and must not be overridden by an earlier PASS.
96
- * - That candidate's attestation is re-checked against the contract and the checkout as they are
97
- * at close time, reusing `attestationRejectionReason` rather than a second proof model.
98
- */
99
- export interface CompletionVerificationInput {
100
- channelDir: string;
101
- taskId: string;
102
- taskBody: string;
103
- cycleId: string | undefined;
104
- /**
105
- * The checkout persisted for a verify run, from the sub-agent run registry. The attestation
106
- * file names its own `subjectDir`, but that file is evidence, not the authority for which
107
- * checkout was verified — so a run whose record is gone fails closed rather than falling back
108
- * to whatever directory the daemon happens to be in.
109
- */
110
- findRunWorkingDirectory: (runId: string) => string | undefined;
111
- fallbackWorkingDirectory?: string;
112
- }
113
- /** Why this task may not be closed as done, or `undefined` when its verification still holds. */
114
- export declare function completionVerificationBlockReason(input: CompletionVerificationInput): Promise<string | undefined>;
@@ -1,226 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import { realpathSync, statSync } from "node:fs";
3
- import { mkdir, readFile } from "node:fs/promises";
4
- import { isAbsolute, join, win32 } from "node:path";
5
- import { writeFileAtomically } from "../shared/atomic-file.js";
6
- import { parseLocalTime } from "../shared/local-time.js";
7
- import { errorMessage } from "../shared/text-utils.js";
8
- import { workspaceSubjectHash } from "./artifact-subject.js";
9
- import { taskBodyHash } from "./ledger.js";
10
- import { readCycleRounds } from "./rounds.js";
11
- import { readStoredTask } from "./store.js";
12
- const FULL_COMMIT_PATTERN = /^[a-f0-9]{40}(?:[a-f0-9]{24})?$/i;
13
- function attestationFilename(runId) {
14
- return `${createHash("sha256").update(runId).digest("hex")}.json`;
15
- }
16
- export function verificationDir(channelDir) {
17
- return join(channelDir, "tasks", ".verifications");
18
- }
19
- export function verificationAttestationPath(channelDir, runId) {
20
- return join(verificationDir(channelDir), attestationFilename(runId));
21
- }
22
- export function parseVerificationVerdict(output) {
23
- const value = /(?:^|\n)VERDICT:\s*(PASS|FAIL)\s*$/i.exec(output.trim())?.[1]?.toLowerCase();
24
- return value === "pass" || value === "fail" ? value : undefined;
25
- }
26
- /** Translate an attestation's subject metadata into the hash options used by verify/close. */
27
- export function getVerificationSubjectHashOptions(attestation) {
28
- if (attestation.subjectMode !== "base-relative" && attestation.subjectBaseCommit === undefined)
29
- return undefined;
30
- if (attestation.subjectBaseCommit === undefined)
31
- return undefined;
32
- if (attestation.subjectMode === "base-relative" && attestation.subjectBaselineUntrackedPaths === undefined)
33
- return undefined;
34
- return {
35
- baseCommit: attestation.subjectBaseCommit,
36
- baselineUntrackedPaths: attestation.subjectBaselineUntrackedPaths ?? [],
37
- };
38
- }
39
- export async function writeVerificationAttestation(channelDir, input) {
40
- const task = await readStoredTask(channelDir, input.taskId);
41
- if (!task)
42
- throw new Error(`Cannot attest verification: task "${input.taskId}" does not exist.`);
43
- const hasSubjectHash = input.subjectHash !== undefined;
44
- const subjectMode = hasSubjectHash
45
- ? (input.subjectMode ?? (input.subjectBaseCommit !== undefined ? "base-relative" : "legacy-head"))
46
- : input.subjectMode;
47
- if (subjectMode === "base-relative" &&
48
- (input.subjectBaseCommit === undefined ||
49
- !FULL_COMMIT_PATTERN.test(input.subjectBaseCommit.trim()) ||
50
- !input.subjectBaselineUntrackedPaths)) {
51
- throw new Error("Cannot attest verification: base-relative subject metadata is incomplete.");
52
- }
53
- if (subjectMode === "legacy-head" &&
54
- (input.subjectBaseCommit !== undefined || input.subjectBaselineUntrackedPaths !== undefined)) {
55
- throw new Error("Cannot attest verification: legacy-head subject cannot carry base-relative metadata.");
56
- }
57
- if (!hasSubjectHash &&
58
- (subjectMode !== undefined ||
59
- input.subjectBaseCommit !== undefined ||
60
- input.subjectBaselineUntrackedPaths !== undefined)) {
61
- throw new Error("Cannot attest verification: subject metadata requires a subject hash.");
62
- }
63
- const attestation = {
64
- version: 1,
65
- runId: input.runId,
66
- taskId: input.taskId,
67
- verdict: input.verdict,
68
- checkedAt: input.checkedAt,
69
- bodyHash: taskBodyHash(task.body),
70
- evidence: input.evidence,
71
- workspaceChanged: input.workspaceChanged,
72
- subjectHash: input.subjectHash,
73
- subjectDir: hasSubjectHash ? input.subjectDir : undefined,
74
- subjectMode,
75
- subjectBaseCommit: subjectMode === "base-relative" ? input.subjectBaseCommit : undefined,
76
- subjectBaselineUntrackedPaths: subjectMode === "base-relative" ? [...(input.subjectBaselineUntrackedPaths ?? [])] : undefined,
77
- verificationStrength: input.verificationStrength,
78
- };
79
- await mkdir(verificationDir(channelDir), { recursive: true });
80
- await writeFileAtomically(verificationAttestationPath(channelDir, input.runId), `${JSON.stringify(attestation, null, 2)}\n`);
81
- return attestation;
82
- }
83
- function canonicalDirectory(path) {
84
- try {
85
- const canonical = realpathSync(path);
86
- return statSync(canonical).isDirectory() ? canonical : undefined;
87
- }
88
- catch {
89
- return undefined;
90
- }
91
- }
92
- function bindSubjectDirectory(runId, subjectDir, options) {
93
- if (!options || subjectDir === undefined)
94
- return subjectDir;
95
- if (!options.trustedWorkingDirectory) {
96
- throw new Error(`Verification run "${runId}" has a subjectDir but no persisted workingDirectory is available; refusing to trust this attestation. Rerun the verifier.`);
97
- }
98
- const canonicalSubjectDir = canonicalDirectory(subjectDir);
99
- const canonicalWorkingDirectory = canonicalDirectory(options.trustedWorkingDirectory);
100
- if (!canonicalSubjectDir || !canonicalWorkingDirectory || canonicalSubjectDir !== canonicalWorkingDirectory) {
101
- throw new Error(`Verification run "${runId}" subjectDir does not match its persisted workingDirectory; refusing to trust this attestation. Rerun the verifier.`);
102
- }
103
- return canonicalSubjectDir;
104
- }
105
- export async function readVerificationAttestation(channelDir, runId, options) {
106
- let value;
107
- try {
108
- value = JSON.parse(await readFile(verificationAttestationPath(channelDir, runId), "utf-8"));
109
- }
110
- catch (error) {
111
- throw new Error(`Verification run "${runId}" was not found or is unreadable. Run a subagent with purpose=verify and taskId first. ${errorMessage(error)}`);
112
- }
113
- const raw = (typeof value === "object" && value !== null ? value : {});
114
- const subjectMode = raw.subjectMode !== undefined
115
- ? raw.subjectMode
116
- : raw.subjectBaseCommit !== undefined
117
- ? "base-relative"
118
- : "legacy-head";
119
- const safeSubjectPath = (path) => {
120
- const normalized = path.replaceAll("\\", "/");
121
- return (path.length > 0 &&
122
- !isAbsolute(path) &&
123
- !win32.isAbsolute(path) &&
124
- !path.includes("\0") &&
125
- !normalized.split("/").includes(".."));
126
- };
127
- if (typeof value !== "object" ||
128
- value === null ||
129
- raw.version !== 1 ||
130
- raw.runId !== runId ||
131
- typeof raw.taskId !== "string" ||
132
- (raw.verdict !== "pass" && raw.verdict !== "fail") ||
133
- typeof raw.checkedAt !== "string" ||
134
- parseLocalTime(raw.checkedAt) === undefined ||
135
- !/^[a-f0-9]{64}$/i.test(String(raw.bodyHash)) ||
136
- typeof raw.evidence !== "string" ||
137
- typeof raw.workspaceChanged !== "boolean" ||
138
- (raw.subjectHash !== undefined && !/^[a-f0-9]{64}$/i.test(String(raw.subjectHash))) ||
139
- (raw.subjectDir !== undefined && typeof raw.subjectDir !== "string") ||
140
- (raw.subjectMode !== undefined && subjectMode !== "legacy-head" && subjectMode !== "base-relative") ||
141
- (raw.subjectBaseCommit !== undefined &&
142
- (typeof raw.subjectBaseCommit !== "string" || !FULL_COMMIT_PATTERN.test(raw.subjectBaseCommit.trim()))) ||
143
- (raw.subjectBaselineUntrackedPaths !== undefined &&
144
- (!Array.isArray(raw.subjectBaselineUntrackedPaths) ||
145
- raw.subjectBaselineUntrackedPaths.some((path) => typeof path !== "string" || !safeSubjectPath(path)))) ||
146
- (raw.subjectHash === undefined &&
147
- (raw.subjectMode !== undefined ||
148
- raw.subjectBaseCommit !== undefined ||
149
- raw.subjectBaselineUntrackedPaths !== undefined)) ||
150
- (raw.subjectHash !== undefined &&
151
- (subjectMode === "base-relative"
152
- ? typeof raw.subjectBaseCommit !== "string" || !Array.isArray(raw.subjectBaselineUntrackedPaths)
153
- : raw.subjectBaseCommit !== undefined || raw.subjectBaselineUntrackedPaths !== undefined)) ||
154
- (raw.verificationStrength !== undefined &&
155
- raw.verificationStrength !== "enforced" &&
156
- raw.verificationStrength !== "advisory")) {
157
- throw new Error(`Verification run "${runId}" has an invalid attestation. Run the verifier again.`);
158
- }
159
- // Pre-spec-040 attestations predate this field; every verifier back then was built-in. When an
160
- // old attestation also lacks subjectDir, consumers may keep its legacy subject semantics. A
161
- // subjectDir-bearing attestation is newer and, when read by task lifecycle code, must be bound to
162
- // a still-available persisted run record instead of choosing an arbitrary checkout.
163
- const attestation = {
164
- ...value,
165
- subjectMode: subjectMode,
166
- verificationStrength: value.verificationStrength ?? "enforced",
167
- };
168
- const boundSubjectDir = bindSubjectDirectory(runId, attestation.subjectDir, options);
169
- return boundSubjectDir === attestation.subjectDir ? attestation : { ...attestation, subjectDir: boundSubjectDir };
170
- }
171
- /**
172
- * Everything `task_verify` used to check before it would import an attestation (spec 051, D7).
173
- *
174
- * The checks are unchanged; only the caller moved. Importing a verifier's verdict is bookkeeping
175
- * the runtime already has the facts for at settlement, so it happens there — but it must still
176
- * fail closed, because the task Markdown is agent-writable and proves nothing on its own (spec
177
- * 040's threat model). Returns the reason it is not acceptable, or `undefined` when it is.
178
- */
179
- export async function attestationRejectionReason(input) {
180
- let attestation;
181
- try {
182
- attestation = await readVerificationAttestation(input.channelDir, input.runId, {
183
- trustedWorkingDirectory: input.trustedWorkingDirectory,
184
- });
185
- }
186
- catch (error) {
187
- return errorMessage(error);
188
- }
189
- if (attestation.taskId !== input.taskId) {
190
- return `attestation belongs to task "${attestation.taskId}"`;
191
- }
192
- if (attestation.workspaceChanged) {
193
- return "verifier changed protected workspace content";
194
- }
195
- if (attestation.bodyHash !== taskBodyHash(input.taskBody)) {
196
- return "task contract changed after verification";
197
- }
198
- if (attestation.subjectHash) {
199
- const subjectDir = attestation.subjectDir ?? input.trustedWorkingDirectory ?? input.fallbackWorkingDirectory ?? process.cwd();
200
- const currentSubject = await workspaceSubjectHash(subjectDir, getVerificationSubjectHashOptions(attestation));
201
- if (!currentSubject)
202
- return "artifact subject checkout could not be read";
203
- if (currentSubject !== attestation.subjectHash)
204
- return "artifact subject changed after verification";
205
- }
206
- return undefined;
207
- }
208
- /** Why this task may not be closed as done, or `undefined` when its verification still holds. */
209
- export async function completionVerificationBlockReason(input) {
210
- const rounds = await readCycleRounds(input.channelDir, input.taskId, input.cycleId);
211
- const latest = rounds.at(-1);
212
- if (!latest)
213
- return "no verification round has landed in this cycle";
214
- if (latest.verdict !== "pass") {
215
- return `the latest verification round (#${latest.n}) is a FAIL${latest.reason ? `: ${latest.reason}` : ""}`;
216
- }
217
- const rejection = await attestationRejectionReason({
218
- channelDir: input.channelDir,
219
- taskId: input.taskId,
220
- runId: latest.verifyRunId,
221
- taskBody: input.taskBody,
222
- trustedWorkingDirectory: input.findRunWorkingDirectory(latest.verifyRunId),
223
- fallbackWorkingDirectory: input.fallbackWorkingDirectory,
224
- });
225
- return rejection ? `the PASS from round #${latest.n} no longer holds: ${rejection}` : undefined;
226
- }