@oyasmi/pipiclaw 0.9.1-beta.1 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/dist/agent/channel-runner.d.ts +7 -1
  2. package/dist/agent/channel-runner.js +42 -15
  3. package/dist/agent/command-extension.js +24 -27
  4. package/dist/agent/commands.d.ts +51 -7
  5. package/dist/agent/commands.js +199 -59
  6. package/dist/agent/prompt/manifest.js +5 -6
  7. package/dist/agent/prompt/sections.js +1 -0
  8. package/dist/agent/reply-limits.d.ts +16 -0
  9. package/dist/agent/reply-limits.js +17 -0
  10. package/dist/agent/runner-factory.d.ts +0 -2
  11. package/dist/agent/session-events.js +2 -2
  12. package/dist/agent/status-render.js +12 -12
  13. package/dist/executor.d.ts +14 -0
  14. package/dist/executor.js +36 -6
  15. package/dist/main.js +3 -4
  16. package/dist/memory/commands.js +79 -38
  17. package/dist/memory/consolidation.d.ts +5 -1
  18. package/dist/memory/consolidation.js +33 -12
  19. package/dist/memory/extraction.d.ts +8 -1
  20. package/dist/memory/extraction.js +47 -4
  21. package/dist/memory/files.d.ts +0 -1
  22. package/dist/memory/files.js +24 -5
  23. package/dist/memory/lifecycle.js +9 -2
  24. package/dist/memory/maintenance-jobs.js +14 -4
  25. package/dist/memory/metadata.d.ts +3 -0
  26. package/dist/memory/metadata.js +7 -0
  27. package/dist/memory/recall.d.ts +9 -0
  28. package/dist/memory/recall.js +101 -17
  29. package/dist/memory/review-log.d.ts +0 -2
  30. package/dist/memory/review-log.js +0 -0
  31. package/dist/memory/session-corpus.js +5 -0
  32. package/dist/memory/session-search.js +9 -0
  33. package/dist/memory/sidecar-worker.js +4 -0
  34. package/dist/memory/source-window.d.ts +0 -1
  35. package/dist/memory/source-window.js +0 -5
  36. package/dist/memory/task-digest.js +0 -2
  37. package/dist/playbooks/agent-delegation.md +32 -24
  38. package/dist/playbooks/background-jobs.md +8 -16
  39. package/dist/playbooks/event-scheduling.md +13 -15
  40. package/dist/playbooks/memory-and-learning.md +29 -22
  41. package/dist/playbooks/outbound-media.md +15 -8
  42. package/dist/playbooks/runtime-orientation.md +40 -37
  43. package/dist/playbooks/task-driving.md +34 -38
  44. package/dist/playbooks/task-planning.md +18 -20
  45. package/dist/runtime/app-home.d.ts +6 -0
  46. package/dist/runtime/app-home.js +15 -6
  47. package/dist/runtime/bootstrap.d.ts +1 -1
  48. package/dist/runtime/bootstrap.js +57 -62
  49. package/dist/runtime/channel-context.d.ts +2 -1
  50. package/dist/runtime/channel-event.d.ts +0 -6
  51. package/dist/runtime/delivery.js +3 -3
  52. package/dist/runtime/dingtalk.d.ts +9 -1
  53. package/dist/runtime/dingtalk.js +27 -13
  54. package/dist/runtime/event-commands.d.ts +15 -0
  55. package/dist/runtime/event-commands.js +48 -40
  56. package/dist/runtime/project-commands.d.ts +16 -0
  57. package/dist/runtime/project-commands.js +13 -17
  58. package/dist/runtime/subagent-commands.d.ts +20 -0
  59. package/dist/runtime/subagent-commands.js +61 -58
  60. package/dist/runtime/task-commands.d.ts +38 -1
  61. package/dist/runtime/task-commands.js +135 -234
  62. package/dist/runtime/task-driver.d.ts +1 -3
  63. package/dist/runtime/task-driver.js +34 -40
  64. package/dist/runtime/task-migration.d.ts +7 -6
  65. package/dist/runtime/task-migration.js +85 -19
  66. package/dist/runtime/task-wake.d.ts +3 -5
  67. package/dist/runtime/task-wake.js +7 -15
  68. package/dist/security/path-guard.js +33 -2
  69. package/dist/security/types.d.ts +9 -0
  70. package/dist/subagents/discovery.d.ts +7 -2
  71. package/dist/subagents/discovery.js +31 -7
  72. package/dist/subagents/external/claude-code.js +42 -2
  73. package/dist/subagents/external/run.js +72 -2
  74. package/dist/subagents/runs.js +28 -3
  75. package/dist/subagents/tool.d.ts +11 -0
  76. package/dist/subagents/tool.js +89 -55
  77. package/dist/subagents/verification-outcome.js +17 -10
  78. package/dist/tasks/control.d.ts +18 -67
  79. package/dist/tasks/control.js +44 -176
  80. package/dist/tasks/ledger.d.ts +7 -13
  81. package/dist/tasks/ledger.js +13 -49
  82. package/dist/tasks/store.d.ts +15 -48
  83. package/dist/tasks/store.js +22 -154
  84. package/dist/tasks/transitions.d.ts +3 -4
  85. package/dist/tasks/transitions.js +8 -27
  86. package/dist/tasks/verification.d.ts +7 -5
  87. package/dist/tools/bash.d.ts +1 -1
  88. package/dist/tools/bash.js +77 -59
  89. package/dist/tools/edit.js +17 -4
  90. package/dist/tools/grep.js +3 -2
  91. package/dist/tools/index.d.ts +0 -2
  92. package/dist/tools/index.js +6 -1
  93. package/dist/tools/job.js +2 -1
  94. package/dist/tools/memory-manage.d.ts +1 -0
  95. package/dist/tools/memory-manage.js +54 -16
  96. package/dist/tools/read.js +21 -5
  97. package/dist/tools/registry.d.ts +0 -1
  98. package/dist/tools/registry.js +0 -1
  99. package/dist/tools/send-media.js +17 -6
  100. package/dist/tools/skill-manage.js +12 -11
  101. package/dist/tools/skill-security.js +1 -1
  102. package/dist/tools/subagent-manage.d.ts +8 -1
  103. package/dist/tools/subagent-manage.js +77 -7
  104. package/dist/tools/task-manage/lifecycle.js +19 -17
  105. package/dist/tools/task-manage/schema.d.ts +2 -6
  106. package/dist/tools/task-manage/schema.js +4 -17
  107. package/dist/tools/task-manage/shared.js +1 -6
  108. package/dist/tools/task-manage/types.d.ts +0 -3
  109. package/dist/tools/task-manage/verification.d.ts +9 -6
  110. package/dist/tools/task-manage/verification.js +19 -71
  111. package/dist/tools/task-manage.d.ts +1 -1
  112. package/dist/tools/task-manage.js +3 -5
  113. package/dist/tools/truncate.d.ts +8 -0
  114. package/dist/tools/truncate.js +8 -0
  115. package/dist/tools/web-fetch.js +9 -1
  116. package/dist/tools/write-content.js +11 -1
  117. package/dist/tui/app.js +1 -1
  118. package/dist/tui/commands.d.ts +1 -1
  119. package/dist/tui/commands.js +1 -1
  120. package/dist/tui/turn-controller.d.ts +1 -1
  121. package/dist/tui/turn-controller.js +14 -4
  122. package/dist/usage/ledger.d.ts +4 -0
  123. package/dist/usage/ledger.js +3 -0
  124. package/dist/usage/render.js +10 -8
  125. package/examples/sub-agents/README.md +2 -0
  126. package/package.json +3 -2
