@zoraxylia/dsh-codex-adapter 0.1.2 → 0.1.4

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-adapter",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Dispatch subtasks to DeepSeek Harness (DSH) agents as native subagents with live progress",
5
5
  "author": {
6
6
  "name": "zx-yk"
package/lib/client.js CHANGED
@@ -1145,13 +1145,25 @@ function WorkersPanel({ ctx }) {
1145
1145
  ]);
1146
1146
  if (j.ok) mergeJobs(j.jobs ?? []);
1147
1147
  if (s.ok) setStatus(s.status);
1148
- if (c.ok) setConfig((prev) => prev ?? c.config);
1148
+ if (c.ok) {
1149
+ setConfig((prev) => prev ?? c.config);
1150
+ const origin = window.location.origin;
1151
+ const hubUrl = String(c.config?.hub_url ?? "");
1152
+ const isLocalOrEmpty = hubUrl === "" || /^https?:\/\/(127\.0\.0\.1|localhost|\[::1\]):\d+$/.test(hubUrl);
1153
+ if (/^https?:\/\//.test(origin) && isLocalOrEmpty && hubUrl !== origin) post("/config", { hub_url: origin }).then((r) => {
1154
+ if (r.ok) setConfig(r.config);
1155
+ }).catch(() => {});
1156
+ }
1149
1157
  if (pr.ok) setPresetRoster({
1150
1158
  defaultId: pr.defaultId,
1151
1159
  presets: pr.presets ?? []
1152
1160
  });
1153
1161
  } catch {}
