@yankeguo/dsh-devlead 0.2.3 → 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 +293 -36
  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
@@ -11,7 +11,7 @@ import { Service } from "@deepseek-ai/cordis";
11
11
  import z2 from "@deepseek-ai/schemastery";
12
12
  import { ReasoningEffortId } from "@deepseek-ai/dsh-llm";
13
13
  import { appendPluginRecord as appendPluginRecord2 } from "@deepseek-ai/dsh-session";
14
- import "@deepseek-ai/dsh-session";
14
+ import { SessionId as toSessionId3 } from "@deepseek-ai/dsh-session";
15
15
  import { DEVLEAD_DEFAULT_MAX_WATCHED as DEVLEAD_DEFAULT_MAX_WATCHED2 } from "@yankeguo/dsh-devlead-protocol";
16
16
 
17
17
  // packages/devlead/src/domain.ts
@@ -15131,6 +15131,7 @@ import {
15131
15131
  } from "@yankeguo/dsh-devlead-protocol";
15132
15132
  var MAX_DIGEST_LINES = 12;
15133
15133
  var DELIVERY_RETRY_MS = 1e3;
15134
+ var MAX_COLD_RESUME_ATTEMPTS = 5;
15134
15135
  var DEVLEAD_MAX_WARNED_FAILURES = 256;
15135
15136
  function renderDevLeadNotice(notifications, total = notifications.length) {
15136
15137
  const shown = notifications.slice(-MAX_DIGEST_LINES);
@@ -15283,8 +15284,12 @@ var DevLeadNotificationHub = class {
15283
15284
  return;
15284
15285
  }
15285
15286
  const runtime = this.ensureLead(sessionId);
15287
+ runtime.resumeAttempts = 0;
15286
15288
  this.setWatched(runtime, state.sessions);
15287
- 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
+ }
15288
15293
  }
15289
15294
  /**
15290
15295
  * Create the runtime row for one lead Session.
@@ -15301,7 +15306,8 @@ var DevLeadNotificationHub = class {
15301
15306
  unsaved: [],
15302
15307
  timer: void 0,
15303
15308
  scheduled: false,
15304
- flushing: false
15309
+ flushing: false,
15310
+ resumeAttempts: 0
15305
15311
  };
15306
15312
  this.leads.set(sessionId, runtime);
15307
15313
  return runtime;
@@ -15461,10 +15467,10 @@ var DevLeadNotificationHub = class {
15461
15467
  const runtime = this.leads.get(leadId);
15462
15468
  if (runtime === void 0) return;
15463
15469
  const session = this.ctx.sessions.get(toSessionId(leadId));
15464
- if (session !== void 0) this.appendNotificationRecord(session, notification, leadId);
15470
+ const persisted = session !== void 0 && this.appendNotificationRecord(session, notification, leadId);
15465
15471
  if (runtime.pending.some((existing) => existing.id === notification.id)) return;
15466
15472
  if (runtime.unsaved.some((existing) => existing.id === notification.id)) return;
15467
- if (session === void 0) {
15473
+ if (!persisted) {
15468
15474
  runtime.unsaved = [...runtime.unsaved, notification].slice(-DEVLEAD_DEFAULT_NOTIFICATION_RETENTION3);
15469
15475
  this.scheduleFlush(runtime);
15470
15476
  return;
@@ -15480,15 +15486,17 @@ var DevLeadNotificationHub = class {
15480
15486
  * @param session - lead Session receiving the record.
15481
15487
  * @param notification - notification to persist.
15482
15488
  * @param leadId - lead Session identity used in warnings.
15489
+ * @returns whether the durable append succeeded.
15483
15490
  */
15484
15491
  appendNotificationRecord(session, notification, leadId) {
15485
15492
  try {
15486
15493
  appendPluginRecord(session, DEVLEAD_NOTIFICATION_RECORD_TYPE3, notificationRecord(notification));
15487
15494
  } catch (error51) {
15488
15495
  this.ctx.logger.warn(`devlead: could not record a notification for lead "${leadId}": ${thrownMessage(error51)}`);
15489
- return;
15496
+ return false;
15490
15497
  }
15491
15498
  void this.checkpoint(session, leadId);
15499
+ return true;
15492
15500
  }
