@eddyskywalker/dsh-chatgpt-subscription 0.72.0 → 0.73.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 +20 -0
- package/lib/client.js +47 -12
- package/lib/client.js.map +1 -1
- package/lib/index.js +445 -59
- package/lib/types/client/antigravity-acp/AntigravityAcpSection.d.ts.map +1 -1
- package/lib/types/client/antigravity-acp/locales.d.ts +42 -18
- package/lib/types/client/antigravity-acp/locales.d.ts.map +1 -1
- package/lib/types/client/locales-ru/antigravity-acp.d.ts.map +1 -1
- package/lib/types/compat.d.ts +1 -1
- package/lib/types/host/antigravity-acp/adapter.d.ts +31 -0
- package/lib/types/host/antigravity-acp/adapter.d.ts.map +1 -1
- package/lib/types/host/antigravity-acp/catalog.d.ts.map +1 -1
- package/lib/types/host/antigravity-acp/mcp-bridge.d.ts +16 -0
- package/lib/types/host/antigravity-acp/mcp-bridge.d.ts.map +1 -1
- package/lib/types/host/antigravity-acp/routes.d.ts.map +1 -1
- package/lib/types/host/antigravity-acp/settings.d.ts +13 -2
- package/lib/types/host/antigravity-acp/settings.d.ts.map +1 -1
- package/lib/types/host/antigravity-acp/types.d.ts +12 -7
- package/lib/types/host/antigravity-acp/types.d.ts.map +1 -1
- package/lib/types/host/cache-warmup/contracts.d.ts +8 -2
- package/lib/types/host/cache-warmup/contracts.d.ts.map +1 -1
- package/lib/types/host/cache-warmup/install.d.ts.map +1 -1
- package/lib/types/host/cache-warmup/projection.d.ts.map +1 -1
- package/lib/types/host/cache-warmup/result-tool.d.ts.map +1 -1
- package/lib/types/host/common/i18n/en.d.ts.map +1 -1
- package/lib/types/host/common/i18n/ru.d.ts.map +1 -1
- package/lib/types/host/common/i18n/zh.d.ts +1 -0
- package/lib/types/host/common/i18n/zh.d.ts.map +1 -1
- package/lib/types/shared/antigravity-acp-contracts.d.ts +12 -0
- package/lib/types/shared/antigravity-acp-contracts.d.ts.map +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -292,7 +292,8 @@ const en = {
|
|
|
292
292
|
"glm.notSignedIn": "No {provider} account is signed in yet.",
|
|
293
293
|
"provider.antigravity-acp": "Antigravity (ACP)",
|
|
294
294
|
"antigravityAcp.notSignedIn": "Antigravity is not signed in. Start the sign-in from this card, or run agy acp --login in a terminal.",
|
|
295
|
-
"antigravityAcp.noBinary": "No usable Antigravity CLI (agy) was found and the official ACP server has not been downloaded."
|
|
295
|
+
"antigravityAcp.noBinary": "No usable Antigravity CLI (agy) was found and the official ACP server has not been downloaded.",
|
|
296
|
+
"antigravityAcp.nativeTool": "[Antigravity ran its own tool outside DSH permissions: {call}]\n"
|
|
296
297
|
};
|
|
297
298
|
//#endregion
|
|
298
299
|
//#region src/host/common/i18n/ru.ts
|
|
@@ -450,7 +451,8 @@ const ru = {
|
|
|
450
451
|
"glm.notSignedIn": "Вход в аккаунт {provider} ещё не выполнен.",
|
|
451
452
|
"provider.antigravity-acp": "Antigravity (ACP)",
|
|
452
453
|
"antigravityAcp.notSignedIn": "Вход в Antigravity не выполнен. Начните его на этой карточке или выполните agy acp --login в терминале.",
|
|
453
|
-
"antigravityAcp.noBinary": "Рабочий Antigravity CLI (agy) не найден, и официальный ACP-сервер ещё не загружен."
|
|
454
|
+
"antigravityAcp.noBinary": "Рабочий Antigravity CLI (agy) не найден, и официальный ACP-сервер ещё не загружен.",
|
|
455
|
+
"antigravityAcp.nativeTool": "[Antigravity использовал собственный инструмент в обход разрешений DSH: {call}]\n"
|
|
454
456
|
};
|
|
455
457
|
//#endregion
|
|
456
458
|
//#region src/host/common/i18n/zh.ts
|
|
@@ -617,7 +619,8 @@ const zh = {
|
|
|
617
619
|
"glm.notSignedIn": "还没有登录 {provider} 账号。",
|
|
618
620
|
"provider.antigravity-acp": "Antigravity(ACP)",
|
|
619
621
|
"antigravityAcp.notSignedIn": "还没有登录 Antigravity:请在设置页发起登录,或在终端执行 agy acp --login。",
|
|
620
|
-
"antigravityAcp.noBinary": "未找到可用的 Antigravity CLI(agy),且官方 ACP 服务端尚未下载。"
|
|
622
|
+
"antigravityAcp.noBinary": "未找到可用的 Antigravity CLI(agy),且官方 ACP 服务端尚未下载。",
|
|
623
|
+
"antigravityAcp.nativeTool": "[Antigravity 使用了它自带的工具,这次调用没有经过 DSH 权限:{call}]\n"
|
|
621
624
|
};
|
|
622
625
|
//#endregion
|
|
623
626
|
//#region src/host/common/i18n/t.ts
|
|
@@ -814,7 +817,7 @@ const ROUTE_PREFIX$5 = "/api/dsh-chatgpt-subscription";
|
|
|
814
817
|
* `test/responses-client.test.ts` asserts the two agree, so a release that
|
|
815
818
|
* forgets this constant fails the suite instead of shipping quietly.
|
|
816
819
|
*/
|
|
817
|
-
const PLUGIN_VERSION = "0.
|
|
820
|
+
const PLUGIN_VERSION = "0.73.0";
|
|
818
821
|
const CODEX_CHATGPT_PROVIDER_ID = "codex-chatgpt";
|
|
819
822
|
const CODEX_API_BASE = "https://chatgpt.com/backend-api/codex";
|
|
820
823
|
const CODEX_RESPONSES_URL = `${CODEX_API_BASE}/responses`;
|
|
@@ -24896,11 +24899,21 @@ var McpBridge = class {
|
|
|
24896
24899
|
await new Promise((resolve) => {
|
|
24897
24900
|
this.pendingResponses.set(callId, resolve);
|
|
24898
24901
|
}).then((outcome) => {
|
|
24902
|
+
const images = outcome.images ?? [];
|
|
24903
|
+
const content = images.length > 0 && outcome.text === "" ? [{
|
|
24904
|
+
type: "text",
|
|
24905
|
+
text: "[tool result carried an image]"
|
|
24906
|
+
}] : [{
|
|
24907
|
+
type: "text",
|
|
24908
|
+
text: outcome.text
|
|
24909
|
+
}];
|
|
24910
|
+
for (const image of images) content.push({
|
|
24911
|
+
type: "image",
|
|
24912
|
+
data: image.data,
|
|
24913
|
+
mimeType: image.mediaType
|
|
24914
|
+
});
|
|
24899
24915
|
respond(response, 200, jsonRpcResult(id, {
|
|
24900
|
-
content
|
|
24901
|
-
type: "text",
|
|
24902
|
-
text: outcome.text
|
|
24903
|
-
}],
|
|
24916
|
+
content,
|
|
24904
24917
|
...outcome.isError ? { isError: true } : {}
|
|
24905
24918
|
}));
|
|
24906
24919
|
});
|
|
@@ -25247,25 +25260,29 @@ function isEffort(value) {
|
|
|
25247
25260
|
* - `availableModels` - the tier ids the model picker itself shows
|
|
25248
25261
|
* (`gemini-4-carbon-low`).
|
|
25249
25262
|
*
|
|
25250
|
-
* A model's own ladder is the set of tier suffixes published for it
|
|
25251
|
-
* with
|
|
25252
|
-
*
|
|
25253
|
-
*
|
|
25254
|
-
*
|
|
25263
|
+
* A model's own ladder is the set of tier suffixes published for it. A model
|
|
25264
|
+
* with no suffixes (its id already carries the tier, such as
|
|
25265
|
+
* `gpt-oss-120b-medium`) publishes no ladder, and this function says so with an
|
|
25266
|
+
* empty list rather than borrowing a global one: `reasoning` is then simply not
|
|
25267
|
+
* offered for it.
|
|
25268
|
+
*
|
|
25269
|
+
* The `thought_level` option is deliberately NOT consulted here. That option
|
|
25270
|
+
* describes the levels of whichever model the session currently has selected -
|
|
25271
|
+
* Argon publishes low/medium/high - so intersecting every model's ladder with
|
|
25272
|
+
* it silently dropped the fourth level a newer model publishes for itself
|
|
25273
|
+
* (`gemini-4-hydrogen-xhigh` never reached the picker).
|
|
25255
25274
|
*
|
|
25256
25275
|
* @param options - The `model` option values, in server order.
|
|
25257
25276
|
* @param availableModels - The tier ids, in server order.
|
|
25258
|
-
* @param acceptedLevels - Levels the server's `thought_level` option accepts; empty when it published none.
|
|
25259
25277
|
* @returns One entry per selectable model, with its ladder least to greatest.
|
|
25260
25278
|
*/
|
|
25261
|
-
function collapseModels(options, availableModels
|
|
25279
|
+
function collapseModels(options, availableModels) {
|
|
25262
25280
|
const byBase = /* @__PURE__ */ new Map();
|
|
25263
25281
|
for (const option of options) for (const candidate of availableModels) {
|
|
25264
25282
|
const id = candidate.modelId;
|
|
25265
25283
|
if (!id.startsWith(option.value + "-")) continue;
|
|
25266
25284
|
const suffix = id.slice(option.value.length + 1);
|
|
25267
25285
|
if (!isEffort(suffix)) continue;
|
|
25268
|
-
if (acceptedLevels.length > 0 && !acceptedLevels.includes(suffix)) continue;
|
|
25269
25286
|
const levels = byBase.get(option.value) ?? /* @__PURE__ */ new Set();
|
|
25270
25287
|
levels.add(suffix);
|
|
25271
25288
|
byBase.set(option.value, levels);
|
|
@@ -25517,7 +25534,7 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
25517
25534
|
const images = await resolveRequestImages$1(options, this.options.attachments, signal).catch(() => NO_RESOLVED_IMAGES$3);
|
|
25518
25535
|
const effort = options.reasoningEffort === void 0 ? settings.defaultReasoningEffort ?? void 0 : String(options.reasoningEffort);
|
|
25519
25536
|
const live = this.live.get(dshSessionId);
|
|
25520
|
-
if (live !== void 0 && live.model === options.model && live.effort === effort && canContinue(options.messages, live.covered, live.fingerprint)) return this.continueTurn(live, options, signal, activity);
|
|
25537
|
+
if (live !== void 0 && live.model === options.model && live.effort === effort && canContinue(options.messages, live.covered, live.fingerprint)) return this.continueTurn(live, options, images, signal, activity);
|
|
25521
25538
|
if (live !== void 0) await this.closeTurn(live);
|
|
25522
25539
|
return this.startTurn(dshSessionId, options, settings, images, effort, signal, activity);
|
|
25523
25540
|
}
|
|
@@ -25540,8 +25557,7 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
25540
25557
|
} else client = this.spawn(launch, queue, activity);
|
|
25541
25558
|
const descriptor = await bridge.start();
|
|
25542
25559
|
const sessionId = await this.openSession(client, options, [descriptor], settings);
|
|
25543
|
-
|
|
25544
|
-
await this.applyConfig(client, sessionId, "model", options.model);
|
|
25560
|
+
await this.applyModelAndEffort(client, sessionId, options.model, effort);
|
|
25545
25561
|
const prompt = buildPrompt(options, images, 0);
|
|
25546
25562
|
if ((options.tools ?? []).length > 0) prompt.blocks.unshift({
|
|
25547
25563
|
type: "text",
|
|
@@ -25559,6 +25575,8 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
25559
25575
|
queue,
|
|
25560
25576
|
settled: void 0,
|
|
25561
25577
|
surfaced: /* @__PURE__ */ new Set(),
|
|
25578
|
+
notedNative: /* @__PURE__ */ new Set(),
|
|
25579
|
+
nativeToolPolicy: settings.nativeToolPolicy,
|
|
25562
25580
|
startedAt: this.now(),
|
|
25563
25581
|
awaitingHarness: false,
|
|
25564
25582
|
sessionsUsed: reusedSessions + 1
|
|
@@ -25574,8 +25592,8 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
25574
25592
|
}
|
|
25575
25593
|
}
|
|
25576
25594
|
/** Continue the live turn after the harness executed its tools. */
|
|
25577
|
-
continueTurn(turn, options, signal, activity) {
|
|
25578
|
-
const results = collectToolResults(options.messages.slice(turn.covered));
|
|
25595
|
+
continueTurn(turn, options, images, signal, activity) {
|
|
25596
|
+
const results = collectToolResults(options.messages.slice(turn.covered), images);
|
|
25579
25597
|
for (const callId of [...turn.surfaced]) {
|
|
25580
25598
|
const outcome = results.get(callId);
|
|
25581
25599
|
turn.bridge.settle(callId, outcome === void 0 ? {
|
|
@@ -25690,8 +25708,31 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
25690
25708
|
}
|
|
25691
25709
|
continue;
|
|
25692
25710
|
}
|
|
25693
|
-
if (type === "tool_call")
|
|
25694
|
-
|
|
25711
|
+
if (type === "tool_call" || type === "tool_call_update") {
|
|
25712
|
+
const native = readNativeToolCall(update);
|
|
25713
|
+
if (native !== void 0) {
|
|
25714
|
+
if (turn.nativeToolPolicy === "cancel") throw acpError("ACP_NATIVE_TOOLS_UNSUPPORTED", `Tool: ${native.name}.`);
|
|
25715
|
+
if (type === "tool_call" && !turn.notedNative.has(native.callId)) {
|
|
25716
|
+
turn.notedNative.add(native.callId);
|
|
25717
|
+
const note = nativeToolNote(native, readNativeToolArguments(update));
|
|
25718
|
+
if (textIndex === void 0) {
|
|
25719
|
+
textIndex = nextIndex;
|
|
25720
|
+
nextIndex += 1;
|
|
25721
|
+
yield {
|
|
25722
|
+
type: "block-start",
|
|
25723
|
+
index: textIndex,
|
|
25724
|
+
blockType: "text"
|
|
25725
|
+
};
|
|
25726
|
+
}
|
|
25727
|
+
text += note;
|
|
25728
|
+
yield {
|
|
25729
|
+
type: "text-delta",
|
|
25730
|
+
index: textIndex,
|
|
25731
|
+
text: note
|
|
25732
|
+
};
|
|
25733
|
+
}
|
|
25734
|
+
}
|
|
25735
|
+
}
|
|
25695
25736
|
continue;
|
|
25696
25737
|
}
|
|
25697
25738
|
const parked = turn.bridge.takeParked();
|
|
@@ -25773,17 +25814,33 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
25773
25814
|
}
|
|
25774
25815
|
}
|
|
25775
25816
|
}
|
|
25817
|
+
/**
|
|
25818
|
+
* Answer one `session/request_permission`.
|
|
25819
|
+
*
|
|
25820
|
+
* Two different requests arrive here and they do not deserve the same answer.
|
|
25821
|
+
* A request for a call the agent makes on the bridge is the agent asking to run
|
|
25822
|
+
* a DSH tool; the bridge already hands that call to the harness, which applies
|
|
25823
|
+
* its own permission presets, so refusing it here would deny the very route
|
|
25824
|
+
* this line exists to provide. A request for the agent's own tool is answered
|
|
25825
|
+
* by `permissionPolicy`, because nothing downstream of it is governed by DSH.
|
|
25826
|
+
*
|
|
25827
|
+
* @param params - The request payload, including the tool call it is about.
|
|
25828
|
+
* @returns The option id to select, or undefined to answer `cancelled`.
|
|
25829
|
+
*/
|
|
25830
|
+
async answerPermission(params) {
|
|
25831
|
+
const options = readPermissionOptions(params);
|
|
25832
|
+
const answer = () => options.find((option) => option.kind === "allow_once")?.optionId ?? options.find((option) => option.kind === "allow_always")?.optionId;
|
|
25833
|
+
const toolCall = asRecord$19(params.toolCall);
|
|
25834
|
+
if ((typeof toolCall?.name === "string" ? toolCall.name : "").startsWith(`mcp_dsh-bridge_`)) return answer();
|
|
25835
|
+
return (await this.options.settings.read()).permissionPolicy === "allow" ? answer() : void 0;
|
|
25836
|
+
}
|
|
25776
25837
|
spawn(launch, queue, activity) {
|
|
25777
25838
|
const handlers = {
|
|
25778
25839
|
onSessionUpdate: (_sessionId, update) => {
|
|
25779
25840
|
queue.push(update);
|
|
25780
25841
|
activity.pulse();
|
|
25781
25842
|
},
|
|
25782
|
-
onPermissionRequest: async (_sessionId, params) =>
|
|
25783
|
-
if ((await this.options.settings.read()).permissionPolicy !== "allow") return void 0;
|
|
25784
|
-
const options = readPermissionOptions(params);
|
|
25785
|
-
return options.find((option) => option.kind === "allow_once")?.optionId ?? options.find((option) => option.kind === "allow_always")?.optionId;
|
|
25786
|
-
},
|
|
25843
|
+
onPermissionRequest: async (_sessionId, params) => this.answerPermission(params),
|
|
25787
25844
|
onExit: (detail) => {
|
|
25788
25845
|
queue.push({
|
|
25789
25846
|
sessionUpdate: "process_exit",
|
|
@@ -25841,15 +25898,41 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
25841
25898
|
}
|
|
25842
25899
|
async applyConfig(client, sessionId, configId, value) {
|
|
25843
25900
|
try {
|
|
25844
|
-
await client.request("session/set_config_option", {
|
|
25901
|
+
return asRecord$19(await client.request("session/set_config_option", {
|
|
25845
25902
|
sessionId,
|
|
25846
25903
|
configId,
|
|
25847
25904
|
value
|
|
25848
|
-
});
|
|
25905
|
+
}));
|
|
25849
25906
|
} catch (error) {
|
|
25850
25907
|
throw new LlmError(`Antigravity ACP rejected ${configId} "${value}": ${error instanceof Error ? error.message : String(error)}`, "UNSUPPORTED_OPTION");
|
|
25851
25908
|
}
|
|
25852
25909
|
}
|
|
25910
|
+
/**
|
|
25911
|
+
* Select the model, then the thinking level, falling back to the model variant
|
|
25912
|
+
* the server publishes for a level the current model does not list.
|
|
25913
|
+
*
|
|
25914
|
+
* `thought_level` is scoped to the model the session already has selected, so
|
|
25915
|
+
* it is applied after the model. The previous order set the level first and
|
|
25916
|
+
* replaced the model after it, which kept the level of the model the session
|
|
25917
|
+
* started on. Some models publish a level as a model variant instead of a
|
|
25918
|
+
* thinking level (`gemini-4-hydrogen-xhigh`): selecting that variant is what
|
|
25919
|
+
* makes the server accept the fourth level.
|
|
25920
|
+
*
|
|
25921
|
+
* @param client - The connection running this turn.
|
|
25922
|
+
* @param sessionId - The ACP session the turn belongs to.
|
|
25923
|
+
* @param model - The model the caller asked for.
|
|
25924
|
+
* @param effort - The requested thinking level, when the caller or settings named one.
|
|
25925
|
+
*/
|
|
25926
|
+
async applyModelAndEffort(client, sessionId, model, effort) {
|
|
25927
|
+
const afterModel = await this.applyConfig(client, sessionId, "model", model);
|
|
25928
|
+
if (effort === void 0) return;
|
|
25929
|
+
const levels = configOptionValues(afterModel, "thought_level");
|
|
25930
|
+
if (levels === void 0 || levels.includes(effort)) {
|
|
25931
|
+
await this.applyConfigQuietly(client, sessionId, "thought_level", effort);
|
|
25932
|
+
return;
|
|
25933
|
+
}
|
|
25934
|
+
await this.applyConfigQuietly(client, sessionId, "model", `${model}-${effort}`);
|
|
25935
|
+
}
|
|
25853
25936
|
async applyConfigQuietly(client, sessionId, configId, value) {
|
|
25854
25937
|
await client.request("session/set_config_option", {
|
|
25855
25938
|
sessionId,
|
|
@@ -25922,11 +26005,7 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
|
|
|
25922
26005
|
queue.push(update);
|
|
25923
26006
|
activity.pulse();
|
|
25924
26007
|
},
|
|
25925
|
-
onPermissionRequest: async (_sessionId, params) =>
|
|
25926
|
-
if ((await this.options.settings.read()).permissionPolicy !== "allow") return void 0;
|
|
25927
|
-
const options = readPermissionOptions(params);
|
|
25928
|
-
return options.find((option) => option.kind === "allow_once")?.optionId ?? options.find((option) => option.kind === "allow_always")?.optionId;
|
|
25929
|
-
},
|
|
26008
|
+
onPermissionRequest: async (_sessionId, params) => this.answerPermission(params),
|
|
25930
26009
|
onExit: (detail) => {
|
|
25931
26010
|
queue.push({
|
|
25932
26011
|
sessionUpdate: "process_exit",
|
|
@@ -25997,15 +26076,43 @@ const BRIDGE_ONLY_INSTRUCTION = [
|
|
|
25997
26076
|
"For every file read, file change, command or other action, call one of the provided tools instead.",
|
|
25998
26077
|
"If no provided tool covers what you need, stop and say so rather than acting directly."
|
|
25999
26078
|
].join(" ");
|
|
26000
|
-
/**
|
|
26001
|
-
|
|
26079
|
+
/**
|
|
26080
|
+
* Tool results keyed by the call id they answer, from the newly appended messages.
|
|
26081
|
+
*
|
|
26082
|
+
* A result is not always text. `read_image` and a screenshot tool answer with an
|
|
26083
|
+
* image block, and keeping only the text half of that handed the agent an empty
|
|
26084
|
+
* string - a successful call it could not tell from a tool that returned
|
|
26085
|
+
* nothing. Image blocks are therefore resolved and carried back as MCP `image`
|
|
26086
|
+
* content; the byte budget is the same one the prompt uses, because both paths
|
|
26087
|
+
* end up inline in the agent's context.
|
|
26088
|
+
*
|
|
26089
|
+
* @param messages - The messages appended since the turn last handed work over.
|
|
26090
|
+
* @param images - Images resolved for this request, keyed by attachment id.
|
|
26091
|
+
* @returns One outcome per answered call id.
|
|
26092
|
+
*/
|
|
26093
|
+
function collectToolResults(messages, images) {
|
|
26002
26094
|
const results = /* @__PURE__ */ new Map();
|
|
26003
26095
|
for (const message of messages) for (const block of message.content) {
|
|
26004
26096
|
if (block.type !== "tool-result") continue;
|
|
26005
26097
|
const result = block;
|
|
26006
26098
|
const text = result.content.map((entry) => entry.type === "text" ? entry.text : "").filter((part) => part !== "").join("\n");
|
|
26099
|
+
const carried = [];
|
|
26100
|
+
let budget = ACP_MAX_INLINE_IMAGE_BYTES;
|
|
26101
|
+
for (const entry of result.content) {
|
|
26102
|
+
if (entry.type !== "image") continue;
|
|
26103
|
+
const inline = imageBlockToInline$2(entry, images);
|
|
26104
|
+
if (inline === void 0) continue;
|
|
26105
|
+
const bytes = Math.ceil(inline.data.length * .75);
|
|
26106
|
+
if (bytes > budget) continue;
|
|
26107
|
+
budget -= bytes;
|
|
26108
|
+
carried.push({
|
|
26109
|
+
mediaType: inline.mediaType,
|
|
26110
|
+
data: inline.data
|
|
26111
|
+
});
|
|
26112
|
+
}
|
|
26007
26113
|
results.set(result.toolCallId, {
|
|
26008
26114
|
text,
|
|
26115
|
+
...carried.length === 0 ? {} : { images: carried },
|
|
26009
26116
|
isError: result.isError === true
|
|
26010
26117
|
});
|
|
26011
26118
|
}
|
|
@@ -26014,32 +26121,78 @@ function collectToolResults(messages) {
|
|
|
26014
26121
|
/**
|
|
26015
26122
|
* Refuse the sampling controls ACP cannot express.
|
|
26016
26123
|
*
|
|
26124
|
+
* `temperature` and `stop` change what the model produces, so accepting a request
|
|
26125
|
+
* that carries one and then ignoring it would answer a different question than
|
|
26126
|
+
* the caller asked. `maxTokens` is deliberately not in that set: it bounds an
|
|
26127
|
+
* answer the caller still reads in full, and the harness's own auxiliary calls
|
|
26128
|
+
* (session titles, compaction) always send one. Refusing it made every title on
|
|
26129
|
+
* this line fail; dropping it costs only the bound, and the bound is the one
|
|
26130
|
+
* thing ACP genuinely cannot express.
|
|
26131
|
+
*
|
|
26017
26132
|
* @param options - The normalized request.
|
|
26018
26133
|
*/
|
|
26019
26134
|
function assertNoSamplingControls(options) {
|
|
26020
26135
|
const unsupported = [];
|
|
26021
26136
|
if (options.temperature !== void 0) unsupported.push("temperature");
|
|
26022
|
-
if (options.maxTokens !== void 0) unsupported.push("maxTokens");
|
|
26023
26137
|
if (options.stop !== void 0 && options.stop.length > 0) unsupported.push("stop");
|
|
26024
26138
|
if (unsupported.length === 0) return;
|
|
26025
|
-
throw acpError("ACP_UNSUPPORTED_OPTION", `Unsupported: ${unsupported.join(", ")}. Antigravity through ACP has no sampling controls; choose a model variant instead of a
|
|
26139
|
+
throw acpError("ACP_UNSUPPORTED_OPTION", `Unsupported: ${unsupported.join(", ")}. Antigravity through ACP has no sampling controls; choose a model variant instead of a stop sequence.`);
|
|
26026
26140
|
}
|
|
26027
26141
|
/**
|
|
26028
|
-
*
|
|
26142
|
+
* Read one `tool_call`/`tool_call_update` as the agent's own tool, or as the bridge.
|
|
26029
26143
|
*
|
|
26030
26144
|
* The official server prefixes its MCP tool names with the server name it was
|
|
26031
|
-
* given (`mcp_dsh-bridge_<tool>`); everything else is the agent's own tool.
|
|
26032
|
-
*
|
|
26033
|
-
*
|
|
26034
|
-
* this harness's control. That is the honest limit: ACP has no way to refuse a
|
|
26035
|
-
* native tool in advance.
|
|
26145
|
+
* given (`mcp_dsh-bridge_<tool>`); everything else is the agent's own tool. What
|
|
26146
|
+
* the caller does with that answer depends on `nativeToolPolicy`: this function
|
|
26147
|
+
* only classifies, so the two policies share one definition of "native".
|
|
26036
26148
|
*
|
|
26037
26149
|
* @param update - One `session/update` payload.
|
|
26150
|
+
* @returns The call's id and name when it is a native call; undefined for the bridge.
|
|
26038
26151
|
*/
|
|
26039
|
-
function
|
|
26152
|
+
function readNativeToolCall(update) {
|
|
26040
26153
|
const name = typeof update.name === "string" ? update.name : "";
|
|
26041
|
-
if (name === "" || name.startsWith(`mcp_dsh-bridge_`)) return;
|
|
26042
|
-
|
|
26154
|
+
if (name === "" || name.startsWith(`mcp_dsh-bridge_`)) return void 0;
|
|
26155
|
+
return {
|
|
26156
|
+
callId: typeof update.toolCallId === "string" ? update.toolCallId : "",
|
|
26157
|
+
name
|
|
26158
|
+
};
|
|
26159
|
+
}
|
|
26160
|
+
/**
|
|
26161
|
+
* The transcript line that records one native tool call.
|
|
26162
|
+
*
|
|
26163
|
+
* Written into the answer rather than logged, because the user is the one who
|
|
26164
|
+
* has to know the action did not pass through DSH. It names the tool and its
|
|
26165
|
+
* arguments and nothing else: a note that paraphrased the arguments would be a
|
|
26166
|
+
* second, unverified account of what the agent did.
|
|
26167
|
+
*
|
|
26168
|
+
* @param native - The call being reported.
|
|
26169
|
+
* @param args - Its raw argument text, when the update carried one.
|
|
26170
|
+
* @returns One sentence, ending in a newline so the model's own text starts fresh.
|
|
26171
|
+
*/
|
|
26172
|
+
function nativeToolNote(native, args) {
|
|
26173
|
+
return t("antigravityAcp.nativeTool", { call: args === "" ? native.name : `${native.name} ${args}` });
|
|
26174
|
+
}
|
|
26175
|
+
/**
|
|
26176
|
+
* The raw argument text one native call was reported with.
|
|
26177
|
+
*
|
|
26178
|
+
* ACP spells the arguments `rawInput` on `tool_call`, and the live server also
|
|
26179
|
+
* sends `title` (a one-line description of the action) rather than a JSON body.
|
|
26180
|
+
* Both are read, in that order, and neither is invented: a call reported without
|
|
26181
|
+
* either is shown by name alone.
|
|
26182
|
+
*
|
|
26183
|
+
* @param update - One `session/update` payload.
|
|
26184
|
+
* @returns The argument or title text, or an empty string when it carried none.
|
|
26185
|
+
*/
|
|
26186
|
+
function readNativeToolArguments(update) {
|
|
26187
|
+
const raw = update.rawInput;
|
|
26188
|
+
if (typeof raw === "string" && raw !== "") return raw;
|
|
26189
|
+
if (typeof raw === "object" && raw !== null) try {
|
|
26190
|
+
return JSON.stringify(raw);
|
|
26191
|
+
} catch {
|
|
26192
|
+
return "";
|
|
26193
|
+
}
|
|
26194
|
+
const title = update.title;
|
|
26195
|
+
return typeof title === "string" ? title : "";
|
|
26043
26196
|
}
|
|
26044
26197
|
/**
|
|
26045
26198
|
* Read one `usage_update` as context occupancy.
|
|
@@ -26175,6 +26328,27 @@ function delay(ms) {
|
|
|
26175
26328
|
function asRecord$19(value) {
|
|
26176
26329
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
26177
26330
|
}
|
|
26331
|
+
/**
|
|
26332
|
+
* The values one `session/set_config_option` result lists for a config option.
|
|
26333
|
+
*
|
|
26334
|
+
* @param result - The response payload, when the server sent one.
|
|
26335
|
+
* @param configId - Option id to read, such as `thought_level`.
|
|
26336
|
+
* @returns The accepted values, or undefined when the answer carried no options.
|
|
26337
|
+
*/
|
|
26338
|
+
function configOptionValues(result, configId) {
|
|
26339
|
+
const options = result?.configOptions;
|
|
26340
|
+
if (!Array.isArray(options)) return void 0;
|
|
26341
|
+
for (const entry of options) {
|
|
26342
|
+
const record = asRecord$19(entry);
|
|
26343
|
+
if (record?.id !== configId) continue;
|
|
26344
|
+
const values = record.options;
|
|
26345
|
+
if (!Array.isArray(values)) return void 0;
|
|
26346
|
+
return values.flatMap((option) => {
|
|
26347
|
+
const value = asRecord$19(option)?.value;
|
|
26348
|
+
return typeof value === "string" ? [value] : [];
|
|
26349
|
+
});
|
|
26350
|
+
}
|
|
26351
|
+
}
|
|
26178
26352
|
/** Where the settings document lives. */
|
|
26179
26353
|
function antigravityAcpSettingsPath() {
|
|
26180
26354
|
return path.join(dshHomeDir(), "storages", "antigravity-acp-settings.json");
|
|
@@ -26185,7 +26359,8 @@ function defaultAntigravityAcpSettings() {
|
|
|
26185
26359
|
enabled: true,
|
|
26186
26360
|
enabledModelIds: null,
|
|
26187
26361
|
defaultReasoningEffort: null,
|
|
26188
|
-
permissionPolicy: "
|
|
26362
|
+
permissionPolicy: "allow",
|
|
26363
|
+
nativeToolPolicy: "allow",
|
|
26189
26364
|
binaryPath: null
|
|
26190
26365
|
};
|
|
26191
26366
|
}
|
|
@@ -26194,7 +26369,9 @@ function defaultAntigravityAcpSettings() {
|
|
|
26194
26369
|
*
|
|
26195
26370
|
* A field that is present but of the wrong type is treated as absent rather than
|
|
26196
26371
|
* as its zero value: a corrupt `enabledModelIds` must not become "every model
|
|
26197
|
-
* off", and a corrupt
|
|
26372
|
+
* off", and a corrupt policy field falls back to that policy's own default
|
|
26373
|
+
* instead of to whichever value a `=== 'x' ? … : …` happens to have in the
|
|
26374
|
+
* negative branch.
|
|
26198
26375
|
*
|
|
26199
26376
|
* @param value - Parsed JSON.
|
|
26200
26377
|
* @returns The settings the document describes, with defaults for anything unreadable.
|
|
@@ -26208,7 +26385,8 @@ function parseAntigravityAcpSettings(value) {
|
|
|
26208
26385
|
enabled: typeof record.enabled === "boolean" ? record.enabled : false,
|
|
26209
26386
|
enabledModelIds,
|
|
26210
26387
|
defaultReasoningEffort: typeof record.defaultReasoningEffort === "string" ? record.defaultReasoningEffort : null,
|
|
26211
|
-
permissionPolicy: record.permissionPolicy === "
|
|
26388
|
+
permissionPolicy: record.permissionPolicy === "reject" ? "reject" : "allow",
|
|
26389
|
+
nativeToolPolicy: record.nativeToolPolicy === "cancel" ? "cancel" : "allow",
|
|
26212
26390
|
binaryPath: typeof record.binaryPath === "string" && record.binaryPath !== "" ? record.binaryPath : null,
|
|
26213
26391
|
...typeof record.lastTurnAt === "number" && Number.isFinite(record.lastTurnAt) ? { lastTurnAt: record.lastTurnAt } : {}
|
|
26214
26392
|
};
|
|
@@ -26267,6 +26445,7 @@ var AntigravityAcpSettingsStore = class {
|
|
|
26267
26445
|
...patch.enabledModelIds === void 0 ? {} : { enabledModelIds: patch.enabledModelIds },
|
|
26268
26446
|
...patch.defaultReasoningEffort === void 0 ? {} : { defaultReasoningEffort: patch.defaultReasoningEffort },
|
|
26269
26447
|
...patch.permissionPolicy === void 0 ? {} : { permissionPolicy: patch.permissionPolicy },
|
|
26448
|
+
...patch.nativeToolPolicy === void 0 ? {} : { nativeToolPolicy: patch.nativeToolPolicy },
|
|
26270
26449
|
...patch.binaryPath === void 0 ? {} : { binaryPath: patch.binaryPath },
|
|
26271
26450
|
...patch.lastTurnAt === void 0 ? {} : { lastTurnAt: patch.lastTurnAt }
|
|
26272
26451
|
};
|
|
@@ -26394,10 +26573,7 @@ async function readCatalogFrom(client, signal) {
|
|
|
26394
26573
|
session = await create();
|
|
26395
26574
|
}
|
|
26396
26575
|
const availableModels = readAvailableModels(asRecord$18(session.models)?.availableModels ?? session.availableModels);
|
|
26397
|
-
const
|
|
26398
|
-
const modelOption = configOptions.find((entry) => typeof entry === "object" && entry !== null && entry.id === "model");
|
|
26399
|
-
const thoughtOption = configOptions.find((entry) => typeof entry === "object" && entry !== null && entry.id === "thought_level");
|
|
26400
|
-
const models = collapseModels(readOptionValues(modelOption), availableModels, readOptionValues(thoughtOption).map((option) => option.value));
|
|
26576
|
+
const models = collapseModels(readOptionValues((Array.isArray(session.configOptions) ? session.configOptions : []).find((entry) => typeof entry === "object" && entry !== null && entry.id === "model")), availableModels);
|
|
26401
26577
|
const tier = readTier$1(session._meta);
|
|
26402
26578
|
return {
|
|
26403
26579
|
models,
|
|
@@ -26920,6 +27096,7 @@ async function readStatus(options) {
|
|
|
26920
27096
|
enabledModelIds: settings.enabledModelIds,
|
|
26921
27097
|
defaultReasoningEffort: settings.defaultReasoningEffort,
|
|
26922
27098
|
permissionPolicy: settings.permissionPolicy,
|
|
27099
|
+
nativeToolPolicy: settings.nativeToolPolicy,
|
|
26923
27100
|
catalogSynced: catalog !== void 0 && (catalog.fromSnapshot === false || Date.now() - catalog.fetchedAt < CATALOG_FRESHNESS_MS),
|
|
26924
27101
|
...options.usage() === void 0 ? {} : { usage: options.usage() },
|
|
26925
27102
|
...options.occupancy?.() === void 0 ? {} : { occupancy: options.occupancy() },
|
|
@@ -27092,13 +27269,18 @@ function readSettingsUpdate(body) {
|
|
|
27092
27269
|
if (policy !== "reject" && policy !== "allow") return void 0;
|
|
27093
27270
|
update.permissionPolicy = policy;
|
|
27094
27271
|
}
|
|
27272
|
+
if (body.nativeToolPolicy !== void 0) {
|
|
27273
|
+
const policy = body.nativeToolPolicy;
|
|
27274
|
+
if (policy !== "allow" && policy !== "cancel") return void 0;
|
|
27275
|
+
update.nativeToolPolicy = policy;
|
|
27276
|
+
}
|
|
27095
27277
|
if (body.binaryPath !== void 0) if (body.binaryPath === null) update.binaryPath = null;
|
|
27096
27278
|
else if (typeof body.binaryPath === "string") update.binaryPath = body.binaryPath;
|
|
27097
27279
|
else return;
|
|
27098
27280
|
return update;
|
|
27099
27281
|
}
|
|
27100
27282
|
function sameSettings(left, right) {
|
|
27101
|
-
return left.enabled === right.enabled && left.defaultReasoningEffort === right.defaultReasoningEffort && left.permissionPolicy === right.permissionPolicy && left.binaryPath === right.binaryPath && JSON.stringify(left.enabledModelIds) === JSON.stringify(right.enabledModelIds);
|
|
27283
|
+
return left.enabled === right.enabled && left.defaultReasoningEffort === right.defaultReasoningEffort && left.permissionPolicy === right.permissionPolicy && left.nativeToolPolicy === right.nativeToolPolicy && left.binaryPath === right.binaryPath && JSON.stringify(left.enabledModelIds) === JSON.stringify(right.enabledModelIds);
|
|
27102
27284
|
}
|
|
27103
27285
|
function sendJson$10(response, status, body) {
|
|
27104
27286
|
const payload = JSON.stringify(body);
|
|
@@ -27529,8 +27711,14 @@ const CACHE_WARMUP_DEFAULTS = {
|
|
|
27529
27711
|
pageLimitMax: 512,
|
|
27530
27712
|
/** 分页 maxBytes 默认值(字节)。 */
|
|
27531
27713
|
pageMaxBytesDefault: 16 * 1024,
|
|
27532
|
-
/**
|
|
27533
|
-
|
|
27714
|
+
/**
|
|
27715
|
+
* 分页 maxBytes 上限(字节)。
|
|
27716
|
+
*
|
|
27717
|
+
* 25 KB,不是越大越好:补读的每一页都会原样进入下一轮的提示,一次 45 KB 的
|
|
27718
|
+
* 整页重读等于把「省下来的」又付一遍。分页的用途是**精确补读**,不是把整份
|
|
27719
|
+
* 原文再抄一遍;真需要看完全文就多翻几页,每页都要过模型的门。
|
|
27720
|
+
*/
|
|
27721
|
+
pageMaxBytesMax: 25 * 1024,
|
|
27534
27722
|
/** usage registry 的 session 数上限。 */
|
|
27535
27723
|
maxUsageSessions: 256,
|
|
27536
27724
|
/** 每 session 保留的用量报告条数上限。 */
|
|
@@ -29616,6 +29804,197 @@ function buildCompositeSections(entries) {
|
|
|
29616
29804
|
return sections;
|
|
29617
29805
|
}
|
|
29618
29806
|
/**
|
|
29807
|
+
* 识别 `code_run` 里 `tools.read` 的批量返回:`[{ path, offset?, lines: [{ number, text }] }]`。
|
|
29808
|
+
*
|
|
29809
|
+
* 只认**完整、连续、递增**的行号数组;任何一条记录形状不符就整批放弃。
|
|
29810
|
+
* @param value - 候选数组。
|
|
29811
|
+
* @returns 识别出的记录,或 undefined。
|
|
29812
|
+
*/
|
|
29813
|
+
function canonicalBatchReadRecords(value) {
|
|
29814
|
+
const records = [];
|
|
29815
|
+
for (const entry of value) {
|
|
29816
|
+
if (!isPlainRecord$1(entry)) return void 0;
|
|
29817
|
+
if (typeof entry.path !== "string" || entry.path.trim() === "") return void 0;
|
|
29818
|
+
if (!Array.isArray(entry.lines) || entry.lines.length === 0) return void 0;
|
|
29819
|
+
let first = Number.POSITIVE_INFINITY;
|
|
29820
|
+
let last = Number.NEGATIVE_INFINITY;
|
|
29821
|
+
let previous = -1;
|
|
29822
|
+
for (const line of entry.lines) {
|
|
29823
|
+
if (!isPlainRecord$1(line)) return void 0;
|
|
29824
|
+
if (!Number.isSafeInteger(line.number)) return void 0;
|
|
29825
|
+
if (typeof line.text !== "string") return void 0;
|
|
29826
|
+
const number = line.number;
|
|
29827
|
+
if (number <= previous) return void 0;
|
|
29828
|
+
previous = number;
|
|
29829
|
+
if (number < first) first = number;
|
|
29830
|
+
if (number > last) last = number;
|
|
29831
|
+
}
|
|
29832
|
+
records.push({
|
|
29833
|
+
path: entry.path,
|
|
29834
|
+
first,
|
|
29835
|
+
last,
|
|
29836
|
+
lineCount: entry.lines.length
|
|
29837
|
+
});
|
|
29838
|
+
}
|
|
29839
|
+
return records.length > 0 ? records : void 0;
|
|
29840
|
+
}
|
|
29841
|
+
/**
|
|
29842
|
+
* 识别 `code_run` 里批量改写的返回:`[{ path, before, after }]`。
|
|
29843
|
+
*
|
|
29844
|
+
* `before`/`after` 是模型自己刚写进程序的入参,回显它们不携带任何新信息:
|
|
29845
|
+
* 这正是「同一条内容在上下文里出现两次」的那一类浪费。只保留路径与篇幅,
|
|
29846
|
+
* 需要正文时用 `read` 或 ref 补读。
|
|
29847
|
+
* @param value - 候选数组。
|
|
29848
|
+
* @returns 识别出的记录,或 undefined。
|
|
29849
|
+
*/
|
|
29850
|
+
function canonicalBatchEditRecords(value) {
|
|
29851
|
+
const records = [];
|
|
29852
|
+
for (const entry of value) {
|
|
29853
|
+
if (!isPlainRecord$1(entry)) return void 0;
|
|
29854
|
+
if (typeof entry.path !== "string" || entry.path.trim() === "") return void 0;
|
|
29855
|
+
if (typeof entry.before !== "string" || typeof entry.after !== "string") return void 0;
|
|
29856
|
+
if (entry.before === "" && entry.after === "") return void 0;
|
|
29857
|
+
records.push({
|
|
29858
|
+
path: entry.path,
|
|
29859
|
+
beforeChars: entry.before.length,
|
|
29860
|
+
afterChars: entry.after.length
|
|
29861
|
+
});
|
|
29862
|
+
}
|
|
29863
|
+
return records.length > 0 ? records : void 0;
|
|
29864
|
+
}
|
|
29865
|
+
/** 批量读取的预览:每个文件的路径、行范围与行数(完整集合)。 */
|
|
29866
|
+
function buildBatchReadSections(records, maxChars) {
|
|
29867
|
+
const lines = [];
|
|
29868
|
+
let used = 0;
|
|
29869
|
+
let shown = 0;
|
|
29870
|
+
for (const record of records) {
|
|
29871
|
+
const line = ` ${clip(record.path, 140)} lines ${record.first}-${record.last} (${record.lineCount})`;
|
|
29872
|
+
if (shown > 0 && used + line.length + 1 > maxChars) break;
|
|
29873
|
+
lines.push(line);
|
|
29874
|
+
used += line.length + 1;
|
|
29875
|
+
shown += 1;
|
|
29876
|
+
}
|
|
29877
|
+
const sections = [{ lines: [`reads: ${records.length} (complete set; source kept verbatim in the ref)`] }, { lines }];
|
|
29878
|
+
if (shown < records.length) sections.push({ lines: [` … ${records.length - shown} more files (full list via ref)`] });
|
|
29879
|
+
return sections;
|
|
29880
|
+
}
|
|
29881
|
+
/** 批量改写的预览:每个文件的路径与前后篇幅(完整集合,正文不回显)。 */
|
|
29882
|
+
function buildBatchEditSections(records, maxChars) {
|
|
29883
|
+
const lines = [];
|
|
29884
|
+
let used = 0;
|
|
29885
|
+
let shown = 0;
|
|
29886
|
+
for (const record of records) {
|
|
29887
|
+
const line = ` ${clip(record.path, 140)} before ${record.beforeChars}ch → after ${record.afterChars}ch`;
|
|
29888
|
+
if (shown > 0 && used + line.length + 1 > maxChars) break;
|
|
29889
|
+
lines.push(line);
|
|
29890
|
+
used += line.length + 1;
|
|
29891
|
+
shown += 1;
|
|
29892
|
+
}
|
|
29893
|
+
const sections = [{ lines: [`edits: ${records.length} (complete set; before/after bodies kept verbatim in the ref)`] }, { lines }];
|
|
29894
|
+
if (shown < records.length) sections.push({ lines: [` … ${records.length - shown} more files (full list via ref)`] });
|
|
29895
|
+
return sections;
|
|
29896
|
+
}
|
|
29897
|
+
/** 一行带行号的源码(`1: ...`、`1\t...`)。用于识别「路径 → 带行号正文」映射。 */
|
|
29898
|
+
function numberedTextRange(text) {
|
|
29899
|
+
let first = Number.POSITIVE_INFINITY;
|
|
29900
|
+
let last = Number.NEGATIVE_INFINITY;
|
|
29901
|
+
let count = 0;
|
|
29902
|
+
let previous = 0;
|
|
29903
|
+
for (const raw of text.split("\n")) {
|
|
29904
|
+
if (raw.trim() === "") continue;
|
|
29905
|
+
const matched = READ_NUMBERED_LINE.exec(raw);
|
|
29906
|
+
if (matched === null) return void 0;
|
|
29907
|
+
const number = Number(matched[1]);
|
|
29908
|
+
if (!Number.isSafeInteger(number) || number <= previous) return void 0;
|
|
29909
|
+
previous = number;
|
|
29910
|
+
if (number < first) first = number;
|
|
29911
|
+
if (number > last) last = number;
|
|
29912
|
+
count += 1;
|
|
29913
|
+
}
|
|
29914
|
+
if (count === 0) return void 0;
|
|
29915
|
+
return {
|
|
29916
|
+
first,
|
|
29917
|
+
last,
|
|
29918
|
+
lines: count
|
|
29919
|
+
};
|
|
29920
|
+
}
|
|
29921
|
+
/**
|
|
29922
|
+
* `code_run` 批量工具的投影:数组与「路径 → 正文」映射。
|
|
29923
|
+
*
|
|
29924
|
+
* 真实会话里最贵的工具结果几乎全是这一种:模型在程序里批量 `tools.grep` /
|
|
29925
|
+
* `tools.read` / 批量改写,然后把整个数组 `return` 出来,恰好撞上宿主 50K 字符
|
|
29926
|
+
* 渲染上限。它们不是「无法解析的大文本」,而是**结构完全已知的批量结果**。
|
|
29927
|
+
*
|
|
29928
|
+
* 四条闸门(任何一条不满足就交回原文):
|
|
29929
|
+
* - 只认 PTC 家族的程序传输工具,别的工具的同形 JSON 与我们无关;
|
|
29930
|
+
* - 批量读取只认行号完整、连续递增的记录;源码正文只在两种情况下换成大纲:
|
|
29931
|
+
* 明确导航任务,或这条结果**已经被宿主截断**(尾部早已不在上下文里,
|
|
29932
|
+
* 此时「完整索引 + ref 全文」严格优于「半截正文」);
|
|
29933
|
+
* - 批量改写必须是 `{ path, before, after }` 三字段都在的字符串;
|
|
29934
|
+
* - 结果必须真的超过当前预算 —— 小结果不动,避免无谓地扰动前缀。
|
|
29935
|
+
* @param text - 工具结果原文。
|
|
29936
|
+
* @param toolName - 工具名。
|
|
29937
|
+
* @param budgetMaxChars - 当前预览预算的字符上限。
|
|
29938
|
+
* @param navigation - 是否明确导航任务。
|
|
29939
|
+
* @param spilled - 原文是否已被宿主截断并留有 spill 提示。
|
|
29940
|
+
* @returns 投影计划,或 undefined(交回原文)。
|
|
29941
|
+
*/
|
|
29942
|
+
function planBatchToolResult(text, toolName, budgetMaxChars, navigation, spilled) {
|
|
29943
|
+
if (!isPtcTransportName(toolName)) return void 0;
|
|
29944
|
+
if (text.length <= budgetMaxChars) return void 0;
|
|
29945
|
+
let value;
|
|
29946
|
+
try {
|
|
29947
|
+
value = JSON.parse(text);
|
|
29948
|
+
} catch {
|
|
29949
|
+
return;
|
|
29950
|
+
}
|
|
29951
|
+
if (Array.isArray(value)) {
|
|
29952
|
+
const grep = canonicalGrepMatches(value);
|
|
29953
|
+
if (grep !== void 0) return {
|
|
29954
|
+
kind: "preview",
|
|
29955
|
+
strategy: "grep-results",
|
|
29956
|
+
sections: buildGrepEnvelopeSections(grep)
|
|
29957
|
+
};
|
|
29958
|
+
const edits = canonicalBatchEditRecords(value);
|
|
29959
|
+
if (edits !== void 0) return {
|
|
29960
|
+
kind: "preview",
|
|
29961
|
+
strategy: "batch-results",
|
|
29962
|
+
sections: buildBatchEditSections(edits, Math.max(400, budgetMaxChars - 200))
|
|
29963
|
+
};
|
|
29964
|
+
if (navigation === true || spilled) {
|
|
29965
|
+
const reads = canonicalBatchReadRecords(value);
|
|
29966
|
+
if (reads !== void 0) return {
|
|
29967
|
+
kind: "preview",
|
|
29968
|
+
strategy: "batch-results",
|
|
29969
|
+
sections: buildBatchReadSections(reads, Math.max(400, budgetMaxChars - 200))
|
|
29970
|
+
};
|
|
29971
|
+
}
|
|
29972
|
+
return;
|
|
29973
|
+
}
|
|
29974
|
+
if (!isPlainRecord$1(value)) return void 0;
|
|
29975
|
+
if (navigation !== true && !spilled) return void 0;
|
|
29976
|
+
const keys = Object.keys(value);
|
|
29977
|
+
if (keys.length < 2) return void 0;
|
|
29978
|
+
const records = [];
|
|
29979
|
+
for (const key of keys) {
|
|
29980
|
+
const body = value[key];
|
|
29981
|
+
if (typeof body !== "string") return void 0;
|
|
29982
|
+
const range = numberedTextRange(body);
|
|
29983
|
+
if (range === void 0) return void 0;
|
|
29984
|
+
records.push({
|
|
29985
|
+
path: key,
|
|
29986
|
+
first: range.first,
|
|
29987
|
+
last: range.last,
|
|
29988
|
+
lineCount: range.lines
|
|
29989
|
+
});
|
|
29990
|
+
}
|
|
29991
|
+
return {
|
|
29992
|
+
kind: "preview",
|
|
29993
|
+
strategy: "batch-results",
|
|
29994
|
+
sections: buildBatchReadSections(records, Math.max(400, budgetMaxChars - 200))
|
|
29995
|
+
};
|
|
29996
|
+
}
|
|
29997
|
+
/**
|
|
29619
29998
|
* 复合 JSON 信封的投影计划。
|
|
29620
29999
|
*
|
|
29621
30000
|
* 一份结果里混着多个成员(grep + read + glob + log)时,逐个成员摘要:
|
|
@@ -29854,6 +30233,10 @@ function planProjection(text, toolName, navigation, retrievalOnly, spilled = fal
|
|
|
29854
30233
|
const toolCatalog = planToolCatalogProjection(text, toolName);
|
|
29855
30234
|
if (toolCatalog !== void 0) return toolCatalog;
|
|
29856
30235
|
}
|
|
30236
|
+
if (isPtcTransportName(toolName)) {
|
|
30237
|
+
const batch = planBatchToolResult(text, toolName, budgetMaxChars, navigation, spilled);
|
|
30238
|
+
if (batch !== void 0) return batch;
|
|
30239
|
+
}
|
|
29857
30240
|
if (looksLikeContract(text)) return {
|
|
29858
30241
|
kind: "verbatim",
|
|
29859
30242
|
strategy: "verbatim-contract"
|
|
@@ -94790,6 +95173,7 @@ function createCacheWarmupResultTool(deps) {
|
|
|
94790
95173
|
description: [
|
|
94791
95174
|
"Read back a result that was replaced by a preview, using the `ref://<session>/<sha256>` handle written in that preview.",
|
|
94792
95175
|
"Use `action: \"page\"` to read a slice: pass `offset`, and optionally `limit`, `maxBytes`, `fields` and `equals`.",
|
|
95176
|
+
"Keep slices small (a page defaults to 64 lines / 16 KB and is capped at 25 KB): every character a page returns is processed again on the next turn, so read only the slice you need.",
|
|
94793
95177
|
"Every page reports `complete`, `nextOffset`, `omitted` and `totalChars`, so you can see whether more remains instead of assuming a slice is the whole thing.",
|
|
94794
95178
|
"Use `action: \"release\"` when the stored copy is no longer needed."
|
|
94795
95179
|
].join(" "),
|
|
@@ -95102,8 +95486,10 @@ const CACHE_WARMUP_GUIDANCE = [
|
|
|
95102
95486
|
"",
|
|
95103
95487
|
"- A preview is **not** the full result. It states `complete`, `omitted` and `nextOffset` explicitly; treat an incomplete preview as incomplete data, not as the whole output.",
|
|
95104
95488
|
"- To read the original, call `cache_warmup_result` with `action: \"page\"` and that `refId`, then follow `nextOffset` until `complete` is true.",
|
|
95489
|
+
"- Page in small slices (`limit` around 64-120 lines, `maxBytes` at most 8-16 KB) and read only the slice you actually need. Reading a whole stored result back in one call re-sends what the preview just saved.",
|
|
95105
95490
|
"- `action: \"release\"` drops the stored copy. The preview already in the conversation stays identical; it simply can no longer be read back.",
|
|
95106
|
-
"- Source code, type and contract definitions, mixed evidence and anything that could not be parsed reliably are never replaced: they arrive in full."
|
|
95491
|
+
"- Source code, type and contract definitions, mixed evidence and anything that could not be parsed reliably are never replaced: they arrive in full.",
|
|
95492
|
+
"- When a program returns many reads, matches or edits, return a filtered or summarized subset rather than the whole batch: everything you return is processed again on the next turn."
|
|
95107
95493
|
].join("\n");
|
|
95108
95494
|
/**
|
|
95109
95495
|
* 静态引导词的文本提供者。
|