@oyasmi/pipiclaw 0.9.3-beta.6 → 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/README.en.md +1 -1
- package/README.md +1 -1
- 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.d.ts +9 -2
- package/dist/channel/channel-index.js +29 -7
- 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 +192 -64
- 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 +6 -3
- package/dist/runtime/task-driver.js +57 -22
- package/dist/runtime/task-migration.d.ts +7 -2
- package/dist/runtime/task-migration.js +247 -61
- 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.d.ts +18 -1
- package/dist/tasks/store.js +61 -9
- 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
|
@@ -55,6 +55,40 @@ function withRedeliveryNotice(event, deliveries) {
|
|
|
55
55
|
event.text,
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* What a wake was for, in the user's terms (spec 053, D2). The wake's own `text` is a prompt for
|
|
60
|
+
* the model and its `user` an internal producer tag (`TASK_DRIVER`, `SUBAGENT`, …), so neither
|
|
61
|
+
* may reach the chat; every in-process producer prefixes its text with a `[KIND:id…]` tag, which
|
|
62
|
+
* is what this reads instead.
|
|
63
|
+
*/
|
|
64
|
+
function describeWakeSource(event) {
|
|
65
|
+
const tag = /^\[(TASK_DRIVER|SUBAGENT|JOB|EVENT):([^:\]\s]+)/.exec(event.text);
|
|
66
|
+
const id = tag?.[2];
|
|
67
|
+
switch (tag?.[1]) {
|
|
68
|
+
case "TASK_DRIVER":
|
|
69
|
+
return { label: `任务 \`${id}\` 的一次后台唤醒`, nextStep: `用 \`/tasks show ${id}\` 确认任务状态` };
|
|
70
|
+
case "SUBAGENT":
|
|
71
|
+
return { label: `委派 \`${id}\` 的完成通知`, nextStep: `用 \`/subagents show ${id}\` 查看结果` };
|
|
72
|
+
case "JOB":
|
|
73
|
+
return { label: `后台作业 \`${id}\` 的完成通知`, nextStep: "需要时让我查看这个作业的结果" };
|
|
74
|
+
case "EVENT": {
|
|
75
|
+
const name = id?.replace(/\.json$/, "");
|
|
76
|
+
return { label: `定时事件 \`${name}\` 的一次触发`, nextStep: `用 \`/events history ${name}\` 查看触发记录` };
|
|
77
|
+
}
|
|
78
|
+
default:
|
|
79
|
+
return { label: "一次后台唤醒" };
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The notice a channel gets when a wake is given up on (`onExhausted`). It names the source and
|
|
84
|
+
* the record's absolute path — never the wake text, which is a model prompt (spec 053, D2/D6).
|
|
85
|
+
*/
|
|
86
|
+
export function renderDispatchExhaustedNotice(record, stateDir) {
|
|
87
|
+
const source = describeWakeSource(record.event);
|
|
88
|
+
const where = `排查记录在 \`${recordPath(stateDir, record.id)}\``;
|
|
89
|
+
return (`⚠️ ${source.label}连续 ${record.deliveries} 次未能完成,已停止重试。\n` +
|
|
90
|
+
(source.nextStep ? `${source.nextStep};${where}。` : `${where}。`));
|
|
91
|
+
}
|
|
58
92
|
function dispatchId(event) {
|
|
59
93
|
return createHash("sha256")
|
|
60
94
|
.update(JSON.stringify([event.channelId, event.user, event.ts, event.text, event.conversationId]))
|
|
@@ -105,6 +139,12 @@ export class DurableDispatchService {
|
|
|
105
139
|
* lease lapses.
|
|
106
140
|
*/
|
|
107
141
|
this.running = new Set();
|
|
142
|
+
/**
|
|
143
|
+
* Queued dispatch ids folded into another record's turn by `absorbPending`. Each still has its
|
|
144
|
+
* own closure waiting in the channel queue; `markStarted` turns that stale delivery away instead
|
|
145
|
+
* of running the same wake a second time.
|
|
146
|
+
*/
|
|
147
|
+
this.absorbed = new Set();
|
|
108
148
|
this.leaseMs = options.leaseMs ?? DEFAULT_LEASE_MS;
|
|
109
149
|
}
|
|
110
150
|
start() {
|
|
@@ -121,7 +161,7 @@ export class DurableDispatchService {
|
|
|
121
161
|
*/
|
|
122
162
|
drainSafely() {
|
|
123
163
|
this.drainOnce().catch((error) => {
|
|
124
|
-
log.
|
|
164
|
+
log.logWarn("dispatch.drain.failed", "Durable dispatch drain failed", { reason: errorMessage(error) });
|
|
125
165
|
});
|
|
126
166
|
}
|
|
127
167
|
stop() {
|
|
@@ -179,6 +219,8 @@ export class DurableDispatchService {
|
|
|
179
219
|
// Drop the liveness claim too, or the renew branch above would keep this record
|
|
180
220
|
// alive forever and the cancelled turn would never be redelivered.
|
|
181
221
|
this.running.delete(id);
|
|
222
|
+
// `/stop` already dropped the queued closures; the redelivery must not be turned away.
|
|
223
|
+
this.absorbed.delete(id);
|
|
182
224
|
record.leaseExpiresAt = undefined;
|
|
183
225
|
await this.write(record);
|
|
184
226
|
canceled++;
|
|
@@ -186,9 +228,15 @@ export class DurableDispatchService {
|
|
|
186
228
|
}
|
|
187
229
|
return canceled;
|
|
188
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* Claim a dispatch for the turn about to run it. Returns false — run nothing — for a stale
|
|
233
|
+
* delivery of a record another turn already absorbed (see `absorbPending`).
|
|
234
|
+
*/
|
|
189
235
|
async markStarted(id) {
|
|
190
236
|
if (!id)
|
|
191
|
-
return;
|
|
237
|
+
return true;
|
|
238
|
+
if (this.absorbed.delete(id))
|
|
239
|
+
return false;
|
|
192
240
|
this.running.add(id);
|
|
193
241
|
await this.queue.run(id, async () => {
|
|
194
242
|
const record = await this.read(id);
|
|
@@ -198,6 +246,63 @@ export class DurableDispatchService {
|
|
|
198
246
|
record.leaseExpiresAt = new Date(Date.now() + this.leaseMs).toISOString();
|
|
199
247
|
await this.write(record);
|
|
200
248
|
});
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Fold other not-yet-started dispatches of `channelId` that `accept` into the turn that is
|
|
253
|
+
* starting `primaryId`, oldest first, at most `limit` of them. Each one is claimed exactly as
|
|
254
|
+
* `markStarted` would claim it (running, leased, counted as a delivery), so the caller must
|
|
255
|
+
* finish every returned id with `markCompleted` / `markRetryable` alongside the primary — and a
|
|
256
|
+
* crash mid-turn redelivers each of them on its own, unchanged. Returned events carry their
|
|
257
|
+
* own redelivery notice, like a normal delivery would.
|
|
258
|
+
*/
|
|
259
|
+
async absorbPending(channelId, primaryId, accept, limit) {
|
|
260
|
+
if (limit <= 0)
|
|
261
|
+
return [];
|
|
262
|
+
let filenames;
|
|
263
|
+
try {
|
|
264
|
+
filenames = (await readdir(this.options.stateDir)).filter((name) => name.endsWith(".json"));
|
|
265
|
+
}
|
|
266
|
+
catch {
|
|
267
|
+
return [];
|
|
268
|
+
}
|
|
269
|
+
const candidates = [];
|
|
270
|
+
for (const filename of filenames) {
|
|
271
|
+
const id = decodeDispatchId(filename.slice(0, -".json".length));
|
|
272
|
+
if (id === primaryId || this.running.has(id))
|
|
273
|
+
continue;
|
|
274
|
+
const record = await this.read(id);
|
|
275
|
+
if (record && this.isAbsorbable(record, channelId, accept))
|
|
276
|
+
candidates.push({ id, createdAt: record.createdAt });
|
|
277
|
+
}
|
|
278
|
+
candidates.sort((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
279
|
+
const events = [];
|
|
280
|
+
for (const { id } of candidates.slice(0, limit)) {
|
|
281
|
+
await this.queue.run(id, async () => {
|
|
282
|
+
// Re-checked under the record's own lock: a drain or its own delivery may have moved it.
|
|
283
|
+
const record = await this.read(id);
|
|
284
|
+
if (!record || this.running.has(id) || !this.isAbsorbable(record, channelId, accept))
|
|
285
|
+
return;
|
|
286
|
+
if (record.status === "queued")
|
|
287
|
+
this.absorbed.add(id);
|
|
288
|
+
else
|
|
289
|
+
record.deliveries++;
|
|
290
|
+
record.status = "running";
|
|
291
|
+
record.leaseExpiresAt = new Date(Date.now() + this.leaseMs).toISOString();
|
|
292
|
+
record.nextAttemptAt = undefined;
|
|
293
|
+
this.running.add(id);
|
|
294
|
+
await this.write(record);
|
|
295
|
+
events.push(withRedeliveryNotice({ ...record.event, dispatchId: record.id }, record.deliveries));
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
return events;
|
|
299
|
+
}
|
|
300
|
+
/** Not started anywhere: still waiting for delivery (`pending`) or queued behind the current turn. */
|
|
301
|
+
isAbsorbable(record, channelId, accept) {
|
|
302
|
+
return (record.event.channelId === channelId &&
|
|
303
|
+
(record.status === "pending" || record.status === "queued") &&
|
|
304
|
+
record.deliveries < MAX_DELIVERIES &&
|
|
305
|
+
accept(record.event));
|
|
201
306
|
}
|
|
202
307
|
async markCompleted(id) {
|
|
203
308
|
if (!id)
|
|
@@ -283,7 +388,10 @@ export class DurableDispatchService {
|
|
|
283
388
|
await this.options.onExhausted?.(record);
|
|
284
389
|
}
|
|
285
390
|
catch (err) {
|
|
286
|
-
log.
|
|
391
|
+
log.logWarn("dispatch.exhausted_handler.failed", "Exhausted-dispatch handler failed", {
|
|
392
|
+
reason: errorMessage(err),
|
|
393
|
+
fields: { dispatchId: id },
|
|
394
|
+
});
|
|
287
395
|
}
|
|
288
396
|
return;
|
|
289
397
|
}
|
|
@@ -22,33 +22,34 @@ export function parseProjectCommand(args) {
|
|
|
22
22
|
throw new Error("用法:/project reset");
|
|
23
23
|
return { action: "reset" };
|
|
24
24
|
}
|
|
25
|
-
throw new Error(
|
|
25
|
+
throw new Error(`未知子命令 \`${parts[0]}\`。`);
|
|
26
26
|
}
|
|
27
27
|
function formatShow(options) {
|
|
28
28
|
const securityLoad = loadSecurityConfigWithDiagnostics(options.appHomeDir);
|
|
29
29
|
const resolution = resolveProjectAccessPolicy(securityLoad.config, process.cwd());
|
|
30
30
|
const sandbox = currentProjectSandboxStatus();
|
|
31
31
|
const selection = readProjectSelection(options.channelDir);
|
|
32
|
-
const lines = ["
|
|
32
|
+
const lines = ["**项目目录**"];
|
|
33
33
|
if (!selection) {
|
|
34
|
-
lines.push(`-
|
|
34
|
+
lines.push(`- 当前:\`${resolution.policy.defaultRoot}\`(尚未选择过,下一条消息起采用默认目录)`);
|
|
35
35
|
}
|
|
36
36
|
else {
|
|
37
|
-
|
|
37
|
+
const by = selection.updatedBy === "tui-command" ? "终端" : "钉钉";
|
|
38
|
+
lines.push(`- 当前:\`${selection.projectRoot}\`(${by}中设置,更新于 ${selection.updatedAt})`);
|
|
38
39
|
}
|
|
39
|
-
lines.push(`-
|
|
40
|
-
lines.push(`-
|
|
40
|
+
lines.push(`- 访问范围:${resolution.configured ? "仅限项目目录(project)" : "不限制(unbounded,沿用全局文件权限)"}`);
|
|
41
|
+
lines.push(`- 隔离级别:${sandbox.level}(${sandbox.summary})`);
|
|
41
42
|
if (!resolution.configured) {
|
|
42
|
-
lines.push(
|
|
43
|
+
lines.push("- `/project set` 不可用:请部署者在 `security.json` 中配置 `projectAccess` 后再用。");
|
|
43
44
|
}
|
|
44
45
|
else if (!resolution.mutable) {
|
|
45
|
-
lines.push("- projectAccess.defaultRoot
|
|
46
|
+
lines.push("- `projectAccess.defaultRoot` 配置有误,项目切换已被禁用;请部署者查看启动日志。");
|
|
46
47
|
}
|
|
47
48
|
else {
|
|
48
|
-
lines.push(`-
|
|
49
|
+
lines.push(`- 允许的根目录:${resolution.policy.allowedRoots.map((root) => `\`${root}\``).join("、")}`);
|
|
49
50
|
}
|
|
50
51
|
for (const diagnostic of resolution.diagnostics) {
|
|
51
|
-
lines.push(`-
|
|
52
|
+
lines.push(`- ⚠️ ${diagnostic.message}`);
|
|
52
53
|
}
|
|
53
54
|
return lines.join("\n");
|
|
54
55
|
}
|
|
@@ -56,22 +57,22 @@ async function applyScopeChange(options, requestedPath, label) {
|
|
|
56
57
|
const securityLoad = loadSecurityConfigWithDiagnostics(options.appHomeDir);
|
|
57
58
|
const resolution = resolveProjectAccessPolicy(securityLoad.config, process.cwd());
|
|
58
59
|
if (!resolution.configured) {
|
|
59
|
-
return
|
|
60
|
+
return "无法切换项目:未配置 `projectAccess`。请部署者在 `security.json` 中写入 `projectAccess`(`defaultRoot`、`allowedRoots`)后重试。";
|
|
60
61
|
}
|
|
61
62
|
if (!resolution.mutable) {
|
|
62
|
-
return
|
|
63
|
+
return "无法切换项目:`projectAccess.defaultRoot` 配置有误,修复前项目切换已被禁用;请部署者查看启动日志。";
|
|
63
64
|
}
|
|
64
65
|
const real = resolveExistingDirectory(requestedPath);
|
|
65
66
|
if (!real) {
|
|
66
67
|
return `无法切换项目:\`${requestedPath}\` 不是一个存在的绝对目录。`;
|
|
67
68
|
}
|
|
68
69
|
if (!isWithinAllowedRoots(real, resolution.policy)) {
|
|
69
|
-
return `无法切换项目:\`${real}\`
|
|
70
|
+
return `无法切换项目:\`${real}\` 不在允许的根目录内。允许的根目录:${resolution.policy.allowedRoots
|
|
70
71
|
.map((root) => `\`${root}\``)
|
|
71
72
|
.join("、")}。`;
|
|
72
73
|
}
|
|
73
74
|
if (options.isBusy()) {
|
|
74
|
-
return "
|
|
75
|
+
return "无法切换项目:当前频道有回合正在进行。等它结束后重试,或先用 `/stop` 停止。";
|
|
75
76
|
}
|
|
76
77
|
const blockers = await options.listActiveBlockers();
|
|
77
78
|
if (blockers.length > 0) {
|
|
@@ -79,7 +80,7 @@ async function applyScopeChange(options, requestedPath, label) {
|
|
|
79
80
|
}
|
|
80
81
|
await commitProjectSelection(options.channelDir, real, options.actor);
|
|
81
82
|
await options.onScopeChanged?.();
|
|
82
|
-
return `${label}:\`${real}
|
|
83
|
+
return `${label}:\`${real}\`。下一条消息起在新的项目目录下运行。`;
|
|
83
84
|
}
|
|
84
85
|
export async function handleProjectCommand(options) {
|
|
85
86
|
let command;
|
package/dist/runtime/proxy.js
CHANGED
|
@@ -41,11 +41,13 @@ export function installLlmProxy() {
|
|
|
41
41
|
parsed = new URL(explicitProxy);
|
|
42
42
|
}
|
|
43
43
|
catch {
|
|
44
|
-
log.
|
|
44
|
+
log.logWarn("runtime.proxy.invalid", "PIPICLAW_PROXY is not a valid URL; LLM requests connect directly", {
|
|
45
|
+
reason: explicitProxy,
|
|
46
|
+
});
|
|
45
47
|
return { installed: false, source: "none" };
|
|
46
48
|
}
|
|
47
49
|
if (!SUPPORTED_PROXY_PROTOCOLS.has(parsed.protocol)) {
|
|
48
|
-
log.
|
|
50
|
+
log.logWarn("runtime.proxy.unsupported", "PIPICLAW_PROXY protocol unsupported (http/https only, no SOCKS); LLM requests connect directly", { reason: explicitProxy, fields: { protocol: parsed.protocol } });
|
|
49
51
|
return { installed: false, source: "none" };
|
|
50
52
|
}
|
|
51
53
|
const noProxy = process.env.PIPICLAW_NO_PROXY?.trim();
|
|
@@ -55,7 +55,7 @@ export async function runReportCommand(context, name, args) {
|
|
|
55
55
|
...context.runManager
|
|
56
56
|
.list()
|
|
57
57
|
.filter((record) => record.status === "running")
|
|
58
|
-
.map((record) =>
|
|
58
|
+
.map((record) => `委派 \`${record.runId}\`(${record.agent})仍在运行`),
|
|
59
59
|
...context.runningJobLines(),
|
|
60
60
|
],
|
|
61
61
|
onScopeChanged: context.onScopeChanged,
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* loaded catalog: that keeps `/skills` usable while a turn is streaming and for a channel with no
|
|
8
8
|
* active runner, and — the whole reason this exists rather than reusing `/help`'s discovery tail
|
|
9
9
|
* — it is the only place that shows a skill that failed the content scan and was silently dropped
|
|
10
|
-
* from
|
|
10
|
+
* from the prompt's skill list (`src/agent/workspace-resources.ts`).
|
|
11
11
|
*/
|
|
12
12
|
export interface HandleSkillsCommandOptions {
|
|
13
13
|
args: string;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { renderSubcommandUsage } from "../commands/catalog.js";
|
|
2
|
-
import { capReply } from "../commands/reply-limits.js";
|
|
2
|
+
import { capReply, flattenMarkdownForChat } from "../commands/reply-limits.js";
|
|
3
|
+
import { GuardBlockedError, renderGuardBlockForUser } from "../security/block-message.js";
|
|
3
4
|
import { loadSecurityConfigWithDiagnostics } from "../security/config.js";
|
|
5
|
+
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
4
6
|
import { errorMessage } from "../shared/text-utils.js";
|
|
5
7
|
import { listWorkspaceSkills, loadWorkspaceSkillFile } from "../tools/skill.js";
|
|
6
8
|
function usage() {
|
|
@@ -17,25 +19,25 @@ export function parseSkillsCommand(args) {
|
|
|
17
19
|
throw new Error("用法:/skills show <name>");
|
|
18
20
|
return { action: "show", name: parts[1] };
|
|
19
21
|
}
|
|
20
|
-
throw new Error(
|
|
22
|
+
throw new Error(`未知子命令 \`${parts[0]}\`。`);
|
|
21
23
|
}
|
|
22
24
|
async function listSkills(workspaceDir) {
|
|
23
25
|
const skills = await listWorkspaceSkills({ workspaceDir });
|
|
24
26
|
if (skills.length === 0) {
|
|
25
|
-
return (
|
|
26
|
-
|
|
27
|
+
return ("暂无工作区 skill。\n" +
|
|
28
|
+
`让我帮你创建,或手动放到 \`${workspaceDir}/skills/<name>/SKILL.md\`(文件头需要非空的 \`name\`,与目录名一致,以及 \`description\`)。`);
|
|
27
29
|
}
|
|
28
30
|
const loaded = skills.filter((skill) => !skill.warning);
|
|
29
31
|
const rejected = skills.filter((skill) => skill.warning);
|
|
30
|
-
const lines = [
|
|
32
|
+
const lines = [`**工作区 skills**(${loaded.length} 个)· 用 \`/skill:<名称>\` 调用`, ""];
|
|
31
33
|
if (loaded.length > 0) {
|
|
32
|
-
lines.push(...loaded.map((skill) => `- \`${skill.name}\` — ${skill.description || "
|
|
34
|
+
lines.push(...loaded.map((skill) => `- \`${skill.name}\` — ${skill.description || "(无 description)"}`));
|
|
33
35
|
}
|
|
34
36
|
else {
|
|
35
37
|
lines.push("(全部未通过加载,见下)");
|
|
36
38
|
}
|
|
37
39
|
if (rejected.length > 0) {
|
|
38
|
-
lines.push("", "
|
|
40
|
+
lines.push("", "⚠️ 未加载(助手看不到,也无法用 `/skill:名称` 调用)", "");
|
|
39
41
|
lines.push(...rejected.map((skill) => `- \`${skill.name}\` — ${skill.warning}`));
|
|
40
42
|
}
|
|
41
43
|
return capReply(lines.join("\n"), { nextStepHint: "用 `/skills show <name>` 查看单个 skill 的完整正文" }).text;
|
|
@@ -48,11 +50,16 @@ async function showSkill(options, name) {
|
|
|
48
50
|
securityConfig,
|
|
49
51
|
channelId: options.channelId,
|
|
50
52
|
}, name);
|
|
51
|
-
const body = `**Skill \`${file.name}\`**\n\n路径:\`${file.path}\`\n\n${file.content}`;
|
|
52
|
-
return capReply(body, { nextStepHint:
|
|
53
|
+
const body = `**Skill \`${file.name}\`**\n\n路径:\`${file.path}\`\n\n${flattenMarkdownForChat(file.content)}`;
|
|
54
|
+
return capReply(body, { nextStepHint: `完整内容在 \`${file.path}\`` }).text;
|
|
53
55
|
}
|
|
54
56
|
catch (error) {
|
|
55
|
-
|
|
57
|
+
// The loader's errors are written for the model (`Use action "list"…`); say it in the user's terms.
|
|
58
|
+
if (error instanceof RecoverableToolError)
|
|
59
|
+
return `未找到 skill \`${name}\`。用 \`/skills\` 查看可用的 skill。`;
|
|
60
|
+
if (error instanceof GuardBlockedError)
|
|
61
|
+
return renderGuardBlockForUser(error.blocked);
|
|
62
|
+
return `无法读取 skill \`${name}\`:${errorMessage(error)}`;
|
|
56
63
|
}
|
|
57
64
|
}
|
|
58
65
|
export async function handleSkillsCommand(options) {
|
|
@@ -37,10 +37,11 @@ type SubagentsCommand = {
|
|
|
37
37
|
export declare function parseSubagentsCommand(args: string): SubagentsCommand;
|
|
38
38
|
export declare function handleSubagentsCommand(options: HandleSubagentsCommandOptions): Promise<string>;
|
|
39
39
|
/**
|
|
40
|
-
* Render a `RunNotice` (P0-1/P1a) as a
|
|
41
|
-
*
|
|
42
|
-
* caller filters `kind: "progress"` out
|
|
43
|
-
*
|
|
40
|
+
* Render a `RunNotice` (P0-1/P1a) as a runtime push (spec 053, D6): one marker, the run id the
|
|
41
|
+
* user can act on, and — for a failure — the command that shows why. `notices: "off"` is enforced
|
|
42
|
+
* by the caller not invoking this at all; a `"settled"` caller filters `kind: "progress"` out
|
|
43
|
+
* before calling (a `"stalled"` warning needs attention, so it passes both levels). Returns `undefined` for a notice with nothing worth showing (a progress step
|
|
44
|
+
* that never resolved to a label).
|
|
44
45
|
*/
|
|
45
46
|
export declare function renderRunNotice(notice: RunNotice): string | undefined;
|
|
46
47
|
export {};
|