@armadra/agent 0.11.0 → 0.13.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 +19 -0
- package/CHANGELOG.zh-CN.md +19 -0
- package/dist/acp.d.ts +2 -2
- package/dist/acp.js +2 -2
- package/dist/ai/fake/fake-provider.d.ts +6 -0
- package/dist/ai/fake/fake-provider.js +46 -0
- package/dist/ai/fake/fake-script.d.ts +8 -1
- package/dist/ai/fake/fake-script.js +5 -1
- package/dist/bundle/ama.cjs +180 -27
- package/dist/cli/compose-agents.js +8 -0
- package/dist/codemode/host-side.d.ts +7 -0
- package/dist/codemode/host-side.js +7 -2
- package/dist/drivers/acp/client.d.ts +54 -5
- package/dist/drivers/acp/client.js +96 -9
- package/dist/drivers/acp/types.d.ts +69 -3
- package/dist/drivers/acp/types.js +30 -1
- package/dist/modes/interactive/interactive-mode.d.ts +7 -0
- package/dist/modes/interactive/interactive-mode.js +12 -4
- package/dist/permissions/auto-safe.d.ts +3 -0
- package/dist/permissions/auto-safe.js +10 -3
- package/dist/permissions/readonly-bash.d.ts +2 -2
- package/dist/permissions/readonly-bash.js +2 -2
- package/dist/tools/presets.d.ts +7 -0
- package/dist/tools/presets.js +10 -1
- package/dist/tools/task-ctl.d.ts +9 -0
- package/dist/tools/task-ctl.js +22 -3
- package/docs/en/guides/permissions.md +10 -10
- package/docs/en/reference/acp.md +7 -3
- package/docs/guides/agents.md +4 -1
- package/docs/guides/permissions.md +10 -10
- package/docs/reference/acp.md +7 -3
- package/package.json +1 -1
package/dist/bundle/ama.cjs
CHANGED
|
@@ -41,7 +41,7 @@ var AMA_VERSION;
|
|
|
41
41
|
var init_version = __esm({
|
|
42
42
|
"src/version.ts"() {
|
|
43
43
|
"use strict";
|
|
44
|
-
AMA_VERSION = true ? "0.
|
|
44
|
+
AMA_VERSION = true ? "0.13.0" : readPackageVersion();
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
47
|
|
|
@@ -13668,6 +13668,9 @@ function checkResponse(value, path) {
|
|
|
13668
13668
|
if (value["text"] !== void 0 && typeof value["text"] !== "string") {
|
|
13669
13669
|
fail(`${path}.text`, "must be a string");
|
|
13670
13670
|
}
|
|
13671
|
+
if (value["gate"] !== void 0 && typeof value["gate"] !== "string") {
|
|
13672
|
+
fail(`${path}.gate`, "must be a string");
|
|
13673
|
+
}
|
|
13671
13674
|
const stop = value["stopReason"];
|
|
13672
13675
|
if (stop !== void 0 && stop !== "stop" && stop !== "length" && stop !== "toolUse" && stop !== "refusal") {
|
|
13673
13676
|
fail(`${path}.stopReason`, "must be stop / length / toolUse / refusal");
|
|
@@ -13818,6 +13821,20 @@ function sleep(ms, signal) {
|
|
|
13818
13821
|
function tick() {
|
|
13819
13822
|
return new Promise((resolve41) => setImmediate(resolve41));
|
|
13820
13823
|
}
|
|
13824
|
+
function waitOpen(open3, signal) {
|
|
13825
|
+
return new Promise((resolve41) => {
|
|
13826
|
+
if (signal.aborted) {
|
|
13827
|
+
resolve41();
|
|
13828
|
+
return;
|
|
13829
|
+
}
|
|
13830
|
+
const done = () => {
|
|
13831
|
+
signal.removeEventListener("abort", done);
|
|
13832
|
+
resolve41();
|
|
13833
|
+
};
|
|
13834
|
+
signal.addEventListener("abort", done, { once: true });
|
|
13835
|
+
void open3.then(done);
|
|
13836
|
+
});
|
|
13837
|
+
}
|
|
13821
13838
|
var import_node_fs14, FAKE_PROVIDER_ID, FAKE_API_ID, FAKE_SCRIPT_ENV, FAKE_RECORD_ENV, FAKE_MODEL_BASE, FAKE_MODELS, AbortedError, FakeProvider, defaultFakeProvider, fakeApi;
|
|
13822
13839
|
var init_fake_provider = __esm({
|
|
13823
13840
|
"src/ai/fake/fake-provider.ts"() {
|
|
@@ -13856,6 +13873,7 @@ var init_fake_provider = __esm({
|
|
|
13856
13873
|
recordFile;
|
|
13857
13874
|
keepCalls;
|
|
13858
13875
|
count = 0;
|
|
13876
|
+
gates = /* @__PURE__ */ new Map();
|
|
13859
13877
|
constructor(script, options = {}) {
|
|
13860
13878
|
if (typeof script === "function") this.scriptLoader = script;
|
|
13861
13879
|
else if (script !== void 0) this.setScript(script);
|
|
@@ -13882,6 +13900,25 @@ var init_fake_provider = __esm({
|
|
|
13882
13900
|
reset() {
|
|
13883
13901
|
this.calls.length = 0;
|
|
13884
13902
|
this.count = 0;
|
|
13903
|
+
this.gates.clear();
|
|
13904
|
+
}
|
|
13905
|
+
gate(name) {
|
|
13906
|
+
let gate = this.gates.get(name);
|
|
13907
|
+
if (gate === void 0) {
|
|
13908
|
+
let release;
|
|
13909
|
+
const open3 = new Promise((resolve41) => release = resolve41);
|
|
13910
|
+
gate = { open: open3, release, waiting: 0 };
|
|
13911
|
+
this.gates.set(name, gate);
|
|
13912
|
+
}
|
|
13913
|
+
return gate;
|
|
13914
|
+
}
|
|
13915
|
+
/** 放行名为 `name` 的闸门(`FakeResponse.gate`):正在等的调用继续,之后到达的也直接通过。 */
|
|
13916
|
+
release(name) {
|
|
13917
|
+
this.gate(name).release();
|
|
13918
|
+
}
|
|
13919
|
+
/** 正停在闸门 `name` 上的调用个数(测试确认「请求已发出、正在等」)。 */
|
|
13920
|
+
waitingAt(name) {
|
|
13921
|
+
return this.gates.get(name)?.waiting ?? 0;
|
|
13885
13922
|
}
|
|
13886
13923
|
ensureLoaded() {
|
|
13887
13924
|
if (this.loaded) return;
|
|
@@ -13943,6 +13980,16 @@ var init_fake_provider = __esm({
|
|
|
13943
13980
|
};
|
|
13944
13981
|
try {
|
|
13945
13982
|
options.onPayload?.({ fake: true, model: model.id, messages: context.messages.length });
|
|
13983
|
+
if (response.gate !== void 0) {
|
|
13984
|
+
const gate = this.gate(response.gate);
|
|
13985
|
+
gate.waiting++;
|
|
13986
|
+
try {
|
|
13987
|
+
await waitOpen(gate.open, signal);
|
|
13988
|
+
} finally {
|
|
13989
|
+
gate.waiting--;
|
|
13990
|
+
}
|
|
13991
|
+
checkAbort();
|
|
13992
|
+
}
|
|
13946
13993
|
if (response.delayMs) await sleep(response.delayMs, signal);
|
|
13947
13994
|
checkAbort();
|
|
13948
13995
|
const error2 = response.error ? describeFakeError(response.error) : void 0;
|
|
@@ -15493,6 +15540,9 @@ var init_jsonl = __esm({
|
|
|
15493
15540
|
});
|
|
15494
15541
|
|
|
15495
15542
|
// src/drivers/acp/types.ts
|
|
15543
|
+
function isTerminalAuthMethod(method) {
|
|
15544
|
+
return method.type === "terminal";
|
|
15545
|
+
}
|
|
15496
15546
|
var ACP_PROTOCOL_VERSION, ACP_METHODS, RPC_ERRORS, ACP_META_KEY;
|
|
15497
15547
|
var init_types7 = __esm({
|
|
15498
15548
|
"src/drivers/acp/types.ts"() {
|
|
@@ -15500,8 +15550,10 @@ var init_types7 = __esm({
|
|
|
15500
15550
|
ACP_PROTOCOL_VERSION = 1;
|
|
15501
15551
|
ACP_METHODS = {
|
|
15502
15552
|
initialize: "initialize",
|
|
15503
|
-
/**
|
|
15553
|
+
/** 客户端 → Agent:agent 型认证方法经它完成;terminal 型不经它(规范)。 */
|
|
15504
15554
|
authenticate: "authenticate",
|
|
15555
|
+
/** 客户端 → Agent:登出当前账号(Agent 声明 `agentCapabilities.auth.logout` 才可用)。 */
|
|
15556
|
+
logout: "logout",
|
|
15505
15557
|
sessionNew: "session/new",
|
|
15506
15558
|
sessionLoad: "session/load",
|
|
15507
15559
|
sessionResume: "session/resume",
|
|
@@ -15514,6 +15566,8 @@ var init_types7 = __esm({
|
|
|
15514
15566
|
sessionUpdate: "session/update",
|
|
15515
15567
|
requestPermission: "session/request_permission",
|
|
15516
15568
|
elicitationCreate: "elicitation/create",
|
|
15569
|
+
/** Agent → 客户端通知:URL 型 elicitation 已在带外完成。 */
|
|
15570
|
+
elicitationComplete: "elicitation/complete",
|
|
15517
15571
|
/** 协议级取消(双向通知,`requestId` 指对端发来的、尚未答复的请求)。 */
|
|
15518
15572
|
cancelRequest: "$/cancel_request"
|
|
15519
15573
|
};
|
|
@@ -19372,6 +19426,9 @@ var init_task_control = __esm({
|
|
|
19372
19426
|
});
|
|
19373
19427
|
|
|
19374
19428
|
// src/tools/task-ctl.ts
|
|
19429
|
+
function bindTaskCtlWaitCap(tool, capMs) {
|
|
19430
|
+
if (tool !== void 0) waitCaps.set(tool, capMs);
|
|
19431
|
+
}
|
|
19375
19432
|
function fail4(message) {
|
|
19376
19433
|
return { content: message, isError: true };
|
|
19377
19434
|
}
|
|
@@ -19398,7 +19455,7 @@ async function send(input2, ctx) {
|
|
|
19398
19455
|
return { content: result.text, isError: result.isError };
|
|
19399
19456
|
}
|
|
19400
19457
|
function createTaskCtlTool() {
|
|
19401
|
-
|
|
19458
|
+
const tool = {
|
|
19402
19459
|
name: TASK_CTL_TOOL,
|
|
19403
19460
|
label: "TaskCtl",
|
|
19404
19461
|
description: "Manage sub-agent tasks started by task: list them, wait for one, stop it, read its output, or send it a follow-up message (runs in background).",
|
|
@@ -19449,14 +19506,17 @@ ${body}` };
|
|
|
19449
19506
|
};
|
|
19450
19507
|
}
|
|
19451
19508
|
case "wait": {
|
|
19452
|
-
const
|
|
19509
|
+
const cap = Math.min(waitCaps.get(tool) ?? MAX_WAIT_MS, MAX_WAIT_MS);
|
|
19510
|
+
const wanted = Math.min(Math.max(input2.timeoutMs ?? DEFAULT_WAIT_MS, 0), MAX_WAIT_MS);
|
|
19511
|
+
const timeout = Math.min(wanted, cap);
|
|
19453
19512
|
const signal = control.detachSignal(taskId);
|
|
19454
19513
|
const result = await control.wait(taskId, timeout, { signal });
|
|
19455
19514
|
if (result === void 0 && signal.aborted) return { content: waitDetachedText(taskId) };
|
|
19456
19515
|
if (result === void 0) {
|
|
19457
19516
|
const turns = control.get(taskId)?.turns ?? 0;
|
|
19517
|
+
const capped2 = wanted > timeout ? ` Waits are capped at ${Math.round(timeout / 1e3)}s here; do not block on it: keep working, a <task-notification> follows when it finishes.` : "";
|
|
19458
19518
|
return {
|
|
19459
|
-
content: `Task ${taskId} is still running (${turns} turns so far). Wait again or stop it
|
|
19519
|
+
content: `Task ${taskId} is still running (${turns} turns so far). Wait again or stop it.${capped2}`
|
|
19460
19520
|
};
|
|
19461
19521
|
}
|
|
19462
19522
|
return {
|
|
@@ -19470,8 +19530,9 @@ ${result.text}`,
|
|
|
19470
19530
|
}
|
|
19471
19531
|
}
|
|
19472
19532
|
};
|
|
19533
|
+
return tool;
|
|
19473
19534
|
}
|
|
19474
|
-
var TASK_CTL_TOOL, DEFAULT_WAIT_MS, MAX_WAIT_MS;
|
|
19535
|
+
var TASK_CTL_TOOL, DEFAULT_WAIT_MS, MAX_WAIT_MS, COORDINATOR_WAIT_MAX_MS, waitCaps;
|
|
19475
19536
|
var init_task_ctl = __esm({
|
|
19476
19537
|
"src/tools/task-ctl.ts"() {
|
|
19477
19538
|
"use strict";
|
|
@@ -19481,6 +19542,8 @@ var init_task_ctl = __esm({
|
|
|
19481
19542
|
TASK_CTL_TOOL = "task_ctl";
|
|
19482
19543
|
DEFAULT_WAIT_MS = 3e4;
|
|
19483
19544
|
MAX_WAIT_MS = 6e5;
|
|
19545
|
+
COORDINATOR_WAIT_MAX_MS = 5e3;
|
|
19546
|
+
waitCaps = /* @__PURE__ */ new WeakMap();
|
|
19484
19547
|
}
|
|
19485
19548
|
});
|
|
19486
19549
|
|
|
@@ -20364,7 +20427,10 @@ function effectiveCodemodeMode(config, strict) {
|
|
|
20364
20427
|
return resolveCodemodeMode(config, strict).mode;
|
|
20365
20428
|
}
|
|
20366
20429
|
function codemodeCallableFilter(config) {
|
|
20367
|
-
return
|
|
20430
|
+
return isCoordinatorPreset(config) ? "active" : void 0;
|
|
20431
|
+
}
|
|
20432
|
+
function isCoordinatorPreset(config) {
|
|
20433
|
+
return canonicalPreset(config.tools?.preset) === "coordinator";
|
|
20368
20434
|
}
|
|
20369
20435
|
function applyToolAdjustments(base4, adjustments) {
|
|
20370
20436
|
if (adjustments === void 0 || adjustments.length === 0) return [...base4];
|
|
@@ -25563,6 +25629,7 @@ function cdTarget(argv, cwd) {
|
|
|
25563
25629
|
function parseSegment(segment) {
|
|
25564
25630
|
const redirects = extractRedirects(segment);
|
|
25565
25631
|
return {
|
|
25632
|
+
first: shellWords(redirects.rest.replace(/^[({\s]+/, ""))[0],
|
|
25566
25633
|
argv: commandWords(redirects.rest),
|
|
25567
25634
|
withSudo: commandWords(redirects.rest, true),
|
|
25568
25635
|
redirects
|
|
@@ -25586,7 +25653,9 @@ function ruleAsk(info2, options) {
|
|
|
25586
25653
|
}
|
|
25587
25654
|
function safeSegment(info2, extra) {
|
|
25588
25655
|
const argv = info2.withSudo;
|
|
25589
|
-
if (argv.length === 0)
|
|
25656
|
+
if (argv.length === 0) {
|
|
25657
|
+
return info2.first === void 0 ? "empty command" : `${base2(info2.first)} is not in the auto safe list`;
|
|
25658
|
+
}
|
|
25590
25659
|
for (const word of argv) {
|
|
25591
25660
|
if (word.includes("$")) return `variable expansion in ${word}`;
|
|
25592
25661
|
if (GLOB.test(word) && /(^|\/)\.[^./]/.test(word)) return `glob over dotfiles (${word})`;
|
|
@@ -25663,7 +25732,6 @@ var init_auto_safe = __esm({
|
|
|
25663
25732
|
"echo",
|
|
25664
25733
|
"printf",
|
|
25665
25734
|
"which",
|
|
25666
|
-
"printenv",
|
|
25667
25735
|
"true",
|
|
25668
25736
|
"false",
|
|
25669
25737
|
"cut",
|
|
@@ -35016,6 +35084,7 @@ var init_client = __esm({
|
|
|
35016
35084
|
onNotification: (method, params) => {
|
|
35017
35085
|
if (method === ACP_METHODS.sessionUpdate)
|
|
35018
35086
|
options.onUpdate?.(params);
|
|
35087
|
+
else if (method === ACP_METHODS.elicitationComplete) this.onElicitationComplete(params);
|
|
35019
35088
|
},
|
|
35020
35089
|
onClose: () => {
|
|
35021
35090
|
for (const set of this.pendingPermissions.values()) for (const c of set) c.abort();
|
|
@@ -35031,14 +35100,25 @@ var init_client = __esm({
|
|
|
35031
35100
|
* - `mcpServers`:开会话时可经 {@link AcpSessionOptions} 传 MCP 服务器;
|
|
35032
35101
|
* - `elicitation`:构造参数 `onElicitation` 接 `elicitation/create`;
|
|
35033
35102
|
* - `configOptions`:`setConfigOption` 与开会话答的 `configOptions`;
|
|
35034
|
-
* - `terminal`:构造参数 `onTerminal` 接 `terminal
|
|
35103
|
+
* - `terminal`:构造参数 `onTerminal` 接 `terminal/*`;
|
|
35104
|
+
* - `auth`:`authenticate` / `logout`、构造参数 `authTerminal`、`isAuthRequiredError`;
|
|
35105
|
+
* - `elicitationComplete`:构造参数 `onElicitationComplete` 接 `elicitation/complete`,表单字段含多选与 `oneOf`。
|
|
35035
35106
|
*/
|
|
35036
|
-
static features = {
|
|
35107
|
+
static features = {
|
|
35108
|
+
mcpServers: true,
|
|
35109
|
+
elicitation: true,
|
|
35110
|
+
configOptions: true,
|
|
35111
|
+
terminal: true,
|
|
35112
|
+
auth: true,
|
|
35113
|
+
elicitationComplete: true
|
|
35114
|
+
};
|
|
35037
35115
|
peer;
|
|
35038
35116
|
/** sessionId → 挂起权限请求的取消器。 */
|
|
35039
35117
|
pendingPermissions = /* @__PURE__ */ new Map();
|
|
35040
35118
|
/** sessionId(没给就是空串)→ 挂起 elicitation 的取消器。 */
|
|
35041
35119
|
pendingElicitations = /* @__PURE__ */ new Map();
|
|
35120
|
+
/** elicitationId → 挂起 elicitation 的取消器(`elicitation/complete` 用)。 */
|
|
35121
|
+
elicitationsById = /* @__PURE__ */ new Map();
|
|
35042
35122
|
initResult;
|
|
35043
35123
|
get closed() {
|
|
35044
35124
|
return this.peer.closed;
|
|
@@ -35065,7 +35145,10 @@ var init_client = __esm({
|
|
|
35065
35145
|
fs: { readTextFile: false, writeTextFile: false },
|
|
35066
35146
|
terminal: this.options.onTerminal !== void 0,
|
|
35067
35147
|
session: { configOptions: {} },
|
|
35068
|
-
...this.options.
|
|
35148
|
+
...this.options.authTerminal === true ? { auth: { terminal: true } } : {},
|
|
35149
|
+
...this.options.onElicitation !== void 0 || this.options.onElicitationComplete ? {
|
|
35150
|
+
elicitation: this.options.onElicitationComplete !== void 0 ? { form: {}, url: {} } : {}
|
|
35151
|
+
} : {}
|
|
35069
35152
|
},
|
|
35070
35153
|
...this.options.clientInfo !== void 0 ? { clientInfo: this.options.clientInfo } : {}
|
|
35071
35154
|
},
|
|
@@ -35091,9 +35174,30 @@ var init_client = __esm({
|
|
|
35091
35174
|
supportsClose() {
|
|
35092
35175
|
return this.agentCapabilities.sessionCapabilities?.close != null;
|
|
35093
35176
|
}
|
|
35177
|
+
/** Agent 声明了 `auth.logout`(存在即支持)。 */
|
|
35178
|
+
supportsLogout() {
|
|
35179
|
+
return this.agentCapabilities.auth?.logout != null;
|
|
35180
|
+
}
|
|
35094
35181
|
supportsImages() {
|
|
35095
35182
|
return this.agentCapabilities.promptCapabilities?.image === true;
|
|
35096
35183
|
}
|
|
35184
|
+
/**
|
|
35185
|
+
* 用 agent 型认证方法登录(`methodId` 取自 `authMethods`)。terminal 型方法不经 `authenticate`:已知是
|
|
35186
|
+
* terminal 型时抛 -32602,由宿主在终端里跑该方法的 `args` / `env`。失败的错误码原样抛出。
|
|
35187
|
+
*/
|
|
35188
|
+
async authenticate(methodId, signal) {
|
|
35189
|
+
const known = this.authMethods.find((method) => method.id === methodId);
|
|
35190
|
+
if (known !== void 0 && isTerminalAuthMethod(known))
|
|
35191
|
+
throw new RpcError(
|
|
35192
|
+
RPC_ERRORS.invalidParams,
|
|
35193
|
+
`auth method ${methodId} is a terminal method: run it in a terminal, not through authenticate`
|
|
35194
|
+
);
|
|
35195
|
+
return this.peer.request(ACP_METHODS.authenticate, { methodId }, signal);
|
|
35196
|
+
}
|
|
35197
|
+
/** 登出当前账号;Agent 没声明 `auth.logout`(见 `supportsLogout`)时会答 method not found。 */
|
|
35198
|
+
logout(signal) {
|
|
35199
|
+
return this.peer.request(ACP_METHODS.logout, {}, signal);
|
|
35200
|
+
}
|
|
35097
35201
|
newSession(cwd, signal, options) {
|
|
35098
35202
|
return this.peer.request(
|
|
35099
35203
|
ACP_METHODS.sessionNew,
|
|
@@ -35117,14 +35221,34 @@ var init_client = __esm({
|
|
|
35117
35221
|
signal
|
|
35118
35222
|
);
|
|
35119
35223
|
}
|
|
35120
|
-
|
|
35121
|
-
|
|
35122
|
-
|
|
35123
|
-
|
|
35124
|
-
|
|
35224
|
+
/** 一页会话;`cwd` 过滤(绝对路径),`cursor` 取自上一页的 `nextCursor`。 */
|
|
35225
|
+
listSessions(cwd, cursor, signal) {
|
|
35226
|
+
return this.peer.request(
|
|
35227
|
+
ACP_METHODS.sessionList,
|
|
35228
|
+
{
|
|
35229
|
+
...cwd !== void 0 ? { cwd } : {},
|
|
35230
|
+
...cursor !== void 0 ? { cursor } : {}
|
|
35231
|
+
},
|
|
35232
|
+
signal
|
|
35233
|
+
);
|
|
35234
|
+
}
|
|
35235
|
+
/** 跟 `nextCursor` 翻页取全(`maxPages` 防对端游标不终止,缺省 100 页)。 */
|
|
35236
|
+
async listAllSessions(cwd, signal, maxPages = 100) {
|
|
35237
|
+
const sessions = [];
|
|
35238
|
+
let cursor;
|
|
35239
|
+
for (let page2 = 0; page2 < maxPages; page2++) {
|
|
35240
|
+
const result = await this.listSessions(cwd, cursor, signal);
|
|
35241
|
+
sessions.push(...result.sessions ?? []);
|
|
35242
|
+
if (typeof result.nextCursor !== "string" || result.nextCursor === "") break;
|
|
35243
|
+
cursor = result.nextCursor;
|
|
35244
|
+
}
|
|
35245
|
+
return sessions;
|
|
35125
35246
|
}
|
|
35126
|
-
|
|
35127
|
-
|
|
35247
|
+
/** 关闭会话:规范要求 Agent 先取消进行中的工作,所以本端先把该会话挂起的请求收掉。 */
|
|
35248
|
+
closeSession(sessionId, signal) {
|
|
35249
|
+
for (const controller of this.pendingPermissions.get(sessionId) ?? []) controller.abort();
|
|
35250
|
+
for (const controller of this.pendingElicitations.get(sessionId) ?? []) controller.abort();
|
|
35251
|
+
return this.peer.request(ACP_METHODS.sessionClose, { sessionId }, signal);
|
|
35128
35252
|
}
|
|
35129
35253
|
prompt(sessionId, prompt, signal) {
|
|
35130
35254
|
return this.peer.request(ACP_METHODS.sessionPrompt, { sessionId, prompt }, signal);
|
|
@@ -35191,6 +35315,8 @@ var init_client = __esm({
|
|
|
35191
35315
|
const set = this.pendingElicitations.get(key) ?? /* @__PURE__ */ new Set();
|
|
35192
35316
|
set.add(controller);
|
|
35193
35317
|
this.pendingElicitations.set(key, set);
|
|
35318
|
+
const id = typeof request.elicitationId === "string" ? request.elicitationId : void 0;
|
|
35319
|
+
if (id !== void 0) this.elicitationsById.set(id, controller);
|
|
35194
35320
|
const signal = AbortSignal.any([controller.signal, connection]);
|
|
35195
35321
|
try {
|
|
35196
35322
|
const answer = await Promise.race([
|
|
@@ -35205,8 +35331,17 @@ var init_client = __esm({
|
|
|
35205
35331
|
return elicitationAnswer(answer);
|
|
35206
35332
|
} finally {
|
|
35207
35333
|
set.delete(controller);
|
|
35334
|
+
if (id !== void 0 && this.elicitationsById.get(id) === controller)
|
|
35335
|
+
this.elicitationsById.delete(id);
|
|
35208
35336
|
}
|
|
35209
35337
|
}
|
|
35338
|
+
/** 通知没有答复:参数不对就忽略;还挂着的同 id elicitation 先收掉,再交给宿主。 */
|
|
35339
|
+
onElicitationComplete(params) {
|
|
35340
|
+
const id = params?.elicitationId;
|
|
35341
|
+
if (typeof id !== "string") return;
|
|
35342
|
+
this.elicitationsById.get(id)?.abort();
|
|
35343
|
+
this.options.onElicitationComplete?.(params);
|
|
35344
|
+
}
|
|
35210
35345
|
};
|
|
35211
35346
|
}
|
|
35212
35347
|
});
|
|
@@ -38784,6 +38919,7 @@ function subagentEnvironment(deps, catalog) {
|
|
|
38784
38919
|
if (retain !== void 0) env.retain = retain;
|
|
38785
38920
|
const sub = config.subagents;
|
|
38786
38921
|
env.background = resolveTaskBackground(sub?.background, deps.assembly.unattended === true);
|
|
38922
|
+
if (isCoordinatorPreset(config)) env.background = true;
|
|
38787
38923
|
const after = sub?.autoBackgroundAfterMs;
|
|
38788
38924
|
if (typeof after === "number" && after > 0) env.autoBackgroundAfterMs = after;
|
|
38789
38925
|
return env;
|
|
@@ -38836,6 +38972,8 @@ function createSubagentsFactory(deps) {
|
|
|
38836
38972
|
bindTaskAgents(task, catalog);
|
|
38837
38973
|
const env = subagentEnvironment(deps, catalog);
|
|
38838
38974
|
bindTaskBackground(task, env.background === true);
|
|
38975
|
+
if (isCoordinatorPreset(deps.assembly.config))
|
|
38976
|
+
bindTaskCtlWaitCap(deps.assembly.tools.get("task_ctl"), COORDINATOR_WAIT_MAX_MS);
|
|
38839
38977
|
return ({ core }) => core.depth > 0 ? void 0 : createSubagentExtension(core, env, wiring);
|
|
38840
38978
|
}
|
|
38841
38979
|
var warned;
|
|
@@ -38847,6 +38985,8 @@ var init_compose_agents = __esm({
|
|
|
38847
38985
|
init_discover();
|
|
38848
38986
|
init_external();
|
|
38849
38987
|
init_api_impl();
|
|
38988
|
+
init_presets2();
|
|
38989
|
+
init_task_ctl();
|
|
38850
38990
|
init_task();
|
|
38851
38991
|
init_subagent_background();
|
|
38852
38992
|
init_i18n();
|
|
@@ -53863,7 +54003,8 @@ async function runSandbox(request) {
|
|
|
53863
54003
|
calls.abort();
|
|
53864
54004
|
finish2();
|
|
53865
54005
|
};
|
|
53866
|
-
const
|
|
54006
|
+
const timers = request.timeoutTimers ?? realTimeoutTimers;
|
|
54007
|
+
const timer = timers.set(() => {
|
|
53867
54008
|
settle({
|
|
53868
54009
|
ok: false,
|
|
53869
54010
|
timedOut: true,
|
|
@@ -53983,7 +54124,7 @@ async function runSandbox(request) {
|
|
|
53983
54124
|
store: request.store
|
|
53984
54125
|
});
|
|
53985
54126
|
await finished;
|
|
53986
|
-
|
|
54127
|
+
timers.clear(timer);
|
|
53987
54128
|
if (graceTimer !== void 0) clearTimeout(graceTimer);
|
|
53988
54129
|
request.signal.removeEventListener("abort", onAbort);
|
|
53989
54130
|
if (child.exitCode === null && child.signalCode === null) {
|
|
@@ -53994,7 +54135,7 @@ async function runSandbox(request) {
|
|
|
53994
54135
|
child.stdin.end();
|
|
53995
54136
|
return result;
|
|
53996
54137
|
}
|
|
53997
|
-
var import_node_child_process16, import_node_fs68, import_node_path90, import_node_url2, MAX_COLLECTED_OUTPUT_CHARS, ABORT_GRACE_MS, DEFAULT_CODEMODE_HEAP_MB, CODEMODE_OS_POLICY;
|
|
54138
|
+
var import_node_child_process16, import_node_fs68, import_node_path90, import_node_url2, MAX_COLLECTED_OUTPUT_CHARS, ABORT_GRACE_MS, DEFAULT_CODEMODE_HEAP_MB, CODEMODE_OS_POLICY, realTimeoutTimers;
|
|
53998
54139
|
var init_host_side = __esm({
|
|
53999
54140
|
"src/codemode/host-side.ts"() {
|
|
54000
54141
|
"use strict";
|
|
@@ -54014,6 +54155,10 @@ var init_host_side = __esm({
|
|
|
54014
54155
|
network: "deny",
|
|
54015
54156
|
writable: Object.freeze([])
|
|
54016
54157
|
});
|
|
54158
|
+
realTimeoutTimers = {
|
|
54159
|
+
set: (fn, ms) => setTimeout(fn, ms),
|
|
54160
|
+
clear: (handle) => clearTimeout(handle)
|
|
54161
|
+
};
|
|
54017
54162
|
}
|
|
54018
54163
|
});
|
|
54019
54164
|
|
|
@@ -65827,6 +65972,7 @@ function runInteractiveMode(runtime, context, options = {}) {
|
|
|
65827
65972
|
tui.addChild(status);
|
|
65828
65973
|
tui.addChild(area.quota);
|
|
65829
65974
|
let finished = false;
|
|
65975
|
+
const hintTimers = options.hintTimers ?? realHintTimers;
|
|
65830
65976
|
let hintTimer;
|
|
65831
65977
|
let resolveExit = () => void 0;
|
|
65832
65978
|
const render = () => tui.requestRender();
|
|
@@ -65836,14 +65982,13 @@ function runInteractiveMode(runtime, context, options = {}) {
|
|
|
65836
65982
|
};
|
|
65837
65983
|
const showHint = (text, ms = HINT_MS) => {
|
|
65838
65984
|
hint.setText(text === "" ? "" : theme.fg("dim", text));
|
|
65839
|
-
if (hintTimer !== void 0)
|
|
65985
|
+
if (hintTimer !== void 0) hintTimers.clear(hintTimer);
|
|
65840
65986
|
hintTimer = void 0;
|
|
65841
65987
|
if (text !== "") {
|
|
65842
|
-
hintTimer =
|
|
65988
|
+
hintTimer = hintTimers.set(() => {
|
|
65843
65989
|
hint.setText("");
|
|
65844
65990
|
render();
|
|
65845
65991
|
}, ms);
|
|
65846
|
-
hintTimer.unref?.();
|
|
65847
65992
|
}
|
|
65848
65993
|
render();
|
|
65849
65994
|
};
|
|
@@ -66096,7 +66241,7 @@ function runInteractiveMode(runtime, context, options = {}) {
|
|
|
66096
66241
|
if (finished) return;
|
|
66097
66242
|
finished = true;
|
|
66098
66243
|
logoAnimation?.finish();
|
|
66099
|
-
if (hintTimer !== void 0)
|
|
66244
|
+
if (hintTimer !== void 0) hintTimers.clear(hintTimer);
|
|
66100
66245
|
loader.stop();
|
|
66101
66246
|
area.dispose();
|
|
66102
66247
|
osc7501.exit();
|
|
@@ -66162,7 +66307,7 @@ function runInteractiveMode(runtime, context, options = {}) {
|
|
|
66162
66307
|
}
|
|
66163
66308
|
});
|
|
66164
66309
|
}
|
|
66165
|
-
var import_node_path101, HINT_MS;
|
|
66310
|
+
var import_node_path101, HINT_MS, realHintTimers;
|
|
66166
66311
|
var init_interactive_mode = __esm({
|
|
66167
66312
|
"src/modes/interactive/interactive-mode.ts"() {
|
|
66168
66313
|
"use strict";
|
|
@@ -66201,6 +66346,14 @@ var init_interactive_mode = __esm({
|
|
|
66201
66346
|
init_tool_view();
|
|
66202
66347
|
init_task_background();
|
|
66203
66348
|
HINT_MS = 2500;
|
|
66349
|
+
realHintTimers = {
|
|
66350
|
+
set: (fn, ms) => {
|
|
66351
|
+
const handle = setTimeout(fn, ms);
|
|
66352
|
+
handle.unref?.();
|
|
66353
|
+
return handle;
|
|
66354
|
+
},
|
|
66355
|
+
clear: (handle) => clearTimeout(handle)
|
|
66356
|
+
};
|
|
66204
66357
|
}
|
|
66205
66358
|
});
|
|
66206
66359
|
|
|
@@ -18,6 +18,8 @@ import { AgentCatalog } from "../agents/catalog.js";
|
|
|
18
18
|
import { agentSources, discoverAgents } from "../agents/discover.js";
|
|
19
19
|
import { NO_AGENT_PROBE_ENV, SessionExternalAgents, registerExternalAgents, } from "../agents/external.js";
|
|
20
20
|
import { hostRunnersOf } from "../host/api-impl.js";
|
|
21
|
+
import { isCoordinatorPreset } from "../tools/presets.js";
|
|
22
|
+
import { COORDINATOR_WAIT_MAX_MS, bindTaskCtlWaitCap } from "../tools/task-ctl.js";
|
|
21
23
|
import { bindTaskAgents, bindTaskBackground } from "../tools/task.js";
|
|
22
24
|
import { resolveTaskBackground } from "../agent/subagent-background.js";
|
|
23
25
|
import { msg } from "../i18n/index.js";
|
|
@@ -62,6 +64,9 @@ export function subagentEnvironment(deps, catalog) {
|
|
|
62
64
|
// [W7-B1] 缺省后台与自动转后台(配置键 W7-B2 登记于 config/types-w5.ts)
|
|
63
65
|
const sub = config.subagents;
|
|
64
66
|
env.background = resolveTaskBackground(sub?.background, deps.assembly.unattended === true);
|
|
67
|
+
// [#242] 协调者不阻塞:缺省后台,不受 subagents.background / -p 影响(调用参数与类型定义仍优先)
|
|
68
|
+
if (isCoordinatorPreset(config))
|
|
69
|
+
env.background = true;
|
|
65
70
|
const after = sub?.autoBackgroundAfterMs;
|
|
66
71
|
if (typeof after === "number" && after > 0)
|
|
67
72
|
env.autoBackgroundAfterMs = after;
|
|
@@ -120,5 +125,8 @@ export function createSubagentsFactory(deps) {
|
|
|
120
125
|
bindTaskAgents(task, catalog);
|
|
121
126
|
const env = subagentEnvironment(deps, catalog);
|
|
122
127
|
bindTaskBackground(task, env.background === true);
|
|
128
|
+
// [#242] 协调者预设:task_ctl wait 超时封顶(task 与 task_ctl 同进退)
|
|
129
|
+
if (isCoordinatorPreset(deps.assembly.config))
|
|
130
|
+
bindTaskCtlWaitCap(deps.assembly.tools.get("task_ctl"), COORDINATOR_WAIT_MAX_MS);
|
|
123
131
|
return ({ core }) => (core.depth > 0 ? undefined : createSubagentExtension(core, env, wiring));
|
|
124
132
|
}
|
|
@@ -58,6 +58,13 @@ export interface SandboxRunRequest {
|
|
|
58
58
|
requireOsSandbox?: boolean;
|
|
59
59
|
/** 子进程堆上限(MB),缺省 DEFAULT_CODEMODE_HEAP_MB;0 不设上限。 */
|
|
60
60
|
maxHeapMb?: number;
|
|
61
|
+
/** 脚本总超时计时器的注入(测试用手动时钟,不随机器负载漂移);缺省真实 `setTimeout`。 */
|
|
62
|
+
timeoutTimers?: TimeoutTimers;
|
|
63
|
+
}
|
|
64
|
+
/** 脚本总超时的计时器(缺省 `setTimeout`)。 */
|
|
65
|
+
export interface TimeoutTimers {
|
|
66
|
+
set(fn: () => void, ms: number): unknown;
|
|
67
|
+
clear(handle: unknown): void;
|
|
61
68
|
}
|
|
62
69
|
/** 子进程因堆上限 OOM 退出时给模型的文案(固定英文)。 */
|
|
63
70
|
export declare function heapLimitError(heapMb: number): string;
|
|
@@ -80,6 +80,10 @@ export function sandboxEnv(versions = process.versions, platform = process.platf
|
|
|
80
80
|
}
|
|
81
81
|
return env;
|
|
82
82
|
}
|
|
83
|
+
const realTimeoutTimers = {
|
|
84
|
+
set: (fn, ms) => setTimeout(fn, ms),
|
|
85
|
+
clear: (handle) => clearTimeout(handle),
|
|
86
|
+
};
|
|
83
87
|
/** 子进程因堆上限 OOM 退出时给模型的文案(固定英文)。 */
|
|
84
88
|
export function heapLimitError(heapMb) {
|
|
85
89
|
return `Script exceeded the codemode memory limit (${heapMb} MB); process the data in smaller pieces`;
|
|
@@ -157,7 +161,8 @@ export async function runSandbox(request) {
|
|
|
157
161
|
calls.abort();
|
|
158
162
|
finish();
|
|
159
163
|
};
|
|
160
|
-
const
|
|
164
|
+
const timers = request.timeoutTimers ?? realTimeoutTimers;
|
|
165
|
+
const timer = timers.set(() => {
|
|
161
166
|
settle({
|
|
162
167
|
ok: false,
|
|
163
168
|
timedOut: true,
|
|
@@ -280,7 +285,7 @@ export async function runSandbox(request) {
|
|
|
280
285
|
store: request.store,
|
|
281
286
|
});
|
|
282
287
|
await finished;
|
|
283
|
-
|
|
288
|
+
timers.clear(timer);
|
|
284
289
|
if (graceTimer !== undefined)
|
|
285
290
|
clearTimeout(graceTimer);
|
|
286
291
|
request.signal.removeEventListener("abort", onAbort);
|