@armadra/agent 0.17.3 → 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 (157) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/CHANGELOG.zh-CN.md +50 -0
  3. package/README.md +4 -0
  4. package/README.zh-CN.md +4 -0
  5. package/THIRD_PARTY_NOTICES.md +6 -0
  6. package/assets/quickjs/LICENSE +57 -0
  7. package/assets/quickjs/README.md +14 -0
  8. package/assets/quickjs/quickjs.wasm +0 -0
  9. package/dist/agent/recovery-reminder.js +6 -1
  10. package/dist/agent/schema-coerce.d.ts +24 -0
  11. package/dist/agent/schema-coerce.js +157 -0
  12. package/dist/agent/schema.d.ts +1 -1
  13. package/dist/agent/schema.js +1 -1
  14. package/dist/agent/session-cache.js +12 -0
  15. package/dist/agent/tool-runner.js +57 -28
  16. package/dist/agent/types.d.ts +4 -0
  17. package/dist/ai/apis/anthropic-compat.d.ts +3 -1
  18. package/dist/ai/apis/anthropic-compat.js +8 -1
  19. package/dist/ai/apis/anthropic-messages.js +54 -2
  20. package/dist/ai/apis/anthropic-request.d.ts +3 -0
  21. package/dist/ai/apis/anthropic-request.js +7 -1
  22. package/dist/ai/apis/anthropic-threads.d.ts +64 -0
  23. package/dist/ai/apis/anthropic-threads.js +192 -0
  24. package/dist/ai/providers/catalog-data.js +5 -5
  25. package/dist/ai/providers/models-dev-data.js +22 -22
  26. package/dist/ai/types.d.ts +16 -0
  27. package/dist/bundle/ama-sandbox.cjs +96 -2
  28. package/dist/bundle/ama.cjs +29964 -27673
  29. package/dist/cli/bootstrap.js +32 -6
  30. package/dist/cli/compose-agents.js +2 -1
  31. package/dist/cli/compose-extensions-load.d.ts +20 -0
  32. package/dist/cli/compose-extensions-load.js +38 -0
  33. package/dist/cli/compose.js +1 -0
  34. package/dist/cli/deps.d.ts +11 -0
  35. package/dist/cli/runtime.d.ts +7 -0
  36. package/dist/cli/subcommands/config.d.ts +3 -0
  37. package/dist/cli/subcommands/config.js +22 -7
  38. package/dist/cli/subcommands/doctor.js +34 -0
  39. package/dist/cli/subcommands/models-discover.js +6 -2
  40. package/dist/codemode/capability.d.ts +14 -2
  41. package/dist/codemode/capability.js +19 -2
  42. package/dist/codemode/host-side.d.ts +14 -0
  43. package/dist/codemode/host-side.js +81 -10
  44. package/dist/codemode/inner-calls.d.ts +19 -0
  45. package/dist/codemode/inner-calls.js +24 -0
  46. package/dist/codemode/protocol.d.ts +14 -0
  47. package/dist/codemode/protocol.js +9 -1
  48. package/dist/codemode/quickjs/host.d.ts +15 -0
  49. package/dist/codemode/quickjs/host.js +243 -0
  50. package/dist/codemode/quickjs/wasm.d.ts +21 -0
  51. package/dist/codemode/quickjs/wasm.js +39 -0
  52. package/dist/codemode/quickjs/worker.d.ts +55 -0
  53. package/dist/codemode/quickjs/worker.js +457 -0
  54. package/dist/codemode/sandbox-entry.d.ts +4 -0
  55. package/dist/codemode/sandbox-entry.js +95 -3
  56. package/dist/codemode/script-images.d.ts +18 -0
  57. package/dist/codemode/script-images.js +38 -0
  58. package/dist/codemode/script-output.d.ts +19 -0
  59. package/dist/codemode/script-output.js +67 -0
  60. package/dist/codemode/search-tools.d.ts +27 -0
  61. package/dist/codemode/search-tools.js +83 -0
  62. package/dist/codemode/tool.d.ts +4 -0
  63. package/dist/codemode/tool.js +60 -9
  64. package/dist/codemode/worker-pool.d.ts +65 -0
  65. package/dist/codemode/worker-pool.js +131 -0
  66. package/dist/config/extension-tree-hash.d.ts +31 -0
  67. package/dist/config/extension-tree-hash.js +88 -0
  68. package/dist/config/extension-trust.d.ts +70 -0
  69. package/dist/config/extension-trust.js +112 -0
  70. package/dist/config/json-schema.js +3 -1
  71. package/dist/config/key-docs.js +7 -1
  72. package/dist/config/profile.d.ts +2 -0
  73. package/dist/config/profile.js +1 -0
  74. package/dist/config/schema-trust.d.ts +7 -0
  75. package/dist/config/schema-trust.js +46 -0
  76. package/dist/config/schema.d.ts +4 -5
  77. package/dist/config/schema.js +7 -27
  78. package/dist/config/settings-registry.js +2 -0
  79. package/dist/config/trust.d.ts +2 -0
  80. package/dist/config/trust.js +5 -1
  81. package/dist/config/types.d.ts +23 -0
  82. package/dist/config/types.js +1 -0
  83. package/dist/drivers/host-runners.d.ts +15 -4
  84. package/dist/drivers/host-runners.js +31 -17
  85. package/dist/errors.d.ts +1 -1
  86. package/dist/host/api-impl.d.ts +47 -4
  87. package/dist/host/api-impl.js +181 -20
  88. package/dist/host/commands.d.ts +23 -0
  89. package/dist/host/commands.js +76 -0
  90. package/dist/host/extensions.d.ts +43 -0
  91. package/dist/host/extensions.js +117 -0
  92. package/dist/host/resources.d.ts +2 -0
  93. package/dist/host/resources.js +5 -0
  94. package/dist/host/types.d.ts +41 -2
  95. package/dist/host/types.js +4 -2
  96. package/dist/i18n/catalog.d.ts +39 -0
  97. package/dist/i18n/messages/cli.d.ts +24 -0
  98. package/dist/i18n/messages/cli.js +24 -0
  99. package/dist/i18n/messages/config-keys.d.ts +4 -0
  100. package/dist/i18n/messages/config-keys.js +6 -2
  101. package/dist/i18n/messages/config.d.ts +4 -0
  102. package/dist/i18n/messages/drivers.d.ts +22 -0
  103. package/dist/i18n/messages/drivers.js +22 -0
  104. package/dist/i18n/messages/errors.d.ts +1 -1
  105. package/dist/i18n/messages/interactive-startup.d.ts +4 -0
  106. package/dist/i18n/messages/interactive-startup.js +4 -0
  107. package/dist/i18n/messages/interactive-view.d.ts +2 -0
  108. package/dist/i18n/messages/interactive-view.js +2 -0
  109. package/dist/i18n/messages/interactive.d.ts +6 -0
  110. package/dist/i18n/messages/report.d.ts +14 -0
  111. package/dist/i18n/messages/report.js +14 -0
  112. package/dist/i18n/messages/subcommands-config.d.ts +8 -0
  113. package/dist/i18n/messages/subcommands-config.js +8 -0
  114. package/dist/i18n/messages/subcommands.d.ts +8 -0
  115. package/dist/modes/acp/acp-config.d.ts +4 -2
  116. package/dist/modes/acp/acp-config.js +17 -3
  117. package/dist/modes/acp/acp-events.d.ts +2 -0
  118. package/dist/modes/acp/acp-events.js +4 -0
  119. package/dist/modes/acp/acp-server.js +6 -2
  120. package/dist/modes/acp/acp-sessions.d.ts +8 -1
  121. package/dist/modes/acp/acp-sessions.js +18 -0
  122. package/dist/modes/commands-core.d.ts +14 -1
  123. package/dist/modes/commands-core.js +34 -2
  124. package/dist/modes/interactive/startup-ui.js +21 -0
  125. package/dist/modes/interactive/status-area.js +1 -1
  126. package/dist/modes/interactive/tool-view.d.ts +8 -2
  127. package/dist/modes/interactive/tool-view.js +12 -5
  128. package/dist/modes/print/print-mode.d.ts +3 -0
  129. package/dist/modes/print/print-mode.js +35 -8
  130. package/dist/modes/rpc/commands.d.ts +2 -0
  131. package/dist/modes/rpc/commands.js +22 -7
  132. package/dist/modes/rpc/rpc-mode.js +3 -0
  133. package/dist/modes/startup-ui-text.js +11 -0
  134. package/dist/rpc.d.ts +2 -1
  135. package/dist/session/unclean-end.d.ts +8 -0
  136. package/dist/session/unclean-end.js +39 -7
  137. package/dist/tools/registry.d.ts +6 -0
  138. package/dist/tools/registry.js +13 -0
  139. package/dist/tools/types.d.ts +7 -0
  140. package/docs/README.md +1 -1
  141. package/docs/en/README.md +3 -3
  142. package/docs/en/guides/extensions.md +141 -0
  143. package/docs/en/guides/providers.md +27 -7
  144. package/docs/en/guides/tui.md +1 -1
  145. package/docs/en/reference/acp.md +1 -1
  146. package/docs/en/reference/host-api.md +55 -27
  147. package/docs/en/reference/rpc.md +12 -8
  148. package/docs/guides/codemode.md +52 -12
  149. package/docs/guides/extensions.md +136 -0
  150. package/docs/guides/providers.md +21 -1
  151. package/docs/guides/sandbox.md +2 -0
  152. package/docs/guides/tui.md +1 -1
  153. package/docs/reference/acp.md +1 -1
  154. package/docs/reference/host-api.md +55 -27
  155. package/docs/reference/rpc.md +12 -8
  156. package/docs/reference/session-format.md +10 -9
  157. package/package.json +5 -2
