@yankeguo/dsh-devlead 0.2.1 → 0.2.3

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.
Files changed (2) hide show
  1. package/lib/index.js +476 -9
  2. package/package.json +2 -2
package/lib/index.js CHANGED
@@ -9,6 +9,7 @@ var __export = (target, all) => {
9
9
  import { mkdir } from "node:fs/promises";
10
10
  import { Service } from "@deepseek-ai/cordis";
11
11
  import z2 from "@deepseek-ai/schemastery";
12
+ import { ReasoningEffortId } from "@deepseek-ai/dsh-llm";
12
13
  import { appendPluginRecord as appendPluginRecord2 } from "@deepseek-ai/dsh-session";
13
14
  import "@deepseek-ai/dsh-session";
14
15
  import { DEVLEAD_DEFAULT_MAX_WATCHED as DEVLEAD_DEFAULT_MAX_WATCHED2 } from "@yankeguo/dsh-devlead-protocol";
@@ -235,6 +236,138 @@ function assistantExcerpt(blocks) {
235
236
  return excerptLine(text, DEVLEAD_ERROR_EXCERPT_MAX);
236
237
  }
237
238
 
239
+ // packages/devlead/src/dispatch.ts
240
+ function stringField(value) {
241
+ return typeof value === "string" ? value : "";
242
+ }
243
+ function recordOf(value) {
244
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
245
+ }
246
+ function itemsOf(value) {
247
+ return Array.isArray(value) ? value : [];
248
+ }
249
+ function modelViewOf(value) {
250
+ const record2 = recordOf(value);
251
+ if (record2 === void 0) return void 0;
252
+ const id = stringField(record2.id);
253
+ if (id.length === 0) return void 0;
254
+ const name = stringField(record2.name);
255
+ const reasoningRecord = recordOf(record2.reasoning);
256
+ if (reasoningRecord === void 0) {
257
+ return { id, name: name.length === 0 ? id : name };
258
+ }
259
+ const efforts = itemsOf(reasoningRecord.efforts).map((effort) => {
260
+ const effortRecord = recordOf(effort);
261
+ if (effortRecord === void 0) return void 0;
262
+ const effortId = stringField(effortRecord.id);
263
+ if (effortId.length === 0) return void 0;
264
+ const effortName = stringField(effortRecord.name);
265
+ return { id: effortId, name: effortName.length === 0 ? effortId : effortName };
266
+ }).filter((effort) => effort !== void 0);
267
+ const defaultEffort = stringField(reasoningRecord.defaultEffort);
268
+ return {
269
+ id,
270
+ name: name.length === 0 ? id : name,
271
+ reasoning: {
272
+ efforts,
273
+ ...defaultEffort.length === 0 ? {} : { defaultEffort }
274
+ }
275
+ };
276
+ }
277
+ function devLeadModelCatalogOf(value) {
278
+ const record2 = recordOf(value) ?? {};
279
+ const defaultRecord = recordOf(record2.default) ?? {};
280
+ const defaultProvider = stringField(defaultRecord.provider);
281
+ const defaultModel = stringField(defaultRecord.model);
282
+ const defaultEffort = stringField(defaultRecord.reasoningEffort);
283
+ const defaultSelection = {
284
+ provider: defaultProvider,
285
+ model: defaultModel,
286
+ ...defaultEffort.length === 0 ? {} : { reasoningEffort: defaultEffort }
287
+ };
288
+ const routableProviders = itemsOf(record2.routableProviders).filter((provider) => typeof provider === "string" && provider.length > 0);
289
+ const providers = [];
290
+ for (const group of itemsOf(record2.groups)) {
291
+ const groupRecord = recordOf(group);
292
+ if (groupRecord === void 0) continue;
293
+ const id = stringField(groupRecord.id);
294
+ if (id.length === 0) continue;
295
+ const name = stringField(groupRecord.name);
296
+ const models = itemsOf(groupRecord.models).map(modelViewOf).filter((model) => model !== void 0);
297
+ providers.push({ id, name: name.length === 0 ? id : name, models });
298
+ }
299
+ const failures = [];
300
+ for (const failure of itemsOf(record2.failures)) {
301
+ const failureRecord = recordOf(failure);
302
+ if (failureRecord === void 0) continue;
303
+ const id = stringField(failureRecord.id);
304
+ if (id.length === 0) continue;
305
+ const name = stringField(failureRecord.name);
306
+ failures.push({
307
+ id,
308
+ name: name.length === 0 ? id : name,
309
+ message: stringField(failureRecord.message)
310
+ });
311
+ }
312
+ return { default: defaultSelection, routableProviders, providers, failures };
313
+ }
314
+ function modelCatalogCapabilityOf(ctx) {
315
+ const candidate = ctx.get("sessionController");
316
+ if (typeof candidate !== "object" || candidate === null) return void 0;
317
+ const modelCatalog = candidate.modelCatalog;
318
+ if (typeof modelCatalog !== "function") return void 0;
319
+ return candidate;
320
+ }
321
+ function modelSelectionLabel(selection) {
322
+ const base = `${selection.provider}/${selection.model}`;
323
+ return selection.reasoningEffort === void 0 ? base : `${base} (reasoning effort "${selection.reasoningEffort}")`;
324
+ }
325
+ function normalizeModelSelection(value) {
326
+ if (value === void 0) return void 0;
327
+ const provider = typeof value.provider === "string" ? value.provider.trim() : "";
328
+ const model = typeof value.model === "string" ? value.model.trim() : "";
329
+ const effort = typeof value.reasoningEffort === "string" ? value.reasoningEffort.trim() : "";
330
+ if (provider.length === 0 && model.length === 0) {
331
+ if (effort.length > 0) {
332
+ throw new DevLeadError(
333
+ "reasoningEffort requires an explicit provider and model; the Host default model has no dispatch-time effort override",
334
+ "DEVLEAD_INVALID_INPUT"
335
+ );
336
+ }
337
+ return void 0;
338
+ }
339
+ if (provider.length === 0 || model.length === 0) {
340
+ throw new DevLeadError(
341
+ "provider and model must be provided together",
342
+ "DEVLEAD_INVALID_INPUT"
343
+ );
344
+ }
345
+ return {
346
+ provider,
347
+ model,
348
+ ...effort.length === 0 ? {} : { reasoningEffort: effort }
349
+ };
350
+ }
351
+ function modelValidatorOf(ctx) {
352
+ const candidate = ctx.get("llm");
353
+ if (typeof candidate !== "object" || candidate === null) return void 0;
354
+ const listProviders = candidate.listProviders;
355
+ const listModels = candidate.listModels;
356
+ const resolve = candidate.resolveCallConfig;
357
+ if (typeof listProviders !== "function" || typeof listModels !== "function" || typeof resolve !== "function") {
358
+ return void 0;
359
+ }
360
+ return candidate;
361
+ }
362
+ function agentTeamsCapabilityOf(ctx) {
363
+ const candidate = ctx.get("agentTeams");
364
+ if (typeof candidate !== "object" || candidate === null) return void 0;
365
+ const isEnabled = candidate.isEnabled;
366
+ const setEnabled = candidate.setEnabled;
367
+ if (typeof isEnabled !== "function" || typeof setEnabled !== "function") return void 0;
368
+ return candidate;
369
+ }
370
+
238
371
  // packages/devlead/src/fold.ts
239
372
  import { pluginRecordOf } from "@deepseek-ai/dsh-session";
240
373
 
@@ -15849,17 +15982,32 @@ async function resolveExactSession(deps, reference) {
15849
15982
  return void 0;
15850
15983
  }
15851
15984
  }
