@oyasmi/pipiclaw 0.7.7 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -2
- package/dist/agent/channel-runner.d.ts +4 -4
- package/dist/agent/channel-runner.js +25 -23
- package/dist/agent/commands.js +7 -2
- package/dist/agent/job-manager.d.ts +5 -5
- package/dist/agent/prompt-builder.d.ts +3 -13
- package/dist/agent/prompt-builder.js +49 -159
- package/dist/agent/run-queue.js +2 -1
- package/dist/agent/runner-factory.d.ts +1 -2
- package/dist/agent/runner-factory.js +2 -2
- package/dist/agent/status-render.d.ts +0 -7
- package/dist/agent/status-render.js +8 -3
- package/dist/agent/types.d.ts +2 -0
- package/dist/agent/workspace-resources.d.ts +1 -1
- package/dist/agent/workspace-resources.js +3 -15
- package/dist/executor.d.ts +20 -0
- package/dist/{sandbox.js → executor.js} +3 -95
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/log.d.ts +1 -1
- package/dist/log.js +1 -2
- package/dist/memory/files.js +0 -0
- package/dist/memory/lifecycle.js +6 -5
- package/dist/memory/maintenance-jobs.d.ts +0 -1
- package/dist/memory/maintenance-jobs.js +2 -2
- package/dist/memory/maintenance-state.js +2 -1
- package/dist/memory/post-turn-review.d.ts +0 -1
- package/dist/memory/post-turn-review.js +4 -4
- package/dist/memory/scheduler.d.ts +0 -1
- package/dist/memory/scheduler.js +2 -2
- package/dist/memory/session.js +2 -2
- package/dist/memory/task-digest.js +17 -0
- package/dist/paths.d.ts +2 -0
- package/dist/paths.js +11 -0
- package/dist/playbooks/catalog.d.ts +9 -0
- package/dist/playbooks/catalog.js +44 -0
- package/dist/playbooks/event-scheduling.md +43 -0
- package/dist/playbooks/memory-and-learning.md +45 -0
- package/dist/playbooks/runtime-orientation.md +48 -0
- package/dist/playbooks/task-closeout.md +45 -0
- package/dist/playbooks/task-delegation.md +44 -0
- package/dist/playbooks/task-driving.md +43 -0
- package/dist/playbooks/task-planning.md +47 -0
- package/dist/playbooks/task-recurring.md +42 -0
- package/dist/playbooks/task-repair.md +43 -0
- package/dist/runtime/bootstrap.d.ts +12 -11
- package/dist/runtime/bootstrap.js +81 -57
- package/dist/runtime/delivery.js +4 -3
- package/dist/runtime/dingtalk.d.ts +2 -0
- package/dist/runtime/dingtalk.js +15 -14
- package/dist/runtime/durable-dispatch.d.ts +30 -0
- package/dist/runtime/durable-dispatch.js +172 -0
- package/dist/runtime/event-commands.js +4 -4
- package/dist/runtime/events.d.ts +5 -3
- package/dist/runtime/events.js +17 -13
- package/dist/runtime/task-commands.d.ts +6 -0
- package/dist/runtime/task-commands.js +292 -6
- package/dist/runtime/task-driver.d.ts +32 -0
- package/dist/runtime/task-driver.js +268 -0
- package/dist/security/config.js +2 -1
- package/dist/security/network.js +9 -2
- package/dist/security/path-guard.js +12 -24
- package/dist/security/types.d.ts +0 -1
- package/dist/settings.d.ts +12 -0
- package/dist/settings.js +30 -0
- package/dist/shared/jsonl-appender.js +2 -1
- package/dist/shared/task-ledger.d.ts +35 -0
- package/dist/shared/task-ledger.js +229 -15
- package/dist/shared/text-utils.d.ts +1 -0
- package/dist/shared/text-utils.js +3 -0
- package/dist/subagents/discovery.js +3 -2
- package/dist/subagents/tool.d.ts +15 -3
- package/dist/subagents/tool.js +194 -17
- package/dist/tasks/artifact-subject.d.ts +6 -0
- package/dist/tasks/artifact-subject.js +29 -0
- package/dist/tasks/control.d.ts +83 -0
- package/dist/tasks/control.js +293 -0
- package/dist/tasks/store.d.ts +32 -0
- package/dist/tasks/store.js +142 -0
- package/dist/tasks/verification.d.ts +23 -0
- package/dist/tasks/verification.js +69 -0
- package/dist/tools/bash.d.ts +1 -1
- package/dist/tools/bash.js +3 -5
- package/dist/tools/command-optimizer.d.ts +1 -1
- package/dist/tools/command-optimizer.js +4 -6
- package/dist/tools/config.js +4 -3
- package/dist/tools/edit.d.ts +1 -1
- package/dist/tools/edit.js +0 -0
- package/dist/tools/event-manage.d.ts +0 -1
- package/dist/tools/event-manage.js +9 -14
- package/dist/tools/grep.d.ts +1 -1
- package/dist/tools/grep.js +4 -6
- package/dist/tools/index.d.ts +1 -3
- package/dist/tools/index.js +1 -4
- package/dist/tools/read.d.ts +1 -1
- package/dist/tools/read.js +1 -2
- package/dist/tools/registry.d.ts +2 -3
- package/dist/tools/registry.js +5 -11
- package/dist/tools/skill-manage.d.ts +0 -1
- package/dist/tools/skill-manage.js +7 -14
- package/dist/tools/task-manage.d.ts +37 -4
- package/dist/tools/task-manage.js +398 -39
- package/dist/tools/write-content.d.ts +1 -1
- package/dist/tools/write-content.js +0 -1
- package/dist/tools/write.d.ts +1 -1
- package/dist/tui/app.d.ts +0 -2
- package/dist/tui/app.js +12 -7
- package/dist/tui/cli.d.ts +0 -2
- package/dist/tui/cli.js +3 -25
- package/dist/tui/turn-controller.d.ts +7 -3
- package/dist/tui/turn-controller.js +9 -6
- package/dist/web/client.js +2 -1
- package/package.json +2 -2
- package/dist/sandbox.d.ts +0 -42
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { readdir, readFile } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
|
|
3
|
+
import { parseTaskControl, taskPriorityRank } from "../tasks/control.js";
|
|
4
|
+
const FRONTMATTER_FIELDS = ["status", "wake", "recurrence", "control"];
|
|
4
5
|
const TASK_ID_PATTERN = /^[A-Za-z0-9._-]+$/;
|
|
5
6
|
export const DEFAULT_TASK_MANUAL = "- Follow the DoD, keep the current cycle log updated, and schedule check-ins when waiting.";
|
|
6
7
|
export const STANDARD_TASK_SECTIONS = [
|
|
7
8
|
{ label: "Goal", names: ["Goal", "目标"] },
|
|
8
9
|
{ label: "DoD", names: ["DoD"] },
|
|
9
10
|
{ label: "Manual", names: ["Manual", "手册"] },
|
|
11
|
+
{ label: "Verification", names: ["Verification", "验收"] },
|
|
10
12
|
{ label: "Current Cycle", names: ["Current Cycle", "当前周期"] },
|
|
11
13
|
{ label: "History", names: ["History", "历史"] },
|
|
12
14
|
];
|
|
@@ -45,7 +47,23 @@ export function parseTaskFrontmatter(content) {
|
|
|
45
47
|
const key = line.slice(0, idx).trim();
|
|
46
48
|
if (FRONTMATTER_FIELDS.includes(key)) {
|
|
47
49
|
const value = line.slice(idx + 1).trim();
|
|
48
|
-
|
|
50
|
+
if (key === "control") {
|
|
51
|
+
if (!value) {
|
|
52
|
+
frontmatter.controlReadable = false;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
try {
|
|
56
|
+
frontmatter.control = parseTaskControl(value);
|
|
57
|
+
frontmatter.controlReadable = true;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
frontmatter.controlReadable = false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
frontmatter[key] = value || undefined;
|
|
66
|
+
}
|
|
49
67
|
}
|
|
50
68
|
}
|
|
51
69
|
return frontmatter;
|
|
@@ -58,13 +76,17 @@ export function parseTaskFrontmatter(content) {
|
|
|
58
76
|
export function isTaskActionable(frontmatter, now) {
|
|
59
77
|
if (!frontmatter.readable)
|
|
60
78
|
return true;
|
|
61
|
-
if (frontmatter.
|
|
79
|
+
if (frontmatter.controlReadable === false)
|
|
80
|
+
return true;
|
|
81
|
+
if (frontmatter.status === "done" ||
|
|
82
|
+
frontmatter.status === "cancelled" ||
|
|
83
|
+
frontmatter.status === "escalated" ||
|
|
84
|
+
frontmatter.status === "paused") {
|
|
62
85
|
return false;
|
|
63
|
-
if (frontmatter.wake) {
|
|
64
|
-
const wakeAt = new Date(frontmatter.wake).getTime();
|
|
65
|
-
if (Number.isFinite(wakeAt) && wakeAt > now)
|
|
66
|
-
return false;
|
|
67
86
|
}
|
|
87
|
+
const wakeAt = parseWakeMs(frontmatter);
|
|
88
|
+
if (wakeAt !== undefined && wakeAt > now)
|
|
89
|
+
return false;
|
|
68
90
|
return true;
|
|
69
91
|
}
|
|
70
92
|
/** First `# ` heading after the frontmatter block, or the id when there is none. */
|
|
@@ -76,17 +98,79 @@ export function extractTaskTitle(content, fallbackId) {
|
|
|
76
98
|
}
|
|
77
99
|
return fallbackId;
|
|
78
100
|
}
|
|
101
|
+
function matchesTaskSectionTitle(title, names) {
|
|
102
|
+
const normalized = title.trim().toLowerCase();
|
|
103
|
+
return names.some((name) => {
|
|
104
|
+
const expected = name.toLowerCase();
|
|
105
|
+
return (normalized === expected ||
|
|
106
|
+
normalized.startsWith(`${expected} `) ||
|
|
107
|
+
normalized.startsWith(`${expected}(`) ||
|
|
108
|
+
normalized.startsWith(`${expected}(`));
|
|
109
|
+
});
|
|
110
|
+
}
|
|
79
111
|
export function hasTaskHeading(content, names) {
|
|
80
112
|
return content.split("\n").some((line) => {
|
|
81
113
|
const match = /^#{1,6}\s+(.+?)\s*$/.exec(line);
|
|
82
|
-
return match ?
|
|
114
|
+
return match ? matchesTaskSectionTitle(match[1] ?? "", names) : false;
|
|
83
115
|
});
|
|
84
116
|
}
|
|
85
117
|
export function missingStandardTaskSections(content) {
|
|
86
118
|
return STANDARD_TASK_SECTIONS.filter((section) => !hasTaskHeading(content, section.names)).map((section) => section.label);
|
|
87
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Unchecked Markdown acceptance boxes under the DoD section, plus a synthetic
|
|
122
|
+
* entry when DoD has content but no checkbox syntax at all.
|
|
123
|
+
*
|
|
124
|
+
* Without the "no checklist items" case, a DoD written as prose or a numbered
|
|
125
|
+
* list (no `- [ ]` anywhere) makes this function return an empty array —
|
|
126
|
+
* indistinguishable from "everything is checked" — which would silently let
|
|
127
|
+
* `task_manage candidate`/`done` through with nothing ever actually verified.
|
|
128
|
+
*/
|
|
129
|
+
export function uncheckedTaskAcceptanceItems(content) {
|
|
130
|
+
const unchecked = [];
|
|
131
|
+
let section;
|
|
132
|
+
let sectionLevel = 0;
|
|
133
|
+
let dodHasContent = false;
|
|
134
|
+
let dodHasCheckbox = false;
|
|
135
|
+
for (const line of content.split("\n")) {
|
|
136
|
+
const heading = /^(#{1,6})\s+(.+?)\s*$/.exec(line);
|
|
137
|
+
if (heading) {
|
|
138
|
+
const level = heading[1]?.length ?? 7;
|
|
139
|
+
if (matchesTaskSectionTitle(heading[2] ?? "", ["DoD"])) {
|
|
140
|
+
section = "DoD";
|
|
141
|
+
sectionLevel = level;
|
|
142
|
+
}
|
|
143
|
+
else if (matchesTaskSectionTitle(heading[2] ?? "", ["Verification", "验收"])) {
|
|
144
|
+
section = "Verification";
|
|
145
|
+
sectionLevel = level;
|
|
146
|
+
}
|
|
147
|
+
else if (section && level <= sectionLevel) {
|
|
148
|
+
section = undefined;
|
|
149
|
+
}
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
if (!section)
|
|
153
|
+
continue;
|
|
154
|
+
if (section === "DoD" && line.trim())
|
|
155
|
+
dodHasContent = true;
|
|
156
|
+
const checkbox = /^\s*[-*]\s+\[([ xX])\]\s*(.+?)\s*$/.exec(line);
|
|
157
|
+
if (checkbox) {
|
|
158
|
+
if (section === "DoD")
|
|
159
|
+
dodHasCheckbox = true;
|
|
160
|
+
if (checkbox[1] === " ")
|
|
161
|
+
unchecked.push(`${section}: ${checkbox[2]}`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (dodHasContent && !dodHasCheckbox) {
|
|
165
|
+
unchecked.push('DoD has no checklist items — rewrite it as "- [ ] ..." acceptance items before requesting verification or done.');
|
|
166
|
+
}
|
|
167
|
+
return unchecked;
|
|
168
|
+
}
|
|
88
169
|
export function renderStandardTaskBody(input) {
|
|
89
170
|
const manual = input.manual?.trim() || DEFAULT_TASK_MANUAL;
|
|
171
|
+
const verificationPlan = input.verificationPlan?.trim() ||
|
|
172
|
+
"- Check every DoD item against concrete evidence.\n- Run the relevant deterministic checks before declaring PASS.";
|
|
173
|
+
const verificationMode = input.verificationMode ?? "independent";
|
|
90
174
|
return [
|
|
91
175
|
`# ${input.title}`,
|
|
92
176
|
"",
|
|
@@ -99,6 +183,10 @@ export function renderStandardTaskBody(input) {
|
|
|
99
183
|
"## Manual",
|
|
100
184
|
manual,
|
|
101
185
|
"",
|
|
186
|
+
"## Verification",
|
|
187
|
+
`Mode: ${verificationMode}`,
|
|
188
|
+
verificationPlan,
|
|
189
|
+
"",
|
|
102
190
|
"## Current Cycle",
|
|
103
191
|
"- Created; next step: start work and append progress here before ending each turn.",
|
|
104
192
|
"",
|
|
@@ -106,24 +194,136 @@ export function renderStandardTaskBody(input) {
|
|
|
106
194
|
"",
|
|
107
195
|
].join("\n");
|
|
108
196
|
}
|
|
109
|
-
|
|
197
|
+
export function renderTaskDocument(fields, body) {
|
|
198
|
+
const lines = ["---", `status: ${fields.status}`];
|
|
199
|
+
if (fields.wake)
|
|
200
|
+
lines.push(`wake: ${fields.wake}`);
|
|
201
|
+
if (fields.recurrence)
|
|
202
|
+
lines.push(`recurrence: ${fields.recurrence}`);
|
|
203
|
+
if (fields.control)
|
|
204
|
+
lines.push(`control: ${JSON.stringify(fields.control)}`);
|
|
205
|
+
lines.push("---");
|
|
206
|
+
return `${lines.join("\n")}\n${body}`;
|
|
207
|
+
}
|
|
208
|
+
/** Append one progress bullet to the standard Current Cycle section. */
|
|
209
|
+
export function appendCurrentCycleNote(content, note) {
|
|
210
|
+
const trimmedNote = note.trim().replace(/\s+/g, " ");
|
|
211
|
+
if (!trimmedNote) {
|
|
212
|
+
throw new Error("Current Cycle note must not be empty.");
|
|
213
|
+
}
|
|
214
|
+
const lines = content.split("\n");
|
|
215
|
+
let sectionStart = -1;
|
|
216
|
+
let sectionLevel = 0;
|
|
217
|
+
for (let index = 0; index < lines.length; index++) {
|
|
218
|
+
const match = /^(#{1,6})\s+(.+?)\s*$/.exec(lines[index] ?? "");
|
|
219
|
+
if (!match || !matchesTaskSectionTitle(match[2] ?? "", ["Current Cycle", "当前周期"]))
|
|
220
|
+
continue;
|
|
221
|
+
sectionStart = index;
|
|
222
|
+
sectionLevel = match[1]?.length ?? 0;
|
|
223
|
+
}
|
|
224
|
+
if (sectionStart === -1) {
|
|
225
|
+
throw new Error('Task body has no "Current Cycle" section; normalize the task skeleton first.');
|
|
226
|
+
}
|
|
227
|
+
let insertAt = lines.length;
|
|
228
|
+
for (let index = sectionStart + 1; index < lines.length; index++) {
|
|
229
|
+
const match = /^(#{1,6})\s+/.exec(lines[index] ?? "");
|
|
230
|
+
if (match && (match[1]?.length ?? 7) <= sectionLevel) {
|
|
231
|
+
insertAt = index;
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
while (insertAt > sectionStart + 1 && (lines[insertAt - 1] ?? "").trim() === "") {
|
|
236
|
+
insertAt--;
|
|
237
|
+
}
|
|
238
|
+
lines.splice(insertAt, 0, `- ${trimmedNote}`);
|
|
239
|
+
return lines.join("\n");
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Close the visible current-cycle notes into History and open a fresh cycle.
|
|
243
|
+
* Periodic task cycles deliberately use this small, deterministic transformation
|
|
244
|
+
* instead of asking the model to hand-edit headings and risk appending future
|
|
245
|
+
* checkpoints to the previous cycle.
|
|
246
|
+
*/
|
|
247
|
+
export function startTaskCycle(content, cycleId) {
|
|
248
|
+
const normalizedCycleId = cycleId.trim();
|
|
249
|
+
if (!normalizedCycleId)
|
|
250
|
+
throw new Error("Cycle id must not be empty.");
|
|
251
|
+
const lines = content.split("\n");
|
|
252
|
+
let currentStart = -1;
|
|
253
|
+
let currentLevel = 0;
|
|
254
|
+
let historyStart = -1;
|
|
255
|
+
for (let index = 0; index < lines.length; index++) {
|
|
256
|
+
const match = /^(#{1,6})\s+(.+?)\s*$/.exec(lines[index] ?? "");
|
|
257
|
+
if (!match)
|
|
258
|
+
continue;
|
|
259
|
+
const level = match[1]?.length ?? 0;
|
|
260
|
+
if (matchesTaskSectionTitle(match[2] ?? "", ["Current Cycle", "当前周期"])) {
|
|
261
|
+
currentStart = index;
|
|
262
|
+
currentLevel = level;
|
|
263
|
+
}
|
|
264
|
+
if (matchesTaskSectionTitle(match[2] ?? "", ["History", "历史"])) {
|
|
265
|
+
historyStart = index;
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
if (currentStart === -1 || historyStart === -1 || historyStart <= currentStart) {
|
|
270
|
+
throw new Error('Task body needs ordered "Current Cycle" and "History" sections before starting a new cycle.');
|
|
271
|
+
}
|
|
272
|
+
let currentEnd = historyStart;
|
|
273
|
+
for (let index = currentStart + 1; index < historyStart; index++) {
|
|
274
|
+
const match = /^(#{1,6})\s+/.exec(lines[index] ?? "");
|
|
275
|
+
if (match && (match[1]?.length ?? 7) <= currentLevel) {
|
|
276
|
+
currentEnd = index;
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
const previous = lines
|
|
281
|
+
.slice(currentStart + 1, currentEnd)
|
|
282
|
+
.join("\n")
|
|
283
|
+
.trim();
|
|
284
|
+
const previousHeading = (lines[currentStart] ?? "## Current Cycle").replace(/^#+\s*/, "").trim();
|
|
285
|
+
const replacement = [
|
|
286
|
+
`${"#".repeat(currentLevel)} Current Cycle (${normalizedCycleId})`,
|
|
287
|
+
"- Cycle started; next step: follow the Manual and checkpoint concrete progress.",
|
|
288
|
+
];
|
|
289
|
+
lines.splice(currentStart, currentEnd - currentStart, ...replacement);
|
|
290
|
+
const shiftedHistoryStart = historyStart + replacement.length - (currentEnd - currentStart);
|
|
291
|
+
const historyEntry = [
|
|
292
|
+
`### ${previousHeading} — closed`,
|
|
293
|
+
...(previous ? [previous] : ["- No checkpoint was recorded in the previous cycle."]),
|
|
294
|
+
"",
|
|
295
|
+
];
|
|
296
|
+
// A nested history heading would be unusual; inserting directly after the
|
|
297
|
+
// canonical History heading remains predictable and preserves all older notes.
|
|
298
|
+
lines.splice(shiftedHistoryStart + 1, 0, ...historyEntry);
|
|
299
|
+
return lines.join("\n");
|
|
300
|
+
}
|
|
301
|
+
/** Last non-empty bullet/line under a "当前周期"/"current cycle" heading. */
|
|
110
302
|
function extractLatestNote(content) {
|
|
111
303
|
const lines = content.split("\n");
|
|
112
304
|
let inSection = false;
|
|
305
|
+
let sectionLevel = 0;
|
|
306
|
+
let latest;
|
|
113
307
|
for (const line of lines) {
|
|
114
|
-
|
|
115
|
-
|
|
308
|
+
const heading = /^(#{1,6})\s+(.+?)\s*$/.exec(line);
|
|
309
|
+
if (heading) {
|
|
310
|
+
if (inSection && (heading[1]?.length ?? 7) <= sectionLevel)
|
|
311
|
+
break;
|
|
312
|
+
if (!inSection && matchesTaskSectionTitle(heading[2] ?? "", ["Current Cycle", "当前周期"])) {
|
|
313
|
+
inSection = true;
|
|
314
|
+
sectionLevel = heading[1]?.length ?? 0;
|
|
315
|
+
}
|
|
116
316
|
continue;
|
|
117
317
|
}
|
|
118
318
|
if (!inSection)
|
|
119
319
|
continue;
|
|
120
320
|
const trimmed = line.replace(/^\s*[-*]\s+/, "").trim();
|
|
121
321
|
if (trimmed)
|
|
122
|
-
|
|
322
|
+
latest = trimmed;
|
|
123
323
|
}
|
|
124
|
-
return
|
|
324
|
+
return latest;
|
|
125
325
|
}
|
|
126
|
-
function
|
|
326
|
+
function parseWakeMs(frontmatter) {
|
|
127
327
|
if (!frontmatter.wake)
|
|
128
328
|
return undefined;
|
|
129
329
|
const at = new Date(frontmatter.wake).getTime();
|
|
@@ -133,6 +333,20 @@ function wakeMsOf(frontmatter) {
|
|
|
133
333
|
export function compareTaskEntries(a, b) {
|
|
134
334
|
if (a.actionable !== b.actionable)
|
|
135
335
|
return a.actionable ? -1 : 1;
|
|
336
|
+
if (a.actionable && b.actionable) {
|
|
337
|
+
const ap = taskPriorityRank(a.frontmatter.control?.priority ?? "normal");
|
|
338
|
+
const bp = taskPriorityRank(b.frontmatter.control?.priority ?? "normal");
|
|
339
|
+
if (ap !== bp)
|
|
340
|
+
return ap - bp;
|
|
341
|
+
const ad = a.frontmatter.control?.deadline
|
|
342
|
+
? new Date(a.frontmatter.control.deadline).getTime()
|
|
343
|
+
: Number.POSITIVE_INFINITY;
|
|
344
|
+
const bd = b.frontmatter.control?.deadline
|
|
345
|
+
? new Date(b.frontmatter.control.deadline).getTime()
|
|
346
|
+
: Number.POSITIVE_INFINITY;
|
|
347
|
+
if (ad !== bd)
|
|
348
|
+
return ad - bd;
|
|
349
|
+
}
|
|
136
350
|
const aw = a.wakeMs ?? Number.NEGATIVE_INFINITY;
|
|
137
351
|
const bw = b.wakeMs ?? Number.NEGATIVE_INFINITY;
|
|
138
352
|
if (aw !== bw)
|
|
@@ -146,7 +360,7 @@ function toEntry(id, content, now) {
|
|
|
146
360
|
title: extractTaskTitle(content, id),
|
|
147
361
|
frontmatter,
|
|
148
362
|
actionable: isTaskActionable(frontmatter, now),
|
|
149
|
-
wakeMs:
|
|
363
|
+
wakeMs: parseWakeMs(frontmatter),
|
|
150
364
|
latestNote: extractLatestNote(content),
|
|
151
365
|
};
|
|
152
366
|
}
|
|
@@ -8,4 +8,5 @@ export declare const HAN_REGEX: RegExp;
|
|
|
8
8
|
/** Strip a trailing `.json` from an event filename to get its logical name. */
|
|
9
9
|
export declare function eventNameFromFilename(filename: string): string;
|
|
10
10
|
export declare function extractLabelFromArgs(args: unknown): string | null;
|
|
11
|
+
export declare function errorMessage(err: unknown): string;
|
|
11
12
|
export declare function extractAssistantText(message: AssistantMessage): string;
|
|
@@ -31,6 +31,9 @@ export function extractLabelFromArgs(args) {
|
|
|
31
31
|
const label = args.label;
|
|
32
32
|
return typeof label === "string" && label.trim() ? label.trim() : null;
|
|
33
33
|
}
|
|
34
|
+
export function errorMessage(err) {
|
|
35
|
+
return err instanceof Error ? err.message : String(err);
|
|
36
|
+
}
|
|
34
37
|
export function extractAssistantText(message) {
|
|
35
38
|
return message.content
|
|
36
39
|
.filter((part) => part.type === "text")
|
|
@@ -3,6 +3,7 @@ import { existsSync, readdirSync, readFileSync } from "fs";
|
|
|
3
3
|
import { join } from "path";
|
|
4
4
|
import { findExactModelReferenceMatch, formatModelReference } from "../models/utils.js";
|
|
5
5
|
import { SUB_AGENTS_DIR_NAME } from "../paths.js";
|
|
6
|
+
import { errorMessage } from "../shared/text-utils.js";
|
|
6
7
|
const ALLOWED_SUB_AGENT_TOOLS = ["read", "bash", "edit", "write", "web_search", "web_fetch"];
|
|
7
8
|
const DEFAULT_SUB_AGENT_TOOLS = ["read", "bash"];
|
|
8
9
|
const DEFAULT_MAX_TURNS = 24;
|
|
@@ -188,7 +189,7 @@ export function discoverSubAgents(workspaceDir, availableModels) {
|
|
|
188
189
|
return {
|
|
189
190
|
directory,
|
|
190
191
|
agents: [],
|
|
191
|
-
warnings: [`Failed to read sub-agents directory (${
|
|
192
|
+
warnings: [`Failed to read sub-agents directory (${errorMessage(error)})`],
|
|
192
193
|
};
|
|
193
194
|
}
|
|
194
195
|
for (const entry of entries) {
|
|
@@ -198,7 +199,7 @@ export function discoverSubAgents(workspaceDir, availableModels) {
|
|
|
198
199
|
content = readFileSync(filePath, "utf-8");
|
|
199
200
|
}
|
|
200
201
|
catch (error) {
|
|
201
|
-
warnings.push(`${entry.name}: failed to read file (${
|
|
202
|
+
warnings.push(`${entry.name}: failed to read file (${errorMessage(error)})`);
|
|
202
203
|
continue;
|
|
203
204
|
}
|
|
204
205
|
const { frontmatter, body } = parseFrontmatter(content);
|
package/dist/subagents/tool.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type AgentEvent, type AgentMessage, type AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
3
3
|
import { Type } from "typebox";
|
|
4
|
+
import type { Executor } from "../executor.js";
|
|
4
5
|
import type { MemoryCandidateStore } from "../memory/candidates.js";
|
|
5
|
-
import type { Executor } from "../sandbox.js";
|
|
6
6
|
import type { SecurityConfig } from "../security/types.js";
|
|
7
7
|
import type { PipiclawMemoryRecallSettings } from "../settings.js";
|
|
8
8
|
import type { UsageTotals } from "../shared/types.js";
|
|
@@ -23,6 +23,10 @@ declare const subagentSchema: Type.TObject<{
|
|
|
23
23
|
contextMode: Type.TOptional<Type.TUnion<[Type.TLiteral<"isolated">, Type.TLiteral<"contextual">]>>;
|
|
24
24
|
memory: Type.TOptional<Type.TUnion<[Type.TLiteral<"none">, Type.TLiteral<"session">, Type.TLiteral<"relevant">]>>;
|
|
25
25
|
paths: Type.TOptional<Type.TArray<Type.TString>>;
|
|
26
|
+
purpose: Type.TOptional<Type.TUnion<[Type.TLiteral<"work">, Type.TLiteral<"verify">]>>;
|
|
27
|
+
taskId: Type.TOptional<Type.TString>;
|
|
28
|
+
isolation: Type.TOptional<Type.TUnion<[Type.TLiteral<"shared">, Type.TLiteral<"worktree">]>>;
|
|
29
|
+
worktreePath: Type.TOptional<Type.TString>;
|
|
26
30
|
}>;
|
|
27
31
|
export interface SubAgentToolDetails {
|
|
28
32
|
kind: "subagent";
|
|
@@ -36,9 +40,18 @@ export interface SubAgentToolDetails {
|
|
|
36
40
|
failed: boolean;
|
|
37
41
|
failureReason?: string;
|
|
38
42
|
usage: UsageTotals;
|
|
43
|
+
runId: string;
|
|
44
|
+
purpose: "work" | "verify";
|
|
45
|
+
taskId?: string;
|
|
46
|
+
isolation: "shared" | "worktree";
|
|
47
|
+
worktreePath?: string;
|
|
48
|
+
worktreeBranch?: string;
|
|
49
|
+
verificationVerdict?: "pass" | "fail";
|
|
39
50
|
}
|
|
40
51
|
export interface SubAgentToolOptions {
|
|
41
52
|
executor: Executor;
|
|
53
|
+
/** Host checkout used as the shared cwd and worktree source. Defaults to process.cwd(). */
|
|
54
|
+
workingDirectory?: string;
|
|
42
55
|
getCurrentModel: () => Model<Api>;
|
|
43
56
|
getAvailableModels: () => Model<Api>[];
|
|
44
57
|
resolveApiKey: (model: Model<Api>) => Promise<string>;
|
|
@@ -51,9 +64,8 @@ export interface SubAgentToolOptions {
|
|
|
51
64
|
webConfig?: PipiclawWebToolsConfig;
|
|
52
65
|
rtkEnabled?: boolean;
|
|
53
66
|
runtimeContext: {
|
|
54
|
-
|
|
67
|
+
workspaceDir: string;
|
|
55
68
|
channelId: string;
|
|
56
|
-
sandbox: string;
|
|
57
69
|
};
|
|
58
70
|
createWorker?: (config: {
|
|
59
71
|
subAgent: ResolvedSubAgentConfig;
|