@oyasmi/pipiclaw 0.9.5-beta.2 → 0.9.5-beta.4

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 (272) hide show
  1. package/README.en.md +9 -11
  2. package/README.md +9 -11
  3. package/dist/agent/channel-runner.d.ts +12 -24
  4. package/dist/agent/channel-runner.js +74 -30
  5. package/dist/agent/maintenance-context.d.ts +2 -0
  6. package/dist/agent/maintenance-context.js +15 -0
  7. package/dist/agent/prompt/sections.js +8 -6
  8. package/dist/agent/prompt/types.d.ts +1 -1
  9. package/dist/agent/runner-factory.js +1 -1
  10. package/dist/agent/session/command-extension.js +11 -0
  11. package/dist/agent/session/compaction-summary.js +6 -2
  12. package/dist/agent/session/execution-trace.d.ts +14 -0
  13. package/dist/agent/session/execution-trace.js +57 -0
  14. package/dist/agent/session/session-events.d.ts +2 -7
  15. package/dist/agent/session/session-events.js +35 -12
  16. package/dist/agent/session/session-host.d.ts +12 -22
  17. package/dist/agent/session/session-host.js +46 -65
  18. package/dist/agent/turn/task-digest.d.ts +1 -2
  19. package/dist/agent/turn/task-digest.js +33 -33
  20. package/dist/agent/turn/turn-context.d.ts +1 -1
  21. package/dist/agent/turn/turn-context.js +1 -1
  22. package/dist/agent/turn/turn-finish.d.ts +2 -2
  23. package/dist/agent/turn/turn-finish.js +3 -2
  24. package/dist/agent/turn/turn-pipeline.d.ts +4 -2
  25. package/dist/agent/turn/turn-pipeline.js +33 -5
  26. package/dist/agent/types.d.ts +64 -14
  27. package/dist/agent/types.js +3 -0
  28. package/dist/app/home.js +3 -4
  29. package/dist/channel/channel-event.d.ts +4 -12
  30. package/dist/channel/ingress.d.ts +1 -9
  31. package/dist/channel/store.d.ts +1 -1
  32. package/dist/commands/catalog.js +25 -19
  33. package/dist/commands/router.d.ts +5 -2
  34. package/dist/commands/router.js +9 -4
  35. package/dist/config/settings.d.ts +5 -12
  36. package/dist/config/settings.js +0 -7
  37. package/dist/config/tools.d.ts +2 -2
  38. package/dist/config/tools.js +2 -2
  39. package/dist/dingtalk/bot.d.ts +2 -0
  40. package/dist/dingtalk/bot.js +4 -0
  41. package/dist/dingtalk/cards.d.ts +7 -0
  42. package/dist/dingtalk/cards.js +32 -2
  43. package/dist/dingtalk/delivery.d.ts +4 -1
  44. package/dist/dingtalk/delivery.js +104 -191
  45. package/dist/dingtalk/progress.d.ts +41 -6
  46. package/dist/dingtalk/progress.js +173 -16
  47. package/dist/file-store.d.ts +4 -0
  48. package/dist/file-store.js +6 -1
  49. package/dist/jobs/completion-observer.d.ts +20 -0
  50. package/dist/jobs/completion-observer.js +107 -0
  51. package/dist/jobs/completion-signal.d.ts +9 -0
  52. package/dist/jobs/completion-signal.js +32 -0
  53. package/dist/jobs/completion-wake.d.ts +1 -1
  54. package/dist/jobs/completion-wake.js +2 -13
  55. package/dist/jobs/manager.d.ts +11 -29
  56. package/dist/jobs/manager.js +103 -176
  57. package/dist/jobs/probe.d.ts +3 -0
  58. package/dist/jobs/probe.js +42 -0
  59. package/dist/jobs/record.d.ts +3 -6
  60. package/dist/jobs/runtime.d.ts +28 -0
  61. package/dist/jobs/runtime.js +69 -0
  62. package/dist/memory/boundary-work.d.ts +2 -0
  63. package/dist/memory/boundary-work.js +79 -37
  64. package/dist/memory/commands.js +4 -1
  65. package/dist/memory/index-budget.js +18 -15
  66. package/dist/memory/journal.js +2 -1
  67. package/dist/memory/lifecycle.d.ts +4 -8
  68. package/dist/memory/lifecycle.js +21 -51
  69. package/dist/memory/reflect-job.d.ts +0 -6
  70. package/dist/memory/reflect-job.js +13 -34
  71. package/dist/memory/reflect.d.ts +4 -0
  72. package/dist/memory/reflect.js +32 -5
  73. package/dist/memory/review-log.d.ts +13 -0
  74. package/dist/memory/review-log.js +49 -0
  75. package/dist/memory/search.js +7 -4
  76. package/dist/memory/source-window.d.ts +18 -1
  77. package/dist/memory/source-window.js +59 -9
  78. package/dist/memory/store.d.ts +2 -0
  79. package/dist/memory/store.js +45 -13
  80. package/dist/playbooks/agent-delegation.md +10 -4
  81. package/dist/playbooks/background-jobs.md +4 -4
  82. package/dist/playbooks/event-scheduling.md +2 -2
  83. package/dist/playbooks/memory-and-learning.md +3 -3
  84. package/dist/playbooks/outbound-media.md +2 -2
  85. package/dist/playbooks/runtime-orientation.md +10 -6
  86. package/dist/playbooks/task-lead.md +54 -33
  87. package/dist/runtime/bootstrap.d.ts +11 -24
  88. package/dist/runtime/bootstrap.js +92 -59
  89. package/dist/runtime/channel-queue.d.ts +2 -0
  90. package/dist/runtime/channel-queue.js +5 -1
  91. package/dist/runtime/durable-dispatch.d.ts +7 -0
  92. package/dist/runtime/durable-dispatch.js +66 -7
  93. package/dist/runtime/ingress-busy.d.ts +1 -2
  94. package/dist/runtime/ingress-busy.js +2 -35
  95. package/dist/runtime/ingress-commands.d.ts +1 -1
  96. package/dist/runtime/ingress-commands.js +28 -20
  97. package/dist/runtime/ingress-deps.d.ts +4 -7
  98. package/dist/runtime/ingress.js +23 -13
  99. package/dist/runtime/shutdown.d.ts +1 -1
  100. package/dist/runtime/shutdown.js +2 -2
  101. package/dist/runtime/task-close.d.ts +4 -0
  102. package/dist/runtime/task-close.js +102 -0
  103. package/dist/runtime/task-control.d.ts +34 -0
  104. package/dist/runtime/task-control.js +225 -0
  105. package/dist/runtime/task-input.d.ts +13 -0
  106. package/dist/runtime/task-input.js +129 -0
  107. package/dist/runtime/task-lane-types.d.ts +123 -0
  108. package/dist/runtime/task-lane-types.js +14 -0
  109. package/dist/runtime/task-lane.d.ts +99 -0
  110. package/dist/runtime/task-lane.js +703 -0
  111. package/dist/runtime/task-pending.d.ts +8 -0
  112. package/dist/runtime/task-pending.js +40 -0
  113. package/dist/runtime/task-spawn.d.ts +4 -4
  114. package/dist/runtime/task-spawn.js +4 -4
  115. package/dist/runtime/task-step.d.ts +32 -0
  116. package/dist/runtime/task-step.js +276 -0
  117. package/dist/runtime/turn-run.d.ts +4 -16
  118. package/dist/runtime/turn-run.js +17 -155
  119. package/dist/runtime/wake-coalescing.d.ts +1 -3
  120. package/dist/runtime/wake-coalescing.js +2 -4
  121. package/dist/shared/format.d.ts +0 -6
  122. package/dist/shared/format.js +0 -17
  123. package/dist/shared/host-process.d.ts +2 -0
  124. package/dist/shared/host-process.js +16 -1
  125. package/dist/shared/jsonl-appender.d.ts +5 -0
  126. package/dist/shared/jsonl-appender.js +25 -2
  127. package/dist/skills/catalog.d.ts +9 -0
  128. package/dist/skills/catalog.js +34 -0
  129. package/dist/skills/commands.d.ts +3 -12
  130. package/dist/skills/commands.js +36 -22
  131. package/dist/skills/loader.d.ts +2 -31
  132. package/dist/skills/loader.js +101 -68
  133. package/dist/skills/roots.d.ts +12 -0
  134. package/dist/skills/roots.js +18 -0
  135. package/dist/skills/types.d.ts +24 -0
  136. package/dist/skills/types.js +1 -0
  137. package/dist/subagents/completion-wake.js +0 -10
  138. package/dist/subagents/discovery.d.ts +1 -1
  139. package/dist/subagents/discovery.js +10 -16
  140. package/dist/subagents/dispatch.js +8 -16
  141. package/dist/subagents/external/cursor-cli.d.ts +2 -0
  142. package/dist/subagents/external/cursor-cli.js +256 -0
  143. package/dist/subagents/external/harness.d.ts +5 -5
  144. package/dist/subagents/external/reconciliation.d.ts +7 -0
  145. package/dist/subagents/external/reconciliation.js +105 -0
  146. package/dist/subagents/external/recovery.d.ts +20 -0
  147. package/dist/subagents/external/recovery.js +71 -0
  148. package/dist/subagents/external/registry.js +2 -0
  149. package/dist/subagents/external/role-warnings.d.ts +17 -0
  150. package/dist/subagents/external/role-warnings.js +42 -0
  151. package/dist/subagents/external/run.js +18 -22
  152. package/dist/subagents/format.d.ts +1 -1
  153. package/dist/subagents/format.js +1 -1
  154. package/dist/subagents/grace.d.ts +2 -2
  155. package/dist/subagents/grace.js +3 -3
  156. package/dist/subagents/internal/run.js +7 -5
  157. package/dist/subagents/internal/worker.js +31 -2
  158. package/dist/subagents/result.js +2 -3
  159. package/dist/subagents/run-record.d.ts +4 -7
  160. package/dist/subagents/run-record.js +2 -2
  161. package/dist/subagents/runs.d.ts +33 -46
  162. package/dist/subagents/runs.js +126 -245
  163. package/dist/subagents/task-settlement.d.ts +3 -0
  164. package/dist/subagents/task-settlement.js +20 -0
  165. package/dist/subagents/types.d.ts +1 -2
  166. package/dist/subagents/workspace-summary.js +5 -1
  167. package/dist/tasks/archive.d.ts +11 -0
  168. package/dist/tasks/archive.js +141 -0
  169. package/dist/tasks/board.d.ts +5 -12
  170. package/dist/tasks/board.js +4 -30
  171. package/dist/tasks/bound-work.d.ts +12 -6
  172. package/dist/tasks/bound-work.js +37 -24
  173. package/dist/tasks/brief.d.ts +38 -14
  174. package/dist/tasks/brief.js +128 -70
  175. package/dist/tasks/budget.d.ts +3 -3
  176. package/dist/tasks/budget.js +9 -4
  177. package/dist/tasks/commands.d.ts +14 -9
  178. package/dist/tasks/commands.js +190 -121
  179. package/dist/tasks/completion.d.ts +12 -0
  180. package/dist/tasks/completion.js +35 -0
  181. package/dist/tasks/contract.d.ts +8 -17
  182. package/dist/tasks/contract.js +41 -43
  183. package/dist/tasks/control.d.ts +138 -0
  184. package/dist/tasks/control.js +1 -0
  185. package/dist/tasks/create.d.ts +1 -1
  186. package/dist/tasks/create.js +3 -3
  187. package/dist/tasks/delivery.d.ts +24 -0
  188. package/dist/tasks/delivery.js +221 -0
  189. package/dist/tasks/file-mutation.d.ts +5 -0
  190. package/dist/tasks/file-mutation.js +38 -0
  191. package/dist/tasks/frontmatter.d.ts +43 -28
  192. package/dist/tasks/frontmatter.js +83 -40
  193. package/dist/tasks/input-receipts.d.ts +7 -0
  194. package/dist/tasks/input-receipts.js +60 -0
  195. package/dist/tasks/loop-log.d.ts +147 -28
  196. package/dist/tasks/loop-log.js +239 -28
  197. package/dist/tasks/receipts.d.ts +19 -0
  198. package/dist/tasks/receipts.js +48 -0
  199. package/dist/tasks/state.d.ts +93 -0
  200. package/dist/tasks/state.js +156 -0
  201. package/dist/tasks/store.d.ts +81 -49
  202. package/dist/tasks/store.js +244 -147
  203. package/dist/tools/bash.d.ts +3 -5
  204. package/dist/tools/bash.js +8 -22
  205. package/dist/tools/contract/details.d.ts +6 -6
  206. package/dist/tools/contract/details.js +6 -6
  207. package/dist/tools/contract/execution-trace.d.ts +4 -0
  208. package/dist/tools/contract/execution-trace.js +23 -0
  209. package/dist/tools/contract/presentation.js +6 -2
  210. package/dist/tools/edit.d.ts +1 -0
  211. package/dist/tools/edit.js +45 -42
  212. package/dist/tools/index.d.ts +8 -12
  213. package/dist/tools/index.js +16 -6
  214. package/dist/tools/memory-manage.js +8 -1
  215. package/dist/tools/registry.d.ts +7 -11
  216. package/dist/tools/registry.js +52 -25
  217. package/dist/tools/skill.d.ts +2 -2
  218. package/dist/tools/skill.js +24 -10
  219. package/dist/tools/subagent-manage.js +7 -4
  220. package/dist/tools/subagent.d.ts +0 -2
  221. package/dist/tools/subagent.js +2 -7
  222. package/dist/tools/task-manage/control-tools.d.ts +4 -0
  223. package/dist/tools/task-manage/control-tools.js +65 -0
  224. package/dist/tools/task-manage/create.js +2 -1
  225. package/dist/tools/task-manage/factory.d.ts +12 -6
  226. package/dist/tools/task-manage/factory.js +72 -57
  227. package/dist/tools/task-manage/lifecycle.d.ts +7 -12
  228. package/dist/tools/task-manage/lifecycle.js +118 -66
  229. package/dist/tools/task-manage/log-view.js +8 -5
  230. package/dist/tools/task-manage/schema.d.ts +21 -26
  231. package/dist/tools/task-manage/schema.js +29 -35
  232. package/dist/tools/task-manage/shared.d.ts +8 -39
  233. package/dist/tools/task-manage/shared.js +19 -68
  234. package/dist/tools/task-manage/step-tools.d.ts +5 -0
  235. package/dist/tools/task-manage/step-tools.js +103 -0
  236. package/dist/tools/task-manage/types.d.ts +25 -18
  237. package/dist/tools/write-content.d.ts +1 -0
  238. package/dist/tools/write-content.js +6 -1
  239. package/dist/tools/write.d.ts +1 -0
  240. package/dist/tools/write.js +1 -0
  241. package/dist/usage/ledger.d.ts +4 -4
  242. package/dist/usage/render.js +2 -2
  243. package/dist/web/search-providers.js +0 -33
  244. package/dist/webapi/request-policy.js +1 -1
  245. package/examples/sub-agents/README.md +23 -16
  246. package/examples/sub-agents/agents/claude-high.md +1 -1
  247. package/examples/sub-agents/agents/claude-main.md +1 -1
  248. package/examples/sub-agents/agents/codex-flash.md +1 -1
  249. package/examples/sub-agents/agents/codex-high.md +1 -1
  250. package/examples/sub-agents/agents/codex-main.md +4 -4
  251. package/examples/sub-agents/agents/cursor-high.md +22 -0
  252. package/examples/sub-agents/agents/cursor-main.md +22 -0
  253. package/examples/sub-agents/agents/glm-flash.md +1 -1
  254. package/examples/sub-agents/agents/glm-high.md +2 -2
  255. package/examples/sub-agents/agents/scout.md +30 -0
  256. package/package.json +6 -6
  257. package/dist/runtime/task-driver.d.ts +0 -116
  258. package/dist/runtime/task-driver.js +0 -443
  259. package/dist/runtime/task-wake.d.ts +0 -48
  260. package/dist/runtime/task-wake.js +0 -32
  261. package/dist/shared/wake-claim.d.ts +0 -23
  262. package/dist/shared/wake-claim.js +0 -26
  263. package/dist/skills/validation.d.ts +0 -8
  264. package/dist/skills/validation.js +0 -91
  265. package/dist/skills/workspace.d.ts +0 -33
  266. package/dist/skills/workspace.js +0 -116
  267. package/dist/tasks/steer.d.ts +0 -8
  268. package/dist/tasks/steer.js +0 -81
  269. package/dist/tasks/ticket.d.ts +0 -71
  270. package/dist/tasks/ticket.js +0 -138
  271. package/dist/tools/task-manage/step-end.d.ts +0 -11
  272. package/dist/tools/task-manage/step-end.js +0 -117