@@ -0,0 +1,43 @@
1
+ /**
2
+ * 本地扩展(#301,docs/guides/extensions.md):用户自己安装、可以有多个的宿主适配器。
3
+ *
4
+ * - 发现:`<configDir>/extensions/` 下的 `*.{mjs,cjs}` 与带 `index.{mjs,cjs}` 的子目录(#305)按入口名排序,
5
+ * 其后是 profile `extensions`(绝对路径,可以是目录);
6
+ * 不加载项目级。
7
+ * - 激活:每个模块一个独立的 {@link HostApiBinding},共享工具注册表、事件总线、broker 槽、资源注册表与
8
+ * 保温处理器(共享状态见 api-impl 的 `HostContext`);任何失败(加载、版本不等、create 抛错或超时、
9
+ * 没有返回适配器)撤回该模块已注册的全部内容(#304)、只产生 warning 并跳过,不阻止启动(宿主适配器的失败规则不变)。
10
+ * - 释放:按加载的逆序 dispose,失败只回调 onError。
11
+ */
12
+ import type { HostApiBinding } from "./api-impl.js";
13
+ import type { HostAdapterHandle } from "./types.js";
14
+ export declare const EXTENSIONS_DIR = "extensions";
15
+ /** 目录扩展的入口:`index.mjs`,其次 `index.cjs`;都没有时返回 `index.mjs`(加载时报「找不到」)。 */
16
+ export declare function resolveExtensionEntry(path: string): string;
17
+ /**
18
+ * 用户级目录里的扩展(#305 起含目录):单文件 `*.{mjs,cjs}` 与带 `index.{mjs,cjs}` 的子目录,
19
+ * 按入口名(文件名或目录名)一起排序。目录不存在 → 空。
20
+ */
21
+ export declare function discoverExtensionDir(configDir: string): string[];
22
+ /** 加载顺序:用户级目录(按文件名),其后 profile `extensions`;同一路径只算一次。 */
23
+ export declare function discoverExtensions(configDir: string, profileExtensions?: readonly string[]): string[];
24
+ export interface ExtensionSkip {
25
+ path: string;
26
+ reason: string;
27
+ }
28
+ export interface ActivateExtensionsInput {
29
+ /** 要加载的文件(已经过信任决定)。 */
30
+ paths: readonly string[];
31
+ /** 每个模块一个新 binding(共享同一个 HostContext)。 */
32
+ createBinding(): HostApiBinding;
33
+ warn(message: string): void;
34
+ timeoutMs?: number;
35
+ }
36
+ export interface ActivatedExtensions {
37
+ handles: HostAdapterHandle[];
38
+ skipped: ExtensionSkip[];
39
+ }
40
+ /** 逐个激活;失败的只记 warning。 */
41
+ export declare function activateExtensions(input: ActivateExtensionsInput): Promise<ActivatedExtensions>;
42
+ /** 逆序 dispose(每个失败只回调 onError,不影响其余)。 */
43
+ export declare function disposeExtensions(handles: readonly HostAdapterHandle[], onError?: (handle: HostAdapterHandle, error: unknown) => void): Promise<void>;
@@ -0,0 +1,117 @@
1
+ /**
2
+ * 本地扩展(#301,docs/guides/extensions.md):用户自己安装、可以有多个的宿主适配器。
3
+ *
4
+ * - 发现:`<configDir>/extensions/` 下的 `*.{mjs,cjs}` 与带 `index.{mjs,cjs}` 的子目录(#305)按入口名排序,
5
+ * 其后是 profile `extensions`(绝对路径,可以是目录);
6
+ * 不加载项目级。
7
+ * - 激活:每个模块一个独立的 {@link HostApiBinding},共享工具注册表、事件总线、broker 槽、资源注册表与
8
+ * 保温处理器(共享状态见 api-impl 的 `HostContext`);任何失败(加载、版本不等、create 抛错或超时、
9
+ * 没有返回适配器)撤回该模块已注册的全部内容(#304)、只产生 warning 并跳过,不阻止启动(宿主适配器的失败规则不变)。
10
+ * - 释放:按加载的逆序 dispose,失败只回调 onError。
11
+ */
12
+ import { existsSync, readdirSync, statSync } from "node:fs";
13
+ import { join, resolve } from "node:path";
14
+ import { StartupError } from "../errors.js";
15
+ import { msg } from "../i18n/index.js";
16
+ import { createAdapter, disposeHost, loadHostModule } from "./loader.js";
17
+ export const EXTENSIONS_DIR = "extensions";
18
+ const ENTRY_NAMES = ["index.mjs", "index.cjs"];
19
+ function isDir(path) {
20
+ try {
21
+ return statSync(path).isDirectory();
22
+ }
23
+ catch {
24
+ return false;
25
+ }
26
+ }
27
+ /** 目录扩展的入口:`index.mjs`,其次 `index.cjs`;都没有时返回 `index.mjs`(加载时报「找不到」)。 */
28
+ export function resolveExtensionEntry(path) {
29
+ if (!isDir(path))
30
+ return path;
31
+ return join(path, ENTRY_NAMES.find((n) => existsSync(join(path, n))) ?? "index.mjs");
32
+ }
33
+ /**
34
+ * 用户级目录里的扩展(#305 起含目录):单文件 `*.{mjs,cjs}` 与带 `index.{mjs,cjs}` 的子目录,
35
+ * 按入口名(文件名或目录名)一起排序。目录不存在 → 空。
36
+ */
37
+ export function discoverExtensionDir(configDir) {
38
+ const dir = join(configDir, EXTENSIONS_DIR);
39
+ if (!existsSync(dir))
40
+ return [];
41
+ let entries;
42
+ try {
43
+ entries = readdirSync(dir, { withFileTypes: true }).map((e) => ({
44
+ name: e.name,
45
+ // 常规文件与符号链接都先当文件看(链接指向目录时下面再按目录处理)
46
+ file: e.isFile() || e.isSymbolicLink(),
47
+ }));
48
+ }
49
+ catch {
50
+ return [];
51
+ }
52
+ const found = [];
53
+ for (const { name, file } of entries) {
54
+ const full = join(dir, name);
55
+ if (isDir(full)) {
56
+ if (ENTRY_NAMES.some((n) => existsSync(join(full, n))))
57
+ found.push(name);
58
+ }
59
+ else if (file && /\.(mjs|cjs)$/i.test(name)) {
60
+ found.push(name);
61
+ }
62
+ }
63
+ return found.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0)).map((name) => join(dir, name));
64
+ }
65
+ /** 加载顺序:用户级目录(按文件名),其后 profile `extensions`;同一路径只算一次。 */
66
+ export function discoverExtensions(configDir, profileExtensions = []) {
67
+ const seen = new Set();
68
+ const result = [];
69
+ for (const path of [
70
+ ...discoverExtensionDir(configDir),
71
+ ...profileExtensions.map((p) => resolve(p)),
72
+ ]) {
73
+ if (seen.has(path))
74
+ continue;
75
+ seen.add(path);
76
+ result.push(path);
77
+ }
78
+ return result;
79
+ }
80
+ function errorText(error) {
81
+ return error instanceof Error ? error.message : String(error);
82
+ }
83
+ /** 逐个激活;失败的只记 warning。 */
84
+ export async function activateExtensions(input) {
85
+ const handles = [];
86
+ const skipped = [];
87
+ const skip = (path, reason) => {
88
+ skipped.push({ path, reason });
89
+ input.warn(msg().cli.bootstrap.extensionSkipped(path, reason));
90
+ };
91
+ for (const path of input.paths) {
92
+ // [#304] 失败(抛错 / 超时 / 未返回适配器)一律撤回它已注册的内容;之后迟到的注册被忽略
93
+ let binding;
94
+ try {
95
+ const module = await loadHostModule(resolveExtensionEntry(path));
96
+ binding = input.createBinding();
97
+ const adapter = await createAdapter(module, binding.api, path, input.timeoutMs);
98
+ if (adapter === undefined) {
99
+ binding.revoke();
100
+ skip(path, msg().cli.bootstrap.extensionNotActivated);
101
+ continue;
102
+ }
103
+ handles.push(binding.handle(adapter, path));
104
+ }
105
+ catch (error) {
106
+ binding?.revoke();
107
+ skip(path, error instanceof StartupError ? error.message : errorText(error));
108
+ }
109
+ }
110
+ return { handles, skipped };
111
+ }
112
+ /** 逆序 dispose(每个失败只回调 onError,不影响其余)。 */
113
+ export async function disposeExtensions(handles, onError = () => undefined) {
114
+ for (const handle of [...handles].reverse()) {
115
+ await disposeHost(handle, (error) => onError(handle, error));
116
+ }
117
+ }
@@ -12,6 +12,8 @@ export declare class HostResourceRegistry implements HostResourceLookup {
12
12
  private readonly entries;
13
13
  private frozen;
14
14
  register(resource: HostResource): void;
15
+ /** [#304] 撤回:移除 scheme(激活失败的扩展用,不受冻结限制)。 */
16
+ remove(scheme: string, resource: HostResource): void;
15
17
  /** 宿主激活后调用:之后不再接受注册。 */
16
18
  freeze(): void;
17
19
  get isFrozen(): boolean;
@@ -40,6 +40,11 @@ export class HostResourceRegistry {
40
40
  }
41
41
  this.entries.set(scheme, resource);
42
42
  }
