@linxin666/dsh-client-ui-task-board 0.4.19 → 0.4.20

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 (43) hide show
  1. package/README.i18n.yaml +2 -2
  2. package/README.md +1 -1
  3. package/README.zh.md +1 -1
  4. package/lib/client.js +179 -60
  5. package/lib/client.js.map +1 -1
  6. package/lib/index.js +457 -70
  7. package/lib/types/client/board/TaskForm.d.ts +3 -1
  8. package/lib/types/client/index.d.ts +7 -1
  9. package/lib/types/client/native-panel.d.ts +1 -1
  10. package/lib/types/client/seats.d.ts +36 -2
  11. package/lib/types/client/settings-form.d.ts +2 -0
  12. package/lib/types/core/controller.d.ts +1 -1
  13. package/lib/types/core/extension.d.ts +135 -1
  14. package/lib/types/core/session-reuse.d.ts +46 -13
  15. package/lib/types/core/tasks.d.ts +2 -2
  16. package/lib/types/host/agent-tools.d.ts +7 -2
  17. package/lib/types/host/extension-registry.d.ts +30 -1
  18. package/lib/types/host-ledger.d.ts +86 -1
  19. package/lib/types/host-runner.d.ts +20 -1
  20. package/lib/types/host-service.d.ts +59 -14
  21. package/lib/types/protocol.d.ts +9 -1
  22. package/package.json +1 -1
  23. package/src/client/board/ExecutionLog.tsx +9 -2
  24. package/src/client/board/NewTaskModal.tsx +88 -3
  25. package/src/client/board/TaskDetail.tsx +18 -11
  26. package/src/client/board/TaskForm.tsx +13 -2
  27. package/src/client/board.module.css +67 -1
  28. package/src/client/index.ts +3 -0
  29. package/src/client/locales.ts +7 -6
  30. package/src/client/native-panel.tsx +2 -1
  31. package/src/client/seats.tsx +32 -4
  32. package/src/client/service.ts +3 -0
  33. package/src/client/settings-form.ts +21 -2
  34. package/src/core/controller.ts +9 -3
  35. package/src/core/extension.ts +138 -1
  36. package/src/core/session-reuse.ts +58 -21
  37. package/src/core/tasks.ts +2 -2
  38. package/src/host/agent-tools.ts +8 -2
  39. package/src/host/extension-registry.ts +121 -2
  40. package/src/host-ledger.ts +252 -18
  41. package/src/host-runner.ts +44 -5
  42. package/src/host-service.ts +180 -37
  43. package/src/protocol.ts +9 -1
@@ -22,10 +22,21 @@ import { executionSummaryOf } from './core/execution-summary.ts'
22
22
 
23
23
  /**
24
24
  * Host services needed to validate a task's workspace before creating a
25
- * session, and to resolve the workspace an unpinned card runs in.
25
+ * session, resolve the workspace an unpinned card runs in, and tell a reusable
26
+ * conversation apart from an archived one.
26
27
  */
27
28
  export interface TaskBoardWorkspaceRegistry {
28
29
  list(): readonly Workspace[]
30
+ /**
31
+ * The registry-global archive set, in archive order (issue #2068). A Session
32
+ * in it cannot run a turn, so the reuse rule refuses it and the launch starts
33
+ * a fresh conversation instead of settling as `blocked`.
34
+ *
35
+ * Optional: a deployment whose registry face does not report an archive set
36
+ * offers no archive action to defend against, and reuse keeps its
37
+ * pre-archive-set behavior.
38
+ */
39
+ archivedSessionIds?: readonly string[]
29
40
  }
30
41
 
31
42
  /**
@@ -224,6 +235,14 @@ export interface PromptDescendant {
224
235
 
225
236
  /** Execution-shape context appended to the launched task's prompt. */
