@oyasmi/pipiclaw 0.9.1-beta.2 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/channel-runner.d.ts +7 -0
- package/dist/agent/channel-runner.js +42 -13
- package/dist/agent/command-extension.js +24 -27
- package/dist/agent/commands.d.ts +51 -7
- package/dist/agent/commands.js +199 -59
- package/dist/agent/prompt/manifest.js +5 -6
- package/dist/agent/prompt/sections.js +1 -0
- package/dist/agent/reply-limits.d.ts +16 -0
- package/dist/agent/reply-limits.js +17 -0
- package/dist/agent/session-events.js +2 -2
- package/dist/agent/status-render.js +12 -12
- package/dist/executor.d.ts +14 -0
- package/dist/executor.js +36 -6
- package/dist/main.js +3 -4
- package/dist/memory/commands.js +79 -38
- package/dist/memory/consolidation.d.ts +5 -1
- package/dist/memory/consolidation.js +33 -12
- package/dist/memory/extraction.d.ts +8 -1
- package/dist/memory/extraction.js +47 -4
- package/dist/memory/files.d.ts +0 -1
- package/dist/memory/files.js +24 -5
- package/dist/memory/lifecycle.js +9 -2
- package/dist/memory/maintenance-jobs.js +14 -4
- package/dist/memory/metadata.d.ts +3 -0
- package/dist/memory/metadata.js +7 -0
- package/dist/memory/recall.d.ts +9 -0
- package/dist/memory/recall.js +101 -17
- package/dist/memory/review-log.d.ts +0 -2
- package/dist/memory/review-log.js +0 -0
- package/dist/memory/session-corpus.js +5 -0
- package/dist/memory/session-search.js +9 -0
- package/dist/memory/sidecar-worker.js +4 -0
- package/dist/memory/source-window.d.ts +0 -1
- package/dist/memory/source-window.js +0 -5
- package/dist/playbooks/agent-delegation.md +32 -25
- package/dist/playbooks/background-jobs.md +8 -16
- package/dist/playbooks/event-scheduling.md +13 -15
- package/dist/playbooks/memory-and-learning.md +29 -22
- package/dist/playbooks/outbound-media.md +15 -8
- package/dist/playbooks/runtime-orientation.md +40 -37
- package/dist/playbooks/task-driving.md +34 -36
- package/dist/playbooks/task-planning.md +18 -18
- package/dist/runtime/app-home.d.ts +6 -0
- package/dist/runtime/app-home.js +15 -6
- package/dist/runtime/bootstrap.js +44 -13
- package/dist/runtime/channel-context.d.ts +2 -1
- package/dist/runtime/delivery.js +3 -3
- package/dist/runtime/dingtalk.d.ts +9 -1
- package/dist/runtime/dingtalk.js +27 -13
- package/dist/runtime/event-commands.d.ts +15 -0
- package/dist/runtime/event-commands.js +48 -40
- package/dist/runtime/project-commands.d.ts +16 -0
- package/dist/runtime/project-commands.js +13 -17
- package/dist/runtime/subagent-commands.d.ts +20 -0
- package/dist/runtime/subagent-commands.js +61 -58
- package/dist/runtime/task-commands.d.ts +37 -0
- package/dist/runtime/task-commands.js +106 -64
- package/dist/security/path-guard.js +33 -2
- package/dist/security/types.d.ts +9 -0
- package/dist/subagents/discovery.d.ts +7 -2
- package/dist/subagents/discovery.js +31 -7
- package/dist/subagents/external/claude-code.js +42 -2
- package/dist/subagents/external/run.js +61 -8
- package/dist/subagents/runs.js +6 -0
- package/dist/subagents/tool.d.ts +1 -0
- package/dist/subagents/tool.js +62 -53
- package/dist/tasks/verification.d.ts +7 -5
- package/dist/tools/bash.d.ts +1 -1
- package/dist/tools/bash.js +77 -59
- package/dist/tools/edit.js +17 -4
- package/dist/tools/grep.js +3 -2
- package/dist/tools/index.js +4 -0
- package/dist/tools/job.js +2 -1
- package/dist/tools/memory-manage.d.ts +1 -0
- package/dist/tools/memory-manage.js +54 -16
- package/dist/tools/read.js +21 -5
- package/dist/tools/send-media.js +17 -6
- package/dist/tools/skill-manage.js +12 -11
- package/dist/tools/skill-security.js +1 -1
- package/dist/tools/task-manage.js +1 -1
- package/dist/tools/truncate.d.ts +8 -0
- package/dist/tools/truncate.js +8 -0
- package/dist/tools/web-fetch.js +9 -1
- package/dist/tools/write-content.js +11 -1
- package/dist/tui/app.js +1 -1
- package/dist/tui/commands.d.ts +1 -1
- package/dist/tui/commands.js +1 -1
- package/dist/tui/turn-controller.d.ts +1 -1
- package/dist/tui/turn-controller.js +14 -4
- package/dist/usage/render.js +10 -8
- package/examples/sub-agents/README.md +2 -0
- package/package.json +3 -2
package/dist/agent/commands.js
CHANGED
|
@@ -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> <字段> <值>|
|
|
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>|
|
|
120
|
-
description: "
|
|
121
|
-
|
|
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
|
|
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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(
|
|
188
|
-
const session = SESSION_COMMANDS.map(
|
|
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
|
-
|
|
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
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
252
|
-
|
|
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
|
}
|
|
@@ -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 `- ${
|
|
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
|
-
|
|
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(`- ${
|
|
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
|
};
|
|
@@ -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
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as log from "../log.js";
|
|
2
2
|
import { extractLabelFromArgs, truncate } from "../shared/text-utils.js";
|
|
3
3
|
import { isRecord } from "../shared/type-guards.js";
|
|
4
|
-
import { toolResultDetails } from "../tools/tool-details.js";
|
|
4
|
+
import { isRecoverableRejection, toolResultDetails } from "../tools/tool-details.js";
|
|
5
5
|
import { isEffectfulTool, noteChannelEffect } from "./effect-ledger.js";
|
|
6
6
|
import { extractToolResultText, formatProgressEntry } from "./progress-formatter.js";
|
|
7
7
|
import { extractCustomCommandResultText, isAssistantEventMessage, isAutoCompactionEndEvent, isAutoCompactionStartEvent, isAutoRetryStartEvent, isMessageEndEvent, isMessageStartEvent, isSubAgentToolDetails, isTextPart, isThinkingPart, isToolExecutionEndEvent, isToolExecutionStartEvent, isToolExecutionUpdateEvent, isTurnEndEvent, } from "./type-guards.js";
|
|
@@ -106,7 +106,7 @@ export async function handleSessionEvent(event, context) {
|
|
|
106
106
|
// still diagnosable, but never rendered to the user — a red bubble would report a failure
|
|
107
107
|
// that never happened and make the assistant look broken mid-turn. Rejections the *user*
|
|
108
108
|
// must resolve (a security guard refusal or an external decision) stay plain errors and remain visible.
|
|
109
|
-
const rejected =
|
|
109
|
+
const rejected = isRecoverableRejection(event.result);
|
|
110
110
|
const treatAsError = event.isError || Boolean(subAgentDetails?.failed);
|
|
111
111
|
if (treatAsError) {
|
|
112
112
|
log.logToolError(logCtx, event.toolName, durationMs, resultStr);
|
|
@@ -26,39 +26,39 @@ export function formatUptime(ms) {
|
|
|
26
26
|
}
|
|
27
27
|
export function renderStatus(options) {
|
|
28
28
|
const { runner, version, uptimeMs } = options;
|
|
29
|
-
|
|
29
|
+
let runState;
|
|
30
30
|
if (runner?.isBusy()) {
|
|
31
31
|
const task = runner.getTurnStatus().taskText?.trim();
|
|
32
|
-
const preview = task ?
|
|
33
|
-
|
|
32
|
+
const preview = task ? `:${task.length > 80 ? `${task.slice(0, 79)}…` : task}` : "";
|
|
33
|
+
runState = `运行中${preview}`;
|
|
34
34
|
}
|
|
35
35
|
else {
|
|
36
|
-
|
|
36
|
+
runState = "空闲";
|
|
37
37
|
}
|
|
38
|
+
const lines = [`**状态** · ${runState}`];
|
|
38
39
|
if (runner) {
|
|
39
40
|
try {
|
|
40
41
|
const snapshot = runner.getStatusSnapshot();
|
|
41
|
-
|
|
42
|
-
lines.push(`- Thinking: ${snapshot.thinkingLevel}`);
|
|
42
|
+
let modelLine = `- 模型:\`${snapshot.model}\`(thinking \`${snapshot.thinkingLevel}\`)`;
|
|
43
43
|
if (snapshot.fallback) {
|
|
44
44
|
const until = new Date(snapshot.fallback.cooldownUntilMs);
|
|
45
45
|
const hh = String(until.getHours()).padStart(2, "0");
|
|
46
46
|
const mm = String(until.getMinutes()).padStart(2, "0");
|
|
47
|
-
|
|
47
|
+
modelLine += ` · fallback 生效中(primary ${snapshot.fallback.primary} 冷却至 ${hh}:${mm})`;
|
|
48
48
|
}
|
|
49
|
+
lines.push(modelLine);
|
|
49
50
|
if (snapshot.contextTokens !== undefined && snapshot.contextWindow > 0) {
|
|
50
51
|
const percent = ((snapshot.contextTokens / snapshot.contextWindow) * 100).toFixed(1);
|
|
51
|
-
lines.push(`-
|
|
52
|
+
lines.push(`- 上下文:${formatTokenCount(snapshot.contextTokens)} / ${formatTokenCount(snapshot.contextWindow)}(${percent}%)`);
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
catch (err) {
|
|
55
|
-
lines.push(`-
|
|
56
|
+
lines.push(`- 模型:不可用(${errorMessage(err)})`);
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
59
|
else {
|
|
59
|
-
lines.push("-
|
|
60
|
+
lines.push("- 模型:本频道尚未开始过会话");
|
|
60
61
|
}
|
|
61
|
-
lines.push(`-
|
|
62
|
-
lines.push(`- Version: ${version}`);
|
|
62
|
+
lines.push(`- 已运行 ${formatUptime(uptimeMs)} · 版本 \`${version}\``);
|
|
63
63
|
return lines.join("\n");
|
|
64
64
|
}
|
package/dist/executor.d.ts
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
* Create an executor that runs commands on the host machine.
|
|
3
3
|
*/
|
|
4
4
|
export declare function createExecutor(): Executor;
|
|
5
|
+
/**
|
|
6
|
+
* Thrown instead of a plain `Error` when a command is cut short by timeout or abort. Kept
|
|
7
|
+
* deliberately short (no stdout/stderr in the message) because the caught `Error.message` is what
|
|
8
|
+
* a pi SDK tool-call rejection puts, verbatim and untruncated, into the model's context (fix plan
|
|
9
|
+
* §2.2) -- `stdout`/`stderr` are still here for a caller (bash.ts) that wants to show a truncated
|
|
10
|
+
* tail instead of losing the partial output outright.
|
|
11
|
+
*/
|
|
12
|
+
export declare class CommandTerminatedError extends Error {
|
|
13
|
+
readonly stdout: string;
|
|
14
|
+
readonly stderr: string;
|
|
15
|
+
readonly reason: "timeout" | "aborted";
|
|
16
|
+
readonly timeoutSeconds?: number;
|
|
17
|
+
constructor(reason: "timeout" | "aborted", stdout: string, stderr: string, timeoutSeconds?: number);
|
|
18
|
+
}
|
|
5
19
|
export interface Executor {
|
|
6
20
|
/**
|
|
7
21
|
* Execute a bash command
|
package/dist/executor.js
CHANGED
|
@@ -1,10 +1,28 @@
|
|
|
1
1
|
import { spawn } from "child_process";
|
|
2
|
+
const MAX_CAPTURE_BYTES = 10 * 1024 * 1024;
|
|
2
3
|
/**
|
|
3
4
|
* Create an executor that runs commands on the host machine.
|
|
4
5
|
*/
|
|
5
6
|
export function createExecutor() {
|
|
6
7
|
return new HostExecutor();
|
|
7
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Thrown instead of a plain `Error` when a command is cut short by timeout or abort. Kept
|
|
11
|
+
* deliberately short (no stdout/stderr in the message) because the caught `Error.message` is what
|
|
12
|
+
* a pi SDK tool-call rejection puts, verbatim and untruncated, into the model's context (fix plan
|
|
13
|
+
* §2.2) -- `stdout`/`stderr` are still here for a caller (bash.ts) that wants to show a truncated
|
|
14
|
+
* tail instead of losing the partial output outright.
|
|
15
|
+
*/
|
|
16
|
+
export class CommandTerminatedError extends Error {
|
|
17
|
+
constructor(reason, stdout, stderr, timeoutSeconds) {
|
|
18
|
+
super(reason === "timeout" ? `Command timed out after ${timeoutSeconds} seconds` : "Command aborted");
|
|
19
|
+
this.name = "CommandTerminatedError";
|
|
20
|
+
this.reason = reason;
|
|
21
|
+
this.stdout = stdout;
|
|
22
|
+
this.stderr = stderr;
|
|
23
|
+
this.timeoutSeconds = timeoutSeconds;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
8
26
|
class HostExecutor {
|
|
9
27
|
async exec(command, options) {
|
|
10
28
|
return new Promise((resolve, reject) => {
|
|
@@ -26,6 +44,8 @@ class HostExecutor {
|
|
|
26
44
|
}
|
|
27
45
|
let stdout = "";
|
|
28
46
|
let stderr = "";
|
|
47
|
+
let stdoutCapped = false;
|
|
48
|
+
let stderrCapped = false;
|
|
29
49
|
let timedOut = false;
|
|
30
50
|
let settled = false;
|
|
31
51
|
const cleanup = () => {
|
|
@@ -67,16 +87,26 @@ class HostExecutor {
|
|
|
67
87
|
options.signal.addEventListener("abort", onAbort, { once: true });
|
|
68
88
|
}
|
|
69
89
|
}
|
|
90
|
+
// Capped-and-discard rather than "append then re-slice to the cap every chunk": the latter
|
|
91
|
+
// re-copies up to MAX_CAPTURE_BYTES on every single data event once a command is already
|
|
92
|
+
// at the cap, which for a high-output command is many GB of memcpy that blocks the event
|
|
93
|
+
// loop for the whole daemon (fix plan §2.2).
|
|
70
94
|
child.stdout?.on("data", (data) => {
|
|
95
|
+
if (stdoutCapped)
|
|
96
|
+
return;
|
|
71
97
|
stdout += data.toString();
|
|
72
|
-
if (stdout.length >
|
|
73
|
-
stdout = stdout.slice(0,
|
|
98
|
+
if (stdout.length > MAX_CAPTURE_BYTES) {
|
|
99
|
+
stdout = stdout.slice(0, MAX_CAPTURE_BYTES);
|
|
100
|
+
stdoutCapped = true;
|
|
74
101
|
}
|
|
75
102
|
});
|
|
76
103
|
child.stderr?.on("data", (data) => {
|
|
104
|
+
if (stderrCapped)
|
|
105
|
+
return;
|
|
77
106
|
stderr += data.toString();
|
|
78
|
-
if (stderr.length >
|
|
79
|
-
stderr = stderr.slice(0,
|
|
107
|
+
if (stderr.length > MAX_CAPTURE_BYTES) {
|
|
108
|
+
stderr = stderr.slice(0, MAX_CAPTURE_BYTES);
|
|
109
|
+
stderrCapped = true;
|
|
80
110
|
}
|
|
81
111
|
});
|
|
82
112
|
child.on("error", (err) => {
|
|
@@ -84,11 +114,11 @@ class HostExecutor {
|
|
|
84
114
|
});
|
|
85
115
|
child.on("close", (code) => {
|
|
86
116
|
if (options?.signal?.aborted) {
|
|
87
|
-
rejectOnce(new
|
|
117
|
+
rejectOnce(new CommandTerminatedError("aborted", stdout, stderr));
|
|
88
118
|
return;
|
|
89
119
|
}
|
|
90
120
|
if (timedOut) {
|
|
91
|
-
rejectOnce(new
|
|
121
|
+
rejectOnce(new CommandTerminatedError("timeout", stdout, stderr, options?.timeout));
|
|
92
122
|
return;
|
|
93
123
|
}
|
|
94
124
|
resolveOnce({ stdout, stderr, code: code ?? 0 });
|
package/dist/main.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { runAuth } from "./models/auth-cli.js";
|
|
3
|
-
import { isBootstrapExitError } from "./runtime/app-home.js";
|
|
3
|
+
import { formatCliCommandsHelp, isBootstrapExitError } from "./runtime/app-home.js";
|
|
4
4
|
import { bootstrap } from "./runtime/bootstrap.js";
|
|
5
5
|
import { runTui } from "./tui/cli.js";
|
|
6
6
|
function handleError(error) {
|
|
@@ -31,9 +31,8 @@ else if (command === undefined || command === "run" || command.startsWith("-"))
|
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
33
33
|
console.error(`Unknown command: ${command}`);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
console.error(" pipiclaw auth status|login|logout Manage provider credentials");
|
|
34
|
+
for (const line of formatCliCommandsHelp("pipiclaw"))
|
|
35
|
+
console.error(line);
|
|
37
36
|
console.error("Run `pipiclaw --help` for options.");
|
|
38
37
|
process.exit(1);
|
|
39
38
|
}
|