43
+ /** [#304] 撤回:移除 scheme(激活失败的扩展用,不受冻结限制)。 */
44
+ remove(scheme, resource) {
45
+ if (this.entries.get(scheme) === resource)
46
+ this.entries.delete(scheme);
47
+ }
43
48
  /** 宿主激活后调用:之后不再接受注册。 */
44
49
  freeze() {
45
50
  this.frozen = true;
@@ -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;
@@ -427,6 +439,10 @@ declare const en: {
427
439
  sandboxIsolated: (node: number) => string;
428
440
  sandboxOs: (node: number, kind: string) => string;
429
441
  sandboxNone: (node: number) => string;
442
+ sandboxQuickjs: (node: number) => string;
443
+ engineExplicit: (engine: string) => string;
444
+ engineAutoNode: (sandbox: string) => string;
445
+ engineAutoQuickjs: (node: number) => string;
430
446
  codemodeExplicit: (sandbox: string) => string;
431
447
  codemodeFollowsPreset: (preset: string, sandbox: string) => string;
432
448
  presetAlias: (layer: string, label: string, preset: string, canonical: string) => string;
@@ -645,6 +661,7 @@ declare const en: {
645
661
  fetched: (title: string | undefined, size: string, format: string) => string;
646
662
  fetchRedirect: (url: string) => string;
647
663
  awaiting: (glyph: string) => string;
664
+ coerced: string;
648
665
  subagentRunning: (elapsed: string) => string;
649
666
  running: (elapsed: string) => string;
650
667
  moreLines: (ellipsis: string, n: number) => string;
@@ -679,6 +696,8 @@ declare const en: {
679
696
  trustNever: string;
680
697
  moreResources: (n: number) => string;
681
698
  trustTitle: string;
699
+ extensionsTitle: string;
700
+ extensionDirectory: string;
682
701
  resumeTitle: string;
683
702
  modelTitle: string;
684
703
  cwdTitle: string;
@@ -1152,6 +1171,7 @@ declare const en: {
1152
1171
  more: (count: number) => string;
1153
1172
  trustQuestion: (cwd: string) => string;
1154
1173
  trustChoices: string;
1174
+ extensionsQuestion: string;
1155
1175
  resumeQuestion: string;
1156
1176
  resumeAnswer: string;
1157
1177
  pickModel: string;
@@ -1279,6 +1299,7 @@ declare const en: {
1279
1299
  keySource: (source: string, origin: string | undefined) => string;
1280
1300
  hookCommand: (command: string, ms: number) => string;
1281
1301
  codemode: (mode: string, reason: string) => string;
1302
+ codemodeEngine: (engine: string, reason: string) => string;
1282
1303
  warning: (text: string) => string;
1283
1304
  trustTitle: string;
1284
1305
  fromCli: string;
@@ -1286,6 +1307,11 @@ declare const en: {
1286
1307
  trustInvalid: string;
1287
1308
  trust: (cwd: string, trusted: boolean, from: string) => string;
1288
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;
1289
1315
  keysTitle: string;
1290
1316
  authMode: (mode: string, path: string) => string;
1291
1317
  none: string;
@@ -1392,7 +1418,9 @@ declare const en: {
1392
1418
  "codemode.mode": string;
1393
1419
  "codemode.inlineBudget": string;
1394
1420
  "codemode.requireStrict": string;
1421
+ "codemode.maxWorkers": string;
1395
1422
  "codemode.maxHeapMb": string;
1423
+ "codemode.engine": string;
1396
1424
  hooks: string;
1397
1425
  "hooks.timeoutMs": string;
1398
1426
  ui: string;
@@ -1662,9 +1690,20 @@ declare const en: {
1662
1690
  instructionNeedsPath: string;
1663
1691
  instructionNeedsText: string;
1664
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;
1665
1702
  warmingNeedsFunction: string;
1666
1703
  runnerNeedsIdStart: string;
1667
1704
  runnerDoneNeedsFunction: string;
1705
+ runnerExists: (id: string) => string;
1706
+ revokedIgnored: (what: string) => string;
1668
1707
  resourceFrozen: string;
1669
1708
  resourceNotObject: string;
1670
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",
@@ -45,7 +45,9 @@ export declare const en: {
45
45
  "codemode.mode": string;
46
46
  "codemode.inlineBudget": string;
47
47
  "codemode.requireStrict": string;
48
+ "codemode.maxWorkers": string;
48
49
  "codemode.maxHeapMb": string;
50
+ "codemode.engine": string;
49
51
  hooks: string;
50
52
  "hooks.timeoutMs": string;
51
53
  ui: string;
@@ -204,7 +206,9 @@ export declare const zh: {
204
206
  "codemode.mode": string;
205
207
  "codemode.inlineBudget": string;
206
208
  "codemode.requireStrict": string;
209
+ "codemode.maxWorkers": string;
207
210
  "codemode.maxHeapMb": string;
211
+ "codemode.engine": string;
208
212
  hooks: string;
209
213
  "hooks.timeoutMs": string;
210
214
  ui: string;
@@ -96,7 +96,9 @@ const keysEn = {
96
96
  "codemode.mode": "off | on | only; when unset it follows the preset: default → on (Node ≥ 25; Node 22 / 24 → off), codemode-only → only, minimal / coordinator → off; project level only accepts off",
97
97
  "codemode.inlineBudget": "Budget (estimated tokens) for inlining tool declarations in the description in only mode; beyond it only names are listed",
98
98
  "codemode.requireStrict": "true: disable codemode when the runtime Node does not isolate the network (Node 22 / 24)",
99
- "codemode.maxHeapMb": "V8 heap limit (MB) for the script child process; a script that exceeds it ends with an error; 0 sets no limit",
99
+ "codemode.maxWorkers": "Most script child processes alive at once across all sessions in this process (default 2); the AMA_CODEMODE_MAX_WORKERS environment variable takes precedence",
100
+ "codemode.maxHeapMb": "Memory limit (MB) for the script engine (V8 heap of the node child process, QuickJS heap of the quickjs engine); a script that exceeds it ends with an error; 0 sets no limit",
101
+ "codemode.engine": "auto | node | quickjs; auto uses the Node child process when the network is isolated (Node ≥ 25 or an OS sandbox) and QuickJS in WebAssembly otherwise; quickjs makes codemode a read-class tool on every platform; user level only",
100
102
  hooks: "Hook settings (the hooks themselves live in hooks.json)",
101
103
  "hooks.timeoutMs": "Default timeout for a single hook command (ms)",
102
104
  ui: "Terminal interface",
@@ -228,7 +230,9 @@ const keysZh = {
228
230
  "codemode.mode": "off | on | only;不写时跟随预设:default → on(Node ≥ 25;Node 22 / 24 → off)、codemode-only → only、minimal / coordinator → off;项目级只接受 off",
229
231
  "codemode.inlineBudget": "only 模式在描述里内联工具声明的预算(估算 token),超出只列名字",
230
232
  "codemode.requireStrict": "true:运行时 Node 不隔离网络(Node 22 / 24)时直接禁用 codemode",
231
- "codemode.maxHeapMb": "脚本子进程的 V8 堆上限(MB),超出时脚本以错误结束;0 不设上限",
233
+ "codemode.maxWorkers": "本进程内所有会话同时存活的脚本子进程数上限(缺省 2);环境变量 AMA_CODEMODE_MAX_WORKERS 优先",
234
+ "codemode.maxHeapMb": "脚本引擎的内存上限(MB):node 引擎是子进程的 V8 堆,quickjs 引擎是 QuickJS 堆;超出时脚本以错误结束;0 不设上限",
235
+ "codemode.engine": "auto | node | quickjs;auto:网络已隔离(Node ≥ 25 或操作系统沙箱)时用 Node 子进程,否则用 WebAssembly 里的 QuickJS;quickjs 让 codemode 在所有平台都是 read 类;只认用户级",
232
236
  hooks: "Hook 设置(Hook 本身写在 hooks.json)",
233
237
  "hooks.timeoutMs": "单个 Hook 命令的缺省超时(毫秒)",
234
238
  ui: "终端界面",
@@ -45,7 +45,9 @@ export declare const en: {
45
45
  "codemode.mode": string;
46
46
  "codemode.inlineBudget": string;
47
47
  "codemode.requireStrict": string;
48
+ "codemode.maxWorkers": string;
48
49
  "codemode.maxHeapMb": string;
50
+ "codemode.engine": string;
49
51
  hooks: string;
50
52
  "hooks.timeoutMs": string;
51
53
  ui: string;
@@ -318,7 +320,9 @@ export declare const zh: {
318
320
  "codemode.mode": string;
319
321
  "codemode.inlineBudget": string;
320
322
  "codemode.requireStrict": string;
323
+ "codemode.maxWorkers": string;
321
324
  "codemode.maxHeapMb": string;
325
+ "codemode.engine": string;
322
326
  hooks: string;
323
327
  "hooks.timeoutMs": string;
324
328
  ui: string;
@@ -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: "会话的工作目录不存在",