@oyasmi/pipiclaw 0.9.2 → 0.9.3-beta.2

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 (178) hide show
  1. package/README.en.md +250 -0
  2. package/README.md +3 -1
  3. package/dist/agent/channel-runner.d.ts +59 -2
  4. package/dist/agent/channel-runner.js +177 -76
  5. package/dist/agent/job-manager.d.ts +76 -21
  6. package/dist/agent/job-manager.js +447 -63
  7. package/dist/agent/maintenance-context.js +4 -5
  8. package/dist/agent/prompt/manifest.d.ts +0 -2
  9. package/dist/agent/prompt/manifest.js +2 -3
  10. package/dist/agent/prompt/sections.js +3 -3
  11. package/dist/agent/session-events.js +4 -8
  12. package/dist/agent/turn-prompt.d.ts +7 -7
  13. package/dist/agent/turn-prompt.js +6 -9
  14. package/dist/agent/types.d.ts +12 -0
  15. package/dist/agent/types.js +1 -0
  16. package/dist/channel/channel-context.d.ts +13 -0
  17. package/dist/channel/channel-context.js +21 -1
  18. package/dist/commands/catalog.js +47 -20
  19. package/dist/memory/commands.d.ts +8 -0
  20. package/dist/memory/commands.js +113 -148
  21. package/dist/memory/index-budget.d.ts +27 -0
  22. package/dist/memory/index-budget.js +99 -0
  23. package/dist/memory/journal.d.ts +20 -0
  24. package/dist/memory/journal.js +78 -0
  25. package/dist/memory/lifecycle.d.ts +9 -15
  26. package/dist/memory/lifecycle.js +55 -145
  27. package/dist/memory/maintenance-gates.d.ts +13 -47
  28. package/dist/memory/maintenance-gates.js +13 -92
  29. package/dist/memory/maintenance-state.d.ts +10 -16
  30. package/dist/memory/maintenance-state.js +12 -59
  31. package/dist/memory/maintenance-tuning.d.ts +7 -27
  32. package/dist/memory/maintenance-tuning.js +11 -28
  33. package/dist/memory/migrate.d.ts +15 -0
  34. package/dist/memory/migrate.js +364 -0
  35. package/dist/memory/reflect-job.d.ts +43 -0
  36. package/dist/memory/reflect-job.js +117 -0
  37. package/dist/memory/reflect.d.ts +52 -0
  38. package/dist/memory/reflect.js +313 -0
  39. package/dist/memory/render.d.ts +19 -0
  40. package/dist/memory/render.js +35 -0
  41. package/dist/memory/review-log.d.ts +2 -1
  42. package/dist/memory/scheduler.d.ts +2 -3
  43. package/dist/memory/scheduler.js +14 -49
  44. package/dist/memory/search.d.ts +35 -0
  45. package/dist/memory/search.js +297 -0
  46. package/dist/memory/session-search.js +1 -1
  47. package/dist/memory/store.d.ts +108 -0
  48. package/dist/memory/store.js +418 -0
  49. package/dist/memory/task-digest.d.ts +2 -2
  50. package/dist/memory/task-digest.js +29 -36
  51. package/dist/memory/tombstones.d.ts +0 -11
  52. package/dist/memory/tombstones.js +6 -37
  53. package/dist/memory/transcript.js +12 -5
  54. package/dist/playbooks/agent-delegation.md +37 -9
  55. package/dist/playbooks/background-jobs.md +1 -1
  56. package/dist/playbooks/event-scheduling.md +6 -2
  57. package/dist/playbooks/memory-and-learning.md +36 -12
  58. package/dist/playbooks/outbound-media.md +1 -1
  59. package/dist/playbooks/runtime-orientation.md +9 -8
  60. package/dist/playbooks/task-loop.md +110 -0
  61. package/dist/runtime/bootstrap.d.ts +3 -3
  62. package/dist/runtime/bootstrap.js +66 -41
  63. package/dist/runtime/events.d.ts +9 -0
  64. package/dist/runtime/events.js +43 -4
  65. package/dist/runtime/task-commands.d.ts +14 -15
  66. package/dist/runtime/task-commands.js +249 -485
  67. package/dist/runtime/task-driver.d.ts +41 -29
  68. package/dist/runtime/task-driver.js +170 -317
  69. package/dist/runtime/task-migration.d.ts +34 -30
  70. package/dist/runtime/task-migration.js +229 -183
  71. package/dist/runtime/task-wake.d.ts +6 -3
  72. package/dist/runtime/task-wake.js +26 -19
  73. package/dist/settings.d.ts +0 -29
  74. package/dist/settings.js +12 -35
  75. package/dist/shared/markdown-sections.d.ts +0 -1
  76. package/dist/shared/markdown-sections.js +0 -3
  77. package/dist/subagents/discovery.d.ts +2 -2
  78. package/dist/subagents/discovery.js +21 -10
  79. package/dist/subagents/external/progress-tail.js +6 -1
  80. package/dist/subagents/external/run.js +1 -0
  81. package/dist/subagents/runs.d.ts +19 -2
  82. package/dist/subagents/runs.js +73 -4
  83. package/dist/subagents/tool.d.ts +10 -8
  84. package/dist/subagents/tool.js +55 -94
  85. package/dist/tasks/brief.d.ts +17 -0
  86. package/dist/tasks/brief.js +57 -0
  87. package/dist/tasks/budget.d.ts +26 -0
  88. package/dist/tasks/budget.js +59 -0
  89. package/dist/tasks/cycle.d.ts +48 -0
  90. package/dist/tasks/cycle.js +94 -0
  91. package/dist/tasks/frontmatter.d.ts +73 -0
  92. package/dist/tasks/frontmatter.js +175 -0
  93. package/dist/tasks/ledger.d.ts +66 -106
  94. package/dist/tasks/ledger.js +90 -546
  95. package/dist/tasks/log.d.ts +88 -0
  96. package/dist/tasks/log.js +97 -0
  97. package/dist/tasks/rounds.d.ts +41 -0
  98. package/dist/tasks/rounds.js +53 -0
  99. package/dist/tasks/session-path.d.ts +9 -0
  100. package/dist/tasks/session-path.js +16 -0
  101. package/dist/tasks/steer.d.ts +8 -0
  102. package/dist/tasks/steer.js +79 -0
  103. package/dist/tasks/store.d.ts +60 -35
  104. package/dist/tasks/store.js +166 -107
  105. package/dist/tasks/ticket.d.ts +102 -0
  106. package/dist/tasks/ticket.js +209 -0
  107. package/dist/tasks/verification.d.ts +47 -0
  108. package/dist/tasks/verification.js +60 -1
  109. package/dist/tools/index.d.ts +13 -4
  110. package/dist/tools/index.js +5 -10
  111. package/dist/tools/memory-manage.d.ts +6 -16
  112. package/dist/tools/memory-manage.js +108 -129
  113. package/dist/tools/presentation.js +2 -1
  114. package/dist/tools/registry.d.ts +11 -2
  115. package/dist/tools/registry.js +17 -6
  116. package/dist/tools/subagent-manage.d.ts +0 -9
  117. package/dist/tools/subagent-manage.js +8 -17
  118. package/dist/tools/task-manage/create.js +2 -2
  119. package/dist/tools/task-manage/lifecycle.d.ts +9 -4
  120. package/dist/tools/task-manage/lifecycle.js +136 -188
  121. package/dist/tools/task-manage/log-view.d.ts +8 -0
  122. package/dist/tools/task-manage/log-view.js +24 -0
  123. package/dist/tools/task-manage/schema.d.ts +38 -14
  124. package/dist/tools/task-manage/schema.js +46 -27
  125. package/dist/tools/task-manage/shared.d.ts +35 -31
  126. package/dist/tools/task-manage/shared.js +130 -141
  127. package/dist/tools/task-manage/step-end.d.ts +11 -0
  128. package/dist/tools/task-manage/step-end.js +134 -0
  129. package/dist/tools/task-manage/types.d.ts +23 -32
  130. package/dist/tools/task-manage.d.ts +4 -3
  131. package/dist/tools/task-manage.js +30 -15
  132. package/dist/tools/tool-details.d.ts +1 -1
  133. package/dist/tui/app.js +0 -2
  134. package/examples/sub-agents/README.md +54 -38
  135. package/examples/sub-agents/builder-hard.md +21 -12
  136. package/examples/sub-agents/builder.md +24 -16
  137. package/examples/sub-agents/explorer.md +17 -15
  138. package/examples/sub-agents/git-committer.md +8 -6
  139. package/examples/sub-agents/planner.md +17 -16
  140. package/examples/sub-agents/reviewer.md +11 -9
  141. package/examples/sub-agents/verifier.md +22 -16
  142. package/examples/sub-agents/worker.md +22 -6
  143. package/package.json +1 -1
  144. package/dist/agent/effect-ledger.d.ts +0 -32
  145. package/dist/agent/effect-ledger.js +0 -89
  146. package/dist/memory/bootstrap.d.ts +0 -17
  147. package/dist/memory/bootstrap.js +0 -120
  148. package/dist/memory/candidates.d.ts +0 -26
  149. package/dist/memory/candidates.js +0 -202
  150. package/dist/memory/consolidation.d.ts +0 -54
  151. package/dist/memory/consolidation.js +0 -292
  152. package/dist/memory/extraction.d.ts +0 -54
  153. package/dist/memory/extraction.js +0 -240
  154. package/dist/memory/files.d.ts +0 -71
  155. package/dist/memory/files.js +0 -419
  156. package/dist/memory/maintenance-jobs.d.ts +0 -41
  157. package/dist/memory/maintenance-jobs.js +0 -265
  158. package/dist/memory/metadata.d.ts +0 -57
  159. package/dist/memory/metadata.js +0 -142
  160. package/dist/memory/probation.d.ts +0 -17
  161. package/dist/memory/probation.js +0 -44
  162. package/dist/memory/promotion.d.ts +0 -38
  163. package/dist/memory/promotion.js +0 -36
  164. package/dist/memory/recall.d.ts +0 -59
  165. package/dist/memory/recall.js +0 -746
  166. package/dist/memory/session.d.ts +0 -24
  167. package/dist/memory/session.js +0 -273
  168. package/dist/playbooks/task-driving.md +0 -92
  169. package/dist/playbooks/task-planning.md +0 -58
  170. package/dist/tasks/control.d.ts +0 -56
  171. package/dist/tasks/control.js +0 -169
  172. package/dist/tasks/transitions.d.ts +0 -16
  173. package/dist/tasks/transitions.js +0 -48
  174. package/dist/tools/task-manage/verification.d.ts +0 -19
  175. package/dist/tools/task-manage/verification.js +0 -91
  176. package/examples/sub-agents/documenter.md +0 -50
  177. package/examples/sub-agents/log-sifter.md +0 -47
  178. package/examples/sub-agents/scout.md +0 -34
