@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.
- package/CHANGELOG.md +50 -0
- package/CHANGELOG.zh-CN.md +50 -0
- package/README.md +4 -0
- package/README.zh-CN.md +4 -0
- package/THIRD_PARTY_NOTICES.md +6 -0
- package/assets/quickjs/LICENSE +57 -0
- package/assets/quickjs/README.md +14 -0
- package/assets/quickjs/quickjs.wasm +0 -0
- package/dist/agent/recovery-reminder.js +6 -1
- package/dist/agent/schema-coerce.d.ts +24 -0
- package/dist/agent/schema-coerce.js +157 -0
- package/dist/agent/schema.d.ts +1 -1
- package/dist/agent/schema.js +1 -1
- package/dist/agent/session-cache.js +12 -0
- package/dist/agent/tool-runner.js +57 -28
- package/dist/agent/types.d.ts +4 -0
- package/dist/ai/apis/anthropic-compat.d.ts +3 -1
- package/dist/ai/apis/anthropic-compat.js +8 -1
- package/dist/ai/apis/anthropic-messages.js +54 -2
- package/dist/ai/apis/anthropic-request.d.ts +3 -0
- package/dist/ai/apis/anthropic-request.js +7 -1
- package/dist/ai/apis/anthropic-threads.d.ts +64 -0
- package/dist/ai/apis/anthropic-threads.js +192 -0
- package/dist/ai/providers/catalog-data.js +5 -5
- package/dist/ai/providers/models-dev-data.js +22 -22
- package/dist/ai/types.d.ts +16 -0
- package/dist/bundle/ama-sandbox.cjs +96 -2
- package/dist/bundle/ama.cjs +29964 -27673
- package/dist/cli/bootstrap.js +32 -6
- package/dist/cli/compose-agents.js +2 -1
- package/dist/cli/compose-extensions-load.d.ts +20 -0
- package/dist/cli/compose-extensions-load.js +38 -0
- package/dist/cli/compose.js +1 -0
- package/dist/cli/deps.d.ts +11 -0
- package/dist/cli/runtime.d.ts +7 -0
- package/dist/cli/subcommands/config.d.ts +3 -0
- package/dist/cli/subcommands/config.js +22 -7
- package/dist/cli/subcommands/doctor.js +34 -0
- package/dist/cli/subcommands/models-discover.js +6 -2
- package/dist/codemode/capability.d.ts +14 -2
- package/dist/codemode/capability.js +19 -2
- package/dist/codemode/host-side.d.ts +14 -0
- package/dist/codemode/host-side.js +81 -10
- package/dist/codemode/inner-calls.d.ts +19 -0
- package/dist/codemode/inner-calls.js +24 -0
- package/dist/codemode/protocol.d.ts +14 -0
- package/dist/codemode/protocol.js +9 -1
- package/dist/codemode/quickjs/host.d.ts +15 -0
- package/dist/codemode/quickjs/host.js +243 -0
- package/dist/codemode/quickjs/wasm.d.ts +21 -0
- package/dist/codemode/quickjs/wasm.js +39 -0
- package/dist/codemode/quickjs/worker.d.ts +55 -0
- package/dist/codemode/quickjs/worker.js +457 -0
- package/dist/codemode/sandbox-entry.d.ts +4 -0
- package/dist/codemode/sandbox-entry.js +95 -3
- package/dist/codemode/script-images.d.ts +18 -0
- package/dist/codemode/script-images.js +38 -0
- package/dist/codemode/script-output.d.ts +19 -0
- package/dist/codemode/script-output.js +67 -0
- package/dist/codemode/search-tools.d.ts +27 -0
- package/dist/codemode/search-tools.js +83 -0
- package/dist/codemode/tool.d.ts +4 -0
- package/dist/codemode/tool.js +60 -9
- package/dist/codemode/worker-pool.d.ts +65 -0
- package/dist/codemode/worker-pool.js +131 -0
- package/dist/config/extension-tree-hash.d.ts +31 -0
- package/dist/config/extension-tree-hash.js +88 -0
- package/dist/config/extension-trust.d.ts +70 -0
- package/dist/config/extension-trust.js +112 -0
- package/dist/config/json-schema.js +3 -1
- package/dist/config/key-docs.js +7 -1
- package/dist/config/profile.d.ts +2 -0
- package/dist/config/profile.js +1 -0
- package/dist/config/schema-trust.d.ts +7 -0
- package/dist/config/schema-trust.js +46 -0
- package/dist/config/schema.d.ts +4 -5
- package/dist/config/schema.js +7 -27
- package/dist/config/settings-registry.js +2 -0
- package/dist/config/trust.d.ts +2 -0
- package/dist/config/trust.js +5 -1
- package/dist/config/types.d.ts +23 -0
- package/dist/config/types.js +1 -0
- package/dist/drivers/host-runners.d.ts +15 -4
- package/dist/drivers/host-runners.js +31 -17
- package/dist/errors.d.ts +1 -1
- package/dist/host/api-impl.d.ts +47 -4
- package/dist/host/api-impl.js +181 -20
- package/dist/host/commands.d.ts +23 -0
- package/dist/host/commands.js +76 -0
- package/dist/host/extensions.d.ts +43 -0
- package/dist/host/extensions.js +117 -0
- package/dist/host/resources.d.ts +2 -0
- package/dist/host/resources.js +5 -0
- package/dist/host/types.d.ts +41 -2
- package/dist/host/types.js +4 -2
- package/dist/i18n/catalog.d.ts +39 -0
- package/dist/i18n/messages/cli.d.ts +24 -0
- package/dist/i18n/messages/cli.js +24 -0
- package/dist/i18n/messages/config-keys.d.ts +4 -0
- package/dist/i18n/messages/config-keys.js +6 -2
- package/dist/i18n/messages/config.d.ts +4 -0
- package/dist/i18n/messages/drivers.d.ts +22 -0
- package/dist/i18n/messages/drivers.js +22 -0
- package/dist/i18n/messages/errors.d.ts +1 -1
- package/dist/i18n/messages/interactive-startup.d.ts +4 -0
- package/dist/i18n/messages/interactive-startup.js +4 -0
- package/dist/i18n/messages/interactive-view.d.ts +2 -0
- package/dist/i18n/messages/interactive-view.js +2 -0
- package/dist/i18n/messages/interactive.d.ts +6 -0
- package/dist/i18n/messages/report.d.ts +14 -0
- package/dist/i18n/messages/report.js +14 -0
- package/dist/i18n/messages/subcommands-config.d.ts +8 -0
- package/dist/i18n/messages/subcommands-config.js +8 -0
- package/dist/i18n/messages/subcommands.d.ts +8 -0
- package/dist/modes/acp/acp-config.d.ts +4 -2
- package/dist/modes/acp/acp-config.js +17 -3
- package/dist/modes/acp/acp-events.d.ts +2 -0
- package/dist/modes/acp/acp-events.js +4 -0
- package/dist/modes/acp/acp-server.js +6 -2
- package/dist/modes/acp/acp-sessions.d.ts +8 -1
- package/dist/modes/acp/acp-sessions.js +18 -0
- package/dist/modes/commands-core.d.ts +14 -1
- package/dist/modes/commands-core.js +34 -2
- package/dist/modes/interactive/startup-ui.js +21 -0
- package/dist/modes/interactive/status-area.js +1 -1
- package/dist/modes/interactive/tool-view.d.ts +8 -2
- package/dist/modes/interactive/tool-view.js +12 -5
- package/dist/modes/print/print-mode.d.ts +3 -0
- package/dist/modes/print/print-mode.js +35 -8
- package/dist/modes/rpc/commands.d.ts +2 -0
- package/dist/modes/rpc/commands.js +22 -7
- package/dist/modes/rpc/rpc-mode.js +3 -0
- package/dist/modes/startup-ui-text.js +11 -0
- package/dist/rpc.d.ts +2 -1
- package/dist/session/unclean-end.d.ts +8 -0
- package/dist/session/unclean-end.js +39 -7
- package/dist/tools/registry.d.ts +6 -0
- package/dist/tools/registry.js +13 -0
- package/dist/tools/types.d.ts +7 -0
- package/docs/README.md +1 -1
- package/docs/en/README.md +3 -3
- package/docs/en/guides/extensions.md +141 -0
- package/docs/en/guides/providers.md +27 -7
- package/docs/en/guides/tui.md +1 -1
- package/docs/en/reference/acp.md +1 -1
- package/docs/en/reference/host-api.md +55 -27
- package/docs/en/reference/rpc.md +12 -8
- package/docs/guides/codemode.md +52 -12
- package/docs/guides/extensions.md +136 -0
- package/docs/guides/providers.md +21 -1
- package/docs/guides/sandbox.md +2 -0
- package/docs/guides/tui.md +1 -1
- package/docs/reference/acp.md +1 -1
- package/docs/reference/host-api.md +55 -27
- package/docs/reference/rpc.md +12 -8
- package/docs/reference/session-format.md +10 -9
- package/package.json +5 -2
package/dist/cli/bootstrap.js
CHANGED
|
@@ -17,17 +17,20 @@ import { decideTrust } from "../config/trust.js";
|
|
|
17
17
|
import { AmaError, StartupError, isAmaError } from "../errors.js";
|
|
18
18
|
import { loadHookConfigs } from "../hooks/config.js";
|
|
19
19
|
import { HookDispatcher } from "../hooks/dispatcher.js";
|
|
20
|
-
import { AgentEventBus, createHostApi } from "../host/api-impl.js";
|
|
20
|
+
import { AgentEventBus, createHostApi, createHostContext, mergedHostStatus, } from "../host/api-impl.js";
|
|
21
|
+
import { disposeExtensions } from "../host/extensions.js";
|
|
21
22
|
import { activateHost, disposeHost } from "../host/loader.js";
|
|
22
23
|
import { HostResourceRegistry } from "../host/resources.js";
|
|
23
24
|
import { normalizeResourceRef } from "../tools/resource-ref.js";
|
|
24
25
|
import { helpText, parseArgs, UsageError } from "./args.js";
|
|
25
26
|
import { hostSessionStart } from "./compose-events.js";
|
|
27
|
+
import { loadExtensions } from "./compose-extensions-load.js";
|
|
26
28
|
import { applyFromOption } from "./from-prompt.js";
|
|
27
29
|
import { ExitCode } from "./exit-codes.js";
|
|
28
30
|
import { applyProfile, applyToolFilters, decideMode, defaultSendUser, instructionSources, resolveModel, sessionRequestOf, sourceOf, step, thinkingOf, toStartupError, } from "./startup-steps.js";
|
|
29
31
|
import { resolveSystemPromptArg } from "./system-prompt-arg.js";
|
|
30
32
|
import { memoryEnvOverride, resolveMemory } from "./compose-memory.js";
|
|
33
|
+
import { isReservedCommandName } from "../modes/commands-core.js";
|
|
31
34
|
import { msg, resolveLocale, setLocale } from "../i18n/index.js";
|
|
32
35
|
/** §11.1 第 3–14 步。 */
|
|
33
36
|
export async function bootstrap(argsIn, deps, io) {
|
|
@@ -201,7 +204,8 @@ export async function bootstrap(argsIn, deps, io) {
|
|
|
201
204
|
if (level === "warn" || level === "error")
|
|
202
205
|
warn(m().eventWarning(message, detail instanceof Error ? detail.message : undefined));
|
|
203
206
|
});
|
|
204
|
-
const
|
|
207
|
+
const hostContext = createHostContext({ reservedCommand: isReservedCommandName });
|
|
208
|
+
const hostDeps = {
|
|
205
209
|
mode,
|
|
206
210
|
env: io.env,
|
|
207
211
|
session: {
|
|
@@ -219,14 +223,31 @@ export async function bootstrap(argsIn, deps, io) {
|
|
|
219
223
|
},
|
|
220
224
|
stderr: io.stderr,
|
|
221
225
|
resources: hostResources,
|
|
222
|
-
}
|
|
226
|
+
};
|
|
227
|
+
const binding = createHostApi(hostDeps, hostContext);
|
|
223
228
|
let uiBroker;
|
|
224
229
|
const hostSpec = args.host;
|
|
225
230
|
let host;
|
|
226
231
|
if (hostSpec !== undefined) {
|
|
227
232
|
host = await step(ExitCode.HostOrHook, m().steps.host, () => activateHost({ module: hostSpec, binding, cwd: io.cwd }));
|
|
228
233
|
}
|
|
234
|
+
// [#301] 本地扩展:宿主适配器之后、组装会话之前;失败只 warning
|
|
235
|
+
const extensions = await loadExtensions({
|
|
236
|
+
configDir: paths.configDir,
|
|
237
|
+
profileExtensions: profile?.extensions ?? [],
|
|
238
|
+
deps: hostDeps,
|
|
239
|
+
context: hostContext,
|
|
240
|
+
noTrust: args.trust === false,
|
|
241
|
+
interactive,
|
|
242
|
+
prompt: deps.ui?.promptExtensions,
|
|
243
|
+
warn,
|
|
244
|
+
});
|
|
229
245
|
hostResources.freeze();
|
|
246
|
+
// 扩展按加载逆序先 dispose,宿主适配器最后(各自失败只 warning)
|
|
247
|
+
const disposeAll = async () => {
|
|
248
|
+
await disposeExtensions(extensions, (h, e) => warn(m().extensionDisposeFailed(h.source, String(e))));
|
|
249
|
+
await disposeHost(host, (e) => warn(m().hostDisposeFailed(String(e))));
|
|
250
|
+
};
|
|
230
251
|
let shutdown;
|
|
231
252
|
try {
|
|
232
253
|
applyToolFilters(args, tools);
|
|
@@ -287,9 +308,11 @@ export async function bootstrap(argsIn, deps, io) {
|
|
|
287
308
|
host: {
|
|
288
309
|
handle: host,
|
|
289
310
|
broker: binding.broker,
|
|
290
|
-
instructions:
|
|
311
|
+
instructions: hostContext.instructions,
|
|
312
|
+
extensions,
|
|
291
313
|
warmingDecider: binding.warmingDecider,
|
|
292
314
|
resources: hostResources.list(),
|
|
315
|
+
runners: hostContext.runners,
|
|
293
316
|
},
|
|
294
317
|
uiBroker: () => uiBroker,
|
|
295
318
|
onSessionReplaced: (next) => {
|
|
@@ -323,7 +346,7 @@ export async function bootstrap(argsIn, deps, io) {
|
|
|
323
346
|
disposed ??= (async () => {
|
|
324
347
|
await events.emit("session_shutdown", {});
|
|
325
348
|
await hooks.run("SessionEnd", { reason }).catch(() => undefined);
|
|
326
|
-
await
|
|
349
|
+
await disposeAll();
|
|
327
350
|
// 会话被替换过时 dispose 当前那个(旧会话由替换方负责)
|
|
328
351
|
await session?.dispose();
|
|
329
352
|
})();
|
|
@@ -358,6 +381,9 @@ export async function bootstrap(argsIn, deps, io) {
|
|
|
358
381
|
},
|
|
359
382
|
hooks,
|
|
360
383
|
host,
|
|
384
|
+
extensions,
|
|
385
|
+
hostCommands: hostContext.commands,
|
|
386
|
+
hostStatus: () => mergedHostStatus(hostContext),
|
|
361
387
|
permission,
|
|
362
388
|
tools,
|
|
363
389
|
approvals: {
|
|
@@ -374,7 +400,7 @@ export async function bootstrap(argsIn, deps, io) {
|
|
|
374
400
|
if (shutdown !== undefined)
|
|
375
401
|
await shutdown("exit").catch(() => undefined);
|
|
376
402
|
else
|
|
377
|
-
await
|
|
403
|
+
await disposeAll();
|
|
378
404
|
throw toStartupError(error, ExitCode.RuntimeError, m().steps.startup);
|
|
379
405
|
}
|
|
380
406
|
}
|
|
@@ -79,7 +79,8 @@ export function subagentEnvironment(deps, catalog) {
|
|
|
79
79
|
export function externalWiring(deps) {
|
|
80
80
|
const { assembly } = deps;
|
|
81
81
|
const api = assembly.host.handle?.api;
|
|
82
|
-
|
|
82
|
+
// [#306] 共享注册表(宿主适配器与扩展);`hosted` 仍只看宿主适配器
|
|
83
|
+
const hostRunners = assembly.host.runners ?? (api === undefined ? undefined : hostRunnersOf(api));
|
|
83
84
|
const config = assembly.config;
|
|
84
85
|
const wiring = {
|
|
85
86
|
env: deps.env,
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 启动第 13 步的扩展部分(#301):发现 → 按哈希信任决定 → 激活(失败只 warning)。宿主适配器先于它激活,
|
|
3
|
+
* 资源注册表在它之后冻结。
|
|
4
|
+
*/
|
|
5
|
+
import { type ExtensionPromptFile } from "../config/extension-trust.js";
|
|
6
|
+
import type { TrustPromptAnswer } from "../config/trust.js";
|
|
7
|
+
import { type HostApiDeps, type HostContext } from "../host/api-impl.js";
|
|
8
|
+
import type { HostAdapterHandle } from "../host/types.js";
|
|
9
|
+
export interface LoadExtensionsInput {
|
|
10
|
+
configDir: string;
|
|
11
|
+
profileExtensions: readonly string[];
|
|
12
|
+
deps: HostApiDeps;
|
|
13
|
+
context: HostContext;
|
|
14
|
+
/** `--no-trust`。 */
|
|
15
|
+
noTrust: boolean;
|
|
16
|
+
interactive: boolean;
|
|
17
|
+
prompt?: ((files: readonly ExtensionPromptFile[]) => Promise<TrustPromptAnswer>) | undefined;
|
|
18
|
+
warn(message: string): void;
|
|
19
|
+
}
|
|
20
|
+
export declare function loadExtensions(input: LoadExtensionsInput): Promise<HostAdapterHandle[]>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 启动第 13 步的扩展部分(#301):发现 → 按哈希信任决定 → 激活(失败只 warning)。宿主适配器先于它激活,
|
|
3
|
+
* 资源注册表在它之后冻结。
|
|
4
|
+
*/
|
|
5
|
+
import { decideExtensions } from "../config/extension-trust.js";
|
|
6
|
+
import { createHostApi } from "../host/api-impl.js";
|
|
7
|
+
import { activateExtensions, discoverExtensions } from "../host/extensions.js";
|
|
8
|
+
import { msg } from "../i18n/index.js";
|
|
9
|
+
export async function loadExtensions(input) {
|
|
10
|
+
const found = discoverExtensions(input.configDir, input.profileExtensions);
|
|
11
|
+
if (found.length === 0)
|
|
12
|
+
return [];
|
|
13
|
+
// 读 / 写 trust.json 或询问界面出错:全部跳过并 warning,不让扩展的问题变成启动失败(宿主已激活)
|
|
14
|
+
let decision;
|
|
15
|
+
try {
|
|
16
|
+
decision = await decideExtensions({
|
|
17
|
+
paths: found,
|
|
18
|
+
configDir: input.configDir,
|
|
19
|
+
disabled: input.noTrust,
|
|
20
|
+
interactive: input.interactive,
|
|
21
|
+
prompt: input.prompt,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
input.warn(msg().cli.bootstrap.extensionsTrustFailed(error instanceof Error ? error.message : String(error)));
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
const m = msg().cli.bootstrap;
|
|
29
|
+
for (const skipped of decision.skipped) {
|
|
30
|
+
input.warn(m.extensionSkipped(skipped.path, m.extensionReason[skipped.reason]));
|
|
31
|
+
}
|
|
32
|
+
const { handles } = await activateExtensions({
|
|
33
|
+
paths: decision.load,
|
|
34
|
+
createBinding: () => createHostApi(input.deps, input.context),
|
|
35
|
+
warn: input.warn,
|
|
36
|
+
});
|
|
37
|
+
return handles;
|
|
38
|
+
}
|
package/dist/cli/compose.js
CHANGED
|
@@ -200,6 +200,7 @@ function lazyUi(load) {
|
|
|
200
200
|
const get = () => (ui ??= load());
|
|
201
201
|
return {
|
|
202
202
|
promptTrust: async (cwd, resources) => (await get()).promptTrust(cwd, resources),
|
|
203
|
+
promptExtensions: async (files) => (await get()).promptExtensions(files),
|
|
203
204
|
pickSession: async (items) => (await get()).pickSession(items),
|
|
204
205
|
pickModel: async (providers, reason) => (await get()).pickModel(providers, reason),
|
|
205
206
|
askCwd: async (missing) => (await get()).askCwd(missing),
|
package/dist/cli/deps.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ import type { TrustPromptAnswer } from "../config/trust.js";
|
|
|
17
17
|
import type { HookDispatcherApi } from "../hooks/types.js";
|
|
18
18
|
import type { MemoryRuntime } from "../memory/runtime.js";
|
|
19
19
|
import type { WarmingDecisionHandler } from "../ai/cache/types.js";
|
|
20
|
+
import type { HostRunnerRegistry } from "../drivers/host-runners.js";
|
|
20
21
|
import type { AgentEventBus } from "../host/api-impl.js";
|
|
21
22
|
import type { ApprovalBroker, HostAdapterHandle, InstructionSource } from "../host/types.js";
|
|
22
23
|
import type { PermissionMode, PermissionPipelineApi } from "../permissions/types.js";
|
|
@@ -96,6 +97,8 @@ export interface SessionAssembly {
|
|
|
96
97
|
events: AgentEventBus;
|
|
97
98
|
host: {
|
|
98
99
|
handle: HostAdapterHandle | undefined;
|
|
100
|
+
/** [#301] 已激活的本地扩展(加载顺序);没有时为空表。 */
|
|
101
|
+
extensions?: readonly HostAdapterHandle[];
|
|
99
102
|
/** 宿主 broker(链首);undefined 交给 UI / 无人值守。 */
|
|
100
103
|
broker(): ApprovalBroker | undefined;
|
|
101
104
|
/** 系统提示 host 节。 */
|
|
@@ -107,6 +110,8 @@ export interface SessionAssembly {
|
|
|
107
110
|
scheme: string;
|
|
108
111
|
describe: string;
|
|
109
112
|
}[];
|
|
113
|
+
/** [#306] 宿主适配器与本地扩展共用的 runner 注册表(`task` 与 `/agents` 读它)。 */
|
|
114
|
+
runners?: HostRunnerRegistry;
|
|
110
115
|
};
|
|
111
116
|
/** `Runtime.approvals.setUiBroker` 设置的 UI broker(链尾);每次审批现取,未设置为 undefined。 */
|
|
112
117
|
uiBroker(): ApprovalBroker | undefined;
|
|
@@ -151,6 +156,12 @@ export type ModeRunner = (runtime: Runtime, context: ModeContext) => Promise<num
|
|
|
151
156
|
/** 交互 UI 回调(B7 / B6 line 提供);全部可选,缺省按非交互处理。 */
|
|
152
157
|
export interface InteractiveUi {
|
|
153
158
|
promptTrust?(cwd: string, resources: readonly string[]): Promise<TrustPromptAnswer>;
|
|
159
|
+
/** [#301] 本地扩展首次出现或内容变化时询问(一次,列出全部待定文件的路径与 sha256)。 */
|
|
160
|
+
promptExtensions?(files: readonly {
|
|
161
|
+
path: string;
|
|
162
|
+
sha256: string;
|
|
163
|
+
directory?: boolean;
|
|
164
|
+
}[]): Promise<TrustPromptAnswer>;
|
|
154
165
|
/** `--resume` 无 id:返回会话 id,undefined = 用户取消(退出码 5)。 */
|
|
155
166
|
pickSession?(items: readonly SessionListItem[]): Promise<string | undefined>;
|
|
156
167
|
/** 无 key / 无模型时选择模型;返回 `provider/id`,undefined = 取消(退出码 4)。 */
|
package/dist/cli/runtime.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ import type { AgentSession } from "../agent/types.js";
|
|
|
10
10
|
import type { AmaConfig } from "../config/types.js";
|
|
11
11
|
import type { HookDispatcherApi } from "../hooks/types.js";
|
|
12
12
|
import type { ApprovalBroker, HostAdapterHandle, HostMode, InstructionSource } from "../host/types.js";
|
|
13
|
+
import type { HostCommandSource } from "../host/commands.js";
|
|
13
14
|
import type { PermissionPipelineApi } from "../permissions/types.js";
|
|
14
15
|
import type { SessionManagerApi } from "../session/types.js";
|
|
15
16
|
import type { ToolRegistryApi } from "../tools/types.js";
|
|
@@ -81,6 +82,12 @@ export interface Runtime {
|
|
|
81
82
|
readonly hooks: HookDispatcherApi;
|
|
82
83
|
/** 未激活宿主适配器时为 undefined。 */
|
|
83
84
|
readonly host: HostAdapterHandle | undefined;
|
|
85
|
+
/** [#301] 已激活的本地扩展(加载顺序,来源路径与 id);没有时为空表。 */
|
|
86
|
+
readonly extensions?: readonly HostAdapterHandle[];
|
|
87
|
+
/** [#301] 宿主适配器与全部扩展 `ui.setStatus` 合并后的状态表(状态栏)。 */
|
|
88
|
+
hostStatus?(): ReadonlyMap<string, string>;
|
|
89
|
+
/** [#301] 宿主适配器与扩展经 `commands.register` 注册的斜杠命令(分派与列出)。 */
|
|
90
|
+
readonly hostCommands?: HostCommandSource;
|
|
84
91
|
readonly permission: PermissionPipelineApi;
|
|
85
92
|
readonly tools: ToolRegistryApi;
|
|
86
93
|
readonly approvals: RuntimeApprovals;
|
|
@@ -61,6 +61,9 @@ export interface CodemodeDescription {
|
|
|
61
61
|
/** 人读原因。 */
|
|
62
62
|
reason: string;
|
|
63
63
|
strict: boolean;
|
|
64
|
+
/** 实际使用的脚本引擎与原因(`codemode.engine`,缺省 auto)。 */
|
|
65
|
+
engine: "node" | "quickjs";
|
|
66
|
+
engineReason: string;
|
|
64
67
|
/** 生效模式不是 off 但 codemode 工具不可用(requireStrict)时的说明。 */
|
|
65
68
|
unavailable?: string;
|
|
66
69
|
}
|
|
@@ -23,7 +23,7 @@ import { modelsDevCachePath } from "../../ai/providers/models-dev-cache.js";
|
|
|
23
23
|
import { initConfigDir } from "../../config/init.js";
|
|
24
24
|
import { CONFIG_SCHEMA_FILE } from "../../config/json-schema.js";
|
|
25
25
|
import { CODEMODE_MODES, TOOLS_PRESET_ALIASES, TOOLS_PRESET_INPUTS, canonicalPreset, } from "../../config/types.js";
|
|
26
|
-
import { codemodeAvailability, detectSandboxCapability, sandboxCapabilityFor, } from "../../codemode/capability.js";
|
|
26
|
+
import { codemodeAvailability, applyCodemodeEngine, detectSandboxCapability, sandboxCapabilityFor, } from "../../codemode/capability.js";
|
|
27
27
|
import { baseUrlEnvOf } from "../../ai/providers/registry.js";
|
|
28
28
|
import { classifyKeyValue } from "../../config/auth-file.js";
|
|
29
29
|
import { CODEMODE_TOOL, resolveCodemodeMode, resolvePreset } from "../../tools/presets.js";
|
|
@@ -248,14 +248,24 @@ export function sourcesOf(effective, layers) {
|
|
|
248
248
|
* 操作系统沙箱);不传按配置的 `sandbox.enabled` 用运行时能力。
|
|
249
249
|
*/
|
|
250
250
|
export function describeCodemode(config, nodeVersion) {
|
|
251
|
-
const capability = nodeVersion === undefined
|
|
251
|
+
const capability = nodeVersion === undefined
|
|
252
|
+
? sandboxCapabilityFor(config)
|
|
253
|
+
: applyCodemodeEngine(detectSandboxCapability(nodeVersion), config.codemode?.engine);
|
|
252
254
|
const resolved = resolveCodemodeMode(config, capability.strict);
|
|
253
255
|
const m = msg().subcommands.configShow;
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
256
|
+
const engine = capability.engine ?? "node";
|
|
257
|
+
const sandbox = engine === "quickjs"
|
|
258
|
+
? m.sandboxQuickjs(capability.nodeMajor)
|
|
259
|
+
: capability.nodeMajor >= 25
|
|
260
|
+
? m.sandboxIsolated(capability.nodeMajor)
|
|
261
|
+
: capability.strict
|
|
262
|
+
? m.sandboxOs(capability.nodeMajor, capability.os.kind)
|
|
263
|
+
: m.sandboxNone(capability.nodeMajor);
|
|
264
|
+
const engineReason = capability.engineSource === "config"
|
|
265
|
+
? m.engineExplicit(engine)
|
|
266
|
+
: engine === "quickjs"
|
|
267
|
+
? m.engineAutoQuickjs(capability.nodeMajor)
|
|
268
|
+
: m.engineAutoNode(sandbox);
|
|
259
269
|
const reason = resolved.source === "config"
|
|
260
270
|
? m.codemodeExplicit(sandbox)
|
|
261
271
|
: m.codemodeFollowsPreset(resolved.preset, sandbox);
|
|
@@ -264,6 +274,8 @@ export function describeCodemode(config, nodeVersion) {
|
|
|
264
274
|
source: resolved.source,
|
|
265
275
|
reason,
|
|
266
276
|
strict: capability.strict,
|
|
277
|
+
engine,
|
|
278
|
+
engineReason,
|
|
267
279
|
};
|
|
268
280
|
if (resolved.mode !== "off") {
|
|
269
281
|
const availability = codemodeAvailability(config.codemode?.requireStrict, capability);
|
|
@@ -347,6 +359,9 @@ export async function runConfig(argv, io, deps) {
|
|
|
347
359
|
value,
|
|
348
360
|
source: sources.get(path) ?? "default",
|
|
349
361
|
}));
|
|
362
|
+
const engineRow = rows.find((row) => row.path === "codemode.engine");
|
|
363
|
+
if (engineRow !== undefined && config.codemode?.engine === undefined)
|
|
364
|
+
engineRow.source = m.defaultSource(codemode.engineReason);
|
|
350
365
|
if (config.codemode?.mode === undefined)
|
|
351
366
|
rows.push({
|
|
352
367
|
path: "codemode.mode",
|
|
@@ -16,6 +16,8 @@ import { findContextFiles } from "../../config/context-files.js";
|
|
|
16
16
|
import { loadConfigFile, probeConfigFile } from "../../config/load.js";
|
|
17
17
|
import { mergeProjectAndCli } from "../../config/merge.js";
|
|
18
18
|
import { CONFIG_FILE, HOOKS_FILE, projectFile, userFile } from "../../config/paths.js";
|
|
19
|
+
import { inspectExtension } from "../../config/extension-trust.js";
|
|
20
|
+
import { discoverExtensions } from "../../host/extensions.js";
|
|
19
21
|
import { findTrustEntry, readTrustFile, trustGatedResources } from "../../config/trust.js";
|
|
20
22
|
import { loadHookConfigs } from "../../hooks/config.js";
|
|
21
23
|
import { osSandboxStatus } from "../../sandbox/detect.js";
|
|
@@ -100,6 +102,36 @@ function trustSection(report, io, level, flag) {
|
|
|
100
102
|
}
|
|
101
103
|
return trusted;
|
|
102
104
|
}
|
|
105
|
+
/** [#301] 本地扩展:文件、哈希前缀与信任状态;不执行扩展代码。 */
|
|
106
|
+
function extensionsSection(report, level, noTrust) {
|
|
107
|
+
const m = msg().report.doctor;
|
|
108
|
+
const reasons = msg().cli.bootstrap.extensionReason;
|
|
109
|
+
report.section(m.extensionsTitle);
|
|
110
|
+
const paths = discoverExtensions(level.configDir, level.profile?.extensions ?? []);
|
|
111
|
+
if (paths.length === 0) {
|
|
112
|
+
report.item(m.extensionsNone);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
report.item(m.extensionsNote);
|
|
116
|
+
let recorded = [];
|
|
117
|
+
try {
|
|
118
|
+
recorded = readTrustFile(level.configDir).extensions ?? [];
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
report.problem(error.message);
|
|
122
|
+
}
|
|
123
|
+
for (const path of paths) {
|
|
124
|
+
const info = inspectExtension(path, recorded);
|
|
125
|
+
const reason = noTrust
|
|
126
|
+
? "no-trust"
|
|
127
|
+
: info.status === "trusted"
|
|
128
|
+
? undefined
|
|
129
|
+
: info.status === "unknown"
|
|
130
|
+
? "untrusted"
|
|
131
|
+
: info.status;
|
|
132
|
+
report.item(m.extensionLine(reason === undefined, info.path, m.extensionSha(info.sha256), reason === undefined ? undefined : reasons[reason], info.directory === true));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
103
135
|
async function keySection(report, io, level, deps) {
|
|
104
136
|
const m = msg().report.doctor;
|
|
105
137
|
report.section(m.keysTitle);
|
|
@@ -287,6 +319,7 @@ export async function runDoctor(argv, io, deps) {
|
|
|
287
319
|
report.item(m.permissionMode(merged.config.permission?.mode ?? "default"));
|
|
288
320
|
const codemode = describeCodemode(merged.config);
|
|
289
321
|
report.item(m.codemode(codemode.mode, codemode.reason));
|
|
322
|
+
report.item(m.codemodeEngine(codemode.engine, codemode.engineReason));
|
|
290
323
|
if (codemode.unavailable !== undefined)
|
|
291
324
|
report.item(` ${codemode.unavailable}`);
|
|
292
325
|
const os = osSandboxStatus(merged.config.sandbox?.enabled ?? "auto");
|
|
@@ -307,6 +340,7 @@ export async function runDoctor(argv, io, deps) {
|
|
|
307
340
|
for (const file of context.files)
|
|
308
341
|
report.item(`${file.scope === "user" ? m.contextUser : m.contextProject} ${file.path}`);
|
|
309
342
|
await keySection(report, io, level, deps);
|
|
343
|
+
extensionsSection(report, level, flags.has("no-trust"));
|
|
310
344
|
hookSection(report, io, level, trusted);
|
|
311
345
|
report.item(m.userHooks(userFile(level, HOOKS_FILE)));
|
|
312
346
|
proxySection(report, io);
|
|
@@ -29,7 +29,7 @@ import { CHATGPT_PROVIDER_ID, codexClientVersion } from "../../auth/chatgpt/pres
|
|
|
29
29
|
import { liveToken } from "../../auth/oauth/live.js";
|
|
30
30
|
import { discoverLocalModels, materializeModel } from "../../ai/providers/registry.js";
|
|
31
31
|
import { thinkingMapOf, writeDiscoveredCache, } from "../../ai/providers/discovered-cache.js";
|
|
32
|
-
import { withCustomDefaults } from "../../ai/providers/catalog.js";
|
|
32
|
+
import { catalogByAlias, withCustomDefaults } from "../../ai/providers/catalog.js";
|
|
33
33
|
import { describeModelsDev, loadModelsDevIndex } from "../../ai/providers/models-dev-cache.js";
|
|
34
34
|
import { matchLabel, modelsDevFields } from "../../ai/providers/models-dev.js";
|
|
35
35
|
import { existsSync } from "node:fs";
|
|
@@ -221,7 +221,11 @@ async function run(ctx) {
|
|
|
221
221
|
const unmatched = new Set();
|
|
222
222
|
for (const model of found) {
|
|
223
223
|
const known = configured.get(model.id);
|
|
224
|
-
|
|
224
|
+
// 目录别名指向官方条目时按它的快照 ref 再找一次:中转站的 id 在聚合源下架后,
|
|
225
|
+
// 运行时仍经别名继承窗口(enrich 的 catalog-alias),不该报「未匹配」
|
|
226
|
+
const aliasRef = catalogByAlias(model.id)?.snapshotRef;
|
|
227
|
+
const match = mdIndex.match(model.id) ??
|
|
228
|
+
(aliasRef !== undefined ? mdIndex.match(model.id, aliasRef) : undefined);
|
|
225
229
|
const fields = match !== undefined ? modelsDevFields(match.model) : undefined;
|
|
226
230
|
if (fields?.toolCall === false)
|
|
227
231
|
noTools.add(model.id);
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* 能力在进程内只探测一次(OS 沙箱探针有缓存),同一环境下描述与权限类字节稳定。状态栏直接调用
|
|
13
13
|
* `detectSandboxCapability()`(不经宿主 status);组装根先用 `configureOsSandbox` 记下 `sandbox.enabled`。
|
|
14
14
|
*/
|
|
15
|
-
import type { SandboxConfig } from "../config/types.js";
|
|
15
|
+
import type { CodemodeEngineSetting, SandboxConfig } from "../config/types.js";
|
|
16
16
|
import { type OsSandboxStatus } from "../sandbox/detect.js";
|
|
17
17
|
export interface SandboxCapability {
|
|
18
18
|
/** 权限模型同时隔离文件、子进程与网络。 */
|
|
@@ -25,7 +25,16 @@ export interface SandboxCapability {
|
|
|
25
25
|
permissionFlag: "--permission" | "--experimental-permission";
|
|
26
26
|
/** 操作系统沙箱(`kind: none` 表示没有);codemode 子进程经它启动。 */
|
|
27
27
|
os: OsSandboxStatus;
|
|
28
|
+
/** 实际使用的引擎;缺省(直接 `detectSandboxCapability()`)是 Node 子进程。 */
|
|
29
|
+
engine?: "node" | "quickjs";
|
|
30
|
+
/** 引擎是配置显式指定(config)还是 auto 按网络隔离能力选的。 */
|
|
31
|
+
engineSource?: "config" | "auto";
|
|
28
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* 按 `codemode.engine`(缺省 auto)选引擎:auto = 网络已隔离(Node ≥ 25 或 OS 沙箱)时用 Node 子进程,
|
|
35
|
+
* 否则用 QuickJS。QuickJS 下脚本只能经 `tools.*` 触达外界,所以 `strict`(codemode 为 read 类)。
|
|
36
|
+
*/
|
|
37
|
+
export declare function applyCodemodeEngine(capability: SandboxCapability, setting?: CodemodeEngineSetting): SandboxCapability;
|
|
29
38
|
export declare const NETWORK_NOT_ISOLATED = "network not isolated";
|
|
30
39
|
export declare function parseNodeMajor(version: string): number;
|
|
31
40
|
/** `--permission` 在 Node 22.13 / 23.5 之后才是稳定名字;之前只有 `--experimental-permission`。 */
|
|
@@ -38,9 +47,12 @@ export declare function detectSandboxCapability(nodeVersion?: string, allowedFla
|
|
|
38
47
|
/** 按配置的 `sandbox.enabled`(缺省 auto)得到运行时能力。 */
|
|
39
48
|
export declare function sandboxCapabilityFor(config: {
|
|
40
49
|
sandbox?: SandboxConfig;
|
|
50
|
+
codemode?: {
|
|
51
|
+
engine?: CodemodeEngineSetting;
|
|
52
|
+
};
|
|
41
53
|
}): SandboxCapability;
|
|
42
54
|
/** strict 是否依赖 OS 沙箱(Node 22 / 24):此时子进程必须经 OS 沙箱启动,包装不了就报错。 */
|
|
43
|
-
export declare function strictNeedsOsSandbox(capability: Pick<SandboxCapability, "strict" | "nodeMajor">): boolean;
|
|
55
|
+
export declare function strictNeedsOsSandbox(capability: Pick<SandboxCapability, "strict" | "nodeMajor" | "engine">): boolean;
|
|
44
56
|
export type CodemodeAvailability = {
|
|
45
57
|
available: true;
|
|
46
58
|
capability: SandboxCapability;
|
|
@@ -14,6 +14,23 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import { NO_OS_SANDBOX, osSandboxStatus } from "../sandbox/detect.js";
|
|
16
16
|
import { msg } from "../i18n/index.js";
|
|
17
|
+
/**
|
|
18
|
+
* 按 `codemode.engine`(缺省 auto)选引擎:auto = 网络已隔离(Node ≥ 25 或 OS 沙箱)时用 Node 子进程,
|
|
19
|
+
* 否则用 QuickJS。QuickJS 下脚本只能经 `tools.*` 触达外界,所以 `strict`(codemode 为 read 类)。
|
|
20
|
+
*/
|
|
21
|
+
export function applyCodemodeEngine(capability, setting = "auto") {
|
|
22
|
+
const source = setting === "auto" ? "auto" : "config";
|
|
23
|
+
const engine = setting === "auto" ? (capability.strict ? "node" : "quickjs") : setting;
|
|
24
|
+
if (engine === "node")
|
|
25
|
+
return { ...capability, engine, engineSource: source };
|
|
26
|
+
return {
|
|
27
|
+
...capability,
|
|
28
|
+
strict: true,
|
|
29
|
+
engine,
|
|
30
|
+
engineSource: source,
|
|
31
|
+
reason: "QuickJS engine: scripts run in a WebAssembly VM and can only reach tools",
|
|
32
|
+
};
|
|
33
|
+
}
|
|
17
34
|
export const NETWORK_NOT_ISOLATED = "network not isolated";
|
|
18
35
|
export function parseNodeMajor(version) {
|
|
19
36
|
const major = Number.parseInt(version.replace(/^v/, "").split(".")[0] ?? "", 10);
|
|
@@ -59,11 +76,11 @@ export function detectSandboxCapability(nodeVersion, allowedFlags, os) {
|
|
|
59
76
|
}
|
|
60
77
|
/** 按配置的 `sandbox.enabled`(缺省 auto)得到运行时能力。 */
|
|
61
78
|
export function sandboxCapabilityFor(config) {
|
|
62
|
-
return detectSandboxCapability(undefined, undefined, osSandboxStatus(config.sandbox?.enabled ?? "auto"));
|
|
79
|
+
return applyCodemodeEngine(detectSandboxCapability(undefined, undefined, osSandboxStatus(config.sandbox?.enabled ?? "auto")), config.codemode?.engine);
|
|
63
80
|
}
|
|
64
81
|
/** strict 是否依赖 OS 沙箱(Node 22 / 24):此时子进程必须经 OS 沙箱启动,包装不了就报错。 */
|
|
65
82
|
export function strictNeedsOsSandbox(capability) {
|
|
66
|
-
return capability.strict && capability.nodeMajor < 25;
|
|
83
|
+
return capability.strict && capability.nodeMajor < 25 && capability.engine !== "quickjs";
|
|
67
84
|
}
|
|
68
85
|
/** `requireStrict` 且运行时不是 strict → 禁用并给出 warning;非 strict 但允许 → 可用并提示。 */
|
|
69
86
|
export function codemodeAvailability(requireStrict, capability = detectSandboxCapability()) {
|
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
* (完整门禁);名字是 `codemode` 直接拒绝。脚本结束时 abort 仍在跑的调用。
|
|
14
14
|
* - 超时:父进程计时,到点杀子进程树(POSIX 进程组 / Windows taskkill);外层 abort:先发
|
|
15
15
|
* `abort`,宽限后杀树。
|
|
16
|
+
* - 名额:进程内同时存活的子进程数受 `worker-pool.ts` 限制,排队最多 60 s 且计入 `timeout_ms`;名额在子进程
|
|
17
|
+
* `close` 时归还,不是结果落定时。
|
|
16
18
|
* - OS 沙箱(docs/guides/sandbox.md):有可用的 sandbox-exec / bwrap / unshare 时,整条命令行经它启动,拒绝
|
|
17
19
|
* 网络与一切写入(`CODEMODE_OS_POLICY`;子进程本来就没有写权限)。Node 22 / 24 的 strict 依赖这一层
|
|
18
20
|
* (`requireOsSandbox`),包装不了就报错,不裸跑;Node ≥ 25 是叠加的纵深防御。
|
|
@@ -21,6 +23,7 @@ import { type OsSandboxStatus } from "../sandbox/detect.js";
|
|
|
21
23
|
import type { OsSandboxPolicy } from "../sandbox/profile.js";
|
|
22
24
|
import { type WrappedCommand } from "../sandbox/wrap.js";
|
|
23
25
|
import { type SandboxCapability } from "./capability.js";
|
|
26
|
+
import { type WorkerPool } from "./worker-pool.js";
|
|
24
27
|
import { type ScriptOptions, type StoreSnapshot, type ToolDecl } from "./protocol.js";
|
|
25
28
|
/** 父进程累积的输出上限(字符);超出后丢弃中段(给模型的再按 max_output_tokens 截)。 */
|
|
26
29
|
export declare const MAX_COLLECTED_OUTPUT_CHARS: number;
|
|
@@ -46,6 +49,8 @@ export interface SandboxRunRequest {
|
|
|
46
49
|
/** 执行一次内层工具调用:解析为脚本拿到的值,失败抛 Error(消息给脚本)。 */
|
|
47
50
|
callTool(name: string, input: unknown, signal: AbortSignal): Promise<unknown>;
|
|
48
51
|
onOutput?(text: string): void;
|
|
52
|
+
/** 脚本里的 `searchTools(query, options)`;缺省时搜不到任何工具。抛错变成脚本里的 Error。 */
|
|
53
|
+
searchTools?(query: unknown, options: unknown): unknown;
|
|
49
54
|
signal: AbortSignal;
|
|
50
55
|
/** 缺省 resolveSandboxEntry()。 */
|
|
51
56
|
entry?: string;
|
|
@@ -58,6 +63,10 @@ export interface SandboxRunRequest {
|
|
|
58
63
|
requireOsSandbox?: boolean;
|
|
59
64
|
/** 子进程堆上限(MB),缺省 DEFAULT_CODEMODE_HEAP_MB;0 不设上限。 */
|
|
60
65
|
maxHeapMb?: number;
|
|
66
|
+
/** 进程级沙箱名额池,缺省共享的 `codemodeWorkerPool`;测试注入带假时钟的池。 */
|
|
67
|
+
workerPool?: WorkerPool;
|
|
68
|
+
/** 同时存活的沙箱子进程上限(调用方每次读环境变量 / 配置);缺省 2。 */
|
|
69
|
+
maxWorkers?: number;
|
|
61
70
|
/** 脚本总超时计时器的注入(测试用手动时钟,不随机器负载漂移);缺省真实 `setTimeout`。 */
|
|
62
71
|
timeoutTimers?: TimeoutTimers;
|
|
63
72
|
}
|
|
@@ -81,6 +90,11 @@ export interface SandboxRunResult {
|
|
|
81
90
|
toolCalls: number;
|
|
82
91
|
/** 输出超过 MAX_COLLECTED_OUTPUT_CHARS 被丢弃的字符数。 */
|
|
83
92
|
droppedChars: number;
|
|
93
|
+
/** `image(v)` 产出的图(子进程已按文件头校验;使用前仍须再校验)。 */
|
|
94
|
+
images: {
|
|
95
|
+
data: string;
|
|
96
|
+
mimeType: string;
|
|
97
|
+
}[];
|
|
84
98
|
/** 子进程 pid(POSIX 下也是进程组 id)。 */
|
|
85
99
|
pid?: number;
|
|
86
100
|
}
|