1154
- }, [get, mergeJobs]);
1162
+ }, [
1163
+ get,
1164
+ post,
1165
+ mergeJobs
1166
+ ]);
1155
1167
  (0, react.useEffect)(() => {
1156
1168
  refreshAll();
1157
1169
  const timer = setInterval(() => {
package/lib/server.mjs CHANGED
@@ -15059,7 +15059,7 @@ function describeBindings(config = {}) {
15059
15059
  }
15060
15060
 
15061
15061
  // src/server.mjs
15062
- var server = new McpServer({ name: "dsh-adapter", version: "0.1.2" });
15062
+ var server = new McpServer({ name: "dsh-adapter", version: "0.1.4" });
15063
15063
  var tierSchema = external_exports.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.");
15064
15064
  var effortSchema = external_exports.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).");
15065
15065
  var workerSchema = external_exports.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\xD7model\xD7effort. See dsh_worker_config output, worker_profiles field, for the available profiles.');
@@ -15087,7 +15087,8 @@ var sessionConfig = {
15087
15087
  origin_depth_limit: DEFAULT_ORIGIN_DEPTH_LIMIT
15088
15088
  };
15089
15089
  function bindingForTier(tier) {
15090
- return resolveTierBinding(tier, sessionConfig);
15090
+ const pinned = [sessionConfig[`${tier}_provider`], sessionConfig[`${tier}_model`]].some((v) => typeof v === "string" && v.trim() !== "");
15091
+ return pinned ? resolveTierBinding(tier, sessionConfig) : {};
15091
15092
  }
15092
15093
  function presetForTier(tier) {
15093
15094
  const p = tier === "flash" ? sessionConfig.preset_flash : sessionConfig.preset_pro;
@@ -15271,11 +15272,13 @@ server.registerTool("dsh_worker_config", {
15271
15272
  const bindings = describeBindings(sessionConfig);
15272
15273
  const custom2 = Object.entries(bindings).filter(([, b]) => b.custom).map(([tier]) => tier);
15273
15274
  const unknown = available === null ? [] : custom2.filter((tier) => !available.some((p) => p.id === bindings[tier].provider));
15275
+ const availableModels = available === null ? null : Object.fromEntries(available.map((p) => [p.id, p.models ?? []]));
15274
15276
  return text({
15275
15277
  ...sessionConfig,
15276
15278
  hub_reachable: reachable,
15277
15279
  bindings,
15278
15280
  available_providers: available,
15281
+ available_models: availableModels,
15279
15282
  ...available === null && custom2.length > 0 ? { 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." } : {},
15280
15283
  ...unknown.length > 0 ? { 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.` } : {},
15281
15284
  ...custom2.length > 0 ? { 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.' } : {},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zoraxylia/dsh-codex-adapter",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
5
  "main": "./src/hub/index.mjs",
6
6
  "description": "DeepSeek Harness plugin: dispatch work to DSH agents from Claude Code / Codex, as native subagents with live progress",
@@ -516,10 +516,23 @@ function WorkersPanel({ ctx }: { ctx: any }) {
516
516
  const [j, s, c, pr] = await Promise.all([get('/jobs'), get('/install/status'), get('/config'), get('/presets')]);
517
517
  if (j.ok) mergeJobs(j.jobs ?? []);
518
518
  if (s.ok) setStatus(s.status);
519
- if (c.ok) setConfig((prev: any) => prev ?? c.config);
519
+ if (c.ok) {
520
+ setConfig((prev: any) => prev ?? c.config);
521
+ // The desktop host binds an OS-assigned port on every launch, so the
522
+ // stored hub_url goes stale and host-side MCP shims fall back to
523
+ // standalone mode. Opening this page is the natural moment to repoint
524
+ // it at the address the page itself was served from. A hub_url naming
525
+ // another machine is left alone.
526
+ const origin = window.location.origin;
527
+ const hubUrl = String(c.config?.hub_url ?? '');
528
+ const isLocalOrEmpty = hubUrl === '' || /^https?:\/\/(127\.0\.0\.1|localhost|\[::1\]):\d+$/.test(hubUrl);
529
+ if (/^https?:\/\//.test(origin) && isLocalOrEmpty && hubUrl !== origin) {
530
+ void post('/config', { hub_url: origin }).then((r) => { if (r.ok) setConfig(r.config); }).catch(() => {});
531
+ }
532
+ }
520
533
  if (pr.ok) setPresetRoster({ defaultId: pr.defaultId, presets: pr.presets ?? [] });
521
534
  } catch { /* instance restarting */ }
522
- }, [get, mergeJobs]);
535
+ }, [get, post, mergeJobs]);
523
536
 
524
537
  useEffect(() => {
525
538
  void refreshAll();
package/src/hub/index.mjs CHANGED
@@ -122,12 +122,68 @@ export class WorkerRegistry {
122
122
  this.shard.publish([...this.jobs.values()].map((j) => this.view(j)));
123
123
  }
124
124
 
125
+ /** One bounded capability probe; the route counts as usable when it streams. */
126
+ async probeRoute(llm, binding) {
127
+ try {
128
+ const result = await probeProvider(llm, binding, { timeoutMs: 12000 });
129
+ return result.status === 'verified' || result.status === 'no_tool_call';
130
+ } catch { return false; }
131
+ }
132
+
133
+ /**
134
+ * Resolve a tier that the user has not pinned. The shipped default route
135
+ * (deepseek-official) fails on installs without DEEPSEEK_API_KEY, and a
136
+ * provider that exists may still have no channel for the requested model —
137
+ * the pro tier hits exactly that. Probe the configured providers, take the
138
+ * first route that streams, and persist it so later dispatches skip the
139
+ * search. Pinned bindings never reach this path.
140
+ */
141
+ async resolveUsableTier(tier, bound) {
142
+ this.autoTier ??= {};
143
+ if (this.autoTier[tier]) return this.autoTier[tier];
144
+ const llm = this.ctx?.get?.('llm') ?? this.ctx?.llm;
145
+ if (!llm) return bound;
146
+ if (await this.probeRoute(llm, bound)) { this.autoTier[tier] = bound; return bound; }
147
+ const builtin = new Set(['deepseek-official', 'deepseek-account']);
148
+ let ids = [];
149
+ try {
150
+ ids = llm.listProviders().map((p) => p.id).filter((id) => id !== bound.provider);
151
+ } catch { return bound; }
152
+ ids.sort((a, b) => Number(builtin.has(a)) - Number(builtin.has(b)));
153
+ const candidates = [];
154
+ for (const id of ids) {
155
+ let models = [];
156
+ try { models = await llm.listModels(id); } catch { continue; }
157
+ for (const m of models.slice(0, 3)) candidates.push({ provider: id, model: m.id });
158
+ if (candidates.length >= 5) break;
159
+ }
160
+ for (const candidate of candidates) {
161
+ if (await this.probeRoute(llm, candidate)) {
162
+ this.autoTier[tier] = candidate;
163
+ try {
164
+ writeGlobalConfig({ [`${tier}_provider`]: candidate.provider, [`${tier}_model`]: candidate.model });
165
+ } catch { /* read-only home: keep the in-memory choice */ }
166
+ this.ctx?.logger?.info?.(`dsh-adapter: ${tier} auto-bound to ${candidate.provider}/${candidate.model}`);
167
+ return candidate;
168
+ }
169
+ }
170
+ this.ctx?.logger?.warn?.(`dsh-adapter: no usable ${tier} route; keeping ${bound.provider}/${bound.model}`);
171
+ return bound;
172
+ }
173
+
125
174
  async spawn({ task, tier = 'flash', effort = 'max', cwd, source = 'api', provider, model, preset }) {
126
175
  if (!TIERS.includes(tier)) throw new Error(`unknown tier "${tier}"`);
127
176
  // An explicit {provider, model} from the caller wins (the MCP process owns
128
177
  // session-level overrides, exactly as it does for presets); otherwise the
129
178
  // hub's own stored config decides, and failing that the tier default.
130
- const bound = resolveTierBinding(tier, this.getConfig?.() ?? {});
179
+ const tierConfig = this.getConfig?.() ?? {};
180
+ const pinned = [provider, model, tierConfig[`${tier}_provider`], tierConfig[`${tier}_model`]]
181
+ .some((v) => typeof v === 'string' && v.trim() !== '');
182
+ let bound = resolveTierBinding(tier, tierConfig);
183
+ // Nothing pinned means the user is on the shipped default (deepseek-official),
184
+ // which needs DEEPSEEK_API_KEY. Find a route that actually works once, then
185
+ // remember it, instead of failing every dispatch on a missing key.
186
+ if (!pinned) bound = await this.resolveUsableTier(tier, bound);
131
187
  const resolvedProvider = typeof provider === 'string' && provider.trim() !== '' ? provider.trim() : bound.provider;
132
188
  const resolvedModel = typeof model === 'string' && model.trim() !== '' ? model.trim() : bound.model;
133
189
  if (!['off', 'high', 'max'].includes(effort)) throw new Error(`unknown effort "${effort}"`);
@@ -381,18 +437,33 @@ export async function apply(ctx) {
381
437
  // hub_url goes stale after each restart and the host-side MCP shim falls
382
438
  // back to standalone mode. Publish this instance's origin into the shared
383
439
  // config instead; a hub_url that names another machine is left untouched.
440
+ const originOf = () => {
441
+ try {
442
+ const value = webServer.getOrigin?.();
443
+ if (typeof value === 'string' && value) return value;
444
+ } catch { /* listener not bound yet */ }
445
+ try {
446
+ const port = webServer.port;
447
+ if (Number.isInteger(port) && port > 0) return 'http://127.0.0.1:' + port;
448
+ } catch { /* port accessor unavailable */ }
449
+ return undefined;
450
+ };
384
451
  const syncHubUrl = (attempt = 0) => {
452
+ const origin = originOf();
453
+ if (!origin) {
454
+ // The listener can bind well after plugins apply; keep trying quietly.
455
+ if (attempt < 15) { setTimeout(() => syncHubUrl(attempt + 1), 2000).unref?.(); return; }
456
+ ctx.logger?.warn?.('dsh-adapter: hub_url sync gave up waiting for the listener');
457
+ return;
458
+ }
385
459
  try {
386
- const origin = webServer.getOrigin?.();
387
460
  const current = readGlobalConfig();
388
461
  const isLocal = /^https?:\/\/(127\.0\.0\.1|localhost|\[::1\]):\d+$/.test(current.hub_url ?? '');
389
- if (origin && (!current.hub_url || isLocal) && current.hub_url !== origin) {
462
+ if ((!current.hub_url || isLocal) && current.hub_url !== origin) {
390
463
  writeGlobalConfig({ hub_url: origin });
391
464
  ctx.logger?.info?.('dsh-adapter: hub_url synced to ' + origin);
392
465
  }
393
466
  } catch (err) {
394
- // getOrigin() throws until the listener is bound; retry briefly.
395
- if (attempt < 3) { setTimeout(() => syncHubUrl(attempt + 1), 1500).unref?.(); return; }
396
467
  ctx.logger?.warn?.('dsh-adapter: hub_url sync skipped: ' + (err?.message ?? err));
397
468
  }
398
469
  };
@@ -555,7 +626,12 @@ export async function apply(ctx) {
555
626
  if (!isLoopbackRequest(req)) return sendJson(res, 403, { ok: false, error: 'loopback only' });
556
627
  try {
557
628
  const { readGlobalConfig } = await import('../install/install.mjs');
558
- const providers = ctx.llm.listProviders().map((p) => ({ id: p.id, name: p.name ?? p.id }));
629
+ const providers = [];
630
+ for (const p of ctx.llm.listProviders()) {
631
+ let models = [];
632
+ try { models = (await ctx.llm.listModels(p.id)).map((m) => m.id); } catch { /* adapter without a catalog */ }
633
+ providers.push({ id: p.id, name: p.name ?? p.id, models });
634
+ }
559
635
  return sendJson(res, 200, {
560
636
  ok: true,
561
637
  providers,
package/src/server.mjs CHANGED
@@ -12,7 +12,7 @@ import { acquireCwdLock, releaseCwdLockByJobId, updateCwdLockHolder, getCwdLocks
12
12
  import { resolveWorkerCwd } from './paths.mjs';
13
13
  import { detectOrchestrator } from './process-info.mjs';
14
14
 
15
- const server = new McpServer({ name: 'dsh-adapter', version: '0.1.2' });
15
+ const server = new McpServer({ name: 'dsh-adapter', version: '0.1.4' });
16
16
 
17
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
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).');
@@ -46,9 +46,16 @@ const sessionConfig = {
46
46
  origin_depth_limit: DEFAULT_ORIGIN_DEPTH_LIMIT,
47
47
  };
48
48
 
49
- /** The {provider, model} this session dispatches `tier` to. */
49
+ /**
50
+ * The {provider, model} this session pins for `tier`, or {} when the user has
51
+ * not pinned anything. Sending the resolved default here would look like an
52
+ * explicit choice to the hub and disable its usable-route fallback, which is
53
+ * exactly how an install without DEEPSEEK_API_KEY kept failing.
54
+ */
50
55
  function bindingForTier(tier) {
51
- return resolveTierBinding(tier, sessionConfig);
56
+ const pinned = [sessionConfig[`${tier}_provider`], sessionConfig[`${tier}_model`]]
57
+ .some((v) => typeof v === 'string' && v.trim() !== '');
58
+ return pinned ? resolveTierBinding(tier, sessionConfig) : {};
52
59
  }
53
60
 
54
61
  function presetForTier(tier) {
@@ -282,11 +289,15 @@ server.registerTool('dsh_worker_config', {
282
289
  const unknown = available === null
283
290
  ? []
284
291
  : custom.filter((tier) => !available.some((p) => p.id === bindings[tier].provider));
292
+ const availableModels = available === null
293
+ ? null
294
+ : Object.fromEntries(available.map((p) => [p.id, p.models ?? []]));
285
295
  return text({
286
296
  ...sessionConfig,
287
297
  hub_reachable: reachable,
288
298
  bindings,
289
299
  available_providers: available,
300
+ available_models: availableModels,
290
301
  ...(available === null && custom.length > 0
291
302
  ? { 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
303
  : {}),