@oyasmi/pipiclaw 0.9.1-beta.2 → 0.9.2-beta.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 +9 -1
- package/dist/agent/channel-runner.js +51 -18
- 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/effect-ledger.js +9 -2
- package/dist/agent/job-manager.d.ts +4 -0
- package/dist/agent/job-manager.js +17 -2
- package/dist/agent/prompt/manifest.d.ts +1 -1
- package/dist/agent/prompt/manifest.js +6 -7
- package/dist/agent/prompt/sections.js +9 -5
- package/dist/agent/reply-limits.d.ts +16 -0
- package/dist/agent/reply-limits.js +17 -0
- package/dist/agent/session-events.d.ts +2 -0
- package/dist/agent/session-events.js +29 -14
- package/dist/agent/status-render.js +12 -12
- package/dist/agent/turn-recovery.js +2 -2
- package/dist/agent/type-guards.js +5 -1
- package/dist/agent/workspace-resources.d.ts +2 -2
- package/dist/agent/workspace-resources.js +41 -3
- package/dist/executor.d.ts +28 -0
- package/dist/executor.js +120 -18
- package/dist/file-store.d.ts +96 -0
- package/dist/file-store.js +189 -0
- 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 +35 -38
- 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 +31 -12
- package/dist/memory/lifecycle.js +9 -2
- package/dist/memory/maintenance-jobs.js +16 -38
- package/dist/memory/maintenance-state.js +2 -1
- package/dist/memory/metadata.d.ts +3 -0
- package/dist/memory/metadata.js +7 -0
- package/dist/memory/recall.d.ts +19 -0
- package/dist/memory/recall.js +116 -24
- 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 +15 -22
- 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/memory/transcript.d.ts +10 -0
- package/dist/memory/transcript.js +39 -0
- package/dist/playbooks/agent-delegation.md +34 -25
- package/dist/playbooks/background-jobs.md +8 -16
- package/dist/playbooks/catalog.d.ts +1 -1
- package/dist/playbooks/catalog.js +1 -1
- package/dist/playbooks/event-scheduling.md +15 -15
- package/dist/playbooks/memory-and-learning.md +30 -23
- package/dist/playbooks/outbound-media.md +15 -8
- package/dist/playbooks/runtime-orientation.md +40 -37
- package/dist/playbooks/task-driving.md +36 -38
- package/dist/playbooks/task-planning.md +21 -21
- package/dist/runtime/app-home.d.ts +6 -0
- package/dist/runtime/app-home.js +16 -7
- package/dist/runtime/bootstrap.js +54 -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 +30 -15
- package/dist/runtime/durable-dispatch.d.ts +26 -1
- package/dist/runtime/durable-dispatch.js +51 -5
- package/dist/runtime/event-commands.d.ts +15 -0
- package/dist/runtime/event-commands.js +55 -56
- package/dist/runtime/events.d.ts +4 -2
- package/dist/runtime/events.js +15 -20
- 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 +108 -66
- package/dist/runtime/task-driver.js +2 -2
- package/dist/security/block-message.d.ts +11 -0
- package/dist/security/block-message.js +12 -0
- package/dist/security/path-guard-check.d.ts +13 -0
- package/dist/security/path-guard-check.js +39 -0
- package/dist/security/path-guard.js +61 -12
- package/dist/security/types.d.ts +9 -0
- package/dist/settings.js +3 -2
- package/dist/shared/atomic-file.d.ts +17 -1
- package/dist/shared/atomic-file.js +50 -3
- package/dist/shared/duration.d.ts +2 -0
- package/dist/shared/duration.js +7 -0
- package/dist/shared/safe-id.d.ts +19 -0
- package/dist/shared/safe-id.js +24 -0
- package/dist/shared/text-utils.d.ts +1 -1
- package/dist/shared/text-utils.js +3 -8
- package/dist/shared/type-guards.d.ts +2 -0
- package/dist/shared/type-guards.js +4 -0
- package/dist/subagents/discovery.d.ts +51 -19
- package/dist/subagents/discovery.js +93 -98
- package/dist/subagents/external/claude-code.js +40 -2
- package/dist/subagents/external/harness.d.ts +1 -1
- package/dist/subagents/external/run.js +61 -8
- package/dist/subagents/format.d.ts +3 -2
- package/dist/subagents/format.js +3 -7
- package/dist/subagents/runs.d.ts +1 -1
- package/dist/subagents/runs.js +10 -9
- package/dist/subagents/tool.d.ts +31 -18
- package/dist/subagents/tool.js +592 -562
- package/dist/subagents/workspace-lease.js +1 -1
- package/dist/tasks/control.js +7 -9
- package/dist/tasks/ledger.d.ts +2 -2
- package/dist/tasks/ledger.js +3 -7
- package/dist/tasks/transitions.d.ts +5 -1
- package/dist/tasks/transitions.js +2 -2
- package/dist/tasks/verification.d.ts +7 -5
- package/dist/tools/bash.d.ts +1 -2
- package/dist/tools/bash.js +99 -76
- package/dist/tools/config.d.ts +6 -1
- package/dist/tools/config.js +9 -0
- package/dist/tools/edit.d.ts +2 -3
- package/dist/tools/edit.js +276 -75
- package/dist/tools/event-manage.d.ts +13 -7
- package/dist/tools/event-manage.js +52 -14
- package/dist/tools/glob-match.d.ts +11 -0
- package/dist/tools/glob-match.js +75 -0
- package/dist/tools/glob.d.ts +15 -0
- package/dist/tools/glob.js +113 -0
- package/dist/tools/grep.d.ts +0 -1
- package/dist/tools/grep.js +60 -44
- package/dist/tools/ignore-dirs.d.ts +6 -0
- package/dist/tools/ignore-dirs.js +15 -0
- package/dist/tools/index.d.ts +3 -0
- package/dist/tools/index.js +54 -40
- package/dist/tools/job.d.ts +0 -1
- package/dist/tools/job.js +3 -9
- package/dist/tools/line-index.d.ts +16 -0
- package/dist/tools/line-index.js +76 -0
- package/dist/tools/memory-manage.d.ts +21 -8
- package/dist/tools/memory-manage.js +114 -103
- package/dist/tools/presentation.d.ts +2 -0
- package/dist/tools/presentation.js +109 -0
- package/dist/tools/read.d.ts +2 -2
- package/dist/tools/read.js +100 -120
- package/dist/tools/registry.d.ts +4 -1
- package/dist/tools/registry.js +89 -22
- package/dist/tools/send-media.d.ts +6 -6
- package/dist/tools/send-media.js +21 -43
- package/dist/tools/session-search.d.ts +0 -1
- package/dist/tools/session-search.js +0 -1
- package/dist/tools/skill-security.d.ts +0 -2
- package/dist/tools/skill-security.js +1 -25
- package/dist/tools/skill.d.ts +31 -0
- package/dist/tools/skill.js +153 -0
- package/dist/tools/subagent-manage.d.ts +6 -5
- package/dist/tools/subagent-manage.js +47 -47
- package/dist/tools/task-manage/create.d.ts +2 -2
- package/dist/tools/task-manage/create.js +1 -3
- package/dist/tools/task-manage/lifecycle.d.ts +9 -6
- package/dist/tools/task-manage/lifecycle.js +49 -56
- package/dist/tools/task-manage/schema.d.ts +27 -15
- package/dist/tools/task-manage/schema.js +58 -74
- package/dist/tools/task-manage/shared.d.ts +11 -6
- package/dist/tools/task-manage/shared.js +30 -21
- package/dist/tools/task-manage/types.d.ts +14 -15
- package/dist/tools/task-manage/verification.d.ts +4 -4
- package/dist/tools/task-manage/verification.js +6 -8
- package/dist/tools/task-manage.d.ts +8 -11
- package/dist/tools/task-manage.js +63 -50
- package/dist/tools/tool-details.d.ts +17 -1
- package/dist/tools/tool-details.js +24 -0
- package/dist/tools/truncate.d.ts +8 -0
- package/dist/tools/truncate.js +8 -0
- package/dist/tools/web-fetch.d.ts +0 -1
- package/dist/tools/web-fetch.js +9 -2
- package/dist/tools/web-search.d.ts +0 -1
- package/dist/tools/web-search.js +0 -1
- package/dist/tools/write-content.d.ts +3 -3
- package/dist/tools/write-content.js +12 -41
- package/dist/tools/write.d.ts +2 -3
- package/dist/tools/write.js +3 -4
- 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/ledger.js +7 -4
- package/dist/usage/render.js +10 -8
- package/examples/sub-agents/README.md +2 -0
- package/package.json +3 -2
- package/dist/tools/skill-manage.d.ts +0 -41
- package/dist/tools/skill-manage.js +0 -231
|
@@ -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";
|
|
@@ -19,25 +21,19 @@ import { parseScheduledEventContent } from "./events.js";
|
|
|
19
21
|
*
|
|
20
22
|
* Deliberately a small, flat set: the ones a user already knows they want to change (when it
|
|
21
23
|
* should wake, what it should do next, how much rope it has). Everything structural — status
|
|
22
|
-
* transitions and verification — stays with `
|
|
24
|
+
* transitions and verification — stays with `task_update`/`task_close`/`task_verify`, whose state
|
|
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);
|
|
@@ -248,7 +279,7 @@ export async function resumeTask(options, idInput) {
|
|
|
248
279
|
* The alternative — telling the model "change wake to tomorrow 9am" — costs a whole turn and its
|
|
249
280
|
* tokens to reach the same one-line write. Validation is not re-implemented here: `wake` reuses
|
|
250
281
|
* the shared local-time parser (accepting a local timestamp or a relative offset like `+2h`) and
|
|
251
|
-
* everything else goes through `applyTaskControlPatch`, the same function `
|
|
282
|
+
* everything else goes through `applyTaskControlPatch`, the same function `task_update` (no note) uses,
|
|
252
283
|
* so the two entry points cannot drift apart.
|
|
253
284
|
*/
|
|
254
285
|
async function setTaskField(options, idInput, field, value) {
|
|
@@ -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_update(不带 note)或直接修复那一行 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_update(不带 note)修复 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_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_update(不带 note)写一条合法的 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_close outcome=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_update 把它改成 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_update 把 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_update 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;
|
|
@@ -143,8 +143,8 @@ export function createTaskDriverEvent(channelId, entry, nowMs) {
|
|
|
143
143
|
(repairOnly
|
|
144
144
|
? "After the metadata is repaired, leave task work for a later wake. "
|
|
145
145
|
: "Advance the next concrete step under the task's current goal, control, acceptance, and verification state. ") +
|
|
146
|
-
`If complete or waiting, use the matching
|
|
147
|
-
"For a recurring occurrence intentionally not run because it is duplicate or already satisfied, call
|
|
146
|
+
`If complete or waiting, use the matching task_close/task_update action from the playbook. ` +
|
|
147
|
+
"For a recurring occurrence intentionally not run because it is duplicate or already satisfied, call task_close outcome=skip with the reason, then respond with exactly [SILENT]. " +
|
|
148
148
|
"If no task state or tool action is needed and this wake produces no user-visible result, respond with exactly [SILENT].",
|
|
149
149
|
ts: String(nowMs),
|
|
150
150
|
conversationType: channelId.startsWith("group_") ? "2" : "1",
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** One `Label: value` line in a security-guard block message. */
|
|
2
|
+
export interface BlockMessageDetail {
|
|
3
|
+
label: string;
|
|
4
|
+
value: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Shared scaffold for a guard's user/model-facing block message: `"<Subject> blocked [category]"`
|
|
8
|
+
* followed by one line per detail. Used by both the path guard and the command guard so their
|
|
9
|
+
* wording does not drift line by line as each grows its own detail set.
|
|
10
|
+
*/
|
|
11
|
+
export declare function formatBlockMessage(subject: string, category: string | undefined, details: BlockMessageDetail[]): string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared scaffold for a guard's user/model-facing block message: `"<Subject> blocked [category]"`
|
|
3
|
+
* followed by one line per detail. Used by both the path guard and the command guard so their
|
|
4
|
+
* wording does not drift line by line as each grows its own detail set.
|
|
5
|
+
*/
|
|
6
|
+
export function formatBlockMessage(subject, category, details) {
|
|
7
|
+
const lines = [`${subject} blocked${category ? ` [${category}]` : ""}`];
|
|
8
|
+
for (const detail of details) {
|
|
9
|
+
lines.push(`${detail.label}: ${detail.value}`);
|
|
10
|
+
}
|
|
11
|
+
return lines.join("\n");
|
|
12
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SecurityConfig, SecurityRuntimeContext } from "./types.js";
|
|
2
|
+
export interface PathGuardCheckOptions {
|
|
3
|
+
tool: string;
|
|
4
|
+
channelId?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Run the path guard and return the single resolved path every file tool must operate on from
|
|
8
|
+
* here on (spec 044, D1.1) -- what the guard judged and what `FileStore`/`Executor` actually opens
|
|
9
|
+
* are the same value by construction, never re-derived. Always returns a `resolvedPath`, including
|
|
10
|
+
* when `security.json` has the guard disabled: resolution is normalization, not policy, so turning
|
|
11
|
+
* the guard off must not be the one case where a tool falls back to an unresolved raw path.
|
|
12
|
+
*/
|
|
13
|
+
export declare function checkPathGuard(rawPath: string, operation: "read" | "write", securityConfig: SecurityConfig, securityContext: SecurityRuntimeContext, options: PathGuardCheckOptions): Promise<string>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { formatBlockMessage } from "./block-message.js";
|
|
2
|
+
import { logSecurityEvent } from "./logger.js";
|
|
3
|
+
import { guardPath } from "./path-guard.js";
|
|
4
|
+
function formatPathBlockMessage(resolvedPath, category, reason) {
|
|
5
|
+
const details = [];
|
|
6
|
+
if (reason)
|
|
7
|
+
details.push({ label: "Reason", value: reason });
|
|
8
|
+
if (resolvedPath)
|
|
9
|
+
details.push({ label: "Resolved path", value: resolvedPath });
|
|
10
|
+
return formatBlockMessage("Path", category, details);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Run the path guard and return the single resolved path every file tool must operate on from
|
|
14
|
+
* here on (spec 044, D1.1) -- what the guard judged and what `FileStore`/`Executor` actually opens
|
|
15
|
+
* are the same value by construction, never re-derived. Always returns a `resolvedPath`, including
|
|
16
|
+
* when `security.json` has the guard disabled: resolution is normalization, not policy, so turning
|
|
17
|
+
* the guard off must not be the one case where a tool falls back to an unresolved raw path.
|
|
18
|
+
*/
|
|
19
|
+
export async function checkPathGuard(rawPath, operation, securityConfig, securityContext, options) {
|
|
20
|
+
const effectiveConfig = securityConfig.enabled
|
|
21
|
+
? securityConfig.pathGuard
|
|
22
|
+
: { ...securityConfig.pathGuard, enabled: false };
|
|
23
|
+
const guardResult = guardPath(rawPath, operation, { ...securityContext, config: effectiveConfig });
|
|
24
|
+
if (!guardResult.allowed) {
|
|
25
|
+
await logSecurityEvent(securityContext.agentWorkspaceDir, securityConfig, {
|
|
26
|
+
type: "path",
|
|
27
|
+
tool: options.tool,
|
|
28
|
+
channelId: options.channelId,
|
|
29
|
+
rawPath,
|
|
30
|
+
operation,
|
|
31
|
+
resolvedPath: guardResult.resolvedPath,
|
|
32
|
+
category: guardResult.category,
|
|
33
|
+
reason: guardResult.reason,
|
|
34
|
+
});
|
|
35
|
+
throw new Error(formatPathBlockMessage(guardResult.resolvedPath, guardResult.category, guardResult.reason));
|
|
36
|
+
}
|
|
37
|
+
// `guardPath` always populates `resolvedPath` on an allowed result (see D1.1 above).
|
|
38
|
+
return guardResult.resolvedPath;
|
|
39
|
+
}
|
|
@@ -124,9 +124,24 @@ function resolveForGuard(path, ctx) {
|
|
|
124
124
|
if (existsSync(normalized)) {
|
|
125
125
|
return realpathSync(normalized);
|
|
126
126
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
127
|
+
// Walk up to the nearest existing ancestor, remembering every missing path segment along the
|
|
128
|
+
// way, then reattach them onto that ancestor's realpath (spec 044: a file tool's real write
|
|
129
|
+
// target is now this resolved path, not a raw `mkdir -p`'d one, so this has to be exact). A
|
|
130
|
+
// naive "existing ancestor + basename" only handles a single missing directory level -- writing
|
|
131
|
+
// `a/b/c.txt` where neither `a` nor `a/b` exist yet used to silently drop the `a/b` segment and
|
|
132
|
+
// resolve to `<ancestor>/c.txt` instead of `<ancestor>/a/b/c.txt`.
|
|
133
|
+
const missingSegments = [];
|
|
134
|
+
let current = normalized;
|
|
135
|
+
while (!existsSync(current)) {
|
|
136
|
+
missingSegments.unshift(basename(current));
|
|
137
|
+
const parent = dirname(current);
|
|
138
|
+
if (parent === current) {
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
current = parent;
|
|
142
|
+
}
|
|
143
|
+
const ancestorRealPath = existsSync(current) ? realpathSync(current) : current;
|
|
144
|
+
return resolve(ancestorRealPath, ...missingSegments);
|
|
130
145
|
}
|
|
131
146
|
function matchesAnyPath(path, exactPaths, prefixes) {
|
|
132
147
|
return exactPaths.includes(path) || prefixes.some((prefix) => startsWithPathPrefix(path, prefix));
|
|
@@ -215,14 +230,36 @@ function isWithinProjectRoot(path, ctx) {
|
|
|
215
230
|
}
|
|
216
231
|
return startsWithPathPrefix(path, normalize(root));
|
|
217
232
|
}
|
|
218
|
-
/** Runtime-owned
|
|
219
|
-
* `boundary: "project"`
|
|
220
|
-
*
|
|
221
|
-
|
|
222
|
-
|
|
233
|
+
/** Runtime-owned exception: the AgentWorkspace's `skills/` tree stays reachable under
|
|
234
|
+
* `boundary: "project"` regardless of which project is selected (spec 043, D6.2) -- reads so the
|
|
235
|
+
* model can load a skill's playbook, and writes so `write`/`edit` can author one (the `skill` tool
|
|
236
|
+
* itself is read-only; authoring goes through the generic file tools). The symlink-write check
|
|
237
|
+
* above this call in `guardPath` still applies, so a skill file that is itself a symlink cannot be
|
|
238
|
+
* written through even inside this exception. */
|
|
239
|
+
function isAgentWorkspaceSkillsAccess(path, ctx) {
|
|
240
|
+
return startsWithPathPrefix(path, normalize(join(ctx.agentWorkspaceDir, "skills")));
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Runtime-owned exception for the channel's own directory, in the same spirit as `skills/`: spec
|
|
244
|
+
* 043's D5 puts `SESSION.md`, channel `MEMORY.md`, `HISTORY.md` and `tasks/` in the AgentWorkspace
|
|
245
|
+
* precisely so a channel keeps its continuity across project switches — but D6.2's project bound
|
|
246
|
+
* then put them outside every allowed root, so a task wake could tell the model to open
|
|
247
|
+
* `tasks/<id>.md` and the guard would refuse.
|
|
248
|
+
*
|
|
249
|
+
* Reads are allowed throughout. Writes are allowed only under `tasks/`: the three memory files are
|
|
250
|
+
* runtime-maintained and go through the memory tools (a file write there races the maintenance
|
|
251
|
+
* queue), while a task's body is model-authored prose that `task_update` cannot rewrite — it
|
|
252
|
+
* replaces frontmatter and keeps the body verbatim, so revising a task contract needs `edit`.
|
|
253
|
+
*/
|
|
254
|
+
function isChannelDirAccess(path, operation, ctx) {
|
|
255
|
+
if (!ctx.channelDir) {
|
|
223
256
|
return false;
|
|
224
257
|
}
|
|
225
|
-
|
|
258
|
+
const channelDir = normalize(ctx.channelDir);
|
|
259
|
+
if (!startsWithPathPrefix(path, channelDir)) {
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
return operation === "read" || startsWithPathPrefix(path, normalize(join(channelDir, "tasks")));
|
|
226
263
|
}
|
|
227
264
|
function isDeniedSystemPath(path) {
|
|
228
265
|
if (isWithinTemp(path)) {
|
|
@@ -262,7 +299,10 @@ function formatBlockedResult(operation, rawPath, resolvedPath, category, reason)
|
|
|
262
299
|
}
|
|
263
300
|
export function guardPath(rawPath, operation, ctx) {
|
|
264
301
|
if (!ctx.config.enabled) {
|
|
265
|
-
|
|
302
|
+
// Resolution is normalization, not policy, so `resolvedPath` stays populated even with the
|
|
303
|
+
// guard off (spec 044, D1.1): callers rely on it being the one path every file tool actually
|
|
304
|
+
// opens, and a guard-disabled deployment must not be the one case that breaks that invariant.
|
|
305
|
+
return { allowed: true, operation, rawPath, resolvedPath: resolveForGuard(resolveTargetPath(rawPath, ctx), ctx) };
|
|
266
306
|
}
|
|
267
307
|
const homeDir = ctx.homeDir ?? homedir();
|
|
268
308
|
const effectiveCtx = {
|
|
@@ -270,6 +310,7 @@ export function guardPath(rawPath, operation, ctx) {
|
|
|
270
310
|
agentWorkspaceDir: resolveRootForGuard(ctx.agentWorkspaceDir, ctx),
|
|
271
311
|
homeDir: resolveRootForGuard(homeDir, ctx),
|
|
272
312
|
projectRoot: ctx.projectRoot ? resolveRootForGuard(ctx.projectRoot, ctx) : ctx.projectRoot,
|
|
313
|
+
channelDir: ctx.channelDir ? resolveRootForGuard(ctx.channelDir, ctx) : ctx.channelDir,
|
|
273
314
|
};
|
|
274
315
|
const resolvedTarget = resolveTargetPath(rawPath, ctx);
|
|
275
316
|
const guardedPath = resolveForGuard(resolvedTarget, ctx);
|
|
@@ -300,11 +341,19 @@ export function guardPath(rawPath, operation, ctx) {
|
|
|
300
341
|
}
|
|
301
342
|
if (pathAllowedByDefaults(guardedPath, effectiveCtx) ||
|
|
302
343
|
isBundledPlaybookRead(guardedPath, operation) ||
|
|
303
|
-
|
|
344
|
+
isAgentWorkspaceSkillsAccess(guardedPath, effectiveCtx) ||
|
|
345
|
+
isChannelDirAccess(guardedPath, operation, effectiveCtx)) {
|
|
304
346
|
return { allowed: true, operation, rawPath, resolvedPath: guardedPath };
|
|
305
347
|
}
|
|
306
348
|
if (isDeniedSystemPath(guardedPath)) {
|
|
307
349
|
return formatBlockedResult(operation, rawPath, guardedPath, "system-path", `${operation === "read" ? "Reading" : "Writing"} system paths is not allowed by default`);
|
|
308
350
|
}
|
|
309
|
-
|
|
351
|
+
// The reason names the roots that are actually in effect. Under `boundary: "project"` the
|
|
352
|
+
// generic wording ("outside workspace, home, and temp") is worse than unhelpful: workspace and
|
|
353
|
+
// home are themselves out of bounds there, so a model taking it at face value retries against a
|
|
354
|
+
// path that can never be allowed.
|
|
355
|
+
const verb = operation === "read" ? "Reading" : "Writing";
|
|
356
|
+
return formatBlockedResult(operation, rawPath, guardedPath, "outside-allowed-roots", effectiveCtx.boundary === "project"
|
|
357
|
+
? `${verb} outside the current project root (${effectiveCtx.projectRoot ?? "unset"}) is not allowed`
|
|
358
|
+
: `${verb} outside workspace, home, and temp paths is not allowed`);
|
|
310
359
|
}
|
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 {
|
package/dist/settings.js
CHANGED
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This module currently provides only PipiclawSettingsManager.
|
|
8
8
|
*/
|
|
9
|
-
import { existsSync, mkdirSync, readFileSync
|
|
9
|
+
import { existsSync, mkdirSync, readFileSync } from "fs";
|
|
10
10
|
import { dirname, join } from "path";
|
|
11
11
|
import * as log from "./log.js";
|
|
12
12
|
import { getMemoryMaintenanceTuning, getSessionRefreshCadence, } from "./memory/maintenance-tuning.js";
|
|
13
|
+
import { writeFileAtomicallySync } from "./shared/atomic-file.js";
|
|
13
14
|
import { fileStamp } from "./shared/file-stamp.js";
|
|
14
15
|
const DEFAULT_TUI = {
|
|
15
16
|
responseMode: "full_progress_then_plain_final",
|
|
@@ -178,7 +179,7 @@ export class PipiclawSettingsManager {
|
|
|
178
179
|
if (!existsSync(dir)) {
|
|
179
180
|
mkdirSync(dir, { recursive: true });
|
|
180
181
|
}
|
|
181
|
-
|
|
182
|
+
writeFileAtomicallySync(this.settingsPath, JSON.stringify(this.settings, null, 2));
|
|
182
183
|
}
|
|
183
184
|
catch (error) {
|
|
184
185
|
log.logWarning(`Could not save settings file`, `${this.settingsPath}\n${String(error)}`);
|