@@ -32,10 +32,4 @@ export interface ChannelEvent {
32
32
  taskId: string;
33
33
  dispatchId: string;
34
34
  };
35
- /**
36
- * The `attemptGeneration` this event's claim recorded, for `[TASK_DRIVER:id]` events only.
37
- * Carried through durable dispatch so `finishTaskAttempt` can tell a stale, superseded claim's
38
- * turn from the current one, even when redelivery or claim races reorder completions.
39
- */
40
- taskAttemptGeneration?: number;
41
35
  }
@@ -60,7 +60,7 @@ class ChannelDeliveryController {
60
60
  // synthetic event (which carries no conversation payload) still names its channel.
61
61
  channelName: this.event.channelName ?? this.event.channelId,
62
62
  respond: async (text, shouldLog = true) => this.appendProgress(text, shouldLog),
63
- respondPlain: async (text, shouldLog = true) => this.sendFinal(text, shouldLog),
63
+ respondPlain: async (text, shouldLog = true, title) => this.sendFinal(text, shouldLog, title),
64
64
  replaceMessage: async (text) => this.replaceWithFinal(text),
65
65
  respondInThread: async (text) => {
66
66
  if (this.closed || !text.trim()) {
@@ -152,11 +152,11 @@ class ChannelDeliveryController {
152
152
  this.mode = "progress";
153
153
  this.bumpRevision(false);
154
154
  }
155
- async sendFinal(text, shouldLog) {
155
+ async sendFinal(text, shouldLog, title) {
156
156
  if (this.closed || this.finalResponseDelivered)
157
157
  return this.finalResponseDelivered;
158
158
  this.clearCardWarmup();
159
- const delivered = await this.bot.sendPlain(this.event.channelId, text);
159
+ const delivered = await this.bot.sendPlain(this.event.channelId, text, title ? { title, markdown: true } : undefined);
160
160
  if (!delivered) {
161
161
  // Do not archive a response we failed to deliver: the conversation log
162
162
  // must not claim we answered when the user never received it.
@@ -153,8 +153,16 @@ export declare class DingTalkBot implements MediaSender {
153
153
  *
154
154
  * Only the message shape is decided here; the DM-vs-group routing and the POST itself belong to
155
155
  * `sendRobotMessage`, which every other outbound message type already goes through.
156
+ *
157
+ * `opts` lets a caller that already knows what it produced (a command reply) state the format
158
+ * and a real title instead of the regex guess below, which exists only for callers — free-form
159
+ * notices, `replaceWithFinal` — that do not know their own content ahead of time (review
160
+ * 2026-08-24 §1.3c).
156
161
  */
157
- sendPlain(channelId: string, text: string): Promise<boolean>;
162
+ sendPlain(channelId: string, text: string, opts?: {
163
+ title?: string;
164
+ markdown?: boolean;
165
+ }): Promise<boolean>;
158
166
  /**
159
167
  * Deliver a local file to a channel as a native attachment. Uploads the bytes
160
168
  * to get a `media_id`, then sends a `sampleImageMsg` (inline image) or
@@ -683,16 +683,22 @@ export class DingTalkBot {
683
683
  *
684
684
  * Only the message shape is decided here; the DM-vs-group routing and the POST itself belong to
685
685
  * `sendRobotMessage`, which every other outbound message type already goes through.
686
+ *
687
+ * `opts` lets a caller that already knows what it produced (a command reply) state the format
688
+ * and a real title instead of the regex guess below, which exists only for callers — free-form
689
+ * notices, `replaceWithFinal` — that do not know their own content ahead of time (review
690
+ * 2026-08-24 §1.3c).
686
691
  */
687
- async sendPlain(channelId, text) {
692
+ async sendPlain(channelId, text, opts) {
688
693
  const meta = this.getConversationMeta(channelId);
689
694
  if (!meta) {
690
695
  log.logWarning(`No conversation metadata for ${channelId}, cannot send plain message`);
691
696
  return false;
692
697
  }
693
- const hasMarkdown = /^#{1,6}\s|^\s*[-*]\s|\*\*.*\*\*|```|`[^`]+`|\[.*?\]\(.*?\)/m.test(text);
698
+ const hasMarkdown = opts?.markdown ?? /^#{1,6}\s|^\s*[-*]\s|\*\*.*\*\*|```|`[^`]+`|\[.*?\]\(.*?\)/m.test(text);
699
+ const title = opts?.title ?? "Bot";
694
700
  const msgKey = hasMarkdown ? "sampleMarkdown" : "sampleText";
695
- const msgParam = hasMarkdown ? JSON.stringify({ text, title: "Bot" }) : JSON.stringify({ content: text });
701
+ const msgParam = hasMarkdown ? JSON.stringify({ text, title }) : JSON.stringify({ content: text });
696
702
  return this.sendRobotMessage(meta, msgKey, msgParam);
697
703
  }
698
704
  // ==========================================================================
@@ -1082,13 +1088,16 @@ export class DingTalkBot {
1082
1088
  if (builtInCommand) {
1083
1089
  switch (builtInCommand.name) {
1084
1090
  case "help":
1085
- await this.sendPlain(channelId, renderBuiltInHelp());
1091
+ await this.sendPlain(channelId, renderBuiltInHelp(builtInCommand.args), {
1092
+ title: "/help",
1093
+ markdown: true,
1094
+ });
1086
1095
  return;
1087
1096
  case "stop": {
1088
1097
  const outcome = await this.handler.handleStop(channelId, this);
1089
1098
  await this.sendPlain(channelId, outcome.pausedTaskId
1090
1099
  ? `已停止当前回合。任务 \`${outcome.pausedTaskId}\` 已暂停,用 \`/tasks resume ${outcome.pausedTaskId}\` 继续。`
1091
- : "已停止当前回合。");
1100
+ : "已停止当前回合。", { title: "/stop", markdown: true });
1092
1101
  return;
1093
1102
  }
1094
1103
  case "steer":
@@ -1100,15 +1109,20 @@ export class DingTalkBot {
1100
1109
  }
1101
1110
  return;
1102
1111
  }
1103
- case "events":
1104
- case "tasks":
1105
- case "status":
1106
- case "usage":
1107
- case "context":
1108
- case "subagents":
1109
- case "project": {
1112
+ default: {
1113
+ // Every remaining BuiltInCommandName is a stateless report (events/tasks/status/usage/
1114
+ // context/subagents/project), narrowed to RuntimeCommandName by TS after the four
1115
+ // cases above. Busy has no sendCommandReply-style retry semantics, so `/context` is
1116
+ // answered here like the rest instead of the runner-handled path idle uses for it
1117
+ // (see the IDLE_RUNTIME_COMMAND_NAMES comment in bootstrap.ts).
1110
1118
  const response = await this.handler.runRuntimeCommand(event, builtInCommand.name, builtInCommand.args);
1111
- await this.sendPlain(channelId, response);
1119
+ const delivered = await this.sendPlain(channelId, response, {
1120
+ title: `/${builtInCommand.name}`,
1121
+ markdown: true,
1122
+ });
1123
+ if (!delivered) {
1124
+ log.logWarning(`[${channelId}] Failed to deliver /${builtInCommand.name} reply`, `${response.length} chars`);
1125
+ }
1112
1126
  return;
1113
1127
  }
1114
1128
  }
@@ -3,9 +3,24 @@ export interface HandleEventsCommandOptions {
3
3
  workspaceDir: string;
4
4
  historyPath: string;
5
5
  }
6
+ type EventsCommand = {
7
+ action: "list";
8
+ } | {
9
+ action: "show";
10
+ name: string;
11
+ } | {
12
+ action: "delete";
13
+ name: string;
14
+ } | {
15
+ action: "history";
16
+ name?: string;
17
+ };
18
+ /** Exported so `test/commands-subcommands.test.ts` can feed every broadcast example back through it. */
19
+ export declare function parseEventsCommand(args: string): EventsCommand;
6
20
  export declare function normalizeEventName(name: string): string;
7
21
  export declare function resolveEventPath(workspaceDir: string, name: string): {
8
22
  eventName: string;
9
23
  eventPath: string;
10
24
  };
11
25
  export declare function handleEventsCommand(options: HandleEventsCommandOptions): Promise<string>;
26
+ export {};
@@ -1,50 +1,48 @@
1
1
  import { existsSync } from "fs";
2
2
  import { readdir, readFile, unlink } from "fs/promises";
3
3
  import { join, resolve, sep } from "path";
4
+ import { renderSubcommandUsage } from "../agent/commands.js";
5
+ import { capReply } from "../agent/reply-limits.js";
4
6
  import { errorMessage, eventNameFromFilename } from "../shared/text-utils.js";
5
7
  import { parseScheduledEventContent } from "./events.js";
6
8
  const EVENT_NAME_PATTERN = /^[A-Za-z0-9._-]+$/;
7
9
  const DEFAULT_HISTORY_LIMIT = 20;
8
10
  const TEXT_PREVIEW_MAX_CHARS = 100;
9
11
  function usage() {
10
- return `# Events
11
-
12
- Usage:
13
-
14
- - \`/events list\`
15
- - \`/events show <name>\`
16
- - \`/events delete <name>\`
17
- - \`/events history [name]\``;
12
+ return renderSubcommandUsage("events");
18
13
  }
19
- function parseEventsCommand(args) {
14
+ /** Exported so `test/commands-subcommands.test.ts` can feed every broadcast example back through it. */
15
+ export function parseEventsCommand(args) {
20
16
  const parts = args.trim().split(/\s+/).filter(Boolean);
21
17
  const action = parts[0];
22
18
  const name = parts[1];
23
19
  if (!action || action === "list") {
24
20
  if (parts.length > 1)
25
- throw new Error("Usage: /events list");
21
+ throw new Error("用法:/events list");
26
22
  return { action: "list" };
27
23
  }
28
24
  if (action === "show") {
29
25
  if (!name || parts.length > 2)
30
- throw new Error("Usage: /events show <name>");
26
+ throw new Error("用法:/events show <name>");
31
27
  return { action, name };
32
28
  }
33
29
  if (action === "delete") {
34
30
  if (!name || parts.length > 2)
35
- throw new Error("Usage: /events delete <name>");
31
+ throw new Error("用法:/events delete <name>");
36
32
  return { action, name };
37
33
  }
38
34
  if (action === "history") {
39
35
  if (parts.length > 2)
40
- throw new Error("Usage: /events history [name]");
36
+ throw new Error("用法:/events history [name]");
41
37
  return name ? { action, name } : { action };
42
38
  }
43
- throw new Error(`Unknown /events action: ${action}`);
39
+ throw new Error(`未知的 /events 动作:${action}`);
44
40
  }
45
41
  function eventsDir(workspaceDir) {
46
42
  return join(workspaceDir, "events");
47
43
  }
44
+ // English on purpose: shared with the model-facing `event_manage` tool (src/tools/event-manage.ts),
45
+ // which follows the tool-error convention elsewhere in the codebase, not the command-reply one.
48
46
  export function normalizeEventName(name) {
49
47
  const trimmed = name.trim();
50
48
  const normalized = trimmed.endsWith(".json") ? trimmed.slice(0, -".json".length) : trimmed;
@@ -67,24 +65,24 @@ function clipText(text, maxChars = TEXT_PREVIEW_MAX_CHARS) {
67
65
  return normalized.length > maxChars ? `${normalized.slice(0, maxChars - 1)}...` : normalized;
68
66
  }
69
67
  function formatEventSummary(name, event) {
70
- const lines = [`- ${name}`, ` type: ${event.type}`, ` channelId: ${event.channelId}`];
68
+ const lines = [`**${name}**`, `- 类型:${event.type}`, `- channelId:${event.channelId}`];
71
69
  if (event.type === "one-shot") {
72
- lines.push(` at: ${event.at}`);
70
+ lines.push(`- 触发时间:${event.at}`);
73
71
  }
74
72
  if (event.type === "periodic") {
75
- lines.push(` schedule: ${event.schedule}`);
73
+ lines.push(`- schedule:${event.schedule}`);
76
74
  }
77
- lines.push(` text: ${clipText(event.text)}`);
75
+ lines.push(`- 内容:${clipText(event.text)}`);
78
76
  return lines.join("\n");
79
77
  }
80
78
  async function listEvents(workspaceDir) {
81
79
  const dir = eventsDir(workspaceDir);
82
80
  if (!existsSync(dir)) {
83
- return "# Events\n\nNo events directory found.";
81
+ return "**定时事件**\n\n没有找到 events 目录。";
84
82
  }
85
83
  const filenames = (await readdir(dir)).filter((filename) => filename.endsWith(".json")).sort();
86
84
  if (filenames.length === 0) {
87
- return "# Events\n\nNo event files found.";
85
+ return "**定时事件**\n\n暂无事件文件。";
88
86
  }
89
87
  const blocks = [];
90
88
  for (const filename of filenames) {
@@ -96,19 +94,21 @@ async function listEvents(workspaceDir) {
96
94
  }
97
95
  catch (error) {
98
96
  const message = errorMessage(error);
99
- blocks.push(`- ${name}\n invalid: ${message}`);
97
+ blocks.push(`**${name}**\n- ⚠ 无效:${message}`);
100
98
  }
101
99
  }
102
- return `# Events\n\n${blocks.join("\n\n")}`;
100
+ return capReply(`**定时事件**\n\n${blocks.join("\n\n")}`, {
101
+ nextStepHint: "用 `/events show <name>` 查看单个事件",
102
+ }).text;
103
103
  }
104
104
  async function showEvent(workspaceDir, name) {
105
105
  const { eventName, eventPath } = resolveEventPath(workspaceDir, name);
106
106
  if (!existsSync(eventPath)) {
107
- return `Event not found: ${eventName}`;
107
+ return `找不到事件:${eventName}`;
108
108
  }
109
109
  const raw = await readFile(eventPath, "utf-8");
110
110
  const parsed = JSON.parse(raw);
111
- return `# Event: ${eventName}
111
+ return `**事件 ${eventName}**
112
112
 
113
113
  \`\`\`json
114
114
  ${JSON.stringify(parsed, null, 2)}
@@ -117,10 +117,20 @@ ${JSON.stringify(parsed, null, 2)}
117
117
  async function deleteEvent(workspaceDir, name) {
118
118
  const { eventName, eventPath } = resolveEventPath(workspaceDir, name);
119
119
  if (!existsSync(eventPath)) {
120
- return `Event not found: ${eventName}`;
120
+ return `找不到事件:${eventName}`;
121
+ }
122
+ // Read before deleting so the reply carries what was removed (review 2026-08-24 §3.4):
123
+ // an accidental delete stays recoverable from chat history instead of a bare confirmation.
124
+ let summary;
125
+ try {
126
+ const event = parseScheduledEventContent(await readFile(eventPath, "utf-8"), `${eventName}.json`);
127
+ summary = formatEventSummary(eventName, event);
128
+ }
129
+ catch {
130
+ // Unparseable content is still safe to delete; just skip the summary.
121
131
  }
122
132
  await unlink(eventPath);
123
- return `Deleted event: ${eventName}`;
133
+ return summary ? `已删除事件:\n\n${summary}` : `已删除事件:${eventName}`;
124
134
  }
125
135
  function parseHistoryLine(line) {
126
136
  try {
@@ -137,24 +147,24 @@ function parseHistoryLine(line) {
137
147
  function formatHistoryRecord(record) {
138
148
  const details = [];
139
149
  if (record.channelId)
140
- details.push(` channelId: ${record.channelId}`);
150
+ details.push(`- channelId:${record.channelId}`);
141
151
  if (record.schedule)
142
- details.push(` schedule: ${record.schedule}`);
152
+ details.push(`- schedule:${record.schedule}`);
143
153
  if (record.at)
144
- details.push(` at: ${record.at}`);
154
+ details.push(`- 触发时间:${record.at}`);
145
155
  if (record.nextRunAt)
146
- details.push(` nextRunAt: ${record.nextRunAt}`);
156
+ details.push(`- 下次运行:${record.nextRunAt}`);
147
157
  if (record.reason)
148
- details.push(` reason: ${record.reason}`);
158
+ details.push(`- 原因:${record.reason}`);
149
159
  if (record.textPreview)
150
- details.push(` text: ${clipText(record.textPreview)}`);
151
- const header = `- ${record.ts} ${record.eventName} ${record.action} ${record.result}`;
160
+ details.push(`- 内容:${clipText(record.textPreview)}`);
161
+ const header = `**${record.ts} ${record.eventName}** ${record.action} · ${record.result}`;
152
162
  return details.length > 0 ? `${header}\n${details.join("\n")}` : header;
153
163
  }
154
164
  async function showHistory(historyPath, name) {
155
165
  const eventName = name ? normalizeEventName(name) : undefined;
156
166
  if (!existsSync(historyPath)) {
157
- return "# Event History\n\nNo event history found.";
167
+ return "**事件历史**\n\n暂无事件历史。";
158
168
  }
159
169
  const raw = await readFile(historyPath, "utf-8");
160
170
  const records = raw
@@ -167,12 +177,10 @@ async function showHistory(historyPath, name) {
167
177
  .slice(-DEFAULT_HISTORY_LIMIT)
168
178
  .reverse();
169
179
  if (records.length === 0) {
170
- return eventName
171
- ? `# Event History\n\nNo history found for event: ${eventName}`
172
- : "# Event History\n\nNo history found.";
180
+ return eventName ? `**事件历史**\n\n未找到事件 ${eventName} 的历史。` : "**事件历史**\n\n暂无事件历史。";
173
181
  }
174
- const suffix = eventName ? `: ${eventName}` : "";
175
- return `# Event History${suffix}\n\n${records.map(formatHistoryRecord).join("\n\n")}`;
182
+ const suffix = eventName ? ` · ${eventName}` : "";
183
+ return `**事件历史**${suffix}\n\n${records.map(formatHistoryRecord).join("\n\n")}`;
176
184
  }
177
185
  export async function handleEventsCommand(options) {
178
186
  let command;
@@ -197,6 +205,6 @@ export async function handleEventsCommand(options) {
197
205
  }
198
206
  catch (error) {
199
207
  const message = errorMessage(error);
200
- return `Could not ${command.action} events: ${message}`;
208
+ return `执行 /events ${command.action} 失败:${message}`;
201
209
  }
202
210
  }
@@ -1,3 +1,16 @@
1
+ /**
2
+ * `/project` — the human control path for a channel's project scope (spec 043, D7). Mirrors
3
+ * `task-commands.ts`/`subagent-commands.ts`'s shape: pure-ish functions returning markdown, no
4
+ * bot/event coupling. Mutations never reach the model.
5
+ */
6
+ type ProjectCommand = {
7
+ action: "show";
8
+ } | {
9
+ action: "set";
10
+ path: string;
11
+ } | {
12
+ action: "reset";
13
+ };
1
14
  export interface HandleProjectCommandOptions {
2
15
  args: string;
3
16
  channelId: string;
@@ -13,4 +26,7 @@ export interface HandleProjectCommandOptions {
13
26
  * and let the next access rebuild it under the new scope (D4.2). Not called on any failure path. */
14
27
  onScopeChanged?: () => Promise<void> | void;
15
28
  }
29
+ /** Exported so `test/commands-subcommands.test.ts` can feed every broadcast example back through it. */
30
+ export declare function parseProjectCommand(args: string): ProjectCommand;
16
31
  export declare function handleProjectCommand(options: HandleProjectCommandOptions): Promise<string>;
32
+ export {};
@@ -1,17 +1,13 @@
1
+ import { renderSubcommandUsage } from "../agent/commands.js";
1
2
  import { loadSecurityConfigWithDiagnostics } from "../security/config.js";
2
3
  import { currentProjectSandboxStatus, isWithinAllowedRoots, resolveExistingDirectory, resolveProjectAccessPolicy, } from "../security/project-scope.js";
3
4
  import { errorMessage } from "../shared/text-utils.js";
4
5
  import { commitProjectSelection, readProjectSelection } from "./project-scope-store.js";
5
6
  function usage() {
6
- return `# 项目作用域
7
-
8
- 用法:
9
-
10
- - \`/project\` — 查看当前频道的项目目录与访问边界
11
- - \`/project set <absolute-path>\` — 切换项目目录(需频道空闲,且目录在允许的可选根内)
12
- - \`/project reset\` — 切回 app 默认项目目录`;
7
+ return renderSubcommandUsage("project");
13
8
  }
14
- function parseProjectCommand(args) {
9
+ /** Exported so `test/commands-subcommands.test.ts` can feed every broadcast example back through it. */
10
+ export function parseProjectCommand(args) {
15
11
  const trimmed = args.trim();
16
12
  if (!trimmed)
17
13
  return { action: "show" };
@@ -33,26 +29,26 @@ function formatShow(options) {
33
29
  const resolution = resolveProjectAccessPolicy(securityLoad.config, process.cwd());
34
30
  const sandbox = currentProjectSandboxStatus();
35
31
  const selection = readProjectSelection(options.channelDir);
36
- const lines = ["# 项目作用域", ""];
32
+ const lines = ["**项目作用域**"];
37
33
  if (!selection) {
38
- lines.push(`项目目录:\`${resolution.policy.defaultRoot}\`(尚未选择过,将在下次准入时采用 app 默认值)`);
34
+ lines.push(`- 项目目录:\`${resolution.policy.defaultRoot}\`(尚未选择过,将在下次准入时采用 app 默认值)`);
39
35
  }
40
36
  else {
41
- lines.push(`项目目录:\`${selection.projectRoot}\`(${selection.updatedBy},更新于 ${selection.updatedAt})`);
37
+ lines.push(`- 项目目录:\`${selection.projectRoot}\`(${selection.updatedBy},更新于 ${selection.updatedAt})`);
42
38
  }
43
- lines.push(`边界:${resolution.configured ? "project(文件工具被约束在此目录内)" : "unbounded(沿用旧的全局文件权限)"}`);
44
- lines.push(`Enforcement:${sandbox.level}(${sandbox.summary})`);
39
+ lines.push(`- 边界:${resolution.configured ? "project(文件工具被约束在此目录内)" : "unbounded(沿用旧的全局文件权限)"}`);
40
+ lines.push(`- Enforcement:${sandbox.level}(${sandbox.summary})`);
45
41
  if (!resolution.configured) {
46
- lines.push("", `未配置 projectAccess:\`/project set\` 不可用。在 \`security.json\` 写入 projectAccess 段后即可使用。`);
42
+ lines.push(`- 未配置 projectAccess:\`/project set\` 不可用。在 \`security.json\` 写入 projectAccess 段后即可使用。`);
47
43
  }
48
44
  else if (!resolution.mutable) {
49
- lines.push("", "projectAccess.defaultRoot 配置有误,项目切换已被禁用,见启动诊断。");
45
+ lines.push("- projectAccess.defaultRoot 配置有误,项目切换已被禁用,见启动诊断。");
50
46
  }
51
47
  else {
52
- lines.push("", `可选根:${resolution.policy.allowedRoots.map((root) => `\`${root}\``).join("、")}`);
48
+ lines.push(`- 可选根:${resolution.policy.allowedRoots.map((root) => `\`${root}\``).join("、")}`);
53
49
  }
54
50
  for (const diagnostic of resolution.diagnostics) {
55
- lines.push(`⚠ ${diagnostic.message}`);
51
+ lines.push(`- ⚠ ${diagnostic.message}`);
56
52
  }
57
53
  return lines.join("\n");
58
54
  }
@@ -14,4 +14,24 @@ export interface HandleSubagentsCommandOptions {
14
14
  * a live `ChannelRunner` (spec 041). Lazy — never called unless a `roles` view is actually rendered. */
15
15
  getDetachedDiscovery?: () => Promise<SubAgentDiscoveryResult>;
16
16
  }
17
+ type ListFilter = "default" | "running" | "failed" | "all";
18
+ type SubagentsCommand = {
19
+ action: "list";
20
+ filter: ListFilter;
21
+ } | {
22
+ action: "show";
23
+ ref: string;
24
+ } | {
25
+ action: "output";
26
+ ref: string;
27
+ } | {
28
+ action: "cancel";
29
+ ref: string;
30
+ } | {
31
+ action: "roles";
32
+ name?: string;
33
+ };
34
+ /** Exported so `test/commands-subcommands.test.ts` can feed every broadcast example back through it. */
35
+ export declare function parseSubagentsCommand(args: string): SubagentsCommand;
17
36
  export declare function handleSubagentsCommand(options: HandleSubagentsCommandOptions): Promise<string>;
37
+ export {};