@yankeguo/dsh-devlead 0.2.6 → 0.3.0-rc.2

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 +15 -4
  2. package/lib/index.js +537 -112
  3. package/package.json +3 -2
package/README.md CHANGED
@@ -11,11 +11,22 @@ Session holds it; `off`/`reset` release immediately, archiving or deleting the h
11
11
  releasable, and a restart/rehydration reconciles historical duplicates and keeps one Session.
12
12
  Admission is serialized in-process and scans live projections plus the durable corpus.
13
13
 
14
+ `sessionQueuedInputs(agent, sessionId, signal?)` projects a live Session's pending inbox inputs
15
+ (id, boundary, source kind/form/sender, bounded text excerpt, enqueue instant from the durable
16
+ `agent/inbox/spliced` log); a cold target reports undefined. `retractQueuedInput(agent, sessionId,
17
+ inputId, signal?)` withdraws one queued input this lead authored (devlead relay with its own
18
+ sender id) through the Host's per-message `inbox.remove`; other producers' inputs are refused,
19
+ an already-gone input is idempotent (`retracted: false`), and the target must be live and not the
20
+ lead itself. `promptSession` accepts `interruptInbox: 'clear-all' | 'keep' | 'clear-own'`
21
+ (default `clear-all`): because the Host stop providers always clear the inbox, retention is a
22
+ snapshot before the stop and a restore of the same identified messages after it, ahead of the
23
+ replacement prompt; the result reports `retainedInputs` when a retention policy ran.
24
+
14
25
  `reportProgress(agent, { message, kind?, summary? }, signal?)` lets a watched, non-DevLead Session
15
26
  send a one-way report to its unique active lead. It resolves the active lead that watches it through
16
- the hub's reverse index, validates size/kind, deduplicates identical messages within a turn, enforces four
17
- distinct reports per turn (`DEVLEAD_REPORT_RATE_LIMITED`), and otherwise refuses with
18
- `DEVLEAD_NOT_SUPERVISED`. The receipt is `{ report, durable, queued, warning? }`.
27
+ the hub's reverse index, validates size/kind, deduplicates identical kind+message pairs within a turn, enforces four
28
+ distinct non-question reports per turn (`DEVLEAD_REPORT_RATE_LIMITED`; `question` reports are exempt
29
+ from that budget), and otherwise refuses with `DEVLEAD_NOT_SUPERVISED`. The receipt is `{ report, durable, queued, warning? }`.
19
30
 
20
31
  The report is first written to a durable outbox (`devlead_report_outbox` over the optional
21
32
  `storageDomain` KV facility), then a `plugin:devlead/report` receipt is appended to the lead's
@@ -37,7 +48,7 @@ dsh plugin --profile desktop add @yankeguo/dsh-devlead-bundle
37
48
 
38
49
  ## Requirements
39
50
 
