@oyasmi/pipiclaw 0.8.8 → 0.8.9-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 (38) hide show
  1. package/dist/memory/task-digest.js +1 -1
  2. package/dist/playbooks/task-closeout.md +11 -10
  3. package/dist/playbooks/task-delegation.md +1 -1
  4. package/dist/playbooks/task-driving.md +6 -7
  5. package/dist/playbooks/task-planning.md +7 -5
  6. package/dist/playbooks/task-recurring.md +7 -4
  7. package/dist/playbooks/task-repair.md +7 -7
  8. package/dist/runtime/bootstrap.js +5 -1
  9. package/dist/runtime/task-commands.js +29 -51
  10. package/dist/runtime/task-driver.d.ts +0 -8
  11. package/dist/runtime/task-driver.js +83 -82
  12. package/dist/runtime/task-migration.d.ts +11 -0
  13. package/dist/runtime/task-migration.js +70 -0
  14. package/dist/shared/task-events.d.ts +0 -26
  15. package/dist/shared/task-events.js +0 -15
  16. package/dist/shared/task-ledger.d.ts +23 -1
  17. package/dist/shared/task-ledger.js +65 -16
  18. package/dist/tasks/control.d.ts +4 -0
  19. package/dist/tasks/control.js +3 -0
  20. package/dist/tasks/store.d.ts +28 -1
  21. package/dist/tasks/store.js +63 -6
  22. package/dist/tasks/transitions.d.ts +40 -0
  23. package/dist/tasks/transitions.js +81 -0
  24. package/dist/tools/task-manage/create.d.ts +2 -0
  25. package/dist/tools/task-manage/create.js +34 -0
  26. package/dist/tools/task-manage/lifecycle.d.ts +6 -0
  27. package/dist/tools/task-manage/lifecycle.js +196 -0
  28. package/dist/tools/task-manage/schema.d.ts +43 -0
  29. package/dist/tools/task-manage/schema.js +89 -0
  30. package/dist/tools/task-manage/shared.d.ts +36 -0
  31. package/dist/tools/task-manage/shared.js +246 -0
  32. package/dist/tools/task-manage/types.d.ts +53 -0
  33. package/dist/tools/task-manage/types.js +1 -0
  34. package/dist/tools/task-manage/verification.d.ts +16 -0
  35. package/dist/tools/task-manage/verification.js +111 -0
  36. package/dist/tools/task-manage.d.ts +9 -89
  37. package/dist/tools/task-manage.js +8 -696
  38. package/package.json +1 -1
@@ -18,7 +18,7 @@ function relativeWake(wakeMs, now) {
18
18
  return `wake ${Math.round(hours / 24)}d`;
19
19
  }
