@oyasmi/pipiclaw 0.9.1-beta.2 → 0.9.2-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/dist/agent/channel-runner.d.ts +9 -1
- package/dist/agent/channel-runner.js +51 -18
- package/dist/agent/command-extension.js +24 -27
- package/dist/agent/commands.d.ts +51 -7
- package/dist/agent/commands.js +199 -59
- package/dist/agent/effect-ledger.js +9 -2
- package/dist/agent/job-manager.d.ts +4 -0
- package/dist/agent/job-manager.js +17 -2
- package/dist/agent/prompt/manifest.d.ts +1 -1
- package/dist/agent/prompt/manifest.js +6 -7
- package/dist/agent/prompt/sections.js +9 -5
- package/dist/agent/reply-limits.d.ts +16 -0
- package/dist/agent/reply-limits.js +17 -0
- package/dist/agent/session-events.d.ts +2 -0
- package/dist/agent/session-events.js +29 -14
- package/dist/agent/status-render.js +12 -12
- package/dist/agent/turn-recovery.js +2 -2
- package/dist/agent/type-guards.js +5 -1
- package/dist/agent/workspace-resources.d.ts +2 -2
- package/dist/agent/workspace-resources.js +41 -3
- package/dist/executor.d.ts +28 -0
- package/dist/executor.js +120 -18
- package/dist/file-store.d.ts +96 -0
- package/dist/file-store.js +189 -0
- package/dist/main.js +3 -4
- package/dist/memory/commands.js +79 -38
- package/dist/memory/consolidation.d.ts +5 -1
- package/dist/memory/consolidation.js +35 -38
- package/dist/memory/extraction.d.ts +8 -1
- package/dist/memory/extraction.js +47 -4
- package/dist/memory/files.d.ts +0 -1
- package/dist/memory/files.js +31 -12
- package/dist/memory/lifecycle.js +9 -2
- package/dist/memory/maintenance-jobs.js +16 -38
- package/dist/memory/maintenance-state.js +2 -1
- package/dist/memory/metadata.d.ts +3 -0
- package/dist/memory/metadata.js +7 -0
- package/dist/memory/recall.d.ts +19 -0
- package/dist/memory/recall.js +116 -24
- package/dist/memory/review-log.d.ts +0 -2
- package/dist/memory/review-log.js +0 -0
- package/dist/memory/session-corpus.js +5 -0
- package/dist/memory/session-search.js +15 -22
- package/dist/memory/sidecar-worker.js +4 -0
- package/dist/memory/source-window.d.ts +0 -1
- package/dist/memory/source-window.js +0 -5
- package/dist/memory/transcript.d.ts +10 -0
- package/dist/memory/transcript.js +39 -0
- package/dist/playbooks/agent-delegation.md +34 -25
- package/dist/playbooks/background-jobs.md +8 -16
- package/dist/playbooks/catalog.d.ts +1 -1
- package/dist/playbooks/catalog.js +1 -1
- package/dist/playbooks/event-scheduling.md +15 -15
- package/dist/playbooks/memory-and-learning.md +30 -23
- package/dist/playbooks/outbound-media.md +15 -8
- package/dist/playbooks/runtime-orientation.md +40 -37
- package/dist/playbooks/task-driving.md +36 -38
- package/dist/playbooks/task-planning.md +21 -21
- package/dist/runtime/app-home.d.ts +6 -0
- package/dist/runtime/app-home.js +16 -7
- package/dist/runtime/bootstrap.js +54 -13
- package/dist/runtime/channel-context.d.ts +2 -1
- package/dist/runtime/delivery.js +3 -3
- package/dist/runtime/dingtalk.d.ts +9 -1
- package/dist/runtime/dingtalk.js +30 -15
- package/dist/runtime/durable-dispatch.d.ts +26 -1
- package/dist/runtime/durable-dispatch.js +51 -5
- package/dist/runtime/event-commands.d.ts +15 -0
- package/dist/runtime/event-commands.js +55 -56
- package/dist/runtime/events.d.ts +4 -2
- package/dist/runtime/events.js +15 -20
- package/dist/runtime/project-commands.d.ts +16 -0
- package/dist/runtime/project-commands.js +13 -17
- package/dist/runtime/subagent-commands.d.ts +20 -0
- package/dist/runtime/subagent-commands.js +61 -58
- package/dist/runtime/task-commands.d.ts +37 -0
- package/dist/runtime/task-commands.js +108 -66
- package/dist/runtime/task-driver.js +2 -2
- package/dist/security/block-message.d.ts +11 -0
- package/dist/security/block-message.js +12 -0
- package/dist/security/path-guard-check.d.ts +13 -0
- package/dist/security/path-guard-check.js +39 -0
- package/dist/security/path-guard.js +61 -12
- package/dist/security/types.d.ts +9 -0
- package/dist/settings.js +3 -2
- package/dist/shared/atomic-file.d.ts +17 -1
- package/dist/shared/atomic-file.js +50 -3
- package/dist/shared/duration.d.ts +2 -0
- package/dist/shared/duration.js +7 -0
- package/dist/shared/safe-id.d.ts +19 -0
- package/dist/shared/safe-id.js +24 -0
- package/dist/shared/text-utils.d.ts +1 -1
- package/dist/shared/text-utils.js +3 -8
- package/dist/shared/type-guards.d.ts +2 -0
- package/dist/shared/type-guards.js +4 -0
- package/dist/subagents/discovery.d.ts +51 -19
- package/dist/subagents/discovery.js +93 -98
- package/dist/subagents/external/claude-code.js +40 -2
- package/dist/subagents/external/harness.d.ts +1 -1
- package/dist/subagents/external/run.js +61 -8
- package/dist/subagents/format.d.ts +3 -2
- package/dist/subagents/format.js +3 -7
- package/dist/subagents/runs.d.ts +1 -1
- package/dist/subagents/runs.js +10 -9
- package/dist/subagents/tool.d.ts +31 -18
- package/dist/subagents/tool.js +592 -562
- package/dist/subagents/workspace-lease.js +1 -1
- package/dist/tasks/control.js +7 -9
- package/dist/tasks/ledger.d.ts +2 -2
- package/dist/tasks/ledger.js +3 -7
- package/dist/tasks/transitions.d.ts +5 -1
- package/dist/tasks/transitions.js +2 -2
- package/dist/tasks/verification.d.ts +7 -5
- package/dist/tools/bash.d.ts +1 -2
- package/dist/tools/bash.js +99 -76
- package/dist/tools/config.d.ts +6 -1
- package/dist/tools/config.js +9 -0
- package/dist/tools/edit.d.ts +2 -3
- package/dist/tools/edit.js +276 -75
- package/dist/tools/event-manage.d.ts +13 -7
- package/dist/tools/event-manage.js +52 -14
- package/dist/tools/glob-match.d.ts +11 -0
- package/dist/tools/glob-match.js +75 -0
- package/dist/tools/glob.d.ts +15 -0
- package/dist/tools/glob.js +113 -0
- package/dist/tools/grep.d.ts +0 -1
- package/dist/tools/grep.js +60 -44
- package/dist/tools/ignore-dirs.d.ts +6 -0
- package/dist/tools/ignore-dirs.js +15 -0
- package/dist/tools/index.d.ts +3 -0
- package/dist/tools/index.js +54 -40
- package/dist/tools/job.d.ts +0 -1
- package/dist/tools/job.js +3 -9
- package/dist/tools/line-index.d.ts +16 -0
- package/dist/tools/line-index.js +76 -0
- package/dist/tools/memory-manage.d.ts +21 -8
- package/dist/tools/memory-manage.js +114 -103
- package/dist/tools/presentation.d.ts +2 -0
- package/dist/tools/presentation.js +109 -0
- package/dist/tools/read.d.ts +2 -2
- package/dist/tools/read.js +100 -120
- package/dist/tools/registry.d.ts +4 -1
- package/dist/tools/registry.js +89 -22
- package/dist/tools/send-media.d.ts +6 -6
- package/dist/tools/send-media.js +21 -43
- package/dist/tools/session-search.d.ts +0 -1
- package/dist/tools/session-search.js +0 -1
- package/dist/tools/skill-security.d.ts +0 -2
- package/dist/tools/skill-security.js +1 -25
- package/dist/tools/skill.d.ts +31 -0
- package/dist/tools/skill.js +153 -0
- package/dist/tools/subagent-manage.d.ts +6 -5
- package/dist/tools/subagent-manage.js +47 -47
- package/dist/tools/task-manage/create.d.ts +2 -2
- package/dist/tools/task-manage/create.js +1 -3
- package/dist/tools/task-manage/lifecycle.d.ts +9 -6
- package/dist/tools/task-manage/lifecycle.js +49 -56
- package/dist/tools/task-manage/schema.d.ts +27 -15
- package/dist/tools/task-manage/schema.js +58 -74
- package/dist/tools/task-manage/shared.d.ts +11 -6
- package/dist/tools/task-manage/shared.js +30 -21
- package/dist/tools/task-manage/types.d.ts +14 -15
- package/dist/tools/task-manage/verification.d.ts +4 -4
- package/dist/tools/task-manage/verification.js +6 -8
- package/dist/tools/task-manage.d.ts +8 -11
- package/dist/tools/task-manage.js +63 -50
- package/dist/tools/tool-details.d.ts +17 -1
- package/dist/tools/tool-details.js +24 -0
- package/dist/tools/truncate.d.ts +8 -0
- package/dist/tools/truncate.js +8 -0
- package/dist/tools/web-fetch.d.ts +0 -1
- package/dist/tools/web-fetch.js +9 -2
- package/dist/tools/web-search.d.ts +0 -1
- package/dist/tools/web-search.js +0 -1
- package/dist/tools/write-content.d.ts +3 -3
- package/dist/tools/write-content.js +12 -41
- package/dist/tools/write.d.ts +2 -3
- package/dist/tools/write.js +3 -4
- package/dist/tui/app.js +1 -1
- package/dist/tui/commands.d.ts +1 -1
- package/dist/tui/commands.js +1 -1
- package/dist/tui/turn-controller.d.ts +1 -1
- package/dist/tui/turn-controller.js +14 -4
- package/dist/usage/ledger.js +7 -4
- package/dist/usage/render.js +10 -8
- package/examples/sub-agents/README.md +2 -0
- package/package.json +3 -2
- package/dist/tools/skill-manage.d.ts +0 -41
- package/dist/tools/skill-manage.js +0 -231
|
@@ -9,44 +9,27 @@ import { normalizeStoredStatus, resolveTaskTransition } from "../../tasks/transi
|
|
|
9
9
|
import { RecoverableToolError } from "../tool-details.js";
|
|
10
10
|
import { appendCompletionEvidence, applySet, cleanupTaskEvents, describeTaskSchedule, markdownValue, readTaskDocument, renderTaskFile, requiredField, tasksDir, } from "./shared.js";
|
|
11
11
|
import { assertVerificationAttestationMatches } from "./verification.js";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
/**
|
|
13
|
+
* `task_update` merges the old `progress`/`set` actions into one, branching on whether `note` is
|
|
14
|
+
* present (spec 046, D3.2): a note means "checkpoint an open cycle" (active/waiting only, and
|
|
15
|
+
* never repairs a bad control line in the same call); no note means "metadata-only edit" (also
|
|
16
|
+
* allowed on sleeping, and the only path that can repair an unparsable control line).
|
|
17
|
+
*/
|
|
18
|
+
export async function updateTask(options, request) {
|
|
15
19
|
const id = normalizeTaskId(request.id);
|
|
20
|
+
const hasNote = request.note !== undefined;
|
|
16
21
|
const taskPath = join(tasksDir(options), `${id}.md`);
|
|
17
|
-
const { fields, body } = await readTaskDocument(taskPath, id, request.control !== undefined);
|
|
18
|
-
const
|
|
19
|
-
resolveTaskTransition("
|
|
22
|
+
const { fields, body } = await readTaskDocument(taskPath, id, !hasNote && request.control !== undefined);
|
|
23
|
+
const from = normalizeStoredStatus(fields.status);
|
|
24
|
+
resolveTaskTransition(hasNote ? "checkpoint" : "metadata", id, from, request.status);
|
|
20
25
|
const nextFields = applySet(fields, request);
|
|
21
26
|
if (nextFields.status === "sleeping" && !nextFields.schedule) {
|
|
22
27
|
throw new RecoverableToolError(`Task "${id}" is one-shot; sleeping is valid only for recurring tasks.`);
|
|
23
28
|
}
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
action: "set",
|
|
27
|
-
id,
|
|
28
|
-
path: taskPath,
|
|
29
|
-
status: nextFields.status,
|
|
30
|
-
notice: `已更新任务 \`${id}\`(${describeTaskSchedule(nextFields)})。`,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
export async function progressTask(options, request) {
|
|
34
|
-
if (!request.id)
|
|
35
|
-
throw new RecoverableToolError('action "progress" requires an id.');
|
|
36
|
-
const id = normalizeTaskId(request.id);
|
|
37
|
-
const note = requiredField(request.note, "note", "progress");
|
|
38
|
-
const taskPath = join(tasksDir(options), `${id}.md`);
|
|
39
|
-
const { fields, body } = await readTaskDocument(taskPath, id);
|
|
40
|
-
const from = normalizeStoredStatus(fields.status);
|
|
41
|
-
resolveTaskTransition("progress", id, from, request.status);
|
|
42
|
-
if (from === "sleeping") {
|
|
43
|
-
throw new RecoverableToolError(`Task "${id}" is sleeping; wait for its occurrence or use /tasks run ${id}.`);
|
|
44
|
-
}
|
|
45
|
-
const nextFields = applySet(fields, request);
|
|
46
|
-
if (nextFields.status === "sleeping") {
|
|
29
|
+
if (hasNote && nextFields.status === "sleeping") {
|
|
47
30
|
throw new RecoverableToolError(`Progress cannot open a recurring cycle; use /tasks run ${id} or wait for its wake.`);
|
|
48
31
|
}
|
|
49
|
-
if (nextFields.control) {
|
|
32
|
+
if (hasNote && nextFields.control) {
|
|
50
33
|
if (nextFields.status === "active") {
|
|
51
34
|
nextFields.control.waitingFor = undefined;
|
|
52
35
|
}
|
|
@@ -54,36 +37,41 @@ export async function progressTask(options, request) {
|
|
|
54
37
|
nextFields.control.waitingFor = nextFields.wake ? "time" : "external-signal";
|
|
55
38
|
}
|
|
56
39
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
40
|
+
let nextBody = body;
|
|
41
|
+
if (request.planSteps?.length) {
|
|
42
|
+
const patched = applyTaskPlanPatch(body, request.planSteps);
|
|
43
|
+
nextBody = hasNote
|
|
44
|
+
? appendCurrentCycleNote(patched.body, patched.summary ? `${request.note} ${patched.summary}` : request.note)
|
|
45
|
+
: patched.body;
|
|
46
|
+
}
|
|
47
|
+
else if (hasNote) {
|
|
48
|
+
nextBody = appendCurrentCycleNote(body, request.note);
|
|
49
|
+
}
|
|
61
50
|
await writeFileAtomically(taskPath, renderTaskFile(nextFields, nextBody));
|
|
62
51
|
return {
|
|
63
|
-
action: "
|
|
52
|
+
action: "update",
|
|
64
53
|
id,
|
|
65
54
|
path: taskPath,
|
|
66
55
|
status: nextFields.status,
|
|
67
|
-
notice:
|
|
56
|
+
notice: hasNote
|
|
57
|
+
? `已记录任务 \`${id}\` 的进展(${describeTaskSchedule(nextFields)})。`
|
|
58
|
+
: `已更新任务 \`${id}\`(${describeTaskSchedule(nextFields)})。`,
|
|
68
59
|
};
|
|
69
60
|
}
|
|
70
|
-
|
|
71
|
-
if (!request.id)
|
|
72
|
-
throw new RecoverableToolError('action "complete" requires an id.');
|
|
73
|
-
const id = normalizeTaskId(request.id);
|
|
61
|
+
async function closeAsComplete(options, id, request) {
|
|
74
62
|
const dir = tasksDir(options);
|
|
75
63
|
const taskPath = join(dir, `${id}.md`);
|
|
76
64
|
const { fields, body } = await readTaskDocument(taskPath, id);
|
|
77
65
|
resolveTaskTransition("complete", id, normalizeStoredStatus(fields.status));
|
|
78
66
|
const uncheckedAcceptance = uncheckedTaskAcceptanceItems(body);
|
|
79
67
|
if (uncheckedAcceptance.length > 0) {
|
|
80
|
-
throw new RecoverableToolError(`Task "${id}" still has unchecked acceptance items: ${uncheckedAcceptance.join("; ")}. Check them with evidence before
|
|
68
|
+
throw new RecoverableToolError(`Task "${id}" still has unchecked acceptance items: ${uncheckedAcceptance.join("; ")}. Check them with evidence before task_close.`);
|
|
81
69
|
}
|
|
82
70
|
let verificationNote = "";
|
|
83
71
|
if (fields.control?.verification.required) {
|
|
84
72
|
const verification = fields.control.verification;
|
|
85
73
|
if (verification.status !== "passed" || !verification.runId) {
|
|
86
|
-
throw new RecoverableToolError(`Task "${id}" requires an independent PASS. Dispatch a purpose=verify sub-agent, then
|
|
74
|
+
throw new RecoverableToolError(`Task "${id}" requires an independent PASS. Dispatch a purpose=verify sub-agent, then task_verify with its run id.`);
|
|
87
75
|
}
|
|
88
76
|
// The attestation file is the sole authority — for the verdict, the body-hash freshness
|
|
89
77
|
// check, and the artifact subject. The task Markdown is agent-writable and proves nothing.
|
|
@@ -140,7 +128,7 @@ export async function completeTask(options, request) {
|
|
|
140
128
|
const { deleted } = await cleanupTaskEvents(options, id);
|
|
141
129
|
const cleanup = deleted.length > 0 ? `,清理事件 ${deleted.join(", ")}` : "";
|
|
142
130
|
return {
|
|
143
|
-
action: "
|
|
131
|
+
action: "close",
|
|
144
132
|
id,
|
|
145
133
|
path: finalPath,
|
|
146
134
|
status: recurring ? "sleeping" : undefined,
|
|
@@ -149,16 +137,13 @@ export async function completeTask(options, request) {
|
|
|
149
137
|
notice: `任务 \`${id}\` 已完成(${archived ? "已归档" : "已进入 sleeping,等待下一 occurrence"}${cleanup})。${verificationNote}`,
|
|
150
138
|
};
|
|
151
139
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
throw new RecoverableToolError('action "skip" requires an id.');
|
|
155
|
-
const id = normalizeTaskId(request.id);
|
|
156
|
-
const reason = requiredField(request.reason, "reason", "skip");
|
|
140
|
+
async function closeAsSkip(options, id, request) {
|
|
141
|
+
const reason = requiredField(request.reason, "reason", "task_close outcome=skip");
|
|
157
142
|
const taskPath = join(tasksDir(options), `${id}.md`);
|
|
158
143
|
const { fields, body } = await readTaskDocument(taskPath, id);
|
|
159
144
|
resolveTaskTransition("skip", id, normalizeStoredStatus(fields.status));
|
|
160
145
|
if (!fields.schedule) {
|
|
161
|
-
throw new RecoverableToolError(`Task "${id}" is not recurring; use complete after satisfying its DoD or cancel
|
|
146
|
+
throw new RecoverableToolError(`Task "${id}" is not recurring; use task_close outcome=complete after satisfying its DoD, or outcome=cancel.`);
|
|
162
147
|
}
|
|
163
148
|
const skippedBody = appendCurrentCycleNote(body, `Skipped: ${reason}`);
|
|
164
149
|
if (fields.control) {
|
|
@@ -168,7 +153,7 @@ export async function skipTask(options, request) {
|
|
|
168
153
|
await writeFileAtomically(taskPath, renderTaskFile({ ...fields, status: "sleeping", enabled: true, wake: undefined }, skippedBody));
|
|
169
154
|
const { deleted } = await cleanupTaskEvents(options, id);
|
|
170
155
|
return {
|
|
171
|
-
action: "
|
|
156
|
+
action: "close",
|
|
172
157
|
id,
|
|
173
158
|
path: taskPath,
|
|
174
159
|
status: "sleeping",
|
|
@@ -177,11 +162,8 @@ export async function skipTask(options, request) {
|
|
|
177
162
|
notice: `任务 \`${id}\` 本周期已跳过并进入 sleeping,等待下一次计划唤醒;若无需通知用户,请回复 [SILENT]。`,
|
|
178
163
|
};
|
|
179
164
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
throw new RecoverableToolError('action "cancel" requires an id.');
|
|
183
|
-
const id = normalizeTaskId(request.id);
|
|
184
|
-
const reason = requiredField(request.reason, "reason", "cancel");
|
|
165
|
+
async function closeAsCancel(options, id, request) {
|
|
166
|
+
const reason = requiredField(request.reason, "reason", "task_close outcome=cancel");
|
|
185
167
|
const dir = tasksDir(options);
|
|
186
168
|
const taskPath = join(dir, `${id}.md`);
|
|
187
169
|
const { fields, body } = await readTaskDocument(taskPath, id);
|
|
@@ -194,7 +176,7 @@ export async function cancelTask(options, request) {
|
|
|
194
176
|
const finalPath = join(archiveDir, `${id}.md`);
|
|
195
177
|
await rename(taskPath, finalPath);
|
|
196
178
|
return {
|
|
197
|
-
action: "
|
|
179
|
+
action: "close",
|
|
198
180
|
id,
|
|
199
181
|
path: finalPath,
|
|
200
182
|
status: undefined,
|
|
@@ -203,6 +185,17 @@ export async function cancelTask(options, request) {
|
|
|
203
185
|
notice: `任务 \`${id}\` 已取消并归档${deleted.length ? `,清理事件 ${deleted.join(", ")}` : ""}。`,
|
|
204
186
|
};
|
|
205
187
|
}
|
|
188
|
+
export async function closeTask(options, request) {
|
|
189
|
+
const id = normalizeTaskId(request.id);
|
|
190
|
+
switch (request.outcome) {
|
|
191
|
+
case "complete":
|
|
192
|
+
return closeAsComplete(options, id, request);
|
|
193
|
+
case "skip":
|
|
194
|
+
return closeAsSkip(options, id, request);
|
|
195
|
+
case "cancel":
|
|
196
|
+
return closeAsCancel(options, id, request);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
206
199
|
export async function listTasks(options) {
|
|
207
200
|
const entries = (await readActiveTasks(tasksDir(options))).filter((entry) => !entry.frontmatter.archiveOutcome);
|
|
208
201
|
return {
|
|
@@ -1,35 +1,47 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
|
-
import type { TaskManageAction } from "./types.js";
|
|
3
2
|
export declare const SETTABLE_STATUSES: readonly ["active", "waiting", "sleeping"];
|
|
4
|
-
export declare const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
export declare const taskListSchema: Type.TObject<{}>;
|
|
4
|
+
export declare const taskCreateSchema: Type.TObject<{
|
|
5
|
+
id: Type.TString;
|
|
6
|
+
title: Type.TString;
|
|
7
|
+
goal: Type.TString;
|
|
8
|
+
dod: Type.TString;
|
|
9
|
+
plan: Type.TOptional<Type.TString>;
|
|
11
10
|
manual: Type.TOptional<Type.TString>;
|
|
12
11
|
verificationPlan: Type.TOptional<Type.TString>;
|
|
13
|
-
|
|
12
|
+
verificationRequired: Type.TOptional<Type.TBoolean>;
|
|
13
|
+
status: Type.TOptional<Type.TUnion<Type.TLiteral<"active" | "waiting" | "sleeping">[]>>;
|
|
14
|
+
wake: Type.TOptional<Type.TString>;
|
|
15
|
+
schedule: Type.TOptional<Type.TString>;
|
|
16
|
+
deadline: Type.TOptional<Type.TString>;
|
|
17
|
+
}>;
|
|
18
|
+
export declare const taskUpdateSchema: Type.TObject<{
|
|
19
|
+
id: Type.TString;
|
|
20
|
+
note: Type.TOptional<Type.TString>;
|
|
14
21
|
planSteps: Type.TOptional<Type.TArray<Type.TObject<{
|
|
15
22
|
id: Type.TString;
|
|
16
23
|
status: Type.TOptional<Type.TUnion<[Type.TLiteral<"todo">, Type.TLiteral<"done">, Type.TLiteral<"blocked">, Type.TLiteral<"dropped">]>>;
|
|
17
24
|
text: Type.TOptional<Type.TString>;
|
|
18
25
|
}>>>;
|
|
26
|
+
status: Type.TOptional<Type.TUnion<Type.TLiteral<"active" | "waiting" | "sleeping">[]>>;
|
|
27
|
+
wake: Type.TOptional<Type.TString>;
|
|
28
|
+
schedule: Type.TOptional<Type.TString>;
|
|
19
29
|
control: Type.TOptional<Type.TObject<{
|
|
20
30
|
deadline: Type.TOptional<Type.TString>;
|
|
21
31
|
nextAction: Type.TOptional<Type.TString>;
|
|
22
32
|
waitingFor: Type.TOptional<Type.TUnion<[Type.TLiteral<"time">, Type.TLiteral<"user">, Type.TLiteral<"job">, Type.TLiteral<"external-signal">]>>;
|
|
23
33
|
verificationRequired: Type.TOptional<Type.TBoolean>;
|
|
24
34
|
}>>;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
verifierRunId: Type.TOptional<Type.TString>;
|
|
35
|
+
}>;
|
|
36
|
+
export declare const taskCloseSchema: Type.TObject<{
|
|
37
|
+
id: Type.TString;
|
|
38
|
+
outcome: Type.TUnion<[Type.TLiteral<"complete">, Type.TLiteral<"skip">, Type.TLiteral<"cancel">]>;
|
|
30
39
|
summary: Type.TOptional<Type.TString>;
|
|
31
40
|
evidence: Type.TOptional<Type.TString>;
|
|
32
41
|
residualRisk: Type.TOptional<Type.TString>;
|
|
33
42
|
reason: Type.TOptional<Type.TString>;
|
|
34
43
|
}>;
|
|
35
|
-
export declare
|
|
44
|
+
export declare const taskVerifySchema: Type.TObject<{
|
|
45
|
+
id: Type.TString;
|
|
46
|
+
verifierRunId: Type.TString;
|
|
47
|
+
}>;
|
|
@@ -1,89 +1,73 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
2
|
import { SETTABLE_TASK_STATUSES } from "../../tasks/transitions.js";
|
|
3
|
-
import { RecoverableToolError } from "../tool-details.js";
|
|
4
3
|
export const SETTABLE_STATUSES = SETTABLE_TASK_STATUSES;
|
|
4
|
+
const idField = Type.String({ description: "Task id (filename without .md)." });
|
|
5
|
+
const planStepsField = Type.Optional(Type.Array(Type.Object({
|
|
6
|
+
id: Type.String({ description: 'Plan step id, e.g. "P2"; new ids append a step.' }),
|
|
7
|
+
status: Type.Optional(Type.Union([Type.Literal("todo"), Type.Literal("done"), Type.Literal("blocked"), Type.Literal("dropped")], {
|
|
8
|
+
description: "New status for this step.",
|
|
9
|
+
})),
|
|
10
|
+
text: Type.Optional(Type.String({ description: "Step text; required when appending a new id." })),
|
|
11
|
+
}), { description: "Update or append Plan steps by id." }));
|
|
12
|
+
const wakeField = Type.Optional(Type.String({
|
|
13
|
+
description: "Earliest-recheck time; empty string clears it. Local time e.g. 2026-07-27T07:30:00+08:00, or relative +2h/+45m/+3d.",
|
|
14
|
+
}));
|
|
15
|
+
const scheduleField = Type.Optional(Type.String({
|
|
16
|
+
description: "Five-field cron cadence; makes this recurring. Empty string clears it. Min every 30 minutes.",
|
|
17
|
+
}));
|
|
18
|
+
export const taskListSchema = Type.Object({});
|
|
19
|
+
export const taskCreateSchema = Type.Object({
|
|
20
|
+
id: idField,
|
|
21
|
+
title: Type.String({ description: "Task title (H1 heading)." }),
|
|
22
|
+
goal: Type.String({ description: "Concise task goal." }),
|
|
23
|
+
dod: Type.String({
|
|
24
|
+
description: 'Checklist items, e.g. "- [ ] <criterion>"; plain prose is rejected.',
|
|
25
|
+
}),
|
|
26
|
+
plan: Type.Optional(Type.String({
|
|
27
|
+
description: 'Initial "## Plan" steps, one per line — the means, not the DoD.',
|
|
28
|
+
})),
|
|
29
|
+
manual: Type.Optional(Type.String({ description: "Initial operating steps or checklist." })),
|
|
30
|
+
verificationPlan: Type.Optional(Type.String({ description: "Deterministic checks the verifier must perform." })),
|
|
31
|
+
verificationRequired: Type.Optional(Type.Boolean({ description: "Whether complete requires a verifier attestation. Default false." })),
|
|
32
|
+
status: Type.Optional(Type.Union(SETTABLE_STATUSES.map((status) => Type.Literal(status)), { description: "Initial status; default active." })),
|
|
33
|
+
wake: wakeField,
|
|
34
|
+
schedule: scheduleField,
|
|
35
|
+
deadline: Type.Optional(Type.String({ description: "Local time deadline, e.g. 2026-07-27T18:00:00+08:00." })),
|
|
36
|
+
});
|
|
5
37
|
const taskControlSchema = Type.Object({
|
|
6
38
|
deadline: Type.Optional(Type.String({
|
|
7
|
-
description: "Local time deadline, e.g. 2026-07-27T18:00:00+08:00
|
|
39
|
+
description: "Local time deadline, e.g. 2026-07-27T18:00:00+08:00; empty string clears it.",
|
|
8
40
|
})),
|
|
9
41
|
nextAction: Type.Optional(Type.String({ description: "Concrete next executable step; empty string clears it." })),
|
|
10
42
|
waitingFor: Type.Optional(Type.Union([Type.Literal("time"), Type.Literal("user"), Type.Literal("job"), Type.Literal("external-signal")], {
|
|
11
|
-
description: "Diagnostic recovery source;
|
|
12
|
-
})),
|
|
13
|
-
verificationRequired: Type.Optional(Type.Boolean({
|
|
14
|
-
description: "Whether complete requires an independent verifier attestation. Default false; set true only when the task produces a checkable artifact (code, config, a runnable command) a read-only verifier sub-agent can inspect.",
|
|
43
|
+
description: "Diagnostic recovery source; record-only.",
|
|
15
44
|
})),
|
|
45
|
+
verificationRequired: Type.Optional(Type.Boolean({ description: "Whether complete requires a verifier attestation. Default false." })),
|
|
16
46
|
});
|
|
17
|
-
export const
|
|
18
|
-
|
|
19
|
-
action: Type.Union([
|
|
20
|
-
Type.Literal("create"),
|
|
21
|
-
Type.Literal("progress"),
|
|
22
|
-
Type.Literal("set"),
|
|
23
|
-
Type.Literal("verify"),
|
|
24
|
-
Type.Literal("complete"),
|
|
25
|
-
Type.Literal("skip"),
|
|
26
|
-
Type.Literal("cancel"),
|
|
27
|
-
Type.Literal("list"),
|
|
28
|
-
], {
|
|
29
|
-
description: '"create" writes a persistent task; "progress" checkpoints work — to wait on an independent verifier, dispatch a purpose=verify sub-agent with taskId and park like any other delegation (status=waiting, waitingFor=external-signal); "set" repairs metadata; "verify" imports the verifier\'s attestation by run id; "complete" closes a task; "skip" closes one recurring occurrence without claiming completion; "cancel" archives abandoned work; "list" returns tasks. Recurring tasks sleep between occurrences.',
|
|
30
|
-
}),
|
|
31
|
-
id: Type.Optional(Type.String({ description: "Task id (filename without .md). Required for create/progress/set/complete." })),
|
|
32
|
-
title: Type.Optional(Type.String({ description: "Required for create: task title used as the H1 heading." })),
|
|
33
|
-
goal: Type.Optional(Type.String({ description: "Required for create: concise task goal." })),
|
|
34
|
-
dod: Type.Optional(Type.String({
|
|
35
|
-
description: 'Required for create: acceptance criteria as Markdown checklist items, one per line, e.g. "- [ ] <criterion>". Plain prose or a numbered list without checkboxes is rejected — verification/complete can only verify items that are checkable.',
|
|
36
|
-
})),
|
|
37
|
-
manual: Type.Optional(Type.String({ description: "Optional for create: initial operating steps or checklist." })),
|
|
38
|
-
verificationPlan: Type.Optional(Type.String({ description: "Optional for create: deterministic checks the verifier must perform." })),
|
|
39
|
-
plan: Type.Optional(Type.String({
|
|
40
|
-
description: 'Optional for create: initial "## Plan" steps, one per line — the means, not the DoD. A step without a ' +
|
|
41
|
-
'leading "P<n>" id gets one auto-assigned in order. Update step status/text later via progress\'s planSteps, not by editing this at create time.',
|
|
42
|
-
})),
|
|
43
|
-
planSteps: Type.Optional(Type.Array(Type.Object({
|
|
44
|
-
id: Type.String({
|
|
45
|
-
description: 'Plan step id, e.g. "P2". An id not yet present is appended as a new step.',
|
|
46
|
-
}),
|
|
47
|
-
status: Type.Optional(Type.Union([Type.Literal("todo"), Type.Literal("done"), Type.Literal("blocked"), Type.Literal("dropped")], { description: "New status for this step; omit to leave it unchanged." })),
|
|
48
|
-
text: Type.Optional(Type.String({ description: "New step text; required when appending a step with an unseen id." })),
|
|
49
|
-
}), {
|
|
50
|
-
description: "For progress: update or append Plan steps by id, e.g. mark P2 done, P3 blocked, and add a new P5. " +
|
|
51
|
-
'Requires the task to already have a "## Plan" section, or this call is the one that creates it.',
|
|
52
|
-
})),
|
|
53
|
-
control: Type.Optional(taskControlSchema),
|
|
54
|
-
status: Type.Optional(Type.Union(SETTABLE_STATUSES.map((status) => Type.Literal(status)), { description: "New status for create/progress/set. Use complete/skip/cancel for lifecycle close-out." })),
|
|
55
|
-
wake: Type.Optional(Type.String({
|
|
56
|
-
description: "Earliest-recheck time for create/progress/set; empty string clears it. Local time, e.g. " +
|
|
57
|
-
"2026-07-27T07:30:00+08:00 (host timezone if no offset given), or a relative offset from now " +
|
|
58
|
-
"like +2h / +45m / +3d — never do the local-to-UTC conversion by hand. The native task driver " +
|
|
59
|
-
"resumes it; no .checkin event is needed.",
|
|
60
|
-
})),
|
|
61
|
-
schedule: Type.Optional(Type.String({
|
|
62
|
-
description: "Five-field cron cadence (host timezone) that makes this a recurring task; empty string clears it. " +
|
|
63
|
-
"Changing this on an existing task recomputes wake to the new cadence's next occurrence unless this " +
|
|
64
|
-
"same call also sets wake explicitly. Recurring creation starts in sleeping and opens cycles at occurrences. Min every 30 minutes.",
|
|
65
|
-
})),
|
|
47
|
+
export const taskUpdateSchema = Type.Object({
|
|
48
|
+
id: idField,
|
|
66
49
|
note: Type.Optional(Type.String({
|
|
67
|
-
description: "
|
|
50
|
+
description: "Current Cycle checkpoint — what changed, evidence, next step.",
|
|
68
51
|
})),
|
|
69
|
-
|
|
70
|
-
|
|
52
|
+
planSteps: planStepsField,
|
|
53
|
+
status: Type.Optional(Type.Union(SETTABLE_STATUSES.map((status) => Type.Literal(status)), { description: "New status; use task_close for lifecycle close-out." })),
|
|
54
|
+
wake: wakeField,
|
|
55
|
+
schedule: scheduleField,
|
|
56
|
+
control: Type.Optional(taskControlSchema),
|
|
57
|
+
});
|
|
58
|
+
export const taskCloseSchema = Type.Object({
|
|
59
|
+
id: idField,
|
|
60
|
+
outcome: Type.Union([Type.Literal("complete"), Type.Literal("skip"), Type.Literal("cancel")], {
|
|
61
|
+
description: "complete / skip (recurring only) / cancel.",
|
|
62
|
+
}),
|
|
63
|
+
summary: Type.Optional(Type.String({ description: "Concise completion summary; required for outcome=complete." })),
|
|
71
64
|
evidence: Type.Optional(Type.String({
|
|
72
|
-
description: "
|
|
65
|
+
description: "Verification evidence, or a clear not-run reason. Required for outcome=complete.",
|
|
73
66
|
})),
|
|
74
|
-
residualRisk: Type.Optional(Type.String({ description: "
|
|
75
|
-
reason: Type.Optional(Type.String({ description: "
|
|
67
|
+
residualRisk: Type.Optional(Type.String({ description: "Remaining risk or follow-up note; optional." })),
|
|
68
|
+
reason: Type.Optional(Type.String({ description: "Why this occurrence was skipped or the task abandoned; required for skip/cancel." })),
|
|
69
|
+
});
|
|
70
|
+
export const taskVerifySchema = Type.Object({
|
|
71
|
+
id: idField,
|
|
72
|
+
verifierRunId: Type.String({ description: "Run id returned by a purpose=verify sub-agent." }),
|
|
76
73
|
});
|
|
77
|
-
export function parseAction(action) {
|
|
78
|
-
if (action === "create" ||
|
|
79
|
-
action === "progress" ||
|
|
80
|
-
action === "set" ||
|
|
81
|
-
action === "verify" ||
|
|
82
|
-
action === "complete" ||
|
|
83
|
-
action === "skip" ||
|
|
84
|
-
action === "cancel" ||
|
|
85
|
-
action === "list") {
|
|
86
|
-
return action;
|
|
87
|
-
}
|
|
88
|
-
throw new RecoverableToolError("Unsupported task action. Next step: use create, progress, set, verify, complete, skip, cancel, or list.");
|
|
89
|
-
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TaskCloseRequest, TaskCreateRequest, TaskFields, TaskManageToolOptions, TaskUpdateRequest } from "./types.js";
|
|
2
2
|
export declare function tasksDir(options: TaskManageToolOptions): string;
|
|
3
3
|
export declare function eventsDir(options: TaskManageToolOptions): string;
|
|
4
4
|
export declare function renderTaskFile(fields: TaskFields, body: string): string;
|
|
5
5
|
export declare function requiredField(value: string | undefined, field: string, action: string): string;
|
|
6
6
|
export declare function requireNonEmpty(value: string | undefined, field: string): string;
|
|
7
7
|
export declare function markdownValue(value: string): string;
|
|
8
|
-
export declare function appendCompletionEvidence(body: string, request:
|
|
9
|
-
export declare function renderTaskSkeleton(request:
|
|
8
|
+
export declare function appendCompletionEvidence(body: string, request: TaskCloseRequest): string;
|
|
9
|
+
export declare function renderTaskSkeleton(request: TaskCreateRequest): {
|
|
10
10
|
fields: TaskFields;
|
|
11
11
|
body: string;
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
14
|
* Read a task file and split it into validated frontmatter and a verbatim body.
|
|
15
15
|
* Fail-closed: an unreadable frontmatter block is rejected (fix it with edit first)
|
|
16
|
-
* rather than guessed at, so
|
|
16
|
+
* rather than guessed at, so these tools never silently mangle a body.
|
|
17
17
|
*/
|
|
18
18
|
export declare function readTaskDocument(taskPath: string, id: string, allowControlRepair?: boolean): Promise<{
|
|
19
19
|
fields: TaskFields;
|
|
@@ -27,8 +27,8 @@ export declare function readTaskDocument(taskPath: string, id: string, allowCont
|
|
|
27
27
|
* moment the model chooses it, rather than leaving it to be rediscovered by a task that goes quiet.
|
|
28
28
|
*/
|
|
29
29
|
export declare function describeTaskSchedule(fields: TaskFields): string;
|
|
30
|
-
/** Apply a
|
|
31
|
-
export declare function applySet(fields: TaskFields, request:
|
|
30
|
+
/** Apply a metadata patch (status/wake/schedule/control) onto the existing frontmatter. */
|
|
31
|
+
export declare function applySet(fields: TaskFields, request: Pick<TaskUpdateRequest, "status" | "wake" | "schedule" | "control">): TaskFields;
|
|
32
32
|
/**
|
|
33
33
|
* On close-out (complete or cancel), delete every task-owned event.
|
|
34
34
|
*
|
|
@@ -36,6 +36,11 @@ export declare function applySet(fields: TaskFields, request: TaskManageRequest)
|
|
|
36
36
|
* recurring task needs no surviving `.schedule` event — the driver reopens each cycle from
|
|
37
37
|
* frontmatter. Any remaining task-owned events are temporary sensors/check-ins that a closed
|
|
38
38
|
* task should not keep alive. A file that cannot be parsed is left for `/events` to handle.
|
|
39
|
+
*
|
|
40
|
+
* Matching is done by parsing each candidate name and comparing the full task id, not by
|
|
41
|
+
* prefix — a prefix match on `task.<channel>.<id>.` would also match a *different* task whose
|
|
42
|
+
* id happens to start with this one plus a dot (e.g. closing "v1" must not delete events owned
|
|
43
|
+
* by "v1.2-release").
|
|
39
44
|
*/
|
|
40
45
|
export declare function cleanupTaskEvents(options: TaskManageToolOptions, id: string): Promise<{
|
|
41
46
|
deleted: string[];
|
|
@@ -7,7 +7,7 @@ import { formatLocalTime, parseWakeInput } from "../../shared/local-time.js";
|
|
|
7
7
|
import { errorMessage } from "../../shared/text-utils.js";
|
|
8
8
|
import { applyTaskControlPatch, createDefaultTaskControl } from "../../tasks/control.js";
|
|
9
9
|
import { normalizeTaskFields, parseTaskFrontmatter, renderStandardTaskBody, renderTaskDocument, taskBody, upsertCurrentCycleCompletionEvidence, } from "../../tasks/ledger.js";
|
|
10
|
-
import {
|
|
10
|
+
import { parseTaskEventName } from "../../tasks/task-events.js";
|
|
11
11
|
import { nextTaskWake, validateTaskSchedule } from "../../tasks/task-schedule.js";
|
|
12
12
|
import { isSettableTaskStatus } from "../../tasks/transitions.js";
|
|
13
13
|
import { RecoverableToolError } from "../tool-details.js";
|
|
@@ -24,12 +24,12 @@ export function renderTaskFile(fields, body) {
|
|
|
24
24
|
export function requiredField(value, field, action) {
|
|
25
25
|
const trimmed = value?.trim();
|
|
26
26
|
if (!trimmed) {
|
|
27
|
-
throw new RecoverableToolError(
|
|
27
|
+
throw new RecoverableToolError(`${action} requires ${field}.`);
|
|
28
28
|
}
|
|
29
29
|
return trimmed;
|
|
30
30
|
}
|
|
31
31
|
export function requireNonEmpty(value, field) {
|
|
32
|
-
return requiredField(value, field, "complete");
|
|
32
|
+
return requiredField(value, field, "task_close outcome=complete");
|
|
33
33
|
}
|
|
34
34
|
export function markdownValue(value) {
|
|
35
35
|
const lines = value.trim().split(/\r?\n/);
|
|
@@ -55,12 +55,14 @@ function normalizeCreateStatus(status) {
|
|
|
55
55
|
throw new RecoverableToolError(`Invalid status "${status}". Use one of ${SETTABLE_STATUSES.join(", ")}.`);
|
|
56
56
|
}
|
|
57
57
|
export function renderTaskSkeleton(request) {
|
|
58
|
-
const title = requiredField(request.title, "title", "create");
|
|
59
|
-
const goal = requiredField(request.goal, "goal", "create");
|
|
60
|
-
const dod = requiredField(request.dod, "dod", "create");
|
|
61
58
|
// Independent verification is opt-in: it is a quality fact, not an external-action policy.
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
// `deadline`/`verificationRequired` are flattened onto task_create (spec 046, D3.1) — creation
|
|
60
|
+
// has no `nextAction`/`waitingFor` to set, so there is nothing a nested `control` would add.
|
|
61
|
+
const control = applyTaskControlPatch(createDefaultTaskControl(request.verificationRequired ?? false), {
|
|
62
|
+
deadline: request.deadline,
|
|
63
|
+
verificationRequired: request.verificationRequired,
|
|
64
|
+
});
|
|
65
|
+
const fields = applySet({ status: normalizeCreateStatus(request.status), enabled: true, control }, { status: request.status, wake: request.wake, schedule: request.schedule });
|
|
64
66
|
if (!fields.schedule && fields.status === "sleeping") {
|
|
65
67
|
throw new RecoverableToolError('A one-shot task cannot use status "sleeping"; create it as active or waiting.');
|
|
66
68
|
}
|
|
@@ -75,9 +77,9 @@ export function renderTaskSkeleton(request) {
|
|
|
75
77
|
fields.wake = next ? formatLocalTime(next) : undefined;
|
|
76
78
|
}
|
|
77
79
|
const body = renderStandardTaskBody({
|
|
78
|
-
title,
|
|
79
|
-
goal,
|
|
80
|
-
dod,
|
|
80
|
+
title: request.title,
|
|
81
|
+
goal: request.goal,
|
|
82
|
+
dod: request.dod,
|
|
81
83
|
manual: request.manual,
|
|
82
84
|
verificationPlan: request.verificationPlan,
|
|
83
85
|
verificationRequired: control.verification.required,
|
|
@@ -88,19 +90,19 @@ export function renderTaskSkeleton(request) {
|
|
|
88
90
|
/**
|
|
89
91
|
* Read a task file and split it into validated frontmatter and a verbatim body.
|
|
90
92
|
* Fail-closed: an unreadable frontmatter block is rejected (fix it with edit first)
|
|
91
|
-
* rather than guessed at, so
|
|
93
|
+
* rather than guessed at, so these tools never silently mangle a body.
|
|
92
94
|
*/
|
|
93
95
|
export async function readTaskDocument(taskPath, id, allowControlRepair = false) {
|
|
94
96
|
if (!existsSync(taskPath)) {
|
|
95
|
-
throw new RecoverableToolError(`Task "${id}" does not exist; create it with
|
|
97
|
+
throw new RecoverableToolError(`Task "${id}" does not exist; create it with task_create first.`);
|
|
96
98
|
}
|
|
97
99
|
const content = await readFile(taskPath, "utf-8");
|
|
98
100
|
const frontmatter = parseTaskFrontmatter(content);
|
|
99
101
|
if (!frontmatter.readable) {
|
|
100
|
-
throw new RecoverableToolError(`Task "${id}" has no readable frontmatter; fix it with edit before using
|
|
102
|
+
throw new RecoverableToolError(`Task "${id}" has no readable frontmatter; fix it with edit before using task_update.`);
|
|
101
103
|
}
|
|
102
104
|
if (frontmatter.controlReadable === false && !allowControlRepair) {
|
|
103
|
-
throw new RecoverableToolError(`Task "${id}" has invalid control metadata; repair it with
|
|
105
|
+
throw new RecoverableToolError(`Task "${id}" has invalid control metadata; repair it with task_update (no note) and an explicit control patch first.`);
|
|
104
106
|
}
|
|
105
107
|
return {
|
|
106
108
|
fields: {
|
|
@@ -108,8 +110,8 @@ export async function readTaskDocument(taskPath, id, allowControlRepair = false)
|
|
|
108
110
|
enabled: frontmatter.enabled,
|
|
109
111
|
wake: frontmatter.wake,
|
|
110
112
|
schedule: frontmatter.schedule,
|
|
111
|
-
// A successful
|
|
112
|
-
//
|
|
113
|
+
// A successful write upgrades a hand-written/v0 task to the v2 control contract
|
|
114
|
+
// instead of preserving an ungoverned task indefinitely.
|
|
113
115
|
control: frontmatter.control ?? createDefaultTaskControl(),
|
|
114
116
|
outcome: frontmatter.archiveOutcome,
|
|
115
117
|
closedAt: frontmatter.closedAt,
|
|
@@ -133,12 +135,12 @@ export function describeTaskSchedule(fields) {
|
|
|
133
135
|
}
|
|
134
136
|
return `status: ${fields.status}${fields.wake ? `, wake: ${fields.wake}` : ""}`;
|
|
135
137
|
}
|
|
136
|
-
/** Apply a
|
|
138
|
+
/** Apply a metadata patch (status/wake/schedule/control) onto the existing frontmatter. */
|
|
137
139
|
export function applySet(fields, request) {
|
|
138
140
|
const next = { ...fields };
|
|
139
141
|
if (request.status !== undefined) {
|
|
140
142
|
if (!isSettableTaskStatus(request.status)) {
|
|
141
|
-
throw new RecoverableToolError(`Invalid status "${request.status}". Use one of ${SETTABLE_STATUSES.join(", ")}, or
|
|
143
|
+
throw new RecoverableToolError(`Invalid status "${request.status}". Use one of ${SETTABLE_STATUSES.join(", ")}, or task_close.`);
|
|
142
144
|
}
|
|
143
145
|
next.status = request.status;
|
|
144
146
|
}
|
|
@@ -188,15 +190,22 @@ export function applySet(fields, request) {
|
|
|
188
190
|
* recurring task needs no surviving `.schedule` event — the driver reopens each cycle from
|
|
189
191
|
* frontmatter. Any remaining task-owned events are temporary sensors/check-ins that a closed
|
|
190
192
|
* task should not keep alive. A file that cannot be parsed is left for `/events` to handle.
|
|
193
|
+
*
|
|
194
|
+
* Matching is done by parsing each candidate name and comparing the full task id, not by
|
|
195
|
+
* prefix — a prefix match on `task.<channel>.<id>.` would also match a *different* task whose
|
|
196
|
+
* id happens to start with this one plus a dot (e.g. closing "v1" must not delete events owned
|
|
197
|
+
* by "v1.2-release").
|
|
191
198
|
*/
|
|
192
199
|
export async function cleanupTaskEvents(options, id) {
|
|
193
200
|
const dir = eventsDir(options);
|
|
194
201
|
if (!existsSync(dir))
|
|
195
202
|
return { deleted: [] };
|
|
196
|
-
const prefix = taskEventPrefix(options.channelId, id);
|
|
197
203
|
const deleted = [];
|
|
198
204
|
for (const filename of (await readdir(dir)).sort()) {
|
|
199
|
-
if (!filename.endsWith(".json")
|
|
205
|
+
if (!filename.endsWith(".json"))
|
|
206
|
+
continue;
|
|
207
|
+
const parsed = parseTaskEventName(filename.slice(0, -".json".length), options.channelId);
|
|
208
|
+
if (parsed?.id !== id)
|
|
200
209
|
continue;
|
|
201
210
|
const eventPath = join(dir, filename);
|
|
202
211
|
let content;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { Static } from "typebox";
|
|
2
2
|
import type { TaskControl } from "../../tasks/control.js";
|
|
3
|
-
import type {
|
|
4
|
-
export type TaskManageAction = Static<typeof taskManageSchema>["action"];
|
|
3
|
+
import type { taskCloseSchema, taskCreateSchema, taskUpdateSchema, taskVerifySchema } from "./schema.js";
|
|
5
4
|
export interface TaskManageResult {
|
|
6
|
-
action:
|
|
5
|
+
action: "create" | "update" | "close" | "verify" | "list";
|
|
7
6
|
id?: string;
|
|
8
7
|
path?: string;
|
|
9
8
|
status?: string;
|
|
@@ -21,22 +20,22 @@ export interface TaskManageResult {
|
|
|
21
20
|
notice: string;
|
|
22
21
|
}
|
|
23
22
|
/**
|
|
24
|
-
*
|
|
23
|
+
* Five request types, derived from the five schemas the model actually sees (spec 046, D3.3) —
|
|
24
|
+
* the spec 036 D8 "derive from schema" discipline, doubled: each action's required fields are now
|
|
25
|
+
* non-optional in the type, not merely documented as "required for X" in a shared schema's prose.
|
|
25
26
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* independent acceptance — `verificationRequired` — was read by the implementation and absent
|
|
30
|
-
* from the schema, so no model could ever ask for it. Deriving the request type makes that class
|
|
31
|
-
* of drift a compile error. `label` is the tool's UI affordance, not part of the request.
|
|
32
|
-
*
|
|
33
|
-
* `status` stays a plain string: it is validated in code against the transition table so a legacy
|
|
34
|
-
* or closing legacy value gets a fixable error naming the right action, rather than a
|
|
35
|
-
* bare schema rejection.
|
|
27
|
+
* `status`/`outcome` stay plain strings where the underlying schema uses a literal union: they are
|
|
28
|
+
* validated in code against the transition table so a legacy or closing value gets a fixable error
|
|
29
|
+
* naming the right tool, rather than a bare schema rejection.
|
|
36
30
|
*/
|
|
37
|
-
export type
|
|
31
|
+
export type TaskCreateRequest = Omit<Static<typeof taskCreateSchema>, "status"> & {
|
|
32
|
+
status?: string;
|
|
33
|
+
};
|
|
34
|
+
export type TaskUpdateRequest = Omit<Static<typeof taskUpdateSchema>, "status"> & {
|
|
38
35
|
status?: string;
|
|
39
36
|
};
|
|
37
|
+
export type TaskCloseRequest = Static<typeof taskCloseSchema>;
|
|
38
|
+
export type TaskVerifyRequest = Static<typeof taskVerifySchema>;
|
|
40
39
|
export interface TaskManageToolOptions {
|
|
41
40
|
workspaceDir: string;
|
|
42
41
|
channelDir: string;
|