@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.
Files changed (189) hide show
  1. package/dist/agent/channel-runner.d.ts +9 -1
  2. package/dist/agent/channel-runner.js +51 -18
  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/effect-ledger.js +9 -2
  7. package/dist/agent/job-manager.d.ts +4 -0
  8. package/dist/agent/job-manager.js +17 -2
  9. package/dist/agent/prompt/manifest.d.ts +1 -1
  10. package/dist/agent/prompt/manifest.js +6 -7
  11. package/dist/agent/prompt/sections.js +9 -5
  12. package/dist/agent/reply-limits.d.ts +16 -0
  13. package/dist/agent/reply-limits.js +17 -0
  14. package/dist/agent/session-events.d.ts +2 -0
  15. package/dist/agent/session-events.js +29 -14
  16. package/dist/agent/status-render.js +12 -12
  17. package/dist/agent/turn-recovery.js +2 -2
  18. package/dist/agent/type-guards.js +5 -1
  19. package/dist/agent/workspace-resources.d.ts +2 -2
  20. package/dist/agent/workspace-resources.js +41 -3
  21. package/dist/executor.d.ts +28 -0
  22. package/dist/executor.js +120 -18
  23. package/dist/file-store.d.ts +96 -0
  24. package/dist/file-store.js +189 -0
  25. package/dist/main.js +3 -4
  26. package/dist/memory/commands.js +79 -38
  27. package/dist/memory/consolidation.d.ts +5 -1
  28. package/dist/memory/consolidation.js +35 -38
  29. package/dist/memory/extraction.d.ts +8 -1
  30. package/dist/memory/extraction.js +47 -4
  31. package/dist/memory/files.d.ts +0 -1
  32. package/dist/memory/files.js +31 -12
  33. package/dist/memory/lifecycle.js +9 -2
  34. package/dist/memory/maintenance-jobs.js +16 -38
  35. package/dist/memory/maintenance-state.js +2 -1
  36. package/dist/memory/metadata.d.ts +3 -0
  37. package/dist/memory/metadata.js +7 -0
  38. package/dist/memory/recall.d.ts +19 -0
  39. package/dist/memory/recall.js +116 -24
  40. package/dist/memory/review-log.d.ts +0 -2
  41. package/dist/memory/review-log.js +0 -0
  42. package/dist/memory/session-corpus.js +5 -0
  43. package/dist/memory/session-search.js +15 -22
  44. package/dist/memory/sidecar-worker.js +4 -0
  45. package/dist/memory/source-window.d.ts +0 -1
  46. package/dist/memory/source-window.js +0 -5
  47. package/dist/memory/transcript.d.ts +10 -0
  48. package/dist/memory/transcript.js +39 -0
  49. package/dist/playbooks/agent-delegation.md +34 -25
  50. package/dist/playbooks/background-jobs.md +8 -16
  51. package/dist/playbooks/catalog.d.ts +1 -1
  52. package/dist/playbooks/catalog.js +1 -1
  53. package/dist/playbooks/event-scheduling.md +15 -15
  54. package/dist/playbooks/memory-and-learning.md +30 -23
  55. package/dist/playbooks/outbound-media.md +15 -8
  56. package/dist/playbooks/runtime-orientation.md +40 -37
  57. package/dist/playbooks/task-driving.md +36 -38
  58. package/dist/playbooks/task-planning.md +21 -21
  59. package/dist/runtime/app-home.d.ts +6 -0
  60. package/dist/runtime/app-home.js +16 -7
  61. package/dist/runtime/bootstrap.js +54 -13
  62. package/dist/runtime/channel-context.d.ts +2 -1
  63. package/dist/runtime/delivery.js +3 -3
  64. package/dist/runtime/dingtalk.d.ts +9 -1
  65. package/dist/runtime/dingtalk.js +30 -15
  66. package/dist/runtime/durable-dispatch.d.ts +26 -1
  67. package/dist/runtime/durable-dispatch.js +51 -5
  68. package/dist/runtime/event-commands.d.ts +15 -0
  69. package/dist/runtime/event-commands.js +55 -56
  70. package/dist/runtime/events.d.ts +4 -2
  71. package/dist/runtime/events.js +15 -20
  72. package/dist/runtime/project-commands.d.ts +16 -0
  73. package/dist/runtime/project-commands.js +13 -17
  74. package/dist/runtime/subagent-commands.d.ts +20 -0
  75. package/dist/runtime/subagent-commands.js +61 -58
  76. package/dist/runtime/task-commands.d.ts +37 -0
  77. package/dist/runtime/task-commands.js +108 -66
  78. package/dist/runtime/task-driver.js +2 -2
  79. package/dist/security/block-message.d.ts +11 -0
  80. package/dist/security/block-message.js +12 -0
  81. package/dist/security/path-guard-check.d.ts +13 -0
  82. package/dist/security/path-guard-check.js +39 -0
  83. package/dist/security/path-guard.js +61 -12
  84. package/dist/security/types.d.ts +9 -0
  85. package/dist/settings.js +3 -2
  86. package/dist/shared/atomic-file.d.ts +17 -1
  87. package/dist/shared/atomic-file.js +50 -3
  88. package/dist/shared/duration.d.ts +2 -0
  89. package/dist/shared/duration.js +7 -0
  90. package/dist/shared/safe-id.d.ts +19 -0
  91. package/dist/shared/safe-id.js +24 -0
  92. package/dist/shared/text-utils.d.ts +1 -1
  93. package/dist/shared/text-utils.js +3 -8
  94. package/dist/shared/type-guards.d.ts +2 -0
  95. package/dist/shared/type-guards.js +4 -0
  96. package/dist/subagents/discovery.d.ts +51 -19
  97. package/dist/subagents/discovery.js +93 -98
  98. package/dist/subagents/external/claude-code.js +40 -2
  99. package/dist/subagents/external/harness.d.ts +1 -1
  100. package/dist/subagents/external/run.js +61 -8
  101. package/dist/subagents/format.d.ts +3 -2
  102. package/dist/subagents/format.js +3 -7
  103. package/dist/subagents/runs.d.ts +1 -1
  104. package/dist/subagents/runs.js +10 -9
  105. package/dist/subagents/tool.d.ts +31 -18
  106. package/dist/subagents/tool.js +592 -562
  107. package/dist/subagents/workspace-lease.js +1 -1
  108. package/dist/tasks/control.js +7 -9
  109. package/dist/tasks/ledger.d.ts +2 -2
  110. package/dist/tasks/ledger.js +3 -7
  111. package/dist/tasks/transitions.d.ts +5 -1
  112. package/dist/tasks/transitions.js +2 -2
  113. package/dist/tasks/verification.d.ts +7 -5
  114. package/dist/tools/bash.d.ts +1 -2
  115. package/dist/tools/bash.js +99 -76
  116. package/dist/tools/config.d.ts +6 -1
  117. package/dist/tools/config.js +9 -0
  118. package/dist/tools/edit.d.ts +2 -3
  119. package/dist/tools/edit.js +276 -75
  120. package/dist/tools/event-manage.d.ts +13 -7
  121. package/dist/tools/event-manage.js +52 -14
  122. package/dist/tools/glob-match.d.ts +11 -0
  123. package/dist/tools/glob-match.js +75 -0
  124. package/dist/tools/glob.d.ts +15 -0
  125. package/dist/tools/glob.js +113 -0
  126. package/dist/tools/grep.d.ts +0 -1
  127. package/dist/tools/grep.js +60 -44
  128. package/dist/tools/ignore-dirs.d.ts +6 -0
  129. package/dist/tools/ignore-dirs.js +15 -0
  130. package/dist/tools/index.d.ts +3 -0
  131. package/dist/tools/index.js +54 -40
  132. package/dist/tools/job.d.ts +0 -1
  133. package/dist/tools/job.js +3 -9
  134. package/dist/tools/line-index.d.ts +16 -0
  135. package/dist/tools/line-index.js +76 -0
  136. package/dist/tools/memory-manage.d.ts +21 -8
  137. package/dist/tools/memory-manage.js +114 -103
  138. package/dist/tools/presentation.d.ts +2 -0
  139. package/dist/tools/presentation.js +109 -0
  140. package/dist/tools/read.d.ts +2 -2
  141. package/dist/tools/read.js +100 -120
  142. package/dist/tools/registry.d.ts +4 -1
  143. package/dist/tools/registry.js +89 -22
  144. package/dist/tools/send-media.d.ts +6 -6
  145. package/dist/tools/send-media.js +21 -43
  146. package/dist/tools/session-search.d.ts +0 -1
  147. package/dist/tools/session-search.js +0 -1
  148. package/dist/tools/skill-security.d.ts +0 -2
  149. package/dist/tools/skill-security.js +1 -25
  150. package/dist/tools/skill.d.ts +31 -0
  151. package/dist/tools/skill.js +153 -0
  152. package/dist/tools/subagent-manage.d.ts +6 -5
  153. package/dist/tools/subagent-manage.js +47 -47
  154. package/dist/tools/task-manage/create.d.ts +2 -2
  155. package/dist/tools/task-manage/create.js +1 -3
  156. package/dist/tools/task-manage/lifecycle.d.ts +9 -6
  157. package/dist/tools/task-manage/lifecycle.js +49 -56
  158. package/dist/tools/task-manage/schema.d.ts +27 -15
  159. package/dist/tools/task-manage/schema.js +58 -74
  160. package/dist/tools/task-manage/shared.d.ts +11 -6
  161. package/dist/tools/task-manage/shared.js +30 -21
  162. package/dist/tools/task-manage/types.d.ts +14 -15
  163. package/dist/tools/task-manage/verification.d.ts +4 -4
  164. package/dist/tools/task-manage/verification.js +6 -8
  165. package/dist/tools/task-manage.d.ts +8 -11
  166. package/dist/tools/task-manage.js +63 -50
  167. package/dist/tools/tool-details.d.ts +17 -1
  168. package/dist/tools/tool-details.js +24 -0
  169. package/dist/tools/truncate.d.ts +8 -0
  170. package/dist/tools/truncate.js +8 -0
  171. package/dist/tools/web-fetch.d.ts +0 -1
  172. package/dist/tools/web-fetch.js +9 -2
  173. package/dist/tools/web-search.d.ts +0 -1
  174. package/dist/tools/web-search.js +0 -1
  175. package/dist/tools/write-content.d.ts +3 -3
  176. package/dist/tools/write-content.js +12 -41
  177. package/dist/tools/write.d.ts +2 -3
  178. package/dist/tools/write.js +3 -4
  179. package/dist/tui/app.js +1 -1
  180. package/dist/tui/commands.d.ts +1 -1
  181. package/dist/tui/commands.js +1 -1
  182. package/dist/tui/turn-controller.d.ts +1 -1
  183. package/dist/tui/turn-controller.js +14 -4
  184. package/dist/usage/ledger.js +7 -4
  185. package/dist/usage/render.js +10 -8
  186. package/examples/sub-agents/README.md +2 -0
  187. package/package.json +3 -2
  188. package/dist/tools/skill-manage.d.ts +0 -41
  189. package/dist/tools/skill-manage.js +0 -231
