@oyasmi/pipiclaw 0.9.1 → 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.
Files changed (149) hide show
  1. package/dist/agent/channel-runner.d.ts +2 -1
  2. package/dist/agent/channel-runner.js +9 -5
  3. package/dist/agent/effect-ledger.js +9 -2
  4. package/dist/agent/job-manager.d.ts +4 -0
  5. package/dist/agent/job-manager.js +17 -2
  6. package/dist/agent/prompt/manifest.d.ts +1 -1
  7. package/dist/agent/prompt/manifest.js +1 -1
  8. package/dist/agent/prompt/sections.js +8 -5
  9. package/dist/agent/session-events.d.ts +2 -0
  10. package/dist/agent/session-events.js +29 -14
  11. package/dist/agent/turn-recovery.js +2 -2
  12. package/dist/agent/type-guards.js +5 -1
  13. package/dist/agent/workspace-resources.d.ts +2 -2
  14. package/dist/agent/workspace-resources.js +41 -3
  15. package/dist/executor.d.ts +14 -0
  16. package/dist/executor.js +96 -24
  17. package/dist/file-store.d.ts +96 -0
  18. package/dist/file-store.js +189 -0
  19. package/dist/memory/consolidation.js +2 -26
  20. package/dist/memory/files.js +7 -7
  21. package/dist/memory/maintenance-jobs.js +2 -34
  22. package/dist/memory/maintenance-state.js +2 -1
  23. package/dist/memory/recall.d.ts +10 -0
  24. package/dist/memory/recall.js +15 -7
  25. package/dist/memory/session-search.js +6 -22
  26. package/dist/memory/transcript.d.ts +10 -0
  27. package/dist/memory/transcript.js +39 -0
  28. package/dist/playbooks/agent-delegation.md +6 -4
  29. package/dist/playbooks/background-jobs.md +1 -1
  30. package/dist/playbooks/catalog.d.ts +1 -1
  31. package/dist/playbooks/catalog.js +1 -1
  32. package/dist/playbooks/event-scheduling.md +2 -0
  33. package/dist/playbooks/memory-and-learning.md +11 -11
  34. package/dist/playbooks/runtime-orientation.md +3 -3
  35. package/dist/playbooks/task-driving.md +5 -5
  36. package/dist/playbooks/task-planning.md +5 -5
  37. package/dist/runtime/app-home.js +1 -1
  38. package/dist/runtime/bootstrap.js +10 -0
  39. package/dist/runtime/dingtalk.js +3 -2
  40. package/dist/runtime/durable-dispatch.d.ts +26 -1
  41. package/dist/runtime/durable-dispatch.js +51 -5
  42. package/dist/runtime/event-commands.js +7 -16
  43. package/dist/runtime/events.d.ts +4 -2
  44. package/dist/runtime/events.js +15 -20
  45. package/dist/runtime/subagent-commands.js +1 -1
  46. package/dist/runtime/task-commands.d.ts +1 -1
  47. package/dist/runtime/task-commands.js +10 -10
  48. package/dist/runtime/task-driver.js +2 -2
  49. package/dist/security/block-message.d.ts +11 -0
  50. package/dist/security/block-message.js +12 -0
  51. package/dist/security/path-guard-check.d.ts +13 -0
  52. package/dist/security/path-guard-check.js +39 -0
  53. package/dist/security/path-guard.js +32 -14
  54. package/dist/settings.js +3 -2
  55. package/dist/shared/atomic-file.d.ts +17 -1
  56. package/dist/shared/atomic-file.js +50 -3
  57. package/dist/shared/duration.d.ts +2 -0
  58. package/dist/shared/duration.js +7 -0
  59. package/dist/shared/safe-id.d.ts +19 -0
  60. package/dist/shared/safe-id.js +24 -0
  61. package/dist/shared/text-utils.d.ts +1 -1
  62. package/dist/shared/text-utils.js +3 -8
  63. package/dist/shared/type-guards.d.ts +2 -0
  64. package/dist/shared/type-guards.js +4 -0
  65. package/dist/subagents/discovery.d.ts +44 -17
  66. package/dist/subagents/discovery.js +82 -111
  67. package/dist/subagents/external/claude-code.js +1 -3
  68. package/dist/subagents/external/harness.d.ts +1 -1
  69. package/dist/subagents/format.d.ts +3 -2
  70. package/dist/subagents/format.js +3 -7
  71. package/dist/subagents/runs.d.ts +1 -1
  72. package/dist/subagents/runs.js +4 -9
  73. package/dist/subagents/tool.d.ts +31 -19
  74. package/dist/subagents/tool.js +582 -561
  75. package/dist/subagents/workspace-lease.js +1 -1
  76. package/dist/tasks/control.js +7 -9
  77. package/dist/tasks/ledger.d.ts +2 -2
  78. package/dist/tasks/ledger.js +3 -7
  79. package/dist/tasks/transitions.d.ts +5 -1
  80. package/dist/tasks/transitions.js +2 -2
  81. package/dist/tools/bash.d.ts +0 -1
  82. package/dist/tools/bash.js +45 -40
  83. package/dist/tools/config.d.ts +6 -1
  84. package/dist/tools/config.js +9 -0
  85. package/dist/tools/edit.d.ts +2 -3
  86. package/dist/tools/edit.js +274 -86
  87. package/dist/tools/event-manage.d.ts +13 -7
  88. package/dist/tools/event-manage.js +52 -14
  89. package/dist/tools/glob-match.d.ts +11 -0
  90. package/dist/tools/glob-match.js +75 -0
  91. package/dist/tools/glob.d.ts +15 -0
  92. package/dist/tools/glob.js +113 -0
  93. package/dist/tools/grep.d.ts +0 -1
  94. package/dist/tools/grep.js +57 -42
  95. package/dist/tools/ignore-dirs.d.ts +6 -0
  96. package/dist/tools/ignore-dirs.js +15 -0
  97. package/dist/tools/index.d.ts +3 -0
  98. package/dist/tools/index.js +50 -40
  99. package/dist/tools/job.d.ts +0 -1
  100. package/dist/tools/job.js +1 -8
  101. package/dist/tools/line-index.d.ts +16 -0
  102. package/dist/tools/line-index.js +76 -0
  103. package/dist/tools/memory-manage.d.ts +20 -8
  104. package/dist/tools/memory-manage.js +65 -92
  105. package/dist/tools/presentation.d.ts +2 -0
  106. package/dist/tools/presentation.js +109 -0
  107. package/dist/tools/read.d.ts +2 -2
  108. package/dist/tools/read.js +97 -133
  109. package/dist/tools/registry.d.ts +4 -1
  110. package/dist/tools/registry.js +89 -22
  111. package/dist/tools/send-media.d.ts +6 -6
  112. package/dist/tools/send-media.js +16 -49
  113. package/dist/tools/session-search.d.ts +0 -1
  114. package/dist/tools/session-search.js +0 -1
  115. package/dist/tools/skill-security.d.ts +0 -2
  116. package/dist/tools/skill-security.js +0 -24
  117. package/dist/tools/skill.d.ts +31 -0
  118. package/dist/tools/skill.js +153 -0
  119. package/dist/tools/subagent-manage.d.ts +6 -5
  120. package/dist/tools/subagent-manage.js +47 -47
  121. package/dist/tools/task-manage/create.d.ts +2 -2
  122. package/dist/tools/task-manage/create.js +1 -3
  123. package/dist/tools/task-manage/lifecycle.d.ts +9 -6
  124. package/dist/tools/task-manage/lifecycle.js +49 -56
  125. package/dist/tools/task-manage/schema.d.ts +27 -15
  126. package/dist/tools/task-manage/schema.js +58 -74
  127. package/dist/tools/task-manage/shared.d.ts +11 -6
  128. package/dist/tools/task-manage/shared.js +30 -21
  129. package/dist/tools/task-manage/types.d.ts +14 -15
  130. package/dist/tools/task-manage/verification.d.ts +4 -4
  131. package/dist/tools/task-manage/verification.js +6 -8
  132. package/dist/tools/task-manage.d.ts +8 -11
  133. package/dist/tools/task-manage.js +63 -50
  134. package/dist/tools/tool-details.d.ts +17 -1
  135. package/dist/tools/tool-details.js +24 -0
  136. package/dist/tools/truncate.d.ts +5 -5
  137. package/dist/tools/truncate.js +5 -5
  138. package/dist/tools/web-fetch.d.ts +0 -1
  139. package/dist/tools/web-fetch.js +0 -1
  140. package/dist/tools/web-search.d.ts +0 -1
  141. package/dist/tools/web-search.js +0 -1
  142. package/dist/tools/write-content.d.ts +3 -3
  143. package/dist/tools/write-content.js +12 -51
  144. package/dist/tools/write.d.ts +2 -3
  145. package/dist/tools/write.js +3 -4
  146. package/dist/usage/ledger.js +7 -4
  147. package/package.json +1 -1
  148. package/dist/tools/skill-manage.d.ts +0 -41
  149. package/dist/tools/skill-manage.js +0 -232