15985
+ var SESSION_ID_PREFIX = "session-";
15986
+ function matchSessionIds(candidates, reference) {
15987
+ const mayOmitPrefix = !reference.startsWith(SESSION_ID_PREFIX);
15988
+ const matched = /* @__PURE__ */ new Set();
15989
+ for (const id of candidates) {
15990
+ if (id.startsWith(reference)) {
15991
+ matched.add(id);
15992
+ continue;
15993
+ }
15994
+ if (mayOmitPrefix && id.startsWith(SESSION_ID_PREFIX) && id.slice(SESSION_ID_PREFIX.length).startsWith(reference)) {
15995
+ matched.add(id);
15996
+ }
15997
+ }
15998
+ return [...matched];
15999
+ }
15852
16000
  async function resolveSessionReference(deps, reference) {
15853
16001
  const trimmed = reference.trim();
15854
16002
  if (trimmed.length === 0) throw new DevLeadError("a Session id is required", "DEVLEAD_INVALID_INPUT");
15855
16003
  const exact = await resolveExactSession(deps, trimmed);
15856
16004
  if (exact !== void 0) return exact;
15857
16005
  const candidates = await collectSessionIds(deps, void 0, true);
15858
- const matched = candidates.filter((id) => id.startsWith(trimmed));
16006
+ const matched = matchSessionIds(candidates, trimmed);
15859
16007
  const resolvedId = matched.find((id) => id === trimmed) ?? (matched.length === 1 ? matched[0] : void 0);
15860
16008
  if (resolvedId === void 0 && matched.length === 0) {
15861
16009
  throw new DevLeadError(
15862
- `no Session matches "${reference}"; list the addressable Sessions with devlead_list_sessions`,
16010
+ `no Session matches "${reference}"; the id may be incomplete or truncated, so look up the full id with devlead_list_sessions and retry`,
15863
16011
  "DEVLEAD_SESSION_NOT_FOUND"
15864
16012
  );
15865
16013
  }
@@ -15941,6 +16089,27 @@ function workspacePathFailure(error51, path) {
15941
16089
  "DEVLEAD_INVALID_INPUT"
15942
16090
  );
15943
16091
  }
