@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.
Files changed (113) hide show
  1. package/dist/agent/channel-runner.js +137 -61
  2. package/dist/agent/command-extension.js +47 -34
  3. package/dist/agent/job-manager.js +31 -11
  4. package/dist/agent/model-fallback.js +1 -1
  5. package/dist/agent/prompt/manifest.d.ts +6 -1
  6. package/dist/agent/prompt/manifest.js +45 -64
  7. package/dist/agent/prompt/resources.js +4 -1
  8. package/dist/agent/run-queue.js +7 -2
  9. package/dist/agent/session-adapter.js +1 -1
  10. package/dist/agent/session-events.js +17 -6
  11. package/dist/agent/session-resource-gate.js +3 -1
  12. package/dist/agent/status-render.d.ts +0 -1
  13. package/dist/agent/status-render.js +4 -16
  14. package/dist/agent/turn-error.d.ts +31 -0
  15. package/dist/agent/turn-error.js +68 -0
  16. package/dist/app-services.js +7 -4
  17. package/dist/channel/channel-index.js +4 -1
  18. package/dist/channel/project-scope-store.js +1 -1
  19. package/dist/commands/catalog.d.ts +21 -4
  20. package/dist/commands/catalog.js +88 -41
  21. package/dist/commands/reply-limits.d.ts +6 -0
  22. package/dist/commands/reply-limits.js +24 -0
  23. package/dist/events/event-commands.js +94 -44
  24. package/dist/events/event-validation.d.ts +13 -2
  25. package/dist/events/event-validation.js +17 -9
  26. package/dist/events/events.js +77 -32
  27. package/dist/executor.js +2 -2
  28. package/dist/log.d.ts +12 -2
  29. package/dist/log.js +26 -34
  30. package/dist/main.js +1 -1
  31. package/dist/memory/commands.js +29 -23
  32. package/dist/memory/lifecycle.js +26 -5
  33. package/dist/memory/maintenance-state.js +4 -1
  34. package/dist/memory/scheduler.js +3 -1
  35. package/dist/models/auth-cli.js +3 -2
  36. package/dist/paths.d.ts +2 -0
  37. package/dist/paths.js +9 -0
  38. package/dist/playbooks/agent-delegation.md +2 -2
  39. package/dist/runtime/app-home.d.ts +6 -0
  40. package/dist/runtime/app-home.js +21 -3
  41. package/dist/runtime/bootstrap.js +189 -60
  42. package/dist/runtime/channel-queue.js +1 -1
  43. package/dist/runtime/delivery.js +29 -15
  44. package/dist/runtime/dingtalk.js +96 -42
  45. package/dist/runtime/durable-dispatch.d.ts +27 -1
  46. package/dist/runtime/durable-dispatch.js +111 -3
  47. package/dist/runtime/project-commands.js +16 -15
  48. package/dist/runtime/proxy.js +4 -2
  49. package/dist/runtime/report-commands.js +1 -1
  50. package/dist/runtime/skill-commands.d.ts +1 -1
  51. package/dist/runtime/skill-commands.js +17 -10
  52. package/dist/runtime/subagent-commands.d.ts +5 -4
  53. package/dist/runtime/subagent-commands.js +116 -77
  54. package/dist/runtime/task-commands.d.ts +1 -1
  55. package/dist/runtime/task-commands.js +110 -64
  56. package/dist/runtime/task-driver.d.ts +4 -2
  57. package/dist/runtime/task-driver.js +55 -20
  58. package/dist/runtime/task-migration.js +23 -6
  59. package/dist/runtime/task-spawn.js +12 -5
  60. package/dist/runtime/wake-coalescing.d.ts +18 -0
  61. package/dist/runtime/wake-coalescing.js +29 -0
  62. package/dist/security/block-message.d.ts +22 -1
  63. package/dist/security/block-message.js +66 -1
  64. package/dist/security/network.d.ts +2 -1
  65. package/dist/security/network.js +3 -2
  66. package/dist/security/path-guard-check.js +2 -2
  67. package/dist/settings.d.ts +3 -2
  68. package/dist/settings.js +4 -1
  69. package/dist/shared/format.d.ts +12 -0
  70. package/dist/shared/format.js +37 -0
  71. package/dist/shared/host-process.js +15 -3
  72. package/dist/shared/with-timeout.d.ts +3 -2
  73. package/dist/shared/with-timeout.js +14 -3
  74. package/dist/subagents/external/claude-code.js +23 -1
  75. package/dist/subagents/external/progress-tail.d.ts +17 -0
  76. package/dist/subagents/external/progress-tail.js +64 -17
  77. package/dist/subagents/external/run.d.ts +3 -0
  78. package/dist/subagents/external/run.js +21 -7
  79. package/dist/subagents/external/settlement.d.ts +3 -0
  80. package/dist/subagents/external/settlement.js +1 -1
  81. package/dist/subagents/runs.d.ts +21 -1
  82. package/dist/subagents/runs.js +137 -32
  83. package/dist/subagents/tool.d.ts +22 -15
  84. package/dist/subagents/tool.js +226 -32
  85. package/dist/subagents/workspace-summary.d.ts +16 -4
  86. package/dist/subagents/workspace-summary.js +74 -18
  87. package/dist/tasks/board.d.ts +8 -1
  88. package/dist/tasks/board.js +37 -2
  89. package/dist/tasks/frontmatter.d.ts +5 -0
  90. package/dist/tasks/frontmatter.js +8 -0
  91. package/dist/tasks/log.d.ts +11 -1
  92. package/dist/tasks/log.js +58 -2
  93. package/dist/tasks/store.js +4 -2
  94. package/dist/tasks/ticket.d.ts +3 -1
  95. package/dist/tasks/ticket.js +19 -1
  96. package/dist/tools/bash.js +2 -2
  97. package/dist/tools/index.d.ts +2 -0
  98. package/dist/tools/index.js +1 -0
  99. package/dist/tools/memory-manage.js +4 -1
  100. package/dist/tools/subagent-manage.d.ts +1 -1
  101. package/dist/tools/subagent-manage.js +16 -11
  102. package/dist/tools/task-manage/step-end.js +4 -1
  103. package/dist/tools/tool-details.d.ts +10 -2
  104. package/dist/tools/tool-details.js +39 -2
  105. package/dist/tui/cli.js +2 -2
  106. package/dist/tui/commands.js +4 -4
  107. package/dist/tui/pitui-frontend.js +1 -1
  108. package/dist/tui/renderer.js +3 -2
  109. package/dist/tui/turn-controller.d.ts +2 -0
  110. package/dist/tui/turn-controller.js +36 -21
  111. package/dist/usage/ledger.js +3 -1
  112. package/dist/usage/render.js +3 -1
  113. package/package.json +1 -1