226
237
  export interface PromptContext {
238
+ /**
239
+ * The launch gate's section: what a provider that kept this run local needs
240
+ * the session to know before it reads the card. Injected on the same path as
241
+ * the tag prefixes and ahead of them, so it opens the prompt. Absent on every
242
+ * run nobody intercepted, which is what keeps the prompt byte-for-byte what
243
+ * it was before the seam existed.
244
+ */
245
+ launchPreamble?: string
227
246
  /**
228
247
  * The card's outstanding descendants. Present exactly when this run is an
229
248
  * autonomous dispatch: the Host opens no session for them, so this session
@@ -311,9 +330,13 @@ export function promptText(task: TaskRecord, context: PromptContext = {}): strin
311
330
  const handoverPreamble = handover === undefined || handover.references.length === 0
312
331
  ? undefined
313
332
  : `交接包引用(来自任务看板续接卡片,冻结于 ${new Date(handover.bundledAt).toISOString()}):\n${handover.references.map(reference => `- ${reference}`).join('\n')}`
314
- // Tag prompts come first: they are the run's standing context (business line,
315
- // output location), the handover preamble is a per-card note, the scheduled
316
- // section states why this run exists, and the task body is the instruction.
333
+ // The launch gate's section comes first (it states what this run is), then the
334
+ // tag prompts, which are the run's standing context (business line, output
335
+ // location); the handover preamble is a per-card note, the scheduled section
336
+ // states why this run exists, and the task body is the instruction.
337
+ // The launch gate's section opens the prompt: it states what this run IS
338
+ // before the board says anything about it.
339
+ const launchPreamble = launchPromptPreamble(context)
317
340
  const tagPreamble = tagPromptPreamble(task)
318
341
  // The attachment section names the readable paths of the card's files. It
319
342
  // is a section of its own, never folded into the handover preamble.
@@ -324,7 +347,7 @@ export function promptText(task: TaskRecord, context: PromptContext = {}): strin
324
347
  // The rework section sits last: it is the most specific instruction of this
325
348
  // run and therefore the one read immediately before the card body.
326
349
  const reworkSection = reworkPromptPreamble(context)
327
- const preambles = [tagPreamble, attachmentSection, handoverSection, schedulePreamble, runPreamble, reworkSection]
350
+ const preambles = [launchPreamble, tagPreamble, attachmentSection, handoverSection, schedulePreamble, runPreamble, reworkSection]
328
351
  .filter((part): part is string => part !== undefined)
329
352
  const preamble = preambles.length === 0 ? undefined : preambles.join('\n\n')
330
353
  const freeze = task.freeze
@@ -336,6 +359,22 @@ export function promptText(task: TaskRecord, context: PromptContext = {}): strin
336
359
  return preamble === undefined ? declaration : `${preamble}\n\n${declaration}`
337
360
  }
338
361
 
362
+ /**
363
+ * Build the launch-gate section of the execution prompt.
364
+ *
365
+ * A provider that answered `local` keeps the board's own execution and only
366
+ * adds context for it, so its text is a preamble like the tag prompts: same
367
+ * injection path, same placement rules, and the same delimiter neutralization —
368
+ * a preamble a provider composed from card text can therefore not counterfeit
369
+ * the freeze wrap either. A blank preamble yields undefined and the prompt is
370
+ * exactly what an unintercepted run produces.
371
+ */
372
+ function launchPromptPreamble(context: PromptContext): string | undefined {
373
+ const preamble = context.launchPreamble?.trim()
374
+ if (preamble === undefined || preamble === '') return undefined
375
+ return escapeProvenanceDelimiter(preamble)
376
+ }
377
+
339
378
  /**
340
379
  * Build the tag section of the execution prompt (issue #1521). Only tags with
341
380
  * a non-blank `promptPrefix` contribute; a task whose tags are all bare names
@@ -3,7 +3,7 @@ import { DEFAULT_RUN_LAUNCH_WIDTH, normalizeRunLaunchWidth } from './core/launch
3
3
  import { DEFAULT_SPEND_BUDGET_TOKENS, spendCapMessage, spendCapReached } from './core/spend-budget.ts'
4
4
  import { usedTokensToday } from './host-spend.ts'
5
5
  import { DEFAULT_SESSION_POLL_SECONDS, normalizeSessionPollSeconds, sessionPollMs } from './core/poll-cadence.ts'
6
- import { reusableSessionId } from './core/session-reuse.ts'
6
+ import { newestSettledSessionId, reusableSessionId } from './core/session-reuse.ts'
7
7
  import { LaunchAdmissionQueue, type QueuedLaunch } from './host/launch-admission.ts'
8
8
  import { HostTaskLedger, type OpenedRun, type OpenExecutionReference } from './host-ledger.ts'
9
9
  import { HostExecutionRunner, SessionLaunchError, type GatewayPeer, type SessionCommandDispatcher, type SessionSummary, type TaskBoardWorkspaceRegistry } from './host-runner.ts'
@@ -13,8 +13,8 @@ import { PowerInhibitor } from './power-inhibitor.ts'
13
13
  import { TASK_BOARD_SCHEMA_VERSION, type TaskBoardAction, type TaskBoardEventPayload, type TaskBoardSnapshot } from './protocol.ts'
14
14
  import { projectSnapshotForWire } from './core/wire-projection.ts'
15
15
  import type { CardDefaults } from './core/card-defaults.ts'
16
- import { TaskBoardExtensionRegistry } from './host/extension-registry.ts'
17
- import type { TaskBoardExtension } from './core/extension.ts'
16
+ import { TaskBoardExtensionRegistry, type TaskBoardExtensionLogger } from './host/extension-registry.ts'
17
+ import type { TaskBoardExtension, TaskBoardLaunchTrigger } from './core/extension.ts'
18
18
  import { isTaskPermission, normalizeTargetId, type ExecutionOutcome, type ExecutionSummary, type ScheduleMode, type TaskRecord, type TaskStatus } from './core/tasks.ts'
19
19
  import type { ModelCatalogView } from './core/model-catalog.ts'
20
20
  import type { TaskPermission } from './core/handover.ts'
@@ -58,11 +58,32 @@ const ABANDONED_LAUNCH_REASON = 'host stopped before this execution started'
58
58
 
59
59
  /**
60
60
  * Why a rework could not launch: it redoes work in the card's own
61
- * conversation, so a session the Host cannot continue means there is nothing to
62
- * send the reviewer's instructions into. Starting a fresh conversation instead
63
- * would hand those instructions to an agent that never saw the work.
61
+ * conversation, so a session the Host cannot confirm as reachable means there is
62
+ * nothing to send the reviewer's instructions into. Starting a fresh
63
+ * conversation instead would hand those instructions to an agent that never saw
64
+ * the work. "Could not be confirmed" also covers an unreadable roster, which is
65
+ * neither "idle" nor "gone".
64
66
  */
65
- const REWORK_SESSION_REASON = 'rework: the card\'s previous execution session is not present and idle in the host session roster, so there is no conversation to send the rework instructions into'
67
+ const REWORK_SESSION_REASON = 'rework: the card\'s previous execution session could not be confirmed as present and idle in the host session roster, so there is no conversation to send the rework instructions into'
68
+
69
+ /**
70
+ * Why a rework could not launch into an archived conversation (issue #2068).
71
+ * The session still exists, so the generic reason would misdirect: the operator
72
+ * has to unarchive that conversation before the rework can be sent into it.
73
+ * @param sessionId - the archived conversation the rework addressed.
74
+ * @returns the refusal the operator reads on the card.
75
+ */
76
+ const reworkArchivedReason = (sessionId: string): string =>
77
+ 'rework: the card\'s previous execution session ' + sessionId
78
+ + ' is archived, so the Host will not run a turn in it; unarchive that session and start the rework again'
79
+
80
+ /** What a launch may do with the card's previous conversation. */
81
+ interface ReuseDecision {
82
+ /** The session this launch continues in; absent when it starts fresh. */
83
+ sessionId?: string
84
+ /** The newest settled session is in the archive set, so reuse refused it. */
85
+ archivedSessionId?: string
86
+ }
66
87
 
67
88
  /**
68
89
  * The host model catalog one run group freezes, read once for the whole group.
@@ -338,6 +359,13 @@ export class TaskBoardHostService {
338
359
  * Absent means "not proven legacy", which keeps the force exactly as it is.
339
360
  */
340
361
  legacyAgentTeams?: () => boolean
362
+ /**
363
+ * Logging seat the extension registry writes to. Absent keeps the process
364
+ * console, which is what a deployment without an opinion wants; a
365
+ * deployment (or a test) that collects the board's own warnings and errors
366
+ * injects its own.
367
+ */
368
+ extensionLogger?: TaskBoardExtensionLogger
341
369
  } = {}) {
342
370
  this.ledger = options.ledger ?? new HostTaskLedger(undefined, undefined, {
343
371
  sessionDefaultPermission: options.sessionDefaultPermission,
@@ -377,7 +405,14 @@ export class TaskBoardHostService {
377
405
  this.applyBoardAction(crypto.randomUUID(), { kind: 'rework', taskId, instructions }, initiator)
378
406
  },
379
407
  now: this.now,
408
+ onPublished: () => { this.emit() },
409
+ ...(options.extensionLogger === undefined ? {} : { logger: options.extensionLogger }),
380
410
  })
411
+ // The board's single launch gate. Every run — manual, rerun, rework, a due
412
+ // schedule, the run tool — is opened by the ledger, so attaching the gate
413
+ // there is what makes one point cover all of them, before a session exists
414
+ // and before an execution record is written.
415
+ this.ledger.setLaunchGate((task, context) => this.extensions.interceptLaunch(task, context))
381
416
  installStreamErrorGuards()
382
417
  this.ledger.subscribe(() => {
383
418
  this.syncPowerReasons()
@@ -482,6 +517,7 @@ export class TaskBoardHostService {
482
517
  // refuse an oversized selection before it uploads anything.
483
518
  ...(this.attachmentStore() === undefined ? {} : { attachmentLimits: publishedAttachmentLimits(this.attachmentStore()) }),
484
519
  ...(Object.keys(published).length === 0 ? {} : { extensions: published }),
520
+ extensionsRevision: this.extensions.publishedRevision,
485
521
  })
486
522
  }
487
523
 
@@ -506,7 +542,12 @@ export class TaskBoardHostService {
506
542
  /** SSE frame payload; deliberately skips the tasks deep-clone of {@link snapshot}. */
507
543
  eventPayload(): TaskBoardEventPayload {
508
544
  const { revision, scheduler } = this.ledger.summary()
509
- return { revision, scheduler, power: this.power.snapshot() }
545
+ return {
546
+ revision,
547
+ extensionsRevision: this.extensions.publishedRevision,
548
+ scheduler,
549
+ power: this.power.snapshot(),
550
+ }
510
551
  }
511
552
 
512
553
  subscribe(listener: () => void): () => void {
@@ -579,10 +620,10 @@ export class TaskBoardHostService {
579
620
  await verifyAttachments(store, attachments)
580
621
  }
581
622
 
582
- apply(requestId: string, action: Extract<TaskBoardAction, { kind: 'extension-action' }>, initiator?: string): Promise<TaskBoardSnapshot>
583
- apply(requestId: string, action: Exclude<TaskBoardAction, { kind: 'extension-action' }>, initiator?: string): TaskBoardSnapshot
584
- apply(requestId: string, action: TaskBoardAction, initiator?: string): TaskBoardSnapshot | Promise<TaskBoardSnapshot>
585
- apply(requestId: string, action: TaskBoardAction, initiator?: string): TaskBoardSnapshot | Promise<TaskBoardSnapshot> {
623
+ apply(requestId: string, action: Extract<TaskBoardAction, { kind: 'extension-action' }>, initiator?: string, trigger?: TaskBoardLaunchTrigger): Promise<TaskBoardSnapshot>
624
+ apply(requestId: string, action: Exclude<TaskBoardAction, { kind: 'extension-action' }>, initiator?: string, trigger?: TaskBoardLaunchTrigger): TaskBoardSnapshot
625
+ apply(requestId: string, action: TaskBoardAction, initiator?: string, trigger?: TaskBoardLaunchTrigger): TaskBoardSnapshot | Promise<TaskBoardSnapshot>
626
+ apply(requestId: string, action: TaskBoardAction, initiator?: string, trigger?: TaskBoardLaunchTrigger): TaskBoardSnapshot | Promise<TaskBoardSnapshot> {
586
627
  if (!this.active) throw new Error('task board is disabled')
587
628
  // A caller that never met the HTTP envelope parser can name a kind this build
588
629
  // does not implement. It is refused here, in the board's own vocabulary: the
@@ -602,7 +643,7 @@ export class TaskBoardHostService {
602
643
  // The answer to a write is a read like any other — it crosses the same wire
603
644
  // (the HTTP action route and the remote bridge's board.apply) — so it leaves
604
645
  // through the same projection as snapshot().
605
- return projectSnapshotForWire(this.applyBoardAction(requestId, action, initiator))
646
+ return projectSnapshotForWire(this.applyBoardAction(requestId, action, initiator, false, trigger))
606
647
  }
607
648
 
608
649
  /**
@@ -610,7 +651,13 @@ export class TaskBoardHostService {
610
651
  * calls and the same-origin wire both land here, so the two surfaces can
611
652
  * never disagree about a card.
612
653
  */
613
- private applyBoardAction(requestId: string, action: Exclude<TaskBoardAction, { kind: 'extension-action' }>, initiator?: string, attachmentVerified = false): TaskBoardSnapshot {
654
+ private applyBoardAction(
655
+ requestId: string,
656
+ action: Exclude<TaskBoardAction, { kind: 'extension-action' }>,
657
+ initiator?: string,
658
+ attachmentVerified = false,
659
+ trigger?: TaskBoardLaunchTrigger,
660
+ ): TaskBoardSnapshot {
614
661
  // Attachments reach the ledger only through the VERIFIED action path: the
615
662
  // in-process capability face, the agent tools and the legacy import never
616
663
  // carry them, and an action that does is refused here rather than
@@ -620,7 +667,7 @@ export class TaskBoardHostService {
620
667
  }
621
668
  const before = this.statusMap()
622
669
  if (action.kind === 'run' || action.kind === 'rerun' || action.kind === 'rework') this.assertSpendCap()
623
- const result = this.ledger.applyRequest(requestId, this.withInheritedWorkspace(action, initiator), initiator)
670
+ const result = this.ledger.applyRequest(requestId, this.withInheritedWorkspace(action, initiator), initiator, trigger)
624
671
  if (result.runs !== undefined) this.dispatchRuns(result.runs)
625
672
  // A committed write that can move a rule moves the nearest trigger;
626
673
  // re-arm from the ledger so a created or edited schedule fires at its own
@@ -660,12 +707,20 @@ export class TaskBoardHostService {
660
707
 
661
708
  /** Route one provider action and answer the resulting board snapshot. */
662
709
  private async handleExtensionAction(action: Extract<TaskBoardAction, { kind: 'extension-action' }>): Promise<TaskBoardSnapshot> {
663
- await this.extensions.handleAction({
710
+ const answer = await this.extensions.handleAction({
664
711
  extensionId: action.extensionId,
665
712
  action: action.action,
666
713
  ...(action.taskId === undefined ? {} : { taskId: action.taskId }),
667
714
  ...(action.payload === undefined ? {} : { payload: action.payload }),
668
715
  })
716
+ // Providers that return a structured `{ ok: false, error }` reply instead
717
+ // of throwing still communicate a refusal: turn it into an action error so
718
+ // the HTTP channel and browser `dispatch()` surface the rejection rather
719
+ // than reporting false success.
720
+ if (typeof answer === 'object' && answer !== null && (answer as { ok?: unknown }).ok === false) {
721
+ const reason = (answer as { error?: unknown }).error
722
+ throw new Error(typeof reason === 'string' && reason.trim() !== '' ? reason : `extension "${action.extensionId}" refused action "${action.action}"`)
723
+ }
669
724
  return this.snapshot()
670
725
  }
671
726
 
@@ -737,6 +792,10 @@ export class TaskBoardHostService {
737
792
  // A cron-triggered run additionally states its own firing instant and
738
793
  // rule zone, so a scheduled job can resolve "today" without guessing.
739
794
  const contextParts = {
795
+ // The launch gate's preamble opens the prompt: a provider that keeps the
796
+ // run local states its own context once, ahead of everything the board
797
+ // would have said on this run.
798
+ ...(opened.promptPreamble === undefined ? {} : { launchPreamble: opened.promptPreamble }),
740
799
  ...(descendants.length === 0 ? {} : {
741
800
  descendants: descendants.map(descendant => ({
742
801
  id: descendant.id,
@@ -885,36 +944,106 @@ export class TaskBoardHostService {
885
944
  /**
886
945
  * The session a run may continue in, for a card that opted into reuse
887
946
  * (issue #1419). Reuse requires positive evidence that the previous session
888
- * is present and idle, and that evidence must be read for THIS launch: an
889
- * idle board no longer polls, so a roster cached from an earlier pass could
890
- * be hours old — either refusing a session that has been idle all along, or
891
- * prompting into one that started running since. A card that did not opt in
892
- * reads no roster at all, and a read that fails mints a fresh conversation
893
- * exactly as an unknown roster always did.
947
+ * is present, idle, and not archived, and that evidence must be read for THIS
948
+ * launch: an idle board no longer polls, so a roster cached from an earlier
949
+ * pass could be hours old — either refusing a session that has been idle all
950
+ * along, or prompting into one that started running since. A card that did not
951
+ * opt in reads no roster at all, and a read that fails mints a fresh
952
+ * conversation exactly as an unknown roster always did.
894
953
  * @param task - the task about to run.
895
- * @param force - continue the settled session regardless of the card's own
896
- * opt-in (a rework), which the reuse rule accepts without waiving any of its
897
- * evidence conditions.
898
954
  * @returns the session id to continue in, or undefined for a fresh session.
899
955
  */
900
- private async reuseSessionFor(task: TaskRecord, force?: boolean): Promise<string | undefined> {
901
- if (task.reuseSession !== true && force !== true) return undefined
956
+ private async reuseSessionFor(task: TaskRecord): Promise<string | undefined> {
957
+ if (task.reuseSession !== true) return undefined
958
+ const decision = await this.reuseDecision(task, false)
959
+ if (decision.sessionId !== undefined) return decision.sessionId
960
+ if (decision.archivedSessionId !== undefined) {
961
+ safeConsoleWarn(`[dsh-task-board] session reuse skipped for task ${task.id}: session ${decision.archivedSessionId} is archived, starting a fresh conversation`)
962
+ }
963
+ return undefined
964
+ }
965
+
966
+ /**
967
+ * One reuse decision for this launch: the session to continue in, or nothing
968
+ * plus the reason nothing was chosen, so each caller can report it.
969
+ *
970
+ * Reuse never targets a session in the Workspace registry's archive set
971
+ * (issue #2068). The Host's archived-session gate rejects the first step of a
972
+ * turn in an archived session before any model request is issued, so the
973
+ * run would settle as the opaque failure `agent turn ended without
974
+ * completing: blocked` — the fate of every scheduled run of a card whose
975
+ * conversation the user archived while cleaning the sidebar. Starting a fresh
976
+ * conversation is the only safe answer: archiving is a live user decision,
977
+ * and the board must not unarchive a conversation behind the user's back to
978
+ * keep reusing it.
979
+ * @param task - the task about to run.
980
+ * @param force - reuse without the card's own opt-in (a rework).
981
+ * @returns the reuse decision for this launch.
982
+ */
983
+ private async reuseDecision(task: TaskRecord, force: boolean): Promise<ReuseDecision> {
902
984
  let running: Awaited<ReturnType<HostExecutionRunner['listRunning']>>
903
985
  try {
904
986
  running = await this.runner.listRunning()
905
987
  } catch (error) {
906
- // A read that failed is an unknown roster, and an unknown roster never
907
- // reuses; the launch itself must not fail over the reuse probe.
988
+ // The runner already reports a roster it could not read as an unknown
989
+ // roster, so a throw here is a probe failure rather than an outcome. The
990
+ // launch must never fail over its own reuse probe: log it neutrally (the
991
+ // caller decides between a fresh session and a refusal) and reuse nothing.
908
992
  this.notePollFailure()
909
- safeConsoleError('[dsh-task-board] session roster read for session reuse failed; starting a fresh session', error)
910
- return undefined
993
+ safeConsoleError('[dsh-task-board] the session reuse probe failed; reuse is skipped for this launch', error)
994
+ return {}
911
995
  }
912
- if (!running.known) return undefined
913
- return reusableSessionId(
996
+ if (!running.known) return {}
997
+ const archived = this.archivedSessionIds()
998
+ const sessionId = reusableSessionId(
914
999
  task,
915
1000
  new Set(running.items.filter(item => !item.running).map(item => item.sessionId)),
916
- force === true ? { force: true } : {},
1001
+ {
1002
+ ...(force ? { force: true } : {}),
1003
+ ...(archived === undefined ? {} : { archivedSessionIds: archived }),
1004
+ },
917
1005
  )
1006
+ if (sessionId !== undefined) return { sessionId }
1007
+ const archivedSessionId = this.archivedReuseTarget(task, archived)
1008
+ return archivedSessionId === undefined ? {} : { archivedSessionId }
1009
+ }
1010
+
1011
+ /**
1012
+ * The archived conversation the reuse rule refused, when it refused one.
1013
+ *
1014
+ * Reuse skipping an archived conversation is otherwise invisible: the board
1015
+ * simply opens a new one, and only the caller knows which outcome it produced.
1016
+ * @param task - the task about to run.
1017
+ * @param archived - the archive set read for this launch, when reported.
1018
+ * @returns the newest settled session id when it is archived, else undefined.
1019
+ */
1020
+ private archivedReuseTarget(task: TaskRecord, archived: ReadonlySet<string> | undefined): string | undefined {
1021
+ if (archived === undefined) return undefined
1022
+ const newest = newestSettledSessionId(task)
1023
+ return newest !== undefined && archived.has(newest) ? newest : undefined
1024
+ }
1025
+
1026
+ /**
1027
+ * The Workspace registry's archive set, or undefined when this deployment's
1028
+ * registry face cannot report one. An unreportable set is unknown evidence,
1029
+ * never proof that nothing is archived: the rule then keeps its pre-archive
1030
+ * behavior instead of inventing a refusal, because a registry face without
1031
+ * the getter serves no archive action for the board to defend against.
1032
+ *
1033
+ * Read per launch rather than cached: archiving is a live user action, and an
1034
+ * idle board no longer polls, so a set kept from an earlier pass could already
1035
+ * claim a session that the user archived a moment ago.
1036
+ * @returns the archived session ids, or undefined when unreportable.
1037
+ */
1038
+ private archivedSessionIds(): ReadonlySet<string> | undefined {
1039
+ try {
1040
+ const archived = this.workspaceRegistry?.archivedSessionIds
1041
+ return archived === undefined ? undefined : new Set(archived)
1042
+ } catch {
1043
+ // A face that throws while reporting its archive set is unreportable, and
1044
+ // a reuse probe never fails the launch it was only advising.
1045
+ return undefined
1046
+ }
918
1047
  }
919
1048
 
920
1049
  /**
@@ -930,9 +1059,11 @@ export class TaskBoardHostService {
930
1059
  * @returns the session id this rework continues in.
931
1060
  */
932
1061
  private async reworkSessionFor(task: TaskRecord): Promise<string> {
933
- const sessionId = await this.reuseSessionFor(task, true)
934
- if (sessionId === undefined) throw new Error(REWORK_SESSION_REASON)
935
- return sessionId
1062
+ const decision = await this.reuseDecision(task, true)
1063
+ if (decision.sessionId !== undefined) return decision.sessionId
1064
+ throw new Error(decision.archivedSessionId === undefined
1065
+ ? REWORK_SESSION_REASON
1066
+ : reworkArchivedReason(decision.archivedSessionId))
936
1067
  }
937
1068
 
938
1069
  /** Reuse the session list this poll already fetched: one list RPC per tick, not 1 + E. */
@@ -1270,3 +1401,15 @@ export function safeConsoleError(message: string, ...args: unknown[]): void {
1270
1401
  // Best-effort stderr write; ignore write errors when stderr stream fails
1271
1402
  }
1272
1403
  }
1404
+
1405
+ /**
1406
+ * Defensively log to console.warn, for a diagnostic that must never turn a
1407
+ * launch decision into a failed run when the stderr write itself fails.
1408
+ */
1409
+ function safeConsoleWarn(message: string, ...args: unknown[]): void {
1410
+ try {
1411
+ console.warn(message, ...args)
1412
+ } catch {
1413
+ // Best-effort stderr write; ignore write errors when stderr stream fails
1414
+ }
1415
+ }
package/src/protocol.ts CHANGED
@@ -98,6 +98,13 @@ export interface TaskBoardSnapshot {
98
98
  * The board forwards them verbatim; it never interprets their shape.
99
99
  */
100
100
  extensions?: Record<string, unknown>
101
+ /**
102
+ * Monotonic counter bumped whenever any extension publishes, updates, or
103
+ * withdraws its summary. Carried on both full snapshots and SSE frames so
104
+ * browsers refetch `/state` when a provider publishes without touching the
105
+ * task ledger revision.
106
+ */
107
+ extensionsRevision?: number
101
108
  /**
102
109
  * The attachment limits this deployment enforces, so the browser can refuse
103
110
  * an oversized selection before it uploads anything. The board's own caps
@@ -130,9 +137,10 @@ export interface TaskBoardModelCatalog {
130
137
  catalog: ModelCatalogView
131
138
  }
132
139
 
133
- /** SSE event frame: revision/scheduler/power only, never the task list. */
140
+ /** SSE event frame: revision/scheduler/power (plus extension summary revision), never the task list. */
134
141
  export interface TaskBoardEventPayload {
135
142
  revision: number
143
+ extensionsRevision?: number
136
144
  scheduler: TaskBoardSchedulerSnapshot
137
145
  power: TaskBoardPowerSnapshot
138
146
  }