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/cli-image.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
|
-
import { accessSync, constants, copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, utimesSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { accessSync, closeSync, constants, copyFileSync, existsSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, utimesSync, writeFileSync } from "node:fs";
|
|
4
4
|
import path, { basename, delimiter, dirname, extname, isAbsolute, join, relative, resolve } from "node:path";
|
|
5
5
|
import { pathToFileURL } from "node:url";
|
|
6
6
|
import { homedir } from "node:os";
|
|
@@ -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,
|
|
@@ -598,6 +611,8 @@ function resolveConfig(entry, env = process.env, overrides = readOverrides()) {
|
|
|
598
611
|
translateSkipSameModel: asBool(get("translateSkipSameModel")) ?? base.translateSkipSameModel,
|
|
599
612
|
translateBindConversation: asBool(get("translateBindConversation")) ?? base.translateBindConversation,
|
|
600
613
|
translateMinIntervalMs: asNum(get("translateMinIntervalMs")) ?? base.translateMinIntervalMs,
|
|
614
|
+
showHeaderBadge: asBool(get("showHeaderBadge")) ?? base.showHeaderBadge,
|
|
615
|
+
showTranslateAction: asBool(get("showTranslateAction")) ?? base.showTranslateAction,
|
|
601
616
|
imageModel: asString(get("imageModel")) ?? base.imageModel,
|
|
602
617
|
imageEffort: asString(get("imageEffort")) ?? base.imageEffort,
|
|
603
618
|
imageTimeoutMs: asNum(get("imageTimeoutMs")) ?? base.imageTimeoutMs,
|
|
@@ -702,6 +717,14 @@ function resolveConfig(entry, env = process.env, overrides = readOverrides()) {
|
|
|
702
717
|
if (env.DSH_AGY_TRANSLATE_MODEL) cfg.translateModel = env.DSH_AGY_TRANSLATE_MODEL;
|
|
703
718
|
if (env.DSH_AGY_TRANSLATE_EFFORT) cfg.translateEffort = env.DSH_AGY_TRANSLATE_EFFORT;
|
|
704
719
|
if (env.DSH_AGY_TRANSLATE_LANG) cfg.translateTargetLanguage = env.DSH_AGY_TRANSLATE_LANG;
|
|
720
|
+
if (env.DSH_AGY_SHOW_HEADER_BADGE !== void 0) {
|
|
721
|
+
const shb = asBool(env.DSH_AGY_SHOW_HEADER_BADGE);
|
|
722
|
+
if (shb !== void 0) cfg.showHeaderBadge = shb;
|
|
723
|
+
}
|
|
724
|
+
if (env.DSH_AGY_SHOW_TRANSLATE_ACTION !== void 0) {
|
|
725
|
+
const sta = asBool(env.DSH_AGY_SHOW_TRANSLATE_ACTION);
|
|
726
|
+
if (sta !== void 0) cfg.showTranslateAction = sta;
|
|
727
|
+
}
|
|
705
728
|
if (env.DSH_AGY_IMAGE_MODEL) cfg.imageModel = env.DSH_AGY_IMAGE_MODEL;
|
|
706
729
|
if (env.DSH_AGY_IMAGE_EFFORT) cfg.imageEffort = env.DSH_AGY_IMAGE_EFFORT;
|
|
707
730
|
if (env.DSH_AGY_IMAGE_TIMEOUT_MS) {
|
|
@@ -1905,7 +1928,7 @@ function buildMirrorRunCode(runId, eventIndex, toolName, brief) {
|
|
|
1905
1928
|
step: eventIndex
|
|
1906
1929
|
});
|
|
1907
1930
|
return {
|
|
1908
|
-
code: "// dsh-agy-link mirror: replay recorded agy tool step " + eventIndex + " (" + toolName + ")\
|
|
1931
|
+
code: "// dsh-agy-link mirror: replay recorded agy tool step " + eventIndex + " (" + toolName + ")\nawait tools['agy_tool'](" + invocation + ")",
|
|
1909
1932
|
description: brief !== void 0 && brief !== "" ? brief + " · " + toolName : toolName
|
|
1910
1933
|
};
|
|
1911
1934
|
}
|
|
@@ -2036,9 +2059,14 @@ function toolStepBrief(toolName, args, server) {
|
|
|
2036
2059
|
return timing ? "schedule " + timing : prompt ? "schedule " + prompt.slice(0, 40) : "schedule";
|
|
2037
2060
|
}
|
|
2038
2061
|
if (effTool === "invoke_subagent") {
|
|
2062
|
+
const directRole = pickStr("Role", "role", "TypeName", "typeName");
|
|
2039
2063
|
const subs = a.Subagents ?? a.subagents;
|
|
2040
|
-
const
|
|
2041
|
-
|
|
2064
|
+
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 : "";
|
|
2065
|
+
let role = (directRole || subRole).trim();
|
|
2066
|
+
if (role.startsWith("\"") && role.endsWith("\"")) try {
|
|
2067
|
+
role = JSON.parse(role);
|
|
2068
|
+
} catch {}
|
|
2069
|
+
return role ? "subagent: " + role : "invoke subagent";
|
|
2042
2070
|
}
|
|
2043
2071
|
if (effTool === "send_message") {
|
|
2044
2072
|
const recipient = pickStr("Recipient", "recipient", "to");
|
|
@@ -2081,6 +2109,19 @@ function rewriteImageMarkdown(text, mediaBaseUrl) {
|
|
|
2081
2109
|
return `}`})`;
|
|
2082
2110
|
});
|
|
2083
2111
|
}
|
|
2112
|
+
/** 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. */
|
|
2113
|
+
function normalizeFileLinks(text) {
|
|
2114
|
+
if (!text) return text;
|
|
2115
|
+
return text.replace(/(^|[^\!])\[([^\]]+)\]\((file:\/\/\/[^\s)]+|file:\/\/[^\s)]+)\)/g, (_, prefix, label, url) => {
|
|
2116
|
+
let target = url.trim();
|
|
2117
|
+
if (target.startsWith("file://")) {
|
|
2118
|
+
target = target.slice(7);
|
|
2119
|
+
if (/^\/[A-Za-z]:/.test(target)) target = target.slice(1);
|
|
2120
|
+
}
|
|
2121
|
+
target = target.replace(/\\/g, "/");
|
|
2122
|
+
return `${prefix}[${label}](${target})`;
|
|
2123
|
+
});
|
|
2124
|
+
}
|
|
2084
2125
|
//#endregion
|
|
2085
2126
|
//#region src/host/recording.ts
|
|
2086
2127
|
const waiters = Symbol("waiters");
|
|
@@ -2697,7 +2738,7 @@ var EventMapper = class {
|
|
|
2697
2738
|
this.sawTextStep = true;
|
|
2698
2739
|
yield* this.ensureBlock("text");
|
|
2699
2740
|
let d;
|
|
2700
|
-
const processedText = this.opts.mediaBaseUrl ? rewriteImageMarkdown(ev.text, this.opts.mediaBaseUrl) : ev.text;
|
|
2741
|
+
const processedText = normalizeFileLinks(this.opts.mediaBaseUrl ? rewriteImageMarkdown(ev.text, this.opts.mediaBaseUrl) : ev.text);
|
|
2701
2742
|
if (ev.fragment === true) {
|
|
2702
2743
|
const acc = (this.emittedByKey.get(ev.stepKey) ?? "") + processedText;
|
|
2703
2744
|
this.emittedByKey.set(ev.stepKey, acc);
|
|
@@ -2733,7 +2774,7 @@ var EventMapper = class {
|
|
|
2733
2774
|
const prev = this.emittedByKey.get(ev.stepKey) ?? "";
|
|
2734
2775
|
const deltaText = suffixDelta(prev, ev.text);
|
|
2735
2776
|
this.emittedByKey.set(ev.stepKey, ev.text);
|
|
2736
|
-
const banner = prev === "" ? "[agy subagent] " : "";
|
|
2777
|
+
const banner = prev === "" && !ev.text.startsWith("[") ? "[agy subagent] " : "";
|
|
2737
2778
|
const d = this.appendDelta(banner + deltaText);
|
|
2738
2779
|
if (d) yield d;
|
|
2739
2780
|
}
|
|
@@ -2777,9 +2818,10 @@ var EventMapper = class {
|
|
|
2777
2818
|
}
|
|
2778
2819
|
if (!ev.ok) {
|
|
2779
2820
|
if (ev.response === "") return;
|
|
2821
|
+
const respText = normalizeFileLinks(ev.response);
|
|
2780
2822
|
if (!this.sawTextStep) {
|
|
2781
2823
|
yield* this.ensureBlock("text");
|
|
2782
|
-
const d = this.appendDelta(
|
|
2824
|
+
const d = this.appendDelta(respText);
|
|
2783
2825
|
if (d) yield d;
|
|
2784
2826
|
}
|
|
2785
2827
|
if (ev.error !== void 0 && ev.error !== "") {
|
|
@@ -2789,7 +2831,7 @@ var EventMapper = class {
|
|
|
2789
2831
|
}
|
|
2790
2832
|
} else if (!this.sawTextStep && ev.response !== "") {
|
|
2791
2833
|
yield* this.ensureBlock("text");
|
|
2792
|
-
const d = this.appendDelta(ev.response);
|
|
2834
|
+
const d = this.appendDelta(normalizeFileLinks(ev.response));
|
|
2793
2835
|
if (d) yield d;
|
|
2794
2836
|
}
|
|
2795
2837
|
yield* this.flushBannerOnlyThoughts();
|
|
@@ -2908,6 +2950,21 @@ function findConversationDb(conversationId, accountHome) {
|
|
|
2908
2950
|
}
|
|
2909
2951
|
return null;
|
|
2910
2952
|
}
|
|
2953
|
+
/** Candidate brain directories for a conversation id across system + pool homes. */
|
|
2954
|
+
function brainDirCandidates(accountHome) {
|
|
2955
|
+
return conversationsDirCandidates(accountHome).map((d) => join(d, "..", "brain"));
|
|
2956
|
+
}
|
|
2957
|
+
/** Locate an existing conversation brain directory across system + pool homes. */
|
|
2958
|
+
function findBrainDir(conversationId, accountHome) {
|
|
2959
|
+
if (!isSafeConversationId(conversationId)) return null;
|
|
2960
|
+
for (const dir of brainDirCandidates(accountHome)) {
|
|
2961
|
+
const p = join(dir, conversationId);
|
|
2962
|
+
try {
|
|
2963
|
+
if (existsSync(p)) return p;
|
|
2964
|
+
} catch {}
|
|
2965
|
+
}
|
|
2966
|
+
return null;
|
|
2967
|
+
}
|
|
2911
2968
|
/** agy conversation ids are path-safe tokens; reject anything else before join(). */
|
|
2912
2969
|
const SAFE_CONVERSATION_ID = /^[A-Za-z0-9_-]{1,64}$/;
|
|
2913
2970
|
function isSafeConversationId(id) {
|
|
@@ -3808,6 +3865,80 @@ var FailoverBudget = class FailoverBudget {
|
|
|
3808
3865
|
}
|
|
3809
3866
|
};
|
|
3810
3867
|
//#endregion
|
|
3868
|
+
//#region src/common/reasoning.ts
|
|
3869
|
+
/** Every effort id agy accepts, in ascending intensity order. */
|
|
3870
|
+
const REASONING_EFFORTS = [
|
|
3871
|
+
"low",
|
|
3872
|
+
"medium",
|
|
3873
|
+
"high",
|
|
3874
|
+
"xhigh",
|
|
3875
|
+
"max"
|
|
3876
|
+
];
|
|
3877
|
+
/**
|
|
3878
|
+
* Display names, matching agy's own model picker ("Extra" is `xhigh`, which is
|
|
3879
|
+
* how the GUI labels it while `agy --help` spells it `xhigh`).
|
|
3880
|
+
*/
|
|
3881
|
+
const EFFORT_LABELS = {
|
|
3882
|
+
low: "Low",
|
|
3883
|
+
medium: "Medium",
|
|
3884
|
+
high: "High",
|
|
3885
|
+
xhigh: "Extra",
|
|
3886
|
+
max: "Max"
|
|
3887
|
+
};
|
|
3888
|
+
/** Display name for an effort id; unknown ids are shown verbatim. */
|
|
3889
|
+
function effortLabel(id) {
|
|
3890
|
+
const key = typeof id === "string" ? id.trim().toLowerCase() : "";
|
|
3891
|
+
return EFFORT_LABELS[key] ?? (typeof id === "string" ? id.trim() : "");
|
|
3892
|
+
}
|
|
3893
|
+
/**
|
|
3894
|
+
* Effort suffixes ordered so a LONGER suffix always wins: `gemini-4-hydrogen-xhigh`
|
|
3895
|
+
* must fold as `gemini-4-hydrogen` + `xhigh`, never as `gemini-4-hydrogen-x` + `high`.
|
|
3896
|
+
*/
|
|
3897
|
+
const EFFORT_SUFFIXES = [...REASONING_EFFORTS].sort((a, b) => b.length - a.length || a.localeCompare(b));
|
|
3898
|
+
/**
|
|
3899
|
+
* Split a discovered agy slug into (base, effort).
|
|
3900
|
+
*
|
|
3901
|
+
* Returns `effort: undefined` when the slug carries no effort suffix. The
|
|
3902
|
+
* caller still decides whether the base is real — a lone `gemini-x-medium`
|
|
3903
|
+
* with no siblings must stay verbatim rather than inventing a base.
|
|
3904
|
+
*/
|
|
3905
|
+
function splitEffortSuffix(slug) {
|
|
3906
|
+
const id = typeof slug === "string" ? slug.trim() : "";
|
|
3907
|
+
for (const effort of EFFORT_SUFFIXES) {
|
|
3908
|
+
const suffix = "-" + effort;
|
|
3909
|
+
if (id.length > suffix.length && id.endsWith(suffix)) return {
|
|
3910
|
+
base: id.slice(0, -suffix.length),
|
|
3911
|
+
effort
|
|
3912
|
+
};
|
|
3913
|
+
}
|
|
3914
|
+
return { base: id };
|
|
3915
|
+
}
|
|
3916
|
+
/**
|
|
3917
|
+
* Canonical ordering + de-duplication of an effort set.
|
|
3918
|
+
*
|
|
3919
|
+
* Order is always `REASONING_EFFORTS`, so the picker and the settings
|
|
3920
|
+
* dropdowns can never disagree about the order of Low/Medium/High/Extra.
|
|
3921
|
+
*
|
|
3922
|
+
* Ids this build does not know yet (a newer agy level, or a hand-written
|
|
3923
|
+
* `fallbackModels` entry) are kept AFTER the known ones in first-seen order —
|
|
3924
|
+
* dropping them would silently delete a user's configuration.
|
|
3925
|
+
*/
|
|
3926
|
+
function normalizeEfforts(list) {
|
|
3927
|
+
if (list === void 0 || list === null) return [];
|
|
3928
|
+
const present = /* @__PURE__ */ new Set();
|
|
3929
|
+
const order = [];
|
|
3930
|
+
for (const raw of list) {
|
|
3931
|
+
if (typeof raw !== "string") continue;
|
|
3932
|
+
const id = raw.trim().toLowerCase();
|
|
3933
|
+
if (id === "" || present.has(id)) continue;
|
|
3934
|
+
present.add(id);
|
|
3935
|
+
order.push(id);
|
|
3936
|
+
}
|
|
3937
|
+
const known = REASONING_EFFORTS.filter((e) => present.has(e));
|
|
3938
|
+
const unknown = order.filter((e) => !REASONING_EFFORTS.includes(e));
|
|
3939
|
+
return [...known, ...unknown];
|
|
3940
|
+
}
|
|
3941
|
+
//#endregion
|
|
3811
3942
|
//#region src/host/models.ts
|
|
3812
3943
|
/** Check whether any enabled account in the pool has confirmed access to Argon. */
|
|
3813
3944
|
function poolHasArgon(pool, catalog) {
|
|
@@ -3890,15 +4021,16 @@ function extractModelList(parsed) {
|
|
|
3890
4021
|
}
|
|
3891
4022
|
return out;
|
|
3892
4023
|
}
|
|
3893
|
-
const EFFORT_SUFFIXES = [
|
|
3894
|
-
"low",
|
|
3895
|
-
"medium",
|
|
3896
|
-
"high"
|
|
3897
|
-
];
|
|
3898
4024
|
/** Fold Gemini/Argon/Claude effort variants into base + effort set (spec ADR-10).
|
|
3899
4025
|
* Claude 5.5 is listed only as tiered slugs by agy 1.5.3; the base slug is the
|
|
3900
4026
|
* one that accepts `--effort`, and passing a tiered slug together with the flag
|
|
3901
|
-
* is rejected ("--model … conflicts with --effort=…").
|
|
4027
|
+
* is rejected ("--model … conflicts with --effort=…").
|
|
4028
|
+
*
|
|
4029
|
+
* The effort vocabulary itself (including agy 1.5.7's `xhigh`, which its picker
|
|
4030
|
+
* labels "Extra") comes from `common/reasoning.ts` — folding must never carry
|
|
4031
|
+
* its own copy of the list, or a new level silently becomes a bogus MODEL:
|
|
4032
|
+
* a missed `xhigh` used to surface `gemini-4-hydrogen-xhigh` next to
|
|
4033
|
+
* `gemini-4-hydrogen` in DSH's picker. */
|
|
3902
4034
|
function foldEfforts(raw) {
|
|
3903
4035
|
const bases = /* @__PURE__ */ new Map();
|
|
3904
4036
|
const verbatim = [];
|
|
@@ -3912,26 +4044,23 @@ function foldEfforts(raw) {
|
|
|
3912
4044
|
});
|
|
3913
4045
|
continue;
|
|
3914
4046
|
}
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
const
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
folded = true;
|
|
3930
|
-
break;
|
|
3931
|
-
}
|
|
4047
|
+
const split = splitEffortSuffix(r.slug);
|
|
4048
|
+
if (split.effort !== void 0) {
|
|
4049
|
+
const base = split.base;
|
|
4050
|
+
const eff = split.effort;
|
|
4051
|
+
const hasBare = slugSet.has(base);
|
|
4052
|
+
const hasSibling = raw.some((x) => x.slug !== r.slug && splitEffortSuffix(x.slug).base === base);
|
|
4053
|
+
if (hasBare || hasSibling) {
|
|
4054
|
+
const entry = bases.get(base) ?? {
|
|
4055
|
+
label: stripEffortLabel(r.label, eff),
|
|
4056
|
+
efforts: /* @__PURE__ */ new Set()
|
|
4057
|
+
};
|
|
4058
|
+
entry.efforts.add(eff);
|
|
4059
|
+
bases.set(base, entry);
|
|
4060
|
+
continue;
|
|
3932
4061
|
}
|
|
3933
4062
|
}
|
|
3934
|
-
|
|
4063
|
+
verbatim.push({
|
|
3935
4064
|
id: r.slug,
|
|
3936
4065
|
name: r.label,
|
|
3937
4066
|
efforts: null
|
|
@@ -3939,7 +4068,7 @@ function foldEfforts(raw) {
|
|
|
3939
4068
|
}
|
|
3940
4069
|
const folded = [];
|
|
3941
4070
|
for (const [id, v] of bases) {
|
|
3942
|
-
const efforts =
|
|
4071
|
+
const efforts = normalizeEfforts(v.efforts);
|
|
3943
4072
|
folded.push({
|
|
3944
4073
|
id,
|
|
3945
4074
|
name: v.label !== "" ? v.label : id,
|
|
@@ -3952,9 +4081,7 @@ function foldEfforts(raw) {
|
|
|
3952
4081
|
for (const r of raw) if (r.slug === e.id || r.slug.startsWith(e.id + "-")) best = Math.min(best, rawOrder.get(r.slug) ?? Infinity);
|
|
3953
4082
|
return best;
|
|
3954
4083
|
};
|
|
3955
|
-
folded.sort((a, b) => rank(a) - rank(b));
|
|
3956
|
-
verbatim.sort((a, b) => rank(a) - rank(b));
|
|
3957
|
-
return [...folded, ...verbatim.filter((e) => !bases.has(e.id))];
|
|
4084
|
+
return [...folded, ...verbatim.filter((e) => !bases.has(e.id))].sort((a, b) => rank(a) - rank(b));
|
|
3958
4085
|
}
|
|
3959
4086
|
function stripEffortLabel(label, eff) {
|
|
3960
4087
|
const re = new RegExp("\\s*\\(?" + eff + "\\)?\\s*$", "i");
|
|
@@ -3989,7 +4116,8 @@ function sanitizeCatalogEntries(models) {
|
|
|
3989
4116
|
const name = typeof m.name === "string" && m.name.trim() !== "" ? m.name.trim() : id;
|
|
3990
4117
|
entries.push({
|
|
3991
4118
|
id,
|
|
3992
|
-
name
|
|
4119
|
+
name,
|
|
4120
|
+
efforts: normalizeEfforts(m.efforts)
|
|
3993
4121
|
});
|
|
3994
4122
|
}
|
|
3995
4123
|
return {
|
|
@@ -4013,6 +4141,12 @@ var ModelCatalog = class ModelCatalog {
|
|
|
4013
4141
|
*/
|
|
4014
4142
|
static FALLBACK_RETRY_MS = 6e4;
|
|
4015
4143
|
lastAttemptAt = 0;
|
|
4144
|
+
/**
|
|
4145
|
+
* Per-account probe timestamps. `refreshIfNeeded(accountId)` used to skip
|
|
4146
|
+
* the throttle whenever the account had no catalog yet, so a signed-out /
|
|
4147
|
+
* expired account could be probed on EVERY listModels() read (issue #106).
|
|
4148
|
+
*/
|
|
4149
|
+
accountAttemptAt = /* @__PURE__ */ new Map();
|
|
4016
4150
|
constructor(discover, fallbackDefs, ttlMs, onUpdate) {
|
|
4017
4151
|
this.discover = discover;
|
|
4018
4152
|
this.fallbackDefs = fallbackDefs;
|
|
@@ -4096,6 +4230,9 @@ var ModelCatalog = class ModelCatalog {
|
|
|
4096
4230
|
const age = now - targetCat.discoveredAt;
|
|
4097
4231
|
if (targetCat.source === "discovered" && age < this.ttlMs) return;
|
|
4098
4232
|
if (targetCat.source === "fallback" && now - this.lastAttemptAt < ModelCatalog.FALLBACK_RETRY_MS) return;
|
|
4233
|
+
} else {
|
|
4234
|
+
if (now - (this.accountAttemptAt.get(accountId) ?? 0) < ModelCatalog.FALLBACK_RETRY_MS) return;
|
|
4235
|
+
this.accountAttemptAt.set(accountId, now);
|
|
4099
4236
|
}
|
|
4100
4237
|
this.lastAttemptAt = now;
|
|
4101
4238
|
this.refreshing = this.refresh(accountId).finally(() => {
|
|
@@ -4103,6 +4240,20 @@ var ModelCatalog = class ModelCatalog {
|
|
|
4103
4240
|
});
|
|
4104
4241
|
return this.refreshing;
|
|
4105
4242
|
}
|
|
4243
|
+
/**
|
|
4244
|
+
* Read-path discovery for one account (listModels). Unlike
|
|
4245
|
+
* `forceRefreshAndNotify()` this is throttled and NEVER broadcasts on a
|
|
4246
|
+
* failed probe: an unconditional `adapters-updated` made DSH's browser
|
|
4247
|
+
* re-read the catalog, which called listModels() again — a self-exciting
|
|
4248
|
+
* 1:1 read/probe/announce loop while signed out (issue #106). `refresh()`
|
|
4249
|
+
* itself announces only when the catalog contents actually changed, so a
|
|
4250
|
+
* successful first build still updates the picker exactly once.
|
|
4251
|
+
*/
|
|
4252
|
+
async ensureAccountCatalog(accountId) {
|
|
4253
|
+
if (!accountId || this.accountCatalogs.has(accountId)) return this.get(accountId);
|
|
4254
|
+
await this.refreshIfNeeded(accountId);
|
|
4255
|
+
return this.get(accountId);
|
|
4256
|
+
}
|
|
4106
4257
|
async forceRefresh(accountId) {
|
|
4107
4258
|
await this.refresh(accountId);
|
|
4108
4259
|
return this.get(accountId);
|
|
@@ -4121,8 +4272,10 @@ var ModelCatalog = class ModelCatalog {
|
|
|
4121
4272
|
* switching to a Pro/Ultra account).
|
|
4122
4273
|
*/
|
|
4123
4274
|
async forceRefreshAndNotify(accountId) {
|
|
4275
|
+
const hadCatalog = accountId ? this.hasAccountCatalog(accountId) : true;
|
|
4124
4276
|
await this.refresh(accountId, false);
|
|
4125
|
-
this.
|
|
4277
|
+
const hasCatalog = accountId ? this.hasAccountCatalog(accountId) : true;
|
|
4278
|
+
if (hadCatalog || hasCatalog) this.onUpdate?.();
|
|
4126
4279
|
return this.get(accountId);
|
|
4127
4280
|
}
|
|
4128
4281
|
/**
|
|
@@ -4181,11 +4334,11 @@ var ModelCatalog = class ModelCatalog {
|
|
|
4181
4334
|
};
|
|
4182
4335
|
function resolveModelSlug(id) {
|
|
4183
4336
|
const s = id.trim().toLowerCase();
|
|
4184
|
-
if (s === "claude-opus") return
|
|
4185
|
-
if (s === "claude-sonnet") return
|
|
4337
|
+
if (s === "claude-opus") return PREFERRED_CLAUDE_OPUS;
|
|
4338
|
+
if (s === "claude-sonnet") return PREFERRED_CLAUDE;
|
|
4186
4339
|
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";
|
|
4187
4340
|
if (s === "claude-sonnet-4.6" || s === "claude-sonnet-4-5") return "claude-sonnet-4-6";
|
|
4188
|
-
if (s === "gpt-oss-120b" || s === "gpt-oss-20b" || s === "gpt-oss") return
|
|
4341
|
+
if (s === "gpt-oss-120b" || s === "gpt-oss-20b" || s === "gpt-oss") return PREFERRED_OPENAI;
|
|
4189
4342
|
const claude55 = s.match(/^(claude-(?:sonnet|opus)-5-5)-(?:low|medium|high)$/);
|
|
4190
4343
|
if (claude55 !== null && claude55[1] !== void 0) return claude55[1];
|
|
4191
4344
|
return id.trim();
|
|
@@ -4222,7 +4375,7 @@ function listAvailableModels(deps) {
|
|
|
4222
4375
|
let models;
|
|
4223
4376
|
if (activeAcc && pool) {
|
|
4224
4377
|
models = deps.catalog.getModelsForAccount(activeAcc, pool);
|
|
4225
|
-
if (!deps.catalog.hasAccountCatalog(activeAcc.id)) deps.catalog.
|
|
4378
|
+
if (!deps.catalog.hasAccountCatalog(activeAcc.id)) deps.catalog.ensureAccountCatalog(activeAcc.id).catch(() => void 0);
|
|
4226
4379
|
} else models = deps.catalog.getUnion(accounts, pool);
|
|
4227
4380
|
const { entries, dropped } = sanitizeCatalogEntries(models);
|
|
4228
4381
|
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)");
|
|
@@ -4256,7 +4409,7 @@ function resolveModelInfo(deps, model) {
|
|
|
4256
4409
|
defaultMaxTokens: typeof cfg.maxTokensDefault === "number" && cfg.maxTokensDefault > 0 ? cfg.maxTokensDefault : 8192
|
|
4257
4410
|
};
|
|
4258
4411
|
if (deps.isEffortUnsupported(cleanId)) {} else if (entry && Array.isArray(entry.efforts) && entry.efforts.length > 0) {
|
|
4259
|
-
const cleanEfforts =
|
|
4412
|
+
const cleanEfforts = normalizeEfforts(entry.efforts);
|
|
4260
4413
|
if (cleanEfforts.length > 0) {
|
|
4261
4414
|
const def = defaultEffortFor({
|
|
4262
4415
|
...entry,
|
|
@@ -4266,7 +4419,7 @@ function resolveModelInfo(deps, model) {
|
|
|
4266
4419
|
resolved.reasoning = {
|
|
4267
4420
|
efforts: cleanEfforts.map((e) => ({
|
|
4268
4421
|
id: e,
|
|
4269
|
-
name: e
|
|
4422
|
+
name: effortLabel(e)
|
|
4270
4423
|
})),
|
|
4271
4424
|
...validDef ? { defaultEffort: validDef } : {}
|
|
4272
4425
|
};
|
|
@@ -4669,6 +4822,17 @@ function nodeScriptEnv(env) {
|
|
|
4669
4822
|
};
|
|
4670
4823
|
}
|
|
4671
4824
|
//#endregion
|
|
4825
|
+
//#region src/common/timeouts.ts
|
|
4826
|
+
/**
|
|
4827
|
+
* Grace the idle watchdog grants before killing a quiet child. libuv runs the
|
|
4828
|
+
* timers phase BEFORE the poll phase: when the DSH host's event loop is blocked
|
|
4829
|
+
* (a large parse, many parallel workers), an expired watchdog can fire before
|
|
4830
|
+
* queued stdout/stderr from a still-active child is delivered. One short grace
|
|
4831
|
+
* lets that output arrive instead of killing a healthy run. Capped at the run's
|
|
4832
|
+
* own idle budget so short-budget tests and genuine idle kills stay prompt.
|
|
4833
|
+
*/
|
|
4834
|
+
const WATCHDOG_GRACE_MS = 5e3;
|
|
4835
|
+
//#endregion
|
|
4672
4836
|
//#region src/host/auto-updater.ts
|
|
4673
4837
|
function nonBlank(v) {
|
|
4674
4838
|
return (v ?? "").trim();
|
|
@@ -4828,6 +4992,7 @@ function createRunState(opts) {
|
|
|
4828
4992
|
settled: false,
|
|
4829
4993
|
idleBudgetMs: opts.timeoutMs,
|
|
4830
4994
|
watchdog: null,
|
|
4995
|
+
watchdogGraceUsed: false,
|
|
4831
4996
|
turnCap: null
|
|
4832
4997
|
};
|
|
4833
4998
|
}
|
|
@@ -4885,13 +5050,22 @@ function writeInitialStdin(opts, child) {
|
|
|
4885
5050
|
} catch {}
|
|
4886
5051
|
}
|
|
4887
5052
|
function makeRefreshWatchdog(child, state) {
|
|
4888
|
-
|
|
4889
|
-
if (!state.idleBudgetMs || state.idleBudgetMs <= 0 || state.settled) return;
|
|
5053
|
+
const arm = (budgetMs) => {
|
|
4890
5054
|
if (state.watchdog) clearTimeout(state.watchdog);
|
|
4891
5055
|
state.watchdog = setTimeout(() => {
|
|
5056
|
+
if (!state.watchdogGraceUsed) {
|
|
5057
|
+
state.watchdogGraceUsed = true;
|
|
5058
|
+
arm(Math.min(budgetMs, WATCHDOG_GRACE_MS));
|
|
5059
|
+
return;
|
|
5060
|
+
}
|
|
4892
5061
|
state.timedOut = true;
|
|
4893
5062
|
killTree(child);
|
|
4894
|
-
},
|
|
5063
|
+
}, budgetMs);
|
|
5064
|
+
};
|
|
5065
|
+
return () => {
|
|
5066
|
+
if (!state.idleBudgetMs || state.idleBudgetMs <= 0 || state.settled) return;
|
|
5067
|
+
state.watchdogGraceUsed = false;
|
|
5068
|
+
arm(state.idleBudgetMs);
|
|
4895
5069
|
};
|
|
4896
5070
|
}
|
|
4897
5071
|
function armTurnCap(child, opts, state) {
|
|
@@ -5687,9 +5861,9 @@ function crossFamilyFallback(deps, family) {
|
|
|
5687
5861
|
const pool = deps.pool;
|
|
5688
5862
|
if (pool === void 0) return null;
|
|
5689
5863
|
const familyModel = {
|
|
5690
|
-
google:
|
|
5691
|
-
anthropic:
|
|
5692
|
-
openai:
|
|
5864
|
+
google: PREFERRED_GEMINI_FLASH,
|
|
5865
|
+
anthropic: PREFERRED_CLAUDE,
|
|
5866
|
+
openai: PREFERRED_OPENAI
|
|
5693
5867
|
};
|
|
5694
5868
|
for (const fbFam of [
|
|
5695
5869
|
"google",
|
|
@@ -6583,14 +6757,15 @@ function writeJsonAtomic(file, body) {
|
|
|
6583
6757
|
} catch {}
|
|
6584
6758
|
throw lastErr;
|
|
6585
6759
|
}
|
|
6586
|
-
function defaultPoolDir(home
|
|
6587
|
-
if (process.env.DSH_STATE_DIR) return join(process.env.DSH_STATE_DIR, "agy-accounts");
|
|
6588
|
-
const
|
|
6760
|
+
function defaultPoolDir(home) {
|
|
6761
|
+
if (home === void 0 && process.env.DSH_STATE_DIR) return join(process.env.DSH_STATE_DIR, "agy-accounts");
|
|
6762
|
+
const effectiveHome = home ?? homedir();
|
|
6763
|
+
const idx = effectiveHome.replace(/\\/g, "/").indexOf("/.dsh/agy-accounts/");
|
|
6589
6764
|
if (idx !== -1) {
|
|
6590
|
-
const realHome =
|
|
6765
|
+
const realHome = effectiveHome.slice(0, idx);
|
|
6591
6766
|
return join(realHome, ".dsh", "agy-accounts");
|
|
6592
6767
|
}
|
|
6593
|
-
return join(
|
|
6768
|
+
return join(effectiveHome, ".dsh", "agy-accounts");
|
|
6594
6769
|
}
|
|
6595
6770
|
/**
|
|
6596
6771
|
* True when a family's cached quota snapshot benches the account.
|
|
@@ -32591,6 +32766,263 @@ function buildAgyEnv(input) {
|
|
|
32591
32766
|
return env;
|
|
32592
32767
|
}
|
|
32593
32768
|
//#endregion
|
|
32769
|
+
//#region src/features/subagent/tracker.ts
|
|
32770
|
+
/**
|
|
32771
|
+
* Swallow the failures a live transcript produces by design — a row still being
|
|
32772
|
+
* written, a file replaced under us — and surface anything else, so a plain code
|
|
32773
|
+
* bug cannot hide behind an empty `catch`.
|
|
32774
|
+
*/
|
|
32775
|
+
function noteFailure(log, what, err) {
|
|
32776
|
+
if (err instanceof SyntaxError) return;
|
|
32777
|
+
const code = err?.code;
|
|
32778
|
+
if (code === "ENOENT" || code === "EACCES" || code === "EPERM" || code === "EBUSY") return;
|
|
32779
|
+
log?.(`subagent tracker: ${what} — ${String(err)}`);
|
|
32780
|
+
}
|
|
32781
|
+
function stripQuotes(s) {
|
|
32782
|
+
if (s.startsWith("\"") && s.endsWith("\"") || s.startsWith("'") && s.endsWith("'")) return s.slice(1, -1);
|
|
32783
|
+
return s;
|
|
32784
|
+
}
|
|
32785
|
+
function parseJsonObj(v) {
|
|
32786
|
+
if (!v) return {};
|
|
32787
|
+
if (typeof v === "object" && !Array.isArray(v)) return v;
|
|
32788
|
+
if (typeof v === "string") try {
|
|
32789
|
+
const p = JSON.parse(v);
|
|
32790
|
+
if (p && typeof p === "object" && !Array.isArray(p)) return p;
|
|
32791
|
+
} catch {}
|
|
32792
|
+
return {};
|
|
32793
|
+
}
|
|
32794
|
+
function stringArg(obj, ...keys) {
|
|
32795
|
+
for (const k of keys) {
|
|
32796
|
+
const v = obj[k];
|
|
32797
|
+
if (typeof v === "string" && v !== "") return stripQuotes(v);
|
|
32798
|
+
}
|
|
32799
|
+
return "";
|
|
32800
|
+
}
|
|
32801
|
+
function formatSubagentAction(role, tool, rawArgs) {
|
|
32802
|
+
const args = parseJsonObj(rawArgs);
|
|
32803
|
+
const prefix = `[子代理 · ${role}]`;
|
|
32804
|
+
switch (tool) {
|
|
32805
|
+
case "view_file":
|
|
32806
|
+
case "read_file": {
|
|
32807
|
+
const p = stringArg(args, "Path", "path", "TargetFile", "target_file", "AbsolutePath", "targetFile");
|
|
32808
|
+
return `${prefix} 正在查阅文件: ${(p ? basename(p.replace(/\\/g, "/")) : "") || p || "file"}`;
|
|
32809
|
+
}
|
|
32810
|
+
case "edit_file":
|
|
32811
|
+
case "replace_file_content":
|
|
32812
|
+
case "write_file":
|
|
32813
|
+
case "create_file": {
|
|
32814
|
+
const p = stringArg(args, "Path", "path", "TargetFile", "target_file", "AbsolutePath");
|
|
32815
|
+
return `${prefix} 正在修改/创建文件: ${(p ? basename(p.replace(/\\/g, "/")) : "") || p || "file"}`;
|
|
32816
|
+
}
|
|
32817
|
+
case "search_web":
|
|
32818
|
+
case "web_search": return `${prefix} 正在检索网络: "${stringArg(args, "query", "Query", "q").slice(0, 80)}"`;
|
|
32819
|
+
case "grep_search":
|
|
32820
|
+
case "find_by_name": return `${prefix} 正在检索代码: "${stringArg(args, "pattern", "Pattern", "query", "Query", "filename", "Target").slice(0, 60)}"`;
|
|
32821
|
+
case "list_dir":
|
|
32822
|
+
case "ls": return `${prefix} 正在浏览目录: ${stringArg(args, "Path", "path", "Directory", "dir") || "."}`;
|
|
32823
|
+
case "run_command":
|
|
32824
|
+
case "bash":
|
|
32825
|
+
case "execute_command": {
|
|
32826
|
+
const summary = stringArg(args, "toolSummary", "description", "Description");
|
|
32827
|
+
const cmd = stringArg(args, "CommandLine", "command_line", "command", "cmd");
|
|
32828
|
+
return `${prefix} 正在执行终端命令: ${summary || cmd.slice(0, 70)}`;
|
|
32829
|
+
}
|
|
32830
|
+
case "generate_image": return `${prefix} 正在生成参考图像: ${stringArg(args, "prompt", "Prompt", "image_name").slice(0, 60)}`;
|
|
32831
|
+
case "send_message": return `${prefix} 阶段调研完成,正在向主代理提交报告`;
|
|
32832
|
+
case "invoke_subagent": return `${prefix} 启动协同专员: ${stringArg(args, "Role", "role", "TypeName", "typeName") || "subagent"}`;
|
|
32833
|
+
case "manage_subagents": return `${prefix} 正在协调子代理状态 (${stringArg(args, "Action", "action") || "status"})`;
|
|
32834
|
+
case "schedule": return `${prefix} 设置后台定时任务`;
|
|
32835
|
+
default: return `${prefix} 执行操作: ${tool}`;
|
|
32836
|
+
}
|
|
32837
|
+
}
|
|
32838
|
+
var SubagentTracker = class {
|
|
32839
|
+
opts;
|
|
32840
|
+
conversationId;
|
|
32841
|
+
accountHome;
|
|
32842
|
+
brainDir = null;
|
|
32843
|
+
trackedSubagents = /* @__PURE__ */ new Map();
|
|
32844
|
+
seenStepKeys = /* @__PURE__ */ new Set();
|
|
32845
|
+
timer = null;
|
|
32846
|
+
active = false;
|
|
32847
|
+
polling = false;
|
|
32848
|
+
pollIntervalMs;
|
|
32849
|
+
constructor(opts) {
|
|
32850
|
+
this.opts = opts;
|
|
32851
|
+
this.conversationId = opts.conversationId ?? "";
|
|
32852
|
+
this.accountHome = opts.accountHome;
|
|
32853
|
+
this.pollIntervalMs = opts.pollIntervalMs ?? 500;
|
|
32854
|
+
}
|
|
32855
|
+
/** Follow the conversation agy reported in its stream-json init/result envelope. */
|
|
32856
|
+
setConversationId(cid) {
|
|
32857
|
+
if (cid === "" || cid === this.conversationId) return;
|
|
32858
|
+
this.conversationId = cid;
|
|
32859
|
+
this.brainDir = null;
|
|
32860
|
+
if (this.active) this.poll();
|
|
32861
|
+
}
|
|
32862
|
+
start() {
|
|
32863
|
+
if (this.active) return;
|
|
32864
|
+
this.active = true;
|
|
32865
|
+
this.poll();
|
|
32866
|
+
this.timer = setInterval(() => this.poll(), this.pollIntervalMs);
|
|
32867
|
+
this.timer.unref?.();
|
|
32868
|
+
}
|
|
32869
|
+
stop() {
|
|
32870
|
+
this.active = false;
|
|
32871
|
+
if (this.timer) {
|
|
32872
|
+
clearInterval(this.timer);
|
|
32873
|
+
this.timer = null;
|
|
32874
|
+
}
|
|
32875
|
+
}
|
|
32876
|
+
/** Run one scan across known conversations and subagents. */
|
|
32877
|
+
poll() {
|
|
32878
|
+
if (this.polling || !this.active) return;
|
|
32879
|
+
if (!this.conversationId) return;
|
|
32880
|
+
this.polling = true;
|
|
32881
|
+
try {
|
|
32882
|
+
if (!this.brainDir) this.brainDir = findBrainDir(this.conversationId, this.accountHome);
|
|
32883
|
+
if (!this.brainDir) return;
|
|
32884
|
+
const convsToScan = [this.conversationId, ...Array.from(this.trackedSubagents.keys())];
|
|
32885
|
+
for (const cid of convsToScan) this.scanSubagentsForConv(cid);
|
|
32886
|
+
for (const sub of this.trackedSubagents.values()) this.pollSubagentTranscript(sub);
|
|
32887
|
+
} catch (err) {
|
|
32888
|
+
noteFailure(this.opts.log, "poll", err);
|
|
32889
|
+
} finally {
|
|
32890
|
+
this.polling = false;
|
|
32891
|
+
}
|
|
32892
|
+
}
|
|
32893
|
+
scanSubagentsForConv(cid) {
|
|
32894
|
+
const bDir = cid === this.conversationId ? this.brainDir : findBrainDir(cid, this.accountHome);
|
|
32895
|
+
if (!bDir) return;
|
|
32896
|
+
const subagentsDir = join(bDir, ".system_generated", "subagents");
|
|
32897
|
+
if (!existsSync(subagentsDir)) return;
|
|
32898
|
+
let files;
|
|
32899
|
+
try {
|
|
32900
|
+
files = readdirSync(subagentsDir);
|
|
32901
|
+
} catch {
|
|
32902
|
+
return;
|
|
32903
|
+
}
|
|
32904
|
+
for (const f of files) {
|
|
32905
|
+
if (!f.endsWith(".json")) continue;
|
|
32906
|
+
const fullPath = join(subagentsDir, f);
|
|
32907
|
+
try {
|
|
32908
|
+
const raw = readFileSync(fullPath, "utf8");
|
|
32909
|
+
const obj = JSON.parse(raw);
|
|
32910
|
+
const subId = typeof obj?.conversationId === "string" ? obj.conversationId : f.replace(/\.json$/, "");
|
|
32911
|
+
if (!subId || this.trackedSubagents.has(subId)) continue;
|
|
32912
|
+
const desc = obj?.subagentDescriptor;
|
|
32913
|
+
const role = typeof desc?.role === "string" && desc.role !== "" ? desc.role : "专员";
|
|
32914
|
+
const typeName = typeof desc?.typeName === "string" && desc.typeName !== "" ? desc.typeName : "Subagent";
|
|
32915
|
+
const tracked = {
|
|
32916
|
+
conversationId: subId,
|
|
32917
|
+
role,
|
|
32918
|
+
typeName,
|
|
32919
|
+
brainDir: findBrainDir(subId, this.accountHome) ?? join(bDir, "..", subId),
|
|
32920
|
+
offset: 0,
|
|
32921
|
+
rest: "",
|
|
32922
|
+
lines: 0
|
|
32923
|
+
};
|
|
32924
|
+
this.trackedSubagents.set(subId, tracked);
|
|
32925
|
+
const spawnKey = `subagent-spawn-${subId}`;
|
|
32926
|
+
if (!this.seenStepKeys.has(spawnKey)) {
|
|
32927
|
+
this.seenStepKeys.add(spawnKey);
|
|
32928
|
+
const ev = {
|
|
32929
|
+
kind: "step",
|
|
32930
|
+
stepKey: spawnKey,
|
|
32931
|
+
stepKind: "subagent",
|
|
32932
|
+
text: `[子代理 · ${role}] 已启动协同专员 (${typeName})\n`,
|
|
32933
|
+
raw: obj
|
|
32934
|
+
};
|
|
32935
|
+
this.opts.onEvent(ev);
|
|
32936
|
+
this.opts.noteActivity?.();
|
|
32937
|
+
}
|
|
32938
|
+
} catch (err) {
|
|
32939
|
+
noteFailure(this.opts.log, `descriptor ${f}`, err);
|
|
32940
|
+
}
|
|
32941
|
+
}
|
|
32942
|
+
}
|
|
32943
|
+
/**
|
|
32944
|
+
* Read the transcript lines appended since the last poll.
|
|
32945
|
+
*
|
|
32946
|
+
* agy rewrites nothing and only appends, so the tracker keeps a byte offset
|
|
32947
|
+
* instead of re-reading (and re-splitting) a transcript that grows to hundreds
|
|
32948
|
+
* of kilobytes: each poll costs one bounded read of the new bytes.
|
|
32949
|
+
*/
|
|
32950
|
+
readNewLines(sub) {
|
|
32951
|
+
const logPath = join(sub.brainDir, ".system_generated", "logs", "transcript.jsonl");
|
|
32952
|
+
let size;
|
|
32953
|
+
try {
|
|
32954
|
+
const st = statSync(logPath);
|
|
32955
|
+
if (!st.isFile()) return [];
|
|
32956
|
+
size = st.size;
|
|
32957
|
+
} catch {
|
|
32958
|
+
return [];
|
|
32959
|
+
}
|
|
32960
|
+
if (size < sub.offset) {
|
|
32961
|
+
sub.offset = 0;
|
|
32962
|
+
sub.rest = "";
|
|
32963
|
+
}
|
|
32964
|
+
if (size === sub.offset) return [];
|
|
32965
|
+
const length = size - sub.offset;
|
|
32966
|
+
const buffer = Buffer.allocUnsafe(length);
|
|
32967
|
+
try {
|
|
32968
|
+
const fd = openSync(logPath, "r");
|
|
32969
|
+
try {
|
|
32970
|
+
readSync(fd, buffer, 0, length, sub.offset);
|
|
32971
|
+
} finally {
|
|
32972
|
+
closeSync(fd);
|
|
32973
|
+
}
|
|
32974
|
+
} catch {
|
|
32975
|
+
return [];
|
|
32976
|
+
}
|
|
32977
|
+
sub.offset = size;
|
|
32978
|
+
const parts = (sub.rest + buffer.toString("utf8")).split("\n");
|
|
32979
|
+
sub.rest = parts.pop() ?? "";
|
|
32980
|
+
return parts.filter((line) => line.trim() !== "");
|
|
32981
|
+
}
|
|
32982
|
+
pollSubagentTranscript(sub) {
|
|
32983
|
+
for (const line of this.readNewLines(sub)) try {
|
|
32984
|
+
const o = JSON.parse(line);
|
|
32985
|
+
sub.lines += 1;
|
|
32986
|
+
const stepIdx = typeof o.step_index === "number" ? o.step_index : sub.lines;
|
|
32987
|
+
const baseKey = `subagent-${sub.conversationId}-${stepIdx}`;
|
|
32988
|
+
if (Array.isArray(o.tool_calls) && o.tool_calls.length > 0) for (let tcIdx = 0; tcIdx < o.tool_calls.length; tcIdx++) {
|
|
32989
|
+
const tc = o.tool_calls[tcIdx];
|
|
32990
|
+
const toolName = typeof tc?.name === "string" ? tc.name : "";
|
|
32991
|
+
if (toolName === "") continue;
|
|
32992
|
+
const k = `${baseKey}-tc-${tcIdx}`;
|
|
32993
|
+
if (this.seenStepKeys.has(k)) continue;
|
|
32994
|
+
this.seenStepKeys.add(k);
|
|
32995
|
+
const ev = {
|
|
32996
|
+
kind: "step",
|
|
32997
|
+
stepKey: k,
|
|
32998
|
+
stepKind: "subagent",
|
|
32999
|
+
text: `${formatSubagentAction(sub.role, toolName, tc.args)}\n`,
|
|
33000
|
+
raw: o
|
|
33001
|
+
};
|
|
33002
|
+
this.opts.onEvent(ev);
|
|
33003
|
+
this.opts.noteActivity?.();
|
|
33004
|
+
}
|
|
33005
|
+
else if (o.type === "PLANNER_RESPONSE" && typeof o.content === "string" && o.content.trim() !== "") {
|
|
33006
|
+
const k = `${baseKey}-content`;
|
|
33007
|
+
if (this.seenStepKeys.has(k)) continue;
|
|
33008
|
+
this.seenStepKeys.add(k);
|
|
33009
|
+
const firstLine = o.content.trim().split("\n")[0].replace(/^#+\s*/, "").slice(0, 100);
|
|
33010
|
+
if (firstLine !== "") {
|
|
33011
|
+
const ev = {
|
|
33012
|
+
kind: "step",
|
|
33013
|
+
stepKey: k,
|
|
33014
|
+
stepKind: "subagent",
|
|
33015
|
+
text: `[子代理 · ${sub.role}] 阶段进展: ${firstLine}\n`,
|
|
33016
|
+
raw: o
|
|
33017
|
+
};
|
|
33018
|
+
this.opts.onEvent(ev);
|
|
33019
|
+
this.opts.noteActivity?.();
|
|
33020
|
+
}
|
|
33021
|
+
}
|
|
33022
|
+
} catch {}
|
|
33023
|
+
}
|
|
33024
|
+
};
|
|
33025
|
+
//#endregion
|
|
32594
33026
|
//#region src/provider/attempt.ts
|
|
32595
33027
|
function brief$1(s) {
|
|
32596
33028
|
const flat = s.trim().replace(/\s+/g, " ");
|
|
@@ -32731,7 +33163,7 @@ function createToolWatchdog(log, cfg) {
|
|
|
32731
33163
|
};
|
|
32732
33164
|
}
|
|
32733
33165
|
/** Create the recording, parser, HOME snapshot and tool watchdog for one run. */
|
|
32734
|
-
function createAttemptRecorder(deps, cfg, account) {
|
|
33166
|
+
function createAttemptRecorder(deps, cfg, account, initialConversationId) {
|
|
32735
33167
|
const rec = deps.runs.create();
|
|
32736
33168
|
rec.accountHome = account && account.dir ? account.dir : void 0;
|
|
32737
33169
|
const conversationsDir = conversationsDirFor(rec.accountHome);
|
|
@@ -32739,20 +33171,41 @@ function createAttemptRecorder(deps, cfg, account) {
|
|
|
32739
33171
|
const parser = new StreamJsonParser();
|
|
32740
33172
|
deps.onParser?.(parser);
|
|
32741
33173
|
const watchdog = createToolWatchdog(deps.log, cfg);
|
|
33174
|
+
const tracker = new SubagentTracker({
|
|
33175
|
+
conversationId: initialConversationId,
|
|
33176
|
+
accountHome: rec.accountHome,
|
|
33177
|
+
log: deps.log,
|
|
33178
|
+
onEvent: (ev) => {
|
|
33179
|
+
rec.append(ev);
|
|
33180
|
+
},
|
|
33181
|
+
noteActivity: () => {
|
|
33182
|
+
watchdog.markEvent();
|
|
33183
|
+
}
|
|
33184
|
+
});
|
|
32742
33185
|
const state = {
|
|
32743
33186
|
rec,
|
|
32744
33187
|
parser,
|
|
32745
33188
|
conversationsDir,
|
|
32746
33189
|
before,
|
|
32747
|
-
streamCid: null,
|
|
33190
|
+
streamCid: initialConversationId ?? null,
|
|
32748
33191
|
printTimeoutMinutes: watchdog.printTimeoutMinutes,
|
|
32749
|
-
attachProcess: (proc) =>
|
|
33192
|
+
attachProcess: (proc) => {
|
|
33193
|
+
watchdog.attach(proc);
|
|
33194
|
+
tracker.start();
|
|
33195
|
+
proc.outcome.finally(() => tracker.stop());
|
|
33196
|
+
},
|
|
32750
33197
|
feedLine: (line, onEvent, onFirstEvent) => {
|
|
32751
33198
|
watchdog.markEvent();
|
|
32752
33199
|
onFirstEvent?.();
|
|
32753
33200
|
for (const ev of parser.feed(line + "\n")) {
|
|
32754
|
-
if (ev.kind === "init" && ev.conversationId)
|
|
32755
|
-
|
|
33201
|
+
if (ev.kind === "init" && ev.conversationId) {
|
|
33202
|
+
state.streamCid = ev.conversationId;
|
|
33203
|
+
tracker.setConversationId(ev.conversationId);
|
|
33204
|
+
}
|
|
33205
|
+
if (ev.kind === "result" && ev.conversationId !== "") {
|
|
33206
|
+
state.streamCid = ev.conversationId;
|
|
33207
|
+
tracker.setConversationId(ev.conversationId);
|
|
33208
|
+
}
|
|
32756
33209
|
watchdog.trackStep(ev);
|
|
32757
33210
|
rec.append(ev);
|
|
32758
33211
|
if (typeof onEvent === "function") try {
|
|
@@ -32762,14 +33215,20 @@ function createAttemptRecorder(deps, cfg, account) {
|
|
|
32762
33215
|
},
|
|
32763
33216
|
drain: (onEvent) => {
|
|
32764
33217
|
for (const ev of parser.flush()) {
|
|
32765
|
-
if (ev.kind === "result" && ev.conversationId !== "")
|
|
33218
|
+
if (ev.kind === "result" && ev.conversationId !== "") {
|
|
33219
|
+
state.streamCid = ev.conversationId;
|
|
33220
|
+
tracker.setConversationId(ev.conversationId);
|
|
33221
|
+
}
|
|
32766
33222
|
rec.append(ev);
|
|
32767
33223
|
if (typeof onEvent === "function") try {
|
|
32768
33224
|
onEvent(ev);
|
|
32769
33225
|
} catch {}
|
|
32770
33226
|
}
|
|
32771
33227
|
},
|
|
32772
|
-
stop: () =>
|
|
33228
|
+
stop: () => {
|
|
33229
|
+
watchdog.stop();
|
|
33230
|
+
tracker.stop();
|
|
33231
|
+
},
|
|
32773
33232
|
conversationId: () => state.streamCid ?? diffConversations(before, conversationsDir).conversationId
|
|
32774
33233
|
};
|
|
32775
33234
|
return state;
|
|
@@ -33322,7 +33781,7 @@ async function handleAttemptOutcome(deps, input, ctx) {
|
|
|
33322
33781
|
* queue notices; the outcome closure runs detached exactly as before.
|
|
33323
33782
|
*/
|
|
33324
33783
|
async function* runAgyAttempt(deps, input) {
|
|
33325
|
-
const recorder = createAttemptRecorder(deps, input.cfg, input.account);
|
|
33784
|
+
const recorder = createAttemptRecorder(deps, input.cfg, input.account, input.binding?.conversationId);
|
|
33326
33785
|
const spawn = buildSpawnArgs(input, recorder.printTimeoutMinutes, deps.log);
|
|
33327
33786
|
const slot = yield* dispatchCredentialSlot(deps, {
|
|
33328
33787
|
...input,
|