@oyasmi/pipiclaw 0.9.3 → 0.9.4-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/channel-runner.js +137 -61
- package/dist/agent/command-extension.js +47 -34
- package/dist/agent/job-manager.js +31 -11
- package/dist/agent/model-fallback.js +1 -1
- package/dist/agent/prompt/manifest.d.ts +6 -1
- package/dist/agent/prompt/manifest.js +45 -64
- package/dist/agent/prompt/resources.js +4 -1
- package/dist/agent/run-queue.js +7 -2
- package/dist/agent/session-adapter.js +1 -1
- package/dist/agent/session-events.js +17 -6
- package/dist/agent/session-resource-gate.js +3 -1
- package/dist/agent/status-render.d.ts +0 -1
- package/dist/agent/status-render.js +4 -16
- package/dist/agent/turn-error.d.ts +31 -0
- package/dist/agent/turn-error.js +68 -0
- package/dist/app-services.js +7 -4
- package/dist/channel/channel-index.js +4 -1
- package/dist/channel/project-scope-store.js +1 -1
- package/dist/commands/catalog.d.ts +21 -4
- package/dist/commands/catalog.js +88 -41
- package/dist/commands/reply-limits.d.ts +6 -0
- package/dist/commands/reply-limits.js +24 -0
- package/dist/events/event-commands.js +94 -44
- package/dist/events/event-validation.d.ts +13 -2
- package/dist/events/event-validation.js +17 -9
- package/dist/events/events.js +77 -32
- package/dist/executor.js +2 -2
- package/dist/log.d.ts +12 -2
- package/dist/log.js +26 -34
- package/dist/main.js +1 -1
- package/dist/memory/commands.js +29 -23
- package/dist/memory/lifecycle.js +26 -5
- package/dist/memory/maintenance-state.js +4 -1
- package/dist/memory/scheduler.js +3 -1
- package/dist/models/auth-cli.js +3 -2
- package/dist/paths.d.ts +2 -0
- package/dist/paths.js +9 -0
- package/dist/playbooks/agent-delegation.md +2 -2
- package/dist/runtime/app-home.d.ts +6 -0
- package/dist/runtime/app-home.js +21 -3
- package/dist/runtime/bootstrap.js +189 -60
- package/dist/runtime/channel-queue.js +1 -1
- package/dist/runtime/delivery.js +29 -15
- package/dist/runtime/dingtalk.js +96 -42
- package/dist/runtime/durable-dispatch.d.ts +27 -1
- package/dist/runtime/durable-dispatch.js +111 -3
- package/dist/runtime/project-commands.js +16 -15
- package/dist/runtime/proxy.js +4 -2
- package/dist/runtime/report-commands.js +1 -1
- package/dist/runtime/skill-commands.d.ts +1 -1
- package/dist/runtime/skill-commands.js +17 -10
- package/dist/runtime/subagent-commands.d.ts +5 -4
- package/dist/runtime/subagent-commands.js +116 -77
- package/dist/runtime/task-commands.d.ts +1 -1
- package/dist/runtime/task-commands.js +110 -64
- package/dist/runtime/task-driver.d.ts +4 -2
- package/dist/runtime/task-driver.js +55 -20
- package/dist/runtime/task-migration.js +23 -6
- package/dist/runtime/task-spawn.js +12 -5
- package/dist/runtime/wake-coalescing.d.ts +18 -0
- package/dist/runtime/wake-coalescing.js +29 -0
- package/dist/security/block-message.d.ts +22 -1
- package/dist/security/block-message.js +66 -1
- package/dist/security/network.d.ts +2 -1
- package/dist/security/network.js +3 -2
- package/dist/security/path-guard-check.js +2 -2
- package/dist/settings.d.ts +3 -2
- package/dist/settings.js +4 -1
- package/dist/shared/format.d.ts +12 -0
- package/dist/shared/format.js +37 -0
- package/dist/shared/host-process.js +15 -3
- package/dist/shared/with-timeout.d.ts +3 -2
- package/dist/shared/with-timeout.js +14 -3
- package/dist/subagents/external/claude-code.js +23 -1
- package/dist/subagents/external/progress-tail.d.ts +17 -0
- package/dist/subagents/external/progress-tail.js +64 -17
- package/dist/subagents/external/run.d.ts +3 -0
- package/dist/subagents/external/run.js +21 -7
- package/dist/subagents/external/settlement.d.ts +3 -0
- package/dist/subagents/external/settlement.js +1 -1
- package/dist/subagents/runs.d.ts +21 -1
- package/dist/subagents/runs.js +137 -32
- package/dist/subagents/tool.d.ts +22 -15
- package/dist/subagents/tool.js +226 -32
- package/dist/subagents/workspace-summary.d.ts +16 -4
- package/dist/subagents/workspace-summary.js +74 -18
- package/dist/tasks/board.d.ts +8 -1
- package/dist/tasks/board.js +37 -2
- package/dist/tasks/frontmatter.d.ts +5 -0
- package/dist/tasks/frontmatter.js +8 -0
- package/dist/tasks/log.d.ts +11 -1
- package/dist/tasks/log.js +58 -2
- package/dist/tasks/store.js +4 -2
- package/dist/tasks/ticket.d.ts +3 -1
- package/dist/tasks/ticket.js +19 -1
- package/dist/tools/bash.js +2 -2
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.js +1 -0
- package/dist/tools/memory-manage.js +4 -1
- package/dist/tools/subagent-manage.d.ts +1 -1
- package/dist/tools/subagent-manage.js +16 -11
- package/dist/tools/task-manage/step-end.js +4 -1
- package/dist/tools/tool-details.d.ts +10 -2
- package/dist/tools/tool-details.js +39 -2
- package/dist/tui/cli.js +2 -2
- package/dist/tui/commands.js +4 -4
- package/dist/tui/pitui-frontend.js +1 -1
- package/dist/tui/renderer.js +3 -2
- package/dist/tui/turn-controller.d.ts +2 -0
- package/dist/tui/turn-controller.js +36 -21
- package/dist/usage/ledger.js +3 -1
- package/dist/usage/render.js +3 -1
- package/package.json +1 -1
|
@@ -105,7 +105,7 @@ export function resolveProjectScope(channelDir, resolution) {
|
|
|
105
105
|
if (resolution.configured && !isWithinAllowedRoots(real, resolution.policy)) {
|
|
106
106
|
return {
|
|
107
107
|
kind: "blocked",
|
|
108
|
-
reason: `项目目录
|
|
108
|
+
reason: `项目目录 \`${real}\` 已不在允许的根目录内(security.json 的 projectAccess 已变更)。请在频道空闲时用 \`/project set <路径>\` 或 \`/project reset\` 重新选择。`,
|
|
109
109
|
};
|
|
110
110
|
}
|
|
111
111
|
return { kind: "ready", scope: { projectRoot: real, boundary, sandbox }, selection: existing };
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* `memory/commands.ts`, `agent/command-extension.ts`). This file has no imports at all, so nothing
|
|
11
11
|
* here can drag a layer into another one.
|
|
12
12
|
*
|
|
13
|
-
* The
|
|
13
|
+
* The user-facing copy conventions these commands follow are recorded in AGENTS.md; `reply-limits.ts`
|
|
14
14
|
* next to this file enforces rule 5 (the length budget).
|
|
15
15
|
*/
|
|
16
16
|
export type BuiltInCommandName = "help" | "steer" | "followup" | "stop" | "events" | "tasks" | "status" | "usage" | "context" | "subagents" | "project" | "skills";
|
|
@@ -42,7 +42,7 @@ export interface CommandSubSpec {
|
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
44
|
* Single source of truth for a slash command's metadata. `HELP_TEXT`, the TUI
|
|
45
|
-
* autocomplete list, the busy-time hint, and the known-command set are all
|
|
45
|
+
* autocomplete list, the busy-time hint (`formatBusyHint`), and the known-command set are all
|
|
46
46
|
* derived from these tables — do not hand-maintain those in parallel.
|
|
47
47
|
*
|
|
48
48
|
* `subcommands`, where present, is *also* the single source for that command's own `usage()`
|
|
@@ -70,6 +70,8 @@ export interface CommandSpec {
|
|
|
70
70
|
runnerHandled?: boolean;
|
|
71
71
|
/** Broadcast list of this command's subcommands, for commands with a `/<name> <action> ...` shape. */
|
|
72
72
|
subcommands?: CommandSubSpec[];
|
|
73
|
+
/** Extra paragraph shown only in `/help <name>`, for context too specific for the top-level list. */
|
|
74
|
+
note?: string;
|
|
73
75
|
}
|
|
74
76
|
/**
|
|
75
77
|
* Transport commands: handled directly by the runtime layer (never sent to the
|
|
@@ -89,8 +91,12 @@ export declare function isBuiltInCommandName(name: string): name is BuiltInComma
|
|
|
89
91
|
export declare function isSessionCommandName(name: string): boolean;
|
|
90
92
|
/** Narrow a parsed built-in to one `ChannelRunner.handleBuiltinCommand` accepts. */
|
|
91
93
|
export declare function isRunnerBuiltInCommand(command: BuiltInCommand): command is RunnerBuiltInCommand;
|
|
92
|
-
/**
|
|
93
|
-
|
|
94
|
+
/**
|
|
95
|
+
* The reply to a slash command that cannot run mid-turn — one source for DingTalk and the TUI
|
|
96
|
+
* (spec 053, D8). Both lists are derived from `availableWhileBusy`, so a command whose busy
|
|
97
|
+
* behaviour changes moves between them on its own instead of a hand-kept list going stale.
|
|
98
|
+
*/
|
|
99
|
+
export declare function formatBusyHint(): string;
|
|
94
100
|
/**
|
|
95
101
|
* Renders a command's subcommand table as its `usage()` text — the single source `task-commands.ts`,
|
|
96
102
|
* `event-commands.ts`, `subagent-commands.ts`, `project-commands.ts`, and `memory/commands.ts` call
|
|
@@ -113,6 +119,17 @@ export declare function slashCommandName(text: string): string | null;
|
|
|
113
119
|
* every `skill:` name rather than trusting it.
|
|
114
120
|
*/
|
|
115
121
|
export declare function isKnownCommandName(name: string, knownSkillNames?: Iterable<string>): boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Replies around queueing that DingTalk and the TUI both give (spec 053, D10). One wording per
|
|
124
|
+
* situation, so the two surfaces cannot drift into two languages again.
|
|
125
|
+
*/
|
|
126
|
+
export declare function formatMissingQueueMessage(name: "steer" | "followup"): string;
|
|
127
|
+
/** `explainFollowup`: a plain busy-time message was steered implicitly, so say how to defer it instead. */
|
|
128
|
+
export declare function formatSteerQueued(explainFollowup: boolean): string;
|
|
129
|
+
export declare function formatFollowupQueued(): string;
|
|
130
|
+
export declare function formatNoRunningTurn(name: "stop" | "steer" | "followup"): string;
|
|
131
|
+
/** The `/new` confirmation, shared by the DingTalk runtime path and the session-layer command. */
|
|
132
|
+
export declare function formatNewSessionReply(sessionId: string): string;
|
|
116
133
|
export declare function formatUnknownCommandMessage(name: string): string;
|
|
117
134
|
export declare function parseBuiltInCommand(text: string): BuiltInCommand | null;
|
|
118
135
|
/**
|
package/dist/commands/catalog.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* `memory/commands.ts`, `agent/command-extension.ts`). This file has no imports at all, so nothing
|
|
11
11
|
* here can drag a layer into another one.
|
|
12
12
|
*
|
|
13
|
-
* The
|
|
13
|
+
* The user-facing copy conventions these commands follow are recorded in AGENTS.md; `reply-limits.ts`
|
|
14
14
|
* next to this file enforces rule 5 (the length budget).
|
|
15
15
|
*/
|
|
16
16
|
/**
|
|
@@ -27,7 +27,7 @@ export const BUILT_IN_COMMANDS = [
|
|
|
27
27
|
},
|
|
28
28
|
{
|
|
29
29
|
name: "stop",
|
|
30
|
-
description: "
|
|
30
|
+
description: "停止当前回合;若该回合是某个任务的一步,同时暂停该任务",
|
|
31
31
|
examples: ["/stop"],
|
|
32
32
|
availableWhileBusy: true,
|
|
33
33
|
runnerHandled: true,
|
|
@@ -35,8 +35,9 @@ export const BUILT_IN_COMMANDS = [
|
|
|
35
35
|
{
|
|
36
36
|
name: "steer",
|
|
37
37
|
argumentHint: "<消息>",
|
|
38
|
-
description: "
|
|
39
|
-
examples: ["/steer
|
|
38
|
+
description: "在当前工具调用结束后调整正在运行的回合",
|
|
39
|
+
examples: ["/steer 改用上海时区,只汇总最新的更新"],
|
|
40
|
+
note: "回合进行中直接发送的普通消息默认按 `/steer` 处理。部署者可以在 channel.json 把 `busyMessageDefault` 设为 `followUp`,改为排到当前回合之后执行;`responseMode` 控制答复的输出形态。",
|
|
40
41
|
availableWhileBusy: true,
|
|
41
42
|
runnerHandled: true,
|
|
42
43
|
},
|
|
@@ -44,7 +45,7 @@ export const BUILT_IN_COMMANDS = [
|
|
|
44
45
|
name: "followup",
|
|
45
46
|
argumentHint: "<消息>",
|
|
46
47
|
description: "排队一条请求,等当前回合结束后再执行",
|
|
47
|
-
examples: ["/followup
|
|
48
|
+
examples: ["/followup 完成后再写一份简短的总结"],
|
|
48
49
|
availableWhileBusy: true,
|
|
49
50
|
runnerHandled: true,
|
|
50
51
|
},
|
|
@@ -73,27 +74,27 @@ export const BUILT_IN_COMMANDS = [
|
|
|
73
74
|
{
|
|
74
75
|
name: "tasks",
|
|
75
76
|
argumentHint: "[show <id>|log <id>|steer <id> <内容>|reply <id> <内容>|pause <id>|resume <id> [+steps N|+usd X]|archive|doctor]",
|
|
76
|
-
description: "查看、指挥并诊断本频道的长程任务;pause
|
|
77
|
+
description: "查看、指挥并诊断本频道的长程任务;pause 只停止自动执行,保留等待条件",
|
|
77
78
|
availableWhileBusy: true,
|
|
78
79
|
subcommands: [
|
|
79
80
|
{ name: "list", description: "列出本频道进行中的任务(默认动作,可省略)", example: "/tasks" },
|
|
80
81
|
{
|
|
81
82
|
name: "show",
|
|
82
83
|
args: "<id>",
|
|
83
|
-
description: "
|
|
84
|
+
description: "查看任务说明、工作项、最近记录与用量",
|
|
84
85
|
example: "/tasks show weekly-report",
|
|
85
86
|
},
|
|
86
87
|
{
|
|
87
88
|
name: "log",
|
|
88
89
|
args: "<id>",
|
|
89
|
-
description: "
|
|
90
|
+
description: "查看该任务的记录(含每次委派的开始与结束)",
|
|
90
91
|
example: "/tasks log weekly-report",
|
|
91
92
|
},
|
|
92
93
|
{ name: "archive", description: "列出已归档(已关闭)的任务", example: "/tasks archive" },
|
|
93
94
|
{
|
|
94
95
|
name: "pause",
|
|
95
96
|
args: "<id>",
|
|
96
|
-
description: "
|
|
97
|
+
description: "停止该任务的自动执行(保留等待条件)",
|
|
97
98
|
example: "/tasks pause weekly-report",
|
|
98
99
|
},
|
|
99
100
|
{
|
|
@@ -105,7 +106,7 @@ export const BUILT_IN_COMMANDS = [
|
|
|
105
106
|
{
|
|
106
107
|
name: "steer",
|
|
107
108
|
args: "<id> <内容>",
|
|
108
|
-
description: "
|
|
109
|
+
description: "把一条指示排给该任务的下一步,不打断正在执行的这一步",
|
|
109
110
|
example: "/tasks steer weekly-report 先跑一遍 npm run check",
|
|
110
111
|
},
|
|
111
112
|
{
|
|
@@ -133,7 +134,7 @@ export const BUILT_IN_COMMANDS = [
|
|
|
133
134
|
{
|
|
134
135
|
name: "context",
|
|
135
136
|
argumentHint: "[detail]",
|
|
136
|
-
description: "
|
|
137
|
+
description: "显示实际发给模型的内容:系统提示词分段、工具定义、上一回合的上下文",
|
|
137
138
|
examples: ["/context", "/context detail"],
|
|
138
139
|
// Read-only accounting of state the runner already holds: no LLM call, no session
|
|
139
140
|
// access, so it answers mid-turn like /status and /usage do.
|
|
@@ -143,7 +144,7 @@ export const BUILT_IN_COMMANDS = [
|
|
|
143
144
|
{
|
|
144
145
|
name: "subagents",
|
|
145
146
|
argumentHint: "<list [running|failed|all]|show <id>|output <id>|cancel <id|all>|roles [name]>",
|
|
146
|
-
description: "
|
|
147
|
+
description: "查看与控制委派(内置与外部)、浏览角色目录;cancel 不经过模型,直接终止",
|
|
147
148
|
// A human control path independent of the model (spec 040, D6): /stop no longer kills a
|
|
148
149
|
// dispatched delegation, so cancel must work even when the model/turn is unavailable.
|
|
149
150
|
availableWhileBusy: true,
|
|
@@ -151,19 +152,19 @@ export const BUILT_IN_COMMANDS = [
|
|
|
151
152
|
{
|
|
152
153
|
name: "list",
|
|
153
154
|
args: "[running|failed|all]",
|
|
154
|
-
description: "
|
|
155
|
+
description: "运行中的委派,以及最近完成的几条(不带筛选时)",
|
|
155
156
|
example: "/subagents list failed",
|
|
156
157
|
},
|
|
157
158
|
{
|
|
158
159
|
name: "show",
|
|
159
160
|
args: "<runId>",
|
|
160
|
-
description: "
|
|
161
|
+
description: "单个委派的详情(含实际命令行、stderr 尾部)",
|
|
161
162
|
example: "/subagents show run_a1b2c3",
|
|
162
163
|
},
|
|
163
164
|
{
|
|
164
165
|
name: "output",
|
|
165
166
|
args: "<runId>",
|
|
166
|
-
description: "
|
|
167
|
+
description: "该委派的文本产出(output.md 尾部)",
|
|
167
168
|
example: "/subagents output run_a1b2c3",
|
|
168
169
|
},
|
|
169
170
|
{
|
|
@@ -183,7 +184,7 @@ export const BUILT_IN_COMMANDS = [
|
|
|
183
184
|
{
|
|
184
185
|
name: "project",
|
|
185
186
|
argumentHint: "[set <absolute-path>|reset]",
|
|
186
|
-
description: "
|
|
187
|
+
description: "查看或切换本频道的项目目录(读写文件与执行命令的工作目录);set/reset 需频道空闲",
|
|
187
188
|
// The read form answers like /status; set/reset validate idleness themselves and reply
|
|
188
189
|
// with a plain error instead of blocking the built-in-command dispatch path.
|
|
189
190
|
availableWhileBusy: true,
|
|
@@ -192,10 +193,10 @@ export const BUILT_IN_COMMANDS = [
|
|
|
192
193
|
{
|
|
193
194
|
name: "set",
|
|
194
195
|
args: "<absolute-path>",
|
|
195
|
-
description: "
|
|
196
|
+
description: "切换项目目录(需频道空闲,且目录在允许的根目录内)",
|
|
196
197
|
example: "/project set /home/me/projects/foo",
|
|
197
198
|
},
|
|
198
|
-
{ name: "reset", description: "
|
|
199
|
+
{ name: "reset", description: "切回默认项目目录", example: "/project reset" },
|
|
199
200
|
],
|
|
200
201
|
},
|
|
201
202
|
{
|
|
@@ -223,11 +224,11 @@ export const SESSION_COMMANDS = [
|
|
|
223
224
|
{
|
|
224
225
|
name: "memory",
|
|
225
226
|
argumentHint: "[status|list [type]|show <name>|forget <name>|journal [date]]",
|
|
226
|
-
description: "
|
|
227
|
+
description: "查看频道记忆、观察期条目与后台整理状态;不经过模型的记忆管理入口",
|
|
227
228
|
subcommands: [
|
|
228
229
|
{
|
|
229
230
|
name: "status",
|
|
230
|
-
description: "
|
|
231
|
+
description: "记忆状态概览:分类计数、观察期条目、上次整理、索引大小",
|
|
231
232
|
example: "/memory status",
|
|
232
233
|
},
|
|
233
234
|
{
|
|
@@ -239,16 +240,21 @@ export const SESSION_COMMANDS = [
|
|
|
239
240
|
{
|
|
240
241
|
name: "show",
|
|
241
242
|
args: "<name>",
|
|
242
|
-
description: "
|
|
243
|
+
description: "查看单条记忆的全文与元信息",
|
|
243
244
|
example: "/memory show deploy-window-thursday",
|
|
244
245
|
},
|
|
245
246
|
{
|
|
246
247
|
name: "forget",
|
|
247
248
|
args: "<name>",
|
|
248
|
-
description: "
|
|
249
|
+
description: "不经过模型直接删除一条记忆,并记入忽略名单,后台整理不会再自动写回",
|
|
249
250
|
example: "/memory forget deploy-window-thursday",
|
|
250
251
|
},
|
|
251
|
-
{
|
|
252
|
+
{
|
|
253
|
+
name: "journal",
|
|
254
|
+
args: "[YYYY-MM-DD]",
|
|
255
|
+
description: "查看某天的工作日记,默认今天",
|
|
256
|
+
example: "/memory journal",
|
|
257
|
+
},
|
|
252
258
|
],
|
|
253
259
|
},
|
|
254
260
|
{
|
|
@@ -278,7 +284,7 @@ export const SESSION_COMMANDS = [
|
|
|
278
284
|
name: "compact",
|
|
279
285
|
argumentHint: "[压缩要求]",
|
|
280
286
|
description: "手动压缩当前会话上下文,可附加自定义要求",
|
|
281
|
-
examples: ["/compact", "/compact
|
|
287
|
+
examples: ["/compact", "/compact 保留最新的待办和决定"],
|
|
282
288
|
},
|
|
283
289
|
];
|
|
284
290
|
const BUILT_IN_NAMES = new Set(BUILT_IN_COMMANDS.map((command) => command.name));
|
|
@@ -305,12 +311,18 @@ const RUNNER_BUILT_IN_NAMES = new Set(BUILT_IN_COMMANDS.filter((command) => comm
|
|
|
305
311
|
export function isRunnerBuiltInCommand(command) {
|
|
306
312
|
return RUNNER_BUILT_IN_NAMES.has(command.name);
|
|
307
313
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
+
function commandList(specs) {
|
|
315
|
+
return specs.map((command) => `\`/${command.name}\``).join("、");
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* The reply to a slash command that cannot run mid-turn — one source for DingTalk and the TUI
|
|
319
|
+
* (spec 053, D8). Both lists are derived from `availableWhileBusy`, so a command whose busy
|
|
320
|
+
* behaviour changes moves between them on its own instead of a hand-kept list going stale.
|
|
321
|
+
*/
|
|
322
|
+
export function formatBusyHint() {
|
|
323
|
+
const whileBusy = ALL_COMMANDS.filter((command) => command.availableWhileBusy);
|
|
324
|
+
const idleOnly = ALL_COMMANDS.filter((command) => !command.availableWhileBusy);
|
|
325
|
+
return `当前已有回合在运行。运行中可用:${commandList(whileBusy)}。${commandList(idleOnly)} 需要等空闲后再用。`;
|
|
314
326
|
}
|
|
315
327
|
/**
|
|
316
328
|
* Renders a command's subcommand table as its `usage()` text — the single source `task-commands.ts`,
|
|
@@ -331,8 +343,12 @@ function renderCommandSummaryLine(spec) {
|
|
|
331
343
|
}
|
|
332
344
|
/** The full detail for one command: argument syntax, subcommands or examples. Used by `/help <name>`. */
|
|
333
345
|
function renderCommandDetail(spec) {
|
|
334
|
-
const
|
|
335
|
-
|
|
346
|
+
const lines = [`**/${spec.name}**`, spec.description];
|
|
347
|
+
// With subcommands, each bullet already spells out its own syntax.
|
|
348
|
+
if (spec.argumentHint && !spec.subcommands?.length)
|
|
349
|
+
lines.push(`用法:\`/${spec.name} ${spec.argumentHint}\``);
|
|
350
|
+
if (spec.note)
|
|
351
|
+
lines.push(spec.note);
|
|
336
352
|
if (spec.subcommands?.length) {
|
|
337
353
|
for (const sub of spec.subcommands) {
|
|
338
354
|
const base = `- \`/${spec.name} ${sub.name}${sub.args ? ` ${sub.args}` : ""}\` — ${sub.description}`;
|
|
@@ -351,22 +367,24 @@ export function renderCommandHelp(name) {
|
|
|
351
367
|
const spec = ALL_COMMANDS.find((command) => command.name === name);
|
|
352
368
|
return spec ? renderCommandDetail(spec) : undefined;
|
|
353
369
|
}
|
|
370
|
+
/**
|
|
371
|
+
* Grouped by when a command can be used — the one thing a user needs to know before sending it —
|
|
372
|
+
* rather than by which layer handles it (spec 053, D4/D8).
|
|
373
|
+
*/
|
|
354
374
|
function renderHelpText() {
|
|
355
|
-
const
|
|
356
|
-
const
|
|
375
|
+
const anytime = ALL_COMMANDS.filter((command) => command.availableWhileBusy).map(renderCommandSummaryLine);
|
|
376
|
+
const idleOnly = ALL_COMMANDS.filter((command) => !command.availableWhileBusy).map(renderCommandSummaryLine);
|
|
357
377
|
return `**斜杠命令**
|
|
358
378
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
**传输层命令** · 由钉钉传输层/运行时直接处理,回合进行中也可以用
|
|
379
|
+
助手处理一条消息的完整过程称为一个回合。用 \`/help <命令名>\` 查看某个命令的用法和示例,例如 \`/help tasks\`。
|
|
362
380
|
|
|
363
|
-
|
|
381
|
+
**随时可用** · 回合进行中也可以发送
|
|
364
382
|
|
|
365
|
-
|
|
383
|
+
${anytime.join("\n")}
|
|
366
384
|
|
|
367
|
-
|
|
385
|
+
**空闲时可用** · 需要等当前回合结束
|
|
368
386
|
|
|
369
|
-
${
|
|
387
|
+
${idleOnly.join("\n")}
|
|
370
388
|
`;
|
|
371
389
|
}
|
|
372
390
|
const HELP_TEXT = renderHelpText();
|
|
@@ -404,6 +422,35 @@ export function isKnownCommandName(name, knownSkillNames) {
|
|
|
404
422
|
}
|
|
405
423
|
return false;
|
|
406
424
|
}
|
|
425
|
+
/**
|
|
426
|
+
* Replies around queueing that DingTalk and the TUI both give (spec 053, D10). One wording per
|
|
427
|
+
* situation, so the two surfaces cannot drift into two languages again.
|
|
428
|
+
*/
|
|
429
|
+
export function formatMissingQueueMessage(name) {
|
|
430
|
+
return `缺少消息内容。用法:\`/${name} <消息>\``;
|
|
431
|
+
}
|
|
432
|
+
/** `explainFollowup`: a plain busy-time message was steered implicitly, so say how to defer it instead. */
|
|
433
|
+
export function formatSteerQueued(explainFollowup) {
|
|
434
|
+
const base = "已作为 steer 排队,当前工具调用结束后生效。";
|
|
435
|
+
return explainFollowup ? `${base}想等整个回合结束再执行,用 \`/followup <消息>\`。` : base;
|
|
436
|
+
}
|
|
437
|
+
export function formatFollowupQueued() {
|
|
438
|
+
return "已排队,当前回合结束后执行。";
|
|
439
|
+
}
|
|
440
|
+
export function formatNoRunningTurn(name) {
|
|
441
|
+
switch (name) {
|
|
442
|
+
case "stop":
|
|
443
|
+
return "当前没有运行中的回合,`/stop` 只在回合进行中有用。";
|
|
444
|
+
case "steer":
|
|
445
|
+
return "当前没有运行中的回合,直接发消息即可,不用 `/steer`。";
|
|
446
|
+
case "followup":
|
|
447
|
+
return "当前没有运行中的回合,直接发消息即可;`/followup` 用于回合进行中排队。";
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
/** The `/new` confirmation, shared by the DingTalk runtime path and the session-layer command. */
|
|
451
|
+
export function formatNewSessionReply(sessionId) {
|
|
452
|
+
return `已开启新会话(会话 ID:\`${sessionId}\`)。`;
|
|
453
|
+
}
|
|
407
454
|
export function formatUnknownCommandMessage(name) {
|
|
408
455
|
return `未知命令 \`/${name}\`。发送 \`/help\` 查看可用命令。`;
|
|
409
456
|
}
|
|
@@ -14,3 +14,9 @@ export interface CapReplyResult {
|
|
|
14
14
|
truncated: boolean;
|
|
15
15
|
}
|
|
16
16
|
export declare function capReply(text: string, options: CapReplyOptions): CapReplyResult;
|
|
17
|
+
/**
|
|
18
|
+
* Reshape a markdown file for a chat reply (rule 3/4): `#` headings become a bold line and
|
|
19
|
+
* indentation is dropped, since DingTalk keeps neither. Fenced code blocks pass through as-is.
|
|
20
|
+
* Used where a reply quotes a file the user wrote (a task contract, a skill body).
|
|
21
|
+
*/
|
|
22
|
+
export declare function flattenMarkdownForChat(text: string): string;
|
|
@@ -15,3 +15,27 @@ export function capReply(text, options) {
|
|
|
15
15
|
const head = text.slice(0, cut).trimEnd();
|
|
16
16
|
return { text: `${head}\n\n(内容过长已截断;${options.nextStepHint})`, truncated: true };
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Reshape a markdown file for a chat reply (rule 3/4): `#` headings become a bold line and
|
|
20
|
+
* indentation is dropped, since DingTalk keeps neither. Fenced code blocks pass through as-is.
|
|
21
|
+
* Used where a reply quotes a file the user wrote (a task contract, a skill body).
|
|
22
|
+
*/
|
|
23
|
+
export function flattenMarkdownForChat(text) {
|
|
24
|
+
const out = [];
|
|
25
|
+
let fenced = false;
|
|
26
|
+
for (const raw of text.split("\n")) {
|
|
27
|
+
if (/^\s*```/.test(raw)) {
|
|
28
|
+
fenced = !fenced;
|
|
29
|
+
out.push(raw.trim());
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (fenced) {
|
|
33
|
+
out.push(raw);
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const trimmed = raw.trim();
|
|
37
|
+
const heading = /^#{1,6}\s+(.*)$/.exec(trimmed);
|
|
38
|
+
out.push(heading ? `**${heading[1]}**` : trimmed);
|
|
39
|
+
}
|
|
40
|
+
return out.join("\n").replace(/\n{3,}/g, "\n\n");
|
|
41
|
+
}
|
|
@@ -5,6 +5,7 @@ import { renderSubcommandUsage } from "../commands/catalog.js";
|
|
|
5
5
|
import { capReply } from "../commands/reply-limits.js";
|
|
6
6
|
import { normalizeSafeId, resolveSafeIdPath } from "../shared/safe-id.js";
|
|
7
7
|
import { errorMessage, eventNameFromFilename, clipText as sharedClipText } from "../shared/text-utils.js";
|
|
8
|
+
import { EventDefinitionError, validateScheduledEvent } from "./event-validation.js";
|
|
8
9
|
import { describeEventPayload, parseScheduledEventContent, } from "./events.js";
|
|
9
10
|
const EVENT_NAME_PATTERN = /^[A-Za-z0-9._-]+$/;
|
|
10
11
|
const DEFAULT_HISTORY_LIMIT = 20;
|
|
@@ -37,7 +38,7 @@ export function parseEventsCommand(args) {
|
|
|
37
38
|
throw new Error("用法:/events history [name]");
|
|
38
39
|
return name ? { action, name } : { action };
|
|
39
40
|
}
|
|
40
|
-
throw new Error(
|
|
41
|
+
throw new Error(`未知子命令 \`${action}\`。`);
|
|
41
42
|
}
|
|
42
43
|
function eventsDir(workspaceDir) {
|
|
43
44
|
return join(workspaceDir, "events");
|
|
@@ -56,60 +57,91 @@ function clipText(text, maxChars = TEXT_PREVIEW_MAX_CHARS) {
|
|
|
56
57
|
return sharedClipText(text, maxChars, { headRatio: 1, omitHint: "...", collapseWhitespace: true });
|
|
57
58
|
}
|
|
58
59
|
function formatEventSummary(name, event) {
|
|
59
|
-
const lines = [`**${name}**`, `- 类型:${event.type}`, `- channelId
|
|
60
|
+
const lines = [`**${name}**`, `- 类型:${event.type}`, `- 频道(channelId):${event.channelId}`];
|
|
60
61
|
if (event.type === "one-shot") {
|
|
61
62
|
lines.push(`- 触发时间:${event.at}`);
|
|
62
63
|
}
|
|
63
64
|
if (event.type === "periodic") {
|
|
64
|
-
lines.push(`- schedule
|
|
65
|
+
lines.push(`- 时间表(schedule):${event.schedule}`);
|
|
65
66
|
}
|
|
66
67
|
lines.push(`- 内容:${clipText(describeEventPayload(event))}`);
|
|
67
68
|
return lines.join("\n");
|
|
68
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Why a definition is invalid, in the user's terms (spec 053, D2). The error's own message is
|
|
72
|
+
* English text for the model (`event_manage`), so it is never pasted here.
|
|
73
|
+
*/
|
|
74
|
+
const PROBLEM_TEXT = {
|
|
75
|
+
malformed: "文件不是有效的 JSON",
|
|
76
|
+
"missing-field": "缺少必填字段(type、channelId、at 或 schedule,以及 text 或 task 之一)",
|
|
77
|
+
payload: "text 和 task 必须恰好填一个",
|
|
78
|
+
"task-template": "task 模板无效",
|
|
79
|
+
"pre-action": "preAction 配置无效",
|
|
80
|
+
immediate: "不再支持 immediate 类型",
|
|
81
|
+
"unknown-type": "未知的事件类型",
|
|
82
|
+
"one-shot-time": "at 不是有效的时间",
|
|
83
|
+
"one-shot-too-soon": "at 距现在不足 2 分钟",
|
|
84
|
+
"one-shot-too-far": "at 超过约 24.8 天,更远的时间请改用 periodic",
|
|
85
|
+
"cron-invalid": "schedule 不是有效的 cron 表达式",
|
|
86
|
+
"cadence-too-frequent": "触发过于频繁(没有 preAction 时至少间隔 30 分钟,有 preAction 时至少 5 分钟)",
|
|
87
|
+
"pre-action-blocked": "preAction 命令被安全策略拦截",
|
|
88
|
+
};
|
|
89
|
+
function describeEventProblem(error, name) {
|
|
90
|
+
if (error instanceof EventDefinitionError)
|
|
91
|
+
return PROBLEM_TEXT[error.kind];
|
|
92
|
+
return `定义无效,用 \`/events show ${name}\` 查看`;
|
|
93
|
+
}
|
|
94
|
+
const EMPTY_EVENTS = "暂无定时事件。\n在对话里告诉我要定时做什么,我会创建事件。";
|
|
69
95
|
async function listEvents(workspaceDir) {
|
|
70
96
|
const dir = eventsDir(workspaceDir);
|
|
71
|
-
if (!existsSync(dir))
|
|
72
|
-
return
|
|
73
|
-
}
|
|
97
|
+
if (!existsSync(dir))
|
|
98
|
+
return EMPTY_EVENTS;
|
|
74
99
|
const filenames = (await readdir(dir)).filter((filename) => filename.endsWith(".json")).sort();
|
|
75
|
-
if (filenames.length === 0)
|
|
76
|
-
return
|
|
77
|
-
}
|
|
100
|
+
if (filenames.length === 0)
|
|
101
|
+
return EMPTY_EVENTS;
|
|
78
102
|
const blocks = [];
|
|
79
103
|
for (const filename of filenames) {
|
|
80
104
|
const eventPath = join(dir, filename);
|
|
81
105
|
const name = eventNameFromFilename(filename);
|
|
82
106
|
try {
|
|
83
107
|
const event = parseScheduledEventContent(await readFile(eventPath, "utf-8"), filename);
|
|
108
|
+
// The same definition rules the watcher applies, so "listed as fine" means "will run".
|
|
109
|
+
// The lead-time rule is creation-only (an overdue one-shot is a legitimate recovery).
|
|
110
|
+
validateScheduledEvent(event, { enforceOneShotLead: false });
|
|
84
111
|
blocks.push(formatEventSummary(name, event));
|
|
85
112
|
}
|
|
86
113
|
catch (error) {
|
|
87
|
-
|
|
88
|
-
blocks.push(`**${name}**\n- ⚠ 无效:${message}`);
|
|
114
|
+
blocks.push(`**${name}**\n- ⚠️ 无效:${describeEventProblem(error, name)}`);
|
|
89
115
|
}
|
|
90
116
|
}
|
|
91
117
|
return capReply(`**定时事件**\n\n${blocks.join("\n\n")}`, {
|
|
92
118
|
nextStepHint: "用 `/events show <name>` 查看单个事件",
|
|
93
119
|
}).text;
|
|
94
120
|
}
|
|
121
|
+
function eventNotFound(eventName) {
|
|
122
|
+
return `未找到事件 \`${eventName}\`。用 \`/events list\` 查看。`;
|
|
123
|
+
}
|
|
95
124
|
async function showEvent(workspaceDir, name) {
|
|
96
125
|
const { eventName, eventPath } = resolveEventPath(workspaceDir, name);
|
|
97
|
-
if (!existsSync(eventPath))
|
|
98
|
-
return
|
|
99
|
-
}
|
|
126
|
+
if (!existsSync(eventPath))
|
|
127
|
+
return eventNotFound(eventName);
|
|
100
128
|
const raw = await readFile(eventPath, "utf-8");
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
129
|
+
let body;
|
|
130
|
+
try {
|
|
131
|
+
body = JSON.stringify(JSON.parse(raw), null, 2);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
// Show the bytes as they are: an unparseable file is exactly the case the user needs to see.
|
|
135
|
+
body = raw;
|
|
136
|
+
}
|
|
137
|
+
return capReply(`**事件 ${eventName}**\n\n\`\`\`json\n${body}\n\`\`\``, {
|
|
138
|
+
nextStepHint: `完整文件在 \`${eventPath}\``,
|
|
139
|
+
}).text;
|
|
107
140
|
}
|
|
108
141
|
async function deleteEvent(workspaceDir, name) {
|
|
109
142
|
const { eventName, eventPath } = resolveEventPath(workspaceDir, name);
|
|
110
|
-
if (!existsSync(eventPath))
|
|
111
|
-
return
|
|
112
|
-
}
|
|
143
|
+
if (!existsSync(eventPath))
|
|
144
|
+
return eventNotFound(eventName);
|
|
113
145
|
// Read before deleting so the reply carries what was removed (review 2026-08-24 §3.4):
|
|
114
146
|
// an accidental delete stays recoverable from chat history instead of a bare confirmation.
|
|
115
147
|
let summary;
|
|
@@ -121,7 +153,7 @@ async function deleteEvent(workspaceDir, name) {
|
|
|
121
153
|
// Unparseable content is still safe to delete; just skip the summary.
|
|
122
154
|
}
|
|
123
155
|
await unlink(eventPath);
|
|
124
|
-
return summary ? `已删除事件:\n\n${summary}` :
|
|
156
|
+
return summary ? `已删除事件:\n\n${summary}` : `已删除事件 \`${eventName}\`。`;
|
|
125
157
|
}
|
|
126
158
|
function parseHistoryLine(line) {
|
|
127
159
|
try {
|
|
@@ -135,28 +167,45 @@ function parseHistoryLine(line) {
|
|
|
135
167
|
return null;
|
|
136
168
|
}
|
|
137
169
|
}
|
|
170
|
+
const HISTORY_ACTION = {
|
|
171
|
+
loaded: "已加载",
|
|
172
|
+
scheduled: "已排程",
|
|
173
|
+
triggered: "已触发",
|
|
174
|
+
skipped: "已跳过",
|
|
175
|
+
enqueued: "已送达频道",
|
|
176
|
+
queue_full: "频道队列已满",
|
|
177
|
+
deleted: "已删除",
|
|
178
|
+
invalid: "无效",
|
|
179
|
+
pre_action_started: "preAction 开始",
|
|
180
|
+
pre_action_passed: "preAction 通过",
|
|
181
|
+
pre_action_blocked: "preAction 未通过",
|
|
182
|
+
pre_action_failed: "preAction 出错",
|
|
183
|
+
cancelled: "已取消",
|
|
184
|
+
};
|
|
185
|
+
const HISTORY_RESULT = { ok: "成功", error: "失败", skipped: "跳过" };
|
|
186
|
+
/** `2026-10-11T14:02:33.000+08:00` → `10-11 14:02`. */
|
|
187
|
+
function minuteStamp(ts) {
|
|
188
|
+
const match = /^\d{4}-(\d{2}-\d{2})T(\d{2}:\d{2})/.exec(ts);
|
|
189
|
+
return match ? `${match[1]} ${match[2]}` : ts;
|
|
190
|
+
}
|
|
191
|
+
/** One flat bullet per record; the operator detail (`reason`) is quoted as-is, it is a log entry. */
|
|
138
192
|
function formatHistoryRecord(record) {
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if (record.schedule)
|
|
143
|
-
details.push(`- schedule:${record.schedule}`);
|
|
144
|
-
if (record.at)
|
|
145
|
-
details.push(`- 触发时间:${record.at}`);
|
|
193
|
+
const action = HISTORY_ACTION[record.action] ?? record.action;
|
|
194
|
+
const result = HISTORY_RESULT[record.result] ?? record.result;
|
|
195
|
+
const bits = [`${minuteStamp(record.ts)} ${record.eventName}`, `${action}(${result})`];
|
|
146
196
|
if (record.nextRunAt)
|
|
147
|
-
|
|
197
|
+
bits.push(`下次 ${minuteStamp(record.nextRunAt)}`);
|
|
148
198
|
if (record.reason)
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
details.push(`- 内容:${clipText(record.textPreview)}`);
|
|
152
|
-
const header = `**${record.ts} ${record.eventName}** ${record.action} · ${record.result}`;
|
|
153
|
-
return details.length > 0 ? `${header}\n${details.join("\n")}` : header;
|
|
199
|
+
bits.push(`详情:\`${clipText(record.reason.replace(/`/g, "'"))}\``);
|
|
200
|
+
return `- ${bits.join(" · ")}`;
|
|
154
201
|
}
|
|
155
202
|
async function showHistory(historyPath, name) {
|
|
156
203
|
const eventName = name ? normalizeEventName(name) : undefined;
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
204
|
+
const empty = eventName
|
|
205
|
+
? `暂无事件 \`${eventName}\` 的触发记录。\n事件触发后会记录在这里。`
|
|
206
|
+
: "暂无事件触发记录。\n事件触发后会记录在这里。";
|
|
207
|
+
if (!existsSync(historyPath))
|
|
208
|
+
return empty;
|
|
160
209
|
const raw = await readFile(historyPath, "utf-8");
|
|
161
210
|
const records = raw
|
|
162
211
|
.split("\n")
|
|
@@ -167,11 +216,12 @@ async function showHistory(historyPath, name) {
|
|
|
167
216
|
.filter((record) => !eventName || record.eventName === eventName)
|
|
168
217
|
.slice(-DEFAULT_HISTORY_LIMIT)
|
|
169
218
|
.reverse();
|
|
170
|
-
if (records.length === 0)
|
|
171
|
-
return
|
|
172
|
-
}
|
|
219
|
+
if (records.length === 0)
|
|
220
|
+
return empty;
|
|
173
221
|
const suffix = eventName ? ` · ${eventName}` : "";
|
|
174
|
-
return `**事件历史**${suffix}
|
|
222
|
+
return capReply(`**事件历史**${suffix}(最近 ${records.length} 条)\n\n${records.map(formatHistoryRecord).join("\n")}`, {
|
|
223
|
+
nextStepHint: `用 \`/events history <name>\` 只看一个事件;完整记录在 \`${historyPath}\``,
|
|
224
|
+
}).text;
|
|
175
225
|
}
|
|
176
226
|
export async function handleEventsCommand(options) {
|
|
177
227
|
let command;
|
|
@@ -24,10 +24,21 @@ export declare const MIN_PERIODIC_INTERVAL_MS: number;
|
|
|
24
24
|
export declare const MIN_PERIODIC_INTERVAL_WITH_PREACTION_MS: number;
|
|
25
25
|
/** sanity cap on total scheduled events to keep the directory (and the scheduler) from being flooded. */
|
|
26
26
|
export declare const MAX_EVENT_FILES = 50;
|
|
27
|
-
|
|
27
|
+
/**
|
|
28
|
+
* What is wrong with an event definition, as data (spec 053, D2). The error `message` is English
|
|
29
|
+
* and written for the model (`event_manage` returns it as a recoverable rejection); `/events list`
|
|
30
|
+
* renders `kind` in the user's terms instead of pasting that text into the chat.
|
|
31
|
+
*/
|
|
32
|
+
export type EventProblemKind = "malformed" | "missing-field" | "payload" | "task-template" | "pre-action" | "immediate" | "unknown-type" | "one-shot-time" | "one-shot-too-soon" | "one-shot-too-far" | "cron-invalid" | "cadence-too-frequent" | "pre-action-blocked";
|
|
33
|
+
/** A definition the file parser rejects. Kept distinct from `EventValidationError`, which the tool treats as model-fixable. */
|
|
34
|
+
export declare class EventDefinitionError extends Error {
|
|
35
|
+
readonly kind: EventProblemKind;
|
|
36
|
+
constructor(kind: EventProblemKind, message: string);
|
|
37
|
+
}
|
|
38
|
+
export declare class EventValidationError extends EventDefinitionError {
|
|
28
39
|
/** Whether the model can usefully retry with a corrected definition. */
|
|
29
40
|
readonly recoverable: boolean;
|
|
30
|
-
constructor(message: string, recoverable?: boolean);
|
|
41
|
+
constructor(kind: EventProblemKind, message: string, recoverable?: boolean);
|
|
31
42
|
}
|
|
32
43
|
export declare function validateOneShotLead(event: ScheduledEvent & {
|
|
33
44
|
type: "one-shot";
|