15493
15501
  /**
15494
15502
  * Fire-and-forget one Session durability checkpoint.
@@ -15582,7 +15590,6 @@ var DevLeadNotificationHub = class {
15582
15590
  if (session !== void 0) {
15583
15591
  this.persistUnsaved(session, runtime);
15584
15592
  runtime.pending = [];
15585
- runtime.unsaved = [];
15586
15593
  }
15587
15594
  this.clearTimer(runtime);
15588
15595
  return;
@@ -15637,6 +15644,26 @@ var DevLeadNotificationHub = class {
15637
15644
  void this.flush(runtime);
15638
15645
  }, DELIVERY_RETRY_MS);
15639
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
+ }
15640
15667
  /**
15641
15668
  * Whether one lead Agent already holds an undelivered digest notice.
15642
15669
  * @param agent - live lead Agent.
@@ -15665,12 +15692,14 @@ var DevLeadNotificationHub = class {
15665
15692
  if (this.stopping) return;
15666
15693
  if ("error" in resolved) {
15667
15694
  this.ctx.logger.warn(`devlead: could not resume lead "${leadId}": ${resolved.error.message}`);
15695
+ this.retryColdResume(runtime);
15668
15696
  return;
15669
15697
  }
15670
15698
  this.syncLead(resolved.agent);
15671
15699
  } catch (error51) {
15672
15700
  if (!this.stopping) {
15673
15701
  this.ctx.logger.warn(`devlead: could not resume lead "${leadId}": ${thrownMessage(error51)}`);
15702
+ this.retryColdResume(runtime);
15674
15703
  }
15675
15704
  } finally {
15676
15705
  this.resuming.delete(leadId);
@@ -15679,14 +15708,17 @@ var DevLeadNotificationHub = class {
15679
15708
  };
15680
15709
 
15681
15710
  // packages/devlead/src/persistence.ts
15682
- async function persistedSessionsOf(ctx) {
15711
+ async function persistedSessionsOf(ctx, signal) {
15683
15712
  const candidate = ctx.get("sessionPersistence");
15684
15713
  if (typeof candidate !== "object" || candidate === null) return { verifiable: false };
15685
15714
  const list = candidate.list;
15686
15715
  if (typeof list !== "function") return { verifiable: false };
15687
15716
  let listed;
15688
15717
  try {
15689
- listed = await Promise.resolve(list.call(candidate));
15718
+ listed = await Promise.resolve(list.call(
15719
+ candidate,
15720
+ signal === void 0 ? void 0 : { signal }
15721
+ ));
15690
15722
  } catch {
15691
15723
  return { verifiable: true };
15692
15724
  }
@@ -15704,6 +15736,42 @@ async function persistedSessionsOf(ctx) {
15704
15736
  return { verifiable: true, ids };
15705
15737
  }
15706
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
+
15707
15775
  // packages/devlead/src/projection-cache.ts
15708
15776
  function projectionCacheOf(ctx) {
15709
15777
  const candidate = ctx.get("sessionProjectionCache");
@@ -15711,7 +15779,10 @@ function projectionCacheOf(ctx) {
15711
15779
  const cachedSnapshot = candidate.cachedSnapshot;
15712
15780
  if (typeof cachedSnapshot !== "function") return void 0;
15713
15781
  const service = candidate;
15714
- 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
+ };
15715
15786
  }
15716
15787
  function devLeadPrefilterOf(cache, header) {
15717
15788
  let snapshot;
@@ -15785,6 +15856,12 @@ async function collectSessionIds(deps, workspace, exhaustive = false) {
15785
15856
  }
15786
15857
  } catch (error51) {
15787
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
+ }
15788
15865
  }
15789
15866
  }
15790
15867
  }
@@ -15824,6 +15901,37 @@ async function knownSessions(deps, ids) {
15824
15901
  }
15825
15902
  return result;
15826
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
+ }
15827
15935
  async function readSessionFacts(deps, ids) {
15828
15936
  const known = await knownSessions(deps, ids);
15829
15937
  const workspaces = /* @__PURE__ */ new Map();
