@armadra/agent 0.18.0 → 0.19.0

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 (82) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/CHANGELOG.zh-CN.md +20 -0
  3. package/README.md +4 -0
  4. package/README.zh-CN.md +4 -0
  5. package/dist/bundle/ama.cjs +25956 -25161
  6. package/dist/cli/bootstrap.js +32 -6
  7. package/dist/cli/compose-agents.js +2 -1
  8. package/dist/cli/compose-extensions-load.d.ts +20 -0
  9. package/dist/cli/compose-extensions-load.js +38 -0
  10. package/dist/cli/compose.js +1 -0
  11. package/dist/cli/deps.d.ts +11 -0
  12. package/dist/cli/runtime.d.ts +7 -0
  13. package/dist/cli/subcommands/doctor.js +33 -0
  14. package/dist/config/extension-tree-hash.d.ts +31 -0
  15. package/dist/config/extension-tree-hash.js +88 -0
  16. package/dist/config/extension-trust.d.ts +70 -0
  17. package/dist/config/extension-trust.js +112 -0
  18. package/dist/config/profile.d.ts +2 -0
  19. package/dist/config/profile.js +1 -0
  20. package/dist/config/schema-trust.d.ts +7 -0
  21. package/dist/config/schema-trust.js +46 -0
  22. package/dist/config/schema.d.ts +4 -5
  23. package/dist/config/schema.js +3 -25
  24. package/dist/config/trust.d.ts +2 -0
  25. package/dist/config/trust.js +5 -1
  26. package/dist/config/types.d.ts +13 -0
  27. package/dist/drivers/host-runners.d.ts +15 -4
  28. package/dist/drivers/host-runners.js +31 -17
  29. package/dist/errors.d.ts +1 -1
  30. package/dist/host/api-impl.d.ts +47 -4
  31. package/dist/host/api-impl.js +181 -20
  32. package/dist/host/commands.d.ts +23 -0
  33. package/dist/host/commands.js +76 -0
  34. package/dist/host/extensions.d.ts +43 -0
  35. package/dist/host/extensions.js +117 -0
  36. package/dist/host/resources.d.ts +2 -0
  37. package/dist/host/resources.js +5 -0
  38. package/dist/host/types.d.ts +41 -2
  39. package/dist/host/types.js +4 -2
  40. package/dist/i18n/catalog.d.ts +31 -0
  41. package/dist/i18n/messages/cli.d.ts +24 -0
  42. package/dist/i18n/messages/cli.js +24 -0
  43. package/dist/i18n/messages/drivers.d.ts +22 -0
  44. package/dist/i18n/messages/drivers.js +22 -0
  45. package/dist/i18n/messages/errors.d.ts +1 -1
  46. package/dist/i18n/messages/interactive-startup.d.ts +4 -0
  47. package/dist/i18n/messages/interactive-startup.js +4 -0
  48. package/dist/i18n/messages/interactive.d.ts +4 -0
  49. package/dist/i18n/messages/report.d.ts +12 -0
  50. package/dist/i18n/messages/report.js +12 -0
  51. package/dist/modes/acp/acp-config.d.ts +4 -2
  52. package/dist/modes/acp/acp-config.js +17 -3
  53. package/dist/modes/acp/acp-events.d.ts +2 -0
  54. package/dist/modes/acp/acp-events.js +4 -0
  55. package/dist/modes/acp/acp-server.js +6 -2
  56. package/dist/modes/acp/acp-sessions.d.ts +8 -1
  57. package/dist/modes/acp/acp-sessions.js +18 -0
  58. package/dist/modes/commands-core.d.ts +14 -1
  59. package/dist/modes/commands-core.js +34 -2
  60. package/dist/modes/interactive/startup-ui.js +21 -0
  61. package/dist/modes/interactive/status-area.js +1 -1
  62. package/dist/modes/print/print-mode.d.ts +3 -0
  63. package/dist/modes/print/print-mode.js +35 -8
  64. package/dist/modes/rpc/commands.d.ts +2 -0
  65. package/dist/modes/rpc/commands.js +22 -7
  66. package/dist/modes/rpc/rpc-mode.js +3 -0
  67. package/dist/modes/startup-ui-text.js +11 -0
  68. package/dist/rpc.d.ts +2 -1
  69. package/dist/tools/registry.d.ts +6 -0
  70. package/dist/tools/registry.js +13 -0
  71. package/dist/tools/types.d.ts +7 -0
  72. package/docs/README.md +1 -1
  73. package/docs/en/README.md +3 -3
  74. package/docs/en/guides/extensions.md +141 -0
  75. package/docs/en/reference/acp.md +1 -1
  76. package/docs/en/reference/host-api.md +55 -27
  77. package/docs/en/reference/rpc.md +9 -7
  78. package/docs/guides/extensions.md +136 -0
  79. package/docs/reference/acp.md +1 -1
  80. package/docs/reference/host-api.md +55 -27
  81. package/docs/reference/rpc.md +9 -7
  82. package/package.json +4 -2
@@ -19,6 +19,8 @@
19
19
  * 增量递增 {@link HOST_API_MINOR},宿主按成员是否存在做特性探测。
20
20
  * - (#270)host-api 1.2:可选面 `HostApi.resources`(宿主资源命名空间,内置 `read` 读 `scheme://path`;
21
21
  * 类型在 tools/resource-ref.ts,此处再导出)。
