@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.
- package/README.en.md +1 -1
- package/README.md +1 -1
- package/dist/agent/channel-runner.d.ts +4 -8
- package/dist/agent/channel-runner.js +14 -34
- package/dist/agent/job-manager.d.ts +12 -0
- package/dist/agent/job-manager.js +42 -1
- package/dist/agent/prompt/sections.js +2 -2
- package/dist/agent/runner-factory.d.ts +2 -2
- package/dist/agent/types.d.ts +11 -7
- package/dist/channel/channel-index.d.ts +9 -2
- package/dist/channel/channel-index.js +25 -6
- package/dist/channel/project-scope-store.d.ts +20 -0
- package/dist/channel/project-scope-store.js +22 -7
- package/dist/commands/catalog.js +6 -12
- package/dist/events/event-commands.js +2 -2
- package/dist/events/events.d.ts +51 -30
- package/dist/events/events.js +70 -98
- package/dist/memory/journal.d.ts +2 -3
- package/dist/memory/journal.js +2 -3
- package/dist/memory/maintenance-tuning.d.ts +0 -1
- package/dist/memory/maintenance-tuning.js +0 -1
- package/dist/memory/scheduler.js +8 -16
- package/dist/memory/search.js +2 -3
- package/dist/memory/session-search.js +3 -9
- package/dist/memory/store.d.ts +1 -1
- package/dist/memory/store.js +9 -1
- package/dist/memory/task-digest.js +10 -11
- package/dist/memory/tombstones.js +2 -4
- package/dist/models/provider-login.d.ts +1 -1
- package/dist/models/provider-login.js +1 -1
- package/dist/playbooks/agent-delegation.md +6 -6
- package/dist/playbooks/background-jobs.md +1 -1
- package/dist/playbooks/event-scheduling.md +22 -13
- package/dist/playbooks/memory-and-learning.md +2 -2
- package/dist/playbooks/outbound-media.md +1 -1
- package/dist/playbooks/runtime-orientation.md +3 -3
- package/dist/playbooks/task-lead.md +82 -0
- package/dist/runtime/bootstrap.js +94 -187
- package/dist/runtime/durable-dispatch.js +30 -3
- package/dist/runtime/report-commands.d.ts +30 -0
- package/dist/runtime/report-commands.js +71 -0
- package/dist/runtime/subagent-commands.js +1 -1
- package/dist/runtime/task-commands.d.ts +0 -8
- package/dist/runtime/task-commands.js +48 -85
- package/dist/runtime/task-driver.d.ts +15 -10
- package/dist/runtime/task-driver.js +36 -41
- package/dist/runtime/task-migration.d.ts +23 -29
- package/dist/runtime/task-migration.js +364 -183
- package/dist/runtime/task-spawn.d.ts +24 -0
- package/dist/runtime/task-spawn.js +49 -0
- package/dist/runtime/task-wake.d.ts +33 -46
- package/dist/runtime/task-wake.js +15 -90
- package/dist/security/network.js +44 -9
- package/dist/settings.d.ts +1 -8
- package/dist/settings.js +1 -8
- package/dist/subagents/discovery.js +3 -15
- package/dist/subagents/external/run.d.ts +3 -1
- package/dist/subagents/external/run.js +2 -20
- package/dist/subagents/external/settlement.d.ts +4 -16
- package/dist/subagents/external/settlement.js +16 -67
- package/dist/subagents/runs.d.ts +15 -29
- package/dist/subagents/runs.js +70 -158
- package/dist/subagents/tool.d.ts +20 -4
- package/dist/subagents/tool.js +63 -87
- package/dist/subagents/verification-outcome.d.ts +13 -19
- package/dist/subagents/verification-outcome.js +8 -22
- package/dist/subagents/workspace-summary.d.ts +8 -0
- package/dist/subagents/workspace-summary.js +29 -0
- package/dist/tasks/board.d.ts +43 -0
- package/dist/tasks/board.js +134 -0
- package/dist/tasks/brief.d.ts +10 -5
- package/dist/tasks/brief.js +78 -26
- package/dist/tasks/budget.d.ts +13 -14
- package/dist/tasks/budget.js +21 -40
- package/dist/tasks/contract-input.d.ts +19 -0
- package/dist/tasks/contract-input.js +55 -0
- package/dist/tasks/create.d.ts +17 -0
- package/dist/tasks/create.js +36 -0
- package/dist/tasks/frontmatter.d.ts +20 -27
- package/dist/tasks/frontmatter.js +18 -31
- package/dist/tasks/ledger.d.ts +61 -117
- package/dist/tasks/ledger.js +78 -223
- package/dist/tasks/log.d.ts +62 -35
- package/dist/tasks/log.js +51 -29
- package/dist/tasks/session-path.d.ts +3 -3
- package/dist/tasks/session-path.js +4 -5
- package/dist/tasks/store.d.ts +27 -28
- package/dist/tasks/store.js +89 -83
- package/dist/tasks/ticket.d.ts +33 -66
- package/dist/tasks/ticket.js +31 -120
- package/dist/tasks/work-log.d.ts +20 -0
- package/dist/tasks/work-log.js +42 -0
- package/dist/tools/bash.d.ts +1 -1
- package/dist/tools/bash.js +1 -1
- package/dist/tools/event-manage.d.ts +16 -2
- package/dist/tools/event-manage.js +30 -12
- package/dist/tools/index.d.ts +5 -3
- package/dist/tools/index.js +5 -5
- package/dist/tools/registry.d.ts +6 -4
- package/dist/tools/registry.js +1 -4
- package/dist/tools/subagent-manage.js +4 -2
- package/dist/tools/task-manage/create.js +11 -27
- package/dist/tools/task-manage/lifecycle.d.ts +6 -7
- package/dist/tools/task-manage/lifecycle.js +23 -106
- package/dist/tools/task-manage/log-view.d.ts +3 -2
- package/dist/tools/task-manage/log-view.js +6 -6
- package/dist/tools/task-manage/schema.d.ts +10 -30
- package/dist/tools/task-manage/schema.js +33 -49
- package/dist/tools/task-manage/shared.d.ts +35 -42
- package/dist/tools/task-manage/shared.js +53 -192
- package/dist/tools/task-manage/step-end.d.ts +6 -6
- package/dist/tools/task-manage/step-end.js +61 -98
- package/dist/tools/task-manage/types.d.ts +8 -9
- package/dist/tools/task-manage.js +5 -5
- package/dist/tui/app.js +11 -38
- package/dist/tui/commands.d.ts +18 -8
- package/dist/tui/commands.js +2 -9
- package/dist/tui/turn-controller.d.ts +2 -14
- package/dist/tui/turn-controller.js +1 -17
- package/dist/web/client.js +9 -1
- package/examples/sub-agents/README.md +7 -4
- package/examples/sub-agents/agents/codex-flash.md +2 -2
- package/examples/sub-agents/agents/codex-high.md +1 -1
- package/examples/sub-agents/agents/codex-main.md +1 -1
- package/examples/sub-agents/agents/codex-review.md +23 -0
- package/examples/sub-agents/roles/verifier.md +1 -1
- package/package.json +1 -1
- package/dist/memory/maintenance-migration.d.ts +0 -5
- package/dist/memory/maintenance-migration.js +0 -91
- package/dist/memory/migrate.d.ts +0 -15
- package/dist/memory/migrate.js +0 -364
- package/dist/playbooks/task-loop.md +0 -90
- package/dist/tasks/artifact-subject.d.ts +0 -40
- package/dist/tasks/artifact-subject.js +0 -334
- package/dist/tasks/cycle.d.ts +0 -48
- package/dist/tasks/cycle.js +0 -94
- package/dist/tasks/rounds.d.ts +0 -41
- package/dist/tasks/rounds.js +0 -53
- package/dist/tasks/task-events.d.ts +0 -6
- package/dist/tasks/task-events.js +0 -14
- package/dist/tasks/task-schedule.d.ts +0 -18
- package/dist/tasks/task-schedule.js +0 -50
- package/dist/tasks/verification.d.ts +0 -114
- package/dist/tasks/verification.js +0 -226
package/dist/tasks/ledger.js
CHANGED
|
@@ -1,29 +1,13 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
1
|
import { readdir, readFile, stat } from "node:fs/promises";
|
|
3
2
|
import { join } from "node:path";
|
|
4
3
|
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
5
4
|
import { normalizeSafeId } from "../shared/safe-id.js";
|
|
6
|
-
import { isTaskRunnable,
|
|
5
|
+
import { isTaskRunnable, parseTaskFrontmatter, renderTaskFrontmatter } from "./frontmatter.js";
|
|
7
6
|
import { ticketDueMs, ticketExpired } from "./ticket.js";
|
|
8
7
|
const TASK_ID_PATTERN = /^[A-Za-z0-9._-]+$/;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
{ label: "DoD", names: ["DoD"] },
|
|
13
|
-
{ label: "Manual", names: ["Manual", "手册"] },
|
|
14
|
-
{ label: "Verification", names: ["Verification", "验收"] },
|
|
15
|
-
];
|
|
16
|
-
/**
|
|
17
|
-
* `## Plan` is a deliberately optional section (spec 037, D2) — it is not part of
|
|
18
|
-
* `STANDARD_TASK_SECTIONS`, so `missingStandardTaskSections` never flags its absence. A two-step
|
|
19
|
-
* task or any pre-existing task simply has no Plan.
|
|
20
|
-
*/
|
|
21
|
-
const PLAN_SECTION_NAMES = ["Plan", "计划"];
|
|
22
|
-
/**
|
|
23
|
-
* The single historical paragraph a v4 contract keeps (spec 051, D5). Declared here rather than
|
|
24
|
-
* in `cycle.ts` so `taskContractSegment` can end the contract at it without a circular import.
|
|
25
|
-
*/
|
|
26
|
-
export const LAST_RESULT_SECTION_NAMES = ["上次结果", "Last Result"];
|
|
8
|
+
/** `## Work Items` is deliberately optional: a two-step task or an item-less template simply has none. */
|
|
9
|
+
const ITEMS_SECTION_NAMES = ["Work Items", "工作项"];
|
|
10
|
+
const ITEMS_HEADING = "## Work Items";
|
|
27
11
|
/** Validate/normalize a task id (filename without `.md`), rejecting path traversal. */
|
|
28
12
|
export function normalizeTaskId(id) {
|
|
29
13
|
return normalizeSafeId(id, { suffix: ".md", pattern: TASK_ID_PATTERN, label: "task id" });
|
|
@@ -38,60 +22,25 @@ export function taskBody(content) {
|
|
|
38
22
|
const after = content.indexOf("\n", end + 1);
|
|
39
23
|
return after === -1 ? "" : content.slice(after + 1);
|
|
40
24
|
}
|
|
41
|
-
|
|
42
|
-
* The task's *contract* segment: the body up to (excluding) whichever of "Plan" or "上次结果"
|
|
43
|
-
* appears first — i.e. the H1 title, Goal, DoD (with its checkbox state), Manual and
|
|
44
|
-
* Verification (spec 029, D4).
|
|
45
|
-
*
|
|
46
|
-
* Verification PASS binds to this segment, not the whole body, so routine `progress` notes
|
|
47
|
-
* (Current Cycle, and — spec 037, D1 — Plan step status) never invalidate a PASS; only a change
|
|
48
|
-
* to what the task promises to do and how it is checked does.
|
|
49
|
-
* Plan is deliberately excluded from the contract even though it always precedes Current Cycle
|
|
50
|
-
* in a freshly rendered skeleton: it is the task's *means*, not its promise, and is meant to be
|
|
51
|
-
* revised without re-triggering verification. This also means a task with an existing PASS can
|
|
52
|
-
* have `## Plan` inserted between Verification and Current Cycle with the contract segment
|
|
53
|
-
* unchanged byte-for-byte, as long as nothing before it changed.
|
|
54
|
-
* A body without either heading (non-standard) falls back to the whole body.
|
|
55
|
-
*/
|
|
56
|
-
export function taskContractSegment(body) {
|
|
57
|
-
const lines = body.split("\n");
|
|
58
|
-
for (let index = 0; index < lines.length; index++) {
|
|
59
|
-
const match = /^#{1,6}\s+(.+?)\s*$/.exec(lines[index] ?? "");
|
|
60
|
-
if (match &&
|
|
61
|
-
(matchesTaskSectionTitle(match[1] ?? "", PLAN_SECTION_NAMES) ||
|
|
62
|
-
matchesTaskSectionTitle(match[1] ?? "", LAST_RESULT_SECTION_NAMES))) {
|
|
63
|
-
return lines.slice(0, index).join("\n").replace(/\s+$/, "");
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return body;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Hash the task's *contract* segment (Goal/DoD/Manual/Verification), not the whole body, so a
|
|
70
|
-
* verification PASS survives routine step logging and only breaks when the contract itself
|
|
71
|
-
* changes (spec 029, D4). Lives next to `taskContractSegment` because it is that function's
|
|
72
|
-
* only real consumer.
|
|
73
|
-
*/
|
|
74
|
-
export function taskBodyHash(body) {
|
|
75
|
-
return createHash("sha256").update(taskContractSegment(body)).digest("hex");
|
|
76
|
-
}
|
|
77
|
-
const PLAN_STEP_STATUS_BY_MARKER = {
|
|
25
|
+
const ITEM_STATUS_BY_MARKER = {
|
|
78
26
|
" ": "todo",
|
|
79
27
|
x: "done",
|
|
80
28
|
X: "done",
|
|
81
29
|
"!": "blocked",
|
|
82
30
|
"~": "dropped",
|
|
83
31
|
};
|
|
84
|
-
const
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
32
|
+
const ITEM_MARKER_BY_STATUS = { todo: " ", done: "x", blocked: "!", dropped: "~" };
|
|
33
|
+
const ITEM_CHECKBOX_LINE = /^\s*[-*]\s+\[([ xX!~])\]\s+(.*)$/;
|
|
34
|
+
const ITEM_ID_PREFIX = /^([PW]\d+)[.、)]?\s+(\S.*)$/i;
|
|
35
|
+
const ITEM_DOD_REF_SUFFIX = /(?:→|->)\s*dod:\s*([\d,\s]+)\s*$/i;
|
|
36
|
+
function parseItemLine(line, lineIndex, fallbackId) {
|
|
37
|
+
const checkbox = ITEM_CHECKBOX_LINE.exec(line);
|
|
89
38
|
if (!checkbox)
|
|
90
39
|
return undefined;
|
|
91
|
-
const status =
|
|
40
|
+
const status = ITEM_STATUS_BY_MARKER[checkbox[1] ?? " "] ?? "todo";
|
|
92
41
|
let rest = (checkbox[2] ?? "").trim();
|
|
93
42
|
let dodRefs = [];
|
|
94
|
-
const dodMatch =
|
|
43
|
+
const dodMatch = ITEM_DOD_REF_SUFFIX.exec(rest);
|
|
95
44
|
if (dodMatch) {
|
|
96
45
|
dodRefs = (dodMatch[1] ?? "")
|
|
97
46
|
.split(",")
|
|
@@ -99,116 +48,99 @@ function parsePlanStepLine(line, lineIndex, fallbackId) {
|
|
|
99
48
|
.filter((n) => Number.isInteger(n) && n > 0);
|
|
100
49
|
rest = rest.slice(0, dodMatch.index).trim();
|
|
101
50
|
}
|
|
102
|
-
const idMatch =
|
|
51
|
+
const idMatch = ITEM_ID_PREFIX.exec(rest);
|
|
103
52
|
const id = idMatch ? (idMatch[1] ?? fallbackId).toUpperCase() : fallbackId;
|
|
104
53
|
const text = idMatch ? (idMatch[2] ?? "").trim() : rest;
|
|
105
54
|
return { id, status, text, dodRefs, lineIndex };
|
|
106
55
|
}
|
|
107
56
|
/**
|
|
108
|
-
* Parse the optional `##
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
* self-reported, for the same reason `task-driver.ts`'s fingerprint excludes the model's own
|
|
114
|
-
* progress notes — a runtime-derived signal cannot be talked into lying about itself.
|
|
57
|
+
* Parse the optional `## Work Items` section: the leader's hand-maintained list of independently
|
|
58
|
+
* deliverable pieces of the project. Four checkbox states — `[ ]` todo, `[x]` done, `[!]`
|
|
59
|
+
* blocked, `[~]` dropped — and no separate "doing" marker: the current item is *derived* (first
|
|
60
|
+
* `todo`/`blocked` in document order), not self-reported. The runtime never ticks an item itself
|
|
61
|
+
* (spec 052, D4): "the delegate says it is done" and "the leader checked it" are different facts.
|
|
115
62
|
*
|
|
116
|
-
* Returns `undefined` when there is no
|
|
117
|
-
* it (nothing to summarize) — both read the same as "this task has no Plan yet".
|
|
63
|
+
* Returns `undefined` when there is no such heading, or it has no checkbox lines under it.
|
|
118
64
|
*/
|
|
119
|
-
export function
|
|
65
|
+
export function parseTaskItems(content) {
|
|
120
66
|
const lines = content.split("\n");
|
|
121
|
-
const bounds = findTaskSectionBounds(lines,
|
|
67
|
+
const bounds = findTaskSectionBounds(lines, ITEMS_SECTION_NAMES);
|
|
122
68
|
if (!bounds)
|
|
123
69
|
return undefined;
|
|
124
|
-
const
|
|
70
|
+
const items = [];
|
|
125
71
|
let position = 0;
|
|
126
72
|
for (let index = bounds.headingIndex + 1; index < bounds.end; index++) {
|
|
127
73
|
const line = lines[index] ?? "";
|
|
128
74
|
if (!/^\s*[-*]\s+\[/.test(line))
|
|
129
75
|
continue;
|
|
130
76
|
position++;
|
|
131
|
-
const
|
|
132
|
-
if (
|
|
133
|
-
|
|
77
|
+
const item = parseItemLine(line, index, `W${position}`);
|
|
78
|
+
if (item)
|
|
79
|
+
items.push(item);
|
|
134
80
|
}
|
|
135
|
-
if (
|
|
81
|
+
if (items.length === 0)
|
|
136
82
|
return undefined;
|
|
137
83
|
return {
|
|
138
|
-
|
|
139
|
-
total:
|
|
140
|
-
done:
|
|
141
|
-
current:
|
|
84
|
+
items,
|
|
85
|
+
total: items.filter((item) => item.status !== "dropped").length,
|
|
86
|
+
done: items.filter((item) => item.status === "done").length,
|
|
87
|
+
current: items.find((item) => item.status === "todo" || item.status === "blocked"),
|
|
142
88
|
};
|
|
143
89
|
}
|
|
144
|
-
|
|
145
|
-
function renderPlanStepLine(id, status, text, dodRefs = []) {
|
|
90
|
+
function renderItemLine(id, status, text, dodRefs = []) {
|
|
146
91
|
const suffix = dodRefs.length > 0 ? ` → dod:${dodRefs.join(",")}` : "";
|
|
147
|
-
return `- [${
|
|
92
|
+
return `- [${ITEM_MARKER_BY_STATUS[status]}] ${id} ${text}${suffix}`;
|
|
148
93
|
}
|
|
149
|
-
/**
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
* anchor; a task with neither section simply gets its Plan appended rather than being rejected.
|
|
153
|
-
*/
|
|
154
|
-
function insertEmptyPlanSection(body) {
|
|
155
|
-
const lines = body.split("\n");
|
|
156
|
-
for (let index = 0; index < lines.length; index++) {
|
|
157
|
-
const match = /^(#{1,6})\s+(.+?)\s*$/.exec(lines[index] ?? "");
|
|
158
|
-
if (match && matchesTaskSectionTitle(match[2] ?? "", LAST_RESULT_SECTION_NAMES)) {
|
|
159
|
-
lines.splice(index, 0, "## Plan", "");
|
|
160
|
-
return lines.join("\n");
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
return `${body.replace(/\n+$/, "")}\n\n## Plan\n`;
|
|
94
|
+
/** Append an empty `## Work Items` heading at the end of the contract. */
|
|
95
|
+
function appendEmptyItemsSection(body) {
|
|
96
|
+
return `${body.replace(/\n+$/, "")}\n\n${ITEMS_HEADING}\n`;
|
|
164
97
|
}
|
|
165
98
|
/**
|
|
166
|
-
* Update or append
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
* The returned `summary` is deliberately not a new persisted field (see the file-level doc on
|
|
173
|
-
* `TaskPlanSummary`): it is meant to be appended to the caller's own Current Cycle note, so the
|
|
174
|
-
* change history rides on the log `startTaskCycle` already folds into History — no second,
|
|
175
|
-
* unconsumed revision counter.
|
|
99
|
+
* Update or append Work Items by id. An id that already exists gets its status/text patched in
|
|
100
|
+
* place, preserving its `dod` refs and position; an unseen id is appended as a new item (`text`
|
|
101
|
+
* is then required — there is nothing sensible to append otherwise). A task with no section yet
|
|
102
|
+
* gets an empty one first, so the very first `items` call on a task is also the one that creates
|
|
103
|
+
* its list.
|
|
176
104
|
*/
|
|
177
|
-
export function
|
|
105
|
+
export function applyTaskItemsPatch(body, patches) {
|
|
178
106
|
if (patches.length === 0)
|
|
179
107
|
return { body, summary: "" };
|
|
180
|
-
let working =
|
|
108
|
+
let working = parseTaskItems(body) ? body : appendEmptyItemsSection(body);
|
|
181
109
|
const deltas = [];
|
|
182
110
|
for (const patch of patches) {
|
|
183
111
|
const trimmedId = patch.id.trim();
|
|
184
112
|
if (!trimmedId)
|
|
185
|
-
throw new RecoverableToolError("
|
|
186
|
-
const existing =
|
|
113
|
+
throw new RecoverableToolError("An items entry's id must not be empty.");
|
|
114
|
+
const existing = parseTaskItems(working)?.items.find((item) => item.id.toUpperCase() === trimmedId.toUpperCase());
|
|
187
115
|
if (existing) {
|
|
188
116
|
const lines = working.split("\n");
|
|
189
117
|
const nextStatus = patch.status ?? existing.status;
|
|
190
118
|
const nextText = patch.text?.trim() || existing.text;
|
|
191
|
-
lines[existing.lineIndex] =
|
|
119
|
+
lines[existing.lineIndex] = renderItemLine(existing.id, nextStatus, nextText, existing.dodRefs);
|
|
192
120
|
working = lines.join("\n");
|
|
193
121
|
deltas.push(patch.status ? `${existing.id}→${patch.status}` : `${existing.id} updated`);
|
|
194
122
|
continue;
|
|
195
123
|
}
|
|
196
124
|
const text = patch.text?.trim();
|
|
197
125
|
if (!text) {
|
|
198
|
-
throw new RecoverableToolError(`
|
|
126
|
+
throw new RecoverableToolError(`Work item "${trimmedId}" does not exist yet; adding a new item requires text.`);
|
|
199
127
|
}
|
|
200
128
|
const id = trimmedId.toUpperCase();
|
|
201
129
|
const lines = working.split("\n");
|
|
202
|
-
const bounds = findTaskSectionBounds(lines,
|
|
130
|
+
const bounds = findTaskSectionBounds(lines, ITEMS_SECTION_NAMES);
|
|
203
131
|
let insertAt = bounds?.end ?? lines.length;
|
|
204
132
|
const afterHeading = (bounds?.headingIndex ?? -1) + 1;
|
|
205
133
|
while (insertAt > afterHeading && (lines[insertAt - 1] ?? "").trim() === "")
|
|
206
134
|
insertAt--;
|
|
207
|
-
lines.splice(insertAt, 0,
|
|
135
|
+
lines.splice(insertAt, 0, renderItemLine(id, patch.status ?? "todo", text));
|
|
208
136
|
working = lines.join("\n");
|
|
209
137
|
deltas.push(`+${id} ${text}`);
|
|
210
138
|
}
|
|
211
|
-
return { body: working, summary: deltas.length > 0 ? `
|
|
139
|
+
return { body: working, summary: deltas.length > 0 ? `items: ${deltas.join("; ")}` : "" };
|
|
140
|
+
}
|
|
141
|
+
/** Whether `id` names an existing Work Item of the task body (case-insensitive). */
|
|
142
|
+
export function findTaskItem(body, id) {
|
|
143
|
+
return parseTaskItems(body)?.items.find((item) => item.id.toUpperCase() === id.trim().toUpperCase());
|
|
212
144
|
}
|
|
213
145
|
/** First `# ` heading after the frontmatter block, or the id when there is none. */
|
|
214
146
|
export function extractTaskTitle(content, fallbackId) {
|
|
@@ -232,7 +164,7 @@ export function matchesTaskSectionTitle(title, names) {
|
|
|
232
164
|
/**
|
|
233
165
|
* Find the first heading matching one of `names` and the exclusive end of its body — the next
|
|
234
166
|
* heading at the same or a shallower level, or end of document. Every task-document section scan
|
|
235
|
-
* (
|
|
167
|
+
* (Work Items, DoD) shares this exact rule; only what a caller does with
|
|
236
168
|
* the bounds differs.
|
|
237
169
|
*/
|
|
238
170
|
export function findTaskSectionBounds(lines, names) {
|
|
@@ -256,8 +188,7 @@ export function findTaskSectionBounds(lines, names) {
|
|
|
256
188
|
/**
|
|
257
189
|
* For every line, which of `sections` (each a label plus its heading aliases) it falls under,
|
|
258
190
|
* using the same heading-scoping rule as {@link findTaskSectionBounds}. A heading line itself is
|
|
259
|
-
* never "in" a section.
|
|
260
|
-
* lives in exactly one place.
|
|
191
|
+
* never "in" a section.
|
|
261
192
|
*/
|
|
262
193
|
function classifyTaskSectionLines(lines, sections) {
|
|
263
194
|
const result = new Array(lines.length);
|
|
@@ -281,85 +212,46 @@ function classifyTaskSectionLines(lines, sections) {
|
|
|
281
212
|
}
|
|
282
213
|
return result;
|
|
283
214
|
}
|
|
284
|
-
|
|
285
|
-
return content.split("\n").some((line) => {
|
|
286
|
-
const match = /^#{1,6}\s+(.+?)\s*$/.exec(line);
|
|
287
|
-
return match ? matchesTaskSectionTitle(match[1] ?? "", names) : false;
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
export function missingStandardTaskSections(content) {
|
|
291
|
-
return STANDARD_TASK_SECTIONS.filter((section) => !hasTaskHeading(content, section.names)).map((section) => section.label);
|
|
292
|
-
}
|
|
215
|
+
const DOD_SECTION = [{ label: "DoD", names: ["DoD"] }];
|
|
293
216
|
/**
|
|
294
|
-
* Unchecked Markdown acceptance boxes under the DoD section, plus a synthetic
|
|
295
|
-
*
|
|
217
|
+
* Unchecked Markdown acceptance boxes under the DoD section, plus a synthetic entry when DoD has
|
|
218
|
+
* content but no checkbox syntax at all.
|
|
296
219
|
*
|
|
297
|
-
* Without the "no checklist items" case, a DoD written as prose or a numbered
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
* `task_close outcome=complete` through with nothing ever actually verified.
|
|
220
|
+
* Without the "no checklist items" case, a DoD written as prose or a numbered list (no `- [ ]`
|
|
221
|
+
* anywhere) makes this function return an empty array — indistinguishable from "everything is
|
|
222
|
+
* checked" — which would silently let a task close with nothing ever actually checked.
|
|
301
223
|
*/
|
|
302
|
-
const DOD_VERIFICATION_SECTIONS = [
|
|
303
|
-
{ label: "DoD", names: ["DoD"] },
|
|
304
|
-
{ label: "Verification", names: ["Verification", "验收"] },
|
|
305
|
-
];
|
|
306
224
|
export function uncheckedTaskAcceptanceItems(content) {
|
|
307
225
|
const unchecked = [];
|
|
308
226
|
const lines = content.split("\n");
|
|
309
|
-
const sectionOf = classifyTaskSectionLines(lines,
|
|
227
|
+
const sectionOf = classifyTaskSectionLines(lines, DOD_SECTION);
|
|
310
228
|
let dodHasContent = false;
|
|
311
229
|
let dodHasCheckbox = false;
|
|
312
230
|
for (let index = 0; index < lines.length; index++) {
|
|
313
|
-
|
|
314
|
-
if (!section)
|
|
231
|
+
if (!sectionOf[index])
|
|
315
232
|
continue;
|
|
316
233
|
const line = lines[index] ?? "";
|
|
317
|
-
if (
|
|
234
|
+
if (line.trim())
|
|
318
235
|
dodHasContent = true;
|
|
319
236
|
const checkbox = /^\s*[-*]\s+\[([ xX])\]\s*(.+?)\s*$/.exec(line);
|
|
320
237
|
if (checkbox) {
|
|
321
|
-
|
|
322
|
-
dodHasCheckbox = true;
|
|
238
|
+
dodHasCheckbox = true;
|
|
323
239
|
if (checkbox[1] === " ")
|
|
324
|
-
unchecked.push(
|
|
240
|
+
unchecked.push(`DoD: ${checkbox[2]}`);
|
|
325
241
|
}
|
|
326
242
|
}
|
|
327
243
|
if (dodHasContent && !dodHasCheckbox) {
|
|
328
|
-
unchecked.push('DoD has no checklist items — rewrite it as "- [ ] ..." acceptance items before
|
|
244
|
+
unchecked.push('DoD has no checklist items — rewrite it as "- [ ] ..." acceptance items before finishing.');
|
|
329
245
|
}
|
|
330
246
|
return unchecked;
|
|
331
247
|
}
|
|
332
248
|
/**
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
|
|
336
|
-
export function countTaskDodItems(content) {
|
|
337
|
-
const lines = content.split("\n");
|
|
338
|
-
const sectionOf = classifyTaskSectionLines(lines, [{ label: "DoD", names: ["DoD"] }]);
|
|
339
|
-
let count = 0;
|
|
340
|
-
for (let index = 0; index < lines.length; index++) {
|
|
341
|
-
if (sectionOf[index] === "DoD" && /^\s*[-*]\s+\[[ xX]\]/.test(lines[index] ?? ""))
|
|
342
|
-
count++;
|
|
343
|
-
}
|
|
344
|
-
return count;
|
|
345
|
-
}
|
|
346
|
-
/** A plain plan-step line gets an auto-assigned `P<n>` id unless it already starts with one. */
|
|
347
|
-
function ensurePlanStepId(line, fallbackIndex) {
|
|
348
|
-
return PLAN_STEP_ID_PREFIX.test(line) ? line : `P${fallbackIndex} ${line}`;
|
|
349
|
-
}
|
|
350
|
-
/**
|
|
351
|
-
* The v4 task skeleton: contract only (spec 051, D5). `## Current Cycle` and `## History` are
|
|
352
|
-
* gone — the per-step record lives in `<id>.jsonl`, and the one paragraph the contract keeps
|
|
353
|
-
* (`## 上次结果`) is written by the cycle-close path, not by the skeleton.
|
|
249
|
+
* The task skeleton: Goal, DoD and (optionally) Work Items (spec 052, §3.4). The runtime never
|
|
250
|
+
* rewrites the body afterwards, so there is no history section here — the per-step record lives
|
|
251
|
+
* in `<id>.jsonl`.
|
|
354
252
|
*/
|
|
355
253
|
export function renderStandardTaskBody(input) {
|
|
356
|
-
const
|
|
357
|
-
const verificationPlan = input.verificationPlan?.trim() ||
|
|
358
|
-
"- Check every DoD item against concrete evidence.\n- Run the relevant deterministic checks before declaring PASS.";
|
|
359
|
-
const planLines = (input.plan ?? "")
|
|
360
|
-
.split("\n")
|
|
361
|
-
.map((line) => line.trim())
|
|
362
|
-
.filter(Boolean);
|
|
254
|
+
const itemLines = (input.items ?? []).map((item) => item.text.trim()).filter(Boolean);
|
|
363
255
|
return [
|
|
364
256
|
`# ${input.title}`,
|
|
365
257
|
"",
|
|
@@ -369,52 +261,15 @@ export function renderStandardTaskBody(input) {
|
|
|
369
261
|
"## DoD",
|
|
370
262
|
input.dod,
|
|
371
263
|
"",
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
"",
|
|
375
|
-
"## Verification",
|
|
376
|
-
// Only stated when it constrains closing the task; an unverified task says nothing
|
|
377
|
-
// rather than advertising a second, weaker mode (spec 036, D5).
|
|
378
|
-
...(input.verificationRequired ? ["Independent verification: required"] : []),
|
|
379
|
-
verificationPlan,
|
|
380
|
-
"",
|
|
381
|
-
// Plan is optional (spec 037, D2/D3): omitted entirely when create was not given one,
|
|
382
|
-
// rather than rendering an empty section a doctor check would then have to special-case.
|
|
383
|
-
...(planLines.length > 0
|
|
384
|
-
? ["## Plan", ...planLines.map((line, index) => `- [ ] ${ensurePlanStepId(line, index + 1)}`), ""]
|
|
264
|
+
...(itemLines.length > 0
|
|
265
|
+
? [ITEMS_HEADING, ...itemLines.map((text, index) => renderItemLine(`W${index + 1}`, "todo", text)), ""]
|
|
385
266
|
: []),
|
|
386
267
|
].join("\n");
|
|
387
268
|
}
|
|
388
|
-
/** Serialize a task document:
|
|
269
|
+
/** Serialize a task document: frontmatter block plus the body, unchanged. */
|
|
389
270
|
export function renderTaskDocument(fields, rawBody) {
|
|
390
271
|
return `${renderTaskFrontmatter(fields)}\n${rawBody}`;
|
|
391
272
|
}
|
|
392
|
-
/**
|
|
393
|
-
* Reset a recurring task's per-cycle checkboxes: DoD/Verification acceptance items and Plan
|
|
394
|
-
* steps both go back to unchecked, so cycle N+1 can never pass its acceptance gate on cycle N's
|
|
395
|
-
* evidence. `[~]` dropped plan steps are left alone — that step was deliberately abandoned, not
|
|
396
|
-
* merely finished, and a new cycle should not resurrect it.
|
|
397
|
-
*/
|
|
398
|
-
export function resetTaskPlanForCycle(body) {
|
|
399
|
-
const lines = body.split("\n");
|
|
400
|
-
const sectionOf = classifyTaskSectionLines(lines, DOD_VERIFICATION_SECTIONS);
|
|
401
|
-
for (let index = 0; index < lines.length; index++) {
|
|
402
|
-
if (!sectionOf[index])
|
|
403
|
-
continue;
|
|
404
|
-
const checkbox = /^(\s*[-*]\s+)\[[xX]\](\s*.*)$/.exec(lines[index] ?? "");
|
|
405
|
-
if (checkbox)
|
|
406
|
-
lines[index] = `${checkbox[1]}[ ]${checkbox[2]}`;
|
|
407
|
-
}
|
|
408
|
-
const bounds = findTaskSectionBounds(lines, PLAN_SECTION_NAMES);
|
|
409
|
-
if (bounds) {
|
|
410
|
-
for (let index = bounds.headingIndex + 1; index < bounds.end; index++) {
|
|
411
|
-
const checkbox = /^(\s*[-*]\s+)\[[xX!]\](\s*.*)$/.exec(lines[index] ?? "");
|
|
412
|
-
if (checkbox)
|
|
413
|
-
lines[index] = `${checkbox[1]}[ ]${checkbox[2]}`;
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
return lines.join("\n");
|
|
417
|
-
}
|
|
418
273
|
/**
|
|
419
274
|
* Runnable first; then a parked task whose backstop already expired (the runtime owes it a
|
|
420
275
|
* reopen); then earliest due ticket; then id. Sorting expired parks ahead of ordinary parks is
|
|
@@ -434,14 +289,14 @@ export function compareTaskEntries(a, b) {
|
|
|
434
289
|
return a.id.localeCompare(b.id);
|
|
435
290
|
}
|
|
436
291
|
function toEntry(id, content) {
|
|
437
|
-
const parsed =
|
|
292
|
+
const parsed = parseTaskFrontmatter(content);
|
|
438
293
|
return {
|
|
439
294
|
id,
|
|
440
295
|
title: extractTaskTitle(content, id),
|
|
441
296
|
fields: parsed.fields,
|
|
442
297
|
readable: parsed.readable,
|
|
443
298
|
legacy: parsed.legacy,
|
|
444
|
-
|
|
299
|
+
items: parseTaskItems(content),
|
|
445
300
|
};
|
|
446
301
|
}
|
|
447
302
|
/** The clock-dependent half of an entry, recomputed on every read (never cached). */
|
|
@@ -450,7 +305,7 @@ function withClock(entry, now) {
|
|
|
450
305
|
const ticket = entry.fields.ticket;
|
|
451
306
|
return {
|
|
452
307
|
...entry,
|
|
453
|
-
runnable: isTaskRunnable(entry.fields),
|
|
308
|
+
runnable: isTaskRunnable(entry.fields) && !entry.legacy,
|
|
454
309
|
dueMs: ticket ? ticketDueMs(ticket) : undefined,
|
|
455
310
|
expired: ticket !== undefined && !entry.fields.paused && ticketExpired(ticket, nowDate),
|
|
456
311
|
};
|
package/dist/tasks/log.d.ts
CHANGED
|
@@ -4,57 +4,87 @@
|
|
|
4
4
|
* v3 kept this history inline in the task file under `## History`, capped at 24 KB / 8 entries.
|
|
5
5
|
* Both long-lived tasks on the author's machine sat permanently *at* that cap: 79% of a 30 KB
|
|
6
6
|
* task file was closed cycles the model re-read on every single wake and never acted on. Moving
|
|
7
|
-
* it here keeps the contract small enough to inject whole (INV-6) while making the history
|
|
8
|
-
*
|
|
7
|
+
* it here keeps the contract small enough to inject whole (INV-6) while making the history much
|
|
8
|
+
* longer before anything is folded away: the log rotates at `MAX_LOG_BYTES` and keeps two rotated
|
|
9
|
+
* backups (`.1`, `.2`) alongside the current file — bounded retention, not an accidental cap.
|
|
10
|
+
* `readTaskLog`/`archiveTask` must enumerate all three; reading or archiving only the current
|
|
11
|
+
* file silently drops whatever had already rotated out of it (R9).
|
|
9
12
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
13
|
+
* Spec 052 adds `dispatch` / `settle` records: the run and job managers write them when work is
|
|
14
|
+
* bound to the task and when it settles, so the task keeps the outcome of every delegation long
|
|
15
|
+
* after the run record itself has been garbage-collected (INV-5). The step brief renders them as
|
|
16
|
+
* the `<task_board>`. The log is append-only and is never rewritten.
|
|
12
17
|
*/
|
|
13
|
-
export type TaskStepOutcome = "continue" | "park" | "done"
|
|
18
|
+
export type TaskStepOutcome = "continue" | "park" | "done";
|
|
14
19
|
export interface TaskStepRecord {
|
|
15
20
|
ts: string;
|
|
16
|
-
cycle: string;
|
|
17
21
|
kind: "step";
|
|
18
22
|
seq: number;
|
|
19
23
|
outcome: TaskStepOutcome;
|
|
20
24
|
note: string;
|
|
21
25
|
tools: string[];
|
|
26
|
+
/** What this step sent the user, when it sent anything. Kept so the next occurrence knows what was delivered. */
|
|
27
|
+
report?: string;
|
|
22
28
|
usd?: number;
|
|
23
29
|
usdEstimated?: boolean;
|
|
24
30
|
units?: number;
|
|
25
31
|
}
|
|
26
|
-
|
|
32
|
+
/** A delegation or background job was bound to this task (spec 052, D4). `ref` is a run or job id. */
|
|
33
|
+
export interface TaskDispatchRecord {
|
|
27
34
|
ts: string;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
kind: "dispatch";
|
|
36
|
+
ref: string;
|
|
37
|
+
/** The Work Items id this dispatch was for, when the leader named one. */
|
|
38
|
+
item?: string;
|
|
39
|
+
/** The role (delegation) or the command (job), for the board. */
|
|
40
|
+
agent?: string;
|
|
41
|
+
purpose?: "work" | "verify";
|
|
42
|
+
label?: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The bound delegation or job settled. Written by the run/job manager at settlement, so the
|
|
46
|
+
* task keeps the outcome after the run record itself has been garbage-collected (INV-5).
|
|
47
|
+
*/
|
|
48
|
+
export interface TaskSettleRecord {
|
|
49
|
+
ts: string;
|
|
50
|
+
kind: "settle";
|
|
51
|
+
ref: string;
|
|
52
|
+
item?: string;
|
|
53
|
+
status: string;
|
|
54
|
+
/** `purpose=verify` runs only: the checker's declared verdict. */
|
|
55
|
+
verdict?: "pass" | "fail";
|
|
56
|
+
usd?: number;
|
|
57
|
+
usdEstimated?: boolean;
|
|
58
|
+
/** Where the full output lives (a run's `output.md`, a job's output file). */
|
|
59
|
+
output?: string;
|
|
60
|
+
/** The output's tail, as the completion wake shows it. Untrusted executor text, not instructions. */
|
|
61
|
+
tail?: string;
|
|
62
|
+
/** A run's working directory afterwards (`git status --porcelain`), as the completion wake shows it. */
|
|
63
|
+
changed?: string;
|
|
64
|
+
exitCode?: number;
|
|
65
|
+
durationMs?: number;
|
|
37
66
|
}
|
|
38
67
|
export interface TaskExpiredRecord {
|
|
39
68
|
ts: string;
|
|
40
|
-
cycle: string;
|
|
41
69
|
kind: "expired";
|
|
42
70
|
ticket: string;
|
|
43
71
|
action: "reopened" | "paused";
|
|
44
72
|
}
|
|
45
73
|
export interface TaskCloseRecord {
|
|
46
74
|
ts: string;
|
|
47
|
-
cycle: string;
|
|
48
75
|
kind: "close";
|
|
49
76
|
outcome: "done" | "cancelled";
|
|
50
|
-
|
|
51
|
-
evidence?: string;
|
|
52
|
-
residualRisk?: string;
|
|
77
|
+
note: string;
|
|
53
78
|
steps: number;
|
|
54
|
-
rounds: number;
|
|
55
79
|
usd: number;
|
|
56
80
|
}
|
|
57
|
-
|
|
81
|
+
/** Written only by the v3 → v5 conversion, to explain a decision it made about this task. */
|
|
82
|
+
export interface TaskNoteRecord {
|
|
83
|
+
ts: string;
|
|
84
|
+
kind: "note";
|
|
85
|
+
note: string;
|
|
86
|
+
}
|
|
87
|
+
export type TaskLogRecord = TaskStepRecord | TaskDispatchRecord | TaskSettleRecord | TaskExpiredRecord | TaskCloseRecord | TaskNoteRecord;
|
|
58
88
|
export declare function taskLogPath(channelDir: string, id: string): string;
|
|
59
89
|
/** Where `archiveTask` moves a closed task's `.jsonl`. */
|
|
60
90
|
export declare function taskArchiveLogPath(channelDir: string, id: string): string;
|
|
@@ -62,23 +92,15 @@ export declare function taskArchiveLogPath(channelDir: string, id: string): stri
|
|
|
62
92
|
export declare function taskLogIsArchived(channelDir: string, id: string): boolean;
|
|
63
93
|
/** Test seam: drop cached appenders so a temp-dir fixture does not leak into the next case. */
|
|
64
94
|
export declare function resetTaskLogAppenders(): Promise<void>;
|
|
65
|
-
export type TaskLogInput =
|
|
66
|
-
ts?: string;
|
|
67
|
-
}) | (Omit<TaskRoundRecord, "ts"> & {
|
|
68
|
-
ts?: string;
|
|
69
|
-
}) | (Omit<TaskExpiredRecord, "ts"> & {
|
|
70
|
-
ts?: string;
|
|
71
|
-
}) | (Omit<TaskCloseRecord, "ts"> & {
|
|
72
|
-
ts?: string;
|
|
73
|
-
});
|
|
95
|
+
export type TaskLogInput = Omit<TaskStepRecord, "ts"> | Omit<TaskDispatchRecord, "ts"> | Omit<TaskSettleRecord, "ts"> | Omit<TaskExpiredRecord, "ts"> | Omit<TaskCloseRecord, "ts"> | Omit<TaskNoteRecord, "ts">;
|
|
74
96
|
/**
|
|
75
97
|
* Append one record. `appendStrict` rather than `append`: the loop log is the only durable trace
|
|
76
98
|
* of what a step did, so a dropped record would make the next brief lie about the task's history.
|
|
77
99
|
*/
|
|
78
|
-
export declare function appendTaskLog(channelDir: string, id: string, record: TaskLogInput
|
|
100
|
+
export declare function appendTaskLog(channelDir: string, id: string, record: TaskLogInput & {
|
|
101
|
+
ts?: string;
|
|
102
|
+
}): Promise<void>;
|
|
79
103
|
export interface ReadTaskLogOptions {
|
|
80
|
-
/** Only records from this cycle. */
|
|
81
|
-
cycle?: string;
|
|
82
104
|
/** Keep at most this many, counted from the end (the most recent). */
|
|
83
105
|
limit?: number;
|
|
84
106
|
kinds?: readonly TaskLogRecord["kind"][];
|
|
@@ -86,6 +108,11 @@ export interface ReadTaskLogOptions {
|
|
|
86
108
|
/**
|
|
87
109
|
* Read the log back, newest-last. Unparseable lines are skipped rather than failing the read: a
|
|
88
110
|
* hand-edited or half-written line must not make a task's whole history unreadable.
|
|
111
|
+
*
|
|
112
|
+
* Reads every existing rotated shard (R9), not just the current file — `MAX_LOG_BYTES` rotation
|
|
113
|
+
* moves older records into `.1`/`.2` behind the caller's back, and a read that only looked at the
|
|
114
|
+
* current file made rotated-out history invisible to `task_log`, briefs, and and the board
|
|
115
|
+
* alike even though it was still on disk.
|
|
89
116
|
*/
|
|
90
117
|
export declare function readTaskLog(channelDir: string, id: string, options?: ReadTaskLogOptions): Promise<TaskLogRecord[]>;
|
|
91
118
|
/** One line per record, for the step brief and `/tasks show`. */
|