@@ -15845,12 +15953,12 @@ async function readSessionFacts(deps, ids) {
15845
15953
  }
15846
15954
  return { known, workspaces, archived };
15847
15955
  }
15848
- function rankSessionIds(deps, ids, facts, limit) {
15956
+ function rankSessionIds(deps, ids, known, limit) {
15849
15957
  const ranked = ids.map((id) => ({
15850
15958
  id,
15851
15959
  watched: deps.isWatched(id),
15852
15960
  running: deps.ctx.agents.get(toSessionId2(id))?.status === "running",
15853
- createdAt: facts.known.get(id)?.header?.createdAt ?? 0
15961
+ createdAt: known.get(id)?.header?.createdAt ?? 0
15854
15962
  }));
15855
15963
  ranked.sort((left, right) => {
15856
15964
  if (left.watched !== right.watched) return left.watched ? -1 : 1;
@@ -15911,7 +16019,8 @@ async function buildSessionView(deps, sessionId, withLog, facts) {
15911
16019
  const workspace = facts.workspaces.get(sessionId);
15912
16020
  const boundary = agent === void 0 ? void 0 : ctx.agents.turnBoundaryOf(agent.session);
15913
16021
  const log = withLog ? await sessionLogFacts(deps, sessionId) : {};
15914
- 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;
15915
16024
  return {
15916
16025
  sessionId,
15917
16026
  ...known?.title === void 0 ? {} : { title: known.title },
@@ -16137,6 +16246,12 @@ var DevLeadService = class extends Service {
16137
16246
  rehydrated = false;
16138
16247
  /** In-flight rehydration attempt, so concurrent readiness triggers share it. */
16139
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;
16140
16255
  /**
16141
16256
  * Disposers of the armed readiness retry: the optional-service injection fiber
16142
16257
  * and, while the query engine itself is missing, the lifecycle listeners.
@@ -16160,7 +16275,11 @@ var DevLeadService = class extends Service {
16160
16275
  );
16161
16276
  this.hub.start();
16162
16277
  this.ctx.effect(function* () {
16163
- yield () => this.disposeRehydrationRetry();
16278
+ yield () => {
16279
+ this.disposed = true;
16280
+ this.wakeReadiness();
16281
+ this.disposeRehydrationRetry();
16282
+ };
16164
16283
  }.bind(this), "devlead: cold rehydration");
16165
16284
  await this.rehydrateFromPersistence();
16166
16285
  }
@@ -16204,7 +16323,7 @@ var DevLeadService = class extends Service {
16204
16323
  * steady Host pays one macrotask plus one comparison.
16205
16324
  */
16206
16325
  async runRehydration() {
16207
- if (this.rehydrated) return;
16326
+ if (this.rehydrated || this.disposed) return;
16208
16327
  const queryReady = this.ctx.get("sessionQuery") !== void 0;
16209
16328
  try {
16210
16329
  this.hub.rehydrate(this.liveAttachLeads());
@@ -16229,12 +16348,14 @@ var DevLeadService = class extends Service {
16229
16348
  return;
16230
16349
  }
16231
16350
  await this.awaitCorpusReady();
16232
- if (this.rehydrated) return;
16351
+ if (this.rehydrated || this.disposed) return;
16233
16352
  try {
16234
- 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));
16235
16355
  } catch (error51) {
16236
16356
  this.ctx.logger.warn(`devlead: cold lead rehydration failed: ${thrownMessage(error51)}`);
16237
16357
  }
16358
+ if (this.disposed) return;
16238
16359
  this.finalizeRehydration();
16239
16360
  }
16240
16361
  /**
@@ -16249,29 +16370,34 @@ var DevLeadService = class extends Service {
16249
16370
  */
16250
16371
  async awaitCorpusReady() {
16251
16372
  const deadline = Date.now() + REHYDRATION_READINESS_TIMEOUT_MS;
16252
- let probe = await persistedSessionsOf(this.ctx);
16253
- while (probe.verifiable && probe.ids === void 0 && Date.now() < deadline) {
16254
- await new Promise((resolve) => {
16255
- setTimeout(resolve, REHYDRATION_READINESS_POLL_MS);
16256
- });
16257
- 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;
16258
16387
  }
16259
- const ids = probe.ids;
16260
- if (ids === void 0) return;
16261
16388
  if (ids.size === 0) return;
16262
16389
  let consistent = false;
16263
- while (Date.now() < deadline) {
16264
- const listed = await this.listedPersistedSessionIds();
16390
+ while (!this.disposed && Date.now() < deadline) {
16391
+ const listed = await this.listedPersistedSessionIds(deadline);
16265
16392
  if (this.containsAllSessionIds(listed, ids)) {
16266
16393
  consistent = true;
16267
16394
  break;
16268
16395
  }
16269
- await new Promise((resolve) => {
16270
- setTimeout(resolve, REHYDRATION_READINESS_POLL_MS);
16271
- });
16396
+ await this.readinessSleep(REHYDRATION_READINESS_POLL_MS);
16272
16397
  }
16398
+ if (this.disposed) return;
16273
16399
  if (!consistent) {
16274
- consistent = this.containsAllSessionIds(await this.listedPersistedSessionIds(), ids);
16400
+ consistent = this.containsAllSessionIds(await this.listedPersistedSessionIds(deadline), ids);
16275
16401
  }
16276
16402
  if (!consistent) {
16277
16403
  this.ctx.logger.warn(
@@ -16279,6 +16405,51 @@ var DevLeadService = class extends Service {
16279
16405
  );
16280
16406
  }
16281
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
+ }
16282
16453
  /**
16283
16454
  * Whether one corpus listing contains every expected Session id.
16284
16455
  * @param listed - ids visible in the query corpus.
@@ -16297,19 +16468,30 @@ var DevLeadService = class extends Service {
16297
16468
  * Before its optional persistence binding is installed the query engine merges
16298
16469
  * only live Sessions, so this is the number the readiness barrier compares
16299
16470
  * against the persistence service's complete stored listing.
16471
+ * @param deadline - absolute readiness deadline for the listing read.
16300
16472
  * @returns the visible persisted Session ids.
16301
16473
  */
16302
- async listedPersistedSessionIds() {
16474
+ async listedPersistedSessionIds(deadline) {
16303
16475
  const query = this.ctx.get("sessionQuery");
16304
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);
16305
16481
  try {
16306
- 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();
16307
16487
  return new Set(
16308
16488
  records.filter((record2) => record2.persisted).map((record2) => String(record2.header.id))
16309
16489
  );
16310
16490
  } catch (error51) {
16311
16491
  this.ctx.logger.debug(`devlead: corpus readiness listing failed: ${thrownMessage(error51)}`);
16312
16492
  return /* @__PURE__ */ new Set();
16493
+ } finally {
16494
+ clearTimeout(timer);
16313
16495
  }
16314
16496
  }
16315
16497
  /**
@@ -16407,7 +16589,7 @@ var DevLeadService = class extends Service {
16407
16589
  }
16408
16590
  /**
16409
16591
  * Save one Session's DevLead selection. Human-entry points own this call: the
16410
- * `/devlead` command and the browser switch, never a model tool.
16592
+ * `/devlead` command and the composer-toolbar toggle, never a model tool.
16411
16593
  * @param agent - exact live Session Agent receiving the selection.
16412
16594
  * @param enabled - selected mode.
16413
16595
  * @param signal - cancellation checked before the write.
@@ -16428,11 +16610,13 @@ var DevLeadService = class extends Service {
16428
16610
  }
16429
16611
  this.appendResetRecord(agent.session);
16430
16612
  await this.flushDurably(agent.session, `DevLead reset for Session "${agent.id}"`);
16613
+ await this.checkpointProjectionCache(agent.session, `DevLead reset for Session "${agent.id}"`);
16431
16614
  return;
16432
16615
  }
16433
16616
  if (current.enabled === enabled) return;
16434
16617
  appendPluginRecord2(agent.session, DEVLEAD_MODE_RECORD_TYPE, modeRecord(enabled, Date.now()));
16435
16618
  await this.flushDurably(agent.session, `DevLead mode for Session "${agent.id}"`);
16619
+ await this.checkpointProjectionCache(agent.session, `DevLead mode for Session "${agent.id}"`);
16436
16620
  }
16437
16621
  /**
16438
16622
  * Discard one Session's durable DevLead state so a damaged fold can recover.
@@ -16452,6 +16636,7 @@ var DevLeadService = class extends Service {
16452
16636
  signal?.throwIfAborted();
16453
16637
  this.appendResetRecord(agent.session);
16454
16638
  await this.flushDurably(agent.session, `DevLead reset for Session "${agent.id}"`);
16639
+ await this.checkpointProjectionCache(agent.session, `DevLead reset for Session "${agent.id}"`);
16455
16640
  }
16456
16641
  /**
16457
16642
  * Append one reset marker to a Session log.
@@ -16469,6 +16654,7 @@ var DevLeadService = class extends Service {
16469
16654
  * @returns detached Workspace views in registry order.
16470
16655
  */
16471
16656
  async listWorkspaces(signal) {
16657
+ signal?.throwIfAborted();
16472
16658
  const registry2 = this.ctx.get("workspaceRegistry");
16473
16659
  if (registry2 === void 0) return [];
16474
16660
  const views = [];
@@ -16606,9 +16792,10 @@ var DevLeadService = class extends Service {
16606
16792
  const listingCap = options.watchedOnly === true ? Math.max(this.resolved.maxListedSessions, deps.watchedSessions.length) : this.resolved.maxListedSessions;
16607
16793
  const requestedLimit = listLimit(options.limit, listingCap);
16608
16794
  const limit = options.watchedOnly === true ? Math.max(requestedLimit, deps.watchedSessions.length) : requestedLimit;
16609
- const facts = await readSessionFacts(deps, ids);
16795
+ const ranking = await sessionRankFacts(deps, ids);
16610
16796
  signal?.throwIfAborted();
16611
- const retained = rankSessionIds(deps, ids, facts, limit);
16797
+ const retained = rankSessionIds(deps, ids, ranking, limit);
16798
+ const facts = await readSessionFacts(deps, retained);
16612
16799
  return await devLeadSessionViews(deps, retained, false, facts);
16613
16800
  }
16614
16801
  /**
@@ -16648,6 +16835,52 @@ var DevLeadService = class extends Service {
16648
16835
  signal?.throwIfAborted();
16649
16836
  return devLeadModelCatalogOf(catalog);
16650
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
+ }
16651
16884
  /**
16652
16885
  * Read one Session in detail, including folded turn and assistant facts.
16653
16886
  * @param agent - exact live lead Agent.
@@ -17020,6 +17253,29 @@ var DevLeadService = class extends Service {
17020
17253
  this.ctx.logger.warn(`devlead: ${what} could not be flushed to persistence: ${thrownMessage(error51)}`);
17021
17254
  }
17022
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
+ }
17023
17279
  /** Reject any use of a tool surface while DevLead mode is off. */
17024
17280
  assertReady(agent) {
17025
17281
  this.assertLive(agent);
@@ -17509,6 +17765,7 @@ var DevLeadService = class extends Service {
17509
17765
  const next = watching ? [...state.sessions, id] : state.sessions.filter((existing) => existing !== id);
17510
17766
  appendPluginRecord2(agent.session, DEVLEAD_WATCH_RECORD_TYPE, watchRecord(next, Date.now()));
17511
17767
  await this.flushDurably(agent.session, `watch set for lead "${agent.id}"`);
17768
+ await this.checkpointProjectionCache(agent.session, `watch set for lead "${agent.id}"`);
17512
17769
  return { sessionId: id, watched: watching, sessions: next };
17513
17770
  }
17514
17771
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yankeguo/dsh-devlead",
3
- "version": "0.2.3",
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.3"
46
+ "@yankeguo/dsh-devlead-protocol": "0.2.4"
47
47
  },
48
48
  "engines": {
49
49
  "dsh": ">=0.2.2-rc.1 <0.3.0"