@lynn123411/dsh-subagent-judge-dispatch 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DETAILS.md +2 -2
- package/README.md +1 -1
- package/lib/index.js +66 -28
- package/lib/index.js.map +3 -3
- package/package.json +15 -15
package/DETAILS.md
CHANGED
|
@@ -33,7 +33,7 @@ dsh plugin --profile web add @lynn123411/dsh-subagent-judge-dispatch
|
|
|
33
33
|
|
|
34
34
|
## 判断与改写
|
|
35
35
|
|
|
36
|
-
- **插手位置**:宿主的 `agent/
|
|
36
|
+
- **插手位置**:宿主的 `agent/created` 钩子。注册在根层上下文,每个代理创建时都会经过;插件自己用 `subagentDepth`(会话头里的 `delegationDepth` 与运行时 `options.subagentDepth` 取较大者)筛出子代理。宿主在释放子代理排队工作前 await 这个钩子,所以这里用 `agent.model.select()` 定下的路线就是它第一步用的路线;`agent/request` 不能用于这件事——那一步的选择已经定死,改提供方或模型会被宿主拒绝;0.2.2 起该钩子已标为 deprecated,官方迁移方向正是 `agent.model.select()`。
|
|
37
37
|
- **判断次数**:按子代理 id 记住已判过的,一个跑十步的子代理只问一次。
|
|
38
38
|
- **判断模型读到的任务**:先是派出这次活的标签(`subagent/descriptor` 的 `label`,宿主用它当子会话标题),再是任务正文原文,两段之间空一行。标签只有三五个词,是派工方写的摘要;正文才是「这个活到底要做什么」。只发标签,判断只能看出个大概方向;只发正文,遇到开头是套话的任务就丢了派工方的意图。
|
|
39
39
|
- **任务正文怎么取**:取子代理自己那条 `source.kind === 'user'` 的消息。用户角色不等于任务——工作目录提示、工作区指令、运行时快照、技能清单、时间快照都写成用户消息,按来源筛才分得开。这条消息在子代理一生里以两种形状出现,两种都要认:派工那一刻它是收件箱里的待办(`agent/inbox/spliced` 事件里 `inserted` 的那条),宿主在步边界认领之后才写成 `user/message`。判断发生在步内的那次请求里,比写成 `user/message` 早,只认后者会在唯一要紧的那次请求上读空、只剩标签。宿主的返回指引(「你的父代理 id 是……完事用 `send_message` 回报」)是那条消息末尾追加的一个文本块,讲的是怎么交作业,不算任务,取正文时整块去掉。
|
|
@@ -84,7 +84,7 @@ cd plugins/dsh-subagent-judge-dispatch && pnpm check
|
|
|
84
84
|
`check` = `typecheck` + `build` + 五个自检 + `assert:lib-untracked`:
|
|
85
85
|
|
|
86
86
|
- **`scripts/test-decision.mjs`** 打的是 `src/`(Node 直接跑 `.ts`),守判断与改写这条纯逻辑:失败时**按身份**退回同一个对象(不是深比较——深比较会放过「复制一份再写回原值」这种仍然算覆盖的写法)、三项同写、残缺行不生效、答复读取的三种形状与七种空答复、四种失败原因各自的归类、超时不重试、日志文件留 200 条、页面只取最近 10 条、换一个 LogStore 实例也读得回来、文件缺失或残缺都不抛、读出来是副本,编号按位置从 1 连着。它还守判断模型读到的输入:标签在前正文在后、没标签时只发正文、两样都没有时输入为空、短任务一字不动、长任务留头尾并写明省掉多少字、刚好到上限的不算截断。另有一条守「判断带回的提示词就是发出去的那一段」:成功、失败、没发出请求三种情形各一条。
|
|
87
|
-
- **`scripts/smoke-host.mjs`** 起真 cordis `Context`,把 `agent/
|
|
87
|
+
- **`scripts/smoke-host.mjs`** 起真 cordis `Context`,把 `agent/created` 钩子按宿主的方式跑一遍(判定后断言 `agent.model.select()` 收到了什么;判定没成时断言一次都没调):主代理不被判断、同一子代理只判一次、两个开关各自的短路、发送出去的请求体形状、判断输入是标签加正文两段、正文按 `source.kind` 取(工作目录提示不算任务)、新建子代理时从父会话刚记录的派工调用里按标签取正文、派工消息还在收件箱里与已经落盘成 `user/message` 两种形状都读得到、宿主追加的返回指引不送进去、长任务留头尾且写明省掉多少字、没有描述时取任务正文、叉出来的子代理只读自己的事件、日志的子代理一栏只写标签、判断过的记忆有上限。它的夹具照真实日志的形状搭:先是 `working-directory` 的通知,再是收件箱里那份待办;两种形状各有一组用例,一组把消息留在收件箱,一组用落盘后的 `user/message`。它另起一个挂着 `connection` 的实例,从日志路由读回那一行,断言 `prompt` 与真正发出去的请求体同值——判断成功与判断失败各一条。
|
|
88
88
|
- **`scripts/smoke-client.mjs`** 按 Web shell 的方式装载 `lib/client.js`(`window.__ModuleLoader__.load` 桩件),喂假 cordis 服务:断言卡片注册进 `plugins.bundle.config`、key 是包名、走 `slots.inject`、读本插件自己的命名空间与宿主那份「子代理可选用哪些模型」设置、以宿主在服务本条目为挂载条件、样式表在 `apply()` 追加一次且没写死色值,以及 zh/en 键集一致。它的守卫带反例断言(「守卫拒绝未声明的服务读取」必须抛),否则那一串绿灯是假的。
|
|
89
89
|
|
|
90
90
|
- **`scripts/test-card.mjs`** 打的是 `src/`,守配置卡片这层状态机:文字格只在提交时写且只写改过的那一项、开关与行的增删当场写、连续两次提交合并成一次写、没填完的行照常写入而页面只在行上提示、宿主回 `false` 算没写进去、密钥跟着判断服务那次提交一起写且写的是固定引用名、密钥值从不进页面状态、草稿按字段保留(宿主改了一项而我在改另一项时,提交只写我改的那一项),「选择」一列只写模型与强度、悬停才带上供应商且两条路都不留悬空的分隔点,以及清单的 JSON 导出与导入各自认什么、拒什么。
|
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
- **只改两样**:只改写子代理使用的模型与思考强度,不改名字、不改标题、不动主对话,其余一概沿用 DSH 原本的派工流程。
|
|
18
18
|
- **判断永不打断派工**:连不上、超过 5 秒、答复对不上清单、答复为空,这四种都算判断失败;失败时一个字段都不写,子代理原样继承主代理的模型与强度,不重试。代价是每次派工最多多等 5 秒。
|
|
19
|
-
-
|
|
19
|
+
- **每个子代理只判一次**:判断挂在宿主公开的「子代理创建」钩子上,由插件自己记住已经判过的子代理,所以一个跑十步的子代理也只问一次。
|
|
20
20
|
- **填完就保存**:没有保存按钮。文字格离开输入框就写,开关与行的增删当场写,写入失败在那一节底部就地说明;切到日志标签或离开插件页之前,还没离开输入框的那一格也会先写下去。
|
|
21
21
|
- **密钥只写不读**:密钥值一交出去就不再留在页面状态里;页面只显示「已存 / 还没有」,以及一个删掉它的按钮。
|
|
22
22
|
- **形态与装配**:bundle 型插件,装完即用、在 profile 里不用手写补丁;装配、开发副本与验证见 [DETAILS.md](./DETAILS.md)。
|
package/lib/index.js
CHANGED
|
@@ -169,15 +169,6 @@ function outcomeReason(outcome, decision) {
|
|
|
169
169
|
if (outcome.kind !== "matched") return outcome.reason;
|
|
170
170
|
return "incomplete";
|
|
171
171
|
}
|
|
172
|
-
function applyDecision(config, decision) {
|
|
173
|
-
if (decision.kind === "none") return config;
|
|
174
|
-
return {
|
|
175
|
-
...config,
|
|
176
|
-
provider: decision.rewrite.provider,
|
|
177
|
-
model: decision.rewrite.model,
|
|
178
|
-
reasoningEffort: decision.rewrite.reasoningEffort
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
172
|
|
|
182
173
|
// src/server/identity.ts
|
|
183
174
|
function ownEventsOf(session) {
|
|
@@ -223,6 +214,44 @@ function readTaskText(agent) {
|
|
|
223
214
|
}
|
|
224
215
|
return "";
|
|
225
216
|
}
|
|
217
|
+
function readDelegatedTask(agent, parentSessionOf) {
|
|
218
|
+
const own = readTaskText(agent);
|
|
219
|
+
if (own !== "") return own;
|
|
220
|
+
const parentId = agent.session.header.parentSession;
|
|
221
|
+
if (typeof parentId !== "string" || parentId === "") return "";
|
|
222
|
+
const parent = parentSessionOf(parentId);
|
|
223
|
+
if (parent === void 0 || typeof parent.snapshotEvents !== "function") return "";
|
|
224
|
+
const label = readChildLabel(agent);
|
|
225
|
+
const events = parent.snapshotEvents();
|
|
226
|
+
let fallback = "";
|
|
227
|
+
for (let index = events.length - 1; index >= 0; index -= 1) {
|
|
228
|
+
const event = events[index];
|
|
229
|
+
if (event.type !== "tool/call") continue;
|
|
230
|
+
const call = delegatedCallOf(event.data);
|
|
231
|
+
if (call === void 0) continue;
|
|
232
|
+
if (label !== "" && call.description === label) return call.prompt;
|
|
233
|
+
if (fallback === "") fallback = call.prompt;
|
|
234
|
+
}
|
|
235
|
+
return fallback;
|
|
236
|
+
}
|
|
237
|
+
function delegatedCallOf(data) {
|
|
238
|
+
if (typeof data !== "object" || data === null) return void 0;
|
|
239
|
+
const raw = data.arguments;
|
|
240
|
+
if (typeof raw !== "string") return void 0;
|
|
241
|
+
let parsed;
|
|
242
|
+
try {
|
|
243
|
+
parsed = JSON.parse(raw);
|
|
244
|
+
} catch {
|
|
245
|
+
return void 0;
|
|
246
|
+
}
|
|
247
|
+
if (typeof parsed !== "object" || parsed === null) return void 0;
|
|
248
|
+
const record = parsed;
|
|
249
|
+
if (typeof record.prompt !== "string" || record.prompt.trim() === "") return void 0;
|
|
250
|
+
return {
|
|
251
|
+
prompt: record.prompt,
|
|
252
|
+
...typeof record.description === "string" ? { description: record.description } : {}
|
|
253
|
+
};
|
|
254
|
+
}
|
|
226
255
|
function delegationMessagesOf(event) {
|
|
227
256
|
if (event.type === "user/message") {
|
|
228
257
|
return sourceOf(event.data)?.kind === "user" ? [event.data] : [];
|
|
@@ -359,7 +388,7 @@ async function judgeTaskType(endpoint, rows, subject, fetchImpl = fetch) {
|
|
|
359
388
|
import * as fs from "node:fs/promises";
|
|
360
389
|
import * as path from "node:path";
|
|
361
390
|
|
|
362
|
-
// node_modules/.pnpm/@deepseek-ai+dsh-home-paths@0.2.
|
|
391
|
+
// node_modules/.pnpm/@deepseek-ai+dsh-home-paths@0.2.2-rc.1_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-home-paths/lib/index.js
|
|
363
392
|
import { homedir } from "node:os";
|
|
364
393
|
import { basename, dirname, join, resolve } from "node:path";
|
|
365
394
|
var DSH_HOME_DIR_NAME = ".dsh";
|
|
@@ -591,28 +620,37 @@ function apply(ctx, config) {
|
|
|
591
620
|
"dsh-subagent-judge-dispatch: settings page policy"
|
|
592
621
|
);
|
|
593
622
|
});
|
|
594
|
-
ctx.on("agent/
|
|
595
|
-
const resolved = await next();
|
|
623
|
+
ctx.on("agent/created", async (payload) => {
|
|
596
624
|
const agent = payload?.agent;
|
|
597
|
-
if (agent === void 0) return
|
|
625
|
+
if (agent === void 0) return;
|
|
598
626
|
const cfg = resolvedConfig();
|
|
599
|
-
if (!isSubagent(agent) || !cfg.enabled) return
|
|
600
|
-
if (judged.has(agent.id)) return
|
|
601
|
-
if (!isJudgeUsable(cfg)) return
|
|
627
|
+
if (!isSubagent(agent) || !cfg.enabled) return;
|
|
628
|
+
if (judged.has(agent.id)) return;
|
|
629
|
+
if (!isJudgeUsable(cfg)) return;
|
|
602
630
|
judged.add(agent.id);
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
{
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
631
|
+
try {
|
|
632
|
+
const label = readChildLabel(agent);
|
|
633
|
+
const taskText = readDelegatedTask(agent, (id) => ctx.sessions.get(id));
|
|
634
|
+
const inherited = agent.model.current() ?? { provider: "", model: "" };
|
|
635
|
+
const outcome = await judgeTaskType(
|
|
636
|
+
{ url: cfg.endpointUrl, model: cfg.judgeModel, apiKey },
|
|
637
|
+
selectableRows(cfg.rows),
|
|
638
|
+
composeJudgeSubject(label, taskText)
|
|
639
|
+
);
|
|
640
|
+
const decision = decideRewrite(outcome);
|
|
641
|
+
if (decision.kind === "rewrite") {
|
|
642
|
+
agent.model.select({
|
|
643
|
+
provider: decision.rewrite.provider,
|
|
644
|
+
model: decision.rewrite.model,
|
|
645
|
+
reasoningEffort: decision.rewrite.reasoningEffort
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
if (cfg.logEnabled) {
|
|
649
|
+
await logReady;
|
|
650
|
+
log.append(buildEntry(ctx, agent, inherited, decision, outcome, label, taskText));
|
|
651
|
+
}
|
|
652
|
+
} catch {
|
|
614
653
|
}
|
|
615
|
-
return applyDecision(resolved, decision);
|
|
616
654
|
});
|
|
617
655
|
ctx.inject(["connection"], (connectionCtx) => {
|
|
618
656
|
const routes = createFetchRoutes({
|
package/lib/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/server/config.ts", "../src/server/judge-prompt.ts", "../src/server/credentials.ts", "../src/server/dispatch.ts", "../src/server/identity.ts", "../src/server/judge-client.ts", "../src/server/log-store.ts", "../node_modules/.pnpm/@deepseek-ai+dsh-home-paths@0.2.
|
|
4
|
-
"sourcesContent": ["/**\n * This plugin's Config schema and the live read face the wiring consumes.\n *\n * Every field is `volatile()`, which is what lets the configuration card on the\n * Plugins page commit an edit into these refs without remounting the plugin:\n * the wiring reads the current value on every delegation rather than a snapshot\n * taken when the Host loaded.\n *\n * The type-list rows carry no sequence number. The page assigns `1..n` from the\n * array order, the judge answers with that number, and the log shows it \u2014 so a\n * number can never be duplicated, and the reader never has to maintain one.\n */\n\nimport type { Volatile } from '@deepseek-ai/cordis';\nimport z from '@deepseek-ai/schemastery';\nimport type Schema from '@deepseek-ai/schemastery';\nimport { isSelectableRow } from './judge-prompt.ts';\nimport type { TypeRow } from './types.ts';\n\n/**\n * The settings namespace this plugin owns. A namespace IS the Profile entry id,\n * so the user-editable layer is this plugin's own row in the active profile's\n * patch \u2014 the same literal as the `id` in `cordis.patch.yml`, and a different\n * literal from the npm package name the card is keyed by.\n */\nexport const SETTINGS_NAMESPACE = 'dsh-subagent-judge-dispatch';\n\n/** Endpoint the page prefills: one System One example. */\nexport const DEFAULT_ENDPOINT_URL = 'http://127.0.0.1:3425/v1/systemone';\n\n/** Judge model the page prefills. */\nexport const DEFAULT_JUDGE_MODEL = 'future-jev/jev-latest';\n\n/** One type-list row as the configuration document stores it. */\nconst TypeRowSchema = z.object({\n /** Criterion text the judge reads for this type. */\n description: z.string().default(''),\n /** Provider route of the model this type runs on. */\n provider: z.string().default(''),\n /** Model id interpreted by that provider. */\n model: z.string().default(''),\n /** Reasoning effort id this type runs at. */\n effort: z.string().default(''),\n});\n\n/** This plugin's live configuration. */\nexport const Config: Schema = z.object({\n /** Whether a judgement may rewrite a subagent's model and effort. */\n enabled: z.boolean().default(true).volatile(),\n /** Whether judgements are written to the plugin's own log. */\n logEnabled: z.boolean().default(true).volatile(),\n /** Full judge endpoint URL. */\n endpointUrl: z.string().default(DEFAULT_ENDPOINT_URL).volatile(),\n /** Judge model id. */\n judgeModel: z.string().default(DEFAULT_JUDGE_MODEL).volatile(),\n /** The task-type list, in page order. */\n rows: z.array(TypeRowSchema).default([]).volatile(),\n});\n\n/** Fields of this plugin's Config as the runtime resolved them. */\nexport interface PluginConfigRefs {\n readonly enabled: Volatile<boolean>;\n readonly logEnabled: Volatile<boolean>;\n readonly endpointUrl: Volatile<string>;\n readonly judgeModel: Volatile<string>;\n readonly rows: Volatile<StoredRow[]>;\n}\n\n/** One stored row, before the page assigns its sequence number. */\nexport interface StoredRow {\n description: string;\n provider: string;\n model: string;\n effort: string;\n}\n\n/** A detached plain read of this plugin's configuration. */\nexport interface ResolvedConfig {\n enabled: boolean;\n logEnabled: boolean;\n endpointUrl: string;\n judgeModel: string;\n rows: TypeRow[];\n}\n\n/**\n * Read the current committed value of every Config field, numbering the rows.\n * @param refs - the runtime-resolved Config object.\n * @returns a detached plain config value.\n */\nexport function readPluginConfig(refs: PluginConfigRefs): ResolvedConfig {\n const stored = refs.rows.get();\n const rows: TypeRow[] = (Array.isArray(stored) ? stored : []).map((row, index) => ({\n // The number is positional, so deleting a row renumbers the rest. A log\n // entry written before that edit may therefore name a different type; the\n // reader accepted that when choosing continuous numbering.\n id: index + 1,\n description: typeof row?.description === 'string' ? row.description : '',\n provider: typeof row?.provider === 'string' ? row.provider : '',\n model: typeof row?.model === 'string' ? row.model : '',\n effort: typeof row?.effort === 'string' ? row.effort : '',\n }));\n return {\n enabled: refs.enabled.get() !== false,\n logEnabled: refs.logEnabled.get() !== false,\n endpointUrl: typeof refs.endpointUrl.get() === 'string' ? refs.endpointUrl.get() : DEFAULT_ENDPOINT_URL,\n judgeModel: typeof refs.judgeModel.get() === 'string' ? refs.judgeModel.get() : DEFAULT_JUDGE_MODEL,\n rows,\n };\n}\n\n/**\n * Whether a judgement would do anything at all: the model-rewrite switch is on,\n * a judge endpoint and model are named, and at least one row is selectable.\n *\n * @param config - the resolved configuration.\n * @returns whether a delegation would be judged.\n */\nexport function isJudgeUsable(config: ResolvedConfig): boolean {\n if (!config.enabled) return false;\n if (config.endpointUrl.trim() === '' || config.judgeModel.trim() === '') return false;\n return config.rows.some(isSelectableRow);\n}\n", "/**\n * The judgement request the plugin sends, and the answer it reads back.\n *\n * Two pure functions live here, so the whole \"what did the judge decide\"\n * question is answerable without a Host, a socket, or a timer:\n *\n * - {@link buildJudgeRequest} turns the type list plus the task text into the\n * exact body that goes out.\n * - {@link readJudgeAnswer} turns whatever came back into a decision, treating\n * every malformed, empty or off-list answer as \"no decision\" rather than\n * inventing one.\n *\n * The protocol is the System One one: POST a body of `{ model, state,\n * questions }`, where each question is a `choice` carrying an `instructions`\n * line and a `criteria` map of option id to the text that option means. The\n * answer names the chosen option id.\n */\n\nimport type { TypeRow } from './types.ts';\n\n/** The one question key the plugin asks. */\nexport const QUESTION_KEY = 'task_type';\n\n/**\n * The question's instructions line.\n *\n * It says what to weigh, not what the types are: the types themselves arrive as\n * the criteria map, so the reader's own descriptions are the whole criterion\n * list and nothing here can drift from them.\n */\nexport const QUESTION_INSTRUCTIONS =\n 'Which single task type below does the delegated job best match? '\n + 'Weigh what the job actually requires, not how it is phrased. '\n + 'Answer with the number of exactly one listed type.';\n\n/** The option id the connectivity check offers: the only one it offers. */\nexport const PROBE_OPTION_ID = '1';\n\n/** The task text the connectivity check sends. */\nexport const PROBE_TASK_TEXT = '\u8FDE\u63A5\u6D4B\u8BD5\uFF1A\u8FD9\u662F\u4E00\u6B21\u5224\u65AD\u670D\u52A1\u7684\u8FDE\u901A\u6027\u68C0\u67E5\u3002';\n\n/**\n * The connectivity check's instructions.\n *\n * It asks for the one option that exists, so an endpoint that understands the\n * protocol at all can answer it: answering it wrong is a failure of the\n * protocol, not of the reader's task list.\n */\nexport const PROBE_INSTRUCTIONS =\n 'Answer with the number of the one option listed below.';\n\n/** The single criterion the connectivity check offers. */\nexport const PROBE_CRITERION = '\u786E\u8BA4\u8FD9\u6B21\u8C03\u7528\u53EF\u4EE5\u5B8C\u6210\u3002';\n\n/** One option of the judge's question. */\nexport interface JudgeChoice {\n type: 'choice';\n instructions: string;\n criteria: Record<string, string>;\n}\n\n/** The exact body sent to the judge endpoint. */\nexport interface JudgeRequest {\n model: string;\n state: { message: string };\n questions: { [QUESTION_KEY]: JudgeChoice };\n}\n\n/**\n * Whether one row is complete enough to be offered to the judge.\n *\n * A row needs its provider, model and effort: a half-filled row could otherwise\n * be chosen and then have nothing to write, which would turn the reader's\n * unfinished edit into a delegation that silently lost its route. This is the\n * ONE place that rule lives \u2014 the page, the config gate and the rewrite all ask\n * this function rather than restating the three comparisons.\n *\n * The parameter is narrowed to the three fields the rule reads, so the page's\n * draft row (which carries no sequence number) and the server's numbered row\n * both satisfy it without either shape being converted into the other.\n *\n * @param row - one row, numbered or drafted.\n * @returns whether the judge may choose it.\n */\nexport function isSelectableRow(row: Pick<TypeRow, 'provider' | 'model' | 'effort'>): boolean {\n return row.provider.trim() !== '' && row.model.trim() !== '' && row.effort.trim() !== '';\n}\n\n/**\n * Which rows may be offered to the judge.\n * @param rows - every row on the page, in page order.\n * @returns the rows the judge may choose, in page order.\n */\nexport function selectableRows(rows: readonly TypeRow[]): TypeRow[] {\n return rows.filter(isSelectableRow);\n}\n\n/**\n * How much of a delegated task's opening the judge reads.\n *\n * The judge answers one multiple-choice question; the opening of a task says\n * what kind of job it is, and the rest is usually detail the choice does not\n * turn on. Bounding it keeps the request small and keeps one enormous\n * delegation from crowding out the type list it is being weighed against.\n */\nexport const SUBJECT_HEAD_CHARS = 1400;\n\n/**\n * How much of a task's closing the judge reads.\n *\n * Supplementary requirements are written at the end \u2014 \"also run the review\" \u2014\n * so the tail is kept rather than the middle.\n */\nexport const SUBJECT_TAIL_CHARS = 400;\n\n/** Opening words of the label line the judge reads above the task. */\nexport const LABEL_PREFIX = 'Delegation label: ';\n\n/**\n * Build the subject the judge is asked to classify.\n *\n * Two parts, in the order the reader would put them: the delegation's own label\n * \u2014 a summary the delegating agent wrote, which carries its intent \u2014 and then\n * the task text itself. The label alone is a display phrase of a few words, too\n * little to classify by; the task text alone loses that intent when it opens\n * with boilerplate.\n *\n * @param label - the delegation label, or '' when the child has none.\n * @param taskText - the delegated task text, or '' when it cannot be read.\n * @returns the subject to send, bounded to {@link SUBJECT_HEAD_CHARS} plus\n * {@link SUBJECT_TAIL_CHARS} characters of task text.\n */\nexport function composeJudgeSubject(label: string, taskText: string): string {\n const task = clipTaskText(taskText.trim());\n const heading = label.trim();\n if (heading === '') return task;\n return task === '' ? LABEL_PREFIX + heading : `${LABEL_PREFIX}${heading}\\n\\n${task}`;\n}\n\n/**\n * Bound a task text to its opening and closing.\n *\n * The dropped middle is named rather than silently removed, so a reader looking\n * at the logged request can tell truncation from a short task. The marker is\n * English like the rest of the protocol, so it reads as a note from the plugin\n * rather than as part of the task, whatever language the task is written in.\n *\n * @param text - the task text.\n * @returns the text, or its head and tail around a count of what was dropped.\n */\nfunction clipTaskText(text: string): string {\n if (text.length <= SUBJECT_HEAD_CHARS + SUBJECT_TAIL_CHARS) return text;\n const dropped = text.length - SUBJECT_HEAD_CHARS - SUBJECT_TAIL_CHARS;\n const head = text.slice(0, SUBJECT_HEAD_CHARS);\n const tail = text.slice(text.length - SUBJECT_TAIL_CHARS);\n return `${head}\\n\u2026 (${dropped} characters omitted) \u2026\\n${tail}`;\n}\n\n/**\n * Build the exact body sent to the judge endpoint.\n *\n * @param rows - the selectable rows, in page order.\n * @param model - the judge model id.\n * @param subject - the text the judge classifies, from {@link composeJudgeSubject}.\n * @returns the request body.\n */\nexport function buildJudgeRequest(\n rows: readonly TypeRow[],\n model: string,\n subject: string,\n): JudgeRequest {\n const criteria: Record<string, string> = {};\n for (const row of rows) criteria[String(row.id)] = row.description;\n return {\n model,\n state: { message: subject },\n questions: {\n [QUESTION_KEY]: {\n type: 'choice',\n instructions: QUESTION_INSTRUCTIONS,\n criteria,\n },\n },\n };\n}\n\n/**\n * Build the body the connectivity check sends.\n *\n * It carries its own single option rather than the reader's task types: the\n * question the button answers is \"does this endpoint and model work\", and that\n * question has an answer before any type list exists. Requiring a finished list\n * first would make the check unable to tell a reader with an empty list from a\n * reader whose endpoint is down.\n *\n * @param model - the judge model id.\n * @returns the request body.\n */\nexport function buildProbeRequest(model: string): JudgeRequest {\n return {\n model,\n state: { message: PROBE_TASK_TEXT },\n questions: {\n [QUESTION_KEY]: {\n type: 'choice',\n instructions: PROBE_INSTRUCTIONS,\n criteria: { [PROBE_OPTION_ID]: PROBE_CRITERION },\n },\n },\n };\n}\n\n/**\n * Serialize one request body the way the page shows it.\n *\n * Both the preview and a logged judgement display this text, while the call\n * itself sends the same object compacted onto the wire. Deriving both from one\n * body is what keeps the shown text from describing a different request than\n * the one that went out.\n *\n * @param body - the request body.\n * @returns the pretty-printed JSON.\n */\nexport function formatJudgeRequest(body: JudgeRequest): string {\n return JSON.stringify(body, null, 2);\n}\n\n/**\n * The text the configuration page's preview shows.\n *\n * It is the request body minus the subject, because no delegation exists until\n * one happens; the preview marks both spots the subject will fill rather than\n * inventing a task. The two markers are told apart, because the real subject is\n * a label line followed by the task text and the preview should read that way.\n *\n * @param rows - the selectable rows, in page order.\n * @param model - the judge model id.\n * @returns the pretty-printed preview text.\n */\nexport function buildPreview(rows: readonly TypeRow[], model: string): string {\n return formatJudgeRequest(\n buildJudgeRequest(rows, model, composeJudgeSubject('\uFF08\u6D3E\u5DE5\u65F6\u624D\u586B\uFF1A\u6D3E\u5DE5\u6807\u7B7E\uFF09', '\uFF08\u6D3E\u5DE5\u65F6\u624D\u586B\uFF1A\u4EFB\u52A1\u6B63\u6587\uFF09')),\n );\n}\n\n/** What reading the judge's answer produced. */\nexport type JudgeDecision =\n | { kind: 'row'; row: TypeRow }\n | { kind: 'empty' }\n | { kind: 'unmatched' };\n\n/**\n * Find the chosen option id inside whatever the endpoint answered.\n *\n * The protocol's own shape is `answers.<key>.choice`; the two fallbacks are the\n * ones the reference clients read, so an endpoint that answers the shorter way\n * still works. Anything else \u2014 a missing body, a non-string, an empty string \u2014\n * yields `undefined` and is treated as no answer.\n *\n * @param payload - the decoded response body.\n * @returns the chosen option id, or undefined when the body names none.\n */\nexport function readChoice(payload: unknown): string | undefined {\n if (typeof payload !== 'object' || payload === null) return undefined;\n const body = payload as Record<string, unknown>;\n const answers = body.answers;\n const fromAnswers =\n typeof answers === 'object' && answers !== null\n ? (answers as Record<string, unknown>)[QUESTION_KEY]\n : undefined;\n const candidate = fromAnswers ?? body[QUESTION_KEY];\n if (typeof candidate === 'object' && candidate !== null) {\n const choice = (candidate as Record<string, unknown>).choice;\n if (typeof choice === 'string' && choice.trim() !== '') return choice.trim();\n if (typeof choice === 'number' && Number.isFinite(choice)) return String(choice);\n return undefined;\n }\n if (typeof candidate === 'string' && candidate.trim() !== '') return candidate.trim();\n if (typeof candidate === 'number' && Number.isFinite(candidate)) return String(candidate);\n return undefined;\n}\n\n/**\n * Turn the judge's answer into a decision.\n *\n * The choice is the type row's number. Matching is by that number's numeric\n * value, so an endpoint that answers `\"3\"` and one that answers `3` agree; a\n * number no listed row carries is `unmatched`, and a body naming no choice at\n * all is `empty`. Both travel to the log as their own reason, because \"it\n * answered nothing\" and \"it answered something I do not have\" send the reader\n * to different fixes.\n *\n * @param payload - the decoded response body.\n * @param rows - the selectable rows, in page order.\n * @returns the decision.\n */\nexport function readJudgeAnswer(payload: unknown, rows: readonly TypeRow[]): JudgeDecision {\n const choice = readChoice(payload);\n if (choice === undefined) return { kind: 'empty' };\n const wanted = Number(choice);\n if (!Number.isFinite(wanted)) return { kind: 'unmatched' };\n const row = rows.find((candidate) => candidate.id === wanted);\n return row === undefined ? { kind: 'unmatched' } : { kind: 'row', row };\n}\n", "/**\n * Where the judgement key lives, and the Host service it is read through.\n *\n * The reference name is a constant of the plugin rather than a setting: the\n * page asks for the key itself and stores it write-only through the DSH\n * credentials service, so a reader never has to know what a \"credential\n * reference\" is, and no surface can point the plugin at somebody else's key.\n * This module imports nothing, so both halves can share the literal.\n *\n * The key value crosses in one direction only: it is written, and read back by\n * the Host half alone. The browser face reads a status-only view.\n */\n\n/** Credential reference the judgement key is stored under. */\nexport const JUDGE_API_KEY_REF = 'SUBAGENT_JUDGE_API_KEY';\n\n/** Minimal structural shape of the Host's `ctx.credentials` service. */\nexport interface CredentialsServiceLike {\n /** Resolve a reference to its stored or inherited value. */\n resolve(ref: string): Promise<{ value: string; source?: string } | undefined>;\n /** Status-only view of a reference; never returns the plaintext value. */\n describe(ref: string): Promise<{ configured: boolean; source?: string; writable: boolean }>;\n /** Store a non-empty value under a reference. */\n set(ref: string, value: string): Promise<void>;\n /** Remove a reference from the document. */\n unset(ref: string): Promise<void>;\n}\n\n/** Minimal structural shape of the browser's `ctx.remote.credentials` face. */\nexport interface CredentialsRemoteLike {\n describe(refs: string[]): Promise<\n { ok: true; value: Record<string, { configured: boolean; source?: string; writable: boolean }> }\n | { ok: false; error: { message: string } }\n >;\n set(ref: string, value: string): Promise<{ ok: true } | { ok: false; error: { message: string } }>;\n unset(ref: string): Promise<{ ok: true } | { ok: false; error: { message: string } }>;\n}\n", "/**\n * The decision half: given what the judge said, decide exactly what to write\n * onto a subagent's next model call \u2014 or write nothing at all.\n *\n * This module holds the one rule that matters most, so it is a pure function\n * that a test can drive directly: **any** judgement that did not end in a\n * usable row writes nothing. Not \"writes the inherited values\", not \"writes a\n * partial route\" \u2014 nothing. Writing anything is a replacement, so a fallback\n * that wrote the parent's own values back would still be an overwrite, and a\n * partial write would drop the inherited reasoning effort\n * (`resolveChildAgentOptions` deletes it when a route changes without one).\n */\n\nimport { isSelectableRow } from './judge-prompt.ts';\nimport type { FallbackReason, JudgeOutcome, TypeRow } from './types.ts';\n\n/** The three fields a rewrite carries, all present or none at all. */\nexport interface RouteRewrite {\n provider: string;\n model: string;\n reasoningEffort: string;\n}\n\n/** What to write for one judged subagent. */\nexport type DispatchDecision =\n | { kind: 'rewrite'; rewrite: RouteRewrite }\n | { kind: 'none' };\n\n/**\n * Turn a judgement into the rewrite it authorises.\n *\n * The three fields travel as one object because they must be written as one:\n * a route change without an explicit effort makes the Host drop the inherited\n * effort, so a caller can never be handed two of the three.\n *\n * @param outcome - what the judge call produced.\n * @returns the rewrite, or `none` when the child must inherit unchanged.\n */\nexport function decideRewrite(outcome: JudgeOutcome): DispatchDecision {\n if (outcome.kind !== 'matched') return { kind: 'none' };\n const row: TypeRow = outcome.row;\n // A row the judge could select but that is missing a piece is not a rewrite\n // this plugin may make; leaving the child alone is always safe.\n if (!isSelectableRow(row)) return { kind: 'none' };\n return {\n kind: 'rewrite',\n rewrite: {\n provider: row.provider.trim(),\n model: row.model.trim(),\n reasoningEffort: row.effort.trim(),\n },\n };\n}\n\n/**\n * Why a delegation ended up inheriting, as the log reports it.\n *\n * The judge answering nothing, the judge answering a number this list does not\n * have, an unreachable endpoint and an expired budget are four different fixes\n * for the reader \u2014 \"it answered nothing\" points at the endpoint, \"no listed\n * type\" points at the descriptions. A selected row that turned out to be missing\n * a field is a fifth: the judgement worked, the row it named was not usable.\n *\n * A judgement that produced a rewrite has no reason at all.\n *\n * @param outcome - what the judge call produced.\n * @param decision - what was written for it.\n * @returns the reason to record, or undefined when the rewrite landed.\n */\nexport function outcomeReason(\n outcome: JudgeOutcome,\n decision: DispatchDecision,\n): FallbackReason | undefined {\n if (decision.kind === 'rewrite') return undefined;\n if (outcome.kind !== 'matched') return outcome.reason;\n return 'incomplete';\n}\n\n/**\n * Apply a rewrite onto one model-call configuration.\n *\n * The incoming configuration is returned untouched on `none`, which is what\n * makes \"the child inherits exactly what the main agent runs\" true rather than\n * approximated: no field is restated, so nothing about the call changes.\n *\n * @param config - the call configuration the Host resolved.\n * @param decision - what to write.\n * @returns the configuration to use.\n */\nexport function applyDecision<T extends { provider: string; model: string; reasoningEffort?: unknown }>(\n config: T,\n decision: DispatchDecision,\n): T {\n if (decision.kind === 'none') return config;\n return {\n ...config,\n provider: decision.rewrite.provider,\n model: decision.rewrite.model,\n reasoningEffort: decision.rewrite.reasoningEffort,\n };\n}\n", "/**\n * Reading one subagent's identity, from the child Agent alone.\n *\n * Inside `agent/request` the plugin holds a child Agent and nothing else: no\n * delegation record, no parent handle. Everything the log needs \u2014 what the child\n * was asked to do, and which conversation asked for it \u2014 has to be read back out\n * of the child's own durable session facts.\n */\n\n/**\n * The read surface of a Session this module needs; kept structural for tests.\n *\n * `ownEvents` (or `snapshotEvents(inheritedEventCount)`) is the child-owned tail\n * of the log. It matters: a forked child's log opens with the parent's finished\n * turns, so reading from the start would hand the judge the ANCESTOR's\n * descriptor label and the parent conversation's first message.\n */\nexport interface SessionLike {\n readonly header: { readonly parentSession?: string; readonly delegationDepth?: number };\n readonly inheritedEventCount?: number;\n ownEvents?(): readonly SessionEventLike[];\n snapshotEvents(from?: number): readonly SessionEventLike[];\n}\n\n/** One session event as this module reads it. */\nexport interface SessionEventLike {\n readonly type: string;\n readonly data?: unknown;\n}\n\n/** The read surface of an Agent this module needs. */\nexport interface AgentLike {\n readonly id: string;\n readonly options: { readonly subagentDepth?: number };\n readonly session: SessionLike;\n}\n\n/**\n * Read only the events this child itself produced.\n *\n * A forked child inherits the parent's completed prefix, and the inherited part\n * carries an ancestor's descriptor and the parent's own messages. Everything\n * this module reads must come from the child-owned tail, or the judge is told\n * about a different agent's job. Three shapes are accepted because the session\n * type is structural here: `ownEvents()`, `snapshotEvents(from)` with the\n * inherited count, and a plain full read as the last resort.\n *\n * @param session - the child's session.\n * @returns the child-owned events, in log order.\n */\nexport function ownEventsOf(session: SessionLike): readonly SessionEventLike[] {\n if (typeof session.ownEvents === 'function') return session.ownEvents();\n const inherited = session.inheritedEventCount;\n if (typeof inherited === 'number' && Number.isSafeInteger(inherited) && inherited > 0) {\n return session.snapshotEvents(inherited);\n }\n return session.snapshotEvents();\n}\n\n/**\n * Whether one agent is a subagent, rather than a top-level conversation.\n *\n * Two sources are consulted because neither alone is complete: the durable\n * header is authoritative and monotone (a resumed child keeps its depth), while\n * `options.subagentDepth` is stamped onto the live options and may deepen the\n * count but never lower it. Absence in both means a top-level agent.\n *\n * @param agent - the agent making the request.\n * @returns whether this is a subagent.\n */\nexport function isSubagent(agent: AgentLike): boolean {\n const fromHeader = agent.session.header.delegationDepth;\n const fromOptions = agent.options.subagentDepth;\n const depth = Math.max(\n typeof fromHeader === 'number' && Number.isSafeInteger(fromHeader) ? fromHeader : 0,\n typeof fromOptions === 'number' && Number.isSafeInteger(fromOptions) ? fromOptions : 0,\n );\n return depth >= 1;\n}\n\n/** Opening words of the return guidance the Host appends to a delegation. */\nexport const RETURN_GUIDANCE_PREFIX = 'Your parent agent id is ';\n\n/**\n * Read the child's delegation description.\n *\n * The subagent tool passes the model's `description` as the activation label,\n * and the child's durable descriptor keeps it \u2014 which is why it is readable here\n * without the parent's tool call. Only the child's OWN events are read, and the\n * LAST descriptor wins: a resumed or re-activated child appends a fresh one, and\n * the newest is the delegation actually running.\n *\n * The label is a display summary the delegating agent wrote, so it is returned\n * on its own and never merged with the task text: the judge gets the label as a\n * heading over the task, and the log's subagent column gets the label alone.\n *\n * @param agent - the subagent.\n * @returns the description, or '' when its descriptor carries none.\n */\nexport function readChildLabel(agent: AgentLike): string {\n let found = '';\n for (const event of ownEventsOf(agent.session)) {\n if (event.type !== 'subagent/descriptor') continue;\n const data = event.data;\n if (typeof data !== 'object' || data === null) continue;\n const label = (data as { label?: unknown }).label;\n if (typeof label === 'string' && label.trim() !== '') found = label.trim();\n }\n return found;\n}\n\n/**\n * Read the task the parent delegated.\n *\n * The delegation is the message whose `source.kind` is `user`; every other\n * producer writes user-role messages too \u2014 the working directory notice,\n * workspace instructions, the runtime snapshot, the skill catalog, the time\n * snapshot \u2014 so the source is what separates the task from the context wrapped\n * around it.\n *\n * Two shapes carry that message, and both are read because the judgement runs\n * before the second one exists. A delegation starts as pending inbox input, so\n * it first appears inside an `agent/inbox/spliced` event; the Host claims it at\n * the step boundary and only then appends the `user/message` carrying it. The\n * judge is asked during the step's request, which is before that append \u2014 so\n * reading only `user/message` would find nothing on the very request that\n * matters. From the next step on the `user/message` is there instead.\n *\n * The Host appends its return guidance as one trailing block of that message.\n * It tells the child how to report back, not what the job is, so it is dropped:\n * leaving it in would spend most of the subject on boilerplate.\n *\n * Only the child's OWN events are read, because a forked child's log opens with\n * the parent's finished turns.\n *\n * @param agent - the subagent.\n * @returns the delegated task text, or '' when no delegation message exists.\n */\nexport function readTaskText(agent: AgentLike): string {\n for (const event of ownEventsOf(agent.session)) {\n const candidates = delegationMessagesOf(event);\n for (const data of candidates) {\n const blocks = textBlocksOf(data);\n // The guidance is appended last; a task that happens to open with the same\n // words is still honored because only the trailing block is examined.\n if (blocks.length > 1 && blocks[blocks.length - 1].startsWith(RETURN_GUIDANCE_PREFIX)) {\n blocks.pop();\n }\n const text = blocks.join('\\n').trim();\n if (text !== '') return text;\n }\n }\n return '';\n}\n\n/**\n * The messages one event contributes, in log order.\n *\n * A delegation message is written twice across a child's life \u2014 once as pending\n * inbox input, once as the committed `user/message` \u2014 so both event shapes are\n * unwrapped here and the caller keeps the first usable one.\n *\n * @param event - one child-owned session event.\n * @returns the delegation-shaped messages the event carries, possibly none.\n */\nfunction delegationMessagesOf(event: SessionEventLike): unknown[] {\n if (event.type === 'user/message') {\n return sourceOf(event.data)?.kind === 'user' ? [event.data] : [];\n }\n if (event.type === 'agent/inbox/spliced') {\n const inserted = (event.data as { inserted?: unknown } | undefined)?.inserted;\n if (!Array.isArray(inserted)) return [];\n return inserted.filter((message) => sourceOf(message)?.kind === 'user');\n }\n return [];\n}\n\n/** Read the durable producer facts off one message payload. */\nfunction sourceOf(data: unknown): { kind: string } | undefined {\n if (typeof data !== 'object' || data === null) return undefined;\n const source = (data as { source?: unknown }).source;\n if (typeof source !== 'object' || source === null) return undefined;\n const kind = (source as { kind?: unknown }).kind;\n return typeof kind === 'string' ? { kind } : undefined;\n}\n\n/** Pull the text blocks out of a message payload, in order. */\nfunction textBlocksOf(data: unknown): string[] {\n if (typeof data !== 'object' || data === null) return [];\n const content = (data as { content?: unknown }).content;\n if (!Array.isArray(content)) return [];\n const texts: string[] = [];\n for (const block of content) {\n if (typeof block !== 'object' || block === null) continue;\n const record = block as { type?: unknown; text?: unknown };\n if (record.type === 'text' && typeof record.text === 'string') texts.push(record.text);\n }\n return texts;\n}\n\n/**\n * Walk up a child's lineage to the top-level conversation that started it.\n *\n * A nested subagent's direct parent is another subagent, and the log's job is to\n * name the conversation the reader recognises \u2014 so the walk continues until a\n * session names no parent. The walk is bounded, because a resumed or forged\n * lineage must not be able to spin this loop.\n *\n * @param startId - the child's direct parent session id.\n * @param lookup - resolves a session id to its live session.\n * @returns the top-level session id, or the starting id when the walk stops.\n */\nexport function resolveRootSessionId(\n startId: string,\n lookup: (id: string) => SessionLike | undefined,\n): string {\n const seen = new Set<string>([startId]);\n let current = startId;\n for (let hop = 0; hop < 32; hop += 1) {\n const session = lookup(current);\n const parent = session?.header.parentSession;\n if (typeof parent !== 'string' || parent === '' || seen.has(parent)) return current;\n seen.add(parent);\n current = parent;\n }\n return current;\n}\n", "/**\n * The judge call itself: one POST, one budget, no retry.\n *\n * The call can fail in exactly four ways \u2014 unreachable, timed out, an answer\n * that names no option, an answer whose row is unusable \u2014 and every one of them\n * ends the same way for the caller: no rewrite happens and the child inherits\n * what the main agent is running. That is why nothing here throws: a delegation\n * must never fail because the judge was unavailable.\n */\n\nimport {\n PROBE_OPTION_ID,\n buildJudgeRequest,\n buildProbeRequest,\n formatJudgeRequest,\n readJudgeAnswer,\n} from './judge-prompt.ts';\nimport type { FallbackReason, JudgeOutcome, ProbeOutcome, TypeRow } from './types.ts';\n\n/** How long a judgement may take before it is abandoned. */\nexport const JUDGE_TIMEOUT_MS = 5000;\n\n/** What the judge client needs from the Host to make one call. */\nexport interface JudgeEndpoint {\n /** Full endpoint URL, including the protocol path. */\n url: string;\n /** Judge model id. */\n model: string;\n /** Authorization value, or '' when the endpoint needs none. */\n apiKey: string;\n}\n\n/** Structural `fetch` so tests can supply their own. */\nexport type FetchLike = (input: string, init: RequestInit) => Promise<Response>;\n\n/**\n * Ask the judge whether this endpoint and model can answer at all.\n *\n * This is a different question from a judgement, so it sends its own request\n * with its own single option: the reader uses the button to find out whether\n * the endpoint and model work, which is answerable before any task type has\n * been written. It never throws for the same reason a judgement never does \u2014\n * the page reports the reason, it does not handle an exception.\n *\n * @param endpoint - where and how to call the judge.\n * @param fetchImpl - the fetch to call; defaults to the global one.\n * @returns whether the endpoint answered, and how long it took.\n */\nexport async function probeJudge(\n endpoint: JudgeEndpoint,\n fetchImpl: FetchLike = fetch,\n): Promise<ProbeOutcome> {\n const startedAt = Date.now();\n const elapsed = (): number => Date.now() - startedAt;\n if (endpoint.url.trim() === '' || endpoint.model.trim() === '') {\n return { ok: false, latencyMs: elapsed(), reason: 'unconfigured' };\n }\n\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), JUDGE_TIMEOUT_MS);\n let timedOut = false;\n const onTimeout = (): void => {\n timedOut = true;\n };\n controller.signal.addEventListener('abort', onTimeout);\n\n try {\n const response = await fetchImpl(endpoint.url.trim(), {\n method: 'POST',\n headers: {\n 'content-type': 'application/json',\n ...endpoint.apiKey.trim() === '' ? {} : { authorization: `Bearer ${endpoint.apiKey.trim()}` },\n },\n body: JSON.stringify(buildProbeRequest(endpoint.model.trim())),\n signal: controller.signal,\n });\n if (!response.ok) return { ok: false, latencyMs: elapsed(), reason: 'unreachable' };\n const payload: unknown = await response.json();\n // The check asked for the one option it offered: any answer that names a\n // different option means the endpoint did not read the request it was sent.\n return readJudgeAnswer(payload, [{\n id: Number(PROBE_OPTION_ID),\n description: '',\n provider: '',\n model: '',\n effort: '',\n }]).kind === 'row'\n ? { ok: true, latencyMs: elapsed() }\n : { ok: false, latencyMs: elapsed(), reason: 'unmatched' };\n } catch {\n return { ok: false, latencyMs: elapsed(), reason: timedOut ? 'timeout' : 'unreachable' };\n } finally {\n clearTimeout(timer);\n controller.signal.removeEventListener('abort', onTimeout);\n }\n}\n\n/**\n * Ask the judge which type one delegated job is.\n *\n * Never throws and never lets an abort cancel the delegation: every failure is\n * reported as a `fallback` outcome carrying its own reason, and the caller\n * writes nothing.\n *\n * @param endpoint - where and how to call the judge.\n * @param rows - the selectable rows, in page order.\n * @param subject - the text to classify, from `composeJudgeSubject`.\n * @param fetchImpl - the fetch to call; defaults to the global one.\n * @returns the decision, or the fallback reason that replaced it.\n */\nexport async function judgeTaskType(\n endpoint: JudgeEndpoint,\n rows: readonly TypeRow[],\n subject: string,\n fetchImpl: FetchLike = fetch,\n): Promise<JudgeOutcome> {\n const startedAt = Date.now();\n const elapsed = (): number => Date.now() - startedAt;\n if (endpoint.url.trim() === '' || endpoint.model.trim() === '' || rows.length === 0) {\n return { kind: 'fallback', reason: 'unreachable', latencyMs: elapsed(), prompt: '' };\n }\n\n const body = buildJudgeRequest(rows, endpoint.model.trim(), subject);\n // The body the log keeps is the one sent, not a re-built one: the reader\n // opens it to see exactly what the judge was asked.\n const prompt = formatJudgeRequest(body);\n\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), JUDGE_TIMEOUT_MS);\n let timedOut = false;\n const onTimeout = (): void => {\n timedOut = true;\n };\n controller.signal.addEventListener('abort', onTimeout);\n\n try {\n const response = await fetchImpl(endpoint.url.trim(), {\n method: 'POST',\n headers: {\n 'content-type': 'application/json',\n // Sent only when there is a key: an unauthenticated local endpoint\n // would otherwise receive an empty Bearer and reject the call itself.\n ...endpoint.apiKey.trim() === '' ? {} : { authorization: `Bearer ${endpoint.apiKey.trim()}` },\n },\n body: JSON.stringify(body),\n signal: controller.signal,\n });\n if (!response.ok) {\n return { kind: 'fallback', reason: 'unreachable', latencyMs: elapsed(), prompt };\n }\n const payload: unknown = await response.json();\n const decision = readJudgeAnswer(payload, rows);\n if (decision.kind === 'empty') {\n return { kind: 'fallback', reason: 'unmatched', latencyMs: elapsed(), prompt };\n }\n if (decision.kind === 'unmatched') {\n return { kind: 'fallback', reason: 'unmatched', latencyMs: elapsed(), prompt };\n }\n return { kind: 'matched', row: decision.row, latencyMs: elapsed(), prompt };\n } catch {\n const reason: FallbackReason = timedOut ? 'timeout' : 'unreachable';\n return { kind: 'fallback', reason, latencyMs: elapsed(), prompt };\n } finally {\n clearTimeout(timer);\n controller.signal.removeEventListener('abort', onTimeout);\n }\n}\n", "/**\n * The plugin's own log, kept on disk under the DSH home.\n *\n * The Host's native subagent list has no model column and a plugin cannot add\n * one, so this log is the only place a delegation's assigned route is visible.\n * It outlives the Host process: a judgement that ran yesterday is still one\n * question away today.\n *\n * Two bounds, deliberately different. The file keeps {@link LOG_KEEP} entries\n * so \"what did it pick last time\" survives a restart, while the configuration\n * page shows only {@link LOG_PAGE_LIMIT}: the page is a glance at what just\n * happened, not a log viewer.\n */\n\nimport * as fs from 'node:fs/promises';\nimport * as path from 'node:path';\nimport { dshHomePath } from '@deepseek-ai/dsh-home-paths';\nimport type { LogEntry } from './types.ts';\n\n/** How many entries the file keeps. */\nexport const LOG_KEEP = 200;\n\n/** How many entries the configuration page shows. */\nexport const LOG_PAGE_LIMIT = 10;\n\n/**\n * Read one entry from a stored document value, tolerating a partial record.\n *\n * The file outlives the process, so a line written by another version may be\n * missing a field. Such a line keeps whatever it does carry rather than\n * rejecting the whole document.\n *\n * @param value - one element of the stored array.\n * @returns the entry, or undefined when the value is not an object.\n */\nfunction readEntry(value: unknown): LogEntry | undefined {\n if (typeof value !== 'object' || value === null) return undefined;\n const record = value as Record<string, unknown>;\n const text = (key: string): string => (typeof record[key] === 'string' ? (record[key] as string) : '');\n const count = (key: string): number =>\n typeof record[key] === 'number' && Number.isFinite(record[key]) ? (record[key] as number) : 0;\n return {\n typeId: typeof record.typeId === 'number' ? record.typeId : null,\n provider: text('provider'),\n model: text('model'),\n effort: text('effort'),\n ...typeof record.reason === 'string' ? { reason: record.reason as LogEntry['reason'] } : {},\n at: count('at'),\n latencyMs: count('latencyMs'),\n parentTitle: text('parentTitle'),\n childLabel: text('childLabel'),\n prompt: text('prompt'),\n };\n}\n\n/** A bounded, newest-first log backed by one JSON file. */\nexport class LogStore {\n private entries: LogEntry[] = [];\n private readonly filePath: string;\n /** The initial read, so an append issued before it lands cannot be overwritten by it. */\n private loading: Promise<void> | null = null;\n /** Writes are chained, so two appends cannot interleave their file replaces. */\n private writing: Promise<void> = Promise.resolve();\n\n /**\n * @param filePath - where the log lives; defaults to this plugin's own\n * directory under the DSH home.\n */\n constructor(filePath: string = dshHomePath('dsh-subagent-judge-dispatch', 'judgements.json')) {\n this.filePath = filePath;\n }\n\n /**\n * Load what a previous process wrote.\n *\n * A missing, unreadable or malformed file leaves the log empty; the next\n * append rewrites it. This method never rejects, because a broken log must\n * never stop a judgement.\n */\n init(): Promise<void> {\n this.loading ??= this.load();\n return this.loading;\n }\n\n /** Read the file once and adopt what it holds. */\n private async load(): Promise<void> {\n try {\n const raw = await fs.readFile(this.filePath, 'utf-8');\n const parsed = JSON.parse(raw) as unknown;\n const list = Array.isArray(parsed) ? parsed : [];\n // \u5148\u8BFB\u5230\u7684\u8BB0\u5F55\u6392\u5728\u8FD9\u6B21\u8FD0\u884C\u65B0\u5199\u7684\u90A3\u51E0\u6761\u540E\u9762\uFF0C\u8C01\u4E5F\u4E0D\u4F1A\u76D6\u6389\u8C01\u3002\n const stored = list\n .map(readEntry)\n .filter((entry): entry is LogEntry => entry !== undefined);\n this.entries = [...this.entries, ...stored].slice(0, LOG_KEEP);\n } catch {\n // \u6587\u4EF6\u4E0D\u5B58\u5728\u6216\u8BFB\u4E0D\u52A8\u5C31\u4ECE\u7A7A\u65E5\u5FD7\u8D77\u6B65\uFF1B\u8FD9\u6B21\u8FD0\u884C\u5DF2\u7ECF\u8FFD\u52A0\u7684\u8BB0\u5F55\u4FDD\u6301\u539F\u6837\u3002\n }\n }\n\n /**\n * Append one entry, dropping the oldest beyond {@link LOG_KEEP}, and write.\n *\n * The write starts at once rather than on a timer: a judgement is rare enough\n * that coalescing buys nothing, and a delayed write is a record a hard exit\n * can lose.\n *\n * @param entry - the entry to append.\n */\n append(entry: LogEntry): void {\n this.entries = [entry, ...this.entries].slice(0, LOG_KEEP);\n // \u78C1\u76D8\u91CC\u90A3\u4EFD\u5148\u8BFB\u5B8C\u518D\u5408\u5E76\uFF0C\u5426\u5219\u8FD9\u6B21\u521A\u8BB0\u4E0B\u7684\u4E00\u6761\u4F1A\u88AB\u521D\u59CB\u8BFB\u53D6\u6574\u4EFD\u6362\u6210\u65E7\u8BB0\u5F55\u3002\n // \u4E0A\u4E00\u7B14\u5199\u5728\u8D4B\u65B0\u503C\u4E4B\u524D\u53D6\u4E0B\u6765\uFF1A\u5199\u6210 `() => this.writing` \u4F1A\u7B49\u81EA\u5DF1\uFF0C\u6C38\u8FDC\u4E0D\u843D\u5730\u3002\n const previous = this.writing;\n const afterLoad = this.loading === null ? previous : this.loading.then(() => previous);\n this.writing = afterLoad.then(() => this.write()).catch((error) => {\n console.warn('[dsh-subagent-judge-dispatch] \u5224\u65AD\u65E5\u5FD7\u5199\u4E0D\u8FDB\u78C1\u76D8\uFF1A', error);\n });\n }\n\n /**\n * Read the whole kept log, newest first.\n * @returns a detached copy, so a reader cannot mutate the stored entries.\n */\n list(): LogEntry[] {\n return this.entries.map((entry) => ({ ...entry }));\n }\n\n /** Wait for the initial read and the writes already started to land. */\n async flush(): Promise<void> {\n if (this.loading !== null) await this.loading;\n await this.writing;\n }\n\n /** Replace the file atomically, so a crash cannot leave half a document. */\n private async write(): Promise<void> {\n const temp = `${this.filePath}.tmp.${Date.now()}.${Math.random().toString(36).slice(2)}`;\n try {\n await fs.mkdir(path.dirname(this.filePath), { recursive: true });\n await fs.writeFile(temp, JSON.stringify(this.entries, null, 2), 'utf-8');\n await fs.rename(temp, this.filePath);\n } catch (error) {\n try {\n await fs.unlink(temp);\n } catch {\n // The temp file may never have been created; nothing to clean up.\n }\n throw error;\n }\n }\n}\n", "import { opendir, realpath } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { basename, dirname, join, resolve } from \"node:path\";\n//#region lib/types/index.js\n/**\n* Shared filesystem path helpers for DeepSeek Harness user data.\n*\n* @module @deepseek-ai/dsh-home-paths\n*/\n/** Directory name for the default DeepSeek Harness home under the OS home. */\nconst DSH_HOME_DIR_NAME = \".dsh\";\n/** Stable user-facing display form for the default DeepSeek Harness home. */\nconst DEFAULT_DSH_HOME_DISPLAY = `~/${DSH_HOME_DIR_NAME}`;\n/** Environment variable that overrides the default DeepSeek Harness home. */\nconst DSH_HOME_ENV = \"DSH_HOME\";\n/** Directory name for the default shared agent configuration root under the OS home. */\nconst AGENTS_HOME_DIR_NAME = \".agents\";\n/** Stable user-facing display form for the default shared agent configuration root. */\nconst DEFAULT_AGENTS_HOME_DISPLAY = `~/${AGENTS_HOME_DIR_NAME}`;\n/** Environment variable that overrides the default shared agent configuration root. */\nconst AGENTS_HOME_ENV = \"DSH_AGENTS_HOME\";\n/**\n* Give a native filesystem watcher one canonical spelling of a path, even\n* when its final components do not exist yet. The deepest existing ancestor\n* is resolved through {@link realpath}; when a suffix is missing, that\n* ancestor is also proved to be an enumerable directory before the suffix is\n* restored. This prevents Windows from treating a regular-file ancestor as\n* ordinary absence, and prevents short-name aliases from being mixed with\n* long paths emitted by the native watcher backend.\n* @param path - Watch target or root, resolved against the current directory.\n* @returns the target with its existing ancestor canonicalized.\n* @throws when ancestor traversal encounters an error other than absence, or\n* the existing ancestor of a missing suffix is not an enumerable directory.\n*/\nasync function canonicalizeWatchPath(path) {\n\tlet current = resolve(path);\n\tconst missing = [];\n\twhile (true) try {\n\t\tconst canonical = await realpath(current);\n\t\tif (missing.length > 0) await (await opendir(canonical)).close();\n\t\treturn join(canonical, ...missing.reverse());\n\t} catch (error) {\n\t\tif (error.code !== \"ENOENT\") throw error;\n\t\tconst parent = dirname(current);\n\t\t/* v8 ignore next -- a filesystem root exists, so traversal resolves before this guard */\n\t\tif (parent === current) throw error;\n\t\tmissing.push(basename(current));\n\t\tcurrent = parent;\n\t}\n}\n/**\n* Resolve the default DeepSeek Harness home using Node's platform path rules.\n* @returns the absolute default harness home path.\n*/\nfunction defaultDshHome() {\n\treturn join(homedir(), DSH_HOME_DIR_NAME);\n}\n/**\n* Resolve the default shared agent configuration root using Node's platform path rules.\n* @returns the absolute default shared agent configuration root.\n*/\nfunction defaultAgentsHome() {\n\treturn join(homedir(), AGENTS_HOME_DIR_NAME);\n}\n/**\n* Expand supported tilde prefixes against the operating-system home.\n* @param path - configured path that may begin with `~`, `~/`, or `~\\`.\n* @returns the expanded path, or the original value when no supported prefix is present.\n*/\nfunction expandHomePath(path) {\n\tif (path === \"~\") return homedir();\n\tif (path.startsWith(\"~/\") || path.startsWith(\"~\\\\\")) return join(homedir(), path.slice(2));\n\treturn path;\n}\n/**\n* Resolve one user-data root from an explicit path, an environment override, and a default.\n* @param configured - explicit path, which has highest precedence.\n* @param env - environment mapping to read.\n* @param envName - environment variable that overrides the default.\n* @param fallback - default root, used when neither the explicit path nor the environment provides one.\n* @returns the normalized absolute root.\n*/\nfunction resolveRoot(configured, env, envName, fallback) {\n\tconst fromEnv = env[envName];\n\treturn resolve(expandHomePath(configured ?? (fromEnv !== void 0 && fromEnv.trim().length > 0 ? fromEnv : fallback())));\n}\n/**\n* Label one resolved user-data root symbolically for user-facing display.\n* @param resolvedRoot - absolute path returned by the matching resolver.\n* @param defaultRoot - absolute default root whose symbolic label applies to a match.\n* @param defaultLabel - symbolic label for the default root.\n* @param envName - environment variable name that labels any other root.\n* @returns the symbolic label.\n*/\nfunction rootDisplay(resolvedRoot, defaultRoot, defaultLabel, envName) {\n\treturn resolvedRoot === resolve(defaultRoot) ? defaultLabel : `$${envName}`;\n}\n/**\n* Resolve the single-root DeepSeek Harness home.\n*\n* Precedence, highest first: an explicit configured path, `$DSH_HOME`, then\n* `~/.dsh`. The harness keeps all user data under one root. An empty or\n* whitespace-only `$DSH_HOME` is treated as unset, so a blank override never\n* resolves the home to the current working directory.\n* @param configured - explicit harness-home override, which has highest precedence.\n* @param env - environment mapping used to read `DSH_HOME`.\n* @returns the normalized absolute harness home path.\n*/\nfunction resolveDshHome(configured, env = process.env) {\n\treturn resolveRoot(configured, env, DSH_HOME_ENV, defaultDshHome);\n}\n/**\n* Resolve the shared agent configuration root.\n*\n* Precedence, highest first: an explicit configured path, `$DSH_AGENTS_HOME`,\n* then `~/.agents`. The root holds configuration shared with other agent tools,\n* so it stays independent of the DeepSeek Harness home. An empty or\n* whitespace-only `$DSH_AGENTS_HOME` is treated as unset, so a blank override\n* never resolves the root to the current working directory.\n* @param configured - explicit shared-root override, which has highest precedence.\n* @param env - environment mapping used to read `DSH_AGENTS_HOME`.\n* @returns the normalized absolute shared agent configuration root.\n*/\nfunction resolveAgentsHome(configured, env = process.env) {\n\treturn resolveRoot(configured, env, AGENTS_HOME_ENV, defaultAgentsHome);\n}\n/**\n* Join path segments onto the resolved DeepSeek Harness home.\n* @param segments - path segments appended to the Harness home; an empty list returns the home itself.\n* @returns the normalized absolute joined path.\n*/\nfunction dshHomePath(...segments) {\n\treturn join(resolveDshHome(), ...segments);\n}\n/**\n* Join path segments onto the resolved Harness home's `cache` directory without creating it; no arguments returns the directory itself.\n* @param optionsOrSegment - explicit home override, or the first path segment; omission uses the default home resolution.\n* @param segments - additional path segments after the first child, if any.\n* @returns the normalized absolute cache path.\n*/\nfunction dshCachePath(optionsOrSegment = {}, ...segments) {\n\tif (typeof optionsOrSegment === \"string\") return dshHomePath(\"cache\", optionsOrSegment, ...segments);\n\treturn join(resolveDshHome(optionsOrSegment.dshHome), \"cache\", ...segments);\n}\n/**\n* Describe a resolved harness home symbolically for user-facing display.\n*\n* It never returns an absolute machine path: the default home is labelled\n* `~/.dsh`, and any configured home is labelled `$DSH_HOME`.\n* @param resolvedHome - the absolute path returned by {@link resolveDshHome}.\n* @returns `~/.dsh` for the default home, otherwise `$DSH_HOME`.\n*/\nfunction dshHomeDisplay(resolvedHome) {\n\treturn rootDisplay(resolvedHome, defaultDshHome(), DEFAULT_DSH_HOME_DISPLAY, DSH_HOME_ENV);\n}\n/**\n* Describe a resolved shared agent configuration root symbolically for user-facing display.\n*\n* It never returns an absolute machine path: the default root is labelled\n* `~/.agents`, and any configured root is labelled `$DSH_AGENTS_HOME`.\n* @param resolvedHome - the absolute path returned by {@link resolveAgentsHome}.\n* @returns `~/.agents` for the default root, otherwise `$DSH_AGENTS_HOME`.\n*/\nfunction agentsHomeDisplay(resolvedHome) {\n\treturn rootDisplay(resolvedHome, defaultAgentsHome(), DEFAULT_AGENTS_HOME_DISPLAY, AGENTS_HOME_ENV);\n}\n//#endregion\nexport { AGENTS_HOME_DIR_NAME, AGENTS_HOME_ENV, DEFAULT_AGENTS_HOME_DISPLAY, DEFAULT_DSH_HOME_DISPLAY, DSH_HOME_DIR_NAME, DSH_HOME_ENV, agentsHomeDisplay, canonicalizeWatchPath, defaultAgentsHome, defaultDshHome, dshCachePath, dshHomeDisplay, dshHomePath, expandHomePath, resolveAgentsHome, resolveDshHome };\n", "/**\n * This plugin's exact Fetch routes, carried by Connection's authenticated\n * `/api` transport below the shared channel.\n *\n * Three surfaces, and no fourth: configuration is read and written through\n * DSH's own shared configuration form (`ctx.configForms`) and the `credentials`\n * Remote API, so nothing here touches either. What is left is what only the\n * Host knows \u2014 the runtime log, the exact text a judgement would send, and\n * whether the judge endpoint answers at all.\n */\n\nimport type { ConnectionFetchRoute } from '@deepseek-ai/dsh-client-connection';\nimport { buildPreview, selectableRows } from './judge-prompt.ts';\nimport { LOG_PAGE_LIMIT } from './log-store.ts';\nimport { probeJudge } from './judge-client.ts';\nimport type { ResolvedConfig } from './config.ts';\nimport type { LogEntry } from './types.ts';\n\n/** Runtime log route path. */\nexport const LOG_ROUTE_PATH = '/api/dsh-subagent-judge-dispatch/log';\n\n/** Exact judge-prompt preview route path. */\nexport const PREVIEW_ROUTE_PATH = '/api/dsh-subagent-judge-dispatch/preview';\n\n/** Judge endpoint probe route path. */\nexport const PROBE_ROUTE_PATH = '/api/dsh-subagent-judge-dispatch/probe';\n\nfunction sendJson(status: number, body: unknown): Response {\n return new Response(JSON.stringify(body), {\n status,\n headers: { 'Content-Type': 'application/json; charset=utf-8' },\n });\n}\n\n/** What one probe reports back to the page. */\nexport interface ProbeResult {\n ok: boolean;\n latencyMs: number;\n /** Which failure it was, when it failed. */\n reason?: string;\n}\n\n/** The Host-side face the routes read. */\nexport interface DispatchRouteFace {\n /** Current committed configuration. */\n config(): ResolvedConfig;\n /** Read the whole kept log, newest first; may resolve once the file has been read. */\n log(): LogEntry[] | Promise<LogEntry[]>;\n /** The judge key resolved from credentials, or '' when unset. */\n apiKey(): string;\n}\n\n/**\n * Build this plugin's Fetch routes.\n * @param face - the Host-side reads the routes serve.\n * @returns the routes to register on Connection.\n */\nexport function createFetchRoutes(face: DispatchRouteFace): ConnectionFetchRoute[] {\n const log: ConnectionFetchRoute = {\n path: LOG_ROUTE_PATH,\n methods: ['GET'],\n requestBody: 'buffered',\n fetch: async () => {\n try {\n // The page shows only the tail of the log; the file keeps the rest.\n return sendJson(200, { ok: true, entries: (await face.log()).slice(0, LOG_PAGE_LIMIT) });\n } catch (err) {\n return sendJson(500, { ok: false, error: describe(err) });\n }\n },\n };\n\n const preview: ConnectionFetchRoute = {\n path: PREVIEW_ROUTE_PATH,\n methods: ['GET'],\n requestBody: 'buffered',\n fetch: async () => {\n try {\n const config = face.config();\n // Built by the same function the real call uses, so what the page shows\n // cannot drift from what goes out.\n const text = buildPreview(selectableRows(config.rows), config.judgeModel.trim());\n return sendJson(200, { ok: true, preview: text });\n } catch (err) {\n return sendJson(500, { ok: false, error: describe(err) });\n }\n },\n };\n\n const probe: ConnectionFetchRoute = {\n path: PROBE_ROUTE_PATH,\n methods: ['POST'],\n requestBody: 'buffered',\n fetch: async () => {\n try {\n const config = face.config();\n // \u53EA\u95EE\u300C\u8FD9\u4E2A\u5730\u5740\u4E0E\u6A21\u578B\u7B54\u4E0D\u7B54\u5F97\u4E0A\u6765\u300D\uFF0C\u6240\u4EE5\u4E0D\u95EE\u7C7B\u578B\u6E05\u5355\uFF1A\u6E05\u5355\u662F\u5224\u65AD\u65F6\u624D\n // \u9700\u8981\u7684\u8F93\u5165\uFF0C\u62FF\u5B83\u5F53\u4F5C\u80FD\u4E0D\u80FD\u6D4B\u7684\u524D\u63D0\uFF0C\u4F1A\u8BA9\u7A7A\u6E05\u5355\u7684\u8BFB\u8005\u4EE5\u4E3A\u670D\u52A1\u574F\u4E86\u3002\n const outcome = await probeJudge({\n url: config.endpointUrl,\n model: config.judgeModel,\n apiKey: face.apiKey(),\n });\n return sendJson(200, { ...outcome } satisfies ProbeResult);\n } catch (err) {\n return sendJson(500, { ok: false, error: describe(err) });\n }\n },\n };\n\n return [log, preview, probe];\n}\n\n/** One-line error text for a route failure. */\nfunction describe(err: unknown): string {\n return err instanceof Error ? err.message : String(err);\n}\n", "import type { HostConnectionHandle } from '@deepseek-ai/dsh-client-connection';\nimport {\n isJudgeUsable,\n readPluginConfig,\n SETTINGS_NAMESPACE,\n type PluginConfigRefs,\n type ResolvedConfig,\n} from './server/config.ts';\nimport { JUDGE_API_KEY_REF, type CredentialsServiceLike } from './server/credentials.ts';\nimport { applyDecision, decideRewrite, outcomeReason } from './server/dispatch.ts';\nimport {\n isSubagent,\n readChildLabel,\n readTaskText,\n resolveRootSessionId,\n type SessionLike,\n} from './server/identity.ts';\nimport { judgeTaskType } from './server/judge-client.ts';\nimport { composeJudgeSubject, selectableRows } from './server/judge-prompt.ts';\nimport { LogStore } from './server/log-store.ts';\nimport { createFetchRoutes } from './server/router.ts';\nimport type { LogEntry } from './server/types.ts';\n\n/**\n * Stable Cordis loader name; the same literal as the `id` of this plugin's row\n * in `cordis.patch.yml` and as its settings namespace.\n */\nexport const name = SETTINGS_NAMESPACE;\n\n/**\n * Declared services. `credentials` is the DSH-owned secret surface the judge key\n * is read through; `sessions` and `sessionTitle` turn a child Agent's id into the\n * conversation title the log shows. The Fetch routes ride Connection's\n * authenticated transport, which only a Web carrier composes, so they are taken\n * through `ctx.inject` and the plugin still loads without one.\n */\nexport const inject = ['credentials', 'sessions', 'sessionTitle'];\n\nexport { Config, DEFAULT_ENDPOINT_URL, DEFAULT_JUDGE_MODEL } from './server/config.ts';\nexport { JUDGE_API_KEY_REF } from './server/credentials.ts';\n\n/** Minimal structural shape of the `sessionTitle` service. */\ninterface SessionTitleLike {\n get(session: unknown): { title: string } | undefined;\n}\n\n/** Minimal structural shape of this plugin's own `settings` usage. */\ninterface SettingsLike {\n configure(presentation: { auto?: boolean }, owner?: unknown): () => void;\n}\n\n/**\n * The Host context surface this plugin uses.\n *\n * Declared structurally rather than by extending `Context`: the fields read here\n * (`inject` with a narrower dependency list, `on` for one waterfall event) are a\n * subset with a deliberately looser signature, and widening `inject` to satisfy\n * the interface would hide the services this plugin actually declares through\n * the exported `inject` table.\n */\ninterface HostContext {\n credentials: CredentialsServiceLike;\n sessions: { get(id: string): unknown };\n sessionTitle: SessionTitleLike;\n settings: SettingsLike;\n fiber: unknown;\n on(event: string, listener: (...args: any[]) => unknown): () => void;\n effect(factory: () => void | (() => void), label?: string): unknown;\n inject(names: string[] | string, callback: (ctx: HostContext) => void | (() => void)): void;\n}\n\n/** Which Agent fields this plugin reads inside the request hook. */\ninterface RequestAgent {\n id: string;\n options: { subagentDepth?: number };\n session: SessionLike;\n}\n\n/** One resolved model call the waterfall hands through. */\ninterface CallConfig {\n provider: string;\n model: string;\n reasoningEffort?: unknown;\n [key: string]: unknown;\n}\n\n/** How many judged children to remember before forgetting the oldest. */\nconst JUDGED_LIMIT = 500;\n\n/**\n * The set of children already judged, bounded so a long-running instance cannot\n * grow without limit.\n *\n * Insertion order is eviction order: a `Set` iterates oldest-first, so the one\n * entry that goes is always the earliest judgement. Forgetting a very old child\n * costs at most one extra judgement should it somehow make another request,\n * which is strictly better than an unbounded map keyed by every subagent ever\n * delegated.\n */\nclass JudgedChildren {\n private readonly seen = new Set<string>();\n\n /** Record a child as judged, forgetting the oldest entry past the cap. */\n add(id: string): void {\n this.seen.add(id);\n if (this.seen.size <= JUDGED_LIMIT) return;\n const oldest = this.seen.values().next();\n if (!oldest.done) this.seen.delete(oldest.value);\n }\n\n /** Whether this child has already been judged. */\n has(id: string): boolean {\n return this.seen.has(id);\n }\n}\n\n/**\n * Mount the host half: judge every subagent once, write the route the judgement\n * chose, and keep the log the Plugins page reads.\n *\n * @param ctx - DSH Host context.\n * @param config - this plugin's runtime-resolved Config (every field a live ref).\n */\nexport function apply(ctx: HostContext, config: PluginConfigRefs): void {\n const log = new LogStore();\n /** Children already judged, so a ten-step child is asked about once. */\n const judged = new JudgedChildren();\n let apiKey = '';\n\n // The log outlives the process: read what a previous run wrote before the\n // first append could overwrite it. `init` never rejects \u2014 a missing or broken\n // file just leaves the log empty.\n const logReady = log.init();\n\n const resolvedConfig = (): ResolvedConfig => readPluginConfig(config);\n\n /** Re-read the judge key; a key set outside the page takes effect at once. */\n const refreshKey = async (): Promise<void> => {\n try {\n apiKey = ((await ctx.credentials.resolve(JUDGE_API_KEY_REF))?.value ?? '').trim();\n } catch {\n apiKey = '';\n }\n };\n void refreshKey();\n ctx.on('credentials/reference-updated', () => {\n void refreshKey();\n });\n\n // Settings are read and written through the Plugins page's own card; DSH must\n // not also derive a generic settings form for the same entry.\n ctx.inject(['settings'], (child) => {\n child.effect(\n () => child.settings.configure({ auto: false }, child.fiber),\n 'dsh-subagent-judge-dispatch: settings page policy'\n );\n });\n\n /**\n * The delegation hook: one judgement per subagent, then the route it chose.\n *\n * Never throws and never cancels: every failure path returns the config the\n * Host already resolved, which is what makes a judge outage cost latency and\n * nothing else. The judgement is awaited because the Host awaits this\n * waterfall, so it can add up to the judge budget to that one delegation.\n */\n ctx.on('agent/request', async (payload: { agent?: RequestAgent }, next: () => Promise<CallConfig>) => {\n const resolved = await next();\n const agent = payload?.agent;\n if (agent === undefined) return resolved;\n const cfg = resolvedConfig();\n // Only subagents, and only while the model-rewrite switch is on: with it off\n // nothing is judged and nothing is logged, so the log only ever holds\n // judgements that actually ran.\n if (!isSubagent(agent) || !cfg.enabled) return resolved;\n if (judged.has(agent.id)) return resolved;\n if (!isJudgeUsable(cfg)) return resolved;\n judged.add(agent.id);\n\n const label = readChildLabel(agent);\n const taskText = readTaskText(agent);\n const outcome = await judgeTaskType(\n { url: cfg.endpointUrl, model: cfg.judgeModel, apiKey },\n selectableRows(cfg.rows),\n composeJudgeSubject(label, taskText),\n );\n const decision = decideRewrite(outcome);\n\n if (cfg.logEnabled) {\n // Wait for the stored log before appending, so the first judgement of a\n // run does not overwrite the history it was about to join.\n await logReady;\n log.append(buildEntry(ctx, agent, resolved, decision, outcome, label, taskText));\n }\n return applyDecision(resolved, decision);\n });\n\n // The three reads only the Host can answer. Connection's /api transport is\n // composed by a Web carrier; without one the plugin loads and simply has no\n // HTTP surface.\n ctx.inject(['connection'], (connectionCtx) => {\n const routes = createFetchRoutes({\n config: resolvedConfig,\n // \u8DEF\u7531\u53EF\u80FD\u5728\u78C1\u76D8\u8BFB\u5B8C\u4E4B\u540E\u624D\u88AB\u95EE\u5230\uFF0C\u4E5F\u53EF\u80FD\u5728\u4E4B\u524D\uFF1A\u5148\u7B49\u90A3\u4E00\u6B21\u8BFB\uFF0C\u522B\u628A\u300C\u8FD8\u6CA1\u8BFB\u5B8C\u300D\n // \u62A5\u6210\u300C\u4E00\u6761\u90FD\u6CA1\u6709\u300D\u3002\n log: async () => {\n await logReady;\n return log.list();\n },\n apiKey: () => apiKey,\n });\n const disposers = routes.map((route) =>\n (connectionCtx as HostContext & { connection: HostConnectionHandle }).connection.fetch.register(route)\n );\n return () => {\n for (const dispose of disposers) void Promise.resolve(dispose()).catch(() => {});\n };\n });\n\n // \u6BCF\u6B21\u8FFD\u52A0\u90FD\u7ACB\u523B\u5F00\u5199\uFF1B\u5378\u8F7D\u65F6\u518D\u7B49\u4E00\u6B21\u5728\u98DE\u7684\u5199\u843D\u5730\uFF0C\u5378\u8F7D\u4E0D\u4E22\u6700\u540E\u90A3\u6761\u3002\n ctx.effect(\n () => () => {\n void log.flush();\n },\n 'dsh-subagent-judge-dispatch: judgement log flush',\n );\n}\n\n/**\n * Build the log row for one judged delegation.\n *\n * A fallback row reports the route the child actually keeps \u2014 the main agent's\n * resolved provider, model and effort \u2014 rather than a blank, because the point\n * of the row is what the child ran on. The subagent column carries the\n * delegation's own label; the task text is part of the request shown in the\n * row's detail, not repeated in the table.\n */\nfunction buildEntry(\n ctx: HostContext,\n agent: RequestAgent,\n resolved: CallConfig,\n decision: ReturnType<typeof decideRewrite>,\n outcome: Awaited<ReturnType<typeof judgeTaskType>>,\n label: string,\n taskText: string,\n): LogEntry {\n const matched = decision.kind === 'rewrite';\n const reason = outcomeReason(outcome, decision);\n return {\n typeId: matched && outcome.kind === 'matched' ? outcome.row.id : null,\n provider: matched ? decision.rewrite.provider : resolved.provider,\n model: matched ? decision.rewrite.model : resolved.model,\n effort: matched\n ? decision.rewrite.reasoningEffort\n : typeof resolved.reasoningEffort === 'string' ? resolved.reasoningEffort : '',\n ...reason === undefined ? {} : { reason },\n at: Date.now(),\n latencyMs: outcome.latencyMs,\n parentTitle: readParentTitle(ctx, agent.session.header.parentSession),\n childLabel: truncate(label !== '' ? label : taskText),\n prompt: outcome.prompt,\n };\n}\n\n/**\n * Name the conversation that delegated, the way the reader sees it in the\n * session list: its title, falling back to the session id when it has none.\n */\nfunction readParentTitle(ctx: HostContext, parentId: string | undefined): string {\n if (typeof parentId !== 'string' || parentId === '') return '';\n try {\n const rootId = resolveRootSessionId(parentId, (id) => ctx.sessions.get(id) as SessionLike | undefined);\n const session = ctx.sessions.get(rootId);\n if (session === undefined) return rootId;\n const title = ctx.sessionTitle.get(session)?.title;\n return typeof title === 'string' && title.trim() !== '' ? title.trim() : rootId;\n } catch {\n return parentId;\n }\n}\n\n/** Keep one log label to a readable length. */\nfunction truncate(text: string, max = 60): string {\n const collapsed = text.replace(/\\s+/g, ' ').trim();\n return collapsed.length <= max ? collapsed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xC,IAAI,KAAK,IAAI;AAAA,IACb,WAAW,QAAQ;AAAA,IACnB,aAAa,gBAAgB,KAAK,MAAM,QAAQ,OAAO,aAAa;AAAA,IACpE,YAAY,SAAS,UAAU,KAAK,QAAQ,QAAQ;AAAA,IACpD,QAAQ,QAAQ;AAAA,EAClB;AACF;AAMA,SAAS,gBAAgB,KAAkB,UAAsC;AAC/E,MAAI,OAAO,aAAa,YAAY,aAAa,GAAI,QAAO;AAC5D,MAAI;AACF,UAAM,SAAS,qBAAqB,UAAU,CAAC,OAAO,IAAI,SAAS,IAAI,EAAE,CAA4B;AACrG,UAAM,UAAU,IAAI,SAAS,IAAI,MAAM;AACvC,QAAI,YAAY,OAAW,QAAO;AAClC,UAAM,QAAQ,IAAI,aAAa,IAAI,OAAO,GAAG;AAC7C,WAAO,OAAO,UAAU,YAAY,MAAM,KAAK,MAAM,KAAK,MAAM,KAAK,IAAI;AAAA,EAC3E,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAGA,SAAS,SAAS,MAAc,MAAM,IAAY;AAChD,QAAM,YAAY,KAAK,QAAQ,QAAQ,GAAG,EAAE,KAAK;AACjD,SAAO,UAAU,UAAU,MAAM,YAAY,GAAG,UAAU,MAAM,GAAG,MAAM,CAAC,CAAC;AAC7E;",
|
|
3
|
+
"sources": ["../src/server/config.ts", "../src/server/judge-prompt.ts", "../src/server/credentials.ts", "../src/server/dispatch.ts", "../src/server/identity.ts", "../src/server/judge-client.ts", "../src/server/log-store.ts", "../node_modules/.pnpm/@deepseek-ai+dsh-home-paths@0.2.2-rc.1_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-home-paths/lib/index.js", "../src/server/router.ts", "../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * This plugin's Config schema and the live read face the wiring consumes.\n *\n * Every field is `volatile()`, which is what lets the configuration card on the\n * Plugins page commit an edit into these refs without remounting the plugin:\n * the wiring reads the current value on every delegation rather than a snapshot\n * taken when the Host loaded.\n *\n * The type-list rows carry no sequence number. The page assigns `1..n` from the\n * array order, the judge answers with that number, and the log shows it \u2014 so a\n * number can never be duplicated, and the reader never has to maintain one.\n */\n\nimport type { Volatile } from '@deepseek-ai/cordis';\nimport z from '@deepseek-ai/schemastery';\nimport type Schema from '@deepseek-ai/schemastery';\nimport { isSelectableRow } from './judge-prompt.ts';\nimport type { TypeRow } from './types.ts';\n\n/**\n * The settings namespace this plugin owns. A namespace IS the Profile entry id,\n * so the user-editable layer is this plugin's own row in the active profile's\n * patch \u2014 the same literal as the `id` in `cordis.patch.yml`, and a different\n * literal from the npm package name the card is keyed by.\n */\nexport const SETTINGS_NAMESPACE = 'dsh-subagent-judge-dispatch';\n\n/** Endpoint the page prefills: one System One example. */\nexport const DEFAULT_ENDPOINT_URL = 'http://127.0.0.1:3425/v1/systemone';\n\n/** Judge model the page prefills. */\nexport const DEFAULT_JUDGE_MODEL = 'future-jev/jev-latest';\n\n/** One type-list row as the configuration document stores it. */\nconst TypeRowSchema = z.object({\n /** Criterion text the judge reads for this type. */\n description: z.string().default(''),\n /** Provider route of the model this type runs on. */\n provider: z.string().default(''),\n /** Model id interpreted by that provider. */\n model: z.string().default(''),\n /** Reasoning effort id this type runs at. */\n effort: z.string().default(''),\n});\n\n/** This plugin's live configuration. */\nexport const Config: Schema = z.object({\n /** Whether a judgement may rewrite a subagent's model and effort. */\n enabled: z.boolean().default(true).volatile(),\n /** Whether judgements are written to the plugin's own log. */\n logEnabled: z.boolean().default(true).volatile(),\n /** Full judge endpoint URL. */\n endpointUrl: z.string().default(DEFAULT_ENDPOINT_URL).volatile(),\n /** Judge model id. */\n judgeModel: z.string().default(DEFAULT_JUDGE_MODEL).volatile(),\n /** The task-type list, in page order. */\n rows: z.array(TypeRowSchema).default([]).volatile(),\n});\n\n/** Fields of this plugin's Config as the runtime resolved them. */\nexport interface PluginConfigRefs {\n readonly enabled: Volatile<boolean>;\n readonly logEnabled: Volatile<boolean>;\n readonly endpointUrl: Volatile<string>;\n readonly judgeModel: Volatile<string>;\n readonly rows: Volatile<StoredRow[]>;\n}\n\n/** One stored row, before the page assigns its sequence number. */\nexport interface StoredRow {\n description: string;\n provider: string;\n model: string;\n effort: string;\n}\n\n/** A detached plain read of this plugin's configuration. */\nexport interface ResolvedConfig {\n enabled: boolean;\n logEnabled: boolean;\n endpointUrl: string;\n judgeModel: string;\n rows: TypeRow[];\n}\n\n/**\n * Read the current committed value of every Config field, numbering the rows.\n * @param refs - the runtime-resolved Config object.\n * @returns a detached plain config value.\n */\nexport function readPluginConfig(refs: PluginConfigRefs): ResolvedConfig {\n const stored = refs.rows.get();\n const rows: TypeRow[] = (Array.isArray(stored) ? stored : []).map((row, index) => ({\n // The number is positional, so deleting a row renumbers the rest. A log\n // entry written before that edit may therefore name a different type; the\n // reader accepted that when choosing continuous numbering.\n id: index + 1,\n description: typeof row?.description === 'string' ? row.description : '',\n provider: typeof row?.provider === 'string' ? row.provider : '',\n model: typeof row?.model === 'string' ? row.model : '',\n effort: typeof row?.effort === 'string' ? row.effort : '',\n }));\n return {\n enabled: refs.enabled.get() !== false,\n logEnabled: refs.logEnabled.get() !== false,\n endpointUrl: typeof refs.endpointUrl.get() === 'string' ? refs.endpointUrl.get() : DEFAULT_ENDPOINT_URL,\n judgeModel: typeof refs.judgeModel.get() === 'string' ? refs.judgeModel.get() : DEFAULT_JUDGE_MODEL,\n rows,\n };\n}\n\n/**\n * Whether a judgement would do anything at all: the model-rewrite switch is on,\n * a judge endpoint and model are named, and at least one row is selectable.\n *\n * @param config - the resolved configuration.\n * @returns whether a delegation would be judged.\n */\nexport function isJudgeUsable(config: ResolvedConfig): boolean {\n if (!config.enabled) return false;\n if (config.endpointUrl.trim() === '' || config.judgeModel.trim() === '') return false;\n return config.rows.some(isSelectableRow);\n}\n", "/**\n * The judgement request the plugin sends, and the answer it reads back.\n *\n * Two pure functions live here, so the whole \"what did the judge decide\"\n * question is answerable without a Host, a socket, or a timer:\n *\n * - {@link buildJudgeRequest} turns the type list plus the task text into the\n * exact body that goes out.\n * - {@link readJudgeAnswer} turns whatever came back into a decision, treating\n * every malformed, empty or off-list answer as \"no decision\" rather than\n * inventing one.\n *\n * The protocol is the System One one: POST a body of `{ model, state,\n * questions }`, where each question is a `choice` carrying an `instructions`\n * line and a `criteria` map of option id to the text that option means. The\n * answer names the chosen option id.\n */\n\nimport type { TypeRow } from './types.ts';\n\n/** The one question key the plugin asks. */\nexport const QUESTION_KEY = 'task_type';\n\n/**\n * The question's instructions line.\n *\n * It says what to weigh, not what the types are: the types themselves arrive as\n * the criteria map, so the reader's own descriptions are the whole criterion\n * list and nothing here can drift from them.\n */\nexport const QUESTION_INSTRUCTIONS =\n 'Which single task type below does the delegated job best match? '\n + 'Weigh what the job actually requires, not how it is phrased. '\n + 'Answer with the number of exactly one listed type.';\n\n/** The option id the connectivity check offers: the only one it offers. */\nexport const PROBE_OPTION_ID = '1';\n\n/** The task text the connectivity check sends. */\nexport const PROBE_TASK_TEXT = '\u8FDE\u63A5\u6D4B\u8BD5\uFF1A\u8FD9\u662F\u4E00\u6B21\u5224\u65AD\u670D\u52A1\u7684\u8FDE\u901A\u6027\u68C0\u67E5\u3002';\n\n/**\n * The connectivity check's instructions.\n *\n * It asks for the one option that exists, so an endpoint that understands the\n * protocol at all can answer it: answering it wrong is a failure of the\n * protocol, not of the reader's task list.\n */\nexport const PROBE_INSTRUCTIONS =\n 'Answer with the number of the one option listed below.';\n\n/** The single criterion the connectivity check offers. */\nexport const PROBE_CRITERION = '\u786E\u8BA4\u8FD9\u6B21\u8C03\u7528\u53EF\u4EE5\u5B8C\u6210\u3002';\n\n/** One option of the judge's question. */\nexport interface JudgeChoice {\n type: 'choice';\n instructions: string;\n criteria: Record<string, string>;\n}\n\n/** The exact body sent to the judge endpoint. */\nexport interface JudgeRequest {\n model: string;\n state: { message: string };\n questions: { [QUESTION_KEY]: JudgeChoice };\n}\n\n/**\n * Whether one row is complete enough to be offered to the judge.\n *\n * A row needs its provider, model and effort: a half-filled row could otherwise\n * be chosen and then have nothing to write, which would turn the reader's\n * unfinished edit into a delegation that silently lost its route. This is the\n * ONE place that rule lives \u2014 the page, the config gate and the rewrite all ask\n * this function rather than restating the three comparisons.\n *\n * The parameter is narrowed to the three fields the rule reads, so the page's\n * draft row (which carries no sequence number) and the server's numbered row\n * both satisfy it without either shape being converted into the other.\n *\n * @param row - one row, numbered or drafted.\n * @returns whether the judge may choose it.\n */\nexport function isSelectableRow(row: Pick<TypeRow, 'provider' | 'model' | 'effort'>): boolean {\n return row.provider.trim() !== '' && row.model.trim() !== '' && row.effort.trim() !== '';\n}\n\n/**\n * Which rows may be offered to the judge.\n * @param rows - every row on the page, in page order.\n * @returns the rows the judge may choose, in page order.\n */\nexport function selectableRows(rows: readonly TypeRow[]): TypeRow[] {\n return rows.filter(isSelectableRow);\n}\n\n/**\n * How much of a delegated task's opening the judge reads.\n *\n * The judge answers one multiple-choice question; the opening of a task says\n * what kind of job it is, and the rest is usually detail the choice does not\n * turn on. Bounding it keeps the request small and keeps one enormous\n * delegation from crowding out the type list it is being weighed against.\n */\nexport const SUBJECT_HEAD_CHARS = 1400;\n\n/**\n * How much of a task's closing the judge reads.\n *\n * Supplementary requirements are written at the end \u2014 \"also run the review\" \u2014\n * so the tail is kept rather than the middle.\n */\nexport const SUBJECT_TAIL_CHARS = 400;\n\n/** Opening words of the label line the judge reads above the task. */\nexport const LABEL_PREFIX = 'Delegation label: ';\n\n/**\n * Build the subject the judge is asked to classify.\n *\n * Two parts, in the order the reader would put them: the delegation's own label\n * \u2014 a summary the delegating agent wrote, which carries its intent \u2014 and then\n * the task text itself. The label alone is a display phrase of a few words, too\n * little to classify by; the task text alone loses that intent when it opens\n * with boilerplate.\n *\n * @param label - the delegation label, or '' when the child has none.\n * @param taskText - the delegated task text, or '' when it cannot be read.\n * @returns the subject to send, bounded to {@link SUBJECT_HEAD_CHARS} plus\n * {@link SUBJECT_TAIL_CHARS} characters of task text.\n */\nexport function composeJudgeSubject(label: string, taskText: string): string {\n const task = clipTaskText(taskText.trim());\n const heading = label.trim();\n if (heading === '') return task;\n return task === '' ? LABEL_PREFIX + heading : `${LABEL_PREFIX}${heading}\\n\\n${task}`;\n}\n\n/**\n * Bound a task text to its opening and closing.\n *\n * The dropped middle is named rather than silently removed, so a reader looking\n * at the logged request can tell truncation from a short task. The marker is\n * English like the rest of the protocol, so it reads as a note from the plugin\n * rather than as part of the task, whatever language the task is written in.\n *\n * @param text - the task text.\n * @returns the text, or its head and tail around a count of what was dropped.\n */\nfunction clipTaskText(text: string): string {\n if (text.length <= SUBJECT_HEAD_CHARS + SUBJECT_TAIL_CHARS) return text;\n const dropped = text.length - SUBJECT_HEAD_CHARS - SUBJECT_TAIL_CHARS;\n const head = text.slice(0, SUBJECT_HEAD_CHARS);\n const tail = text.slice(text.length - SUBJECT_TAIL_CHARS);\n return `${head}\\n\u2026 (${dropped} characters omitted) \u2026\\n${tail}`;\n}\n\n/**\n * Build the exact body sent to the judge endpoint.\n *\n * @param rows - the selectable rows, in page order.\n * @param model - the judge model id.\n * @param subject - the text the judge classifies, from {@link composeJudgeSubject}.\n * @returns the request body.\n */\nexport function buildJudgeRequest(\n rows: readonly TypeRow[],\n model: string,\n subject: string,\n): JudgeRequest {\n const criteria: Record<string, string> = {};\n for (const row of rows) criteria[String(row.id)] = row.description;\n return {\n model,\n state: { message: subject },\n questions: {\n [QUESTION_KEY]: {\n type: 'choice',\n instructions: QUESTION_INSTRUCTIONS,\n criteria,\n },\n },\n };\n}\n\n/**\n * Build the body the connectivity check sends.\n *\n * It carries its own single option rather than the reader's task types: the\n * question the button answers is \"does this endpoint and model work\", and that\n * question has an answer before any type list exists. Requiring a finished list\n * first would make the check unable to tell a reader with an empty list from a\n * reader whose endpoint is down.\n *\n * @param model - the judge model id.\n * @returns the request body.\n */\nexport function buildProbeRequest(model: string): JudgeRequest {\n return {\n model,\n state: { message: PROBE_TASK_TEXT },\n questions: {\n [QUESTION_KEY]: {\n type: 'choice',\n instructions: PROBE_INSTRUCTIONS,\n criteria: { [PROBE_OPTION_ID]: PROBE_CRITERION },\n },\n },\n };\n}\n\n/**\n * Serialize one request body the way the page shows it.\n *\n * Both the preview and a logged judgement display this text, while the call\n * itself sends the same object compacted onto the wire. Deriving both from one\n * body is what keeps the shown text from describing a different request than\n * the one that went out.\n *\n * @param body - the request body.\n * @returns the pretty-printed JSON.\n */\nexport function formatJudgeRequest(body: JudgeRequest): string {\n return JSON.stringify(body, null, 2);\n}\n\n/**\n * The text the configuration page's preview shows.\n *\n * It is the request body minus the subject, because no delegation exists until\n * one happens; the preview marks both spots the subject will fill rather than\n * inventing a task. The two markers are told apart, because the real subject is\n * a label line followed by the task text and the preview should read that way.\n *\n * @param rows - the selectable rows, in page order.\n * @param model - the judge model id.\n * @returns the pretty-printed preview text.\n */\nexport function buildPreview(rows: readonly TypeRow[], model: string): string {\n return formatJudgeRequest(\n buildJudgeRequest(rows, model, composeJudgeSubject('\uFF08\u6D3E\u5DE5\u65F6\u624D\u586B\uFF1A\u6D3E\u5DE5\u6807\u7B7E\uFF09', '\uFF08\u6D3E\u5DE5\u65F6\u624D\u586B\uFF1A\u4EFB\u52A1\u6B63\u6587\uFF09')),\n );\n}\n\n/** What reading the judge's answer produced. */\nexport type JudgeDecision =\n | { kind: 'row'; row: TypeRow }\n | { kind: 'empty' }\n | { kind: 'unmatched' };\n\n/**\n * Find the chosen option id inside whatever the endpoint answered.\n *\n * The protocol's own shape is `answers.<key>.choice`; the two fallbacks are the\n * ones the reference clients read, so an endpoint that answers the shorter way\n * still works. Anything else \u2014 a missing body, a non-string, an empty string \u2014\n * yields `undefined` and is treated as no answer.\n *\n * @param payload - the decoded response body.\n * @returns the chosen option id, or undefined when the body names none.\n */\nexport function readChoice(payload: unknown): string | undefined {\n if (typeof payload !== 'object' || payload === null) return undefined;\n const body = payload as Record<string, unknown>;\n const answers = body.answers;\n const fromAnswers =\n typeof answers === 'object' && answers !== null\n ? (answers as Record<string, unknown>)[QUESTION_KEY]\n : undefined;\n const candidate = fromAnswers ?? body[QUESTION_KEY];\n if (typeof candidate === 'object' && candidate !== null) {\n const choice = (candidate as Record<string, unknown>).choice;\n if (typeof choice === 'string' && choice.trim() !== '') return choice.trim();\n if (typeof choice === 'number' && Number.isFinite(choice)) return String(choice);\n return undefined;\n }\n if (typeof candidate === 'string' && candidate.trim() !== '') return candidate.trim();\n if (typeof candidate === 'number' && Number.isFinite(candidate)) return String(candidate);\n return undefined;\n}\n\n/**\n * Turn the judge's answer into a decision.\n *\n * The choice is the type row's number. Matching is by that number's numeric\n * value, so an endpoint that answers `\"3\"` and one that answers `3` agree; a\n * number no listed row carries is `unmatched`, and a body naming no choice at\n * all is `empty`. Both travel to the log as their own reason, because \"it\n * answered nothing\" and \"it answered something I do not have\" send the reader\n * to different fixes.\n *\n * @param payload - the decoded response body.\n * @param rows - the selectable rows, in page order.\n * @returns the decision.\n */\nexport function readJudgeAnswer(payload: unknown, rows: readonly TypeRow[]): JudgeDecision {\n const choice = readChoice(payload);\n if (choice === undefined) return { kind: 'empty' };\n const wanted = Number(choice);\n if (!Number.isFinite(wanted)) return { kind: 'unmatched' };\n const row = rows.find((candidate) => candidate.id === wanted);\n return row === undefined ? { kind: 'unmatched' } : { kind: 'row', row };\n}\n", "/**\n * Where the judgement key lives, and the Host service it is read through.\n *\n * The reference name is a constant of the plugin rather than a setting: the\n * page asks for the key itself and stores it write-only through the DSH\n * credentials service, so a reader never has to know what a \"credential\n * reference\" is, and no surface can point the plugin at somebody else's key.\n * This module imports nothing, so both halves can share the literal.\n *\n * The key value crosses in one direction only: it is written, and read back by\n * the Host half alone. The browser face reads a status-only view.\n */\n\n/** Credential reference the judgement key is stored under. */\nexport const JUDGE_API_KEY_REF = 'SUBAGENT_JUDGE_API_KEY';\n\n/** Minimal structural shape of the Host's `ctx.credentials` service. */\nexport interface CredentialsServiceLike {\n /** Resolve a reference to its stored or inherited value. */\n resolve(ref: string): Promise<{ value: string; source?: string } | undefined>;\n /** Status-only view of a reference; never returns the plaintext value. */\n describe(ref: string): Promise<{ configured: boolean; source?: string; writable: boolean }>;\n /** Store a non-empty value under a reference. */\n set(ref: string, value: string): Promise<void>;\n /** Remove a reference from the document. */\n unset(ref: string): Promise<void>;\n}\n\n/** Minimal structural shape of the browser's `ctx.remote.credentials` face. */\nexport interface CredentialsRemoteLike {\n describe(refs: string[]): Promise<\n { ok: true; value: Record<string, { configured: boolean; source?: string; writable: boolean }> }\n | { ok: false; error: { message: string } }\n >;\n set(ref: string, value: string): Promise<{ ok: true } | { ok: false; error: { message: string } }>;\n unset(ref: string): Promise<{ ok: true } | { ok: false; error: { message: string } }>;\n}\n", "/**\n * The decision half: given what the judge said, decide exactly what to write\n * onto a subagent's next model call \u2014 or write nothing at all.\n *\n * This module holds the one rule that matters most, so it is a pure function\n * that a test can drive directly: **any** judgement that did not end in a\n * usable row writes nothing. Not \"writes the inherited values\", not \"writes a\n * partial route\" \u2014 nothing. Writing anything is a replacement, so a fallback\n * that wrote the parent's own values back would still be an overwrite, and a\n * partial write would drop the inherited reasoning effort\n * (`resolveChildAgentOptions` deletes it when a route changes without one).\n */\n\nimport { isSelectableRow } from './judge-prompt.ts';\nimport type { FallbackReason, JudgeOutcome, TypeRow } from './types.ts';\n\n/** The three fields a rewrite carries, all present or none at all. */\nexport interface RouteRewrite {\n provider: string;\n model: string;\n reasoningEffort: string;\n}\n\n/** What to write for one judged subagent. */\nexport type DispatchDecision =\n | { kind: 'rewrite'; rewrite: RouteRewrite }\n | { kind: 'none' };\n\n/**\n * Turn a judgement into the rewrite it authorises.\n *\n * The three fields travel as one object because they must be written as one:\n * a route change without an explicit effort makes the Host drop the inherited\n * effort, so a caller can never be handed two of the three.\n *\n * @param outcome - what the judge call produced.\n * @returns the rewrite, or `none` when the child must inherit unchanged.\n */\nexport function decideRewrite(outcome: JudgeOutcome): DispatchDecision {\n if (outcome.kind !== 'matched') return { kind: 'none' };\n const row: TypeRow = outcome.row;\n // A row the judge could select but that is missing a piece is not a rewrite\n // this plugin may make; leaving the child alone is always safe.\n if (!isSelectableRow(row)) return { kind: 'none' };\n return {\n kind: 'rewrite',\n rewrite: {\n provider: row.provider.trim(),\n model: row.model.trim(),\n reasoningEffort: row.effort.trim(),\n },\n };\n}\n\n/**\n * Why a delegation ended up inheriting, as the log reports it.\n *\n * The judge answering nothing, the judge answering a number this list does not\n * have, an unreachable endpoint and an expired budget are four different fixes\n * for the reader \u2014 \"it answered nothing\" points at the endpoint, \"no listed\n * type\" points at the descriptions. A selected row that turned out to be missing\n * a field is a fifth: the judgement worked, the row it named was not usable.\n *\n * A judgement that produced a rewrite has no reason at all.\n *\n * @param outcome - what the judge call produced.\n * @param decision - what was written for it.\n * @returns the reason to record, or undefined when the rewrite landed.\n */\nexport function outcomeReason(\n outcome: JudgeOutcome,\n decision: DispatchDecision,\n): FallbackReason | undefined {\n if (decision.kind === 'rewrite') return undefined;\n if (outcome.kind !== 'matched') return outcome.reason;\n return 'incomplete';\n}\n\n", "/**\n * Reading one subagent's identity, from the child Agent and the session log.\n *\n * When the child is created the plugin holds a child Agent and nothing else: no\n * delegation record, no parent handle. Everything the log needs \u2014 what the child\n * was asked to do, and which conversation asked for it \u2014 has to be read back out\n * of durable session facts: the child's own events, and the delegating call the\n * parent has already logged.\n */\n\n/**\n * The read surface of a Session this module needs; kept structural for tests.\n *\n * `ownEvents` (or `snapshotEvents(inheritedEventCount)`) is the child-owned tail\n * of the log. It matters: a forked child's log opens with the parent's finished\n * turns, so reading from the start would hand the judge the ANCESTOR's\n * descriptor label and the parent conversation's first message.\n */\nexport interface SessionLike {\n readonly header: { readonly parentSession?: string; readonly delegationDepth?: number };\n readonly inheritedEventCount?: number;\n ownEvents?(): readonly SessionEventLike[];\n snapshotEvents(from?: number): readonly SessionEventLike[];\n}\n\n/** One session event as this module reads it. */\nexport interface SessionEventLike {\n readonly type: string;\n readonly data?: unknown;\n}\n\n/** The read surface of an Agent this module needs. */\nexport interface AgentLike {\n readonly id: string;\n readonly options: { readonly subagentDepth?: number };\n readonly session: SessionLike;\n}\n\n/**\n * Read only the events this child itself produced.\n *\n * A forked child inherits the parent's completed prefix, and the inherited part\n * carries an ancestor's descriptor and the parent's own messages. Everything\n * this module reads must come from the child-owned tail, or the judge is told\n * about a different agent's job. Three shapes are accepted because the session\n * type is structural here: `ownEvents()`, `snapshotEvents(from)` with the\n * inherited count, and a plain full read as the last resort.\n *\n * @param session - the child's session.\n * @returns the child-owned events, in log order.\n */\nexport function ownEventsOf(session: SessionLike): readonly SessionEventLike[] {\n if (typeof session.ownEvents === 'function') return session.ownEvents();\n const inherited = session.inheritedEventCount;\n if (typeof inherited === 'number' && Number.isSafeInteger(inherited) && inherited > 0) {\n return session.snapshotEvents(inherited);\n }\n return session.snapshotEvents();\n}\n\n/**\n * Whether one agent is a subagent, rather than a top-level conversation.\n *\n * Two sources are consulted because neither alone is complete: the durable\n * header is authoritative and monotone (a resumed child keeps its depth), while\n * `options.subagentDepth` is stamped onto the live options and may deepen the\n * count but never lower it. Absence in both means a top-level agent.\n *\n * @param agent - the agent making the request.\n * @returns whether this is a subagent.\n */\nexport function isSubagent(agent: AgentLike): boolean {\n const fromHeader = agent.session.header.delegationDepth;\n const fromOptions = agent.options.subagentDepth;\n const depth = Math.max(\n typeof fromHeader === 'number' && Number.isSafeInteger(fromHeader) ? fromHeader : 0,\n typeof fromOptions === 'number' && Number.isSafeInteger(fromOptions) ? fromOptions : 0,\n );\n return depth >= 1;\n}\n\n/** Opening words of the return guidance the Host appends to a delegation. */\nexport const RETURN_GUIDANCE_PREFIX = 'Your parent agent id is ';\n\n/**\n * Read the child's delegation description.\n *\n * The subagent tool passes the model's `description` as the activation label,\n * and the child's durable descriptor keeps it \u2014 which is why it is readable here\n * without the parent's tool call. Only the child's OWN events are read, and the\n * LAST descriptor wins: a resumed or re-activated child appends a fresh one, and\n * the newest is the delegation actually running.\n *\n * The label is a display summary the delegating agent wrote, so it is returned\n * on its own and never merged with the task text: the judge gets the label as a\n * heading over the task, and the log's subagent column gets the label alone.\n *\n * @param agent - the subagent.\n * @returns the description, or '' when its descriptor carries none.\n */\nexport function readChildLabel(agent: AgentLike): string {\n let found = '';\n for (const event of ownEventsOf(agent.session)) {\n if (event.type !== 'subagent/descriptor') continue;\n const data = event.data;\n if (typeof data !== 'object' || data === null) continue;\n const label = (data as { label?: unknown }).label;\n if (typeof label === 'string' && label.trim() !== '') found = label.trim();\n }\n return found;\n}\n\n/**\n * Read the task the parent delegated.\n *\n * The delegation is the message whose `source.kind` is `user`; every other\n * producer writes user-role messages too \u2014 the working directory notice,\n * workspace instructions, the runtime snapshot, the skill catalog, the time\n * snapshot \u2014 so the source is what separates the task from the context wrapped\n * around it.\n *\n * Two shapes carry that message, and both are read because the judgement runs\n * before the second one exists. A delegation starts as pending inbox input, so\n * it first appears inside an `agent/inbox/spliced` event; the Host claims it at\n * the step boundary and only then appends the `user/message` carrying it. The\n * judge is asked during the step's request, which is before that append \u2014 so\n * reading only `user/message` would find nothing on the very request that\n * matters. From the next step on the `user/message` is there instead.\n *\n * The Host appends its return guidance as one trailing block of that message.\n * It tells the child how to report back, not what the job is, so it is dropped:\n * leaving it in would spend most of the subject on boilerplate.\n *\n * Only the child's OWN events are read, because a forked child's log opens with\n * the parent's finished turns.\n *\n * @param agent - the subagent.\n * @returns the delegated task text, or '' when no delegation message exists.\n */\nexport function readTaskText(agent: AgentLike): string {\n for (const event of ownEventsOf(agent.session)) {\n const candidates = delegationMessagesOf(event);\n for (const data of candidates) {\n const blocks = textBlocksOf(data);\n // The guidance is appended last; a task that happens to open with the same\n // words is still honored because only the trailing block is examined.\n if (blocks.length > 1 && blocks[blocks.length - 1].startsWith(RETURN_GUIDANCE_PREFIX)) {\n blocks.pop();\n }\n const text = blocks.join('\\n').trim();\n if (text !== '') return text;\n }\n }\n return '';\n}\n\n/**\n * The parent-session lookup this module needs; kept structural for tests.\n */\nexport type ParentSessionLookup = (id: string) => SessionLike | undefined;\n\n/**\n * Read the task the parent delegated, at the moment the child is created.\n *\n * A fresh delegation reaches the child only after creation: the Host submits the\n * prompt as queued inbox input once the creation listeners return. So the child's\n * own log has no task yet, and the text is read from the delegating `tool/call`\n * the parent recorded before dispatching. A resumed child does carry the message\n * in its own log, which is why that read is tried first.\n *\n * The delegating call is identified by the description the parent wrote, which is\n * the same string the child's descriptor keeps as its label; the newest call with\n * a task prompt is the fallback when the labels cannot be matched.\n *\n * @param agent - the subagent.\n * @param parentSessionOf - resolves a session id to its live session.\n * @returns the delegated task text, or '' when no delegating call is readable.\n */\nexport function readDelegatedTask(agent: AgentLike, parentSessionOf: ParentSessionLookup): string {\n const own = readTaskText(agent);\n if (own !== '') return own;\n const parentId = agent.session.header.parentSession;\n if (typeof parentId !== 'string' || parentId === '') return '';\n const parent = parentSessionOf(parentId);\n if (parent === undefined || typeof parent.snapshotEvents !== 'function') return '';\n const label = readChildLabel(agent);\n const events = parent.snapshotEvents();\n let fallback = '';\n for (let index = events.length - 1; index >= 0; index -= 1) {\n const event = events[index];\n if (event.type !== 'tool/call') continue;\n const call = delegatedCallOf(event.data);\n if (call === undefined) continue;\n if (label !== '' && call.description === label) return call.prompt;\n if (fallback === '') fallback = call.prompt;\n }\n return fallback;\n}\n\n/** The task prompt and description of one recorded tool call, when it carries them. */\nfunction delegatedCallOf(data: unknown): { prompt: string; description?: string } | undefined {\n if (typeof data !== 'object' || data === null) return undefined;\n const raw = (data as { arguments?: unknown }).arguments;\n if (typeof raw !== 'string') return undefined;\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch {\n return undefined;\n }\n if (typeof parsed !== 'object' || parsed === null) return undefined;\n const record = parsed as { prompt?: unknown; description?: unknown };\n if (typeof record.prompt !== 'string' || record.prompt.trim() === '') return undefined;\n return {\n prompt: record.prompt,\n ...(typeof record.description === 'string' ? { description: record.description } : {}),\n };\n}\n\n/**\n * The messages one event contributes, in log order.\n *\n * A delegation message is written twice across a child's life \u2014 once as pending\n * inbox input, once as the committed `user/message` \u2014 so both event shapes are\n * unwrapped here and the caller keeps the first usable one.\n *\n * @param event - one child-owned session event.\n * @returns the delegation-shaped messages the event carries, possibly none.\n */\nfunction delegationMessagesOf(event: SessionEventLike): unknown[] {\n if (event.type === 'user/message') {\n return sourceOf(event.data)?.kind === 'user' ? [event.data] : [];\n }\n if (event.type === 'agent/inbox/spliced') {\n const inserted = (event.data as { inserted?: unknown } | undefined)?.inserted;\n if (!Array.isArray(inserted)) return [];\n return inserted.filter((message) => sourceOf(message)?.kind === 'user');\n }\n return [];\n}\n\n/** Read the durable producer facts off one message payload. */\nfunction sourceOf(data: unknown): { kind: string } | undefined {\n if (typeof data !== 'object' || data === null) return undefined;\n const source = (data as { source?: unknown }).source;\n if (typeof source !== 'object' || source === null) return undefined;\n const kind = (source as { kind?: unknown }).kind;\n return typeof kind === 'string' ? { kind } : undefined;\n}\n\n/** Pull the text blocks out of a message payload, in order. */\nfunction textBlocksOf(data: unknown): string[] {\n if (typeof data !== 'object' || data === null) return [];\n const content = (data as { content?: unknown }).content;\n if (!Array.isArray(content)) return [];\n const texts: string[] = [];\n for (const block of content) {\n if (typeof block !== 'object' || block === null) continue;\n const record = block as { type?: unknown; text?: unknown };\n if (record.type === 'text' && typeof record.text === 'string') texts.push(record.text);\n }\n return texts;\n}\n\n/**\n * Walk up a child's lineage to the top-level conversation that started it.\n *\n * A nested subagent's direct parent is another subagent, and the log's job is to\n * name the conversation the reader recognises \u2014 so the walk continues until a\n * session names no parent. The walk is bounded, because a resumed or forged\n * lineage must not be able to spin this loop.\n *\n * @param startId - the child's direct parent session id.\n * @param lookup - resolves a session id to its live session.\n * @returns the top-level session id, or the starting id when the walk stops.\n */\nexport function resolveRootSessionId(\n startId: string,\n lookup: (id: string) => SessionLike | undefined,\n): string {\n const seen = new Set<string>([startId]);\n let current = startId;\n for (let hop = 0; hop < 32; hop += 1) {\n const session = lookup(current);\n const parent = session?.header.parentSession;\n if (typeof parent !== 'string' || parent === '' || seen.has(parent)) return current;\n seen.add(parent);\n current = parent;\n }\n return current;\n}\n", "/**\n * The judge call itself: one POST, one budget, no retry.\n *\n * The call can fail in exactly four ways \u2014 unreachable, timed out, an answer\n * that names no option, an answer whose row is unusable \u2014 and every one of them\n * ends the same way for the caller: no rewrite happens and the child inherits\n * what the main agent is running. That is why nothing here throws: a delegation\n * must never fail because the judge was unavailable.\n */\n\nimport {\n PROBE_OPTION_ID,\n buildJudgeRequest,\n buildProbeRequest,\n formatJudgeRequest,\n readJudgeAnswer,\n} from './judge-prompt.ts';\nimport type { FallbackReason, JudgeOutcome, ProbeOutcome, TypeRow } from './types.ts';\n\n/** How long a judgement may take before it is abandoned. */\nexport const JUDGE_TIMEOUT_MS = 5000;\n\n/** What the judge client needs from the Host to make one call. */\nexport interface JudgeEndpoint {\n /** Full endpoint URL, including the protocol path. */\n url: string;\n /** Judge model id. */\n model: string;\n /** Authorization value, or '' when the endpoint needs none. */\n apiKey: string;\n}\n\n/** Structural `fetch` so tests can supply their own. */\nexport type FetchLike = (input: string, init: RequestInit) => Promise<Response>;\n\n/**\n * Ask the judge whether this endpoint and model can answer at all.\n *\n * This is a different question from a judgement, so it sends its own request\n * with its own single option: the reader uses the button to find out whether\n * the endpoint and model work, which is answerable before any task type has\n * been written. It never throws for the same reason a judgement never does \u2014\n * the page reports the reason, it does not handle an exception.\n *\n * @param endpoint - where and how to call the judge.\n * @param fetchImpl - the fetch to call; defaults to the global one.\n * @returns whether the endpoint answered, and how long it took.\n */\nexport async function probeJudge(\n endpoint: JudgeEndpoint,\n fetchImpl: FetchLike = fetch,\n): Promise<ProbeOutcome> {\n const startedAt = Date.now();\n const elapsed = (): number => Date.now() - startedAt;\n if (endpoint.url.trim() === '' || endpoint.model.trim() === '') {\n return { ok: false, latencyMs: elapsed(), reason: 'unconfigured' };\n }\n\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), JUDGE_TIMEOUT_MS);\n let timedOut = false;\n const onTimeout = (): void => {\n timedOut = true;\n };\n controller.signal.addEventListener('abort', onTimeout);\n\n try {\n const response = await fetchImpl(endpoint.url.trim(), {\n method: 'POST',\n headers: {\n 'content-type': 'application/json',\n ...endpoint.apiKey.trim() === '' ? {} : { authorization: `Bearer ${endpoint.apiKey.trim()}` },\n },\n body: JSON.stringify(buildProbeRequest(endpoint.model.trim())),\n signal: controller.signal,\n });\n if (!response.ok) return { ok: false, latencyMs: elapsed(), reason: 'unreachable' };\n const payload: unknown = await response.json();\n // The check asked for the one option it offered: any answer that names a\n // different option means the endpoint did not read the request it was sent.\n return readJudgeAnswer(payload, [{\n id: Number(PROBE_OPTION_ID),\n description: '',\n provider: '',\n model: '',\n effort: '',\n }]).kind === 'row'\n ? { ok: true, latencyMs: elapsed() }\n : { ok: false, latencyMs: elapsed(), reason: 'unmatched' };\n } catch {\n return { ok: false, latencyMs: elapsed(), reason: timedOut ? 'timeout' : 'unreachable' };\n } finally {\n clearTimeout(timer);\n controller.signal.removeEventListener('abort', onTimeout);\n }\n}\n\n/**\n * Ask the judge which type one delegated job is.\n *\n * Never throws and never lets an abort cancel the delegation: every failure is\n * reported as a `fallback` outcome carrying its own reason, and the caller\n * writes nothing.\n *\n * @param endpoint - where and how to call the judge.\n * @param rows - the selectable rows, in page order.\n * @param subject - the text to classify, from `composeJudgeSubject`.\n * @param fetchImpl - the fetch to call; defaults to the global one.\n * @returns the decision, or the fallback reason that replaced it.\n */\nexport async function judgeTaskType(\n endpoint: JudgeEndpoint,\n rows: readonly TypeRow[],\n subject: string,\n fetchImpl: FetchLike = fetch,\n): Promise<JudgeOutcome> {\n const startedAt = Date.now();\n const elapsed = (): number => Date.now() - startedAt;\n if (endpoint.url.trim() === '' || endpoint.model.trim() === '' || rows.length === 0) {\n return { kind: 'fallback', reason: 'unreachable', latencyMs: elapsed(), prompt: '' };\n }\n\n const body = buildJudgeRequest(rows, endpoint.model.trim(), subject);\n // The body the log keeps is the one sent, not a re-built one: the reader\n // opens it to see exactly what the judge was asked.\n const prompt = formatJudgeRequest(body);\n\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), JUDGE_TIMEOUT_MS);\n let timedOut = false;\n const onTimeout = (): void => {\n timedOut = true;\n };\n controller.signal.addEventListener('abort', onTimeout);\n\n try {\n const response = await fetchImpl(endpoint.url.trim(), {\n method: 'POST',\n headers: {\n 'content-type': 'application/json',\n // Sent only when there is a key: an unauthenticated local endpoint\n // would otherwise receive an empty Bearer and reject the call itself.\n ...endpoint.apiKey.trim() === '' ? {} : { authorization: `Bearer ${endpoint.apiKey.trim()}` },\n },\n body: JSON.stringify(body),\n signal: controller.signal,\n });\n if (!response.ok) {\n return { kind: 'fallback', reason: 'unreachable', latencyMs: elapsed(), prompt };\n }\n const payload: unknown = await response.json();\n const decision = readJudgeAnswer(payload, rows);\n if (decision.kind === 'empty') {\n return { kind: 'fallback', reason: 'unmatched', latencyMs: elapsed(), prompt };\n }\n if (decision.kind === 'unmatched') {\n return { kind: 'fallback', reason: 'unmatched', latencyMs: elapsed(), prompt };\n }\n return { kind: 'matched', row: decision.row, latencyMs: elapsed(), prompt };\n } catch {\n const reason: FallbackReason = timedOut ? 'timeout' : 'unreachable';\n return { kind: 'fallback', reason, latencyMs: elapsed(), prompt };\n } finally {\n clearTimeout(timer);\n controller.signal.removeEventListener('abort', onTimeout);\n }\n}\n", "/**\n * The plugin's own log, kept on disk under the DSH home.\n *\n * The Host's native subagent list has no model column and a plugin cannot add\n * one, so this log is the only place a delegation's assigned route is visible.\n * It outlives the Host process: a judgement that ran yesterday is still one\n * question away today.\n *\n * Two bounds, deliberately different. The file keeps {@link LOG_KEEP} entries\n * so \"what did it pick last time\" survives a restart, while the configuration\n * page shows only {@link LOG_PAGE_LIMIT}: the page is a glance at what just\n * happened, not a log viewer.\n */\n\nimport * as fs from 'node:fs/promises';\nimport * as path from 'node:path';\nimport { dshHomePath } from '@deepseek-ai/dsh-home-paths';\nimport type { LogEntry } from './types.ts';\n\n/** How many entries the file keeps. */\nexport const LOG_KEEP = 200;\n\n/** How many entries the configuration page shows. */\nexport const LOG_PAGE_LIMIT = 10;\n\n/**\n * Read one entry from a stored document value, tolerating a partial record.\n *\n * The file outlives the process, so a line written by another version may be\n * missing a field. Such a line keeps whatever it does carry rather than\n * rejecting the whole document.\n *\n * @param value - one element of the stored array.\n * @returns the entry, or undefined when the value is not an object.\n */\nfunction readEntry(value: unknown): LogEntry | undefined {\n if (typeof value !== 'object' || value === null) return undefined;\n const record = value as Record<string, unknown>;\n const text = (key: string): string => (typeof record[key] === 'string' ? (record[key] as string) : '');\n const count = (key: string): number =>\n typeof record[key] === 'number' && Number.isFinite(record[key]) ? (record[key] as number) : 0;\n return {\n typeId: typeof record.typeId === 'number' ? record.typeId : null,\n provider: text('provider'),\n model: text('model'),\n effort: text('effort'),\n ...typeof record.reason === 'string' ? { reason: record.reason as LogEntry['reason'] } : {},\n at: count('at'),\n latencyMs: count('latencyMs'),\n parentTitle: text('parentTitle'),\n childLabel: text('childLabel'),\n prompt: text('prompt'),\n };\n}\n\n/** A bounded, newest-first log backed by one JSON file. */\nexport class LogStore {\n private entries: LogEntry[] = [];\n private readonly filePath: string;\n /** The initial read, so an append issued before it lands cannot be overwritten by it. */\n private loading: Promise<void> | null = null;\n /** Writes are chained, so two appends cannot interleave their file replaces. */\n private writing: Promise<void> = Promise.resolve();\n\n /**\n * @param filePath - where the log lives; defaults to this plugin's own\n * directory under the DSH home.\n */\n constructor(filePath: string = dshHomePath('dsh-subagent-judge-dispatch', 'judgements.json')) {\n this.filePath = filePath;\n }\n\n /**\n * Load what a previous process wrote.\n *\n * A missing, unreadable or malformed file leaves the log empty; the next\n * append rewrites it. This method never rejects, because a broken log must\n * never stop a judgement.\n */\n init(): Promise<void> {\n this.loading ??= this.load();\n return this.loading;\n }\n\n /** Read the file once and adopt what it holds. */\n private async load(): Promise<void> {\n try {\n const raw = await fs.readFile(this.filePath, 'utf-8');\n const parsed = JSON.parse(raw) as unknown;\n const list = Array.isArray(parsed) ? parsed : [];\n // \u5148\u8BFB\u5230\u7684\u8BB0\u5F55\u6392\u5728\u8FD9\u6B21\u8FD0\u884C\u65B0\u5199\u7684\u90A3\u51E0\u6761\u540E\u9762\uFF0C\u8C01\u4E5F\u4E0D\u4F1A\u76D6\u6389\u8C01\u3002\n const stored = list\n .map(readEntry)\n .filter((entry): entry is LogEntry => entry !== undefined);\n this.entries = [...this.entries, ...stored].slice(0, LOG_KEEP);\n } catch {\n // \u6587\u4EF6\u4E0D\u5B58\u5728\u6216\u8BFB\u4E0D\u52A8\u5C31\u4ECE\u7A7A\u65E5\u5FD7\u8D77\u6B65\uFF1B\u8FD9\u6B21\u8FD0\u884C\u5DF2\u7ECF\u8FFD\u52A0\u7684\u8BB0\u5F55\u4FDD\u6301\u539F\u6837\u3002\n }\n }\n\n /**\n * Append one entry, dropping the oldest beyond {@link LOG_KEEP}, and write.\n *\n * The write starts at once rather than on a timer: a judgement is rare enough\n * that coalescing buys nothing, and a delayed write is a record a hard exit\n * can lose.\n *\n * @param entry - the entry to append.\n */\n append(entry: LogEntry): void {\n this.entries = [entry, ...this.entries].slice(0, LOG_KEEP);\n // \u78C1\u76D8\u91CC\u90A3\u4EFD\u5148\u8BFB\u5B8C\u518D\u5408\u5E76\uFF0C\u5426\u5219\u8FD9\u6B21\u521A\u8BB0\u4E0B\u7684\u4E00\u6761\u4F1A\u88AB\u521D\u59CB\u8BFB\u53D6\u6574\u4EFD\u6362\u6210\u65E7\u8BB0\u5F55\u3002\n // \u4E0A\u4E00\u7B14\u5199\u5728\u8D4B\u65B0\u503C\u4E4B\u524D\u53D6\u4E0B\u6765\uFF1A\u5199\u6210 `() => this.writing` \u4F1A\u7B49\u81EA\u5DF1\uFF0C\u6C38\u8FDC\u4E0D\u843D\u5730\u3002\n const previous = this.writing;\n const afterLoad = this.loading === null ? previous : this.loading.then(() => previous);\n this.writing = afterLoad.then(() => this.write()).catch((error) => {\n console.warn('[dsh-subagent-judge-dispatch] \u5224\u65AD\u65E5\u5FD7\u5199\u4E0D\u8FDB\u78C1\u76D8\uFF1A', error);\n });\n }\n\n /**\n * Read the whole kept log, newest first.\n * @returns a detached copy, so a reader cannot mutate the stored entries.\n */\n list(): LogEntry[] {\n return this.entries.map((entry) => ({ ...entry }));\n }\n\n /** Wait for the initial read and the writes already started to land. */\n async flush(): Promise<void> {\n if (this.loading !== null) await this.loading;\n await this.writing;\n }\n\n /** Replace the file atomically, so a crash cannot leave half a document. */\n private async write(): Promise<void> {\n const temp = `${this.filePath}.tmp.${Date.now()}.${Math.random().toString(36).slice(2)}`;\n try {\n await fs.mkdir(path.dirname(this.filePath), { recursive: true });\n await fs.writeFile(temp, JSON.stringify(this.entries, null, 2), 'utf-8');\n await fs.rename(temp, this.filePath);\n } catch (error) {\n try {\n await fs.unlink(temp);\n } catch {\n // The temp file may never have been created; nothing to clean up.\n }\n throw error;\n }\n }\n}\n", "import { opendir, realpath } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport { basename, dirname, join, resolve } from \"node:path\";\n//#region lib/types/index.js\n/**\n* Shared filesystem path helpers for DeepSeek Harness user data.\n*\n* @module @deepseek-ai/dsh-home-paths\n*/\n/** Directory name for the default DeepSeek Harness home under the OS home. */\nconst DSH_HOME_DIR_NAME = \".dsh\";\n/** Stable user-facing display form for the default DeepSeek Harness home. */\nconst DEFAULT_DSH_HOME_DISPLAY = `~/${DSH_HOME_DIR_NAME}`;\n/** Environment variable that overrides the default DeepSeek Harness home. */\nconst DSH_HOME_ENV = \"DSH_HOME\";\n/** Directory name for the default shared agent configuration root under the OS home. */\nconst AGENTS_HOME_DIR_NAME = \".agents\";\n/** Stable user-facing display form for the default shared agent configuration root. */\nconst DEFAULT_AGENTS_HOME_DISPLAY = `~/${AGENTS_HOME_DIR_NAME}`;\n/** Environment variable that overrides the default shared agent configuration root. */\nconst AGENTS_HOME_ENV = \"DSH_AGENTS_HOME\";\n/**\n* Give a native filesystem watcher one canonical spelling of a path, even\n* when its final components do not exist yet. The deepest existing ancestor\n* is resolved through {@link realpath}; when a suffix is missing, that\n* ancestor is also proved to be an enumerable directory before the suffix is\n* restored. This prevents Windows from treating a regular-file ancestor as\n* ordinary absence, and prevents short-name aliases from being mixed with\n* long paths emitted by the native watcher backend.\n* @param path - Watch target or root, resolved against the current directory.\n* @returns the target with its existing ancestor canonicalized.\n* @throws when ancestor traversal encounters an error other than absence, or\n* the existing ancestor of a missing suffix is not an enumerable directory.\n*/\nasync function canonicalizeWatchPath(path) {\n\tlet current = resolve(path);\n\tconst missing = [];\n\twhile (true) try {\n\t\tconst canonical = await realpath(current);\n\t\tif (missing.length > 0) await (await opendir(canonical)).close();\n\t\treturn join(canonical, ...missing.reverse());\n\t} catch (error) {\n\t\tif (error.code !== \"ENOENT\") throw error;\n\t\tconst parent = dirname(current);\n\t\t/* v8 ignore next -- a filesystem root exists, so traversal resolves before this guard */\n\t\tif (parent === current) throw error;\n\t\tmissing.push(basename(current));\n\t\tcurrent = parent;\n\t}\n}\n/**\n* Resolve the default DeepSeek Harness home using Node's platform path rules.\n* @returns the absolute default harness home path.\n*/\nfunction defaultDshHome() {\n\treturn join(homedir(), DSH_HOME_DIR_NAME);\n}\n/**\n* Resolve the default shared agent configuration root using Node's platform path rules.\n* @returns the absolute default shared agent configuration root.\n*/\nfunction defaultAgentsHome() {\n\treturn join(homedir(), AGENTS_HOME_DIR_NAME);\n}\n/**\n* Expand supported tilde prefixes against the operating-system home.\n* @param path - configured path that may begin with `~`, `~/`, or `~\\`.\n* @returns the expanded path, or the original value when no supported prefix is present.\n*/\nfunction expandHomePath(path) {\n\tif (path === \"~\") return homedir();\n\tif (path.startsWith(\"~/\") || path.startsWith(\"~\\\\\")) return join(homedir(), path.slice(2));\n\treturn path;\n}\n/**\n* Resolve one user-data root from an explicit path, an environment override, and a default.\n* @param configured - explicit path, which has highest precedence.\n* @param env - environment mapping to read.\n* @param envName - environment variable that overrides the default.\n* @param fallback - default root, used when neither the explicit path nor the environment provides one.\n* @returns the normalized absolute root.\n*/\nfunction resolveRoot(configured, env, envName, fallback) {\n\tconst fromEnv = env[envName];\n\treturn resolve(expandHomePath(configured ?? (fromEnv !== void 0 && fromEnv.trim().length > 0 ? fromEnv : fallback())));\n}\n/**\n* Label one resolved user-data root symbolically for user-facing display.\n* @param resolvedRoot - absolute path returned by the matching resolver.\n* @param defaultRoot - absolute default root whose symbolic label applies to a match.\n* @param defaultLabel - symbolic label for the default root.\n* @param envName - environment variable name that labels any other root.\n* @returns the symbolic label.\n*/\nfunction rootDisplay(resolvedRoot, defaultRoot, defaultLabel, envName) {\n\treturn resolvedRoot === resolve(defaultRoot) ? defaultLabel : `$${envName}`;\n}\n/**\n* Resolve the single-root DeepSeek Harness home.\n*\n* Precedence, highest first: an explicit configured path, `$DSH_HOME`, then\n* `~/.dsh`. The harness keeps all user data under one root. An empty or\n* whitespace-only `$DSH_HOME` is treated as unset, so a blank override never\n* resolves the home to the current working directory.\n* @param configured - explicit harness-home override, which has highest precedence.\n* @param env - environment mapping used to read `DSH_HOME`.\n* @returns the normalized absolute harness home path.\n*/\nfunction resolveDshHome(configured, env = process.env) {\n\treturn resolveRoot(configured, env, DSH_HOME_ENV, defaultDshHome);\n}\n/**\n* Resolve the shared agent configuration root.\n*\n* Precedence, highest first: an explicit configured path, `$DSH_AGENTS_HOME`,\n* then `~/.agents`. The root holds configuration shared with other agent tools,\n* so it stays independent of the DeepSeek Harness home. An empty or\n* whitespace-only `$DSH_AGENTS_HOME` is treated as unset, so a blank override\n* never resolves the root to the current working directory.\n* @param configured - explicit shared-root override, which has highest precedence.\n* @param env - environment mapping used to read `DSH_AGENTS_HOME`.\n* @returns the normalized absolute shared agent configuration root.\n*/\nfunction resolveAgentsHome(configured, env = process.env) {\n\treturn resolveRoot(configured, env, AGENTS_HOME_ENV, defaultAgentsHome);\n}\n/**\n* Join path segments onto the resolved DeepSeek Harness home.\n* @param segments - path segments appended to the Harness home; an empty list returns the home itself.\n* @returns the normalized absolute joined path.\n*/\nfunction dshHomePath(...segments) {\n\treturn join(resolveDshHome(), ...segments);\n}\n/**\n* Join path segments onto the resolved Harness home's `cache` directory without creating it; no arguments returns the directory itself.\n* @param optionsOrSegment - explicit home override, or the first path segment; omission uses the default home resolution.\n* @param segments - additional path segments after the first child, if any.\n* @returns the normalized absolute cache path.\n*/\nfunction dshCachePath(optionsOrSegment = {}, ...segments) {\n\tif (typeof optionsOrSegment === \"string\") return dshHomePath(\"cache\", optionsOrSegment, ...segments);\n\treturn join(resolveDshHome(optionsOrSegment.dshHome), \"cache\", ...segments);\n}\n/**\n* Describe a resolved harness home symbolically for user-facing display.\n*\n* It never returns an absolute machine path: the default home is labelled\n* `~/.dsh`, and any configured home is labelled `$DSH_HOME`.\n* @param resolvedHome - the absolute path returned by {@link resolveDshHome}.\n* @returns `~/.dsh` for the default home, otherwise `$DSH_HOME`.\n*/\nfunction dshHomeDisplay(resolvedHome) {\n\treturn rootDisplay(resolvedHome, defaultDshHome(), DEFAULT_DSH_HOME_DISPLAY, DSH_HOME_ENV);\n}\n/**\n* Describe a resolved shared agent configuration root symbolically for user-facing display.\n*\n* It never returns an absolute machine path: the default root is labelled\n* `~/.agents`, and any configured root is labelled `$DSH_AGENTS_HOME`.\n* @param resolvedHome - the absolute path returned by {@link resolveAgentsHome}.\n* @returns `~/.agents` for the default root, otherwise `$DSH_AGENTS_HOME`.\n*/\nfunction agentsHomeDisplay(resolvedHome) {\n\treturn rootDisplay(resolvedHome, defaultAgentsHome(), DEFAULT_AGENTS_HOME_DISPLAY, AGENTS_HOME_ENV);\n}\n//#endregion\nexport { AGENTS_HOME_DIR_NAME, AGENTS_HOME_ENV, DEFAULT_AGENTS_HOME_DISPLAY, DEFAULT_DSH_HOME_DISPLAY, DSH_HOME_DIR_NAME, DSH_HOME_ENV, agentsHomeDisplay, canonicalizeWatchPath, defaultAgentsHome, defaultDshHome, dshCachePath, dshHomeDisplay, dshHomePath, expandHomePath, resolveAgentsHome, resolveDshHome };\n", "/**\n * This plugin's exact Fetch routes, carried by Connection's authenticated\n * `/api` transport below the shared channel.\n *\n * Three surfaces, and no fourth: configuration is read and written through\n * DSH's own shared configuration form (`ctx.configForms`) and the `credentials`\n * Remote API, so nothing here touches either. What is left is what only the\n * Host knows \u2014 the runtime log, the exact text a judgement would send, and\n * whether the judge endpoint answers at all.\n */\n\nimport type { ConnectionFetchRoute } from '@deepseek-ai/dsh-client-connection';\nimport { buildPreview, selectableRows } from './judge-prompt.ts';\nimport { LOG_PAGE_LIMIT } from './log-store.ts';\nimport { probeJudge } from './judge-client.ts';\nimport type { ResolvedConfig } from './config.ts';\nimport type { LogEntry } from './types.ts';\n\n/** Runtime log route path. */\nexport const LOG_ROUTE_PATH = '/api/dsh-subagent-judge-dispatch/log';\n\n/** Exact judge-prompt preview route path. */\nexport const PREVIEW_ROUTE_PATH = '/api/dsh-subagent-judge-dispatch/preview';\n\n/** Judge endpoint probe route path. */\nexport const PROBE_ROUTE_PATH = '/api/dsh-subagent-judge-dispatch/probe';\n\nfunction sendJson(status: number, body: unknown): Response {\n return new Response(JSON.stringify(body), {\n status,\n headers: { 'Content-Type': 'application/json; charset=utf-8' },\n });\n}\n\n/** What one probe reports back to the page. */\nexport interface ProbeResult {\n ok: boolean;\n latencyMs: number;\n /** Which failure it was, when it failed. */\n reason?: string;\n}\n\n/** The Host-side face the routes read. */\nexport interface DispatchRouteFace {\n /** Current committed configuration. */\n config(): ResolvedConfig;\n /** Read the whole kept log, newest first; may resolve once the file has been read. */\n log(): LogEntry[] | Promise<LogEntry[]>;\n /** The judge key resolved from credentials, or '' when unset. */\n apiKey(): string;\n}\n\n/**\n * Build this plugin's Fetch routes.\n * @param face - the Host-side reads the routes serve.\n * @returns the routes to register on Connection.\n */\nexport function createFetchRoutes(face: DispatchRouteFace): ConnectionFetchRoute[] {\n const log: ConnectionFetchRoute = {\n path: LOG_ROUTE_PATH,\n methods: ['GET'],\n requestBody: 'buffered',\n fetch: async () => {\n try {\n // The page shows only the tail of the log; the file keeps the rest.\n return sendJson(200, { ok: true, entries: (await face.log()).slice(0, LOG_PAGE_LIMIT) });\n } catch (err) {\n return sendJson(500, { ok: false, error: describe(err) });\n }\n },\n };\n\n const preview: ConnectionFetchRoute = {\n path: PREVIEW_ROUTE_PATH,\n methods: ['GET'],\n requestBody: 'buffered',\n fetch: async () => {\n try {\n const config = face.config();\n // Built by the same function the real call uses, so what the page shows\n // cannot drift from what goes out.\n const text = buildPreview(selectableRows(config.rows), config.judgeModel.trim());\n return sendJson(200, { ok: true, preview: text });\n } catch (err) {\n return sendJson(500, { ok: false, error: describe(err) });\n }\n },\n };\n\n const probe: ConnectionFetchRoute = {\n path: PROBE_ROUTE_PATH,\n methods: ['POST'],\n requestBody: 'buffered',\n fetch: async () => {\n try {\n const config = face.config();\n // \u53EA\u95EE\u300C\u8FD9\u4E2A\u5730\u5740\u4E0E\u6A21\u578B\u7B54\u4E0D\u7B54\u5F97\u4E0A\u6765\u300D\uFF0C\u6240\u4EE5\u4E0D\u95EE\u7C7B\u578B\u6E05\u5355\uFF1A\u6E05\u5355\u662F\u5224\u65AD\u65F6\u624D\n // \u9700\u8981\u7684\u8F93\u5165\uFF0C\u62FF\u5B83\u5F53\u4F5C\u80FD\u4E0D\u80FD\u6D4B\u7684\u524D\u63D0\uFF0C\u4F1A\u8BA9\u7A7A\u6E05\u5355\u7684\u8BFB\u8005\u4EE5\u4E3A\u670D\u52A1\u574F\u4E86\u3002\n const outcome = await probeJudge({\n url: config.endpointUrl,\n model: config.judgeModel,\n apiKey: face.apiKey(),\n });\n return sendJson(200, { ...outcome } satisfies ProbeResult);\n } catch (err) {\n return sendJson(500, { ok: false, error: describe(err) });\n }\n },\n };\n\n return [log, preview, probe];\n}\n\n/** One-line error text for a route failure. */\nfunction describe(err: unknown): string {\n return err instanceof Error ? err.message : String(err);\n}\n", "import type { HostConnectionHandle } from '@deepseek-ai/dsh-client-connection';\nimport {\n isJudgeUsable,\n readPluginConfig,\n SETTINGS_NAMESPACE,\n type PluginConfigRefs,\n type ResolvedConfig,\n} from './server/config.ts';\nimport { JUDGE_API_KEY_REF, type CredentialsServiceLike } from './server/credentials.ts';\nimport { decideRewrite, outcomeReason } from './server/dispatch.ts';\nimport {\n isSubagent,\n readChildLabel,\n readDelegatedTask,\n resolveRootSessionId,\n type SessionLike,\n} from './server/identity.ts';\nimport { judgeTaskType } from './server/judge-client.ts';\nimport { composeJudgeSubject, selectableRows } from './server/judge-prompt.ts';\nimport { LogStore } from './server/log-store.ts';\nimport { createFetchRoutes } from './server/router.ts';\nimport type { LogEntry } from './server/types.ts';\n\n/**\n * Stable Cordis loader name; the same literal as the `id` of this plugin's row\n * in `cordis.patch.yml` and as its settings namespace.\n */\nexport const name = SETTINGS_NAMESPACE;\n\n/**\n * Declared services. `credentials` is the DSH-owned secret surface the judge key\n * is read through; `sessions` and `sessionTitle` turn a child Agent's id into the\n * conversation title the log shows. The Fetch routes ride Connection's\n * authenticated transport, which only a Web carrier composes, so they are taken\n * through `ctx.inject` and the plugin still loads without one.\n */\nexport const inject = ['credentials', 'sessions', 'sessionTitle'];\n\nexport { Config, DEFAULT_ENDPOINT_URL, DEFAULT_JUDGE_MODEL } from './server/config.ts';\nexport { JUDGE_API_KEY_REF } from './server/credentials.ts';\n\n/** Minimal structural shape of the `sessionTitle` service. */\ninterface SessionTitleLike {\n get(session: unknown): { title: string } | undefined;\n}\n\n/** Minimal structural shape of this plugin's own `settings` usage. */\ninterface SettingsLike {\n configure(presentation: { auto?: boolean }, owner?: unknown): () => void;\n}\n\n/**\n * The Host context surface this plugin uses.\n *\n * Declared structurally rather than by extending `Context`: the fields read here\n * (`inject` with a narrower dependency list, `on` for one waterfall event) are a\n * subset with a deliberately looser signature, and widening `inject` to satisfy\n * the interface would hide the services this plugin actually declares through\n * the exported `inject` table.\n */\ninterface HostContext {\n credentials: CredentialsServiceLike;\n sessions: { get(id: string): unknown };\n sessionTitle: SessionTitleLike;\n settings: SettingsLike;\n fiber: unknown;\n on(event: string, listener: (...args: any[]) => unknown): () => void;\n effect(factory: () => void | (() => void), label?: string): unknown;\n inject(names: string[] | string, callback: (ctx: HostContext) => void | (() => void)): void;\n}\n\n/** The route a child runs on; the three fields travel together. */\ninterface RouteSelection {\n provider: string;\n model: string;\n reasoningEffort?: string;\n}\n\n/** The Agent model face this plugin uses: read the inherited route, select the judged one. */\ninterface AgentModelLike {\n current(): RouteSelection | undefined;\n select(selection: RouteSelection): void;\n}\n\n/** Which Agent fields this plugin reads when a child is created. */\ninterface RequestAgent {\n id: string;\n options: { subagentDepth?: number };\n session: SessionLike;\n model: AgentModelLike;\n}\n\n/** How many judged children to remember before forgetting the oldest. */\nconst JUDGED_LIMIT = 500;\n\n/**\n * The set of children already judged, bounded so a long-running instance cannot\n * grow without limit.\n *\n * Insertion order is eviction order: a `Set` iterates oldest-first, so the one\n * entry that goes is always the earliest judgement. Forgetting a very old child\n * costs at most one extra judgement should it somehow make another request,\n * which is strictly better than an unbounded map keyed by every subagent ever\n * delegated.\n */\nclass JudgedChildren {\n private readonly seen = new Set<string>();\n\n /** Record a child as judged, forgetting the oldest entry past the cap. */\n add(id: string): void {\n this.seen.add(id);\n if (this.seen.size <= JUDGED_LIMIT) return;\n const oldest = this.seen.values().next();\n if (!oldest.done) this.seen.delete(oldest.value);\n }\n\n /** Whether this child has already been judged. */\n has(id: string): boolean {\n return this.seen.has(id);\n }\n}\n\n/**\n * Mount the host half: judge every subagent once, write the route the judgement\n * chose, and keep the log the Plugins page reads.\n *\n * @param ctx - DSH Host context.\n * @param config - this plugin's runtime-resolved Config (every field a live ref).\n */\nexport function apply(ctx: HostContext, config: PluginConfigRefs): void {\n const log = new LogStore();\n /** Children already judged, so a ten-step child is asked about once. */\n const judged = new JudgedChildren();\n let apiKey = '';\n\n // The log outlives the process: read what a previous run wrote before the\n // first append could overwrite it. `init` never rejects \u2014 a missing or broken\n // file just leaves the log empty.\n const logReady = log.init();\n\n const resolvedConfig = (): ResolvedConfig => readPluginConfig(config);\n\n /** Re-read the judge key; a key set outside the page takes effect at once. */\n const refreshKey = async (): Promise<void> => {\n try {\n apiKey = ((await ctx.credentials.resolve(JUDGE_API_KEY_REF))?.value ?? '').trim();\n } catch {\n apiKey = '';\n }\n };\n void refreshKey();\n ctx.on('credentials/reference-updated', () => {\n void refreshKey();\n });\n\n // Settings are read and written through the Plugins page's own card; DSH must\n // not also derive a generic settings form for the same entry.\n ctx.inject(['settings'], (child) => {\n child.effect(\n () => child.settings.configure({ auto: false }, child.fiber),\n 'dsh-subagent-judge-dispatch: settings page policy'\n );\n });\n\n /**\n * The delegation hook: one judgement per subagent, then the route it chose.\n *\n * Runs on `agent/created`, which the Host awaits before releasing the child's\n * queued work: the route selected here is the one the child's first step\n * prepares with.\n *\n * Never throws and never cancels: every failure path writes nothing, which is\n * what makes a judge outage cost latency and nothing else. The judgement is\n * awaited because the Host awaits this hook, so it can add up to the judge\n * budget to that one delegation.\n */\n ctx.on('agent/created', async (payload: { agent?: RequestAgent }) => {\n const agent = payload?.agent;\n if (agent === undefined) return;\n const cfg = resolvedConfig();\n // Only subagents, and only while the model-rewrite switch is on: with it off\n // nothing is judged and nothing is logged, so the log only ever holds\n // judgements that actually ran.\n if (!isSubagent(agent) || !cfg.enabled) return;\n if (judged.has(agent.id)) return;\n if (!isJudgeUsable(cfg)) return;\n judged.add(agent.id);\n\n try {\n const label = readChildLabel(agent);\n const taskText = readDelegatedTask(agent, (id) => ctx.sessions.get(id) as SessionLike | undefined);\n const inherited = agent.model.current() ?? { provider: '', model: '' };\n const outcome = await judgeTaskType(\n { url: cfg.endpointUrl, model: cfg.judgeModel, apiKey },\n selectableRows(cfg.rows),\n composeJudgeSubject(label, taskText),\n );\n const decision = decideRewrite(outcome);\n\n // A judgement that produced no usable row writes nothing: the child keeps\n // exactly the route the Host resolved for it.\n if (decision.kind === 'rewrite') {\n agent.model.select({\n provider: decision.rewrite.provider,\n model: decision.rewrite.model,\n reasoningEffort: decision.rewrite.reasoningEffort,\n });\n }\n\n if (cfg.logEnabled) {\n // Wait for the stored log before appending, so the first judgement of a\n // run does not overwrite the history it was about to join.\n await logReady;\n log.append(buildEntry(ctx, agent, inherited, decision, outcome, label, taskText));\n }\n } catch {\n // A judge outage, an unreadable parent log or a Host rejection of the\n // selection costs this delegation latency and nothing else.\n }\n });\n\n // The three reads only the Host can answer. Connection's /api transport is\n // composed by a Web carrier; without one the plugin loads and simply has no\n // HTTP surface.\n ctx.inject(['connection'], (connectionCtx) => {\n const routes = createFetchRoutes({\n config: resolvedConfig,\n // \u8DEF\u7531\u53EF\u80FD\u5728\u78C1\u76D8\u8BFB\u5B8C\u4E4B\u540E\u624D\u88AB\u95EE\u5230\uFF0C\u4E5F\u53EF\u80FD\u5728\u4E4B\u524D\uFF1A\u5148\u7B49\u90A3\u4E00\u6B21\u8BFB\uFF0C\u522B\u628A\u300C\u8FD8\u6CA1\u8BFB\u5B8C\u300D\n // \u62A5\u6210\u300C\u4E00\u6761\u90FD\u6CA1\u6709\u300D\u3002\n log: async () => {\n await logReady;\n return log.list();\n },\n apiKey: () => apiKey,\n });\n const disposers = routes.map((route) =>\n (connectionCtx as HostContext & { connection: HostConnectionHandle }).connection.fetch.register(route)\n );\n return () => {\n for (const dispose of disposers) void Promise.resolve(dispose()).catch(() => {});\n };\n });\n\n // \u6BCF\u6B21\u8FFD\u52A0\u90FD\u7ACB\u523B\u5F00\u5199\uFF1B\u5378\u8F7D\u65F6\u518D\u7B49\u4E00\u6B21\u5728\u98DE\u7684\u5199\u843D\u5730\uFF0C\u5378\u8F7D\u4E0D\u4E22\u6700\u540E\u90A3\u6761\u3002\n ctx.effect(\n () => () => {\n void log.flush();\n },\n 'dsh-subagent-judge-dispatch: judgement log flush',\n );\n}\n\n/**\n * Build the log row for one judged delegation.\n *\n * A fallback row reports the route the child actually keeps \u2014 the main agent's\n * resolved provider, model and effort \u2014 rather than a blank, because the point\n * of the row is what the child ran on. The subagent column carries the\n * delegation's own label; the task text is part of the request shown in the\n * row's detail, not repeated in the table.\n */\nfunction buildEntry(\n ctx: HostContext,\n agent: RequestAgent,\n resolved: RouteSelection,\n decision: ReturnType<typeof decideRewrite>,\n outcome: Awaited<ReturnType<typeof judgeTaskType>>,\n label: string,\n taskText: string,\n): LogEntry {\n const matched = decision.kind === 'rewrite';\n const reason = outcomeReason(outcome, decision);\n return {\n typeId: matched && outcome.kind === 'matched' ? outcome.row.id : null,\n provider: matched ? decision.rewrite.provider : resolved.provider,\n model: matched ? decision.rewrite.model : resolved.model,\n effort: matched\n ? decision.rewrite.reasoningEffort\n : typeof resolved.reasoningEffort === 'string' ? resolved.reasoningEffort : '',\n ...reason === undefined ? {} : { reason },\n at: Date.now(),\n latencyMs: outcome.latencyMs,\n parentTitle: readParentTitle(ctx, agent.session.header.parentSession),\n childLabel: truncate(label !== '' ? label : taskText),\n prompt: outcome.prompt,\n };\n}\n\n/**\n * Name the conversation that delegated, the way the reader sees it in the\n * session list: its title, falling back to the session id when it has none.\n */\nfunction readParentTitle(ctx: HostContext, parentId: string | undefined): string {\n if (typeof parentId !== 'string' || parentId === '') return '';\n try {\n const rootId = resolveRootSessionId(parentId, (id) => ctx.sessions.get(id) as SessionLike | undefined);\n const session = ctx.sessions.get(rootId);\n if (session === undefined) return rootId;\n const title = ctx.sessionTitle.get(session)?.title;\n return typeof title === 'string' && title.trim() !== '' ? title.trim() : rootId;\n } catch {\n return parentId;\n }\n}\n\n/** Keep one log label to a readable length. */\nfunction truncate(text: string, max = 60): string {\n const collapsed = text.replace(/\\s+/g, ' ').trim();\n return collapsed.length <= max ? collapsed : `${collapsed.slice(0, max - 1)}\u2026`;\n}\n"],
|
|
5
|
+
"mappings": ";AAcA,OAAO,OAAO;;;ACOP,IAAM,eAAe;AASrB,IAAM,wBACX;AAKK,IAAM,kBAAkB;AAGxB,IAAM,kBAAkB;AASxB,IAAM,qBACX;AAGK,IAAM,kBAAkB;AAgCxB,SAAS,gBAAgB,KAA8D;AAC5F,SAAO,IAAI,SAAS,KAAK,MAAM,MAAM,IAAI,MAAM,KAAK,MAAM,MAAM,IAAI,OAAO,KAAK,MAAM;AACxF;AAOO,SAAS,eAAe,MAAqC;AACl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M,UAAU,IAAI,SAAS,IAAI,MAAM;AACvC,QAAI,YAAY,OAAW,QAAO;AAClC,UAAM,QAAQ,IAAI,aAAa,IAAI,OAAO,GAAG;AAC7C,WAAO,OAAO,UAAU,YAAY,MAAM,KAAK,MAAM,KAAK,MAAM,KAAK,IAAI;AAAA,EAC3E,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAGA,SAAS,SAAS,MAAc,MAAM,IAAY;AAChD,QAAM,YAAY,KAAK,QAAQ,QAAQ,GAAG,EAAE,KAAK;AACjD,SAAO,UAAU,UAAU,MAAM,YAAY,GAAG,UAAU,MAAM,GAAG,MAAM,CAAC,CAAC;AAC7E;",
|
|
6
6
|
"names": ["path"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynn123411/dsh-subagent-judge-dispatch",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "用一个判断模型从你写的任务类型清单里挑一个编号,据此改写子代理使用的模型与思考强度。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -56,21 +56,21 @@
|
|
|
56
56
|
}
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@deepseek-ai/cordis": "^4.0
|
|
60
|
-
"@deepseek-ai/dsh-client-connection": ">=0.2.
|
|
59
|
+
"@deepseek-ai/cordis": "^4.1.0",
|
|
60
|
+
"@deepseek-ai/dsh-client-connection": ">=0.2.2-rc.1"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@deepseek-ai/cordis": "^4.0
|
|
64
|
-
"@deepseek-ai/dsh-agent": ">=0.2.
|
|
65
|
-
"@deepseek-ai/dsh-client-connection": ">=0.2.
|
|
66
|
-
"@deepseek-ai/dsh-client-locale": ">=0.2.
|
|
67
|
-
"@deepseek-ai/dsh-client-ui-plugin-manager": ">=0.2.
|
|
68
|
-
"@deepseek-ai/dsh-client-ui-primitives": ">=0.2.
|
|
69
|
-
"@deepseek-ai/dsh-client-ui-renderer": ">=0.2.
|
|
70
|
-
"@deepseek-ai/dsh-client-ui-settings": ">=0.2.
|
|
71
|
-
"@deepseek-ai/dsh-client-ui-slots": ">=0.2.
|
|
72
|
-
"@deepseek-ai/dsh-home-paths": ">=0.2.
|
|
73
|
-
"@deepseek-ai/schemastery": "^3.
|
|
63
|
+
"@deepseek-ai/cordis": "^4.1.0",
|
|
64
|
+
"@deepseek-ai/dsh-agent": ">=0.2.2-rc.1",
|
|
65
|
+
"@deepseek-ai/dsh-client-connection": ">=0.2.2-rc.1",
|
|
66
|
+
"@deepseek-ai/dsh-client-locale": ">=0.2.2-rc.1",
|
|
67
|
+
"@deepseek-ai/dsh-client-ui-plugin-manager": ">=0.2.2-rc.1",
|
|
68
|
+
"@deepseek-ai/dsh-client-ui-primitives": ">=0.2.2-rc.1",
|
|
69
|
+
"@deepseek-ai/dsh-client-ui-renderer": ">=0.2.2-rc.1",
|
|
70
|
+
"@deepseek-ai/dsh-client-ui-settings": ">=0.2.2-rc.1",
|
|
71
|
+
"@deepseek-ai/dsh-client-ui-slots": ">=0.2.2-rc.1",
|
|
72
|
+
"@deepseek-ai/dsh-home-paths": ">=0.2.2-rc.1",
|
|
73
|
+
"@deepseek-ai/schemastery": "^3.19.0",
|
|
74
74
|
"@types/node": "^22.20.0",
|
|
75
75
|
"@types/react": "^19.2.18",
|
|
76
76
|
"@types/react-dom": "^19.3.0",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"typescript": "^6.0.0"
|
|
82
82
|
},
|
|
83
83
|
"engines": {
|
|
84
|
-
"dsh": ">=0.2.
|
|
84
|
+
"dsh": ">=0.2.2-rc.1",
|
|
85
85
|
"node": "^22.19 || >=24"
|
|
86
86
|
},
|
|
87
87
|
"packageManager": "pnpm@11.7.0",
|