20
20
  function renderLine(entry, now) {
21
- const status = entry.frontmatter.readable ? (entry.frontmatter.status ?? "open") : "⚠ unreadable frontmatter";
21
+ const status = entry.frontmatter.readable ? (entry.frontmatter.status ?? "active") : "⚠ unreadable frontmatter";
22
22
  const parts = [`${entry.id} — ${entry.title}`, status, relativeWake(entry.wakeMs, now)];
23
23
  const control = entry.frontmatter.control;
24
24
  if (control) {
@@ -13,28 +13,29 @@ priority: 42
13
13
  2. 全部勾完,调用 `task_manage candidate`;该动作追加候选 note、置 verifying、清 wake,本身就是本回合 checkpoint。
14
14
  3. checker-only 回合委派全新 subagent:`purpose: verify`、`taskId: <id>`,明确逐项检查方法。
15
15
  4. verifier 没有 write/edit;bash 只运行明确的非变更检查。Git checkout 上 runtime 会比较前后状态,变化会使 attestation 无效;非 Git 目录没有完整变更检测,不能把 bash 当成结构性只读沙箱。结尾必须是 `VERDICT: PASS` 或 `VERDICT: FAIL`。
16
- 5. 主回合以 runId 调 `task_manage verify`。attestation 绑定 task body hash;Git checkout 上还绑定 HEAD/staged/unstaged/untracked artifact subject。
16
+ 5. 主回合以 runId 调 `task_manage verify`。attestation 绑定 task 的**契约段** hash(Goal/DoD/Manual/Verification,含勾选状态,不含 Current Cycle/History);Git checkout 上还绑定 HEAD/staged/unstaged/untracked artifact subject。
17
17
 
18
- FAIL 后用 progress 记录失败证据、status 回 in-progress,修复后重新 candidate。不要让 verifier 顺手修实现。
18
+ FAIL 后用 progress 记录失败证据、status 回 active,修复后重新 candidate。不要让 verifier 顺手修实现。
19
+
20
+ **PASS 绑定契约、不绑日志**:PASS 之后照常 `progress` 记 Current Cycle 日志不会使 PASS 失效;只有改动契约段(Goal/DoD/Manual/Verification 或勾选状态)才会失效。改了契约就诚实重跑验收。
19
21
 
20
22
  ## 外部副作用
21
23
 
22
- `sideEffects: external` 要求用户通过 `/tasks approve <id>` 授权;agent 不能自授予。授权绑定 task body hash,批准后不要再 progress 或编辑正文。
24
+ `sideEffects: external` 要求用户通过 `/tasks approve <id>` 授权;agent 不能自授予。授权同样绑定契约段 hash:批准后照常记日志无妨,但改动契约正文会要求重新授权。
23
25
 
24
- 只做 external、无需 independent verification 时:准备动作 → progress 置 awaiting-user 并请求审批 → 用户 approve → 执行动作 → 直接 done。
26
+ 只做 external、无需 independent verification 时:准备动作 → progress 置 waiting 并请求审批 → 用户 approve → 执行动作 → 直接 done。
25
27
 
26
- ## independent + external 的正确组合
28
+ ## independent + external 同时存在
27
29
 
28
- 这两个门都存在时,严格按以下顺序,避免 hash 相互失效:
30
+ 契约-绑定的 hash 让两个门不再相互误伤,日常顺序很简单:
29
31
 
30
32
  1. 完成实现、预演外部动作、勾选 acceptance items。
31
33
  2. candidate → verifier → `task_manage verify` 得到 PASS。
32
- 3. 不改正文;用 `task_manage set status=awaiting-user wake=<合理时间>` 等待,并请求用户 `/tasks approve <id>`。这里不能 progress。
33
- 4. 用户批准后,driver 在 wake 到期接续;再次确认 PASS、approvalBodyHash 和当前产物仍新鲜。
34
+ 3. 等待审批:用 `task_manage set wake=<合理时间>` 保留在 `verifying` 车道(**只改 wake,不换状态**——离开 verifying 的 set 会作废 PASS),并请求用户 `/tasks approve <id>`。此时记日志无妨。
35
+ 4. 用户批准后,driver 在 wake 到期接续;确认 PASS、approvalBodyHash 与当前产物仍新鲜。
34
36
  5. 执行已批准的外部动作,然后直接 done;结果写入 done 的 summary/evidence。
35
37
 
36
- 不要在 candidate 前审批(candidate 会改正文),也不要 PASS 后 progress(会使 PASS 失效)。批准范围或实现改变时,诚实重走相应门禁。
37
- 如果 wake 到期但用户尚未批准,只用 set 调整 awaiting-user/wake 并提醒,不写 progress note。
38
+ 改动契约段或批准范围时,诚实重走相应门禁。
38
39
 
39
40
  建档时 acceptance items 应描述外部动作的**准备质量**(内容、目标、参数、预演、回滚方案),而不是要求在 candidate 前已经发布/发送。最终外部结果由审批记录和 done evidence 证明;否则“先执行才能勾选”会与“先验收、审批才能执行”形成循环。
40
41
 
@@ -14,7 +14,7 @@ priority: 45
14
14
  - child 的 `control.parent` 指向父任务。
15
15
  - `dependsOn` 表示执行前置;依赖 done 前 driver 不运行 dependent。
16
16
  - 父任务可 dependsOn child,等待全部子成果汇合后集成。
17
- - 依赖缺失、cancelled 或 escalated 会令 dependent escalated。
17
+ - 依赖缺失、cancelled 或被治理器暂停会令 dependent 被治理器暂停。
18
18
  - 父任务有未闭环 child 时不能 done。
19
19
 
20
20
  ## 内建 subagent
@@ -14,7 +14,7 @@ priority: 41
14
14
  3. 检查上一步产物是否已经存在。driver/dispatch 提供至少一次恢复,宕机或租约重放可能让同一步再次到达。
15
15
  4. 只推进一个清晰的下一阶段;不要在未知状态下重复外部动作。
16
16
 
17
- 依赖未完成时 driver 跳过任务且不消耗 attempt;依赖缺失/cancelled/escalated、deadline 或累计预算耗尽会令任务 escalated。
17
+ 依赖未完成时 driver 跳过任务且不消耗 attempt;依赖缺失/cancelled/被治理器暂停、deadline 或累计预算耗尽会令任务被治理器暂停(`paused` + `pausedBy=governor`)。
18
18
 
19
19
  ## 回合结束必须留下确定性状态
20
20
 
@@ -25,15 +25,14 @@ priority: 41
25
25
  - 下一步是什么;
26
26
  - status 与 wake。
27
27
 
28
- 以下生命周期动作本身就是原子 checkpoint,不要再追加 progress:`candidate`、`done`、`cancel`、`start-cycle`。
28
+ 以下生命周期动作本身就是原子 checkpoint,不要再追加 progress:`candidate`、`done`、`cancel`。
29
29
 
30
- `verify` 只更新 control、不改正文。若 PASS 后还要等待 external approval,使用 `task_manage set status=awaiting-user wake=<合理时间>`,并向用户请求 `/tasks approve <id>`;不要 progress,因为正文变化会使 PASS 失效。除此之外不要用 set 代替正常进度日志。
30
+ `verify` 只更新 control、不改正文。若 PASS 后还要等待 external approval,使用 `task_manage set wake=<合理时间>` 停留在 `verifying` 车道(只改 wake、不换状态;离开 verifying 会作废 PASS),并向用户请求 `/tasks approve <id>`。PASS 绑定契约段而非日志——记 Current Cycle 日志不会使 PASS 失效,只有改契约(Goal/DoD/Manual/Verification/勾选)才会。除此之外不要用 set 代替正常进度日志。
31
31
 
32
32
  ## 等待与继续
33
33
 
34
- - 等用户:`awaiting-user` + 合理 wake。
35
- - 等外部系统/委派:`blocked` + 合理 wake。
36
- - 当前仍可继续:保持 `in-progress`,清空 wake。
34
+ - 等用户/外部系统/委派:`waiting` + 合理 wake,把等谁、等什么写进 `blockedReason`。
35
+ - 当前仍可继续:保持 `active`,清空 wake。
37
36
  - 明确停止:由用户 pause;不要用极远 wake 模拟暂停。
38
37
 
39
38
  内建 driver 分钟级扫描 DingTalk `dm_*/group_*` channel。wake 到期后接续;无需 heartbeat、`.checkin` 或额外传感器。TUI 关闭后没有 daemon,不能自动唤醒。
@@ -42,4 +41,4 @@ priority: 41
42
41
 
43
42
  ## 汇报与静默
44
43
 
45
- 有用户需要知道的结果、风险、审批请求时正常汇报。纯内部周期检查且没有新结果时返回 `[SILENT]`。完成时走 `task-closeout.md`,异常或 escalated 走 `task-repair.md`。
44
+ 有用户需要知道的结果、风险、审批请求时正常汇报。纯内部周期检查且没有新结果时返回 `[SILENT]`。完成时走 `task-closeout.md`,异常或被治理器暂停走 `task-repair.md`。
@@ -37,12 +37,14 @@ priority: 40
37
37
 
38
38
  ## 状态与时间
39
39
 
40
- - `open` / `in-progress`:可推进。
41
- - `awaiting-user`:需要用户输入或批准。
42
- - `blocked`:等待外部条件或委派结果。
43
- - `paused`:明确暂停,driver 不运行。
40
+ 六个状态,每个只对应一种 driver 行为:
41
+
42
+ - `active`:可推进(受 wake 门控)。
43
+ - `waiting`:等用户/外部条件/委派结果;等谁、等什么写进 `control.blockedReason`。
44
44
  - `verifying`:只做独立验收,不继续实现。
45
- - `escalated`:治理器停止任务,先诊断再修 control。
45
+ - `paused`:明确暂停,driver 不运行。用户暂停 `pausedBy=user`;治理器停止(预算耗尽等)记 `pausedBy=governor`,先诊断再修 control。
46
+ - `done`:完成;有 schedule 则原地睡到下次 occurrence,否则归档。
47
+ - `cancelled`:放弃并归档。
46
48
 
47
49
  `wake` 是最早重新检查时间,不代表截止时间。等待时设置现实的 wake;可继续时清空 wake,让 driver 按 cooldown 接续。
48
50
 
@@ -21,11 +21,14 @@ task_manage create id=weekly-report title=... goal=... dod=... schedule="30 9 *
21
21
 
22
22
  cron 最密每 30 分钟一次,落盘前校验。纯提醒(无产出、无验收)不建 task,用普通 periodic event。
23
23
 
24
+ **首次执行遵循 cron 语义**:不显式传 `wake` 时,create 会用 croner 把 `wake` 预约到下一次 occurrence,任务 `active` + 未来 `wake`,到点才由 driver 派发普通驱动唤醒——像 crontab 一样,创建不等于立刻跑。需要立刻开跑就显式传一个当下/过去的 `wake`。
25
+
24
26
  ## 周期运行
25
27
 
26
- done 的周期任务留在原地睡眠:`task_manage done` 会用 croner 算出下一次 occurrence 写入 `wake`,状态是 `done` + 未来的 `wake`。到点时 driver 自动派发一条 cycle-start 唤醒。
28
+ done 的周期任务留在原地睡眠:`task_manage done` 后,"唯一时间规则"会用 croner 算出下一次 occurrence 写入 `wake`,状态是 `done` + 未来的 `wake`。
29
+
30
+ 到点时 **runtime 直接开下一周期**(无需你做任何事,也没有 `start-cycle` 动作):折叠上一周期日志入 History、清空本周期用量/验收/授权/worktree 元数据、置 `active`,然后派发一条普通驱动唤醒。你醒来面对的就是一个待推进的新周期,和其他唤醒无异。
27
31
 
28
- - 收到 cycle-start:调用 `task_manage start-cycle`,给稳定 cycleId。它原子折叠上一周期日志、清空本周期用量/验收/授权/worktree 元数据并置 in-progress。
29
32
  - 上周期未完成:不要覆盖或虚勾 DoD。先完成、如实缩小本轮范围并验收,或与用户确认后 cancel 整项任务。
30
33
 
31
34
  周期内继续、等待和恢复只用 task `wake`。
@@ -34,8 +37,8 @@ done 的周期任务留在原地睡眠:`task_manage done` 会用 croner 算出
34
37
 
35
38
  每轮闭环前把返工原因、预检步骤和格式偏好写回 Manual;跨任务才沉淀 workspace skill。
36
39
 
37
- - 改节奏:`task_manage set schedule="<新 cron>"`;若任务当前 done,同一次写入会重算 `wake`。一处真相。
40
+ - 改节奏:`task_manage set schedule="<新 cron>"`;若任务当前 done,写盘时"唯一时间规则"会重算 `wake`。一处真相。
38
41
  - 暂停:`/tasks pause <id>`;`/tasks resume` 恢复。
39
42
  - 退役:`task_manage cancel`,归档任务并清理全部 task-owned events。
40
43
 
41
- 不要手工改 status 开周期。
44
+ 周期由 runtime 自动开启,不需要(也没有)手工开周期的动作。
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: task-repair
3
- description: When a task is escalated, stalled, not waking, or has broken control metadata.
3
+ description: When a task is paused by the governor, stalled, not waking, or has broken control metadata.
4
4
  requires-tools: task_manage
5
5
  priority: 44
6
6
  ---
@@ -9,19 +9,19 @@ priority: 44
9
9
 
10
10
  先用 `task_manage list` 看结构化状态;让用户用 `/tasks doctor` 看带 Next step 的一致性检查,用 `/tasks stats <id>` 看 attempts/token/cost/wall time、最近结果和 verifier 状态。
11
11
 
12
- ## escalated
12
+ ## 被治理器暂停(paused + pausedBy=governor)
13
13
 
14
- driver 在 deadline、累计预算耗尽或 terminal dependency 时停止任务。先读 Current Cycle 和 stats,判断空转、范围错误、预算过小还是依赖终止。
14
+ 治理器在 deadline、累计预算耗尽、terminal dependency,或**连续 3 次唤醒都没有可见进展**(fingerprint 未变,含 silent)时暂停任务(旧称 escalated,现在是 `paused` + `pausedBy=governor`)。先读 Current Cycle 和 stats,判断空转、范围错误、预算过小还是依赖终止。
15
15
 
16
16
  - 方向错:修 Manual/nextAction、重新拆解或 cancel。
17
- - 预算确实不足:向用户说明后用 `task_manage set` 调整 budget/deadline,并把 status 设回 in-progress。
17
+ - 预算确实不足:向用户说明后用 `task_manage set` 调整 budget/deadline,并把 status 设回 active。
18
18
  - 依赖终止:恢复/重建依赖,或 set 更新 dependsOn。
19
19
 
20
- escalated 不能 progress/candidate;set 是审查原因后的修复入口,不要反射性加预算。
20
+ 被暂停的任务不能 progress/candidate;`set`(或 `/tasks resume`)是审查原因后的修复入口,不要反射性加预算。
21
21
 
22
22
  ## 不唤醒或频繁唤醒
23
23
 
24
- 可推进 = 非 done/cancelled/escalated/paused,且 wake 缺失、无效或已到期。
24
+ 可推进 = 非 done/cancelled/paused,且 wake 缺失、无效或已到期。
25
25
 
26
26
  - paused:用户 `/tasks resume <id>`。
27
27
  - wake 太远:纠正 wake;急催用 `/tasks run <id>`。
@@ -36,7 +36,7 @@ frontmatter 只认开头 `---` 块中的 status/wake/recurrence/control;contro
36
36
 
37
37
  ## stale gate
38
38
 
39
- PASS 和 external approval 都绑定 task body;PASS 还可能绑定 Git artifact subject。progress、正文编辑或产物变化后 done 会拒绝:重跑 verifier或请用户重新 approve,不绕过。组合流程见 `task-closeout.md`。
39
+ PASS 和 external approval 都绑定 task 的**契约段**(Goal/DoD/Manual/Verification 及勾选状态,不含 Current Cycle/History);PASS 还可能绑定 Git artifact subject。改契约或产物变化后 done 会拒绝:重跑 verifier 或请用户重新 approve,不绕过。(记 Current Cycle 日志不影响 PASS。)组合流程见 `task-closeout.md`。
40
40
 
41
41
  ## 事件与重启
42
42
 
@@ -29,6 +29,7 @@ import { createEventsWatcher } from "./events.js";
29
29
  import { ChannelStore } from "./store.js";
30
30
  import { pauseTask, handleTasksCommand as runTasksCommand } from "./task-commands.js";
31
31
  import { createTaskDriverEvent, TaskDriver } from "./task-driver.js";
32
+ import { migrateLegacyTaskScheduleEvents } from "./task-migration.js";
32
33
  import { DEFAULT_AGENTS, DEFAULT_SOUL } from "./workspace-templates.js";
33
34
  const DEFAULT_MEMORY = `# Workspace Memory
34
35
 
@@ -647,7 +648,7 @@ export function createRuntimeContext(options) {
647
648
  finally {
648
649
  await durableDispatch?.markCompleted(event.dispatchId);
649
650
  runner.endTurn();
650
- // A finished turn may have written task files (progress/done/start-cycle); rescan
651
+ // A finished turn may have written task files (progress/done/set); rescan
651
652
  // now so a continuing task chain advances immediately instead of after a full sleep.
652
653
  taskDriver.nudge?.();
653
654
  }
@@ -804,6 +805,9 @@ export function createRuntimeContext(options) {
804
805
  });
805
806
  }
806
807
  if (startServices) {
808
+ // One-time close of the 027 migration window: fold any residual legacy `.schedule`
809
+ // events into task frontmatter before the driver relies on frontmatter as the only cadence.
810
+ void migrateLegacyTaskScheduleEvents(options.paths.workspaceDir);
807
811
  eventsWatcher.start();
808
812
  memoryMaintenanceScheduler.start();
809
813
  taskDriver.start();
@@ -1,11 +1,12 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { readdir, readFile } from "node:fs/promises";
3
3
  import { join, resolve, sep } from "node:path";
4
- import { isTaskCheckinEvent, isTaskScheduleEvent, parseTaskEventName, taskEventPrefix } from "../shared/task-events.js";
4
+ import { parseTaskEventName, taskEventPrefix } from "../shared/task-events.js";
5
5
  import { extractTaskTitle, missingStandardTaskSections, normalizeTaskId, readActiveTasks, } from "../shared/task-ledger.js";
6
6
  import { errorMessage } from "../shared/text-utils.js";
7
7
  import { taskBudgetViolation } from "../tasks/control.js";
8
8
  import { claimTaskAttempt, readStoredTask, releaseTaskAttemptClaim, taskBodyHash, writeStoredTask, } from "../tasks/store.js";
9
+ import { normalizeStoredStatus, resolveTaskTransition } from "../tasks/transitions.js";
9
10
  import { readVerificationAttestation } from "../tasks/verification.js";
10
11
  import { parseScheduledEventContent } from "./events.js";
11
12
  function usage() {
@@ -133,13 +134,6 @@ async function readTaskEvents(workspaceDir, channelId) {
133
134
  }
134
135
  return events;
135
136
  }
136
- function eventKey(events, id, use) {
137
- return events.find((event) => event.id === id && event.use === use);
138
- }
139
- function isParseableSchedule(events, id) {
140
- const schedule = eventKey(events, id, "schedule");
141
- return schedule ? isTaskScheduleEvent(schedule) : false;
142
- }
143
137
  function validWakeMs(entry) {
144
138
  const wake = entry.frontmatter.wake;
145
139
  if (!wake)
@@ -195,7 +189,7 @@ async function listTasks(channelDir) {
195
189
  return "# Tasks\n\nNo active tasks.";
196
190
  }
197
191
  const blocks = entries.map((entry) => {
198
- const status = entry.frontmatter.readable ? (entry.frontmatter.status ?? "open") : "⚠ unreadable frontmatter";
192
+ const status = entry.frontmatter.readable ? (entry.frontmatter.status ?? "active") : "⚠ unreadable frontmatter";
199
193
  const detail = [` status: ${status}`, `wake: ${relativeWake(entry.wakeMs, now)}`];
200
194
  const control = entry.frontmatter.control;
201
195
  if (control) {
@@ -232,7 +226,7 @@ async function approveTask(options, idInput) {
232
226
  const control = task.fields.control;
233
227
  if (!control)
234
228
  return `Task ${id} has no governed control metadata. Ask the agent to normalize it before approval.`;
235
- if (task.fields.status === "done" || task.fields.status === "cancelled" || task.fields.status === "escalated") {
229
+ if (task.fields.status === "done" || task.fields.status === "cancelled") {
236
230
  return `Task ${id} is ${task.fields.status} and cannot receive a new external-action approval.`;
237
231
  }
238
232
  if (control.sideEffects !== "external") {
@@ -253,14 +247,19 @@ export async function pauseTask(options, idInput) {
253
247
  const task = await readStoredTask(options.channelDir, id);
254
248
  if (!task)
255
249
  return `Task not found: ${id}`;
256
- if (["done", "cancelled", "escalated"].includes(task.fields.status)) {
257
- return `Task ${id} is ${task.fields.status} and cannot be paused.`;
258
- }
259
- if (task.fields.status === "paused")
250
+ const from = normalizeStoredStatus(task.fields.status);
251
+ if (from === "paused")
260
252
  return `Task ${id} is already paused.`;
253
+ try {
254
+ resolveTaskTransition("pause", id, from);
255
+ }
256
+ catch (error) {
257
+ return errorMessage(error);
258
+ }
261
259
  task.fields.status = "paused";
262
260
  task.fields.wake = undefined;
263
261
  if (task.fields.control) {
262
+ task.fields.control.pausedBy = "user";
264
263
  task.fields.control.lastOutcome = "blocked";
265
264
  task.fields.control.blockedReason = `Paused by ${options.approver?.trim() || "a user"}.`;
266
265
  }
@@ -272,11 +271,14 @@ export async function resumeTask(options, idInput) {
272
271
  const task = await readStoredTask(options.channelDir, id);
273
272
  if (!task)
274
273
  return `Task not found: ${id}`;
275
- if (task.fields.status !== "paused")
276
- return `Task ${id} is ${task.fields.status}, not paused.`;
277
- task.fields.status = "in-progress";
274
+ const from = normalizeStoredStatus(task.fields.status);
275
+ if (from !== "paused")
276
+ return `Task ${id} is ${from}, not paused.`;
277
+ resolveTaskTransition("resume", id, from);
278
+ task.fields.status = "active";
278
279
  task.fields.wake = undefined;
279
280
  if (task.fields.control) {
281
+ task.fields.control.pausedBy = undefined;
280
282
  task.fields.control.lastOutcome = "pending";
281
283
  task.fields.control.blockedReason = undefined;
282
284
  }
@@ -288,13 +290,17 @@ async function runTask(options, idInput) {
288
290
  const task = await readStoredTask(options.channelDir, id);
289
291
  if (!task)
290
292
  return `Task not found: ${id}`;
291
- if (["done", "cancelled", "escalated"].includes(task.fields.status)) {
292
- return `Task ${id} is ${task.fields.status} and cannot be run.`;
293
+ const from = normalizeStoredStatus(task.fields.status);
294
+ try {
295
+ resolveTaskTransition("run", id, from);
293
296
  }
294
- if (task.fields.status === "paused")
295
- task.fields.status = "in-progress";
297
+ catch (error) {
298
+ return errorMessage(error);
299
+ }
300
+ task.fields.status = "active";
296
301
  task.fields.wake = undefined;
297
302
  if (task.fields.control) {
303
+ task.fields.control.pausedBy = undefined;
298
304
  task.fields.control.lastOutcome = "pending";
299
305
  task.fields.control.blockedReason = undefined;
300
306
  }
@@ -409,14 +415,13 @@ async function doctor(options) {
409
415
  return "# Task Doctor\n\nNot available: workspaceDir and channelId are required.";
410
416
  }
411
417
  const now = Date.now();
412
- const hostTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
413
418
  const entries = await readActiveTasks(tasksDir(options.channelDir), now);
414
419
  const activeIds = new Set(entries.map((entry) => entry.id));
415
420
  const archivedIds = await readArchivedTaskIds(options.channelDir);
416
421
  const events = await readTaskEvents(options.workspaceDir, options.channelId);
417
422
  const issues = [];
418
423
  for (const entry of entries) {
419
- const status = entry.frontmatter.status ?? "open";
424
+ const status = entry.frontmatter.status ?? "active";
420
425
  if (!entry.frontmatter.readable) {
421
426
  issues.push(issue(`tasks/${entry.id}.md has unreadable frontmatter; wake/status cannot be trusted.`, `Fix tasks/${entry.id}.md so it starts with readable status/wake/recurrence frontmatter.`));
422
427
  continue;
@@ -464,19 +469,10 @@ async function doctor(options) {
464
469
  }
465
470
  }
466
471
  }
467
- const legacySchedule = eventKey(events, entry.id, "schedule");
468
- const recurring = Boolean(entry.frontmatter.schedule) || isParseableSchedule(events, entry.id);
472
+ const recurring = Boolean(entry.frontmatter.schedule);
469
473
  if (status === "done" && !recurring) {
470
474
  issues.push(issue(`tasks/${entry.id}.md is done but still in the active directory.`, `Archive one-shot task ${entry.id}, or add a schedule cron with task_manage set if it is recurring.`));
471
475
  }
472
- // Migration (027): recurrence cadence now lives in the task's `schedule` frontmatter.
473
- // A remaining canonical .schedule event should be folded in and deleted.
474
- if (legacySchedule && isTaskScheduleEvent(legacySchedule)) {
475
- issues.push(issue(`events/${legacySchedule.filename} is a legacy task .schedule event; cadence is now native to tasks/${entry.id}.md.`, `Fold its cron "${legacySchedule.event.schedule}" into the task's schedule frontmatter with task_manage set, then delete events/${legacySchedule.filename}.`));
476
- if (legacySchedule.event.legacyTimezone && legacySchedule.event.legacyTimezone !== hostTimezone) {
477
- issues.push(issue(`events/${legacySchedule.filename} declares timezone ${legacySchedule.event.legacyTimezone}, which differs from the host ${hostTimezone}.`, `Confirm the intended cadence after folding into frontmatter; the cron will run in the host timezone.`));
478
- }
479
- }
480
476
  const content = await readActiveTaskContent(options.channelDir, entry.id);
481
477
  if (content === undefined) {
482
478
  issues.push(issue(`tasks/${entry.id}.md could not be read during doctor checks.`, `Open tasks/${entry.id}.md manually and repair permissions or file contents.`));
@@ -490,18 +486,6 @@ async function doctor(options) {
490
486
  if (entry.frontmatter.wake && validWakeMs(entry) === undefined) {
491
487
  issues.push(issue(`tasks/${entry.id}.md has an invalid wake value (${entry.frontmatter.wake}); the native driver will treat it as due.`, `Use task_manage set or progress to replace wake with ISO8601, or clear it if the task should continue now.`));
492
488
  }
493
- const checkin = eventKey(events, entry.id, "checkin");
494
- if (checkin && isTaskCheckinEvent(checkin)) {
495
- issues.push(issue(`events/${checkin.filename} is a legacy task checkin; native wake handling makes it redundant.`, `Delete events/${checkin.filename} and keep the task wake value as the single resume condition.`));
496
- const wakeMs = validWakeMs(entry);
497
- const atMs = new Date(checkin.event.at).getTime();
498
- if (wakeMs === undefined) {
499
- issues.push(issue(`tasks/${entry.id}.md has a .checkin event but no valid wake value.`, `Set tasks/${entry.id}.md wake to ${checkin.event.at}, or delete the stale .checkin event.`));
500
- }
501
- else if (Number.isFinite(atMs) && Math.abs(atMs - wakeMs) > 60_000) {
502
- issues.push(issue(`tasks/${entry.id}.md wake does not match its .checkin event time.`, `Sync tasks/${entry.id}.md wake with events/${checkin.filename} at ${checkin.event.at}.`));
503
- }
504
- }
505
489
  }
506
490
  const parentGraph = new Map();
507
491
  const dependencyGraph = new Map();
@@ -534,12 +518,6 @@ async function doctor(options) {
534
518
  if (archivedIds.has(event.id)) {
535
519
  issues.push(issue(`events/${event.filename} points to archived task ${event.id}; closed tasks should have no live events.`, `Delete events/${event.filename}; archived tasks should not wake the agent.`));
536
520
  }
537
- if (event.use === "schedule" && !isTaskScheduleEvent(event)) {
538
- issues.push(issue(`events/${event.filename} is a schedule event but is not periodic.`, `Change events/${event.filename} to type periodic, or rename it away from .schedule.`));
539
- }
540
- if (event.use === "checkin" && !isTaskCheckinEvent(event)) {
541
- issues.push(issue(`events/${event.filename} is a checkin event but is not one-shot.`, `Change events/${event.filename} to type one-shot, or rename it away from .checkin.`));
542
- }
543
521
  }
544
522
  if (issues.length === 0) {
545
523
  return "# Task Doctor\n\nNo task ledger issues found.";
@@ -16,13 +16,6 @@ export interface TaskDriverOptions {
16
16
  }
17
17
  export declare function discoverTaskChannels(workspaceDir: string, knownChannelIds?: Iterable<string>): Promise<string[]>;
18
18
  export declare function createTaskDriverEvent(channelId: string, entry: TaskLedgerEntry, nowMs: number): DingTalkEvent;
19
- /**
20
- * A done recurring task whose schedule has come due. This is the one place the driver
21
- * wakes a `done` task: to open its next cycle. It uses a `[TASK_CYCLE:...]` tag (not
22
- * `[TASK_DRIVER:...]`) so the turn is not charged an attempt — start-cycle resets usage
23
- * anyway, matching the retired periodic-event flow.
24
- */
25
- export declare function createCycleStartEvent(channelId: string, entry: TaskLedgerEntry, nowMs: number): DingTalkEvent;
26
19
  /**
27
20
  * Native, token-gated driver for the persistent task ledger.
28
21
  *
@@ -65,6 +58,5 @@ export declare class TaskDriver {
65
58
  /** Fold `candidate` into the earliest interesting wake moment. */
66
59
  private noteHorizon;
67
60
  private collectHorizons;
68
- private hasLiveScheduleEvent;
69
61
  runOnce(now?: Date): Promise<void>;
70
62
  }