16092
+ var MAX_REPORTED_ACTIVITY_ITEMS = 3;
16093
+ function isActiveSessionFailure(error51) {
16094
+ if (typeof error51 !== "object" || error51 === null) return false;
16095
+ const candidate = error51;
16096
+ return candidate.name === "WorkspaceActiveSessionError" && Array.isArray(candidate.activity);
16097
+ }
16098
+ function isUnknownSessionFailure(error51) {
16099
+ if (typeof error51 !== "object" || error51 === null) return false;
16100
+ return error51.name === "WorkspaceUnknownSessionError";
16101
+ }
16102
+ function describeSessionActivity(activity) {
16103
+ if (activity.length === 0) return "unspecified activity";
16104
+ return activity.map((entry) => {
16105
+ const kind = String(entry.kind);
16106
+ const items = entry.items ?? [];
16107
+ if (items.length === 0) return kind;
16108
+ const labels = items.slice(0, MAX_REPORTED_ACTIVITY_ITEMS).map((item) => item.label ?? item.id);
16109
+ const omitted = items.length - labels.length;
16110
+ return `${kind} (${labels.join(", ")}${omitted > 0 ? `, +${String(omitted)} more` : ""})`;
16111
+ }).join("; ");
16112
+ }
15944
16113
  var DevLeadService = class extends Service {
15945
16114
  static inject = ["agents", "sessions", "sessionProjections"];
15946
16115
  /** Loader schema, applied by the Loader before construction. */
@@ -16369,6 +16538,36 @@ var DevLeadService = class extends Service {
16369
16538
  }
16370
16539
  return await devLeadWorkspaceView(workspace);
16371
16540
  }
16541
+ /**
16542
+ * Close one Workspace by removing its DSH registration.
16543
+ *
16544
+ * This is the registry's own `remove` action, not a deletion: the directory,
16545
+ * its files, and every Session log stay untouched. The Workspace's Sessions
16546
+ * become ungrouped — still openable and continuable — and re-registering the
16547
+ * same directory creates a new registration that does not adopt them.
16548
+ *
16549
+ * The returned view is the pre-removal snapshot, so the caller can report
16550
+ * what it closed and which Sessions it accounted to.
16551
+ * @param agent - exact live lead Agent making the removal.
16552
+ * @param workspace - Workspace id or canonical/registered path.
16553
+ * @param signal - cancellation checked before the registry write.
16554
+ * @returns the pre-removal Workspace view and whether a registration was
16555
+ * removed (`false` when another actor removed it first).
16556
+ * @throws {@link DevLeadError} `DEVLEAD_NOT_ENABLED`/`DEVLEAD_AGENT_NOT_LIVE`
16557
+ * for a disallowed caller, `DEVLEAD_WORKSPACE_NOT_FOUND` when the Host
16558
+ * composes no registry or nothing matches the reference.
16559
+ */
16560
+ async removeWorkspace(agent, workspace, signal) {
16561
+ this.assertReady(agent);
16562
+ signal?.throwIfAborted();
16563
+ const registry2 = this.requireWorkspaceRegistry();
16564
+ const resolved = await resolveWorkspaceReference(this.ctx, workspace, signal);
16565
+ signal?.throwIfAborted();
16566
+ const view = await devLeadWorkspaceView(resolved);
16567
+ signal?.throwIfAborted();
16568
+ const removed = await registry2.delete(resolved.id);
16569
+ return { workspace: view, removed };
16570
+ }
16372
16571
  // ---------------------------------------------------------------------------
