@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.
Files changed (92) hide show
  1. package/dist/agent/channel-runner.d.ts +7 -0
  2. package/dist/agent/channel-runner.js +42 -13
  3. package/dist/agent/command-extension.js +24 -27
  4. package/dist/agent/commands.d.ts +51 -7
  5. package/dist/agent/commands.js +199 -59
  6. package/dist/agent/prompt/manifest.js +5 -6
  7. package/dist/agent/prompt/sections.js +1 -0
  8. package/dist/agent/reply-limits.d.ts +16 -0
  9. package/dist/agent/reply-limits.js +17 -0
  10. package/dist/agent/session-events.js +2 -2
  11. package/dist/agent/status-render.js +12 -12
  12. package/dist/executor.d.ts +14 -0
  13. package/dist/executor.js +36 -6
  14. package/dist/main.js +3 -4
  15. package/dist/memory/commands.js +79 -38
  16. package/dist/memory/consolidation.d.ts +5 -1
  17. package/dist/memory/consolidation.js +33 -12
  18. package/dist/memory/extraction.d.ts +8 -1
  19. package/dist/memory/extraction.js +47 -4
  20. package/dist/memory/files.d.ts +0 -1
  21. package/dist/memory/files.js +24 -5
  22. package/dist/memory/lifecycle.js +9 -2
  23. package/dist/memory/maintenance-jobs.js +14 -4
  24. package/dist/memory/metadata.d.ts +3 -0
  25. package/dist/memory/metadata.js +7 -0
  26. package/dist/memory/recall.d.ts +9 -0
  27. package/dist/memory/recall.js +101 -17
  28. package/dist/memory/review-log.d.ts +0 -2
  29. package/dist/memory/review-log.js +0 -0
  30. package/dist/memory/session-corpus.js +5 -0
  31. package/dist/memory/session-search.js +9 -0
  32. package/dist/memory/sidecar-worker.js +4 -0
  33. package/dist/memory/source-window.d.ts +0 -1
  34. package/dist/memory/source-window.js +0 -5
  35. package/dist/playbooks/agent-delegation.md +32 -25
  36. package/dist/playbooks/background-jobs.md +8 -16
  37. package/dist/playbooks/event-scheduling.md +13 -15
  38. package/dist/playbooks/memory-and-learning.md +29 -22
  39. package/dist/playbooks/outbound-media.md +15 -8
  40. package/dist/playbooks/runtime-orientation.md +40 -37
  41. package/dist/playbooks/task-driving.md +34 -36
  42. package/dist/playbooks/task-planning.md +18 -18
  43. package/dist/runtime/app-home.d.ts +6 -0
  44. package/dist/runtime/app-home.js +15 -6
  45. package/dist/runtime/bootstrap.js +44 -13
  46. package/dist/runtime/channel-context.d.ts +2 -1
  47. package/dist/runtime/delivery.js +3 -3
  48. package/dist/runtime/dingtalk.d.ts +9 -1
  49. package/dist/runtime/dingtalk.js +27 -13
  50. package/dist/runtime/event-commands.d.ts +15 -0
  51. package/dist/runtime/event-commands.js +48 -40
  52. package/dist/runtime/project-commands.d.ts +16 -0
  53. package/dist/runtime/project-commands.js +13 -17
  54. package/dist/runtime/subagent-commands.d.ts +20 -0
  55. package/dist/runtime/subagent-commands.js +61 -58
  56. package/dist/runtime/task-commands.d.ts +37 -0
  57. package/dist/runtime/task-commands.js +106 -64
  58. package/dist/security/path-guard.js +33 -2
  59. package/dist/security/types.d.ts +9 -0
  60. package/dist/subagents/discovery.d.ts +7 -2
  61. package/dist/subagents/discovery.js +31 -7
  62. package/dist/subagents/external/claude-code.js +42 -2
  63. package/dist/subagents/external/run.js +61 -8
  64. package/dist/subagents/runs.js +6 -0
  65. package/dist/subagents/tool.d.ts +1 -0
  66. package/dist/subagents/tool.js +62 -53
  67. package/dist/tasks/verification.d.ts +7 -5
  68. package/dist/tools/bash.d.ts +1 -1
  69. package/dist/tools/bash.js +77 -59
  70. package/dist/tools/edit.js +17 -4
  71. package/dist/tools/grep.js +3 -2
  72. package/dist/tools/index.js +4 -0
  73. package/dist/tools/job.js +2 -1
  74. package/dist/tools/memory-manage.d.ts +1 -0
  75. package/dist/tools/memory-manage.js +54 -16
  76. package/dist/tools/read.js +21 -5
  77. package/dist/tools/send-media.js +17 -6
  78. package/dist/tools/skill-manage.js +12 -11
  79. package/dist/tools/skill-security.js +1 -1
  80. package/dist/tools/task-manage.js +1 -1
  81. package/dist/tools/truncate.d.ts +8 -0
  82. package/dist/tools/truncate.js +8 -0
  83. package/dist/tools/web-fetch.js +9 -1
  84. package/dist/tools/write-content.js +11 -1
  85. package/dist/tui/app.js +1 -1
  86. package/dist/tui/commands.d.ts +1 -1
  87. package/dist/tui/commands.js +1 -1
  88. package/dist/tui/turn-controller.d.ts +1 -1
  89. package/dist/tui/turn-controller.js +14 -4
  90. package/dist/usage/render.js +10 -8
  91. package/examples/sub-agents/README.md +2 -0
  92. package/package.json +3 -2