@@ -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
- export async function setTask(options, request) {
13
- if (!request.id)
14
- throw new RecoverableToolError('action "set" requires an id.');
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 fromStatus = normalizeStoredStatus(fields.status);
19
- resolveTaskTransition("set", id, fromStatus, request.status);
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
- await writeFileAtomically(taskPath, renderTaskFile(nextFields, body));
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
- const { body: bodyWithPlan, summary: planSummary } = request.planSteps?.length
58
- ? applyTaskPlanPatch(body, request.planSteps)
59
- : { body, summary: "" };
60
- const nextBody = appendCurrentCycleNote(bodyWithPlan, planSummary ? `${note} ${planSummary}` : note);
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: "progress",
52
+ action: "update",
64
53
  id,
65
54
  path: taskPath,
66
55
  status: nextFields.status,
67
- notice: `已记录任务 \`${id}\` 的进展(${describeTaskSchedule(nextFields)})。`,
56
+ notice: hasNote
57
+ ? `已记录任务 \`${id}\` 的进展(${describeTaskSchedule(nextFields)})。`
58
+ : `已更新任务 \`${id}\`(${describeTaskSchedule(nextFields)})。`,
68
59
  };
69
60
  }
70
- export async function completeTask(options, request) {
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 complete.`);
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 task_manage verify with its run id.`);
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: "complete",
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
- export async function skipTask(options, request) {
153
- if (!request.id)
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 it.`);
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: "skip",
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
- export async function cancelTask(options, request) {
181
- if (!request.id)
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: "cancel",
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 taskManageSchema: Type.TObject<{
5
- label: Type.TString;
6
- action: Type.TUnion<[Type.TLiteral<"create">, Type.TLiteral<"progress">, Type.TLiteral<"set">, Type.TLiteral<"verify">, Type.TLiteral<"complete">, Type.TLiteral<"skip">, Type.TLiteral<"cancel">, Type.TLiteral<"list">]>;
7
- id: Type.TOptional<Type.TString>;
8
- title: Type.TOptional<Type.TString>;
9
- goal: Type.TOptional<Type.TString>;
10
- dod: Type.TOptional<Type.TString>;
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
- plan: Type.TOptional<Type.TString>;
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
- status: Type.TOptional<Type.TUnion<Type.TLiteral<"active" | "waiting" | "sleeping">[]>>;
26
- wake: Type.TOptional<Type.TString>;
27
- schedule: Type.TOptional<Type.TString>;
28
- note: Type.TOptional<Type.TString>;
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 function parseAction(action: string): TaskManageAction;
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 (host timezone if no offset given); empty string clears it.",
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; it does not create a new lifecycle status.",
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 taskManageSchema = Type.Object({
18
- label: Type.String({ description: "Brief description of the ledger change (shown to the user)" }),
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: "Required for progress: concise Current Cycle entry covering what changed, evidence observed, and the next step.",
50
+ description: "Current Cycle checkpoint — what changed, evidence, next step.",
68
51
  })),
69
- verifierRunId: Type.Optional(Type.String({ description: "Required for verify: run id returned by a purpose=verify sub-agent." })),
70
- summary: Type.Optional(Type.String({ description: "Required for complete: concise completion summary." })),
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: "Required for complete: verification evidence (tests, commands, review result, external confirmation, or a clear not-run reason).",
65
+ description: "Verification evidence, or a clear not-run reason. Required for outcome=complete.",
73
66
  })),
74
- residualRisk: Type.Optional(Type.String({ description: "Optional for complete: remaining risk or follow-up note." })),
75
- reason: Type.Optional(Type.String({ description: "Required for skip/cancel: why this occurrence was skipped or the task abandoned." })),
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 { TaskFields, TaskManageRequest, TaskManageToolOptions } from "./types.js";
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: TaskManageRequest): string;
9
- export declare function renderTaskSkeleton(request: TaskManageRequest): {
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 task_manage never silently mangles a body.
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 `set` request's optional fields onto the existing frontmatter. */
31
- export declare function applySet(fields: TaskFields, request: TaskManageRequest): TaskFields;
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 { taskEventPrefix } from "../../tasks/task-events.js";
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(`action "${action}" requires ${field}.`);
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
- const control = applyTaskControlPatch(createDefaultTaskControl(request.control?.verificationRequired ?? false), request.control ?? {});
63
- const fields = applySet({ status: normalizeCreateStatus(request.status), enabled: true, control }, request);
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 task_manage never silently mangles a body.
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 task_manage action "create" first.`);
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 task_manage.`);
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 task_manage action "set" and an explicit control patch first.`);
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 task_manage write upgrades a hand-written/v0 task to the v2
112
- // control contract instead of preserving an ungoverned task indefinitely.
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 `set` request's optional fields onto the existing frontmatter. */
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 action "complete".`);
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") || !filename.startsWith(prefix))
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 { taskManageSchema } from "./schema.js";
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: TaskManageAction;
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
- * A `task_manage` call, derived from the schema the model actually sees (spec 036, D8).
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
- * It used to be a hand-written mirror of `taskManageSchema`, and the two drifted apart in both
27
- * directions without a single type error: the schema advertised `parent`, `dependsOn` and
28
- * `verificationMode`, all three silently dropped on write, while the one field that turns on
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 TaskManageRequest = Omit<Static<typeof taskManageSchema>, "label" | "status"> & {
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;