@@ -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(`未知的 /project 子命令:${parts[0]}`);
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(`- 项目目录:\`${resolution.policy.defaultRoot}\`(尚未选择过,将在下次准入时采用 app 默认值)`);
34
+ lines.push(`- 当前:\`${resolution.policy.defaultRoot}\`(尚未选择过,下一条消息起采用默认目录)`);
35
35
  }
36
36
  else {
37
- lines.push(`- 项目目录:\`${selection.projectRoot}\`(${selection.updatedBy},更新于 ${selection.updatedAt})`);
37
+ const by = selection.updatedBy === "tui-command" ? "终端" : "钉钉";
38
+ lines.push(`- 当前:\`${selection.projectRoot}\`(${by}中设置,更新于 ${selection.updatedAt})`);
38
39
  }
39
- lines.push(`- 边界:${resolution.configured ? "project(文件工具被约束在此目录内)" : "unbounded(沿用旧的全局文件权限)"}`);
40
- lines.push(`- Enforcement:${sandbox.level}(${sandbox.summary})`);
40
+ lines.push(`- 访问范围:${resolution.configured ? "仅限项目目录(project)" : "不限制(unbounded,沿用全局文件权限)"}`);
41
+ lines.push(`- 隔离级别:${sandbox.level}(${sandbox.summary})`);
41
42
  if (!resolution.configured) {
42
- lines.push(`- 未配置 projectAccess:\`/project set\` 不可用。在 \`security.json\` 写入 projectAccess 段后即可使用。`);
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(`- 可选根:${resolution.policy.allowedRoots.map((root) => `\`${root}\``).join("、")}`);
49
+ lines.push(`- 允许的根目录:${resolution.policy.allowedRoots.map((root) => `\`${root}\``).join("、")}`);
49
50
  }
50
51
  for (const diagnostic of resolution.diagnostics) {
51
- lines.push(`- ⚠ ${diagnostic.message}`);
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 `无法切换项目:未配置 projectAccess。在 \`security.json\` 写入 projectAccess 段(defaultRoot/allowedRoots)后重试。`;
60
+ return "无法切换项目:未配置 `projectAccess`。请部署者在 `security.json` 中写入 `projectAccess`(`defaultRoot`、`allowedRoots`)后重试。";
60
61
  }
