@oyasmi/pipiclaw 0.9.1-beta.2 → 0.9.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/dist/agent/channel-runner.d.ts +7 -0
- package/dist/agent/channel-runner.js +42 -13
- package/dist/agent/command-extension.js +24 -27
- package/dist/agent/commands.d.ts +51 -7
- package/dist/agent/commands.js +199 -59
- package/dist/agent/prompt/manifest.js +5 -6
- package/dist/agent/prompt/sections.js +1 -0
- package/dist/agent/reply-limits.d.ts +16 -0
- package/dist/agent/reply-limits.js +17 -0
- package/dist/agent/session-events.js +2 -2
- package/dist/agent/status-render.js +12 -12
- package/dist/executor.d.ts +14 -0
- package/dist/executor.js +36 -6
- package/dist/main.js +3 -4
- package/dist/memory/commands.js +79 -38
- package/dist/memory/consolidation.d.ts +5 -1
- package/dist/memory/consolidation.js +33 -12
- package/dist/memory/extraction.d.ts +8 -1
- package/dist/memory/extraction.js +47 -4
- package/dist/memory/files.d.ts +0 -1
- package/dist/memory/files.js +24 -5
- package/dist/memory/lifecycle.js +9 -2
- package/dist/memory/maintenance-jobs.js +14 -4
- package/dist/memory/metadata.d.ts +3 -0
- package/dist/memory/metadata.js +7 -0
- package/dist/memory/recall.d.ts +9 -0
- package/dist/memory/recall.js +101 -17
- package/dist/memory/review-log.d.ts +0 -2
- package/dist/memory/review-log.js +0 -0
- package/dist/memory/session-corpus.js +5 -0
- package/dist/memory/session-search.js +9 -0
- package/dist/memory/sidecar-worker.js +4 -0
- package/dist/memory/source-window.d.ts +0 -1
- package/dist/memory/source-window.js +0 -5
- package/dist/playbooks/agent-delegation.md +32 -25
- package/dist/playbooks/background-jobs.md +8 -16
- package/dist/playbooks/event-scheduling.md +13 -15
- package/dist/playbooks/memory-and-learning.md +29 -22
- package/dist/playbooks/outbound-media.md +15 -8
- package/dist/playbooks/runtime-orientation.md +40 -37
- package/dist/playbooks/task-driving.md +34 -36
- package/dist/playbooks/task-planning.md +18 -18
- package/dist/runtime/app-home.d.ts +6 -0
- package/dist/runtime/app-home.js +15 -6
- package/dist/runtime/bootstrap.js +44 -13
- package/dist/runtime/channel-context.d.ts +2 -1
- package/dist/runtime/delivery.js +3 -3
- package/dist/runtime/dingtalk.d.ts +9 -1
- package/dist/runtime/dingtalk.js +27 -13
- package/dist/runtime/event-commands.d.ts +15 -0
- package/dist/runtime/event-commands.js +48 -40
- package/dist/runtime/project-commands.d.ts +16 -0
- package/dist/runtime/project-commands.js +13 -17
- package/dist/runtime/subagent-commands.d.ts +20 -0
- package/dist/runtime/subagent-commands.js +61 -58
- package/dist/runtime/task-commands.d.ts +37 -0
- package/dist/runtime/task-commands.js +106 -64
- package/dist/security/path-guard.js +33 -2
- package/dist/security/types.d.ts +9 -0
- package/dist/subagents/discovery.d.ts +7 -2
- package/dist/subagents/discovery.js +31 -7
- package/dist/subagents/external/claude-code.js +42 -2
- package/dist/subagents/external/run.js +61 -8
- package/dist/subagents/runs.js +6 -0
- package/dist/subagents/tool.d.ts +1 -0
- package/dist/subagents/tool.js +62 -53
- package/dist/tasks/verification.d.ts +7 -5
- package/dist/tools/bash.d.ts +1 -1
- package/dist/tools/bash.js +77 -59
- package/dist/tools/edit.js +17 -4
- package/dist/tools/grep.js +3 -2
- package/dist/tools/index.js +4 -0
- package/dist/tools/job.js +2 -1
- package/dist/tools/memory-manage.d.ts +1 -0
- package/dist/tools/memory-manage.js +54 -16
- package/dist/tools/read.js +21 -5
- package/dist/tools/send-media.js +17 -6
- package/dist/tools/skill-manage.js +12 -11
- package/dist/tools/skill-security.js +1 -1
- package/dist/tools/task-manage.js +1 -1
- package/dist/tools/truncate.d.ts +8 -0
- package/dist/tools/truncate.js +8 -0
- package/dist/tools/web-fetch.js +9 -1
- package/dist/tools/write-content.js +11 -1
- package/dist/tui/app.js +1 -1
- package/dist/tui/commands.d.ts +1 -1
- package/dist/tui/commands.js +1 -1
- package/dist/tui/turn-controller.d.ts +1 -1
- package/dist/tui/turn-controller.js +14 -4
- package/dist/usage/render.js +10 -8
- package/examples/sub-agents/README.md +2 -0
- package/package.json +3 -2
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { readdir, readFile } from "node:fs/promises";
|
|
3
3
|
import { join, resolve, sep } from "node:path";
|
|
4
|
+
import { renderSubcommandUsage } from "../agent/commands.js";
|
|
4
5
|
import { channelJobTaskIds } from "../agent/job-manager.js";
|
|
6
|
+
import { capReply } from "../agent/reply-limits.js";
|
|
5
7
|
import { formatLocalTime, parseLocalTime, parseWakeInput } from "../shared/local-time.js";
|
|
6
8
|
import { errorMessage } from "../shared/text-utils.js";
|
|
7
9
|
import { channelDelegationTaskIds } from "../subagents/runs.js";
|
|
@@ -23,21 +25,15 @@ import { parseScheduledEventContent } from "./events.js";
|
|
|
23
25
|
* machine those fields belong to. The value is the rest of the line, so it may contain spaces.
|
|
24
26
|
*/
|
|
25
27
|
const SETTABLE_TASK_FIELDS = ["wake", "next", "deadline"];
|
|
28
|
+
/** `/tasks show <id>` head-snippet cap; the full file is always readable at its own path. */
|
|
29
|
+
const TASK_SHOW_MAX_CHARS = 4_000;
|
|
30
|
+
// Broadcast (subcommand names, args, descriptions, examples) lives once in commands.ts's
|
|
31
|
+
// `BUILT_IN_COMMANDS` entry for "tasks"; this just renders it (review 2026-08-24 §3.1).
|
|
26
32
|
function usage() {
|
|
27
|
-
return
|
|
28
|
-
|
|
29
|
-
用法:
|
|
30
|
-
|
|
31
|
-
- \`/tasks\` — 列出本频道进行中的任务
|
|
32
|
-
- \`/tasks show <id>\` — 查看单个任务文件(进行中或已归档)
|
|
33
|
-
- \`/tasks archive\` — 列出已归档(已关闭)的任务
|
|
34
|
-
- \`/tasks pause <id>\` — 停止该任务的自动执行(保留当前阶段与 wake)
|
|
35
|
-
- \`/tasks resume <id>\` — 重新启用该任务,按当前阶段继续
|
|
36
|
-
- \`/tasks run <id>\` — 恢复并立即排入一次执行(需要运行时可用)
|
|
37
|
-
- \`/tasks set <id> <${SETTABLE_TASK_FIELDS.join("|")}> <值>\` — 直接改一个字段,不花一个 LLM 回合
|
|
38
|
-
- \`/tasks doctor\` — 只读检查任务/事件一致性`;
|
|
33
|
+
return renderSubcommandUsage("tasks");
|
|
39
34
|
}
|
|
40
|
-
|
|
35
|
+
/** Exported so `test/commands-subcommands.test.ts` can feed every broadcast example back through it. */
|
|
36
|
+
export function parseTasksCommand(args) {
|
|
41
37
|
const trimmed = args.trim();
|
|
42
38
|
const parts = trimmed.split(/\s+/).filter(Boolean);
|
|
43
39
|
const action = parts[0];
|
|
@@ -105,14 +101,42 @@ function resolveTaskPath(dir, id, subdir) {
|
|
|
105
101
|
}
|
|
106
102
|
function relativeWake(wakeMs, now) {
|
|
107
103
|
if (wakeMs === undefined)
|
|
108
|
-
return "
|
|
104
|
+
return "无唤醒时间";
|
|
109
105
|
const local = formatLocalTime(new Date(wakeMs));
|
|
110
106
|
const diffMs = wakeMs - now;
|
|
111
107
|
if (diffMs <= 0)
|
|
112
|
-
return `${local}
|
|
108
|
+
return `${local}(已到期)`;
|
|
113
109
|
const minutes = Math.round(diffMs / 60000);
|
|
114
|
-
const rel = minutes < 60
|
|
115
|
-
|
|
110
|
+
const rel = minutes < 60
|
|
111
|
+
? `${minutes}分钟后`
|
|
112
|
+
: minutes < 1440
|
|
113
|
+
? `${Math.round(minutes / 60)}小时后`
|
|
114
|
+
: `${Math.round(minutes / 1440)}天后`;
|
|
115
|
+
return `${local}(${rel})`;
|
|
116
|
+
}
|
|
117
|
+
function taskStatusLabel(status) {
|
|
118
|
+
switch (status) {
|
|
119
|
+
case "active":
|
|
120
|
+
return "进行中";
|
|
121
|
+
case "waiting":
|
|
122
|
+
return "等待中";
|
|
123
|
+
case "sleeping":
|
|
124
|
+
return "睡眠中";
|
|
125
|
+
default:
|
|
126
|
+
return status;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function verificationStatusLabel(status) {
|
|
130
|
+
switch (status) {
|
|
131
|
+
case "pending":
|
|
132
|
+
return "待验收";
|
|
133
|
+
case "passed":
|
|
134
|
+
return "已通过";
|
|
135
|
+
case "failed":
|
|
136
|
+
return "未通过";
|
|
137
|
+
default:
|
|
138
|
+
return status;
|
|
139
|
+
}
|
|
116
140
|
}
|
|
117
141
|
function eventDir(workspaceDir) {
|
|
118
142
|
return join(workspaceDir, "events");
|
|
@@ -157,7 +181,7 @@ function validWakeMs(entry) {
|
|
|
157
181
|
return parseLocalTime(wake);
|
|
158
182
|
}
|
|
159
183
|
function issue(problem, nextStep) {
|
|
160
|
-
return `- ${problem}
|
|
184
|
+
return `- ${problem}(下一步:${nextStep})`;
|
|
161
185
|
}
|
|
162
186
|
async function readActiveTaskContent(channelDir, id) {
|
|
163
187
|
try {
|
|
@@ -172,35 +196,42 @@ async function listTasks(channelDir) {
|
|
|
172
196
|
const now = Date.now();
|
|
173
197
|
const entries = (await readActiveTasks(dir, now)).filter((entry) => !entry.frontmatter.archiveOutcome);
|
|
174
198
|
if (entries.length === 0) {
|
|
175
|
-
return "
|
|
199
|
+
return "**任务**\n\n暂无进行中的任务。用 `/tasks archive` 查看已归档任务。";
|
|
176
200
|
}
|
|
177
201
|
const blocks = entries.map((entry) => {
|
|
178
|
-
|
|
179
|
-
|
|
202
|
+
if (!entry.frontmatter.readable) {
|
|
203
|
+
return `**${entry.id}** — ${entry.title}\n- ⚠ frontmatter 无法读取,status/wake 不可信`;
|
|
204
|
+
}
|
|
205
|
+
const status = entry.frontmatter.status ?? "active";
|
|
206
|
+
const lines = [
|
|
207
|
+
`**${entry.id}** — ${entry.title}`,
|
|
208
|
+
`- 状态:${taskStatusLabel(status)} · 下次唤醒 ${relativeWake(entry.wakeMs, now)}`,
|
|
209
|
+
];
|
|
180
210
|
const control = entry.frontmatter.control;
|
|
181
211
|
if (control) {
|
|
182
212
|
if (control.verification.required)
|
|
183
|
-
|
|
213
|
+
lines.push(`- 验收:需要验收,${verificationStatusLabel(control.verification.status)}`);
|
|
184
214
|
if (control.waitingFor)
|
|
185
|
-
|
|
215
|
+
lines.push(`- 等待:${control.waitingFor}`);
|
|
186
216
|
if (control.stop)
|
|
187
|
-
|
|
217
|
+
lines.push(`- 已停用:${control.stop.by} — ${control.stop.reason}`);
|
|
188
218
|
if (control.deadline)
|
|
189
|
-
|
|
219
|
+
lines.push(`- 截止:${control.deadline}`);
|
|
190
220
|
if (control.nextAction)
|
|
191
|
-
|
|
192
|
-
if (control.cycleId)
|
|
193
|
-
|
|
194
|
-
}
|
|
221
|
+
lines.push(`- 下一步:${control.nextAction}`);
|
|
222
|
+
if (control.cycleId)
|
|
223
|
+
lines.push(`- ${status === "sleeping" ? "上一周期" : "当前周期"}:${control.cycleId}`);
|
|
195
224
|
}
|
|
196
225
|
if (entry.frontmatter.enabled === false)
|
|
197
|
-
|
|
226
|
+
lines.push("- 已停用(enabled: false)");
|
|
198
227
|
if (entry.frontmatter.schedule) {
|
|
199
|
-
|
|
228
|
+
lines.push(`- 调度时区:${Intl.DateTimeFormat().resolvedOptions().timeZone}(本机)`);
|
|
200
229
|
}
|
|
201
|
-
return
|
|
230
|
+
return lines.join("\n");
|
|
202
231
|
});
|
|
203
|
-
|
|
232
|
+
const footer = "详情 `/tasks show <id>`,体检 `/tasks doctor`";
|
|
233
|
+
const body = `**任务** · ${entries.length} 个进行中\n\n${blocks.join("\n\n")}\n\n${footer}`;
|
|
234
|
+
return capReply(body, { nextStepHint: "用 `/tasks show <id>` 查看单个任务的完整状态" }).text;
|
|
204
235
|
}
|
|
205
236
|
export async function pauseTask(options, idInput) {
|
|
206
237
|
const id = normalizeTaskId(idInput);
|
|
@@ -325,18 +356,27 @@ async function showTask(channelDir, id) {
|
|
|
325
356
|
if (!path) {
|
|
326
357
|
return `找不到任务:${taskId}`;
|
|
327
358
|
}
|
|
328
|
-
const location = path === archivePath ? "
|
|
359
|
+
const location = path === archivePath ? "(已归档)" : "";
|
|
360
|
+
const header = `**任务 ${taskId}**${location}`;
|
|
329
361
|
const content = await readFile(path, "utf-8");
|
|
330
|
-
|
|
362
|
+
// The file already lives on disk at `path`; a huge task file (long Plan/DoD history) is shown
|
|
363
|
+
// as a head snippet with a pointer to that existing path instead of dumping it whole (review
|
|
364
|
+
// 2026-08-24 §2.4/§3.2) — no separate copy needs to be written.
|
|
365
|
+
if (content.length <= TASK_SHOW_MAX_CHARS) {
|
|
366
|
+
return `${header}\n\n\`\`\`markdown\n${content}\n\`\`\``;
|
|
367
|
+
}
|
|
368
|
+
const lastNewline = content.lastIndexOf("\n", TASK_SHOW_MAX_CHARS);
|
|
369
|
+
const head = content.slice(0, lastNewline > 0 ? lastNewline : TASK_SHOW_MAX_CHARS).trimEnd();
|
|
370
|
+
return `${header}\n\n\`\`\`markdown\n${head}\n\`\`\`\n\n(内容过长已截断;完整内容见 \`${path}\`)`;
|
|
331
371
|
}
|
|
332
372
|
async function listArchive(channelDir) {
|
|
333
373
|
const dir = join(tasksDir(channelDir), "archive");
|
|
334
374
|
if (!existsSync(dir)) {
|
|
335
|
-
return "
|
|
375
|
+
return "**已归档任务**\n\n暂无已归档任务。";
|
|
336
376
|
}
|
|
337
377
|
const filenames = (await readdir(dir)).filter((filename) => filename.endsWith(".md")).sort();
|
|
338
378
|
if (filenames.length === 0) {
|
|
339
|
-
return "
|
|
379
|
+
return "**已归档任务**\n\n暂无已归档任务。";
|
|
340
380
|
}
|
|
341
381
|
const blocks = [];
|
|
342
382
|
for (const filename of filenames) {
|
|
@@ -349,11 +389,12 @@ async function listArchive(channelDir) {
|
|
|
349
389
|
blocks.push(`- ${id}`);
|
|
350
390
|
}
|
|
351
391
|
}
|
|
352
|
-
|
|
392
|
+
const body = `**已归档任务** · ${blocks.length} 个\n\n${blocks.join("\n")}`;
|
|
393
|
+
return capReply(body, { nextStepHint: "用 `/tasks show <id>` 查看单个已归档任务" }).text;
|
|
353
394
|
}
|
|
354
395
|
async function doctor(options) {
|
|
355
396
|
if (!options.workspaceDir || !options.channelId) {
|
|
356
|
-
return "
|
|
397
|
+
return "**任务体检**\n\n不可用:需要 workspaceDir 与 channelId。";
|
|
357
398
|
}
|
|
358
399
|
const now = Date.now();
|
|
359
400
|
const entries = await readActiveTasks(tasksDir(options.channelDir), now);
|
|
@@ -366,22 +407,22 @@ async function doctor(options) {
|
|
|
366
407
|
for (const entry of entries) {
|
|
367
408
|
const status = entry.frontmatter.status ?? "active";
|
|
368
409
|
if (!entry.frontmatter.readable) {
|
|
369
|
-
issues.push(issue(`tasks/${entry.id}.md
|
|
410
|
+
issues.push(issue(`tasks/${entry.id}.md 的 frontmatter 无法读取,wake/status 不可信`, `修复 tasks/${entry.id}.md,让它以可读的 status/wake/schedule frontmatter 开头`));
|
|
370
411
|
continue;
|
|
371
412
|
}
|
|
372
413
|
if (entry.frontmatter.controlReadable === false) {
|
|
373
|
-
issues.push(issue(`tasks/${entry.id}.md
|
|
414
|
+
issues.push(issue(`tasks/${entry.id}.md 的 control 元数据无效;治理机制 fail-open,但无法生效`, `用 task_manage set 或直接修复那一行 control JSON,然后再允许任务运行`));
|
|
374
415
|
continue;
|
|
375
416
|
}
|
|
376
417
|
const control = entry.frontmatter.control;
|
|
377
418
|
if (!control && entry.frontmatter.enabled === false) {
|
|
378
|
-
issues.push(issue(`tasks/${entry.id}.md
|
|
419
|
+
issues.push(issue(`tasks/${entry.id}.md 已停用,但完全没有 control.stop 回执`, `用 task_manage set 修复 control 元数据,确认可以继续后再 /tasks resume ${entry.id}`));
|
|
379
420
|
}
|
|
380
421
|
if (control) {
|
|
381
422
|
const storedTask = await readStoredTask(options.channelDir, entry.id);
|
|
382
423
|
const violation = taskBudgetViolation(control, now, status);
|
|
383
424
|
if (violation) {
|
|
384
|
-
issues.push(issue(`tasks/${entry.id}.md
|
|
425
|
+
issues.push(issue(`tasks/${entry.id}.md 超出了它的 control 限额:${violation}`, `检查这个任务,明确提高 budget/deadline 或取消它;否则 driver 会升级处理`));
|
|
385
426
|
}
|
|
386
427
|
if (status !== "sleeping" && control.verification.status === "passed") {
|
|
387
428
|
const attestationOk = control.verification.runId
|
|
@@ -392,48 +433,48 @@ async function doctor(options) {
|
|
|
392
433
|
.catch(() => false)
|
|
393
434
|
: false;
|
|
394
435
|
if (!attestationOk) {
|
|
395
|
-
issues.push(issue(`tasks/${entry.id}.md
|
|
436
|
+
issues.push(issue(`tasks/${entry.id}.md 记录了一次独立 PASS,但磁盘上没有匹配且新鲜的验证 attestation`, `跑一次新的 purpose=verify 子代理,并用 task_manage verify 导入它的 attestation 后再完成`));
|
|
396
437
|
}
|
|
397
438
|
}
|
|
398
439
|
if (entry.frontmatter.enabled === false && !control.stop) {
|
|
399
|
-
issues.push(issue(`tasks/${entry.id}.md
|
|
440
|
+
issues.push(issue(`tasks/${entry.id}.md 已停用,但 control 里没有 stop 回执`, `先弄清是谁停用的,再 /tasks resume ${entry.id};或者用 task_manage set 写一条合法的 stop 记录`));
|
|
400
441
|
}
|
|
401
442
|
if (entry.frontmatter.enabled !== false && control.stop) {
|
|
402
|
-
issues.push(issue(`tasks/${entry.id}.md
|
|
443
|
+
issues.push(issue(`tasks/${entry.id}.md 有 stop 回执,但 enabled 是 true`, `跑 /tasks resume ${entry.id} 清掉过期的 stop 回执,或者显式停用这个任务`));
|
|
403
444
|
}
|
|
404
445
|
}
|
|
405
446
|
const recurring = Boolean(entry.frontmatter.schedule);
|
|
406
447
|
if (status === "sleeping" && !recurring) {
|
|
407
|
-
issues.push(issue(`tasks/${entry.id}.md
|
|
448
|
+
issues.push(issue(`tasks/${entry.id}.md 处于 sleeping,但没有 recurring schedule`, `一次性任务用 task_manage complete/cancel 结束;要保留 sleeping 需要先加一个合法的 schedule`));
|
|
408
449
|
}
|
|
409
450
|
if (recurring) {
|
|
410
451
|
try {
|
|
411
452
|
validateTaskSchedule(entry.frontmatter.schedule);
|
|
412
453
|
}
|
|
413
454
|
catch (error) {
|
|
414
|
-
issues.push(issue(`tasks/${entry.id}.md
|
|
455
|
+
issues.push(issue(`tasks/${entry.id}.md 的 schedule 无效:${errorMessage(error)}`, `修复或清空 ${entry.id} 的 schedule;修复前 driver 会让这个任务保持停用`));
|
|
415
456
|
}
|
|
416
457
|
if (status === "sleeping" && !entry.frontmatter.wake) {
|
|
417
|
-
issues.push(issue(`tasks/${entry.id}.md
|
|
458
|
+
issues.push(issue(`tasks/${entry.id}.md 处于 sleeping,但没有 wake`, `修复 schedule 和 wake,确认无误后 /tasks resume ${entry.id}`));
|
|
418
459
|
}
|
|
419
460
|
}
|
|
420
461
|
if (status === "active" &&
|
|
421
462
|
entry.frontmatter.wake &&
|
|
422
463
|
validWakeMs(entry) !== undefined &&
|
|
423
464
|
validWakeMs(entry) > now) {
|
|
424
|
-
issues.push(issue(`tasks/${entry.id}.md
|
|
465
|
+
issues.push(issue(`tasks/${entry.id}.md 处于 active,但它的 wake 在未来`, `用 task_manage set/progress 把它改成 waiting 且 waitingFor=time,或者清空 wake 让它现在继续`));
|
|
425
466
|
}
|
|
426
467
|
if (recurringTaskMissedOccurrence({ status, schedule: entry.frontmatter.schedule, control }, new Date(now))) {
|
|
427
|
-
issues.push(issue(`tasks/${entry.id}.md
|
|
468
|
+
issues.push(issue(`tasks/${entry.id}.md 有一个已过下次 recurring 时点、仍处于 ${status} 的周期,且没有并行开启新周期`, `完成、跳过或取消 ${entry.id} 当前周期,之后让 driver 计算下一次时点`));
|
|
428
469
|
}
|
|
429
470
|
const content = await readActiveTaskContent(options.channelDir, entry.id);
|
|
430
471
|
if (content === undefined) {
|
|
431
|
-
issues.push(issue(`tasks/${entry.id}.md
|
|
472
|
+
issues.push(issue(`tasks/${entry.id}.md 在体检时读取失败`, `手动打开 tasks/${entry.id}.md,修复权限或文件内容`));
|
|
432
473
|
}
|
|
433
474
|
else {
|
|
434
475
|
const missing = missingStandardTaskSections(content);
|
|
435
476
|
if (missing.length > 0) {
|
|
436
|
-
issues.push(issue(`tasks/${entry.id}.md
|
|
477
|
+
issues.push(issue(`tasks/${entry.id}.md 缺少标准分节:${missing.join(", ")}`, `让 agent 把 tasks/${entry.id}.md 规范化成标准任务骨架`));
|
|
437
478
|
}
|
|
438
479
|
// spec 037, D4: two deterministic, zero-LLM-cost drift checks between a Plan and its
|
|
439
480
|
// DoD — the first real consumer of "is the plan still pointed at the goal?".
|
|
@@ -441,12 +482,12 @@ async function doctor(options) {
|
|
|
441
482
|
const dodCount = countTaskDodItems(content);
|
|
442
483
|
const invalidRefs = entry.plan.steps.flatMap((step) => step.dodRefs.filter((ref) => ref < 1 || ref > dodCount).map((ref) => `${step.id}→dod:${ref}`));
|
|
443
484
|
if (invalidRefs.length > 0) {
|
|
444
|
-
issues.push(issue(`tasks/${entry.id}.md Plan
|
|
485
|
+
issues.push(issue(`tasks/${entry.id}.md 的 Plan 引用了不存在的 DoD 项:${invalidRefs.join(", ")}`, `修正 Plan 里的 "→ dod:N" 引用;如果 DoD 列表变了就重新编号`));
|
|
445
486
|
}
|
|
446
487
|
const covered = new Set(entry.plan.steps.filter((step) => step.status !== "dropped").flatMap((step) => step.dodRefs));
|
|
447
488
|
const uncovered = Array.from({ length: dodCount }, (_, index) => index + 1).filter((dodIndex) => !covered.has(dodIndex));
|
|
448
489
|
if (dodCount > 0 && uncovered.length > 0) {
|
|
449
|
-
issues.push(issue(`tasks/${entry.id}.md
|
|
490
|
+
issues.push(issue(`tasks/${entry.id}.md 有 DoD 项没有 Plan 步骤覆盖:dod:${uncovered.join(",")}`, `给某个 Plan 步骤加上或更新 "→ dod:${uncovered[0]}" 引用,或者确认这些 DoD 项确实不需要专门的步骤`));
|
|
450
491
|
}
|
|
451
492
|
}
|
|
452
493
|
}
|
|
@@ -460,11 +501,11 @@ async function doctor(options) {
|
|
|
460
501
|
const hasDurableWake = Boolean(entry.frontmatter.wake) && validWakeMs(entry) !== undefined;
|
|
461
502
|
const hasRunningSource = runningJobTaskIds.has(entry.id) || runningDelegationTaskIds.has(entry.id);
|
|
462
503
|
if (!hasDurableWake && !hasRunningSource) {
|
|
463
|
-
issues.push(issue(`tasks/${entry.id}.md
|
|
504
|
+
issues.push(issue(`tasks/${entry.id}.md 处于 waiting,且没有可靠的恢复方式(没有合法 wake,也没有记录在案的运行中 job/委派)`, `它只能靠你回复、跑 /tasks run ${entry.id},或者用 /tasks set ${entry.id} wake <本地时间或 +2h> 给它一个 wake 才能恢复;如果等待的东西已经不存在了就取消它`));
|
|
464
505
|
}
|
|
465
506
|
}
|
|
466
507
|
if (entry.frontmatter.wake && validWakeMs(entry) === undefined) {
|
|
467
|
-
issues.push(issue(`tasks/${entry.id}.md
|
|
508
|
+
issues.push(issue(`tasks/${entry.id}.md 的 wake 值无效(${entry.frontmatter.wake});原生 driver 会把它当成已到期处理`, `用 task_manage set 或 progress 把 wake 换成合法本地时间,或者清空它让任务直接继续`));
|
|
468
509
|
}
|
|
469
510
|
// A recurring task's wake should always be an occurrence of its own schedule. A wake that
|
|
470
511
|
// isn't — a stale value left over from a since-changed cron, or a hand-typed local↔UTC
|
|
@@ -476,32 +517,33 @@ async function doctor(options) {
|
|
|
476
517
|
if (wakeMs !== undefined) {
|
|
477
518
|
const priorOccurrence = nextTaskWake(schedule, new Date(wakeMs - 1));
|
|
478
519
|
if (priorOccurrence?.getTime() !== wakeMs) {
|
|
479
|
-
issues.push(issue(`tasks/${entry.id}.md wake
|
|
520
|
+
issues.push(issue(`tasks/${entry.id}.md 的 wake(${formatLocalTime(new Date(wakeMs))})不是它 schedule "${schedule}" 的一个合法时点`, `跑 task_manage set schedule="${schedule}"(不变)用 cron 重新计算 wake,或者手动明确设置 wake`));
|
|
480
521
|
}
|
|
481
522
|
}
|
|
482
523
|
}
|
|
483
524
|
}
|
|
484
525
|
for (const event of events) {
|
|
485
526
|
if (!event.id || !event.use) {
|
|
486
|
-
issues.push(issue(`events/${event.filename}
|
|
527
|
+
issues.push(issue(`events/${event.filename} 不符合 task.<channelId>.<taskId>.<use>.json 命名`, "把这个事件改名为任务专用命名约定,或者当作普通事件管理"));
|
|
487
528
|
continue;
|
|
488
529
|
}
|
|
489
530
|
if (event.error) {
|
|
490
|
-
issues.push(issue(`events/${event.filename}
|
|
531
|
+
issues.push(issue(`events/${event.filename} 无法解析:${event.error}`, `修复或删除 events/${event.filename};无效的任务专属事件不可信`));
|
|
491
532
|
continue;
|
|
492
533
|
}
|
|
493
534
|
if (!activeIds.has(event.id) && !archivedIds.has(event.id)) {
|
|
494
|
-
issues.push(issue(`events/${event.filename}
|
|
535
|
+
issues.push(issue(`events/${event.filename} 指向了不存在的任务 ${event.id}`, `删除 events/${event.filename};如果那个任务在概念上还存在,就重新创建 tasks/${event.id}.md`));
|
|
495
536
|
continue;
|
|
496
537
|
}
|
|
497
538
|
if (archivedIds.has(event.id)) {
|
|
498
|
-
issues.push(issue(`events/${event.filename}
|
|
539
|
+
issues.push(issue(`events/${event.filename} 指向了已归档任务 ${event.id};已关闭的任务不应该还有存活的事件`, `删除 events/${event.filename};已归档任务不应该唤醒 agent`));
|
|
499
540
|
}
|
|
500
541
|
}
|
|
501
542
|
if (issues.length === 0) {
|
|
502
|
-
return "
|
|
543
|
+
return "**任务体检**\n\n未发现任务台账问题。";
|
|
503
544
|
}
|
|
504
|
-
|
|
545
|
+
const body = `**任务体检** · 发现 ${issues.length} 个问题\n\n${issues.join("\n")}`;
|
|
546
|
+
return capReply(body, { nextStepHint: "先处理靠前的问题,再重新运行 `/tasks doctor`" }).text;
|
|
505
547
|
}
|
|
506
548
|
export async function handleTasksCommand(options) {
|
|
507
549
|
let command;
|
|
@@ -224,6 +224,28 @@ function isAgentWorkspaceSkillsRead(path, operation, ctx) {
|
|
|
224
224
|
}
|
|
225
225
|
return startsWithPathPrefix(path, normalize(join(ctx.agentWorkspaceDir, "skills")));
|
|
226
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* Runtime-owned exception for the channel's own directory, in the same spirit as `skills/`: spec
|
|
229
|
+
* 043's D5 puts `SESSION.md`, channel `MEMORY.md`, `HISTORY.md` and `tasks/` in the AgentWorkspace
|
|
230
|
+
* precisely so a channel keeps its continuity across project switches — but D6.2's project bound
|
|
231
|
+
* then put them outside every allowed root, so a task wake could tell the model to open
|
|
232
|
+
* `tasks/<id>.md` and the guard would refuse.
|
|
233
|
+
*
|
|
234
|
+
* Reads are allowed throughout. Writes are allowed only under `tasks/`: the three memory files are
|
|
235
|
+
* runtime-maintained and go through `memory_manage` (a file write there races the maintenance
|
|
236
|
+
* queue), while a task's body is model-authored prose that `task_manage` cannot rewrite — `set`
|
|
237
|
+
* replaces frontmatter and keeps the body verbatim, so revising a task contract needs `edit`.
|
|
238
|
+
*/
|
|
239
|
+
function isChannelDirAccess(path, operation, ctx) {
|
|
240
|
+
if (!ctx.channelDir) {
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
const channelDir = normalize(ctx.channelDir);
|
|
244
|
+
if (!startsWithPathPrefix(path, channelDir)) {
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
return operation === "read" || startsWithPathPrefix(path, normalize(join(channelDir, "tasks")));
|
|
248
|
+
}
|
|
227
249
|
function isDeniedSystemPath(path) {
|
|
228
250
|
if (isWithinTemp(path)) {
|
|
229
251
|
return false;
|
|
@@ -270,6 +292,7 @@ export function guardPath(rawPath, operation, ctx) {
|
|
|
270
292
|
agentWorkspaceDir: resolveRootForGuard(ctx.agentWorkspaceDir, ctx),
|
|
271
293
|
homeDir: resolveRootForGuard(homeDir, ctx),
|
|
272
294
|
projectRoot: ctx.projectRoot ? resolveRootForGuard(ctx.projectRoot, ctx) : ctx.projectRoot,
|
|
295
|
+
channelDir: ctx.channelDir ? resolveRootForGuard(ctx.channelDir, ctx) : ctx.channelDir,
|
|
273
296
|
};
|
|
274
297
|
const resolvedTarget = resolveTargetPath(rawPath, ctx);
|
|
275
298
|
const guardedPath = resolveForGuard(resolvedTarget, ctx);
|
|
@@ -300,11 +323,19 @@ export function guardPath(rawPath, operation, ctx) {
|
|
|
300
323
|
}
|
|
301
324
|
if (pathAllowedByDefaults(guardedPath, effectiveCtx) ||
|
|
302
325
|
isBundledPlaybookRead(guardedPath, operation) ||
|
|
303
|
-
isAgentWorkspaceSkillsRead(guardedPath, operation, effectiveCtx)
|
|
326
|
+
isAgentWorkspaceSkillsRead(guardedPath, operation, effectiveCtx) ||
|
|
327
|
+
isChannelDirAccess(guardedPath, operation, effectiveCtx)) {
|
|
304
328
|
return { allowed: true, operation, rawPath, resolvedPath: guardedPath };
|
|
305
329
|
}
|
|
306
330
|
if (isDeniedSystemPath(guardedPath)) {
|
|
307
331
|
return formatBlockedResult(operation, rawPath, guardedPath, "system-path", `${operation === "read" ? "Reading" : "Writing"} system paths is not allowed by default`);
|
|
308
332
|
}
|
|
309
|
-
|
|
333
|
+
// The reason names the roots that are actually in effect. Under `boundary: "project"` the
|
|
334
|
+
// generic wording ("outside workspace, home, and temp") is worse than unhelpful: workspace and
|
|
335
|
+
// home are themselves out of bounds there, so a model taking it at face value retries against a
|
|
336
|
+
// path that can never be allowed.
|
|
337
|
+
const verb = operation === "read" ? "Reading" : "Writing";
|
|
338
|
+
return formatBlockedResult(operation, rawPath, guardedPath, "outside-allowed-roots", effectiveCtx.boundary === "project"
|
|
339
|
+
? `${verb} outside the current project root (${effectiveCtx.projectRoot ?? "unset"}) is not allowed`
|
|
340
|
+
: `${verb} outside workspace, home, and temp paths is not allowed`);
|
|
310
341
|
}
|
package/dist/security/types.d.ts
CHANGED
|
@@ -46,6 +46,15 @@ export interface SecurityRuntimeContext {
|
|
|
46
46
|
* defaults — `agentWorkspaceDir` + temp + `homeDir`.
|
|
47
47
|
*/
|
|
48
48
|
boundary?: "project" | "unbounded";
|
|
49
|
+
/**
|
|
50
|
+
* The channel's own directory (`<agentWorkspaceDir>/<channelId>`), when the caller is bound to
|
|
51
|
+
* one. It lives under `agentWorkspaceDir`, so it only matters under `boundary: "project"`,
|
|
52
|
+
* where it carries the channel's continuity across project switches (spec 043, D5) and would
|
|
53
|
+
* otherwise fall outside every allowed root. Omit it for callers that are not channel-bound —
|
|
54
|
+
* a sub-agent, for one, gets channel state through its injected context blocks, not by reading
|
|
55
|
+
* the channel's files.
|
|
56
|
+
*/
|
|
57
|
+
channelDir?: string;
|
|
49
58
|
homeDir?: string;
|
|
50
59
|
}
|
|
51
60
|
export interface PathGuardContext extends SecurityRuntimeContext {
|
|
@@ -100,10 +100,9 @@ export interface SubAgentConfig {
|
|
|
100
100
|
* The role is still listed — never silently dropped (D5) — and invocation must explain why. */
|
|
101
101
|
unavailable?: string;
|
|
102
102
|
}
|
|
103
|
-
export interface ResolvedSubAgentConfig extends Omit<SubAgentConfig, "model" | "modelRef"
|
|
103
|
+
export interface ResolvedSubAgentConfig extends Omit<SubAgentConfig, "model" | "modelRef"> {
|
|
104
104
|
model: Model<Api>;
|
|
105
105
|
modelRef: string;
|
|
106
|
-
thinkingLevel: SubAgentThinkingLevel;
|
|
107
106
|
}
|
|
108
107
|
export interface SubAgentDiscoveryResult {
|
|
109
108
|
directory: string;
|
|
@@ -124,7 +123,12 @@ export interface SubAgentInvocationOverrides {
|
|
|
124
123
|
thinkingLevel?: string;
|
|
125
124
|
/** Drives the thinkingLevel default: "verify" defaults on, everything else stays off. */
|
|
126
125
|
purpose?: string;
|
|
126
|
+
mutates?: string;
|
|
127
127
|
}
|
|
128
|
+
/** Internal work/verify default, aligned with the main agent's DEFAULT_MAIN_THINKING_LEVEL
|
|
129
|
+
* (channel-runner.ts). External work leaves thinkingLevel unset instead (see resolveSubAgentConfig):
|
|
130
|
+
* pipiclaw has no standing to pick a reasoning effort for another CLI's own configuration. */
|
|
131
|
+
export declare const DEFAULT_THINKING_LEVEL: SubAgentThinkingLevel;
|
|
128
132
|
export declare function validateSubAgentTask(task: string): string | undefined;
|
|
129
133
|
export declare function getSubAgentsDir(workspaceDir: string): string;
|
|
130
134
|
/**
|
|
@@ -163,6 +167,7 @@ export declare function resolveSubAgentConfig(availableModels: Model<Api>[], cur
|
|
|
163
167
|
subagentDefaultModelRef?: string): {
|
|
164
168
|
config?: ResolvedSubAgentConfig;
|
|
165
169
|
error?: string;
|
|
170
|
+
warning?: string;
|
|
166
171
|
};
|
|
167
172
|
export declare function formatSubAgentList(agents: SubAgentConfig[], maxItems?: number): string;
|
|
168
173
|
/**
|
|
@@ -62,9 +62,10 @@ const ALLOWED_EFFORTS = Object.keys(SUB_AGENT_EFFORT_PRESETS);
|
|
|
62
62
|
* i.e. paths-only injection — remains expressible in frontmatter.
|
|
63
63
|
*/
|
|
64
64
|
const ALLOWED_CONTEXT_CHOICES = ["none", "session", "relevant"];
|
|
65
|
-
/** verify
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
/** Internal work/verify default, aligned with the main agent's DEFAULT_MAIN_THINKING_LEVEL
|
|
66
|
+
* (channel-runner.ts). External work leaves thinkingLevel unset instead (see resolveSubAgentConfig):
|
|
67
|
+
* pipiclaw has no standing to pick a reasoning effort for another CLI's own configuration. */
|
|
68
|
+
export const DEFAULT_THINKING_LEVEL = "medium";
|
|
68
69
|
function validateTextLength(value, maxChars, label) {
|
|
69
70
|
if (value.length <= maxChars) {
|
|
70
71
|
return undefined;
|
|
@@ -676,6 +677,13 @@ subagentDefaultModelRef) {
|
|
|
676
677
|
'"model" frontmatter. The "model" invocation parameter has no effect on external roles and is never resolved against models.json.',
|
|
677
678
|
};
|
|
678
679
|
}
|
|
680
|
+
// External `mutates` is the role file's own self-declaration (checked against its harness/command),
|
|
681
|
+
// same reasoning as `model` above — the caller cannot override what the external role attests about itself.
|
|
682
|
+
if (effectiveRuntime === "external" && overrides.mutates !== undefined) {
|
|
683
|
+
return {
|
|
684
|
+
error: `Sub-agent "${baseConfig?.name}" is external; "mutates" comes from its role file, not the invocation parameter.`,
|
|
685
|
+
};
|
|
686
|
+
}
|
|
679
687
|
const tools = overrides.tools
|
|
680
688
|
? validateToolNames(overrides.tools)
|
|
681
689
|
: { tools: baseConfig?.tools ?? [...DEFAULT_SUB_AGENT_TOOLS] };
|
|
@@ -741,9 +749,24 @@ subagentDefaultModelRef) {
|
|
|
741
749
|
return { error: thinkingLevelOverride.error };
|
|
742
750
|
}
|
|
743
751
|
const purpose = overrides.purpose === "verify" ? "verify" : "work";
|
|
744
|
-
const
|
|
745
|
-
|
|
746
|
-
|
|
752
|
+
const explicitThinkingLevel = thinkingLevelOverride?.value ?? baseConfig?.thinkingLevel;
|
|
753
|
+
// External work is not defaulted: pipiclaw has no standing to pick a reasoning effort for
|
|
754
|
+
// another CLI's own configuration. External verify still defaults — it is the last unattended
|
|
755
|
+
// gate before an attestation is trusted, and "whatever that machine happens to have configured"
|
|
756
|
+
// is not an acceptable substitute for real reasoning.
|
|
757
|
+
const thinkingLevel = explicitThinkingLevel ??
|
|
758
|
+
(effectiveRuntime === "external" && purpose !== "verify" ? undefined : DEFAULT_THINKING_LEVEL);
|
|
759
|
+
const mutatesOverride = parseMutates(overrides.mutates);
|
|
760
|
+
if (mutatesOverride.error) {
|
|
761
|
+
return { error: mutatesOverride.error };
|
|
762
|
+
}
|
|
763
|
+
const mutates = mutatesOverride.value ?? baseConfig?.mutates ?? inferMutatesFromTools(tools.tools);
|
|
764
|
+
// Same rationale as the predefined-role bashWithoutMutatesWarning above (D6): `bash` can write
|
|
765
|
+
// regardless of what `tools` otherwise implies. Inline roles have no frontmatter to declare it
|
|
766
|
+
// in, so the warning goes back to the model in the result text instead of a discovery-time log.
|
|
767
|
+
const bashWithoutMutatesWarning = !baseConfig && tools.tools.includes("bash") && mutatesOverride.value === undefined
|
|
768
|
+
? 'tools include bash but "mutates" is not declared; if this task writes to the workspace, pass mutates: "write" so it takes the exclusive workspace write lease'
|
|
769
|
+
: undefined;
|
|
747
770
|
const systemPrompt = overrides.systemPrompt?.trim() || baseConfig?.systemPrompt || "";
|
|
748
771
|
if (!systemPrompt) {
|
|
749
772
|
return { error: "Sub-agent system prompt cannot be empty." };
|
|
@@ -755,6 +778,7 @@ subagentDefaultModelRef) {
|
|
|
755
778
|
}
|
|
756
779
|
}
|
|
757
780
|
return {
|
|
781
|
+
warning: bashWithoutMutatesWarning,
|
|
758
782
|
config: {
|
|
759
783
|
name: overrides.name?.trim() || baseConfig?.name || "dynamic-subagent",
|
|
760
784
|
description: baseConfig?.description || "Inline sub-agent",
|
|
@@ -778,7 +802,7 @@ subagentDefaultModelRef) {
|
|
|
778
802
|
shell: baseConfig?.shell,
|
|
779
803
|
env: baseConfig?.env,
|
|
780
804
|
workload: baseConfig?.workload,
|
|
781
|
-
mutates
|
|
805
|
+
mutates,
|
|
782
806
|
externalModelRef: baseConfig?.externalModelRef,
|
|
783
807
|
unavailable: baseConfig?.unavailable,
|
|
784
808
|
},
|
|
@@ -29,9 +29,15 @@ function toClaudeEffort(level) {
|
|
|
29
29
|
return undefined;
|
|
30
30
|
return THINKING_LEVEL_TO_CLAUDE_EFFORT[level] ?? level;
|
|
31
31
|
}
|
|
32
|
+
function isRecord(value) {
|
|
33
|
+
return typeof value === "object" && value !== null;
|
|
34
|
+
}
|
|
32
35
|
export const claudeCodeHarness = {
|
|
33
36
|
id: "claude-code",
|
|
34
|
-
|
|
37
|
+
// 2: parseOutcome now falls back to the last streamed `assistant` message's text/usage when a
|
|
38
|
+
// `result` event never arrives (timeout/cancel kill the process before claude-code emits one) —
|
|
39
|
+
// `op=show` can use this to distinguish "adapter is stale" from "the agent itself crashed".
|
|
40
|
+
parserVersion: 2,
|
|
35
41
|
buildInvocation(input) {
|
|
36
42
|
if (input.argv.length === 0) {
|
|
37
43
|
throw new Error("claude-code: command produced no argv tokens");
|
|
@@ -82,6 +88,12 @@ export const claudeCodeHarness = {
|
|
|
82
88
|
let costKnown = false;
|
|
83
89
|
let costTotal;
|
|
84
90
|
let parsedAnyLine = false;
|
|
91
|
+
// Fallback only: a run killed by timeout/cancel never gets a `result` event, so without this
|
|
92
|
+
// a fully productive 90-minute run reports empty text and zero usage (D-review §1.2). Neither
|
|
93
|
+
// of these ever sets `terminalSeen`/`protocolStatus` — only a real `result` event may do that;
|
|
94
|
+
// streamed text is not proof the run finished.
|
|
95
|
+
let lastAssistantText = "";
|
|
96
|
+
let streamedUsage;
|
|
85
97
|
for (const line of input.eventsText.split("\n")) {
|
|
86
98
|
const trimmed = line.trim();
|
|
87
99
|
if (!trimmed)
|
|
@@ -138,12 +150,40 @@ export const claudeCodeHarness = {
|
|
|
138
150
|
usageKnown = true;
|
|
139
151
|
}
|
|
140
152
|
}
|
|
153
|
+
if (record.type === "assistant") {
|
|
154
|
+
const message = record.message;
|
|
155
|
+
if (isRecord(message)) {
|
|
156
|
+
const parts = Array.isArray(message.content) ? message.content : [];
|
|
157
|
+
const text = parts
|
|
158
|
+
.filter((part) => isRecord(part) && part.type === "text" && typeof part.text === "string")
|
|
159
|
+
.map((part) => part.text)
|
|
160
|
+
.join("");
|
|
161
|
+
if (text.trim())
|
|
162
|
+
lastAssistantText = text;
|
|
163
|
+
const rawUsage = message.usage;
|
|
164
|
+
if (isRecord(rawUsage)) {
|
|
165
|
+
streamedUsage = {
|
|
166
|
+
input: Number(rawUsage.input_tokens ?? 0) || 0,
|
|
167
|
+
output: Number(rawUsage.output_tokens ?? 0) || 0,
|
|
168
|
+
cacheRead: Number(rawUsage.cache_read_input_tokens ?? 0) || 0,
|
|
169
|
+
cacheWrite: Number(rawUsage.cache_creation_input_tokens ?? 0) || 0,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
141
174
|
}
|
|
142
175
|
if (!parsedAnyLine && input.eventsText.trim()) {
|
|
143
176
|
protocolStatus = "unparsable";
|
|
144
177
|
}
|
|
178
|
+
if (!terminalSeen && !usageKnown && streamedUsage) {
|
|
179
|
+
usage = {
|
|
180
|
+
...streamedUsage,
|
|
181
|
+
total: streamedUsage.input + streamedUsage.output + streamedUsage.cacheRead + streamedUsage.cacheWrite,
|
|
182
|
+
};
|
|
183
|
+
usageKnown = true;
|
|
184
|
+
}
|
|
145
185
|
return {
|
|
146
|
-
finalText,
|
|
186
|
+
finalText: finalText || lastAssistantText,
|
|
147
187
|
terminalSeen,
|
|
148
188
|
protocolStatus,
|
|
149
189
|
exitCode: input.exitCode,
|