@oyasmi/pipiclaw 0.9.2 → 0.9.3-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +250 -0
- package/README.md +2 -0
- package/dist/agent/channel-runner.d.ts +43 -2
- package/dist/agent/channel-runner.js +135 -75
- package/dist/agent/job-manager.d.ts +76 -21
- package/dist/agent/job-manager.js +447 -63
- package/dist/agent/maintenance-context.js +4 -5
- package/dist/agent/prompt/manifest.d.ts +0 -2
- package/dist/agent/prompt/manifest.js +2 -3
- package/dist/agent/prompt/sections.js +3 -3
- package/dist/agent/session-events.js +4 -8
- package/dist/agent/turn-prompt.d.ts +7 -7
- package/dist/agent/turn-prompt.js +6 -9
- package/dist/agent/types.d.ts +12 -0
- package/dist/agent/types.js +1 -0
- package/dist/channel/channel-context.d.ts +13 -0
- package/dist/channel/channel-context.js +21 -1
- package/dist/commands/catalog.js +47 -20
- package/dist/memory/commands.d.ts +8 -0
- package/dist/memory/commands.js +113 -148
- package/dist/memory/index-budget.d.ts +27 -0
- package/dist/memory/index-budget.js +99 -0
- package/dist/memory/journal.d.ts +20 -0
- package/dist/memory/journal.js +78 -0
- package/dist/memory/lifecycle.d.ts +9 -15
- package/dist/memory/lifecycle.js +55 -145
- package/dist/memory/maintenance-gates.d.ts +13 -47
- package/dist/memory/maintenance-gates.js +13 -92
- package/dist/memory/maintenance-state.d.ts +10 -16
- package/dist/memory/maintenance-state.js +12 -59
- package/dist/memory/maintenance-tuning.d.ts +7 -27
- package/dist/memory/maintenance-tuning.js +11 -28
- package/dist/memory/migrate.d.ts +15 -0
- package/dist/memory/migrate.js +364 -0
- package/dist/memory/reflect-job.d.ts +43 -0
- package/dist/memory/reflect-job.js +117 -0
- package/dist/memory/reflect.d.ts +52 -0
- package/dist/memory/reflect.js +313 -0
- package/dist/memory/render.d.ts +14 -0
- package/dist/memory/render.js +28 -0
- package/dist/memory/review-log.d.ts +2 -1
- package/dist/memory/scheduler.d.ts +2 -3
- package/dist/memory/scheduler.js +14 -49
- package/dist/memory/search.d.ts +35 -0
- package/dist/memory/search.js +297 -0
- package/dist/memory/session-search.js +1 -1
- package/dist/memory/store.d.ts +108 -0
- package/dist/memory/store.js +418 -0
- package/dist/memory/task-digest.d.ts +2 -2
- package/dist/memory/task-digest.js +29 -36
- package/dist/memory/tombstones.d.ts +0 -11
- package/dist/memory/tombstones.js +6 -37
- package/dist/playbooks/agent-delegation.md +4 -2
- package/dist/playbooks/background-jobs.md +1 -1
- package/dist/playbooks/event-scheduling.md +6 -2
- package/dist/playbooks/memory-and-learning.md +18 -11
- package/dist/playbooks/outbound-media.md +1 -1
- package/dist/playbooks/runtime-orientation.md +9 -8
- package/dist/playbooks/task-loop.md +88 -0
- package/dist/runtime/bootstrap.d.ts +3 -3
- package/dist/runtime/bootstrap.js +66 -41
- package/dist/runtime/events.d.ts +9 -0
- package/dist/runtime/events.js +43 -4
- package/dist/runtime/task-commands.d.ts +14 -15
- package/dist/runtime/task-commands.js +249 -485
- package/dist/runtime/task-driver.d.ts +41 -29
- package/dist/runtime/task-driver.js +170 -317
- package/dist/runtime/task-migration.d.ts +34 -30
- package/dist/runtime/task-migration.js +229 -183
- package/dist/runtime/task-wake.d.ts +6 -3
- package/dist/runtime/task-wake.js +26 -19
- package/dist/settings.d.ts +0 -29
- package/dist/settings.js +12 -35
- package/dist/shared/markdown-sections.d.ts +0 -1
- package/dist/shared/markdown-sections.js +0 -3
- package/dist/subagents/discovery.d.ts +2 -2
- package/dist/subagents/discovery.js +21 -10
- package/dist/subagents/external/progress-tail.js +6 -1
- package/dist/subagents/external/run.js +1 -0
- package/dist/subagents/runs.d.ts +19 -2
- package/dist/subagents/runs.js +73 -4
- package/dist/subagents/tool.d.ts +10 -8
- package/dist/subagents/tool.js +55 -94
- package/dist/tasks/brief.d.ts +17 -0
- package/dist/tasks/brief.js +57 -0
- package/dist/tasks/budget.d.ts +26 -0
- package/dist/tasks/budget.js +59 -0
- package/dist/tasks/cycle.d.ts +48 -0
- package/dist/tasks/cycle.js +94 -0
- package/dist/tasks/frontmatter.d.ts +73 -0
- package/dist/tasks/frontmatter.js +175 -0
- package/dist/tasks/ledger.d.ts +66 -106
- package/dist/tasks/ledger.js +90 -546
- package/dist/tasks/log.d.ts +88 -0
- package/dist/tasks/log.js +97 -0
- package/dist/tasks/rounds.d.ts +43 -0
- package/dist/tasks/rounds.js +57 -0
- package/dist/tasks/session-path.d.ts +9 -0
- package/dist/tasks/session-path.js +16 -0
- package/dist/tasks/steer.d.ts +8 -0
- package/dist/tasks/steer.js +79 -0
- package/dist/tasks/store.d.ts +60 -35
- package/dist/tasks/store.js +166 -107
- package/dist/tasks/ticket.d.ts +102 -0
- package/dist/tasks/ticket.js +209 -0
- package/dist/tasks/verification.d.ts +16 -0
- package/dist/tasks/verification.js +40 -1
- package/dist/tools/index.d.ts +13 -4
- package/dist/tools/index.js +5 -10
- package/dist/tools/memory-manage.d.ts +6 -16
- package/dist/tools/memory-manage.js +108 -129
- package/dist/tools/presentation.js +2 -1
- package/dist/tools/registry.d.ts +11 -2
- package/dist/tools/registry.js +17 -6
- package/dist/tools/subagent-manage.d.ts +0 -9
- package/dist/tools/subagent-manage.js +8 -17
- package/dist/tools/task-manage/create.js +2 -2
- package/dist/tools/task-manage/lifecycle.d.ts +9 -4
- package/dist/tools/task-manage/lifecycle.js +139 -187
- package/dist/tools/task-manage/log-view.d.ts +8 -0
- package/dist/tools/task-manage/log-view.js +24 -0
- package/dist/tools/task-manage/schema.d.ts +38 -14
- package/dist/tools/task-manage/schema.js +46 -27
- package/dist/tools/task-manage/shared.d.ts +24 -31
- package/dist/tools/task-manage/shared.js +103 -141
- package/dist/tools/task-manage/step-end.d.ts +11 -0
- package/dist/tools/task-manage/step-end.js +136 -0
- package/dist/tools/task-manage/types.d.ts +23 -32
- package/dist/tools/task-manage.d.ts +4 -3
- package/dist/tools/task-manage.js +30 -15
- package/dist/tools/tool-details.d.ts +1 -1
- package/dist/tui/app.js +0 -2
- package/package.json +1 -1
- package/dist/agent/effect-ledger.d.ts +0 -32
- package/dist/agent/effect-ledger.js +0 -89
- package/dist/memory/bootstrap.d.ts +0 -17
- package/dist/memory/bootstrap.js +0 -120
- package/dist/memory/candidates.d.ts +0 -26
- package/dist/memory/candidates.js +0 -202
- package/dist/memory/consolidation.d.ts +0 -54
- package/dist/memory/consolidation.js +0 -292
- package/dist/memory/extraction.d.ts +0 -54
- package/dist/memory/extraction.js +0 -240
- package/dist/memory/files.d.ts +0 -71
- package/dist/memory/files.js +0 -419
- package/dist/memory/maintenance-jobs.d.ts +0 -41
- package/dist/memory/maintenance-jobs.js +0 -265
- package/dist/memory/metadata.d.ts +0 -57
- package/dist/memory/metadata.js +0 -142
- package/dist/memory/probation.d.ts +0 -17
- package/dist/memory/probation.js +0 -44
- package/dist/memory/promotion.d.ts +0 -38
- package/dist/memory/promotion.js +0 -36
- package/dist/memory/recall.d.ts +0 -59
- package/dist/memory/recall.js +0 -746
- package/dist/memory/session.d.ts +0 -24
- package/dist/memory/session.js +0 -273
- package/dist/playbooks/task-driving.md +0 -92
- package/dist/playbooks/task-planning.md +0 -58
- package/dist/tasks/control.d.ts +0 -56
- package/dist/tasks/control.js +0 -169
- package/dist/tasks/transitions.d.ts +0 -16
- package/dist/tasks/transitions.js +0 -48
- package/dist/tools/task-manage/verification.d.ts +0 -19
- package/dist/tools/task-manage/verification.js +0 -91
package/dist/tasks/control.js
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { formatLocalTime, parseLocalTime } from "../shared/local-time.js";
|
|
2
|
-
import { errorMessage } from "../shared/text-utils.js";
|
|
3
|
-
import { isPlainObject } from "../shared/type-guards.js";
|
|
4
|
-
const WAITING_FOR = ["time", "user", "job", "external-signal"];
|
|
5
|
-
const VERIFICATION_STATUSES = ["pending", "passed", "failed"];
|
|
6
|
-
function optionalString(value) {
|
|
7
|
-
if (typeof value !== "string")
|
|
8
|
-
return undefined;
|
|
9
|
-
const trimmed = value.trim();
|
|
10
|
-
return trimmed || undefined;
|
|
11
|
-
}
|
|
12
|
-
function enumValue(value, values, fallback) {
|
|
13
|
-
if (value === undefined)
|
|
14
|
-
return fallback;
|
|
15
|
-
if (typeof value !== "string" || !values.includes(value)) {
|
|
16
|
-
throw new Error(`control enum value must be one of: ${values.join(", ")}`);
|
|
17
|
-
}
|
|
18
|
-
return value;
|
|
19
|
-
}
|
|
20
|
-
function parseStop(value) {
|
|
21
|
-
if (value === undefined)
|
|
22
|
-
return undefined;
|
|
23
|
-
if (!isPlainObject(value))
|
|
24
|
-
throw new Error("control.stop must be an object");
|
|
25
|
-
const by = enumValue(value.by, ["user", "governor"], "user");
|
|
26
|
-
const reason = optionalString(value.reason);
|
|
27
|
-
const at = optionalString(value.at);
|
|
28
|
-
if (!reason || !at || parseLocalTime(at) === undefined) {
|
|
29
|
-
throw new Error("control.stop requires a reason and valid at timestamp");
|
|
30
|
-
}
|
|
31
|
-
return { by, reason, at: formatLocalTime(new Date(parseLocalTime(at))) };
|
|
32
|
-
}
|
|
33
|
-
export function createDefaultTaskControl(requiresVerification = false) {
|
|
34
|
-
return {
|
|
35
|
-
version: 3,
|
|
36
|
-
verification: { required: requiresVerification, status: "pending" },
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
/** Read the v3 control contract only. Anything else is a read-time failure — see `parseLegacyTaskControl`. */
|
|
40
|
-
export function parseTaskControl(raw) {
|
|
41
|
-
let value;
|
|
42
|
-
try {
|
|
43
|
-
value = JSON.parse(raw);
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
throw new Error(`control is not valid JSON: ${errorMessage(error)}`);
|
|
47
|
-
}
|
|
48
|
-
if (!isPlainObject(value) || value.version !== 3) {
|
|
49
|
-
throw new Error("control must be a version 3 JSON object; repair it with task_update (no note).");
|
|
50
|
-
}
|
|
51
|
-
const verification = isPlainObject(value.verification) ? value.verification : {};
|
|
52
|
-
const deadline = optionalString(value.deadline);
|
|
53
|
-
if (deadline && parseLocalTime(deadline) === undefined) {
|
|
54
|
-
throw new Error("control.deadline must be a valid local time");
|
|
55
|
-
}
|
|
56
|
-
const waitingFor = value.waitingFor === undefined ? undefined : enumValue(value.waitingFor, WAITING_FOR, "external-signal");
|
|
57
|
-
return {
|
|
58
|
-
version: 3,
|
|
59
|
-
deadline,
|
|
60
|
-
nextAction: optionalString(value.nextAction),
|
|
61
|
-
waitingFor,
|
|
62
|
-
verification: {
|
|
63
|
-
required: typeof verification.required === "boolean" ? verification.required : false,
|
|
64
|
-
status: enumValue(verification.status, VERIFICATION_STATUSES, "pending"),
|
|
65
|
-
runId: optionalString(verification.runId),
|
|
66
|
-
},
|
|
67
|
-
cycleId: optionalString(value.cycleId),
|
|
68
|
-
stop: parseStop(value.stop),
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Migration-only reader for v1/v2 control blocks. `parseTaskControl` no longer accepts them —
|
|
73
|
-
* this exists so `migrateLegacyTaskState` (spec 029, D6's window, closed here) can durably
|
|
74
|
-
* upgrade an old file the one time it is encountered. Nothing else may call this.
|
|
75
|
-
*
|
|
76
|
-
* RETIRE AT v0.9.3 — see the header comment in `../runtime/task-migration.js`.
|
|
77
|
-
*/
|
|
78
|
-
export function parseLegacyTaskControl(raw) {
|
|
79
|
-
let value;
|
|
80
|
-
try {
|
|
81
|
-
value = JSON.parse(raw);
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
throw new Error(`control is not valid JSON: ${errorMessage(error)}`);
|
|
85
|
-
}
|
|
86
|
-
if (!isPlainObject(value) || (value.version !== 1 && value.version !== 2)) {
|
|
87
|
-
throw new Error("legacy control must be a version 1 or version 2 JSON object");
|
|
88
|
-
}
|
|
89
|
-
const verification = isPlainObject(value.verification) ? value.verification : {};
|
|
90
|
-
const deadline = optionalString(value.deadline);
|
|
91
|
-
const waitingFor = value.waitingFor === undefined ? undefined : enumValue(value.waitingFor, WAITING_FOR, "external-signal");
|
|
92
|
-
let stop = parseStop(value.stop);
|
|
93
|
-
// v1 stored the stop dimension as a status-side `pausedBy` value. Preserve its
|
|
94
|
-
// operational meaning while converting it to the structured record.
|
|
95
|
-
if (!stop && value.pausedBy !== undefined) {
|
|
96
|
-
const by = enumValue(value.pausedBy, ["user", "governor"], "user");
|
|
97
|
-
stop = {
|
|
98
|
-
by,
|
|
99
|
-
reason: optionalString(value.blockedReason) ?? `Task stopped by ${by}.`,
|
|
100
|
-
at: formatLocalTime(),
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
return {
|
|
104
|
-
version: 3,
|
|
105
|
-
deadline: deadline && parseLocalTime(deadline) !== undefined ? deadline : undefined,
|
|
106
|
-
nextAction: optionalString(value.nextAction),
|
|
107
|
-
waitingFor,
|
|
108
|
-
verification: {
|
|
109
|
-
// v1's independent mode was the only mode that represented a real checker gate.
|
|
110
|
-
required: typeof verification.required === "boolean" ? verification.required : verification.mode === "independent",
|
|
111
|
-
status: enumValue(verification.status, VERIFICATION_STATUSES, "pending"),
|
|
112
|
-
runId: optionalString(verification.runId),
|
|
113
|
-
},
|
|
114
|
-
cycleId: optionalString(value.cycleId),
|
|
115
|
-
stop,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
/** Reset state that is meaningful only within one recurring task cycle. */
|
|
119
|
-
export function resetTaskControlForCycle(control, cycleId) {
|
|
120
|
-
const normalizedCycleId = cycleId.trim();
|
|
121
|
-
if (!normalizedCycleId)
|
|
122
|
-
throw new Error("cycleId must not be empty.");
|
|
123
|
-
return {
|
|
124
|
-
...structuredClone(control),
|
|
125
|
-
nextAction: undefined,
|
|
126
|
-
waitingFor: undefined,
|
|
127
|
-
verification: { required: control.verification.required, status: "pending" },
|
|
128
|
-
cycleId: normalizedCycleId,
|
|
129
|
-
stop: undefined,
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
function patchOptionalString(current, value) {
|
|
133
|
-
if (value === undefined)
|
|
134
|
-
return current;
|
|
135
|
-
return value.trim() || undefined;
|
|
136
|
-
}
|
|
137
|
-
export function applyTaskControlPatch(control, patch) {
|
|
138
|
-
const next = structuredClone(control);
|
|
139
|
-
let normalizedDeadlinePatch = patch.deadline;
|
|
140
|
-
if (patch.deadline?.trim()) {
|
|
141
|
-
const deadlineMs = parseLocalTime(patch.deadline);
|
|
142
|
-
if (deadlineMs === undefined)
|
|
143
|
-
throw new Error(`deadline "${patch.deadline}" is not a valid local time.`);
|
|
144
|
-
normalizedDeadlinePatch = formatLocalTime(new Date(deadlineMs));
|
|
145
|
-
}
|
|
146
|
-
next.deadline = patchOptionalString(next.deadline, normalizedDeadlinePatch);
|
|
147
|
-
next.nextAction = patchOptionalString(next.nextAction, patch.nextAction);
|
|
148
|
-
if (patch.waitingFor !== undefined)
|
|
149
|
-
next.waitingFor = patch.waitingFor;
|
|
150
|
-
if (patch.verificationRequired !== undefined && patch.verificationRequired !== next.verification.required) {
|
|
151
|
-
next.verification = { required: patch.verificationRequired, status: "pending" };
|
|
152
|
-
}
|
|
153
|
-
return next;
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Return a deterministic governance violation for a live task. Sleeping tasks have no current
|
|
157
|
-
* work, so a deadline cannot stop them; waiting and active tasks are both subject to it — a
|
|
158
|
-
* deadline is the user's own intent, not something a task can dodge by parking.
|
|
159
|
-
*/
|
|
160
|
-
export function taskBudgetViolation(control, nowMs, status = "active") {
|
|
161
|
-
if (status === "sleeping")
|
|
162
|
-
return undefined;
|
|
163
|
-
if (control.deadline) {
|
|
164
|
-
const deadlineMs = parseLocalTime(control.deadline);
|
|
165
|
-
if (deadlineMs !== undefined && deadlineMs < nowMs)
|
|
166
|
-
return `deadline exceeded (${control.deadline})`;
|
|
167
|
-
}
|
|
168
|
-
return undefined;
|
|
169
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/** The only lifecycle stages stored in an active task directory. */
|
|
2
|
-
export declare const TASK_STATUSES: readonly ["active", "waiting", "sleeping"];
|
|
3
|
-
export type TaskStatus = (typeof TASK_STATUSES)[number];
|
|
4
|
-
/** Statuses a model/user may set directly; recurring sleeping is runtime-owned but repairable. */
|
|
5
|
-
export declare const SETTABLE_TASK_STATUSES: readonly ["active", "waiting", "sleeping"];
|
|
6
|
-
export type SettableTaskStatus = (typeof SETTABLE_TASK_STATUSES)[number];
|
|
7
|
-
export type TaskLifecycleAction = "create"
|
|
8
|
-
/** task_update with a `note` — a checkpoint on an open cycle. */
|
|
9
|
-
| "checkpoint" | "verify" | "complete" | "skip" | "cancel"
|
|
10
|
-
/** task_update with no `note` — a metadata-only edit (spec 046, D3.2). */
|
|
11
|
-
| "metadata" | "pause" | "resume" | "run" | "governor-stop" | "wait-due" | "cycle-due";
|
|
12
|
-
/** Canonicalize a stored status value, fail-open to `active` for anything not in the current vocabulary. */
|
|
13
|
-
export declare function normalizeStoredStatus(raw: string | undefined): TaskStatus;
|
|
14
|
-
export declare function isSettableTaskStatus(value: string): value is SettableTaskStatus;
|
|
15
|
-
/** Assert an action is legal and resolve caller-supplied target status. */
|
|
16
|
-
export declare function resolveTaskTransition(action: TaskLifecycleAction, id: string, from: TaskStatus, requestedStatus?: string): TaskStatus;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
2
|
-
/** The only lifecycle stages stored in an active task directory. */
|
|
3
|
-
export const TASK_STATUSES = ["active", "waiting", "sleeping"];
|
|
4
|
-
/** Statuses a model/user may set directly; recurring sleeping is runtime-owned but repairable. */
|
|
5
|
-
export const SETTABLE_TASK_STATUSES = ["active", "waiting", "sleeping"];
|
|
6
|
-
const LIVE = ["active", "waiting", "sleeping"];
|
|
7
|
-
const WORKABLE = ["active", "waiting"];
|
|
8
|
-
const TRANSITIONS = {
|
|
9
|
-
create: { from: [], to: "active" },
|
|
10
|
-
checkpoint: { from: WORKABLE, to: "caller" },
|
|
11
|
-
// Not gated on a specific waitingFor value: the wake that reactivates a task parked for a
|
|
12
|
-
// purpose=verify sub-agent already flips it to active before this runs (the same as any other
|
|
13
|
-
// delegation wake), but `verify` also accepts waiting so it is not sensitive to exactly when
|
|
14
|
-
// that reactivation lands relative to the model's own turn.
|
|
15
|
-
verify: { from: WORKABLE, to: "active" },
|
|
16
|
-
complete: { from: ["active"], to: "caller" },
|
|
17
|
-
skip: { from: WORKABLE, to: "sleeping" },
|
|
18
|
-
cancel: { from: LIVE, to: "caller" },
|
|
19
|
-
metadata: { from: LIVE, to: "caller" },
|
|
20
|
-
pause: { from: LIVE, to: "caller" },
|
|
21
|
-
resume: { from: LIVE, to: "caller" },
|
|
22
|
-
run: { from: LIVE, to: "active" },
|
|
23
|
-
"governor-stop": { from: LIVE, to: "caller" },
|
|
24
|
-
"wait-due": { from: ["waiting"], to: "active" },
|
|
25
|
-
"cycle-due": { from: ["sleeping"], to: "active" },
|
|
26
|
-
};
|
|
27
|
-
/** Canonicalize a stored status value, fail-open to `active` for anything not in the current vocabulary. */
|
|
28
|
-
export function normalizeStoredStatus(raw) {
|
|
29
|
-
return raw !== undefined && TASK_STATUSES.includes(raw) ? raw : "active";
|
|
30
|
-
}
|
|
31
|
-
export function isSettableTaskStatus(value) {
|
|
32
|
-
return SETTABLE_TASK_STATUSES.includes(value);
|
|
33
|
-
}
|
|
34
|
-
/** Assert an action is legal and resolve caller-supplied target status. */
|
|
35
|
-
export function resolveTaskTransition(action, id, from, requestedStatus) {
|
|
36
|
-
const rule = TRANSITIONS[action];
|
|
37
|
-
if (!rule.from.includes(from)) {
|
|
38
|
-
throw new RecoverableToolError(`Task ${id} is ${from}; action ${action} allows only from: ${rule.from.join(", ") || "(none)"}.`);
|
|
39
|
-
}
|
|
40
|
-
if (rule.to !== "caller")
|
|
41
|
-
return rule.to;
|
|
42
|
-
if (requestedStatus === undefined)
|
|
43
|
-
return from;
|
|
44
|
-
if (!isSettableTaskStatus(requestedStatus)) {
|
|
45
|
-
throw new RecoverableToolError(`Invalid status "${requestedStatus}". Use one of ${SETTABLE_TASK_STATUSES.join(", ")}.`);
|
|
46
|
-
}
|
|
47
|
-
return requestedStatus;
|
|
48
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { type VerificationAttestation } from "../../tasks/verification.js";
|
|
2
|
-
import type { TaskManageResult, TaskManageToolOptions, TaskVerifyRequest } from "./types.js";
|
|
3
|
-
/**
|
|
4
|
-
* Import a verifier's attestation. The task's own lifecycle status is not the authorization
|
|
5
|
-
* check — a real, matching, on-disk attestation for this task id is (spec 040's threat model:
|
|
6
|
-
* the task Markdown is agent-writable and proves nothing). `task_verify` works whether the task
|
|
7
|
-
* is still `waiting` (e.g. called right after its completion wake reactivated it) or already
|
|
8
|
-
* `active`.
|
|
9
|
-
*/
|
|
10
|
-
export declare function verifyTask(options: TaskManageToolOptions, request: TaskVerifyRequest): Promise<TaskManageResult>;
|
|
11
|
-
/**
|
|
12
|
-
* `verify` writes control.verification from a real attestation file, but the task Markdown
|
|
13
|
-
* itself is writable by the agent's own write/edit tools — nothing stops it from hand-crafting
|
|
14
|
-
* a "passed" verification block that was never backed by a real verifier run. Re-check the
|
|
15
|
-
* attestation file on the consuming side (complete/doctor) too, not just at import time, and
|
|
16
|
-
* against the task's *current* body hash directly — not a mirrored value the task file could
|
|
17
|
-
* itself have drifted.
|
|
18
|
-
*/
|
|
19
|
-
export declare function assertVerificationAttestationMatches(channelDir: string, id: string, runId: string | undefined, currentBodyHash: string, trustedWorkingDirectory?: string): Promise<VerificationAttestation>;
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { writeFileAtomically } from "../../shared/atomic-file.js";
|
|
2
|
-
import { getSubAgentRunManager } from "../../subagents/runs.js";
|
|
3
|
-
import { workspaceSubjectHash } from "../../tasks/artifact-subject.js";
|
|
4
|
-
import { createDefaultTaskControl } from "../../tasks/control.js";
|
|
5
|
-
import { normalizeTaskId } from "../../tasks/ledger.js";
|
|
6
|
-
import { readStoredTask, taskBodyHash } from "../../tasks/store.js";
|
|
7
|
-
import { normalizeStoredStatus, resolveTaskTransition } from "../../tasks/transitions.js";
|
|
8
|
-
import { getVerificationSubjectHashOptions, readVerificationAttestation, } from "../../tasks/verification.js";
|
|
9
|
-
import { RecoverableToolError } from "../tool-details.js";
|
|
10
|
-
import { renderTaskFile } from "./shared.js";
|
|
11
|
-
/**
|
|
12
|
-
* Import a verifier's attestation. The task's own lifecycle status is not the authorization
|
|
13
|
-
* check — a real, matching, on-disk attestation for this task id is (spec 040's threat model:
|
|
14
|
-
* the task Markdown is agent-writable and proves nothing). `task_verify` works whether the task
|
|
15
|
-
* is still `waiting` (e.g. called right after its completion wake reactivated it) or already
|
|
16
|
-
* `active`.
|
|
17
|
-
*/
|
|
18
|
-
export async function verifyTask(options, request) {
|
|
19
|
-
const id = normalizeTaskId(request.id);
|
|
20
|
-
const runId = request.verifierRunId;
|
|
21
|
-
const task = await readStoredTask(options.channelDir, id);
|
|
22
|
-
if (!task)
|
|
23
|
-
throw new RecoverableToolError(`Task "${id}" does not exist; create it before verification.`);
|
|
24
|
-
resolveTaskTransition("verify", id, normalizeStoredStatus(task.fields.status));
|
|
25
|
-
const trustedWorkingDirectory = getSubAgentRunManager(options.channelId).get(runId)?.workingDirectory;
|
|
26
|
-
const attestation = await readVerificationAttestation(options.channelDir, runId, {
|
|
27
|
-
trustedWorkingDirectory,
|
|
28
|
-
});
|
|
29
|
-
if (attestation.taskId !== id) {
|
|
30
|
-
throw new RecoverableToolError(`Verification run "${runId}" belongs to task "${attestation.taskId}", not "${id}".`);
|
|
31
|
-
}
|
|
32
|
-
if (attestation.workspaceChanged) {
|
|
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.`);
|
|
34
|
-
}
|
|
35
|
-
if (attestation.bodyHash !== taskBodyHash(task.body)) {
|
|
36
|
-
throw new RecoverableToolError(`Task "${id}" changed after verification run "${runId}"; rerun the verifier on current content.`);
|
|
37
|
-
}
|
|
38
|
-
if (attestation.subjectHash) {
|
|
39
|
-
const subjectDir = attestation.subjectDir ?? trustedWorkingDirectory ?? options.workingDirectory ?? process.cwd();
|
|
40
|
-
const currentSubject = await workspaceSubjectHash(subjectDir, getVerificationSubjectHashOptions(attestation));
|
|
41
|
-
if (!currentSubject) {
|
|
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.`);
|
|
43
|
-
}
|
|
44
|
-
if (currentSubject !== attestation.subjectHash) {
|
|
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.`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
const control = task.fields.control ?? createDefaultTaskControl(true);
|
|
49
|
-
control.verification = {
|
|
50
|
-
required: true,
|
|
51
|
-
status: attestation.verdict === "pass" ? "passed" : "failed",
|
|
52
|
-
runId,
|
|
53
|
-
};
|
|
54
|
-
control.waitingFor = undefined;
|
|
55
|
-
control.nextAction = undefined;
|
|
56
|
-
task.fields.control = control;
|
|
57
|
-
task.fields.status = "active";
|
|
58
|
-
task.fields.wake = undefined;
|
|
59
|
-
await writeFileAtomically(task.path, renderTaskFile(task.fields, task.body));
|
|
60
|
-
return {
|
|
61
|
-
action: "verify",
|
|
62
|
-
id,
|
|
63
|
-
path: task.path,
|
|
64
|
-
status: "active",
|
|
65
|
-
notice: `任务 \`${id}\` 独立验收结果:${attestation.verdict.toUpperCase()}${attestation.verificationStrength === "advisory" ? "(advisory)" : ""}(run: ${runId})。`,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* `verify` writes control.verification from a real attestation file, but the task Markdown
|
|
70
|
-
* itself is writable by the agent's own write/edit tools — nothing stops it from hand-crafting
|
|
71
|
-
* a "passed" verification block that was never backed by a real verifier run. Re-check the
|
|
72
|
-
* attestation file on the consuming side (complete/doctor) too, not just at import time, and
|
|
73
|
-
* against the task's *current* body hash directly — not a mirrored value the task file could
|
|
74
|
-
* itself have drifted.
|
|
75
|
-
*/
|
|
76
|
-
export async function assertVerificationAttestationMatches(channelDir, id, runId, currentBodyHash, trustedWorkingDirectory) {
|
|
77
|
-
if (!runId) {
|
|
78
|
-
throw new RecoverableToolError(`Task "${id}" has no verification run id; rerun task_verify before task_close.`);
|
|
79
|
-
}
|
|
80
|
-
const attestation = await readVerificationAttestation(channelDir, runId, { trustedWorkingDirectory });
|
|
81
|
-
if (attestation.taskId !== id) {
|
|
82
|
-
throw new RecoverableToolError(`Verification run "${runId}" belongs to task "${attestation.taskId}", not "${id}"; rerun verification.`);
|
|
83
|
-
}
|
|
84
|
-
if (attestation.verdict !== "pass") {
|
|
85
|
-
throw new RecoverableToolError(`Verification run "${runId}" recorded a FAIL, not a PASS; rerun verification.`);
|
|
86
|
-
}
|
|
87
|
-
if (attestation.bodyHash !== currentBodyHash) {
|
|
88
|
-
throw new RecoverableToolError(`Task "${id}" changed since verification run "${runId}"; rerun task_verify.`);
|
|
89
|
-
}
|
|
90
|
-
return attestation;
|
|
91
|
-
}
|