@@ -1,31 +1,32 @@
1
1
  /**
2
- * `/tasks`: the user's control path for the channel's long-horizon tasks (list, show, log, pause,
3
- * resume, run, reply, steer, archive, doctor).
2
+ * `/tasks`: the user's control path for the desk's long-horizon tasks (list, show, log, msg, pause,
3
+ * resume, cancel, archive, doctor). Every state change goes through the `TaskControl` port (spec 064,
4
+ * D25); this module only parses, renders and calls it.
4
5
  */
5
6
  import { existsSync } from "node:fs";
6
7
  import { readdir } from "node:fs/promises";
7
8
  import { join } from "node:path";
8
9
  import { renderSubcommandUsage } from "../commands/catalog.js";
9
10
  import { capReply, flattenMarkdownForChat } from "../commands/reply-limits.js";
10
- import { formatSpanZh } from "../shared/format.js";
11
+ import { formatElapsedZh } from "../shared/format.js";
11
12
  import { parseLocalTime } from "../shared/local-time.js";
12
13
  import { errorMessage } from "../shared/text-utils.js";
14
+ import { isTaskArchiving } from "./archive.js";
13
15
  import { buildTaskBoard, renderTaskBoardForUser } from "./board.js";
16
+ import { taskCostSummary } from "./budget.js";
14
17
  import { normalizeTaskId, readActiveTasks } from "./contract.js";
