@zoraxylia/dsh-codex-adapter 0.0.0-stage → 0.1.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/.claude-plugin/marketplace.json +15 -0
- package/.claude-plugin/plugin.json +8 -0
- package/.mcp.json +8 -0
- package/LICENSE +21 -0
- package/README.de.md +480 -0
- package/README.es.md +480 -0
- package/README.fr.md +480 -0
- package/README.hi.md +480 -0
- package/README.id.md +480 -0
- package/README.ja.md +478 -0
- package/README.ko.md +480 -0
- package/README.md +483 -2
- package/README.pt.md +480 -0
- package/README.ru.md +480 -0
- package/README.th.md +480 -0
- package/README.tr.md +480 -0
- package/README.vi.md +480 -0
- package/README.zh-TW.md +478 -0
- package/README.zh.md +482 -0
- package/agents/ds-flash.md +17 -0
- package/agents/ds-pro.md +17 -0
- package/agy/agents/ds-flash.md +18 -0
- package/agy/agents/ds-pro.md +18 -0
- package/agy/skills/dsh-config/SKILL.md +6 -0
- package/agy/skills/dsh-playbook/SKILL.md +65 -0
- package/agy/skills/dsh-status/SKILL.md +6 -0
- package/codex/agents/ds-flash.toml +23 -0
- package/codex/agents/ds-pro.toml +23 -0
- package/codex/prompts/dsh-config.md +3 -0
- package/codex/prompts/dsh-playbook.md +60 -0
- package/codex/prompts/dsh-status.md +1 -0
- package/commands/config.md +9 -0
- package/commands/off.md +5 -0
- package/commands/on.md +5 -0
- package/commands/playbook.md +64 -0
- package/commands/status.md +5 -0
- package/cordis.patch.yml +4 -0
- package/docs/images/dsh-adapter-host.png +0 -0
- package/docs/images/dsh-adapter-jobs.png +0 -0
- package/docs/images/dsh-adapter-logo.png +0 -0
- package/docs/images/dsh-adapter-overview.png +0 -0
- package/grok/agents/ds-flash.md +19 -0
- package/grok/agents/ds-pro.md +19 -0
- package/grok/commands/dsh-config.md +9 -0
- package/grok/commands/dsh-playbook.md +66 -0
- package/grok/commands/dsh-status.md +5 -0
- package/lib/client.js +2694 -0
- package/lib/server.mjs +15417 -0
- package/package.json +138 -4
- package/scripts/build-client.mjs +23 -0
- package/scripts/build-mcp.mjs +43 -0
- package/scripts/bump-version.mjs +79 -0
- package/scripts/fake-agy.sh +23 -0
- package/scripts/release-local.mjs +87 -0
- package/scripts/smoke-bundle.mjs +166 -0
- package/scripts/smoke-cwd.mjs +41 -0
- package/scripts/smoke-pack.mjs +285 -0
- package/scripts/smoke.mjs +79 -0
- package/scripts/verify-cli-workers.mjs +133 -0
- package/scripts/verify-wpc10-client.mjs +237 -0
- package/scripts/verify-wpc14-proc-endpoints.mjs +356 -0
- package/scripts/verify-wpc9-guardrails.mjs +432 -0
- package/src/cli-workers.mjs +396 -0
- package/src/client/index.tsx +1135 -0
- package/src/client/jobs-view.ts +374 -0
- package/src/cwd-lock.mjs +91 -0
- package/src/hub/index.mjs +643 -0
- package/src/hub-client.mjs +72 -0
- package/src/i18n.mjs +19 -0
- package/src/install/cli.mjs +34 -0
- package/src/install/install.mjs +580 -0
- package/src/jobs.mjs +289 -0
- package/src/multimodal.mjs +744 -0
- package/src/origin-guard.mjs +133 -0
- package/src/paths.mjs +43 -0
- package/src/plugin-env.mjs +65 -0
- package/src/proc-kill.mjs +208 -0
- package/src/process-info.mjs +60 -0
- package/src/provider-probe.mjs +35 -0
- package/src/server.mjs +438 -0
- package/src/status-shard.mjs +95 -0
- package/src/tier-binding.mjs +63 -0
- package/src/vision-route.mjs +139 -0
- package/src/worker-profiles.mjs +95 -0
- package/src/worker-question.mjs +22 -0
- package/statusline/statusline.sh +14 -0
- package/statusline/worker-segment.sh +35 -0
- package/worker.cordis.yml +77 -0
package/src/server.mjs
ADDED
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
// MCP stdio server exposing the DSH worker pool to Claude Code / Codex.
|
|
2
|
+
|
|
3
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
4
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { startJob, waitJob, cancelJob, listJobs, getJob, jobView } from './jobs.mjs';
|
|
7
|
+
import { hubAvailable, hub } from './hub-client.mjs';
|
|
8
|
+
import { startCliJob } from './cli-workers.mjs';
|
|
9
|
+
import { listProfiles, resolveProfile } from './worker-profiles.mjs';
|
|
10
|
+
import { readInheritedOrigin, extendOrigin, DEFAULT_ORIGIN_DEPTH_LIMIT } from './origin-guard.mjs';
|
|
11
|
+
import { acquireCwdLock, releaseCwdLockByJobId, updateCwdLockHolder, getCwdLocks, CwdLockError } from './cwd-lock.mjs';
|
|
12
|
+
import { resolveWorkerCwd } from './paths.mjs';
|
|
13
|
+
import { detectOrchestrator } from './process-info.mjs';
|
|
14
|
+
|
|
15
|
+
const server = new McpServer({ name: 'dsh-adapter', version: '0.1.1' });
|
|
16
|
+
|
|
17
|
+
const tierSchema = z.enum(['flash', 'pro']).optional().describe('Worker model tier. flash = mechanical, well-scoped work (single-file edits, lookups, formatting); pro = multi-file changes, debugging, design judgment. Omit to use the session default. Ignored when worker= is set.');
|
|
18
|
+
const effortSchema = z.enum(['off', 'high', 'max']).optional().describe('Reasoning effort for the worker. Omit to use the session default. With worker= it only applies when passed explicitly and the profile supports it (agy maps to low/medium/high).');
|
|
19
|
+
const workerSchema = z.string().optional().describe('Named CLI worker profile (e.g. "agy" or "grok"). Explicit opt-in only: set it when the user explicitly asks for that external coding CLI, never as a default. When set, dispatch bypasses tier/mode and runs the task through that CLI; the profile pins backend×model×effort. See dsh_worker_config output, worker_profiles field, for the available profiles.');
|
|
20
|
+
const allowConcurrentCwdSchema = z.boolean().optional().describe('Allow this dispatch even though another running worker already holds the same cwd (workspace) lock. Default false: concurrent writers corrupt a shared repo, so the second dispatch is refused with the holder info instead of queueing. Set true only for read-only tasks.');
|
|
21
|
+
|
|
22
|
+
// Session-level configuration. This MCP server process lives exactly as long
|
|
23
|
+
// as one Claude Code / Codex session, so plain memory IS session scope.
|
|
24
|
+
// Initial values come from the global config (~/.config/dsh-adapter/config.json,
|
|
25
|
+
// edited on the DSH settings page); dsh_worker_config overrides per session.
|
|
26
|
+
import { readGlobalConfig } from './install/install.mjs';
|
|
27
|
+
import { describeBindings, resolveTierBinding } from './tier-binding.mjs';
|
|
28
|
+
const globalDefaults = readGlobalConfig();
|
|
29
|
+
const sessionConfig = {
|
|
30
|
+
enabled: true,
|
|
31
|
+
default_tier: globalDefaults.default_tier,
|
|
32
|
+
default_effort: globalDefaults.default_effort,
|
|
33
|
+
mode: globalDefaults.mode, // auto | hub | standalone
|
|
34
|
+
default_timeout_seconds: globalDefaults.default_timeout_seconds,
|
|
35
|
+
tier_policy: globalDefaults.tier_policy, // auto | flash-only | pro-only
|
|
36
|
+
escalate_on_failure: globalDefaults.escalate_on_failure,
|
|
37
|
+
preset_flash: globalDefaults.preset_flash ?? 'default',
|
|
38
|
+
preset_pro: globalDefaults.preset_pro ?? 'default',
|
|
39
|
+
// Tier -> LLM route. A provider id names a route the HOST already has
|
|
40
|
+
// configured; blank means the tier's built-in DeepSeek default (#10).
|
|
41
|
+
flash_provider: globalDefaults.flash_provider ?? '',
|
|
42
|
+
flash_model: globalDefaults.flash_model ?? '',
|
|
43
|
+
pro_provider: globalDefaults.pro_provider ?? '',
|
|
44
|
+
pro_model: globalDefaults.pro_model ?? '',
|
|
45
|
+
// WPC9: max worker→worker nesting depth before a dispatch is refused.
|
|
46
|
+
origin_depth_limit: DEFAULT_ORIGIN_DEPTH_LIMIT,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/** The {provider, model} this session dispatches `tier` to. */
|
|
50
|
+
function bindingForTier(tier) {
|
|
51
|
+
return resolveTierBinding(tier, sessionConfig);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function presetForTier(tier) {
|
|
55
|
+
const p = tier === 'flash' ? sessionConfig.preset_flash : sessionConfig.preset_pro;
|
|
56
|
+
return !p || p === 'default' ? undefined : p;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Tool-layer tier enforcement: the policy overrides whatever was requested. */
|
|
60
|
+
function applyTierPolicy(tier) {
|
|
61
|
+
if (sessionConfig.tier_policy === 'flash-only') return 'flash';
|
|
62
|
+
if (sessionConfig.tier_policy === 'pro-only') return 'pro';
|
|
63
|
+
return tier ?? sessionConfig.default_tier;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function text(obj) {
|
|
67
|
+
return { content: [{ type: 'text', text: typeof obj === 'string' ? obj : JSON.stringify(obj, null, 2) }] };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Which orchestrator spawned this MCP server — stamped on every job so the
|
|
71
|
+
// panel can show where a dispatch came from.
|
|
72
|
+
const ORCHESTRATOR = detectOrchestrator();
|
|
73
|
+
|
|
74
|
+
// ---------- WPC9 guardrails ----------
|
|
75
|
+
|
|
76
|
+
// Origin chain this adapter instance inherited from whoever spawned it (read at
|
|
77
|
+
// startup from the env written by the dispatching adapter — origin-guard.mjs).
|
|
78
|
+
// Every dispatch appends its own hop and refuses loops / over-deep chains
|
|
79
|
+
// BEFORE anything is spawned, so recursion can never start burning quota.
|
|
80
|
+
const INHERITED_ORIGIN = readInheritedOrigin(process.env);
|
|
81
|
+
const depthLimitNow = () => sessionConfig.origin_depth_limit ?? DEFAULT_ORIGIN_DEPTH_LIMIT;
|
|
82
|
+
|
|
83
|
+
// Hub jobs run inside the DSH host and have no settle callback on this side,
|
|
84
|
+
// so the origin recorded at spawn time is kept here and re-attached to every
|
|
85
|
+
// hub view this session returns (the hub itself ignores the extra spawn
|
|
86
|
+
// fields until the hub side adopts them).
|
|
87
|
+
const hubOrigins = new Map();
|
|
88
|
+
|
|
89
|
+
function attachOrigin(view, jobId) {
|
|
90
|
+
if (!view || typeof view !== 'object') return view;
|
|
91
|
+
const o = hubOrigins.get(jobId);
|
|
92
|
+
if (o && view.origin_depth === undefined) {
|
|
93
|
+
view.origin_depth = o.depth;
|
|
94
|
+
view.origin_chain = o.chain;
|
|
95
|
+
}
|
|
96
|
+
return view;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Readable refusal payload for the two origin guard checks. */
|
|
100
|
+
function originRefusal(res) {
|
|
101
|
+
return text({ error: `dispatch refused by origin guard: ${res.error.reason}`, ...res.error });
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Acquire the cwd advisory lock for a hub dispatch (job id is unknown until
|
|
106
|
+
* the hub answers, so it is backfilled by updateCwdLockHolder). A conflict
|
|
107
|
+
* against a hub-held lock is re-checked once against the hub: a hub job can
|
|
108
|
+
* settle without this side ever hearing about it, and a stale lock must not
|
|
109
|
+
* permanently block the cwd.
|
|
110
|
+
*/
|
|
111
|
+
async function acquireDispatchLock({ cwd, backend, mode, allowConcurrent }) {
|
|
112
|
+
for (let attempt = 0; ; attempt++) {
|
|
113
|
+
try {
|
|
114
|
+
return acquireCwdLock({ cwd, jobId: null, backend, mode, startedAt: new Date().toISOString(), allowConcurrent });
|
|
115
|
+
} catch (err) {
|
|
116
|
+
if (!(err instanceof CwdLockError) || attempt > 0 || err.holder.mode !== 'hub') throw err;
|
|
117
|
+
let settled = false;
|
|
118
|
+
try { settled = (await hub.get(err.holder.jobId, 0)).status !== 'running'; }
|
|
119
|
+
catch (e) { if (String(e?.message ?? e).includes('no such job')) settled = true; }
|
|
120
|
+
if (!settled) throw err;
|
|
121
|
+
releaseCwdLockByJobId(err.holder.jobId);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function dispatchDisabled() {
|
|
127
|
+
return text({
|
|
128
|
+
error: 'worker dispatch is disabled for this session (set via dsh_worker_config). Report this to the user instead of doing the task yourself.',
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async function resolveMode() {
|
|
133
|
+
if (sessionConfig.mode === 'standalone') return 'standalone';
|
|
134
|
+
const up = await hubAvailable();
|
|
135
|
+
if (sessionConfig.mode === 'hub' && !up) throw new Error('session mode is "hub" but the DSH workers hub is not reachable');
|
|
136
|
+
return up ? 'hub' : 'standalone';
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
server.registerTool('dsh_run_worker', {
|
|
140
|
+
title: 'Run DSH worker (blocking)',
|
|
141
|
+
description: 'Run one DSH (DeepSeek Harness) coding agent task and block until it finishes. Tier guidance: flash for mechanical, well-scoped work (single-file edits, lookups, formatting); pro for multi-file changes, debugging, and design judgment. The task string must be self-contained: the worker has zero conversation context, so include absolute paths, exact acceptance criteria, and constraints. Set worker="agy" or "grok" only when the user explicitly asks for that CLI, never as a default. Guardrails refuse (never queue) worker→worker recursion beyond the origin-chain depth cap and a second writer on the same cwd; allow_concurrent_cwd: true only for read-only tasks.',
|
|
142
|
+
inputSchema: {
|
|
143
|
+
task: z.string().describe('Full task description for the worker, self-contained'),
|
|
144
|
+
tier: tierSchema,
|
|
145
|
+
effort: effortSchema,
|
|
146
|
+
worker: workerSchema,
|
|
147
|
+
cwd: z.string().optional().describe('Workspace directory for the worker. Relative paths resolve against the caller\'s current workspace; "." or "current" mean the current workspace. Omit for the current workspace.'),
|
|
148
|
+
timeout_seconds: z.number().int().positive().max(7200).optional(),
|
|
149
|
+
allow_concurrent_cwd: allowConcurrentCwdSchema,
|
|
150
|
+
},
|
|
151
|
+
}, async ({ task, tier, effort, worker, cwd, timeout_seconds, allow_concurrent_cwd }) => {
|
|
152
|
+
if (!sessionConfig.enabled) return dispatchDisabled();
|
|
153
|
+
const workDir = resolveWorkerCwd(cwd);
|
|
154
|
+
const e = effort ?? sessionConfig.default_effort;
|
|
155
|
+
const timeout = timeout_seconds ?? sessionConfig.default_timeout_seconds;
|
|
156
|
+
const depthLimit = depthLimitNow();
|
|
157
|
+
|
|
158
|
+
// CLI profile dispatch: worker= names a profile and bypasses the
|
|
159
|
+
// hub/standalone tier logic entirely (no tier policy, no escalation — the
|
|
160
|
+
// profile pins backend×model×effort). Calls without worker= are untouched.
|
|
161
|
+
if (worker) {
|
|
162
|
+
const profile = resolveProfile(worker); // throws listing the available profile names
|
|
163
|
+
const origin = extendOrigin({ inherited: INHERITED_ORIGIN, backend: profile.backend, cwd: workDir, source: ORCHESTRATOR, depthLimit });
|
|
164
|
+
if (!origin.ok) return originRefusal(origin);
|
|
165
|
+
let job;
|
|
166
|
+
try {
|
|
167
|
+
job = await startCliJob({ worker, task, cwd: workDir, timeoutMs: timeout * 1000, source: ORCHESTRATOR, effort, origin: origin.origin, allowConcurrentCwd: !!allow_concurrent_cwd });
|
|
168
|
+
} catch (err) {
|
|
169
|
+
if (err instanceof CwdLockError) return text({ error: err.message, rejected_by: 'cwd-lock', holder: err.holder });
|
|
170
|
+
throw err;
|
|
171
|
+
}
|
|
172
|
+
await waitJob(job.id, timeout * 1000);
|
|
173
|
+
const view = jobView(job, { withResult: true });
|
|
174
|
+
if (view.status === 'running') return text({ ...view, note: `still running after ${timeout}s; poll with dsh_worker_result` });
|
|
175
|
+
return text(view);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const runOnce = async (t) => {
|
|
179
|
+
if ((await resolveMode()) === 'hub') {
|
|
180
|
+
const origin = extendOrigin({ inherited: INHERITED_ORIGIN, backend: 'hub', cwd: workDir, source: ORCHESTRATOR, depthLimit });
|
|
181
|
+
if (!origin.ok) return { refusal: originRefusal(origin) };
|
|
182
|
+
let lock;
|
|
183
|
+
try {
|
|
184
|
+
lock = await acquireDispatchLock({ cwd: workDir, backend: 'hub', mode: 'hub', allowConcurrent: !!allow_concurrent_cwd });
|
|
185
|
+
} catch (err) {
|
|
186
|
+
if (err instanceof CwdLockError) return { refusal: text({ error: err.message, rejected_by: 'cwd-lock', holder: err.holder }) };
|
|
187
|
+
throw err;
|
|
188
|
+
}
|
|
189
|
+
let spawned;
|
|
190
|
+
try {
|
|
191
|
+
spawned = await hub.spawn({ task, tier: t, effort: e, cwd: workDir, source: ORCHESTRATOR, preset: presetForTier(t), ...bindingForTier(t), origin_chain: origin.origin.chain, origin_depth: origin.origin.depth });
|
|
192
|
+
updateCwdLockHolder({ cwd: workDir, jobId: spawned.id });
|
|
193
|
+
hubOrigins.set(spawned.id, origin.origin);
|
|
194
|
+
} catch (err) {
|
|
195
|
+
lock.release();
|
|
196
|
+
throw err;
|
|
197
|
+
}
|
|
198
|
+
// The hub client slices this wait internally; a single request that
|
|
199
|
+
// waits minutes would be cut by undici's 300 s header timeout and
|
|
200
|
+
// reported as a bare "fetch failed" while the job kept running.
|
|
201
|
+
const got = await hub.get(spawned.id, timeout);
|
|
202
|
+
attachOrigin(got, spawned.id);
|
|
203
|
+
if (got.status !== 'running') releaseCwdLockByJobId(spawned.id);
|
|
204
|
+
return { view: got };
|
|
205
|
+
}
|
|
206
|
+
const origin = extendOrigin({ inherited: INHERITED_ORIGIN, backend: 'standalone', cwd: workDir, source: ORCHESTRATOR, depthLimit });
|
|
207
|
+
if (!origin.ok) return { refusal: originRefusal(origin) };
|
|
208
|
+
let job;
|
|
209
|
+
try {
|
|
210
|
+
job = await startJob({ task, tier: t, effort: e, cwd: workDir, timeoutMs: timeout * 1000, source: ORCHESTRATOR, origin: origin.origin, allowConcurrentCwd: !!allow_concurrent_cwd, ...bindingForTier(t) });
|
|
211
|
+
} catch (err) {
|
|
212
|
+
if (err instanceof CwdLockError) return { refusal: text({ error: err.message, rejected_by: 'cwd-lock', holder: err.holder }) };
|
|
213
|
+
throw err;
|
|
214
|
+
}
|
|
215
|
+
await waitJob(job.id, timeout * 1000);
|
|
216
|
+
return { view: jobView(job, { withResult: true }) };
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const firstTier = applyTierPolicy(tier);
|
|
220
|
+
let res = await runOnce(firstTier);
|
|
221
|
+
if (res.refusal) return res.refusal;
|
|
222
|
+
let job = res.view;
|
|
223
|
+
if (job.status === 'running') return text({ ...job, note: `still running after ${timeout}s; poll with dsh_worker_result` });
|
|
224
|
+
|
|
225
|
+
// Escalate on evidence, not prediction: a failed flash run retries once on
|
|
226
|
+
// pro — unless the policy pins the tier to flash.
|
|
227
|
+
if (job.status === 'failed' && sessionConfig.escalate_on_failure
|
|
228
|
+
&& firstTier === 'flash' && sessionConfig.tier_policy !== 'flash-only') {
|
|
229
|
+
const firstError = job.error ?? job.stopReason ?? 'unknown failure';
|
|
230
|
+
res = await runOnce('pro');
|
|
231
|
+
if (res.refusal) return res.refusal;
|
|
232
|
+
job = res.view;
|
|
233
|
+
if (job.status === 'running') return text({ ...job, escalated: true, note: `escalated to pro, still running after ${timeout}s; poll with dsh_worker_result` });
|
|
234
|
+
return text({ ...job, escalated: true, flash_failure: String(firstError).slice(0, 200) });
|
|
235
|
+
}
|
|
236
|
+
return text(job);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
server.registerTool('dsh_worker_probe', {
|
|
240
|
+
title: 'Probe a configured worker model route',
|
|
241
|
+
description: 'Explicitly test one DSH-configured provider/model with a small no-op tool-call request. Requires the hub. Does not start a worker, touch files, or change bindings; it may consume one model request. A listed provider is not proof of agent/tool support. Results are observations at checked_at, not a permanent capability guarantee.',
|
|
242
|
+
inputSchema: { tier: z.enum(['flash', 'pro']).optional(), provider: z.string().optional(), model: z.string().optional() },
|
|
243
|
+
}, async ({ tier, provider, model }) => {
|
|
244
|
+
if (!(await hubAvailable())) return text({ status: 'hub_unavailable', tool_call_verified: false });
|
|
245
|
+
const bound = bindingForTier(tier ?? sessionConfig.default_tier);
|
|
246
|
+
return text(await hub.probe({ provider: provider?.trim() || bound.provider, model: model?.trim() || bound.model }));
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
server.registerTool('dsh_worker_config', {
|
|
250
|
+
title: 'Session worker configuration',
|
|
251
|
+
description: 'Read or update session-level worker settings: enable/disable dispatch, default tier/effort/timeout, execution mode (auto = prefer hub, hub = require the DSH hub, standalone = never use it), tier policy, failure escalation, and which LLM route each tier dispatches to. Call with no arguments to read. To run workers on a local model (Ollama and the like), configure that provider ONCE in DSH and then name it here with flash_provider/flash_model or pro_provider/pro_model — this plugin never defines providers of its own. available_providers lists what the host has configured (hub mode only); bindings shows what each tier currently resolves to. The output includes worker_profiles — the external-CLI backends (agy, grok) usable via the worker= parameter of dsh_run_worker / dsh_spawn_worker — and origin, the inherited worker→worker dispatch chain with its depth limit. Session-only.',
|
|
252
|
+
inputSchema: {
|
|
253
|
+
enabled: z.boolean().optional().describe('false = refuse all worker dispatch this session'),
|
|
254
|
+
default_tier: z.enum(['flash', 'pro']).optional(),
|
|
255
|
+
default_effort: z.enum(['off', 'high', 'max']).optional(),
|
|
256
|
+
mode: z.enum(['auto', 'hub', 'standalone']).optional(),
|
|
257
|
+
default_timeout_seconds: z.number().int().positive().max(7200).optional(),
|
|
258
|
+
tier_policy: z.enum(['auto', 'flash-only', 'pro-only']).optional().describe('flash-only / pro-only clamp every dispatch to one tier'),
|
|
259
|
+
escalate_on_failure: z.boolean().optional().describe('retry a failed blocking flash run once on pro'),
|
|
260
|
+
preset_flash: z.string().optional().describe('hub-mode agent preset for flash workers (preset id, or "default")'),
|
|
261
|
+
preset_pro: z.string().optional().describe('hub-mode agent preset for pro workers (preset id, or "default")'),
|
|
262
|
+
flash_provider: z.string().optional().describe('LLM provider route the flash tier dispatches to. Must be a provider DSH already has configured — see available_providers in this tool\'s output. Empty string restores the built-in DeepSeek default. Configure the provider itself in DSH, not here.'),
|
|
263
|
+
flash_model: z.string().optional().describe('Model id for the flash tier, as that provider names it (e.g. a local Ollama model). Empty string restores the default.'),
|
|
264
|
+
pro_provider: z.string().optional().describe('LLM provider route the pro tier dispatches to. Same rules as flash_provider.'),
|
|
265
|
+
pro_model: z.string().optional().describe('Model id for the pro tier. Empty string restores the default.'),
|
|
266
|
+
origin_depth_limit: z.number().int().min(1).max(32).optional().describe('Max worker→worker origin-chain depth (default 3). Deeper dispatches are refused to stop recursive self-amplification; raise only for deliberate deep delegation.'),
|
|
267
|
+
reset: z.boolean().optional().describe('true = restore all defaults first'),
|
|
268
|
+
},
|
|
269
|
+
}, async ({ reset, ...patch }) => {
|
|
270
|
+
if (reset) {
|
|
271
|
+
Object.assign(sessionConfig, { enabled: true, ...globalDefaults });
|
|
272
|
+
sessionConfig.origin_depth_limit = DEFAULT_ORIGIN_DEPTH_LIMIT;
|
|
273
|
+
}
|
|
274
|
+
for (const [k, v] of Object.entries(patch)) if (v !== undefined) sessionConfig[k] = v;
|
|
275
|
+
const reachable = await hubAvailable();
|
|
276
|
+
// Only the hub can enumerate the host's LLM routes (this process has no
|
|
277
|
+
// ctx.llm), so in standalone mode the list is honestly absent rather than
|
|
278
|
+
// empty — "we cannot see them" is not "there are none".
|
|
279
|
+
const available = reachable ? (await hub.providers()).providers : null;
|
|
280
|
+
const bindings = describeBindings(sessionConfig);
|
|
281
|
+
const custom = Object.entries(bindings).filter(([, b]) => b.custom).map(([tier]) => tier);
|
|
282
|
+
const unknown = available === null
|
|
283
|
+
? []
|
|
284
|
+
: custom.filter((tier) => !available.some((p) => p.id === bindings[tier].provider));
|
|
285
|
+
return text({
|
|
286
|
+
...sessionConfig,
|
|
287
|
+
hub_reachable: reachable,
|
|
288
|
+
bindings,
|
|
289
|
+
available_providers: available,
|
|
290
|
+
...(available === null && custom.length > 0
|
|
291
|
+
? { providers_note: 'The hub is not reachable, so the configured provider ids could not be checked against what DSH actually has. A route DSH does not know will fail at dispatch, not here.' }
|
|
292
|
+
: {}),
|
|
293
|
+
...(unknown.length > 0
|
|
294
|
+
? { providers_warning: `DSH has no provider route named ${unknown.map((t) => JSON.stringify(bindings[t].provider)).join(', ')} (bound to: ${unknown.join(', ')}). Configure it in DSH first, or these dispatches will fail.` }
|
|
295
|
+
: {}),
|
|
296
|
+
...(custom.length > 0
|
|
297
|
+
? { route_caveat: 'Appearing in available_providers only means an adapter is registered, NOT that it can run a worker. Measured: a route registered purely to re-route another provider fails a dispatch with "registration.adapter.prepareCall is not a function". Nor does DSH report tool-calling support anywhere, and a worker that cannot call tools returns prose and touches no files. A tier bound to a custom route is therefore UNVERIFIED until you call dsh_worker_probe for the configured route; the probe observes one request and is not a permanent capability guarantee.' }
|
|
298
|
+
: {}),
|
|
299
|
+
worker_profiles: listProfiles(),
|
|
300
|
+
origin: { chain: INHERITED_ORIGIN.chain, depth: INHERITED_ORIGIN.depth, depth_limit: depthLimitNow() },
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
server.registerTool('dsh_spawn_worker', {
|
|
305
|
+
title: 'Spawn DSH worker (async)',
|
|
306
|
+
description: 'Start a DSH (DeepSeek Harness) coding agent in the background and return immediately with a job id — use it to fan out several workers in parallel. The spawn response carries claims, not results: always fetch each job\'s final result later with dsh_worker_result. Same tier guidance as dsh_run_worker: flash for mechanical, well-scoped work, pro for multi-file changes and debugging. The task string must be self-contained (absolute paths, acceptance criteria, constraints) — the worker sees nothing of your conversation. worker="agy" or "grok" only when the user explicitly asks for that CLI, never a default. Guardrails refuse (never queue) origin-chain recursion and a second writer on the same cwd; allow_concurrent_cwd: true only for read-only fan-out.',
|
|
307
|
+
inputSchema: {
|
|
308
|
+
task: z.string().describe('Full task description for the worker, self-contained — the worker has no conversation context, so include absolute paths, acceptance criteria and constraints'),
|
|
309
|
+
tier: tierSchema,
|
|
310
|
+
effort: effortSchema,
|
|
311
|
+
worker: workerSchema,
|
|
312
|
+
cwd: z.string().optional().describe('Workspace directory for the worker. Relative paths resolve against the caller\'s current workspace; "." or "current" mean the current workspace. Omit for the current workspace.'),
|
|
313
|
+
allow_concurrent_cwd: allowConcurrentCwdSchema,
|
|
314
|
+
},
|
|
315
|
+
}, async ({ task, tier, effort, worker, cwd, allow_concurrent_cwd }) => {
|
|
316
|
+
if (!sessionConfig.enabled) return dispatchDisabled();
|
|
317
|
+
const workDir = resolveWorkerCwd(cwd);
|
|
318
|
+
const depthLimit = depthLimitNow();
|
|
319
|
+
if (worker) {
|
|
320
|
+
// CLI profile dispatch; no hub/standalone involvement, no tier policy.
|
|
321
|
+
const profile = resolveProfile(worker);
|
|
322
|
+
const origin = extendOrigin({ inherited: INHERITED_ORIGIN, backend: profile.backend, cwd: workDir, source: ORCHESTRATOR, depthLimit });
|
|
323
|
+
if (!origin.ok) return originRefusal(origin);
|
|
324
|
+
try {
|
|
325
|
+
const job = await startCliJob({ worker, task, cwd: workDir, source: ORCHESTRATOR, effort, origin: origin.origin, allowConcurrentCwd: !!allow_concurrent_cwd });
|
|
326
|
+
return text(jobView(job));
|
|
327
|
+
} catch (err) {
|
|
328
|
+
if (err instanceof CwdLockError) return text({ error: err.message, rejected_by: 'cwd-lock', holder: err.holder });
|
|
329
|
+
throw err;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
const t = applyTierPolicy(tier);
|
|
333
|
+
const e = effort ?? sessionConfig.default_effort;
|
|
334
|
+
if ((await resolveMode()) === 'hub') {
|
|
335
|
+
const origin = extendOrigin({ inherited: INHERITED_ORIGIN, backend: 'hub', cwd: workDir, source: ORCHESTRATOR, depthLimit });
|
|
336
|
+
if (!origin.ok) return originRefusal(origin);
|
|
337
|
+
let lock;
|
|
338
|
+
try {
|
|
339
|
+
lock = await acquireDispatchLock({ cwd: workDir, backend: 'hub', mode: 'hub', allowConcurrent: !!allow_concurrent_cwd });
|
|
340
|
+
} catch (err) {
|
|
341
|
+
if (err instanceof CwdLockError) return text({ error: err.message, rejected_by: 'cwd-lock', holder: err.holder });
|
|
342
|
+
throw err;
|
|
343
|
+
}
|
|
344
|
+
let spawned;
|
|
345
|
+
try {
|
|
346
|
+
spawned = await hub.spawn({ task, tier: t, effort: e, cwd: workDir, source: ORCHESTRATOR, preset: presetForTier(t), ...bindingForTier(t), origin_chain: origin.origin.chain, origin_depth: origin.origin.depth });
|
|
347
|
+
updateCwdLockHolder({ cwd: workDir, jobId: spawned.id });
|
|
348
|
+
hubOrigins.set(spawned.id, origin.origin);
|
|
349
|
+
} catch (err) {
|
|
350
|
+
lock.release();
|
|
351
|
+
throw err;
|
|
352
|
+
}
|
|
353
|
+
attachOrigin(spawned, spawned.id);
|
|
354
|
+
return text(spawned);
|
|
355
|
+
}
|
|
356
|
+
const origin = extendOrigin({ inherited: INHERITED_ORIGIN, backend: 'standalone', cwd: workDir, source: ORCHESTRATOR, depthLimit });
|
|
357
|
+
if (!origin.ok) return originRefusal(origin);
|
|
358
|
+
try {
|
|
359
|
+
const job = await startJob({ task, tier: t, effort: e, cwd: workDir, source: ORCHESTRATOR, origin: origin.origin, allowConcurrentCwd: !!allow_concurrent_cwd, ...bindingForTier(t) });
|
|
360
|
+
return text(jobView(job));
|
|
361
|
+
} catch (err) {
|
|
362
|
+
if (err instanceof CwdLockError) return text({ error: err.message, rejected_by: 'cwd-lock', holder: err.holder });
|
|
363
|
+
throw err;
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
server.registerTool('dsh_worker_status', {
|
|
368
|
+
title: 'DSH worker status',
|
|
369
|
+
description: 'List all DSH worker jobs in this session with live progress (turn/step, current tool, token usage) plus the cwd advisory locks (kind: "cwd-lock" entries show which workspace is held by which running job). Use it before dispatching into a busy workspace and to see whether spawned jobs are still running.',
|
|
370
|
+
inputSchema: {},
|
|
371
|
+
}, async () => {
|
|
372
|
+
const hubUp = await hubAvailable();
|
|
373
|
+
const remote = hubUp ? await hub.list().catch(() => null) : [];
|
|
374
|
+
const remoteJobs = remote ?? [];
|
|
375
|
+
if (remote !== null) {
|
|
376
|
+
// The list actually arrived: hub-held locks whose job is settled or gone
|
|
377
|
+
// release now. A failed fetch (remote === null) must NOT release locks —
|
|
378
|
+
// a down hub says nothing about whether its jobs still run.
|
|
379
|
+
const byId = new Map(remoteJobs.map((j) => [j.id, j]));
|
|
380
|
+
for (const l of getCwdLocks()) {
|
|
381
|
+
if (l.holder.mode !== 'hub') continue;
|
|
382
|
+
const j = byId.get(l.holder.jobId);
|
|
383
|
+
if (j === undefined || j.status !== 'running') releaseCwdLockByJobId(l.holder.jobId);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
for (const j of remoteJobs) attachOrigin(j, j.id);
|
|
387
|
+
const local = listJobs().map((j) => jobView(j));
|
|
388
|
+
const locks = getCwdLocks().map((l, i) => ({
|
|
389
|
+
kind: 'cwd-lock',
|
|
390
|
+
id: `cwd-lock-${i + 1}`,
|
|
391
|
+
cwd: l.cwd,
|
|
392
|
+
holder: l.holder,
|
|
393
|
+
note: 'advisory workspace lock: a running worker holds this cwd, so a new dispatch to it is refused (unless allow_concurrent_cwd is set)',
|
|
394
|
+
}));
|
|
395
|
+
return text([...remoteJobs, ...local, ...locks]);
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
server.registerTool('dsh_worker_result', {
|
|
399
|
+
title: 'DSH worker result',
|
|
400
|
+
description: 'Fetch the final result of a worker job, optionally waiting up to wait_seconds. Always call this for spawned jobs: the dsh_spawn_worker response returns only the job id and status claims, never the result. If a result seems missing or stale (for example after a hub restart orphaned the job), verify against the working tree and dsh_worker_status instead of trusting the summary.',
|
|
401
|
+
inputSchema: {
|
|
402
|
+
job_id: z.string(),
|
|
403
|
+
wait_seconds: z.number().int().min(0).max(7200).default(0).describe('0 = return current state immediately'),
|
|
404
|
+
},
|
|
405
|
+
}, async ({ job_id, wait_seconds }) => {
|
|
406
|
+
if (job_id.startsWith('hub-')) {
|
|
407
|
+
if (!(await hubAvailable())) return text({ error: 'hub not reachable' });
|
|
408
|
+
const view = await hub.get(job_id, wait_seconds).catch((e) => ({ error: e.message }));
|
|
409
|
+
if (view && view.id) {
|
|
410
|
+
attachOrigin(view, view.id);
|
|
411
|
+
if (view.status !== 'running') releaseCwdLockByJobId(job_id);
|
|
412
|
+
}
|
|
413
|
+
return text(view);
|
|
414
|
+
}
|
|
415
|
+
if (!getJob(job_id)) return text({ error: `no such job: ${job_id}` });
|
|
416
|
+
const job = await waitJob(job_id, wait_seconds > 0 ? wait_seconds * 1000 : 1);
|
|
417
|
+
return text(jobView(job, { withResult: true }));
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
server.registerTool('dsh_worker_cancel', {
|
|
421
|
+
title: 'Cancel DSH worker',
|
|
422
|
+
description: 'Cancel a running worker job: terminates its runtime process and releases its cwd lock. Use it when a workspace lock is held by a job that is stuck or no longer needed, so a new dispatch to that cwd can proceed.',
|
|
423
|
+
inputSchema: { job_id: z.string() },
|
|
424
|
+
}, async ({ job_id }) => {
|
|
425
|
+
if (job_id.startsWith('hub-')) {
|
|
426
|
+
if (!(await hubAvailable())) return text({ error: 'hub not reachable' });
|
|
427
|
+
const view = await hub.cancel(job_id).catch((e) => ({ error: e.message }));
|
|
428
|
+
if (view && view.id) {
|
|
429
|
+
attachOrigin(view, view.id);
|
|
430
|
+
releaseCwdLockByJobId(job_id); // cancelled = holder being disposed
|
|
431
|
+
}
|
|
432
|
+
return text(view);
|
|
433
|
+
}
|
|
434
|
+
if (!getJob(job_id)) return text({ error: `no such job: ${job_id}` });
|
|
435
|
+
return text(jobView(await cancelJob(job_id), { withResult: true }));
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
await server.connect(new StdioServerTransport());
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// Sharded worker-status publishing: every writer (hub process, per-session
|
|
2
|
+
// standalone MCP server) owns one file under ~/.config/dsh-adapter/status.d/
|
|
3
|
+
// and readers merge all fresh shards. Kills the last-writer-wins race that a
|
|
4
|
+
// single shared status.json had with multiple concurrent writers.
|
|
5
|
+
|
|
6
|
+
import { writeFileSync, mkdirSync, rmSync, readdirSync, readFileSync } from 'node:fs';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import { homedir } from 'node:os';
|
|
9
|
+
|
|
10
|
+
const CONFIG_DIR = join(homedir(), '.config', 'dsh-adapter');
|
|
11
|
+
const SHARD_DIR = join(CONFIG_DIR, 'status.d');
|
|
12
|
+
export const SHARD_FRESH_MS = 30 * 60 * 1000;
|
|
13
|
+
|
|
14
|
+
export function createShardWriter(kind) {
|
|
15
|
+
const writer = `${kind}-${process.pid}`;
|
|
16
|
+
const file = join(SHARD_DIR, `${writer}.json`);
|
|
17
|
+
const cleanup = () => { try { rmSync(file, { force: true }); } catch {} };
|
|
18
|
+
process.once('exit', cleanup);
|
|
19
|
+
process.once('SIGINT', () => { cleanup(); process.exit(130); });
|
|
20
|
+
process.once('SIGTERM', () => { cleanup(); process.exit(143); });
|
|
21
|
+
return {
|
|
22
|
+
writer,
|
|
23
|
+
publish(jobs) {
|
|
24
|
+
try {
|
|
25
|
+
mkdirSync(SHARD_DIR, { recursive: true });
|
|
26
|
+
writeFileSync(file, JSON.stringify({ updatedAt: new Date().toISOString(), writer, jobs }, null, 2));
|
|
27
|
+
} catch {}
|
|
28
|
+
},
|
|
29
|
+
dispose: cleanup,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Whether the process that wrote a shard still exists. Writers are named
|
|
35
|
+
* "<kind>-<pid>"; process.kill(pid, 0) answers existence without signalling
|
|
36
|
+
* (ESRCH = gone, EPERM = exists but owned elsewhere). Returns null when the
|
|
37
|
+
* writer is not a parseable "<kind>-<pid>" (e.g. the legacy status.json).
|
|
38
|
+
*/
|
|
39
|
+
export function writerProcessAlive(writer) {
|
|
40
|
+
if (typeof writer !== 'string') return null;
|
|
41
|
+
const m = /-(\d+)$/.exec(writer);
|
|
42
|
+
if (!m) return null;
|
|
43
|
+
const pid = Number(m[1]);
|
|
44
|
+
if (!Number.isInteger(pid) || pid <= 0) return null;
|
|
45
|
+
try { process.kill(pid, 0); return true; }
|
|
46
|
+
catch (err) {
|
|
47
|
+
if (err?.code === 'ESRCH') return false;
|
|
48
|
+
if (err?.code === 'EPERM') return true;
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Merge fresh shards (plus the legacy status.json during transition). */
|
|
54
|
+
export function readMergedStatus({ excludeWriter } = {}) {
|
|
55
|
+
const jobs = [];
|
|
56
|
+
const now = Date.now();
|
|
57
|
+
const consume = (raw, file) => {
|
|
58
|
+
try {
|
|
59
|
+
const shard = JSON.parse(raw);
|
|
60
|
+
if (shard.writer === excludeWriter) return;
|
|
61
|
+
if (now - +new Date(shard.updatedAt) > SHARD_FRESH_MS) {
|
|
62
|
+
// A writer killed hard (SIGKILL, crash) never ran its exit cleanup, so
|
|
63
|
+
// its shard file lingers and every reader re-reads it forever. Once the
|
|
64
|
+
// shard is stale AND its writer is provably gone, drop the file. Unknown
|
|
65
|
+
// liveness (null) is left alone — never delete on a guess.
|
|
66
|
+
if (file && writerProcessAlive(shard.writer) === false) {
|
|
67
|
+
try { rmSync(file, { force: true }); } catch {}
|
|
68
|
+
}
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
// WPC10: expose the owning writer's liveness and last-write time so the
|
|
72
|
+
// panel can flag running jobs whose instance died (orphans) instead of
|
|
73
|
+
// showing them as running forever or dropping them silently.
|
|
74
|
+
const writerAlive = writerProcessAlive(shard.writer);
|
|
75
|
+
for (const job of shard.jobs ?? []) {
|
|
76
|
+
jobs.push({
|
|
77
|
+
...job,
|
|
78
|
+
origin: shard.writer ?? 'legacy',
|
|
79
|
+
originWriterAlive: writerAlive,
|
|
80
|
+
originShardUpdatedAt: typeof shard.updatedAt === 'string' ? shard.updatedAt : null,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
} catch {}
|
|
84
|
+
};
|
|
85
|
+
try {
|
|
86
|
+
for (const f of readdirSync(SHARD_DIR)) {
|
|
87
|
+
if (f.endsWith('.json')) {
|
|
88
|
+
const p = join(SHARD_DIR, f);
|
|
89
|
+
try { consume(readFileSync(p, 'utf8'), p); } catch {}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
} catch {}
|
|
93
|
+
try { consume(readFileSync(join(CONFIG_DIR, 'status.json'), 'utf8')); } catch {}
|
|
94
|
+
return jobs;
|
|
95
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Which LLM route a worker tier dispatches to.
|
|
2
|
+
//
|
|
3
|
+
// Historically each tier was two constants: provider "deepseek-official" plus
|
|
4
|
+
// deepseek-v4-flash / deepseek-v4-pro. A user who had already configured
|
|
5
|
+
// another route in DSH — a local Ollama server is the motivating case
|
|
6
|
+
// (issue #10) — had no way to send workers to it, even though the dispatch
|
|
7
|
+
// path already hands {provider, model} to the host and the host resolves the
|
|
8
|
+
// provider id itself.
|
|
9
|
+
//
|
|
10
|
+
// This module is the one place that answers "tier -> route". It deliberately
|
|
11
|
+
// does NOT define providers: a provider is configured once, in DSH, and named
|
|
12
|
+
// here. That keeps one configuration surface instead of three (DSH's own
|
|
13
|
+
// provider settings, this plugin's custom-provider list for the vision route,
|
|
14
|
+
// and a third one for workers).
|
|
15
|
+
|
|
16
|
+
/** The built-in DeepSeek route for each tier — the behaviour before #10. */
|
|
17
|
+
export const DEFAULT_TIER_BINDING = Object.freeze({
|
|
18
|
+
flash: Object.freeze({ provider: 'deepseek-official', model: 'deepseek-v4-flash' }),
|
|
19
|
+
pro: Object.freeze({ provider: 'deepseek-official', model: 'deepseek-v4-pro' }),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export const TIERS = Object.freeze(['flash', 'pro']);
|
|
23
|
+
|
|
24
|
+
/** A configured value counts only when it is a non-blank string. */
|
|
25
|
+
function configured(value) {
|
|
26
|
+
return typeof value === 'string' && value.trim() !== '' ? value.trim() : undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Resolve one tier against a config object.
|
|
31
|
+
*
|
|
32
|
+
* Provider and model are resolved INDEPENDENTLY, so naming only a model keeps
|
|
33
|
+
* the default provider (the common "same endpoint, different model" case) and
|
|
34
|
+
* naming only a provider keeps the tier's model id (an OpenAI-compatible
|
|
35
|
+
* gateway that serves the same model name). A blank value is not a
|
|
36
|
+
* configuration — it falls back rather than dispatching to "".
|
|
37
|
+
*/
|
|
38
|
+
export function resolveTierBinding(tier, config = {}) {
|
|
39
|
+
const fallback = DEFAULT_TIER_BINDING[tier];
|
|
40
|
+
if (fallback === undefined) {
|
|
41
|
+
throw new Error(`unknown tier "${tier}" (expected: ${TIERS.join(', ')})`);
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
provider: configured(config[`${tier}_provider`]) ?? fallback.provider,
|
|
45
|
+
model: configured(config[`${tier}_model`]) ?? fallback.model,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** True when this tier dispatches somewhere other than the shipped default. */
|
|
50
|
+
export function isCustomBinding(tier, config = {}) {
|
|
51
|
+
const resolved = resolveTierBinding(tier, config);
|
|
52
|
+
const fallback = DEFAULT_TIER_BINDING[tier];
|
|
53
|
+
return resolved.provider !== fallback.provider || resolved.model !== fallback.model;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Both tiers at once, for config views. */
|
|
57
|
+
export function describeBindings(config = {}) {
|
|
58
|
+
const out = {};
|
|
59
|
+
for (const tier of TIERS) {
|
|
60
|
+
out[tier] = { ...resolveTierBinding(tier, config), custom: isCustomBinding(tier, config) };
|
|
61
|
+
}
|
|
62
|
+
return out;
|
|
63
|
+
}
|