dsh-agy-link 0.6.21 → 0.6.22
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 +73 -0
- package/README.md +1 -1
- package/dist/cli-image.mjs +545 -86
- package/dist/client.js +587 -225
- package/dist/index.js +874 -184
- package/docs/CONFIGURATION.md +11 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2,8 +2,8 @@ import { createRequire } from "node:module";
|
|
|
2
2
|
import path, { basename, delimiter, dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
5
|
-
import { execFile, execFileSync, spawn } from "node:child_process";
|
|
6
|
-
import { accessSync, chmodSync, constants, copyFileSync, createReadStream, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, utimesSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { execFile, execFileSync, spawn, spawnSync } from "node:child_process";
|
|
6
|
+
import { accessSync, chmodSync, closeSync, constants, copyFileSync, createReadStream, existsSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, utimesSync, writeFileSync } from "node:fs";
|
|
7
7
|
import { homedir, tmpdir } from "node:os";
|
|
8
8
|
import { mkdir, mkdtemp, readFile, readdir, rm, stat, unlink, writeFile } from "node:fs/promises";
|
|
9
9
|
import * as dshLlm from "@deepseek-ai/dsh-llm";
|
|
@@ -16,12 +16,23 @@ import { EventEmitter } from "node:events";
|
|
|
16
16
|
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
17
17
|
var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
|
|
18
18
|
//#endregion
|
|
19
|
-
//#region src/common/
|
|
20
|
-
|
|
19
|
+
//#region src/common/model-lineup.ts
|
|
20
|
+
/** Gemini Flash — the cheap, always-available workhorse. */
|
|
21
|
+
const PREFERRED_GEMINI_FLASH = "gemini-3.8-flash";
|
|
22
|
+
/** Anthropic tier (Sonnet — the default Anthropic pick). */
|
|
23
|
+
const PREFERRED_CLAUDE = "claude-sonnet-5-5";
|
|
24
|
+
/** Anthropic top tier; reached through the bare `claude-opus` alias. */
|
|
25
|
+
const PREFERRED_CLAUDE_OPUS = "claude-opus-5-5";
|
|
26
|
+
/** OpenAI tier. */
|
|
27
|
+
const PREFERRED_OPENAI = "gpt-oss-120b-medium";
|
|
28
|
+
/**
|
|
29
|
+
* Offline/signed-out lineup. Mirrors `agy models` (agy 1.5.7) exactly —
|
|
30
|
+
* same ids, same effort sets, same order.
|
|
31
|
+
*/
|
|
21
32
|
const DEFAULT_FALLBACK_MODELS = [
|
|
22
33
|
{
|
|
23
|
-
id: "gemini-4-
|
|
24
|
-
name: "Gemini 4
|
|
34
|
+
id: "gemini-4-argon",
|
|
35
|
+
name: "Gemini 4 Argon",
|
|
25
36
|
efforts: [
|
|
26
37
|
"low",
|
|
27
38
|
"medium",
|
|
@@ -29,17 +40,22 @@ const DEFAULT_FALLBACK_MODELS = [
|
|
|
29
40
|
]
|
|
30
41
|
},
|
|
31
42
|
{
|
|
32
|
-
id: "gemini-
|
|
33
|
-
name: "Gemini
|
|
43
|
+
id: "gemini-4-hydrogen",
|
|
44
|
+
name: "Gemini 4 Hydrogen",
|
|
34
45
|
efforts: [
|
|
35
46
|
"low",
|
|
36
47
|
"medium",
|
|
37
|
-
"high"
|
|
48
|
+
"high",
|
|
49
|
+
"xhigh"
|
|
38
50
|
]
|
|
39
51
|
},
|
|
40
52
|
{
|
|
41
|
-
id: "gemini-
|
|
42
|
-
name: "
|
|
53
|
+
id: "gemini-pro-orchestrator-g1-pro",
|
|
54
|
+
name: "Orchestrator (Argon)"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
id: "gemini-3.8-flash",
|
|
58
|
+
name: "Gemini 3.8 Flash",
|
|
43
59
|
efforts: [
|
|
44
60
|
"low",
|
|
45
61
|
"medium",
|
|
@@ -47,16 +63,8 @@ const DEFAULT_FALLBACK_MODELS = [
|
|
|
47
63
|
]
|
|
48
64
|
},
|
|
49
65
|
{
|
|
50
|
-
id: "claude-
|
|
51
|
-
name: "Claude
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
id: "claude-opus-4-6-thinking",
|
|
55
|
-
name: "Claude Opus 4.6 (Thinking)"
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
id: "claude-sonnet-5-5",
|
|
59
|
-
name: "Claude Sonnet 5.5",
|
|
66
|
+
id: "claude-opus-5-5",
|
|
67
|
+
name: "Claude Opus 5.5",
|
|
60
68
|
efforts: [
|
|
61
69
|
"low",
|
|
62
70
|
"medium",
|
|
@@ -64,8 +72,8 @@ const DEFAULT_FALLBACK_MODELS = [
|
|
|
64
72
|
]
|
|
65
73
|
},
|
|
66
74
|
{
|
|
67
|
-
id: "claude-
|
|
68
|
-
name: "Claude
|
|
75
|
+
id: "claude-sonnet-5-5",
|
|
76
|
+
name: "Claude Sonnet 5.5",
|
|
69
77
|
efforts: [
|
|
70
78
|
"low",
|
|
71
79
|
"medium",
|
|
@@ -77,6 +85,9 @@ const DEFAULT_FALLBACK_MODELS = [
|
|
|
77
85
|
name: "GPT-OSS 120B (Medium)"
|
|
78
86
|
}
|
|
79
87
|
];
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/common/types/config.ts
|
|
90
|
+
const PROVIDER_ID = "antigravity";
|
|
80
91
|
function defaultConfig() {
|
|
81
92
|
return {
|
|
82
93
|
enabled: true,
|
|
@@ -146,9 +157,9 @@ function defaultConfig() {
|
|
|
146
157
|
proxyUrl: "",
|
|
147
158
|
suppressAgyAutoUpdate: process.platform === "win32",
|
|
148
159
|
autoWarmup: false,
|
|
149
|
-
warmupModels: [
|
|
160
|
+
warmupModels: [PREFERRED_GEMINI_FLASH, PREFERRED_CLAUDE],
|
|
150
161
|
autoTranslate: false,
|
|
151
|
-
translateModel:
|
|
162
|
+
translateModel: PREFERRED_GEMINI_FLASH,
|
|
152
163
|
translateEffort: "medium",
|
|
153
164
|
translateTargetLanguage: "中文(简体)",
|
|
154
165
|
translateMaxChars: 8e3,
|
|
@@ -158,6 +169,8 @@ function defaultConfig() {
|
|
|
158
169
|
translateBindConversation: true,
|
|
159
170
|
translateSkipSameModel: true,
|
|
160
171
|
translateMinIntervalMs: 3e3,
|
|
172
|
+
showHeaderBadge: true,
|
|
173
|
+
showTranslateAction: true,
|
|
161
174
|
imageModel: "",
|
|
162
175
|
imageEffort: "low",
|
|
163
176
|
imageTimeoutMs: 24e4,
|
|
@@ -597,6 +610,80 @@ function defaultPoolData() {
|
|
|
597
610
|
};
|
|
598
611
|
}
|
|
599
612
|
//#endregion
|
|
613
|
+
//#region src/common/reasoning.ts
|
|
614
|
+
/** Every effort id agy accepts, in ascending intensity order. */
|
|
615
|
+
const REASONING_EFFORTS = [
|
|
616
|
+
"low",
|
|
617
|
+
"medium",
|
|
618
|
+
"high",
|
|
619
|
+
"xhigh",
|
|
620
|
+
"max"
|
|
621
|
+
];
|
|
622
|
+
/**
|
|
623
|
+
* Display names, matching agy's own model picker ("Extra" is `xhigh`, which is
|
|
624
|
+
* how the GUI labels it while `agy --help` spells it `xhigh`).
|
|
625
|
+
*/
|
|
626
|
+
const EFFORT_LABELS = {
|
|
627
|
+
low: "Low",
|
|
628
|
+
medium: "Medium",
|
|
629
|
+
high: "High",
|
|
630
|
+
xhigh: "Extra",
|
|
631
|
+
max: "Max"
|
|
632
|
+
};
|
|
633
|
+
/** Display name for an effort id; unknown ids are shown verbatim. */
|
|
634
|
+
function effortLabel(id) {
|
|
635
|
+
const key = typeof id === "string" ? id.trim().toLowerCase() : "";
|
|
636
|
+
return EFFORT_LABELS[key] ?? (typeof id === "string" ? id.trim() : "");
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* Effort suffixes ordered so a LONGER suffix always wins: `gemini-4-hydrogen-xhigh`
|
|
640
|
+
* must fold as `gemini-4-hydrogen` + `xhigh`, never as `gemini-4-hydrogen-x` + `high`.
|
|
641
|
+
*/
|
|
642
|
+
const EFFORT_SUFFIXES = [...REASONING_EFFORTS].sort((a, b) => b.length - a.length || a.localeCompare(b));
|
|
643
|
+
/**
|
|
644
|
+
* Split a discovered agy slug into (base, effort).
|
|
645
|
+
*
|
|
646
|
+
* Returns `effort: undefined` when the slug carries no effort suffix. The
|
|
647
|
+
* caller still decides whether the base is real — a lone `gemini-x-medium`
|
|
648
|
+
* with no siblings must stay verbatim rather than inventing a base.
|
|
649
|
+
*/
|
|
650
|
+
function splitEffortSuffix(slug) {
|
|
651
|
+
const id = typeof slug === "string" ? slug.trim() : "";
|
|
652
|
+
for (const effort of EFFORT_SUFFIXES) {
|
|
653
|
+
const suffix = "-" + effort;
|
|
654
|
+
if (id.length > suffix.length && id.endsWith(suffix)) return {
|
|
655
|
+
base: id.slice(0, -suffix.length),
|
|
656
|
+
effort
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
return { base: id };
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Canonical ordering + de-duplication of an effort set.
|
|
663
|
+
*
|
|
664
|
+
* Order is always `REASONING_EFFORTS`, so the picker and the settings
|
|
665
|
+
* dropdowns can never disagree about the order of Low/Medium/High/Extra.
|
|
666
|
+
*
|
|
667
|
+
* Ids this build does not know yet (a newer agy level, or a hand-written
|
|
668
|
+
* `fallbackModels` entry) are kept AFTER the known ones in first-seen order —
|
|
669
|
+
* dropping them would silently delete a user's configuration.
|
|
670
|
+
*/
|
|
671
|
+
function normalizeEfforts(list) {
|
|
672
|
+
if (list === void 0 || list === null) return [];
|
|
673
|
+
const present = /* @__PURE__ */ new Set();
|
|
674
|
+
const order = [];
|
|
675
|
+
for (const raw of list) {
|
|
676
|
+
if (typeof raw !== "string") continue;
|
|
677
|
+
const id = raw.trim().toLowerCase();
|
|
678
|
+
if (id === "" || present.has(id)) continue;
|
|
679
|
+
present.add(id);
|
|
680
|
+
order.push(id);
|
|
681
|
+
}
|
|
682
|
+
const known = REASONING_EFFORTS.filter((e) => present.has(e));
|
|
683
|
+
const unknown = order.filter((e) => !REASONING_EFFORTS.includes(e));
|
|
684
|
+
return [...known, ...unknown];
|
|
685
|
+
}
|
|
686
|
+
//#endregion
|
|
600
687
|
//#region src/host/models.ts
|
|
601
688
|
/** Check whether any enabled account in the pool has confirmed access to Argon. */
|
|
602
689
|
function poolHasArgon(pool, catalog) {
|
|
@@ -679,15 +766,16 @@ function extractModelList(parsed) {
|
|
|
679
766
|
}
|
|
680
767
|
return out;
|
|
681
768
|
}
|
|
682
|
-
const EFFORT_SUFFIXES = [
|
|
683
|
-
"low",
|
|
684
|
-
"medium",
|
|
685
|
-
"high"
|
|
686
|
-
];
|
|
687
769
|
/** Fold Gemini/Argon/Claude effort variants into base + effort set (spec ADR-10).
|
|
688
770
|
* Claude 5.5 is listed only as tiered slugs by agy 1.5.3; the base slug is the
|
|
689
771
|
* one that accepts `--effort`, and passing a tiered slug together with the flag
|
|
690
|
-
* is rejected ("--model … conflicts with --effort=…").
|
|
772
|
+
* is rejected ("--model … conflicts with --effort=…").
|
|
773
|
+
*
|
|
774
|
+
* The effort vocabulary itself (including agy 1.5.7's `xhigh`, which its picker
|
|
775
|
+
* labels "Extra") comes from `common/reasoning.ts` — folding must never carry
|
|
776
|
+
* its own copy of the list, or a new level silently becomes a bogus MODEL:
|
|
777
|
+
* a missed `xhigh` used to surface `gemini-4-hydrogen-xhigh` next to
|
|
778
|
+
* `gemini-4-hydrogen` in DSH's picker. */
|
|
691
779
|
function foldEfforts(raw) {
|
|
692
780
|
const bases = /* @__PURE__ */ new Map();
|
|
693
781
|
const verbatim = [];
|
|
@@ -701,26 +789,23 @@ function foldEfforts(raw) {
|
|
|
701
789
|
});
|
|
702
790
|
continue;
|
|
703
791
|
}
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
const
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
folded = true;
|
|
719
|
-
break;
|
|
720
|
-
}
|
|
792
|
+
const split = splitEffortSuffix(r.slug);
|
|
793
|
+
if (split.effort !== void 0) {
|
|
794
|
+
const base = split.base;
|
|
795
|
+
const eff = split.effort;
|
|
796
|
+
const hasBare = slugSet.has(base);
|
|
797
|
+
const hasSibling = raw.some((x) => x.slug !== r.slug && splitEffortSuffix(x.slug).base === base);
|
|
798
|
+
if (hasBare || hasSibling) {
|
|
799
|
+
const entry = bases.get(base) ?? {
|
|
800
|
+
label: stripEffortLabel(r.label, eff),
|
|
801
|
+
efforts: /* @__PURE__ */ new Set()
|
|
802
|
+
};
|
|
803
|
+
entry.efforts.add(eff);
|
|
804
|
+
bases.set(base, entry);
|
|
805
|
+
continue;
|
|
721
806
|
}
|
|
722
807
|
}
|
|
723
|
-
|
|
808
|
+
verbatim.push({
|
|
724
809
|
id: r.slug,
|
|
725
810
|
name: r.label,
|
|
726
811
|
efforts: null
|
|
@@ -728,7 +813,7 @@ function foldEfforts(raw) {
|
|
|
728
813
|
}
|
|
729
814
|
const folded = [];
|
|
730
815
|
for (const [id, v] of bases) {
|
|
731
|
-
const efforts =
|
|
816
|
+
const efforts = normalizeEfforts(v.efforts);
|
|
732
817
|
folded.push({
|
|
733
818
|
id,
|
|
734
819
|
name: v.label !== "" ? v.label : id,
|
|
@@ -741,9 +826,7 @@ function foldEfforts(raw) {
|
|
|
741
826
|
for (const r of raw) if (r.slug === e.id || r.slug.startsWith(e.id + "-")) best = Math.min(best, rawOrder.get(r.slug) ?? Infinity);
|
|
742
827
|
return best;
|
|
743
828
|
};
|
|
744
|
-
folded.sort((a, b) => rank(a) - rank(b));
|
|
745
|
-
verbatim.sort((a, b) => rank(a) - rank(b));
|
|
746
|
-
return [...folded, ...verbatim.filter((e) => !bases.has(e.id))];
|
|
829
|
+
return [...folded, ...verbatim.filter((e) => !bases.has(e.id))].sort((a, b) => rank(a) - rank(b));
|
|
747
830
|
}
|
|
748
831
|
function stripEffortLabel(label, eff) {
|
|
749
832
|
const re = new RegExp("\\s*\\(?" + eff + "\\)?\\s*$", "i");
|
|
@@ -778,7 +861,8 @@ function sanitizeCatalogEntries(models) {
|
|
|
778
861
|
const name = typeof m.name === "string" && m.name.trim() !== "" ? m.name.trim() : id;
|
|
779
862
|
entries.push({
|
|
780
863
|
id,
|
|
781
|
-
name
|
|
864
|
+
name,
|
|
865
|
+
efforts: normalizeEfforts(m.efforts)
|
|
782
866
|
});
|
|
783
867
|
}
|
|
784
868
|
return {
|
|
@@ -802,6 +886,12 @@ var ModelCatalog = class ModelCatalog {
|
|
|
802
886
|
*/
|
|
803
887
|
static FALLBACK_RETRY_MS = 6e4;
|
|
804
888
|
lastAttemptAt = 0;
|
|
889
|
+
/**
|
|
890
|
+
* Per-account probe timestamps. `refreshIfNeeded(accountId)` used to skip
|
|
891
|
+
* the throttle whenever the account had no catalog yet, so a signed-out /
|
|
892
|
+
* expired account could be probed on EVERY listModels() read (issue #106).
|
|
893
|
+
*/
|
|
894
|
+
accountAttemptAt = /* @__PURE__ */ new Map();
|
|
805
895
|
constructor(discover, fallbackDefs, ttlMs, onUpdate) {
|
|
806
896
|
this.discover = discover;
|
|
807
897
|
this.fallbackDefs = fallbackDefs;
|
|
@@ -885,6 +975,9 @@ var ModelCatalog = class ModelCatalog {
|
|
|
885
975
|
const age = now - targetCat.discoveredAt;
|
|
886
976
|
if (targetCat.source === "discovered" && age < this.ttlMs) return;
|
|
887
977
|
if (targetCat.source === "fallback" && now - this.lastAttemptAt < ModelCatalog.FALLBACK_RETRY_MS) return;
|
|
978
|
+
} else {
|
|
979
|
+
if (now - (this.accountAttemptAt.get(accountId) ?? 0) < ModelCatalog.FALLBACK_RETRY_MS) return;
|
|
980
|
+
this.accountAttemptAt.set(accountId, now);
|
|
888
981
|
}
|
|
889
982
|
this.lastAttemptAt = now;
|
|
890
983
|
this.refreshing = this.refresh(accountId).finally(() => {
|
|
@@ -892,6 +985,20 @@ var ModelCatalog = class ModelCatalog {
|
|
|
892
985
|
});
|
|
893
986
|
return this.refreshing;
|
|
894
987
|
}
|
|
988
|
+
/**
|
|
989
|
+
* Read-path discovery for one account (listModels). Unlike
|
|
990
|
+
* `forceRefreshAndNotify()` this is throttled and NEVER broadcasts on a
|
|
991
|
+
* failed probe: an unconditional `adapters-updated` made DSH's browser
|
|
992
|
+
* re-read the catalog, which called listModels() again — a self-exciting
|
|
993
|
+
* 1:1 read/probe/announce loop while signed out (issue #106). `refresh()`
|
|
994
|
+
* itself announces only when the catalog contents actually changed, so a
|
|
995
|
+
* successful first build still updates the picker exactly once.
|
|
996
|
+
*/
|
|
997
|
+
async ensureAccountCatalog(accountId) {
|
|
998
|
+
if (!accountId || this.accountCatalogs.has(accountId)) return this.get(accountId);
|
|
999
|
+
await this.refreshIfNeeded(accountId);
|
|
1000
|
+
return this.get(accountId);
|
|
1001
|
+
}
|
|
895
1002
|
async forceRefresh(accountId) {
|
|
896
1003
|
await this.refresh(accountId);
|
|
897
1004
|
return this.get(accountId);
|
|
@@ -910,8 +1017,10 @@ var ModelCatalog = class ModelCatalog {
|
|
|
910
1017
|
* switching to a Pro/Ultra account).
|
|
911
1018
|
*/
|
|
912
1019
|
async forceRefreshAndNotify(accountId) {
|
|
1020
|
+
const hadCatalog = accountId ? this.hasAccountCatalog(accountId) : true;
|
|
913
1021
|
await this.refresh(accountId, false);
|
|
914
|
-
this.
|
|
1022
|
+
const hasCatalog = accountId ? this.hasAccountCatalog(accountId) : true;
|
|
1023
|
+
if (hadCatalog || hasCatalog) this.onUpdate?.();
|
|
915
1024
|
return this.get(accountId);
|
|
916
1025
|
}
|
|
917
1026
|
/**
|
|
@@ -970,11 +1079,11 @@ var ModelCatalog = class ModelCatalog {
|
|
|
970
1079
|
};
|
|
971
1080
|
function resolveModelSlug(id) {
|
|
972
1081
|
const s = id.trim().toLowerCase();
|
|
973
|
-
if (s === "claude-opus") return
|
|
974
|
-
if (s === "claude-sonnet") return
|
|
1082
|
+
if (s === "claude-opus") return PREFERRED_CLAUDE_OPUS;
|
|
1083
|
+
if (s === "claude-sonnet") return PREFERRED_CLAUDE;
|
|
975
1084
|
if (s === "claude-opus-4-6" || s === "claude-opus-4-8" || s === "claude-opus-4.6" || s === "claude-opus-4-5") return "claude-opus-4-6-thinking";
|
|
976
1085
|
if (s === "claude-sonnet-4.6" || s === "claude-sonnet-4-5") return "claude-sonnet-4-6";
|
|
977
|
-
if (s === "gpt-oss-120b" || s === "gpt-oss-20b" || s === "gpt-oss") return
|
|
1086
|
+
if (s === "gpt-oss-120b" || s === "gpt-oss-20b" || s === "gpt-oss") return PREFERRED_OPENAI;
|
|
978
1087
|
const claude55 = s.match(/^(claude-(?:sonnet|opus)-5-5)-(?:low|medium|high)$/);
|
|
979
1088
|
if (claude55 !== null && claude55[1] !== void 0) return claude55[1];
|
|
980
1089
|
return id.trim();
|
|
@@ -1783,6 +1892,33 @@ function nodeScriptEnv(env) {
|
|
|
1783
1892
|
ELECTRON_RUN_AS_NODE: "1"
|
|
1784
1893
|
};
|
|
1785
1894
|
}
|
|
1895
|
+
//#endregion
|
|
1896
|
+
//#region src/common/timeouts.ts
|
|
1897
|
+
/** Host-side hard deadline for any plugin route; the last line of defence. */
|
|
1898
|
+
const ROUTE_TIMEOUT_MS = 3e4;
|
|
1899
|
+
/** Slack above a job's own deadline before its route may give up. */
|
|
1900
|
+
const ROUTE_DEADLINE_SLACK_MS = 15e3;
|
|
1901
|
+
/**
|
|
1902
|
+
* Deadline for a route that fronts a genuinely long job (a translation is a
|
|
1903
|
+
* full agy turn: `translateTimeoutMs` defaults to 120s and medium effort
|
|
1904
|
+
* typically takes 20–45s). The general 30s route deadline would answer 504
|
|
1905
|
+
* first, and because `sendJson` is exactly-once the real 200 would then be
|
|
1906
|
+
* discarded — every slow translation would look like a failure.
|
|
1907
|
+
*/
|
|
1908
|
+
function longRouteTimeout(jobTimeoutMs) {
|
|
1909
|
+
return Math.max(ROUTE_TIMEOUT_MS, (Number.isFinite(jobTimeoutMs) && jobTimeoutMs > 0 ? jobTimeoutMs : ROUTE_TIMEOUT_MS) + ROUTE_DEADLINE_SLACK_MS);
|
|
1910
|
+
}
|
|
1911
|
+
/** How long a manual quota refresh keeps its dedupe entry when work never settles. */
|
|
1912
|
+
const QUOTA_REFRESH_DEDUP_MS = 9e4;
|
|
1913
|
+
/**
|
|
1914
|
+
* Grace the idle watchdog grants before killing a quiet child. libuv runs the
|
|
1915
|
+
* timers phase BEFORE the poll phase: when the DSH host's event loop is blocked
|
|
1916
|
+
* (a large parse, many parallel workers), an expired watchdog can fire before
|
|
1917
|
+
* queued stdout/stderr from a still-active child is delivered. One short grace
|
|
1918
|
+
* lets that output arrive instead of killing a healthy run. Capped at the run's
|
|
1919
|
+
* own idle budget so short-budget tests and genuine idle kills stay prompt.
|
|
1920
|
+
*/
|
|
1921
|
+
const WATCHDOG_GRACE_MS = 5e3;
|
|
1786
1922
|
function nonBlank(v) {
|
|
1787
1923
|
return (v ?? "").trim();
|
|
1788
1924
|
}
|
|
@@ -1959,6 +2095,7 @@ function createRunState(opts) {
|
|
|
1959
2095
|
settled: false,
|
|
1960
2096
|
idleBudgetMs: opts.timeoutMs,
|
|
1961
2097
|
watchdog: null,
|
|
2098
|
+
watchdogGraceUsed: false,
|
|
1962
2099
|
turnCap: null
|
|
1963
2100
|
};
|
|
1964
2101
|
}
|
|
@@ -2016,13 +2153,22 @@ function writeInitialStdin(opts, child) {
|
|
|
2016
2153
|
} catch {}
|
|
2017
2154
|
}
|
|
2018
2155
|
function makeRefreshWatchdog(child, state) {
|
|
2019
|
-
|
|
2020
|
-
if (!state.idleBudgetMs || state.idleBudgetMs <= 0 || state.settled) return;
|
|
2156
|
+
const arm = (budgetMs) => {
|
|
2021
2157
|
if (state.watchdog) clearTimeout(state.watchdog);
|
|
2022
2158
|
state.watchdog = setTimeout(() => {
|
|
2159
|
+
if (!state.watchdogGraceUsed) {
|
|
2160
|
+
state.watchdogGraceUsed = true;
|
|
2161
|
+
arm(Math.min(budgetMs, WATCHDOG_GRACE_MS));
|
|
2162
|
+
return;
|
|
2163
|
+
}
|
|
2023
2164
|
state.timedOut = true;
|
|
2024
2165
|
killTree(child);
|
|
2025
|
-
},
|
|
2166
|
+
}, budgetMs);
|
|
2167
|
+
};
|
|
2168
|
+
return () => {
|
|
2169
|
+
if (!state.idleBudgetMs || state.idleBudgetMs <= 0 || state.settled) return;
|
|
2170
|
+
state.watchdogGraceUsed = false;
|
|
2171
|
+
arm(state.idleBudgetMs);
|
|
2026
2172
|
};
|
|
2027
2173
|
}
|
|
2028
2174
|
function armTurnCap(child, opts, state) {
|
|
@@ -3201,7 +3347,7 @@ function buildMirrorRunCode(runId, eventIndex, toolName, brief) {
|
|
|
3201
3347
|
step: eventIndex
|
|
3202
3348
|
});
|
|
3203
3349
|
return {
|
|
3204
|
-
code: "// dsh-agy-link mirror: replay recorded agy tool step " + eventIndex + " (" + toolName + ")\
|
|
3350
|
+
code: "// dsh-agy-link mirror: replay recorded agy tool step " + eventIndex + " (" + toolName + ")\nawait tools['agy_tool'](" + invocation + ")",
|
|
3205
3351
|
description: brief !== void 0 && brief !== "" ? brief + " · " + toolName : toolName
|
|
3206
3352
|
};
|
|
3207
3353
|
}
|
|
@@ -3358,9 +3504,14 @@ function toolStepBrief(toolName, args, server) {
|
|
|
3358
3504
|
return timing ? "schedule " + timing : prompt ? "schedule " + prompt.slice(0, 40) : "schedule";
|
|
3359
3505
|
}
|
|
3360
3506
|
if (effTool === "invoke_subagent") {
|
|
3507
|
+
const directRole = pickStr("Role", "role", "TypeName", "typeName");
|
|
3361
3508
|
const subs = a.Subagents ?? a.subagents;
|
|
3362
|
-
const
|
|
3363
|
-
|
|
3509
|
+
const subRole = Array.isArray(subs) && subs.length > 0 && typeof subs[0].Role === "string" ? subs[0].Role : Array.isArray(subs) && subs.length > 0 && typeof subs[0].TypeName === "string" ? subs[0].TypeName : "";
|
|
3510
|
+
let role = (directRole || subRole).trim();
|
|
3511
|
+
if (role.startsWith("\"") && role.endsWith("\"")) try {
|
|
3512
|
+
role = JSON.parse(role);
|
|
3513
|
+
} catch {}
|
|
3514
|
+
return role ? "subagent: " + role : "invoke subagent";
|
|
3364
3515
|
}
|
|
3365
3516
|
if (effTool === "send_message") {
|
|
3366
3517
|
const recipient = pickStr("Recipient", "recipient", "to");
|
|
@@ -3510,12 +3661,23 @@ function presentScheduleCall(input) {
|
|
|
3510
3661
|
rawInput: input
|
|
3511
3662
|
};
|
|
3512
3663
|
}
|
|
3664
|
+
function cleanRole(raw) {
|
|
3665
|
+
if (!raw) return void 0;
|
|
3666
|
+
let s = raw.trim();
|
|
3667
|
+
if (s.startsWith("\"") && s.endsWith("\"")) try {
|
|
3668
|
+
s = JSON.parse(s);
|
|
3669
|
+
} catch {}
|
|
3670
|
+
return s || void 0;
|
|
3671
|
+
}
|
|
3513
3672
|
function presentSubagentCall(input) {
|
|
3514
3673
|
const subs = input.Subagents ?? input.subagents;
|
|
3515
|
-
const
|
|
3674
|
+
const subRole = Array.isArray(subs) && subs.length > 0 && typeof subs[0].Role === "string" ? subs[0].Role : Array.isArray(subs) && subs.length > 0 && typeof subs[0].TypeName === "string" ? subs[0].TypeName : void 0;
|
|
3675
|
+
const directRole = cleanRole(pick(input, "Role", "role"));
|
|
3676
|
+
const directTypeName = cleanRole(pick(input, "TypeName", "typeName"));
|
|
3677
|
+
const effRole = cleanRole(subRole) ?? (directRole && directTypeName ? `${directRole} (${directTypeName})` : directRole ?? directTypeName);
|
|
3516
3678
|
return {
|
|
3517
3679
|
card: "generic",
|
|
3518
|
-
title: pick(input, "Description", "description", "toolAction", "toolSummary") ?? (
|
|
3680
|
+
title: pick(input, "Description", "description", "toolAction", "toolSummary") ?? (effRole ? `Subagent: ${effRole}` : "Invoke subagent"),
|
|
3519
3681
|
kind: "execute",
|
|
3520
3682
|
rawInput: input
|
|
3521
3683
|
};
|
|
@@ -3776,6 +3938,19 @@ function rewriteImageMarkdown(text, mediaBaseUrl) {
|
|
|
3776
3938
|
return `}`})`;
|
|
3777
3939
|
});
|
|
3778
3940
|
}
|
|
3941
|
+
/** Normalize Markdown file links: strip file:/// prefix so DSH's native markdown compiler treats them as local files and opens them in the native right sidebar. */
|
|
3942
|
+
function normalizeFileLinks(text) {
|
|
3943
|
+
if (!text) return text;
|
|
3944
|
+
return text.replace(/(^|[^\!])\[([^\]]+)\]\((file:\/\/\/[^\s)]+|file:\/\/[^\s)]+)\)/g, (_, prefix, label, url) => {
|
|
3945
|
+
let target = url.trim();
|
|
3946
|
+
if (target.startsWith("file://")) {
|
|
3947
|
+
target = target.slice(7);
|
|
3948
|
+
if (/^\/[A-Za-z]:/.test(target)) target = target.slice(1);
|
|
3949
|
+
}
|
|
3950
|
+
target = target.replace(/\\/g, "/");
|
|
3951
|
+
return `${prefix}[${label}](${target})`;
|
|
3952
|
+
});
|
|
3953
|
+
}
|
|
3779
3954
|
//#endregion
|
|
3780
3955
|
//#region src/host/recording.ts
|
|
3781
3956
|
function classifyToolError(error) {
|
|
@@ -4398,7 +4573,7 @@ var EventMapper = class {
|
|
|
4398
4573
|
this.sawTextStep = true;
|
|
4399
4574
|
yield* this.ensureBlock("text");
|
|
4400
4575
|
let d;
|
|
4401
|
-
const processedText = this.opts.mediaBaseUrl ? rewriteImageMarkdown(ev.text, this.opts.mediaBaseUrl) : ev.text;
|
|
4576
|
+
const processedText = normalizeFileLinks(this.opts.mediaBaseUrl ? rewriteImageMarkdown(ev.text, this.opts.mediaBaseUrl) : ev.text);
|
|
4402
4577
|
if (ev.fragment === true) {
|
|
4403
4578
|
const acc = (this.emittedByKey.get(ev.stepKey) ?? "") + processedText;
|
|
4404
4579
|
this.emittedByKey.set(ev.stepKey, acc);
|
|
@@ -4434,7 +4609,7 @@ var EventMapper = class {
|
|
|
4434
4609
|
const prev = this.emittedByKey.get(ev.stepKey) ?? "";
|
|
4435
4610
|
const deltaText = suffixDelta(prev, ev.text);
|
|
4436
4611
|
this.emittedByKey.set(ev.stepKey, ev.text);
|
|
4437
|
-
const banner = prev === "" ? "[agy subagent] " : "";
|
|
4612
|
+
const banner = prev === "" && !ev.text.startsWith("[") ? "[agy subagent] " : "";
|
|
4438
4613
|
const d = this.appendDelta(banner + deltaText);
|
|
4439
4614
|
if (d) yield d;
|
|
4440
4615
|
}
|
|
@@ -4478,9 +4653,10 @@ var EventMapper = class {
|
|
|
4478
4653
|
}
|
|
4479
4654
|
if (!ev.ok) {
|
|
4480
4655
|
if (ev.response === "") return;
|
|
4656
|
+
const respText = normalizeFileLinks(ev.response);
|
|
4481
4657
|
if (!this.sawTextStep) {
|
|
4482
4658
|
yield* this.ensureBlock("text");
|
|
4483
|
-
const d = this.appendDelta(
|
|
4659
|
+
const d = this.appendDelta(respText);
|
|
4484
4660
|
if (d) yield d;
|
|
4485
4661
|
}
|
|
4486
4662
|
if (ev.error !== void 0 && ev.error !== "") {
|
|
@@ -4490,7 +4666,7 @@ var EventMapper = class {
|
|
|
4490
4666
|
}
|
|
4491
4667
|
} else if (!this.sawTextStep && ev.response !== "") {
|
|
4492
4668
|
yield* this.ensureBlock("text");
|
|
4493
|
-
const d = this.appendDelta(ev.response);
|
|
4669
|
+
const d = this.appendDelta(normalizeFileLinks(ev.response));
|
|
4494
4670
|
if (d) yield d;
|
|
4495
4671
|
}
|
|
4496
4672
|
yield* this.flushBannerOnlyThoughts();
|
|
@@ -4609,6 +4785,21 @@ function findConversationDb(conversationId, accountHome) {
|
|
|
4609
4785
|
}
|
|
4610
4786
|
return null;
|
|
4611
4787
|
}
|
|
4788
|
+
/** Candidate brain directories for a conversation id across system + pool homes. */
|
|
4789
|
+
function brainDirCandidates(accountHome) {
|
|
4790
|
+
return conversationsDirCandidates(accountHome).map((d) => join(d, "..", "brain"));
|
|
4791
|
+
}
|
|
4792
|
+
/** Locate an existing conversation brain directory across system + pool homes. */
|
|
4793
|
+
function findBrainDir(conversationId, accountHome) {
|
|
4794
|
+
if (!isSafeConversationId(conversationId)) return null;
|
|
4795
|
+
for (const dir of brainDirCandidates(accountHome)) {
|
|
4796
|
+
const p = join(dir, conversationId);
|
|
4797
|
+
try {
|
|
4798
|
+
if (existsSync(p)) return p;
|
|
4799
|
+
} catch {}
|
|
4800
|
+
}
|
|
4801
|
+
return null;
|
|
4802
|
+
}
|
|
4612
4803
|
/** agy conversation ids are path-safe tokens; reject anything else before join(). */
|
|
4613
4804
|
const SAFE_CONVERSATION_ID = /^[A-Za-z0-9_-]{1,64}$/;
|
|
4614
4805
|
function isSafeConversationId(id) {
|
|
@@ -5524,7 +5715,7 @@ function listAvailableModels(deps) {
|
|
|
5524
5715
|
let models;
|
|
5525
5716
|
if (activeAcc && pool) {
|
|
5526
5717
|
models = deps.catalog.getModelsForAccount(activeAcc, pool);
|
|
5527
|
-
if (!deps.catalog.hasAccountCatalog(activeAcc.id)) deps.catalog.
|
|
5718
|
+
if (!deps.catalog.hasAccountCatalog(activeAcc.id)) deps.catalog.ensureAccountCatalog(activeAcc.id).catch(() => void 0);
|
|
5528
5719
|
} else models = deps.catalog.getUnion(accounts, pool);
|
|
5529
5720
|
const { entries, dropped } = sanitizeCatalogEntries(models);
|
|
5530
5721
|
if (dropped.length > 0) deps.warnOnce("catalog-dupes", "model catalog contained duplicate ids [" + dropped.join(", ") + "] — kept first occurrence so DSH does not drop the whole provider group (INVALID_CATALOG)");
|
|
@@ -5558,7 +5749,7 @@ function resolveModelInfo(deps, model) {
|
|
|
5558
5749
|
defaultMaxTokens: typeof cfg.maxTokensDefault === "number" && cfg.maxTokensDefault > 0 ? cfg.maxTokensDefault : 8192
|
|
5559
5750
|
};
|
|
5560
5751
|
if (deps.isEffortUnsupported(cleanId)) {} else if (entry && Array.isArray(entry.efforts) && entry.efforts.length > 0) {
|
|
5561
|
-
const cleanEfforts =
|
|
5752
|
+
const cleanEfforts = normalizeEfforts(entry.efforts);
|
|
5562
5753
|
if (cleanEfforts.length > 0) {
|
|
5563
5754
|
const def = defaultEffortFor({
|
|
5564
5755
|
...entry,
|
|
@@ -5568,7 +5759,7 @@ function resolveModelInfo(deps, model) {
|
|
|
5568
5759
|
resolved.reasoning = {
|
|
5569
5760
|
efforts: cleanEfforts.map((e) => ({
|
|
5570
5761
|
id: e,
|
|
5571
|
-
name: e
|
|
5762
|
+
name: effortLabel(e)
|
|
5572
5763
|
})),
|
|
5573
5764
|
...validDef ? { defaultEffort: validDef } : {}
|
|
5574
5765
|
};
|
|
@@ -5794,6 +5985,8 @@ function resolveConfig(entry, env = process.env, overrides = readOverrides()) {
|
|
|
5794
5985
|
translateSkipSameModel: asBool(get("translateSkipSameModel")) ?? base.translateSkipSameModel,
|
|
5795
5986
|
translateBindConversation: asBool(get("translateBindConversation")) ?? base.translateBindConversation,
|
|
5796
5987
|
translateMinIntervalMs: asNum(get("translateMinIntervalMs")) ?? base.translateMinIntervalMs,
|
|
5988
|
+
showHeaderBadge: asBool(get("showHeaderBadge")) ?? base.showHeaderBadge,
|
|
5989
|
+
showTranslateAction: asBool(get("showTranslateAction")) ?? base.showTranslateAction,
|
|
5797
5990
|
imageModel: asString(get("imageModel")) ?? base.imageModel,
|
|
5798
5991
|
imageEffort: asString(get("imageEffort")) ?? base.imageEffort,
|
|
5799
5992
|
imageTimeoutMs: asNum(get("imageTimeoutMs")) ?? base.imageTimeoutMs,
|
|
@@ -5898,6 +6091,14 @@ function resolveConfig(entry, env = process.env, overrides = readOverrides()) {
|
|
|
5898
6091
|
if (env.DSH_AGY_TRANSLATE_MODEL) cfg.translateModel = env.DSH_AGY_TRANSLATE_MODEL;
|
|
5899
6092
|
if (env.DSH_AGY_TRANSLATE_EFFORT) cfg.translateEffort = env.DSH_AGY_TRANSLATE_EFFORT;
|
|
5900
6093
|
if (env.DSH_AGY_TRANSLATE_LANG) cfg.translateTargetLanguage = env.DSH_AGY_TRANSLATE_LANG;
|
|
6094
|
+
if (env.DSH_AGY_SHOW_HEADER_BADGE !== void 0) {
|
|
6095
|
+
const shb = asBool(env.DSH_AGY_SHOW_HEADER_BADGE);
|
|
6096
|
+
if (shb !== void 0) cfg.showHeaderBadge = shb;
|
|
6097
|
+
}
|
|
6098
|
+
if (env.DSH_AGY_SHOW_TRANSLATE_ACTION !== void 0) {
|
|
6099
|
+
const sta = asBool(env.DSH_AGY_SHOW_TRANSLATE_ACTION);
|
|
6100
|
+
if (sta !== void 0) cfg.showTranslateAction = sta;
|
|
6101
|
+
}
|
|
5901
6102
|
if (env.DSH_AGY_IMAGE_MODEL) cfg.imageModel = env.DSH_AGY_IMAGE_MODEL;
|
|
5902
6103
|
if (env.DSH_AGY_IMAGE_EFFORT) cfg.imageEffort = env.DSH_AGY_IMAGE_EFFORT;
|
|
5903
6104
|
if (env.DSH_AGY_IMAGE_TIMEOUT_MS) {
|
|
@@ -6601,9 +6802,9 @@ function crossFamilyFallback(deps, family) {
|
|
|
6601
6802
|
const pool = deps.pool;
|
|
6602
6803
|
if (pool === void 0) return null;
|
|
6603
6804
|
const familyModel = {
|
|
6604
|
-
google:
|
|
6605
|
-
anthropic:
|
|
6606
|
-
openai:
|
|
6805
|
+
google: PREFERRED_GEMINI_FLASH,
|
|
6806
|
+
anthropic: PREFERRED_CLAUDE,
|
|
6807
|
+
openai: PREFERRED_OPENAI
|
|
6607
6808
|
};
|
|
6608
6809
|
for (const fbFam of [
|
|
6609
6810
|
"google",
|
|
@@ -7131,14 +7332,15 @@ function writeJsonAtomic(file, body) {
|
|
|
7131
7332
|
} catch {}
|
|
7132
7333
|
throw lastErr;
|
|
7133
7334
|
}
|
|
7134
|
-
function defaultPoolDir(home
|
|
7135
|
-
if (process.env.DSH_STATE_DIR) return join(process.env.DSH_STATE_DIR, "agy-accounts");
|
|
7136
|
-
const
|
|
7335
|
+
function defaultPoolDir(home) {
|
|
7336
|
+
if (home === void 0 && process.env.DSH_STATE_DIR) return join(process.env.DSH_STATE_DIR, "agy-accounts");
|
|
7337
|
+
const effectiveHome = home ?? homedir();
|
|
7338
|
+
const idx = effectiveHome.replace(/\\/g, "/").indexOf("/.dsh/agy-accounts/");
|
|
7137
7339
|
if (idx !== -1) {
|
|
7138
|
-
const realHome =
|
|
7340
|
+
const realHome = effectiveHome.slice(0, idx);
|
|
7139
7341
|
return join(realHome, ".dsh", "agy-accounts");
|
|
7140
7342
|
}
|
|
7141
|
-
return join(
|
|
7343
|
+
return join(effectiveHome, ".dsh", "agy-accounts");
|
|
7142
7344
|
}
|
|
7143
7345
|
/**
|
|
7144
7346
|
* True when a family's cached quota snapshot benches the account.
|
|
@@ -33075,6 +33277,263 @@ async function acquireCredentialSlot(account, pool, options = {}) {
|
|
|
33075
33277
|
});
|
|
33076
33278
|
}
|
|
33077
33279
|
//#endregion
|
|
33280
|
+
//#region src/features/subagent/tracker.ts
|
|
33281
|
+
/**
|
|
33282
|
+
* Swallow the failures a live transcript produces by design — a row still being
|
|
33283
|
+
* written, a file replaced under us — and surface anything else, so a plain code
|
|
33284
|
+
* bug cannot hide behind an empty `catch`.
|
|
33285
|
+
*/
|
|
33286
|
+
function noteFailure(log, what, err) {
|
|
33287
|
+
if (err instanceof SyntaxError) return;
|
|
33288
|
+
const code = err?.code;
|
|
33289
|
+
if (code === "ENOENT" || code === "EACCES" || code === "EPERM" || code === "EBUSY") return;
|
|
33290
|
+
log?.(`subagent tracker: ${what} — ${String(err)}`);
|
|
33291
|
+
}
|
|
33292
|
+
function stripQuotes(s) {
|
|
33293
|
+
if (s.startsWith("\"") && s.endsWith("\"") || s.startsWith("'") && s.endsWith("'")) return s.slice(1, -1);
|
|
33294
|
+
return s;
|
|
33295
|
+
}
|
|
33296
|
+
function parseJsonObj(v) {
|
|
33297
|
+
if (!v) return {};
|
|
33298
|
+
if (typeof v === "object" && !Array.isArray(v)) return v;
|
|
33299
|
+
if (typeof v === "string") try {
|
|
33300
|
+
const p = JSON.parse(v);
|
|
33301
|
+
if (p && typeof p === "object" && !Array.isArray(p)) return p;
|
|
33302
|
+
} catch {}
|
|
33303
|
+
return {};
|
|
33304
|
+
}
|
|
33305
|
+
function stringArg(obj, ...keys) {
|
|
33306
|
+
for (const k of keys) {
|
|
33307
|
+
const v = obj[k];
|
|
33308
|
+
if (typeof v === "string" && v !== "") return stripQuotes(v);
|
|
33309
|
+
}
|
|
33310
|
+
return "";
|
|
33311
|
+
}
|
|
33312
|
+
function formatSubagentAction(role, tool, rawArgs) {
|
|
33313
|
+
const args = parseJsonObj(rawArgs);
|
|
33314
|
+
const prefix = `[子代理 · ${role}]`;
|
|
33315
|
+
switch (tool) {
|
|
33316
|
+
case "view_file":
|
|
33317
|
+
case "read_file": {
|
|
33318
|
+
const p = stringArg(args, "Path", "path", "TargetFile", "target_file", "AbsolutePath", "targetFile");
|
|
33319
|
+
return `${prefix} 正在查阅文件: ${(p ? basename(p.replace(/\\/g, "/")) : "") || p || "file"}`;
|
|
33320
|
+
}
|
|
33321
|
+
case "edit_file":
|
|
33322
|
+
case "replace_file_content":
|
|
33323
|
+
case "write_file":
|
|
33324
|
+
case "create_file": {
|
|
33325
|
+
const p = stringArg(args, "Path", "path", "TargetFile", "target_file", "AbsolutePath");
|
|
33326
|
+
return `${prefix} 正在修改/创建文件: ${(p ? basename(p.replace(/\\/g, "/")) : "") || p || "file"}`;
|
|
33327
|
+
}
|
|
33328
|
+
case "search_web":
|
|
33329
|
+
case "web_search": return `${prefix} 正在检索网络: "${stringArg(args, "query", "Query", "q").slice(0, 80)}"`;
|
|
33330
|
+
case "grep_search":
|
|
33331
|
+
case "find_by_name": return `${prefix} 正在检索代码: "${stringArg(args, "pattern", "Pattern", "query", "Query", "filename", "Target").slice(0, 60)}"`;
|
|
33332
|
+
case "list_dir":
|
|
33333
|
+
case "ls": return `${prefix} 正在浏览目录: ${stringArg(args, "Path", "path", "Directory", "dir") || "."}`;
|
|
33334
|
+
case "run_command":
|
|
33335
|
+
case "bash":
|
|
33336
|
+
case "execute_command": {
|
|
33337
|
+
const summary = stringArg(args, "toolSummary", "description", "Description");
|
|
33338
|
+
const cmd = stringArg(args, "CommandLine", "command_line", "command", "cmd");
|
|
33339
|
+
return `${prefix} 正在执行终端命令: ${summary || cmd.slice(0, 70)}`;
|
|
33340
|
+
}
|
|
33341
|
+
case "generate_image": return `${prefix} 正在生成参考图像: ${stringArg(args, "prompt", "Prompt", "image_name").slice(0, 60)}`;
|
|
33342
|
+
case "send_message": return `${prefix} 阶段调研完成,正在向主代理提交报告`;
|
|
33343
|
+
case "invoke_subagent": return `${prefix} 启动协同专员: ${stringArg(args, "Role", "role", "TypeName", "typeName") || "subagent"}`;
|
|
33344
|
+
case "manage_subagents": return `${prefix} 正在协调子代理状态 (${stringArg(args, "Action", "action") || "status"})`;
|
|
33345
|
+
case "schedule": return `${prefix} 设置后台定时任务`;
|
|
33346
|
+
default: return `${prefix} 执行操作: ${tool}`;
|
|
33347
|
+
}
|
|
33348
|
+
}
|
|
33349
|
+
var SubagentTracker = class {
|
|
33350
|
+
opts;
|
|
33351
|
+
conversationId;
|
|
33352
|
+
accountHome;
|
|
33353
|
+
brainDir = null;
|
|
33354
|
+
trackedSubagents = /* @__PURE__ */ new Map();
|
|
33355
|
+
seenStepKeys = /* @__PURE__ */ new Set();
|
|
33356
|
+
timer = null;
|
|
33357
|
+
active = false;
|
|
33358
|
+
polling = false;
|
|
33359
|
+
pollIntervalMs;
|
|
33360
|
+
constructor(opts) {
|
|
33361
|
+
this.opts = opts;
|
|
33362
|
+
this.conversationId = opts.conversationId ?? "";
|
|
33363
|
+
this.accountHome = opts.accountHome;
|
|
33364
|
+
this.pollIntervalMs = opts.pollIntervalMs ?? 500;
|
|
33365
|
+
}
|
|
33366
|
+
/** Follow the conversation agy reported in its stream-json init/result envelope. */
|
|
33367
|
+
setConversationId(cid) {
|
|
33368
|
+
if (cid === "" || cid === this.conversationId) return;
|
|
33369
|
+
this.conversationId = cid;
|
|
33370
|
+
this.brainDir = null;
|
|
33371
|
+
if (this.active) this.poll();
|
|
33372
|
+
}
|
|
33373
|
+
start() {
|
|
33374
|
+
if (this.active) return;
|
|
33375
|
+
this.active = true;
|
|
33376
|
+
this.poll();
|
|
33377
|
+
this.timer = setInterval(() => this.poll(), this.pollIntervalMs);
|
|
33378
|
+
this.timer.unref?.();
|
|
33379
|
+
}
|
|
33380
|
+
stop() {
|
|
33381
|
+
this.active = false;
|
|
33382
|
+
if (this.timer) {
|
|
33383
|
+
clearInterval(this.timer);
|
|
33384
|
+
this.timer = null;
|
|
33385
|
+
}
|
|
33386
|
+
}
|
|
33387
|
+
/** Run one scan across known conversations and subagents. */
|
|
33388
|
+
poll() {
|
|
33389
|
+
if (this.polling || !this.active) return;
|
|
33390
|
+
if (!this.conversationId) return;
|
|
33391
|
+
this.polling = true;
|
|
33392
|
+
try {
|
|
33393
|
+
if (!this.brainDir) this.brainDir = findBrainDir(this.conversationId, this.accountHome);
|
|
33394
|
+
if (!this.brainDir) return;
|
|
33395
|
+
const convsToScan = [this.conversationId, ...Array.from(this.trackedSubagents.keys())];
|
|
33396
|
+
for (const cid of convsToScan) this.scanSubagentsForConv(cid);
|
|
33397
|
+
for (const sub of this.trackedSubagents.values()) this.pollSubagentTranscript(sub);
|
|
33398
|
+
} catch (err) {
|
|
33399
|
+
noteFailure(this.opts.log, "poll", err);
|
|
33400
|
+
} finally {
|
|
33401
|
+
this.polling = false;
|
|
33402
|
+
}
|
|
33403
|
+
}
|
|
33404
|
+
scanSubagentsForConv(cid) {
|
|
33405
|
+
const bDir = cid === this.conversationId ? this.brainDir : findBrainDir(cid, this.accountHome);
|
|
33406
|
+
if (!bDir) return;
|
|
33407
|
+
const subagentsDir = join(bDir, ".system_generated", "subagents");
|
|
33408
|
+
if (!existsSync(subagentsDir)) return;
|
|
33409
|
+
let files;
|
|
33410
|
+
try {
|
|
33411
|
+
files = readdirSync(subagentsDir);
|
|
33412
|
+
} catch {
|
|
33413
|
+
return;
|
|
33414
|
+
}
|
|
33415
|
+
for (const f of files) {
|
|
33416
|
+
if (!f.endsWith(".json")) continue;
|
|
33417
|
+
const fullPath = join(subagentsDir, f);
|
|
33418
|
+
try {
|
|
33419
|
+
const raw = readFileSync(fullPath, "utf8");
|
|
33420
|
+
const obj = JSON.parse(raw);
|
|
33421
|
+
const subId = typeof obj?.conversationId === "string" ? obj.conversationId : f.replace(/\.json$/, "");
|
|
33422
|
+
if (!subId || this.trackedSubagents.has(subId)) continue;
|
|
33423
|
+
const desc = obj?.subagentDescriptor;
|
|
33424
|
+
const role = typeof desc?.role === "string" && desc.role !== "" ? desc.role : "专员";
|
|
33425
|
+
const typeName = typeof desc?.typeName === "string" && desc.typeName !== "" ? desc.typeName : "Subagent";
|
|
33426
|
+
const tracked = {
|
|
33427
|
+
conversationId: subId,
|
|
33428
|
+
role,
|
|
33429
|
+
typeName,
|
|
33430
|
+
brainDir: findBrainDir(subId, this.accountHome) ?? join(bDir, "..", subId),
|
|
33431
|
+
offset: 0,
|
|
33432
|
+
rest: "",
|
|
33433
|
+
lines: 0
|
|
33434
|
+
};
|
|
33435
|
+
this.trackedSubagents.set(subId, tracked);
|
|
33436
|
+
const spawnKey = `subagent-spawn-${subId}`;
|
|
33437
|
+
if (!this.seenStepKeys.has(spawnKey)) {
|
|
33438
|
+
this.seenStepKeys.add(spawnKey);
|
|
33439
|
+
const ev = {
|
|
33440
|
+
kind: "step",
|
|
33441
|
+
stepKey: spawnKey,
|
|
33442
|
+
stepKind: "subagent",
|
|
33443
|
+
text: `[子代理 · ${role}] 已启动协同专员 (${typeName})\n`,
|
|
33444
|
+
raw: obj
|
|
33445
|
+
};
|
|
33446
|
+
this.opts.onEvent(ev);
|
|
33447
|
+
this.opts.noteActivity?.();
|
|
33448
|
+
}
|
|
33449
|
+
} catch (err) {
|
|
33450
|
+
noteFailure(this.opts.log, `descriptor ${f}`, err);
|
|
33451
|
+
}
|
|
33452
|
+
}
|
|
33453
|
+
}
|
|
33454
|
+
/**
|
|
33455
|
+
* Read the transcript lines appended since the last poll.
|
|
33456
|
+
*
|
|
33457
|
+
* agy rewrites nothing and only appends, so the tracker keeps a byte offset
|
|
33458
|
+
* instead of re-reading (and re-splitting) a transcript that grows to hundreds
|
|
33459
|
+
* of kilobytes: each poll costs one bounded read of the new bytes.
|
|
33460
|
+
*/
|
|
33461
|
+
readNewLines(sub) {
|
|
33462
|
+
const logPath = join(sub.brainDir, ".system_generated", "logs", "transcript.jsonl");
|
|
33463
|
+
let size;
|
|
33464
|
+
try {
|
|
33465
|
+
const st = statSync(logPath);
|
|
33466
|
+
if (!st.isFile()) return [];
|
|
33467
|
+
size = st.size;
|
|
33468
|
+
} catch {
|
|
33469
|
+
return [];
|
|
33470
|
+
}
|
|
33471
|
+
if (size < sub.offset) {
|
|
33472
|
+
sub.offset = 0;
|
|
33473
|
+
sub.rest = "";
|
|
33474
|
+
}
|
|
33475
|
+
if (size === sub.offset) return [];
|
|
33476
|
+
const length = size - sub.offset;
|
|
33477
|
+
const buffer = Buffer.allocUnsafe(length);
|
|
33478
|
+
try {
|
|
33479
|
+
const fd = openSync(logPath, "r");
|
|
33480
|
+
try {
|
|
33481
|
+
readSync(fd, buffer, 0, length, sub.offset);
|
|
33482
|
+
} finally {
|
|
33483
|
+
closeSync(fd);
|
|
33484
|
+
}
|
|
33485
|
+
} catch {
|
|
33486
|
+
return [];
|
|
33487
|
+
}
|
|
33488
|
+
sub.offset = size;
|
|
33489
|
+
const parts = (sub.rest + buffer.toString("utf8")).split("\n");
|
|
33490
|
+
sub.rest = parts.pop() ?? "";
|
|
33491
|
+
return parts.filter((line) => line.trim() !== "");
|
|
33492
|
+
}
|
|
33493
|
+
pollSubagentTranscript(sub) {
|
|
33494
|
+
for (const line of this.readNewLines(sub)) try {
|
|
33495
|
+
const o = JSON.parse(line);
|
|
33496
|
+
sub.lines += 1;
|
|
33497
|
+
const stepIdx = typeof o.step_index === "number" ? o.step_index : sub.lines;
|
|
33498
|
+
const baseKey = `subagent-${sub.conversationId}-${stepIdx}`;
|
|
33499
|
+
if (Array.isArray(o.tool_calls) && o.tool_calls.length > 0) for (let tcIdx = 0; tcIdx < o.tool_calls.length; tcIdx++) {
|
|
33500
|
+
const tc = o.tool_calls[tcIdx];
|
|
33501
|
+
const toolName = typeof tc?.name === "string" ? tc.name : "";
|
|
33502
|
+
if (toolName === "") continue;
|
|
33503
|
+
const k = `${baseKey}-tc-${tcIdx}`;
|
|
33504
|
+
if (this.seenStepKeys.has(k)) continue;
|
|
33505
|
+
this.seenStepKeys.add(k);
|
|
33506
|
+
const ev = {
|
|
33507
|
+
kind: "step",
|
|
33508
|
+
stepKey: k,
|
|
33509
|
+
stepKind: "subagent",
|
|
33510
|
+
text: `${formatSubagentAction(sub.role, toolName, tc.args)}\n`,
|
|
33511
|
+
raw: o
|
|
33512
|
+
};
|
|
33513
|
+
this.opts.onEvent(ev);
|
|
33514
|
+
this.opts.noteActivity?.();
|
|
33515
|
+
}
|
|
33516
|
+
else if (o.type === "PLANNER_RESPONSE" && typeof o.content === "string" && o.content.trim() !== "") {
|
|
33517
|
+
const k = `${baseKey}-content`;
|
|
33518
|
+
if (this.seenStepKeys.has(k)) continue;
|
|
33519
|
+
this.seenStepKeys.add(k);
|
|
33520
|
+
const firstLine = o.content.trim().split("\n")[0].replace(/^#+\s*/, "").slice(0, 100);
|
|
33521
|
+
if (firstLine !== "") {
|
|
33522
|
+
const ev = {
|
|
33523
|
+
kind: "step",
|
|
33524
|
+
stepKey: k,
|
|
33525
|
+
stepKind: "subagent",
|
|
33526
|
+
text: `[子代理 · ${sub.role}] 阶段进展: ${firstLine}\n`,
|
|
33527
|
+
raw: o
|
|
33528
|
+
};
|
|
33529
|
+
this.opts.onEvent(ev);
|
|
33530
|
+
this.opts.noteActivity?.();
|
|
33531
|
+
}
|
|
33532
|
+
}
|
|
33533
|
+
} catch {}
|
|
33534
|
+
}
|
|
33535
|
+
};
|
|
33536
|
+
//#endregion
|
|
33078
33537
|
//#region src/provider/attempt.ts
|
|
33079
33538
|
function brief$1(s) {
|
|
33080
33539
|
const flat = s.trim().replace(/\s+/g, " ");
|
|
@@ -33215,7 +33674,7 @@ function createToolWatchdog(log, cfg) {
|
|
|
33215
33674
|
};
|
|
33216
33675
|
}
|
|
33217
33676
|
/** Create the recording, parser, HOME snapshot and tool watchdog for one run. */
|
|
33218
|
-
function createAttemptRecorder(deps, cfg, account) {
|
|
33677
|
+
function createAttemptRecorder(deps, cfg, account, initialConversationId) {
|
|
33219
33678
|
const rec = deps.runs.create();
|
|
33220
33679
|
rec.accountHome = account && account.dir ? account.dir : void 0;
|
|
33221
33680
|
const conversationsDir = conversationsDirFor(rec.accountHome);
|
|
@@ -33223,20 +33682,41 @@ function createAttemptRecorder(deps, cfg, account) {
|
|
|
33223
33682
|
const parser = new StreamJsonParser();
|
|
33224
33683
|
deps.onParser?.(parser);
|
|
33225
33684
|
const watchdog = createToolWatchdog(deps.log, cfg);
|
|
33685
|
+
const tracker = new SubagentTracker({
|
|
33686
|
+
conversationId: initialConversationId,
|
|
33687
|
+
accountHome: rec.accountHome,
|
|
33688
|
+
log: deps.log,
|
|
33689
|
+
onEvent: (ev) => {
|
|
33690
|
+
rec.append(ev);
|
|
33691
|
+
},
|
|
33692
|
+
noteActivity: () => {
|
|
33693
|
+
watchdog.markEvent();
|
|
33694
|
+
}
|
|
33695
|
+
});
|
|
33226
33696
|
const state = {
|
|
33227
33697
|
rec,
|
|
33228
33698
|
parser,
|
|
33229
33699
|
conversationsDir,
|
|
33230
33700
|
before,
|
|
33231
|
-
streamCid: null,
|
|
33701
|
+
streamCid: initialConversationId ?? null,
|
|
33232
33702
|
printTimeoutMinutes: watchdog.printTimeoutMinutes,
|
|
33233
|
-
attachProcess: (proc) =>
|
|
33703
|
+
attachProcess: (proc) => {
|
|
33704
|
+
watchdog.attach(proc);
|
|
33705
|
+
tracker.start();
|
|
33706
|
+
proc.outcome.finally(() => tracker.stop());
|
|
33707
|
+
},
|
|
33234
33708
|
feedLine: (line, onEvent, onFirstEvent) => {
|
|
33235
33709
|
watchdog.markEvent();
|
|
33236
33710
|
onFirstEvent?.();
|
|
33237
33711
|
for (const ev of parser.feed(line + "\n")) {
|
|
33238
|
-
if (ev.kind === "init" && ev.conversationId)
|
|
33239
|
-
|
|
33712
|
+
if (ev.kind === "init" && ev.conversationId) {
|
|
33713
|
+
state.streamCid = ev.conversationId;
|
|
33714
|
+
tracker.setConversationId(ev.conversationId);
|
|
33715
|
+
}
|
|
33716
|
+
if (ev.kind === "result" && ev.conversationId !== "") {
|
|
33717
|
+
state.streamCid = ev.conversationId;
|
|
33718
|
+
tracker.setConversationId(ev.conversationId);
|
|
33719
|
+
}
|
|
33240
33720
|
watchdog.trackStep(ev);
|
|
33241
33721
|
rec.append(ev);
|
|
33242
33722
|
if (typeof onEvent === "function") try {
|
|
@@ -33246,14 +33726,20 @@ function createAttemptRecorder(deps, cfg, account) {
|
|
|
33246
33726
|
},
|
|
33247
33727
|
drain: (onEvent) => {
|
|
33248
33728
|
for (const ev of parser.flush()) {
|
|
33249
|
-
if (ev.kind === "result" && ev.conversationId !== "")
|
|
33729
|
+
if (ev.kind === "result" && ev.conversationId !== "") {
|
|
33730
|
+
state.streamCid = ev.conversationId;
|
|
33731
|
+
tracker.setConversationId(ev.conversationId);
|
|
33732
|
+
}
|
|
33250
33733
|
rec.append(ev);
|
|
33251
33734
|
if (typeof onEvent === "function") try {
|
|
33252
33735
|
onEvent(ev);
|
|
33253
33736
|
} catch {}
|
|
33254
33737
|
}
|
|
33255
33738
|
},
|
|
33256
|
-
stop: () =>
|
|
33739
|
+
stop: () => {
|
|
33740
|
+
watchdog.stop();
|
|
33741
|
+
tracker.stop();
|
|
33742
|
+
},
|
|
33257
33743
|
conversationId: () => state.streamCid ?? diffConversations(before, conversationsDir).conversationId
|
|
33258
33744
|
};
|
|
33259
33745
|
return state;
|
|
@@ -33806,7 +34292,7 @@ async function handleAttemptOutcome(deps, input, ctx) {
|
|
|
33806
34292
|
* queue notices; the outcome closure runs detached exactly as before.
|
|
33807
34293
|
*/
|
|
33808
34294
|
async function* runAgyAttempt(deps, input) {
|
|
33809
|
-
const recorder = createAttemptRecorder(deps, input.cfg, input.account);
|
|
34295
|
+
const recorder = createAttemptRecorder(deps, input.cfg, input.account, input.binding?.conversationId);
|
|
33810
34296
|
const spawn = buildSpawnArgs(input, recorder.printTimeoutMinutes, deps.log);
|
|
33811
34297
|
const slot = yield* dispatchCredentialSlot(deps, {
|
|
33812
34298
|
...input,
|
|
@@ -34255,26 +34741,38 @@ const ALIASES = {
|
|
|
34255
34741
|
"gpt-oss": "gpt-oss",
|
|
34256
34742
|
oss: "gpt-oss"
|
|
34257
34743
|
};
|
|
34744
|
+
/**
|
|
34745
|
+
* Split a model word into (base, effort): `"gemini-3.8-flash high"`,
|
|
34746
|
+
* `"gemini-high"` and `"hydrogen extra"` all carry a level. The effort list is
|
|
34747
|
+
* the canonical one (common/reasoning.ts), longest suffix first, so `xhigh`
|
|
34748
|
+
* is never read as `high`.
|
|
34749
|
+
*/
|
|
34750
|
+
function splitAskQuery(input) {
|
|
34751
|
+
const q = input.trim().toLowerCase();
|
|
34752
|
+
const prefix = ALIASES[q] ?? q.replace(/\s+/g, "-");
|
|
34753
|
+
for (const eff of EFFORT_SUFFIXES) if (q.endsWith(" " + eff) || q.endsWith("-" + eff)) return {
|
|
34754
|
+
base: prefix.slice(0, -(eff.length + 1)),
|
|
34755
|
+
effort: eff
|
|
34756
|
+
};
|
|
34757
|
+
return { base: prefix };
|
|
34758
|
+
}
|
|
34759
|
+
/** The effort a model word asks for, if any (`"hydrogen extra"` → `xhigh`). */
|
|
34760
|
+
function resolveAskEffort(input) {
|
|
34761
|
+
const q = input.trim();
|
|
34762
|
+
if (q === "") return void 0;
|
|
34763
|
+
return splitAskQuery(q).effort;
|
|
34764
|
+
}
|
|
34258
34765
|
/** Resolve a user-facing model word against the live catalog. */
|
|
34259
34766
|
function resolveAskModel(input, catalog, defaultModel) {
|
|
34260
34767
|
const q = input.trim().toLowerCase();
|
|
34261
34768
|
if (q === "") return defaultModel;
|
|
34262
34769
|
const ids = catalog.models.map((m) => m.id);
|
|
34263
34770
|
if (ids.includes(q)) return q;
|
|
34264
|
-
const
|
|
34265
|
-
let level = "";
|
|
34266
|
-
for (const eff of [
|
|
34267
|
-
"high",
|
|
34268
|
-
"medium",
|
|
34269
|
-
"low"
|
|
34270
|
-
]) if (q.endsWith(" " + eff) || q.endsWith("-" + eff)) level = eff;
|
|
34271
|
-
const base = level !== "" ? prefix.replace(/-?(high|medium|low)$/, "") : prefix;
|
|
34771
|
+
const { base } = splitAskQuery(q);
|
|
34272
34772
|
const candidates = ids.filter((id) => id.startsWith(base));
|
|
34273
34773
|
if (candidates.length === 0) return defaultModel !== "" ? defaultModel : q;
|
|
34274
34774
|
const sorted = candidates.slice().sort(compareNatural$1);
|
|
34275
|
-
|
|
34276
|
-
if (level === "") return last;
|
|
34277
|
-
return sorted.find((id) => id.endsWith("-" + level)) ?? last;
|
|
34775
|
+
return sorted[sorted.length - 1] ?? q;
|
|
34278
34776
|
}
|
|
34279
34777
|
function compareNatural$1(a, b) {
|
|
34280
34778
|
const na = a.split(/(\d+)/);
|
|
@@ -34290,7 +34788,22 @@ function compareNatural$1(a, b) {
|
|
|
34290
34788
|
}
|
|
34291
34789
|
return 0;
|
|
34292
34790
|
}
|
|
34791
|
+
/**
|
|
34792
|
+
* The `model` parameter's help text, built from the LIVE catalog: the model list
|
|
34793
|
+
* and the effort list are never retyped here (a hardcoded "flash, pro, gemini,
|
|
34794
|
+
* sonnet, opus" line is the same drift that put models in the picker agy does
|
|
34795
|
+
* not have). Family words still work through ALIASES.
|
|
34796
|
+
*/
|
|
34797
|
+
function askModelHelp(catalog) {
|
|
34798
|
+
const ids = catalog.models.map((m) => m.id);
|
|
34799
|
+
return "Model to ask: " + (ids.length > 0 ? ids.join(", ") : "any agy model id") + ", a family word (" + Object.keys(ALIASES).join(", ") + "), or an exact slug (default: the bridge default model).";
|
|
34800
|
+
}
|
|
34801
|
+
/** The `effort` parameter's help text, from the canonical effort vocabulary. */
|
|
34802
|
+
function askEffortHelp() {
|
|
34803
|
+
return "Reasoning effort for effort-capable models: " + REASONING_EFFORTS.join(", ") + ".";
|
|
34804
|
+
}
|
|
34293
34805
|
function defineAgyAskTool(deps) {
|
|
34806
|
+
const catalogNow = deps.catalog();
|
|
34294
34807
|
return defineTool({
|
|
34295
34808
|
name: "agy_ask",
|
|
34296
34809
|
description: "Delegate a one-shot task to a Google Antigravity model via the agy CLI (e.g. ask Gemini for a review while keeping the current model). Returns the final answer text.",
|
|
@@ -34302,11 +34815,11 @@ function defineAgyAskTool(deps) {
|
|
|
34302
34815
|
},
|
|
34303
34816
|
model: {
|
|
34304
34817
|
type: "string",
|
|
34305
|
-
description:
|
|
34818
|
+
description: askModelHelp(catalogNow)
|
|
34306
34819
|
},
|
|
34307
34820
|
effort: {
|
|
34308
34821
|
type: "string",
|
|
34309
|
-
description:
|
|
34822
|
+
description: askEffortHelp()
|
|
34310
34823
|
},
|
|
34311
34824
|
mode: {
|
|
34312
34825
|
type: "string",
|
|
@@ -34345,7 +34858,8 @@ function defineAgyAskTool(deps) {
|
|
|
34345
34858
|
}
|
|
34346
34859
|
const readPaths = typeof args.readPaths === "string" && args.readPaths.trim() !== "" ? args.readPaths.split(/[ ,]+/).filter(Boolean) : [];
|
|
34347
34860
|
const entry = findEntry(deps.catalog(), model);
|
|
34348
|
-
const
|
|
34861
|
+
const askedEffort = resolveAskEffort(args.model ?? "");
|
|
34862
|
+
const wanted = args.effort ?? askedEffort ?? (entry?.efforts ? defaultEffortFor(entry, cfg) : void 0);
|
|
34349
34863
|
const learned = deps.effortUnsupported?.() ?? [];
|
|
34350
34864
|
const refusedBefore = wanted !== void 0 && learned.some((m) => m !== "" && (m === model || m === entry?.id));
|
|
34351
34865
|
const call = (effort) => runAgyOnce(deps, {
|
|
@@ -35570,6 +36084,43 @@ function writeMcpConfig(file, bridge) {
|
|
|
35570
36084
|
}
|
|
35571
36085
|
//#endregion
|
|
35572
36086
|
//#region src/host/boot-hygiene.ts
|
|
36087
|
+
/**
|
|
36088
|
+
* On macOS, agy uses go-keyring which stores OAuth credentials inside the
|
|
36089
|
+
* account's isolated keychain (acc.dir/Library/Keychains/login.keychain-db) rather
|
|
36090
|
+
* than writing a file to ~/.gemini/antigravity-cli/antigravity-oauth-token.
|
|
36091
|
+
* When the disk token file is absent, recover it from the keychain so the account
|
|
36092
|
+
* is not falsely quarantined as auth_required.
|
|
36093
|
+
*/
|
|
36094
|
+
function restoreTokenFromMacKeychain(accDir, tokenFile, log) {
|
|
36095
|
+
if (process.platform !== "darwin") return null;
|
|
36096
|
+
const targetKc = [join(accDir, "Library", "Keychains", "login.keychain-db"), join(accDir, "Library", "Keychains", "login.keychain")].find((p) => existsSync(p));
|
|
36097
|
+
if (!targetKc) return null;
|
|
36098
|
+
try {
|
|
36099
|
+
const raw = execFileSync("security", [
|
|
36100
|
+
"find-generic-password",
|
|
36101
|
+
"-s",
|
|
36102
|
+
"gemini",
|
|
36103
|
+
"-a",
|
|
36104
|
+
"antigravity",
|
|
36105
|
+
"-w",
|
|
36106
|
+
targetKc
|
|
36107
|
+
], {
|
|
36108
|
+
encoding: "utf8",
|
|
36109
|
+
timeout: 3e3,
|
|
36110
|
+
windowsHide: true
|
|
36111
|
+
}).trim();
|
|
36112
|
+
if (!raw.startsWith("go-keyring-base64:")) return null;
|
|
36113
|
+
const jsonStr = Buffer.from(raw.slice(18), "base64").toString("utf8");
|
|
36114
|
+
if (!hasRefreshToken(jsonStr)) return null;
|
|
36115
|
+
mkdirSync(dirname(tokenFile), { recursive: true });
|
|
36116
|
+
writeFileSync(tokenFile, jsonStr, { mode: 384 });
|
|
36117
|
+
saveCredentialBackup(tokenFile, jsonStr);
|
|
36118
|
+
log?.(`[agy-link] restored account credential from macOS isolated keychain for ${accDir}`);
|
|
36119
|
+
return jsonStr;
|
|
36120
|
+
} catch {
|
|
36121
|
+
return null;
|
|
36122
|
+
}
|
|
36123
|
+
}
|
|
35573
36124
|
function runBootHygiene(services) {
|
|
35574
36125
|
const { pool, store, log, getConfig } = services;
|
|
35575
36126
|
try {
|
|
@@ -35587,7 +36138,9 @@ function runBootHygiene(services) {
|
|
|
35587
36138
|
for (const acc of pool.getAccounts()) if (acc.dir && !acc.systemHome) {
|
|
35588
36139
|
purgeStaleIsolatedKeychain(acc.dir);
|
|
35589
36140
|
if (ensureIsolatedKeychain(acc.dir)) kcProvisioned++;
|
|
35590
|
-
const
|
|
36141
|
+
const tokenFile = join(acc.dir, ".gemini", "antigravity-cli", "antigravity-oauth-token");
|
|
36142
|
+
let token = readAccountCredential(tokenFile, log);
|
|
36143
|
+
if (!token && process.platform === "darwin") token = restoreTokenFromMacKeychain(acc.dir, tokenFile, log);
|
|
35591
36144
|
if (!token && !acc.authRequired) {
|
|
35592
36145
|
pool.markAuthRequired?.(acc.id, "credential file is missing or corrupted");
|
|
35593
36146
|
log(`account ${acc.alias || acc.id} has no valid credential file; marked as auth_required`);
|
|
@@ -36236,7 +36789,7 @@ function clip(text, max) {
|
|
|
36236
36789
|
* An explicit request (command flag) is honoured even when the advisory catalog
|
|
36237
36790
|
* has never listed it — the adapter accepts unknown ids. The DEFAULT goes
|
|
36238
36791
|
* through a fallback chain so a plan without Gemini 3.8 still translates:
|
|
36239
|
-
* `
|
|
36792
|
+
* `PREFERRED_GEMINI_FLASH` → newest `gemini-*-flash` → `defaultModel` → first model.
|
|
36240
36793
|
*/
|
|
36241
36794
|
function resolveTranslateTarget(cfg, catalog, override) {
|
|
36242
36795
|
const requested = (override?.model ?? cfg.translateModel ?? "").trim();
|
|
@@ -36248,7 +36801,7 @@ function resolveTranslateTarget(cfg, catalog, override) {
|
|
|
36248
36801
|
model = resolveModelSlug(requested);
|
|
36249
36802
|
entry = findEntry(catalog, model);
|
|
36250
36803
|
} else {
|
|
36251
|
-
const candidates = [
|
|
36804
|
+
const candidates = [PREFERRED_GEMINI_FLASH];
|
|
36252
36805
|
if (cfg.defaultModel !== "") candidates.push(cfg.defaultModel);
|
|
36253
36806
|
for (const cand of candidates) {
|
|
36254
36807
|
const found = findEntry(catalog, cand);
|
|
@@ -38063,7 +38616,26 @@ async function getStoredToken(deps, account, allowKeychainFallback = true) {
|
|
|
38063
38616
|
if (keychainToken && (keychainToken.accessToken || keychainToken.refreshToken)) return keychainToken;
|
|
38064
38617
|
}
|
|
38065
38618
|
}
|
|
38066
|
-
return disk;
|
|
38619
|
+
if (disk) return disk;
|
|
38620
|
+
if (account.dir && !account.systemHome && process.platform === "darwin" && allowKeychainFallback) {
|
|
38621
|
+
const targetKc = [join(account.dir, "Library", "Keychains", "login.keychain-db"), join(account.dir, "Library", "Keychains", "login.keychain")].find((p) => existsSync(p));
|
|
38622
|
+
if (targetKc) try {
|
|
38623
|
+
const raw = (await execFileT("security", [
|
|
38624
|
+
"find-generic-password",
|
|
38625
|
+
"-s",
|
|
38626
|
+
"gemini",
|
|
38627
|
+
"-a",
|
|
38628
|
+
"antigravity",
|
|
38629
|
+
"-w",
|
|
38630
|
+
targetKc
|
|
38631
|
+
], 3e3)).trim();
|
|
38632
|
+
if (raw) {
|
|
38633
|
+
const tok = parseGoKeyringPayload(raw);
|
|
38634
|
+
if (tok && (tok.accessToken || tok.refreshToken)) return tok;
|
|
38635
|
+
}
|
|
38636
|
+
} catch {}
|
|
38637
|
+
}
|
|
38638
|
+
return null;
|
|
38067
38639
|
}
|
|
38068
38640
|
/**
|
|
38069
38641
|
* Persist a refreshed access token in agy's own on-disk shape.
|
|
@@ -39371,10 +39943,45 @@ function createHostServices(ctx, entryConfig = {}) {
|
|
|
39371
39943
|
}
|
|
39372
39944
|
//#endregion
|
|
39373
39945
|
//#region src/transport/http/respond.ts
|
|
39946
|
+
/** Every plugin HTTP response has a hard deadline (see common/timeouts.ts). */
|
|
39947
|
+
/** WeakSet: `sendJson` must be exactly-once per response, even after a timeout. */
|
|
39948
|
+
const answered = /* @__PURE__ */ new WeakSet();
|
|
39374
39949
|
const sendJson = (res, status, body) => {
|
|
39375
|
-
|
|
39376
|
-
|
|
39950
|
+
if (answered.has(res)) return;
|
|
39951
|
+
answered.add(res);
|
|
39952
|
+
try {
|
|
39953
|
+
res.writeHead(status, { "Content-Type": "application/json; charset=utf-8" });
|
|
39954
|
+
res.end(JSON.stringify(body));
|
|
39955
|
+
} catch {}
|
|
39377
39956
|
};
|
|
39957
|
+
/**
|
|
39958
|
+
* Run one async route body with a GUARANTEED single response:
|
|
39959
|
+
* - normal path: the body sends whatever it likes;
|
|
39960
|
+
* - a rejection (thrown by a dependency, or a bug): 500 with `ok:false`;
|
|
39961
|
+
* - a hung promise past `ROUTE_TIMEOUT_MS`: 504 with `ok:false`.
|
|
39962
|
+
*
|
|
39963
|
+
* `sendJson` is exactly-once, so a late body can never write a second head
|
|
39964
|
+
* (`ERR_HTTP_HEADERS_SENT`) after a timeout. Every async route uses this one
|
|
39965
|
+
* helper instead of a bare `void (async () => …)()` — there is no second
|
|
39966
|
+
* error-handling copy to drift.
|
|
39967
|
+
*/
|
|
39968
|
+
function runRoute(res, body, timeoutMs = ROUTE_TIMEOUT_MS) {
|
|
39969
|
+
const raw = res;
|
|
39970
|
+
const timer = setTimeout(() => {
|
|
39971
|
+
sendJson(raw, 504, {
|
|
39972
|
+
ok: false,
|
|
39973
|
+
error: "request timed out"
|
|
39974
|
+
});
|
|
39975
|
+
}, timeoutMs);
|
|
39976
|
+
timer.unref?.();
|
|
39977
|
+
body().catch((err) => {
|
|
39978
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
39979
|
+
sendJson(raw, 500, {
|
|
39980
|
+
ok: false,
|
|
39981
|
+
error: message
|
|
39982
|
+
});
|
|
39983
|
+
}).finally(() => clearTimeout(timer));
|
|
39984
|
+
}
|
|
39378
39985
|
const readBody = async (req, strict = false) => {
|
|
39379
39986
|
const result = await readJsonBody(req);
|
|
39380
39987
|
if (result.invalid || result.tooLarge) return strict ? { __invalidJson: true } : {};
|
|
@@ -39401,7 +40008,7 @@ const queryParam = (req, key) => {
|
|
|
39401
40008
|
function handleStatus(services, req, res) {
|
|
39402
40009
|
const { getConfig, bin, store, pool, catalog, auth, poolAuth, adapter, translation, lastRun } = services;
|
|
39403
40010
|
const { version: versionCache, dormantReason } = services.status;
|
|
39404
|
-
(async () => {
|
|
40011
|
+
runRoute(res, async () => {
|
|
39405
40012
|
const cfg = getConfig();
|
|
39406
40013
|
const cat = catalog.get();
|
|
39407
40014
|
const poolData = pool?.getPoolData ? pool.getPoolData(cfg.proxyUrl?.trim() || void 0) : void 0;
|
|
@@ -39435,6 +40042,8 @@ function handleStatus(services, req, res) {
|
|
|
39435
40042
|
translateModel: cfg.translateModel,
|
|
39436
40043
|
translateEffort: cfg.translateEffort,
|
|
39437
40044
|
translateTargetLanguage: cfg.translateTargetLanguage,
|
|
40045
|
+
showHeaderBadge: cfg.showHeaderBadge,
|
|
40046
|
+
showTranslateAction: cfg.showTranslateAction,
|
|
39438
40047
|
imageModel: cfg.imageModel,
|
|
39439
40048
|
imageEffort: cfg.imageEffort,
|
|
39440
40049
|
imageOutputDir: cfg.imageOutputDir,
|
|
@@ -39446,7 +40055,7 @@ function handleStatus(services, req, res) {
|
|
|
39446
40055
|
effortUnsupported: adapter.effortUnsupportedModels(),
|
|
39447
40056
|
lastRun
|
|
39448
40057
|
});
|
|
39449
|
-
})
|
|
40058
|
+
});
|
|
39450
40059
|
}
|
|
39451
40060
|
function register$5(reg, services) {
|
|
39452
40061
|
reg({
|
|
@@ -39463,7 +40072,7 @@ function handlePoolList(services, req, res) {
|
|
|
39463
40072
|
}
|
|
39464
40073
|
function handlePoolBeginAdd(services, req, res) {
|
|
39465
40074
|
const { getConfig, poolAuth } = services;
|
|
39466
|
-
(async () => {
|
|
40075
|
+
runRoute(res, async () => {
|
|
39467
40076
|
if (methodOf(req) !== "POST") {
|
|
39468
40077
|
sendJson(res, 405, { error: "POST only" });
|
|
39469
40078
|
return;
|
|
@@ -39473,11 +40082,11 @@ function handlePoolBeginAdd(services, req, res) {
|
|
|
39473
40082
|
const proxyUrl = typeof body.proxyUrl === "string" && body.proxyUrl.trim() !== "" ? body.proxyUrl.trim() : getConfig().proxyUrl.trim() || detectSystemProxy() || void 0;
|
|
39474
40083
|
const st = await poolAuth.begin(alias, proxyUrl);
|
|
39475
40084
|
sendJson(res, st.ok ? 200 : 500, st);
|
|
39476
|
-
})
|
|
40085
|
+
});
|
|
39477
40086
|
}
|
|
39478
40087
|
function handlePoolCompleteAdd(services, req, res) {
|
|
39479
40088
|
const { pool, poolAuth } = services;
|
|
39480
|
-
(async () => {
|
|
40089
|
+
runRoute(res, async () => {
|
|
39481
40090
|
if (methodOf(req) !== "POST") {
|
|
39482
40091
|
sendJson(res, 405, { error: "POST only" });
|
|
39483
40092
|
return;
|
|
@@ -39499,11 +40108,11 @@ function handlePoolCompleteAdd(services, req, res) {
|
|
|
39499
40108
|
code: st.code,
|
|
39500
40109
|
pool: pool.getPoolData()
|
|
39501
40110
|
});
|
|
39502
|
-
})
|
|
40111
|
+
});
|
|
39503
40112
|
}
|
|
39504
40113
|
function handlePoolCancelAdd(services, req, res) {
|
|
39505
40114
|
const { pool, poolAuth } = services;
|
|
39506
|
-
(async () => {
|
|
40115
|
+
runRoute(res, async () => {
|
|
39507
40116
|
if (methodOf(req) !== "POST") {
|
|
39508
40117
|
sendJson(res, 405, { error: "POST only" });
|
|
39509
40118
|
return;
|
|
@@ -39514,11 +40123,11 @@ function handlePoolCancelAdd(services, req, res) {
|
|
|
39514
40123
|
ok: true,
|
|
39515
40124
|
pool: pool.getPoolData()
|
|
39516
40125
|
});
|
|
39517
|
-
})
|
|
40126
|
+
});
|
|
39518
40127
|
}
|
|
39519
40128
|
function handlePoolAdd(services, req, res) {
|
|
39520
40129
|
const { getConfig, pool, bridgeState } = services;
|
|
39521
|
-
(async () => {
|
|
40130
|
+
runRoute(res, async () => {
|
|
39522
40131
|
if (methodOf(req) !== "POST") {
|
|
39523
40132
|
sendJson(res, 405, { error: "POST only" });
|
|
39524
40133
|
return;
|
|
@@ -39540,11 +40149,11 @@ function handlePoolAdd(services, req, res) {
|
|
|
39540
40149
|
account: acc,
|
|
39541
40150
|
pool: pool.getPoolData()
|
|
39542
40151
|
});
|
|
39543
|
-
})
|
|
40152
|
+
});
|
|
39544
40153
|
}
|
|
39545
40154
|
function handlePoolOpenTerminal(services, req, res) {
|
|
39546
40155
|
const { pool } = services;
|
|
39547
|
-
(async () => {
|
|
40156
|
+
runRoute(res, async () => {
|
|
39548
40157
|
if (methodOf(req) !== "POST") {
|
|
39549
40158
|
sendJson(res, 405, { error: "POST only" });
|
|
39550
40159
|
return;
|
|
@@ -39561,11 +40170,11 @@ function handlePoolOpenTerminal(services, req, res) {
|
|
|
39561
40170
|
ok: true,
|
|
39562
40171
|
dir: acc.dir
|
|
39563
40172
|
});
|
|
39564
|
-
})
|
|
40173
|
+
});
|
|
39565
40174
|
}
|
|
39566
40175
|
function handlePoolRemove(services, req, res) {
|
|
39567
40176
|
const { pool, notifyPicker } = services;
|
|
39568
|
-
(async () => {
|
|
40177
|
+
runRoute(res, async () => {
|
|
39569
40178
|
if (methodOf(req) !== "POST") {
|
|
39570
40179
|
sendJson(res, 405, { error: "POST only" });
|
|
39571
40180
|
return;
|
|
@@ -39578,11 +40187,11 @@ function handlePoolRemove(services, req, res) {
|
|
|
39578
40187
|
ok: true,
|
|
39579
40188
|
pool: pool.getPoolData()
|
|
39580
40189
|
});
|
|
39581
|
-
})
|
|
40190
|
+
});
|
|
39582
40191
|
}
|
|
39583
40192
|
function handlePoolEnable(services, req, res) {
|
|
39584
40193
|
const { pool, notifyPicker } = services;
|
|
39585
|
-
(async () => {
|
|
40194
|
+
runRoute(res, async () => {
|
|
39586
40195
|
if (methodOf(req) !== "POST") {
|
|
39587
40196
|
sendJson(res, 405, { error: "POST only" });
|
|
39588
40197
|
return;
|
|
@@ -39596,11 +40205,11 @@ function handlePoolEnable(services, req, res) {
|
|
|
39596
40205
|
ok,
|
|
39597
40206
|
pool: pool.getPoolData()
|
|
39598
40207
|
});
|
|
39599
|
-
})
|
|
40208
|
+
});
|
|
39600
40209
|
}
|
|
39601
40210
|
function handlePoolProxy(services, req, res) {
|
|
39602
40211
|
const { pool } = services;
|
|
39603
|
-
(async () => {
|
|
40212
|
+
runRoute(res, async () => {
|
|
39604
40213
|
if (methodOf(req) !== "POST") {
|
|
39605
40214
|
sendJson(res, 405, { error: "POST only" });
|
|
39606
40215
|
return;
|
|
@@ -39613,11 +40222,11 @@ function handlePoolProxy(services, req, res) {
|
|
|
39613
40222
|
ok: true,
|
|
39614
40223
|
pool: pool.getPoolData()
|
|
39615
40224
|
});
|
|
39616
|
-
})
|
|
40225
|
+
});
|
|
39617
40226
|
}
|
|
39618
40227
|
function handlePoolPrimary(services, req, res) {
|
|
39619
40228
|
const { pool, catalog, notifyPicker } = services;
|
|
39620
|
-
(async () => {
|
|
40229
|
+
runRoute(res, async () => {
|
|
39621
40230
|
if (methodOf(req) !== "POST") {
|
|
39622
40231
|
sendJson(res, 405, { error: "POST only" });
|
|
39623
40232
|
return;
|
|
@@ -39632,11 +40241,11 @@ function handlePoolPrimary(services, req, res) {
|
|
|
39632
40241
|
ok: true,
|
|
39633
40242
|
pool: pool.getPoolData()
|
|
39634
40243
|
});
|
|
39635
|
-
})
|
|
40244
|
+
});
|
|
39636
40245
|
}
|
|
39637
40246
|
function handlePoolMode(services, req, res) {
|
|
39638
40247
|
const { pool } = services;
|
|
39639
|
-
(async () => {
|
|
40248
|
+
runRoute(res, async () => {
|
|
39640
40249
|
if (methodOf(req) !== "POST") {
|
|
39641
40250
|
sendJson(res, 405, { error: "POST only" });
|
|
39642
40251
|
return;
|
|
@@ -39647,31 +40256,54 @@ function handlePoolMode(services, req, res) {
|
|
|
39647
40256
|
ok: true,
|
|
39648
40257
|
pool: pool.getPoolData()
|
|
39649
40258
|
});
|
|
39650
|
-
})
|
|
40259
|
+
});
|
|
39651
40260
|
}
|
|
40261
|
+
/**
|
|
40262
|
+
* In-flight quota refreshes, keyed by account id ('' = all). A manual refresh
|
|
40263
|
+
* runs `agy /usage` (20s cap) plus several REST calls; waiting for all of that
|
|
40264
|
+
* before answering is what made the console's "同步中" spin. Rapid clicks must
|
|
40265
|
+
* not stack duplicate pipelines either.
|
|
40266
|
+
*/
|
|
40267
|
+
const quotaRefreshInFlight = /* @__PURE__ */ new Map();
|
|
39652
40268
|
function handlePoolRefreshQuota(services, req, res) {
|
|
39653
|
-
const { pool, quota, catalog
|
|
39654
|
-
(async () => {
|
|
40269
|
+
const { pool, quota, catalog } = services;
|
|
40270
|
+
runRoute(res, async () => {
|
|
39655
40271
|
if (methodOf(req) !== "POST") {
|
|
39656
40272
|
sendJson(res, 405, { error: "POST only" });
|
|
39657
40273
|
return;
|
|
39658
40274
|
}
|
|
39659
40275
|
const body = await readBody(req);
|
|
39660
40276
|
const id = typeof body.id === "string" ? body.id : "";
|
|
39661
|
-
|
|
39662
|
-
|
|
39663
|
-
|
|
39664
|
-
|
|
39665
|
-
|
|
40277
|
+
const key = id || "__all__";
|
|
40278
|
+
if (!quotaRefreshInFlight.has(key)) {
|
|
40279
|
+
const work = (async () => {
|
|
40280
|
+
if (id) {
|
|
40281
|
+
const acc = pool.getAccount(id);
|
|
40282
|
+
if (acc) await quota.refreshAccountQuota(acc, true);
|
|
40283
|
+
} else await quota.refreshAllQuotas(true);
|
|
40284
|
+
await catalog.forceRefresh().catch(() => void 0);
|
|
40285
|
+
})().catch(() => void 0);
|
|
40286
|
+
let releaseTimer;
|
|
40287
|
+
const entry = work.finally(() => {
|
|
40288
|
+
if (releaseTimer !== void 0) clearTimeout(releaseTimer);
|
|
40289
|
+
if (quotaRefreshInFlight.get(key) === entry) quotaRefreshInFlight.delete(key);
|
|
40290
|
+
});
|
|
40291
|
+
quotaRefreshInFlight.set(key, entry);
|
|
40292
|
+
releaseTimer = setTimeout(() => {
|
|
40293
|
+
if (quotaRefreshInFlight.get(key) === entry) quotaRefreshInFlight.delete(key);
|
|
40294
|
+
}, QUOTA_REFRESH_DEDUP_MS);
|
|
40295
|
+
releaseTimer.unref?.();
|
|
40296
|
+
}
|
|
39666
40297
|
sendJson(res, 200, {
|
|
39667
40298
|
ok: true,
|
|
40299
|
+
pending: true,
|
|
39668
40300
|
pool: pool.getPoolData()
|
|
39669
40301
|
});
|
|
39670
|
-
})
|
|
40302
|
+
});
|
|
39671
40303
|
}
|
|
39672
40304
|
function handlePoolWarmup(services, req, res) {
|
|
39673
40305
|
const { pool, quota, warmup } = services;
|
|
39674
|
-
(async () => {
|
|
40306
|
+
runRoute(res, async () => {
|
|
39675
40307
|
try {
|
|
39676
40308
|
if (methodOf(req) !== "POST") {
|
|
39677
40309
|
sendJson(res, 405, { error: "POST only" });
|
|
@@ -39718,11 +40350,11 @@ function handlePoolWarmup(services, req, res) {
|
|
|
39718
40350
|
} catch (e) {
|
|
39719
40351
|
sendJson(res, 500, { error: String(e) });
|
|
39720
40352
|
}
|
|
39721
|
-
})
|
|
40353
|
+
});
|
|
39722
40354
|
}
|
|
39723
40355
|
function handlePoolClearCooldown(services, req, res) {
|
|
39724
40356
|
const { pool } = services;
|
|
39725
|
-
(async () => {
|
|
40357
|
+
runRoute(res, async () => {
|
|
39726
40358
|
if (methodOf(req) !== "POST") {
|
|
39727
40359
|
sendJson(res, 405, { error: "POST only" });
|
|
39728
40360
|
return;
|
|
@@ -39735,11 +40367,11 @@ function handlePoolClearCooldown(services, req, res) {
|
|
|
39735
40367
|
ok: true,
|
|
39736
40368
|
pool: pool.getPoolData()
|
|
39737
40369
|
});
|
|
39738
|
-
})
|
|
40370
|
+
});
|
|
39739
40371
|
}
|
|
39740
40372
|
function handlePoolSetActive(services, req, res) {
|
|
39741
40373
|
const { pool, catalog, notifyPicker } = services;
|
|
39742
|
-
(async () => {
|
|
40374
|
+
runRoute(res, async () => {
|
|
39743
40375
|
if (methodOf(req) !== "POST") {
|
|
39744
40376
|
sendJson(res, 405, { error: "POST only" });
|
|
39745
40377
|
return;
|
|
@@ -39756,11 +40388,11 @@ function handlePoolSetActive(services, req, res) {
|
|
|
39756
40388
|
ok,
|
|
39757
40389
|
pool: pool.getPoolData()
|
|
39758
40390
|
});
|
|
39759
|
-
})
|
|
40391
|
+
});
|
|
39760
40392
|
}
|
|
39761
40393
|
function handlePoolReorder(services, req, res) {
|
|
39762
40394
|
const { pool, catalog, notifyPicker } = services;
|
|
39763
|
-
(async () => {
|
|
40395
|
+
runRoute(res, async () => {
|
|
39764
40396
|
if (methodOf(req) !== "POST") {
|
|
39765
40397
|
sendJson(res, 405, { error: "POST only" });
|
|
39766
40398
|
return;
|
|
@@ -39777,11 +40409,11 @@ function handlePoolReorder(services, req, res) {
|
|
|
39777
40409
|
ok: true,
|
|
39778
40410
|
pool: pool.getPoolData()
|
|
39779
40411
|
});
|
|
39780
|
-
})
|
|
40412
|
+
});
|
|
39781
40413
|
}
|
|
39782
40414
|
function handlePoolImport(services, req, res) {
|
|
39783
40415
|
const { poolAuth, pool, notifyPicker } = services;
|
|
39784
|
-
(async () => {
|
|
40416
|
+
runRoute(res, async () => {
|
|
39785
40417
|
if (methodOf(req) !== "POST") {
|
|
39786
40418
|
sendJson(res, 405, { error: "POST only" });
|
|
39787
40419
|
return;
|
|
@@ -39812,7 +40444,7 @@ function handlePoolImport(services, req, res) {
|
|
|
39812
40444
|
error: result.error || "Import failed",
|
|
39813
40445
|
code: result.code
|
|
39814
40446
|
});
|
|
39815
|
-
})
|
|
40447
|
+
});
|
|
39816
40448
|
}
|
|
39817
40449
|
function register$4(reg, services) {
|
|
39818
40450
|
reg({
|
|
@@ -39905,7 +40537,7 @@ function register$4(reg, services) {
|
|
|
39905
40537
|
//#region src/transport/http/routes/auth.ts
|
|
39906
40538
|
function handleAuthBegin(services, req, res) {
|
|
39907
40539
|
const { getConfig, auth } = services;
|
|
39908
|
-
(async () => {
|
|
40540
|
+
runRoute(res, async () => {
|
|
39909
40541
|
if (methodOf(req) !== "POST") {
|
|
39910
40542
|
sendJson(res, 405, { error: "POST only" });
|
|
39911
40543
|
return;
|
|
@@ -39916,11 +40548,11 @@ function handleAuthBegin(services, req, res) {
|
|
|
39916
40548
|
const proxyUrl = typeof body.proxyUrl === "string" && body.proxyUrl.trim() !== "" ? body.proxyUrl.trim() : getConfig().proxyUrl.trim() || detectSystemProxy() || void 0;
|
|
39917
40549
|
const st = await auth.begin(homeDir, accountId, proxyUrl);
|
|
39918
40550
|
sendJson(res, 200, st);
|
|
39919
|
-
})
|
|
40551
|
+
});
|
|
39920
40552
|
}
|
|
39921
40553
|
function handleAuthCode(services, req, res) {
|
|
39922
40554
|
const { store, pool, quota, catalog, auth } = services;
|
|
39923
|
-
(async () => {
|
|
40555
|
+
runRoute(res, async () => {
|
|
39924
40556
|
if (methodOf(req) !== "POST") {
|
|
39925
40557
|
sendJson(res, 405, { error: "POST only" });
|
|
39926
40558
|
return;
|
|
@@ -39941,11 +40573,11 @@ function handleAuthCode(services, req, res) {
|
|
|
39941
40573
|
catalog.forceRefresh().catch(() => void 0);
|
|
39942
40574
|
}
|
|
39943
40575
|
sendJson(res, 200, st);
|
|
39944
|
-
})
|
|
40576
|
+
});
|
|
39945
40577
|
}
|
|
39946
40578
|
function handleAuthCancel(services, req, res) {
|
|
39947
40579
|
const { auth } = services;
|
|
39948
|
-
(async () => {
|
|
40580
|
+
runRoute(res, async () => {
|
|
39949
40581
|
if (methodOf(req) !== "POST") {
|
|
39950
40582
|
sendJson(res, 405, { error: "POST only" });
|
|
39951
40583
|
return;
|
|
@@ -39953,11 +40585,11 @@ function handleAuthCancel(services, req, res) {
|
|
|
39953
40585
|
await readBody(req);
|
|
39954
40586
|
const st = auth.cancelAuth();
|
|
39955
40587
|
sendJson(res, 200, st);
|
|
39956
|
-
})
|
|
40588
|
+
});
|
|
39957
40589
|
}
|
|
39958
40590
|
function handleAuthQr(services, req, res) {
|
|
39959
40591
|
const { auth } = services;
|
|
39960
|
-
(async () => {
|
|
40592
|
+
runRoute(res, async () => {
|
|
39961
40593
|
const st = auth.status();
|
|
39962
40594
|
const url = st.phase === "pending" ? st.url : void 0;
|
|
39963
40595
|
if (!url) {
|
|
@@ -39981,7 +40613,7 @@ function handleAuthQr(services, req, res) {
|
|
|
39981
40613
|
} catch {
|
|
39982
40614
|
sendJson(res, 500, { error: "qr generation failed" });
|
|
39983
40615
|
}
|
|
39984
|
-
})
|
|
40616
|
+
});
|
|
39985
40617
|
}
|
|
39986
40618
|
function register$3(reg, services) {
|
|
39987
40619
|
reg({
|
|
@@ -40009,7 +40641,7 @@ function register$3(reg, services) {
|
|
|
40009
40641
|
//#region src/transport/http/routes/config.ts
|
|
40010
40642
|
function handleConfig(services, req, res) {
|
|
40011
40643
|
const { setOverride, notifyPicker, onConfigWritten } = services;
|
|
40012
|
-
(async () => {
|
|
40644
|
+
runRoute(res, async () => {
|
|
40013
40645
|
if (methodOf(req) !== "POST") {
|
|
40014
40646
|
sendJson(res, 405, { error: "POST only" });
|
|
40015
40647
|
return;
|
|
@@ -40038,7 +40670,9 @@ function handleConfig(services, req, res) {
|
|
|
40038
40670
|
"imageTimeoutMs",
|
|
40039
40671
|
"imageMaxBytes",
|
|
40040
40672
|
"imageOutputDir",
|
|
40041
|
-
"imageRetries"
|
|
40673
|
+
"imageRetries",
|
|
40674
|
+
"showHeaderBadge",
|
|
40675
|
+
"showTranslateAction"
|
|
40042
40676
|
].includes(key)) {
|
|
40043
40677
|
sendJson(res, 400, { error: "key not settable" });
|
|
40044
40678
|
return;
|
|
@@ -40059,7 +40693,7 @@ function handleConfig(services, req, res) {
|
|
|
40059
40693
|
key,
|
|
40060
40694
|
value: body.value
|
|
40061
40695
|
});
|
|
40062
|
-
})
|
|
40696
|
+
});
|
|
40063
40697
|
}
|
|
40064
40698
|
function register$2(reg, services) {
|
|
40065
40699
|
reg({
|
|
@@ -40071,8 +40705,8 @@ function register$2(reg, services) {
|
|
|
40071
40705
|
//#endregion
|
|
40072
40706
|
//#region src/transport/http/routes/translate.ts
|
|
40073
40707
|
function handleTranslate(services, req, res) {
|
|
40074
|
-
const { translation } = services;
|
|
40075
|
-
(async () => {
|
|
40708
|
+
const { translation, getConfig } = services;
|
|
40709
|
+
runRoute(res, async () => {
|
|
40076
40710
|
if (methodOf(req) !== "POST") {
|
|
40077
40711
|
sendJson(res, 405, { error: "POST only" });
|
|
40078
40712
|
return;
|
|
@@ -40121,7 +40755,7 @@ function handleTranslate(services, req, res) {
|
|
|
40121
40755
|
} catch (e) {
|
|
40122
40756
|
sendJson(res, 500, { error: String(e) });
|
|
40123
40757
|
}
|
|
40124
|
-
}
|
|
40758
|
+
}, longRouteTimeout(getConfig().translateTimeoutMs));
|
|
40125
40759
|
}
|
|
40126
40760
|
function handleTranslatePending(services, req, res) {
|
|
40127
40761
|
const { translation } = services;
|
|
@@ -40239,6 +40873,7 @@ function safeDecodeUri(s) {
|
|
|
40239
40873
|
}
|
|
40240
40874
|
function parseRawMediaUri(raw) {
|
|
40241
40875
|
let p = raw;
|
|
40876
|
+
if (p.startsWith("~/") || p.startsWith("~\\")) p = join(homedir(), p.slice(2));
|
|
40242
40877
|
if (p.startsWith("file://")) {
|
|
40243
40878
|
let converted = null;
|
|
40244
40879
|
try {
|
|
@@ -40294,8 +40929,9 @@ function resolveLocalMediaPath(rawPath, workspaceRoots) {
|
|
|
40294
40929
|
if (!rawPath || typeof rawPath !== "string") return null;
|
|
40295
40930
|
const p = parseRawMediaUri(rawPath.trim());
|
|
40296
40931
|
if (p === null) return null;
|
|
40297
|
-
|
|
40298
|
-
|
|
40932
|
+
const cleanPath = p.split(/[?#]/)[0] ?? p;
|
|
40933
|
+
if (IS_WIN && (/^[A-Za-z]:/.test(cleanPath) || cleanPath.startsWith("\\\\")) || !IS_WIN && cleanPath.startsWith("/")) {
|
|
40934
|
+
const resolved = resolve(cleanPath);
|
|
40299
40935
|
if (existsSync(resolved)) return resolved;
|
|
40300
40936
|
}
|
|
40301
40937
|
const roots = [];
|
|
@@ -40303,12 +40939,12 @@ function resolveLocalMediaPath(rawPath, workspaceRoots) {
|
|
|
40303
40939
|
else if (Array.isArray(workspaceRoots)) {
|
|
40304
40940
|
for (const r of workspaceRoots) if (typeof r === "string" && r !== "") roots.push(r);
|
|
40305
40941
|
}
|
|
40306
|
-
const strippedRel =
|
|
40307
|
-
const baseName = extname(
|
|
40942
|
+
const strippedRel = cleanPath.replace(/^[/\\]+/, "");
|
|
40943
|
+
const baseName = extname(cleanPath) ? cleanPath.split(/[/\\]/).pop() : cleanPath;
|
|
40308
40944
|
for (const root of roots) {
|
|
40309
|
-
const candidate = resolve(root,
|
|
40945
|
+
const candidate = resolve(root, cleanPath);
|
|
40310
40946
|
if (existsSync(candidate)) return candidate;
|
|
40311
|
-
if (strippedRel !==
|
|
40947
|
+
if (strippedRel !== cleanPath) {
|
|
40312
40948
|
const relCandidate = resolve(root, strippedRel);
|
|
40313
40949
|
if (existsSync(relCandidate)) return relCandidate;
|
|
40314
40950
|
}
|
|
@@ -40317,7 +40953,7 @@ function resolveLocalMediaPath(rawPath, workspaceRoots) {
|
|
|
40317
40953
|
const found = searchInDirectory(root, strippedRel, baseName, root === homedir() || root === "/" || IS_WIN && /^[A-Za-z]:\\?$/.test(root) ? 1 : 3);
|
|
40318
40954
|
if (found) return found;
|
|
40319
40955
|
}
|
|
40320
|
-
const resolved = resolve(
|
|
40956
|
+
const resolved = resolve(cleanPath);
|
|
40321
40957
|
if (existsSync(resolved)) return resolved;
|
|
40322
40958
|
return null;
|
|
40323
40959
|
}
|
|
@@ -40432,20 +41068,71 @@ function executeOpenInSystem(targetPath, reveal = false) {
|
|
|
40432
41068
|
return { ok: true };
|
|
40433
41069
|
}
|
|
40434
41070
|
if (process.platform === "win32") {
|
|
40435
|
-
if (reveal)
|
|
40436
|
-
|
|
40437
|
-
|
|
40438
|
-
|
|
40439
|
-
|
|
40440
|
-
|
|
40441
|
-
|
|
40442
|
-
|
|
40443
|
-
targetPath
|
|
40444
|
-
|
|
40445
|
-
|
|
40446
|
-
|
|
40447
|
-
|
|
40448
|
-
|
|
41071
|
+
if (reveal) {
|
|
41072
|
+
spawn("explorer.exe", [`/select,${targetPath}`], {
|
|
41073
|
+
detached: true,
|
|
41074
|
+
stdio: "ignore"
|
|
41075
|
+
}).unref();
|
|
41076
|
+
return { ok: true };
|
|
41077
|
+
}
|
|
41078
|
+
try {
|
|
41079
|
+
const psCmd = `Start-Process -FilePath "${targetPath.replace(/"/g, "`\"")}" -ErrorAction Stop`;
|
|
41080
|
+
if (spawnSync("powershell.exe", [
|
|
41081
|
+
"-NoProfile",
|
|
41082
|
+
"-NonInteractive",
|
|
41083
|
+
"-Command",
|
|
41084
|
+
psCmd
|
|
41085
|
+
], {
|
|
41086
|
+
timeout: 4e3,
|
|
41087
|
+
encoding: "utf-8",
|
|
41088
|
+
windowsHide: true
|
|
41089
|
+
}).status === 0) return { ok: true };
|
|
41090
|
+
} catch {}
|
|
41091
|
+
const ext = extname(targetPath).toLowerCase();
|
|
41092
|
+
if ([
|
|
41093
|
+
".md",
|
|
41094
|
+
".txt",
|
|
41095
|
+
".json",
|
|
41096
|
+
".jsonl",
|
|
41097
|
+
".yaml",
|
|
41098
|
+
".yml",
|
|
41099
|
+
".ts",
|
|
41100
|
+
".js",
|
|
41101
|
+
".py",
|
|
41102
|
+
".gd",
|
|
41103
|
+
".log",
|
|
41104
|
+
".env"
|
|
41105
|
+
].includes(ext)) {
|
|
41106
|
+
try {
|
|
41107
|
+
if (spawnSync("cmd.exe", [
|
|
41108
|
+
"/c",
|
|
41109
|
+
"code",
|
|
41110
|
+
targetPath
|
|
41111
|
+
], {
|
|
41112
|
+
timeout: 3e3,
|
|
41113
|
+
windowsHide: true
|
|
41114
|
+
}).status === 0) return { ok: true };
|
|
41115
|
+
} catch {}
|
|
41116
|
+
try {
|
|
41117
|
+
spawn("notepad.exe", [targetPath], {
|
|
41118
|
+
detached: true,
|
|
41119
|
+
stdio: "ignore"
|
|
41120
|
+
}).unref();
|
|
41121
|
+
return { ok: true };
|
|
41122
|
+
} catch {}
|
|
41123
|
+
}
|
|
41124
|
+
try {
|
|
41125
|
+
spawn("explorer.exe", [`/select,${targetPath}`], {
|
|
41126
|
+
detached: true,
|
|
41127
|
+
stdio: "ignore"
|
|
41128
|
+
}).unref();
|
|
41129
|
+
return { ok: true };
|
|
41130
|
+
} catch (err) {
|
|
41131
|
+
return {
|
|
41132
|
+
ok: false,
|
|
41133
|
+
error: String(err)
|
|
41134
|
+
};
|
|
41135
|
+
}
|
|
40449
41136
|
}
|
|
40450
41137
|
spawn("xdg-open", [targetPath], {
|
|
40451
41138
|
detached: true,
|
|
@@ -40639,6 +41326,9 @@ function collectWorkspaceRoots(services) {
|
|
|
40639
41326
|
if (existsSync(desktop) && !roots.includes(desktop)) roots.push(desktop);
|
|
40640
41327
|
if (existsSync(downloads) && !roots.includes(downloads)) roots.push(downloads);
|
|
40641
41328
|
if (!roots.includes(home)) roots.push(home);
|
|
41329
|
+
try {
|
|
41330
|
+
for (const b of brainDirCandidates()) if (existsSync(b) && !roots.includes(b)) roots.push(b);
|
|
41331
|
+
} catch {}
|
|
40642
41332
|
return roots;
|
|
40643
41333
|
}
|
|
40644
41334
|
function handleMedia(services, req, res) {
|