61
62
  if (!resolution.mutable) {
62
- return `无法切换项目:projectAccess.defaultRoot 配置有误(见启动诊断),项目切换已被禁用直到修复。`;
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}\` 不在允许的可选根内。可选根:${resolution.policy.allowedRoots
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;
@@ -41,11 +41,13 @@ export function installLlmProxy() {
41
41
  parsed = new URL(explicitProxy);
42
42
  }
43
43
  catch {
44
- log.logWarning("PIPICLAW_PROXY is not a valid URL; LLM requests will connect directly", explicitProxy);
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.logWarning(`PIPICLAW_PROXY uses unsupported protocol "${parsed.protocol}" (only http:// and https:// proxy URLs are supported, no SOCKS); LLM requests will connect directly`, explicitProxy);
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) => `subagent run \`${record.runId}\` (${record.agent})`),
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 `<available_skills>` (`src/agent/workspace-resources.ts`).
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(`未知的 /skills 子命令:${parts[0]}`);
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 (`**Workspace skills**\n\n暂无工作区 skill(\`${workspaceDir}/skills/\` 下没有)。\n\n` +
26
- "用 write/edit 在 `workspace/skills/<name>/SKILL.md` 直接创建,frontmatter 需要非空的 `name`(与目录名一致)和 `description`。");
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 = [`**Workspace skills**(${loaded.length} 个)· 用 \`/skill:<名称>\` 调用`, ""];
32
+ const lines = [`**工作区 skills**(${loaded.length} 个)· 用 \`/skill:<名称>\` 调用`, ""];
31
33
  if (loaded.length > 0) {
32
- lines.push(...loaded.map((skill) => `- \`${skill.name}\` — ${skill.description || "(无 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("", "⚠ 未加载(不在 `<available_skills>` 中,也无法通过 `/skill:名称` 调用)", "");
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: `用 read 工具打开 ${file.path} 继续查看` }).text;
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
- return `无法查看 skill:${errorMessage(error)}`;
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 one-line reply — a confirmation, per the command reply
41
- * conventions. `notices: "off"` is enforced by the caller not invoking this at all; a `"settled"`
42
- * caller filters `kind: "progress"` out before calling. Returns `undefined` for a notice with
43
- * nothing worth showing (a progress step that never resolved to a label).
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 {};
@@ -1,9 +1,11 @@
1
1
  import { readFile } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
3
  import { renderSubcommandUsage } from "../commands/catalog.js";
4
- import { formatDuration } from "../shared/format.js";
5
- import { errorMessage } from "../shared/text-utils.js";
6
- import { formatCost, formatRunDuration, harnessLabel } from "../subagents/format.js";
4
+ import { capReply } from "../commands/reply-limits.js";
5
+ import { formatElapsedZh } from "../shared/format.js";
6
+ import { errorMessage, truncate } from "../shared/text-utils.js";
7
+ import { readLastOutputAt, STALL_THRESHOLD_MS } from "../subagents/external/progress-tail.js";
8
+ import { elapsedMs, formatCost, harnessLabel } from "../subagents/format.js";
7
9
  function usage() {
8
10
  return `${renderSubcommandUsage("subagents")}\n\n\`runId\` 支持不带 \`run_\` 前缀的简写,只要能唯一匹配即可,例如 \`show a1b2c3\`。`;
9
11
  }
@@ -43,7 +45,7 @@ export function parseSubagentsCommand(args) {
43
45
  throw new Error("用法:/subagents roles [name]");
44
46
  return { action: "roles", name: parts[1] };
45
47
  }
46
- throw new Error(`未知的 /subagents 子命令:${action}`);
48
+ throw new Error(`未知子命令 \`${action}\`。`);
47
49
  }
48
50
  function statusLabel(status) {
49
51
  switch (status) {
@@ -56,21 +58,26 @@ function statusLabel(status) {
56
58
  case "cancelled":
57
59
  return "已取消";
58
60
  case "lost":
59
- return "丢失(daemon 重启或无法确认)";
61
+ return "已丢失(服务重启后无法确认状态)";
60
62
  }
61
63
  }
64
+ /** User-facing run duration; a restart-reconciled run's figure is an estimate (spec 042 D1). */
65
+ function runDuration(record) {
66
+ const text = formatElapsedZh(elapsedMs(record));
67
+ return record.durationEstimated ? `约 ${text}` : text;
68
+ }
62
69
  function formatRunLine(record) {
63
- const bits = [harnessLabel(record), formatRunDuration(record)];
70
+ const bits = [harnessLabel(record), runDuration(record)];
64
71
  if (record.taskId)
65
- bits.push(`task ${record.taskId}`);
72
+ bits.push(`任务 ${record.taskId}`);
66
73
  if (record.leaseKey)
67
74
  bits.push("持有写锁");
68
75
  const cost = formatCost(record);
69
76
  if (cost)
70
77
  bits.push(cost);
71
- const header = `- \`${record.runId}\` ${record.agent} (${bits.join(", ")}) — ${statusLabel(record.status)} — "${record.label}"`;
78
+ const header = `- \`${record.runId}\` ${record.agent}(${bits.join(",")})· ${statusLabel(record.status)} · “${truncate(record.label, 60)}”`;
72
79
  if (record.status === "failed" && record.failureReason) {
73
- return `${header}(失败原因:${record.failureReason})`;
80
+ return `${header}(失败原因:${truncate(record.failureReason.replace(/\s+/g, " "), 120)})`;
74
81
  }
75
82
  return header;
76
83
  }
@@ -92,9 +99,9 @@ function formatRolesTail(discovery) {
92
99
  const parts = [`角色目录:${available} 个可用`];
93
100
  if (unavailable.length > 0)
94
101
  parts.push(`${unavailable.length} 个不可用`);
95
- let line = `${parts.join(",")} — 用 /subagents roles 查看`;
96
- for (const warning of discovery.warnings) {
97
- line += `\n⚠ discovery: ${warning}`;
102
+ let line = `${parts.join(",")},用 \`/subagents roles\` 查看`;
103
+ if (discovery.warnings.length > 0) {
104
+ line += `\n⚠️ 角色目录有 ${discovery.warnings.length} 个问题,用 \`/subagents roles\` 查看`;
98
105
  }
99
106
  return line;
100
107
  }
@@ -108,13 +115,19 @@ function capListForDisplay(records) {
108
115
  return { shown: records };
109
116
  return {
110
117
  shown: records.slice(0, LIST_FILTER_CAP),
111
- truncatedNote: `显示最近 ${LIST_FILTER_CAP} 条,共 ${records.length} 条——用更具体的筛选缩小范围。`,
118
+ truncatedNote: `显示最近 ${LIST_FILTER_CAP} 条,共 ${records.length} 条;用更具体的筛选缩小范围。`,
112
119
  };
113
120
  }
114
121
  async function listRuns(options, filter) {
122
+ const report = await renderRunList(options, filter);
123
+ return capReply(report, {
124
+ nextStepHint: "用 `/subagents list running` 或 `/subagents list failed` 缩小范围,`/subagents show <runId>` 查看单个委派",
125
+ }).text;
126
+ }
127
+ async function renderRunList(options, filter) {
115
128
  const records = options.runManager.list();
116
129
  if (records.length === 0)
117
- return "**委派 Run**\n\n没有委派记录。";
130
+ return "暂无委派记录。\n让我把一件事交给某个角色去做之后,会出现在这里。";
118
131
  const running = records.filter((record) => record.status === "running").sort((a, b) => b.startedAt - a.startedAt);
119
132
  const terminal = records
120
133
  .filter((record) => record.status !== "running")
@@ -122,24 +135,24 @@ async function listRuns(options, filter) {
122
135
  const sections = [];
123
136
  if (filter === "running") {
124
137
  const { shown, truncatedNote } = capListForDisplay(running);
125
- sections.push(shown.length === 0 ? "没有正在运行的 run。" : shown.map(formatRunLine).join("\n"));
138
+ sections.push(shown.length === 0 ? "没有正在运行的委派。" : shown.map(formatRunLine).join("\n"));
126
139
  if (truncatedNote)
127
140
  sections.push(truncatedNote);
128
- return `**委派 Run** · 运行中\n\n${sections.join("\n\n")}`;
141
+ return `**委派** · 运行中\n\n${sections.join("\n\n")}`;
129
142
  }
130
143
  if (filter === "failed") {
131
144
  const { shown, truncatedNote } = capListForDisplay(terminal.filter((record) => record.status === "failed"));
132
- sections.push(shown.length === 0 ? "没有失败的 run。" : shown.map(formatRunLine).join("\n"));
145
+ sections.push(shown.length === 0 ? "没有失败的委派。" : shown.map(formatRunLine).join("\n"));
133
146
  if (truncatedNote)
134
147
  sections.push(truncatedNote);
135
- return `**委派 Run** · 失败\n\n${sections.join("\n\n")}`;
148
+ return `**委派** · 失败\n\n${sections.join("\n\n")}`;
136
149
  }
137
150
  if (filter === "all") {
138
151
  const { shown, truncatedNote } = capListForDisplay([...running, ...terminal]);
139
152
  sections.push(shown.map(formatRunLine).join("\n"));
140
153
  if (truncatedNote)
141
154
  sections.push(truncatedNote);
142
- return `**委派 Run** · 全部(${records.length})\n\n${sections.join("\n\n")}`;
155
+ return `**委派** · 全部(${records.length})\n\n${sections.join("\n\n")}`;
143
156
  }
144
157
  // default: an overview — every running run, plus a capped tail of recent completions.
145
158
  if (running.length > 0) {
@@ -147,25 +160,29 @@ async function listRuns(options, filter) {
147
160
  }
148
161
  const shown = terminal.slice(0, DEFAULT_LIST_COMPLETED_LIMIT);
149
162
  if (shown.length > 0) {
150
- const countNote = terminal.length > shown.length ? `显示 ${shown.length} / 共 ${terminal.length}` : `${shown.length}`;
163
+ const countNote = terminal.length > shown.length ? `显示 ${shown.length} 条,共 ${terminal.length} 条` : `${shown.length}`;
151
164
  sections.push(`**最近完成**(${countNote})\n${shown.map(formatRunLine).join("\n")}`);
152
165
  }
153
- if (sections.length === 0)
154
- sections.push("没有委派记录。");
155
166
  const discovery = await resolveDiscovery(options);
156
167
  if (discovery)
157
168
  sections.push(formatRolesTail(discovery));
158
169
  sections.push("用 `/subagents show <runId>` 看详情,`/subagents output <runId>` 看产出。");
159
- return `**委派 Run**\n\n${sections.join("\n\n")}`;
170
+ return `**委派**\n\n${sections.join("\n\n")}`;
171
+ }
172
+ /** `/subagents show`: the stderr tail it quotes, and how much of the argv. The rest is on disk. */
173
+ const STDERR_TAIL_LINES = 10;
174
+ const ARGV_SHOW_CHARS = 200;
175
+ /** `/subagents output`: the output tail it quotes; the full `output.md` is in the artifact dir. */
176
+ const OUTPUT_TAIL_CHARS = 1_200;
177
+ function runNotFound(ref) {
178
+ return `未找到委派 \`${ref}\`。用 \`/subagents list all\` 查看。`;
160
179
  }
161
- const STDERR_TAIL_CHARS = 2_000;
162
- const OUTPUT_TAIL_CHARS = 4_000;
163
180
  function formatRunResolution(resolution, ref) {
164
181
  if (resolution.kind === "not_found")
165
- return `未找到 run:\`${ref}\``;
182
+ return runNotFound(ref);
166
183
  if (resolution.kind === "ambiguous") {
167
- const candidates = resolution.candidates.map((record) => `\`${record.runId}\` (${record.agent})`).join("、");
168
- return `"${ref}" 匹配到多个 run:${candidates}。请提供更完整的 runId。`;
184
+ const candidates = resolution.candidates.map((record) => `\`${record.runId}\`(${record.agent})`).join("、");
185
+ return `\`${ref}\` 匹配到多个委派:${candidates}。请提供更完整的 runId。`;
169
186
  }
170
187
  return undefined;
171
188
  }
@@ -173,94 +190,108 @@ async function showRun(manager, ref) {
173
190
  const resolution = manager.resolveRef(ref);
174
191
  const error = formatRunResolution(resolution, ref);
175
192
  if (error || resolution.kind !== "found")
176
- return error ?? `未找到 run:\`${ref}\``;
193
+ return error ?? runNotFound(ref);
177
194
  const record = resolution.record;
178
195
  const lines = [
179
- `**Run \`${record.runId}\`**`,
180
- `- 角色:${record.agent} (${harnessLabel(record)}, ${record.source})`,
196
+ `**委派 \`${record.runId}\`**`,
197
+ `- 角色:${record.agent}(${harnessLabel(record)},${record.source})`,
181
198
  `- 标签:${record.label}`,
182
- `- 状态:${statusLabel(record.status)}(耗时 ${formatRunDuration(record)})`,
199
+ `- 状态:${statusLabel(record.status)}(耗时 ${runDuration(record)})`,
183
200
  ];
184
201
  if (record.failureReason)
185
- lines.push(`- 失败原因:${record.failureReason}`);
202
+ lines.push(`- 失败原因:${truncate(record.failureReason.replace(/\s+/g, " "), 300)}`);
186
203
  if (record.verificationVerdict) {
187
- lines.push(`- 检查结论:${record.verificationVerdict === "pass" ? "PASS" : "FAIL"}`);
204
+ lines.push(`- 验收结论:${record.verificationVerdict === "pass" ? "通过" : "未通过"}`);
188
205
  }
189
206
  lines.push(`- 开始:${new Date(record.startedAt).toLocaleString()}`);
190
207
  if (record.finishedAt)
191
208
  lines.push(`- 结束:${new Date(record.finishedAt).toLocaleString()}`);
192
- lines.push(`- purpose:${record.purpose}`, `- 工作目录:\`${record.workingDirectory}\``, `- 产物目录:\`${record.artifactDir}\``);
209
+ lines.push(`- 用途(purpose):${record.purpose}`, `- 工作目录:\`${record.workingDirectory}\``, `- 产物目录:\`${record.artifactDir}\``);
193
210
  if (record.taskId)
194
- lines.push(`- 所属任务:${record.taskId}`);
211
+ lines.push(`- 所属任务:\`${record.taskId}\``);
195
212
  if (record.leaseKey)
196
213
  lines.push("- 持有写锁:是");
197
214
  if (record.model)
198
215
  lines.push(`- 模型:${record.model}`);
199
216
  const cost = formatCost(record);
200
- lines.push(`- usage:input=${record.usage.input} output=${record.usage.output}${cost ? ` cost=${cost}` : record.costKnown ? "" : "(cost 未知)"}`);
201
- if (record.argv)
202
- lines.push("", "实际 argv:", "```", JSON.stringify(record.argv), "```");
217
+ const costText = cost ? `,花费 ${cost}` : record.costKnown ? "" : ",花费未知";
218
+ lines.push(`- 用量:输入 ${record.usage.input} tokens,输出 ${record.usage.output} tokens${costText}`);
219
+ if (record.argv) {
220
+ lines.push(`- 实际命令行:\`${truncate(JSON.stringify(record.argv).replace(/`/g, "'"), ARGV_SHOW_CHARS)}\``);
221
+ }
203
222
  if (record.parserVersion !== undefined || record.cliVersion) {
204
223
  // Spec 042 D12: lets a human tell "the target CLI's own protocol drifted out from under this
205
224
  // adapter" apart from "the agent itself failed" — the two look identical from status alone.
206
225
  const parts = [];
207
226
  if (record.parserVersion !== undefined)
208
- parts.push(`parserVersion=${record.parserVersion}`);
209
- parts.push(`cliVersion=${record.cliVersion ?? "(未知)"}`);
210
- lines.push(`- 适配器/CLI:${parts.join(",")}`);
227
+ parts.push(`适配器版本(parserVersion)${record.parserVersion}`);
228
+ parts.push(`CLI 版本 ${record.cliVersion ?? "未知"}`);
229
+ lines.push(`- ${parts.join(",")}`);
230
+ }
231
+ for (const warning of record.invocationWarnings ?? [])
232
+ lines.push(`- ⚠️ 启动时的警告:${warning}`);
233
+ if (record.sessionId) {
234
+ lines.push(`- 会话(sessionId):\`${record.sessionId}\`,可以让我在这个会话上继续追问`);
235
+ }
236
+ if (record.runtime === "external" && record.status === "running") {
237
+ const lastOutputAt = await readLastOutputAt(record.artifactDir);
238
+ const silentMs = Date.now() - (lastOutputAt ?? record.processStartedAt ?? record.startedAt);
239
+ lines.push(silentMs >= STALL_THRESHOLD_MS
240
+ ? `- ⚠️ 最近输出:${formatElapsedZh(silentMs)}前,可能卡住了;需要时用 \`/subagents cancel ${record.runId}\` 取消`
241
+ : `- 最近输出:${formatElapsedZh(silentMs)}前`);
211
242
  }
212
- if (record.invocationWarnings?.length) {
213
- lines.push("", "⚠ 派发时的警告:", ...record.invocationWarnings.map((warning) => `- ${warning}`));
214
- }
215
- if (record.sessionId)
216
- lines.push(`- sessionId:\`${record.sessionId}\`(可用于 subagent_run op=follow_up)`);
217
243
  if (record.runtime === "external") {
218
244
  const stderrTail = await readFile(join(record.artifactDir, "stderr.log"), "utf-8")
219
- .then((text) => text.slice(-STDERR_TAIL_CHARS))
245
+ .then((text) => text.trimEnd().split("\n").slice(-STDERR_TAIL_LINES).join("\n"))
220
246
  .catch(() => undefined);
221
247
  if (stderrTail?.trim()) {
222
- lines.push("", "**stderr(尾部)**", "```", stderrTail, "```");
248
+ lines.push("", `**stderr(最后 ${STDERR_TAIL_LINES} 行)**`, "```", stderrTail, "```");
223
249
  }
224
250
  }
225
- return lines.join("\n");
251
+ return capReply(lines.join("\n"), {
252
+ nextStepHint: `用 \`/subagents output ${record.runId}\` 查看产出,完整文件在 \`${record.artifactDir}\``,
253
+ }).text;
226
254
  }
227
255
  async function showOutput(manager, ref) {
228
256
  const resolution = manager.resolveRef(ref);
229
257
  const error = formatRunResolution(resolution, ref);
230
258
  if (error || resolution.kind !== "found")
231
- return error ?? `未找到 run:\`${ref}\``;
259
+ return error ?? runNotFound(ref);
232
260
  const record = resolution.record;
233
- const outputText = await readFile(join(record.artifactDir, "output.md"), "utf-8").catch(() => undefined);
261
+ const outputPath = join(record.artifactDir, "output.md");
262
+ const outputText = await readFile(outputPath, "utf-8").catch(() => undefined);
234
263
  if (!outputText?.trim()) {
235
- const runningNote = record.status === "running" ? "该 run 仍在运行,可能还没有产出。" : "该 run 没有文本产出。";
236
- return `**Run \`${record.runId}\` 的产出**\n\n${runningNote}产物目录:\`${record.artifactDir}\``;
264
+ const runningNote = record.status === "running" ? "该委派仍在运行,可能还没有产出。" : "该委派没有文本产出。";
265
+ return `${runningNote}产物目录:\`${record.artifactDir}\``;
237
266
  }
238
267
  const tail = outputText.slice(-OUTPUT_TAIL_CHARS);
239
- const truncatedNote = outputText.length > tail.length ? `(只显示末尾 ${OUTPUT_TAIL_CHARS} 字符,完整内容见上方产物目录)\n\n` : "";
240
- return `**Run \`${record.runId}\` 的产出**\n\n${truncatedNote}\`\`\`\n${tail}\n\`\`\``;
268
+ const truncatedNote = outputText.length > tail.length ? `只显示末尾 ${OUTPUT_TAIL_CHARS} 字,完整内容在 \`${outputPath}\`。\n\n` : "";
269
+ return `**委派 \`${record.runId}\` 的产出**\n\n${truncatedNote}\`\`\`\n${tail}\n\`\`\``;
241
270
  }
242
271
  async function cancelRun(manager, ref) {
243
272
  if (ref === "all") {
244
273
  const running = manager.list().filter((record) => record.status === "running");
245
274
  if (running.length === 0)
246
- return "没有正在运行的 run。";
275
+ return "没有正在运行的委派。";
247
276
  const results = await Promise.all(running.map(async (record) => {
248
277
  const status = await manager.cancel(record.runId);
249
- return `- \`${record.runId}\` (${record.agent}):${status}`;
278
+ return `- \`${record.runId}\`(${record.agent}):${status === "not_found" ? "未找到" : statusLabel(status)}`;
250
279
  }));
251
- return `**已请求终止 ${running.length} 个 run**\n\n${results.join("\n")}`;
280
+ return `**已请求终止 ${running.length} 个委派**\n\n${results.join("\n")}`;
252
281
  }
253
282
  const resolution = manager.resolveRef(ref);
254
283
  const error = formatRunResolution(resolution, ref);
255
284
  if (error || resolution.kind !== "found")
256
- return error ?? `未找到 run:\`${ref}\``;
285
+ return error ?? runNotFound(ref);
257
286
  const status = await manager.cancel(resolution.record.runId);
258
- return `已请求终止 run \`${resolution.record.runId}\`:${status}`;
287
+ if (status === "running")
288
+ return `已请求终止委派 \`${resolution.record.runId}\`。`;
289
+ return `委派 \`${resolution.record.runId}\` 已不在运行(${status === "not_found" ? "未找到" : statusLabel(status)}),无需终止。`;
259
290
  }
260
291
  function formatRoleSummaryLine(agent) {
261
292
  const kind = agent.runtime === "external" ? `外部/${agent.harness}` : "内置";
262
293
  const mutates = agent.mutates ?? (agent.tools.includes("write") || agent.tools.includes("edit") ? "write" : "read");
263
- const unavailable = agent.unavailable ? ` — ⚠ 不可用:${agent.unavailable}` : "";
294
+ const unavailable = agent.unavailable ? ` — ⚠️ 不可用:${agent.unavailable}` : "";
264
295
  const modelLabel = agent.runtime === "external" ? (agent.externalModelRef ?? "CLI 决定") : (agent.modelRef ?? "默认");
265
296
  const thinkingLabel = agent.thinkingLevel ?? (agent.runtime === "external" ? "未设置" : "默认 medium");
266
297
  // Keyless by design: the four positions are fixed — runtime, mutates, model, thinking.
@@ -275,7 +306,7 @@ function formatRoleDetail(agent) {
275
306
  `- 说明:${agent.description}`,
276
307
  ];
277
308
  if (agent.unavailable)
278
- lines.push(`- ⚠ 不可用:${agent.unavailable}`);
309
+ lines.push(`- ⚠️ 不可用:${agent.unavailable}`);
279
310
  lines.push(`- mutates:${agent.mutates ?? "(未声明,由 tools 推断)"}`);
280
311
  if (agent.runtime === "internal") {
281
312
  lines.push(`- model:${agent.modelRef ?? "默认"}`, `- thinking:${agent.thinkingLevel ?? "默认 medium"}`, `- tools:${agent.tools.join(", ") || "(none)"}`, `- 预算:maxTurns=${agent.maxTurns} maxToolCalls=${agent.maxToolCalls} maxWallTimeSec=${agent.maxWallTimeSec} bashTimeoutSec=${agent.bashTimeoutSec}`, `- contextMode:${agent.contextMode},memory:${agent.memory}`);
@@ -283,12 +314,12 @@ function formatRoleDetail(agent) {
283
314
  else {
284
315
  lines.push(`- command:\`${agent.command ?? ""}\`${agent.shell ? "(通过 shell 执行)" : ""}`, `- maxWallTimeSec:${agent.maxWallTimeSec}`);
285
316
  lines.push(`- model:${agent.externalModelRef ?? "CLI 决定"}`);
286
- lines.push(`- thinking:${agent.thinkingLevel ?? "未设置(verify 派发默认 medium)"}`);
317
+ lines.push(`- thinking:${agent.thinkingLevel ?? "未设置(验收委派默认 medium)"}`);
287
318
  // spec 042 D4: contextMode/memory are effective for external roles too (memory 默认 none,
288
319
  // 显式声明 session/relevant 才会把频道会话状态发给外部进程) — 显示出来而不是只在内置分支里说明。
289
320
  lines.push(`- contextMode:${agent.contextMode},memory:${agent.memory}`);
290
321
  if (agent.memory !== "none") {
291
- lines.push(`- ⚠ 该角色会把频道会话状态/记忆片段发送给外部进程(memory: ${agent.memory})`);
322
+ lines.push(`- ⚠️ 该角色会把频道会话状态或记忆片段发送给外部进程(memory:${agent.memory})`);
292
323
  }
293
324
  }
294
325
  if (agent.paths.length > 0)
@@ -299,7 +330,7 @@ function formatRoleDetail(agent) {
299
330
  lines.push("", "system prompt:", renderCappedPromptBlock(agent));
300
331
  return lines.join("\n");
301
332
  }
302
- const SYSTEM_PROMPT_SHOW_MAX_CHARS = 4_000;
333
+ const SYSTEM_PROMPT_SHOW_MAX_CHARS = 800;
303
334
  function renderCappedPromptBlock(agent) {
304
335
  const prompt = agent.systemPrompt;
305
336
  if (prompt.length <= SYSTEM_PROMPT_SHOW_MAX_CHARS) {
@@ -319,7 +350,7 @@ async function showRoles(options, name) {
319
350
  const agent = discovery.agents.find((candidate) => candidate.name === name);
320
351
  if (!agent) {
321
352
  const available = discovery.agents.length > 0 ? discovery.agents.map((a) => a.name).join(", ") : "(none)";
322
- return `未找到角色 "${name}"。可用角色:${available}`;
353
+ return `未找到角色 \`${name}\`。可用角色:${available}`;
323
354
  }
324
355
  return formatRoleDetail(agent);
325
356
  }
@@ -333,7 +364,7 @@ async function showRoles(options, name) {
333
364
  if (discovery.agents.length === 0)
334
365
  sections.push("目录为空。");
335
366
  for (const warning of discovery.warnings)
336
- sections.push(`⚠ discovery: ${warning}`);
367
+ sections.push(`⚠️ 角色文件问题:${warning}`);
337
368
  sections.push("用 `/subagents roles <name>` 看单个角色的详情。");
338
369
  return sections.join("\n\n");
339
370
  }
@@ -364,22 +395,30 @@ export async function handleSubagentsCommand(options) {
364
395
  }
365
396
  }
366
397
  /**
367
- * Render a `RunNotice` (P0-1/P1a) as a one-line reply — a confirmation, per the command reply
368
- * conventions. `notices: "off"` is enforced by the caller not invoking this at all; a `"settled"`
369
- * caller filters `kind: "progress"` out before calling. Returns `undefined` for a notice with
370
- * nothing worth showing (a progress step that never resolved to a label).
398
+ * Render a `RunNotice` (P0-1/P1a) as a runtime push (spec 053, D6): one marker, the run id the
399
+ * user can act on, and — for a failure — the command that shows why. `notices: "off"` is enforced
400
+ * by the caller not invoking this at all; a `"settled"` caller filters `kind: "progress"` out
401
+ * before calling (a `"stalled"` warning needs attention, so it passes both levels). Returns `undefined` for a notice with nothing worth showing (a progress step
402
+ * that never resolved to a label).
371
403
  */
372
404
  export function renderRunNotice(notice) {
405
+ const subject = `委派 \`${notice.runId}\`(${notice.agent})`;
373
406
  if (notice.kind === "progress") {
374
- return notice.step ? `⏳ ${notice.agent} · ${notice.step}` : undefined;
407
+ return notice.step ? `⏳ ${subject} · ${notice.step}` : undefined;
375
408
  }
376
- const durationText = formatDuration(notice.durationMs);
409
+ if (notice.kind === "stalled") {
410
+ return (`⚠️ ${subject}已经 ${formatElapsedZh(notice.silentMs ?? 0)}没有新输出,可能卡住了\n` +
411
+ `用 \`/subagents show ${notice.runId}\` 查看,确认卡住后用 \`/subagents cancel ${notice.runId}\` 取消。`);
412
+ }
413
+ const durationText = formatElapsedZh(notice.durationMs);
377
414
  switch (notice.status) {
378
415
  case "completed":
379
- return `✅ ${notice.agent} 完成 · ${durationText}`;
416
+ return `✅ ${subject}完成 · ${durationText}`;
380
417
  case "cancelled":
381
- return `🛑 ${notice.agent} 已取消 · ${durationText}`;
418
+ return `🛑 ${subject}已取消 · ${durationText}`;
419
+ case "lost":
420
+ return `⚠️ ${subject}状态无法确认 · ${durationText}\n用 \`/subagents show ${notice.runId}\` 查看详情。`;
382
421
  default:
383
- return `⚠️ ${notice.agent} 失败 · ${durationText}`;
422
+ return `⚠️ ${subject}失败 · ${durationText}\n用 \`/subagents show ${notice.runId}\` 查看原因。`;
384
423
  }
385
424
  }
@@ -1,4 +1,4 @@
1
- import type { TaskBudget } from "../tasks/frontmatter.js";
1
+ import { type TaskBudget } from "../tasks/frontmatter.js";
2
2
  export interface HandleTasksCommandOptions {
3
3
  args: string;
4
4
  /** The channel directory; tasks live in `<channelDir>/tasks/`. */