18
+ import { readTaskDeliveries } from "./delivery.js";
15
19
  import { taskStateLabel } from "./frontmatter.js";
16
- import { readTaskLog, renderTaskLogLineForUser, taskArchiveLogPath, taskLogIsArchived, taskLogPath, } from "./loop-log.js";
17
- import { withTaskMutation } from "./mutation-lock.js";
18
- import { hasTaskSteer, queueTaskSteer } from "./steer.js";
19
- import { archivedTaskPath, pauseTask as pauseTaskDocument, readStoredTask, redeemTicket, resumeTask as resumeTaskDocument, taskPath, updateStoredTask, } from "./store.js";
20
- import { describeTicketForUser } from "./ticket.js";
20
+ import { readTaskLog, renderTaskLogLineForUser, taskArchiveLogPath, taskLogIsArchived, taskLogIssues, taskLogPath, } from "./loop-log.js";
21
+ import { archivedTaskPath, readStoredTask, taskPath } from "./store.js";
21
22
  /** `/tasks show <id>` contract excerpt; the full file is always readable at its own path. */
22
23
  const TASK_SHOW_CONTRACT_CHARS = 500;
23
24
  const SHOW_LOG_LINES = 5;
24
25
  /** `/tasks log <id>`: the most recent records; older ones are in the `.jsonl` it names. */
25
26
  const LOG_LINES = 15;
26
27
  const ARCHIVE_LIST_LIMIT = 20;
27
- /** A backstop this far past due means the driver is not running, not that it is merely about to act. */
28
- const EXPIRED_GRACE_MS = 60 * 60 * 1000;
28
+ /** A work wait this old with nothing in flight means the lane is not running, not that it is about to act. */
29
+ const STALE_WORK_WAIT_MS = 60 * 60 * 1000;
29
30
  // Broadcast (subcommand names, args, descriptions, examples) lives once in commands/catalog.ts's
30
31
  // `BUILT_IN_COMMANDS` entry for "tasks"; this just renders it (review 2026-08-24 §3.1).