16373
16572
  // Sessions
16374
16573
  // ---------------------------------------------------------------------------
@@ -16412,6 +16611,43 @@ var DevLeadService = class extends Service {
16412
16611
  const retained = rankSessionIds(deps, ids, facts, limit);
16413
16612
  return await devLeadSessionViews(deps, retained, false, facts);
16414
16613
  }
16614
+ /**
16615
+ * Read the Host's model catalog for dispatch-time selection.
16616
+ *
16617
+ * The view reports the Host default selection, routable providers, each
16618
+ * provider's advertised models and reasoning efforts, and catalog lookup
16619
+ * failures. It is read-only: no Session, profile default, or Team state is
16620
+ * changed. The controller's catalog method takes no cancellation token, so
16621
+ * the signal is checked before and after the read.
16622
+ * @param agent - exact live lead Agent.
16623
+ * @param signal - cancellation checked before and after the catalog read.
16624
+ * @returns the normalized model catalog view.
16625
+ * @throws {@link DevLeadError} `DEVLEAD_SESSION_UNAVAILABLE` when the Host
16626
+ * composes no Session controller with a model catalog or the read fails.
16627
+ */
16628
+ async listModels(agent, signal) {
16629
+ this.assertReady(agent);
16630
+ signal?.throwIfAborted();
16631
+ const controller = modelCatalogCapabilityOf(this.ctx);
16632
+ if (controller === void 0) {
16633
+ throw new DevLeadError(
16634
+ "this Host cannot list models: no API Session controller with a model catalog is composed",
16635
+ "DEVLEAD_SESSION_UNAVAILABLE"
16636
+ );
16637
+ }
16638
+ let catalog;
16639
+ try {
16640
+ catalog = await controller.modelCatalog();
16641
+ } catch (error51) {
16642
+ signal?.throwIfAborted();
16643
+ throw new DevLeadError(
16644
+ `could not read the model catalog: ${thrownMessage(error51)}`,
16645
+ "DEVLEAD_SESSION_UNAVAILABLE"
16646
+ );
16647
+ }
16648
+ signal?.throwIfAborted();
16649
+ return devLeadModelCatalogOf(catalog);
16650
+ }
16415
16651
  /**
16416
16652
  * Read one Session in detail, including folded turn and assistant facts.
16417
16653
  * @param agent - exact live lead Agent.
@@ -16444,19 +16680,32 @@ var DevLeadService = class extends Service {
16444
16680
  * next side effect, so a cancelled create may leave a watched Session behind
16445
16681
  * without running isolation or admitting the prompt. Session creation itself
16446
16682
  * is not abortable once started.
16683
+ *
16684
+ * A requested model selection and Agent Teams mode are creation-time
16685
+ * settings, applied to the new Session's own Agent immediately after the
16686
+ * Session exists and before its title/watch/isolation/prompt. The model is
16687
+ * validated against the Host's LLM registry first, and it is recorded with
16688
+ * `agent.model.select`, never through the Session controller's `selectModel`
16689
+ * (which would also rewrite the profile default model). An application
16690
+ * failure after creation reports the created Session id and leaves that
16691
+ * Session in place, matching the service's non-rollback creation contract.
16447
16692
  * @param agent - exact live lead Agent.
16448
16693
  * @param request - Workspace, optional title, initial prompt, watch policy,
16449
- * preset, and checkout isolation mode.
16694
+ * preset, checkout isolation mode, creation-time model selection, and
16695
+ * creation-time Agent Teams mode.
16450
16696
  * @param signal - cancellation checked between stages and threaded into the
16451
16697
  * worktree creation.
16452
- * @returns the created Session, the Workspace it joined, and the
16453
- * checkout-isolation outcome.
16698
+ * @returns the created Session, the Workspace it joined, the
16699
+ * checkout-isolation outcome, and any applied model/Team settings.
16454
16700
  * @throws {@link DevLeadError} when the mode is off, the Host cannot create
16455
- * Sessions, or the destination is not usable.
16701
+ * Sessions, the destination is not usable, or a requested model/Team
16702
+ * capability is unavailable.
16456
16703
  */