@@ -0,0 +1,175 @@
1
+ import { formatLocalTime } from "../shared/local-time.js";
2
+ import { isPlainObject } from "../shared/type-guards.js";
3
+ import { parseTicket } from "./ticket.js";
4
+ const STATES = ["open", "parked", "done"];
5
+ /** Fixed render order, so a diff of a task file reads the same way every time. */
6
+ const FIELD_ORDER = ["state", "paused", "schedule", "ticket", "cycle", "budget", "verify"];
7
+ function parseJsonObject(raw) {
8
+ try {
9
+ const value = JSON.parse(raw);
10
+ return isPlainObject(value) ? value : undefined;
11
+ }
12
+ catch {
13
+ return undefined;
14
+ }
15
+ }
16
+ function parsePaused(raw) {
17
+ const value = parseJsonObject(raw);
18
+ if (!value)
19
+ return undefined;
20
+ const by = value.by === "runtime" ? "runtime" : "user";
21
+ const reason = typeof value.reason === "string" ? value.reason.trim() : "";
22
+ const at = typeof value.at === "string" ? value.at.trim() : "";
23
+ if (!reason)
24
+ return undefined;
25
+ return { by, reason, at: at || formatLocalTime() };
26
+ }
27
+ function nonNegativeNumber(value, fallback) {
28
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : fallback;
29
+ }
30
+ function parseCycle(raw) {
31
+ const value = parseJsonObject(raw);
32
+ if (!value || typeof value.id !== "string" || !value.id.trim())
33
+ return undefined;
34
+ return {
35
+ id: value.id.trim(),
36
+ startedAt: typeof value.startedAt === "string" && value.startedAt ? value.startedAt : formatLocalTime(),
37
+ steps: nonNegativeNumber(value.steps, 0),
38
+ rounds: nonNegativeNumber(value.rounds, 0),
39
+ usd: nonNegativeNumber(value.usd, 0),
40
+ usdEstimated: value.usdEstimated === true,
41
+ expired: nonNegativeNumber(value.expired, 0),
42
+ };
43
+ }
44
+ function parseBudget(raw) {
45
+ const value = parseJsonObject(raw);
46
+ if (!value)
47
+ return undefined;
48
+ const budget = {};
49
+ if (typeof value.steps === "number" && value.steps > 0)
50
+ budget.steps = value.steps;
51
+ if (typeof value.wallMin === "number" && value.wallMin > 0)
52
+ budget.wallMin = value.wallMin;
53
+ if (typeof value.usd === "number" && value.usd > 0)
54
+ budget.usd = value.usd;
55
+ if (typeof value.rounds === "number" && value.rounds > 0)
56
+ budget.rounds = value.rounds;
57
+ if (typeof value.until === "string" && value.until.trim())
58
+ budget.until = value.until.trim();
59
+ return Object.keys(budget).length > 0 ? budget : undefined;
60
+ }
61
+ /**
62
+ * Read the leading frontmatter block. Unreadable input fails **open** to a live `open` task: a
63
+ * corrupt file has to surface as work the runtime tries to touch, not silently disappear from the
64
+ * ledger — the same fail-open stance v3 took, for the same reason.
65
+ */
66
+ export function parseTaskFrontmatterV4(content) {
67
+ if (!content.startsWith("---"))
68
+ return { fields: { state: "open" }, readable: false, legacy: false };
69
+ const end = content.indexOf("\n---", 3);
70
+ if (end === -1)
71
+ return { fields: { state: "open" }, readable: false, legacy: false };
72
+ const fields = { state: "open" };
73
+ let legacy = false;
74
+ let sawState = false;
75
+ for (const line of content.slice(3, end).split("\n")) {
76
+ const idx = line.indexOf(":");
77
+ if (idx === -1)
78
+ continue;
79
+ const key = line.slice(0, idx).trim();
80
+ const value = line.slice(idx + 1).trim();
81
+ switch (key) {
82
+ case "state":
83
+ if (STATES.includes(value)) {
84
+ fields.state = value;
85
+ sawState = true;
86
+ }
87
+ break;
88
+ case "paused":
89
+ fields.paused = parsePaused(value);
90
+ break;
91
+ case "schedule":
92
+ fields.schedule = value || undefined;
93
+ break;
94
+ case "ticket":
95
+ fields.ticket = parseTicket(value);
96
+ break;
97
+ case "cycle":
98
+ fields.cycle = parseCycle(value);
99
+ break;
100
+ case "budget":
101
+ fields.budget = parseBudget(value);
102
+ break;
103
+ case "verify":
104
+ if (value === "required")
105
+ fields.verify = "required";
106
+ break;
107
+ case "outcome":
108
+ if (value === "completed" || value === "cancelled")
109
+ fields.outcome = value;
110
+ break;
111
+ case "closedAt":
112
+ fields.closedAt = value || undefined;
113
+ break;
114
+ // v3 leftovers: their presence is the migrator's trigger, their values are its input.
115
+ case "status":
116
+ case "enabled":
117
+ case "control":
118
+ case "wake":
119
+ legacy = true;
120
+ break;
121
+ default:
122
+ break;
123
+ }
124
+ }
125
+ if (fields.outcome)
126
+ fields.state = "done";
127
+ // A file with no recognizable v4 or v3 marker is not frontmatter we understand.
128
+ const readable = sawState || fields.outcome !== undefined || legacy;
129
+ return { fields: normalizeTaskFrontmatter(fields), readable, legacy };
130
+ }
131
+ /**
132
+ * Enforce INV-1 on every write and read: `parked` requires a ticket, and a ticket only means
133
+ * anything while parked. Doing it here rather than at each call site is what makes "a parked task
134
+ * always has a redeemable, backstopped source" a property of the file format instead of a rule
135
+ * every writer has to remember.
136
+ */
137
+ export function normalizeTaskFrontmatter(fields) {
138
+ const next = { ...fields };
139
+ if (next.outcome) {
140
+ next.state = "done";
141
+ next.ticket = undefined;
142
+ next.paused = undefined;
143
+ return next;
144
+ }
145
+ if (next.state === "parked" && !next.ticket)
146
+ next.state = "open";
147
+ if (next.state !== "parked")
148
+ next.ticket = undefined;
149
+ return next;
150
+ }
151
+ export function renderTaskFrontmatter(fields) {
152
+ const document = normalizeTaskFrontmatter(fields);
153
+ const lines = ["---"];
154
+ if (document.outcome) {
155
+ lines.push(`outcome: ${document.outcome}`);
156
+ if (document.closedAt)
157
+ lines.push(`closedAt: ${document.closedAt}`);
158
+ if (document.cycle)
159
+ lines.push(`cycle: ${JSON.stringify(document.cycle)}`);
160
+ lines.push("---");
161
+ return lines.join("\n");
162
+ }
163
+ for (const key of FIELD_ORDER) {
164
+ const value = document[key];
165
+ if (value === undefined)
166
+ continue;
167
+ lines.push(typeof value === "string" ? `${key}: ${value}` : `${key}: ${JSON.stringify(value)}`);
168
+ }
169
+ lines.push("---");
170
+ return lines.join("\n");
171
+ }
172
+ /** Whether the driver may schedule a step for this task right now. */
173
+ export function isTaskRunnable(fields) {
174
+ return fields.state === "open" && !fields.paused && !fields.outcome;
175
+ }
@@ -1,48 +1,32 @@
1
- import { type TaskControl } from "./control.js";
2
- export type TaskArchiveOutcome = "completed" | "cancelled";
1
+ import { type TaskFrontmatterV4 } from "./frontmatter.js";
3
2
  /**
4
3
  * Shared reader for the task ledger (`workspace/<channelId>/tasks/*.md`).
5
4
  *
6
5
  * This is the sole implementation of the frontmatter contract documented in
7
- * `docs/events-and-tasks.md` ("Frontmatter 契约(单一事实源)"). It used to be one of two
8
- * halves — a dependency-free `tasks-pending.mjs` sensor under workspace/skills was the
9
- * other — but the native TaskDriver (spec 022) replaced that sensor, so `actionable` now
10
- * has a single owner. The parsing stays deliberately literal (flat `key: value` fields,
11
- * live-vs-archived, wake gating, fail-open on unreadable frontmatter) because task files
12
- * are hand-editable and must degrade toward "wake me up so I can be fixed".
13
- * `/tasks`, the task digest, and `task_list` all read through here.
6
+ * `docs/tasks.md`. The parsing stays deliberately literal (flat `key: value` fields,
7
+ * live-vs-archived, fail-open on unreadable frontmatter) because task files are hand-editable
8
+ * and must degrade toward "wake me up so I can be fixed". `/tasks`, the task digest, and
9
+ * `task_list` all read through here.
10
+ *
11
+ * Spec 051 split the frontmatter contract itself into `frontmatter.ts` (fields) and `ticket.ts`
12
+ * (the waiting claim); what stays here is the *body*: sections, Plan, DoD, and the skeleton.
14
13
  */