@@ -1,50 +1,48 @@
1
1
  import { existsSync } from "fs";
2
2
  import { readdir, readFile, unlink } from "fs/promises";
3
3
  import { join, resolve, sep } from "path";
4
+ import { renderSubcommandUsage } from "../agent/commands.js";
5
+ import { capReply } from "../agent/reply-limits.js";
4
6
  import { errorMessage, eventNameFromFilename } from "../shared/text-utils.js";
5
7
  import { parseScheduledEventContent } from "./events.js";
6
8
  const EVENT_NAME_PATTERN = /^[A-Za-z0-9._-]+$/;
7
9
  const DEFAULT_HISTORY_LIMIT = 20;
8
10
  const TEXT_PREVIEW_MAX_CHARS = 100;
9
11
  function usage() {
10
- return `# Events
11
-
12
- Usage:
13
-
14
- - \`/events list\`
15
- - \`/events show <name>\`
16
- - \`/events delete <name>\`
17
- - \`/events history [name]\``;
12
+ return renderSubcommandUsage("events");
18
13
  }
19
- function parseEventsCommand(args) {
14
+ /** Exported so `test/commands-subcommands.test.ts` can feed every broadcast example back through it. */
15
+ export function parseEventsCommand(args) {
20
16
  const parts = args.trim().split(/\s+/).filter(Boolean);
21
17
  const action = parts[0];
22
18
  const name = parts[1];
23
19
  if (!action || action === "list") {
24
20
  if (parts.length > 1)
25
- throw new Error("Usage: /events list");
21
+ throw new Error("用法:/events list");
26
22
  return { action: "list" };
27
23
  }
28
24
  if (action === "show") {
29
25
  if (!name || parts.length > 2)
30
- throw new Error("Usage: /events show <name>");
26
+ throw new Error("用法:/events show <name>");
31
27
  return { action, name };
32
28
  }
33
29
  if (action === "delete") {
34
30
  if (!name || parts.length > 2)
35
- throw new Error("Usage: /events delete <name>");
31
+ throw new Error("用法:/events delete <name>");
36
32
  return { action, name };
37
33
  }
38
34
  if (action === "history") {
39
35
  if (parts.length > 2)
40
- throw new Error("Usage: /events history [name]");
36
+ throw new Error("用法:/events history [name]");
41
37
  return name ? { action, name } : { action };
42
38
  }
43
- throw new Error(`Unknown /events action: ${action}`);
39
+ throw new Error(`未知的 /events 动作:${action}`);
44
40
  }
45
41
  function eventsDir(workspaceDir) {
46
42
  return join(workspaceDir, "events");
47
43
  }
44
+ // English on purpose: shared with the model-facing `event_manage` tool (src/tools/event-manage.ts),
45
+ // which follows the tool-error convention elsewhere in the codebase, not the command-reply one.
48
46
  export function normalizeEventName(name) {
49
47
  const trimmed = name.trim();
50
48
  const normalized = trimmed.endsWith(".json") ? trimmed.slice(0, -".json".length) : trimmed;
@@ -67,24 +65,24 @@ function clipText(text, maxChars = TEXT_PREVIEW_MAX_CHARS) {
67
65
  return normalized.length > maxChars ? `${normalized.slice(0, maxChars - 1)}...` : normalized;
68
66
  }
69
67
  function formatEventSummary(name, event) {
70
- const lines = [`- ${name}`, ` type: ${event.type}`, ` channelId: ${event.channelId}`];
68
+ const lines = [`**${name}**`, `- 类型:${event.type}`, `- channelId:${event.channelId}`];
71
69
  if (event.type === "one-shot") {
72
- lines.push(` at: ${event.at}`);
70
+ lines.push(`- 触发时间:${event.at}`);
73
71
  }
74
72
  if (event.type === "periodic") {
75
- lines.push(` schedule: ${event.schedule}`);
73
+ lines.push(`- schedule:${event.schedule}`);
76
74
  }
77
- lines.push(` text: ${clipText(event.text)}`);
75
+ lines.push(`- 内容:${clipText(event.text)}`);
78
76
  return lines.join("\n");
79
77
  }
80
78
  async function listEvents(workspaceDir) {
81
79
  const dir = eventsDir(workspaceDir);
82
80
  if (!existsSync(dir)) {
83
- return "# Events\n\nNo events directory found.";
81
+ return "**定时事件**\n\n没有找到 events 目录。";
84
82
  }
85
83
  const filenames = (await readdir(dir)).filter((filename) => filename.endsWith(".json")).sort();
86
84
  if (filenames.length === 0) {
87
- return "# Events\n\nNo event files found.";
85
+ return "**定时事件**\n\n暂无事件文件。";
88
86
  }
89
87
  const blocks = [];
90
88
  for (const filename of filenames) {
@@ -96,19 +94,21 @@ async function listEvents(workspaceDir) {
96
94
  }
97
95
  catch (error) {
98
96
  const message = errorMessage(error);
99
- blocks.push(`- ${name}\n invalid: ${message}`);
97
+ blocks.push(`**${name}**\n- ⚠ 无效:${message}`);
100
98
  }
101
99
  }
102
- return `# Events\n\n${blocks.join("\n\n")}`;
100
+ return capReply(`**定时事件**\n\n${blocks.join("\n\n")}`, {
101
+ nextStepHint: "用 `/events show <name>` 查看单个事件",
102
+ }).text;
103
103
  }
104
104
  async function showEvent(workspaceDir, name) {
105
105
  const { eventName, eventPath } = resolveEventPath(workspaceDir, name);
106
106
  if (!existsSync(eventPath)) {
107
- return `Event not found: ${eventName}`;
107
+ return `找不到事件:${eventName}`;
108
108
  }
109
109
  const raw = await readFile(eventPath, "utf-8");
110
110
  const parsed = JSON.parse(raw);
111
- return `# Event: ${eventName}
111
+ return `**事件 ${eventName}**
112
112
 
113
113
  \`\`\`json
114
114
  ${JSON.stringify(parsed, null, 2)}
@@ -117,10 +117,20 @@ ${JSON.stringify(parsed, null, 2)}
117
117
  async function deleteEvent(workspaceDir, name) {
118
118
  const { eventName, eventPath } = resolveEventPath(workspaceDir, name);
119
119
  if (!existsSync(eventPath)) {
120
- return `Event not found: ${eventName}`;
120
+ return `找不到事件:${eventName}`;
121
+ }
122
+ // Read before deleting so the reply carries what was removed (review 2026-08-24 §3.4):
123
+ // an accidental delete stays recoverable from chat history instead of a bare confirmation.
124
+ let summary;
125
+ try {
126
+ const event = parseScheduledEventContent(await readFile(eventPath, "utf-8"), `${eventName}.json`);
127
+ summary = formatEventSummary(eventName, event);
128
+ }
129
+ catch {
130
+ // Unparseable content is still safe to delete; just skip the summary.
121
131
  }
122
132
  await unlink(eventPath);
123
- return `Deleted event: ${eventName}`;
133
+ return summary ? `已删除事件:\n\n${summary}` : `已删除事件:${eventName}`;
124
134
  }
125
135
  function parseHistoryLine(line) {
126
136
  try {
@@ -137,24 +147,24 @@ function parseHistoryLine(line) {
137
147
  function formatHistoryRecord(record) {
138
148
  const details = [];
139
149
  if (record.channelId)
140
- details.push(` channelId: ${record.channelId}`);
150
+ details.push(`- channelId:${record.channelId}`);
141
151
  if (record.schedule)
142
- details.push(` schedule: ${record.schedule}`);
152
+ details.push(`- schedule:${record.schedule}`);
143
153
  if (record.at)
144
- details.push(` at: ${record.at}`);
154
+ details.push(`- 触发时间:${record.at}`);
145
155
  if (record.nextRunAt)
146
- details.push(` nextRunAt: ${record.nextRunAt}`);
156
+ details.push(`- 下次运行:${record.nextRunAt}`);
147
157
  if (record.reason)
148
- details.push(` reason: ${record.reason}`);
158
+ details.push(`- 原因:${record.reason}`);
149
159
  if (record.textPreview)
150
- details.push(` text: ${clipText(record.textPreview)}`);
151
- const header = `- ${record.ts} ${record.eventName} ${record.action} ${record.result}`;
160
+ details.push(`- 内容:${clipText(record.textPreview)}`);
161
+ const header = `**${record.ts} ${record.eventName}** ${record.action} · ${record.result}`;
152
162
  return details.length > 0 ? `${header}\n${details.join("\n")}` : header;
153
163
  }
154
164
  async function showHistory(historyPath, name) {
155
165
  const eventName = name ? normalizeEventName(name) : undefined;
156
166
  if (!existsSync(historyPath)) {
157
- return "# Event History\n\nNo event history found.";
167
+ return "**事件历史**\n\n暂无事件历史。";
158
168
  }
159
169
  const raw = await readFile(historyPath, "utf-8");
160
170
  const records = raw
@@ -167,12 +177,10 @@ async function showHistory(historyPath, name) {
167
177
  .slice(-DEFAULT_HISTORY_LIMIT)
168
178
  .reverse();
169
179
  if (records.length === 0) {
170
- return eventName
171
- ? `# Event History\n\nNo history found for event: ${eventName}`
172
- : "# Event History\n\nNo history found.";
180
+ return eventName ? `**事件历史**\n\n未找到事件 ${eventName} 的历史。` : "**事件历史**\n\n暂无事件历史。";
173
181
  }
174
- const suffix = eventName ? `: ${eventName}` : "";
175
- return `# Event History${suffix}\n\n${records.map(formatHistoryRecord).join("\n\n")}`;
182
+ const suffix = eventName ? ` · ${eventName}` : "";
183
+ return `**事件历史**${suffix}\n\n${records.map(formatHistoryRecord).join("\n\n")}`;
176
184
  }
177
185
  export async function handleEventsCommand(options) {
178
186
  let command;
@@ -197,6 +205,6 @@ export async function handleEventsCommand(options) {
197
205
  }
198
206
  catch (error) {
199
207
  const message = errorMessage(error);
200
- return `Could not ${command.action} events: ${message}`;
208
+ return `执行 /events ${command.action} 失败:${message}`;
201
209
  }
202
210
  }
@@ -1,3 +1,16 @@
1
+ /**
2
+ * `/project` — the human control path for a channel's project scope (spec 043, D7). Mirrors
3
+ * `task-commands.ts`/`subagent-commands.ts`'s shape: pure-ish functions returning markdown, no
4
+ * bot/event coupling. Mutations never reach the model.
5
+ */
6
+ type ProjectCommand = {
7
+ action: "show";
8
+ } | {
9
+ action: "set";
10
+ path: string;
11
+ } | {
12
+ action: "reset";
13
+ };
1
14
  export interface HandleProjectCommandOptions {
2
15
  args: string;
3
16
  channelId: string;
@@ -13,4 +26,7 @@ export interface HandleProjectCommandOptions {
13
26
  * and let the next access rebuild it under the new scope (D4.2). Not called on any failure path. */
14
27
  onScopeChanged?: () => Promise<void> | void;
15
28
  }
29
+ /** Exported so `test/commands-subcommands.test.ts` can feed every broadcast example back through it. */
30
+ export declare function parseProjectCommand(args: string): ProjectCommand;
16
31
  export declare function handleProjectCommand(options: HandleProjectCommandOptions): Promise<string>;
32
+ export {};
@@ -1,17 +1,13 @@
1
+ import { renderSubcommandUsage } from "../agent/commands.js";
1
2
  import { loadSecurityConfigWithDiagnostics } from "../security/config.js";
2
3
  import { currentProjectSandboxStatus, isWithinAllowedRoots, resolveExistingDirectory, resolveProjectAccessPolicy, } from "../security/project-scope.js";
3
4
  import { errorMessage } from "../shared/text-utils.js";
4
5
  import { commitProjectSelection, readProjectSelection } from "./project-scope-store.js";
5
6
  function usage() {
6
- return `# 项目作用域
7
-
8
- 用法:
9
-
10
- - \`/project\` — 查看当前频道的项目目录与访问边界
11
- - \`/project set <absolute-path>\` — 切换项目目录(需频道空闲,且目录在允许的可选根内)
12
- - \`/project reset\` — 切回 app 默认项目目录`;
7
+ return renderSubcommandUsage("project");
13
8
  }
14
- function parseProjectCommand(args) {
9
+ /** Exported so `test/commands-subcommands.test.ts` can feed every broadcast example back through it. */
10
+ export function parseProjectCommand(args) {
15
11
  const trimmed = args.trim();
16
12
  if (!trimmed)
17
13
  return { action: "show" };
@@ -33,26 +29,26 @@ function formatShow(options) {
33
29
  const resolution = resolveProjectAccessPolicy(securityLoad.config, process.cwd());
34
30
  const sandbox = currentProjectSandboxStatus();
35
31
  const selection = readProjectSelection(options.channelDir);
36
- const lines = ["# 项目作用域", ""];
32
+ const lines = ["**项目作用域**"];
37
33
  if (!selection) {
38
- lines.push(`项目目录:\`${resolution.policy.defaultRoot}\`(尚未选择过,将在下次准入时采用 app 默认值)`);
34
+ lines.push(`- 项目目录:\`${resolution.policy.defaultRoot}\`(尚未选择过,将在下次准入时采用 app 默认值)`);
39
35
  }
40
36
  else {
41
- lines.push(`项目目录:\`${selection.projectRoot}\`(${selection.updatedBy},更新于 ${selection.updatedAt})`);
37
+ lines.push(`- 项目目录:\`${selection.projectRoot}\`(${selection.updatedBy},更新于 ${selection.updatedAt})`);
42
38
  }
43
- lines.push(`边界:${resolution.configured ? "project(文件工具被约束在此目录内)" : "unbounded(沿用旧的全局文件权限)"}`);
44
- lines.push(`Enforcement:${sandbox.level}(${sandbox.summary})`);
39
+ lines.push(`- 边界:${resolution.configured ? "project(文件工具被约束在此目录内)" : "unbounded(沿用旧的全局文件权限)"}`);
40
+ lines.push(`- Enforcement:${sandbox.level}(${sandbox.summary})`);
45
41
  if (!resolution.configured) {
46
- lines.push("", `未配置 projectAccess:\`/project set\` 不可用。在 \`security.json\` 写入 projectAccess 段后即可使用。`);
42
+ lines.push(`- 未配置 projectAccess:\`/project set\` 不可用。在 \`security.json\` 写入 projectAccess 段后即可使用。`);
47
43
  }
48
44
  else if (!resolution.mutable) {
49
- lines.push("", "projectAccess.defaultRoot 配置有误,项目切换已被禁用,见启动诊断。");
45
+ lines.push("- projectAccess.defaultRoot 配置有误,项目切换已被禁用,见启动诊断。");
50
46
  }
51
47
  else {
52
- lines.push("", `可选根:${resolution.policy.allowedRoots.map((root) => `\`${root}\``).join("、")}`);
48
+ lines.push(`- 可选根:${resolution.policy.allowedRoots.map((root) => `\`${root}\``).join("、")}`);
53
49
  }
54
50
  for (const diagnostic of resolution.diagnostics) {
55
- lines.push(`⚠ ${diagnostic.message}`);
51
+ lines.push(`- ⚠ ${diagnostic.message}`);
56
52
  }
57
53
  return lines.join("\n");
58
54
  }
@@ -14,4 +14,24 @@ export interface HandleSubagentsCommandOptions {
14
14
  * a live `ChannelRunner` (spec 041). Lazy — never called unless a `roles` view is actually rendered. */
15
15
  getDetachedDiscovery?: () => Promise<SubAgentDiscoveryResult>;
16
16
  }
17
+ type ListFilter = "default" | "running" | "failed" | "all";
18
+ type SubagentsCommand = {
19
+ action: "list";
20
+ filter: ListFilter;
21
+ } | {
22
+ action: "show";
23
+ ref: string;
24
+ } | {
25
+ action: "output";
26
+ ref: string;
27
+ } | {
28
+ action: "cancel";
29
+ ref: string;
30
+ } | {
31
+ action: "roles";
32
+ name?: string;
33
+ };
34
+ /** Exported so `test/commands-subcommands.test.ts` can feed every broadcast example back through it. */
35
+ export declare function parseSubagentsCommand(args: string): SubagentsCommand;
17
36
  export declare function handleSubagentsCommand(options: HandleSubagentsCommandOptions): Promise<string>;
37
+ export {};
@@ -1,23 +1,14 @@
1
1
  import { readFile } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
+ import { renderSubcommandUsage } from "../agent/commands.js";
3
4
  import { errorMessage } from "../shared/text-utils.js";
4
5
  import { formatCost, formatRunDuration, harnessLabel } from "../subagents/format.js";
5
6
  import { getSubAgentRunManager } from "../subagents/runs.js";
6
7
  function usage() {
7
- return `# 委派 Run
8
-
9
- 用法:
10
-
11
- - \`/subagents\` — 运行中的 run + 最近完成的几条 + 角色目录摘要
12
- - \`/subagents list [running|failed|all]\` — 按状态筛选
13
- - \`/subagents show <runId>\` — 单个 run 的完整详情(含实际 argv、stderr 尾部)
14
- - \`/subagents output <runId>\` — 该 run 的文本产出(output.md 尾部)
15
- - \`/subagents cancel <runId|all>\` — 直接终止,不经过模型
16
- - \`/subagents roles [name]\` — 角色目录;带 name 时查看单个角色的详情
17
-
18
- \`runId\` 支持不带 \`run_\` 前缀的简写,只要能唯一匹配即可,例如 \`show a1b2c3\`。`;
8
+ return `${renderSubcommandUsage("subagents")}\n\n\`runId\` 支持不带 \`run_\` 前缀的简写,只要能唯一匹配即可,例如 \`show a1b2c3\`。`;
19
9
  }
20
- function parseSubagentsCommand(args) {
10
+ /** Exported so `test/commands-subcommands.test.ts` can feed every broadcast example back through it. */
11
+ export function parseSubagentsCommand(args) {
21
12
  const parts = args.trim().split(/\s+/).filter(Boolean);
22
13
  const action = parts[0];
23
14
  if (!action || action === "list") {
@@ -79,7 +70,7 @@ function formatRunLine(record) {
79
70
  bits.push(cost);
80
71
  const header = `- \`${record.runId}\` ${record.agent} (${bits.join(", ")}) — ${statusLabel(record.status)} — "${record.label}"`;
81
72
  if (record.status === "failed" && record.failureReason) {
82
- return `${header}\n 失败原因:${record.failureReason}`;
73
+ return `${header}(失败原因:${record.failureReason})`;
83
74
  }
84
75
  return header;
85
76
  }
@@ -123,7 +114,7 @@ function capListForDisplay(records) {
123
114
  async function listRuns(options, filter) {
124
115
  const records = getSubAgentRunManager(options.channelId).list();
125
116
  if (records.length === 0)
126
- return "# 委派 Run\n\n没有委派记录。";
117
+ return "**委派 Run**\n\n没有委派记录。";
127
118
  const running = records.filter((record) => record.status === "running").sort((a, b) => b.startedAt - a.startedAt);
128
119
  const terminal = records
129
120
  .filter((record) => record.status !== "running")
@@ -134,30 +125,30 @@ async function listRuns(options, filter) {
134
125
  sections.push(shown.length === 0 ? "没有正在运行的 run。" : shown.map(formatRunLine).join("\n"));
135
126
  if (truncatedNote)
136
127
  sections.push(truncatedNote);
137
- return `# 委派 Run — 运行中\n\n${sections.join("\n\n")}`;
128
+ return `**委派 Run** · 运行中\n\n${sections.join("\n\n")}`;
138
129
  }
139
130
  if (filter === "failed") {
140
131
  const { shown, truncatedNote } = capListForDisplay(terminal.filter((record) => record.status === "failed"));
141
132
  sections.push(shown.length === 0 ? "没有失败的 run。" : shown.map(formatRunLine).join("\n"));
142
133
  if (truncatedNote)
143
134
  sections.push(truncatedNote);
144
- return `# 委派 Run — 失败\n\n${sections.join("\n\n")}`;
135
+ return `**委派 Run** · 失败\n\n${sections.join("\n\n")}`;
145
136
  }
146
137
  if (filter === "all") {
147
138
  const { shown, truncatedNote } = capListForDisplay([...running, ...terminal]);
148
139
  sections.push(shown.map(formatRunLine).join("\n"));
149
140
  if (truncatedNote)
150
141
  sections.push(truncatedNote);
151
- return `# 委派 Run — 全部(${records.length})\n\n${sections.join("\n\n")}`;
142
+ return `**委派 Run** · 全部(${records.length})\n\n${sections.join("\n\n")}`;
152
143
  }
153
144
  // default: an overview — every running run, plus a capped tail of recent completions.
154
145
  if (running.length > 0) {
155
- sections.push(`## 运行中 (${running.length})\n${running.map(formatRunLine).join("\n")}`);
146
+ sections.push(`**运行中**(${running.length})\n${running.map(formatRunLine).join("\n")}`);
156
147
  }
157
148
  const shown = terminal.slice(0, DEFAULT_LIST_COMPLETED_LIMIT);
158
149
  if (shown.length > 0) {
159
150
  const countNote = terminal.length > shown.length ? `显示 ${shown.length} / 共 ${terminal.length}` : `${shown.length}`;
160
- sections.push(`## 最近完成 (${countNote})\n${shown.map(formatRunLine).join("\n")}`);
151
+ sections.push(`**最近完成**(${countNote})\n${shown.map(formatRunLine).join("\n")}`);
161
152
  }
162
153
  if (sections.length === 0)
163
154
  sections.push("没有委派记录。");
@@ -165,7 +156,7 @@ async function listRuns(options, filter) {
165
156
  if (discovery)
166
157
  sections.push(formatRolesTail(discovery));
167
158
  sections.push("用 `/subagents show <runId>` 看详情,`/subagents output <runId>` 看产出。");
168
- return `# 委派 Run\n\n${sections.join("\n\n")}`;
159
+ return `**委派 Run**\n\n${sections.join("\n\n")}`;
169
160
  }
170
161
  const STDERR_TAIL_CHARS = 2_000;
171
162
  const OUTPUT_TAIL_CHARS = 4_000;
@@ -185,29 +176,28 @@ async function showRun(channelId, ref) {
185
176
  return error ?? `未找到 run:\`${ref}\``;
186
177
  const record = resolution.record;
187
178
  const lines = [
188
- `# Run \`${record.runId}\``,
189
- "",
190
- `角色:${record.agent} (${harnessLabel(record)}, ${record.source})`,
191
- `标签:${record.label}`,
192
- `状态:${statusLabel(record.status)}(耗时 ${formatRunDuration(record)})`,
179
+ `**Run \`${record.runId}\`**`,
180
+ `- 角色:${record.agent} (${harnessLabel(record)}, ${record.source})`,
181
+ `- 标签:${record.label}`,
182
+ `- 状态:${statusLabel(record.status)}(耗时 ${formatRunDuration(record)})`,
193
183
  ];
194
184
  if (record.failureReason)
195
- lines.push(`失败原因:${record.failureReason}`);
185
+ lines.push(`- 失败原因:${record.failureReason}`);
196
186
  if (record.verificationVerdict) {
197
- lines.push(`验收结论:${record.verificationVerdict === "pass" ? "PASS" : "FAIL"}${record.verificationStrength === "advisory" ? "(advisory)" : ""}`);
187
+ lines.push(`- 验收结论:${record.verificationVerdict === "pass" ? "PASS" : "FAIL"}${record.verificationStrength === "advisory" ? "(advisory)" : ""}`);
198
188
  }
199
- lines.push(`开始:${new Date(record.startedAt).toLocaleString()}`);
189
+ lines.push(`- 开始:${new Date(record.startedAt).toLocaleString()}`);
200
190
  if (record.finishedAt)
201
- lines.push(`结束:${new Date(record.finishedAt).toLocaleString()}`);
202
- lines.push(`purpose:${record.purpose}`, `工作目录:\`${record.workingDirectory}\``, `产物目录:\`${record.artifactDir}\``);
191
+ lines.push(`- 结束:${new Date(record.finishedAt).toLocaleString()}`);
192
+ lines.push(`- purpose:${record.purpose}`, `- 工作目录:\`${record.workingDirectory}\``, `- 产物目录:\`${record.artifactDir}\``);
203
193
  if (record.taskId)
204
- lines.push(`所属任务:${record.taskId}`);
194
+ lines.push(`- 所属任务:${record.taskId}`);
205
195
  if (record.leaseKey)
206
- lines.push("持有写锁:是");
196
+ lines.push("- 持有写锁:是");
207
197
  if (record.model)
208
- lines.push(`模型:${record.model}`);
198
+ lines.push(`- 模型:${record.model}`);
209
199
  const cost = formatCost(record);
210
- lines.push(`usage:input=${record.usage.input} output=${record.usage.output}${cost ? ` cost=${cost}` : record.costKnown ? "" : "(cost 未知)"}`);
200
+ lines.push(`- usage:input=${record.usage.input} output=${record.usage.output}${cost ? ` cost=${cost}` : record.costKnown ? "" : "(cost 未知)"}`);
211
201
  if (record.argv)
212
202
  lines.push("", "实际 argv:", "```", JSON.stringify(record.argv), "```");
213
203
  if (record.parserVersion !== undefined || record.cliVersion) {
@@ -217,19 +207,19 @@ async function showRun(channelId, ref) {
217
207
  if (record.parserVersion !== undefined)
218
208
  parts.push(`parserVersion=${record.parserVersion}`);
219
209
  parts.push(`cliVersion=${record.cliVersion ?? "(未知)"}`);
220
- lines.push(`适配器/CLI:${parts.join(",")}`);
210
+ lines.push(`- 适配器/CLI:${parts.join(",")}`);
221
211
  }
222
212
  if (record.invocationWarnings?.length) {
223
213
  lines.push("", "⚠ 派发时的警告:", ...record.invocationWarnings.map((warning) => `- ${warning}`));
224
214
  }
225
215
  if (record.sessionId)
226
- lines.push(`sessionId:\`${record.sessionId}\`(可用于 subagent_manage op=follow_up)`);
216
+ lines.push(`- sessionId:\`${record.sessionId}\`(可用于 subagent_manage op=follow_up)`);
227
217
  if (record.runtime === "external") {
228
218
  const stderrTail = await readFile(join(record.artifactDir, "stderr.log"), "utf-8")
229
219
  .then((text) => text.slice(-STDERR_TAIL_CHARS))
230
220
  .catch(() => undefined);
231
221
  if (stderrTail?.trim()) {
232
- lines.push("", "## stderr (tail)", "```", stderrTail, "```");
222
+ lines.push("", "**stderr(尾部)**", "```", stderrTail, "```");
233
223
  }
234
224
  }
235
225
  return lines.join("\n");
@@ -243,11 +233,11 @@ async function showOutput(channelId, ref) {
243
233
  const outputText = await readFile(join(record.artifactDir, "output.md"), "utf-8").catch(() => undefined);
244
234
  if (!outputText?.trim()) {
245
235
  const runningNote = record.status === "running" ? "该 run 仍在运行,可能还没有产出。" : "该 run 没有文本产出。";
246
- return `# Run \`${record.runId}\` 的产出\n\n${runningNote}产物目录:\`${record.artifactDir}\``;
236
+ return `**Run \`${record.runId}\` 的产出**\n\n${runningNote}产物目录:\`${record.artifactDir}\``;
247
237
  }
248
238
  const tail = outputText.slice(-OUTPUT_TAIL_CHARS);
249
239
  const truncatedNote = outputText.length > tail.length ? `(只显示末尾 ${OUTPUT_TAIL_CHARS} 字符,完整内容见上方产物目录)\n\n` : "";
250
- return `# Run \`${record.runId}\` 的产出\n\n${truncatedNote}\`\`\`\n${tail}\n\`\`\``;
240
+ return `**Run \`${record.runId}\` 的产出**\n\n${truncatedNote}\`\`\`\n${tail}\n\`\`\``;
251
241
  }
252
242
  async function cancelRun(channelId, ref) {
253
243
  const manager = getSubAgentRunManager(channelId);
@@ -259,7 +249,7 @@ async function cancelRun(channelId, ref) {
259
249
  const status = await manager.cancel(record.runId);
260
250
  return `- \`${record.runId}\` (${record.agent}):${status}`;
261
251
  }));
262
- return `# 已请求终止 ${running.length} 个 run\n\n${results.join("\n")}`;
252
+ return `**已请求终止 ${running.length} 个 run**\n\n${results.join("\n")}`;
263
253
  }
264
254
  const resolution = manager.resolveRef(ref);
265
255
  const error = formatRunResolution(resolution, ref);
@@ -277,34 +267,47 @@ function formatRoleSummaryLine(agent) {
277
267
  function formatRoleDetail(agent) {
278
268
  const kind = agent.runtime === "external" ? `外部/${agent.harness}` : "内置";
279
269
  const lines = [
280
- `# 角色 \`${agent.name}\``,
281
- "",
282
- `runtime:${kind}`,
283
- `来源:${agent.source} (${agent.filePath ?? "inline"})`,
284
- `说明:${agent.description}`,
270
+ `**角色 \`${agent.name}\`**`,
271
+ `- runtime:${kind}`,
272
+ `- 来源:${agent.source} (${agent.filePath ?? "inline"})`,
273
+ `- 说明:${agent.description}`,
285
274
  ];
286
275
  if (agent.unavailable)
287
- lines.push(`⚠ 不可用:${agent.unavailable}`);
288
- lines.push(`mutates:${agent.mutates ?? "(未声明,由 tools 推断)"}`);
276
+ lines.push(`- ⚠ 不可用:${agent.unavailable}`);
277
+ lines.push(`- mutates:${agent.mutates ?? "(未声明,由 tools 推断)"}`);
289
278
  if (agent.runtime === "internal") {
290
- lines.push(`模型:${agent.modelRef ?? "(默认)"}`, `tools:${agent.tools.join(", ") || "(none)"}`, `预算:maxTurns=${agent.maxTurns} maxToolCalls=${agent.maxToolCalls} maxWallTimeSec=${agent.maxWallTimeSec} bashTimeoutSec=${agent.bashTimeoutSec}`, `contextMode:${agent.contextMode},memory:${agent.memory}`);
279
+ lines.push(`- 模型:${agent.modelRef ?? "(默认)"}`, `- tools:${agent.tools.join(", ") || "(none)"}`, `- 预算:maxTurns=${agent.maxTurns} maxToolCalls=${agent.maxToolCalls} maxWallTimeSec=${agent.maxWallTimeSec} bashTimeoutSec=${agent.bashTimeoutSec}`, `- contextMode:${agent.contextMode},memory:${agent.memory}`);
291
280
  }
292
281
  else {
293
- lines.push(`command:\`${agent.command ?? ""}\`${agent.shell ? "(通过 shell 执行)" : ""}`, `maxWallTimeSec:${agent.maxWallTimeSec}`);
282
+ lines.push(`- command:\`${agent.command ?? ""}\`${agent.shell ? "(通过 shell 执行)" : ""}`, `- maxWallTimeSec:${agent.maxWallTimeSec}`);
294
283
  if (agent.externalModelRef)
295
- lines.push(`模型:${agent.externalModelRef}`);
284
+ lines.push(`- 模型:${agent.externalModelRef}`);
296
285
  // spec 042 D4: contextMode/memory are effective for external roles too (memory 默认 none,
297
286
  // 显式声明 session/relevant 才会把频道会话状态发给外部进程) — 显示出来而不是只在内置分支里说明。
298
- lines.push(`contextMode:${agent.contextMode},memory:${agent.memory}`);
287
+ lines.push(`- contextMode:${agent.contextMode},memory:${agent.memory}`);
299
288
  if (agent.memory !== "none") {
300
- lines.push(`⚠ 该角色会把频道会话状态/记忆片段发送给外部进程(memory: ${agent.memory})`);
289
+ lines.push(`- ⚠ 该角色会把频道会话状态/记忆片段发送给外部进程(memory: ${agent.memory})`);
301
290
  }
302
291
  }
303
292
  if (agent.paths.length > 0)
304
- lines.push(`paths:${agent.paths.join(", ")}`);
305
- lines.push("", "system prompt:", "```", agent.systemPrompt, "```");
293
+ lines.push(`- paths:${agent.paths.join(", ")}`);
294
+ // A full system prompt can be several KB; a role backed by a file is shown as a head snippet
295
+ // with a pointer to that file instead (review 2026-08-24 §2.4/§3.2). Inline roles have no file
296
+ // to point to, so they get a plain truncation note instead.
297
+ lines.push("", "system prompt:", renderCappedPromptBlock(agent));
306
298
  return lines.join("\n");
307
299
  }
300
+ const SYSTEM_PROMPT_SHOW_MAX_CHARS = 4_000;
301
+ function renderCappedPromptBlock(agent) {
302
+ const prompt = agent.systemPrompt;
303
+ if (prompt.length <= SYSTEM_PROMPT_SHOW_MAX_CHARS) {
304
+ return `\`\`\`\n${prompt}\n\`\`\``;
305
+ }
306
+ const lastNewline = prompt.lastIndexOf("\n", SYSTEM_PROMPT_SHOW_MAX_CHARS);
307
+ const head = prompt.slice(0, lastNewline > 0 ? lastNewline : SYSTEM_PROMPT_SHOW_MAX_CHARS).trimEnd();
308
+ const nextStep = agent.filePath ? `完整内容见 \`${agent.filePath}\`` : "该角色内联定义,无文件可查看完整内容";
309
+ return `\`\`\`\n${head}\n\`\`\`\n\n(内容过长已截断;${nextStep})`;
310
+ }
308
311
  async function showRoles(options, name) {
309
312
  const discovery = await resolveDiscovery(options);
310
313
  if (!discovery) {
@@ -320,11 +323,11 @@ async function showRoles(options, name) {
320
323
  }
321
324
  const internal = discovery.agents.filter((agent) => agent.runtime === "internal");
322
325
  const external = discovery.agents.filter((agent) => agent.runtime === "external");
323
- const sections = [`# 角色目录\n\n目录:\`${discovery.directory}\``];
326
+ const sections = [`**角色目录**\n\n目录:\`${discovery.directory}\``];
324
327
  if (external.length > 0)
325
- sections.push(`## 外部\n${external.map(formatRoleSummaryLine).join("\n")}`);
328
+ sections.push(`**外部**\n${external.map(formatRoleSummaryLine).join("\n")}`);
326
329
  if (internal.length > 0)
327
- sections.push(`## 内置\n${internal.map(formatRoleSummaryLine).join("\n")}`);
330
+ sections.push(`**内置**\n${internal.map(formatRoleSummaryLine).join("\n")}`);
328
331
  if (discovery.agents.length === 0)
329
332
  sections.push("目录为空。");
330
333
  for (const warning of discovery.warnings)
@@ -8,6 +8,43 @@ export interface HandleTasksCommandOptions {
8
8
  /** Optional immediate task wake, available in the long-lived DingTalk runtime. */
9
9
  dispatchTask?: (id: string) => Promise<boolean>;
10
10
  }
11
+ /**
12
+ * Fields `/tasks set` can edit directly.
13
+ *
14
+ * Deliberately a small, flat set: the ones a user already knows they want to change (when it
15
+ * should wake, what it should do next, how much rope it has). Everything structural — status
16
+ * transitions and verification — stays with `task_manage`, whose state
17
+ * machine those fields belong to. The value is the rest of the line, so it may contain spaces.
18
+ */
19
+ declare const SETTABLE_TASK_FIELDS: readonly ["wake", "next", "deadline"];
20
+ type SettableTaskField = (typeof SETTABLE_TASK_FIELDS)[number];
21
+ type TasksCommand = {
22
+ action: "list";
23
+ } | {
24
+ action: "show";
25
+ id: string;
26
+ } | {
27
+ action: "archive";
28
+ } | {
29
+ action: "doctor";
30
+ } | {
31
+ action: "pause";
32
+ id: string;
33
+ } | {
34
+ action: "resume";
35
+ id: string;
36
+ } | {
37
+ action: "run";
38
+ id: string;
39
+ } | {
40
+ action: "set";
41
+ id: string;
42
+ field: SettableTaskField;
43
+ value: string;
44
+ };
45
+ /** Exported so `test/commands-subcommands.test.ts` can feed every broadcast example back through it. */
46
+ export declare function parseTasksCommand(args: string): TasksCommand;
11
47
  export declare function pauseTask(options: HandleTasksCommandOptions, idInput: string): Promise<string>;
12
48
  export declare function resumeTask(options: HandleTasksCommandOptions, idInput: string): Promise<string>;
13
49
  export declare function handleTasksCommand(options: HandleTasksCommandOptions): Promise<string>;
50
+ export {};