16457
16704
  async createSession(agent, request, signal) {
16458
16705
  this.assertReady(agent);
16459
16706
  signal?.throwIfAborted();
16707
+ const requestedModel = normalizeModelSelection(request.model);
16708
+ const requestedTeams = request.agentTeams;
16460
16709
  const controller = this.ctx.get("sessionController");
16461
16710
  if (controller === void 0) {
16462
16711
  throw new DevLeadError(
@@ -16464,6 +16713,14 @@ var DevLeadService = class extends Service {
16464
16713
  "DEVLEAD_SESSION_UNAVAILABLE"
16465
16714
  );
16466
16715
  }
16716
+ const teams = requestedTeams === void 0 ? void 0 : agentTeamsCapabilityOf(this.ctx);
16717
+ if (requestedTeams === true && teams === void 0) {
16718
+ throw new DevLeadError(
16719
+ "this Host composes no Agent Teams service, so agent_teams cannot be enabled. Agent Teams is available from DSH 0.2.2-rc.2 (and is included in the default composition there); omit agent_teams or continue without Team mode",
16720
+ "DEVLEAD_TEAM_UNAVAILABLE"
16721
+ );
16722
+ }
16723
+ if (requestedModel !== void 0) await this.assertModelSelectable(requestedModel, signal);
16467
16724
  const watch = request.watch ?? true;
16468
16725
  const releaseWatch = watch ? this.reserveWatchSlot(agent) : void 0;
16469
16726
  try {
@@ -16488,6 +16745,7 @@ var DevLeadService = class extends Service {
16488
16745
  }
16489
16746
  signal?.throwIfAborted();
16490
16747
  const sessionId = String(created.sessionId);
16748
+ const applied = await this.applyDispatchSettings(created, requestedModel, requestedTeams, teams, signal);
16491
16749
  if (request.title !== void 0 && request.title.trim().length > 0) {
16492
16750
  this.tryRename(created.sessionId, request.title.trim());
16493
16751
  }
@@ -16508,7 +16766,9 @@ var DevLeadService = class extends Service {
16508
16766
  session: await devLeadSessionView(deps, sessionId, true),
16509
16767
  workspace: await devLeadWorkspaceView(workspace),
16510
16768
  prompted,
16511
- isolation
16769
+ isolation,
16770
+ ...applied.model === void 0 ? {} : { model: applied.model },
16771
+ ...applied.agentTeams === void 0 ? {} : { agentTeams: applied.agentTeams }
16512
16772
  };
16513
16773
  } finally {
16514
16774
  releaseWatch?.();
@@ -16572,6 +16832,88 @@ var DevLeadService = class extends Service {
16572
16832
  resumed
16573
16833
  };
16574
16834
  }
16835
+ /**
16836
+ * Close one Session by archiving it in the Workspace registry.
16837
+ *
16838
+ * Archiving is the DSH `archive` action: the Session disappears from grouping
16839
+ * surfaces but its log is kept, and {@link unarchiveSession} restores it to
16840
+ * its recorded Workspace position. It is idempotent: an already archived
16841
+ * Session resolves without writing, asking, or stopping anything, and
16842
+ * `stopped` is then `false` even when `stopRunning` is true.
16843
+ *
16844
+ * With `stopRunning` unset the Host refuses a Session whose running work was
16845
+ * reported by a `workspace/session-activity` provider; that refusal is mapped
16846
+ * to `DEVLEAD_SESSION_ACTIVE` with the activity families in the message.
16847
+ * With `stopRunning: true` the archive is written first and the Host is then
16848
+ * asked to stop that work through the same providers the human's own stop
16849
+ * action uses; running work is never awaited to settlement, so the result
16850
+ * reports `stopped: true` as soon as the requests were issued.
16851
+ *
16852
+ * A lead Session can never archive itself: that would pause its own
16853
+ * notification delivery, and `stopRunning` would cancel the very turn making
16854
+ * the call. The rejection is a domain error that points the human at the
16855
+ * Workspace sidebar.
16856
+ * @param agent - exact live lead Agent making the archival.
16857
+ * @param sessionId - Session id, unique prefix, or bare uuid prefix.
16858
+ * @param options - stop-running policy (default `false`) and cancellation
16859
+ * checked before the registry write.
16860
+ * @returns the archived Session identity and whether the Host was asked to
16861
+ * stop the Session's running work (`false` when it was already archived).
16862
+ * @throws {@link DevLeadError} `DEVLEAD_NOT_ENABLED`/`DEVLEAD_AGENT_NOT_LIVE`
16863
+ * for a disallowed caller, `DEVLEAD_INVALID_INPUT` for the lead's own
16864
+ * Session, `DEVLEAD_SESSION_NOT_FOUND` for an unknown Session,
16865
+ * `DEVLEAD_SESSION_ACTIVE` for running work without `stopRunning`, and
16866
+ * `DEVLEAD_WORKSPACE_NOT_FOUND` when the Host composes no registry.
16867
+ */
16868
+ async archiveSession(agent, sessionId, options = {}) {
16869
+ this.assertReady(agent);
16870
+ const signal = options.signal;
16871
+ signal?.throwIfAborted();
16872
+ const deps = this.viewDeps(agent, signal);
16873
+ const resolved = await resolveSessionReference(deps, sessionId);
16874
+ const id = String(resolved.sessionId);
16875
+ signal?.throwIfAborted();
16876
+ if (id === String(agent.id)) {
16877
+ throw new DevLeadError(
16878
+ "a DevLead Session cannot archive itself; ask the human to close this Session from the Workspace sidebar",
16879
+ "DEVLEAD_INVALID_INPUT"
16880
+ );
16881
+ }
16882
+ const registry2 = this.requireWorkspaceRegistry();
16883
+ if (registry2.archivedSessionIds.includes(resolved.sessionId)) {
16884
+ return { sessionId: id, archived: true, stopped: false };
16885
+ }
16886
+ const stopRunning = options.stopRunning ?? false;
16887
+ try {
16888
+ await registry2.archiveSession(resolved.sessionId, { stopActivity: stopRunning });
16889
+ } catch (error51) {
16890
+ throw this.archiveFailure(id, error51) ?? error51;
16891
+ }
16892
+ return { sessionId: id, archived: true, stopped: stopRunning };
16893
+ }
16894
+ /**
16895
+ * Restore one archived Session to its recorded Workspace position.
16896
+ *
16897
+ * Unarchiving is idempotent: an id that is not archived resolves without
16898
+ * writing. The Session log was never touched by the archive.
16899
+ * @param agent - exact live lead Agent making the restore.
16900
+ * @param sessionId - Session id, unique prefix, or bare uuid prefix.
16901
+ * @param signal - cancellation checked before the registry write.
16902
+ * @returns the restored Session identity.
16903
+ * @throws {@link DevLeadError} `DEVLEAD_SESSION_NOT_FOUND` when nothing
16904
+ * matches the reference, `DEVLEAD_WORKSPACE_NOT_FOUND` when the Host
16905
+ * composes no registry, and the caller errors of {@link assertReady}.
16906
+ */
16907
+ async unarchiveSession(agent, sessionId, signal) {
16908
+ this.assertReady(agent);
16909
+ signal?.throwIfAborted();
16910
+ const deps = this.viewDeps(agent, signal);
16911
+ const resolved = await resolveSessionReference(deps, sessionId);
16912
+ signal?.throwIfAborted();
16913
+ const registry2 = this.requireWorkspaceRegistry();
16914
+ await registry2.unarchiveSession(resolved.sessionId);
16915
+ return { sessionId: String(resolved.sessionId), archived: false };
16916
+ }
16575
16917
  /**
16576
16918
  * Add or remove one Session from this lead's watch set.
16577
16919
  * @param agent - exact live lead Agent.
@@ -16811,12 +17153,114 @@ var DevLeadService = class extends Service {
16811
17153
  }
16812
17154
  return [...leads].map(([sessionId, watched]) => ({ sessionId, watched }));
16813
17155
  }
16814
- /** Require the Workspace registry capability. */
17156
+ /**
17157
+ * Validate one requested model selection against the Host's LLM registry.
17158
+ * @param selection - normalized provider/model/effort selection.
17159
+ * @param signal - cancellation checked around the adapter lookup.
17160
+ * @throws {@link DevLeadError} `DEVLEAD_MODEL_UNAVAILABLE` when the Host
17161
+ * composes no validator or the adapter rejects the route/effort.
17162
+ */
17163
+ async assertModelSelectable(selection, signal) {
17164
+ const validator = modelValidatorOf(this.ctx);
17165
+ if (validator === void 0) {
17166
+ throw new DevLeadError(
17167
+ `cannot validate model "${modelSelectionLabel(selection)}": this Host composes no LLM registry. Call devlead_list_models to see available providers, models, and reasoning efforts`,
17168
+ "DEVLEAD_MODEL_UNAVAILABLE"
17169
+ );
17170
+ }
17171
+ try {
17172
+ if (!validator.listProviders().some((provider) => provider.id === selection.provider)) {
17173
+ throw new Error(`provider "${selection.provider}" is not registered`);
17174
+ }
17175
+ const models = await validator.listModels(selection.provider);
17176
+ if (!models.some((model) => model.id === selection.model)) {
17177
+ throw new Error(`model "${selection.model}" is not in provider "${selection.provider}"'s available model list`);
17178
+ }
17179
+ await validator.resolveCallConfig(selection, signal);
17180
+ } catch (error51) {
17181
+ signal?.throwIfAborted();
17182
+ throw new DevLeadError(
17183
+ `model "${modelSelectionLabel(selection)}" is not available: ${thrownMessage(error51)}. Call devlead_list_models to see available providers, models, and reasoning efforts`,
17184
+ "DEVLEAD_MODEL_UNAVAILABLE"
17185
+ );
17186
+ }
17187
+ signal?.throwIfAborted();
17188
+ }
17189
+ /**
17190
+ * Apply creation-time dispatch settings to a freshly created Session.
17191
+ *
17192
+ * The settings are recorded on the child Agent itself: the model through
17193
+ * `agent.model.select` (durable Session-level event, never the profile
17194
+ * default), and Team mode through the optional Team service. A failure here
17195
+ * happens after the Session exists, so the error names its id and the Session
17196
+ * is deliberately left in place (the service's creation contract does not
17197
+ * roll back side effects).
17198
+ * @param created - the controller's create result.
17199
+ * @param model - normalized model selection, when requested.
17200
+ * @param teamsRequested - requested Team mode, when explicitly set.
17201
+ * @param teams - detected Team capability, when one is composed.
17202
+ * @param signal - cancellation checked between applications.
17203
+ * @returns the settings that were actually applied.
17204
+ * @throws {@link DevLeadError} with the created Session id in the message when
17205
+ * the Agent is not live or an application step fails.
17206
+ */
17207
+ async applyDispatchSettings(created, model, teamsRequested, teams, signal) {
17208
+ if (model === void 0 && teamsRequested === void 0) return {};
17209
+ const sessionId = String(created.sessionId);
17210
+ const child = this.ctx.agents.get(created.sessionId);
17211
+ if (child === void 0) {
17212
+ throw new DevLeadError(
17213
+ `Session "${sessionId}" was created but its Agent is not live, so the requested dispatch settings could not be applied; the Session remains and can be continued`,
17214
+ "DEVLEAD_SESSION_UNAVAILABLE"
17215
+ );
17216
+ }
17217
+ const applied = {};
17218
+ if (model !== void 0) {
17219
+ try {
17220
+ child.model.select({
17221
+ provider: model.provider,
17222
+ model: model.model,
17223
+ ...model.reasoningEffort === void 0 ? {} : { reasoningEffort: ReasoningEffortId(model.reasoningEffort) }
17224
+ });
17225
+ } catch (error51) {
17226
+ signal?.throwIfAborted();
17227
+ throw new DevLeadError(
17228
+ `Session "${sessionId}" was created but model "${modelSelectionLabel(model)}" could not be applied; the Session remains: ${thrownMessage(error51)}. Call devlead_list_models to see available providers, models, and reasoning efforts`,
17229
+ "DEVLEAD_MODEL_UNAVAILABLE"
17230
+ );
17231
+ }
17232
+ await this.flushDurably(child.session, `model selection for Session "${sessionId}"`);
17233
+ applied.model = { ...model };
17234
+ }
17235
+ if (teamsRequested !== void 0) {
17236
+ if (teamsRequested === true && teams === void 0) {
17237
+ throw new DevLeadError(
17238
+ `Session "${sessionId}" was created but this Host composes no Agent Teams service, so agent_teams could not be enabled; the Session remains. Agent Teams is available from DSH 0.2.2-rc.2 (included in the default composition there)`,
17239
+ "DEVLEAD_TEAM_UNAVAILABLE"
17240
+ );
17241
+ }
17242
+ if (teams !== void 0) {
17243
+ try {
17244
+ await teams.setEnabled(child, teamsRequested, signal);
17245
+ } catch (error51) {
17246
+ signal?.throwIfAborted();
17247
+ throw new DevLeadError(
17248
+ `Session "${sessionId}" was created but Agent Teams could not be ${teamsRequested ? "enabled" : "disabled"}; the Session remains: ${thrownMessage(error51)}`,
17249
+ "DEVLEAD_TEAM_UNAVAILABLE"
17250
+ );
17251
+ }
17252
+ }
17253
+ applied.agentTeams = teamsRequested;
17254
+ }
17255
+ signal?.throwIfAborted();
17256
+ return applied;
17257
+ }
17258
+ /** Require the Workspace registry capability (Workspaces and Session archive state). */
16815
17259
  requireWorkspaceRegistry() {
16816
17260
  const registry2 = this.ctx.get("workspaceRegistry");
16817
17261
  if (registry2 === void 0) {
16818
17262
  throw new DevLeadError(
16819
- "this Host composes no Workspace registry, so Workspaces cannot be managed",
17263
+ "this Host composes no Workspace registry, so Workspaces and archived Sessions cannot be managed",
16820
17264
  "DEVLEAD_WORKSPACE_NOT_FOUND"
16821
17265
  );
16822
17266
  }
@@ -16962,6 +17406,29 @@ var DevLeadService = class extends Service {
16962
17406
  if (code === "session/not-found") return new DevLeadError(message, "DEVLEAD_SESSION_NOT_FOUND");
16963
17407
  return new DevLeadError(message, "DEVLEAD_SESSION_UNAVAILABLE");
16964
17408
  }
17409
+ /**
17410
+ * Map one Workspace-registry archive failure to the stable DevLead
17411
+ * vocabulary.
17412
+ * @param sessionId - Session identity the archive addressed.
17413
+ * @param error - failure thrown by `workspaceRegistry.archiveSession`.
17414
+ * @returns the mapped domain failure, or undefined for an infrastructure
17415
+ * failure the caller rethrows unchanged.
17416
+ */
17417
+ archiveFailure(sessionId, error51) {
17418
+ if (isActiveSessionFailure(error51)) {
17419
+ return new DevLeadError(
17420
+ `Session "${sessionId}" is still active (${describeSessionActivity(error51.activity)}); stop that work first, or retry with stop_running: true to archive it and ask the Host to stop it now`,
17421
+ "DEVLEAD_SESSION_ACTIVE"
17422
+ );
17423
+ }
17424
+ if (isUnknownSessionFailure(error51)) {
17425
+ return new DevLeadError(
17426
+ `no Session matches "${sessionId}"; it may have disappeared since it was resolved`,
17427
+ "DEVLEAD_SESSION_NOT_FOUND"
17428
+ );
17429
+ }
17430
+ return void 0;
17431
+ }
16965
17432
  /**
16966
17433
  * Admit one lead-authored prompt into a Session, resuming a cold Session.
16967
17434
  * @param leadAgent - exact live lead Agent.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yankeguo/dsh-devlead",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "DevLead mode core service for the DeepSeek Harness: durable per-session mode, Workspace and Session orchestration, watched-session notifications, and the `devLead` Session projection.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -43,7 +43,7 @@
43
43
  }
44
44
  },
45
45
  "dependencies": {
46
- "@yankeguo/dsh-devlead-protocol": "0.2.1"
46
+ "@yankeguo/dsh-devlead-protocol": "0.2.3"
47
47
  },
48
48
  "engines": {
49
49
  "dsh": ">=0.2.2-rc.1 <0.3.0"