dsh-agy-link 0.6.33 → 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 +14 -0
- package/dist/cli-image.mjs +202 -108
- package/dist/index.js +206 -108
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
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
|
+
|
|
3
17
|
## 0.6.33 (2026-11-17)
|
|
4
18
|
|
|
5
19
|
### English
|
package/dist/cli-image.mjs
CHANGED
|
@@ -2320,7 +2320,7 @@ var RunRecording = class {
|
|
|
2320
2320
|
}
|
|
2321
2321
|
/** Whether a result event (ok or error-with-response) was recorded. */
|
|
2322
2322
|
get hasResult() {
|
|
2323
|
-
return this.
|
|
2323
|
+
return this.events.some((e) => e.kind === "result");
|
|
2324
2324
|
}
|
|
2325
2325
|
/** The last result envelope's finish-relevant projection, when one arrived. */
|
|
2326
2326
|
getResultEvent() {
|
|
@@ -4904,13 +4904,6 @@ function nodeScriptEnv(env) {
|
|
|
4904
4904
|
* own idle budget so short-budget tests and genuine idle kills stay prompt.
|
|
4905
4905
|
*/
|
|
4906
4906
|
const WATCHDOG_GRACE_MS = 5e3;
|
|
4907
|
-
/**
|
|
4908
|
-
* Grace after agy reports `root agent idle; waiting ... for background task(s)`.
|
|
4909
|
-
* The prompt turn's answer is already streamed; a stuck GUI dialog / background
|
|
4910
|
-
* child would otherwise keep print mode alive for hours (issue #119). Short and
|
|
4911
|
-
* fixed so the turn settles promptly instead of hanging DSH's event stream.
|
|
4912
|
-
*/
|
|
4913
|
-
const IDLE_BACKGROUND_GRACE_MS = 5e3;
|
|
4914
4907
|
//#endregion
|
|
4915
4908
|
//#region src/host/auto-updater.ts
|
|
4916
4909
|
function nonBlank(v) {
|
|
@@ -5074,7 +5067,9 @@ function createRunState(opts) {
|
|
|
5074
5067
|
watchdogGraceUsed: false,
|
|
5075
5068
|
turnCap: null,
|
|
5076
5069
|
idleGraceTimer: null,
|
|
5077
|
-
idleGraceTerminated: false
|
|
5070
|
+
idleGraceTerminated: false,
|
|
5071
|
+
idleGraceExempt: false,
|
|
5072
|
+
idleObserved: false
|
|
5078
5073
|
};
|
|
5079
5074
|
}
|
|
5080
5075
|
function spawnAgyChild(opts, env, viaCmd, isNode) {
|
|
@@ -5161,11 +5156,44 @@ function armTurnCap(child, opts, state) {
|
|
|
5161
5156
|
function isBackgroundStderrNoise(line) {
|
|
5162
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");
|
|
5163
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
|
+
}
|
|
5164
5190
|
function attachOutputStreams(child, opts, state, refreshWatchdog) {
|
|
5165
5191
|
const stdoutDecoder = makeLineDecoder(consoleOutputEncoding());
|
|
5166
5192
|
const stderrDecoder = makeLineDecoder(consoleOutputEncoding());
|
|
5167
5193
|
child.stdout?.on("data", (chunk) => {
|
|
5168
5194
|
refreshWatchdog();
|
|
5195
|
+
clearIdleGrace(state);
|
|
5196
|
+
state.idleObserved = false;
|
|
5169
5197
|
const text = stdoutDecoder.push(chunk);
|
|
5170
5198
|
if (text === "") return;
|
|
5171
5199
|
state.stdout += text;
|
|
@@ -5183,15 +5211,8 @@ function attachOutputStreams(child, opts, state, refreshWatchdog) {
|
|
|
5183
5211
|
if (text !== "") {
|
|
5184
5212
|
state.stderr = (state.stderr + text).slice(-4096);
|
|
5185
5213
|
if (/root agent idle;\s*waiting/i.test(text)) {
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
if (!state.settled) {
|
|
5189
|
-
state.idleGraceTerminated = true;
|
|
5190
|
-
killTree(child);
|
|
5191
|
-
}
|
|
5192
|
-
}, IDLE_BACKGROUND_GRACE_MS);
|
|
5193
|
-
state.idleGraceTimer.unref?.();
|
|
5194
|
-
}
|
|
5214
|
+
state.idleObserved = true;
|
|
5215
|
+
armIdleGrace(child, opts, state);
|
|
5195
5216
|
} else if (opts.stderrKeepalive && !isBackgroundStderrNoise(text)) refreshWatchdog();
|
|
5196
5217
|
}
|
|
5197
5218
|
});
|
|
@@ -5264,6 +5285,11 @@ function startAgyProcess(opts) {
|
|
|
5264
5285
|
if (budgetMs !== void 0) state.idleBudgetMs = budgetMs;
|
|
5265
5286
|
refreshWatchdog();
|
|
5266
5287
|
},
|
|
5288
|
+
exemptIdleGrace: (exempt) => {
|
|
5289
|
+
state.idleGraceExempt = exempt;
|
|
5290
|
+
if (exempt) clearIdleGrace(state);
|
|
5291
|
+
else if (state.idleObserved) armIdleGrace(child, opts, state);
|
|
5292
|
+
},
|
|
5267
5293
|
kill: (reason) => {
|
|
5268
5294
|
if (reason === "timeout") state.timedOut = true;
|
|
5269
5295
|
else state.aborted = true;
|
|
@@ -5938,6 +5964,8 @@ function mergeSentImageIds(existing, added, max = 64) {
|
|
|
5938
5964
|
}
|
|
5939
5965
|
//#endregion
|
|
5940
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;
|
|
5941
5969
|
/** Session affinity: reuse the account this session last ran on, if eligible. */
|
|
5942
5970
|
function stickyAccount(deps, family, sessionKey, model) {
|
|
5943
5971
|
const pool = deps.pool;
|
|
@@ -5986,6 +6014,28 @@ async function waitForShortReset(pool, family, model) {
|
|
|
5986
6014
|
await new Promise((r) => setTimeout(r, countdown + 250));
|
|
5987
6015
|
return pool.selectAccount(family, model) ?? void 0;
|
|
5988
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
|
+
}
|
|
5989
6039
|
/** Build the "all accounts unavailable" error with the real reasons. */
|
|
5990
6040
|
function unavailableError(pool, family, model) {
|
|
5991
6041
|
const allAccounts = pool.getAccounts();
|
|
@@ -6037,6 +6087,7 @@ async function selectSessionAccount(input) {
|
|
|
6037
6087
|
}
|
|
6038
6088
|
}
|
|
6039
6089
|
if (account === void 0) account = await waitForShortReset(pool, family, activeModel);
|
|
6090
|
+
if (account === void 0) account = await healStaleModelSnapshot(deps, pool, family, activeModel);
|
|
6040
6091
|
if (account === void 0) throw unavailableError(pool, family, activeModel);
|
|
6041
6092
|
}
|
|
6042
6093
|
return {
|
|
@@ -6367,6 +6418,116 @@ async function stagePromptImages(input) {
|
|
|
6367
6418
|
};
|
|
6368
6419
|
}
|
|
6369
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
|
|
6370
6531
|
//#region src/host/discovery.ts
|
|
6371
6532
|
function defaultConversationsDir() {
|
|
6372
6533
|
return process.env.DSH_AGY_CONVERSATIONS_DIR ?? join(homedir(), ".gemini", "antigravity-cli", "conversations");
|
|
@@ -6835,6 +6996,22 @@ function readAgyRunLogText(homeDir, before) {
|
|
|
6835
6996
|
return parts.join("\n");
|
|
6836
6997
|
}
|
|
6837
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
|
|
6838
7015
|
//#region src/domain/accounts/paths.ts
|
|
6839
7016
|
/**
|
|
6840
7017
|
* Write `body` to `file` without ever publishing a torn snapshot: a tmp name
|
|
@@ -7909,9 +8086,11 @@ var AccountPoolManager = class {
|
|
|
7909
8086
|
}
|
|
7910
8087
|
/** Determine whether a managed account supports a specific model. */
|
|
7911
8088
|
isModelSupported(acc, model) {
|
|
7912
|
-
|
|
7913
|
-
|
|
7914
|
-
|
|
8089
|
+
return accountCanServeModel(acc, model, {
|
|
8090
|
+
unsupportedModels: this.unsupportedModels,
|
|
8091
|
+
catalogFor: (id) => this.catalog?.get(id),
|
|
8092
|
+
pool: this
|
|
8093
|
+
});
|
|
7915
8094
|
}
|
|
7916
8095
|
markModelUnsupported(accountId, model) {
|
|
7917
8096
|
const set = this.unsupportedModels.get(accountId) ?? /* @__PURE__ */ new Set();
|
|
@@ -33198,92 +33377,6 @@ function buildSpawnArgs(input, printTimeoutMinutes, log) {
|
|
|
33198
33377
|
stdinPayload
|
|
33199
33378
|
};
|
|
33200
33379
|
}
|
|
33201
|
-
/**
|
|
33202
|
-
* Idle-budget + long-tool heartbeat state. While an agy tool step is ACTIVE the
|
|
33203
|
-
* child is legitimately silent on stdout (maven compile, language-server
|
|
33204
|
-
* build, …) — issue #33 — so the watchdog raises the idle budget; bare
|
|
33205
|
-
* generation gets a bounded floor so a hung SSE stream can fail and rotate.
|
|
33206
|
-
*/
|
|
33207
|
-
function createToolWatchdog(log, cfg) {
|
|
33208
|
-
const openToolKeys = /* @__PURE__ */ new Set();
|
|
33209
|
-
const openToolSince = /* @__PURE__ */ new Map();
|
|
33210
|
-
const longToolIdleMinutes = cfg.longToolIdleMinutes > 0 ? cfg.longToolIdleMinutes : 0;
|
|
33211
|
-
let printTimeoutMinutes = Math.max(longToolIdleMinutes > 0 ? longToolIdleMinutes : Math.ceil(cfg.timeoutMs / 6e4), Math.ceil(cfg.timeoutMs / 6e4));
|
|
33212
|
-
if (cfg.maxTurnMinutes > 0 && printTimeoutMinutes > cfg.maxTurnMinutes) printTimeoutMinutes = cfg.maxTurnMinutes;
|
|
33213
|
-
const longToolIdleMs = longToolIdleMinutes > 0 ? longToolIdleMinutes * 6e4 : cfg.timeoutMs;
|
|
33214
|
-
const generationIdleMs = Math.max(cfg.timeoutMs, 9e5);
|
|
33215
|
-
let runningProc = null;
|
|
33216
|
-
let sawAnyEvent = false;
|
|
33217
|
-
let lastOutputAt = 0;
|
|
33218
|
-
const TOOL_HEARTBEAT_MS = 3e5;
|
|
33219
|
-
let toolHeartbeat = null;
|
|
33220
|
-
const apply = () => {
|
|
33221
|
-
runningProc?.noteActivity(openToolKeys.size > 0 ? longToolIdleMs : generationIdleMs);
|
|
33222
|
-
};
|
|
33223
|
-
const stop = () => {
|
|
33224
|
-
if (toolHeartbeat !== null) {
|
|
33225
|
-
clearInterval(toolHeartbeat);
|
|
33226
|
-
toolHeartbeat = null;
|
|
33227
|
-
}
|
|
33228
|
-
};
|
|
33229
|
-
const start = () => {
|
|
33230
|
-
if (toolHeartbeat !== null) return;
|
|
33231
|
-
toolHeartbeat = setInterval(() => {
|
|
33232
|
-
if (openToolKeys.size === 0 && !sawAnyEvent) {
|
|
33233
|
-
stop();
|
|
33234
|
-
return;
|
|
33235
|
-
}
|
|
33236
|
-
let oldest = Date.now();
|
|
33237
|
-
for (const startedAt of openToolSince.values()) if (startedAt < oldest) oldest = startedAt;
|
|
33238
|
-
if (openToolKeys.size === 0 && lastOutputAt > 0) oldest = lastOutputAt;
|
|
33239
|
-
const mins = Math.max(1, Math.round((Date.now() - oldest) / 6e4));
|
|
33240
|
-
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");
|
|
33241
|
-
}, TOOL_HEARTBEAT_MS);
|
|
33242
|
-
toolHeartbeat.unref?.();
|
|
33243
|
-
};
|
|
33244
|
-
return {
|
|
33245
|
-
printTimeoutMinutes,
|
|
33246
|
-
attach: (proc) => {
|
|
33247
|
-
runningProc = proc;
|
|
33248
|
-
apply();
|
|
33249
|
-
},
|
|
33250
|
-
markEvent: () => {
|
|
33251
|
-
sawAnyEvent = true;
|
|
33252
|
-
lastOutputAt = Date.now();
|
|
33253
|
-
start();
|
|
33254
|
-
apply();
|
|
33255
|
-
},
|
|
33256
|
-
trackStep: (ev) => {
|
|
33257
|
-
if (ev.kind !== "step") return;
|
|
33258
|
-
if (ev.stepKind === "tool" && ev.tool !== void 0) {
|
|
33259
|
-
if (!(ev.state === "DONE" || ev.state === "ERROR" || ev.state === "RUNNING" || ev.state === void 0 && (ev.tool.output !== void 0 || ev.tool.error !== void 0))) {
|
|
33260
|
-
if (!openToolKeys.has(ev.stepKey)) {
|
|
33261
|
-
openToolKeys.add(ev.stepKey);
|
|
33262
|
-
openToolSince.set(ev.stepKey, Date.now());
|
|
33263
|
-
apply();
|
|
33264
|
-
start();
|
|
33265
|
-
}
|
|
33266
|
-
} else if (openToolKeys.delete(ev.stepKey)) {
|
|
33267
|
-
openToolSince.delete(ev.stepKey);
|
|
33268
|
-
apply();
|
|
33269
|
-
if (openToolKeys.size === 0) stop();
|
|
33270
|
-
}
|
|
33271
|
-
} else if (ev.stepKind === "text" || ev.stepKind === "thinking") {
|
|
33272
|
-
if (openToolKeys.size > 0) {
|
|
33273
|
-
openToolKeys.clear();
|
|
33274
|
-
openToolSince.clear();
|
|
33275
|
-
apply();
|
|
33276
|
-
stop();
|
|
33277
|
-
}
|
|
33278
|
-
}
|
|
33279
|
-
},
|
|
33280
|
-
stop: () => {
|
|
33281
|
-
stop();
|
|
33282
|
-
openToolKeys.clear();
|
|
33283
|
-
openToolSince.clear();
|
|
33284
|
-
}
|
|
33285
|
-
};
|
|
33286
|
-
}
|
|
33287
33380
|
/** Create the recording, parser, HOME snapshot and tool watchdog for one run. */
|
|
33288
33381
|
function createAttemptRecorder(deps, cfg, account, initialConversationId) {
|
|
33289
33382
|
const rec = deps.runs.create();
|
|
@@ -34208,7 +34301,8 @@ var AgyAdapter = class extends LlmAdapter {
|
|
|
34208
34301
|
deps: {
|
|
34209
34302
|
...this.deps.pool === void 0 ? {} : { pool: this.deps.pool },
|
|
34210
34303
|
store: this.deps.store,
|
|
34211
|
-
...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 }
|
|
34212
34306
|
},
|
|
34213
34307
|
cfg,
|
|
34214
34308
|
model,
|
package/dist/index.js
CHANGED
|
@@ -1951,13 +1951,6 @@ const QUOTA_REFRESH_DEDUP_MS = 9e4;
|
|
|
1951
1951
|
* own idle budget so short-budget tests and genuine idle kills stay prompt.
|
|
1952
1952
|
*/
|
|
1953
1953
|
const WATCHDOG_GRACE_MS = 5e3;
|
|
1954
|
-
/**
|
|
1955
|
-
* Grace after agy reports `root agent idle; waiting ... for background task(s)`.
|
|
1956
|
-
* The prompt turn's answer is already streamed; a stuck GUI dialog / background
|
|
1957
|
-
* child would otherwise keep print mode alive for hours (issue #119). Short and
|
|
1958
|
-
* fixed so the turn settles promptly instead of hanging DSH's event stream.
|
|
1959
|
-
*/
|
|
1960
|
-
const IDLE_BACKGROUND_GRACE_MS = 5e3;
|
|
1961
1954
|
function nonBlank(v) {
|
|
1962
1955
|
return (v ?? "").trim();
|
|
1963
1956
|
}
|
|
@@ -2137,7 +2130,9 @@ function createRunState(opts) {
|
|
|
2137
2130
|
watchdogGraceUsed: false,
|
|
2138
2131
|
turnCap: null,
|
|
2139
2132
|
idleGraceTimer: null,
|
|
2140
|
-
idleGraceTerminated: false
|
|
2133
|
+
idleGraceTerminated: false,
|
|
2134
|
+
idleGraceExempt: false,
|
|
2135
|
+
idleObserved: false
|
|
2141
2136
|
};
|
|
2142
2137
|
}
|
|
2143
2138
|
function spawnAgyChild(opts, env, viaCmd, isNode) {
|
|
@@ -2224,11 +2219,44 @@ function armTurnCap(child, opts, state) {
|
|
|
2224
2219
|
function isBackgroundStderrNoise(line) {
|
|
2225
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");
|
|
2226
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
|
+
}
|
|
2227
2253
|
function attachOutputStreams(child, opts, state, refreshWatchdog) {
|
|
2228
2254
|
const stdoutDecoder = makeLineDecoder(consoleOutputEncoding());
|
|
2229
2255
|
const stderrDecoder = makeLineDecoder(consoleOutputEncoding());
|
|
2230
2256
|
child.stdout?.on("data", (chunk) => {
|
|
2231
2257
|
refreshWatchdog();
|
|
2258
|
+
clearIdleGrace(state);
|
|
2259
|
+
state.idleObserved = false;
|
|
2232
2260
|
const text = stdoutDecoder.push(chunk);
|
|
2233
2261
|
if (text === "") return;
|
|
2234
2262
|
state.stdout += text;
|
|
@@ -2246,15 +2274,8 @@ function attachOutputStreams(child, opts, state, refreshWatchdog) {
|
|
|
2246
2274
|
if (text !== "") {
|
|
2247
2275
|
state.stderr = (state.stderr + text).slice(-4096);
|
|
2248
2276
|
if (/root agent idle;\s*waiting/i.test(text)) {
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
if (!state.settled) {
|
|
2252
|
-
state.idleGraceTerminated = true;
|
|
2253
|
-
killTree(child);
|
|
2254
|
-
}
|
|
2255
|
-
}, IDLE_BACKGROUND_GRACE_MS);
|
|
2256
|
-
state.idleGraceTimer.unref?.();
|
|
2257
|
-
}
|
|
2277
|
+
state.idleObserved = true;
|
|
2278
|
+
armIdleGrace(child, opts, state);
|
|
2258
2279
|
} else if (opts.stderrKeepalive && !isBackgroundStderrNoise(text)) refreshWatchdog();
|
|
2259
2280
|
}
|
|
2260
2281
|
});
|
|
@@ -2327,6 +2348,11 @@ function startAgyProcess(opts) {
|
|
|
2327
2348
|
if (budgetMs !== void 0) state.idleBudgetMs = budgetMs;
|
|
2328
2349
|
refreshWatchdog();
|
|
2329
2350
|
},
|
|
2351
|
+
exemptIdleGrace: (exempt) => {
|
|
2352
|
+
state.idleGraceExempt = exempt;
|
|
2353
|
+
if (exempt) clearIdleGrace(state);
|
|
2354
|
+
else if (state.idleObserved) armIdleGrace(child, opts, state);
|
|
2355
|
+
},
|
|
2330
2356
|
kill: (reason) => {
|
|
2331
2357
|
if (reason === "timeout") state.timedOut = true;
|
|
2332
2358
|
else state.aborted = true;
|
|
@@ -4193,7 +4219,7 @@ var RunRecording = class {
|
|
|
4193
4219
|
}
|
|
4194
4220
|
/** Whether a result event (ok or error-with-response) was recorded. */
|
|
4195
4221
|
get hasResult() {
|
|
4196
|
-
return this.
|
|
4222
|
+
return this.events.some((e) => e.kind === "result");
|
|
4197
4223
|
}
|
|
4198
4224
|
/** The last result envelope's finish-relevant projection, when one arrived. */
|
|
4199
4225
|
getResultEvent() {
|
|
@@ -6875,6 +6901,8 @@ function mergeSentImageIds(existing, added, max = 64) {
|
|
|
6875
6901
|
}
|
|
6876
6902
|
//#endregion
|
|
6877
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;
|
|
6878
6906
|
/** Session affinity: reuse the account this session last ran on, if eligible. */
|
|
6879
6907
|
function stickyAccount(deps, family, sessionKey, model) {
|
|
6880
6908
|
const pool = deps.pool;
|
|
@@ -6923,6 +6951,28 @@ async function waitForShortReset(pool, family, model) {
|
|
|
6923
6951
|
await new Promise((r) => setTimeout(r, countdown + 250));
|
|
6924
6952
|
return pool.selectAccount(family, model) ?? void 0;
|
|
6925
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
|
+
}
|
|
6926
6976
|
/** Build the "all accounts unavailable" error with the real reasons. */
|
|
6927
6977
|
function unavailableError(pool, family, model) {
|
|
6928
6978
|
const allAccounts = pool.getAccounts();
|
|
@@ -6974,6 +7024,7 @@ async function selectSessionAccount(input) {
|
|
|
6974
7024
|
}
|
|
6975
7025
|
}
|
|
6976
7026
|
if (account === void 0) account = await waitForShortReset(pool, family, activeModel);
|
|
7027
|
+
if (account === void 0) account = await healStaleModelSnapshot(deps, pool, family, activeModel);
|
|
6977
7028
|
if (account === void 0) throw unavailableError(pool, family, activeModel);
|
|
6978
7029
|
}
|
|
6979
7030
|
return {
|
|
@@ -7304,6 +7355,116 @@ async function stagePromptImages(input) {
|
|
|
7304
7355
|
};
|
|
7305
7356
|
}
|
|
7306
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
|
|
7307
7468
|
//#region src/host/discovery.ts
|
|
7308
7469
|
function defaultConversationsDir() {
|
|
7309
7470
|
return process.env.DSH_AGY_CONVERSATIONS_DIR ?? join(homedir(), ".gemini", "antigravity-cli", "conversations");
|
|
@@ -7405,6 +7566,22 @@ function readAgyRunLogText(homeDir, before) {
|
|
|
7405
7566
|
return parts.join("\n");
|
|
7406
7567
|
}
|
|
7407
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
|
|
7408
7585
|
//#region src/domain/accounts/paths.ts
|
|
7409
7586
|
/**
|
|
7410
7587
|
* Write `body` to `file` without ever publishing a torn snapshot: a tmp name
|
|
@@ -8171,9 +8348,11 @@ var AccountPoolManager = class {
|
|
|
8171
8348
|
}
|
|
8172
8349
|
/** Determine whether a managed account supports a specific model. */
|
|
8173
8350
|
isModelSupported(acc, model) {
|
|
8174
|
-
|
|
8175
|
-
|
|
8176
|
-
|
|
8351
|
+
return accountCanServeModel(acc, model, {
|
|
8352
|
+
unsupportedModels: this.unsupportedModels,
|
|
8353
|
+
catalogFor: (id) => this.catalog?.get(id),
|
|
8354
|
+
pool: this
|
|
8355
|
+
});
|
|
8177
8356
|
}
|
|
8178
8357
|
markModelUnsupported(accountId, model) {
|
|
8179
8358
|
const set = this.unsupportedModels.get(accountId) ?? /* @__PURE__ */ new Set();
|
|
@@ -33712,92 +33891,6 @@ function buildSpawnArgs(input, printTimeoutMinutes, log) {
|
|
|
33712
33891
|
stdinPayload
|
|
33713
33892
|
};
|
|
33714
33893
|
}
|
|
33715
|
-
/**
|
|
33716
|
-
* Idle-budget + long-tool heartbeat state. While an agy tool step is ACTIVE the
|
|
33717
|
-
* child is legitimately silent on stdout (maven compile, language-server
|
|
33718
|
-
* build, …) — issue #33 — so the watchdog raises the idle budget; bare
|
|
33719
|
-
* generation gets a bounded floor so a hung SSE stream can fail and rotate.
|
|
33720
|
-
*/
|
|
33721
|
-
function createToolWatchdog(log, cfg) {
|
|
33722
|
-
const openToolKeys = /* @__PURE__ */ new Set();
|
|
33723
|
-
const openToolSince = /* @__PURE__ */ new Map();
|
|
33724
|
-
const longToolIdleMinutes = cfg.longToolIdleMinutes > 0 ? cfg.longToolIdleMinutes : 0;
|
|
33725
|
-
let printTimeoutMinutes = Math.max(longToolIdleMinutes > 0 ? longToolIdleMinutes : Math.ceil(cfg.timeoutMs / 6e4), Math.ceil(cfg.timeoutMs / 6e4));
|
|
33726
|
-
if (cfg.maxTurnMinutes > 0 && printTimeoutMinutes > cfg.maxTurnMinutes) printTimeoutMinutes = cfg.maxTurnMinutes;
|
|
33727
|
-
const longToolIdleMs = longToolIdleMinutes > 0 ? longToolIdleMinutes * 6e4 : cfg.timeoutMs;
|
|
33728
|
-
const generationIdleMs = Math.max(cfg.timeoutMs, 9e5);
|
|
33729
|
-
let runningProc = null;
|
|
33730
|
-
let sawAnyEvent = false;
|
|
33731
|
-
let lastOutputAt = 0;
|
|
33732
|
-
const TOOL_HEARTBEAT_MS = 3e5;
|
|
33733
|
-
let toolHeartbeat = null;
|
|
33734
|
-
const apply = () => {
|
|
33735
|
-
runningProc?.noteActivity(openToolKeys.size > 0 ? longToolIdleMs : generationIdleMs);
|
|
33736
|
-
};
|
|
33737
|
-
const stop = () => {
|
|
33738
|
-
if (toolHeartbeat !== null) {
|
|
33739
|
-
clearInterval(toolHeartbeat);
|
|
33740
|
-
toolHeartbeat = null;
|
|
33741
|
-
}
|
|
33742
|
-
};
|
|
33743
|
-
const start = () => {
|
|
33744
|
-
if (toolHeartbeat !== null) return;
|
|
33745
|
-
toolHeartbeat = setInterval(() => {
|
|
33746
|
-
if (openToolKeys.size === 0 && !sawAnyEvent) {
|
|
33747
|
-
stop();
|
|
33748
|
-
return;
|
|
33749
|
-
}
|
|
33750
|
-
let oldest = Date.now();
|
|
33751
|
-
for (const startedAt of openToolSince.values()) if (startedAt < oldest) oldest = startedAt;
|
|
33752
|
-
if (openToolKeys.size === 0 && lastOutputAt > 0) oldest = lastOutputAt;
|
|
33753
|
-
const mins = Math.max(1, Math.round((Date.now() - oldest) / 6e4));
|
|
33754
|
-
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");
|
|
33755
|
-
}, TOOL_HEARTBEAT_MS);
|
|
33756
|
-
toolHeartbeat.unref?.();
|
|
33757
|
-
};
|
|
33758
|
-
return {
|
|
33759
|
-
printTimeoutMinutes,
|
|
33760
|
-
attach: (proc) => {
|
|
33761
|
-
runningProc = proc;
|
|
33762
|
-
apply();
|
|
33763
|
-
},
|
|
33764
|
-
markEvent: () => {
|
|
33765
|
-
sawAnyEvent = true;
|
|
33766
|
-
lastOutputAt = Date.now();
|
|
33767
|
-
start();
|
|
33768
|
-
apply();
|
|
33769
|
-
},
|
|
33770
|
-
trackStep: (ev) => {
|
|
33771
|
-
if (ev.kind !== "step") return;
|
|
33772
|
-
if (ev.stepKind === "tool" && ev.tool !== void 0) {
|
|
33773
|
-
if (!(ev.state === "DONE" || ev.state === "ERROR" || ev.state === "RUNNING" || ev.state === void 0 && (ev.tool.output !== void 0 || ev.tool.error !== void 0))) {
|
|
33774
|
-
if (!openToolKeys.has(ev.stepKey)) {
|
|
33775
|
-
openToolKeys.add(ev.stepKey);
|
|
33776
|
-
openToolSince.set(ev.stepKey, Date.now());
|
|
33777
|
-
apply();
|
|
33778
|
-
start();
|
|
33779
|
-
}
|
|
33780
|
-
} else if (openToolKeys.delete(ev.stepKey)) {
|
|
33781
|
-
openToolSince.delete(ev.stepKey);
|
|
33782
|
-
apply();
|
|
33783
|
-
if (openToolKeys.size === 0) stop();
|
|
33784
|
-
}
|
|
33785
|
-
} else if (ev.stepKind === "text" || ev.stepKind === "thinking") {
|
|
33786
|
-
if (openToolKeys.size > 0) {
|
|
33787
|
-
openToolKeys.clear();
|
|
33788
|
-
openToolSince.clear();
|
|
33789
|
-
apply();
|
|
33790
|
-
stop();
|
|
33791
|
-
}
|
|
33792
|
-
}
|
|
33793
|
-
},
|
|
33794
|
-
stop: () => {
|
|
33795
|
-
stop();
|
|
33796
|
-
openToolKeys.clear();
|
|
33797
|
-
openToolSince.clear();
|
|
33798
|
-
}
|
|
33799
|
-
};
|
|
33800
|
-
}
|
|
33801
33894
|
/** Create the recording, parser, HOME snapshot and tool watchdog for one run. */
|
|
33802
33895
|
function createAttemptRecorder(deps, cfg, account, initialConversationId) {
|
|
33803
33896
|
const rec = deps.runs.create();
|
|
@@ -34722,7 +34815,8 @@ var AgyAdapter = class extends LlmAdapter {
|
|
|
34722
34815
|
deps: {
|
|
34723
34816
|
...this.deps.pool === void 0 ? {} : { pool: this.deps.pool },
|
|
34724
34817
|
store: this.deps.store,
|
|
34725
|
-
...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 }
|
|
34726
34820
|
},
|
|
34727
34821
|
cfg,
|
|
34728
34822
|
model,
|
|
@@ -39854,6 +39948,10 @@ function createHostServices(ctx, entryConfig = {}) {
|
|
|
39854
39948
|
log,
|
|
39855
39949
|
runs,
|
|
39856
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
|
+
},
|
|
39857
39955
|
effortUnsupported: () => effortStore.read(),
|
|
39858
39956
|
onEffortUnsupported: (model) => effortStore.remember(model),
|
|
39859
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.
|
|
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",
|