15
- export interface TaskFrontmatter {
16
- /** false => frontmatter could not be read (fail-open: the task is treated as actionable). */
17
- readable: boolean;
18
- status?: string;
19
- /** The unnormalized on-disk status value; startup migration is its only consumer. */
20
- rawStatus?: string;
21
- /** True when a legacy terminal file in the active directory needs archiving. */
22
- archiveOutcome?: TaskArchiveOutcome;
23
- closedAt?: string;
24
- enabled: boolean;
25
- wake?: string;
26
- /** Five-field cron cadence (host timezone). Present ⇒ this is a recurring task. */
27
- schedule?: string;
28
- control?: TaskControl;
29
- /** false only when a control field exists but cannot be parsed/validated as v3. */
30
- controlReadable?: boolean;
31
- /** The unparsed `control:` value; startup migration re-parses this with the legacy reader. */
32
- controlRaw?: string;
33
- }
34
14
  export interface TaskLedgerEntry {
35
15
  /** Filename without `.md`; the task id. */
36
16
  id: string;
37
17
  /** First `# ` heading in the body, or the id when none. */
38
18
  title: string;
39
- frontmatter: TaskFrontmatter;
40
- /** Non-terminal, not parked (`waiting` without a wake), and (no valid wake OR wake ≤ now). */
41
- actionable: boolean;
42
- /** Milliseconds since epoch parsed from `wake`, or undefined when unset/unparseable. */
43
- wakeMs?: number;
44
- /** First bullet/line under a "当前周期"/"current cycle" heading, if any (digest only). */
45
- latestNote?: string;
19
+ fields: TaskFrontmatterV4;
20
+ /** false => frontmatter could not be read; the task is surfaced rather than skipped. */
21
+ readable: boolean;
22
+ /** True when this file still carries v3 `status`/`control` frontmatter. */
23
+ legacy: boolean;
24
+ /** The driver may schedule a step for this task right now. */
25
+ runnable: boolean;
26
+ /** When a driver-polled ticket (`time`/`schedule`) comes due, if it has not already. */
27
+ dueMs?: number;
28
+ /** True when a parked task's backstop has passed and the runtime owes it a reopen (D2). */
29
+ expired: boolean;
46
30
  /** Parsed `## Plan` section, if the task has one (spec 037, D2). */
47
31
  plan?: TaskPlanSummary;
48
32
  }
