@oyasmi/pipiclaw 0.9.3-beta.5 → 0.9.3

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 (144) hide show
  1. package/README.en.md +1 -1
  2. package/README.md +1 -1
  3. package/dist/agent/channel-runner.d.ts +4 -8
  4. package/dist/agent/channel-runner.js +14 -34
  5. package/dist/agent/job-manager.d.ts +12 -0
  6. package/dist/agent/job-manager.js +42 -1
  7. package/dist/agent/prompt/sections.js +2 -2
  8. package/dist/agent/runner-factory.d.ts +2 -2
  9. package/dist/agent/types.d.ts +11 -7
  10. package/dist/channel/channel-index.d.ts +9 -2
  11. package/dist/channel/channel-index.js +25 -6
  12. package/dist/channel/project-scope-store.d.ts +20 -0
  13. package/dist/channel/project-scope-store.js +22 -7
  14. package/dist/commands/catalog.js +6 -12
  15. package/dist/events/event-commands.js +2 -2
  16. package/dist/events/events.d.ts +51 -30
  17. package/dist/events/events.js +70 -98
  18. package/dist/memory/journal.d.ts +2 -3
  19. package/dist/memory/journal.js +2 -3
  20. package/dist/memory/maintenance-tuning.d.ts +0 -1
  21. package/dist/memory/maintenance-tuning.js +0 -1
  22. package/dist/memory/scheduler.js +8 -16
  23. package/dist/memory/search.js +2 -3
  24. package/dist/memory/session-search.js +3 -9
  25. package/dist/memory/store.d.ts +1 -1
  26. package/dist/memory/store.js +9 -1
  27. package/dist/memory/task-digest.js +10 -11
  28. package/dist/memory/tombstones.js +2 -4
  29. package/dist/models/provider-login.d.ts +1 -1
  30. package/dist/models/provider-login.js +1 -1
  31. package/dist/playbooks/agent-delegation.md +6 -6
  32. package/dist/playbooks/background-jobs.md +1 -1
  33. package/dist/playbooks/event-scheduling.md +22 -13
  34. package/dist/playbooks/memory-and-learning.md +2 -2
  35. package/dist/playbooks/outbound-media.md +1 -1
  36. package/dist/playbooks/runtime-orientation.md +3 -3
  37. package/dist/playbooks/task-lead.md +82 -0
  38. package/dist/runtime/bootstrap.js +94 -187
  39. package/dist/runtime/durable-dispatch.js +30 -3
  40. package/dist/runtime/report-commands.d.ts +30 -0
  41. package/dist/runtime/report-commands.js +71 -0
  42. package/dist/runtime/subagent-commands.js +1 -1
  43. package/dist/runtime/task-commands.d.ts +0 -8
  44. package/dist/runtime/task-commands.js +48 -85
  45. package/dist/runtime/task-driver.d.ts +15 -10
  46. package/dist/runtime/task-driver.js +36 -41
  47. package/dist/runtime/task-migration.d.ts +23 -29
  48. package/dist/runtime/task-migration.js +364 -183
  49. package/dist/runtime/task-spawn.d.ts +24 -0
  50. package/dist/runtime/task-spawn.js +49 -0
  51. package/dist/runtime/task-wake.d.ts +33 -46
  52. package/dist/runtime/task-wake.js +15 -90
  53. package/dist/security/network.js +44 -9
  54. package/dist/settings.d.ts +1 -8
  55. package/dist/settings.js +1 -8
  56. package/dist/subagents/discovery.js +3 -15
  57. package/dist/subagents/external/run.d.ts +3 -1
  58. package/dist/subagents/external/run.js +2 -20
  59. package/dist/subagents/external/settlement.d.ts +4 -16
  60. package/dist/subagents/external/settlement.js +16 -67
  61. package/dist/subagents/runs.d.ts +15 -29
  62. package/dist/subagents/runs.js +70 -158
  63. package/dist/subagents/tool.d.ts +20 -4
  64. package/dist/subagents/tool.js +63 -87
  65. package/dist/subagents/verification-outcome.d.ts +13 -19
  66. package/dist/subagents/verification-outcome.js +8 -22
  67. package/dist/subagents/workspace-summary.d.ts +8 -0
  68. package/dist/subagents/workspace-summary.js +29 -0
  69. package/dist/tasks/board.d.ts +43 -0
  70. package/dist/tasks/board.js +134 -0
  71. package/dist/tasks/brief.d.ts +10 -5
  72. package/dist/tasks/brief.js +78 -26
  73. package/dist/tasks/budget.d.ts +13 -14
  74. package/dist/tasks/budget.js +21 -40
  75. package/dist/tasks/contract-input.d.ts +19 -0
  76. package/dist/tasks/contract-input.js +55 -0
  77. package/dist/tasks/create.d.ts +17 -0
  78. package/dist/tasks/create.js +36 -0
  79. package/dist/tasks/frontmatter.d.ts +20 -27
  80. package/dist/tasks/frontmatter.js +18 -31
  81. package/dist/tasks/ledger.d.ts +61 -117
  82. package/dist/tasks/ledger.js +78 -223
  83. package/dist/tasks/log.d.ts +62 -35
  84. package/dist/tasks/log.js +51 -29
  85. package/dist/tasks/session-path.d.ts +3 -3
  86. package/dist/tasks/session-path.js +4 -5
  87. package/dist/tasks/store.d.ts +27 -28
  88. package/dist/tasks/store.js +89 -83
  89. package/dist/tasks/ticket.d.ts +33 -66
  90. package/dist/tasks/ticket.js +31 -120
  91. package/dist/tasks/work-log.d.ts +20 -0
  92. package/dist/tasks/work-log.js +42 -0
  93. package/dist/tools/bash.d.ts +1 -1
  94. package/dist/tools/bash.js +1 -1
  95. package/dist/tools/event-manage.d.ts +16 -2
  96. package/dist/tools/event-manage.js +30 -12
  97. package/dist/tools/index.d.ts +5 -3
  98. package/dist/tools/index.js +5 -5
  99. package/dist/tools/registry.d.ts +6 -4
  100. package/dist/tools/registry.js +1 -4
  101. package/dist/tools/subagent-manage.js +4 -2
  102. package/dist/tools/task-manage/create.js +11 -27
  103. package/dist/tools/task-manage/lifecycle.d.ts +6 -7
  104. package/dist/tools/task-manage/lifecycle.js +23 -106
  105. package/dist/tools/task-manage/log-view.d.ts +3 -2
  106. package/dist/tools/task-manage/log-view.js +6 -6
  107. package/dist/tools/task-manage/schema.d.ts +10 -30
  108. package/dist/tools/task-manage/schema.js +33 -49
  109. package/dist/tools/task-manage/shared.d.ts +35 -42
  110. package/dist/tools/task-manage/shared.js +53 -192
  111. package/dist/tools/task-manage/step-end.d.ts +6 -6
  112. package/dist/tools/task-manage/step-end.js +61 -98
  113. package/dist/tools/task-manage/types.d.ts +8 -9
  114. package/dist/tools/task-manage.js +5 -5
  115. package/dist/tui/app.js +11 -38
  116. package/dist/tui/commands.d.ts +18 -8
  117. package/dist/tui/commands.js +2 -9
  118. package/dist/tui/turn-controller.d.ts +2 -14
  119. package/dist/tui/turn-controller.js +1 -17
  120. package/dist/web/client.js +9 -1
  121. package/examples/sub-agents/README.md +7 -4
  122. package/examples/sub-agents/agents/codex-flash.md +2 -2
  123. package/examples/sub-agents/agents/codex-high.md +1 -1
  124. package/examples/sub-agents/agents/codex-main.md +1 -1
  125. package/examples/sub-agents/agents/codex-review.md +23 -0
  126. package/examples/sub-agents/roles/verifier.md +1 -1
  127. package/package.json +1 -1
  128. package/dist/memory/maintenance-migration.d.ts +0 -5
  129. package/dist/memory/maintenance-migration.js +0 -91
  130. package/dist/memory/migrate.d.ts +0 -15
  131. package/dist/memory/migrate.js +0 -364
  132. package/dist/playbooks/task-loop.md +0 -90
  133. package/dist/tasks/artifact-subject.d.ts +0 -40
  134. package/dist/tasks/artifact-subject.js +0 -334
  135. package/dist/tasks/cycle.d.ts +0 -48
  136. package/dist/tasks/cycle.js +0 -94
  137. package/dist/tasks/rounds.d.ts +0 -41
  138. package/dist/tasks/rounds.js +0 -53
  139. package/dist/tasks/task-events.d.ts +0 -6
  140. package/dist/tasks/task-events.js +0 -14
  141. package/dist/tasks/task-schedule.d.ts +0 -18
  142. package/dist/tasks/task-schedule.js +0 -50
  143. package/dist/tasks/verification.d.ts +0 -114
  144. package/dist/tasks/verification.js +0 -226
