@oyasmi/pipiclaw 0.9.2-beta.1 → 0.9.2-beta.2

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.
@@ -1,4 +1,6 @@
1
+ import type { WorkspaceSubjectHashOptions } from "./artifact-subject.js";
1
2
  export type VerificationVerdict = "pass" | "fail";
3
+ export type VerificationSubjectMode = "legacy-head" | "base-relative";
2
4
  /**
3
5
  * A verifier's verdict, recorded on disk beside the task (spec 036, D6).
4
6
  *
@@ -17,7 +19,7 @@ export interface VerificationAttestation {
17
19
  bodyHash: string;
18
20
  evidence: string;
19
21
  workspaceChanged: boolean;
20
- /** Git HEAD + working-tree subject that the verifier actually inspected. */
22
+ /** Git subject that the verifier actually inspected. */
21
23
  subjectHash?: string;
22
24
  /**
23
25
  * The checkout `subjectHash` was computed in. Recorded so `verify` and `complete` recompute the
@@ -27,6 +29,17 @@ export interface VerificationAttestation {
27
29
  * a PASS against an unrelated repository. Absent on attestations written before this field.
28
30
  */
29
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[];
30
43
  /**
31
44
  * `enforced` — a built-in verifier that could not write at all: write/edit are structurally
32
45
  * removed before it runs, and its role declared no `bash` either (a real gate). `advisory` —
@@ -38,8 +51,17 @@ export interface VerificationAttestation {
38
51
  */
39
52
  verificationStrength: "enforced" | "advisory";
40
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
+ }
41
61
  export declare function verificationDir(channelDir: string): string;
42
62
  export declare function verificationAttestationPath(channelDir: string, runId: string): string;
43
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;
44
66
  export declare function writeVerificationAttestation(channelDir: string, input: Omit<VerificationAttestation, "version" | "bodyHash">): Promise<VerificationAttestation>;
45
- export declare function readVerificationAttestation(channelDir: string, runId: string): Promise<VerificationAttestation>;
67
+ export declare function readVerificationAttestation(channelDir: string, runId: string, options?: VerificationAttestationReadOptions): Promise<VerificationAttestation>;
@@ -1,10 +1,12 @@
1
1
  import { createHash } from "node:crypto";
2
+ import { realpathSync, statSync } from "node:fs";
2
3
  import { mkdir, readFile } from "node:fs/promises";
3
- import { join } from "node:path";
4
+ import { isAbsolute, join, win32 } from "node:path";
4
5
  import { writeFileAtomically } from "../shared/atomic-file.js";
5
6
  import { parseLocalTime } from "../shared/local-time.js";
6
7
  import { errorMessage } from "../shared/text-utils.js";
7
8
  import { readStoredTask, taskBodyHash } from "./store.js";
9
+ const FULL_COMMIT_PATTERN = /^[a-f0-9]{40}(?:[a-f0-9]{24})?$/i;
8
10
  function attestationFilename(runId) {
9
11
  return `${createHash("sha256").update(runId).digest("hex")}.json`;
10
12
  }
@@ -18,10 +20,43 @@ export function parseVerificationVerdict(output) {
18
20
  const value = /(?:^|\n)VERDICT:\s*(PASS|FAIL)\s*$/i.exec(output.trim())?.[1]?.toLowerCase();
19
21
  return value === "pass" || value === "fail" ? value : undefined;
20
22
  }
