@yankeguo/dsh-devlead 0.2.2 → 0.2.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.
Files changed (3) hide show
  1. package/README.md +6 -4
  2. package/lib/index.js +594 -41
  3. package/package.json +11 -11
package/README.md CHANGED
@@ -17,9 +17,10 @@ dsh plugin --profile desktop add @yankeguo/dsh-devlead-bundle
17
17
  - Peer services `agents`, `sessions`, `sessionProjections` (provided by the default `dsh-base`
18
18
  composition).
19
19
  - Optional, probed at call time: `workspaceRegistry`, `sessionController`, `sessionTitle`,
20
- `sessionQuery`, `sessionProjectionCache` (cold-lead rehydration pre-filter), `sessionPersistence`
21
- (durable-corpus readiness barrier), and the experimental `worktrees` capability. Missing optional services degrade to fewer features or structured domain
22
- errors; no experimental package is imported, injected, or declared.
20
+ `agentPresets` (read-only preset roster discovery), `sessionQuery`, `sessionProjectionCache`
21
+ (cold-lead rehydration pre-filter), `sessionPersistence` (durable-corpus readiness barrier), and
22
+ the experimental `worktrees` capability. Missing optional services degrade to fewer features or
23
+ structured domain errors; no experimental package is imported, injected, or declared.
23
24
  - Cold-lead rehydration: at plugin load the hub rebuilds its watch index from durable state
24
25
  (`sessionQuery` listing → projection-cache pre-filter → exact fold; unclassified rows are capped
25
26
  at 64 full-log reads). Without a projection cache only live lead Sessions are recovered. A
@@ -29,7 +30,8 @@ dsh plugin --profile desktop add @yankeguo/dsh-devlead-bundle
29
30
  ## Configuration
30
31
 
31
32
  The Loader row id `devlead` accepts `notificationBatchMs`, `maxWatchedSessions`,
