dsh-agy-link 0.6.32 → 0.6.34

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 CHANGED
@@ -1,5 +1,33 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.34 (2026-11-18)
4
+
5
+ ### English
6
+
7
+ - **Fix(regression from v0.6.32/PR #119): subagent turns no longer die 5s after going idle (fixes #124).** Two linked defects. (1) `RunRecording.hasResult` was `resultConversationId !== null`, but `init` sets that id on the very first frame — so it was true before any `result` envelope, the synthetic result appended on an idle-grace kill never ran, and every such turn ended in `agy stream ended without a result event`. It now reflects an actual `result` event; the conversation id still comes from `init`. (2) The 5s idle reaper could not tell an orphaned background command from agy legitimately waiting for `invoke_subagent` / `send_message` / `run_workflow` / `swarm`. `RunningProcess.exemptIdleGrace()` now suspends the reaper while such a tool is outstanding (raised by the tool watchdog, cleared when the root agent speaks again), and new stdout output cancels a pending kill so a wake-up cannot race it. The orphan reaper still fires once the wait ends, and `maxTurnMinutes` / the activity watchdog still bound the total.
8
+ - **Fix(diagnostics): a stale model snapshot heals itself before failing the turn (fixes #125).** `accountSupportsModel()` still answers per account — that answer routes requests, so corroborating across accounts made selection pick an account that could not serve the model. Instead, when EVERY enabled account is denied *solely* because the requested model is missing from its per-model snapshot, `selectSessionAccount()` now refreshes pool quotas + catalog once (20s cap, non-forced so cooldowns are respected) and retries selection. A genuinely unsupported model simply fails the retry; quota/auth/cooldown blockers never trigger the refresh.
9
+ - **Refactor(modules):** extracted `src/provider/tool-watchdog.ts` and `src/host/model-support.ts` so `attempt.ts` / `pool.ts` stay under the 600-line budget with cohesive units rather than compressed comments. Test margins for two subprocess-based suites were widened so a cold Node start on a busy host cannot fail them spuriously.
10
+
11
+ ### 中文
12
+
13
+ - **修复(v0.6.32 / PR #119 的回归):子代理轮次不再在空闲 5 秒后被误杀(修复 #124)。** 两个联动缺陷。(1) `RunRecording.hasResult` 原先判断 `resultConversationId !== null`,而 `init` 在第一帧就写入了该 id——于是任何真实运行从第一帧起 `hasResult` 就为真,idle 宽限终止时合成的 result 成了死代码,每轮都以 `agy stream ended without a result event` 结束。现在只认真正的 `result` 事件;会话 id 仍由 `init` 提供。(2) 5 秒 idle 回收器无法区分「残留后台命令」与「agy 正常等待子代理回报」。新增 `RunningProcess.exemptIdleGrace()`:子代理协作工具未完成时挂起回收器(由工具看门狗置位、根 Agent 再次发言时清除),并让新的 stdout 输出取消已挂起的终止,避免唤醒竞态被误杀。等待结束后残留后台任务仍会被回收,总时长仍受 `maxTurnMinutes` 与活动看门狗约束。
14
+ - **修复(诊断):陈旧模型快照在整轮失败前先自愈一次(修复 #125)。** `accountSupportsModel()` 仍按账号作答——该答案用于路由,跨账号互证会让选择器挑到无法服务该模型的账号。改为:当**所有启用账号都仅因「型号不在 per-model 快照」被淘汰**时,`selectSessionAccount()` 先刷新一次号池额度与目录(上限 20s、非强制以尊重冷却),再重试选择。型号确实不受支持时重试仍失败;额度/认证/冷却类阻塞不会触发刷新。
15
+ - **重构(模块)**:抽出 `src/provider/tool-watchdog.ts` 与 `src/host/model-support.ts`,让 `attempt.ts` / `pool.ts` 以高内聚单元而非压缩注释维持在 600 行预算内。两处子进程测试的 margin 放宽,避免忙主机上冷启动 Node 造成的假失败。
16
+
17
+ ## 0.6.33 (2026-11-17)
18
+
19
+ ### English
20
+
21
+ - **Fix(diagnostics): "model not in catalog" is no longer reported as a missing plan (fixes #120, #122).** `explainIneligibility()` used one `'unsupported'` reason for both "the account has no access to this family/plan" and "this model id isn't in the account's catalog"; `unavailableError()` then always hinted `requires a plan with google enabled`. That sent users account-shopping when every account simply lacked the model. A distinct `'model-unsupported'` reason now produces a targeted message ("not in any enabled account's catalog — refresh the model list or pick a listed model; NOT a missing plan"), while genuine family-level `unsupported` keeps its original wording.
22
+ - **Fix(models): a stale/fallback `agy models` snapshot can no longer veto the account's own quota groups (fixes #122).** `accountSupportsModel()` treated a negative `source: 'discovered'` catalog as authoritative even when the snapshot was captured while agy's auth was unavailable (a static 4/6-item fallback list) or simply stale. A discovered catalog still affirms positively; a *negative* entry now yields to explicit per-model quota evidence, so `gemini-4-hydrogen` from a fresh `/pool/refresh-quota` is selected without manually re-activating every account.
23
+ - Tests: new pure regression file for the reason split and stale-catalog veto, plus an updated error-message assertion. A family with no quota evidence still reports `unsupported`; a catalog with no quota evidence remains authoritative.
24
+
25
+ ### 中文
26
+
27
+ - **修复(诊断):「模型不在目录」不再误报为套餐缺失(修复 #120、#122)。** `explainIneligibility()` 把「账号没有该 family/套餐权限」与「该 model id 不在账号目录」都归为 `'unsupported'`,`unavailableError()` 于是一律提示 `requires a plan with google enabled`——用户会误以为掉权限而反复换号,实则所有账号都没有这个型号。现在新增独立的 `'model-unsupported'` 原因,文案改为「不在任何启用账号的目录里——刷新模型列表或换一个已列出的型号;不是套餐问题」;真正的 family 级 `unsupported` 文案保持不变。
28
+ - **修复(模型):陈旧/兜底的 `agy models` 快照不再否决账号自身额度组(修复 #122)。** `accountSupportsModel()` 此前把 `source: 'discovered'` 目录的**否定**结果当权威,即使该快照是 agy 鉴权未就绪时打印的静态 4/6 条兜底清单、或已经陈旧。现在已发现目录仍可**正向确认**模型;但**否定**结果要让位于明确的 per-model 额度证据,因此执行 `/pool/refresh-quota` 后即可选到 `gemini-4-hydrogen`,无需逐账号手工 `set-active` 重探。
29
+ - 测试:新增纯函数回归覆盖原因分流与陈旧目录否决,并更新错误文案断言。无额度证据时 family 仍报 `unsupported`,无额度证据时目录仍为权威。
30
+
3
31
  ## 0.6.32 (2026-11-17)
4
32
 
5
33
  ### English
@@ -1481,7 +1481,12 @@ function accountSupportsModel(acc, model, pool, catalog) {
1481
1481
  if (!model || model.trim() === "") return true;
1482
1482
  const clean = model.trim();
1483
1483
  if (isArgonModel(clean)) return accountHasArgon(acc, pool, catalog);
1484
- if (catalog && catalog.source === "discovered" && Array.isArray(catalog.models) && catalog.models.length > 0) return catalog.models.some((m) => modelMatches(clean, m.id));
1484
+ if (catalog && catalog.source === "discovered" && Array.isArray(catalog.models) && catalog.models.length > 0) {
1485
+ if (catalog.models.some((m) => modelMatches(clean, m.id))) return true;
1486
+ const familyQuotaModels = acc.quotas?.[modelFamilyOf(clean)]?.models;
1487
+ if (Array.isArray(familyQuotaModels) && familyQuotaModels.some((m) => modelMatches(clean, m.modelId))) return true;
1488
+ return false;
1489
+ }
1485
1490
  const family = modelFamilyOf(clean);
1486
1491
  const familyQuota = acc.quotas?.[family];
1487
1492
  if (familyQuota) {
@@ -2315,7 +2320,7 @@ var RunRecording = class {
2315
2320
  }
2316
2321
  /** Whether a result event (ok or error-with-response) was recorded. */
2317
2322
  get hasResult() {
2318
- return this.resultConversationId !== null || this.events.some((e) => e.kind === "result");
2323
+ return this.events.some((e) => e.kind === "result");
2319
2324
  }
2320
2325
  /** The last result envelope's finish-relevant projection, when one arrived. */
2321
2326
  getResultEvent() {
@@ -4899,13 +4904,6 @@ function nodeScriptEnv(env) {
4899
4904
  * own idle budget so short-budget tests and genuine idle kills stay prompt.
4900
4905
  */
4901
4906
  const WATCHDOG_GRACE_MS = 5e3;
4902
- /**
4903
- * Grace after agy reports `root agent idle; waiting ... for background task(s)`.
4904
- * The prompt turn's answer is already streamed; a stuck GUI dialog / background
4905
- * child would otherwise keep print mode alive for hours (issue #119). Short and
4906
- * fixed so the turn settles promptly instead of hanging DSH's event stream.
4907
- */
4908
- const IDLE_BACKGROUND_GRACE_MS = 5e3;
4909
4907
  //#endregion
4910
4908
  //#region src/host/auto-updater.ts
4911
4909
  function nonBlank(v) {
@@ -5069,7 +5067,9 @@ function createRunState(opts) {
5069
5067
  watchdogGraceUsed: false,
5070
5068
  turnCap: null,
5071
5069
  idleGraceTimer: null,
5072
- idleGraceTerminated: false
5070
+ idleGraceTerminated: false,
5071
+ idleGraceExempt: false,
5072
+ idleObserved: false
5073
5073
  };
5074
5074
  }
5075
5075
  function spawnAgyChild(opts, env, viaCmd, isNode) {
@@ -5156,11 +5156,44 @@ function armTurnCap(child, opts, state) {
5156
5156
  function isBackgroundStderrNoise(line) {
5157
5157
  return line.includes("fetchAvailableModels") || line.includes("loadCodeAssist") || line.includes("token refreshed") || line.includes("FetchConfig") || line.includes("ListExperiments") || line.includes("daily-cloudcode-pa.googleapis.com") || line.includes("http_helpers.go");
5158
5158
  }
5159
+ function clearIdleGrace(state) {
5160
+ if (state.idleGraceTimer !== null) {
5161
+ clearTimeout(state.idleGraceTimer);
5162
+ state.idleGraceTimer = null;
5163
+ }
5164
+ }
5165
+ /**
5166
+ * Arm the idle-grace reaper for a `root agent idle; waiting …` line.
5167
+ *
5168
+ * The reaper exists for genuinely orphaned background work (a dev server, a
5169
+ * blocked GUI dialog) that would otherwise keep print mode alive for hours
5170
+ * (#119). It must NOT fire while agy is legitimately waiting for a subagent to
5171
+ * wake the root agent — `exemptIdleGrace(true)` is how the attempt layer marks
5172
+ * that state (#124). When exempt, the check re-arms instead of killing, and the
5173
+ * normal activity watchdog / maxTurnMinutes still bound the wait.
5174
+ */
5175
+ function armIdleGrace(child, opts, state) {
5176
+ if (state.idleGraceTimer !== null || state.settled) return;
5177
+ const graceMs = opts.idleGraceMs ?? 5e3;
5178
+ state.idleGraceTimer = setTimeout(() => {
5179
+ state.idleGraceTimer = null;
5180
+ if (state.settled) return;
5181
+ if (state.idleGraceExempt) {
5182
+ armIdleGrace(child, opts, state);
5183
+ return;
5184
+ }
5185
+ state.idleGraceTerminated = true;
5186
+ killTree(child);
5187
+ }, graceMs);
5188
+ state.idleGraceTimer.unref?.();
5189
+ }
5159
5190
  function attachOutputStreams(child, opts, state, refreshWatchdog) {
5160
5191
  const stdoutDecoder = makeLineDecoder(consoleOutputEncoding());
5161
5192
  const stderrDecoder = makeLineDecoder(consoleOutputEncoding());
5162
5193
  child.stdout?.on("data", (chunk) => {
5163
5194
  refreshWatchdog();
5195
+ clearIdleGrace(state);
5196
+ state.idleObserved = false;
5164
5197
  const text = stdoutDecoder.push(chunk);
5165
5198
  if (text === "") return;
5166
5199
  state.stdout += text;
@@ -5178,15 +5211,8 @@ function attachOutputStreams(child, opts, state, refreshWatchdog) {
5178
5211
  if (text !== "") {
5179
5212
  state.stderr = (state.stderr + text).slice(-4096);
5180
5213
  if (/root agent idle;\s*waiting/i.test(text)) {
5181
- if (!state.idleGraceTimer) {
5182
- state.idleGraceTimer = setTimeout(() => {
5183
- if (!state.settled) {
5184
- state.idleGraceTerminated = true;
5185
- killTree(child);
5186
- }
5187
- }, IDLE_BACKGROUND_GRACE_MS);
5188
- state.idleGraceTimer.unref?.();
5189
- }
5214
+ state.idleObserved = true;
5215
+ armIdleGrace(child, opts, state);
5190
5216
  } else if (opts.stderrKeepalive && !isBackgroundStderrNoise(text)) refreshWatchdog();
5191
5217
  }
5192
5218
  });
@@ -5259,6 +5285,11 @@ function startAgyProcess(opts) {
5259
5285
  if (budgetMs !== void 0) state.idleBudgetMs = budgetMs;
5260
5286
  refreshWatchdog();
5261
5287
  },
5288
+ exemptIdleGrace: (exempt) => {
5289
+ state.idleGraceExempt = exempt;
5290
+ if (exempt) clearIdleGrace(state);
5291
+ else if (state.idleObserved) armIdleGrace(child, opts, state);
5292
+ },
5262
5293
  kill: (reason) => {
5263
5294
  if (reason === "timeout") state.timedOut = true;
5264
5295
  else state.aborted = true;
@@ -5933,6 +5964,8 @@ function mergeSentImageIds(existing, added, max = 64) {
5933
5964
  }
5934
5965
  //#endregion
5935
5966
  //#region src/provider/account-selection.ts
5967
+ /** Upper bound on the self-heal refresh so a slow network cannot stall a turn. */
5968
+ const MODEL_HEAL_TIMEOUT_MS = 2e4;
5936
5969
  /** Session affinity: reuse the account this session last ran on, if eligible. */
5937
5970
  function stickyAccount(deps, family, sessionKey, model) {
5938
5971
  const pool = deps.pool;
@@ -5981,6 +6014,28 @@ async function waitForShortReset(pool, family, model) {
5981
6014
  await new Promise((r) => setTimeout(r, countdown + 250));
5982
6015
  return pool.selectAccount(family, model) ?? void 0;
5983
6016
  }
6017
+ /**
6018
+ * One self-heal attempt for issue #125: if EVERY enabled account was denied
6019
+ * solely because the requested model is absent from its per-model snapshot,
6020
+ * refresh quotas and retry selection once. A truncated snapshot is the common
6021
+ * cause (the pool demonstrably served the model minutes earlier); a genuinely
6022
+ * unsupported model simply fails the retry and reports as before.
6023
+ */
6024
+ async function healStaleModelSnapshot(deps, pool, family, model) {
6025
+ const refresh = deps.refreshQuota;
6026
+ if (refresh === void 0 || model === "") return void 0;
6027
+ const enabled = pool.getAccounts().filter((a) => a.enabled);
6028
+ if (enabled.length === 0) return void 0;
6029
+ if (!enabled.map((a) => pool.explainIneligibility?.(a, family, Date.now(), model) ?? null).every((r) => r === "model-unsupported")) return void 0;
6030
+ try {
6031
+ await Promise.race([refresh(), new Promise((resolve) => {
6032
+ setTimeout(resolve, MODEL_HEAL_TIMEOUT_MS).unref?.();
6033
+ })]);
6034
+ } catch {
6035
+ return;
6036
+ }
6037
+ return pool.selectAccount(family, model) ?? void 0;
6038
+ }
5984
6039
  /** Build the "all accounts unavailable" error with the real reasons. */
5985
6040
  function unavailableError(pool, family, model) {
5986
6041
  const allAccounts = pool.getAccounts();
@@ -5990,6 +6045,7 @@ function unavailableError(pool, family, model) {
5990
6045
  const cooling = reasons.filter((r) => r === "cooldown").length;
5991
6046
  const quotaBlocked = reasons.filter((r) => r === "quota").length;
5992
6047
  const unsupported = reasons.filter((r) => r === "unsupported").length;
6048
+ const modelUnsupported = reasons.filter((r) => r === "model-unsupported").length;
5993
6049
  const signedOut = accounts.filter((a) => a.authRequired === true).length;
5994
6050
  const countdown = pool.getEarliestAvailableCountdown?.(family) ?? pool.getEarliestResetCountdown(family);
5995
6051
  let why;
@@ -6000,12 +6056,13 @@ function unavailableError(pool, family, model) {
6000
6056
  if (cooling > 0) details.push(`${cooling} in cooldown`);
6001
6057
  if (quotaBlocked > 0) details.push(`${quotaBlocked} quota-exhausted`);
6002
6058
  if (unsupported > 0) details.push(`${unsupported} lack ${family} access`);
6059
+ if (modelUnsupported > 0) details.push(`${modelUnsupported} lack model "${model ?? ""}" in their catalog`);
6003
6060
  if (signedOut > 0) details.push(`${signedOut} signed out`);
6004
6061
  if (disabled > 0) details.push(`${disabled} disabled`);
6005
6062
  why = `no account can serve ${family} right now${details.length > 0 ? ` (${details.join(", ")})` : ""}`;
6006
6063
  }
6007
6064
  const waitStr = countdown !== null && countdown > 0 ? ` (earliest reset in ${Math.ceil(countdown / 1e3)}s)` : "";
6008
- const hint = unsupported > 0 && quotaBlocked === 0 && cooling === 0 ? `No enabled account has access to ${family} (requires a plan with ${family} enabled).` : quotaBlocked > 0 && cooling === 0 ? "Add an account, wait for the quota reset, or run /agy clear-cooldown to override the current quota snapshot." : "Add an account, wait for reset, or run /agy clear-cooldown.";
6065
+ const hint = modelUnsupported > 0 && unsupported === 0 && quotaBlocked === 0 && cooling === 0 ? `Requested model "${model ?? ""}" is not in any enabled account's catalog — refresh the model list (POST /plugins/agy-link/pool/refresh-quota) or pick a listed model. It is NOT a missing ${family} plan.` : unsupported > 0 && quotaBlocked === 0 && cooling === 0 ? `No enabled account has access to ${family} (requires a plan with ${family} enabled).` : quotaBlocked > 0 && cooling === 0 ? "Add an account, wait for the quota reset, or run /agy clear-cooldown to override the current quota snapshot." : "Add an account, wait for reset, or run /agy clear-cooldown.";
6009
6066
  return new LlmError(`All Antigravity accounts are unavailable: ${why}${waitStr}. ${hint}`, Err.AGY_ERROR);
6010
6067
  }
6011
6068
  async function selectSessionAccount(input) {
@@ -6030,6 +6087,7 @@ async function selectSessionAccount(input) {
6030
6087
  }
6031
6088
  }
6032
6089
  if (account === void 0) account = await waitForShortReset(pool, family, activeModel);
6090
+ if (account === void 0) account = await healStaleModelSnapshot(deps, pool, family, activeModel);
6033
6091
  if (account === void 0) throw unavailableError(pool, family, activeModel);
6034
6092
  }
6035
6093
  return {
@@ -6360,6 +6418,116 @@ async function stagePromptImages(input) {
6360
6418
  };
6361
6419
  }
6362
6420
  //#endregion
6421
+ //#region src/provider/tool-watchdog.ts
6422
+ /**
6423
+ * agy tools that hand work to a subagent and leave the ROOT agent idle until the
6424
+ * subagent reports back. While one of these is outstanding, the
6425
+ * `root agent idle; waiting …` line is normal cooperation, not an orphaned
6426
+ * background command (issue #124).
6427
+ */
6428
+ const SUBAGENT_COLLAB_TOOLS = /* @__PURE__ */ new Set([
6429
+ "invoke_subagent",
6430
+ "send_message",
6431
+ "run_workflow",
6432
+ "swarm"
6433
+ ]);
6434
+ /**
6435
+ * Idle-budget + long-tool heartbeat state. While an agy tool step is ACTIVE the
6436
+ * child is legitimately silent on stdout (maven compile, language-server
6437
+ * build, …) — issue #33 — so the watchdog raises the idle budget; bare
6438
+ * generation gets a bounded floor so a hung SSE stream can fail and rotate.
6439
+ */
6440
+ function createToolWatchdog(log, cfg) {
6441
+ const openToolKeys = /* @__PURE__ */ new Set();
6442
+ const openToolSince = /* @__PURE__ */ new Map();
6443
+ const longToolIdleMinutes = cfg.longToolIdleMinutes > 0 ? cfg.longToolIdleMinutes : 0;
6444
+ let printTimeoutMinutes = Math.max(longToolIdleMinutes > 0 ? longToolIdleMinutes : Math.ceil(cfg.timeoutMs / 6e4), Math.ceil(cfg.timeoutMs / 6e4));
6445
+ if (cfg.maxTurnMinutes > 0 && printTimeoutMinutes > cfg.maxTurnMinutes) printTimeoutMinutes = cfg.maxTurnMinutes;
6446
+ const longToolIdleMs = longToolIdleMinutes > 0 ? longToolIdleMinutes * 6e4 : cfg.timeoutMs;
6447
+ const generationIdleMs = Math.max(cfg.timeoutMs, 9e5);
6448
+ let runningProc = null;
6449
+ let awaitingSubagent = false;
6450
+ let sawAnyEvent = false;
6451
+ let lastOutputAt = 0;
6452
+ const TOOL_HEARTBEAT_MS = 3e5;
6453
+ let toolHeartbeat = null;
6454
+ const apply = () => {
6455
+ runningProc?.noteActivity(openToolKeys.size > 0 ? longToolIdleMs : generationIdleMs);
6456
+ };
6457
+ const setAwaitingSubagent = (next) => {
6458
+ if (awaitingSubagent === next) return;
6459
+ awaitingSubagent = next;
6460
+ runningProc?.exemptIdleGrace(next);
6461
+ };
6462
+ const stop = () => {
6463
+ if (toolHeartbeat !== null) {
6464
+ clearInterval(toolHeartbeat);
6465
+ toolHeartbeat = null;
6466
+ }
6467
+ };
6468
+ const start = () => {
6469
+ if (toolHeartbeat !== null) return;
6470
+ toolHeartbeat = setInterval(() => {
6471
+ if (openToolKeys.size === 0 && !sawAnyEvent) {
6472
+ stop();
6473
+ return;
6474
+ }
6475
+ let oldest = Date.now();
6476
+ for (const startedAt of openToolSince.values()) if (startedAt < oldest) oldest = startedAt;
6477
+ if (openToolKeys.size === 0 && lastOutputAt > 0) oldest = lastOutputAt;
6478
+ const mins = Math.max(1, Math.round((Date.now() - oldest) / 6e4));
6479
+ log?.(openToolKeys.size > 0 ? "agy tool step still running: " + openToolKeys.size + " open, oldest " + mins + "m (idle budget " + Math.round(longToolIdleMs / 6e4) + "m) — the turn is waiting on agy" : "agy run still working: no new output for " + mins + "m (idle budget " + Math.round(longToolIdleMs / 6e4) + "m) — the turn is waiting on agy; press Stop to cancel");
6480
+ }, TOOL_HEARTBEAT_MS);
6481
+ toolHeartbeat.unref?.();
6482
+ };
6483
+ return {
6484
+ printTimeoutMinutes,
6485
+ attach: (proc) => {
6486
+ runningProc = proc;
6487
+ proc?.exemptIdleGrace(awaitingSubagent);
6488
+ apply();
6489
+ },
6490
+ markEvent: () => {
6491
+ sawAnyEvent = true;
6492
+ lastOutputAt = Date.now();
6493
+ start();
6494
+ apply();
6495
+ },
6496
+ trackStep: (ev) => {
6497
+ if (ev.kind !== "step") return;
6498
+ if (ev.stepKind === "tool" && ev.tool !== void 0) {
6499
+ if (SUBAGENT_COLLAB_TOOLS.has(ev.tool.name)) setAwaitingSubagent(true);
6500
+ if (!(ev.state === "DONE" || ev.state === "ERROR" || ev.state === "RUNNING" || ev.state === void 0 && (ev.tool.output !== void 0 || ev.tool.error !== void 0))) {
6501
+ if (!openToolKeys.has(ev.stepKey)) {
6502
+ openToolKeys.add(ev.stepKey);
6503
+ openToolSince.set(ev.stepKey, Date.now());
6504
+ apply();
6505
+ start();
6506
+ }
6507
+ } else if (openToolKeys.delete(ev.stepKey)) {
6508
+ openToolSince.delete(ev.stepKey);
6509
+ apply();
6510
+ if (openToolKeys.size === 0) stop();
6511
+ }
6512
+ } else if (ev.stepKind === "text" || ev.stepKind === "thinking") {
6513
+ setAwaitingSubagent(false);
6514
+ if (openToolKeys.size > 0) {
6515
+ openToolKeys.clear();
6516
+ openToolSince.clear();
6517
+ apply();
6518
+ stop();
6519
+ }
6520
+ }
6521
+ },
6522
+ stop: () => {
6523
+ stop();
6524
+ setAwaitingSubagent(false);
6525
+ openToolKeys.clear();
6526
+ openToolSince.clear();
6527
+ }
6528
+ };
6529
+ }
6530
+ //#endregion
6363
6531
  //#region src/host/discovery.ts
6364
6532
  function defaultConversationsDir() {
6365
6533
  return process.env.DSH_AGY_CONVERSATIONS_DIR ?? join(homedir(), ".gemini", "antigravity-cli", "conversations");
@@ -6828,6 +6996,22 @@ function readAgyRunLogText(homeDir, before) {
6828
6996
  return parts.join("\n");
6829
6997
  }
6830
6998
  //#endregion
6999
+ //#region src/host/model-support.ts
7000
+ /**
7001
+ * Whether `acc` can serve `model`.
7002
+ *
7003
+ * A learned refusal is final for that account. Otherwise the per-model quota
7004
+ * snapshot and the discovered catalog decide. Deliberately ACCOUNT-scoped: this
7005
+ * is what `selectAccount` routes on, so a sibling account must never make an
7006
+ * account look capable of a model its own evidence denies (that would route an
7007
+ * unsupported model to the wrong account). Pool-wide "nobody serves this" is
7008
+ * handled by the self-heal refresh in account-selection instead (issue #125).
7009
+ */
7010
+ function accountCanServeModel(acc, model, ctx) {
7011
+ if (ctx.unsupportedModels.get(acc.id)?.has(baseModelSlug(model))) return false;
7012
+ return accountSupportsModel(acc, model, ctx.pool, ctx.catalogFor(acc.id));
7013
+ }
7014
+ //#endregion
6831
7015
  //#region src/domain/accounts/paths.ts
6832
7016
  /**
6833
7017
  * Write `body` to `file` without ever publishing a torn snapshot: a tmp name
@@ -6899,7 +7083,7 @@ function explainIneligibility(acc, family, now, pool, model) {
6899
7083
  if (!acc.enabled) return "disabled";
6900
7084
  if (acc.authRequired) return "auth";
6901
7085
  if (family === "argon" && !accountHasArgon(acc, pool)) return "unsupported";
6902
- if (model && pool && typeof pool.isModelSupported === "function" && !pool.isModelSupported(acc, model)) return "unsupported";
7086
+ if (model && pool && typeof pool.isModelSupported === "function" && !pool.isModelSupported(acc, model)) return "model-unsupported";
6903
7087
  const cd = acc.cooldowns?.[family];
6904
7088
  if (cd && cd.cooldownUntil > now) return "cooldown";
6905
7089
  if (isQuotaBenched(acc, family, now)) return "quota";
@@ -7902,9 +8086,11 @@ var AccountPoolManager = class {
7902
8086
  }
7903
8087
  /** Determine whether a managed account supports a specific model. */
7904
8088
  isModelSupported(acc, model) {
7905
- if (this.unsupportedModels.get(acc.id)?.has(baseModelSlug(model))) return false;
7906
- const cat = this.catalog?.get(acc.id);
7907
- return accountSupportsModel(acc, model, this, cat);
8089
+ return accountCanServeModel(acc, model, {
8090
+ unsupportedModels: this.unsupportedModels,
8091
+ catalogFor: (id) => this.catalog?.get(id),
8092
+ pool: this
8093
+ });
7908
8094
  }
7909
8095
  markModelUnsupported(accountId, model) {
7910
8096
  const set = this.unsupportedModels.get(accountId) ?? /* @__PURE__ */ new Set();
@@ -33191,92 +33377,6 @@ function buildSpawnArgs(input, printTimeoutMinutes, log) {
33191
33377
  stdinPayload
33192
33378
  };
33193
33379
  }
33194
- /**
33195
- * Idle-budget + long-tool heartbeat state. While an agy tool step is ACTIVE the
33196
- * child is legitimately silent on stdout (maven compile, language-server
33197
- * build, …) — issue #33 — so the watchdog raises the idle budget; bare
33198
- * generation gets a bounded floor so a hung SSE stream can fail and rotate.
33199
- */
33200
- function createToolWatchdog(log, cfg) {
33201
- const openToolKeys = /* @__PURE__ */ new Set();
33202
- const openToolSince = /* @__PURE__ */ new Map();
33203
- const longToolIdleMinutes = cfg.longToolIdleMinutes > 0 ? cfg.longToolIdleMinutes : 0;
33204
- let printTimeoutMinutes = Math.max(longToolIdleMinutes > 0 ? longToolIdleMinutes : Math.ceil(cfg.timeoutMs / 6e4), Math.ceil(cfg.timeoutMs / 6e4));
33205
- if (cfg.maxTurnMinutes > 0 && printTimeoutMinutes > cfg.maxTurnMinutes) printTimeoutMinutes = cfg.maxTurnMinutes;
33206
- const longToolIdleMs = longToolIdleMinutes > 0 ? longToolIdleMinutes * 6e4 : cfg.timeoutMs;
33207
- const generationIdleMs = Math.max(cfg.timeoutMs, 9e5);
33208
- let runningProc = null;
33209
- let sawAnyEvent = false;
33210
- let lastOutputAt = 0;
33211
- const TOOL_HEARTBEAT_MS = 3e5;
33212
- let toolHeartbeat = null;
33213
- const apply = () => {
33214
- runningProc?.noteActivity(openToolKeys.size > 0 ? longToolIdleMs : generationIdleMs);
33215
- };
33216
- const stop = () => {
33217
- if (toolHeartbeat !== null) {
33218
- clearInterval(toolHeartbeat);
33219
- toolHeartbeat = null;
33220
- }
33221
- };
33222
- const start = () => {
33223
- if (toolHeartbeat !== null) return;
33224
- toolHeartbeat = setInterval(() => {
33225
- if (openToolKeys.size === 0 && !sawAnyEvent) {
33226
- stop();
33227
- return;
33228
- }
33229
- let oldest = Date.now();
33230
- for (const startedAt of openToolSince.values()) if (startedAt < oldest) oldest = startedAt;
33231
- if (openToolKeys.size === 0 && lastOutputAt > 0) oldest = lastOutputAt;
33232
- const mins = Math.max(1, Math.round((Date.now() - oldest) / 6e4));
33233
- log?.(openToolKeys.size > 0 ? "agy tool step still running: " + openToolKeys.size + " open, oldest " + mins + "m (idle budget " + Math.round(longToolIdleMs / 6e4) + "m) — the turn is waiting on agy" : "agy run still working: no new output for " + mins + "m (idle budget " + Math.round(longToolIdleMs / 6e4) + "m) — the turn is waiting on agy; press Stop to cancel");
33234
- }, TOOL_HEARTBEAT_MS);
33235
- toolHeartbeat.unref?.();
33236
- };
33237
- return {
33238
- printTimeoutMinutes,
33239
- attach: (proc) => {
33240
- runningProc = proc;
33241
- apply();
33242
- },
33243
- markEvent: () => {
33244
- sawAnyEvent = true;
33245
- lastOutputAt = Date.now();
33246
- start();
33247
- apply();
33248
- },
33249
- trackStep: (ev) => {
33250
- if (ev.kind !== "step") return;
33251
- if (ev.stepKind === "tool" && ev.tool !== void 0) {
33252
- if (!(ev.state === "DONE" || ev.state === "ERROR" || ev.state === "RUNNING" || ev.state === void 0 && (ev.tool.output !== void 0 || ev.tool.error !== void 0))) {
33253
- if (!openToolKeys.has(ev.stepKey)) {
33254
- openToolKeys.add(ev.stepKey);
33255
- openToolSince.set(ev.stepKey, Date.now());
33256
- apply();
33257
- start();
33258
- }
33259
- } else if (openToolKeys.delete(ev.stepKey)) {
33260
- openToolSince.delete(ev.stepKey);
33261
- apply();
33262
- if (openToolKeys.size === 0) stop();
33263
- }
33264
- } else if (ev.stepKind === "text" || ev.stepKind === "thinking") {
33265
- if (openToolKeys.size > 0) {
33266
- openToolKeys.clear();
33267
- openToolSince.clear();
33268
- apply();
33269
- stop();
33270
- }
33271
- }
33272
- },
33273
- stop: () => {
33274
- stop();
33275
- openToolKeys.clear();
33276
- openToolSince.clear();
33277
- }
33278
- };
33279
- }
33280
33380
  /** Create the recording, parser, HOME snapshot and tool watchdog for one run. */
33281
33381
  function createAttemptRecorder(deps, cfg, account, initialConversationId) {
33282
33382
  const rec = deps.runs.create();
@@ -34201,7 +34301,8 @@ var AgyAdapter = class extends LlmAdapter {
34201
34301
  deps: {
34202
34302
  ...this.deps.pool === void 0 ? {} : { pool: this.deps.pool },
34203
34303
  store: this.deps.store,
34204
- ...this.deps.syncSessionModel === void 0 ? {} : { syncSessionModel: (id, m, effort) => this.deps.syncSessionModel?.(id, m, effort) }
34304
+ ...this.deps.syncSessionModel === void 0 ? {} : { syncSessionModel: (id, m, effort) => this.deps.syncSessionModel?.(id, m, effort) },
34305
+ ...this.deps.refreshQuota === void 0 ? {} : { refreshQuota: this.deps.refreshQuota }
34205
34306
  },
34206
34307
  cfg,
34207
34308
  model,
package/dist/index.js CHANGED
@@ -559,7 +559,12 @@ function accountSupportsModel(acc, model, pool, catalog) {
559
559
  if (!model || model.trim() === "") return true;
560
560
  const clean = model.trim();
561
561
  if (isArgonModel(clean)) return accountHasArgon(acc, pool, catalog);
562
- if (catalog && catalog.source === "discovered" && Array.isArray(catalog.models) && catalog.models.length > 0) return catalog.models.some((m) => modelMatches(clean, m.id));
562
+ if (catalog && catalog.source === "discovered" && Array.isArray(catalog.models) && catalog.models.length > 0) {
563
+ if (catalog.models.some((m) => modelMatches(clean, m.id))) return true;
564
+ const familyQuotaModels = acc.quotas?.[modelFamilyOf(clean)]?.models;
565
+ if (Array.isArray(familyQuotaModels) && familyQuotaModels.some((m) => modelMatches(clean, m.modelId))) return true;
566
+ return false;
567
+ }
563
568
  const family = modelFamilyOf(clean);
564
569
  const familyQuota = acc.quotas?.[family];
565
570
  if (familyQuota) {
@@ -1946,13 +1951,6 @@ const QUOTA_REFRESH_DEDUP_MS = 9e4;
1946
1951
  * own idle budget so short-budget tests and genuine idle kills stay prompt.
1947
1952
  */
1948
1953
  const WATCHDOG_GRACE_MS = 5e3;
1949
- /**
1950
- * Grace after agy reports `root agent idle; waiting ... for background task(s)`.
1951
- * The prompt turn's answer is already streamed; a stuck GUI dialog / background
1952
- * child would otherwise keep print mode alive for hours (issue #119). Short and
1953
- * fixed so the turn settles promptly instead of hanging DSH's event stream.
1954
- */
1955
- const IDLE_BACKGROUND_GRACE_MS = 5e3;
1956
1954
  function nonBlank(v) {
1957
1955
  return (v ?? "").trim();
1958
1956
  }
@@ -2132,7 +2130,9 @@ function createRunState(opts) {
2132
2130
  watchdogGraceUsed: false,
2133
2131
  turnCap: null,
2134
2132
  idleGraceTimer: null,
2135
- idleGraceTerminated: false
2133
+ idleGraceTerminated: false,
2134
+ idleGraceExempt: false,
2135
+ idleObserved: false
2136
2136
  };
2137
2137
  }
2138
2138
  function spawnAgyChild(opts, env, viaCmd, isNode) {
@@ -2219,11 +2219,44 @@ function armTurnCap(child, opts, state) {
2219
2219
  function isBackgroundStderrNoise(line) {
2220
2220
  return line.includes("fetchAvailableModels") || line.includes("loadCodeAssist") || line.includes("token refreshed") || line.includes("FetchConfig") || line.includes("ListExperiments") || line.includes("daily-cloudcode-pa.googleapis.com") || line.includes("http_helpers.go");
2221
2221
  }
2222
+ function clearIdleGrace(state) {
2223
+ if (state.idleGraceTimer !== null) {
2224
+ clearTimeout(state.idleGraceTimer);
2225
+ state.idleGraceTimer = null;
2226
+ }
2227
+ }
2228
+ /**
2229
+ * Arm the idle-grace reaper for a `root agent idle; waiting …` line.
2230
+ *
2231
+ * The reaper exists for genuinely orphaned background work (a dev server, a
2232
+ * blocked GUI dialog) that would otherwise keep print mode alive for hours
2233
+ * (#119). It must NOT fire while agy is legitimately waiting for a subagent to
2234
+ * wake the root agent — `exemptIdleGrace(true)` is how the attempt layer marks
2235
+ * that state (#124). When exempt, the check re-arms instead of killing, and the
2236
+ * normal activity watchdog / maxTurnMinutes still bound the wait.
2237
+ */
2238
+ function armIdleGrace(child, opts, state) {
2239
+ if (state.idleGraceTimer !== null || state.settled) return;
2240
+ const graceMs = opts.idleGraceMs ?? 5e3;
2241
+ state.idleGraceTimer = setTimeout(() => {
2242
+ state.idleGraceTimer = null;
2243
+ if (state.settled) return;
2244
+ if (state.idleGraceExempt) {
2245
+ armIdleGrace(child, opts, state);
2246
+ return;
2247
+ }
2248
+ state.idleGraceTerminated = true;
2249
+ killTree(child);
2250
+ }, graceMs);
2251
+ state.idleGraceTimer.unref?.();
2252
+ }
2222
2253
  function attachOutputStreams(child, opts, state, refreshWatchdog) {
2223
2254
  const stdoutDecoder = makeLineDecoder(consoleOutputEncoding());
2224
2255
  const stderrDecoder = makeLineDecoder(consoleOutputEncoding());
2225
2256
  child.stdout?.on("data", (chunk) => {
2226
2257
  refreshWatchdog();
2258
+ clearIdleGrace(state);
2259
+ state.idleObserved = false;
2227
2260
  const text = stdoutDecoder.push(chunk);
2228
2261
  if (text === "") return;
2229
2262
  state.stdout += text;
@@ -2241,15 +2274,8 @@ function attachOutputStreams(child, opts, state, refreshWatchdog) {
2241
2274
  if (text !== "") {
2242
2275
  state.stderr = (state.stderr + text).slice(-4096);
2243
2276
  if (/root agent idle;\s*waiting/i.test(text)) {
2244
- if (!state.idleGraceTimer) {
2245
- state.idleGraceTimer = setTimeout(() => {
2246
- if (!state.settled) {
2247
- state.idleGraceTerminated = true;
2248
- killTree(child);
2249
- }
2250
- }, IDLE_BACKGROUND_GRACE_MS);
2251
- state.idleGraceTimer.unref?.();
2252
- }
2277
+ state.idleObserved = true;
2278
+ armIdleGrace(child, opts, state);
2253
2279
  } else if (opts.stderrKeepalive && !isBackgroundStderrNoise(text)) refreshWatchdog();
2254
2280
  }
2255
2281
  });
@@ -2322,6 +2348,11 @@ function startAgyProcess(opts) {
2322
2348
  if (budgetMs !== void 0) state.idleBudgetMs = budgetMs;
2323
2349
  refreshWatchdog();
2324
2350
  },
2351
+ exemptIdleGrace: (exempt) => {
2352
+ state.idleGraceExempt = exempt;
2353
+ if (exempt) clearIdleGrace(state);
2354
+ else if (state.idleObserved) armIdleGrace(child, opts, state);
2355
+ },
2325
2356
  kill: (reason) => {
2326
2357
  if (reason === "timeout") state.timedOut = true;
2327
2358
  else state.aborted = true;
@@ -4188,7 +4219,7 @@ var RunRecording = class {
4188
4219
  }
4189
4220
  /** Whether a result event (ok or error-with-response) was recorded. */
4190
4221
  get hasResult() {
4191
- return this.resultConversationId !== null || this.events.some((e) => e.kind === "result");
4222
+ return this.events.some((e) => e.kind === "result");
4192
4223
  }
4193
4224
  /** The last result envelope's finish-relevant projection, when one arrived. */
4194
4225
  getResultEvent() {
@@ -6870,6 +6901,8 @@ function mergeSentImageIds(existing, added, max = 64) {
6870
6901
  }
6871
6902
  //#endregion
6872
6903
  //#region src/provider/account-selection.ts
6904
+ /** Upper bound on the self-heal refresh so a slow network cannot stall a turn. */
6905
+ const MODEL_HEAL_TIMEOUT_MS = 2e4;
6873
6906
  /** Session affinity: reuse the account this session last ran on, if eligible. */
6874
6907
  function stickyAccount(deps, family, sessionKey, model) {
6875
6908
  const pool = deps.pool;
@@ -6918,6 +6951,28 @@ async function waitForShortReset(pool, family, model) {
6918
6951
  await new Promise((r) => setTimeout(r, countdown + 250));
6919
6952
  return pool.selectAccount(family, model) ?? void 0;
6920
6953
  }
6954
+ /**
6955
+ * One self-heal attempt for issue #125: if EVERY enabled account was denied
6956
+ * solely because the requested model is absent from its per-model snapshot,
6957
+ * refresh quotas and retry selection once. A truncated snapshot is the common
6958
+ * cause (the pool demonstrably served the model minutes earlier); a genuinely
6959
+ * unsupported model simply fails the retry and reports as before.
6960
+ */
6961
+ async function healStaleModelSnapshot(deps, pool, family, model) {
6962
+ const refresh = deps.refreshQuota;
6963
+ if (refresh === void 0 || model === "") return void 0;
6964
+ const enabled = pool.getAccounts().filter((a) => a.enabled);
6965
+ if (enabled.length === 0) return void 0;
6966
+ if (!enabled.map((a) => pool.explainIneligibility?.(a, family, Date.now(), model) ?? null).every((r) => r === "model-unsupported")) return void 0;
6967
+ try {
6968
+ await Promise.race([refresh(), new Promise((resolve) => {
6969
+ setTimeout(resolve, MODEL_HEAL_TIMEOUT_MS).unref?.();
6970
+ })]);
6971
+ } catch {
6972
+ return;
6973
+ }
6974
+ return pool.selectAccount(family, model) ?? void 0;
6975
+ }
6921
6976
  /** Build the "all accounts unavailable" error with the real reasons. */
6922
6977
  function unavailableError(pool, family, model) {
6923
6978
  const allAccounts = pool.getAccounts();
@@ -6927,6 +6982,7 @@ function unavailableError(pool, family, model) {
6927
6982
  const cooling = reasons.filter((r) => r === "cooldown").length;
6928
6983
  const quotaBlocked = reasons.filter((r) => r === "quota").length;
6929
6984
  const unsupported = reasons.filter((r) => r === "unsupported").length;
6985
+ const modelUnsupported = reasons.filter((r) => r === "model-unsupported").length;
6930
6986
  const signedOut = accounts.filter((a) => a.authRequired === true).length;
6931
6987
  const countdown = pool.getEarliestAvailableCountdown?.(family) ?? pool.getEarliestResetCountdown(family);
6932
6988
  let why;
@@ -6937,12 +6993,13 @@ function unavailableError(pool, family, model) {
6937
6993
  if (cooling > 0) details.push(`${cooling} in cooldown`);
6938
6994
  if (quotaBlocked > 0) details.push(`${quotaBlocked} quota-exhausted`);
6939
6995
  if (unsupported > 0) details.push(`${unsupported} lack ${family} access`);
6996
+ if (modelUnsupported > 0) details.push(`${modelUnsupported} lack model "${model ?? ""}" in their catalog`);
6940
6997
  if (signedOut > 0) details.push(`${signedOut} signed out`);
6941
6998
  if (disabled > 0) details.push(`${disabled} disabled`);
6942
6999
  why = `no account can serve ${family} right now${details.length > 0 ? ` (${details.join(", ")})` : ""}`;
6943
7000
  }
6944
7001
  const waitStr = countdown !== null && countdown > 0 ? ` (earliest reset in ${Math.ceil(countdown / 1e3)}s)` : "";
6945
- const hint = unsupported > 0 && quotaBlocked === 0 && cooling === 0 ? `No enabled account has access to ${family} (requires a plan with ${family} enabled).` : quotaBlocked > 0 && cooling === 0 ? "Add an account, wait for the quota reset, or run /agy clear-cooldown to override the current quota snapshot." : "Add an account, wait for reset, or run /agy clear-cooldown.";
7002
+ const hint = modelUnsupported > 0 && unsupported === 0 && quotaBlocked === 0 && cooling === 0 ? `Requested model "${model ?? ""}" is not in any enabled account's catalog — refresh the model list (POST /plugins/agy-link/pool/refresh-quota) or pick a listed model. It is NOT a missing ${family} plan.` : unsupported > 0 && quotaBlocked === 0 && cooling === 0 ? `No enabled account has access to ${family} (requires a plan with ${family} enabled).` : quotaBlocked > 0 && cooling === 0 ? "Add an account, wait for the quota reset, or run /agy clear-cooldown to override the current quota snapshot." : "Add an account, wait for reset, or run /agy clear-cooldown.";
6946
7003
  return new LlmError(`All Antigravity accounts are unavailable: ${why}${waitStr}. ${hint}`, Err.AGY_ERROR);
6947
7004
  }
6948
7005
  async function selectSessionAccount(input) {
@@ -6967,6 +7024,7 @@ async function selectSessionAccount(input) {
6967
7024
  }
6968
7025
  }
6969
7026
  if (account === void 0) account = await waitForShortReset(pool, family, activeModel);
7027
+ if (account === void 0) account = await healStaleModelSnapshot(deps, pool, family, activeModel);
6970
7028
  if (account === void 0) throw unavailableError(pool, family, activeModel);
6971
7029
  }
6972
7030
  return {
@@ -7297,6 +7355,116 @@ async function stagePromptImages(input) {
7297
7355
  };
7298
7356
  }
7299
7357
  //#endregion
7358
+ //#region src/provider/tool-watchdog.ts
7359
+ /**
7360
+ * agy tools that hand work to a subagent and leave the ROOT agent idle until the
7361
+ * subagent reports back. While one of these is outstanding, the
7362
+ * `root agent idle; waiting …` line is normal cooperation, not an orphaned
7363
+ * background command (issue #124).
7364
+ */
7365
+ const SUBAGENT_COLLAB_TOOLS = /* @__PURE__ */ new Set([
7366
+ "invoke_subagent",
7367
+ "send_message",
7368
+ "run_workflow",
7369
+ "swarm"
7370
+ ]);
7371
+ /**
7372
+ * Idle-budget + long-tool heartbeat state. While an agy tool step is ACTIVE the
7373
+ * child is legitimately silent on stdout (maven compile, language-server
7374
+ * build, …) — issue #33 — so the watchdog raises the idle budget; bare
7375
+ * generation gets a bounded floor so a hung SSE stream can fail and rotate.
7376
+ */
7377
+ function createToolWatchdog(log, cfg) {
7378
+ const openToolKeys = /* @__PURE__ */ new Set();
7379
+ const openToolSince = /* @__PURE__ */ new Map();
7380
+ const longToolIdleMinutes = cfg.longToolIdleMinutes > 0 ? cfg.longToolIdleMinutes : 0;
7381
+ let printTimeoutMinutes = Math.max(longToolIdleMinutes > 0 ? longToolIdleMinutes : Math.ceil(cfg.timeoutMs / 6e4), Math.ceil(cfg.timeoutMs / 6e4));
7382
+ if (cfg.maxTurnMinutes > 0 && printTimeoutMinutes > cfg.maxTurnMinutes) printTimeoutMinutes = cfg.maxTurnMinutes;
7383
+ const longToolIdleMs = longToolIdleMinutes > 0 ? longToolIdleMinutes * 6e4 : cfg.timeoutMs;
7384
+ const generationIdleMs = Math.max(cfg.timeoutMs, 9e5);
7385
+ let runningProc = null;
7386
+ let awaitingSubagent = false;
7387
+ let sawAnyEvent = false;
7388
+ let lastOutputAt = 0;
7389
+ const TOOL_HEARTBEAT_MS = 3e5;
7390
+ let toolHeartbeat = null;
7391
+ const apply = () => {
7392
+ runningProc?.noteActivity(openToolKeys.size > 0 ? longToolIdleMs : generationIdleMs);
7393
+ };
7394
+ const setAwaitingSubagent = (next) => {
7395
+ if (awaitingSubagent === next) return;
7396
+ awaitingSubagent = next;
7397
+ runningProc?.exemptIdleGrace(next);
7398
+ };
7399
+ const stop = () => {
7400
+ if (toolHeartbeat !== null) {
7401
+ clearInterval(toolHeartbeat);
7402
+ toolHeartbeat = null;
7403
+ }
7404
+ };
7405
+ const start = () => {
7406
+ if (toolHeartbeat !== null) return;
7407
+ toolHeartbeat = setInterval(() => {
7408
+ if (openToolKeys.size === 0 && !sawAnyEvent) {
7409
+ stop();
7410
+ return;
7411
+ }
7412
+ let oldest = Date.now();
7413
+ for (const startedAt of openToolSince.values()) if (startedAt < oldest) oldest = startedAt;
7414
+ if (openToolKeys.size === 0 && lastOutputAt > 0) oldest = lastOutputAt;
7415
+ const mins = Math.max(1, Math.round((Date.now() - oldest) / 6e4));
7416
+ log?.(openToolKeys.size > 0 ? "agy tool step still running: " + openToolKeys.size + " open, oldest " + mins + "m (idle budget " + Math.round(longToolIdleMs / 6e4) + "m) — the turn is waiting on agy" : "agy run still working: no new output for " + mins + "m (idle budget " + Math.round(longToolIdleMs / 6e4) + "m) — the turn is waiting on agy; press Stop to cancel");
7417
+ }, TOOL_HEARTBEAT_MS);
7418
+ toolHeartbeat.unref?.();
7419
+ };
7420
+ return {
7421
+ printTimeoutMinutes,
7422
+ attach: (proc) => {
7423
+ runningProc = proc;
7424
+ proc?.exemptIdleGrace(awaitingSubagent);
7425
+ apply();
7426
+ },
7427
+ markEvent: () => {
7428
+ sawAnyEvent = true;
7429
+ lastOutputAt = Date.now();
7430
+ start();
7431
+ apply();
7432
+ },
7433
+ trackStep: (ev) => {
7434
+ if (ev.kind !== "step") return;
7435
+ if (ev.stepKind === "tool" && ev.tool !== void 0) {
7436
+ if (SUBAGENT_COLLAB_TOOLS.has(ev.tool.name)) setAwaitingSubagent(true);
7437
+ if (!(ev.state === "DONE" || ev.state === "ERROR" || ev.state === "RUNNING" || ev.state === void 0 && (ev.tool.output !== void 0 || ev.tool.error !== void 0))) {
7438
+ if (!openToolKeys.has(ev.stepKey)) {
7439
+ openToolKeys.add(ev.stepKey);
7440
+ openToolSince.set(ev.stepKey, Date.now());
7441
+ apply();
7442
+ start();
7443
+ }
7444
+ } else if (openToolKeys.delete(ev.stepKey)) {
7445
+ openToolSince.delete(ev.stepKey);
7446
+ apply();
7447
+ if (openToolKeys.size === 0) stop();
7448
+ }
7449
+ } else if (ev.stepKind === "text" || ev.stepKind === "thinking") {
7450
+ setAwaitingSubagent(false);
7451
+ if (openToolKeys.size > 0) {
7452
+ openToolKeys.clear();
7453
+ openToolSince.clear();
7454
+ apply();
7455
+ stop();
7456
+ }
7457
+ }
7458
+ },
7459
+ stop: () => {
7460
+ stop();
7461
+ setAwaitingSubagent(false);
7462
+ openToolKeys.clear();
7463
+ openToolSince.clear();
7464
+ }
7465
+ };
7466
+ }
7467
+ //#endregion
7300
7468
  //#region src/host/discovery.ts
7301
7469
  function defaultConversationsDir() {
7302
7470
  return process.env.DSH_AGY_CONVERSATIONS_DIR ?? join(homedir(), ".gemini", "antigravity-cli", "conversations");
@@ -7398,6 +7566,22 @@ function readAgyRunLogText(homeDir, before) {
7398
7566
  return parts.join("\n");
7399
7567
  }
7400
7568
  //#endregion
7569
+ //#region src/host/model-support.ts
7570
+ /**
7571
+ * Whether `acc` can serve `model`.
7572
+ *
7573
+ * A learned refusal is final for that account. Otherwise the per-model quota
7574
+ * snapshot and the discovered catalog decide. Deliberately ACCOUNT-scoped: this
7575
+ * is what `selectAccount` routes on, so a sibling account must never make an
7576
+ * account look capable of a model its own evidence denies (that would route an
7577
+ * unsupported model to the wrong account). Pool-wide "nobody serves this" is
7578
+ * handled by the self-heal refresh in account-selection instead (issue #125).
7579
+ */
7580
+ function accountCanServeModel(acc, model, ctx) {
7581
+ if (ctx.unsupportedModels.get(acc.id)?.has(baseModelSlug(model))) return false;
7582
+ return accountSupportsModel(acc, model, ctx.pool, ctx.catalogFor(acc.id));
7583
+ }
7584
+ //#endregion
7401
7585
  //#region src/domain/accounts/paths.ts
7402
7586
  /**
7403
7587
  * Write `body` to `file` without ever publishing a torn snapshot: a tmp name
@@ -7469,7 +7653,7 @@ function explainIneligibility(acc, family, now, pool, model) {
7469
7653
  if (!acc.enabled) return "disabled";
7470
7654
  if (acc.authRequired) return "auth";
7471
7655
  if (family === "argon" && !accountHasArgon(acc, pool)) return "unsupported";
7472
- if (model && pool && typeof pool.isModelSupported === "function" && !pool.isModelSupported(acc, model)) return "unsupported";
7656
+ if (model && pool && typeof pool.isModelSupported === "function" && !pool.isModelSupported(acc, model)) return "model-unsupported";
7473
7657
  const cd = acc.cooldowns?.[family];
7474
7658
  if (cd && cd.cooldownUntil > now) return "cooldown";
7475
7659
  if (isQuotaBenched(acc, family, now)) return "quota";
@@ -8164,9 +8348,11 @@ var AccountPoolManager = class {
8164
8348
  }
8165
8349
  /** Determine whether a managed account supports a specific model. */
8166
8350
  isModelSupported(acc, model) {
8167
- if (this.unsupportedModels.get(acc.id)?.has(baseModelSlug(model))) return false;
8168
- const cat = this.catalog?.get(acc.id);
8169
- return accountSupportsModel(acc, model, this, cat);
8351
+ return accountCanServeModel(acc, model, {
8352
+ unsupportedModels: this.unsupportedModels,
8353
+ catalogFor: (id) => this.catalog?.get(id),
8354
+ pool: this
8355
+ });
8170
8356
  }
8171
8357
  markModelUnsupported(accountId, model) {
8172
8358
  const set = this.unsupportedModels.get(accountId) ?? /* @__PURE__ */ new Set();
@@ -33705,92 +33891,6 @@ function buildSpawnArgs(input, printTimeoutMinutes, log) {
33705
33891
  stdinPayload
33706
33892
  };
33707
33893
  }
33708
- /**
33709
- * Idle-budget + long-tool heartbeat state. While an agy tool step is ACTIVE the
33710
- * child is legitimately silent on stdout (maven compile, language-server
33711
- * build, …) — issue #33 — so the watchdog raises the idle budget; bare
33712
- * generation gets a bounded floor so a hung SSE stream can fail and rotate.
33713
- */
33714
- function createToolWatchdog(log, cfg) {
33715
- const openToolKeys = /* @__PURE__ */ new Set();
33716
- const openToolSince = /* @__PURE__ */ new Map();
33717
- const longToolIdleMinutes = cfg.longToolIdleMinutes > 0 ? cfg.longToolIdleMinutes : 0;
33718
- let printTimeoutMinutes = Math.max(longToolIdleMinutes > 0 ? longToolIdleMinutes : Math.ceil(cfg.timeoutMs / 6e4), Math.ceil(cfg.timeoutMs / 6e4));
33719
- if (cfg.maxTurnMinutes > 0 && printTimeoutMinutes > cfg.maxTurnMinutes) printTimeoutMinutes = cfg.maxTurnMinutes;
33720
- const longToolIdleMs = longToolIdleMinutes > 0 ? longToolIdleMinutes * 6e4 : cfg.timeoutMs;
33721
- const generationIdleMs = Math.max(cfg.timeoutMs, 9e5);
33722
- let runningProc = null;
33723
- let sawAnyEvent = false;
33724
- let lastOutputAt = 0;
33725
- const TOOL_HEARTBEAT_MS = 3e5;
33726
- let toolHeartbeat = null;
33727
- const apply = () => {
33728
- runningProc?.noteActivity(openToolKeys.size > 0 ? longToolIdleMs : generationIdleMs);
33729
- };
33730
- const stop = () => {
33731
- if (toolHeartbeat !== null) {
33732
- clearInterval(toolHeartbeat);
33733
- toolHeartbeat = null;
33734
- }
33735
- };
33736
- const start = () => {
33737
- if (toolHeartbeat !== null) return;
33738
- toolHeartbeat = setInterval(() => {
33739
- if (openToolKeys.size === 0 && !sawAnyEvent) {
33740
- stop();
33741
- return;
33742
- }
33743
- let oldest = Date.now();
33744
- for (const startedAt of openToolSince.values()) if (startedAt < oldest) oldest = startedAt;
33745
- if (openToolKeys.size === 0 && lastOutputAt > 0) oldest = lastOutputAt;
33746
- const mins = Math.max(1, Math.round((Date.now() - oldest) / 6e4));
33747
- log?.(openToolKeys.size > 0 ? "agy tool step still running: " + openToolKeys.size + " open, oldest " + mins + "m (idle budget " + Math.round(longToolIdleMs / 6e4) + "m) — the turn is waiting on agy" : "agy run still working: no new output for " + mins + "m (idle budget " + Math.round(longToolIdleMs / 6e4) + "m) — the turn is waiting on agy; press Stop to cancel");
33748
- }, TOOL_HEARTBEAT_MS);
33749
- toolHeartbeat.unref?.();
33750
- };
33751
- return {
33752
- printTimeoutMinutes,
33753
- attach: (proc) => {
33754
- runningProc = proc;
33755
- apply();
33756
- },
33757
- markEvent: () => {
33758
- sawAnyEvent = true;
33759
- lastOutputAt = Date.now();
33760
- start();
33761
- apply();
33762
- },
33763
- trackStep: (ev) => {
33764
- if (ev.kind !== "step") return;
33765
- if (ev.stepKind === "tool" && ev.tool !== void 0) {
33766
- if (!(ev.state === "DONE" || ev.state === "ERROR" || ev.state === "RUNNING" || ev.state === void 0 && (ev.tool.output !== void 0 || ev.tool.error !== void 0))) {
33767
- if (!openToolKeys.has(ev.stepKey)) {
33768
- openToolKeys.add(ev.stepKey);
33769
- openToolSince.set(ev.stepKey, Date.now());
33770
- apply();
33771
- start();
33772
- }
33773
- } else if (openToolKeys.delete(ev.stepKey)) {
33774
- openToolSince.delete(ev.stepKey);
33775
- apply();
33776
- if (openToolKeys.size === 0) stop();
33777
- }
33778
- } else if (ev.stepKind === "text" || ev.stepKind === "thinking") {
33779
- if (openToolKeys.size > 0) {
33780
- openToolKeys.clear();
33781
- openToolSince.clear();
33782
- apply();
33783
- stop();
33784
- }
33785
- }
33786
- },
33787
- stop: () => {
33788
- stop();
33789
- openToolKeys.clear();
33790
- openToolSince.clear();
33791
- }
33792
- };
33793
- }
33794
33894
  /** Create the recording, parser, HOME snapshot and tool watchdog for one run. */
33795
33895
  function createAttemptRecorder(deps, cfg, account, initialConversationId) {
33796
33896
  const rec = deps.runs.create();
@@ -34715,7 +34815,8 @@ var AgyAdapter = class extends LlmAdapter {
34715
34815
  deps: {
34716
34816
  ...this.deps.pool === void 0 ? {} : { pool: this.deps.pool },
34717
34817
  store: this.deps.store,
34718
- ...this.deps.syncSessionModel === void 0 ? {} : { syncSessionModel: (id, m, effort) => this.deps.syncSessionModel?.(id, m, effort) }
34818
+ ...this.deps.syncSessionModel === void 0 ? {} : { syncSessionModel: (id, m, effort) => this.deps.syncSessionModel?.(id, m, effort) },
34819
+ ...this.deps.refreshQuota === void 0 ? {} : { refreshQuota: this.deps.refreshQuota }
34719
34820
  },
34720
34821
  cfg,
34721
34822
  model,
@@ -39847,6 +39948,10 @@ function createHostServices(ctx, entryConfig = {}) {
39847
39948
  log,
39848
39949
  runs,
39849
39950
  getMediaBaseUrl: () => webServerPort.current ? `http://127.0.0.1:${webServerPort.current}/plugins/agy-link/media` : null,
39951
+ refreshQuota: async () => {
39952
+ await quota.refreshAllQuotas(false).catch(() => void 0);
39953
+ await catalog.forceRefreshAndNotify().catch(() => void 0);
39954
+ },
39850
39955
  effortUnsupported: () => effortStore.read(),
39851
39956
  onEffortUnsupported: (model) => effortStore.remember(model),
39852
39957
  sessionCwd: (sessionId) => sessionWorkspace(sessionId),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-agy-link",
3
- "version": "0.6.32",
3
+ "version": "0.6.34",
4
4
  "description": "Google Antigravity (agy CLI) models for DeepSeek Harness — stream Gemini/Claude/GPT-OSS subscriptions into DSH with thinking, tool activity, token usage and in-GUI Google OAuth login.",
5
5
  "type": "module",
6
6
  "license": "MIT",