@@ -8,12 +8,14 @@ export const BUILT_IN_COMMANDS = [
8
8
  description: "显示命令帮助",
9
9
  examples: ["/help"],
10
10
  availableWhileBusy: true,
11
+ runnerHandled: true,
11
12
  },
12
13
  {
13
14
  name: "stop",
14
15
  description: "停止当前回合;若该回合由任务驱动,同时暂停该任务",
15
16
  examples: ["/stop"],
16
17
  availableWhileBusy: true,
18
+ runnerHandled: true,
17
19
  },
18
20
  {
19
21
  name: "steer",
@@ -21,6 +23,7 @@ export const BUILT_IN_COMMANDS = [
21
23
  description: "在当前工具步骤结束后调整正在运行的回合",
22
24
  examples: ["/steer Use the Shanghai time zone and summarize only the latest updates"],
23
25
  availableWhileBusy: true,
26
+ runnerHandled: true,
24
27
  },
25
28
  {
26
29
  name: "followup",
@@ -28,36 +31,70 @@ export const BUILT_IN_COMMANDS = [
28
31
  description: "排队一条请求,等当前回合结束后再执行",
29
32
  examples: ["/followup After that, draft a short executive summary"],
30
33
  availableWhileBusy: true,
34
+ runnerHandled: true,
31
35
  },
32
36
  {
33
37
  name: "events",
34
38
  argumentHint: "<list|show|delete|history>",
35
39
  description: "管理定时事件文件,查看事件历史",
36
- examples: [
37
- "/events list",
38
- "/events show weekly-review",
39
- "/events delete weekly-review",
40
- "/events history weekly-review",
41
- ],
42
40
  availableWhileBusy: true,
41
+ subcommands: [
42
+ { name: "list", description: "列出所有定时事件", example: "/events list" },
43
+ { name: "show", args: "<name>", description: "查看单个事件的完整内容", example: "/events show weekly-review" },
44
+ {
45
+ name: "delete",
46
+ args: "<name>",
47
+ description: "删除一个事件(回显被删内容,误删可从聊天记录恢复)",
48
+ example: "/events delete weekly-review",
49
+ },
50
+ {
51
+ name: "history",
52
+ args: "[name]",
53
+ description: "查看事件触发历史,不带参数显示全部",
54
+ example: "/events history weekly-review",
55
+ },
56
+ ],
43
57
  },
44
58
  {
45
59
  name: "tasks",
46
- argumentHint: "[show <id>|archive|pause <id>|resume <id>|run <id>|set <id> <字段> <值>|stats [id]|doctor]",
60
+ argumentHint: "[show <id>|archive|pause <id>|resume <id>|run <id>|set <id> <字段> <值>|doctor]",
47
61
  description: "查看、诊断并直接编辑本频道的任务台账;pause 只停用执行,保留阶段与 wake",
48
- examples: [
49
- "/tasks",
50
- "/tasks show weekly-report",
51
- "/tasks archive",
52
- "/tasks pause weekly-report",
53
- "/tasks resume weekly-report",
54
- "/tasks run weekly-report",
55
- "/tasks set weekly-report wake 2026-07-28T09:00:00+08:00",
56
- "/tasks set weekly-report next 跑一遍构建并贴出失败堆栈",
57
- "/tasks stats weekly-report",
58
- "/tasks doctor",
59
- ],
60
62
  availableWhileBusy: true,
63
+ subcommands: [
64
+ { name: "list", description: "列出本频道进行中的任务(默认动作,可省略)", example: "/tasks" },
65
+ {
66
+ name: "show",
67
+ args: "<id>",
68
+ description: "查看单个任务文件(进行中或已归档)",
69
+ example: "/tasks show weekly-report",
70
+ },
71
+ { name: "archive", description: "列出已归档(已关闭)的任务", example: "/tasks archive" },
72
+ {
73
+ name: "pause",
74
+ args: "<id>",
75
+ description: "停止该任务的自动执行(保留当前阶段与 wake)",
76
+ example: "/tasks pause weekly-report",
77
+ },
78
+ {
79
+ name: "resume",
80
+ args: "<id>",
81
+ description: "重新启用该任务,按当前阶段继续",
82
+ example: "/tasks resume weekly-report",
83
+ },
84
+ {
85
+ name: "run",
86
+ args: "<id>",
87
+ description: "恢复并立即排入一次执行(需要运行时可用)",
88
+ example: "/tasks run weekly-report",
89
+ },
90
+ {
91
+ name: "set",
92
+ args: "<id> <wake|next|deadline> <值>",
93
+ description: "直接改一个字段,不花一个 LLM 回合",
94
+ example: "/tasks set weekly-report wake 2026-07-28T09:00:00+08:00",
95
+ },
96
+ { name: "doctor", description: "只读检查任务/事件一致性", example: "/tasks doctor" },
97
+ ],
61
98
  },
62
99
  {
63
100
  name: "status",
@@ -80,32 +117,65 @@ export const BUILT_IN_COMMANDS = [
80
117
  // Read-only accounting of state the runner already holds: no LLM call, no session
81
118
  // access, so it answers mid-turn like /status and /usage do.
82
119
  availableWhileBusy: true,
120
+ runnerHandled: true,
83
121
  },
84
122
  {
85
123
  name: "subagents",
86
124
  argumentHint: "<list [running|failed|all]|show <id>|output <id>|cancel <id|all>|roles [name]>",
87
125
  description: "查看与控制委派 run(内置与外部)、浏览角色目录;cancel 不经过模型,直接终止",
88
- examples: [
89
- "/subagents",
90
- "/subagents list failed",
91
- "/subagents show run_a1b2c3",
92
- "/subagents output run_a1b2c3",
93
- "/subagents cancel run_a1b2c3",
94
- "/subagents roles",
95
- "/subagents roles builder-hard",
96
- ],
97
126
  // A human control path independent of the model (spec 040, D6): /stop no longer kills a
98
127
  // dispatched delegation, so cancel must work even when the model/turn is unavailable.
99
128
  availableWhileBusy: true,
129
+ subcommands: [
130
+ {
131
+ name: "list",
132
+ args: "[running|failed|all]",
133
+ description: "运行中的 run + 最近完成的几条(不带筛选时)",
134
+ example: "/subagents list failed",
135
+ },
136
+ {
137
+ name: "show",
138
+ args: "<runId>",
139
+ description: "单个 run 的完整详情(含实际 argv、stderr 尾部)",
140
+ example: "/subagents show run_a1b2c3",
141
+ },
142
+ {
143
+ name: "output",
144
+ args: "<runId>",
145
+ description: "该 run 的文本产出(output.md 尾部)",
146
+ example: "/subagents output run_a1b2c3",
147
+ },
148
+ {
149
+ name: "cancel",
150
+ args: "<runId|all>",
151
+ description: "直接终止,不经过模型",
152
+ example: "/subagents cancel run_a1b2c3",
153
+ },
154
+ {
155
+ name: "roles",
156
+ args: "[name]",
157
+ description: "角色目录;带 name 时查看单个角色的详情",
158
+ example: "/subagents roles builder-hard",
159
+ },
160
+ ],
100
161
  },
101
162
  {
102
163
  name: "project",
103
164
  argumentHint: "[set <absolute-path>|reset]",
104
165
  description: "查看或切换本频道的项目目录(文件工具/shell 的工作面);set/reset 需频道空闲",
105
- examples: ["/project", "/project set /home/me/projects/foo", "/project reset"],
106
166
  // The read form answers like /status; set/reset validate idleness themselves and reply
107
167
  // with a plain error instead of blocking the built-in-command dispatch path.
108
168
  availableWhileBusy: true,
169
+ subcommands: [
170
+ { name: "show", description: "查看当前频道的项目目录与访问边界(默认动作,可省略)", example: "/project" },
171
+ {
172
+ name: "set",
173
+ args: "<absolute-path>",
174
+ description: "切换项目目录(需频道空闲,且目录在允许的可选根内)",
175
+ example: "/project set /home/me/projects/foo",
176
+ },
177
+ { name: "reset", description: "切回 app 默认项目目录", example: "/project reset" },
178
+ ],
109
179
  },
110
180
  ];
111
181
  /**
@@ -116,9 +186,19 @@ export const BUILT_IN_COMMANDS = [
116
186
  export const SESSION_COMMANDS = [
117
187
  {
118
188
  name: "memory",
119
- argumentHint: "[status|list|show <id>|pending]",
120
- description: "查看生效记忆、元数据、召回统计、墓碑与待确认建议",
121
- examples: ["/memory status", "/memory list", "/memory show m-1234abcd", "/memory pending"],
189
+ argumentHint: "[status|list|show <id>|recent]",
190
+ description: "查看生效记忆、元数据、召回统计、墓碑与近期写入/删除活动",
191
+ subcommands: [
192
+ { name: "status", description: "记忆状态概览", example: "/memory status" },
193
+ { name: "list", description: "列出生效的记忆条目", example: "/memory list" },
194
+ {
195
+ name: "show",
196
+ args: "<entry-id>",
197
+ description: "查看单条记忆的内容与元数据",
198
+ example: "/memory show m-1234abcd",
199
+ },
200
+ { name: "recent", description: "查看最近 7 天的记忆写入/删除活动", example: "/memory recent" },
201
+ ],
122
202
  },
123
203
  {
124
204
  name: "session",
@@ -152,6 +232,7 @@ export const SESSION_COMMANDS = [
152
232
  ];
153
233
  const BUILT_IN_NAMES = new Set(BUILT_IN_COMMANDS.map((command) => command.name));
154
234
  const KNOWN_COMMAND_NAMES = new Set([...BUILT_IN_NAMES, ...SESSION_COMMANDS.map((command) => command.name)]);
235
+ const ALL_COMMANDS = [...BUILT_IN_COMMANDS, ...SESSION_COMMANDS];
155
236
  /** Look up the shared description for a session command (used by the SDK extension). */
156
237
  export function sessionCommandDescription(name) {
157
238
  const spec = SESSION_COMMANDS.find((command) => command.name === name);
@@ -163,7 +244,12 @@ export function sessionCommandDescription(name) {
163
244
  export function isBuiltInCommandName(name) {
164
245
  return BUILT_IN_NAMES.has(name);
165
246
  }
166
- const RUNNER_BUILT_IN_NAMES = new Set(["help", "stop", "steer", "followup", "context"]);
247
+ const SESSION_COMMAND_NAMES = new Set(SESSION_COMMANDS.map((command) => command.name));
248
+ /** True for a session-layer command name (`/model`, `/compact`, …) — needs the idle session layer. */
249
+ export function isSessionCommandName(name) {
250
+ return SESSION_COMMAND_NAMES.has(name);
251
+ }
252
+ const RUNNER_BUILT_IN_NAMES = new Set(BUILT_IN_COMMANDS.filter((command) => command.runnerHandled).map((command) => command.name));
167
253
  /** Narrow a parsed built-in to one `ChannelRunner.handleBuiltinCommand` accepts. */
168
254
  export function isRunnerBuiltInCommand(command) {
169
255
  return RUNNER_BUILT_IN_NAMES.has(command.name);
@@ -175,34 +261,59 @@ export function formatBusyCommandList() {
175
261
  .map((command) => `\`/${command.name}\``)
176
262
  .join(", ");
177
263
  }
178
- function renderCommandEntry(spec) {
179
- const header = `- \`/${spec.name}${spec.argumentHint ? ` ${spec.argumentHint}` : ""}\``;
180
- const lines = [header, ` ${spec.description}`];
181
- for (const example of spec.examples ?? []) {
182
- lines.push(` 示例:\`${example}\``);
264
+ /**
265
+ * Renders a command's subcommand table as its `usage()` text — the single source `task-commands.ts`,
266
+ * `event-commands.ts`, `subagent-commands.ts`, `project-commands.ts`, and `memory/commands.ts` call
267
+ * on a parse error, replacing five hand-written `usage()` bodies (review 2026-08-24 §3.1).
268
+ */
269
+ export function renderSubcommandUsage(name) {
270
+ const spec = ALL_COMMANDS.find((command) => command.name === name);
271
+ if (!spec?.subcommands?.length) {
272
+ return `**/${name}**`;
273
+ }
274
+ const lines = spec.subcommands.map((sub) => `- \`/${name} ${sub.name}${sub.args ? ` ${sub.args}` : ""}\` — ${sub.description}`);
275
+ return `**/${name}**\n\n${lines.join("\n")}`;
276
+ }
277
+ /** One line per command: name + description, no args/examples. Used by the top-level `/help`. */
278
+ function renderCommandSummaryLine(spec) {
279
+ return `- \`/${spec.name}\` — ${spec.description}`;
280
+ }
281
+ /** The full detail for one command: argument syntax, subcommands or examples. Used by `/help <name>`. */
282
+ function renderCommandDetail(spec) {
283
+ const header = `**/${spec.name}${spec.argumentHint ? ` ${spec.argumentHint}` : ""}**`;
284
+ const lines = [header, spec.description];
285
+ if (spec.subcommands?.length) {
286
+ for (const sub of spec.subcommands) {
287
+ const base = `- \`/${spec.name} ${sub.name}${sub.args ? ` ${sub.args}` : ""}\` — ${sub.description}`;
288
+ lines.push(sub.example ? `${base}(例:\`${sub.example}\`)` : base);
289
+ }
290
+ }
291
+ else if (spec.examples?.length) {
292
+ for (const example of spec.examples) {
293
+ lines.push(`- 示例:\`${example}\``);
294
+ }
183
295
  }
184
296
  return lines.join("\n");
185
297
  }
298
+ /** `/help <name>`'s content, or `undefined` for an unknown command name. */
299
+ export function renderCommandHelp(name) {
300
+ const spec = ALL_COMMANDS.find((command) => command.name === name);
301
+ return spec ? renderCommandDetail(spec) : undefined;
302
+ }
186
303
  function renderHelpText() {
187
- const transport = BUILT_IN_COMMANDS.map(renderCommandEntry).join("\n");
188
- const session = SESSION_COMMANDS.map(renderCommandEntry).join("\n");
189
- return `# 斜杠命令
190
-
191
- Pipiclaw 的命令分为两组。
304
+ const transport = BUILT_IN_COMMANDS.map(renderCommandSummaryLine).join("\n");
305
+ const session = SESSION_COMMANDS.map(renderCommandSummaryLine).join("\n");
306
+ return `**斜杠命令**
192
307
 
193
- ## 传输层命令
308
+ Pipiclaw 的命令分为两组;用 \`/help <命令名>\` 查看某个命令的详细用法和示例(例如 \`/help tasks\`)。
194
309
 
195
- 由钉钉传输层/运行时直接处理,回合进行中也可以用。
310
+ **传输层命令** · 由钉钉传输层/运行时直接处理,回合进行中也可以用
196
311
 
197
312
  ${transport}
198
313
 
199
- 回合进行中发送的普通消息按 \`busyMessageDefault\` 处理,默认是 \`steer\`;在 channel.json 里设为 \`followUp\`(或 \`followup\`)则改为排队到当前回合之后执行。
314
+ 回合进行中发送的普通消息按 \`busyMessageDefault\` 处理,默认是 \`steer\`;在 channel.json 里设为 \`followUp\`(或 \`followup\`)则改为排队到当前回合之后执行。channel.json 的 \`responseMode\` 控制输出形态,详见文档。
200
315
 
201
- channel.json 的 \`responseMode\` 控制输出形态:\`full_progress_then_plain_final\`(默认)流式展示完整进度,再发一条纯文本结论;\`rolling_progress_then_plain_final\` 只保留最近几条进度,收尾给一行摘要;\`final_card_only\` 隐藏进度,只在 AI 卡片里给最终结果。
202
-
203
- ## 会话层命令
204
-
205
- 由 Pipiclaw 会话层处理,需要在空闲时使用:
316
+ **会话层命令** · 由 Pipiclaw 会话层处理,需要在空闲时使用
206
317
 
207
318
  ${session}
208
319
  `;
@@ -218,13 +329,29 @@ export function slashCommandName(text) {
218
329
  return match ? match[1].toLowerCase() : null;
219
330
  }
220
331
  /**
221
- * True if `text` is a slash command the runtime or session layer knows how to
222
- * handle: a built-in transport command, a session command, or a skill
223
- * invocation (`/skill:name`). Prompt-template names are resolved separately by
224
- * the runner, which has the session's live template list.
332
+ * True if `text` is a slash command the runtime or session layer knows how to handle: a built-in
333
+ * transport command, a session command, or a skill invocation (`/skill:name`) naming a skill
334
+ * actually present in `knownSkillNames`. Prompt-template names are resolved separately by the
335
+ * runner, which has the session's live template list.
336
+ *
337
+ * `knownSkillNames` used to be unchecked — any `/skill:<anything>` counted as known and got a full
338
+ * LLM turn, bypassing the "unknown command never reaches the model" guarantee this function exists
339
+ * to provide (review 2026-08-24 §1.9). Omitting `knownSkillNames` (no roster available) rejects
340
+ * every `skill:` name rather than trusting it.
225
341
  */
226
- export function isKnownCommandName(name) {
227
- return KNOWN_COMMAND_NAMES.has(name) || name.startsWith("skill:");
342
+ export function isKnownCommandName(name, knownSkillNames) {
343
+ if (KNOWN_COMMAND_NAMES.has(name)) {
344
+ return true;
345
+ }
346
+ if (!name.startsWith("skill:") || !knownSkillNames) {
347
+ return false;
348
+ }
349
+ const skillName = name.slice("skill:".length);
350
+ for (const candidate of knownSkillNames) {
351
+ if (candidate === skillName)
352
+ return true;
353
+ }
354
+ return false;
228
355
  }
229
356
  export function formatUnknownCommandMessage(name) {
230
357
  return `未知命令 \`/${name}\`。发送 \`/help\` 查看可用命令。`;
@@ -248,6 +375,19 @@ export function parseBuiltInCommand(text) {
248
375
  }
249
376
  return null;
250
377
  }
251
- export function renderBuiltInHelp() {
252
- return HELP_TEXT;
378
+ /**
379
+ * `/help` (top-level command listing) or `/help <name>` (that command's subcommands/examples) —
380
+ * two-level help so the top level stays scannable instead of the ~40-line wall of every example
381
+ * (review 2026-08-24 §2.2.1). `args` is the raw text after `/help`.
382
+ */
383
+ export function renderBuiltInHelp(args = "") {
384
+ const name = args.trim().toLowerCase();
385
+ if (!name) {
386
+ return HELP_TEXT;
387
+ }
388
+ const detail = renderCommandHelp(name);
389
+ if (detail) {
390
+ return detail;
391
+ }
392
+ return `未找到命令 \`/${name}\`。\n\n${HELP_TEXT}`;
253
393
  }
@@ -9,7 +9,7 @@ import { isRecord } from "../shared/type-guards.js";
9
9
  *
10
10
  * Effects are counted here instead, and only for things that change the world outside the task
11
11
  * ledger: writes, outbound media, sub-agent runs, background job launches, and a user-visible
12
- * reply. Self-report tools (`task_manage`, `memory_manage`) and read-only tools deliberately do
12
+ * reply. Self-report tools (`task_create`/`task_update`/`task_close`/`task_verify`, `memory_save`/`memory_search`/`memory_forget`) and read-only tools deliberately do
13
13
  * not count — a claim of progress is not evidence of it.
14
14
  *
15
15
  * The tally lives in process memory, exactly like the driver's futile counter it feeds; a restart
@@ -21,7 +21,7 @@ import { isRecord } from "../shared/type-guards.js";
21
21
  const counts = new Map();
22
22
  const taskCounts = new Map();
23
23
  /** Tools whose successful completion is, by itself, a visible change to the world. */
24
- const EFFECT_TOOLS = new Set(["write", "edit", "send_media", "subagent"]);
24
+ const EFFECT_TOOLS = new Set(["write", "edit", "send_media", "subagent", "subagent_inline"]);
25
25
  export function noteChannelEffect(channelId) {
26
26
  counts.set(channelId, (counts.get(channelId) ?? 0) + 1);
27
27
  }
@@ -71,6 +71,13 @@ export function resetChannelEffects() {
71
71
  * claims to look. What "futile" now means is the honest thing: a wake that executed nothing at all.
72
72
  */
73
73
  export function isEffectfulTool(toolName, details) {
74
+ if (toolName === "subagent_run") {
75
+ // Spec 047, F6/D3.2: op=follow_up dispatches a new external run — as much a visible change
76
+ // to the world as `subagent` itself. show/cancel are not. The discriminator is `resumedFrom`
77
+ // in `details` rather than `op`, because only a successful dispatch sets it: every follow_up
78
+ // failure path throws or returns a RecoverableToolError, so a rejection can never count.
79
+ return isRecord(details) && typeof details.resumedFrom === "string";
80
+ }
74
81
  if (toolName === "bash") {
75
82
  if (!isRecord(details))
76
83
  return false;
@@ -1,4 +1,5 @@
1
1
  import type { Executor } from "../executor.js";
2
+ import { type FileStore } from "../file-store.js";
2
3
  import type { ChannelEvent } from "../runtime/channel-event.js";
3
4
  /**
4
5
  * Per-channel manager for background bash jobs. A long command that ran synchronously would hold
@@ -59,6 +60,8 @@ export interface JobManagerOptions {
59
60
  /** Delivers the completion wake. Omit to disable waking (sub-agent and test paths). */
60
61
  dispatch?: (event: ChannelEvent) => boolean | Promise<boolean>;
61
62
  sweepIntervalMs?: number;
63
+ /** File-content port for reading a job's spill file (spec 044, D8). Defaults to `createFileStore()`. */
64
+ fileStore?: FileStore;
62
65
  }
63
66
  /** Cap on concurrently running jobs per channel, so a runaway model can't spawn unbounded processes. */
64
67
  export declare const MAX_RUNNING_JOBS = 5;
@@ -88,6 +91,7 @@ export declare class ChannelJobManager {
88
91
  private sweeping;
89
92
  private readonly options;
90
93
  private readonly sweepIntervalMs;
94
+ private readonly fileStore;
91
95
  constructor(channelId: string, executor: Executor, options?: JobManagerOptions | number);
92
96
  private recordPath;
93
97
  /** Mirror a record to disk. Persistence is best-effort: it must never fail a job operation. */
@@ -2,6 +2,7 @@ import { randomBytes } from "node:crypto";
2
2
  import { chmod, mkdir, readdir, readFile, unlink } from "node:fs/promises";
3
3
  import { tmpdir } from "node:os";
4
4
  import { join } from "node:path";
5
+ import { createFileStore } from "../file-store.js";
5
6
  import * as log from "../log.js";
6
7
  import { writeFileAtomically } from "../shared/atomic-file.js";
7
8
  import { createSerialQueue } from "../shared/serial-queue.js";
@@ -30,6 +31,8 @@ export const SWEEP_INTERVAL_MS = 10_000;
30
31
  export const FINISHED_JOB_RETENTION_MS = 24 * 60 * 60_000;
31
32
  /** Bytes of captured output carried inline in the completion wake. */
32
33
  const WAKE_OUTPUT_TAIL_BYTES = 2_000;
34
+ /** Upper bound on how much of a spill file's tail `readOutput` reads (spec 044, D8). */
35
+ const JOB_OUTPUT_READ_MAX_BYTES = 512 * 1024;
33
36
  function jobSpillPath(id) {
34
37
  return join(tmpdir(), `pipiclaw-job-${id}.log`);
35
38
  }
@@ -82,6 +85,7 @@ export class ChannelJobManager {
82
85
  // A bare number keeps the original `sweepIntervalMs` positional form working for tests.
83
86
  this.options = typeof options === "number" ? { sweepIntervalMs: options } : options;
84
87
  this.sweepIntervalMs = this.options.sweepIntervalMs ?? SWEEP_INTERVAL_MS;
88
+ this.fileStore = this.options.fileStore ?? createFileStore();
85
89
  }
86
90
  recordPath(id) {
87
91
  return this.options.stateDir ? join(this.options.stateDir, `${id}.json`) : undefined;
@@ -531,8 +535,19 @@ export class ChannelJobManager {
531
535
  if (!record) {
532
536
  return undefined;
533
537
  }
534
- const result = await this.executor.exec(`cat ${shellEscape(record.spillFile)} 2>/dev/null || true`, { signal });
535
- return { spillFile: record.spillFile, text: result.stdout };
538
+ // Both callers (the completion wake and the `job` tool) only ever want the *tail* of a job's
539
+ // output, so read it via `FileStore` straight from the end of the file rather than shelling
540
+ // out to `cat` (spec 044, D8) -- no 10MB shell-capture cap silently eating the head of a long
541
+ // job's output before the tail-truncation logic even runs, and no subprocess for what's a
542
+ // plain local-file read.
543
+ const stat = await this.fileStore.stat(record.spillFile);
544
+ if (!stat) {
545
+ return { spillFile: record.spillFile, text: "" };
546
+ }
547
+ const start = Math.max(0, stat.size - JOB_OUTPUT_READ_MAX_BYTES);
548
+ const { data } = await this.fileStore.readBytes(record.spillFile, { start, signal });
549
+ const text = start > 0 ? `[...output truncated...]\n${data.toString("utf-8")}` : data.toString("utf-8");
550
+ return { spillFile: record.spillFile, text };
536
551
  }
537
552
  }
538
553
  // One manager per channel, shared across tool rebuilds so job records survive a resource reload —
@@ -18,7 +18,7 @@ export declare const AUTOMATIC_TURN_CONTEXT_BUDGET_UNITS = 3000;
18
18
  * Tool schemas are the larger half of the fixed per-turn cost and were the only part of it with
19
19
  * no budget at all: the runtime-authored prompt is capped at 700 units while the schemas beside it
20
20
  * run several thousand. They sit in the provider's cache prefix, so the steady-state price is low —
21
- * but every `rebuildSessionTools` (a `skill_manage` write, `/reload`, any resource reload) swaps
21
+ * but every `rebuildSessionTools` (a workspace skill write, `/reload`, any resource reload) swaps
22
22
  * that prefix and pays for all of it again.
23
23
  *
24
24
  * There is no hard cap on purpose. A schema cannot be auto-trimmed the way a prompt section can:
@@ -19,7 +19,7 @@ export const AUTOMATIC_TURN_CONTEXT_BUDGET_UNITS = 3_000;
19
19
  * Tool schemas are the larger half of the fixed per-turn cost and were the only part of it with
20
20
  * no budget at all: the runtime-authored prompt is capped at 700 units while the schemas beside it
21
21
  * run several thousand. They sit in the provider's cache prefix, so the steady-state price is low —
22
- * but every `rebuildSessionTools` (a `skill_manage` write, `/reload`, any resource reload) swaps
22
+ * but every `rebuildSessionTools` (a workspace skill write, `/reload`, any resource reload) swaps
23
23
  * that prefix and pays for all of it again.
24
24
  *
25
25
  * There is no hard cap on purpose. A schema cannot be auto-trimmed the way a prompt section can:
@@ -77,14 +77,11 @@ export function buildPromptManifest(build, finalPrompt) {
77
77
  function formatNumber(value) {
78
78
  return value.toLocaleString("en-US");
79
79
  }
80
- function pad(text, width) {
81
- return text.length >= width ? text : text + " ".repeat(width - text.length);
82
- }
83
80
  function renderWorkspaceResourceLine(label, resource) {
84
81
  if (!resource || resource.isDefaultTemplate)
85
82
  return undefined;
86
83
  const state = resource.truncated ? "truncated" : "complete";
87
- return `- ${pad(label, 10)}${formatNumber(resource.injectedUnits)} / ${formatNumber(resource.budgetUnits)} units, ${state}`;
84
+ return `- ${label}: ${formatNumber(resource.injectedUnits)} / ${formatNumber(resource.budgetUnits)} units, ${state}`;
88
85
  }
89
86
  export function renderContextReport(input) {
90
87
  const { build, finalPrompt, detail } = input;
@@ -99,12 +96,14 @@ export function renderContextReport(input) {
99
96
  }
100
97
  lines.push(`Fingerprint (Pipiclaw sections): sha256:${build.fingerprint.slice(0, 16)}`);
101
98
  lines.push("");
102
- const width = Math.max(...build.sections.map((section) => section.id.length), 12) + 2;
99
+ // Space-padded column alignment relies on a monospace font: DingTalk's proportional rendering
100
+ // collapses it back into unaligned runs, so each field is punctuation-delimited instead of
101
+ // column-aligned (review 2026-08-24 §1.3a).
103
102
  for (const section of build.sections) {
104
103
  const flags = [section.cacheClass];
105
104
  if (section.truncated)
106
105
  flags.push(`truncated from ${formatNumber(section.rawUnits)} units`);
107
- lines.push(`- ${pad(section.id, width)}${formatNumber(section.injectedUnits).padStart(6)} units ${formatNumber(section.injectedChars).padStart(7)} chars ${flags.join(", ")}`);
106
+ lines.push(`- ${section.id}: ${formatNumber(section.injectedUnits)} units, ${formatNumber(section.injectedChars)} chars, ${flags.join(", ")}`);
108
107
  }
109
108
  const soulLine = renderWorkspaceResourceLine("SOUL.md", input.soul);
110
109
  const agentsLine = renderWorkspaceResourceLine("AGENTS.md", input.agents);
@@ -59,6 +59,7 @@ export const EXECUTION_SECTION = {
59
59
  "## Working Contract",
60
60
  "- For actionable requests, continue until the requested outcome exists or you are genuinely blocked. Inspect before changing and verify material results.",
61
61
  "- State what remains unverified. Tool definitions are the source of truth for available capabilities and parameters.",
62
+ "- Background jobs and delegations wake this channel when they finish: end the turn instead of polling, scheduling a check-in, or looping to wait.",
62
63
  "- Before non-trivial use of a Pipiclaw mechanism or workspace procedure, read the matching runtime guide or skill.",
63
64
  ].join("\n"),
64
65
  };
@@ -71,8 +72,8 @@ export const INVARIANTS_SECTION = {
71
72
  maxChars: 900,
72
73
  overflow: "error",
73
74
  render: (context) => {
74
- const memoryLine = hasTool(context, "memory_manage")
75
- ? "- SESSION.md, MEMORY.md and HISTORY.md are runtime-managed; do not edit them with file tools. Use `memory_manage` in the same turn when the user explicitly asks to remember or forget something."
75
+ const memoryLine = hasTool(context, "memory_save")
76
+ ? "- SESSION.md, MEMORY.md and HISTORY.md are runtime-managed; do not edit them with file tools. Use `memory_save` / `memory_forget` in the same turn when the user explicitly asks to remember or forget something."
76
77
  : "- SESSION.md, MEMORY.md and HISTORY.md are runtime-managed; do not edit them with file tools.";
77
78
  return [
78
79
  "## Runtime Boundaries",
@@ -89,12 +90,12 @@ export const TASK_CORE_SECTION = {
89
90
  source: "runtime/tasks",
90
91
  authority: "runtime-hard",
91
92
  cacheClass: "runtime-stable",
92
- requiresAllTools: ["task_manage"],
93
+ requiresAllTools: ["task_create", "task_update", "task_close"],
93
94
  maxChars: 600,
94
95
  overflow: "error",
95
96
  render: () => [
96
97
  "## Persistent Work",
97
- "Use a task only when work must survive this turn. Follow the exact task file and runtime guide named by a task wake; use `task_manage` for lifecycle state and never expand the task's stated scope or bypass its verification gate.",
98
+ "Use a task only when work must survive this turn. Follow the exact task file and runtime guide named by a task wake; use `task_update`/`task_close` for lifecycle state and never expand the task's stated scope or bypass its verification gate.",
98
99
  ].join("\n"),
99
100
  };
100
101
  export const PLAYBOOKS_SECTION = {
@@ -128,9 +129,12 @@ export const SUBAGENTS_SECTION = {
128
129
  // (it does not count toward the 700/1200 unit budget — see builder.ts's
129
130
  // RUNTIME_AUTHORED_SECTION_IDS — so it must not be padded just because it is "free").
130
131
  if (context.subAgents.length === 0) {
132
+ const hasInline = context.tools.some((tool) => tool.name === "subagent_inline");
131
133
  return [
132
134
  "## Sub-Agents",
133
- "Delegate with `subagent`: pass an inline `systemPrompt` (no configured agent is required).",
135
+ hasInline
136
+ ? "No configured agent exists yet: delegate with `subagent_inline`, passing a `systemPrompt` (no configured agent is required)."
137
+ : "No configured agent exists and `subagent_inline` is off; ask the deployer to add a role or enable it.",
134
138
  "A sub-agent starts blank — state goal, scope, paths, constraints, acceptance criteria in `task`.",
135
139
  "Read agent-delegation.md before non-trivial delegation.",
136
140
  ].join("\n");
@@ -0,0 +1,16 @@
1
+ /**
2
+ * A shared length cap for command replies (review 2026-08-24 §1.8/§3.3 rule 5): DingTalk has no
3
+ * client-side scrolling affordance for a long plain message, so an unbounded list/report reads as
4
+ * a wall of text on mobile. Cuts on a line boundary — never mid-line — and always leaves the
5
+ * caller's own "how to see the rest" hint instead of silently dropping content.
6
+ */
7
+ export interface CapReplyOptions {
8
+ maxChars?: number;
9
+ /** What to tell the user to do next, e.g. "用更具体的筛选缩小范围" or "用 `/tasks show <id>` 查看完整内容". */
10
+ nextStepHint: string;
11
+ }
12
+ export interface CapReplyResult {
13
+ text: string;
14
+ truncated: boolean;
15
+ }
16
+ export declare function capReply(text: string, options: CapReplyOptions): CapReplyResult;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * A shared length cap for command replies (review 2026-08-24 §1.8/§3.3 rule 5): DingTalk has no
3
+ * client-side scrolling affordance for a long plain message, so an unbounded list/report reads as
4
+ * a wall of text on mobile. Cuts on a line boundary — never mid-line — and always leaves the
5
+ * caller's own "how to see the rest" hint instead of silently dropping content.
6
+ */
7
+ const DEFAULT_MAX_CHARS = 1500;
8
+ export function capReply(text, options) {
9
+ const maxChars = options.maxChars ?? DEFAULT_MAX_CHARS;
10
+ if (text.length <= maxChars) {
11
+ return { text, truncated: false };
12
+ }
13
+ const lastNewline = text.lastIndexOf("\n", maxChars);
14
+ const cut = lastNewline > 0 ? lastNewline : maxChars;
15
+ const head = text.slice(0, cut).trimEnd();
16
+ return { text: `${head}\n\n(内容过长已截断;${options.nextStepHint})`, truncated: true };
17
+ }
@@ -14,5 +14,7 @@ export interface SessionEventHandlerContext {
14
14
  ledger: UsageLedger;
15
15
  isModelCostKnown?: (modelReference: string) => boolean;
16
16
  refreshSessionResources?: () => Promise<void>;
17
+ /** Absolute path to `<workspaceDir>/skills` — see `isWorkspaceSkillWrite`. */
18
+ skillsDir?: string;
17
19
  }
18
20
  export declare function handleSessionEvent(event: unknown, context: SessionEventHandlerContext): Promise<void>;