32
- `maxListedSessions`, `wakeColdSession` (default `true` since 0.2.0), and `defaultAgentPreset`. See the
33
+ `maxListedSessions`, `wakeColdSession` (default `true` since 0.2.0), and `defaultAgentPreset`
34
+ (used when a created Session names no preset; an invalid id fails creation). See the
33
35
  [configuration section](https://github.com/yankeguo/dsh-devlead/blob/main/README.md#configuration) for defaults and ranges; all limits are
34
36
  validated at both the Loader and direct-construction boundaries.
35
37
 
package/lib/index.js CHANGED
@@ -9,8 +9,9 @@ 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
- import "@deepseek-ai/dsh-session";
14
+ import { SessionId as toSessionId3 } from "@deepseek-ai/dsh-session";
14
15
  import { DEVLEAD_DEFAULT_MAX_WATCHED as DEVLEAD_DEFAULT_MAX_WATCHED2 } from "@yankeguo/dsh-devlead-protocol";
15
16
 
16
17
  // packages/devlead/src/domain.ts
@@ -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
 
@@ -14998,6 +15131,7 @@ import {
14998
15131
  } from "@yankeguo/dsh-devlead-protocol";
14999
15132
  var MAX_DIGEST_LINES = 12;
15000
15133
  var DELIVERY_RETRY_MS = 1e3;
15134
+ var MAX_COLD_RESUME_ATTEMPTS = 5;
15001
15135
  var DEVLEAD_MAX_WARNED_FAILURES = 256;
15002
15136
  function renderDevLeadNotice(notifications, total = notifications.length) {
15003
15137
  const shown = notifications.slice(-MAX_DIGEST_LINES);
@@ -15150,8 +15284,12 @@ var DevLeadNotificationHub = class {
15150
15284
  return;
15151
15285
  }
15152
15286
  const runtime = this.ensureLead(sessionId);
15287
+ runtime.resumeAttempts = 0;
15153
15288
  this.setWatched(runtime, state.sessions);
15154
- if (runtime.pending.length > 0 || runtime.unsaved.length > 0) this.scheduleFlush(runtime);
15289
+ if (runtime.pending.length > 0 || runtime.unsaved.length > 0) {
15290
+ this.clearTimer(runtime);
15291
+ this.scheduleFlush(runtime);
15292
+ }
15155
15293
  }
15156
15294
  /**
15157
15295
  * Create the runtime row for one lead Session.
@@ -15168,7 +15306,8 @@ var DevLeadNotificationHub = class {
15168
15306
  unsaved: [],
15169
15307
  timer: void 0,
15170
15308
  scheduled: false,
15171
- flushing: false
15309
+ flushing: false,
15310
+ resumeAttempts: 0
15172
15311
  };
15173
15312
  this.leads.set(sessionId, runtime);
15174
15313
  return runtime;
@@ -15328,10 +15467,10 @@ var DevLeadNotificationHub = class {
15328
15467
  const runtime = this.leads.get(leadId);
15329
15468
  if (runtime === void 0) return;
15330
15469
  const session = this.ctx.sessions.get(toSessionId(leadId));
15331
- if (session !== void 0) this.appendNotificationRecord(session, notification, leadId);
15470
+ const persisted = session !== void 0 && this.appendNotificationRecord(session, notification, leadId);
15332
15471
  if (runtime.pending.some((existing) => existing.id === notification.id)) return;
15333
15472
  if (runtime.unsaved.some((existing) => existing.id === notification.id)) return;
15334
- if (session === void 0) {
15473
+ if (!persisted) {
15335
15474
  runtime.unsaved = [...runtime.unsaved, notification].slice(-DEVLEAD_DEFAULT_NOTIFICATION_RETENTION3);
15336
15475
  this.scheduleFlush(runtime);
15337
15476
  return;
@@ -15347,15 +15486,17 @@ var DevLeadNotificationHub = class {
15347
15486
  * @param session - lead Session receiving the record.
15348
15487
  * @param notification - notification to persist.
15349
15488
  * @param leadId - lead Session identity used in warnings.
15489
+ * @returns whether the durable append succeeded.
15350
15490
  */
15351
15491
  appendNotificationRecord(session, notification, leadId) {
15352
15492
  try {
15353
15493
  appendPluginRecord(session, DEVLEAD_NOTIFICATION_RECORD_TYPE3, notificationRecord(notification));
15354
15494
  } catch (error51) {
15355
15495
  this.ctx.logger.warn(`devlead: could not record a notification for lead "${leadId}": ${thrownMessage(error51)}`);
15356
- return;
15496
+ return false;
15357
15497
  }
15358
15498
  void this.checkpoint(session, leadId);
15499
+ return true;
15359
15500
  }
15360
15501
  /**
15361
15502
  * Fire-and-forget one Session durability checkpoint.
@@ -15449,7 +15590,6 @@ var DevLeadNotificationHub = class {
15449
15590
  if (session !== void 0) {
15450
15591
  this.persistUnsaved(session, runtime);
15451
15592
  runtime.pending = [];
15452
- runtime.unsaved = [];
15453
15593
  }
15454
15594
  this.clearTimer(runtime);
15455
15595
  return;
@@ -15504,6 +15644,26 @@ var DevLeadNotificationHub = class {
15504
15644
  void this.flush(runtime);
15505
15645
  }, DELIVERY_RETRY_MS);
15506
15646
  }
15647
+ /**
15648
+ * Schedule a bounded retry after a failed cold-lead resume.
15649
+ *
15650
+ * A cold lead's unsaved notifications are memory-only, so a transient
15651
+ * resolve failure (a held writer, a warming controller) must not strand the
15652
+ * batch until the next watched `turn/end`. The attempt counter is reset when
15653
+ * the Agent becomes live; after the cap, one warning reports the give-up and
15654
+ * the next live index or watched event retries naturally.
15655
+ * @param runtime - lead runtime row.
15656
+ */
15657
+ retryColdResume(runtime) {
15658
+ runtime.resumeAttempts += 1;
15659
+ if (runtime.resumeAttempts >= MAX_COLD_RESUME_ATTEMPTS) {
15660
+ this.ctx.logger.warn(
15661
+ `devlead: giving up resuming cold lead "${runtime.sessionId}" after ${runtime.resumeAttempts} attempts; open the Session or wait for its next watched event`
15662
+ );
15663
+ return;
15664
+ }
15665
+ this.scheduleRetry(runtime);
15666
+ }
15507
15667
  /**
15508
15668
  * Whether one lead Agent already holds an undelivered digest notice.
15509
15669
  * @param agent - live lead Agent.
@@ -15532,12 +15692,14 @@ var DevLeadNotificationHub = class {
15532
15692
  if (this.stopping) return;
15533
15693
  if ("error" in resolved) {
15534
15694
  this.ctx.logger.warn(`devlead: could not resume lead "${leadId}": ${resolved.error.message}`);
15695
+ this.retryColdResume(runtime);
15535
15696
  return;
15536
15697
  }
15537
15698
  this.syncLead(resolved.agent);
15538
15699
  } catch (error51) {
15539
15700
  if (!this.stopping) {
15540
15701
  this.ctx.logger.warn(`devlead: could not resume lead "${leadId}": ${thrownMessage(error51)}`);
15702
+ this.retryColdResume(runtime);
15541
15703
  }
15542
15704
  } finally {
15543
15705
  this.resuming.delete(leadId);
@@ -15546,14 +15708,17 @@ var DevLeadNotificationHub = class {
15546
15708
  };
15547
15709
 
15548
15710
  // packages/devlead/src/persistence.ts
15549
- async function persistedSessionsOf(ctx) {
15711
+ async function persistedSessionsOf(ctx, signal) {
15550
15712
  const candidate = ctx.get("sessionPersistence");
15551
15713
  if (typeof candidate !== "object" || candidate === null) return { verifiable: false };
15552
15714
  const list = candidate.list;
15553
15715
  if (typeof list !== "function") return { verifiable: false };
15554
15716
  let listed;
15555
15717
  try {
15556
- listed = await Promise.resolve(list.call(candidate));
15718
+ listed = await Promise.resolve(list.call(
15719
+ candidate,
15720
+ signal === void 0 ? void 0 : { signal }
15721
+ ));
15557
15722
  } catch {
15558
15723
  return { verifiable: true };
15559
15724
  }
@@ -15571,6 +15736,42 @@ async function persistedSessionsOf(ctx) {
15571
15736
  return { verifiable: true, ids };
15572
15737
  }
15573
15738
 
15739
+ // packages/devlead/src/presets.ts
15740
+ function recordOf2(value) {
15741
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
15742
+ }
15743
+ function stringField2(value) {
15744
+ return typeof value === "string" ? value : "";
15745
+ }
15746
+ function agentPresetRosterCapabilityOf(ctx) {
15747
+ const candidate = ctx.get("agentPresets");
15748
+ if (typeof candidate !== "object" || candidate === null) return void 0;
15749
+ const defaultId = candidate.defaultId;
15750
+ const list = candidate.list;
15751
+ if (typeof defaultId !== "string" || typeof list !== "function") return void 0;
15752
+ return candidate;
15753
+ }
15754
+ function devLeadAgentPresetsOf(rows, defaultId) {
15755
+ const presets = [];
15756
+ for (const row of rows) {
15757
+ const record2 = recordOf2(row);
15758
+ if (record2 === void 0) continue;
15759
+ const id = stringField2(record2.id).trim();
15760
+ if (id.length === 0) continue;
15761
+ const name = stringField2(record2.name).trim();
15762
+ const description = stringField2(record2.description).trim();
15763
+ const broken = stringField2(record2.broken).trim();
15764
+ presets.push({
15765
+ id,
15766
+ default: id === defaultId,
15767
+ ...name.length === 0 ? {} : { name },
15768
+ ...description.length === 0 ? {} : { description },
15769
+ ...broken.length === 0 ? {} : { broken }
15770
+ });
15771
+ }
15772
+ return presets;
15773
+ }
15774
+
15574
15775
  // packages/devlead/src/projection-cache.ts
15575
15776
  function projectionCacheOf(ctx) {
15576
15777
  const candidate = ctx.get("sessionProjectionCache");
@@ -15578,7 +15779,10 @@ function projectionCacheOf(ctx) {
15578
15779
  const cachedSnapshot = candidate.cachedSnapshot;
15579
15780
  if (typeof cachedSnapshot !== "function") return void 0;
15580
15781
  const service = candidate;
15581
- return { cachedSnapshot: (header) => service.cachedSnapshot(header) };
15782
+ return {
15783
+ cachedSnapshot: (header) => service.cachedSnapshot(header),
15784
+ ...typeof service.write === "function" ? { write: (session) => service.write(session) } : {}
15785
+ };
15582
15786
  }
15583
15787
  function devLeadPrefilterOf(cache, header) {
15584
15788
  let snapshot;
@@ -15652,6 +15856,12 @@ async function collectSessionIds(deps, workspace, exhaustive = false) {
15652
15856
  }
15653
15857
  } catch (error51) {
15654
15858
  rethrowIfAborted(error51, signal);
15859
+ if (exhaustive) {
15860
+ throw new DevLeadError(
15861
+ `could not list persisted Sessions to resolve a full identity: ${thrownMessage(error51)}`,
15862
+ "DEVLEAD_SESSION_UNAVAILABLE"
15863
+ );
15864
+ }
15655
15865
  }
15656
15866
  }
15657
15867
  }
@@ -15691,6 +15901,37 @@ async function knownSessions(deps, ids) {
15691
15901
  }
15692
15902
  return result;
15693
15903
  }
15904
+ async function sessionRankFacts(deps, ids) {
15905
+ const { ctx, signal } = deps;
15906
+ const result = /* @__PURE__ */ new Map();
15907
+ const missingHeader = [];
15908
+ for (const id of ids) {
15909
+ const session = ctx.sessions.get(toSessionId2(id));
15910
+ const agent = ctx.agents.get(toSessionId2(id));
15911
+ const live = session !== void 0 || agent !== void 0;
15912
+ const sessionObject = session ?? agent?.session;
15913
+ const title = sessionObject === void 0 ? void 0 : ctx.get("sessionTitle")?.get(sessionObject)?.title;
15914
+ result.set(id, { title, header: sessionObject?.header, live });
15915
+ if (sessionObject === void 0) missingHeader.push(id);
15916
+ }
15917
+ if (missingHeader.length > 0) {
15918
+ const query = ctx.get("sessionQuery");
15919
+ if (query !== void 0) {
15920
+ try {
15921
+ const records = await query.listSessions(signal);
15922
+ const wanted = new Set(missingHeader);
15923
+ for (const record2 of records) {
15924
+ const id = String(record2.header.id);
15925
+ const entry = wanted.has(id) ? result.get(id) : void 0;
15926
+ if (entry !== void 0) result.set(id, { ...entry, header: record2.header });
15927
+ }
15928
+ } catch (error51) {
15929
+ rethrowIfAborted(error51, signal);
15930
+ }
15931
+ }
15932
+ }
15933
+ return result;
15934
+ }
15694
15935
  async function readSessionFacts(deps, ids) {
15695
15936
  const known = await knownSessions(deps, ids);
15696
15937
  const workspaces = /* @__PURE__ */ new Map();
@@ -15712,12 +15953,12 @@ async function readSessionFacts(deps, ids) {
15712
15953
  }
15713
15954
  return { known, workspaces, archived };
15714
15955
  }