31
32
  function usage() {
@@ -58,7 +59,7 @@ export function parseTasksCommand(args) {
58
59
  throw new Error(`用法:/tasks ${action}`);
59
60
  return { action };
60
61
  }
61
- if (action === "show" || action === "pause" || action === "log") {
62
+ if (action === "show" || action === "pause" || action === "log" || action === "cancel") {
62
63
  const id = parts[1];
63
64
  if (!id || parts.length > 2)
64
65
  throw new Error(`用法:/tasks ${action} <id>`);
@@ -70,11 +71,11 @@ export function parseTasksCommand(args) {
70
71
  throw new Error("用法:/tasks resume <id> [+steps N|+usd X]");
71
72
  return { action: "resume", id, grants: parseGrants(parts.slice(2).join(" ")) };
72
73
  }
73
- if (action === "steer" || action === "reply") {
74
- // Everything after the id is the message, verbatim — guidance is a sentence.
75
- const match = /^(?:steer|reply)\s+(\S+)\s+([\s\S]+)$/.exec(trimmed);
74
+ if (action === "msg") {
75
+ // Everything after the id is the message, verbatim — it is a sentence addressed to the task.
76
+ const match = /^msg\s+(\S+)\s+([\s\S]+)$/.exec(trimmed);
76
77
  if (!match)
77
- throw new Error(`用法:/tasks ${action} <id> <内容>`);
78
+ throw new Error("用法:/tasks msg <id> <内容>");
78
79
  return { action, id: match[1], text: match[2].trim() };
79
80
  }
80
81
  throw new Error(`未知子命令 \`${action}\`。`);
@@ -82,45 +83,61 @@ export function parseTasksCommand(args) {
82
83
  function tasksDir(deskDir) {
83
84
  return join(deskDir, "tasks");
84
85
  }
85
- /** `(最晚 3 小时后重新检查)` — when the runtime looks at a parked task again no matter what. */
86
- function backstopHint(by, now) {
87
- const atMs = parseLocalTime(by);
88
- if (atMs === undefined || !Number.isFinite(atMs))
89
- return "";
90
- const diffMs = atMs - now;
91
- return diffMs <= 0 ? "(已过最晚检查时间)" : `(最晚 ${formatSpanZh(diffMs)}后重新检查)`;
92
- }
93
86
  function usageSummary(entry) {
94
87
  const usage = entry.fields.usage;
95
88
  if (!usage)
96
89
  return undefined;
97
- const cost = usage.usd > 0 ? ` · 花费 $${usage.usd.toFixed(2)}${usage.usdEstimated ? "(含估算)" : ""}` : "";
90
+ const cost = usage.usd > 0 || usage.unknownCostCount ? ` · 花费 ${taskCostSummary(usage)}` : "";
98
91
  return `已用 ${usage.steps} 步${cost}`;
99
92
  }
100
- function ticketSummary(entry, now) {
101
- const ticket = entry.fields.ticket;
102
- return ticket ? `${describeTicketForUser(ticket)}${backstopHint(ticket.by, now)}` : undefined;
103
- }
104
93
  /** The delivery-channel note for a task, or `undefined` when it delivers here and is live. */
105
94
  function deliveryNote(channel, options) {
106
95
  if (!channel)
107
- return "已暂停:未指定投递频道";
96
+ return "已冻结:未指定汇报频道";
108
97
  const described = options.describeChannel(channel);
109
98
  if (!described.boundHere)
110
- return `已暂停:投递频道未绑定到本工位(${described.label})`;
111
- return channel === options.currentChannelId ? undefined : `投递到${described.label}`;
99
+ return `已冻结:汇报频道未绑定到本工位(${described.label})`;
100
+ return channel === options.currentChannelId ? undefined : `汇报到${described.label}`;
112
101
  }
113
- function renderListLine(entry, options, now) {
114
- const { deskDir } = options;
115
- const bits = [`\`${entry.id}\` ${entry.title}`, taskStateLabel(entry.fields.state)];
102
+ /** The state in the user's words, with how long it has been so and what is happening right now. */
103
+ function describeLive(entry, live, now) {
104
+ if (live?.closing)
105
+ return "交付与收尾中";
106
+ const label = taskStateLabel(entry.fields);
107
+ if (entry.fields.state === "running" && live?.step) {
108
+ const tool = live.step.tool ? `,正在${live.step.tool.summary}` : "";
109
+ return `${label}(第 ${live.step.seq} 步,已 ${formatElapsedZh(now - live.step.startedAt)}${tool})`;
110
+ }
111
+ const since = entry.fields.waiting ? parseLocalTime(entry.fields.waiting.since) : undefined;
112
+ if (entry.fields.state === "waiting" &&
113
+ entry.fields.waiting?.kind !== "time" &&
114
+ since !== undefined &&
115
+ now > since) {
116
+ return `${label}(已等 ${formatElapsedZh(now - since)})`;
117
+ }
118
+ return label;
119
+ }
120
+ function describePending(live, now) {
121
+ return live.pending.map((work) => {
122
+ const who = work.kind === "delegation" ? `委派 \`${work.ref}\`(${work.label})` : `后台作业 \`${work.ref}\``;
123
+ const quiet = work.stalled && work.lastOutputAt !== undefined
124
+ ? ` · ⚠️ ${formatElapsedZh(now - work.lastOutputAt)}没有输出`
125
+ : "";
126
+ return `${who} 已运行 ${formatElapsedZh(now - work.startedAt)}${quiet}`;
127
+ });
128
+ }
129
+ function renderListLine(entry, live, options, now) {
130
+ const bits = [`\`${entry.id}\` ${entry.title}`, describeLive(entry, live, now)];
116
131
  const delivery = deliveryNote(entry.fields.channel, options);
117
132
  if (delivery)
118
133
  bits.push(delivery);
119
- if (entry.fields.paused)
120
- bits.push(`已暂停(${entry.fields.paused.reason})`);
121
- const ticket = ticketSummary(entry, now);
122
- if (ticket)
123
- bits.push(ticket);
134
+ if (entry.fields.state === "waiting" && entry.fields.waiting?.kind === "user") {
135
+ bits.push(`问题:${entry.fields.waiting.question.replace(/\s+/g, " ").slice(0, 80)}`);
136
+ }
137
+ if (live && live.pending.length > 0) {
138
+ const stalled = live.pending.filter((work) => work.stalled).length;
139
+ bits.push(`在途 ${live.pending.length} 项${stalled > 0 ? `(⚠️ ${stalled} 项疑似卡住)` : ""}`);
140
+ }
124
141
  if (entry.items)
125
142
  bits.push(`工作项 ${entry.items.done}/${entry.items.total}`);
126
143
  if (entry.fields.origin)
@@ -128,21 +145,24 @@ function renderListLine(entry, options, now) {
128
145
  const usage = usageSummary(entry);
129
146
  if (usage)
130
147
  bits.push(usage);
131
- if (hasTaskSteer(deskDir, entry.id))
132
- bits.push("有待处理的指示");
133
148
  if (!entry.readable)
134
149
  bits.push("⚠️ 文件头(frontmatter)不可读");
135
150
  return `- ${bits.join(" · ")}`;
136
151
  }
152
+ async function snapshotsById(options) {
153
+ const snapshots = await options.control.snapshot(options.desk).catch(() => []);
154
+ return new Map(snapshots.map((snapshot) => [snapshot.id, snapshot]));
155
+ }
137
156
  async function listTasks(options) {
138
157
  const now = Date.now();
139
- const entries = (await readActiveTasks(tasksDir(options.deskDir), now)).filter((entry) => !entry.fields.outcome);
158
+ const entries = (await readActiveTasks(tasksDir(options.deskDir))).filter((entry) => !entry.fields.outcome);
140
159
  if (entries.length === 0) {
141
160
  return "暂无进行中的任务。\n在对话里告诉我目标,并说明作为长程任务推进。";
142
161
  }
162
+ const live = await snapshotsById(options);
143
163
  const report = [
144
164
  `**任务(${entries.length})**`,
145
- ...entries.map((entry) => renderListLine(entry, options, now)),
165
+ ...entries.map((entry) => renderListLine(entry, live.get(entry.id), options, now)),
146
166
  ].join("\n");
147
167
  return capReply(report, { nextStepHint: "用 `/tasks show <id>` 查看单个任务" }).text;
148
168
  }
@@ -167,36 +187,43 @@ async function showTask(options, idInput) {
167
187
  if (!document)
168
188
  return notFound(id);
169
189
  const now = Date.now();
170
- const entry = (await readActiveTasks(tasksDir(deskDir), now)).find((candidate) => candidate.id === id);
190
+ const entry = (await readActiveTasks(tasksDir(deskDir))).find((candidate) => candidate.id === id);
191
+ const live = entry ? (await options.control.snapshot(options.desk, id).catch(() => []))[0] : undefined;
171
192
  const head = [`**任务 ${id}**`];
172
- head.push(`- 状态:${taskStateLabel(document.fields.state)}`);
193
+ head.push(`- 状态:${entry ? describeLive(entry, live, now) : taskOutcomeLabel(document.fields.outcome)}`);
194
+ if (document.fields.state === "waiting" && document.fields.waiting?.kind === "user") {
195
+ head.push(`- 等你回复:${document.fields.waiting.question}`);
196
+ }
173
197
  const channel = document.fields.channel;
174
198
  if (!document.fields.outcome) {
175
199
  const note = deliveryNote(channel, options);
176
200
  head.push(channel
177
- ? `- 投递频道(channel):${options.describeChannel(channel).label}${note?.startsWith("已暂停") ? `(${note})` : ""}`
178
- : `- 投递频道:未指定(${note})`);
201
+ ? `- 汇报频道(channel):${options.describeChannel(channel).label}${note?.startsWith("已冻结") ? `(${note})` : ""}`
202
+ : `- 汇报频道:未指定(${note})`);
179
203
  }
180
204
  if (document.fields.paused) {
181
205
  const by = document.fields.paused.by === "user" ? "由你暂停" : "由系统暂停";
182
206
  head.push(`- 已暂停(${by}):${document.fields.paused.reason}`);
183
207
  }
184
- if (document.fields.ticket) {
185
- const ticket = document.fields.ticket;
186
- head.push(`- 等待:${describeTicketForUser(ticket)}${backstopHint(ticket.by, now)}`);
187
- }
208
+ if (live)
209
+ for (const line of describePending(live, now))
210
+ head.push(`- 在途:${line}`);
188
211
  if (document.fields.origin)
189
212
  head.push(`- 来自事件:${document.fields.origin}`);
190
213
  const usage = entry ? usageSummary(entry) : undefined;
191
214
  if (usage)
192
215
  head.push(`- 用量:${usage}`);
193
- const board = await buildTaskBoard(deskDir, id, document.body);
216
+ const records = await readTaskLog(deskDir, id);
217
+ const board = buildTaskBoard(records, document.body);
194
218
  const boardLines = board ? ["", "**工作项**", renderTaskBoardForUser(board, id, now)] : [];
195
- const log = await readTaskLog(deskDir, id, {
196
- kinds: ["step", "expired", "close"],
197
- limit: SHOW_LOG_LINES,
198
- });
199
- const logLines = log.length > 0 ? ["", "**最近记录**", ...log.map(renderTaskLogLineForUser)] : [];
219
+ const recent = records
220
+ .filter((record) => record.kind !== "step" &&
221
+ record.kind !== "dispatch" &&
222
+ record.kind !== "stall" &&
223
+ record.kind !== "input_ack" &&
224
+ record.kind !== "checkpoint")
225
+ .slice(-SHOW_LOG_LINES);
226
+ const logLines = recent.length > 0 ? ["", "**最近记录**", ...recent.map(renderTaskLogLineForUser)] : [];
200
227
  const path = existsSync(taskPath(deskDir, id)) ? taskPath(deskDir, id) : archivedTaskPath(deskDir, id);
201
228
  const contract = contractExcerpt(document.body, TASK_SHOW_CONTRACT_CHARS);
202
229
  const report = [
@@ -212,6 +239,9 @@ async function showTask(options, idInput) {
212
239
  ].join("\n");
213
240
  return capReply(report, { nextStepHint: `用 \`/tasks log ${id}\` 查看记录,完整任务说明在 \`${path}\`` }).text;
214
241
  }
242
+ function taskOutcomeLabel(outcome) {
243
+ return outcome === "completed" ? "已完成" : outcome === "cancelled" ? "已取消" : "未知";
244
+ }
215
245
  const ARCHIVE_OUTCOME = { completed: "已完成", cancelled: "已取消" };
216
246
  async function listArchive(deskDir) {
217
247
  const archiveDir = join(tasksDir(deskDir), "archive");
@@ -241,13 +271,21 @@ async function listArchive(deskDir) {
241
271
  }
242
272
  async function showTaskLog(deskDir, idInput) {
243
273
  const id = normalizeTaskId(idInput);
244
- const all = await readTaskLog(deskDir, id);
274
+ const issues = await taskLogIssues(deskDir, id);
275
+ const all = (await readTaskLog(deskDir, id)).filter((record) => record.kind !== "input_ack" && record.kind !== "checkpoint" && record.kind !== "report_delivered");
276
+ if (issues.length > 0 && all.length === 0)
277
+ return `任务 \`${id}\` 的记录有损坏,暂无可读取记录。请部署者检查 \`${issues[0].path}:${issues[0].line}\`,并从任务会话核对丢失的内容。`;
245
278
  if (all.length === 0)
246
279
  return `任务 \`${id}\` 暂无记录。\n任务执行第一步后会出现在这里。`;
247
280
  const records = all.slice(-LOG_LINES);
248
281
  const path = taskLogIsArchived(deskDir, id) ? taskArchiveLogPath(deskDir, id) : taskLogPath(deskDir, id);
249
282
  const lines = [
250
283
  `**任务 ${id} 的记录(最近 ${records.length} 条,共 ${all.length} 条)**`,
284
+ ...(issues.length > 0
285
+ ? [
286
+ `- ⚠️ 有 ${issues.length} 行记录损坏,请部署者检查 \`${issues[0].path}:${issues[0].line}\`;以下保留完整记录。`,
287
+ ]
288
+ : []),
251
289
  ...records.map(renderTaskLogLineForUser),
252
290
  ];
253
291
  if (all.length > records.length)
@@ -256,102 +294,136 @@ async function showTaskLog(deskDir, idInput) {
256
294
  }
257
295
  async function pauseTask(options, idInput) {
258
296
  const id = normalizeTaskId(idInput);
259
- const document = await pauseTaskDocument(options.deskDir, id, {
297
+ const outcome = await options.control.pause(options.desk, id, {
260
298
  by: "user",
261
299
  reason: "用户通过 /tasks pause 暂停。",
262
300
  });
263
- if (!document)
301
+ if (outcome.kind === "not_found")
264
302
  return notFound(id);
265
- return `已暂停任务 \`${id}\`,等待条件已保留;需要继续时用 \`/tasks resume ${id}\`。`;
303
+ if (outcome.kind === "unchanged")
304
+ return `任务 \`${id}\` 已经是暂停状态。`;
305
+ return `已暂停任务 \`${id}\`:已请求停止当前步骤,在途的委派和作业继续运行,结果会记下。继续用 \`/tasks resume ${id}\`。`;
266
306
  }
267
- export async function resumeTask(options, idInput, grants = {}) {
307
+ async function resumeTask(options, idInput, grants) {
268
308
  const id = normalizeTaskId(idInput);
269
- const document = await resumeTaskDocument(options.deskDir, id);
270
- if (!document)
309
+ const outcome = await options.control.resume(options.desk, id, grants);
310
+ if (outcome.kind === "not_found")
271
311
  return notFound(id);
312
+ if (outcome.kind === "unchanged")
313
+ return `任务 \`${id}\` 当前没有暂停,无需恢复。`;
314
+ if (outcome.kind === "stopping")
315
+ return `任务 \`${id}\` 的当前步骤尚未停止。请稍后再用 \`/tasks resume ${id}\` 重试;持续未停止时请联系部署者重启服务。`;
272
316
  const granted = [];
273
- if (Object.keys(grants).length > 0) {
274
- await updateStoredTask(options.deskDir, id, (task) => {
275
- const budget = { ...task.fields.budget };
276
- for (const key of ["steps", "usd"]) {
277
- const extra = grants[key];
278
- if (extra === undefined)
279
- continue;
280
- // A grant is *additional* headroom on top of whatever the task already spent, so
281
- // resuming a task that hit its ceiling actually lets it run rather than re-stopping
282
- // on the next step.
283
- const spent = key === "steps" ? task.fields.usage?.steps : task.fields.usage?.usd;
284
- budget[key] = (spent ?? 0) + extra;
285
- granted.push(key === "steps" ? `${extra} 步` : `$${extra}`);
286
- }
287
- task.fields.budget = budget;
288
- });
289
- }
317
+ if (grants.steps)
318
+ granted.push(`${grants.steps} 步`);
319
+ if (grants.usd)
320
+ granted.push(`$${grants.usd}`);
290
321
  return `已恢复任务 \`${id}\`${granted.length > 0 ? `,追加预算 ${granted.join("、")}` : ""}。`;
291
322
  }
292
- async function steerTask(options, idInput, text) {
323
+ async function cancelTask(options, idInput) {
293
324
  const id = normalizeTaskId(idInput);
294
- const document = await readStoredTask(options.deskDir, id);
295
- if (!document)
325
+ const outcome = await options.control.cancel(options.desk, id, {
326
+ by: "user",
327
+ note: "用户通过 /tasks cancel 取消。",
328
+ channel: options.currentChannelId,
329
+ });
330
+ if (outcome.kind === "not_found")
296
331
  return notFound(id);
297
- await queueTaskSteer(options.deskDir, id, text);
298
- return `已把这条指示排给任务 \`${id}\` 的下一步,不会打断正在执行的这一步。`;
332
+ const stopped = outcome.cancelled.length > 0
333
+ ? `,并取消了在途工作 ${outcome.cancelled.map((ref) => `\`${ref}\``).join("、")}`
334
+ : "";
335
+ return `已取消任务 \`${id}\`${stopped}。任务记录已归档,可用 \`/tasks log ${id}\` 查看。`;
299
336
  }
300
- /**
301
- * Answer an `ask` ticket: the reply becomes the next step's first input, and redeeming the ticket
302
- * is what actually reopens the task. A task parked on something else keeps its ticket — the reply
303
- * is still queued, because the user's words should not be dropped just because the timing was off.
304
- */
305
- async function replyToTask(options, idInput, text) {
337
+ async function messageTask(options, idInput, text) {
306
338
  const id = normalizeTaskId(idInput);
307
- const document = await readStoredTask(options.deskDir, id);
308
- if (!document)
309
- return notFound(id);
310
- await queueTaskSteer(options.deskDir, id, text, "用户回答");
311
- const redeemed = await redeemTicket(options.deskDir, id, (ticket) => ticket.kind === "ask");
312
- if (!redeemed) {
313
- return `任务 \`${id}\` 当前并没有在等你的回答;内容已记下,下一步会看到。`;
339
+ const outcome = await options.control.message(options.desk, id, {
340
+ from: options.senderName,
341
+ channel: options.currentChannelId,
342
+ text,
343
+ });
344
+ switch (outcome.kind) {
345
+ case "not_found":
346
+ return notFound(id);
347
+ case "closing":
348
+ return `任务 \`${id}\` 已进入交付与收尾,未接收新指示。如需改变目标,先用 \`/tasks cancel ${id}\` 取消,再提出新要求。`;
349
+ case "injected":
350
+ return `消息已保存,并已排入任务 \`${id}\` 当前步骤;未处理的内容会在后续继续转达。`;
351
+ case "woke":
352
+ return `已收到,任务 \`${id}\` 会继续推进。`;
353
+ case "queued_for_next_step":
354
+ return `已把这条消息排给任务 \`${id}\` 的下一步。`;
355
+ case "held_paused":
356
+ return `任务 \`${id}\` 已暂停:消息已记下,恢复(\`/tasks resume ${id}\`)后下一步会看到。`;
357
+ case "held_frozen":
358
+ return `任务 \`${id}\` 的汇报频道未绑定到本工位,任务已冻结:消息已记下,频道绑定回来后下一步会看到。`;
314
359
  }
315
- if (options.dispatchTask)
316
- await options.dispatchTask(id);
317
- return `已回复任务 \`${id}\`,它会继续推进。`;
318
360
  }
319
361
  function issue(problem, nextStep) {
320
362
  return `- ${problem}(下一步:${nextStep})`;
321
363
  }
322
364
  /**
323
- * `/tasks doctor`, deliberately small (spec 051, D11; spec 052, D11).
324
- *
325
- * Most of what older doctors looked for cannot be produced any more: the frontmatter normalizer
326
- * and `resolveTicket` reject those states at write time. What is left is what a *hand edit* can
327
- * still create.
365
+ * `/tasks doctor`, deliberately small (spec 064, D25). The state machine rejects most bad states at
366
+ * write time; what is left is what a *hand edit* can still create, and a lane that is not running.
328
367
  */
329
368
  async function doctor(options) {
330
369
  const now = Date.now();
331
- const entries = await readActiveTasks(tasksDir(options.deskDir), now);
370
+ const entries = await readActiveTasks(tasksDir(options.deskDir));
371
+ const live = await snapshotsById(options);
332
372
  const problems = [];
333
373
  for (const entry of entries) {
374
+ if (isTaskArchiving(options.deskDir, entry.id))
375
+ problems.push(issue(`\`${entry.id}\` 的归档尚未完成`, "运行时会自动恢复;持续未完成时请部署者检查磁盘和权限"));
376
+ for (const damaged of await taskLogIssues(options.deskDir, entry.id))
377
+ problems.push(issue(`\`${entry.id}\` 的任务记录有损坏:\`${damaged.path}:${damaged.line}\``, "请部署者检查该行;后续完整记录仍会读取,已丢失的内容需从会话记录核对"));
334
378
  if (!entry.readable) {
335
- problems.push(issue(`\`${entry.id}\` 的文件头(frontmatter)不可读`, `让我修复 \`${taskPath(options.deskDir, entry.id)}\` 的文件头,或手动修改`));
379
+ problems.push(issue(`\`${entry.id}\` 的文件头(frontmatter)不可读,任务不会执行`, `让我修复 \`${taskPath(options.deskDir, entry.id)}\` 的文件头,或手动修改`));
336
380
  continue;
337
381
  }
338
382
  if (!entry.fields.channel) {
339
- problems.push(issue(`\`${entry.id}\` 没有投递频道(channel),已暂停`, `在 \`${taskPath(options.deskDir, entry.id)}\` 的文件头加一行 \`channel: <频道 ID>\``));
383
+ problems.push(issue(`\`${entry.id}\` 没有汇报频道(channel),已冻结`, `在 \`${taskPath(options.deskDir, entry.id)}\` 的文件头加一行 \`channel: <频道 ID>\``));
340
384
  }
341
385
  else if (!options.describeChannel(entry.fields.channel).boundHere) {
342
- problems.push(issue(`\`${entry.id}\` 的投递频道没有绑定到本工位,已暂停`, "在那个频道里把它绑定回本工位,或把文件头的 `channel:` 改成本工位已绑定的频道"));
386
+ problems.push(issue(`\`${entry.id}\` 的汇报频道没有绑定到本工位,已冻结`, "在那个频道里把它绑定回本工位,或把文件头的 `channel:` 改成本工位已绑定的频道"));
343
387
  }
344
- const by = entry.fields.ticket ? parseLocalTime(entry.fields.ticket.by) : undefined;
345
- if (entry.expired && !entry.fields.paused && by !== undefined && by < now - EXPIRED_GRACE_MS) {
346
- problems.push(issue(`\`${entry.id}\` 的等待条件已超过最晚检查时间 1 小时以上`, "自动调度本该重新开始或通知;请部署者确认服务器上的 pipiclaw 仍在运行"));
388
+ const waiting = entry.fields.waiting;
389
+ const since = waiting?.kind === "work" ? parseLocalTime(waiting.since) : undefined;
390
+ if (since !== undefined && now - since > STALE_WORK_WAIT_MS && (live.get(entry.id)?.pending.length ?? 0) === 0) {
391
+ problems.push(issue(`\`${entry.id}\` 在等结果,但已超过 1 小时没有任何在途工作`, "自动调度本该重新开始;请部署者确认服务器上的 pipiclaw 仍在运行"));
347
392
  }
348
393
  }
394
+ for (const message of await readTaskDeliveries(options.deskDir))
395
+ if (message.attempts > 0)
396
+ problems.push(issue(`\`${message.taskId}\` 有待确认的消息,已尝试 ${message.attempts} 次`, "运行时会自动重试;持续未送达时请部署者检查投递频道和网络"));
349
397
  if (problems.length === 0)
350
398
  return `检查了 ${entries.length} 个任务,未发现问题。`;
351
399
  return capReply([`**任务体检(${problems.length} 项)**`, ...problems].join("\n"), {
352
400
  nextStepHint: "逐个修复后再运行 `/tasks doctor` 查看剩余的问题",
353
401
  }).text;
354
402
  }
403
+ /** Tasks holding an execution slot: a step is running or delegated work is awaited (D12). */
404
+ function isExecuting(snapshot) {
405
+ return (!snapshot.frozen &&
406
+ !snapshot.closing &&
407
+ (snapshot.state === "running" || (snapshot.state === "waiting" && snapshot.waiting?.kind === "work")));
408
+ }
409
+ /** `/stop` stops the chat turn only; a line naming the executing tasks says where a task is stopped (spec 064, D27). */
410
+ export function renderStopTaskHint(snapshots) {
411
+ const executing = snapshots.filter(isExecuting);
412
+ if (executing.length === 0)
413
+ return undefined;
414
+ const ids = executing.map((snapshot) => `\`${snapshot.id}\``).join("、");
415
+ return `本工位有任务在后台执行:${ids}。\`/stop\` 不会停它们;要暂停用 \`/tasks pause <id>\`。`;
416
+ }
417
+ /** The one `/status` line about the desk's tasks, or `undefined` when there are none (D28). */
418
+ export function renderTaskStatusLine(snapshots) {
419
+ if (snapshots.length === 0)
420
+ return undefined;
421
+ const running = snapshots.filter(isExecuting).length;
422
+ const queued = snapshots.filter((snapshot) => snapshot.state === "queued" && !snapshot.closing).length;
423
+ const closing = snapshots.filter((snapshot) => snapshot.closing).length;
424
+ const asking = snapshots.filter((snapshot) => snapshot.state === "waiting" && snapshot.waiting?.kind === "user").length;
425
+ return `- 后台任务:执行中 ${running} · 排队 ${queued} · 等你回复 ${asking}${closing ? ` · 交付与收尾 ${closing}` : ""}`;
426
+ }
355
427
  export async function handleTasksCommand(options) {
356
428
  let command;
357
429
  try {
@@ -361,9 +433,6 @@ export async function handleTasksCommand(options) {
361
433
  return `${errorMessage(error)}\n\n${usage()}`;
362
434
  }
363
435
  try {
364
- if ("id" in command && command.id && command.action !== "show" && command.action !== "log") {
365
- return await withTaskMutation(options.deskDir, command.id, () => dispatchTasksCommand(options, command));
366
- }
367
436
  return await dispatchTasksCommand(options, command);
368
437
  }
369
438
  catch (error) {
@@ -384,10 +453,10 @@ async function dispatchTasksCommand(options, command) {
384
453
  return await pauseTask(options, command.id);
385
454
  case "resume":
386
455
  return await resumeTask(options, command.id, command.grants);
387
- case "steer":
388
- return await steerTask(options, command.id, command.text);
389
- case "reply":
390
- return await replyToTask(options, command.id, command.text);
456
+ case "cancel":
457
+ return await cancelTask(options, command.id);
458
+ case "msg":
459
+ return await messageTask(options, command.id, command.text);
391
460
  case "doctor":
392
461
  return await doctor(options);
393
462
  }
@@ -0,0 +1,12 @@
1
+ import type { TaskStepIntent } from "./control.js";
2
+ import { type TaskLogRecord, type TaskReportRecord } from "./loop-log.js";
3
+ /** A durable close always wins over ordinary scheduling, including after restart. */
4
+ export declare function pendingTaskClose(records: readonly TaskLogRecord[]): TaskStepIntent["close"];
5
+ /** Bind completion to this step's specific final report, never an old progress update. */
6
+ export declare function finalTaskReport(records: readonly TaskLogRecord[], options?: {
7
+ seq?: number;
8
+ fromChat?: boolean;
9
+ }): TaskReportRecord & {
10
+ id: string;
11
+ };
12
+ export declare function taskReportDelivered(records: readonly TaskLogRecord[], reportId: string | undefined, channel?: string): boolean;
@@ -0,0 +1,35 @@
1
+ import { RecoverableToolError } from "../shared/recoverable-error.js";
2
+ import { lastStep } from "./loop-log.js";
3
+ /** A durable close always wins over ordinary scheduling, including after restart. */
4
+ export function pendingTaskClose(records) {
5
+ const latest = [...records]
6
+ .reverse()
7
+ .find((record) => record.kind === "step_end" || record.kind === "close" || record.kind === "close_rejected");
8
+ if (latest?.kind === "step_end")
9
+ return latest.close;
10
+ if (latest?.kind === "close")
11
+ return {
12
+ outcome: latest.outcome === "done" ? "complete" : "cancel",
13
+ note: latest.note,
14
+ reportId: latest.reportId,
15
+ };
16
+ return undefined;
17
+ }
18
+ /** Bind completion to this step's specific final report, never an old progress update. */
19
+ export function finalTaskReport(records, options = {}) {
20
+ const seq = options.seq ?? lastStep(records)?.step.seq;
21
+ const report = [...records].reverse().find((record) => record.kind === "report" && record.seq === seq);
22
+ if (report?.kind !== "report" || !report.id) {
23
+ throw new RecoverableToolError(options.fromChat
24
+ ? "Completion needs the leader's final report. Use task_message to ask the task to finish; if paused, use task_resume, then let the leader report and close."
25
+ : "Completion needs a final report from the current step. Use task_report to deliver the results and evidence, then call task_close again.");
26
+ }
27
+ return report;
28
+ }
29
+ export function taskReportDelivered(records, reportId, channel) {
30
+ return (!!reportId &&
31
+ records.some((record) => record.kind === "report" &&
32
+ record.id === reportId &&
33
+ record.delivered &&
34
+ (channel === undefined || record.channel === channel)));
35
+ }
@@ -6,8 +6,8 @@ import { type TaskFrontmatter } from "./frontmatter.js";
6
6
  * on unreadable frontmatter) because task files are hand-editable and must degrade toward "wake
7
7
  * me up so I can be fixed". `/tasks`, the task digest, and `task_list` all read through here.
8
8
  *
9
- * Frontmatter lives in `frontmatter.ts` and the waiting claim in `ticket.ts`; what stays here is
10
- * the *body*: sections, Work Items, DoD, and the skeleton.
9
+ * Frontmatter lives in `frontmatter.ts`; what stays here is the *body*: sections, Work Items, DoD,
10
+ * and the skeleton.
11
11
  */
12
12
  export interface TaskLedgerEntry {
13
13
  /** Filename without `.md`; the task id. */
@@ -17,12 +17,6 @@ export interface TaskLedgerEntry {
17
17
  fields: TaskFrontmatter;
18
18
  /** false => frontmatter could not be read; the task is surfaced rather than skipped. */
19
19
  readable: boolean;
20
- /** The driver may schedule a step for this task right now. */
21
- runnable: boolean;
22
- /** When a driver-polled `time` ticket comes due, if it has not already. */
23
- dueMs?: number;
24
- /** True when a parked task's backstop has passed and the runtime owes it a reopen. */
25
- expired: boolean;
26
20
  /** Parsed `## Work Items` section, if the task has one. */
27
21
  items?: TaskItemsSummary;
28
22
  }
@@ -115,6 +109,8 @@ export declare function findTaskSectionBounds(lines: readonly string[], names: r
115
109
  * checked" — which would silently let a task close with nothing ever actually checked.
116
110
  */
117
111
  export declare function uncheckedTaskAcceptanceItems(content: string): string[];
112
+ /** Closing checks structure, not the truth of the leader's evidence. Dropped items are explicit scope changes. */
113
+ export declare function assertTaskAcceptance(content: string): void;
118
114
  /**
119
115
  * The task skeleton: Goal, DoD and (optionally) Work Items (spec 052, §3.4). The runtime never
120
116
  * rewrites the body afterwards, so there is no history section here — the per-step record lives
@@ -123,16 +119,11 @@ export declare function uncheckedTaskAcceptanceItems(content: string): string[];
123
119
  export declare function renderStandardTaskBody(input: TaskContractInput): string;
124
120
  /** Serialize a task document: frontmatter block plus the body, unchanged. */
125
121
  export declare function renderTaskDocument(fields: TaskFrontmatter, rawBody: string): string;
126
- /**
127
- * Runnable first; then a parked task whose backstop already expired (the runtime owes it a
128
- * reopen); then earliest due ticket; then id. Sorting expired parks ahead of ordinary parks is
129
- * what keeps D2-INV's deadline honest when a channel has more ready work than one tick can carry.
130
- */
122
+ /** Group by state, then oldest project first (`usage.startedAt`, the lane's own admission order), then id. */
131
123
  export declare function compareTaskEntries(a: TaskLedgerEntry, b: TaskLedgerEntry): number;
132
124
  /**
133
125
  * Read every `.md` file in `tasks/` (root only — the `archive/` subdirectory is not
134
- * scanned), returning entries sorted runnable-first. A file that cannot be read is still
135
- * returned (fail-open: `readable: false`, `runnable: true`) so problems surface.
136
- * Missing directory → empty list.
126
+ * scanned), in display order. A file that cannot be read is still returned (fail-open:
127
+ * `readable: false`) so problems surface. Missing directory → empty list.
137
128
  */
138
- export declare function readActiveTasks(tasksDir: string, now?: number): Promise<TaskLedgerEntry[]>;
129
+ export declare function readActiveTasks(tasksDir: string): Promise<TaskLedgerEntry[]>;