@eddyskywalker/dsh-chatgpt-subscription 0.98.1 → 0.99.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/README.md +1 -1
  2. package/lib/client.js +478 -499
  3. package/lib/client.js.map +1 -1
  4. package/lib/index.js +690 -84
  5. package/lib/types/client/common/AccountPoolSection.d.ts +2 -0
  6. package/lib/types/client/common/AccountPoolSection.d.ts.map +1 -1
  7. package/lib/types/client/common/styles.d.ts.map +1 -1
  8. package/lib/types/client/features/advisor/locales.d.ts +1 -1
  9. package/lib/types/client/locales-ru/alibaba-token-plan.d.ts.map +1 -1
  10. package/lib/types/client/locales-ru/antigravity-acp.d.ts.map +1 -1
  11. package/lib/types/client/locales-ru/grok.d.ts.map +1 -1
  12. package/lib/types/client/locales-ru/longcat.d.ts.map +1 -1
  13. package/lib/types/client/locales-ru/opencode-zen.d.ts.map +1 -1
  14. package/lib/types/client/locales-ru/qianfan-token-plan.d.ts.map +1 -1
  15. package/lib/types/client/locales-ru/tencent-tokenhub.d.ts.map +1 -1
  16. package/lib/types/client/locales-ru/volcengine-ark.d.ts.map +1 -1
  17. package/lib/types/client/providers/alibaba-token-plan/AtpSection.d.ts.map +1 -1
  18. package/lib/types/client/providers/alibaba-token-plan/locales.d.ts +5 -7
  19. package/lib/types/client/providers/alibaba-token-plan/locales.d.ts.map +1 -1
  20. package/lib/types/client/providers/antigravity-acp/AntigravityAcpSection.d.ts.map +1 -1
  21. package/lib/types/client/providers/antigravity-acp/api.d.ts +2 -0
  22. package/lib/types/client/providers/antigravity-acp/api.d.ts.map +1 -1
  23. package/lib/types/client/providers/antigravity-acp/locales.d.ts +78 -60
  24. package/lib/types/client/providers/antigravity-acp/locales.d.ts.map +1 -1
  25. package/lib/types/client/providers/claude/locales.d.ts +24 -24
  26. package/lib/types/client/providers/claude-api/ClaudeApiSection.d.ts.map +1 -1
  27. package/lib/types/client/providers/claude-api/locales.d.ts +5 -7
  28. package/lib/types/client/providers/claude-api/locales.d.ts.map +1 -1
  29. package/lib/types/client/providers/cline-pass/locales.d.ts +6 -6
  30. package/lib/types/client/providers/codex-chatgpt/locales.d.ts +14 -14
  31. package/lib/types/client/providers/command-code/locales.d.ts +3 -3
  32. package/lib/types/client/providers/copilot/CopilotSection.d.ts.map +1 -1
  33. package/lib/types/client/providers/glm-coding-plan/locales.d.ts +12 -12
  34. package/lib/types/client/providers/grok/GrokSection.d.ts.map +1 -1
  35. package/lib/types/client/providers/grok/locales.d.ts +1 -3
  36. package/lib/types/client/providers/grok/locales.d.ts.map +1 -1
  37. package/lib/types/client/providers/grok/styles.d.ts.map +1 -1
  38. package/lib/types/client/providers/kimi-code/locales.d.ts +12 -12
  39. package/lib/types/client/providers/kimi-code/styles.d.ts.map +1 -1
  40. package/lib/types/client/providers/longcat/LongcatSection.d.ts.map +1 -1
  41. package/lib/types/client/providers/longcat/locales.d.ts +1 -3
  42. package/lib/types/client/providers/longcat/locales.d.ts.map +1 -1
  43. package/lib/types/client/providers/minimax-code/locales.d.ts +9 -9
  44. package/lib/types/client/providers/opencode-zen/OpenCodeZenSection.d.ts.map +1 -1
  45. package/lib/types/client/providers/opencode-zen/locales.d.ts +3 -5
  46. package/lib/types/client/providers/opencode-zen/locales.d.ts.map +1 -1
  47. package/lib/types/client/providers/opendesign/locales.d.ts +24 -24
  48. package/lib/types/client/providers/qianfan-token-plan/QianfanSection.d.ts.map +1 -1
  49. package/lib/types/client/providers/qianfan-token-plan/locales.d.ts +11 -7
  50. package/lib/types/client/providers/qianfan-token-plan/locales.d.ts.map +1 -1
  51. package/lib/types/client/providers/qianwen-token-plan/QianwenTokenPlanSection.d.ts.map +1 -1
  52. package/lib/types/client/providers/qianwen-token-plan/locales.d.ts +3 -5
  53. package/lib/types/client/providers/qianwen-token-plan/locales.d.ts.map +1 -1
  54. package/lib/types/client/providers/relayone/RelayOneSection.d.ts.map +1 -1
  55. package/lib/types/client/providers/relayone/locales.d.ts +3 -5
  56. package/lib/types/client/providers/relayone/locales.d.ts.map +1 -1
  57. package/lib/types/client/providers/step-code/locales.d.ts +24 -24
  58. package/lib/types/client/providers/tencent-tokenhub/TokenHubSection.d.ts.map +1 -1
  59. package/lib/types/client/providers/tencent-tokenhub/locales.d.ts +7 -9
  60. package/lib/types/client/providers/tencent-tokenhub/locales.d.ts.map +1 -1
  61. package/lib/types/client/providers/volcengine-ark/ArkSection.d.ts.map +1 -1
  62. package/lib/types/client/providers/volcengine-ark/locales.d.ts +5 -7
  63. package/lib/types/client/providers/volcengine-ark/locales.d.ts.map +1 -1
  64. package/lib/types/client/providers/workbuddy/locales.d.ts +30 -30
  65. package/lib/types/client/providers/xiaomi-mimo/MimoSection.d.ts.map +1 -1
  66. package/lib/types/client/providers/xiaomi-mimo/locales.d.ts +3 -5
  67. package/lib/types/client/providers/xiaomi-mimo/locales.d.ts.map +1 -1
  68. package/lib/types/compat.d.ts +1 -1
  69. package/lib/types/host/common/i18n/en.d.ts.map +1 -1
  70. package/lib/types/host/common/i18n/ru.d.ts.map +1 -1
  71. package/lib/types/host/common/i18n/zh.d.ts +1 -0
  72. package/lib/types/host/common/i18n/zh.d.ts.map +1 -1
  73. package/lib/types/host/providers/antigravity-acp/acp-client.d.ts +18 -0
  74. package/lib/types/host/providers/antigravity-acp/acp-client.d.ts.map +1 -1
  75. package/lib/types/host/providers/antigravity-acp/adapter.d.ts +47 -5
  76. package/lib/types/host/providers/antigravity-acp/adapter.d.ts.map +1 -1
  77. package/lib/types/host/providers/antigravity-acp/binary.d.ts +2 -2
  78. package/lib/types/host/providers/antigravity-acp/cooldown.d.ts +35 -0
  79. package/lib/types/host/providers/antigravity-acp/cooldown.d.ts.map +1 -0
  80. package/lib/types/host/providers/antigravity-acp/history.d.ts +17 -0
  81. package/lib/types/host/providers/antigravity-acp/history.d.ts.map +1 -1
  82. package/lib/types/host/providers/antigravity-acp/login.d.ts +22 -0
  83. package/lib/types/host/providers/antigravity-acp/login.d.ts.map +1 -1
  84. package/lib/types/host/providers/antigravity-acp/routes.d.ts +5 -0
  85. package/lib/types/host/providers/antigravity-acp/routes.d.ts.map +1 -1
  86. package/lib/types/host/providers/antigravity-acp/session-state.d.ts +73 -0
  87. package/lib/types/host/providers/antigravity-acp/session-state.d.ts.map +1 -0
  88. package/lib/types/host/providers/antigravity-acp/settings.d.ts +3 -4
  89. package/lib/types/host/providers/antigravity-acp/settings.d.ts.map +1 -1
  90. package/lib/types/host/providers/copilot/routes.d.ts.map +1 -1
  91. package/lib/types/host/providers/opendesign/adapter.d.ts.map +1 -1
  92. package/lib/types/host/providers/opendesign/mapper.d.ts +1 -1
  93. package/lib/types/host/providers/opendesign/mapper.d.ts.map +1 -1
  94. package/lib/types/host/providers/qianfan-token-plan/mapper.d.ts.map +1 -1
  95. package/lib/types/host/providers/relayone/adapter.d.ts.map +1 -1
  96. package/lib/types/host/providers/relayone/mapper-openai.d.ts.map +1 -1
  97. package/lib/types/host/runtime/deepseek-v41-flash/progress-governor.d.ts +0 -1
  98. package/lib/types/host/runtime/deepseek-v41-flash/progress-governor.d.ts.map +1 -1
  99. package/lib/types/host/runtime/deepseek-v41-flash/reasoning-seed.d.ts +2 -1
  100. package/lib/types/host/runtime/deepseek-v41-flash/reasoning-seed.d.ts.map +1 -1
  101. package/lib/types/host/runtime/deepseek-v41-flash/state-anchor.d.ts +0 -1
  102. package/lib/types/host/runtime/deepseek-v41-flash/state-anchor.d.ts.map +1 -1
  103. package/lib/types/host/runtime/open-models/state-anchor.d.ts +0 -1
  104. package/lib/types/host/runtime/open-models/state-anchor.d.ts.map +1 -1
  105. package/lib/types/index.d.ts.map +1 -1
  106. package/lib/types/shared/antigravity-acp-contracts.d.ts +3 -3
  107. package/lib/types/shared/qianfan-token-plan-contracts.d.ts +4 -3
  108. package/lib/types/shared/qianfan-token-plan-contracts.d.ts.map +1 -1
  109. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -296,6 +296,7 @@ const en = {
296
296
  "antigravityAcp.notSignedIn": "Antigravity is not signed in. Start the sign-in from this card, or run agy acp --login in a terminal.",
297
297
  "antigravityAcp.noBinary": "No usable Antigravity CLI (agy) was found and the official ACP server has not been downloaded.",
298
298
  "antigravityAcp.nativeTool": "[Antigravity ran its own tool outside DSH permissions: {call}]\n",
299
+ "antigravityAcp.nativeToolDenied": "[Antigravity requested its own tool; this call will be denied and the turn continues. Use the tools DSH provides: {call}]\n",
299
300
  "provider.qianwen-token-plan": "Qwen Token Plan",
300
301
  "provider.copilot": "GitHub Copilot",
301
302
  "provider.volcengine-ark": "Volcengine Ark",
@@ -478,6 +479,7 @@ const ru = {
478
479
  "antigravityAcp.notSignedIn": "Вход в Antigravity не выполнен. Начните его на этой карточке или выполните agy acp --login в терминале.",
479
480
  "antigravityAcp.noBinary": "Рабочий Antigravity CLI (agy) не найден, и официальный ACP-сервер ещё не загружен.",
480
481
  "antigravityAcp.nativeTool": "[Antigravity использовал собственный инструмент в обход разрешений DSH: {call}]\n",
482
+ "antigravityAcp.nativeToolDenied": "[Antigravity запросил свой инструмент; этот вызов будет отклонён, а ход продолжится. Используйте инструменты DSH: {call}]\n",
481
483
  "provider.qianwen-token-plan": "Qwen Token Plan",
482
484
  "provider.copilot": "GitHub Copilot (подписка)",
483
485
  "provider.volcengine-ark": "Volcengine Ark (Арк)",
@@ -669,6 +671,7 @@ const zh = {
669
671
  "antigravityAcp.notSignedIn": "还没有登录 Antigravity:请在设置页发起登录,或在终端执行 agy acp --login。",
670
672
  "antigravityAcp.noBinary": "未找到可用的 Antigravity CLI(agy),且官方 ACP 服务端尚未下载。",
671
673
  "antigravityAcp.nativeTool": "[Antigravity 使用了它自带的工具,这次调用没有经过 DSH 权限:{call}]\n",
674
+ "antigravityAcp.nativeToolDenied": "[Antigravity 请求使用它自带的工具,本次调用将被拒绝且对话继续;请改用 DSH 提供的工具:{call}]\n",
672
675
  "provider.qianwen-token-plan": "Qwen Token Plan(千问)",
673
676
  "provider.copilot": "GitHub Copilot(订阅)",
674
677
  "provider.volcengine-ark": "火山方舟(Ark 套餐)",
@@ -888,7 +891,7 @@ const ROUTE_PREFIX$6 = "/api/dsh-chatgpt-subscription";
888
891
  * `test/responses-client.test.ts` asserts the two agree, so a release that
889
892
  * forgets this constant fails the suite instead of shipping quietly.
890
893
  */
891
- const PLUGIN_VERSION = "0.98.1";
894
+ const PLUGIN_VERSION = "0.99.1";
892
895
  const CODEX_CHATGPT_PROVIDER_ID = "codex-chatgpt";
893
896
  const CODEX_API_BASE = "https://chatgpt.com/backend-api/codex";
894
897
  const CODEX_RESPONSES_URL = `${CODEX_API_BASE}/responses`;
@@ -21002,7 +21005,7 @@ function buildOpenAIRequest$1(options, images = NO_RESOLVED_IMAGES$4) {
21002
21005
  if (toolCalls.length > 0) entry.tool_calls = toolCalls;
21003
21006
  const seedReasoning = chatReasoningReplayText(message, options.provider, options.model);
21004
21007
  if (seedReasoning !== null) entry.reasoning_content = seedReasoning;
21005
- if (content !== "" || toolCalls.length > 0) messages.push(entry);
21008
+ if (content !== "" || toolCalls.length > 0 || seedReasoning !== null) messages.push(entry);
21006
21009
  continue;
21007
21010
  }
21008
21011
  const content = openAIUserContent$4(message, images);
@@ -26860,6 +26863,10 @@ var AcpClient = class {
26860
26863
  closed = false;
26861
26864
  stderrTail = "";
26862
26865
  handlers;
26866
+ /** Whether the last initialize result advertised `sessionCapabilities.close`. */
26867
+ sessionClose = false;
26868
+ /** Whether the last initialize result advertised `sessionCapabilities.resume`. */
26869
+ sessionResume = false;
26863
26870
  disposeEofGraceMs;
26864
26871
  disposeGraceMs;
26865
26872
  temp;
@@ -26920,6 +26927,28 @@ var AcpClient = class {
26920
26927
  return !this.closed;
26921
26928
  }
26922
26929
  /**
26930
+ * Remember the capabilities an `initialize` result advertised.
26931
+ *
26932
+ * ACP requires clients to check a session capability before using its method;
26933
+ * a warm process reused across turns therefore keeps this bit alongside the
26934
+ * connection rather than letting each turn guess from the server version.
26935
+ *
26936
+ * @param value - The raw `initialize` result.
26937
+ */
26938
+ noteAgentCapabilities(value) {
26939
+ const capabilities = value?.agentCapabilities?.sessionCapabilities;
26940
+ this.sessionClose = capabilities?.close !== void 0;
26941
+ this.sessionResume = capabilities?.resume !== void 0;
26942
+ }
26943
+ /** Whether this connection may be asked to close a session explicitly. */
26944
+ get supportsSessionClose() {
26945
+ return this.sessionClose;
26946
+ }
26947
+ /** Whether this connection may reconnect to an existing session without replay. */
26948
+ get supportsSessionResume() {
26949
+ return this.sessionResume;
26950
+ }
26951
+ /**
26923
26952
  * Replace the handlers for the next turn.
26924
26953
  *
26925
26954
  * A warm process outlives the turn that started it, and every turn owns its own
@@ -27615,6 +27644,16 @@ const REPLAY_MESSAGE_CHARS = 12e3;
27615
27644
  /** Ceiling for one copy of the request the replay answers. */
27616
27645
  const REPLAY_REQUEST_CHARS = 3e4;
27617
27646
  /**
27647
+ * UTF-8 byte budget for the text blocks in one ACP prompt.
27648
+ *
27649
+ * The official server silently drops the tail of an oversized prompt at about
27650
+ * 192 KB, so the client keeps a margin below that line. Inline image bytes are
27651
+ * governed by ACP's separate image ceiling and are not counted here.
27652
+ */
27653
+ const ACP_MAX_PROMPT_TEXT_BYTES = 18e4;
27654
+ /** Notice used when an old prompt block has to be shortened. */
27655
+ const PROMPT_TRUNCATION_MARKER = "\n…[truncated to fit the Antigravity request budget]…\n";
27656
+ /**
27618
27657
  * Build the prompt for one generation.
27619
27658
  *
27620
27659
  * @param options - Normalized request options.
@@ -27626,12 +27665,94 @@ function buildPrompt(options, images, fromMessage) {
27626
27665
  const messages = options.messages;
27627
27666
  const start = Math.max(0, Math.min(fromMessage, messages.length));
27628
27667
  return {
27629
- blocks: start === 0 && messages.some((message) => message.role === "assistant") ? replayBlocks(messages, images) : renderMessages(messages, messageRange(messages.length, start), images),
27668
+ blocks: capPromptTextBytes(start === 0 && messages.some((message) => message.role === "assistant") ? replayBlocks(messages, images) : renderMessages(messages, messageRange(messages.length, start), images)),
27630
27669
  coveredMessages: messages.length,
27631
27670
  fingerprint: fingerprintMessages(messages, 0, messages.length)
27632
27671
  };
27633
27672
  }
27634
27673
  /**
27674
+ * Keep the UTF-8 text budget below the official server's silent cut-off.
27675
+ *
27676
+ * The first block and the request tail are protected while older middle blocks
27677
+ * are discarded. If a protected block is still too large, it is shortened from
27678
+ * the middle so the newest request remains identifiable. Images are left alone:
27679
+ * ACP has a separate image ceiling for them.
27680
+ */
27681
+ function capPromptTextBytes(blocks, maxBytes = ACP_MAX_PROMPT_TEXT_BYTES) {
27682
+ const next = blocks.map((block) => block.type === "text" ? { ...block } : block);
27683
+ let total = promptTextBytes(next);
27684
+ if (total <= maxBytes) return next;
27685
+ let protectedFrom = next.length - 1;
27686
+ for (let index = next.length - 1; index >= 0; index -= 1) {
27687
+ const block = next[index];
27688
+ if (block?.type !== "text") continue;
27689
+ if (block.text.includes("[current human request]") || block.text === REPLAY_ANCHOR_INSTRUCTION) {
27690
+ protectedFrom = index;
27691
+ break;
27692
+ }
27693
+ }
27694
+ const keep = next.map(() => true);
27695
+ for (let index = 1; index < protectedFrom && total > maxBytes; index += 1) {
27696
+ const block = next[index];
27697
+ if (block?.type !== "text") continue;
27698
+ total -= promptBlockBytes(block);
27699
+ keep[index] = false;
27700
+ }
27701
+ let result = next.filter((_, index) => keep[index]);
27702
+ total = promptTextBytes(result);
27703
+ while (total > maxBytes) {
27704
+ let largestIndex = -1;
27705
+ let largestBytes = -1;
27706
+ for (let index = 0; index < result.length; index += 1) {
27707
+ const block = result[index];
27708
+ if (block?.type !== "text") continue;
27709
+ const bytes = promptBlockBytes(block);
27710
+ if (bytes > largestBytes) {
27711
+ largestBytes = bytes;
27712
+ largestIndex = index;
27713
+ }
27714
+ }
27715
+ if (largestIndex < 0) break;
27716
+ const block = result[largestIndex];
27717
+ if (block?.type !== "text") break;
27718
+ const target = Math.max(0, largestBytes - (total - maxBytes));
27719
+ block.text = truncateUtf8(block.text, target);
27720
+ total = promptTextBytes(result);
27721
+ }
27722
+ result = result.filter((block) => block.type !== "text" || block.text !== "");
27723
+ return result;
27724
+ }
27725
+ function promptTextBytes(blocks) {
27726
+ let total = 0;
27727
+ for (const block of blocks) {
27728
+ if (block.type !== "text") continue;
27729
+ total += promptBlockBytes(block);
27730
+ }
27731
+ return total;
27732
+ }
27733
+ function promptBlockBytes(block) {
27734
+ return Buffer.byteLength(JSON.stringify(block), "utf8");
27735
+ }
27736
+ /** Shorten one UTF-8 string from the middle without crossing the byte budget. */
27737
+ function truncateUtf8(text, maxBytes) {
27738
+ if (maxBytes <= 0) return "";
27739
+ const bytes = Buffer.from(text, "utf8");
27740
+ if (bytes.length <= maxBytes) return text;
27741
+ const markerBytes = Buffer.byteLength(PROMPT_TRUNCATION_MARKER, "utf8");
27742
+ if (maxBytes <= markerBytes) return "";
27743
+ let body = maxBytes - markerBytes;
27744
+ let result = "";
27745
+ for (let attempt = 0; attempt < 8; attempt += 1) {
27746
+ const head = Math.floor(body * .6);
27747
+ const tail = Math.max(0, body - head);
27748
+ result = `${bytes.subarray(0, head).toString("utf8")}${PROMPT_TRUNCATION_MARKER}${bytes.subarray(bytes.length - tail).toString("utf8")}`;
27749
+ const over = Buffer.byteLength(result, "utf8") - maxBytes;
27750
+ if (over <= 0) return result;
27751
+ body = Math.max(0, body - Math.max(16, over));
27752
+ }
27753
+ return "";
27754
+ }
27755
+ /**
27635
27756
  * Digest over a message range.
27636
27757
  *
27637
27758
  * Only the parts the model can see take part: role, block type and payload. Ids
@@ -28336,9 +28457,20 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
28336
28457
  stream(options) {
28337
28458
  return wrapStreamWithWatchdog((watchdogSignal, activity) => this.runAsIterable(options, watchdogSignal, activity), options.signal, ACP_STREAM_IDLE_TIMEOUT_MS, STREAM_IDLE_TIMEOUT_CODE$6, PROVIDER_NAME$23, ACP_FIRST_OUTPUT_TIMEOUT_MS);
28338
28459
  }
28460
+ /**
28461
+ * Drop every parked conversation without interrupting a live answer.
28462
+ *
28463
+ * Used after an account change or sign-out: the old ACP session must not be
28464
+ * reused by the next message. In-flight turns finish but are no longer
28465
+ * parkable, so they cannot write a fresh pointer behind the reset.
28466
+ */
28467
+ async forgetConversations() {
28468
+ for (const entry of [...this.dormant.values()]) await this.closeDormant(entry);
28469
+ for (const turn of this.live.values()) turn.parkable = false;
28470
+ }
28339
28471
  /** Close every process this adapter owns. */
28340
28472
  async dispose() {
28341
- for (const entry of [...this.dormant.values()]) await this.closeDormant(entry);
28473
+ for (const entry of [...this.dormant.values()]) await this.closeDormant(entry, true);
28342
28474
  for (const turn of [...this.live.values()]) {
28343
28475
  if (this.live.get(turn.dshSessionId) === turn) this.live.delete(turn.dshSessionId);
28344
28476
  turn.closed = true;
@@ -28362,7 +28494,17 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
28362
28494
  * not as an empty answer.
28363
28495
  */
28364
28496
  async *runAsIterable(options, signal, activity) {
28365
- yield* await this.run(options, signal, activity);
28497
+ const cooldown = this.options.cooldown;
28498
+ if (cooldown !== void 0) {
28499
+ const remaining = await cooldown.remaining().catch(() => 0);
28500
+ if (remaining > 0) throw acpError("ACP_UPSTREAM_BLOCKED", `A previous upstream refusal is cooling down for another ${Math.ceil(remaining / 1e3)}s.`);
28501
+ }
28502
+ try {
28503
+ yield* await this.run(options, signal, activity);
28504
+ } catch (error) {
28505
+ if (isUpstreamBlocked(error)) await cooldown?.block().catch(() => void 0);
28506
+ throw error;
28507
+ }
28366
28508
  }
28367
28509
  async run(rawOptions, signal, activity) {
28368
28510
  const options = this.effortMemory.follow(normalizeGenerateOptions(rawOptions));
@@ -28378,10 +28520,17 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
28378
28520
  if (live !== void 0) await this.closeTurn(live);
28379
28521
  }
28380
28522
  const dormant = auxiliary ? void 0 : this.dormant.get(dshSessionId);
28523
+ let dormantAttemptFailed = false;
28381
28524
  if (dormant !== void 0) if (this.usableDormant(dormant, options)) {
28382
28525
  const resumed = await this.resumeDormant(dormant, options, settings, effort, images, signal, activity);
28383
28526
  if (resumed !== void 0) return resumed;
28527
+ dormantAttemptFailed = true;
28384
28528
  } else await this.closeDormant(dormant);
28529
+ const persisted = auxiliary || dormantAttemptFailed ? void 0 : await this.options.sessionState?.read(dshSessionId).catch(() => void 0);
28530
+ if (persisted !== void 0) if (this.usablePersisted(persisted, options)) {
28531
+ const resumed = await this.resumePersisted(persisted, dshSessionId, options, settings, effort, images, signal, activity);
28532
+ if (resumed !== void 0) return resumed;
28533
+ } else await this.options.sessionState?.delete(dshSessionId).catch(() => void 0);
28385
28534
  return this.startTurn(dshSessionId, options, settings, images, effort, signal, activity, !auxiliary);
28386
28535
  }
28387
28536
  /** Start a fresh ACP session for one generation and stream its answer. */
@@ -28442,7 +28591,95 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
28442
28591
  throw asLlmError(error);
28443
28592
  }
28444
28593
  }
28445
- /** Continue the live turn after the harness executed its tools. */
28594
+ /** Whether a durable pointer still describes this conversation. */
28595
+ usablePersisted(entry, options) {
28596
+ if (entry.cwd !== this.cwd()) return false;
28597
+ if (entry.tools !== fingerprintTools(options.tools)) return false;
28598
+ return canContinue(options.messages, entry.covered, entry.fingerprint);
28599
+ }
28600
+ /**
28601
+ * Reconnect to a session that outlived the process which created it.
28602
+ *
28603
+ * Officially this is `session/resume`: the server restores the conversation
28604
+ * without replaying it, then the new bridge is attached and only the delta is
28605
+ * sent. Any failure falls back to a cold session; the stale pointer is removed
28606
+ * so the next turn does not retry a conversation the server no longer has.
28607
+ */
28608
+ async resumePersisted(entry, dshSessionId, options, settings, effort, images, signal, activity) {
28609
+ const limit = this.options.maxActiveTurns ?? 4;
28610
+ if (this.activeTurns >= limit) return void 0;
28611
+ this.activeTurns += 1;
28612
+ const queue = new UpdateQueue();
28613
+ const bridge = new McpBridge(options.tools ?? []);
28614
+ const binding = {};
28615
+ let client;
28616
+ try {
28617
+ const launch = await this.options.resolveLaunch();
28618
+ client = this.spawn(launch, queue, activity, binding);
28619
+ const descriptor = await bridge.start();
28620
+ const init = asRecord$19(await client.request("initialize", {
28621
+ protocolVersion: 1,
28622
+ clientCapabilities: {
28623
+ fs: {
28624
+ readTextFile: false,
28625
+ writeTextFile: false
28626
+ },
28627
+ terminal: false
28628
+ },
28629
+ clientInfo: {
28630
+ name: "dsh-chatgpt-subscription",
28631
+ version: "1.0.0"
28632
+ }
28633
+ }, signal));
28634
+ client.noteAgentCapabilities?.(init);
28635
+ if (client.supportsSessionResume !== true) throw new Error("The Antigravity ACP server does not advertise session resume.");
28636
+ const result = asRecord$19(await client.request("session/resume", {
28637
+ sessionId: entry.acpSessionId,
28638
+ cwd: this.cwd(),
28639
+ mcpServers: [descriptor]
28640
+ }, signal));
28641
+ const sessionId = typeof result?.sessionId === "string" ? result.sessionId : entry.acpSessionId;
28642
+ binding.acpSessionId = sessionId;
28643
+ await this.applyModelAndEffort(client, sessionId, options.model, effort);
28644
+ const prompt = buildPrompt(options, images, entry.covered);
28645
+ if ((options.tools ?? []).length > 0) prompt.blocks.unshift({
28646
+ type: "text",
28647
+ text: BRIDGE_ONLY_INSTRUCTION
28648
+ });
28649
+ const turn = {
28650
+ dshSessionId,
28651
+ client,
28652
+ bridge,
28653
+ acpSessionId: sessionId,
28654
+ covered: prompt.coveredMessages,
28655
+ fingerprint: prompt.fingerprint,
28656
+ model: options.model,
28657
+ effort,
28658
+ queue,
28659
+ settled: void 0,
28660
+ surfaced: /* @__PURE__ */ new Set(),
28661
+ notedNative: /* @__PURE__ */ new Set(),
28662
+ nativeToolPolicy: settings.nativeToolPolicy,
28663
+ startedAt: this.now(),
28664
+ awaitingHarness: false,
28665
+ sessionsUsed: 1,
28666
+ tools: fingerprintTools(options.tools),
28667
+ parkable: true,
28668
+ closed: false
28669
+ };
28670
+ this.live.set(dshSessionId, turn);
28671
+ this.sendPrompt(turn, prompt.blocks);
28672
+ return this.pump(turn, signal, activity);
28673
+ } catch {
28674
+ this.activeTurns = Math.max(0, this.activeTurns - 1);
28675
+ await bridge.close().catch(() => void 0);
28676
+ await client?.dispose().catch(() => void 0);
28677
+ await this.options.sessionState?.delete(dshSessionId).catch(() => void 0);
28678
+ return;
28679
+ }
28680
+ }
28681
+ /**
28682
+ * Continue the live turn after the harness executed its tools. */
28446
28683
  continueTurn(turn, options, images, signal, activity) {
28447
28684
  const results = collectToolResults(options.messages.slice(turn.covered), images);
28448
28685
  for (const callId of [...turn.surfaced]) {
@@ -28565,10 +28802,9 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
28565
28802
  if (type === "tool_call" || type === "tool_call_update") {
28566
28803
  const native = readNativeToolCall(update);
28567
28804
  if (native !== void 0) {
28568
- if (turn.nativeToolPolicy === "cancel") throw acpError("ACP_NATIVE_TOOLS_UNSUPPORTED", `Tool: ${native.name}.`);
28569
28805
  if (type === "tool_call" && !turn.notedNative.has(native.callId)) {
28570
28806
  turn.notedNative.add(native.callId);
28571
- const note = nativeToolNote(native, readNativeToolArguments(update));
28807
+ const note = turn.nativeToolPolicy === "cancel" ? nativeToolDeniedNote(native, readNativeToolArguments(update)) : nativeToolNote(native, readNativeToolArguments(update));
28572
28808
  if (textIndex === void 0) {
28573
28809
  textIndex = nextIndex;
28574
28810
  nextIndex += 1;
@@ -28678,9 +28914,12 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
28678
28914
  async answerPermission(params) {
28679
28915
  const options = readPermissionOptions(params);
28680
28916
  const answer = () => options.find((option) => option.kind === "allow_once")?.optionId ?? options.find((option) => option.kind === "allow_always")?.optionId;
28917
+ const deny = () => options.find((option) => option.kind === "reject_once")?.optionId ?? options.find((option) => option.kind === "reject_always")?.optionId;
28681
28918
  const toolCall = asRecord$19(params.toolCall);
28682
28919
  if ((typeof toolCall?.name === "string" ? toolCall.name : "").startsWith(`mcp_dsh-bridge_`)) return answer();
28683
- return (await this.options.settings.read()).permissionPolicy === "allow" ? answer() : void 0;
28920
+ const settings = await this.options.settings.read();
28921
+ if (settings.nativeToolPolicy === "cancel") return deny();
28922
+ return settings.permissionPolicy === "allow" ? answer() : deny();
28684
28923
  }
28685
28924
  spawn(launch, queue, activity, binding) {
28686
28925
  const handlers = {
@@ -28727,6 +28966,7 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
28727
28966
  version: "1.0.0"
28728
28967
  }
28729
28968
  }, options.signal));
28969
+ client.noteAgentCapabilities?.(init);
28730
28970
  const authMethods = Array.isArray(init?.authMethods) ? init.authMethods.map((entry) => String(entry.id ?? "")).filter((id) => id !== "") : [];
28731
28971
  const create = async () => {
28732
28972
  const result = asRecord$19(await client.request("session/new", {
@@ -28949,6 +29189,7 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
28949
29189
  */
28950
29190
  async park(turn) {
28951
29191
  turn.queue.close();
29192
+ await this.rememberSession(turn);
28952
29193
  const limit = this.options.dormantSessionLimit ?? 2;
28953
29194
  if (limit <= 0 || !turn.client.alive) {
28954
29195
  await this.release(turn);
@@ -28970,7 +29211,7 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
28970
29211
  timer: void 0
28971
29212
  };
28972
29213
  const timer = setTimeout(() => {
28973
- this.closeDormant(entry);
29214
+ this.closeDormant(entry, true);
28974
29215
  }, this.options.dormantSessionTimeoutMs ?? 3e5);
28975
29216
  timer.unref?.();
28976
29217
  entry.timer = timer;
@@ -28978,21 +29219,44 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
28978
29219
  while (this.dormant.size > limit) {
28979
29220
  const oldest = this.dormant.values().next().value;
28980
29221
  if (oldest === void 0) break;
28981
- await this.closeDormant(oldest);
29222
+ await this.closeDormant(oldest, true);
28982
29223
  }
28983
29224
  }
28984
29225
  /**
29226
+ * Remember the completed conversation for the next host process.
29227
+ *
29228
+ * Only a parkable turn is stored: auxiliary title/compaction requests carry a
29229
+ * different history and must never replace the user's conversation pointer.
29230
+ */
29231
+ async rememberSession(turn) {
29232
+ if (!turn.parkable || turn.client.supportsSessionResume !== true) return;
29233
+ await this.options.sessionState?.write(turn.dshSessionId, {
29234
+ acpSessionId: turn.acpSessionId,
29235
+ cwd: this.cwd(),
29236
+ covered: turn.covered,
29237
+ fingerprint: turn.fingerprint,
29238
+ tools: turn.tools,
29239
+ model: turn.model,
29240
+ ...turn.effort === void 0 ? {} : { effort: turn.effort }
29241
+ }).catch(() => void 0);
29242
+ }
29243
+ /**
28985
29244
  * Drop a parked session and hand its process back to the pool.
28986
29245
  *
28987
- * The conversation itself is abandoned rather than closed with `session/close`:
28988
- * not every agent version this line supports answers that request, and a request
28989
- * that never settles would occupy one of the client's protocol slots for the
28990
- * life of the process. The next turn opens a fresh conversation on the same warm
29246
+ * The conversation is closed with `session/close` when the agent advertises
29247
+ * that capability, then its process is pooled or disposed. The optional request
29248
+ * is bounded so an older or wedged server cannot hold a protocol slot open; the
29249
+ * next turn opens a fresh conversation on the same warm process. `preserve` is
29250
+ * used only by adapter shutdown, where the durable pointer must outlive this
28991
29251
  * process.
28992
29252
  */
28993
- async closeDormant(entry) {
29253
+ async closeDormant(entry, preserve = false) {
28994
29254
  if (this.dormant.get(entry.dshSessionId) === entry) this.dormant.delete(entry.dshSessionId);
28995
29255
  if (entry.timer !== void 0) clearTimeout(entry.timer);
29256
+ if (!preserve) {
29257
+ await this.closeAcpSession(entry.client, entry.acpSessionId);
29258
+ await this.options.sessionState?.delete(entry.dshSessionId).catch(() => void 0);
29259
+ }
28996
29260
  await this.release({
28997
29261
  client: entry.client,
28998
29262
  bridge: entry.bridge,
@@ -29000,6 +29264,24 @@ var AntigravityAcpAdapter = class extends LlmAdapter {
29000
29264
  });
29001
29265
  }
29002
29266
  /**
29267
+ * Release one ACP session before its process is pooled or disposed.
29268
+ *
29269
+ * Official servers advertise `sessionCapabilities.close`; older ones do not,
29270
+ * and the ACP specification forbids calling the method without that bit. The
29271
+ * short abort keeps a wedged optional request from occupying a protocol slot.
29272
+ */
29273
+ async closeAcpSession(client, acpSessionId) {
29274
+ if (!client.alive || !client.supportsSessionClose) return;
29275
+ const abort = new AbortController();
29276
+ const timer = setTimeout(() => abort.abort(), 2e3);
29277
+ timer.unref?.();
29278
+ try {
29279
+ await client.request("session/close", { sessionId: acpSessionId }, abort.signal);
29280
+ } catch {} finally {
29281
+ clearTimeout(timer);
29282
+ }
29283
+ }
29284
+ /**
29003
29285
  * Take one warm process out of the pool.
29004
29286
  *
29005
29287
  * A process that has opened its session budget is disposed here rather than
@@ -29201,6 +29483,10 @@ function readNativeToolCall(update) {
29201
29483
  function nativeToolNote(native, args) {
29202
29484
  return t("antigravityAcp.nativeTool", { call: args === "" ? native.name : `${native.name} ${args}` });
29203
29485
  }
29486
+ /** One visible note for a native call this client will reject, without ending the turn. */
29487
+ function nativeToolDeniedNote(native, args) {
29488
+ return t("antigravityAcp.nativeToolDenied", { call: args === "" ? native.name : `${native.name} ${args}` });
29489
+ }
29204
29490
  /**
29205
29491
  * The raw argument text one native call was reported with.
29206
29492
  *
@@ -29355,6 +29641,9 @@ function ownsSession(binding, sessionId) {
29355
29641
  if (binding.acpSessionId === void 0) return false;
29356
29642
  return sessionId === binding.acpSessionId;
29357
29643
  }
29644
+ function isUpstreamBlocked(error) {
29645
+ return typeof error === "object" && error !== null && error.code === "ACP_UPSTREAM_BLOCKED";
29646
+ }
29358
29647
  function asLlmError(error) {
29359
29648
  if (error instanceof LlmError) return error;
29360
29649
  if (error instanceof Error && error.name === "AbortError") return new LlmError("The Antigravity ACP turn was cancelled.", "ABORTED");
@@ -29415,7 +29704,7 @@ function defaultAntigravityAcpSettings() {
29415
29704
  enabledModelIds: null,
29416
29705
  defaultReasoningEffort: null,
29417
29706
  permissionPolicy: "allow",
29418
- nativeToolPolicy: "allow",
29707
+ nativeToolPolicy: "cancel",
29419
29708
  binaryPath: null
29420
29709
  };
29421
29710
  }
@@ -29441,7 +29730,7 @@ function parseAntigravityAcpSettings(value) {
29441
29730
  enabledModelIds,
29442
29731
  defaultReasoningEffort: typeof record.defaultReasoningEffort === "string" ? record.defaultReasoningEffort : null,
29443
29732
  permissionPolicy: record.permissionPolicy === "reject" ? "reject" : "allow",
29444
- nativeToolPolicy: record.nativeToolPolicy === "cancel" ? "cancel" : "allow",
29733
+ nativeToolPolicy: record.nativeToolPolicy === "allow" ? "allow" : "cancel",
29445
29734
  binaryPath: typeof record.binaryPath === "string" && record.binaryPath !== "" ? record.binaryPath : null,
29446
29735
  ...typeof record.lastTurnAt === "number" && Number.isFinite(record.lastTurnAt) ? { lastTurnAt: record.lastTurnAt } : {}
29447
29736
  };
@@ -29508,6 +29797,202 @@ var AntigravityAcpSettingsStore = class {
29508
29797
  return next;
29509
29798
  }
29510
29799
  };
29800
+ /** Where the durable session pointers live. */
29801
+ function antigravityAcpSessionStatePath() {
29802
+ return path.join(dshHomeDir(), "storages", "antigravity-acp-sessions.json");
29803
+ }
29804
+ /**
29805
+ * File-backed session pointers.
29806
+ *
29807
+ * Writes are serialized so two completed turns cannot lose each other's update,
29808
+ * and each replacement is atomic. Expired or corrupt entries are ignored rather
29809
+ * than becoming a reason to fail a generation.
29810
+ */
29811
+ var AntigravityAcpSessionStateStore = class {
29812
+ filePath;
29813
+ now;
29814
+ cache = null;
29815
+ loading = null;
29816
+ writes = Promise.resolve();
29817
+ constructor(filePath = antigravityAcpSessionStatePath(), now = Date.now) {
29818
+ this.filePath = filePath;
29819
+ this.now = now;
29820
+ }
29821
+ async read(dshSessionId) {
29822
+ const ref = (await this.all())[dshSessionId];
29823
+ if (ref === void 0) return void 0;
29824
+ if (this.now() - ref.updatedAt > 6048e5) {
29825
+ this.delete(dshSessionId).catch(() => void 0);
29826
+ return;
29827
+ }
29828
+ return ref;
29829
+ }
29830
+ async write(dshSessionId, ref) {
29831
+ await this.enqueue(async () => {
29832
+ const sessions = await this.all();
29833
+ sessions[dshSessionId] = {
29834
+ ...ref,
29835
+ updatedAt: this.now()
29836
+ };
29837
+ this.prune(sessions);
29838
+ await this.persist(sessions);
29839
+ });
29840
+ }
29841
+ async delete(dshSessionId) {
29842
+ await this.enqueue(async () => {
29843
+ const sessions = await this.all();
29844
+ if (sessions[dshSessionId] === void 0) return;
29845
+ delete sessions[dshSessionId];
29846
+ await this.persist(sessions);
29847
+ });
29848
+ }
29849
+ async clear() {
29850
+ await this.enqueue(async () => {
29851
+ await this.persist(Object.create(null));
29852
+ });
29853
+ }
29854
+ async enqueue(work) {
29855
+ const next = this.writes.then(work, work);
29856
+ this.writes = next.catch(() => void 0);
29857
+ return next;
29858
+ }
29859
+ async all() {
29860
+ if (this.cache !== null) return this.cache;
29861
+ if (this.loading !== null) return this.loading;
29862
+ this.loading = this.load().finally(() => {
29863
+ this.loading = null;
29864
+ });
29865
+ return this.loading;
29866
+ }
29867
+ async load() {
29868
+ const sessions = Object.create(null);
29869
+ try {
29870
+ const parsed = JSON.parse(await fs.readFile(this.filePath, "utf8"));
29871
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return sessions;
29872
+ const root = parsed;
29873
+ if (root.version !== 1) return sessions;
29874
+ const stored = root.sessions;
29875
+ if (typeof stored !== "object" || stored === null || Array.isArray(stored)) return sessions;
29876
+ for (const [dshSessionId, value] of Object.entries(stored)) {
29877
+ const ref = parseRef(value, this.now());
29878
+ if (ref !== void 0) sessions[dshSessionId] = ref;
29879
+ }
29880
+ } catch {}
29881
+ this.cache = sessions;
29882
+ return sessions;
29883
+ }
29884
+ async persist(sessions) {
29885
+ await fs.mkdir(path.dirname(this.filePath), { recursive: true });
29886
+ const temp = `${this.filePath}.tmp.${process.pid}.${this.now()}`;
29887
+ const body = JSON.stringify({
29888
+ version: 1,
29889
+ sessions
29890
+ }, null, 2);
29891
+ await fs.writeFile(temp, body, "utf8");
29892
+ await fs.rename(temp, this.filePath);
29893
+ this.cache = sessions;
29894
+ }
29895
+ prune(sessions) {
29896
+ const entries = Object.entries(sessions);
29897
+ if (entries.length <= 64) return;
29898
+ entries.sort((left, right) => left[1].updatedAt - right[1].updatedAt).slice(0, entries.length - 64).forEach(([dshSessionId]) => {
29899
+ delete sessions[dshSessionId];
29900
+ });
29901
+ }
29902
+ };
29903
+ function parseRef(value, now) {
29904
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return void 0;
29905
+ const record = value;
29906
+ if (typeof record.acpSessionId !== "string" || record.acpSessionId === "") return void 0;
29907
+ if (typeof record.cwd !== "string" || record.cwd === "") return void 0;
29908
+ if (typeof record.covered !== "number" || !Number.isInteger(record.covered) || record.covered < 0) return void 0;
29909
+ if (typeof record.fingerprint !== "string" || record.fingerprint === "") return void 0;
29910
+ if (typeof record.tools !== "string" || record.tools === "") return void 0;
29911
+ if (typeof record.model !== "string" || record.model === "") return void 0;
29912
+ if (typeof record.updatedAt !== "number" || !Number.isFinite(record.updatedAt)) return void 0;
29913
+ if (now - record.updatedAt > 6048e5) return void 0;
29914
+ return {
29915
+ acpSessionId: record.acpSessionId,
29916
+ cwd: record.cwd,
29917
+ covered: record.covered,
29918
+ fingerprint: record.fingerprint,
29919
+ tools: record.tools,
29920
+ model: record.model,
29921
+ ...typeof record.effort === "string" && record.effort !== "" ? { effort: record.effort } : {},
29922
+ updatedAt: record.updatedAt
29923
+ };
29924
+ }
29925
+ //#endregion
29926
+ //#region src/host/providers/antigravity-acp/cooldown.ts
29927
+ /**
29928
+ * A short, durable cooldown after an upstream account/rate refusal.
29929
+ *
29930
+ * The point is not to retry sooner or smarter; it is to stop a user (or an
29931
+ * automated client) from putting the same account in front of the same wall
29932
+ * repeatedly. The marker is local, opaque, and contains no credentials.
29933
+ *
29934
+ * @module dsh-chatgpt-subscription/host/antigravity-acp/cooldown
29935
+ */
29936
+ /** How long an upstream refusal suppresses new prompts. */
29937
+ const UPSTREAM_COOLDOWN_MS = 6e4;
29938
+ /** Where the cooldown marker lives. */
29939
+ function antigravityAcpCooldownPath() {
29940
+ return path.join(dshHomeDir(), "storages", "antigravity-acp-upstream-cooldown.json");
29941
+ }
29942
+ /** File-backed cooldown shared by host restarts. */
29943
+ var AntigravityAcpUpstreamCooldownStore = class {
29944
+ filePath;
29945
+ now;
29946
+ blockedUntil;
29947
+ loading = null;
29948
+ writes = Promise.resolve();
29949
+ constructor(filePath = antigravityAcpCooldownPath(), now = Date.now) {
29950
+ this.filePath = filePath;
29951
+ this.now = now;
29952
+ }
29953
+ async remaining() {
29954
+ const until = await this.read();
29955
+ return until === void 0 ? 0 : Math.max(0, until - this.now());
29956
+ }
29957
+ async block() {
29958
+ const until = this.now() + UPSTREAM_COOLDOWN_MS;
29959
+ this.blockedUntil = until;
29960
+ await this.enqueue(async () => {
29961
+ await fs.mkdir(path.dirname(this.filePath), { recursive: true });
29962
+ const temp = `${this.filePath}.tmp.${process.pid}.${this.now()}`;
29963
+ await fs.writeFile(temp, JSON.stringify({
29964
+ version: 1,
29965
+ blockedUntil: until
29966
+ }), "utf8");
29967
+ await fs.rename(temp, this.filePath);
29968
+ });
29969
+ }
29970
+ async read() {
29971
+ if (this.blockedUntil !== void 0) return this.blockedUntil;
29972
+ if (this.loading !== null) return this.loading;
29973
+ this.loading = this.load().finally(() => {
29974
+ this.loading = null;
29975
+ });
29976
+ return this.loading;
29977
+ }
29978
+ async load() {
29979
+ try {
29980
+ const parsed = JSON.parse(await fs.readFile(this.filePath, "utf8"));
29981
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return void 0;
29982
+ const value = parsed.blockedUntil;
29983
+ if (typeof value !== "number" || !Number.isFinite(value)) return void 0;
29984
+ this.blockedUntil = value;
29985
+ return value;
29986
+ } catch {
29987
+ return;
29988
+ }
29989
+ }
29990
+ async enqueue(work) {
29991
+ const next = this.writes.then(work, work);
29992
+ this.writes = next.catch(() => void 0);
29993
+ return next;
29994
+ }
29995
+ };
29511
29996
  /** Budget for one catalogue read; a hung agent must not hold the picker. */
29512
29997
  const CATALOG_TIMEOUT_MS = 2e4;
29513
29998
  /** The reader, with the cache it maintains. */
@@ -29732,47 +30217,47 @@ function asRecord$18(value) {
29732
30217
  * The registry entry this build was verified against.
29733
30218
  *
29734
30219
  * Source: `https://github.com/agentclientprotocol/registry` →
29735
- * `antigravity-acp/agent.json`, fetched 2026-11-12. `license: proprietary`;
30220
+ * `antigravity-acp/agent.json`, latest entry checked against the official Registry.
29736
30221
  * the archive is fetched from `dl.google.com` at install time and is never
29737
30222
  * redistributed with this package.
29738
30223
  */
29739
- const ACP_BINARY_VERSION = "1.5.0";
30224
+ const ACP_BINARY_VERSION = "1.5.2";
29740
30225
  /** Platform archives, keyed by `process.platform` + `process.arch`. */
29741
30226
  const ACP_BINARY_RELEASES = {
29742
30227
  "win32-x64": {
29743
30228
  version: ACP_BINARY_VERSION,
29744
- url: "https://dl.google.com/agy-extensions/releases/windows/agy-acp-server-1.5.0-windows-x86_64.zip",
29745
- sha256: "6163f6b59b381bae419652dbae167bc8cda0ef29d665c0ba8af3d8c7fddd8867",
30229
+ url: "https://dl.google.com/agy-extensions/releases/windows/agy-acp-server-1.5.2-windows-x86_64.zip",
30230
+ sha256: "5cbadd4f4df698572473d8890fc26ec2dc1724501f06e3a963941daec2bd21d6",
29746
30231
  executable: "agy_acp_server.exe"
29747
30232
  },
29748
30233
  "win32-arm64": {
29749
30234
  version: ACP_BINARY_VERSION,
29750
- url: "https://dl.google.com/agy-extensions/releases/windows/agy-acp-server-1.5.0-windows-arm64.zip",
29751
- sha256: "340092b8af6dafc71eb15f4a8ec54b4d1f0bce16d1fa4d163b562c50b905f8f4",
30235
+ url: "https://dl.google.com/agy-extensions/releases/windows/agy-acp-server-1.5.2-windows-arm64.zip",
30236
+ sha256: "8a4b2ea8df2ffefae33309348752e9119d21a6d36090c0eb48631c2e8f5781ab",
29752
30237
  executable: "agy_acp_server.exe"
29753
30238
  },
29754
30239
  "darwin-arm64": {
29755
30240
  version: ACP_BINARY_VERSION,
29756
- url: "https://dl.google.com/agy-extensions/releases/macos/agy-acp-server-1.5.0-darwin-arm64.zip",
29757
- sha256: "c82ecb4ef476bfc35cbe5b2745cdddef873b99c9f5bd7fd11e5ca1fc1667a3fc",
30241
+ url: "https://dl.google.com/agy-extensions/releases/macos/agy-acp-server-1.5.2-darwin-arm64.zip",
30242
+ sha256: "123a16d5c40a8ac99e20f01a62b68dd860fd96b1c528dfb8eaa37ca8733d4845",
29758
30243
  executable: "agy_acp_server.par"
29759
30244
  },
29760
30245
  "darwin-x64": {
29761
30246
  version: ACP_BINARY_VERSION,
29762
- url: "https://dl.google.com/agy-extensions/releases/macos/agy-acp-server-1.5.0-darwin-x86_64.zip",
29763
- sha256: "86a94e33b25d4a38ff30526ad844546860aa9ed98698498d9e87d30eb794426e",
30247
+ url: "https://dl.google.com/agy-extensions/releases/macos/agy-acp-server-1.5.2-darwin-x86_64.zip",
30248
+ sha256: "92addb5580577b5356d35484d72d1a113d9c5312ad766bcb304983aa8e3fbb06",
29764
30249
  executable: "agy_acp_server.par"
29765
30250
  },
29766
30251
  "linux-x64": {
29767
30252
  version: ACP_BINARY_VERSION,
29768
- url: "https://dl.google.com/agy-extensions/releases/linux/agy-acp-server-1.5.0-linux-x86_64.zip",
29769
- sha256: "36f373e8948edf1727b39c7d62b5722d6a4474bdfd72b04ad3d6def571808c9f",
30253
+ url: "https://dl.google.com/agy-extensions/releases/linux/agy-acp-server-1.5.2-linux-x86_64.zip",
30254
+ sha256: "99dd8612450805011619d7b8447ce374c289e00549d8557f36790e1dd6256852",
29770
30255
  executable: "agy_acp_server.par"
29771
30256
  },
29772
30257
  "linux-arm64": {
29773
30258
  version: ACP_BINARY_VERSION,
29774
- url: "https://dl.google.com/agy-extensions/releases/linux/agy-acp-server-1.5.0-linux-arm64.zip",
29775
- sha256: "1e184f439477b54138e94440056b26a78c0a8075a8fd2ffda637ec31267c6459",
30259
+ url: "https://dl.google.com/agy-extensions/releases/linux/agy-acp-server-1.5.2-linux-arm64.zip",
30260
+ sha256: "e729e05ef54ef0763e48900032466b47fa7c9939cde257f93ba49410ab577acb",
29776
30261
  executable: "agy_acp_server.par"
29777
30262
  }
29778
30263
  };
@@ -30109,6 +30594,8 @@ const LOGIN_FAILURE_WINDOW_MS = 1e3;
30109
30594
  const LOGIN_STDERR_CAP = 2e3;
30110
30595
  /** Budget for one auth probe. */
30111
30596
  const AUTH_PROBE_BUDGET_MS = 3e4;
30597
+ /** Budget for the official ACP logout request. */
30598
+ const LOGOUT_BUDGET_MS = 15e3;
30112
30599
  /**
30113
30600
  * Start the official sign-in.
30114
30601
  *
@@ -30159,6 +30646,61 @@ async function startLogin(launch) {
30159
30646
  };
30160
30647
  }
30161
30648
  }
30649
+ /**
30650
+ * End the official sign-in through the ACP `logout` method.
30651
+ *
30652
+ * The ACP specification allows this only after the agent advertises
30653
+ * `agentCapabilities.auth.logout`; older servers simply keep the terminal
30654
+ * instruction on the card. As with sign-in, the official process owns the
30655
+ * credential store and performs the erase itself.
30656
+ *
30657
+ * @param launch - The resolved executable.
30658
+ * @param createClient - Test seam for the ACP connection.
30659
+ * @returns whether the agent confirmed sign-out, and why it did not.
30660
+ */
30661
+ async function logout(launch, createClient) {
30662
+ let client;
30663
+ try {
30664
+ client = createClient?.(launch) ?? new AcpClient({
30665
+ command: launch.command,
30666
+ args: launch.args,
30667
+ cwd: process.cwd()
30668
+ });
30669
+ if (asRecord$17(asRecord$17(asRecord$17(await client.request("initialize", {
30670
+ protocolVersion: 1,
30671
+ clientCapabilities: {
30672
+ fs: {
30673
+ readTextFile: false,
30674
+ writeTextFile: false
30675
+ },
30676
+ terminal: false
30677
+ },
30678
+ clientInfo: {
30679
+ name: "dsh-chatgpt-subscription",
30680
+ version: "1.0.0"
30681
+ }
30682
+ }))?.agentCapabilities)?.auth)?.logout === void 0) return {
30683
+ ok: false,
30684
+ error: "This Antigravity ACP server does not advertise ACP sign-out. Run `agy` and use /logout there."
30685
+ };
30686
+ const abort = new AbortController();
30687
+ const timer = setTimeout(() => abort.abort(), LOGOUT_BUDGET_MS);
30688
+ timer.unref?.();
30689
+ try {
30690
+ await client.request("logout", {}, abort.signal);
30691
+ return { ok: true };
30692
+ } finally {
30693
+ clearTimeout(timer);
30694
+ }
30695
+ } catch (error) {
30696
+ return {
30697
+ ok: false,
30698
+ error: error instanceof Error ? error.message : String(error)
30699
+ };
30700
+ } finally {
30701
+ await client?.dispose().catch(() => void 0);
30702
+ }
30703
+ }
30162
30704
  async function startProtocolLogin(client, methodId) {
30163
30705
  const completion = client.request("authenticate", { methodId }).then(() => ({ started: true }), (error) => ({
30164
30706
  started: false,
@@ -30476,9 +31018,15 @@ function registerAntigravityAcpRoutes(ctx, options) {
30476
31018
  ok: false,
30477
31019
  error: "Cross-origin request rejected."
30478
31020
  });
30479
- return sendJson$23(response, 400, {
31021
+ const result = await options.logout();
31022
+ if (!result.ok) return sendJson$23(response, 400, {
30480
31023
  ok: false,
30481
- error: "Sign-out belongs to the Antigravity CLI. Run `agy` and use /logout there; this card will then show the new state."
31024
+ error: result.error ?? "Sign-out could not be completed."
31025
+ });
31026
+ options.catalog.invalidate();
31027
+ return sendJson$23(response, 200, {
31028
+ ok: true,
31029
+ value: await readStatus(options, { fresh: true })
30482
31030
  });
30483
31031
  }
30484
31032
  if (path === "usage") {
@@ -34183,7 +34731,7 @@ function buildOpenCodeGoChatRequest(options, images, entry, settings) {
34183
34731
  });
34184
34732
  const content = chatContent$2(message, images, false);
34185
34733
  const seedReasoning = chatReasoningReplayText(message, options.provider, options.model);
34186
- if (content !== "" || toolCalls.length > 0) messages.push({
34734
+ if (content !== "" || toolCalls.length > 0 || seedReasoning !== null) messages.push({
34187
34735
  role: "assistant",
34188
34736
  content,
34189
34737
  ...toolCalls.length > 0 ? { tool_calls: toolCalls } : {},
@@ -35813,7 +36361,7 @@ function feedRelayOneAnthropicPayload(state, event) {
35813
36361
  type: "tool-call-delta",
35814
36362
  index,
35815
36363
  id: toToolCallId(id),
35816
- name: name || void 0,
36364
+ ...name === "" ? {} : { name },
35817
36365
  argumentsDelta: seed
35818
36366
  }];
35819
36367
  }
@@ -35867,7 +36415,7 @@ function feedRelayOneAnthropicPayload(state, event) {
35867
36415
  type: "tool-call-delta",
35868
36416
  index: tool.index,
35869
36417
  id: toToolCallId(tool.id),
35870
- name: tool.name || void 0,
36418
+ ...tool.name === "" ? {} : { name: tool.name },
35871
36419
  argumentsDelta: part
35872
36420
  }];
35873
36421
  }
@@ -38601,7 +39149,7 @@ function registerCopilotRoutes(ctx, options) {
38601
39149
  login.cancel();
38602
39150
  return sendJson$21(response, 200, {
38603
39151
  ok: true,
38604
- value: login.status()
39152
+ value: await statusOf()
38605
39153
  });
38606
39154
  }
38607
39155
  if (path === "settings") {
@@ -38618,11 +39166,11 @@ function registerCopilotRoutes(ctx, options) {
38618
39166
  if (typeof body.defaultReasoningEffort === "string" || body.defaultReasoningEffort === null) patch.defaultReasoningEffort = body.defaultReasoningEffort;
38619
39167
  if (typeof body.selectedAccountId === "string" || body.selectedAccountId === null) patch.selectedAccountId = body.selectedAccountId;
38620
39168
  if (typeof body.contextWindowOverrides === "object" && body.contextWindowOverrides !== null) patch.contextWindowOverrides = body.contextWindowOverrides;
38621
- const next = await settings.update(patch);
39169
+ await settings.update(patch);
38622
39170
  ctx.emit?.("llm/adapters-updated");
38623
39171
  return sendJson$21(response, 200, {
38624
39172
  ok: true,
38625
- value: next
39173
+ value: await statusOf()
38626
39174
  });
38627
39175
  }
38628
39176
  if (path === "accounts") {
@@ -38650,7 +39198,7 @@ function registerCopilotRoutes(ctx, options) {
38650
39198
  await accountAction(action, accountId);
38651
39199
  return sendJson$21(response, 200, {
38652
39200
  ok: true,
38653
- value: { ok: true }
39201
+ value: await statusOf()
38654
39202
  });
38655
39203
  }
38656
39204
  if (path === "accounts/refresh") {
@@ -43385,9 +43933,15 @@ const QIANFAN_DEPLOYMENT_IDS = ["personal", "team"];
43385
43933
  function isQianfanDeploymentId(value) {
43386
43934
  return value === "personal" || value === "team";
43387
43935
  }
43388
- const QIANFAN_REASONING_EFFORTS = ["none", "high"];
43936
+ const QIANFAN_REASONING_EFFORTS = [
43937
+ "none",
43938
+ "low",
43939
+ "medium",
43940
+ "high",
43941
+ "max"
43942
+ ];
43389
43943
  function isQianfanReasoningEffort(value) {
43390
- return value === "none" || value === "high";
43944
+ return value === "none" || value === "low" || value === "medium" || value === "high" || value === "max";
43391
43945
  }
43392
43946
  const QIANFAN_IMAGE_DETAILS = [
43393
43947
  "low",
@@ -43889,7 +44443,7 @@ function buildQianfanChatRequest(options, images = NO_RESOLVED_IMAGES$3, setting
43889
44443
  });
43890
44444
  }
43891
44445
  const requested = typeof options.reasoningEffort === "string" && options.reasoningEffort.trim() !== "" ? options.reasoningEffort.trim() : settings.defaultReasoningEffort;
43892
- const effort = requested !== null && (requested === "none" || requested === "high") ? requested : null;
44446
+ const effort = requested !== null && isQianfanReasoningEffort(requested) ? requested : null;
43893
44447
  const thinkingSent = effort !== null && entry.reasoningEfforts.length > 0;
43894
44448
  return {
43895
44449
  body: {
@@ -44536,7 +45090,7 @@ function parseSettingsPatch$9(body) {
44536
45090
  patch.contextWindowOverrides = overrides;
44537
45091
  }
44538
45092
  if (body.defaultReasoningEffort !== void 0) {
44539
- if (body.defaultReasoningEffort !== null && !isQianfanReasoningEffort(body.defaultReasoningEffort)) throw new Error("defaultReasoningEffort must be none, high or null");
45093
+ if (body.defaultReasoningEffort !== null && !isQianfanReasoningEffort(body.defaultReasoningEffort)) throw new Error("defaultReasoningEffort must be none, low, medium, high, max or null");
44540
45094
  patch.defaultReasoningEffort = body.defaultReasoningEffort;
44541
45095
  }
44542
45096
  if (body.imageDetail !== void 0) {
@@ -53976,7 +54530,7 @@ function buildOpenCodeZenChatRequest(options, images, entry, settings) {
53976
54530
  });
53977
54531
  const content = chatContent$1(message, images, false);
53978
54532
  const seedReasoning = chatReasoningReplayText(message, options.provider, options.model);
53979
- if (content !== "" || toolCalls.length > 0) messages.push({
54533
+ if (content !== "" || toolCalls.length > 0 || seedReasoning !== null) messages.push({
53980
54534
  role: "assistant",
53981
54535
  content,
53982
54536
  ...toolCalls.length > 0 ? { tool_calls: toolCalls } : {},
@@ -108518,8 +109072,14 @@ const TOOL_RESULT_IMAGE_TEXT = "Attached image(s) from tool result:";
108518
109072
  function flattenText(blocks) {
108519
109073
  return (blocks ?? []).filter((block) => block.type === "text").map((block) => block.text).join("");
108520
109074
  }
108521
- /** Convert one assistant message, keeping tool calls and reasoning. */
108522
- function serializeAssistant(message) {
109075
+ /**
109076
+ * Convert one assistant message, keeping tool calls and reasoning.
109077
+ *
109078
+ * The gateway streams reasoning as `reasoning`, but DeepSeek replays it only
109079
+ * when the same text arrives as `reasoning_content` (upstream #9618). Echoing
109080
+ * the observed field therefore loses the plan after every tool call.
109081
+ */
109082
+ function serializeAssistant(message, reasoningField) {
108523
109083
  const content = message.content ?? [];
108524
109084
  const text = flattenText(content);
108525
109085
  const reasoning = content.filter((block) => block.type === "reasoning").map((block) => block.text).join("");
@@ -108534,7 +109094,7 @@ function serializeAssistant(message) {
108534
109094
  return {
108535
109095
  role: "assistant",
108536
109096
  content: text,
108537
- ...reasoning.length > 0 ? { [openDesignReasoningDialect.outboundKey()]: reasoning } : {},
109097
+ ...reasoning.length > 0 ? { [reasoningField]: reasoning } : {},
108538
109098
  ...toolCalls.length > 0 ? { tool_calls: toolCalls } : {}
108539
109099
  };
108540
109100
  }
@@ -108628,7 +109188,7 @@ function removalNotice(names) {
108628
109188
  * chat request, so it is dropped too; a pure tool-result message never took that
108629
109189
  * path, because its answers travel as `tool` messages.
108630
109190
  */
108631
- function serializeMessages$1(messages, images) {
109191
+ function serializeMessages$1(messages, images, reasoningField = openDesignReasoningDialect.outboundKey()) {
108632
109192
  const wire = [];
108633
109193
  let pendingToolImages = [];
108634
109194
  /** Call ids of the most recent assistant tool_calls still awaiting an answer. */
@@ -108692,7 +109252,7 @@ function serializeMessages$1(messages, images) {
108692
109252
  if (message.role === "assistant") {
108693
109253
  flushToolImages();
108694
109254
  flushDeferred();
108695
- wire.push(serializeAssistant(message));
109255
+ wire.push(serializeAssistant(message, reasoningField));
108696
109256
  awaiting = (message.content ?? []).filter((block) => block.type === "tool-call").map((block) => block.id);
108697
109257
  continue;
108698
109258
  }
@@ -108798,7 +109358,8 @@ function buildOpenDesignBody(options, connection, images) {
108798
109358
  role: "system",
108799
109359
  content: options.system
108800
109360
  });
108801
- messages.push(...serializeMessages$1(options.messages, images));
109361
+ const reasoningField = isDeepSeekModel(options.model) ? "reasoning_content" : openDesignReasoningDialect.outboundKey();
109362
+ messages.push(...serializeMessages$1(options.messages, images, reasoningField));
108802
109363
  const tools = (options.tools ?? []).map((tool) => ({
108803
109364
  type: "function",
108804
109365
  function: {
@@ -109265,7 +109826,9 @@ const RETRY_POLICY$4 = resolveRetryPolicy({
109265
109826
  "SERVER",
109266
109827
  "TIMEOUT",
109267
109828
  "TRANSPORT",
109268
- "INVALID_TOOL_ARGUMENTS"
109829
+ "INVALID_TOOL_ARGUMENTS",
109830
+ "STREAM_CLOSED",
109831
+ "UPSTREAM"
109269
109832
  ],
109270
109833
  backoff: {
109271
109834
  initialDelayMs: 1500,
@@ -109468,7 +110031,8 @@ var OpenDesignAdapter = class extends LlmAdapter {
109468
110031
  }
109469
110032
  }
109470
110033
  if (response === void 0) {
109471
- lastError = new LlmError$1(`${errorChain$1(transportError)} The request never reached the gateway: ${baseURL} failed during TLS/connect. Check the network or proxy.`, "TRANSPORT", { cause: transportError });
110034
+ const note = errorChain$1(transportError);
110035
+ lastError = new LlmError$1(isPreConnectionFailure(transportError) ? `${note} The request never reached the gateway: ${baseURL} failed during TLS/connect. Check the network or proxy.` : `${note} The gateway connection failed before response headers (HTTP/2 or proxy reset): ${baseURL}. Check the proxy path.`, "TRANSPORT", { cause: transportError });
109472
110036
  break;
109473
110037
  }
109474
110038
  if (!response.ok) {
@@ -120556,7 +121120,7 @@ function mergeGoalUpdate(current, update) {
120556
121120
  return prefix.length > 0 ? `${prefix}...${suffix}` : compactedUpdate;
120557
121121
  }
120558
121122
  /** 消息是否只表示“接着做”(“继续”“好的,继续”“ok go on”)。 */
120559
- function isContinuationOnly(text) {
121123
+ function isContinuationOnly$1(text) {
120560
121124
  let rest = text.toLowerCase().replace(/[\s\p{P}\p{S}]+/gu, "");
120561
121125
  if (rest.length > MAX_CONTINUATION_CHARS) return false;
120562
121126
  while (rest.length > 0) {
@@ -120584,7 +121148,7 @@ function classifyGoalIntake(message) {
120584
121148
  const text = stripReminders(messageText$1(message["content"]));
120585
121149
  if (text.length === 0 || ANCHOR_TEXT.test(text)) return IGNORE;
120586
121150
  const kind = typeof source?.["kind"] === "string" ? source["kind"] : void 0;
120587
- if (kind === void 0 || kind === "user" || kind === "webhook") return isContinuationOnly(text) ? CONTINUE : {
121151
+ if (kind === void 0 || kind === "user" || kind === "webhook") return isContinuationOnly$1(text) ? CONTINUE : {
120588
121152
  kind: "instruction",
120589
121153
  text
120590
121154
  };
@@ -120595,7 +121159,7 @@ function classifyGoalIntake(message) {
120595
121159
  text: objective
120596
121160
  };
120597
121161
  }
120598
- if (kind === "user-question-reply") return isContinuationOnly(text) ? CONTINUE : {
121162
+ if (kind === "user-question-reply") return isContinuationOnly$1(text) ? CONTINUE : {
120599
121163
  kind: "reply",
120600
121164
  text
120601
121165
  };
@@ -121097,7 +121661,7 @@ function defaultEstimateContextTokens(agent, observedChars) {
121097
121661
  }
121098
121662
  return Math.floor(chars / 3.5);
121099
121663
  }
121100
- function formatApproxTokens$1(tokens) {
121664
+ function formatApproxTokens(tokens) {
121101
121665
  if (tokens >= 1e3) return `${Math.round(tokens / 1e3)}k`;
121102
121666
  return String(tokens);
121103
121667
  }
@@ -121108,7 +121672,7 @@ function formatApproxTokens$1(tokens) {
121108
121672
  * GOAL 只含最新回合;更早回合标注为仅供参考,且有任务清单时由 TASKS 承接连续性而不再渲染。
121109
121673
  */
121110
121674
  function renderStateAnchorText(input) {
121111
- const header = `${DEEPSEEK_V41_FLASH_ANCHOR_PREFIX} | step=${input.step} | ctx~${formatApproxTokens$1(input.approxTokens)} | trigger=${input.reason}]`;
121675
+ const header = `${DEEPSEEK_V41_FLASH_ANCHOR_PREFIX} | step=${input.step} | trigger=${input.reason}]`;
121112
121676
  const goalLine = input.goal.length > 0 ? `GOAL: ${input.goal}` : void 0;
121113
121677
  const toolLabel = input.lastErrorTool ? ` (${input.lastErrorTool})` : "";
121114
121678
  const alertLine = input.reason === "consecutive-errors" ? `ALERT: ${input.consecutiveErrors} consecutive tool failures${toolLabel}. Do NOT retry the same approach; switch to minimal verification or inspect the root definition.` : void 0;
@@ -121230,7 +121794,7 @@ function installDeepSeekV41FlashStateAnchor(ctx, options = {}) {
121230
121794
  if (state.lastEffortWarnedTransition !== transition) {
121231
121795
  state.lastEffortWarnedTransition = transition;
121232
121796
  try {
121233
- host?.logger?.warn?.(`[dsh-chatgpt-subscription] DeepSeek V4.1 Flash reasoningEffort changed (${transition}) at ~${formatApproxTokens$1(approxTokens)} context tokens` + (route.sessionId ? ` (session ${route.sessionId})` : "") + "; changing effort mid-session rewrites the leading system prefix and invalidates the 50x KV prefix cache. Keep reasoningEffort static within one long session and route lower/higher effort work to subagents.");
121797
+ host?.logger?.warn?.(`[dsh-chatgpt-subscription] DeepSeek V4.1 Flash reasoningEffort changed (${transition}) at ~${formatApproxTokens(approxTokens)} context tokens` + (route.sessionId ? ` (session ${route.sessionId})` : "") + "; changing effort mid-session rewrites the leading system prefix and invalidates the 50x KV prefix cache. Keep reasoningEffort static within one long session and route lower/higher effort work to subagents.");
121234
121798
  } catch {}
121235
121799
  }
121236
121800
  }
@@ -121283,7 +121847,6 @@ function installDeepSeekV41FlashStateAnchor(ctx, options = {}) {
121283
121847
  state.lastAnchoredStep = state.stepsInTurn;
121284
121848
  const text = renderStateAnchorText({
121285
121849
  step: state.stepsInTurn,
121286
- approxTokens,
121287
121850
  reason: trigger,
121288
121851
  goal,
121289
121852
  earlierGoal: earlierGoals(state.goals),
@@ -121495,12 +122058,9 @@ function classifyProgress(state, name, args, result) {
121495
122058
  }
121496
122059
  return true;
121497
122060
  }
121498
- function formatChars(chars) {
121499
- return chars >= 1e3 ? `${Math.round(chars / 1e3)}k` : String(chars);
121500
- }
121501
122061
  /** 渲染进展检查通知。 */
121502
122062
  function renderProgressNotice(input) {
121503
- return `${`${DEEPSEEK_V41_FLASH_PROGRESS_PREFIX} | level=${input.level} | steps=${input.steps} | reasoning~${formatChars(input.reasoningChars)} chars${input.interrupted ? " | interrupted" : ""}]`}\n${input.interrupted ? "Your previous reasoning was stopped because the task has made no progress since the last check. " : "No new evidence, edit, or completed task since the recent steps. "}${input.level === 1 ? "Before reasoning further, make one minimal tool call that tests your current hypothesis, then act on its result." : input.level === 2 ? "Stop extending the analysis. In a few lines state the confirmed facts, the suspected root cause, what is still unknown, and the single next action; then take that action." : "Do not continue analysing. Identify the specific information you are missing and ask the user for it: call ask_user_question once if that tool is available, otherwise end this turn with one concise question. Do not claim the task is complete."}`;
122063
+ return `${`${DEEPSEEK_V41_FLASH_PROGRESS_PREFIX} | level=${input.level} | steps=${input.steps}${input.interrupted ? " | interrupted" : ""}]`}\n${input.interrupted ? "Your previous reasoning was stopped because the task has made no progress since the last check. " : "No new evidence, edit, or completed task since the recent steps. "}${input.level === 1 ? "Before reasoning further, make one minimal tool call that tests your current hypothesis, then act on its result." : input.level === 2 ? "Stop extending the analysis. In a few lines state the confirmed facts, the suspected root cause, what is still unknown, and the single next action; then take that action." : "Do not continue analysing. Identify the specific information you are missing and ask the user for it: call ask_user_question once if that tool is available, otherwise end this turn with one concise question. Do not claim the task is complete."}`;
121504
122064
  }
121505
122065
  function createNotice(text) {
121506
122066
  return createUserMessage$1({
@@ -121604,7 +122164,6 @@ function installDeepSeekV41FlashProgressGovernor(ctx, options = {}) {
121604
122164
  const text = renderProgressNotice({
121605
122165
  level: state.level,
121606
122166
  steps: state.stepsSinceProgress,
121607
- reasoningChars: state.reasoningSinceProgress,
121608
122167
  interrupted: false
121609
122168
  });
121610
122169
  const existing = Array.isArray(decision.messages) ? decision.messages : [];
@@ -121634,7 +122193,6 @@ function installDeepSeekV41FlashProgressGovernor(ctx, options = {}) {
121634
122193
  const text = renderProgressNotice({
121635
122194
  level,
121636
122195
  steps: state.stepsSinceProgress,
121637
- reasoningChars: state.reasoningSinceProgress,
121638
122196
  interrupted: true
121639
122197
  });
121640
122198
  warn(`DeepSeek V4.1 Flash progress governor stopped no-progress reasoning at level ${level} (cut ${state.cutsThisRequest}/${maxCuts}, session ${sessionId})`);
@@ -121936,9 +122494,6 @@ function buildReasoningSeedMessages(provider, model) {
121936
122494
  content: [{
121937
122495
  type: "reasoning",
121938
122496
  text: exchange.reasoning
121939
- }, {
121940
- type: "text",
121941
- text: exchange.reply
121942
122497
  }],
121943
122498
  source: {
121944
122499
  kind: "model",
@@ -121951,7 +122506,7 @@ function buildReasoningSeedMessages(provider, model) {
121951
122506
  model,
121952
122507
  form: "full"
121953
122508
  },
121954
- blocks: [{ type: "reasoning" }, { type: "text" }]
122509
+ blocks: [{ type: "reasoning" }]
121955
122510
  } } : carriage === "marker" ? { replayState: { response: { kind: REASONING_SEED_SOURCE_KIND } } } : {}
121956
122511
  }
121957
122512
  }]);
@@ -121959,6 +122514,23 @@ function buildReasoningSeedMessages(provider, model) {
121959
122514
  function isSeed(message) {
121960
122515
  return typeof message?.id === "string" && message.id.startsWith("dsh-reasoning-seed-");
121961
122516
  }
122517
+ const REASONING_SEED_SCOPE = [
122518
+ "Archived `Practice round` exchanges are unrelated few-shot examples of reasoning style, not this session's history.",
122519
+ "They never establish a goal, pending work, facts, or tools to call. Only live user messages establish tasks.",
122520
+ "Short requests and greetings are real requests too; resolve follow-ups such as 继续 from the live conversation alone.",
122521
+ "Host system-reminder messages are context, not user turns. All active mode, approval, permission and tool rules remain unchanged."
122522
+ ].join(" ");
122523
+ const REASONING_SEED_CONTINUATION = /^(?:继续|继续吧|接着做|接着来|改一下|continue|go on)[!!.。??]*$/iu;
122524
+ function isContinuationOnly(message) {
122525
+ const content = message?.content;
122526
+ if (content?.length !== 1) return false;
122527
+ const block = content[0];
122528
+ return block.type === "text" && typeof block.text === "string" && REASONING_SEED_CONTINUATION.test(block.text.trim());
122529
+ }
122530
+ function isLiveUserTurn(message) {
122531
+ const source = message.source;
122532
+ return message.role === "user" && (source === void 0 || source.kind === "user");
122533
+ }
121962
122534
  /**
121963
122535
  * 把固定示范分散到对话中:首条用户消息前插入
121964
122536
  * {@link REASONING_SEED_INITIAL_EXCHANGES} 组,之后每隔
@@ -121966,6 +122538,7 @@ function isSeed(message) {
121966
122538
  *
121967
122539
  * 插入位置只由原始消息序号决定。历史增长不会移动旧示范,因此已有前缀缓存保持命中;
121968
122540
  * 同时较近的示范能对抗模型近期长思考的自我强化。工具调用与其结果之间不插入。
122541
+ * 宿主提醒不计入间隔,也不会把示范移动到真人消息之后;每组后的边界声明示范不构成当前任务。
121969
122542
  * 前导段之后若不是用户消息(例如开头就有 developer 工具变更),按原样返回。
121970
122543
  * @param messages - 本次请求的消息。
121971
122544
  * @param provider - 线路 id。
@@ -121979,6 +122552,8 @@ function insertReasoningSeed(messages, provider, model) {
121979
122552
  if (messages[index]?.role !== "user") return messages;
121980
122553
  const seed = buildReasoningSeedMessages(provider, model);
121981
122554
  if (seed.length === 0) return messages;
122555
+ const lastLiveUser = messages.findLastIndex(isLiveUserTurn);
122556
+ if (isContinuationOnly(messages[lastLiveUser]) && messages.slice(0, lastLiveUser).every((message) => !isLiveUserTurn(message))) return messages;
121982
122557
  const out = [...messages.slice(0, index)];
121983
122558
  const exchanges = REASONING_SEED_EXCHANGES.length;
121984
122559
  let exchange = 0;
@@ -121987,7 +122562,19 @@ function insertReasoningSeed(messages, provider, model) {
121987
122562
  out.push(...seed.slice(exchange * 2, exchange * 2 + 2));
121988
122563
  exchange += 1;
121989
122564
  };
122565
+ const insertBoundary = () => {
122566
+ out.push({
122567
+ id: `${REASONING_SEED_ID_PREFIX}boundary`,
122568
+ role: "user",
122569
+ content: [{
122570
+ type: "text",
122571
+ text: `<system-reminder>\n${REASONING_SEED_SCOPE}\n</system-reminder>`
122572
+ }],
122573
+ source: { kind: REASONING_SEED_SOURCE_KIND }
122574
+ });
122575
+ };
121990
122576
  for (let initial = 0; initial < 5; initial += 1) insertNext();
122577
+ insertBoundary();
121991
122578
  let sinceSeed = 0;
121992
122579
  for (; index < messages.length; index += 1) {
121993
122580
  const message = messages[index];
@@ -121995,14 +122582,15 @@ function insertReasoningSeed(messages, provider, model) {
121995
122582
  out.push(message);
121996
122583
  continue;
121997
122584
  }
121998
- sinceSeed += 1;
121999
- if (sinceSeed >= 2) {
122585
+ const liveUser = isLiveUserTurn(message);
122586
+ if (liveUser || message.role === "assistant") sinceSeed += 1;
122587
+ if (liveUser && !isContinuationOnly(message) && sinceSeed >= 2) {
122000
122588
  insertNext();
122589
+ insertBoundary();
122001
122590
  sinceSeed = 0;
122002
122591
  }
122003
122592
  out.push(message);
122004
122593
  }
122005
- if (sinceSeed >= 2 && messages.at(-1)?.role === "tool") insertNext();
122006
122594
  return out;
122007
122595
  }
122008
122596
  /** 读取实验开关(兼容 volatile 活引用与普通布尔值);默认关闭。 */
@@ -122591,13 +123179,9 @@ function recordActiveFile(state, file) {
122591
123179
  state.activeFiles.push(file);
122592
123180
  if (state.activeFiles.length > MAX_ACTIVE_FILES) state.activeFiles.splice(0, state.activeFiles.length - MAX_ACTIVE_FILES);
122593
123181
  }
122594
- function formatApproxTokens(tokens) {
122595
- if (tokens >= 1e3) return `${Math.round(tokens / 1e3)}k`;
122596
- return String(tokens);
122597
- }
122598
123182
  /** 渲染紧凑尾部状态锚文本(保持简短以减少噪声与 token 开销)。 */
122599
123183
  function renderOpenModelStateAnchorText(input) {
122600
- const lines = [`${OPEN_MODEL_ANCHOR_PREFIX} | model=${input.profile.label} | step=${input.step} | ctx~${formatApproxTokens(input.approxTokens)} | trigger=${input.reason}]`];
123184
+ const lines = [`${OPEN_MODEL_ANCHOR_PREFIX} | model=${input.profile.label} | step=${input.step} | trigger=${input.reason}]`];
122601
123185
  if (input.goal.length > 0) lines.push(`${input.goalMerged === true ? "GOAL (later parts override earlier)" : "GOAL"}: ${input.goal}`);
122602
123186
  const hasTasks = input.tasks !== void 0 && input.tasks.length > 0;
122603
123187
  if (hasTasks) lines.push(`TASKS: ${input.tasks}`);
@@ -122727,7 +123311,6 @@ function installOpenModelStateAnchor(ctx, options = {}) {
122727
123311
  const text = renderOpenModelStateAnchorText({
122728
123312
  profile,
122729
123313
  step: state.stepsInTurn,
122730
- approxTokens,
122731
123314
  reason: trigger,
122732
123315
  goal,
122733
123316
  goalMerged: state.goals.turns[state.goals.turns.length - 1]?.merged === true,
@@ -135072,7 +135655,7 @@ function buildRelayOneChatRequest(options, images, entry, settings) {
135072
135655
  });
135073
135656
  const content = chatContent(message, images, false);
135074
135657
  const seedReasoning = chatReasoningReplayText(message, options.provider, options.model);
135075
- if (content !== "" || toolCalls.length > 0) messages.push({
135658
+ if (content !== "" || toolCalls.length > 0 || seedReasoning !== null) messages.push({
135076
135659
  role: "assistant",
135077
135660
  content,
135078
135661
  ...toolCalls.length > 0 ? { tool_calls: toolCalls } : {},
@@ -135254,7 +135837,7 @@ function feedRelayOneChatPayload(state, payload) {
135254
135837
  type: "tool-call-delta",
135255
135838
  index: tool.index,
135256
135839
  id: toToolCallId(tool.id),
135257
- name: tool.name || void 0,
135840
+ ...tool.name === "" ? {} : { name: tool.name },
135258
135841
  argumentsDelta: args
135259
135842
  });
135260
135843
  });
@@ -135672,6 +136255,7 @@ var RelayOneAdapter = class extends LlmAdapter {
135672
136255
  for await (const chunk of parseResponsesStream(response, signal, void 0, activity, checkpoint ?? void 0)) yield checkpoint === null ? chunk : withRelayOneCompactionMetadata(chunk, checkpoint);
135673
136256
  } catch (error) {
135674
136257
  if (error instanceof LlmError$1 && /Codex|ChatGPT/.test(error.message)) throw new LlmError$1(error.message.replace(/Codex|ChatGPT/g, "RelayOne"), error.code, { cause: error });
136258
+ if (error instanceof LlmError$1 && (error.code === "UPSTREAM_ERROR" || error.code === "UPSTREAM")) throw new LlmError$1(error.message, "SERVER_ERROR", { cause: error });
135675
136259
  throw error;
135676
136260
  } finally {
135677
136261
  await response.body?.cancel().catch(() => void 0);
@@ -141115,7 +141699,8 @@ function apply(ctx, pluginConfig = {}) {
141115
141699
  if (fetchForLine === void 0) {
141116
141700
  fetchForLine = proxyManager.createFetch({
141117
141701
  line,
141118
- ...line === "kimi-code" ? { headersTimeoutMs: TRANSPORT_HEADERS_TIMEOUT_MS } : {}
141702
+ ...line === "kimi-code" ? { headersTimeoutMs: TRANSPORT_HEADERS_TIMEOUT_MS } : {},
141703
+ ...line === "opendesign" ? { allowH2: false } : {}
141119
141704
  });
141120
141705
  lineProxyFetches.set(line, fetchForLine);
141121
141706
  }
@@ -141148,6 +141733,8 @@ function apply(ctx, pluginConfig = {}) {
141148
141733
  attachments: ctx.attachments
141149
141734
  }, ollamaAccountPool);
141150
141735
  const antigravityAcpSettings = new AntigravityAcpSettingsStore();
141736
+ const antigravityAcpSessionState = new AntigravityAcpSessionStateStore();
141737
+ const antigravityAcpCooldown = new AntigravityAcpUpstreamCooldownStore();
141151
141738
  const antigravityAcpBinary = new AcpBinaryCache(async (options) => {
141152
141739
  return resolveAcpBinary((await antigravityAcpSettings.read()).binaryPath, { download: options.download !== false });
141153
141740
  });
@@ -141175,7 +141762,9 @@ function apply(ctx, pluginConfig = {}) {
141175
141762
  synced: !read.fromSnapshot
141176
141763
  };
141177
141764
  },
141178
- attachments: ctx.attachments
141765
+ attachments: ctx.attachments,
141766
+ sessionState: antigravityAcpSessionState,
141767
+ cooldown: antigravityAcpCooldown
141179
141768
  });
141180
141769
  antigravityAcpCatalog.rehydrate().catch(() => void 0);
141181
141770
  const antigravityAcpAuth = new AcpAuthCache(() => probeAuthWithLaunch(async () => {
@@ -141240,6 +141829,23 @@ function apply(ctx, pluginConfig = {}) {
141240
141829
  };
141241
141830
  }
141242
141831
  },
141832
+ logout: async () => {
141833
+ try {
141834
+ const result = await logout(await resolveAntigravityLaunch());
141835
+ if (result.ok) {
141836
+ antigravityAcpAuth.invalidate();
141837
+ antigravityAcpCatalog.invalidate();
141838
+ await antigravityAcpAdapter.forgetConversations().catch(() => void 0);
141839
+ await antigravityAcpSessionState.clear().catch(() => void 0);
141840
+ }
141841
+ return result;
141842
+ } catch (error) {
141843
+ return {
141844
+ ok: false,
141845
+ error: error instanceof Error ? error.message : String(error)
141846
+ };
141847
+ }
141848
+ },
141243
141849
  auth: (options) => antigravityAcpAuth.read(options),
141244
141850
  usage: () => antigravityAcpAdapter.usage(),
141245
141851
  occupancy: () => antigravityAcpAdapter.occupancy(),