@@ -56,7 +40,7 @@ export interface TaskSkeletonInput {
56
40
  /** Optional initial `## Plan` steps, one per line; a missing `P<n>` prefix is auto-assigned. */
57
41
  plan?: string;
58
42
  }
59
- export declare const DEFAULT_TASK_MANUAL = "- Follow the DoD, keep the current cycle log updated, and schedule check-ins when waiting.";
43
+ export declare const DEFAULT_TASK_MANUAL = "- Follow the DoD, record evidence in every step note, and park on a ticket when waiting.";
60
44
  export declare const STANDARD_TASK_SECTIONS: readonly [{
61
45
  readonly label: "Goal";
62
46
  readonly names: readonly ["Goal", "目标"];
@@ -69,23 +53,19 @@ export declare const STANDARD_TASK_SECTIONS: readonly [{
69
53
  }, {
70
54
  readonly label: "Verification";
71
55
  readonly names: readonly ["Verification", "验收"];
72
- }, {
73
- readonly label: "Current Cycle";
74
- readonly names: readonly ["Current Cycle", "当前周期"];
75
- }, {
76
- readonly label: "History";
77
- readonly names: readonly ["History", "历史"];
78
56
  }];
79
- /** Recurring task files are working context, not an unbounded audit log. */
80
- export declare const MAX_INLINE_TASK_HISTORY_ENTRIES = 8;
81
- export declare const MAX_INLINE_TASK_HISTORY_CHARS: number;
57
+ /**
58
+ * The single historical paragraph a v4 contract keeps (spec 051, D5). Declared here rather than
59
+ * in `cycle.ts` so `taskContractSegment` can end the contract at it without a circular import.
60
+ */
61
+ export declare const LAST_RESULT_SECTION_NAMES: readonly ["上次结果", "Last Result"];
82
62
  /** Validate/normalize a task id (filename without `.md`), rejecting path traversal. */
83
63
  export declare function normalizeTaskId(id: string): string;
84
64
  /** The document body after the leading frontmatter block, or the whole content when there is none. */
85
65
  export declare function taskBody(content: string): string;
86
66
  /**
87
- * The task's *contract* segment: the body up to (excluding) whichever of "Plan" or "Current
88
- * Cycle" appears first — i.e. the H1 title, Goal, DoD (with its checkbox state), Manual and
67
+ * The task's *contract* segment: the body up to (excluding) whichever of "Plan" or "上次结果"
68
+ * appears first — i.e. the H1 title, Goal, DoD (with its checkbox state), Manual and
89
69
  * Verification (spec 029, D4).
90
70
  *
91
71
  * Verification PASS binds to this segment, not the whole body, so routine `progress` notes
@@ -99,6 +79,13 @@ export declare function taskBody(content: string): string;
99
79
  * A body without either heading (non-standard) falls back to the whole body.
100
80
  */
101
81
  export declare function taskContractSegment(body: string): string;
82
+ /**
83
+ * Hash the task's *contract* segment (Goal/DoD/Manual/Verification), not the whole body, so a
84
+ * verification PASS survives routine step logging and only breaks when the contract itself
85
+ * changes (spec 029, D4). Lives next to `taskContractSegment` because it is that function's
86
+ * only real consumer.
87
+ */
88
+ export declare function taskBodyHash(body: string): string;
102
89
  export type TaskPlanStepStatus = "todo" | "done" | "blocked" | "dropped";
103
90
  export interface TaskPlanStep {
104
91
  /** `P<n>` by convention; a hand-written step without one gets its position as a fallback. */
@@ -153,27 +140,24 @@ export interface ApplyTaskPlanPatchResult {
153
140
  * unconsumed revision counter.
154
141
  */
155
142
  export declare function applyTaskPlanPatch(body: string, patches: readonly TaskPlanStepPatch[]): ApplyTaskPlanPatchResult;
156
- /** Parse the leading frontmatter block and normalize legacy v1 fields in memory. */
157
- export declare function parseTaskFrontmatter(content: string): TaskFrontmatter;
158
- /**
159
- * The single shared judgement: is there work to do on this task right now?
160
- * Unreadable frontmatter is fail-open (actionable) so a corrupt ledger surfaces
161
- * rather than being silently skipped.
162
- *
163
- * `waiting` with no `wake` is the *parked* form (`src/tasks/transitions.ts`): the task is
164
- * blocked on an external signal — a background job finishing, the user answering, `/tasks run` —
165
- * and only that signal may resume it. Without this the runtime's own recommended shape for
166
- * delegating work (start a blocking wait as a `bash async` job, park the task, end the turn)
167
- * was re-dispatched the instant the turn ended, found the job still running, answered
168
- * `[SILENT]`, and after three such wakes was disabled by the governor. A `waiting` task that
169
- * *does* carry a wake is an ordinary timed re-check and stays gated on that wake; an
170
- * unparseable wake still fails open so a hand-edited file surfaces rather than parks forever.
171
- */
172
- /** `waiting` with no `wake`: the driver will not come back on its own. See `isTaskActionable`. */
173
- export declare function isTaskParked(frontmatter: TaskFrontmatter): boolean;
174
- export declare function isTaskActionable(frontmatter: TaskFrontmatter, now: number): boolean;
175
143
  /** First `# ` heading after the frontmatter block, or the id when there is none. */
176
144
  export declare function extractTaskTitle(content: string, fallbackId: string): string;
145
+ export declare function matchesTaskSectionTitle(title: string, names: readonly string[]): boolean;
146
+ export interface TaskSectionBounds {
147
+ /** Line index of the heading line itself. */
148
+ headingIndex: number;
149
+ /** Heading level, 1–6. */
150
+ level: number;
151
+ /** Exclusive end: the next heading at the same or a shallower level, or `lines.length`. */
152
+ end: number;
153
+ }
154
+ /**
155
+ * Find the first heading matching one of `names` and the exclusive end of its body — the next
156
+ * heading at the same or a shallower level, or end of document. Every task-document section scan
157
+ * (Plan, Current Cycle, DoD, Verification) shares this exact rule; only what a caller does with
158
+ * the bounds differs.
159
+ */
160
+ export declare function findTaskSectionBounds(lines: readonly string[], names: readonly string[]): TaskSectionBounds | undefined;
177
161
  export declare function hasTaskHeading(content: string, names: readonly string[]): boolean;
178
162
  export declare function missingStandardTaskSections(content: string): string[];
179
163
  export declare function uncheckedTaskAcceptanceItems(content: string): string[];
@@ -182,55 +166,31 @@ export declare function uncheckedTaskAcceptanceItems(content: string): string[];
182
166
  * step's `→ dod:N` refs (spec 037, D4 — `/tasks doctor`'s drift checks).
183
167
  */
184
168
  export declare function countTaskDodItems(content: string): number;
185
- export declare function renderStandardTaskBody(input: TaskSkeletonInput): string;
186
- export interface TaskDocumentFields {
187
- status: string;
188
- /** Raw v1 value retained only in memory for startup migration. */
189
- legacyStatus?: string;
190
- enabled?: boolean;
191
- wake?: string;
192
- schedule?: string;
193
- control?: TaskControl;
194
- outcome?: TaskArchiveOutcome;
195
- closedAt?: string;
196
- }
197
- /**
198
- * Enforce the v3 write-path invariants. Runtime due transitions are intentionally separate: a
199
- * waiting task is first written active, and a sleeping task is first opened into a cycle, before
200
- * the driver dispatches anything.
201
- */
202
- export declare function normalizeTaskFields(fields: TaskDocumentFields, now?: Date): TaskDocumentFields;
203
169
  /**
204
- * Whether an open recurring cycle has already crossed its next schedule occurrence.
205
- * The runtime must keep working on the old cycle rather than opening a concurrent one.
206
- * Cycle ids intentionally carry the local calendar date; the optional suffix handles a
207
- * same-day manual reopen deterministically.
170
+ * The v4 task skeleton: contract only (spec 051, D5). `## Current Cycle` and `## History` are
171
+ * gone — the per-step record lives in `<id>.jsonl`, and the one paragraph the contract keeps
172
+ * (`## 上次结果`) is written by the cycle-close path, not by the skeleton.
208
173
  */
209
- export declare function recurringTaskMissedOccurrence(fields: TaskDocumentFields, now?: Date): boolean;
210
- export declare function renderTaskDocument(fields: TaskDocumentFields, rawBody: string): string;
211
- /** Append one progress bullet to the standard Current Cycle section. */
212
- export declare function appendCurrentCycleNote(content: string, note: string): string;
174
+ export declare function renderStandardTaskBody(input: TaskSkeletonInput): string;
175
+ /** Serialize a task document: v4 frontmatter block plus the body, unchanged. */
176
+ export declare function renderTaskDocument(fields: TaskFrontmatterV4, rawBody: string): string;
213
177
  /**
214
- * Upsert the completion evidence subsection inside Current Cycle.
215
- *
216
- * Evidence is part of the cycle log, not a new top-level section. This makes the next
217
- * `startTaskCycle` fold it into the matching History entry and prevents repeated completion
218
- * attempts from appending duplicate evidence blocks.
178
+ * Reset a recurring task's per-cycle checkboxes: DoD/Verification acceptance items and Plan
179
+ * steps both go back to unchecked, so cycle N+1 can never pass its acceptance gate on cycle N's
180
+ * evidence. `[~]` dropped plan steps are left alone — that step was deliberately abandoned, not
181
+ * merely finished, and a new cycle should not resurrect it.
219
182
  */
220
- export declare function upsertCurrentCycleCompletionEvidence(content: string, evidenceLines: readonly string[]): string;
183
+ export declare function resetTaskPlanForCycle(body: string): string;
221
184
  /**
222
- * Close the visible current-cycle notes into History and open a fresh cycle.
223
- * Periodic task cycles deliberately use this small, deterministic transformation
224
- * instead of asking the model to hand-edit headings and risk appending future
225
- * checkpoints to the previous cycle.
185
+ * Runnable first; then a parked task whose backstop already expired (the runtime owes it a
186
+ * reopen); then earliest due ticket; then id. Sorting expired parks ahead of ordinary parks is
187
+ * what keeps D2-INV's deadline honest when a channel has more ready work than one tick can carry.
226
188
  */
227
- export declare function startTaskCycle(content: string, cycleId: string, archivePrevious?: boolean): string;
228
- /** Actionable first; then earliest deadline/wake first (unset sorts as "ready now"); then id. */
229
189
  export declare function compareTaskEntries(a: TaskLedgerEntry, b: TaskLedgerEntry): number;
230
190
  /**
231
191
  * Read every `.md` file in `tasks/` (root only — the `archive/` subdirectory is not
232
- * scanned), returning entries sorted actionable-first. A file that cannot be read is
233
- * still returned (fail-open: `readable: false`, `actionable: true`) so problems surface.
192
+ * scanned), returning entries sorted runnable-first. A file that cannot be read is still
193
+ * returned (fail-open: `readable: false`, `runnable: true`) so problems surface.
234
194
  * Missing directory → empty list.
235
195
  */
236
196
  export declare function readActiveTasks(tasksDir: string, now?: number): Promise<TaskLedgerEntry[]>;