22
+ * - (#301)host-api 1.4:可选面 `HostApi.commands`(`register` 斜杠命令,宿主适配器与本地扩展都可用)。
23
+ * 只加不改,主版本不变。
22
24
  * - (#268)host-api 1.3:`session_start` 在 `reason: "resume"` 时带 `uncleanEnd`(上一轮没有正常结束,
23
25
  * 判定见 session/unclean-end.ts)。只加不改,主版本不变。
24
26
  */
@@ -37,10 +39,10 @@ export type { CacheMiss, WarmDecision, WarmingDecisionHandler } from "../ai/cach
37
39
  export declare const HOST_API_VERSION: 1;
38
40
  export type HostApiVersion = typeof HOST_API_VERSION;
39
41
  /**
40
- * host-api 小版本:只加不改的可选面每加一批递增(1 = `runners.onDone`,2 = `resources`,3 = `session_start.uncleanEnd`);
42
+ * host-api 小版本:只加不改的可选面每加一批递增(1 = `runners.onDone`,2 = `resources`,3 = `session_start.uncleanEnd`,4 = `commands`);
41
43
  * 旧运行时没有 `api.minor`,按 0 算。
42
44
  */
43
- export declare const HOST_API_MINOR: 3;
45
+ export declare const HOST_API_MINOR: 4;
44
46
  export type HostMode = "interactive" | "line" | "print" | "rpc";
45
47
  export type InstructionSource = {
46
48
  kind: "file";
@@ -135,6 +137,33 @@ export interface AgentEvents {
135
137
  /** [W6-O] ChatGPT 订阅配额更新(docs/history/wave6-plan.md §4.5)。 */
136
138
  quota_update: Omit<QuotaUpdateEvent, "type">;
137
139
  }
140
+ /** [#301] `commands.register` 的命令:`name` 不带斜杠,`^[a-z][a-z0-9-]{0,63}$`。 */
141
+ export interface HostCommand {
142
+ readonly name: string;
143
+ readonly description: string;
144
+ /** 参数占位(`/help`、补全里显示),如 `"[topic]"`。 */
145
+ readonly args?: string;
146
+ run(args: string, ctx: HostCommandContext): HostCommandResult | Promise<HostCommandResult>;
147
+ }
148
+ /** [#301] 传给命令 `run` 的上下文(刻意很小;要更多能力用注册时拿到的 `api`)。 */
149
+ export interface HostCommandContext {
150
+ readonly mode: HostMode;
151
+ readonly session: {
152
+ id(): string;
153
+ cwd(): string;
154
+ };
155
+ }
156
+ /**
157
+ * [#301] 命令结果:`handled` 把 `message` 显示给用户(不进对话);`prompt` 改发 `text` 作为用户提示。
158
+ * 返回 `undefined` 等同 `{ kind: "handled" }`;其它形状按错误处理。
159
+ */
160
+ export type HostCommandResult = {
161
+ kind: "handled";
162
+ message?: string;
163
+ } | {
164
+ kind: "prompt";
165
+ text: string;
166
+ } | undefined;
138
167
  /** [W5-C0] 宿主注入的 runner:`id` 即 `task(agent=<id>)` 的名字,`description` 进 task 工具描述。 */
139
168
  export type HostRunner = SubagentRunner & {
140
169
  readonly description: string;
@@ -229,6 +258,16 @@ export interface HostApi {
229
258
  */
230
259
  onDone?(handler: (event: RunnerDoneEvent) => void | Promise<void>): () => void;
231
260
  };
261
+ /**
262
+ * [#301] 斜杠命令(host-api 1.4):在内置命令之后、提示模板之前分派;与内置命令(含别名)或已注册的命令
263
+ * 同名则抛错;返回值用于注销。`/help`、补全与 RPC `get_commands`(`source: "extension"`)都列出。
264
+ * 可选面:旧版本运行时没有它,用前判断 `api.commands !== undefined`。
265
+ */
266
+ readonly commands?: {
267
+ register(command: HostCommand): () => void;
268
+ /** 已注册的命令名(全部模块),按注册顺序。 */
269
+ list(): readonly string[];
270
+ };
232
271
  /**
233
272
  * [#270] 宿主资源命名空间(host-api 1.2):注册后内置 `read` 认 `<scheme>://<path>`,按 `read` 的分页与
234
273
  * 截断规则返回宿主给的文本(首行标注不可信),权限类 read、从不询问;系统提示工具节多一行列出全部
@@ -19,12 +19,14 @@
19
19
  * 增量递增 {@link HOST_API_MINOR},宿主按成员是否存在做特性探测。
20
20
  * - (#270)host-api 1.2:可选面 `HostApi.resources`(宿主资源命名空间,内置 `read` 读 `scheme://path`;
21
21
  * 类型在 tools/resource-ref.ts,此处再导出)。
22
+ * - (#301)host-api 1.4:可选面 `HostApi.commands`(`register` 斜杠命令,宿主适配器与本地扩展都可用)。
23
+ * 只加不改,主版本不变。
22
24
  * - (#268)host-api 1.3:`session_start` 在 `reason: "resume"` 时带 `uncleanEnd`(上一轮没有正常结束,
23
25
  * 判定见 session/unclean-end.ts)。只加不改,主版本不变。
24
26
  */
25
27
  export const HOST_API_VERSION = 1;
26
28
  /**
27
- * host-api 小版本:只加不改的可选面每加一批递增(1 = `runners.onDone`,2 = `resources`,3 = `session_start.uncleanEnd`);
29
+ * host-api 小版本:只加不改的可选面每加一批递增(1 = `runners.onDone`,2 = `resources`,3 = `session_start.uncleanEnd`,4 = `commands`);
28
30
  * 旧运行时没有 `api.minor`,按 0 算。
29
31
  */
30
- export const HOST_API_MINOR = 3;
32
+ export const HOST_API_MINOR = 4;
@@ -77,6 +77,18 @@ declare const en: {
77
77
  eventWarning: (message: string, detail?: string) => string;
78
78
  sessionNotReady: string;
79
79
  hostDisposeFailed: (error: string) => string;
80
+ extensionSkipped: (path: string, reason: string) => string;
81
+ extensionNotActivated: string;
82
+ extensionsTrustFailed: (reason: string) => string;
83
+ extensionReason: {
84
+ "no-trust": string;
85
+ untrusted: string;
86
+ changed: string;
87
+ declined: string;
88
+ unreadable: string;
89
+ "too-large": string;
90
+ };
91
+ extensionDisposeFailed: (path: string, error: string) => string;
80
92
  sessionStartBlocked: (reason?: string) => string;
81
93
  subcommandNotDispatched: string;
82
94
  runtimeNotAssembled: string;
@@ -684,6 +696,8 @@ declare const en: {
684
696
  trustNever: string;
685
697
  moreResources: (n: number) => string;
686
698
  trustTitle: string;
699
+ extensionsTitle: string;
700
+ extensionDirectory: string;
687
701
  resumeTitle: string;
688
702
  modelTitle: string;
689
703
  cwdTitle: string;
@@ -1157,6 +1171,7 @@ declare const en: {
1157
1171
  more: (count: number) => string;
1158
1172
  trustQuestion: (cwd: string) => string;
1159
1173
  trustChoices: string;
1174
+ extensionsQuestion: string;
1160
1175
  resumeQuestion: string;
1161
1176
  resumeAnswer: string;
1162
1177
  pickModel: string;
@@ -1292,6 +1307,11 @@ declare const en: {
1292
1307
  trustInvalid: string;
1293
1308
  trust: (cwd: string, trusted: boolean, from: string) => string;
1294
1309
  gated: (trusted: boolean) => string;
1310
+ extensionsTitle: string;
1311
+ extensionsNote: string;
1312
+ extensionsNone: string;
1313
+ extensionLine: (enabled: boolean, path: string, sha: string, reason: string | undefined, directory: boolean) => string;
1314
+ extensionSha: (sha256: string | undefined) => string;
1295
1315
  keysTitle: string;
1296
1316
  authMode: (mode: string, path: string) => string;
1297
1317
  none: string;
@@ -1670,9 +1690,20 @@ declare const en: {
1670
1690
  instructionNeedsPath: string;
1671
1691
  instructionNeedsText: string;
1672
1692
  brokerNeedsAsk: string;
1693
+ brokerIgnored: string;
1694
+ commandNotObject: string;
1695
+ commandBadName: (name: string) => string;
1696
+ commandNoDescription: (name: string) => string;
1697
+ commandNoRun: (name: string) => string;
1698
+ commandBadArgs: (name: string) => string;
1699
+ commandReserved: (name: string) => string;
1700
+ commandExists: (name: string) => string;
1701
+ commandBadResult: (name: string) => string;
1673
1702
  warmingNeedsFunction: string;
1674
1703
  runnerNeedsIdStart: string;
1675
1704
  runnerDoneNeedsFunction: string;
1705
+ runnerExists: (id: string) => string;
1706
+ revokedIgnored: (what: string) => string;
1676
1707
  resourceFrozen: string;
1677
1708
  resourceNotObject: string;
1678
1709
  resourceBadScheme: (scheme: string) => string;
@@ -74,6 +74,18 @@ export declare const en: {
74
74
  eventWarning: (message: string, detail?: string) => string;
75
75
  sessionNotReady: string;
76
76
  hostDisposeFailed: (error: string) => string;
77
+ extensionSkipped: (path: string, reason: string) => string;
78
+ extensionNotActivated: string;
79
+ extensionsTrustFailed: (reason: string) => string;
80
+ extensionReason: {
81
+ "no-trust": string;
82
+ untrusted: string;
83
+ changed: string;
84
+ declined: string;
85
+ unreadable: string;
86
+ "too-large": string;
87
+ };
88
+ extensionDisposeFailed: (path: string, error: string) => string;
77
89
  sessionStartBlocked: (reason?: string) => string;
78
90
  subcommandNotDispatched: string;
79
91
  runtimeNotAssembled: string;
@@ -241,6 +253,18 @@ export declare const zh: {
241
253
  eventWarning: (message: string, detail: string | undefined) => string;
242
254
  sessionNotReady: string;
243
255
  hostDisposeFailed: (error: string) => string;
256
+ extensionSkipped: (path: string, reason: string) => string;
257
+ extensionNotActivated: string;
258
+ extensionsTrustFailed: (reason: string) => string;
259
+ extensionReason: {
260
+ "no-trust": string;
261
+ untrusted: string;
262
+ changed: string;
263
+ declined: string;
264
+ unreadable: string;
265
+ "too-large": string;
266
+ };
267
+ extensionDisposeFailed: (path: string, error: string) => string;
244
268
  sessionStartBlocked: (reason: string | undefined) => string;
245
269
  subcommandNotDispatched: string;
246
270
  runtimeNotAssembled: string;
@@ -56,6 +56,18 @@ export const en = {
56
56
  eventWarning: (message, detail) => detail === undefined ? message : `${message}: ${detail}`,
57
57
  sessionNotReady: "Session is not ready yet",
58
58
  hostDisposeFailed: (error) => `Host adapter dispose failed: ${error}`,
59
+ extensionSkipped: (path, reason) => `Extension skipped: ${path}: ${reason}`,
60
+ extensionNotActivated: "create() returned no adapter",
61
+ extensionsTrustFailed: (reason) => `Local extensions skipped: trust decision failed: ${reason}`,
62
+ extensionReason: {
63
+ "no-trust": "disabled by --no-trust",
64
+ untrusted: "not trusted (approve it in an interactive session)",
65
+ changed: "content changed since it was trusted (approve it in an interactive session)",
66
+ declined: "not trusted",
67
+ unreadable: "cannot read the file",
68
+ "too-large": "directory extension is too large (more than 2000 files or 50 MiB)",
69
+ },
70
+ extensionDisposeFailed: (path, error) => `Extension dispose failed: ${path}: ${error}`,
59
71
  sessionStartBlocked: (reason) => `SessionStart hook blocked startup: ${reason ?? "(no reason given)"}`,
60
72
  subcommandNotDispatched: "Subcommands should be dispatched by main",
61
73
  runtimeNotAssembled: "ama: runtime not assembled (the integration batch injects it via registerRuntimeDeps)\n",
@@ -210,6 +222,18 @@ export const zh = {
210
222
  eventWarning: (message, detail) => (detail === undefined ? message : `${message}:${detail}`),
211
223
  sessionNotReady: "会话尚未就绪",
212
224
  hostDisposeFailed: (error) => `宿主适配器 dispose 失败:${error}`,
225
+ extensionSkipped: (path, reason) => `已跳过扩展:${path}:${reason}`,
226
+ extensionNotActivated: "create() 没有返回适配器",
227
+ extensionsTrustFailed: (reason) => `已跳过全部本地扩展:信任判定失败:${reason}`,
228
+ extensionReason: {
229
+ "no-trust": "被 --no-trust 禁用",
230
+ untrusted: "未信任(在交互会话里确认后启用)",
231
+ changed: "内容自信任后已改变(在交互会话里重新确认后启用)",
232
+ declined: "未信任",
233
+ unreadable: "读不了文件",
234
+ "too-large": "目录扩展过大(超过 2000 个文件或 50 MiB)",
235
+ },
236
+ extensionDisposeFailed: (path, error) => `扩展 dispose 失败:${path}:${error}`,
213
237
  sessionStartBlocked: (reason) => `SessionStart Hook 阻止启动:${reason ?? "(无原因)"}`,
214
238
  subcommandNotDispatched: "子命令应由 main 分派",
215
239
  runtimeNotAssembled: "ama: 运行时尚未装配(集成批次通过 registerRuntimeDeps 注入实现)\n",
@@ -55,9 +55,20 @@ export declare const en: {
55
55
  instructionNeedsPath: string;
56
56
  instructionNeedsText: string;
57
57
  brokerNeedsAsk: string;
58
+ brokerIgnored: string;
59
+ commandNotObject: string;
60
+ commandBadName: (name: string) => string;
61
+ commandNoDescription: (name: string) => string;
62
+ commandNoRun: (name: string) => string;
63
+ commandBadArgs: (name: string) => string;
64
+ commandReserved: (name: string) => string;
65
+ commandExists: (name: string) => string;
66
+ commandBadResult: (name: string) => string;
58
67
  warmingNeedsFunction: string;
59
68
  runnerNeedsIdStart: string;
60
69
  runnerDoneNeedsFunction: string;
70
+ runnerExists: (id: string) => string;
71
+ revokedIgnored: (what: string) => string;
61
72
  resourceFrozen: string;
62
73
  resourceNotObject: string;
63
74
  resourceBadScheme: (scheme: string) => string;
@@ -122,9 +133,20 @@ export declare const zh: {
122
133
  instructionNeedsPath: string;
123
134
  instructionNeedsText: string;
124
135
  brokerNeedsAsk: string;
136
+ brokerIgnored: string;
137
+ commandNotObject: string;
138
+ commandBadName: (name: string) => string;
139
+ commandNoDescription: (name: string) => string;
140
+ commandNoRun: (name: string) => string;
141
+ commandBadArgs: (name: string) => string;
142
+ commandReserved: (name: string) => string;
143
+ commandExists: (name: string) => string;
144
+ commandBadResult: (name: string) => string;
125
145
  warmingNeedsFunction: string;
126
146
  runnerNeedsIdStart: string;
127
147
  runnerDoneNeedsFunction: string;
148
+ runnerExists: (id: string) => string;
149
+ revokedIgnored: (what: string) => string;
128
150
  resourceFrozen: string;
129
151
  resourceNotObject: string;
130
152
  resourceBadScheme: (scheme: string) => string;
@@ -56,9 +56,20 @@ export const en = {
56
56
  instructionNeedsPath: "instructions.add: file needs path",
57
57
  instructionNeedsText: "instructions.add: text needs text",
58
58
  brokerNeedsAsk: "approvals.setBroker: broker needs ask()",
59
+ brokerIgnored: "approvals.setBroker: a broker was already set by another module; ignored",
60
+ commandNotObject: "commands.register: needs a command object",
61
+ commandBadName: (name) => `commands.register: invalid command name ${name} (lowercase letters, digits and -, starting with a letter, at most 64 characters)`,
62
+ commandNoDescription: (name) => `commands.register: ${name} needs a description`,
63
+ commandNoRun: (name) => `commands.register: ${name} needs a run function`,
64
+ commandBadArgs: (name) => `commands.register: ${name} args must be a string`,
65
+ commandReserved: (name) => `commands.register: ${name} is a built-in command`,
66
+ commandExists: (name) => `commands.register: command ${name} already exists`,
67
+ commandBadResult: (name) => `command /${name} returned an invalid result (expected { kind: "handled" } or { kind: "prompt", text })`,
59
68
  warmingNeedsFunction: "cache.onWarmingDecision: needs a function",
60
69
  runnerNeedsIdStart: "runners.provide: needs a runner with id and start",
61
70
  runnerDoneNeedsFunction: "runners.onDone: needs a function",
71
+ runnerExists: (id) => `runners.provide: runner ${id} already exists`,
72
+ revokedIgnored: (what) => `${what}: ignored, this module's registrations were revoked (activation failed)`,
62
73
  resourceFrozen: "resources.register: resources must be registered inside create(); the list is fixed once the session starts",
63
74
  resourceNotObject: "resources.register: the resource must be an object",
64
75
  resourceBadScheme: (scheme) => `resources.register: invalid scheme ${scheme} (expected ^[a-z][a-z0-9+.-]{1,31}$)`,
@@ -123,9 +134,20 @@ export const zh = {
123
134
  instructionNeedsPath: "instructions.add:file 需要 path",
124
135
  instructionNeedsText: "instructions.add:text 需要 text",
125
136
  brokerNeedsAsk: "approvals.setBroker:broker 需要 ask()",
137
+ brokerIgnored: "approvals.setBroker:已有其它模块设置了 broker,本次忽略",
138
+ commandNotObject: "commands.register:需要命令对象",
139
+ commandBadName: (name) => `commands.register:命令名 ${name} 不合法(小写字母、数字与 -,以字母开头,最多 64 个字符)`,
140
+ commandNoDescription: (name) => `commands.register:${name} 需要 description`,
141
+ commandNoRun: (name) => `commands.register:${name} 需要 run 函数`,
142
+ commandBadArgs: (name) => `commands.register:${name} 的 args 必须是字符串`,
143
+ commandReserved: (name) => `commands.register:${name} 是内置命令`,
144
+ commandExists: (name) => `commands.register:命令 ${name} 已存在`,
145
+ commandBadResult: (name) => `命令 /${name} 返回了不合法的结果(应为 { kind: "handled" } 或 { kind: "prompt", text })`,
126
146
  warmingNeedsFunction: "cache.onWarmingDecision:需要函数",
127
147
  runnerNeedsIdStart: "runners.provide:需要带 id 与 start 的 runner",
128
148
  runnerDoneNeedsFunction: "runners.onDone:需要函数",
149
+ runnerExists: (id) => `runners.provide:runner ${id} 已存在`,
150
+ revokedIgnored: (what) => `${what}:已忽略,本模块的注册已撤回(激活失败)`,
129
151
  resourceFrozen: "resources.register:资源只能在 create() 里注册,会话开始后列表已固定",
130
152
  resourceNotObject: "resources.register:资源应为对象",
131
153
  resourceBadScheme: (scheme) => `resources.register:scheme 不合法:${scheme}(应匹配 ^[a-z][a-z0-9+.-]{1,31}$)`,
@@ -76,7 +76,7 @@ export declare const zh: {
76
76
  refreshFailed: (reason: string) => string;
77
77
  notListed: (unknown: string, choices: string) => string;
78
78
  refreshStatus: (status: "failed" | "unchanged" | "updated", providers: number, models: number, at: string | undefined) => string;
79
- section: (kind: "added" | "removed" | "changed", count: number) => string;
79
+ section: (kind: "changed" | "added" | "removed", count: number) => string;
80
80
  more: (count: number) => string;
81
81
  changed: (ref: string, parts: readonly string[]) => string;
82
82
  };
@@ -33,6 +33,8 @@ export declare const en: {
33
33
  trustNever: string;
34
34
  moreResources: (n: number) => string;
35
35
  trustTitle: string;
36
+ extensionsTitle: string;
37
+ extensionDirectory: string;
36
38
  resumeTitle: string;
37
39
  modelTitle: string;
38
40
  cwdTitle: string;
@@ -71,6 +73,8 @@ export declare const zh: {
71
73
  trustNever: string;
72
74
  moreResources: (n: number) => string;
73
75
  trustTitle: string;
76
+ extensionsTitle: string;
77
+ extensionDirectory: string;
74
78
  resumeTitle: string;
75
79
  modelTitle: string;
76
80
  cwdTitle: string;
@@ -34,6 +34,8 @@ export const en = {
34
34
  trustNever: "Don't trust and remember",
35
35
  moreResources: (n) => ` …${n} more`,
36
36
  trustTitle: "Trust this folder's project resources?",
37
+ extensionsTitle: "Enable these local extensions? They run code with your permissions",
38
+ extensionDirectory: "[directory, whole tree hashed]",
37
39
  resumeTitle: "Resume which session?",
38
40
  modelTitle: "Choose a model",
39
41
  cwdTitle: "The session's working directory does not exist",
@@ -72,6 +74,8 @@ export const zh = {
72
74
  trustNever: "不信任并记住",
73
75
  moreResources: (n) => ` …另有 ${n} 项`,
74
76
  trustTitle: "信任这个目录的项目资源?",
77
+ extensionsTitle: "启用这些本地扩展?它们以你的权限运行代码",
78
+ extensionDirectory: "[目录,整棵树计入哈希]",
75
79
  resumeTitle: "恢复哪个会话?",
76
80
  modelTitle: "选择模型",
77
81
  cwdTitle: "会话的工作目录不存在",
@@ -234,6 +234,8 @@ export declare const en: {
234
234
  trustNever: string;
235
235
  moreResources: (n: number) => string;
236
236
  trustTitle: string;
237
+ extensionsTitle: string;
238
+ extensionDirectory: string;
237
239
  resumeTitle: string;
238
240
  modelTitle: string;
239
241
  cwdTitle: string;
@@ -485,6 +487,8 @@ export declare const zh: {
485
487
  trustNever: string;
486
488
  moreResources: (n: number) => string;
487
489
  trustTitle: string;
490
+ extensionsTitle: string;
491
+ extensionDirectory: string;
488
492
  resumeTitle: string;
489
493
  modelTitle: string;
490
494
  cwdTitle: string;
@@ -79,6 +79,7 @@ export declare const en: {
79
79
  more: (count: number) => string;
80
80
  trustQuestion: (cwd: string) => string;
81
81
  trustChoices: string;
82
+ extensionsQuestion: string;
82
83
  resumeQuestion: string;
83
84
  resumeAnswer: string;
84
85
  pickModel: string;
@@ -219,6 +220,11 @@ export declare const en: {
219
220
  trustInvalid: string;
220
221
  trust: (cwd: string, trusted: boolean, from: string) => string;
221
222
  gated: (trusted: boolean) => string;
223
+ extensionsTitle: string;
224
+ extensionsNote: string;
225
+ extensionsNone: string;
226
+ extensionLine: (enabled: boolean, path: string, sha: string, reason: string | undefined, directory: boolean) => string;
227
+ extensionSha: (sha256: string | undefined) => string;
222
228
  keysTitle: string;
223
229
  authMode: (mode: string, path: string) => string;
224
230
  none: string;
@@ -326,6 +332,7 @@ export declare const zh: {
326
332
  more: (count: number) => string;
327
333
  trustQuestion: (cwd: string) => string;
328
334
  trustChoices: string;
335
+ extensionsQuestion: string;
329
336
  resumeQuestion: string;
330
337
  resumeAnswer: string;
331
338
  pickModel: string;
@@ -461,6 +468,11 @@ export declare const zh: {
461
468
  trustInvalid: string;
462
469
  trust: (cwd: string, trusted: boolean, from: string) => string;
463
470
  gated: (trusted: boolean) => string;
471
+ extensionsTitle: string;
472
+ extensionsNote: string;
473
+ extensionsNone: string;
474
+ extensionLine: (enabled: boolean, path: string, sha: string, reason: string | undefined, directory: boolean) => string;
475
+ extensionSha: (sha256: string | undefined) => string;
464
476
  keysTitle: string;
465
477
  authMode: (mode: string, path: string) => string;
466
478
  none: string;
@@ -80,6 +80,7 @@ export const en = {
80
80
  more: (count) => ` …${count} more`,
81
81
  trustQuestion: (cwd) => `Trust this directory's project resources? ${cwd}`,
82
82
  trustChoices: "[y this time / a trust and remember / N don't trust] ",
83
+ extensionsQuestion: "Enable these local extensions? They run code with your permissions",
83
84
  resumeQuestion: "Resume which session?",
84
85
  resumeAnswer: "Number or id: ",
85
86
  pickModel: "Choose a model:",
@@ -220,6 +221,11 @@ export const en = {
220
221
  trustInvalid: "trust.json is invalid",
221
222
  trust: (cwd, trusted, from) => `${cwd}: ${trusted ? "trusted" : "not trusted"} (${from})`,
222
223
  gated: (trusted) => `Resources that need trust${trusted ? "" : " (not loaded now)"}:`,
224
+ extensionsTitle: "Local extensions",
225
+ extensionsNote: "Listed from files and trust records only; doctor never runs extension code, so load failures show at startup",
226
+ extensionsNone: "none (user-level extensions/ and profile extensions are empty)",
227
+ extensionLine: (enabled, path, sha, reason, directory) => `${enabled ? "enabled" : "skipped"} ${directory ? "[directory] " : ""}${path} sha256 ${sha}${reason === undefined ? "" : ` (${reason})`}`,
228
+ extensionSha: (sha256) => sha256?.slice(0, 12) ?? "-",
223
229
  keysTitle: "Key sources (sources only, never values)",
224
230
  authMode: (mode, path) => `auth.json mode ${mode}, should be 600: ${path}`,
225
231
  none: "none",
@@ -333,6 +339,7 @@ export const zh = {
333
339
  more: (count) => ` …另有 ${count} 项`,
334
340
  trustQuestion: (cwd) => `信任这个目录的项目资源?${cwd}`,
335
341
  trustChoices: "[y 仅本次 / a 信任并记住 / N 不信任] ",
342
+ extensionsQuestion: "启用这些本地扩展?它们以你的权限运行代码",
336
343
  resumeQuestion: "恢复哪个会话?",
337
344
  resumeAnswer: "编号或 id:",
338
345
  pickModel: "选择模型:",
@@ -465,6 +472,11 @@ export const zh = {
465
472
  trustInvalid: "trust.json 无效",
466
473
  trust: (cwd, trusted, from) => `${cwd}:${trusted ? "已信任" : "未信任"}(${from})`,
467
474
  gated: (trusted) => `需要信任的资源${trusted ? "" : "(当前不加载)"}:`,
475
+ extensionsTitle: "本地扩展",
476
+ extensionsNote: "只按文件与信任记录列出;doctor 不执行扩展代码,加载失败在启动时才会出现",
477
+ extensionsNone: "无(用户级 extensions/ 与 profile 的 extensions 都为空)",
478
+ extensionLine: (enabled, path, sha, reason, directory) => `${enabled ? "启用" : "跳过"} ${directory ? "[目录] " : ""}${path} sha256 ${sha}${reason === undefined ? "" : ` (${reason})`}`,
479
+ extensionSha: (sha256) => sha256?.slice(0, 12) ?? "-",
468
480
  keysTitle: "Key 来源(只显示来源,不显示值)",
469
481
  authMode: (mode, path) => `auth.json 权限 ${mode},应为 600:${path}`,
470
482
  none: "无",
@@ -12,12 +12,14 @@
12
12
  * 之后 `buildConfigOptions` 同步取(映射器的 `extras()` 是同步的)。没准备过时只列本地供应商与当前模型。
13
13
  * - `applyConfigOption`:`session/set_config_option` → `setModel()` / `setThinkingLevel()`;未知 id、
14
14
  * 非字符串值、找不到的模型、不认识的级别回 invalid params。
15
- * - `availableCommands`:skills → `skill:<name>`,提示模板 → `<name>`(`argumentHint` → `input.hint`)。
15
+ * - `availableCommands`:skills → `skill:<name>`,提示模板 → `<name>`(`argumentHint` → `input.hint`);
16
+ * [#303] 宿主 / 扩展命令 → `<name>`(`args` → `input.hint`),遮住同名提示模板(与其它模式一致)。
16
17
  * 内置斜杠命令(`/new`、`/compact`…)在 ACP 下不执行,不列。
17
18
  */
18
19
  import type { AgentSession } from "../../agent/types.js";
19
20
  import type { ProviderRegistryApi } from "../../ai/types.js";
20
21
  import type { LoadedResources } from "../../cli/runtime.js";
22
+ import type { HostCommandSource } from "../../host/commands.js";
21
23
  import { type AcpAvailableCommand, type AcpSessionConfigOption, type AcpSetConfigOptionParams } from "../../drivers/acp/types.js";
22
24
  import type { PermissionMode } from "../../permissions/types.js";
23
25
  /** 配置项 id(机器字段,不翻译)。 */
@@ -40,4 +42,4 @@ export interface ConfigOptionsExtras {
40
42
  export declare function buildConfigOptions(session: AgentSession, providers: ProviderRegistryApi, env: NodeJS.ProcessEnv, extras?: ConfigOptionsExtras): AcpSessionConfigOption[];
41
43
  /** 未知 id / value → RpcError invalidParams。 */
42
44
  export declare function applyConfigOption(session: AgentSession, params: AcpSetConfigOptionParams): Promise<void>;
43
- export declare function availableCommands(resources: LoadedResources): AcpAvailableCommand[];
45
+ export declare function availableCommands(resources: LoadedResources, hostCommands?: HostCommandSource): AcpAvailableCommand[];
@@ -12,7 +12,8 @@
12
12
  * 之后 `buildConfigOptions` 同步取(映射器的 `extras()` 是同步的)。没准备过时只列本地供应商与当前模型。
13
13
  * - `applyConfigOption`:`session/set_config_option` → `setModel()` / `setThinkingLevel()`;未知 id、
14
14
  * 非字符串值、找不到的模型、不认识的级别回 invalid params。
15
- * - `availableCommands`:skills → `skill:<name>`,提示模板 → `<name>`(`argumentHint` → `input.hint`)。
15
+ * - `availableCommands`:skills → `skill:<name>`,提示模板 → `<name>`(`argumentHint` → `input.hint`);
16
+ * [#303] 宿主 / 扩展命令 → `<name>`(`args` → `input.hint`),遮住同名提示模板(与其它模式一致)。
16
17
  * 内置斜杠命令(`/new`、`/compact`…)在 ACP 下不执行,不列。
17
18
  */
18
19
  import { formatModelRef } from "../../ai/providers/channels.js";
@@ -136,16 +137,29 @@ export async function applyConfigOption(session, params) {
136
137
  throw new RpcError(RPC_ERRORS.invalidParams, msg().acp.core.unknownConfigOption(String(params.configId)));
137
138
  }
138
139
  }
139
- export function availableCommands(resources) {
140
+ export function availableCommands(resources, hostCommands) {
141
+ const hosted = hostCommands?.list() ?? [];
142
+ const shadowed = new Set(hosted.map((c) => c.name));
140
143
  const commands = resources.skills.map((skill) => ({
141
144
  name: `skill:${skill.name}`,
142
145
  description: skill.description,
143
146
  }));
144
- for (const prompt of resources.prompts)
147
+ for (const prompt of resources.prompts) {
148
+ if (shadowed.has(prompt.name))
149
+ continue;
145
150
  commands.push({
146
151
  name: prompt.name,
147
152
  description: prompt.description ?? "",
148
153
  ...(prompt.argumentHint !== undefined ? { input: { hint: prompt.argumentHint } } : {}),
149
154
  });
155
+ }
156
+ for (const command of hosted)
157
+ commands.push({
158
+ name: command.name,
159
+ description: command.description,
160
+ ...(command.args !== undefined && command.args !== ""
161
+ ? { input: { hint: command.args } }
162
+ : {}),
163
+ });
150
164
  return commands;
151
165
  }
@@ -75,6 +75,8 @@ export declare class AcpEventMapper {
75
75
  * 与 `usage_update`(客户端可能刚重建线程,用量不去重,照发一次)。
76
76
  */
77
77
  announce(): void;
78
+ /** [#303] 扩展命令 handled 的输出:一条 `agent_message_chunk`(不开模型回合)。 */
79
+ emitMessage(text: string): void;
78
80
  /** 回合结束后由服务端调:`session_info_update`(标题与上次不同才带 title)。 */
79
81
  emitSessionInfo(title: string | null, updatedAt: string): void;
80
82
  /** 权限请求对应的工具调用 id(按工具名与参数匹配最近一个;有 `context.toolCallId` 时不需要)。 */
@@ -81,6 +81,10 @@ export class AcpEventMapper {
81
81
  this.emit({ sessionUpdate: "config_option_update", configOptions });
82
82
  this.emitUsage(true);
83
83
  }
84
+ /** [#303] 扩展命令 handled 的输出:一条 `agent_message_chunk`(不开模型回合)。 */
85
+ emitMessage(text) {
86
+ this.emit({ sessionUpdate: "agent_message_chunk", content: { type: "text", text } });
87
+ }
84
88
  /** 回合结束后由服务端调:`session_info_update`(标题与上次不同才带 title)。 */
85
89
  emitSessionInfo(title, updatedAt) {
86
90
  const changed = title !== this.lastTitle;
@@ -32,7 +32,7 @@ import { AcpEventMapper, permissionModes, toolKind, toolLocations, toolTitle, }
32
32
  import { msg } from "../../i18n/index.js";
33
33
  import { CONFIG_IDS, applyConfigOption, availableCommands, buildConfigOptions, prepareConfigOptions, } from "./acp-config.js";
34
34
  import { clientCapabilitiesOf } from "./acp-connection.js";
35
- import { PromptQueue, cancelledResult, disposeQuiet, pageSessions, promptWhenIdle, quiesce, sessionTitle, } from "./acp-sessions.js";
35
+ import { PromptQueue, ZERO_USAGE, dispatchHostSlash, cancelledResult, disposeQuiet, pageSessions, promptWhenIdle, quiesce, sessionTitle, } from "./acp-sessions.js";
36
36
  export const ACP_AGENT_CAPABILITIES = {
37
37
  loadSession: true,
38
38
  promptCapabilities: { image: true, audio: false, embeddedContext: true },
@@ -123,7 +123,7 @@ export class AcpServer {
123
123
  extras(session) {
124
124
  return {
125
125
  configOptions: this.configOptions(session),
126
- commands: availableCommands(this.runtime.resources),
126
+ commands: availableCommands(this.runtime.resources, this.runtime.hostCommands),
127
127
  };
128
128
  }
129
129
  configOptions(session) {
@@ -381,6 +381,10 @@ export class AcpServer {
381
381
  let before = session.getStats().tokens;
382
382
  let failure;
383
383
  try {
384
+ if (await dispatchHostSlash(job, this.runtime, session, entry.mapper)) {
385
+ await this.peer.flush();
386
+ return { stopReason: "end_turn", usage: { ...ZERO_USAGE } };
387
+ }
384
388
  // [#166] 起点取在真正发起时:等待期间结束的通知回合不计入本次 usage
385
389
  await promptWhenIdle(session, job, () => void (before = session.getStats().tokens));
386
390
  }
@@ -8,6 +8,7 @@
8
8
  */
9
9
  import type { ImageBlock } from "../../ai/types.js";
10
10
  import type { AgentSessionImpl } from "../../agent/session.js";
11
+ import type { AgentSession } from "../../agent/types.js";
11
12
  import type { TaskControl } from "../../agents/task-control.js";
12
13
  import type { Runtime } from "../../cli/runtime.js";
13
14
  import type { AgentMessage, SessionListItem } from "../../session/types.js";
@@ -30,7 +31,8 @@ export interface PooledSession {
30
31
  /** 排队或在跑的一次 `session/prompt`。 */
31
32
  export interface PromptJob {
32
33
  readonly sessionId: string;
33
- readonly text: string;
34
+ /** [#303] 扩展命令的 `prompt` 结果会改写它。 */
35
+ text: string;
34
36
  readonly images: ImageBlock[];
35
37
  /** `session/cancel` / `session/close` / `$/cancel_request` 要求中断。 */
36
38
  cancelRequested: boolean;
@@ -100,3 +102,8 @@ export declare function quiesce(session: AgentSessionImpl, control: TaskControl
100
102
  * dispose 之后若还有周期(与 dispose 同一时刻开出来的)再 abort 一次。
101
103
  */
102
104
  export declare function disposeQuiet(runtime: Runtime, session: AgentSessionImpl, fallback: AgentSessionImpl, control?: TaskControl, retries?: number): Promise<void>;
105
+ /**
106
+ * [#303] `/<名> 参数` 命中宿主 / 扩展注册的命令:`handled` 发出 `message`(`agent_message_chunk`)并返回 true,
107
+ * 调用方不开模型回合;`prompt` 改写 `job.text` 并返回 false;没有同名命令返回 false。命令抛错原样上抛。
108
+ */
109
+ export declare function dispatchHostSlash(job: PromptJob, runtime: Pick<Runtime, "hostCommands" | "mode">, session: Pick<AgentSession, "state">, mapper: Pick<AcpEventMapper, "emitMessage">): Promise<boolean>;
@@ -11,6 +11,7 @@ import { RPC_ERRORS, } from "../../drivers/acp/types.js";
11
11
  import { RpcError } from "../../drivers/jsonrpc.js";
12
12
  import { AmaError } from "../../errors.js";
13
13
  import { msg } from "../../i18n/index.js";
14
+ import { parseSlash, runHostSlash } from "../commands-core.js";
14
15
  /** `session/list` 每页条数。 */
15
16
  export const LIST_PAGE_SIZE = 50;
16
17
  /** 列表与 `session_info_update` 的标题上限(字符)。 */
@@ -223,3 +224,20 @@ export async function disposeQuiet(runtime, session, fallback, control, retries
223
224
  }
224
225
  await session.abort();
225
226
  }
227
+ /**
228
+ * [#303] `/<名> 参数` 命中宿主 / 扩展注册的命令:`handled` 发出 `message`(`agent_message_chunk`)并返回 true,
229
+ * 调用方不开模型回合;`prompt` 改写 `job.text` 并返回 false;没有同名命令返回 false。命令抛错原样上抛。
230
+ */
231
+ export async function dispatchHostSlash(job, runtime, session, mapper) {
232
+ const slash = parseSlash(job.text);
233
+ if (slash === undefined)
234
+ return false;
235
+ const hosted = await runHostSlash(slash.name, slash.args, runtime, session);
236
+ if (hosted?.kind === "prompt")
237
+ job.text = hosted.text;
238
+ if (hosted?.kind !== "handled")
239
+ return false;
240
+ if (hosted.message !== undefined && hosted.message !== "")
241
+ mapper.emitMessage(hosted.message);
242
+ return true;
243
+ }