40
- - DSH `0.2.2-rc.1`–`0.2.2-rc.4` (the package declares `engines.dsh: >=0.2.2-rc.1 <0.3.0`; this checkout's devDependencies pin rc.1 for the oldest-API typecheck).
51
+ - DSH `0.2.2-rc.1`–`0.2.2-rc.5` (the package declares `engines.dsh: >=0.2.2-rc.1 <0.3.0`; this checkout's devDependencies pin rc.1 for the oldest-API typecheck).
41
52
  - Peer services `agents`, `sessions`, `sessionProjections` (provided by the default `dsh-base`
42
53
  composition).
43
54
  - Optional, probed at call time: `workspaceRegistry`, `sessionController`, `sessionTitle`,
package/lib/index.js CHANGED
@@ -9,7 +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
+ import { MessageId, ReasoningEffortId } from "@deepseek-ai/dsh-llm";
13
13
  import { appendPluginRecord as appendPluginRecord2 } from "@deepseek-ai/dsh-session";
14
14
  import { SessionId as toSessionId3 } from "@deepseek-ai/dsh-session";
15
15
  import {
@@ -114,8 +114,9 @@ function devLeadReport(input) {
114
114
  const title = input.senderSessionTitle === void 0 ? void 0 : excerptLine(input.senderSessionTitle, DEVLEAD_ERROR_EXCERPT_MAX);
115
115
  const summary = input.summary === void 0 ? void 0 : excerptLine(input.summary, DEVLEAD_REPORT_SUMMARY_MAX);
116
116
  const workspaceTitle = input.senderWorkspaceTitle === void 0 ? void 0 : excerptLine(input.senderWorkspaceTitle, DEVLEAD_ERROR_EXCERPT_MAX);
117
+ const turn = Number.isSafeInteger(input.turn) && input.turn >= 0 ? input.turn : 0;
117
118
  return {
118
- id: devLeadReportId(input.senderSessionId, input.turn, input.kind, message),
119
+ id: devLeadReportId(input.senderSessionId, turn, input.kind, message),
119
120
  kind: input.kind,
120
121
  message,
121
122
  ...summary === void 0 ? {} : { summary },
@@ -124,7 +125,7 @@ function devLeadReport(input) {
124
125
  ...input.senderWorkspaceId === void 0 ? {} : { senderWorkspaceId: input.senderWorkspaceId },
125
126
  ...workspaceTitle === void 0 ? {} : { senderWorkspaceTitle: workspaceTitle },
126
127
  leadSessionId: input.leadSessionId,
127
- turn: Number.isSafeInteger(input.turn) && input.turn >= 0 ? input.turn : 0,
128
+ turn,
128
129
  at: representableInstant(input.at, Date.now())
129
130
  };
130
131
  }
@@ -343,7 +344,7 @@ function assistantExcerpt(blocks) {
343
344
  return excerptLine(text, DEVLEAD_ERROR_EXCERPT_MAX);
344
345
  }
345
346
 
346
- // packages/devlead/src/dispatch.ts
347
+ // packages/devlead/src/normalize.ts
347
348
  function stringField(value) {
348
349
  return typeof value === "string" ? value : "";
349
350
  }
@@ -353,6 +354,8 @@ function recordOf(value) {
353
354
  function itemsOf(value) {
354
355
  return Array.isArray(value) ? value : [];
355
356
  }
357
+
358
+ // packages/devlead/src/dispatch.ts
356
359
  function modelViewOf(value) {
357
360
  const record2 = recordOf(value);
358
361
  if (record2 === void 0) return void 0;
@@ -475,6 +478,89 @@ function agentTeamsCapabilityOf(ctx) {
475
478
  return candidate;
476
479
  }
477
480
 
481
+ // packages/devlead/src/inbox.ts
482
+ import { DEVLEAD_ERROR_EXCERPT_MAX as DEVLEAD_ERROR_EXCERPT_MAX2, DEVLEAD_MESSAGE_KIND as DEVLEAD_MESSAGE_KIND2, excerptLine as excerptLine2 } from "@yankeguo/dsh-devlead-protocol";
483
+ function sourceString(source, key) {
484
+ const value = source[key];
485
+ return typeof value === "string" && value.length > 0 ? value : void 0;
486
+ }
487
+ function sourceOf(message) {
488
+ const source = message.source;
489
+ return typeof source === "object" && source !== null && !Array.isArray(source) ? source : {};
490
+ }
491
+ function isOwnRelay(message, leadSessionId) {
492
+ const source = sourceOf(message);
493
+ return source.kind === DEVLEAD_MESSAGE_KIND2 && source.form === "relay" && source.senderSessionId === leadSessionId;
494
+ }
495
+ function locatedInputs(agent) {
496
+ return [
497
+ ...agent.inbox.nextTurn.map((message) => ({ boundary: "next-turn", message })),
498
+ ...agent.inbox.nextStep.map((message) => ({ boundary: "next-step", message }))
499
+ ];
500
+ }
501
+ function enqueuedTimes(session, ids) {
502
+ const times = /* @__PURE__ */ new Map();
503
+ if (ids.size === 0) return times;
504
+ const events = session.snapshotEvents();
505
+ for (let index = events.length - 1; index >= 0 && times.size < ids.size; index -= 1) {
506
+ const event = events[index];
507
+ if (event?.type !== "agent/inbox/spliced") continue;
508
+ const inserted = event.data.inserted;
509
+ if (!Array.isArray(inserted)) continue;
510
+ for (const candidate of inserted) {
511
+ const id = candidate?.id;
512
+ if (typeof id === "string" && ids.has(id) && !times.has(id)) times.set(id, event.time);
513
+ }
514
+ }
515
+ return times;
516
+ }
517
+ function textExcerpt(message) {
518
+ const blocks = message.content;
519
+ if (!Array.isArray(blocks)) return void 0;
520
+ const text = blocks.filter((block) => typeof block === "object" && block !== null && block.type === "text" && typeof block.text === "string").map((block) => block.text).join(" ");
521
+ return excerptLine2(text, DEVLEAD_ERROR_EXCERPT_MAX2);
522
+ }
523
+ function queuedInputsOf(agent) {
524
+ const located = locatedInputs(agent);
525
+ const times = enqueuedTimes(agent.session, new Set(located.map((entry) => String(entry.message.id))));
526
+ return located.map(({ boundary, message }) => {
527
+ const source = sourceOf(message);
528
+ const id = String(message.id);
529
+ const excerpt = textExcerpt(message);
530
+ const enqueuedAt = times.get(id);
531
+ const sourceForm = sourceString(source, "form");
532
+ const senderSessionId = sourceString(source, "senderSessionId");
533
+ return {
534
+ id,
535
+ boundary,
536
+ sourceKind: sourceString(source, "kind") ?? "unknown",
537
+ ...sourceForm === void 0 ? {} : { sourceForm },
538
+ ...senderSessionId === void 0 ? {} : { senderSessionId },
539
+ ...excerpt === void 0 ? {} : { excerpt },
540
+ ...enqueuedAt === void 0 ? {} : { enqueuedAt }
541
+ };
542
+ });
543
+ }
544
+ function restoreInputs(agent, kept) {
545
+ const pending = new Set(locatedInputs(agent).map((entry) => String(entry.message.id)));
546
+ let restored = 0;
547
+ for (let index = kept.length - 1; index >= 0; index -= 1) {
548
+ const entry = kept[index];
549
+ if (entry === void 0) continue;
550
+ const id = String(entry.message.id);
551
+ if (pending.has(id)) continue;
552
+ agent.inbox.prepend(entry.boundary, entry.message);
553
+ pending.add(id);
554
+ restored += 1;
555
+ }
556
+ return restored;
557
+ }
558
+ function keptInputsOf(agent, leadSessionId, policy) {
559
+ if (policy === "clear-all") return [];
560
+ const located = locatedInputs(agent);
561
+ return policy === "keep" ? located : located.filter((entry) => !isOwnRelay(entry.message, leadSessionId));
562
+ }
563
+
478
564
  // node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/external.js
479
565
  var external_exports = {};
480
566
  __export(external_exports, {
@@ -15226,7 +15312,7 @@ var DevLeadReportOutbox = class _DevLeadReportOutbox {
15226
15312
  import { pluginRecordOf } from "@deepseek-ai/dsh-session";
15227
15313
  import {
15228
15314
  DEVLEAD_DEFAULT_NOTIFICATION_RETENTION as DEVLEAD_DEFAULT_NOTIFICATION_RETENTION2,
15229
- DEVLEAD_ERROR_EXCERPT_MAX as DEVLEAD_ERROR_EXCERPT_MAX2,
15315
+ DEVLEAD_ERROR_EXCERPT_MAX as DEVLEAD_ERROR_EXCERPT_MAX3,
15230
15316
  DEVLEAD_MAX_INSTANT as DEVLEAD_MAX_INSTANT3,
15231
15317
  DEVLEAD_MODE_PROJECTION_KEY,
15232
15318
  DEVLEAD_MODE_RECORD_TYPE as DEVLEAD_MODE_RECORD_TYPE2,
@@ -15244,12 +15330,19 @@ import {
15244
15330
  devLeadReportId as devLeadReportId3,
15245
15331
  notificationId as notificationId2
15246
15332
  } from "@yankeguo/dsh-devlead-protocol";
15247
- function emptyDevLeadProjectionState() {
15248
- return { enabled: false, sessions: [], notifications: [], reports: [], failure: null };
15333
+ function emptyDevLeadProjectionState(inheritedEventCount = 0) {
15334
+ return {
15335
+ enabled: false,
15336
+ sessions: [],
15337
+ notifications: [],
15338
+ reports: [],
15339
+ failure: null,
15340
+ inheritedEventCount
15341
+ };
15249
15342
  }
15250
15343
  var excerptSchema = external_exports.string().min(1).refine(
15251
- (value) => value.length <= DEVLEAD_ERROR_EXCERPT_MAX2 * 2 && Array.from(value).length <= DEVLEAD_ERROR_EXCERPT_MAX2,
15252
- { message: `excerpt must be at most ${DEVLEAD_ERROR_EXCERPT_MAX2} code points` }
15344
+ (value) => value.length <= DEVLEAD_ERROR_EXCERPT_MAX3 * 2 && Array.from(value).length <= DEVLEAD_ERROR_EXCERPT_MAX3,
15345
+ { message: `excerpt must be at most ${DEVLEAD_ERROR_EXCERPT_MAX3} code points` }
15253
15346
  );
15254
15347
  var notificationSchema = external_exports.object({
15255
15348
  id: external_exports.string().min(1),
@@ -15320,7 +15413,8 @@ var devLeadProjectionStateSchema = external_exports.object({
15320
15413
  (reports) => new Set(reports.map((report) => report.id)).size === reports.length,
15321
15414
  { message: "report ids must be unique" }
15322
15415
  ),
15323
- failure: external_exports.string().min(1).nullable()
15416
+ failure: external_exports.string().min(1).nullable(),
15417
+ inheritedEventCount: external_exports.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER)
15324
15418
  }).strict();
15325
15419
  var devLeadProjectionSchema = external_exports.object({
15326
15420
  enabled: external_exports.boolean(),
@@ -15348,12 +15442,13 @@ function devLeadProjectionView(state) {
15348
15442
  return view;
15349
15443
  }
15350
15444
  function applyDevLeadProjection(state, event) {
15445
+ if (event.seq < state.inheritedEventCount) return state;
15351
15446
  const record2 = pluginRecordOf(event);
15352
15447
  if (record2 === void 0) return state;
15353
15448
  if (record2.type === DEVLEAD_RESET_RECORD_TYPE2) {
15354
15449
  try {
15355
15450
  decodeResetRecord(record2.data);
15356
- return emptyDevLeadProjectionState();
15451
+ return emptyDevLeadProjectionState(state.inheritedEventCount);
15357
15452
  } catch (error51) {
15358
15453
  if (state.failure !== null) return state;
15359
15454
  return freezeProjection(state, event, record2.type, error51);
@@ -15399,9 +15494,10 @@ function freezeProjection(state, event, type, error51) {
15399
15494
  var devLeadProjectionDefinition = {
15400
15495
  key: DEVLEAD_PROJECTION_KEY,
15401
15496
  stateSchema: devLeadProjectionStateSchema,
15402
- // The unit owns no Session-metadata-derived state, so it ignores the header
15403
- // and inherited-prefix arguments the registry passes.
15404
- init: emptyDevLeadProjectionState,
15497
+ // The unit owns no Session-metadata-derived state (the header is unused), but
15498
+ // it must remember the fork-inherited prefix length so inherited mode/watch
15499
+ // records never describe the forked Session.
15500
+ init: (_header, inheritedEventCount = 0) => emptyDevLeadProjectionState(inheritedEventCount),
15405
15501
  apply: applyDevLeadProjection,
15406
15502
  wire: {
15407
15503
  viewSchema: devLeadProjectionSchema,
@@ -15410,19 +15506,20 @@ var devLeadProjectionDefinition = {
15410
15506
  // conversation reads it: keep it out of every Session summary/list row.
15411
15507
  summary: false
15412
15508
  },
15413
- // 2: adds the retained `reports` array to the state; version 1 cache rows
15414
- // are discarded and refolded from the durable log.
15415
- stateVersion: 2
15509
+ // 3: adds the fork-inherited prefix length (version 2 added reports); older
15510
+ // cache rows are discarded and refolded from the durable log.
15511
+ stateVersion: 3
15416
15512
  };
15417
- function emptyDevLeadWatchProjectionState() {
15418
- return { sessions: [], failure: null };
15513
+ function emptyDevLeadWatchProjectionState(inheritedEventCount = 0) {
15514
+ return { sessions: [], failure: null, inheritedEventCount };
15419
15515
  }
15420
15516
  var devLeadWatchProjectionStateSchema = external_exports.object({
15421
15517
  sessions: external_exports.array(external_exports.string().min(1)).refine(
15422
15518
  (sessions) => new Set(sessions).size === sessions.length,
15423
15519
  { message: "watch sessions must be unique" }
15424
15520
  ),
15425
- failure: external_exports.string().min(1).nullable()
15521
+ failure: external_exports.string().min(1).nullable(),
15522
+ inheritedEventCount: external_exports.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER)
15426
15523
  }).strict();
15427
15524
  var devLeadWatchProjectionSchema = external_exports.object({
15428
15525
  sessions: external_exports.array(external_exports.string().min(1)).refine(
@@ -15434,12 +15531,13 @@ function devLeadWatchProjectionView(state) {
15434
15531
  return { sessions: state.sessions };
15435
15532
  }
15436
15533
  function applyDevLeadWatchProjection(state, event) {
15534
+ if (event.seq < state.inheritedEventCount) return state;
15437
15535
  const record2 = pluginRecordOf(event);
15438
15536
  if (record2 === void 0) return state;
15439
15537
  if (record2.type === DEVLEAD_RESET_RECORD_TYPE2) {
15440
15538
  try {
15441
15539
  decodeResetRecord(record2.data);
15442
- return emptyDevLeadWatchProjectionState();
15540
+ return emptyDevLeadWatchProjectionState(state.inheritedEventCount);
15443
15541
  } catch (error51) {
15444
15542
  if (state.failure !== null) return state;
15445
15543
  const message = error51 instanceof Error ? error51.message : String(error51);
@@ -15454,7 +15552,7 @@ function applyDevLeadWatchProjection(state, event) {
15454
15552
  switch (record2.type) {
15455
15553
  case DEVLEAD_WATCH_RECORD_TYPE2: {
15456
15554
  const watch = decodeWatchRecord(record2.data);
15457
- return sameSessionIds(state.sessions, watch.sessions) ? state : { sessions: watch.sessions, failure: null };
15555
+ return sameSessionIds(state.sessions, watch.sessions) ? state : { sessions: watch.sessions, failure: null, inheritedEventCount: state.inheritedEventCount };
15458
15556
  }
15459
15557
  case DEVLEAD_MODE_RECORD_TYPE2:
15460
15558
  decodeModeRecord(record2.data);
@@ -15479,21 +15577,23 @@ function applyDevLeadWatchProjection(state, event) {
15479
15577
  var devLeadWatchProjectionDefinition = {
15480
15578
  key: DEVLEAD_WATCH_PROJECTION_KEY,
15481
15579
  stateSchema: devLeadWatchProjectionStateSchema,
15482
- init: emptyDevLeadWatchProjectionState,
15580
+ init: (_header, inheritedEventCount = 0) => emptyDevLeadWatchProjectionState(inheritedEventCount),
15483
15581
  apply: applyDevLeadWatchProjection,
15484
15582
  wire: {
15485
15583
  viewSchema: devLeadWatchProjectionSchema,
15486
15584
  view: devLeadWatchProjectionView
15487
15585
  },
15488
- // 1: the initial summary representation of the watch set.
15489
- stateVersion: 1
15586
+ // 2: adds the fork-inherited prefix length; version 1 was the initial
15587
+ // summary representation.
15588
+ stateVersion: 2
15490
15589
  };
15491
- function emptyDevLeadModeProjectionState() {
15492
- return { enabled: false, failure: null };
15590
+ function emptyDevLeadModeProjectionState(inheritedEventCount = 0) {
15591
+ return { enabled: false, failure: null, inheritedEventCount };
15493
15592
  }
15494
15593
  var devLeadModeProjectionStateSchema = external_exports.object({
15495
15594
  enabled: external_exports.boolean(),
15496
- failure: external_exports.string().min(1).nullable()
15595
+ failure: external_exports.string().min(1).nullable(),
15596
+ inheritedEventCount: external_exports.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER)
15497
15597
  }).strict();
15498
15598
  var devLeadModeProjectionSchema = external_exports.object({
15499
15599
  enabled: external_exports.boolean()
@@ -15504,12 +15604,13 @@ function devLeadModeProjectionView(state) {
15504
15604
  return state.enabled ? MODE_ENABLED_VIEW : MODE_DISABLED_VIEW;
15505
15605
  }
15506
15606
  function applyDevLeadModeProjection(state, event) {
15607
+ if (event.seq < state.inheritedEventCount) return state;
15507
15608
  const record2 = pluginRecordOf(event);
15508
15609
  if (record2 === void 0) return state;
15509
15610
  if (record2.type === DEVLEAD_RESET_RECORD_TYPE2) {
15510
15611
  try {
15511
15612
  decodeResetRecord(record2.data);
15512
- return emptyDevLeadModeProjectionState();
15613
+ return emptyDevLeadModeProjectionState(state.inheritedEventCount);
15513
15614
  } catch (error51) {
15514
15615
  if (state.failure !== null) return state;
15515
15616
  const message = error51 instanceof Error ? error51.message : String(error51);
@@ -15524,7 +15625,7 @@ function applyDevLeadModeProjection(state, event) {
15524
15625
  switch (record2.type) {
15525
15626
  case DEVLEAD_MODE_RECORD_TYPE2: {
15526
15627
  const mode = decodeModeRecord(record2.data);
15527
- return mode.enabled === state.enabled ? state : { enabled: mode.enabled, failure: null };
15628
+ return mode.enabled === state.enabled ? state : { enabled: mode.enabled, failure: null, inheritedEventCount: state.inheritedEventCount };
15528
15629
  }
15529
15630
  case DEVLEAD_WATCH_RECORD_TYPE2:
15530
15631
  decodeWatchRecord(record2.data);
@@ -15549,23 +15650,23 @@ function applyDevLeadModeProjection(state, event) {
15549
15650
  var devLeadModeProjectionDefinition = {
15550
15651
  key: DEVLEAD_MODE_PROJECTION_KEY,
15551
15652
  stateSchema: devLeadModeProjectionStateSchema,
15552
- // The unit owns no Session-metadata-derived state, so it ignores the header
15553
- // and inherited-prefix arguments the registry passes.
15554
- init: emptyDevLeadModeProjectionState,
15653
+ init: (_header, inheritedEventCount = 0) => emptyDevLeadModeProjectionState(inheritedEventCount),
15555
15654
  apply: applyDevLeadModeProjection,
15556
15655
  wire: {
15557
15656
  viewSchema: devLeadModeProjectionSchema,
15558
15657
  view: devLeadModeProjectionView
15559
15658
  },
15560
- // 1: the initial durable representation of the compact mode selection.
15561
- stateVersion: 1
15659
+ // 2: adds the fork-inherited prefix length; version 1 was the initial durable
15660
+ // representation of the compact mode selection.
15661
+ stateVersion: 2
15562
15662
  };
15563
15663
 
15564
15664
  // packages/devlead/src/active.ts
15565
15665
  import { pluginRecordOf as pluginRecordOf2 } from "@deepseek-ai/dsh-session";
15566
15666
  import {
15567
15667
  DEVLEAD_MODE_RECORD_TYPE as DEVLEAD_MODE_RECORD_TYPE3,
15568
- DEVLEAD_RESET_RECORD_TYPE as DEVLEAD_RESET_RECORD_TYPE3
15668
+ DEVLEAD_RESET_RECORD_TYPE as DEVLEAD_RESET_RECORD_TYPE3,
15669
+ sessionRefLabel
15569
15670
  } from "@yankeguo/dsh-devlead-protocol";
15570
15671
  function lastEnabledAt(events) {
15571
15672
  let at;
@@ -15592,8 +15693,7 @@ function rankActiveSessions(occupants, preferredSessionId) {
15592
15693
  });
15593
15694
  }
15594
15695
  function activeSessionLabel(occupant) {
15595
- const title = occupant.title?.trim() ?? "";
15596
- return title.length === 0 ? occupant.sessionId : `${title} (${occupant.sessionId})`;
15696
+ return sessionRefLabel(occupant.sessionId, occupant.title);
15597
15697
  }
15598
15698
  function alreadyActiveMessage(occupant) {
15599
15699
  const label = activeSessionLabel(occupant);
@@ -15625,7 +15725,7 @@ import { appendPluginRecord, pluginRecordOf as pluginRecordOf3 } from "@deepseek
15625
15725
  import { SessionId as toSessionId } from "@deepseek-ai/dsh-session";
15626
15726
  import {
15627
15727
  DEVLEAD_DEFAULT_NOTIFICATION_RETENTION as DEVLEAD_DEFAULT_NOTIFICATION_RETENTION3,
15628
- DEVLEAD_MESSAGE_KIND as DEVLEAD_MESSAGE_KIND2,
15728
+ DEVLEAD_MESSAGE_KIND as DEVLEAD_MESSAGE_KIND3,
15629
15729
  DEVLEAD_MODE_RECORD_TYPE as DEVLEAD_MODE_RECORD_TYPE4,
15630
15730
  DEVLEAD_NOTIFICATION_RECORD_TYPE as DEVLEAD_NOTIFICATION_RECORD_TYPE3,
15631
15731
  DEVLEAD_REPORT_RECORD_TYPE as DEVLEAD_REPORT_RECORD_TYPE3,
@@ -15776,9 +15876,8 @@ var DevLeadNotificationHub = class {
15776
15876
  * @returns whether the report belongs to an indexed watch relationship.
15777
15877
  */
15778
15878
  report(report) {
15779
- if (this.stopping) return false;
15780
- const runtime = this.leads.get(report.leadSessionId);
15781
- if (runtime === void 0 || !runtime.watched.has(report.senderSessionId)) return false;
15879
+ const runtime = this.reportRuntime(report);
15880
+ if (runtime === void 0) return false;
15782
15881
  if (runtime.pendingReports.some((existing) => existing.id === report.id) || runtime.unsavedReports.some((existing) => existing.id === report.id)) return true;
15783
15882
  const session = this.ctx.sessions.get(toSessionId(report.leadSessionId));
15784
15883
  if (session !== void 0) {
@@ -15808,12 +15907,8 @@ var DevLeadNotificationHub = class {
15808
15907
  * @returns whether the lead Session log now carries a flushed receipt.
15809
15908
  */
15810
15909
  async persistReport(report) {
15811
- if (this.stopping) return false;
15812
- const runtime = this.leads.get(report.leadSessionId);
15813
- if (runtime === void 0 || !runtime.watched.has(report.senderSessionId)) return false;
15814
- if (this.ctx.get("workspaceRegistry")?.archivedSessionIds.some((id) => String(id) === report.leadSessionId) ?? false) {
15815
- return false;
15816
- }
15910
+ const runtime = this.reportRuntime(report);
15911
+ if (runtime === void 0) return false;
15817
15912
  const session = this.ctx.sessions.get(toSessionId(report.leadSessionId));
15818
15913
  if (session === void 0) {
15819
15914
  runtime.unsavedReports = [...runtime.unsavedReports, report].slice(-DEVLEAD_REPORT_RETENTION2);
@@ -15847,6 +15942,23 @@ var DevLeadNotificationHub = class {
15847
15942
  this.scheduleFlush(runtime);
15848
15943
  return true;
15849
15944
  }
15945
+ /**
15946
+ * Resolve the lead runtime one report may be queued for: the hub must be
15947
+ * running, the lead indexed and still watching the sender, and the lead not
15948
+ * archived. Shared by the sync queue path and the durable receipt path so
15949
+ * both reject the same relationships.
15950
+ * @param report - report addressed to one lead.
15951
+ * @returns the lead runtime, or undefined when the report must be refused.
15952
+ */
15953
+ reportRuntime(report) {
15954
+ if (this.stopping) return void 0;
15955
+ const runtime = this.leads.get(report.leadSessionId);
15956
+ if (runtime === void 0 || !runtime.watched.has(report.senderSessionId)) return void 0;
15957
+ if (this.ctx.get("workspaceRegistry")?.archivedSessionIds.some((id) => String(id) === report.leadSessionId) ?? false) {
15958
+ return void 0;
15959
+ }
15960
+ return runtime;
15961
+ }
15850
15962
  /**
15851
15963
  * Append one report receipt and fire-and-forget its durability checkpoint.
15852
15964
  * @param session - attached lead Session log receiving the record.
@@ -15909,9 +16021,27 @@ var DevLeadNotificationHub = class {
15909
16021
  * @param agent - live Agent that may lead.
15910
16022
  */
15911
16023
  syncLead(agent) {
16024
+ this.syncSession(agent.session);
16025
+ }
16026
+ /**
16027
+ * Reconcile one Session's durable DevLead state with the hub index, with or
16028
+ * without a live Agent.
16029
+ *
16030
+ * Owned mode/watch/reset records can be appended to a Session that is
16031
+ * attached to the store but has no Agent (for example an archived attach-only
16032
+ * holder whose mode-off the admission path just wrote). Such a Session must
16033
+ * still leave the watch index, or it keeps receiving notifications and can
16034
+ * still be selected as a report target. Subagent Sessions are never indexed.
16035
+ * @param session - Session whose owned record was appended.
16036
+ */
16037
+ syncSession(session) {
15912
16038
  if (this.stopping) return;
15913
- const sessionId = String(agent.id);
15914
- const state = this.stateOf(agent.session);
16039
+ const sessionId = String(session.id);
16040
+ if (session.header.origin === "subagent") {
16041
+ this.removeLead(sessionId);
16042
+ return;
16043
+ }
16044
+ const state = this.stateOf(session);
15915
16045
  if (state === void 0 || !state.enabled) {
15916
16046
  this.removeLead(sessionId);
15917
16047
  return;
@@ -16045,6 +16175,22 @@ var DevLeadNotificationHub = class {
16045
16175
  if (record2 !== void 0 && (record2.type === DEVLEAD_MODE_RECORD_TYPE4 || record2.type === DEVLEAD_WATCH_RECORD_TYPE3 || record2.type === DEVLEAD_RESET_RECORD_TYPE)) {
16046
16176
  const agent = this.ctx.agents.get(session.id);
16047
16177
  if (agent !== void 0) this.syncLead(agent);
16178
+ else if (session.header.origin === "subagent") this.removeLead(sessionId);
16179
+ else {
16180
+ const state = this.stateOf(session);
16181
+ if (state === void 0 || !state.enabled) {
16182
+ this.removeLead(sessionId);
16183
+ } else {
16184
+ queueMicrotask(() => {
16185
+ if (this.stopping) return;
16186
+ try {
16187
+ this.syncSession(session);
16188
+ } catch (error51) {
16189
+ this.ctx.logger.warn(`devlead: could not reconcile a DevLead record after append: ${thrownMessage(error51)}`);
16190
+ }
16191
+ });
16192
+ }
16193
+ }
16048
16194
  }
16049
16195
  if (event.type === "assistant/message") {
16050
16196
  if (this.watchers.has(sessionId)) this.rememberAssistant(sessionId, event.data.message.content);
@@ -16258,7 +16404,15 @@ var DevLeadNotificationHub = class {
16258
16404
  }
16259
16405
  this.persistUnsaved(agent.session, runtime);
16260
16406
  if (runtime.pending.length === 0 && runtime.pendingReports.length === 0) return;
16261
- if (this.hasQueuedNotice(agent)) {
16407
+ let queuedNotice = false;
16408
+ try {
16409
+ queuedNotice = this.hasQueuedNotice(agent);
16410
+ } catch (error51) {
16411
+ this.ctx.logger.warn(
16412
+ `devlead: could not inspect the inbox of lead "${runtime.sessionId}" for a queued notice: ${thrownMessage(error51)}`
16413
+ );
16414
+ }
16415
+ if (queuedNotice) {
16262
16416
  this.scheduleRetry(runtime);
16263
16417
  return;
16264
16418
  }
@@ -16336,9 +16490,22 @@ var DevLeadNotificationHub = class {
16336
16490
  hasQueuedNotice(agent) {
16337
16491
  return [...agent.inbox.nextTurn, ...agent.inbox.nextStep].some((message) => {
16338
16492
  const source = message.source;
16339
- return source.kind === DEVLEAD_MESSAGE_KIND2 && source.form === "notice";
16493
+ return source?.kind === DEVLEAD_MESSAGE_KIND3 && source?.form === "notice";
16340
16494
  });
16341
16495
  }
16496
+ /**
16497
+ * Drop one lead runtime and its watch index without touching durable state.
16498
+ *
16499
+ * Admission uses this when a tombstoned occupant is ignored: an archived (or
16500
+ * otherwise unreleasable) holder must not keep receiving notifications or be
16501
+ * selected as a report target. A later live index (`agent/created` after the
16502
+ * human opens it) re-registers the durable state and reconciles it.
16503
+ * @param leadId - lead Session identity to forget.
16504
+ */
16505
+ forgetLead(leadId) {
16506
+ if (this.stopping) return;
16507
+ this.removeLead(leadId);
16508
+ }
16342
16509
  /**
16343
16510
  * Resume one cold lead Session so it can receive its queued digest.
16344
16511
  * @param runtime - lead runtime row.
@@ -16401,12 +16568,6 @@ async function persistedSessionsOf(ctx, signal) {
16401
16568
  }
16402
16569
 
16403
16570
  // packages/devlead/src/presets.ts
16404
- function recordOf2(value) {
16405
- return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
16406
- }
16407
- function stringField2(value) {
16408
- return typeof value === "string" ? value : "";
16409
- }
16410
16571
  function agentPresetRosterCapabilityOf(ctx) {
16411
16572
  const candidate = ctx.get("agentPresets");
16412
16573
  if (typeof candidate !== "object" || candidate === null) return void 0;
@@ -16418,13 +16579,13 @@ function agentPresetRosterCapabilityOf(ctx) {
16418
16579
  function devLeadAgentPresetsOf(rows, defaultId) {
16419
16580
  const presets = [];
16420
16581
  for (const row of rows) {
16421
- const record2 = recordOf2(row);
16582
+ const record2 = recordOf(row);
16422
16583
  if (record2 === void 0) continue;
16423
- const id = stringField2(record2.id).trim();
16584
+ const id = stringField(record2.id).trim();
16424
16585
  if (id.length === 0) continue;
16425
- const name = stringField2(record2.name).trim();
16426
- const description = stringField2(record2.description).trim();
16427
- const broken = stringField2(record2.broken).trim();
16586
+ const name = stringField(record2.name).trim();
16587
+ const description = stringField(record2.description).trim();
16588
+ const broken = stringField(record2.broken).trim();
16428
16589
  presets.push({
16429
16590
  id,
16430
16591
  default: id === defaultId,
@@ -16710,13 +16871,20 @@ async function devLeadSessionViews(deps, ids, withLog, facts) {
16710
16871
  }
16711
16872
  return views;
16712
16873
  }
16874
+ function workspaceCandidateLabel(workspace) {
16875
+ return `${workspace.id} (${workspace.path})`;
16876
+ }
16713
16877
  async function resolveWorkspaceReference(ctx, reference, signal) {
16714
16878
  const registry2 = ctx.get("workspaceRegistry");
16715
16879
  if (registry2 === void 0) {
16716
16880
  throw new DevLeadError("this Host composes no Workspace registry", "DEVLEAD_WORKSPACE_NOT_FOUND");
16717
16881
  }
16718
16882
  const trimmed = reference.trim();
16719
- const byId = registry2.list().find((workspace) => workspace.id === trimmed);
16883
+ if (trimmed.length === 0) {
16884
+ throw new DevLeadError("a Workspace reference is required", "DEVLEAD_INVALID_INPUT");
16885
+ }
16886
+ const workspaces = registry2.list();
16887
+ const byId = workspaces.find((workspace) => workspace.id === trimmed);
16720
16888
  if (byId !== void 0) return byId;
16721
16889
  try {
16722
16890
  signal?.throwIfAborted();
@@ -16726,8 +16894,17 @@ async function resolveWorkspaceReference(ctx, reference, signal) {
16726
16894
  rethrowIfAborted(error51, signal);
16727
16895
  }
16728
16896
  signal?.throwIfAborted();
16897
+ const byTitle = workspaces.filter((workspace) => workspace.title.trim() === trimmed);
16898
+ const only = byTitle[0];
16899
+ if (only !== void 0 && byTitle.length === 1) return only;
16900
+ if (byTitle.length > 1) {
16901
+ throw new DevLeadError(
16902
+ `Workspace title "${trimmed}" is ambiguous: ${byTitle.length} Workspaces share it: ${byTitle.map(workspaceCandidateLabel).join(", ")}; pass a Workspace id or registered path instead`,
16903
+ "DEVLEAD_WORKSPACE_AMBIGUOUS"
16904
+ );
16905
+ }
16729
16906
  throw new DevLeadError(
16730
- `no Workspace matches "${reference}"; register the repository directory first with devlead_use_workspace`,
16907
+ `no Workspace matches "${reference}"; pass a Workspace id, a registered directory path, or an exact title from devlead_list_workspaces. If the repository is not registered yet, add it with devlead_use_workspace.`,
16731
16908
  "DEVLEAD_WORKSPACE_NOT_FOUND"
16732
16909
  );
16733
16910
  }
@@ -16735,12 +16912,10 @@ async function resolveExactSession(deps, reference) {
16735
16912
  const { ctx } = deps;
16736
16913
  const sessionId = toSessionId2(reference);
16737
16914
  const live = ctx.agents.get(sessionId) !== void 0;
16738
- if (deps.watchedSessions.includes(reference)) return { sessionId, live };
16739
16915
  const session = ctx.sessions.get(sessionId) ?? ctx.agents.get(sessionId)?.session;
16740
- if (session !== void 0) {
16741
- if (session.header.origin === "subagent") return void 0;
16742
- return { sessionId, live };
16743
- }
16916
+ if (session !== void 0 && session.header.origin === "subagent") return void 0;
16917
+ if (deps.watchedSessions.includes(reference)) return { sessionId, live };
16918
+ if (session !== void 0) return { sessionId, live };
16744
16919
  const query = ctx.get("sessionQuery");
16745
16920
  if (query === void 0) return void 0;
16746
16921
  try {
@@ -16795,8 +16970,19 @@ async function resolveSessionReference(deps, reference) {
16795
16970
  var MAX_TIMER_DELAY_MS = 2147483647;
16796
16971
  var MAX_COLD_LEAD_LOG_READS = 64;
16797
16972
  var MAX_ACTIVE_SCAN_UNKNOWN_READS = 64;
16973
+ var REPORT_OUTBOX_PRUNE_INTERVAL_MS = 60 * 60 * 1e3;
16798
16974
  var REHYDRATION_READINESS_TIMEOUT_MS = 2e3;
16799
16975
  var REHYDRATION_READINESS_POLL_MS = 100;
16976
+ var DevLeadInterruptedAdmissionError = class extends DevLeadError {
16977
+ /**
16978
+ * @param message - failure text naming both the admission failure and the
16979
+ * already-committed stop.
16980
+ */
16981
+ constructor(message) {
16982
+ super(message, "DEVLEAD_SESSION_UNAVAILABLE");
16983
+ this.name = "DevLeadInterruptedAdmissionError";
16984
+ }
16985
+ };
16800
16986
  var Config = z2.object({
16801
16987
  notificationBatchMs: z2.number().step(1).min(0).max(MAX_TIMER_DELAY_MS).default(400),
16802
16988
  maxWatchedSessions: z2.number().step(1).min(1).default(DEVLEAD_DEFAULT_MAX_WATCHED2),
@@ -16941,6 +17127,8 @@ var DevLeadService = class extends Service {
16941
17127
  outboxInjection;
16942
17128
  /** Guard against overlapping outbox replay passes. */
16943
17129
  outboxReplaying = false;
17130
+ /** Last outbox retention sweep (open or opportunistic report-write prune). */
17131
+ outboxPrunedAt = 0;
16944
17132
  /**
16945
17133
  * Archived holders whose mode-off could not be written. The durable
16946
17134
  * tombstones live in the outbox domain; this set is the in-process mirror
@@ -16977,7 +17165,11 @@ var DevLeadService = class extends Service {
16977
17165
  this.disposeRehydrationRetry();
16978
17166
  this.outboxInjection?.dispose();
16979
17167
  this.outboxInjection = void 0;
16980
- void this.outbox?.close();
17168
+ const opening = this.outboxOpening;
17169
+ return (async () => {
17170
+ await opening?.catch(() => void 0);
17171
+ await this.outbox?.close();
17172
+ })();
16981
17173
  };
16982
17174
  }.bind(this), "devlead: cold rehydration");
16983
17175
  this.ctx.effect(function* () {
@@ -17316,11 +17508,14 @@ var DevLeadService = class extends Service {
17316
17508
  // Mode
17317
17509
  // ---------------------------------------------------------------------------
17318
17510
  /**
17319
- * Whether DevLead mode is selected for one exact live Agent.
17511
+ * Whether DevLead mode is selected for one exact live Agent. A subagent
17512
+ * Session never qualifies, even when a durable mode record was inherited or
17513
+ * hand-edited into its log.
17320
17514
  * @param agent - candidate lead Agent.
17321
17515
  * @returns whether the durable mode is enabled for that Agent's Session.
17322
17516
  */
17323
17517
  isEnabled(agent) {
17518
+ if (agent.session.header.origin === "subagent") return false;
17324
17519
  if (this.ctx.agents.get(agent.id) !== agent) return false;
17325
17520
  const state = this.projectionHandle.stateOf(agent.session);
17326
17521
  return state.failure === null && state.enabled;
@@ -17348,6 +17543,12 @@ var DevLeadService = class extends Service {
17348
17543
  async setEnabled(agent, enabled, signal) {
17349
17544
  await this.withAdmission(async () => {
17350
17545
  this.assertLive(agent);
17546
+ if (agent.session.header.origin === "subagent") {
17547
+ throw new DevLeadError(
17548
+ "a subagent Session cannot hold DevLead mode; use a top-level Session",
17549
+ "DEVLEAD_INVALID_INPUT"
17550
+ );
17551
+ }
17351
17552
  signal?.throwIfAborted();
17352
17553
  const current = this.projectionHandle.stateOf(agent.session);
17353
17554
  if (current.failure !== null) {
@@ -17360,6 +17561,7 @@ var DevLeadService = class extends Service {
17360
17561
  this.appendResetRecord(agent.session);
17361
17562
  await this.flushDurably(agent.session, `DevLead reset for Session "${agent.id}"`);
17362
17563
  await this.checkpointProjectionCache(agent.session, `DevLead reset for Session "${agent.id}"`);
17564
+ await this.discardLeadReportState(String(agent.id));
17363
17565
  if (this.activeSessionId === String(agent.id)) this.activeSessionId = void 0;
17364
17566
  return;
17365
17567
  }
@@ -17404,8 +17606,7 @@ var DevLeadService = class extends Service {
17404
17606
  this.appendResetRecord(agent.session);
17405
17607
  await this.flushDurably(agent.session, `DevLead reset for Session "${agent.id}"`);
17406
17608
  await this.checkpointProjectionCache(agent.session, `DevLead reset for Session "${agent.id}"`);
17407
- await this.outbox?.dropForLead(String(agent.id));
17408
- this.ignoredArchived.delete(String(agent.id));
17609
+ await this.discardLeadReportState(String(agent.id));
17409
17610
  if (this.activeSessionId === String(agent.id)) this.activeSessionId = void 0;
17410
17611
  });
17411
17612
  }
@@ -17416,6 +17617,17 @@ var DevLeadService = class extends Service {
17416
17617
  appendResetRecord(session) {
17417
17618
  appendPluginRecord2(session, DEVLEAD_RESET_RECORD_TYPE, resetRecord(Date.now()));
17418
17619
  }
17620
+ /**
17621
+ * Discard the queue-side state of one lead's DevLead epoch after a reset
17622
+ * marker: undelivered outbox reports and the in-process archived-holder
17623
+ * tombstone mirror. Both `reset()` and the frozen-fold `setEnabled(false)`
17624
+ * recovery are resets semantically, so they must drop the same rows.
17625
+ * @param sessionId - lead Session identity whose queued reports are discarded.
17626
+ */
17627
+ async discardLeadReportState(sessionId) {
17628
+ await this.outbox?.dropForLead(sessionId);
17629
+ this.ignoredArchived.delete(sessionId);
17630
+ }
17419
17631
  // ---------------------------------------------------------------------------
17420
17632
  // Workspaces
17421
17633
  // ---------------------------------------------------------------------------
@@ -17506,7 +17718,7 @@ var DevLeadService = class extends Service {
17506
17718
  * The returned view is the pre-removal snapshot, so the caller can report
17507
17719
  * what it closed and which Sessions it accounted to.
17508
17720
  * @param agent - exact live lead Agent making the removal.
17509
- * @param workspace - Workspace id or canonical/registered path.
17721
+ * @param workspace - Workspace id, registered path, or exact display title.
17510
17722
  * @param signal - cancellation checked before the registry write.
17511
17723
  * @returns the pre-removal Workspace view and whether a registration was
17512
17724
  * removed (`false` when another actor removed it first).
@@ -17668,6 +17880,74 @@ var DevLeadService = class extends Service {
17668
17880
  signal?.throwIfAborted();
17669
17881
  return await devLeadSessionView(deps, String(resolved.sessionId), true);
17670
17882
  }
17883
+ /**
17884
+ * Read the pending inbox inputs of one Session for the detail tool.
17885
+ *
17886
+ * The inbox is driver-owned: only a live Agent has one, so a cold Session
17887
+ * reports undefined (the caller omits the field) rather than an empty list
17888
+ * that would claim "nothing queued" about a log the Host has not folded.
17889
+ * @param agent - exact live lead Agent.
17890
+ * @param sessionId - exact Session identity (already resolved by the caller).
17891
+ * @param signal - cancellation checked before the read.
17892
+ * @returns queued inputs in queue order, or undefined when the target is not live.
17893
+ * @throws {@link DevLeadError} when the caller is not live.
17894
+ */
17895
+ sessionQueuedInputs(agent, sessionId, signal) {
17896
+ this.assertLive(agent);
17897
+ signal?.throwIfAborted();
17898
+ const target = this.ctx.agents.get(toSessionId3(sessionId));
17899
+ return target === void 0 ? void 0 : queuedInputsOf(target);
17900
+ }
17901
+ /**
17902
+ * Withdraw one queued inbox input this lead Session authored.
17903
+ *
17904
+ * Only the lead's own relay prompts are retractable: a human's queued
17905
+ * instruction is the human's intent, a scheduled wake belongs to the
17906
+ * schedule plugin, and another lead's relay belongs to that lead. The call
17907
+ * is idempotent — an input already consumed or withdrawn reports
17908
+ * `retracted: false`. The target must be live (the inbox is driver-owned)
17909
+ * and cannot be the lead itself.
17910
+ * @param agent - exact live lead Agent.
17911
+ * @param sessionId - target Session reference (id or unique prefix).
17912
+ * @param inputId - Host message identity reported by queuedInputs.
17913
+ * @param signal - cancellation checked before each stage.
17914
+ * @returns the retraction outcome.
17915
+ * @throws {@link DevLeadError} `DEVLEAD_INVALID_INPUT` for a self-addressed
17916
+ * call or an input this lead did not author, `DEVLEAD_SESSION_UNAVAILABLE`
17917
+ * for a cold target, and the usual resolution failures.
17918
+ */
17919
+ async retractQueuedInput(agent, sessionId, inputId, signal) {
17920
+ this.assertReady(agent);
17921
+ signal?.throwIfAborted();
17922
+ const deps = this.viewDeps(agent, signal);
17923
+ const resolved = await resolveSessionReference(deps, sessionId);
17924
+ signal?.throwIfAborted();
17925
+ const targetId = String(resolved.sessionId);
17926
+ if (targetId === String(agent.id)) {
17927
+ throw new DevLeadError(
17928
+ "a DevLead Session cannot retract inputs from its own inbox; ask the human to manage this Session",
17929
+ "DEVLEAD_INVALID_INPUT"
17930
+ );
17931
+ }
17932
+ const target = this.ctx.agents.get(resolved.sessionId);
17933
+ if (target === void 0) {
17934
+ throw new DevLeadError(
17935
+ `Session "${targetId}" is not live, so its inbox cannot be inspected or retracted; open it first`,
17936
+ "DEVLEAD_SESSION_UNAVAILABLE"
17937
+ );
17938
+ }
17939
+ const pending = [...target.inbox.nextTurn, ...target.inbox.nextStep].find((message) => String(message.id) === inputId);
17940
+ if (pending === void 0) return { sessionId: targetId, inputId, retracted: false };
17941
+ if (!isOwnRelay(pending, String(agent.id))) {
17942
+ throw new DevLeadError(
17943
+ `queued input "${inputId}" was not authored by this DevLead Session; only your own relay prompts can be retracted \u2014 human, scheduled, and other producers' inputs are not yours to remove`,
17944
+ "DEVLEAD_INVALID_INPUT"
17945
+ );
17946
+ }
17947
+ const retracted = target.inbox.remove(MessageId(inputId));
17948
+ if (retracted) await this.flushDurably(target.session, `retraction of input "${inputId}"`);
17949
+ return { sessionId: targetId, inputId, retracted };
17950
+ }
17671
17951
  /**
17672
17952
  * Create one ordinary Session in a Workspace and optionally prompt it.
17673
17953
  *
@@ -17763,7 +18043,12 @@ var DevLeadService = class extends Service {
17763
18043
  const prompt = request.prompt?.trim() ?? "";
17764
18044
  const prompted = prompt.length > 0;
17765
18045
  if (prompted) {
17766
- await this.admitPrompt(agent, created.sessionId, prompt, false, signal);
18046
+ await this.admitPrompt(agent, created.sessionId, prompt, {
18047
+ allowResume: false,
18048
+ interrupt: false,
18049
+ interruptInbox: "clear-all",
18050
+ signal
18051
+ });
17767
18052
  }
17768
18053
  const deps = this.viewDeps(agent, signal);
17769
18054
  return {
@@ -17781,11 +18066,20 @@ var DevLeadService = class extends Service {
17781
18066
  /**
17782
18067
  * Admit one prompt into an existing Session, resuming a cold Session and
17783
18068
  * watching it by default.
18069
+ *
18070
+ * `interrupt: true` explicitly replaces the Session's current work: when its
18071
+ * Agent is running, the Host's `workspace/session-stop` providers are asked
18072
+ * to stop the turn (and the subagent/job/schedule work they report) before
18073
+ * the prompt is admitted. The stop is fire-and-forget; the replacement
18074
+ * prompt is queued for the next turn and starts once the aborted turn
18075
+ * converges, so it can never join the cancelling turn. An idle or cold
18076
+ * Session skips the stop entirely.
17784
18077
  * @param agent - exact live lead Agent.
17785
18078
  * @param sessionId - Session id or unique prefix.
17786
18079
  * @param prompt - non-empty prompt text.
17787
- * @param options - optional watch policy (default watches) and cancellation
17788
- * checked between stages.
18080
+ * @param options - watch policy, interrupt policy, and cancellation checked
18081
+ * between stages. Cancellation after an interrupt was requested does not
18082
+ * roll the stop back; the replacement prompt is admitted with it.
17789
18083
  * @returns the admitted prompt receipt.
17790
18084
  * @throws {@link DevLeadError} when the Session is missing, archived, or cannot be resumed.
17791
18085
  */
@@ -17815,11 +18109,16 @@ var DevLeadService = class extends Service {
17815
18109
  const alreadyWatched = this.strictStateOf(agent.session).sessions.includes(String(resolved.sessionId));
17816
18110
  const added = watch && !alreadyWatched;
17817
18111
  if (added) await this.setWatching(agent, resolved.sessionId, true, signal);
17818
- let resumed;
18112
+ let admission;
17819
18113
  try {
17820
- resumed = await this.admitPrompt(agent, resolved.sessionId, text, true, signal);
18114
+ admission = await this.admitPrompt(agent, resolved.sessionId, text, {
18115
+ allowResume: true,
18116
+ interrupt: options.interrupt ?? false,
18117
+ interruptInbox: options.interruptInbox ?? "clear-all",
18118
+ signal
18119
+ });
17821
18120
  } catch (error51) {
17822
- if (added) {
18121
+ if (added && !(error51 instanceof DevLeadInterruptedAdmissionError)) {
17823
18122
  try {
17824
18123
  await this.setWatching(agent, resolved.sessionId, false);
17825
18124
  } catch (compensateError) {
@@ -17833,7 +18132,9 @@ var DevLeadService = class extends Service {
17833
18132
  return {
17834
18133
  sessionId: String(resolved.sessionId),
17835
18134
  watched: this.strictStateOf(agent.session).sessions.includes(String(resolved.sessionId)),
17836
- resumed
18135
+ resumed: admission.resumed,
18136
+ interrupted: admission.interrupted,
18137
+ ...admission.retainedInputs === void 0 ? {} : { retainedInputs: admission.retainedInputs }
17837
18138
  };
17838
18139
  }
17839
18140
  /**
@@ -17955,8 +18256,10 @@ var DevLeadService = class extends Service {
17955
18256
  }
17956
18257
  /** Open the optional durable outbox once and load its archived-holder tombstones. */
17957
18258
  async openOutbox() {
18259
+ if (this.disposed) return;
17958
18260
  if (this.outbox !== void 0 || this.outboxOpening !== void 0) return;
17959
18261
  const run = (async () => {
18262
+ if (this.disposed) return;
17960
18263
  const outbox = await DevLeadReportOutbox.open(this.ctx);
17961
18264
  if (outbox === void 0) {
17962
18265
  this.ctx.logger.debug(
@@ -17964,9 +18267,14 @@ var DevLeadService = class extends Service {
17964
18267
  );
17965
18268
  return;
17966
18269
  }
18270
+ if (this.disposed) {
18271
+ await outbox.close();
18272
+ return;
18273
+ }
17967
18274
  this.outbox = outbox;
17968
18275
  for (const sessionId of outbox.ignoredIds()) this.ignoredArchived.add(sessionId);
17969
18276
  await outbox.prune();
18277
+ this.outboxPrunedAt = Date.now();
17970
18278
  })();
17971
18279
  this.outboxOpening = run;
17972
18280
  try {
@@ -17975,6 +18283,20 @@ var DevLeadService = class extends Service {
17975
18283
  this.outboxOpening = void 0;
17976
18284
  }
17977
18285
  }
18286
+ /**
18287
+ * Run one throttled outbox retention sweep before a report write. Replay
18288
+ * already prunes on every pass; this keeps the seven-day horizon enforced on
18289
+ * a Host whose only outbox traffic is report writes (for example a cold lead
18290
+ * with `wakeColdSession: false`).
18291
+ */
18292
+ async pruneOutboxOpportunistically() {
18293
+ const outbox = this.outbox;
18294
+ if (outbox === void 0) return;
18295
+ const now = Date.now();
18296
+ if (this.outboxPrunedAt !== 0 && now - this.outboxPrunedAt < REPORT_OUTBOX_PRUNE_INTERVAL_MS) return;
18297
+ this.outboxPrunedAt = now;
18298
+ await outbox.prune(now);
18299
+ }
17978
18300
  /**
17979
18301
  * Replay durable outbox rows whose lead is now attachable, then clear each
17980
18302
  * row only after its Session-log receipt was flushed.
@@ -17984,6 +18306,7 @@ var DevLeadService = class extends Service {
17984
18306
  this.outboxReplaying = true;
17985
18307
  try {
17986
18308
  await this.outbox.prune();
18309
+ this.outboxPrunedAt = Date.now();
17987
18310
  const archived = new Set(
17988
18311
  (this.ctx.get("workspaceRegistry")?.archivedSessionIds ?? []).map((id) => String(id))
17989
18312
  );
@@ -18023,6 +18346,7 @@ var DevLeadService = class extends Service {
18023
18346
  * @returns the child-facing receipt with durability status.
18024
18347
  */
18025
18348
  async deliverReport(report) {
18349
+ await this.pruneOutboxOpportunistically();
18026
18350
  const outboxed = this.outbox === void 0 ? false : await this.outbox.put(report);
18027
18351
  if (outboxed && this.outbox !== void 0) {
18028
18352
  let delivered = false;
@@ -18110,9 +18434,12 @@ var DevLeadService = class extends Service {
18110
18434
  * for a cold lead by the hub), then the lead is woken through the same
18111
18435
  * coalesced notice path as turn notifications. This method returns after the
18112
18436
  * receipt/queue decision and never waits for the lead's next turn, so the
18113
- * reporter is not blocked. Same-message reports in one turn are idempotent;
18114
- * more than {@link DEVLEAD_REPORT_MAX_PER_TURN} distinct reports in one turn
18115
- * are refused.
18437
+ * reporter is not blocked. Same-kind same-message reports in one turn are
18438
+ * idempotent (the same text under a different kind is a new report);
18439
+ * more than {@link DEVLEAD_REPORT_MAX_PER_TURN} distinct non-question reports
18440
+ * in one turn are refused. `question` reports are the answer-seeking channel
18441
+ * used by the watched-Session question router, so they are exempt from that
18442
+ * progress budget.
18116
18443
  * @param agent - exact live reporter Agent.
18117
18444
  * @param request - report text, kind, and optional summary.
18118
18445
  * @param signal - cancellation checked before durable work.
@@ -18150,7 +18477,7 @@ var DevLeadService = class extends Service {
18150
18477
  const kind = request.kind ?? "progress";
18151
18478
  if (!isDevLeadReportKind2(kind)) {
18152
18479
  throw new DevLeadError(
18153
- `report kind ${JSON.stringify(kind)} is not recognized; use progress, blocked, decision, or fyi`,
18480
+ `report kind ${JSON.stringify(kind)} is not recognized; use progress, blocked, decision, question, or fyi`,
18154
18481
  "DEVLEAD_INVALID_INPUT"
18155
18482
  );
18156
18483
  }
@@ -18168,11 +18495,13 @@ var DevLeadService = class extends Service {
18168
18495
  if (previous === void 0 || previous.turn !== turn || previous.leadSessionId !== leadSessionId) {
18169
18496
  this.reportState.set(reporterId, state);
18170
18497
  }
18171
- const duplicate = state.messages.get(message);
18498
+ const dedupKey = `${kind}\0${message}`;
18499
+ const duplicate = state.messages.get(dedupKey);
18172
18500
  if (duplicate !== void 0) return duplicate;
18173
- if (state.messages.size >= DEVLEAD_REPORT_MAX_PER_TURN) {
18501
+ const progressCount = [...state.messages.values()].filter((entry) => entry.report.kind !== "question").length;
18502
+ if (kind !== "question" && progressCount >= DEVLEAD_REPORT_MAX_PER_TURN) {
18174
18503
  throw new DevLeadError(
18175
- `this Session already sent ${DEVLEAD_REPORT_MAX_PER_TURN} reports in turn ${turn}; wait for the next turn or let the DevLead continue`,
18504
+ `this Session already sent ${DEVLEAD_REPORT_MAX_PER_TURN} non-question reports in turn ${turn}; wait for the next turn or let the DevLead continue`,
18176
18505
  "DEVLEAD_REPORT_RATE_LIMITED"
18177
18506
  );
18178
18507
  }
@@ -18199,7 +18528,7 @@ var DevLeadService = class extends Service {
18199
18528
  });
18200
18529
  signal?.throwIfAborted();
18201
18530
  const receipt = await this.deliverReport(report);
18202
- state.messages.set(message, receipt);
18531
+ state.messages.set(dedupKey, receipt);
18203
18532
  if (this.reportState.size > 512) {
18204
18533
  const oldest = this.reportState.keys().next().value;
18205
18534
  if (oldest !== void 0) this.reportState.delete(oldest);
@@ -18207,13 +18536,15 @@ var DevLeadService = class extends Service {
18207
18536
  return receipt;
18208
18537
  }
18209
18538
  /**
18210
- * Read the retained mid-turn report digest of one live lead.
18539
+ * Read the retained mid-turn report digest of one live lead. Like
18540
+ * {@link notifications}, this is an audit read: a disabled lead may still
18541
+ * inspect what it retained while the mode was on.
18211
18542
  * @param agent - exact live lead Agent.
18212
18543
  * @param options - optional newest-row limit, defaulting to 20.
18213
18544
  * @returns detached reports, oldest first.
18214
18545
  */
18215
18546
  reports(agent, options = {}) {
18216
- this.assertReady(agent);
18547
+ this.assertLive(agent);
18217
18548
  const state = this.strictStateOf(agent.session);
18218
18549
  const limit = options.limit ?? 20;
18219
18550
  const effective = Number.isSafeInteger(limit) && limit > 0 ? limit : 20;
@@ -18336,13 +18667,17 @@ var DevLeadService = class extends Service {
18336
18667
  }
18337
18668
  /**
18338
18669
  * Find an enabled Session other than `agent`, releasing archived holders
18339
- * first. This is the admission check under the global mutex.
18670
+ * first. This is the admission check under the global mutex: it runs the
18671
+ * strict occupancy scan, so an unverifiable persisted corpus refuses the
18672
+ * enable instead of admitting a possible second lead.
18340
18673
  * @param agent - Session requesting the mode.
18341
18674
  * @param signal - caller cancellation checked around the scan and releases.
18342
18675
  * @returns the blocking occupant, or undefined when the mode is free.
18676
+ * @throws {@link DevLeadError} `DEVLEAD_SESSION_UNAVAILABLE` when occupancy
18677
+ * cannot be verified.
18343
18678
  */
18344
18679
  async blockingOccupant(agent, signal) {
18345
- const active = await this.scanActiveSessions(signal);
18680
+ const active = await this.scanActiveSessions(signal, true, true);
18346
18681
  const blockers = [];
18347
18682
  for (const occupant of active) {
18348
18683
  if (occupant.sessionId === String(agent.id)) continue;
@@ -18361,6 +18696,8 @@ var DevLeadService = class extends Service {
18361
18696
  if (this.ignoredArchived.has(occupant.sessionId)) {
18362
18697
  if (await this.releaseActiveOccupant(occupant, "duplicate")) {
18363
18698
  await this.rememberReleased(occupant.sessionId);
18699
+ } else {
18700
+ await this.rememberIgnored(occupant.sessionId);
18364
18701
  }
18365
18702
  continue;
18366
18703
  }
@@ -18377,11 +18714,21 @@ var DevLeadService = class extends Service {
18377
18714
  * are folded exactly, `inactive` rows are skipped, and rows the cache cannot
18378
18715
  * classify (including a Host with no cache) are folded up to a bounded read
18379
18716
  * budget. The budget only limits an arbitrarily large unknown history and is
18380
- * reported; positively active rows are never skipped.
18717
+ * reported.
18718
+ *
18719
+ * `strict` makes the scan safe for admission: a corpus listing failure, or a
18720
+ * log read failure for a row the cache positively classified as active, is a
18721
+ * hard `DEVLEAD_SESSION_UNAVAILABLE` instead of a best-effort skip, because
18722
+ * admitting on an unverifiable corpus could create a second active lead.
18723
+ * Reconciliation and status remain best-effort.
18381
18724
  * @param signal - caller cancellation threaded through query reads.
18725
+ * @param includePersisted - whether the persisted corpus is scanned.
18726
+ * @param strict - whether unknown occupancy is a hard error (admission only).
18382
18727
  * @returns every enabled Session, deduplicated by id.
18728
+ * @throws {@link DevLeadError} `DEVLEAD_SESSION_UNAVAILABLE` when `strict` is
18729
+ * set and a cache-positive candidate or the corpus listing cannot be read.
18383
18730
  */
18384
- async scanActiveSessions(signal, includePersisted = true) {
18731
+ async scanActiveSessions(signal, includePersisted = true, strict = false) {
18385
18732
  const active = /* @__PURE__ */ new Map();
18386
18733
  const seen = /* @__PURE__ */ new Set();
18387
18734
  const archived = new Set(
@@ -18391,6 +18738,7 @@ var DevLeadService = class extends Service {
18391
18738
  const sessionId = String(session.id);
18392
18739
  if (seen.has(sessionId)) return;
18393
18740
  seen.add(sessionId);
18741
+ if (session.header.origin === "subagent") return;
18394
18742
  const state = this.projectionHandle.stateOf(session);
18395
18743
  if (state.failure !== null || !state.enabled) return;
18396
18744
  const title = this.ctx.get("sessionTitle")?.get(session)?.title;
@@ -18416,7 +18764,9 @@ var DevLeadService = class extends Service {
18416
18764
  records = await query.listSessions(signal);
18417
18765
  } catch (error51) {
18418
18766
  if (signal?.aborted === true) throw error51;
18419
- this.ctx.logger.warn(`devlead: could not list persisted Sessions for global DevLead admission: ${thrownMessage(error51)}`);
18767
+ const detail = `could not verify global DevLead occupancy: listing persisted Sessions failed: ${thrownMessage(error51)}`;
18768
+ if (strict) throw new DevLeadError(detail, "DEVLEAD_SESSION_UNAVAILABLE");
18769
+ this.ctx.logger.warn(`devlead: ${detail}`);
18420
18770
  return [...active.values()];
18421
18771
  }
18422
18772
  const cache = projectionCacheOf(this.ctx);
@@ -18427,6 +18777,10 @@ var DevLeadService = class extends Service {
18427
18777
  signal?.throwIfAborted();
18428
18778
  const sessionId = String(record2.header.id);
18429
18779
  if (seen.has(sessionId)) continue;
18780
+ if (record2.header.origin === "subagent") {
18781
+ seen.add(sessionId);
18782
+ continue;
18783
+ }
18430
18784
  const prefilter = cache === void 0 ? "unknown" : devLeadActivePrefilterOf(cache, record2.header);
18431
18785
  if (prefilter === "inactive") {
18432
18786
  seen.add(sessionId);
@@ -18441,17 +18795,26 @@ var DevLeadService = class extends Service {
18441
18795
  }
18442
18796
  seen.add(sessionId);
18443
18797
  let events;
18798
+ let inheritedEventCount = 0;
18444
18799
  try {
18445
- events = (await query.readSession(record2.header.id)).events;
18800
+ const snapshot = await query.readSession(record2.header.id);
18801
+ events = snapshot.events;
18802
+ inheritedEventCount = snapshot.inheritedEventCount;
18446
18803
  } catch (error51) {
18447
18804
  if (signal?.aborted === true) throw error51;
18805
+ if (strict && prefilter === "active") {
18806
+ throw new DevLeadError(
18807
+ `could not verify global DevLead occupancy: persisted Session "${sessionId}" is cached as an active DevLead but its log could not be read: ${thrownMessage(error51)}`,
18808
+ "DEVLEAD_SESSION_UNAVAILABLE"
18809
+ );
18810
+ }
18448
18811
  if (!warnedRead) {
18449
18812
  warnedRead = true;
18450
18813
  this.ctx.logger.warn(`devlead: could not read a persisted Session log for global DevLead admission: ${thrownMessage(error51)}`);
18451
18814
  }
18452
18815
  continue;
18453
18816
  }
18454
- let state = emptyDevLeadProjectionState();
18817
+ let state = emptyDevLeadProjectionState(inheritedEventCount);
18455
18818
  for (const event of events) {
18456
18819
  state = applyDevLeadProjection(state, event);
18457
18820
  if (state.failure !== null) break;
@@ -18539,6 +18902,7 @@ var DevLeadService = class extends Service {
18539
18902
  /** Remember one ignored archived holder in memory and, when available, durably. */
18540
18903
  async rememberIgnored(sessionId) {
18541
18904
  this.ignoredArchived.add(sessionId);
18905
+ this.hub?.forgetLead(sessionId);
18542
18906
  await this.outbox?.rememberIgnored(sessionId);
18543
18907
  }
18544
18908
  /** Forget one ignored-holder tombstone after a successful release. */
@@ -18591,6 +18955,8 @@ var DevLeadService = class extends Service {
18591
18955
  if (this.ignoredArchived.has(occupant.sessionId)) {
18592
18956
  if (await this.releaseActiveOccupant(occupant, "duplicate")) {
18593
18957
  await this.rememberReleased(occupant.sessionId);
18958
+ } else {
18959
+ await this.rememberIgnored(occupant.sessionId);
18594
18960
  }
18595
18961
  continue;
18596
18962
  }
@@ -18731,8 +19097,11 @@ var DevLeadService = class extends Service {
18731
19097
  unknownReads += 1;
18732
19098
  }
18733
19099
  let events;
19100
+ let inheritedEventCount = 0;
18734
19101
  try {
18735
- events = (await query.readSession(record2.header.id)).events;
19102
+ const snapshot = await query.readSession(record2.header.id);
19103
+ events = snapshot.events;
19104
+ inheritedEventCount = snapshot.inheritedEventCount;
18736
19105
  } catch (error51) {
18737
19106
  if (!warnedRead) {
18738
19107
  warnedRead = true;
@@ -18740,7 +19109,7 @@ var DevLeadService = class extends Service {
18740
19109
  }
18741
19110
  continue;
18742
19111
  }
18743
- let state = emptyDevLeadProjectionState();
19112
+ let state = emptyDevLeadProjectionState(inheritedEventCount);
18744
19113
  for (const event of events) {
18745
19114
  state = applyDevLeadProjection(state, event);
18746
19115
  if (state.failure !== null) break;
@@ -18904,7 +19273,7 @@ var DevLeadService = class extends Service {
18904
19273
  * Resolve the Workspace one created Session should join: the requested
18905
19274
  * reference, or the lead's own directory registered on demand.
18906
19275
  * @param agent - exact live lead Agent.
18907
- * @param reference - requested Workspace id or path.
19276
+ * @param reference - requested Workspace id, registered path, or exact title.
18908
19277
  * @returns the target Workspace.
18909
19278
  */
18910
19279
  async createTargetWorkspace(agent, reference) {
@@ -19048,19 +19417,33 @@ var DevLeadService = class extends Service {
19048
19417
  }
19049
19418
  /**
19050
19419
  * Admit one lead-authored prompt into a Session, resuming a cold Session.
19420
+ *
19421
+ * `interrupt` is evaluated only against a live running Agent. The Host's
19422
+ * `workspace/session-stop` providers are the same fan-out archive
19423
+ * `stopActivity` uses; they cancel the turn and stop the Session's reported
19424
+ * subagent/job/schedule work. The stop is fire-and-forget: `followup` is
19425
+ * admitted immediately afterwards, and the Agent reclassifies a wake after
19426
+ * an aborted phase to the next turn and latches it until the aborted
19427
+ * activity converges, so the prompt cannot enter the cancelling turn. No
19428
+ * settlement wait is needed. The inbox retention restore is best-effort: a
19429
+ * failed restore is a warning, and the replacement prompt is admitted anyway
19430
+ * because the stop cannot be rolled back.
19051
19431
  * @param leadAgent - exact live lead Agent.
19052
19432
  * @param sessionId - target Session identity.
19053
19433
  * @param text - non-empty prompt text.
19054
- * @param allowResume - whether a cold Session may be resumed.
19055
- * @param signal - cancellation checked before the resume and the admission.
19056
- * @returns whether the Host resumed a cold Session.
19434
+ * @param options - resume policy, interrupt policy, and cancellation checked
19435
+ * before each stage. Once an interrupt is requested, cancellation does not
19436
+ * roll it back; the replacement prompt is admitted with the stop.
19437
+ * @returns whether the Host resumed a cold Session and whether it was asked
19438
+ * to interrupt a running turn.
19057
19439
  */
19058
- async admitPrompt(leadAgent, sessionId, text, allowResume, signal) {
19440
+ async admitPrompt(leadAgent, sessionId, text, options) {
19441
+ const signal = options.signal;
19059
19442
  signal?.throwIfAborted();
19060
19443
  let target = this.ctx.agents.get(sessionId);
19061
19444
  let resumed = false;
19062
19445
  if (target === void 0) {
19063
- if (!allowResume) {
19446
+ if (!options.allowResume) {
19064
19447
  throw new DevLeadError(`Session "${sessionId}" is not live`, "DEVLEAD_SESSION_UNAVAILABLE");
19065
19448
  }
19066
19449
  const controller = this.ctx.get("sessionController");
@@ -19090,16 +19473,58 @@ var DevLeadService = class extends Service {
19090
19473
  signal?.throwIfAborted();
19091
19474
  }
19092
19475
  signal?.throwIfAborted();
19476
+ let interrupted = false;
19477
+ let retainedInputs;
19478
+ if (options.interrupt && target.status === "running") {
19479
+ interrupted = true;
19480
+ const kept = keptInputsOf(target, String(leadAgent.id), options.interruptInbox);
19481
+ await this.stopSessionActivity(sessionId);
19482
+ if (options.interruptInbox !== "clear-all") {
19483
+ try {
19484
+ retainedInputs = restoreInputs(target, kept);
19485
+ } catch (error51) {
19486
+ this.ctx.logger.warn(
19487
+ `devlead: could not restore queued input for Session "${sessionId}" after the interrupt: ` + thrownMessage(error51)
19488
+ );
19489
+ }
19490
+ }
19491
+ }
19093
19492
  try {
19094
19493
  target.followup(createDevLeadPromptMessage(text, leadAgent));
19095
19494
  } catch (error51) {
19096
- throw new DevLeadError(
19097
- `could not admit a prompt into Session "${sessionId}": ${thrownMessage(error51)}`,
19098
- "DEVLEAD_SESSION_UNAVAILABLE"
19099
- );
19495
+ const detail = `could not admit a prompt into Session "${sessionId}": ${thrownMessage(error51)}`;
19496
+ if (interrupted) {
19497
+ throw new DevLeadInterruptedAdmissionError(
19498
+ `${detail}; the running work was already asked to stop, so the Session keeps its watch \u2014 retry the prompt`
19499
+ );
19500
+ }
19501
+ throw new DevLeadError(detail, "DEVLEAD_SESSION_UNAVAILABLE");
19100
19502
  }
19101
19503
  await this.flushDurably(target.session, `prompt into Session "${sessionId}"`);
19102
- return resumed;
19504
+ return { resumed, interrupted, ...retainedInputs === void 0 ? {} : { retainedInputs } };
19505
+ }
19506
+ /**
19507
+ * Ask every composed `workspace/session-stop` provider to stop one Session's
19508
+ * running work. This is the same fan-out archive `stopActivity` uses, without
19509
+ * the archive write: the Agent registry cancels the running turn, the job
19510
+ * registry kills owned jobs, the subagent runtime cancels running
19511
+ * descendants, and the schedule plugin removes active schedule rows.
19512
+ * Provider failures are logged and never block the replacement prompt; the
19513
+ * cancellation itself is fire-and-forget, so this method does not wait for
19514
+ * the stopped work to settle.
19515
+ * @param sessionId - Session whose running work should stop.
19516
+ */
19517
+ async stopSessionActivity(sessionId) {
19518
+ try {
19519
+ await this.ctx.parallel("workspace/session-stop", { sessionId });
19520
+ } catch (error51) {
19521
+ const failures = error51 instanceof AggregateError ? error51.errors : [error51];
19522
+ for (const failure of failures) {
19523
+ this.ctx.logger.warn(
19524
+ `devlead: stopping Session "${String(sessionId)}" for prompt interrupt failed: ${thrownMessage(failure)}`
19525
+ );
19526
+ }
19527
+ }
19103
19528
  }
19104
19529
  /**
19105
19530
  * Replace one lead's watch set with one Session added or removed.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yankeguo/dsh-devlead",
3
- "version": "0.2.6",
3
+ "version": "0.3.0-rc.2",
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",
@@ -11,6 +11,7 @@
11
11
  "./package.json": "./package.json"
12
12
  },
13
13
  "files": [
14
+ "LICENSE",
14
15
  "lib",
15
16
  "locale/*.json",
16
17
  "README.md"
@@ -43,7 +44,7 @@
43
44
  }
44
45
  },
45
46
  "dependencies": {
46
- "@yankeguo/dsh-devlead-protocol": "0.2.6"
47
+ "@yankeguo/dsh-devlead-protocol": "0.3.0-rc.2"
47
48
  },
48
49
  "engines": {
49
50
  "dsh": ">=0.2.2-rc.1 <0.3.0"