@@ -1,15 +1,14 @@
1
1
  import type { TaskCloseRequest, TaskManageResult, TaskManageToolOptions, TaskUpdateRequest } from "./types.js";
2
2
  /**
3
- * `task_update` is metadata only (spec 051, D4): plan steps, cadence, budget, and whether a done
4
- * needs an independent PASS. Progress notes are no longer written here — they belong to the loop
5
- * log via `task_step_end`, which is the only writer that can also change what the task is waiting
6
- * for. Keeping the two apart is what stops "checkpoint" from quietly becoming a state transition.
3
+ * `task_update` is metadata only (spec 051, D4): Work Items and budget. Progress notes are not
4
+ * written here — they belong to the loop log via `task_step_end`, which is the only writer that
5
+ * can also change what the task is waiting for. Keeping the two apart is what stops "checkpoint"
6
+ * from quietly becoming a state transition.
7
7
  */
8
8
  export declare function updateTask(options: TaskManageToolOptions, request: TaskUpdateRequest): Promise<TaskManageResult>;
9
9
  /**
10
- * Close a task from the chat surface: `complete` archives it, `cancel` archives it as abandoned,
11
- * `skip` closes the current recurring occurrence and parks on the next one. The loop's own
12
- * `task_step_end outcome=done` shares the same close-out path.
10
+ * Close a task from the chat surface: `complete` archives it, `cancel` archives it as abandoned.
11
+ * The loop's own `task_step_end outcome=done` shares the same close-out path.
13
12
  */
14
13
  export declare function closeTask(options: TaskManageToolOptions, request: TaskCloseRequest): Promise<TaskManageResult>;
15
14
  export declare function listTasks(options: TaskManageToolOptions): Promise<TaskManageResult>;
