@oyasmi/pipiclaw 0.8.9 → 0.8.10-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.
- package/README.md +3 -3
- package/dist/agent/channel-runner.d.ts +1 -0
- package/dist/agent/channel-runner.js +6 -10
- package/dist/agent/maintenance-context.d.ts +0 -1
- package/dist/agent/maintenance-context.js +0 -7
- package/dist/agent/session-events.d.ts +1 -0
- package/dist/agent/session-events.js +10 -0
- package/dist/agent/types.d.ts +7 -0
- package/dist/agent/types.js +2 -0
- package/dist/index.d.ts +16 -34
- package/dist/index.js +14 -32
- package/dist/memory/consolidation.js +0 -1
- package/dist/memory/extraction.d.ts +1 -7
- package/dist/memory/extraction.js +2 -46
- package/dist/memory/lifecycle.js +3 -3
- package/dist/memory/maintenance-gates.d.ts +4 -16
- package/dist/memory/maintenance-gates.js +11 -51
- package/dist/memory/maintenance-jobs.d.ts +3 -14
- package/dist/memory/maintenance-jobs.js +12 -103
- package/dist/memory/maintenance-state.d.ts +2 -6
- package/dist/memory/maintenance-state.js +14 -10
- package/dist/memory/maintenance-tuning.d.ts +37 -0
- package/dist/memory/maintenance-tuning.js +46 -0
- package/dist/memory/promotion.d.ts +0 -22
- package/dist/memory/promotion.js +1 -8
- package/dist/memory/review-log.d.ts +1 -1
- package/dist/memory/scheduler.d.ts +1 -9
- package/dist/memory/scheduler.js +3 -15
- package/dist/memory/source-window.d.ts +2 -2
- package/dist/memory/task-digest.js +2 -5
- package/dist/models/utils.d.ts +5 -0
- package/dist/models/utils.js +10 -0
- package/dist/paths.d.ts +0 -1
- package/dist/paths.js +0 -1
- package/dist/playbooks/task-closeout.md +2 -0
- package/dist/playbooks/task-delegation.md +8 -14
- package/dist/playbooks/task-driving.md +3 -4
- package/dist/playbooks/task-planning.md +8 -9
- package/dist/runtime/bootstrap.d.ts +14 -0
- package/dist/runtime/bootstrap.js +9 -4
- package/dist/runtime/task-commands.js +46 -73
- package/dist/runtime/task-driver.js +6 -23
- package/dist/settings.d.ts +39 -40
- package/dist/settings.js +87 -107
- package/dist/shared/task-ledger.d.ts +19 -2
- package/dist/shared/task-ledger.js +194 -5
- package/dist/subagents/discovery.d.ts +41 -7
- package/dist/subagents/discovery.js +74 -24
- package/dist/subagents/tool.d.ts +3 -12
- package/dist/subagents/tool.js +11 -115
- package/dist/tasks/control.d.ts +57 -27
- package/dist/tasks/control.js +94 -93
- package/dist/tasks/store.d.ts +1 -4
- package/dist/tasks/store.js +1 -39
- package/dist/tasks/transitions.d.ts +1 -1
- package/dist/tasks/transitions.js +1 -0
- package/dist/tasks/verification.d.ts +10 -6
- package/dist/tasks/verification.js +0 -6
- package/dist/tools/memory-manage.js +46 -24
- package/dist/tools/task-manage/create.js +1 -2
- package/dist/tools/task-manage/lifecycle.d.ts +7 -0
- package/dist/tools/task-manage/lifecycle.js +52 -32
- package/dist/tools/task-manage/schema.d.ts +2 -9
- package/dist/tools/task-manage/schema.js +9 -19
- package/dist/tools/task-manage/shared.d.ts +0 -2
- package/dist/tools/task-manage/shared.js +8 -69
- package/dist/tools/task-manage/types.d.ts +1 -1
- package/dist/tools/task-manage/verification.js +5 -6
- package/dist/tools/task-manage.js +4 -2
- package/examples/sub-agents/README.md +1 -1
- package/package.json +3 -1
- package/dist/memory/post-turn-review.d.ts +0 -43
- package/dist/memory/post-turn-review.js +0 -136
- package/dist/memory/promotion-signals.d.ts +0 -5
- package/dist/memory/promotion-signals.js +0 -33
package/dist/tasks/store.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export declare function releaseTaskAttemptClaim(channelDir: string, id: string,
|
|
|
28
28
|
export declare function finishTaskAttempt(channelDir: string, id: string, result: {
|
|
29
29
|
tokens: number;
|
|
30
30
|
costUsd: number;
|
|
31
|
+
costKnown: boolean;
|
|
31
32
|
wallTimeMinutes: number;
|
|
32
33
|
failed: boolean;
|
|
33
34
|
silent?: boolean;
|
|
@@ -54,7 +55,3 @@ export declare function openRecurringTaskCycle(channelDir: string, id: string, n
|
|
|
54
55
|
document: StoredTaskDocument;
|
|
55
56
|
cycleId: string;
|
|
56
57
|
} | undefined>;
|
|
57
|
-
export declare function dependencyState(channelDir: string, dependencyIds: readonly string[], ownerId?: string): Promise<{
|
|
58
|
-
ready: boolean;
|
|
59
|
-
reason?: string;
|
|
60
|
-
}>;
|
package/dist/tasks/store.js
CHANGED
|
@@ -94,6 +94,7 @@ export async function finishTaskAttempt(channelDir, id, result) {
|
|
|
94
94
|
return;
|
|
95
95
|
control.usage.tokens += Math.max(0, Math.floor(result.tokens));
|
|
96
96
|
control.usage.costUsd += Math.max(0, result.costUsd);
|
|
97
|
+
control.usage.costKnown &&= result.costKnown;
|
|
97
98
|
control.usage.wallTimeMinutes += Math.max(0, result.wallTimeMinutes);
|
|
98
99
|
control.lastFinishedAt = result.finishedAt.toISOString();
|
|
99
100
|
if (result.silent) {
|
|
@@ -169,42 +170,3 @@ export async function openRecurringTaskCycle(channelDir, id, now) {
|
|
|
169
170
|
return undefined;
|
|
170
171
|
return { document, cycleId };
|
|
171
172
|
}
|
|
172
|
-
export async function dependencyState(channelDir, dependencyIds, ownerId) {
|
|
173
|
-
const detectCycle = async (id, path, active) => {
|
|
174
|
-
if (id === ownerId || active.has(id))
|
|
175
|
-
return `dependency cycle detected (${[...path, id].join(" -> ")})`;
|
|
176
|
-
const dependency = await readStoredTask(channelDir, id, true, true);
|
|
177
|
-
if (!dependency || dependency.fields.status === "done")
|
|
178
|
-
return undefined;
|
|
179
|
-
const nextActive = new Set(active).add(id);
|
|
180
|
-
for (const nestedId of dependency.fields.control?.dependsOn ?? []) {
|
|
181
|
-
const cycle = await detectCycle(nestedId, [...path, id], nextActive);
|
|
182
|
-
if (cycle)
|
|
183
|
-
return cycle;
|
|
184
|
-
}
|
|
185
|
-
return undefined;
|
|
186
|
-
};
|
|
187
|
-
for (const dependencyId of dependencyIds) {
|
|
188
|
-
const cycle = await detectCycle(dependencyId, ownerId ? [ownerId] : [], new Set());
|
|
189
|
-
if (cycle)
|
|
190
|
-
return { ready: false, reason: cycle };
|
|
191
|
-
}
|
|
192
|
-
for (const dependencyId of dependencyIds) {
|
|
193
|
-
const dependency = await readStoredTask(channelDir, dependencyId, true, true);
|
|
194
|
-
if (!dependency)
|
|
195
|
-
return { ready: false, reason: `dependency ${dependencyId} is missing` };
|
|
196
|
-
if (dependency.fields.status === "cancelled") {
|
|
197
|
-
return { ready: false, reason: `dependency ${dependencyId} is cancelled` };
|
|
198
|
-
}
|
|
199
|
-
// A governor-paused dependency will not self-recover, so it blocks the dependent
|
|
200
|
-
// terminally (matches the retired `escalated` semantics); a user pause is a soft wait.
|
|
201
|
-
if (dependency.fields.status === "paused") {
|
|
202
|
-
return dependency.fields.control?.pausedBy === "governor"
|
|
203
|
-
? { ready: false, reason: `dependency ${dependencyId} is paused by the governor` }
|
|
204
|
-
: { ready: false, reason: `waiting for dependency ${dependencyId} (paused)` };
|
|
205
|
-
}
|
|
206
|
-
if (dependency.fields.status !== "done")
|
|
207
|
-
return { ready: false, reason: `waiting for dependency ${dependencyId}` };
|
|
208
|
-
}
|
|
209
|
-
return { ready: true };
|
|
210
|
-
}
|
|
@@ -21,7 +21,7 @@ export declare const SETTABLE_TASK_STATUSES: readonly ["active", "waiting", "pau
|
|
|
21
21
|
export type SettableTaskStatus = (typeof SETTABLE_TASK_STATUSES)[number];
|
|
22
22
|
/** Statuses the driver never dispatches. */
|
|
23
23
|
export declare const TERMINAL_TASK_STATUSES: Set<string>;
|
|
24
|
-
export type TaskLifecycleAction = "create" | "progress" | "candidate" | "verify" | "done" | "cancel" | "set" | "pause" | "resume" | "run";
|
|
24
|
+
export type TaskLifecycleAction = "create" | "progress" | "candidate" | "verify" | "done" | "skip" | "cancel" | "set" | "pause" | "resume" | "run";
|
|
25
25
|
/**
|
|
26
26
|
* Map a stored (possibly legacy) status string to a canonical status.
|
|
27
27
|
* Legacy files are read losslessly and written back canonical on the next write;
|
|
@@ -26,6 +26,7 @@ const TRANSITIONS = {
|
|
|
26
26
|
candidate: { from: ["active", "waiting"], to: "verifying" },
|
|
27
27
|
verify: { from: ["verifying"], to: "verifying" },
|
|
28
28
|
done: { from: ["active", "waiting", "verifying"], to: "done" },
|
|
29
|
+
skip: { from: ["active", "waiting", "verifying"], to: "done" },
|
|
29
30
|
cancel: { from: ["active", "waiting", "verifying", "paused"], to: "cancelled" },
|
|
30
31
|
set: { from: ["active", "waiting", "verifying", "paused", "done"], to: "caller" },
|
|
31
32
|
pause: { from: ["active", "waiting", "verifying"], to: "paused" },
|
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
export type VerificationVerdict = "pass" | "fail";
|
|
2
|
+
/**
|
|
3
|
+
* A verifier's verdict, recorded on disk beside the task (spec 036, D6).
|
|
4
|
+
*
|
|
5
|
+
* This file is the anti-self-certification core: the task Markdown is writable by the agent's
|
|
6
|
+
* own write/edit tools, so a hand-written `status: "passed"` proves nothing. Every field here
|
|
7
|
+
* is re-checked at `done`, which is why the set is exactly the fields something reads —
|
|
8
|
+
* `agent`, `model` and `outputHash` were stored and strictly validated but never once
|
|
9
|
+
* consulted, so they are gone.
|
|
10
|
+
*/
|
|
2
11
|
export interface VerificationAttestation {
|
|
3
12
|
version: 1;
|
|
4
13
|
runId: string;
|
|
5
14
|
taskId: string;
|
|
6
15
|
verdict: VerificationVerdict;
|
|
7
|
-
agent: string;
|
|
8
|
-
model: string;
|
|
9
16
|
checkedAt: string;
|
|
10
17
|
bodyHash: string;
|
|
11
18
|
evidence: string;
|
|
12
|
-
outputHash: string;
|
|
13
19
|
workspaceChanged: boolean;
|
|
14
20
|
/** Git HEAD + working-tree subject that the verifier actually inspected. */
|
|
15
21
|
subjectHash?: string;
|
|
@@ -17,7 +23,5 @@ export interface VerificationAttestation {
|
|
|
17
23
|
export declare function verificationDir(channelDir: string): string;
|
|
18
24
|
export declare function verificationAttestationPath(channelDir: string, runId: string): string;
|
|
19
25
|
export declare function parseVerificationVerdict(output: string): VerificationVerdict | undefined;
|
|
20
|
-
export declare function writeVerificationAttestation(channelDir: string, input: Omit<VerificationAttestation, "version" | "bodyHash"
|
|
21
|
-
output: string;
|
|
22
|
-
}): Promise<VerificationAttestation>;
|
|
26
|
+
export declare function writeVerificationAttestation(channelDir: string, input: Omit<VerificationAttestation, "version" | "bodyHash">): Promise<VerificationAttestation>;
|
|
23
27
|
export declare function readVerificationAttestation(channelDir: string, runId: string): Promise<VerificationAttestation>;
|
|
@@ -26,12 +26,9 @@ export async function writeVerificationAttestation(channelDir, input) {
|
|
|
26
26
|
runId: input.runId,
|
|
27
27
|
taskId: input.taskId,
|
|
28
28
|
verdict: input.verdict,
|
|
29
|
-
agent: input.agent,
|
|
30
|
-
model: input.model,
|
|
31
29
|
checkedAt: input.checkedAt,
|
|
32
30
|
bodyHash: taskBodyHash(task.body),
|
|
33
31
|
evidence: input.evidence,
|
|
34
|
-
outputHash: createHash("sha256").update(input.output).digest("hex"),
|
|
35
32
|
workspaceChanged: input.workspaceChanged,
|
|
36
33
|
subjectHash: input.subjectHash,
|
|
37
34
|
};
|
|
@@ -53,12 +50,9 @@ export async function readVerificationAttestation(channelDir, runId) {
|
|
|
53
50
|
value.runId !== runId ||
|
|
54
51
|
typeof value.taskId !== "string" ||
|
|
55
52
|
(value.verdict !== "pass" && value.verdict !== "fail") ||
|
|
56
|
-
typeof value.agent !== "string" ||
|
|
57
|
-
typeof value.model !== "string" ||
|
|
58
53
|
typeof value.checkedAt !== "string" ||
|
|
59
54
|
!Number.isFinite(new Date(value.checkedAt).getTime()) ||
|
|
60
55
|
!/^[a-f0-9]{64}$/i.test(String(value.bodyHash)) ||
|
|
61
|
-
!/^[a-f0-9]{64}$/i.test(String(value.outputHash)) ||
|
|
62
56
|
typeof value.evidence !== "string" ||
|
|
63
57
|
typeof value.workspaceChanged !== "boolean" ||
|
|
64
58
|
(value.subjectHash !== undefined &&
|
|
@@ -7,6 +7,7 @@ import { recallRelevantMemory } from "../memory/recall.js";
|
|
|
7
7
|
import { appendMemoryReviewLog } from "../memory/review-log.js";
|
|
8
8
|
import { hashMemoryContent } from "../memory/tombstones.js";
|
|
9
9
|
import { readOptionalTextFile } from "../shared/fs-utils.js";
|
|
10
|
+
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
10
11
|
import { errorMessage } from "../shared/text-utils.js";
|
|
11
12
|
const memoryManageSchema = Type.Object({
|
|
12
13
|
label: Type.String({ description: "Brief description of the memory change (shown to user)" }),
|
|
@@ -14,7 +15,7 @@ const memoryManageSchema = Type.Object({
|
|
|
14
15
|
description: '"save" a durable fact, "search" this channel\'s stored memory on demand, or "forget" a stored entry the user asked you to drop.',
|
|
15
16
|
}),
|
|
16
17
|
content: Type.Optional(Type.String({
|
|
17
|
-
description: "
|
|
18
|
+
description: "Required for save: the durable fact as a single self-contained, keyword-rich sentence on one line, written so future keyword search can find it. A save without it is rejected and stores nothing.",
|
|
18
19
|
})),
|
|
19
20
|
query: Type.Optional(Type.String({ description: "For search: what to look for in stored memory." })),
|
|
20
21
|
target: Type.Optional(Type.String({
|
|
@@ -41,16 +42,45 @@ function normalizeMemoryKind(kind) {
|
|
|
41
42
|
function textResult(text, details) {
|
|
42
43
|
return { content: [{ type: "text", text }], details };
|
|
43
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Reject a call whose op-specific payload never arrived.
|
|
47
|
+
*
|
|
48
|
+
* These arguments are `Type.Optional` because each one belongs to exactly one op, so the
|
|
49
|
+
* schema cannot express "required for save, absent for search" — which means the SDK
|
|
50
|
+
* validator lets a payload-less call straight through. Two failure modes reach here and both
|
|
51
|
+
* used to end in a calm `textResult` that read like a completed no-op:
|
|
52
|
+
*
|
|
53
|
+
* 1. The model genuinely omitted the argument.
|
|
54
|
+
* 2. The argument was *lost in transit*. Streamed tool-call arguments are accumulated as
|
|
55
|
+
* text and parsed leniently (`parseStreamingJson`): if the provider truncates or
|
|
56
|
+
* malforms the tail of the JSON — the common shape with OpenAI-compatible Chinese
|
|
57
|
+
* providers on long non-ASCII values — the trailing key is silently dropped and the
|
|
58
|
+
* call still executes. The assistant message is then persisted with the *parsed*
|
|
59
|
+
* arguments, so on the next turn the model reads back its own call with `content`
|
|
60
|
+
* already missing, copies it, and loops forever.
|
|
61
|
+
*
|
|
62
|
+
* A soft result makes (2) unrecoverable, so reject loudly instead: a `RecoverableToolError`
|
|
63
|
+
* surfaces to the model as an error it must fix rather than a saved memory, names the keys
|
|
64
|
+
* that actually arrived so a dropped argument is visible rather than inferred, and tells the
|
|
65
|
+
* model not to replay the previous call. The warning log is the operator-side evidence —
|
|
66
|
+
* `agent.tool.started` carries the raw args but only at debug level.
|
|
67
|
+
*/
|
|
68
|
+
function rejectMissingArgument(op, parameter, args) {
|
|
69
|
+
const received = Object.entries(args)
|
|
70
|
+
.filter(([, value]) => value !== undefined && value !== "")
|
|
71
|
+
.map(([key]) => key);
|
|
72
|
+
log.logWarning(`memory_manage ${op} called without "${parameter}"`, `received arguments: ${received.join(", ") || "(none)"}`);
|
|
73
|
+
throw new RecoverableToolError(`memory_manage op="${op}" requires a non-empty "${parameter}", but the call arrived with only: ${received.join(", ") || "(no arguments)"}. Nothing was ${op === "forget" ? "removed" : op === "save" ? "saved" : "searched"}. Do not repeat the previous ` +
|
|
74
|
+
`call as written — if an earlier call in this conversation is also missing "${parameter}", it was dropped in ` +
|
|
75
|
+
`transit, so re-issue it with "${parameter}" set explicitly and keep the value short and on one line.`);
|
|
76
|
+
}
|
|
44
77
|
export function createMemoryManageTool(options) {
|
|
45
78
|
const queue = options.channelMemoryQueue ?? getDefaultChannelMemoryQueue();
|
|
46
|
-
async function save(
|
|
79
|
+
async function save(args) {
|
|
80
|
+
const { content, kind } = args;
|
|
47
81
|
const trimmed = (content ?? "").trim();
|
|
48
82
|
if (!trimmed) {
|
|
49
|
-
|
|
50
|
-
kind: "memory_manage",
|
|
51
|
-
op: "save",
|
|
52
|
-
saved: false,
|
|
53
|
-
});
|
|
83
|
+
rejectMissingArgument("save", "content", args);
|
|
54
84
|
}
|
|
55
85
|
if (containsSecret(trimmed)) {
|
|
56
86
|
return textResult("This content looks like a credential or secret, so it was not saved. Store the secret in an approved secret manager and remember only its location.", { kind: "memory_manage", op: "save", saved: false, blockedReason: "secret" });
|
|
@@ -71,14 +101,10 @@ export function createMemoryManageTool(options) {
|
|
|
71
101
|
saved: result.added > 0,
|
|
72
102
|
});
|
|
73
103
|
}
|
|
74
|
-
async function search(
|
|
75
|
-
const trimmed = (query ?? "").trim();
|
|
104
|
+
async function search(args) {
|
|
105
|
+
const trimmed = (args.query ?? "").trim();
|
|
76
106
|
if (!trimmed) {
|
|
77
|
-
|
|
78
|
-
kind: "memory_manage",
|
|
79
|
-
op: "search",
|
|
80
|
-
resultCount: 0,
|
|
81
|
-
});
|
|
107
|
+
rejectMissingArgument("search", "query", args);
|
|
82
108
|
}
|
|
83
109
|
// Reuse the recall scoring pipeline (single source of scoring truth) but scoped to the
|
|
84
110
|
// distilled durable files and with model rerank off, so this stays a cheap deterministic
|
|
@@ -110,14 +136,10 @@ export function createMemoryManageTool(options) {
|
|
|
110
136
|
resultCount: items.length,
|
|
111
137
|
});
|
|
112
138
|
}
|
|
113
|
-
async function forget(
|
|
114
|
-
const trimmed = (target ?? "").trim();
|
|
139
|
+
async function forget(args) {
|
|
140
|
+
const trimmed = (args.target ?? "").trim();
|
|
115
141
|
if (!trimmed) {
|
|
116
|
-
|
|
117
|
-
kind: "memory_manage",
|
|
118
|
-
op: "forget",
|
|
119
|
-
forgotten: false,
|
|
120
|
-
});
|
|
142
|
+
rejectMissingArgument("forget", "target", args);
|
|
121
143
|
}
|
|
122
144
|
const memoryPath = getChannelMemoryPath(options.channelDir);
|
|
123
145
|
const existing = await readOptionalTextFile(memoryPath);
|
|
@@ -161,11 +183,11 @@ export function createMemoryManageTool(options) {
|
|
|
161
183
|
execute: async (_toolCallId, args) => {
|
|
162
184
|
switch (args.op) {
|
|
163
185
|
case "save":
|
|
164
|
-
return save(args
|
|
186
|
+
return save(args);
|
|
165
187
|
case "search":
|
|
166
|
-
return search(args
|
|
188
|
+
return search(args);
|
|
167
189
|
case "forget":
|
|
168
|
-
return forget(args
|
|
190
|
+
return forget(args);
|
|
169
191
|
default:
|
|
170
192
|
throw new Error('Unsupported memory op. Use "save", "search", or "forget".');
|
|
171
193
|
}
|
|
@@ -4,7 +4,7 @@ import { join } from "node:path";
|
|
|
4
4
|
import { writeFileAtomically } from "../../shared/atomic-file.js";
|
|
5
5
|
import { normalizeTaskId, uncheckedTaskAcceptanceItems } from "../../shared/task-ledger.js";
|
|
6
6
|
import { RecoverableToolError } from "../tool-details.js";
|
|
7
|
-
import { renderTaskFile, renderTaskSkeleton, tasksDir
|
|
7
|
+
import { renderTaskFile, renderTaskSkeleton, tasksDir } from "./shared.js";
|
|
8
8
|
export async function createTask(options, request) {
|
|
9
9
|
if (!request.id)
|
|
10
10
|
throw new RecoverableToolError('action "create" requires an id.');
|
|
@@ -22,7 +22,6 @@ export async function createTask(options, request) {
|
|
|
22
22
|
const badDod = uncheckedTaskAcceptanceItems(body).find((item) => item.startsWith("DoD has no checklist items"));
|
|
23
23
|
if (badDod)
|
|
24
24
|
throw new RecoverableToolError(badDod);
|
|
25
|
-
await validateTaskRelations(options, id, fields);
|
|
26
25
|
await mkdir(dir, { recursive: true });
|
|
27
26
|
await writeFileAtomically(taskPath, renderTaskFile(fields, body));
|
|
28
27
|
return {
|
|
@@ -2,5 +2,12 @@ import type { TaskManageRequest, TaskManageResult, TaskManageToolOptions } from
|
|
|
2
2
|
export declare function setTask(options: TaskManageToolOptions, request: TaskManageRequest): Promise<TaskManageResult>;
|
|
3
3
|
export declare function progressTask(options: TaskManageToolOptions, request: TaskManageRequest): Promise<TaskManageResult>;
|
|
4
4
|
export declare function doneTask(options: TaskManageToolOptions, request: TaskManageRequest): Promise<TaskManageResult>;
|
|
5
|
+
/**
|
|
6
|
+
* Close one recurring occurrence without pretending its DoD was completed.
|
|
7
|
+
*
|
|
8
|
+
* This is the stateful counterpart of a silent/deduplicated wake: merely returning
|
|
9
|
+
* `[SILENT]` would leave the runtime-opened cycle active with no wake and cause retries.
|
|
10
|
+
*/
|
|
11
|
+
export declare function skipTask(options: TaskManageToolOptions, request: TaskManageRequest): Promise<TaskManageResult>;
|
|
5
12
|
export declare function cancelTask(options: TaskManageToolOptions, request: TaskManageRequest): Promise<TaskManageResult>;
|
|
6
13
|
export declare function listTasks(options: TaskManageToolOptions): Promise<TaskManageResult>;
|
|
@@ -4,10 +4,10 @@ import { writeFileAtomically } from "../../shared/atomic-file.js";
|
|
|
4
4
|
import { appendCurrentCycleNote, normalizeTaskId, readActiveTasks, uncheckedTaskAcceptanceItems, } from "../../shared/task-ledger.js";
|
|
5
5
|
import { workspaceSubjectHash } from "../../tasks/artifact-subject.js";
|
|
6
6
|
import { invalidateTaskVerification } from "../../tasks/control.js";
|
|
7
|
-
import {
|
|
7
|
+
import { taskBodyHash } from "../../tasks/store.js";
|
|
8
8
|
import { normalizeStoredStatus, resolveTaskTransition } from "../../tasks/transitions.js";
|
|
9
9
|
import { RecoverableToolError } from "../tool-details.js";
|
|
10
|
-
import { appendCompletionEvidence, applySet, cleanupTaskEvents, markdownValue, readTaskDocument, renderTaskFile, requiredField, tasksDir,
|
|
10
|
+
import { appendCompletionEvidence, applySet, cleanupTaskEvents, markdownValue, readTaskDocument, renderTaskFile, requiredField, tasksDir, } from "./shared.js";
|
|
11
11
|
import { assertVerificationAttestationMatches } from "./verification.js";
|
|
12
12
|
export async function setTask(options, request) {
|
|
13
13
|
if (!request.id)
|
|
@@ -23,7 +23,6 @@ export async function setTask(options, request) {
|
|
|
23
23
|
if (fromStatus === "verifying" && nextFields.status !== "verifying" && nextFields.control) {
|
|
24
24
|
nextFields.control = invalidateTaskVerification(nextFields.control);
|
|
25
25
|
}
|
|
26
|
-
await validateTaskRelations(options, id, nextFields);
|
|
27
26
|
await writeFileAtomically(taskPath, renderTaskFile(nextFields, body));
|
|
28
27
|
return {
|
|
29
28
|
action: "set",
|
|
@@ -42,20 +41,15 @@ export async function progressTask(options, request) {
|
|
|
42
41
|
const { fields, body } = await readTaskDocument(taskPath, id);
|
|
43
42
|
resolveTaskTransition("progress", id, normalizeStoredStatus(fields.status), request.status);
|
|
44
43
|
const nextFields = applySet(fields, request);
|
|
45
|
-
await validateTaskRelations(options, id, nextFields);
|
|
46
44
|
// D4: a progress note only appends to Current Cycle — it never touches the contract segment
|
|
47
45
|
// that PASS/approval bind to, so it no longer invalidates verification or approval. A real
|
|
48
46
|
// contract change (Goal/DoD/Manual/Verification) goes through write/edit and is caught by the
|
|
49
47
|
// contract-hash checks in verify/done/approve.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
nextFields.control.lastOutcome = "progress";
|
|
56
|
-
if (request.control?.blockedReason === undefined)
|
|
57
|
-
nextFields.control.blockedReason = undefined;
|
|
58
|
-
}
|
|
48
|
+
// Recording progress clears a stale "why it cannot proceed" note unless this call is parking
|
|
49
|
+
// the task (`waiting`) or states a new reason itself. `lastOutcome` is deliberately untouched:
|
|
50
|
+
// the runtime owns it (attempt claim/finish), so an action never has to keep it in sync.
|
|
51
|
+
if (nextFields.control && request.status !== "waiting" && request.control?.blockedReason === undefined) {
|
|
52
|
+
nextFields.control.blockedReason = undefined;
|
|
59
53
|
}
|
|
60
54
|
const nextBody = appendCurrentCycleNote(body, note);
|
|
61
55
|
await writeFileAtomically(taskPath, renderTaskFile(nextFields, nextBody));
|
|
@@ -79,14 +73,6 @@ export async function doneTask(options, request) {
|
|
|
79
73
|
if (uncheckedAcceptance.length > 0) {
|
|
80
74
|
throw new RecoverableToolError(`Task "${id}" still has unchecked acceptance items: ${uncheckedAcceptance.join("; ")}. Check them with evidence before done.`);
|
|
81
75
|
}
|
|
82
|
-
const dependencies = await dependencyState(options.channelDir, fields.control?.dependsOn ?? [], id);
|
|
83
|
-
if (!dependencies.ready) {
|
|
84
|
-
throw new RecoverableToolError(`Task "${id}" cannot be completed: ${dependencies.reason}. Complete its dependencies first.`);
|
|
85
|
-
}
|
|
86
|
-
const children = await unfinishedChildren(options, id);
|
|
87
|
-
if (children.length > 0) {
|
|
88
|
-
throw new RecoverableToolError(`Task "${id}" still has unfinished child tasks: ${children.join(", ")}. Finish or cancel them first.`);
|
|
89
|
-
}
|
|
90
76
|
if (fields.control?.sideEffects === "external") {
|
|
91
77
|
if (fields.control.externalApproval === "required") {
|
|
92
78
|
throw new Error(`Task "${id}" requires explicit external-action approval before it can be completed.`);
|
|
@@ -95,7 +81,7 @@ export async function doneTask(options, request) {
|
|
|
95
81
|
throw new Error(`Task "${id}" changed after external-action approval; ask the user to run /tasks approve ${id} again.`);
|
|
96
82
|
}
|
|
97
83
|
}
|
|
98
|
-
if (fields.control?.verification.
|
|
84
|
+
if (fields.control?.verification.required) {
|
|
99
85
|
const verification = fields.control.verification;
|
|
100
86
|
if (verification.status !== "passed" || !verification.bodyHash || !verification.runId) {
|
|
101
87
|
throw new RecoverableToolError(`Task "${id}" requires an independent PASS. Run a purpose=verify sub-agent, then task_manage verify with its run id.`);
|
|
@@ -104,18 +90,24 @@ export async function doneTask(options, request) {
|
|
|
104
90
|
throw new RecoverableToolError(`Task "${id}" changed after its independent PASS; rerun verification before done.`);
|
|
105
91
|
}
|
|
106
92
|
if (verification.subjectHash) {
|
|
93
|
+
// Fail closed (spec 036, D7): an attestation bound to a Git subject that cannot be
|
|
94
|
+
// recomputed is unverifiable, not implicitly fine.
|
|
107
95
|
const currentSubject = await workspaceSubjectHash(options.workingDirectory ?? process.cwd());
|
|
96
|
+
if (!currentSubject) {
|
|
97
|
+
throw new RecoverableToolError(`Task "${id}" has an independent PASS bound to a Git artifact subject, but the current checkout cannot be read. Run done from the project checkout, or rerun verification.`);
|
|
98
|
+
}
|
|
108
99
|
if (currentSubject !== verification.subjectHash) {
|
|
109
100
|
throw new RecoverableToolError(`Task "${id}" artifacts changed after its independent PASS; rerun verification before done.`);
|
|
110
101
|
}
|
|
111
102
|
}
|
|
112
103
|
await assertVerificationAttestationMatches(options.channelDir, id, verification);
|
|
113
104
|
}
|
|
105
|
+
// Spec 036 D5: `done` always records Summary/Evidence in the body. It no longer also stamps
|
|
106
|
+
// `verification.status = "passed"` for unverified tasks — that was the maker grading itself,
|
|
107
|
+
// and it made a self-report indistinguishable from a verifier's verdict.
|
|
114
108
|
const bodyWithEvidence = appendCompletionEvidence(body, request);
|
|
115
|
-
if (fields.control)
|
|
116
|
-
fields.control.lastOutcome = "verified";
|
|
109
|
+
if (fields.control)
|
|
117
110
|
fields.control.blockedReason = undefined;
|
|
118
|
-
}
|
|
119
111
|
// A recurring task (schedule frontmatter) sleeps in place until its next occurrence. The
|
|
120
112
|
// wake is cleared here and refilled to the next cron occurrence by the single time rule
|
|
121
113
|
// (`normalizeTaskFields`) on the write path, so "done + wake" always describes "asleep
|
|
@@ -146,6 +138,40 @@ export async function doneTask(options, request) {
|
|
|
146
138
|
notice: `任务 \`${id}\` 已完成(${disposition}${cleanup})。`,
|
|
147
139
|
};
|
|
148
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Close one recurring occurrence without pretending its DoD was completed.
|
|
143
|
+
*
|
|
144
|
+
* This is the stateful counterpart of a silent/deduplicated wake: merely returning
|
|
145
|
+
* `[SILENT]` would leave the runtime-opened cycle active with no wake and cause retries.
|
|
146
|
+
*/
|
|
147
|
+
export async function skipTask(options, request) {
|
|
148
|
+
if (!request.id)
|
|
149
|
+
throw new RecoverableToolError('action "skip" requires an id.');
|
|
150
|
+
const id = normalizeTaskId(request.id);
|
|
151
|
+
const reason = requiredField(request.reason, "reason", "skip");
|
|
152
|
+
const taskPath = join(tasksDir(options), `${id}.md`);
|
|
153
|
+
const { fields, body } = await readTaskDocument(taskPath, id);
|
|
154
|
+
resolveTaskTransition("skip", id, normalizeStoredStatus(fields.status));
|
|
155
|
+
if (!fields.schedule) {
|
|
156
|
+
throw new RecoverableToolError(`Task "${id}" is not recurring; use action "cancel" to abandon it or "done" after satisfying its DoD.`);
|
|
157
|
+
}
|
|
158
|
+
const skippedBody = appendCurrentCycleNote(body, `Skipped: ${reason}`);
|
|
159
|
+
if (fields.control) {
|
|
160
|
+
fields.control.blockedReason = undefined;
|
|
161
|
+
fields.control.verification = { required: fields.control.verification.required, status: "pending" };
|
|
162
|
+
}
|
|
163
|
+
await writeFileAtomically(taskPath, renderTaskFile({ ...fields, status: "done", wake: undefined }, skippedBody));
|
|
164
|
+
const { deleted } = await cleanupTaskEvents(options, id);
|
|
165
|
+
return {
|
|
166
|
+
action: "skip",
|
|
167
|
+
id,
|
|
168
|
+
path: taskPath,
|
|
169
|
+
status: "done",
|
|
170
|
+
archived: false,
|
|
171
|
+
deletedEvents: deleted,
|
|
172
|
+
notice: `任务 \`${id}\` 本周期已跳过并休眠至下一次计划唤醒;若无需通知用户,请回复 [SILENT]。`,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
149
175
|
export async function cancelTask(options, request) {
|
|
150
176
|
if (!request.id)
|
|
151
177
|
throw new RecoverableToolError('action "cancel" requires an id.');
|
|
@@ -155,14 +181,8 @@ export async function cancelTask(options, request) {
|
|
|
155
181
|
const taskPath = join(dir, `${id}.md`);
|
|
156
182
|
const { fields, body } = await readTaskDocument(taskPath, id);
|
|
157
183
|
resolveTaskTransition("cancel", id, normalizeStoredStatus(fields.status));
|
|
158
|
-
|
|
159
|
-
if (children.length > 0) {
|
|
160
|
-
throw new RecoverableToolError(`Task "${id}" still has unfinished child tasks: ${children.join(", ")}. Cancel or re-parent them first.`);
|
|
161
|
-
}
|
|
162
|
-
if (fields.control) {
|
|
163
|
-
fields.control.lastOutcome = "blocked";
|
|
184
|
+
if (fields.control)
|
|
164
185
|
fields.control.blockedReason = `Cancelled: ${reason}`;
|
|
165
|
-
}
|
|
166
186
|
const cancelledBody = `${body.replace(/\n+$/, "\n")}\n## Cancellation\n\n- Reason: ${markdownValue(reason)}\n`;
|
|
167
187
|
await writeFileAtomically(taskPath, renderTaskFile({ ...fields, status: "cancelled", wake: undefined }, cancelledBody));
|
|
168
188
|
const { deleted } = await cleanupTaskEvents(options, id);
|
|
@@ -3,7 +3,7 @@ import type { TaskManageAction } from "./types.js";
|
|
|
3
3
|
export declare const SETTABLE_STATUSES: readonly ["active", "waiting", "paused"];
|
|
4
4
|
export declare const taskManageSchema: Type.TObject<{
|
|
5
5
|
label: Type.TString;
|
|
6
|
-
action: Type.TUnion<[Type.TLiteral<"create">, Type.TLiteral<"progress">, Type.TLiteral<"set">, Type.TLiteral<"verify">, Type.TLiteral<"done">, Type.TLiteral<"cancel">, Type.TLiteral<"candidate">, Type.TLiteral<"list">]>;
|
|
6
|
+
action: Type.TUnion<[Type.TLiteral<"create">, Type.TLiteral<"progress">, Type.TLiteral<"set">, Type.TLiteral<"verify">, Type.TLiteral<"done">, Type.TLiteral<"skip">, Type.TLiteral<"cancel">, Type.TLiteral<"candidate">, Type.TLiteral<"list">]>;
|
|
7
7
|
id: Type.TOptional<Type.TString>;
|
|
8
8
|
title: Type.TOptional<Type.TString>;
|
|
9
9
|
goal: Type.TOptional<Type.TString>;
|
|
@@ -14,20 +14,13 @@ export declare const taskManageSchema: Type.TObject<{
|
|
|
14
14
|
priority: Type.TOptional<Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"normal">, Type.TLiteral<"high">, Type.TLiteral<"critical">]>>;
|
|
15
15
|
deadline: Type.TOptional<Type.TString>;
|
|
16
16
|
nextAction: Type.TOptional<Type.TString>;
|
|
17
|
-
lastOutcome: Type.TOptional<Type.TUnion<[Type.TLiteral<"pending">, Type.TLiteral<"running">, Type.TLiteral<"progress">, Type.TLiteral<"blocked">, Type.TLiteral<"failed">, Type.TLiteral<"verified">]>>;
|
|
18
17
|
blockedReason: Type.TOptional<Type.TString>;
|
|
19
18
|
parent: Type.TOptional<Type.TString>;
|
|
20
19
|
dependsOn: Type.TOptional<Type.TArray<Type.TString>>;
|
|
21
|
-
|
|
22
|
-
sideEffects: Type.TOptional<Type.TUnion<[Type.TLiteral<"read-only">, Type.TLiteral<"workspace">, Type.TLiteral<"external">]>>;
|
|
20
|
+
sideEffects: Type.TOptional<Type.TUnion<[Type.TLiteral<"workspace">, Type.TLiteral<"external">]>>;
|
|
23
21
|
externalApproval: Type.TOptional<Type.TUnion<[Type.TLiteral<"not-required">, Type.TLiteral<"required">]>>;
|
|
24
22
|
maxAttempts: Type.TOptional<Type.TInteger>;
|
|
25
|
-
maxTokens: Type.TOptional<Type.TNumber>;
|
|
26
|
-
maxCostUsd: Type.TOptional<Type.TNumber>;
|
|
27
|
-
maxWallTimeMinutes: Type.TOptional<Type.TNumber>;
|
|
28
23
|
verificationMode: Type.TOptional<Type.TUnion<[Type.TLiteral<"evidence">, Type.TLiteral<"independent">]>>;
|
|
29
|
-
worktreePath: Type.TOptional<Type.TString>;
|
|
30
|
-
worktreeBranch: Type.TOptional<Type.TString>;
|
|
31
24
|
}>>;
|
|
32
25
|
status: Type.TOptional<Type.TUnion<Type.TLiteral<"active" | "waiting" | "paused">[]>>;
|
|
33
26
|
wake: Type.TOptional<Type.TString>;
|
|
@@ -6,31 +6,19 @@ const taskControlSchema = Type.Object({
|
|
|
6
6
|
priority: Type.Optional(Type.Union([Type.Literal("low"), Type.Literal("normal"), Type.Literal("high"), Type.Literal("critical")])),
|
|
7
7
|
deadline: Type.Optional(Type.String({ description: "ISO8601 deadline; empty string clears it." })),
|
|
8
8
|
nextAction: Type.Optional(Type.String({ description: "Concrete next executable step; empty string clears it." })),
|
|
9
|
-
lastOutcome: Type.Optional(Type.Union([
|
|
10
|
-
Type.Literal("pending"),
|
|
11
|
-
Type.Literal("running"),
|
|
12
|
-
Type.Literal("progress"),
|
|
13
|
-
Type.Literal("blocked"),
|
|
14
|
-
Type.Literal("failed"),
|
|
15
|
-
Type.Literal("verified"),
|
|
16
|
-
])),
|
|
17
9
|
blockedReason: Type.Optional(Type.String({ description: "Why work cannot currently proceed; empty clears it." })),
|
|
18
10
|
parent: Type.Optional(Type.String({ description: "Parent task id; empty clears it." })),
|
|
19
11
|
dependsOn: Type.Optional(Type.Array(Type.String(), { description: "Task ids that must be done first." })),
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
sideEffects: Type.Optional(Type.Union([Type.Literal("workspace"), Type.Literal("external")], {
|
|
13
|
+
description: '"external" (sending, publishing, deploying, changing an outside system) requires user approval via "/tasks approve" before done.',
|
|
14
|
+
})),
|
|
22
15
|
externalApproval: Type.Optional(Type.Union([Type.Literal("not-required"), Type.Literal("required")], {
|
|
23
16
|
description: 'External approval can only be granted by a user with "/tasks approve <id>".',
|
|
24
17
|
})),
|
|
25
|
-
maxAttempts: Type.Optional(Type.Integer({ minimum: 1 })),
|
|
26
|
-
maxTokens: Type.Optional(Type.Number({ minimum: 0, description: "0 clears this budget." })),
|
|
27
|
-
maxCostUsd: Type.Optional(Type.Number({ minimum: 0, description: "0 clears this budget." })),
|
|
28
|
-
maxWallTimeMinutes: Type.Optional(Type.Number({ minimum: 0, description: "0 clears this budget." })),
|
|
18
|
+
maxAttempts: Type.Optional(Type.Integer({ minimum: 1, description: "Per-cycle attempt stop-loss; the only per-task budget." })),
|
|
29
19
|
verificationMode: Type.Optional(Type.Union([Type.Literal("evidence"), Type.Literal("independent")], {
|
|
30
20
|
description: 'On create, defaults to "evidence" (maker self-checks the DoD against concrete evidence). Set "independent" only when the task produces a checkable artifact (code, config, a runnable command) that a separate read-only verifier sub-agent can inspect — for research/writing/reminder-style tasks, "evidence" is cheaper and just as trustworthy.',
|
|
31
21
|
})),
|
|
32
|
-
worktreePath: Type.Optional(Type.String({ description: "Owned worktree path; empty clears it." })),
|
|
33
|
-
worktreeBranch: Type.Optional(Type.String()),
|
|
34
22
|
});
|
|
35
23
|
export const taskManageSchema = Type.Object({
|
|
36
24
|
label: Type.String({ description: "Brief description of the ledger change (shown to the user)" }),
|
|
@@ -40,11 +28,12 @@ export const taskManageSchema = Type.Object({
|
|
|
40
28
|
Type.Literal("set"),
|
|
41
29
|
Type.Literal("verify"),
|
|
42
30
|
Type.Literal("done"),
|
|
31
|
+
Type.Literal("skip"),
|
|
43
32
|
Type.Literal("cancel"),
|
|
44
33
|
Type.Literal("candidate"),
|
|
45
34
|
Type.Literal("list"),
|
|
46
35
|
], {
|
|
47
|
-
description: '"create" writes a governed task; "progress" atomically checkpoints work; "candidate" requests independent verification; "set" repairs metadata; "verify" imports an independent verifier attestation; "done" closes verified work; "cancel" closes abandoned work; "list" returns tasks. Recurring cycles are reopened automatically by the runtime.',
|
|
36
|
+
description: '"create" writes a governed task; "progress" atomically checkpoints work; "candidate" requests independent verification; "set" repairs metadata; "verify" imports an independent verifier attestation; "done" closes verified work; "skip" closes one recurring occurrence without claiming completion; "cancel" closes abandoned work; "list" returns tasks. Recurring cycles are reopened automatically by the runtime.',
|
|
48
37
|
}),
|
|
49
38
|
id: Type.Optional(Type.String({ description: "Task id (filename without .md). Required for create/progress/set/done." })),
|
|
50
39
|
title: Type.Optional(Type.String({ description: "Required for create: task title used as the H1 heading." })),
|
|
@@ -73,7 +62,7 @@ export const taskManageSchema = Type.Object({
|
|
|
73
62
|
description: "Required for done: verification evidence (tests, commands, review result, external confirmation, or a clear not-run reason).",
|
|
74
63
|
})),
|
|
75
64
|
residualRisk: Type.Optional(Type.String({ description: "Optional for done: remaining risk or follow-up note." })),
|
|
76
|
-
reason: Type.Optional(Type.String({ description: "Required for cancel: why the task
|
|
65
|
+
reason: Type.Optional(Type.String({ description: "Required for skip/cancel: why this occurrence was skipped or the task abandoned." })),
|
|
77
66
|
});
|
|
78
67
|
export function parseAction(action) {
|
|
79
68
|
if (action === "create" ||
|
|
@@ -82,9 +71,10 @@ export function parseAction(action) {
|
|
|
82
71
|
action === "set" ||
|
|
83
72
|
action === "verify" ||
|
|
84
73
|
action === "done" ||
|
|
74
|
+
action === "skip" ||
|
|
85
75
|
action === "cancel" ||
|
|
86
76
|
action === "list") {
|
|
87
77
|
return action;
|
|
88
78
|
}
|
|
89
|
-
throw new RecoverableToolError("Unsupported task action. Use create, progress, candidate, set, verify, done, cancel, or list.");
|
|
79
|
+
throw new RecoverableToolError("Unsupported task action. Use create, progress, candidate, set, verify, done, skip, cancel, or list.");
|
|
90
80
|
}
|
|
@@ -21,7 +21,6 @@ export declare function readTaskDocument(taskPath: string, id: string, allowCont
|
|
|
21
21
|
}>;
|
|
22
22
|
/** Apply a `set` request's optional fields onto the existing frontmatter. */
|
|
23
23
|
export declare function applySet(fields: TaskFields, request: TaskManageRequest): TaskFields;
|
|
24
|
-
export declare function validateTaskRelations(options: TaskManageToolOptions, id: string, fields: TaskFields): Promise<void>;
|
|
25
24
|
/**
|
|
26
25
|
* On close-out (done or cancel), delete every task-owned event.
|
|
27
26
|
*
|
|
@@ -33,4 +32,3 @@ export declare function validateTaskRelations(options: TaskManageToolOptions, id
|
|
|
33
32
|
export declare function cleanupTaskEvents(options: TaskManageToolOptions, id: string): Promise<{
|
|
34
33
|
deleted: string[];
|
|
35
34
|
}>;
|
|
36
|
-
export declare function unfinishedChildren(options: TaskManageToolOptions, parentId: string): Promise<string[]>;
|