23
+ /** Translate an attestation's subject metadata into the hash options used by verify/close. */
24
+ export function getVerificationSubjectHashOptions(attestation) {
25
+ if (attestation.subjectMode !== "base-relative" && attestation.subjectBaseCommit === undefined)
26
+ return undefined;
27
+ if (attestation.subjectBaseCommit === undefined)
28
+ return undefined;
29
+ if (attestation.subjectMode === "base-relative" && attestation.subjectBaselineUntrackedPaths === undefined)
30
+ return undefined;
31
+ return {
32
+ baseCommit: attestation.subjectBaseCommit,
33
+ baselineUntrackedPaths: attestation.subjectBaselineUntrackedPaths ?? [],
34
+ };
35
+ }
21
36
  export async function writeVerificationAttestation(channelDir, input) {
22
37
  const task = await readStoredTask(channelDir, input.taskId);
23
38
  if (!task)
24
39
  throw new Error(`Cannot attest verification: task "${input.taskId}" does not exist.`);
40
+ const hasSubjectHash = input.subjectHash !== undefined;
41
+ const subjectMode = hasSubjectHash
42
+ ? (input.subjectMode ?? (input.subjectBaseCommit !== undefined ? "base-relative" : "legacy-head"))
43
+ : input.subjectMode;
44
+ if (subjectMode === "base-relative" &&
45
+ (input.subjectBaseCommit === undefined ||
46
+ !FULL_COMMIT_PATTERN.test(input.subjectBaseCommit.trim()) ||
47
+ !input.subjectBaselineUntrackedPaths)) {
48
+ throw new Error("Cannot attest verification: base-relative subject metadata is incomplete.");
49
+ }
50
+ if (subjectMode === "legacy-head" &&
51
+ (input.subjectBaseCommit !== undefined || input.subjectBaselineUntrackedPaths !== undefined)) {
52
+ throw new Error("Cannot attest verification: legacy-head subject cannot carry base-relative metadata.");
53
+ }
54
+ if (!hasSubjectHash &&
55
+ (subjectMode !== undefined ||
56
+ input.subjectBaseCommit !== undefined ||
57
+ input.subjectBaselineUntrackedPaths !== undefined)) {
58
+ throw new Error("Cannot attest verification: subject metadata requires a subject hash.");
59
+ }
25
60
  const attestation = {
26
61
  version: 1,
27
62
  runId: input.runId,
@@ -32,14 +67,39 @@ export async function writeVerificationAttestation(channelDir, input) {
32
67
  evidence: input.evidence,
33
68
  workspaceChanged: input.workspaceChanged,
34
69
  subjectHash: input.subjectHash,
35
- subjectDir: input.subjectHash ? input.subjectDir : undefined,
70
+ subjectDir: hasSubjectHash ? input.subjectDir : undefined,
71
+ subjectMode,
72
+ subjectBaseCommit: subjectMode === "base-relative" ? input.subjectBaseCommit : undefined,
73
+ subjectBaselineUntrackedPaths: subjectMode === "base-relative" ? [...(input.subjectBaselineUntrackedPaths ?? [])] : undefined,
36
74
  verificationStrength: input.verificationStrength,
37
75
  };
38
76
  await mkdir(verificationDir(channelDir), { recursive: true });
39
77
  await writeFileAtomically(verificationAttestationPath(channelDir, input.runId), `${JSON.stringify(attestation, null, 2)}\n`);
40
78
  return attestation;
41
79
  }
42
- export async function readVerificationAttestation(channelDir, runId) {
80
+ function canonicalDirectory(path) {
81
+ try {
82
+ const canonical = realpathSync(path);
83
+ return statSync(canonical).isDirectory() ? canonical : undefined;
84
+ }
85
+ catch {
86
+ return undefined;
87
+ }
88
+ }
89
+ function bindSubjectDirectory(runId, subjectDir, options) {
90
+ if (!options || subjectDir === undefined)
91
+ return subjectDir;
92
+ if (!options.trustedWorkingDirectory) {
93
+ throw new Error(`Verification run "${runId}" has a subjectDir but no persisted workingDirectory is available; refusing to trust this attestation. Rerun the verifier.`);
94
+ }
95
+ const canonicalSubjectDir = canonicalDirectory(subjectDir);
96
+ const canonicalWorkingDirectory = canonicalDirectory(options.trustedWorkingDirectory);
97
+ if (!canonicalSubjectDir || !canonicalWorkingDirectory || canonicalSubjectDir !== canonicalWorkingDirectory) {
98
+ throw new Error(`Verification run "${runId}" subjectDir does not match its persisted workingDirectory; refusing to trust this attestation. Rerun the verifier.`);
99
+ }
100
+ return canonicalSubjectDir;
101
+ }
102
+ export async function readVerificationAttestation(channelDir, runId, options) {
43
103
  let value;
44
104
  try {
45
105
  value = JSON.parse(await readFile(verificationAttestationPath(channelDir, runId), "utf-8"));
@@ -47,29 +107,61 @@ export async function readVerificationAttestation(channelDir, runId) {
47
107
  catch (error) {
48
108
  throw new Error(`Verification run "${runId}" was not found or is unreadable. Run a subagent with purpose=verify and taskId first. ${errorMessage(error)}`);
49
109
  }
110
+ const raw = (typeof value === "object" && value !== null ? value : {});
111
+ const subjectMode = raw.subjectMode !== undefined
112
+ ? raw.subjectMode
113
+ : raw.subjectBaseCommit !== undefined
114
+ ? "base-relative"
115
+ : "legacy-head";
116
+ const safeSubjectPath = (path) => {
117
+ const normalized = path.replaceAll("\\", "/");
118
+ return (path.length > 0 &&
119
+ !isAbsolute(path) &&
120
+ !win32.isAbsolute(path) &&
121
+ !path.includes("\0") &&
122
+ !normalized.split("/").includes(".."));
123
+ };
50
124
  if (typeof value !== "object" ||
51
125
  value === null ||
52
- value.version !== 1 ||
53
- value.runId !== runId ||
54
- typeof value.taskId !== "string" ||
55
- (value.verdict !== "pass" && value.verdict !== "fail") ||
56
- typeof value.checkedAt !== "string" ||
57
- parseLocalTime(value.checkedAt) === undefined ||
58
- !/^[a-f0-9]{64}$/i.test(String(value.bodyHash)) ||
59
- typeof value.evidence !== "string" ||
60
- typeof value.workspaceChanged !== "boolean" ||
61
- (value.subjectHash !== undefined &&
62
- !/^[a-f0-9]{64}$/i.test(String(value.subjectHash))) ||
63
- (value.subjectDir !== undefined &&
64
- typeof value.subjectDir !== "string") ||
65
- (value.verificationStrength !== undefined &&
66
- value.verificationStrength !== "enforced" &&
67
- value.verificationStrength !== "advisory")) {
126
+ raw.version !== 1 ||
127
+ raw.runId !== runId ||
128
+ typeof raw.taskId !== "string" ||
129
+ (raw.verdict !== "pass" && raw.verdict !== "fail") ||
130
+ typeof raw.checkedAt !== "string" ||
131
+ parseLocalTime(raw.checkedAt) === undefined ||
132
+ !/^[a-f0-9]{64}$/i.test(String(raw.bodyHash)) ||
133
+ typeof raw.evidence !== "string" ||
134
+ typeof raw.workspaceChanged !== "boolean" ||
135
+ (raw.subjectHash !== undefined && !/^[a-f0-9]{64}$/i.test(String(raw.subjectHash))) ||
136
+ (raw.subjectDir !== undefined && typeof raw.subjectDir !== "string") ||
137
+ (raw.subjectMode !== undefined && subjectMode !== "legacy-head" && subjectMode !== "base-relative") ||
138
+ (raw.subjectBaseCommit !== undefined &&
139
+ (typeof raw.subjectBaseCommit !== "string" || !FULL_COMMIT_PATTERN.test(raw.subjectBaseCommit.trim()))) ||
140
+ (raw.subjectBaselineUntrackedPaths !== undefined &&
141
+ (!Array.isArray(raw.subjectBaselineUntrackedPaths) ||
142
+ raw.subjectBaselineUntrackedPaths.some((path) => typeof path !== "string" || !safeSubjectPath(path)))) ||
143
+ (raw.subjectHash === undefined &&
144
+ (raw.subjectMode !== undefined ||
145
+ raw.subjectBaseCommit !== undefined ||
146
+ raw.subjectBaselineUntrackedPaths !== undefined)) ||
147
+ (raw.subjectHash !== undefined &&
148
+ (subjectMode === "base-relative"
149
+ ? typeof raw.subjectBaseCommit !== "string" || !Array.isArray(raw.subjectBaselineUntrackedPaths)
150
+ : raw.subjectBaseCommit !== undefined || raw.subjectBaselineUntrackedPaths !== undefined)) ||
151
+ (raw.verificationStrength !== undefined &&
152
+ raw.verificationStrength !== "enforced" &&
153
+ raw.verificationStrength !== "advisory")) {
68
154
  throw new Error(`Verification run "${runId}" has an invalid attestation. Run the verifier again.`);
69
155
  }
70
- // Pre-spec-040 attestations predate this field; every verifier back then was built-in.
71
- return {
156
+ // Pre-spec-040 attestations predate this field; every verifier back then was built-in. When an
157
+ // old attestation also lacks subjectDir, consumers may keep its legacy subject semantics. A
158
+ // subjectDir-bearing attestation is newer and, when read by task lifecycle code, must be bound to
159
+ // a still-available persisted run record instead of choosing an arbitrary checkout.
160
+ const attestation = {
72
161
  ...value,
162
+ subjectMode: subjectMode,
73
163
  verificationStrength: value.verificationStrength ?? "enforced",
74
164
  };
165
+ const boundSubjectDir = bindSubjectDirectory(runId, attestation.subjectDir, options);
166
+ return boundSubjectDir === attestation.subjectDir ? attestation : { ...attestation, subjectDir: boundSubjectDir };
75
167
  }
@@ -198,9 +198,9 @@ export function createSubAgentRunTool(options) {
198
198
  if (role.shell) {
199
199
  throw new RecoverableToolError(`Role "${record.agent}" runs its command through a shell, which has no way to carry a resume session id. Delegate a new run instead, carrying forward whatever context it needs.`);
200
200
  }
201
- // Spec 042 D7: verify admission is re-checked against the *current* role config, shared
202
- // with the initial dispatch — a role hot-edited to mutates: write since the original run
203
- // must not silently take the write lease and dispatch just because it once was read-only.
201
+ // Verify admission is re-checked against the *current* role config, shared with the initial
202
+ // dispatch. A write-capable verify follow-up takes the same exclusive lease as any writer;
203
+ // `exec` remains barred because it has no verification protocol terminal.
204
204
  assertVerifyAdmissible(role, record.purpose, record.workingDirectory);
205
205
  // Spec 042 D7: a role hot-edited since the original dispatch (different command, model,
206
206
  // or shell mode) would resume the old session under a harness invocation it never wrote.
@@ -245,19 +245,19 @@ export function createSubAgentRunTool(options) {
245
245
  // inside `buildContextualBlocks` — optional here so a caller that only ever exercises
246
246
  // list/cancel is not forced to wire an LLM-backed dependency it will never use. Absent
247
247
  // either, context blocks degrade to none rather than guessing at a model or key.
248
- const contextualBlocks = options.getCurrentModel && options.resolveApiKey
249
- ? await buildContextualBlocks(task, role, {
250
- channelDir: options.channelDir,
251
- workspaceDir: options.workspaceDir,
252
- runtimeContext: { workspaceDir: options.workspaceDir, channelId: options.channelId },
253
- getMemoryRecallSettings: options.getMemoryRecallSettings,
254
- resolveApiKey: options.resolveApiKey,
255
- memoryCandidateStore: options.memoryCandidateStore,
256
- }, options.getCurrentModel())
257
- : [];
258
- const envelopedTask = buildSubAgentTask(task, role, { workspaceDir: options.workspaceDir, channelId: options.channelId }, contextualBlocks, runContext);
259
248
  let launchResult;
260
249
  try {
250
+ const contextualBlocks = options.getCurrentModel && options.resolveApiKey
251
+ ? await buildContextualBlocks(task, role, {
252
+ channelDir: options.channelDir,
253
+ workspaceDir: options.workspaceDir,
254
+ runtimeContext: { workspaceDir: options.workspaceDir, channelId: options.channelId },
255
+ getMemoryRecallSettings: options.getMemoryRecallSettings,
256
+ resolveApiKey: options.resolveApiKey,
257
+ memoryCandidateStore: options.memoryCandidateStore,
258
+ }, options.getCurrentModel())
259
+ : [];
260
+ const envelopedTask = buildSubAgentTask(task, role, { workspaceDir: options.workspaceDir, channelId: options.channelId }, contextualBlocks, runContext);
261
261
  launchResult = await launchExternalRun({
262
262
  runId: newRunId,
263
263
  channelId: options.channelId,
@@ -2,10 +2,12 @@ import { mkdir, rename } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
3
  import { writeFileAtomically } from "../../shared/atomic-file.js";
4
4
  import { formatLocalTime } from "../../shared/local-time.js";
5
+ import { getSubAgentRunManager } from "../../subagents/runs.js";
5
6
  import { workspaceSubjectHash } from "../../tasks/artifact-subject.js";
6
7
  import { appendCurrentCycleNote, applyTaskPlanPatch, normalizeTaskId, readActiveTasks, uncheckedTaskAcceptanceItems, } from "../../tasks/ledger.js";
7
8
  import { taskBodyHash } from "../../tasks/store.js";
8
9
  import { normalizeStoredStatus, resolveTaskTransition } from "../../tasks/transitions.js";
10
+ import { getVerificationSubjectHashOptions } from "../../tasks/verification.js";
9
11
  import { RecoverableToolError } from "../tool-details.js";
10
12
  import { appendCompletionEvidence, applySet, cleanupTaskEvents, describeTaskSchedule, markdownValue, readTaskDocument, renderTaskFile, requiredField, tasksDir, } from "./shared.js";
11
13
  import { assertVerificationAttestationMatches } from "./verification.js";
@@ -75,15 +77,16 @@ async function closeAsComplete(options, id, request) {
75
77
  }
76
78
  // The attestation file is the sole authority — for the verdict, the body-hash freshness
77
79
  // check, and the artifact subject. The task Markdown is agent-writable and proves nothing.
78
- const attestation = await assertVerificationAttestationMatches(options.channelDir, id, verification.runId, taskBodyHash(body));
80
+ const trustedWorkingDirectory = getSubAgentRunManager(options.channelId).get(verification.runId)?.workingDirectory;
81
+ const attestation = await assertVerificationAttestationMatches(options.channelDir, id, verification.runId, taskBodyHash(body), trustedWorkingDirectory);
79
82
  if (attestation.subjectHash) {
80
- const subjectDir = attestation.subjectDir ?? options.workingDirectory ?? process.cwd();
81
- const currentSubject = await workspaceSubjectHash(subjectDir);
83
+ const subjectDir = attestation.subjectDir ?? trustedWorkingDirectory ?? options.workingDirectory ?? process.cwd();
84
+ const currentSubject = await workspaceSubjectHash(subjectDir, getVerificationSubjectHashOptions(attestation));
82
85
  if (!currentSubject) {
83
86
  throw new RecoverableToolError(`Task "${id}" has an independent PASS bound to ${subjectDir}, but that checkout cannot be read. Restore it or request verification again.`);
84
87
  }
85
88
  if (currentSubject !== attestation.subjectHash) {
86
- throw new RecoverableToolError(`Task "${id}" artifacts changed after its independent PASS; request verification again.`);
89
+ throw new RecoverableToolError(`Task "${id}" artifacts changed after its independent PASS; request verification again. If this is a legacy attestation without a base commit, a normal Git commit can also require re-verification.`);
87
90
  }
88
91
  }
89
92
  // advisory means runtime could not structurally prove the verifier left artifacts alone
@@ -16,4 +16,4 @@ export declare function verifyTask(options: TaskManageToolOptions, request: Task
16
16
  * against the task's *current* body hash directly — not a mirrored value the task file could
17
17
  * itself have drifted.
18
18
  */
19
- export declare function assertVerificationAttestationMatches(channelDir: string, id: string, runId: string | undefined, currentBodyHash: string): Promise<VerificationAttestation>;
19
+ export declare function assertVerificationAttestationMatches(channelDir: string, id: string, runId: string | undefined, currentBodyHash: string, trustedWorkingDirectory?: string): Promise<VerificationAttestation>;
@@ -1,10 +1,11 @@
1
1
  import { writeFileAtomically } from "../../shared/atomic-file.js";
2
+ import { getSubAgentRunManager } from "../../subagents/runs.js";
2
3
  import { workspaceSubjectHash } from "../../tasks/artifact-subject.js";
3
4
  import { createDefaultTaskControl } from "../../tasks/control.js";
4
5
  import { normalizeTaskId } from "../../tasks/ledger.js";
5
6
  import { readStoredTask, taskBodyHash } from "../../tasks/store.js";
6
7
  import { normalizeStoredStatus, resolveTaskTransition } from "../../tasks/transitions.js";
7
- import { readVerificationAttestation } from "../../tasks/verification.js";
8
+ import { getVerificationSubjectHashOptions, readVerificationAttestation, } from "../../tasks/verification.js";
8
9
  import { RecoverableToolError } from "../tool-details.js";
9
10
  import { renderTaskFile } from "./shared.js";
10
11
  /**
@@ -21,23 +22,27 @@ export async function verifyTask(options, request) {
21
22
  if (!task)
22
23
  throw new RecoverableToolError(`Task "${id}" does not exist; create it before verification.`);
23
24
  resolveTaskTransition("verify", id, normalizeStoredStatus(task.fields.status));
24
- const attestation = await readVerificationAttestation(options.channelDir, runId);
25
+ const trustedWorkingDirectory = getSubAgentRunManager(options.channelId).get(runId)?.workingDirectory;
26
+ const attestation = await readVerificationAttestation(options.channelDir, runId, {
27
+ trustedWorkingDirectory,
28
+ });
25
29
  if (attestation.taskId !== id) {
26
30
  throw new RecoverableToolError(`Verification run "${runId}" belongs to task "${attestation.taskId}", not "${id}".`);
27
31
  }
28
32
  if (attestation.workspaceChanged) {
29
- throw new RecoverableToolError(`Verification run "${runId}" changed the workspace; rerun a read-only verifier.`);
33
+ throw new RecoverableToolError(`Verification run "${runId}" changed protected workspace content; rerun the verifier on the current content. Test/build outputs under the documented transient artifact scope are allowed, but implementation changes are not.`);
30
34
  }
31
35
  if (attestation.bodyHash !== taskBodyHash(task.body)) {
32
36
  throw new RecoverableToolError(`Task "${id}" changed after verification run "${runId}"; rerun the verifier on current content.`);
33
37
  }
34
38
  if (attestation.subjectHash) {
35
- const currentSubject = await workspaceSubjectHash(attestation.subjectDir ?? options.workingDirectory ?? process.cwd());
39
+ const subjectDir = attestation.subjectDir ?? trustedWorkingDirectory ?? options.workingDirectory ?? process.cwd();
40
+ const currentSubject = await workspaceSubjectHash(subjectDir, getVerificationSubjectHashOptions(attestation));
36
41
  if (!currentSubject) {
37
42
  throw new RecoverableToolError(`Verification run "${runId}" is bound to a Git artifact subject, but the current checkout cannot be read. Rerun verification from the project checkout.`);
38
43
  }
39
44
  if (currentSubject !== attestation.subjectHash) {
40
- throw new RecoverableToolError(`Task "${id}" artifacts changed after verification run "${runId}"; rerun the verifier.`);
45
+ throw new RecoverableToolError(`Task "${id}" artifacts changed after verification run "${runId}"; rerun the verifier. Legacy attestations without a base commit are HEAD-sensitive and may also require re-verification after a normal Git commit.`);
41
46
  }
42
47
  }
43
48
  const control = task.fields.control ?? createDefaultTaskControl(true);
@@ -68,11 +73,11 @@ export async function verifyTask(options, request) {
68
73
  * against the task's *current* body hash directly — not a mirrored value the task file could
69
74
  * itself have drifted.
70
75
  */
71
- export async function assertVerificationAttestationMatches(channelDir, id, runId, currentBodyHash) {
76
+ export async function assertVerificationAttestationMatches(channelDir, id, runId, currentBodyHash, trustedWorkingDirectory) {
72
77
  if (!runId) {
73
78
  throw new RecoverableToolError(`Task "${id}" has no verification run id; rerun task_verify before task_close.`);
74
79
  }
75
- const attestation = await readVerificationAttestation(channelDir, runId);
80
+ const attestation = await readVerificationAttestation(channelDir, runId, { trustedWorkingDirectory });
76
81
  if (attestation.taskId !== id) {
77
82
  throw new RecoverableToolError(`Verification run "${runId}" belongs to task "${attestation.taskId}", not "${id}"; rerun verification.`);
78
83
  }
@@ -9,7 +9,7 @@
9
9
  * not raise SIGINT). The two-stage Ctrl-C policy lives in the app; here we just
10
10
  * surface the events.
11
11
  */
12
- import { CombinedAutocompleteProvider, Container, Editor, Loader, Markdown, matchesKey, ProcessTerminal, Text, TUI, } from "@earendil-works/pi-tui";
12
+ import { CombinedAutocompleteProvider, Container, Editor, Loader, Markdown, matchesKey, ProcessTerminal, Text, TuiMainScreen, } from "@earendil-works/pi-tui";
13
13
  import { bold, cyan, dim, gray, italic, red, strikethrough, underline, yellow } from "./colors.js";
14
14
  const MARKDOWN_THEME = {
15
15
  heading: (t) => bold(cyan(t)),
@@ -45,7 +45,7 @@ export class PiTuiFrontend {
45
45
  this.editorContainer = new Container();
46
46
  this.turnProgress = [];
47
47
  this.spinnerShown = false;
48
- this.ui = new TUI(new ProcessTerminal(), true);
48
+ this.ui = new TuiMainScreen(new ProcessTerminal(), true);
49
49
  this.editor = new Editor(this.ui, EDITOR_THEME, { paddingX: 1 });
50
50
  this.loader = new Loader(this.ui, (s) => cyan(s), (s) => gray(s), "Working…");
51
51
  if (options.commands?.length) {
@@ -99,7 +99,7 @@ export class PiTuiFrontend {
99
99
  this.ui.requestRender();
100
100
  }
101
101
  showFinal(markdown) {
102
- this.transcript.addChild(new Markdown(markdown, 1, 1, MARKDOWN_THEME));
102
+ this.transcript.addChild(new Markdown(markdown, 1, 1, MARKDOWN_THEME, undefined, { renderLatex: false }));
103
103
  // The turn's progress becomes permanent scrollback; stop tracking it so a
104
104
  // later clearProgress cannot retract it.
105
105
  this.turnProgress = [];
@@ -45,22 +45,22 @@ planner(需求 / 方案 / 验收 / 拆解)
45
45
 
46
46
  reviewer 发现的问题回流给产出角色;verifier 失败回流给 builder,不在验证环节就地修复。闭环之外:worker 承接通用多步分析与产出,scout 只做单点事实查询。
47
47
 
48
- | 角色 | harness | `mutates` | `thinkingLevel` | 用途 |
49
- |---|---|---|---|---|
50
- | `planner` | claude-code (opus) | `read` | high | 只读需求收敛、方案设计、验收定义、任务拆解 |
51
- | `builder` | claude-code (sonnet) | `write` | medium | 边界清晰、验收已定义的实现 + 单元测试 |
52
- | `builder-hard` | claude-code (opus) | `write` | xhigh | builder 已失败、根因难定位或多契约耦合的实现 |
53
- | `reviewer` | codex-cli(只读沙箱) | `read` | high | 与产出者分离的方案 / 代码 / 文档挑错,也可承担只读 `purpose=verify` |
54
- | `verifier` | codex-cli(工作区写沙箱) | `write` | medium | 实际运行系统、复现、冒烟、回归、取证 |
55
- | `scout` | codex-cli(只读沙箱) | `read` | low | 大仓库里的单点事实查询 |
56
- | `worker` | codex-cli(工作区写沙箱) | `write` | medium | 闭环外的数据对比、指标计算、批量处理、专项报告 |
57
- | `documenter` | codex-cli(工作区写沙箱) | `write` | medium | 文档、变更记录和迁移说明;提交统一用 `git-committer` |
48
+ | 角色 | harness | `model` | `mutates` | `thinkingLevel` | 用途 |
49
+ |---|---|---|---|---|---|
50
+ | `planner` | claude-code | `opus` | `read` | high | 只读需求收敛、方案设计、验收定义、任务拆解 |
51
+ | `builder` | claude-code | `sonnet` | `write` | medium | 边界清晰、验收已定义的实现 + 单元测试 |
52
+ | `builder-hard` | claude-code | `opus` | `write` | xhigh | builder 已失败、根因难定位或多契约耦合的实现 |
53
+ | `reviewer` | codex-cli | `gpt-5.6-sol` | `read` | high | 与产出者分离的方案 / 代码 / 文档挑错,也可承担只读 `purpose=verify` |
54
+ | `verifier` | codex-cli | `gpt-5.6-luna` | `write` | high | 实际运行系统、复现、冒烟、回归、取证 |
55
+ | `scout` | codex-cli | `gpt-5.6-luna` | `read` | medium | 大仓库里的单点事实查询 |
56
+ | `worker` | codex-cli | `gpt-5.6-luna` | `write` | max | 闭环外的数据对比、指标计算、批量处理、专项报告 |
57
+ | `documenter` | codex-cli | `gpt-5.6-luna` | `write` | high | 文档、变更记录和迁移说明;提交统一用 `git-committer` |
58
58
 
59
59
  `planner` 用 Claude 的 `--permission-mode plan`,`reviewer` / `scout` 用 Codex 的 `--sandbox read-only`;三者的 `mutates: read` 都有目标 CLI 的权限模式支撑,而不只是提示词声明。它们不占工作区写锁,但评审仍应针对稳定的 diff / commit,不要一边让 builder 改同一工作树、一边评审移动中的目标。
60
60
 
61
- `reviewer` 的完整输出由 runtime 自动保存在 run 的 `output.md`,无需为了“落盘报告”给它工作区写权限。它可以承担 `purpose=verify`;runtime 会追加验收协议并检查工作区 subject 未变化。不过外部 attestation 仍是 `advisory`,而且只读沙箱会阻止产生工作区构建产物的测试,主代理需要按风险补充抽查或另派 verifier。
61
+ `reviewer` 的完整输出由 runtime 自动保存在 run 的 `output.md`,无需为了“落盘报告”给它工作区写权限。它可以承担不产生工作区写入的 `purpose=verify` 检查;runtime 会追加验收协议并检查工作区 subject 未变化。需要运行会生成产物的测试或构建时,应另派 `verifier`;外部 attestation 仍是 `advisory`,主代理需要按风险补充抽查。
62
62
 
63
- `verifier`、`worker`、`documenter` 使用 `--sandbox workspace-write`:足以在 checkout 和系统临时目录中生成测试或文档产物,同时不授予任意宿主文件访问。模板不让这些角色操作 Git 历史或外部系统;如任务确实需要网络、额外可写目录或更高权限,请复制角色后按目标 CLI 的能力最小化放宽,而不是把通用模板整体改成无沙箱。
63
+ `verifier`、`worker`、`documenter` 使用 `--sandbox workspace-write`:足以在 checkout 和系统临时目录中生成测试或文档产物,同时不授予任意宿主文件访问。`verifier` 用于 `purpose=verify` 时会持有目标工作区排他写锁,且 attestation 明确是 `advisory`;它可以生成 `.run/`、`coverage/`、`build/`、`dist/` 等约定临时产物,但不得修改被验收实现或既有 untracked 产品文件。模板不让这些角色操作 Git 历史或外部系统;如任务确实需要网络、额外可写目录或更高权限,请复制角色后按目标 CLI 的能力最小化放宽,而不是把通用模板整体改成无沙箱。
64
64
 
65
65
  `builder` / `builder-hard` 仍用 Claude 的 `--dangerously-skip-permissions`,因为它们需要非交互地完成实现;这是本目录权限最高的默认配置。务必在可信 checkout、最小权限宿主账号中使用。角色文件只声明 `model` 和 `thinkingLevel`,具体的 `--model` / `--effort` 参数由 claude-code harness 自动拼接,不应重复写进 `command`。
66
66
 
@@ -82,7 +82,7 @@ Pipiclaw 只加载工作区 `sub-agents/` 中实际存在且有效的 Markdown
82
82
  ## 需要按本机调整的地方
83
83
 
84
84
  - **`command` 用的是裸命令**(`claude` / `codex`),它们必须在 pipiclaw 进程的 `PATH` 上。如果你本机用的是包装脚本(换 base URL、换额度账号、注入环境变量),把 `command` 换成那个脚本即可——pipiclaw 只做 shell 词法分词,不解释命令内容。找不到可执行文件时角色不会消失,而是标为 `unavailable` 并在调用时给出安装提示。
85
- - **`model` 原样透传给目标 CLI,pipiclaw 不校验**。Claude 角色用了 `opus` / `sonnet`;Codex 角色**没有写 `model`**,交给 CLI 自身的默认配置——请按你的账号可用模型自行填写。
85
+ - **`model` 原样透传给目标 CLI,pipiclaw 不校验**。Claude 角色使用 `opus` / `sonnet`;Codex 角色使用 `gpt-5.6-sol` 或 `gpt-5.6-luna`。如果本机账号不可用,请按目标 CLI 支持的模型替换。
86
86
  - **目标 CLI 参数会变化**。模板按当前 Claude Code / Codex CLI 维护;升级 CLI 后先用 `claude --help`、`codex exec --help` 核对命令。Pipiclaw 只分词和追加协议参数,不会替你校验 flag 是否仍受支持。
87
87
  - **`--dangerously-skip-permissions`** 是 Claude Code 自身的权限跳过标记,Pipiclaw 原样传入。若不接受这个边界,只使用只读角色,或为写角色换成你已验证可在非交互模式工作的更严格权限配置。
88
88
  - **`maxWallTimeSec` 是墙钟上限**,超时会杀进程组但仍解析并回传已产生的输出。按仓库规模和任务量级调整,不要把示例值当成固定答案。
@@ -5,7 +5,8 @@ description: >-
5
5
  runtime: external
6
6
  harness: codex-cli
7
7
  command: codex exec --sandbox workspace-write --skip-git-repo-check
8
- thinkingLevel: medium
8
+ model: gpt-5.6-luna
9
+ thinkingLevel: high
9
10
  workload: heavy
10
11
  mutates: write
11
12
  maxWallTimeSec: 1800
@@ -5,6 +5,7 @@ description: >-
5
5
  runtime: external
6
6
  harness: codex-cli
7
7
  command: codex exec --sandbox read-only --skip-git-repo-check
8
+ model: gpt-5.6-sol
8
9
  thinkingLevel: high
9
10
  workload: heavy
10
11
  mutates: read
@@ -20,6 +21,7 @@ maxWallTimeSec: 1800
20
21
  - **方案**:边界是否收敛,是否适配现有架构,关键契约、迁移、回滚、风险和验收是否闭环。
21
22
  - **代码**:需求符合性、正确性、兼容性和安全性,重点检查边界、并发、错误处理、资源、数据完整性及漏改调用方。
22
23
  - **文档**:对照实现与配置核对事实,检查目标读者能否按步骤完成任务,以及前置、参数、失败处理和迁移是否完整。
24
+ - 需要启动测试或构建时不要把静态评审当作运行验收;本角色可承担 `purpose=verify` 的只读检查,但只适合不会产生工作区写入的检查。需要 `npm test`、`npm run build` 或其他可能生成产物的验证时,改派 `verifier`,并接受其 advisory attestation。
23
25
 
24
26
  ## 发现门槛
25
27
 
@@ -5,7 +5,8 @@ description: >-
5
5
  runtime: external
6
6
  harness: codex-cli
7
7
  command: codex exec --sandbox read-only --skip-git-repo-check
8
- thinkingLevel: low
8
+ model: gpt-5.6-luna
9
+ thinkingLevel: medium
9
10
  workload: heavy
10
11
  mutates: read
11
12
  maxWallTimeSec: 600
@@ -1,11 +1,12 @@
1
1
  ---
2
2
  name: verifier
3
3
  description: >-
4
- 重型运行验证(外部 Codex,可写工作区)。用于复现问题、启动系统、冒烟和回归,按验收项给出可复现的通过/失败/阻塞证据;不负责实现修复。测试可能生成构建产物,因此不能用于要求只读的 purpose=verify。
4
+ 重型运行验证(外部 Codex,可写工作区)。用于复现问题、启动系统、冒烟和回归,按验收项给出可复现的通过/失败/阻塞证据;不负责实现修复。可用于 purpose=verify,但会占用目标工作区排他写锁,attestation 为 advisory。
5
5
  runtime: external
6
6
  harness: codex-cli
7
7
  command: codex exec --sandbox workspace-write --skip-git-repo-check
8
- thinkingLevel: medium
8
+ model: gpt-5.6-luna
9
+ thinkingLevel: high
9
10
  workload: heavy
10
11
  mutates: write
11
12
  maxWallTimeSec: 3600
@@ -16,13 +17,14 @@ maxWallTimeSec: 3600
16
17
  ## 独立性与产物
17
18
 
18
19
  - 先读当前目录适用的仓库指令,记录待验证的 commit/diff 边界和初始状态。发现缺陷时先保存失败证据,不修改产品实现来让验证通过。
19
- - 可以创建验证脚本、夹具、测试数据和报告;优先放在仓库既有测试位置、忽略目录或系统临时目录,并记录用途。只清理本轮创建且可再生的产物。
20
+ - 可以创建验证脚本、夹具、测试数据和报告;优先放在仓库既有测试位置、`.run/`、`coverage/`、`build/`、`dist/` 等约定的临时产物目录或系统临时目录,并记录用途。验证期间新建的临时产物仅在 runtime 识别的明确范围内不计入 subject(Cypress 仅 `cypress/screenshots/`、`cypress/videos/`);验证开始前已存在的 untracked 文件,以及 ignored 的非临时产品文件始终受保护。`cypress/e2e/`、fixtures、support 和 downloads 不是临时产物。只清理本轮创建且可再生的产物。
21
+ - 即使角色声明 `mutates: write`,也不得修改被验收的实现、既有 untracked 产品文件,或为了通过测试而修代码;写锁只保证验证期间没有其他声明写入的委派并发运行,不是宿主机权限沙箱。
20
22
  - 不 commit、push、部署或修改共享环境,不写入真实生产数据。外部服务、凭据、费用、特权或不可逆操作缺失时,将对应条目标为阻塞并说明最小条件。
21
23
 
22
24
  ## 验证方法
23
25
 
24
26
  - 把每条验收标准转成可执行检查:前置环境、输入或操作、预期结果和取证方式。优先使用任务或仓库已有命令,不改写验收口径。
25
- - 顺序执行:环境与依赖预检 → 最小启动与健康检查 → 主路径冒烟 → 关键边界和失败路径 → 受影响范围的定向回归。是否执行全量回归或长时间性能测试,按验收计划、改动风险、可用环境和时间成本决定,并在报告中说明取舍。
27
+ - 顺序执行:环境与依赖预检 → 最小启动与健康检查 → 主路径冒烟 → 关键边界和失败路径 → 受影响范围的定向回归。是否执行全量回归或长时间性能测试,按验收计划、改动风险、可用环境和时间成本决定,并在报告中说明取舍。`purpose=verify` 的 PASS 是 advisory,必须报告实际 diff/subject 检查结果,不能只引用进程退出码。
26
28
  - 保留精确命令、退出码、关键输出或日志和必要的数据摘要。性能或效果结论需说明基线、样本、指标和允许偏差。
27
29
  - 对每项判定为**通过**、**失败**、**阻塞**或**不适用**。通过必须有实际执行证据;实际结果违反预期是失败;环境或输入缺失导致无法判定是阻塞;确认与本次变更无关的条目可标为不适用并给出依据。不把环境故障写成产品缺陷,也不用环境问题掩盖已观测到的产品错误。
28
30
 
@@ -5,7 +5,8 @@ description: >-
5
5
  runtime: external
6
6
  harness: codex-cli
7
7
  command: codex exec --sandbox workspace-write --skip-git-repo-check
8
- thinkingLevel: medium
8
+ model: gpt-5.6-luna
9
+ thinkingLevel: max
9
10
  workload: heavy
10
11
  mutates: write
11
12
  maxWallTimeSec: 1800
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oyasmi/pipiclaw",
3
- "version": "0.9.2-beta.1",
3
+ "version": "0.9.2-beta.2",
4
4
  "description": "An AI assistant runtime for coding and team workflows, with DingTalk AI Cards, sub-agents, memory, and scheduled events.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -42,10 +42,10 @@
42
42
  "test:evals": "vitest --run --config vitest.config.evals.ts"
43
43
  },
44
44
  "dependencies": {
45
- "@earendil-works/pi-agent-core": "0.83.0",
46
- "@earendil-works/pi-ai": "0.83.0",
47
- "@earendil-works/pi-coding-agent": "0.83.0",
48
- "@earendil-works/pi-tui": "0.83.0",
45
+ "@earendil-works/pi-agent-core": "0.84.3",
46
+ "@earendil-works/pi-ai": "0.84.3",
47
+ "@earendil-works/pi-coding-agent": "0.84.3",
48
+ "@earendil-works/pi-tui": "0.84.3",
49
49
  "@mozilla/readability": "^0.6.0",
50
50
  "axios": "^1.7.0",
51
51
  "croner": "^9.1.0",