@@ -1,11 +1,10 @@
1
1
  import { mkdir } from "node:fs/promises";
2
- import { renderCloseSummary, writeLastResult } from "../../tasks/cycle.js";
3
- import { applyTaskPlanPatch, normalizeTaskId, readActiveTasks, uncheckedTaskAcceptanceItems, } from "../../tasks/ledger.js";
4
- import { appendTaskLog } from "../../tasks/log.js";
5
- import { archiveTask, readStoredTask, writeStoredTask } from "../../tasks/store.js";
6
- import { describeTicket, resolveTicket } from "../../tasks/ticket.js";
2
+ import { normalizeTaskBudget } from "../../tasks/contract-input.js";
3
+ import { applyTaskItemsPatch, normalizeTaskId, readActiveTasks } from "../../tasks/ledger.js";
4
+ import { readStoredTask, writeStoredTask } from "../../tasks/store.js";
5
+ import { describeTicket } from "../../tasks/ticket.js";
7
6
  import { RecoverableToolError } from "../tool-details.js";
8
- import { assertVerificationHoldsForClose, buildTicketContext, cleanupTaskEvents, describeTaskState, normalizeBudget, normalizeSchedule, renderCloseEvidence, requiredField, tasksDir, } from "./shared.js";
7
+ import { closeTaskDocument, describeTaskState, requiredField, tasksDir } from "./shared.js";
9
8
  async function requireTask(options, id) {
10
9
  const document = await readStoredTask(options.channelDir, id);
11
10
  if (!document) {
@@ -14,35 +13,26 @@ async function requireTask(options, id) {
14
13
  return document;
15
14
  }
16
15
  /**
17
- * `task_update` is metadata only (spec 051, D4): plan steps, cadence, budget, and whether a done
18
- * needs an independent PASS. Progress notes are no longer written here — they belong to the loop
19
- * log via `task_step_end`, which is the only writer that can also change what the task is waiting
20
- * for. Keeping the two apart is what stops "checkpoint" from quietly becoming a state transition.
16
+ * `task_update` is metadata only (spec 051, D4): Work Items and budget. Progress notes are not
17
+ * written here — they belong to the loop log via `task_step_end`, which is the only writer that
18
+ * can also change what the task is waiting for. Keeping the two apart is what stops "checkpoint"
19
+ * from quietly becoming a state transition.
21
20
  */
22
21
  export async function updateTask(options, request) {
23
22
  const id = normalizeTaskId(request.id);
24
23
  const document = await requireTask(options, id);
25
24
  const changes = [];
26
- if (request.planSteps?.length) {
27
- const patched = applyTaskPlanPatch(document.body, request.planSteps);
25
+ if (request.items?.length) {
26
+ const patched = applyTaskItemsPatch(document.body, request.items);
28
27
  document.body = patched.body;
29
28
  if (patched.summary)
30
29
  changes.push(patched.summary);
31
30
  }
32
- const schedule = normalizeSchedule(request.schedule);
33
- if (schedule !== undefined) {
34
- document.fields.schedule = schedule ?? undefined;
35
- changes.push(schedule ? `schedule=${schedule}` : "schedule 已清除");
36
- }
37
- const budget = normalizeBudget(request.budget);
31
+ const budget = normalizeTaskBudget(request.budget);
38
32
  if (budget) {
39
33
  document.fields.budget = { ...document.fields.budget, ...budget };
40
34
  changes.push("budget 已更新");
41
35
  }
42
- if (request.verificationRequired !== undefined) {
43
- document.fields.verify = request.verificationRequired ? "required" : undefined;
44
- changes.push(`verify=${request.verificationRequired ? "required" : "off"}`);
45
- }
46
36
  await writeStoredTask(document);
47
37
  return {
48
38
  action: "update",
@@ -53,94 +43,22 @@ export async function updateTask(options, request) {
53
43
  };
54
44
  }
55
45
  /**
56
- * Close a task from the chat surface: `complete` archives it, `cancel` archives it as abandoned,
57
- * `skip` closes the current recurring occurrence and parks on the next one. The loop's own
58
- * `task_step_end outcome=done` shares the same close-out path.
46
+ * Close a task from the chat surface: `complete` archives it, `cancel` archives it as abandoned.
47
+ * The loop's own `task_step_end outcome=done` shares the same close-out path.
59
48
  */
60
49
  export async function closeTask(options, request) {
61
50
  const id = normalizeTaskId(request.id);
62
51
  const document = await requireTask(options, id);
63
- const cycleId = document.fields.cycle?.id ?? "-";
64
- if (request.outcome === "complete") {
65
- const unchecked = uncheckedTaskAcceptanceItems(document.body);
66
- if (unchecked.length > 0) {
67
- throw new RecoverableToolError(`Task "${id}" still has unmet acceptance items: ${unchecked.slice(0, 3).join("; ")}. Check them off with edit once the evidence holds.`);
68
- }
69
- await assertVerificationHoldsForClose(options, document, id);
70
- const evidence = renderCloseEvidence(request);
71
- document.body = writeLastResult(document.body, evidence);
72
- await writeStoredTask(document);
73
- await appendTaskLog(options.channelDir, id, {
74
- cycle: cycleId,
75
- kind: "close",
76
- outcome: "done",
77
- summary: requiredField(request.summary, "summary", "task_close outcome=complete"),
78
- evidence: request.evidence,
79
- residualRisk: request.residualRisk,
80
- steps: document.fields.cycle?.steps ?? 0,
81
- rounds: document.fields.cycle?.rounds ?? 0,
82
- usd: document.fields.cycle?.usd ?? 0,
83
- });
84
- const { deleted } = await cleanupTaskEvents(options, id);
85
- await archiveTask(options.channelDir, id, "completed");
86
- return {
87
- action: "close",
88
- id,
89
- archived: true,
90
- deletedEvents: deleted,
91
- notice: `任务 \`${id}\` 已完成并归档。`,
92
- };
93
- }
94
- if (request.outcome === "cancel") {
95
- const reason = requiredField(request.reason, "reason", "task_close outcome=cancel");
96
- document.body = writeLastResult(document.body, `- 已取消:${reason}`);
97
- await writeStoredTask(document);
98
- await appendTaskLog(options.channelDir, id, {
99
- cycle: cycleId,
100
- kind: "close",
101
- outcome: "cancelled",
102
- summary: reason,
103
- steps: document.fields.cycle?.steps ?? 0,
104
- rounds: document.fields.cycle?.rounds ?? 0,
105
- usd: document.fields.cycle?.usd ?? 0,
106
- });
107
- const { deleted } = await cleanupTaskEvents(options, id);
108
- await archiveTask(options.channelDir, id, "cancelled");
109
- return { action: "close", id, archived: true, deletedEvents: deleted, notice: `任务 \`${id}\` 已取消并归档。` };
110
- }
111
- // skip: recurring only — park on the next occurrence without faking completion evidence.
112
- if (!document.fields.schedule) {
113
- throw new RecoverableToolError(`Task "${id}" is one-shot; skip applies to a recurring occurrence. Use outcome=cancel to abandon it.`);
114
- }
115
- const reason = requiredField(request.reason, "reason", "task_close outcome=skip");
116
- const context = await buildTicketContext(options, id, document.fields.schedule);
117
- const ticket = resolveTicket({ kind: "schedule" }, context);
118
- document.body = writeLastResult(document.body, renderCloseSummary({
119
- cycleId,
120
- outcome: "cancelled",
121
- summary: `本次 occurrence 跳过:${reason}`,
122
- steps: document.fields.cycle?.steps ?? 0,
123
- rounds: document.fields.cycle?.rounds ?? 0,
124
- usd: document.fields.cycle?.usd ?? 0,
125
- usdEstimated: document.fields.cycle?.usdEstimated ?? false,
126
- }));
127
- document.fields.state = "parked";
128
- document.fields.ticket = ticket;
129
- await writeStoredTask(document);
130
- await appendTaskLog(options.channelDir, id, {
131
- cycle: cycleId,
132
- kind: "close",
133
- outcome: "cancelled",
134
- summary: `skip: ${reason}`,
135
- steps: document.fields.cycle?.steps ?? 0,
136
- rounds: document.fields.cycle?.rounds ?? 0,
137
- usd: document.fields.cycle?.usd ?? 0,
138
- });
52
+ const note = requiredField(request.note, "note", `task_close outcome=${request.outcome}`);
53
+ const { stillRunning } = await closeTaskDocument({ options, document, id, outcome: request.outcome, note });
54
+ const running = stillRunning.length > 0
55
+ ? ` 仍在运行的委派/作业不会被取消:${stillRunning.join(", ")}(用 subagent_run op=cancel / job cancel 处理)。`
56
+ : "";
139
57
  return {
140
58
  action: "close",
141
59
  id,
142
- state: "parked",
143
- notice: `任务 \`${id}\` 本周期已跳过,${describeTicket(ticket)}。`,
60
+ archived: true,
61
+ notice: `任务 \`${id}\` 已${request.outcome === "complete" ? "完成" : "取消"}并归档。${running}`,
144
62
  };
145
63
  }
146
64
  export async function listTasks(options) {
@@ -153,9 +71,8 @@ export async function listTasks(options) {
153
71
  state: entry.fields.state,
154
72
  paused: Boolean(entry.fields.paused),
155
73
  ticket: entry.fields.ticket ? describeTicket(entry.fields.ticket) : undefined,
156
- cycle: entry.fields.cycle?.id,
157
- steps: entry.fields.cycle?.steps,
158
- rounds: entry.fields.cycle?.rounds,
74
+ steps: entry.fields.usage?.steps,
75
+ items: entry.items ? `${entry.items.done}/${entry.items.total}` : undefined,
159
76
  }));
160
77
  return {
161
78
  action: "list",
@@ -2,7 +2,8 @@ import type { TaskLogRequest, TaskManageResult, TaskManageToolOptions } from "./
2
2
  /**
3
3
  * `task_log` — read the loop log (spec 051, D5).
4
4
  *
5
- * This is what makes the 4 KB contract affordable: the history the task file used to carry
6
- * inline is still there, just addressed on demand instead of injected into every step.
5
+ * This is what makes the small contract affordable: the history the task file used to carry
6
+ * inline is still there, just addressed on demand instead of injected into every step. It also
7
+ * shows the dispatch/settle records the step brief folds into the board.
7
8
  */
8
9
  export declare function readTaskLogTool(options: TaskManageToolOptions, request: TaskLogRequest): Promise<TaskManageResult>;
@@ -5,23 +5,23 @@ const MAX_LIMIT = 100;
5
5
  /**
6
6
  * `task_log` — read the loop log (spec 051, D5).
7
7
  *
8
- * This is what makes the 4 KB contract affordable: the history the task file used to carry
9
- * inline is still there, just addressed on demand instead of injected into every step.
8
+ * This is what makes the small contract affordable: the history the task file used to carry
9
+ * inline is still there, just addressed on demand instead of injected into every step. It also
10
+ * shows the dispatch/settle records the step brief folds into the board.
10
11
  */
11
12
  export async function readTaskLogTool(options, request) {
12
13
  const id = normalizeTaskId(request.id);
13
14
  const limit = Math.min(Math.max(1, Math.trunc(request.limit ?? DEFAULT_LIMIT)), MAX_LIMIT);
14
15
  const archived = taskLogIsArchived(options.channelDir, id);
15
- const records = await readTaskLog(options.channelDir, id, { cycle: request.cycle, limit });
16
+ const records = await readTaskLog(options.channelDir, id, { limit });
16
17
  const entries = records.map(renderTaskLogLine);
17
- const scope = request.cycle ? `(周期 ${request.cycle})` : "";
18
18
  const archivedTag = archived ? "(已归档任务)" : "";
19
19
  return {
20
20
  action: "log",
21
21
  id,
22
22
  entries,
23
23
  notice: entries.length === 0
24
- ? `任务 \`${id}\` 暂无循环日志${scope}${archivedTag}。`
25
- : `任务 \`${id}\` 最近 ${entries.length} 条记录${scope}${archivedTag}。`,
24
+ ? `任务 \`${id}\` 暂无循环日志${archivedTag}。`
25
+ : `任务 \`${id}\` 最近 ${entries.length} 条记录${archivedTag}。`,
26
26
  };
27
27
  }
@@ -5,67 +5,47 @@ export declare const taskCreateSchema: Type.TObject<{
5
5
  title: Type.TString;
6
6
  goal: Type.TString;
7
7
  dod: Type.TString;
8
- plan: Type.TOptional<Type.TString>;
9
- manual: Type.TOptional<Type.TString>;
10
- verificationPlan: Type.TOptional<Type.TString>;
11
- verificationRequired: Type.TOptional<Type.TBoolean>;
12
- schedule: Type.TOptional<Type.TString>;
8
+ items: Type.TOptional<Type.TArray<Type.TObject<{
9
+ text: Type.TString;
10
+ }>>>;
13
11
  budget: Type.TOptional<Type.TObject<{
14
12
  steps: Type.TOptional<Type.TInteger>;
15
- wallMin: Type.TOptional<Type.TNumber>;
16
13
  usd: Type.TOptional<Type.TNumber>;
17
- rounds: Type.TOptional<Type.TInteger>;
18
- until: Type.TOptional<Type.TString>;
19
14
  }>>;
20
15
  }>;
21
16
  export declare const taskUpdateSchema: Type.TObject<{
22
17
  id: Type.TString;
23
- planSteps: Type.TOptional<Type.TArray<Type.TObject<{
18
+ items: Type.TOptional<Type.TArray<Type.TObject<{
24
19
  id: Type.TString;
25
20
  status: Type.TOptional<Type.TUnion<[Type.TLiteral<"todo">, Type.TLiteral<"done">, Type.TLiteral<"blocked">, Type.TLiteral<"dropped">]>>;
26
21
  text: Type.TOptional<Type.TString>;
27
22
  }>>>;
28
- schedule: Type.TOptional<Type.TString>;
29
23
  budget: Type.TOptional<Type.TObject<{
30
24
  steps: Type.TOptional<Type.TInteger>;
31
- wallMin: Type.TOptional<Type.TNumber>;
32
25
  usd: Type.TOptional<Type.TNumber>;
33
- rounds: Type.TOptional<Type.TInteger>;
34
- until: Type.TOptional<Type.TString>;
35
26
  }>>;
36
- verificationRequired: Type.TOptional<Type.TBoolean>;
37
27
  }>;
38
28
  export declare const taskCloseSchema: Type.TObject<{
39
29
  id: Type.TString;
40
- outcome: Type.TUnion<[Type.TLiteral<"complete">, Type.TLiteral<"skip">, Type.TLiteral<"cancel">]>;
41
- summary: Type.TOptional<Type.TString>;
42
- evidence: Type.TOptional<Type.TString>;
43
- residualRisk: Type.TOptional<Type.TString>;
44
- reason: Type.TOptional<Type.TString>;
30
+ outcome: Type.TUnion<[Type.TLiteral<"complete">, Type.TLiteral<"cancel">]>;
31
+ note: Type.TString;
45
32
  }>;
46
33
  export declare const taskLogSchema: Type.TObject<{
47
34
  id: Type.TString;
48
- cycle: Type.TOptional<Type.TString>;
49
35
  limit: Type.TOptional<Type.TInteger>;
50
36
  }>;
51
37
  export declare const taskStepEndSchema: Type.TObject<{
52
- outcome: Type.TUnion<[Type.TLiteral<"continue">, Type.TLiteral<"park">, Type.TLiteral<"done">, Type.TLiteral<"blocked">]>;
38
+ outcome: Type.TUnion<[Type.TLiteral<"continue">, Type.TLiteral<"park">, Type.TLiteral<"done">]>;
53
39
  note: Type.TString;
54
- planSteps: Type.TOptional<Type.TArray<Type.TObject<{
40
+ items: Type.TOptional<Type.TArray<Type.TObject<{
55
41
  id: Type.TString;
56
42
  status: Type.TOptional<Type.TUnion<[Type.TLiteral<"todo">, Type.TLiteral<"done">, Type.TLiteral<"blocked">, Type.TLiteral<"dropped">]>>;
57
43
  text: Type.TOptional<Type.TString>;
58
44
  }>>>;
59
45
  ticket: Type.TOptional<Type.TObject<{
60
- kind: Type.TUnion<[Type.TLiteral<"time">, Type.TLiteral<"run">, Type.TLiteral<"job">, Type.TLiteral<"ask">, Type.TLiteral<"signal">]>;
46
+ kind: Type.TUnion<[Type.TLiteral<"time">, Type.TLiteral<"work">, Type.TLiteral<"ask">]>;
61
47
  at: Type.TOptional<Type.TString>;
62
- id: Type.TOptional<Type.TString>;
63
48
  asked: Type.TOptional<Type.TString>;
64
- event: Type.TOptional<Type.TString>;
65
49
  }>>;
66
- notify: Type.TOptional<Type.TString>;
67
- summary: Type.TOptional<Type.TString>;
68
- evidence: Type.TOptional<Type.TString>;
69
- residualRisk: Type.TOptional<Type.TString>;
70
- reason: Type.TOptional<Type.TString>;
50
+ report: Type.TOptional<Type.TString>;
71
51
  }>;
@@ -1,85 +1,69 @@
1
1
  import { Type } from "typebox";
2
2
  const idField = Type.String({ description: "Task id (filename without .md)." });
3
- const planStepsField = Type.Optional(Type.Array(Type.Object({
4
- id: Type.String({ description: 'Plan step id, e.g. "P2"; new ids append a step.' }),
5
- status: Type.Optional(Type.Union([Type.Literal("todo"), Type.Literal("done"), Type.Literal("blocked"), Type.Literal("dropped")], {
6
- description: "New status for this step.",
7
- })),
8
- text: Type.Optional(Type.String({ description: "Step text; required when appending a new id." })),
9
- }), { description: "Update or append Plan steps by id." }));
10
- const scheduleField = Type.Optional(Type.String({
11
- description: "Five-field cron cadence; makes this recurring. Empty string clears it. Min every 30 minutes.",
12
- }));
13
3
  const budgetField = Type.Optional(Type.Object({
14
- steps: Type.Optional(Type.Integer({ minimum: 1, description: "Max model steps in one cycle." })),
15
- wallMin: Type.Optional(Type.Number({ description: "Max elapsed minutes in one cycle, including parked waits." })),
16
- usd: Type.Optional(Type.Number({ description: "Max attributable cost in one cycle." })),
17
- rounds: Type.Optional(Type.Integer({ minimum: 1, description: "Max delegate→verify rework rounds in one cycle." })),
18
- until: Type.Optional(Type.String({ description: "Hard local-time stop, e.g. 2026-09-06T18:00:00+08:00." })),
4
+ steps: Type.Optional(Type.Integer({ minimum: 1, description: "Max model steps for the whole task." })),
5
+ usd: Type.Optional(Type.Number({ description: "Max attributable cost for the whole task, including bound delegations." })),
19
6
  }, { description: "Per-task budget; omitted keys fall back to the runtime defaults." }));
7
+ /** Update or append Work Items by id. `id` is always required: a new id appends an item (then `text` too). */
8
+ const itemsPatchField = Type.Optional(Type.Array(Type.Object({
9
+ id: Type.String({ description: 'Work item id, e.g. "W2"; an unseen id appends a new item.' }),
10
+ status: Type.Optional(Type.Union([Type.Literal("todo"), Type.Literal("done"), Type.Literal("blocked"), Type.Literal("dropped")], {
11
+ description: "New status for this item. Only you mark an item done — after checking its result.",
12
+ })),
13
+ text: Type.Optional(Type.String({ description: "Item text; required when appending a new id." })),
14
+ }), { description: "Update or append Work Items by id." }));
20
15
  /**
21
- * The waiting ticket a park must carry (spec 051, D2). Every field the runtime cannot derive is
22
- * here and nothing else: `by` is stamped by the runtime, never by the model, because a backstop
23
- * the model can choose is a backstop it can choose not to have.
16
+ * The waiting ticket a park must carry (spec 051, D2; spec 052, D3). Every field the runtime
17
+ * cannot derive is here and nothing else: `by` is stamped by the runtime, never by the model,
18
+ * because a backstop the model can choose is a backstop it can choose not to have, and a `work`
19
+ * ticket needs no id — it waits for whatever this task has in flight.
24
20
  */
25
21
  const ticketField = Type.Object({
26
- kind: Type.Union([Type.Literal("time"), Type.Literal("run"), Type.Literal("job"), Type.Literal("ask"), Type.Literal("signal")], { description: "What will wake this task." }),
22
+ kind: Type.Union([Type.Literal("time"), Type.Literal("work"), Type.Literal("ask")], {
23
+ description: "time = wait for a moment; work = wait for this task's in-flight delegations/jobs (the first to settle wakes you); ask = wait for the user.",
24
+ }),
27
25
  at: Type.Optional(Type.String({ description: 'kind=time: when, e.g. "+2h" or a local timestamp.' })),
28
- id: Type.Optional(Type.String({ description: "kind=run/job: the run or job id this task is waiting on." })),
29
26
  asked: Type.Optional(Type.String({ description: "kind=ask: the question the user must answer." })),
30
- event: Type.Optional(Type.String({ description: "kind=signal: the task-owned periodic event name." })),
31
27
  }, { description: "Ticket describing what will resume this task." });
32
28
  export const taskListSchema = Type.Object({});
33
29
  export const taskCreateSchema = Type.Object({
34
30
  id: idField,
35
31
  title: Type.String({ description: "Task title (H1 heading)." }),
36
- goal: Type.String({ description: "Concise task goal." }),
32
+ goal: Type.String({ description: "The result, its scope, the external actions allowed, key constraints." }),
37
33
  dod: Type.String({
38
34
  description: 'Checklist items, e.g. "- [ ] <criterion>"; plain prose is rejected.',
39
35
  }),
40
- plan: Type.Optional(Type.String({
41
- description: 'Initial "## Plan" steps, one per line — the means, not the DoD.',
36
+ items: Type.Optional(Type.Array(Type.Object({ text: Type.String({ description: "One independently deliverable, checkable piece." }) }), {
37
+ description: "Initial Work Items, numbered W1…Wn in order.",
42
38
  })),
43
- manual: Type.Optional(Type.String({ description: "Initial operating steps or checklist." })),
44
- verificationPlan: Type.Optional(Type.String({ description: "Deterministic checks the verifier must perform." })),
45
- verificationRequired: Type.Optional(Type.Boolean({ description: "Whether done requires an independent verifier PASS. Default false." })),
46
- schedule: scheduleField,
47
39
  budget: budgetField,
48
40
  });
49
41
  export const taskUpdateSchema = Type.Object({
50
42
  id: idField,
51
- planSteps: planStepsField,
52
- schedule: scheduleField,
43
+ items: itemsPatchField,
53
44
  budget: budgetField,
54
- verificationRequired: Type.Optional(Type.Boolean({ description: "Whether done requires an independent verifier PASS." })),
55
45
  });
56
46
  export const taskCloseSchema = Type.Object({
57
47
  id: idField,
58
- outcome: Type.Union([Type.Literal("complete"), Type.Literal("skip"), Type.Literal("cancel")], {
59
- description: "complete / skip (recurring only) / cancel.",
48
+ outcome: Type.Union([Type.Literal("complete"), Type.Literal("cancel")], {
49
+ description: "complete (DoD all checked) or cancel (abandon).",
50
+ }),
51
+ note: Type.String({
52
+ description: "complete: what was achieved and the evidence. cancel: why it was abandoned.",
60
53
  }),
61
- summary: Type.Optional(Type.String({ description: "Concise completion summary; required for outcome=complete." })),
62
- evidence: Type.Optional(Type.String({
63
- description: "Verification evidence, or a clear not-run reason. Required for outcome=complete.",
64
- })),
65
- residualRisk: Type.Optional(Type.String({ description: "Remaining risk or follow-up note; optional." })),
66
- reason: Type.Optional(Type.String({ description: "Why this occurrence was skipped or the task abandoned; required for skip/cancel." })),
67
54
  });
68
55
  export const taskLogSchema = Type.Object({
69
56
  id: idField,
70
- cycle: Type.Optional(Type.String({ description: "Only this cycle's records, e.g. c-2026-09-05." })),
71
57
  limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 100, description: "Most recent N records; default 20." })),
72
58
  });
73
59
  export const taskStepEndSchema = Type.Object({
74
- outcome: Type.Union([Type.Literal("continue"), Type.Literal("park"), Type.Literal("done"), Type.Literal("blocked")], {
75
- description: "continue = more work now; park = wait on a ticket; done = close the cycle; blocked = ask the user.",
60
+ outcome: Type.Union([Type.Literal("continue"), Type.Literal("park"), Type.Literal("done")], {
61
+ description: "continue = more work now; park = wait on a ticket; done = the project is finished.",
62
+ }),
63
+ note: Type.String({
64
+ description: "What this step did, the evidence, and the next step. Goes to the loop log; for done, what was achieved and the proof.",
76
65
  }),
77
- note: Type.String({ description: "What this step did, the evidence, and the next step. Goes to the loop log." }),
78
- planSteps: planStepsField,
66
+ items: itemsPatchField,
79
67
  ticket: Type.Optional(ticketField),
80
- notify: Type.Optional(Type.String({ description: "Message to send the user. Omit to stay silent." })),
81
- summary: Type.Optional(Type.String({ description: "Required for outcome=done: what was achieved." })),
82
- evidence: Type.Optional(Type.String({ description: "Required for outcome=done: concrete proof." })),
83
- residualRisk: Type.Optional(Type.String({ description: "Remaining risk after outcome=done." })),
84
- reason: Type.Optional(Type.String({ description: "Required for outcome=blocked: what is blocking." })),
68
+ report: Type.Optional(Type.String({ description: "Message to send the user (results, delivery, a question). Omit to stay silent." })),
85
69
  });
@@ -1,51 +1,44 @@
1
- import type { TaskBudget, TaskFrontmatterV4 } from "../../tasks/frontmatter.js";
2
- import type { StoredTaskDocument } from "../../tasks/store.js";
3
- import { type TicketContext } from "../../tasks/ticket.js";
4
- import type { TaskCloseRequest, TaskCreateRequest, TaskManageToolOptions, TaskUpdateRequest } from "./types.js";
1
+ import type { TaskFrontmatter } from "../../tasks/frontmatter.js";
2
+ import { type StoredTaskDocument } from "../../tasks/store.js";
3
+ import { type PendingWorkRef, type TicketContext } from "../../tasks/ticket.js";
4
+ import type { TaskManageToolOptions } from "./types.js";
5
5
  export declare function tasksDir(options: TaskManageToolOptions): string;
6
- export declare function eventsDir(options: TaskManageToolOptions): string;
7
- export declare function renderTaskFile(fields: TaskFrontmatterV4, body: string): string;
8
6
  export declare function requiredField(value: string | undefined, field: string, action: string): string;
9
- export declare function markdownValue(value: string): string;
10
- /** The `## 上次结果` paragraph a close writes into the contract. */
11
- export declare function renderCloseEvidence(request: TaskCloseRequest): string;
12
- export declare function normalizeBudget(budget: TaskUpdateRequest["budget"]): Partial<TaskBudget> | undefined;
13
- export declare function normalizeSchedule(schedule: string | undefined): string | undefined | null;
14
- /**
15
- * A newly created task starts `open` — even a recurring one. Creation opens its first cycle
16
- * immediately rather than parking until the next cron occurrence, because "create it and it does
17
- * nothing until tomorrow morning" was consistently surprising; the cadence still governs every
18
- * *subsequent* cycle through the `schedule` ticket the loop parks on when it finishes.
19
- */
20
- export declare function renderTaskSkeleton(request: TaskCreateRequest, now?: Date): {
21
- fields: TaskFrontmatterV4;
22
- body: string;
23
- };
24
7
  /** The scheduling half of a lifecycle notice: where the task stands and who will wake it. */
25
- export declare function describeTaskState(fields: TaskFrontmatterV4): string;
8
+ export declare function describeTaskState(fields: TaskFrontmatter): string;
26
9
  /**
27
- * Build the injected lookup a ticket resolver needs. The run/job/event registries are read here —
28
- * once, at the call site — rather than imported inside `ticket.ts`, which is what keeps the whole
29
- * validation matrix unit-testable against plain fakes.
10
+ * Delegations and background jobs bound to `taskId` that have not settled yet, each with the
11
+ * instant its owner gives up on it. The registries are read here — once, at the call site —
12
+ * rather than imported inside `ticket.ts`, which is what keeps the whole validation matrix
13
+ * unit-testable against plain fakes.
30
14
  */
31
- export declare function buildTicketContext(options: TaskManageToolOptions, taskId: string, schedule: string | undefined, now?: Date): Promise<TicketContext>;
15
+ export declare function listPendingWork(options: TaskManageToolOptions, taskId: string): Promise<PendingWorkRef[]>;
16
+ export declare function buildTicketContext(options: TaskManageToolOptions, taskId: string, now?: Date): Promise<TicketContext>;
17
+ export interface CloseTaskInput {
18
+ options: TaskManageToolOptions;
19
+ document: StoredTaskDocument;
20
+ id: string;
21
+ outcome: "complete" | "cancel";
22
+ note: string;
23
+ /** Steps the loop log should record; defaults to the task's own counter. */
24
+ steps?: number;
25
+ /**
26
+ * Runs after every check has passed and before the close record is written. `task_step_end`
27
+ * records its own step here: it has to land in the active log (archiving moves the log away) and
28
+ * must not land at all if a check rejects the close, or a corrected retry would log it twice.
29
+ */
30
+ afterChecks?: () => Promise<void>;
31
+ }
32
32
  /**
33
- * On close-out (complete or cancel), delete every task-owned event.
33
+ * Close a task: the one close-out both `task_step_end outcome=done` and `task_close` share
34
+ * (spec 052, D6/D7).
34
35
  *
35
- * Matching is done by parsing each candidate name and comparing the full task id, not by prefix —
36
- * a prefix match on `task.<channel>.<id>.` would also match a *different* task whose id happens to
37
- * start with this one plus a dot (e.g. closing "v1" must not delete events owned by "v1.2-release").
36
+ * `complete` has two gates, both cheap and both about the *leader's* own state rather than any
37
+ * runtime proof: every DoD item is checked off (the leader's explicit confirmation), and nothing
38
+ * bound to the task is still in flight (otherwise the project would be archived and the late
39
+ * result would fall back into the chat). `cancel` has neither gate — abandoning work must always
40
+ * be possible — but reports what was left running, because closing a task never cancels it.
38
41
  */
39
- export declare function cleanupTaskEvents(options: TaskManageToolOptions, id: string): Promise<{
40
- deleted: string[];
42
+ export declare function closeTaskDocument(input: CloseTaskInput): Promise<{
43
+ stillRunning: string[];
41
44
  }>;
42
- /**
43
- * The verification gate both close entry points share (`task_step_end outcome=done` and
44
- * `task_close outcome=complete`).
45
- *
46
- * It exists as one function because the two used to ask the question separately and both asked
47
- * the weaker one — "did a PASS ever land in this cycle" — which a contract edit or a further code
48
- * change made *after* the PASS would still satisfy. The real check is re-run here, against the
49
- * contract and the checkout as they stand at close time.
50
- */
51
- export declare function assertVerificationHoldsForClose(options: TaskManageToolOptions, document: StoredTaskDocument, id: string): Promise<void>;