15715
- function rankSessionIds(deps, ids, facts, limit) {
15956
+ function rankSessionIds(deps, ids, known, limit) {
15716
15957
  const ranked = ids.map((id) => ({
15717
15958
  id,
15718
15959
  watched: deps.isWatched(id),
15719
15960
  running: deps.ctx.agents.get(toSessionId2(id))?.status === "running",
15720
- createdAt: facts.known.get(id)?.header?.createdAt ?? 0
15961
+ createdAt: known.get(id)?.header?.createdAt ?? 0
15721
15962
  }));
15722
15963
  ranked.sort((left, right) => {
15723
15964
  if (left.watched !== right.watched) return left.watched ? -1 : 1;
@@ -15778,7 +16019,8 @@ async function buildSessionView(deps, sessionId, withLog, facts) {
15778
16019
  const workspace = facts.workspaces.get(sessionId);
15779
16020
  const boundary = agent === void 0 ? void 0 : ctx.agents.turnBoundaryOf(agent.session);
15780
16021
  const log = withLog ? await sessionLogFacts(deps, sessionId) : {};
15781
- const lastTurn = log.lastTurn ?? boundary?.lastTurn;
16022
+ const boundaryTurn = boundary !== void 0 && boundary.lastTurn > 0 ? boundary.lastTurn : void 0;
16023
+ const lastTurn = log.lastTurn ?? boundaryTurn;
15782
16024
  return {
15783
16025
  sessionId,
15784
16026
  ...known?.title === void 0 ? {} : { title: known.title },
@@ -16004,6 +16246,12 @@ var DevLeadService = class extends Service {
16004
16246
  rehydrated = false;
16005
16247
  /** In-flight rehydration attempt, so concurrent readiness triggers share it. */
16006
16248
  rehydrating;
16249
+ /** Whether the plugin fiber was disposed; late rehydration steps must stop. */
16250
+ disposed = false;
16251
+ /** Resolver of the active readiness sleep, so disposal can wake it. */
16252
+ readinessWake;
16253
+ /** Timer of the active readiness sleep, so disposal can clear it. */
16254
+ readinessTimer;
16007
16255
  /**
16008
16256
  * Disposers of the armed readiness retry: the optional-service injection fiber
16009
16257
  * and, while the query engine itself is missing, the lifecycle listeners.
@@ -16027,7 +16275,11 @@ var DevLeadService = class extends Service {
16027
16275
  );
16028
16276
  this.hub.start();
16029
16277
  this.ctx.effect(function* () {
16030
- yield () => this.disposeRehydrationRetry();
16278
+ yield () => {
16279
+ this.disposed = true;
16280
+ this.wakeReadiness();
16281
+ this.disposeRehydrationRetry();
16282
+ };
16031
16283
  }.bind(this), "devlead: cold rehydration");
16032
16284
  await this.rehydrateFromPersistence();
16033
16285
  }
@@ -16071,7 +16323,7 @@ var DevLeadService = class extends Service {
16071
16323
  * steady Host pays one macrotask plus one comparison.
16072
16324
  */
16073
16325
  async runRehydration() {
16074
- if (this.rehydrated) return;
16326
+ if (this.rehydrated || this.disposed) return;
16075
16327
  const queryReady = this.ctx.get("sessionQuery") !== void 0;
16076
16328
  try {
16077
16329
  this.hub.rehydrate(this.liveAttachLeads());
@@ -16096,12 +16348,14 @@ var DevLeadService = class extends Service {
16096
16348
  return;
16097
16349
  }
16098
16350
  await this.awaitCorpusReady();
16099
- if (this.rehydrated) return;
16351
+ if (this.rehydrated || this.disposed) return;
16100
16352
  try {
16101
- this.hub.rehydrate(await this.persistedLeadRecords(true));
16353
+ const records = await this.persistedLeadRecords(true);
16354
+ this.hub.rehydrate(records.filter((record2) => this.ctx.agents.get(toSessionId3(record2.sessionId)) === void 0));
16102
16355
  } catch (error51) {
16103
16356
  this.ctx.logger.warn(`devlead: cold lead rehydration failed: ${thrownMessage(error51)}`);
16104
16357
  }
16358
+ if (this.disposed) return;
16105
16359
  this.finalizeRehydration();
16106
16360
  }
16107
16361
  /**
@@ -16116,29 +16370,34 @@ var DevLeadService = class extends Service {
16116
16370
  */
16117
16371
  async awaitCorpusReady() {
16118
16372
  const deadline = Date.now() + REHYDRATION_READINESS_TIMEOUT_MS;
16119
- let probe = await persistedSessionsOf(this.ctx);
16120
- while (probe.verifiable && probe.ids === void 0 && Date.now() < deadline) {
16121
- await new Promise((resolve) => {
16122
- setTimeout(resolve, REHYDRATION_READINESS_POLL_MS);
16123
- });
16124
- probe = await persistedSessionsOf(this.ctx);
16373
+ let probe = await this.probeCorpus(deadline);
16374
+ while (!this.disposed && probe?.verifiable === true && probe.ids === void 0 && Date.now() < deadline) {
16375
+ await this.readinessSleep(REHYDRATION_READINESS_POLL_MS);
16376
+ probe = await this.probeCorpus(deadline);
16377
+ }
16378
+ if (this.disposed) return;
16379
+ const ids = probe?.ids;
16380
+ if (ids === void 0) {
16381
+ if (probe?.verifiable === true) {
16382
+ this.ctx.logger.warn(
16383
+ `devlead: the Session persistence listing did not settle within ${REHYDRATION_READINESS_TIMEOUT_MS}ms; cold lead rehydration proceeds best-effort`
16384
+ );
16385
+ }
16386
+ return;
16125
16387
  }
16126
- const ids = probe.ids;
16127
- if (ids === void 0) return;
16128
16388
  if (ids.size === 0) return;
16129
16389
  let consistent = false;
16130
- while (Date.now() < deadline) {
16131
- const listed = await this.listedPersistedSessionIds();
16390
+ while (!this.disposed && Date.now() < deadline) {
16391
+ const listed = await this.listedPersistedSessionIds(deadline);
16132
16392
  if (this.containsAllSessionIds(listed, ids)) {
16133
16393
  consistent = true;
16134
16394
  break;
16135
16395
  }
16136
- await new Promise((resolve) => {
16137
- setTimeout(resolve, REHYDRATION_READINESS_POLL_MS);
16138
- });
16396
+ await this.readinessSleep(REHYDRATION_READINESS_POLL_MS);
16139
16397
  }
16398
+ if (this.disposed) return;
16140
16399
  if (!consistent) {
16141
- consistent = this.containsAllSessionIds(await this.listedPersistedSessionIds(), ids);
16400
+ consistent = this.containsAllSessionIds(await this.listedPersistedSessionIds(deadline), ids);
16142
16401
  }
16143
16402
  if (!consistent) {
16144
16403
  this.ctx.logger.warn(
@@ -16146,6 +16405,51 @@ var DevLeadService = class extends Service {
16146
16405
  );
16147
16406
  }
16148
16407
  }
16408
+ /**
16409
+ * Read the persistence ground truth under the readiness deadline. The real
16410
+ * backend honors the signal; the race is a belt-and-braces bound for a
16411
+ * backend that ignores it, so plugin load can never hang on the probe.
16412
+ * @param deadline - absolute readiness deadline.
16413
+ * @returns the probe result, or undefined when the deadline is already spent
16414
+ * or the listing did not settle in time.
16415
+ */
16416
+ async probeCorpus(deadline) {
16417
+ if (this.disposed) return void 0;
16418
+ const remaining = deadline - Date.now();
16419
+ if (remaining <= 0) return void 0;
16420
+ const controller = new AbortController();
16421
+ const timer = setTimeout(() => controller.abort(), remaining);
16422
+ try {
16423
+ const aborted2 = new Promise((resolve) => {
16424
+ controller.signal.addEventListener("abort", () => resolve(void 0), { once: true });
16425
+ });
16426
+ return await Promise.race([persistedSessionsOf(this.ctx, controller.signal), aborted2]);
16427
+ } finally {
16428
+ clearTimeout(timer);
16429
+ }
16430
+ }
16431
+ /** Resolve a short readiness sleep early when the plugin is disposed. */
16432
+ async readinessSleep(milliseconds) {
16433
+ if (this.disposed) return;
16434
+ await new Promise((resolve) => {
16435
+ this.readinessWake = resolve;
16436
+ this.readinessTimer = setTimeout(() => {
16437
+ this.readinessTimer = void 0;
16438
+ this.readinessWake = void 0;
16439
+ resolve();
16440
+ }, milliseconds);
16441
+ });
16442
+ }
16443
+ /** Wake the active readiness sleep (if any) after disposal. */
16444
+ wakeReadiness() {
16445
+ if (this.readinessTimer !== void 0) {
16446
+ clearTimeout(this.readinessTimer);
16447
+ this.readinessTimer = void 0;
16448
+ }
16449
+ const wake = this.readinessWake;
16450
+ this.readinessWake = void 0;
16451
+ wake?.();
16452
+ }
16149
16453
  /**
16150
16454
  * Whether one corpus listing contains every expected Session id.
16151
16455
  * @param listed - ids visible in the query corpus.
@@ -16164,19 +16468,30 @@ var DevLeadService = class extends Service {
16164
16468
  * Before its optional persistence binding is installed the query engine merges
16165
16469
  * only live Sessions, so this is the number the readiness barrier compares
16166
16470
  * against the persistence service's complete stored listing.
16471
+ * @param deadline - absolute readiness deadline for the listing read.
16167
16472
  * @returns the visible persisted Session ids.
16168
16473
  */
16169
- async listedPersistedSessionIds() {
16474
+ async listedPersistedSessionIds(deadline) {
16170
16475
  const query = this.ctx.get("sessionQuery");
16171
16476
  if (query === void 0) return /* @__PURE__ */ new Set();
16477
+ const remaining = deadline - Date.now();
16478
+ if (remaining <= 0) return /* @__PURE__ */ new Set();
16479
+ const controller = new AbortController();
16480
+ const timer = setTimeout(() => controller.abort(), remaining);
16172
16481
  try {
16173
- const records = await query.listSessions();
16482
+ const aborted2 = new Promise((resolve) => {
16483
+ controller.signal.addEventListener("abort", () => resolve(void 0), { once: true });
16484
+ });
16485
+ const records = await Promise.race([query.listSessions(controller.signal), aborted2]);
16486
+ if (records === void 0) return /* @__PURE__ */ new Set();
16174
16487
  return new Set(
16175
16488
  records.filter((record2) => record2.persisted).map((record2) => String(record2.header.id))
16176
16489
  );
16177
16490
  } catch (error51) {
16178
16491
  this.ctx.logger.debug(`devlead: corpus readiness listing failed: ${thrownMessage(error51)}`);
16179
16492
  return /* @__PURE__ */ new Set();
16493
+ } finally {
16494
+ clearTimeout(timer);
16180
16495
  }
16181
16496
  }
16182
16497
  /**
@@ -16274,7 +16589,7 @@ var DevLeadService = class extends Service {
16274
16589
  }
16275
16590
  /**
16276
16591
  * Save one Session's DevLead selection. Human-entry points own this call: the
16277
- * `/devlead` command and the browser switch, never a model tool.
16592
+ * `/devlead` command and the composer-toolbar toggle, never a model tool.
16278
16593
  * @param agent - exact live Session Agent receiving the selection.
16279
16594
  * @param enabled - selected mode.
16280
16595
  * @param signal - cancellation checked before the write.
@@ -16295,11 +16610,13 @@ var DevLeadService = class extends Service {
16295
16610
  }
16296
16611
  this.appendResetRecord(agent.session);
16297
16612
  await this.flushDurably(agent.session, `DevLead reset for Session "${agent.id}"`);
16613
+ await this.checkpointProjectionCache(agent.session, `DevLead reset for Session "${agent.id}"`);
16298
16614
  return;
16299
16615
  }
16300
16616
  if (current.enabled === enabled) return;
16301
16617
  appendPluginRecord2(agent.session, DEVLEAD_MODE_RECORD_TYPE, modeRecord(enabled, Date.now()));
16302
16618
  await this.flushDurably(agent.session, `DevLead mode for Session "${agent.id}"`);
16619
+ await this.checkpointProjectionCache(agent.session, `DevLead mode for Session "${agent.id}"`);
16303
16620
  }
16304
16621
  /**
16305
16622
  * Discard one Session's durable DevLead state so a damaged fold can recover.
@@ -16319,6 +16636,7 @@ var DevLeadService = class extends Service {
16319
16636
  signal?.throwIfAborted();
16320
16637
  this.appendResetRecord(agent.session);
16321
16638
  await this.flushDurably(agent.session, `DevLead reset for Session "${agent.id}"`);
16639
+ await this.checkpointProjectionCache(agent.session, `DevLead reset for Session "${agent.id}"`);
16322
16640
  }
16323
16641
  /**
16324
16642
  * Append one reset marker to a Session log.
@@ -16336,6 +16654,7 @@ var DevLeadService = class extends Service {
16336
16654
  * @returns detached Workspace views in registry order.
16337
16655
  */
16338
16656
  async listWorkspaces(signal) {
16657
+ signal?.throwIfAborted();
16339
16658
  const registry2 = this.ctx.get("workspaceRegistry");
16340
16659
  if (registry2 === void 0) return [];
16341
16660
  const views = [];
@@ -16473,11 +16792,95 @@ var DevLeadService = class extends Service {
16473
16792
  const listingCap = options.watchedOnly === true ? Math.max(this.resolved.maxListedSessions, deps.watchedSessions.length) : this.resolved.maxListedSessions;
16474
16793
  const requestedLimit = listLimit(options.limit, listingCap);
16475
16794
  const limit = options.watchedOnly === true ? Math.max(requestedLimit, deps.watchedSessions.length) : requestedLimit;
16476
- const facts = await readSessionFacts(deps, ids);
16795
+ const ranking = await sessionRankFacts(deps, ids);
16477
16796
  signal?.throwIfAborted();
16478
- const retained = rankSessionIds(deps, ids, facts, limit);
16797
+ const retained = rankSessionIds(deps, ids, ranking, limit);
16798
+ const facts = await readSessionFacts(deps, retained);
16479
16799
  return await devLeadSessionViews(deps, retained, false, facts);
16480
16800
  }
16801
+ /**
16802
+ * Read the Host's model catalog for dispatch-time selection.
16803
+ *
16804
+ * The view reports the Host default selection, routable providers, each
16805
+ * provider's advertised models and reasoning efforts, and catalog lookup
16806
+ * failures. It is read-only: no Session, profile default, or Team state is
16807
+ * changed. The controller's catalog method takes no cancellation token, so
16808
+ * the signal is checked before and after the read.
16809
+ * @param agent - exact live lead Agent.
16810
+ * @param signal - cancellation checked before and after the catalog read.
16811
+ * @returns the normalized model catalog view.
16812
+ * @throws {@link DevLeadError} `DEVLEAD_SESSION_UNAVAILABLE` when the Host
16813
+ * composes no Session controller with a model catalog or the read fails.
16814
+ */
16815
+ async listModels(agent, signal) {
16816
+ this.assertReady(agent);
16817
+ signal?.throwIfAborted();
16818
+ const controller = modelCatalogCapabilityOf(this.ctx);
16819
+ if (controller === void 0) {
16820
+ throw new DevLeadError(
16821
+ "this Host cannot list models: no API Session controller with a model catalog is composed",
16822
+ "DEVLEAD_SESSION_UNAVAILABLE"
16823
+ );
16824
+ }
16825
+ let catalog;
16826
+ try {
16827
+ catalog = await controller.modelCatalog();
16828
+ } catch (error51) {
16829
+ signal?.throwIfAborted();
16830
+ throw new DevLeadError(
16831
+ `could not read the model catalog: ${thrownMessage(error51)}`,
16832
+ "DEVLEAD_SESSION_UNAVAILABLE"
16833
+ );
16834
+ }
16835
+ signal?.throwIfAborted();
16836
+ return devLeadModelCatalogOf(catalog);
16837
+ }
16838
+ /**
16839
+ * Read the Host's Agent preset roster for creation-time preset selection.
16840
+ *
16841
+ * The roster is optional: a Host that composes no Agent preset service
16842
+ * returns `available: false` with a reason instead of an empty list that
16843
+ * could be mistaken for "no presets defined". When the service is present,
16844
+ * rows are normalized onto the stable protocol view; a row without a usable
16845
+ * id is dropped, and the Host's effective default gets the `default` marker.
16846
+ * This is a read-only capability: no Session, profile default, or preset is
16847
+ * changed.
16848
+ * @param agent - exact live lead Agent.
16849
+ * @param signal - cancellation checked before and after the roster read.
16850
+ * @returns the roster view, or an explicit unavailable result.
16851
+ * @throws {@link DevLeadError} `DEVLEAD_SESSION_UNAVAILABLE` when a composed
16852
+ * roster fails a read.
16853
+ */
16854
+ async listAgentPresets(agent, signal) {
16855
+ this.assertReady(agent);
16856
+ signal?.throwIfAborted();
16857
+ const roster = agentPresetRosterCapabilityOf(this.ctx);
16858
+ if (roster === void 0) {
16859
+ return {
16860
+ available: false,
16861
+ presets: [],
16862
+ reason: "this Host composes no Agent preset roster; omit preset to use the Host default"
16863
+ };
16864
+ }
16865
+ let rows;
16866
+ try {
16867
+ rows = await roster.list();
16868
+ if (!Array.isArray(rows)) {
16869
+ throw new Error("the roster service returned no array");
16870
+ }
16871
+ } catch (error51) {
16872
+ signal?.throwIfAborted();
16873
+ throw new DevLeadError(
16874
+ `could not read the Agent preset roster: ${thrownMessage(error51)}`,
16875
+ "DEVLEAD_SESSION_UNAVAILABLE"
16876
+ );
16877
+ }
16878
+ signal?.throwIfAborted();
16879
+ return {
16880
+ available: true,
16881
+ presets: devLeadAgentPresetsOf(rows, roster.defaultId)
16882
+ };
16883
+ }
16481
16884
  /**
16482
16885
  * Read one Session in detail, including folded turn and assistant facts.
16483
16886
  * @param agent - exact live lead Agent.
@@ -16510,19 +16913,32 @@ var DevLeadService = class extends Service {
16510
16913
  * next side effect, so a cancelled create may leave a watched Session behind
16511
16914
  * without running isolation or admitting the prompt. Session creation itself
16512
16915
  * is not abortable once started.
16916
+ *
16917
+ * A requested model selection and Agent Teams mode are creation-time
16918
+ * settings, applied to the new Session's own Agent immediately after the
16919
+ * Session exists and before its title/watch/isolation/prompt. The model is
16920
+ * validated against the Host's LLM registry first, and it is recorded with
16921
+ * `agent.model.select`, never through the Session controller's `selectModel`
16922
+ * (which would also rewrite the profile default model). An application
16923
+ * failure after creation reports the created Session id and leaves that
16924
+ * Session in place, matching the service's non-rollback creation contract.
16513
16925
  * @param agent - exact live lead Agent.
16514
16926
  * @param request - Workspace, optional title, initial prompt, watch policy,
16515
- * preset, and checkout isolation mode.
16927
+ * preset, checkout isolation mode, creation-time model selection, and
16928
+ * creation-time Agent Teams mode.
16516
16929
  * @param signal - cancellation checked between stages and threaded into the
16517
16930
  * worktree creation.
16518
- * @returns the created Session, the Workspace it joined, and the
16519
- * checkout-isolation outcome.
16931
+ * @returns the created Session, the Workspace it joined, the
16932
+ * checkout-isolation outcome, and any applied model/Team settings.
16520
16933
  * @throws {@link DevLeadError} when the mode is off, the Host cannot create
16521
- * Sessions, or the destination is not usable.
16934
+ * Sessions, the destination is not usable, or a requested model/Team
16935
+ * capability is unavailable.
16522
16936
  */
16523
16937
  async createSession(agent, request, signal) {
16524
16938
  this.assertReady(agent);
16525
16939
  signal?.throwIfAborted();
16940
+ const requestedModel = normalizeModelSelection(request.model);
16941
+ const requestedTeams = request.agentTeams;
16526
16942
  const controller = this.ctx.get("sessionController");
16527
16943
  if (controller === void 0) {
16528
16944
  throw new DevLeadError(
@@ -16530,6 +16946,14 @@ var DevLeadService = class extends Service {
16530
16946
  "DEVLEAD_SESSION_UNAVAILABLE"
16531
16947
  );
16532
16948
  }
16949
+ const teams = requestedTeams === void 0 ? void 0 : agentTeamsCapabilityOf(this.ctx);
16950
+ if (requestedTeams === true && teams === void 0) {
16951
+ throw new DevLeadError(
16952
+ "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",
16953
+ "DEVLEAD_TEAM_UNAVAILABLE"
16954
+ );
16955
+ }
16956
+ if (requestedModel !== void 0) await this.assertModelSelectable(requestedModel, signal);
16533
16957
  const watch = request.watch ?? true;
16534
16958
  const releaseWatch = watch ? this.reserveWatchSlot(agent) : void 0;
16535
16959
  try {
@@ -16554,6 +16978,7 @@ var DevLeadService = class extends Service {
16554
16978
  }
16555
16979
  signal?.throwIfAborted();
16556
16980
  const sessionId = String(created.sessionId);
16981
+ const applied = await this.applyDispatchSettings(created, requestedModel, requestedTeams, teams, signal);
16557
16982
  if (request.title !== void 0 && request.title.trim().length > 0) {
16558
16983
  this.tryRename(created.sessionId, request.title.trim());
16559
16984
  }
@@ -16574,7 +16999,9 @@ var DevLeadService = class extends Service {
16574
16999
  session: await devLeadSessionView(deps, sessionId, true),
16575
17000
  workspace: await devLeadWorkspaceView(workspace),
16576
17001
  prompted,
16577
- isolation
17002
+ isolation,
17003
+ ...applied.model === void 0 ? {} : { model: applied.model },
17004
+ ...applied.agentTeams === void 0 ? {} : { agentTeams: applied.agentTeams }
16578
17005
  };
16579
17006
  } finally {
16580
17007
  releaseWatch?.();
@@ -16826,6 +17253,29 @@ var DevLeadService = class extends Service {
16826
17253
  this.ctx.logger.warn(`devlead: ${what} could not be flushed to persistence: ${thrownMessage(error51)}`);
16827
17254
  }
16828
17255
  }
17256
+ /**
17257
+ * Eagerly checkpoint the optional Session projection cache after a durable
17258
+ * DevLead mode/watch/reset write.
17259
+ *
17260
+ * Cold rehydration trusts a cached "disabled/empty watch" row as a negative
17261
+ * pre-filter, and the cache's normal write-behind can lag the log by its
17262
+ * throttled interval. Without this eager write a crash in that window leaves
17263
+ * a stale negative row that hides a real cold lead until a human opens it.
17264
+ * The write is best-effort: a cache that is absent or fails only leaves the
17265
+ * throttled checkpoint in place, and the scan's exact fold still recovers the
17266
+ * lead whenever the row is positive or unclassified.
17267
+ * @param session - Session whose durable DevLead state just changed.
17268
+ * @param what - operation label for the failure warning.
17269
+ */
17270
+ async checkpointProjectionCache(session, what) {
17271
+ const cache = projectionCacheOf(this.ctx);
17272
+ if (cache?.write === void 0) return;
17273
+ try {
17274
+ await cache.write(session);
17275
+ } catch (error51) {
17276
+ this.ctx.logger.warn(`devlead: ${what} could not be checkpointed into the Session projection cache: ${thrownMessage(error51)}`);
17277
+ }
17278
+ }
16829
17279
  /** Reject any use of a tool surface while DevLead mode is off. */
16830
17280
  assertReady(agent) {
16831
17281
  this.assertLive(agent);
@@ -16959,6 +17409,108 @@ var DevLeadService = class extends Service {
16959
17409
  }
16960
17410
  return [...leads].map(([sessionId, watched]) => ({ sessionId, watched }));
16961
17411
  }
17412
+ /**
17413
+ * Validate one requested model selection against the Host's LLM registry.
17414
+ * @param selection - normalized provider/model/effort selection.
17415
+ * @param signal - cancellation checked around the adapter lookup.
17416
+ * @throws {@link DevLeadError} `DEVLEAD_MODEL_UNAVAILABLE` when the Host
17417
+ * composes no validator or the adapter rejects the route/effort.
17418
+ */
17419
+ async assertModelSelectable(selection, signal) {
17420
+ const validator = modelValidatorOf(this.ctx);
17421
+ if (validator === void 0) {
17422
+ throw new DevLeadError(
17423
+ `cannot validate model "${modelSelectionLabel(selection)}": this Host composes no LLM registry. Call devlead_list_models to see available providers, models, and reasoning efforts`,
17424
+ "DEVLEAD_MODEL_UNAVAILABLE"
17425
+ );
17426
+ }
17427
+ try {
17428
+ if (!validator.listProviders().some((provider) => provider.id === selection.provider)) {
17429
+ throw new Error(`provider "${selection.provider}" is not registered`);
17430
+ }
17431
+ const models = await validator.listModels(selection.provider);
17432
+ if (!models.some((model) => model.id === selection.model)) {
17433
+ throw new Error(`model "${selection.model}" is not in provider "${selection.provider}"'s available model list`);
17434
+ }
17435
+ await validator.resolveCallConfig(selection, signal);
17436
+ } catch (error51) {
17437
+ signal?.throwIfAborted();
17438
+ throw new DevLeadError(
17439
+ `model "${modelSelectionLabel(selection)}" is not available: ${thrownMessage(error51)}. Call devlead_list_models to see available providers, models, and reasoning efforts`,
17440
+ "DEVLEAD_MODEL_UNAVAILABLE"
17441
+ );
17442
+ }
17443
+ signal?.throwIfAborted();
17444
+ }
17445
+ /**
17446
+ * Apply creation-time dispatch settings to a freshly created Session.
17447
+ *
17448
+ * The settings are recorded on the child Agent itself: the model through
17449
+ * `agent.model.select` (durable Session-level event, never the profile
17450
+ * default), and Team mode through the optional Team service. A failure here
17451
+ * happens after the Session exists, so the error names its id and the Session
17452
+ * is deliberately left in place (the service's creation contract does not
17453
+ * roll back side effects).
17454
+ * @param created - the controller's create result.
17455
+ * @param model - normalized model selection, when requested.
17456
+ * @param teamsRequested - requested Team mode, when explicitly set.
17457
+ * @param teams - detected Team capability, when one is composed.
17458
+ * @param signal - cancellation checked between applications.
17459
+ * @returns the settings that were actually applied.
17460
+ * @throws {@link DevLeadError} with the created Session id in the message when
17461
+ * the Agent is not live or an application step fails.
17462
+ */
17463
+ async applyDispatchSettings(created, model, teamsRequested, teams, signal) {
17464
+ if (model === void 0 && teamsRequested === void 0) return {};
17465
+ const sessionId = String(created.sessionId);
17466
+ const child = this.ctx.agents.get(created.sessionId);
17467
+ if (child === void 0) {
17468
+ throw new DevLeadError(
17469
+ `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`,
17470
+ "DEVLEAD_SESSION_UNAVAILABLE"
17471
+ );
17472
+ }
17473
+ const applied = {};
17474
+ if (model !== void 0) {
17475
+ try {
17476
+ child.model.select({
17477
+ provider: model.provider,
17478
+ model: model.model,
17479
+ ...model.reasoningEffort === void 0 ? {} : { reasoningEffort: ReasoningEffortId(model.reasoningEffort) }
17480
+ });
17481
+ } catch (error51) {
17482
+ signal?.throwIfAborted();
17483
+ throw new DevLeadError(
17484
+ `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`,
17485
+ "DEVLEAD_MODEL_UNAVAILABLE"
17486
+ );
17487
+ }
17488
+ await this.flushDurably(child.session, `model selection for Session "${sessionId}"`);
17489
+ applied.model = { ...model };
17490
+ }
17491
+ if (teamsRequested !== void 0) {
17492
+ if (teamsRequested === true && teams === void 0) {
17493
+ throw new DevLeadError(
17494
+ `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)`,
17495
+ "DEVLEAD_TEAM_UNAVAILABLE"
17496
+ );
17497
+ }
17498
+ if (teams !== void 0) {
17499
+ try {
17500
+ await teams.setEnabled(child, teamsRequested, signal);
17501
+ } catch (error51) {
17502
+ signal?.throwIfAborted();
17503
+ throw new DevLeadError(
17504
+ `Session "${sessionId}" was created but Agent Teams could not be ${teamsRequested ? "enabled" : "disabled"}; the Session remains: ${thrownMessage(error51)}`,
17505
+ "DEVLEAD_TEAM_UNAVAILABLE"
17506
+ );
17507
+ }
17508
+ }
17509
+ applied.agentTeams = teamsRequested;
17510
+ }
17511
+ signal?.throwIfAborted();
17512
+ return applied;
17513
+ }
16962
17514
  /** Require the Workspace registry capability (Workspaces and Session archive state). */
16963
17515
  requireWorkspaceRegistry() {
16964
17516
  const registry2 = this.ctx.get("workspaceRegistry");
@@ -17213,6 +17765,7 @@ var DevLeadService = class extends Service {
17213
17765
  const next = watching ? [...state.sessions, id] : state.sessions.filter((existing) => existing !== id);
17214
17766
  appendPluginRecord2(agent.session, DEVLEAD_WATCH_RECORD_TYPE, watchRecord(next, Date.now()));
17215
17767
  await this.flushDurably(agent.session, `watch set for lead "${agent.id}"`);
17768
+ await this.checkpointProjectionCache(agent.session, `watch set for lead "${agent.id}"`);
17216
17769
  return { sessionId: id, watched: watching, sessions: next };
17217
17770
  }
17218
17771
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yankeguo/dsh-devlead",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
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",
@@ -17,16 +17,16 @@
17
17
  ],
18
18
  "peerDependencies": {
19
19
  "@deepseek-ai/cordis": "~4.1.0",
20
- "@deepseek-ai/dsh-agent": "0.2.2-rc.1",
21
- "@deepseek-ai/dsh-api-session-controller": "0.2.2-rc.1",
22
- "@deepseek-ai/dsh-llm": "0.2.2-rc.1",
23
- "@deepseek-ai/dsh-session": "0.2.2-rc.1",
24
- "@deepseek-ai/dsh-session-projection": "0.2.2-rc.1",
25
- "@deepseek-ai/dsh-session-query": "0.2.2-rc.1",
26
- "@deepseek-ai/dsh-session-title": "0.2.2-rc.1",
27
- "@deepseek-ai/dsh-workspace": "0.2.2-rc.1",
20
+ "@deepseek-ai/dsh-agent": ">=0.2.2-rc.1 <0.3.0",
21
+ "@deepseek-ai/dsh-api-session-controller": ">=0.2.2-rc.1 <0.3.0",
22
+ "@deepseek-ai/dsh-llm": ">=0.2.2-rc.1 <0.3.0",
23
+ "@deepseek-ai/dsh-session": ">=0.2.2-rc.1 <0.3.0",
24
+ "@deepseek-ai/dsh-session-projection": ">=0.2.2-rc.1 <0.3.0",
25
+ "@deepseek-ai/dsh-session-query": ">=0.2.2-rc.1 <0.3.0",
26
+ "@deepseek-ai/dsh-session-title": ">=0.2.2-rc.1 <0.3.0",
27
+ "@deepseek-ai/dsh-workspace": ">=0.2.2-rc.1 <0.3.0",
28
28
  "@deepseek-ai/schemastery": "~3.19.0",
29
- "zod": "4.4.3"
29
+ "zod": "^4.4.3"
30
30
  },
31
31
  "peerDependenciesMeta": {
32
32
  "@deepseek-ai/dsh-api-session-controller": {
@@ -43,7 +43,7 @@
43
43
  }
44
44
  },
45
45
  "dependencies": {
46
- "@yankeguo/dsh-devlead-protocol": "0.2.2"
46
+ "@yankeguo/dsh-devlead-protocol": "0.2.4"
47
47
  },
48
48
  "engines": {
49
49
  "dsh": ">=0.2.2-rc.1 <0.3.0"