@aiwayds/dsh-opentui 0.29.0 → 0.29.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.
@@ -3587,6 +3587,56 @@ var init_terminal_size = __esm(() => {
3587
3587
  });
3588
3588
 
3589
3589
  // ../tui-base/src/routes/session/composer-state.ts
3590
+ function isAbortTurnCode(code) {
3591
+ return code === "ABORTED" || code === "USER_ABORT" || code === "SESSION_CLOSED" || code === "FORKED" || code === "INTERRUPTED" || code === "TURN_ABORT_NOOP";
3592
+ }
3593
+
3594
+ class TurnOutcomeTracker {
3595
+ activeTurnId;
3596
+ outcome;
3597
+ beginTurn() {
3598
+ this.activeTurnId = undefined;
3599
+ this.outcome = undefined;
3600
+ }
3601
+ onEvent(event) {
3602
+ const details = event?.details ?? {};
3603
+ if (event?.type === "session.updated" && details.turn === "starting") {
3604
+ const id = details.turnId;
3605
+ if (typeof id === "string" && id !== "")
3606
+ this.activeTurnId = id;
3607
+ return;
3608
+ }
3609
+ if (this.activeTurnId === undefined)
3610
+ return;
3611
+ if (event?.type === "session.error") {
3612
+ if (details.turnId !== this.activeTurnId)
3613
+ return;
3614
+ const code = typeof details.code === "string" ? details.code : "INTERNAL";
3615
+ this.outcome = isAbortTurnCode(code) ? "aborted" : "failed";
3616
+ return;
3617
+ }
3618
+ if (event?.type === "bridge.turn.terminal") {
3619
+ if (details.turnId !== this.activeTurnId)
3620
+ return;
3621
+ if (details.terminalType === "turn/error") {
3622
+ const reason = details.reason ?? {};
3623
+ const code = typeof reason.code === "string" ? reason.code : "INTERNAL";
3624
+ this.outcome = isAbortTurnCode(code) ? "aborted" : "failed";
3625
+ }
3626
+ return;
3627
+ }
3628
+ if (event?.type === "bridge.turn.interrupted" && details.turnId === this.activeTurnId) {
3629
+ this.outcome = "aborted";
3630
+ }
3631
+ }
3632
+ isFailed() {
3633
+ return this.outcome === "failed";
3634
+ }
3635
+ isAborted() {
3636
+ return this.outcome === "aborted";
3637
+ }
3638
+ }
3639
+
3590
3640
  class ComposerHistory {
3591
3641
  entries = [];
3592
3642
  index = null;
@@ -3637,11 +3687,13 @@ class ComposerController {
3637
3687
  history;
3638
3688
  send;
3639
3689
  steer;
3690
+ onSteerRejected;
3640
3691
  onBusyChange;
3641
3692
  chooseDelivery;
3642
3693
  onPendingChange;
3643
3694
  onQueuePaused;
3644
3695
  isTurnAborted;
3696
+ isTurnFailed;
3645
3697
  disabled;
3646
3698
  busyState = false;
3647
3699
  pendingTurn;
@@ -3649,14 +3701,18 @@ class ComposerController {
3649
3701
  pendingRows = [];
3650
3702
  deliverySeq = 0;
3651
3703
  deliveryEpoch = 0;
3704
+ turnGeneration = 0;
3705
+ steerTurnById = new Map;
3652
3706
  constructor(options) {
3653
3707
  this.send = options.send;
3654
3708
  this.steer = options.steer;
3709
+ this.onSteerRejected = options.onSteerRejected;
3655
3710
  this.onBusyChange = options.onBusyChange;
3656
3711
  this.chooseDelivery = options.chooseDelivery;
3657
3712
  this.onPendingChange = options.onPendingChange;
3658
3713
  this.onQueuePaused = options.onQueuePaused;
3659
3714
  this.isTurnAborted = options.isTurnAborted;
3715
+ this.isTurnFailed = options.isTurnFailed;
3660
3716
  this.disabled = options.disabled;
3661
3717
  this.history = options.history ?? new ComposerHistory;
3662
3718
  }
@@ -3695,22 +3751,26 @@ class ComposerController {
3695
3751
  return "cancelled";
3696
3752
  if (delivery === undefined)
3697
3753
  return "cancelled";
3698
- this.history.append(prompt);
3699
3754
  if (!this.busyState) {
3700
- this.startTurn(prompt);
3755
+ this.history.append(prompt);
3756
+ this.startTurn(prompt, "queue");
3701
3757
  return "sent";
3702
3758
  }
3703
3759
  if (delivery === "queue") {
3760
+ this.history.append(prompt);
3704
3761
  this.enqueue(prompt);
3705
3762
  return "queued";
3706
3763
  }
3707
- this.injectSteer(prompt);
3764
+ if (!await this.injectSteer(prompt))
3765
+ return "cancelled";
3766
+ this.history.append(prompt);
3708
3767
  return "steered";
3709
3768
  }
3710
3769
  resetDeliveries() {
3711
3770
  this.deliveryEpoch += 1;
3712
3771
  this.queueItems = [];
3713
3772
  this.pendingRows = [];
3773
+ this.steerTurnById.clear();
3714
3774
  this.emitPending();
3715
3775
  }
3716
3776
  flushQueue() {
@@ -3736,18 +3796,21 @@ class ComposerController {
3736
3796
  emitPending() {
3737
3797
  this.onPendingChange?.(this.pendingRows);
3738
3798
  }
3739
- startTurn(prompt) {
3799
+ startTurn(prompt, source = "user") {
3800
+ const generation = ++this.turnGeneration;
3740
3801
  this.setBusy(true);
3741
- let failed = false;
3742
- const turn = (async () => this.send(prompt))().then(() => {
3802
+ let sendRejected = false;
3803
+ const turn = (async () => this.send(prompt, source))().then(() => {
3743
3804
  return;
3744
3805
  }, () => {
3745
- failed = true;
3806
+ sendRejected = true;
3746
3807
  });
3747
3808
  this.pendingTurn = turn.finally(() => {
3748
3809
  this.pendingTurn = undefined;
3810
+ const failed = sendRejected || (this.isTurnFailed?.() ?? false);
3749
3811
  const aborted = !failed && (this.isTurnAborted?.() ?? false);
3750
- this.markSteerDelivered();
3812
+ if (!failed && !aborted)
3813
+ this.markSteerDelivered(generation);
3751
3814
  if (failed || aborted) {
3752
3815
  this.setBusy(false);
3753
3816
  if (this.queueItems.length > 0) {
@@ -3762,7 +3825,7 @@ class ComposerController {
3762
3825
  return;
3763
3826
  }
3764
3827
  this.dropQueueRow(next.id);
3765
- this.startTurn(next.text);
3828
+ this.startTurn(next.text, "queue");
3766
3829
  });
3767
3830
  }
3768
3831
  enqueue(prompt) {
@@ -3774,16 +3837,33 @@ class ComposerController {
3774
3837
  ];
3775
3838
  this.emitPending();
3776
3839
  }
3777
- injectSteer(prompt) {
3840
+ async injectSteer(prompt) {
3841
+ const epoch = this.deliveryEpoch;
3842
+ const generation = this.turnGeneration;
3843
+ let result;
3844
+ try {
3845
+ const awaited = await this.steer(prompt);
3846
+ result = awaited !== null && typeof awaited === "object" && typeof awaited.accepted === "boolean" ? awaited : { accepted: false, reason: "INVALID_STEER_RESULT" };
3847
+ } catch (err) {
3848
+ result = { accepted: false, reason: err instanceof Error ? err.message : String(err) };
3849
+ }
3850
+ if (epoch !== this.deliveryEpoch)
3851
+ return false;
3852
+ if (!result.accepted) {
3853
+ this.onSteerRejected?.({ text: prompt, reason: result.reason });
3854
+ return false;
3855
+ }
3778
3856
  const id = ++this.deliverySeq;
3857
+ this.steerTurnById.set(id, generation);
3779
3858
  this.pendingRows = [...this.pendingRows, { id, kind: "steer", state: "injected", text: prompt }];
3780
3859
  this.emitPending();
3781
- this.steer(prompt);
3860
+ return true;
3782
3861
  }
3783
- markSteerDelivered() {
3784
- if (!this.pendingRows.some((row) => row.kind === "steer" && row.state === "injected"))
3862
+ markSteerDelivered(generation) {
3863
+ const isMine = (row) => row.kind === "steer" && row.state === "injected" && this.steerTurnById.get(row.id) === generation;
3864
+ if (!this.pendingRows.some(isMine))
3785
3865
  return;
3786
- this.pendingRows = this.pendingRows.map((row) => row.kind === "steer" && row.state === "injected" ? { ...row, state: "delivered" } : row);
3866
+ this.pendingRows = this.pendingRows.map((row) => isMine(row) ? { ...row, state: "delivered" } : row);
3787
3867
  this.emitPending();
3788
3868
  }
3789
3869
  dropQueueRow(id) {
@@ -32458,13 +32538,27 @@ function SessionComposer(props) {
32458
32538
  onCleanup(props.seam.onSubagentViews(() => {}));
32459
32539
  }
32460
32540
  const controller = new ComposerController({
32461
- send: (text) => props.send(text),
32541
+ send: (text, source) => props.send(text, source),
32462
32542
  steer: (text) => props.seam.steer(text),
32543
+ onSteerRejected: ({
32544
+ text
32545
+ }) => {
32546
+ if (disposed || textarea === undefined || textarea.isDestroyed)
32547
+ return;
32548
+ const current = textarea.plainText;
32549
+ if (current !== "" && current !== text)
32550
+ return;
32551
+ if (current !== text) {
32552
+ textarea.setText(text);
32553
+ traceSet("failure-refill", text);
32554
+ }
32555
+ },
32463
32556
  history: props.history,
32464
32557
  chooseDelivery: props.chooseDelivery,
32465
32558
  onPendingChange: props.onPendingChange,
32466
32559
  onQueuePaused: props.onQueuePaused,
32467
32560
  isTurnAborted: props.isTurnAborted,
32561
+ isTurnFailed: props.isTurnFailed,
32468
32562
  disabled: props.disabled,
32469
32563
  onBusyChange: (value) => {
32470
32564
  if (disposed)
@@ -38216,6 +38310,94 @@ function subagentNamePrefix(name, label) {
38216
38310
  return name !== undefined && name !== "" && name !== label ? `${name}: ` : "";
38217
38311
  }
38218
38312
 
38313
+ // ../tui-base/src/routes/session/dock-line-primitives.ts
38314
+ function skinStopAt(row) {
38315
+ return row.startedAt !== undefined && row.elapsedSec !== undefined ? row.startedAt + row.elapsedSec * 1000 : undefined;
38316
+ }
38317
+ function todoTreeLines(todos) {
38318
+ if (todos.length === 0)
38319
+ return [];
38320
+ const done = todos.filter((todo) => todo.status === "completed").length;
38321
+ if (done === todos.length)
38322
+ return [];
38323
+ const lines = [
38324
+ { kind: "todo", segments: [{ text: t("overlay.widgets.todosHeader", { done, total: todos.length }), tone: "running", accent: "todo" }] }
38325
+ ];
38326
+ todos.forEach((todo, i) => {
38327
+ const branch = i === todos.length - 1 ? "\u2514\u2500 " : "\u251C\u2500 ";
38328
+ const glyph = TODO_STATUS_GLYPHS[todo.status] ?? TODO_STATUS_GLYPHS.pending;
38329
+ lines.push({ kind: "todo", segments: [{ text: `${branch}${glyph} ${todo.content}`, tone: "running", accent: "todo" }] });
38330
+ });
38331
+ return lines;
38332
+ }
38333
+ function todoSetStartedAt(todos, now = Date.now()) {
38334
+ const sig = todoSetSignature(todos);
38335
+ const first = todoSetFirstSeen.get(sig);
38336
+ if (first !== undefined)
38337
+ return first;
38338
+ todoSetFirstSeen.set(sig, now);
38339
+ return now;
38340
+ }
38341
+ function todoBriefLine(todos, now = Date.now(), startedAt) {
38342
+ if (todos.length === 0)
38343
+ return "";
38344
+ const done = todos.filter((todo) => todo.status === "completed").length;
38345
+ const anchor = startedAt ?? todoSetStartedAt(todos, now);
38346
+ const secs = Math.max(0, Math.floor((now - anchor) / 1000));
38347
+ return t("overlay.widgets.todosBrief", { done, total: todos.length, secs });
38348
+ }
38349
+ function resetTodoBriefClock() {
38350
+ todoSetFirstSeen.clear();
38351
+ }
38352
+ function toolMarker(status) {
38353
+ return status === "running" ? "\u2699" : status === "failed" ? "\u2718" : "\u2714";
38354
+ }
38355
+ function toolLineText(row, spin, now = Date.now()) {
38356
+ const subject = toolSubject(row.args);
38357
+ const title = subject === "" ? row.name : `${row.name} ${subject}`;
38358
+ const elapsed = row.status === "running" ? row.startedAt !== undefined ? ` \xB7 ${((now - row.startedAt) / 1000).toFixed(1)}s` : "" : row.elapsedSec !== undefined ? ` \xB7 ${row.elapsedSec.toFixed(1)}s` : "";
38359
+ const marker = toolMarker(row.status);
38360
+ spin();
38361
+ const tail = row.status === "running" ? toolDetail(row.args) : toolResultLine(row.output);
38362
+ const body = `${title}${elapsed}${tail !== "" ? ` \xB7 ${tail}` : ""}`;
38363
+ return `${marker} ${body}`;
38364
+ }
38365
+ function thinkBlockLines(row, spin, maxLines = DOCK_WIDGET_MAX_LINES, now = Date.now()) {
38366
+ const lines = row.text.replace(/\r/g, "").split(`
38367
+ `).filter((line) => line.trim() !== "");
38368
+ const n = Math.max(1, Math.floor(maxLines));
38369
+ if (row.streaming === true) {
38370
+ const secs = row.startedAt !== undefined ? `${((now - row.startedAt) / 1000).toFixed(1)}s` : "0.0s";
38371
+ spin();
38372
+ const picked = lines.length === 0 ? [""] : lines.slice(-n);
38373
+ return picked.map((line, index) => index === 0 ? t("overlay.widgets.thinkStreaming", { secs, line }) : ` ${line}`);
38374
+ }
38375
+ if (row.elapsedSec !== undefined) {
38376
+ const secs = `${row.elapsedSec.toFixed(1)}s`;
38377
+ const picked = lines.length === 0 ? [""] : lines.slice(-n);
38378
+ return picked.map((line, index) => index === 0 ? t("overlay.widgets.thinkCollapsed", { secs, line }) : ` ${line}`);
38379
+ }
38380
+ return [];
38381
+ }
38382
+ function activityScene(hasRunningSubagent, hasVisibleThink) {
38383
+ if (hasRunningSubagent)
38384
+ return "A";
38385
+ return hasVisibleThink ? "B" : "C";
38386
+ }
38387
+ var TODO_STATUS_GLYPHS, todoSetSignature = (todos) => todos.map((todo) => todo.content).sort().join("\x01"), todoSetFirstSeen;
38388
+ var init_dock_line_primitives = __esm(() => {
38389
+ init_i18n();
38390
+ init_tool_summarize();
38391
+ init_dock_visibility();
38392
+ TODO_STATUS_GLYPHS = {
38393
+ pending: "\u25CB",
38394
+ in_progress: "\u25CF",
38395
+ completed: "\u2713",
38396
+ cancelled: "\u2298"
38397
+ };
38398
+ todoSetFirstSeen = new Map;
38399
+ });
38400
+
38219
38401
  // ../tui-base/src/routes/session/merged-dock.ts
38220
38402
  function attributeAgents(todos, agents) {
38221
38403
  let parent = null;
@@ -38488,17 +38670,12 @@ function assembleZones(upperLines, lowerRaw, totalLines, cursor) {
38488
38670
  function fitAll(lines, innerWidth) {
38489
38671
  return lines.map((line) => fitLine(line, innerWidth));
38490
38672
  }
38491
- var MERGED_DOCK_TOTAL_LINES = 10, MERGED_DOCK_TOOL_ONLY_MAX = 3, TODO_STATUS_GLYPHS;
38673
+ var MERGED_DOCK_TOTAL_LINES = 10, MERGED_DOCK_TOOL_ONLY_MAX = 3;
38492
38674
  var init_merged_dock = __esm(() => {
38493
38675
  init_locale();
38494
38676
  init_string_width();
38495
- init_widgets_dock();
38496
- TODO_STATUS_GLYPHS = {
38497
- pending: "\u25CB",
38498
- in_progress: "\u25CF",
38499
- completed: "\u2713",
38500
- cancelled: "\u2298"
38501
- };
38677
+ init_dock_line_primitives();
38678
+ init_dock_line_primitives();
38502
38679
  });
38503
38680
 
38504
38681
  // ../tui-base/src/routes/session/widgets-dock.tsx
@@ -38631,9 +38808,6 @@ function skinPulseBrightness(elapsedMs) {
38631
38808
  const phase = elapsedMs % cycle / cycle;
38632
38809
  return 1 - SKIN_PULSE_DIM * (1 - Math.abs(2 * phase - 1));
38633
38810
  }
38634
- function skinStopAt(row) {
38635
- return row.startedAt !== undefined && row.elapsedSec !== undefined ? row.startedAt + row.elapsedSec * 1000 : undefined;
38636
- }
38637
38811
  function skinLineFadeT(id, now = Date.now()) {
38638
38812
  let seen = lineFirstSeen.get(id);
38639
38813
  if (seen === undefined) {
@@ -38729,37 +38903,6 @@ function todosSummaryFromTodos(todos) {
38729
38903
  });
38730
38904
  return active ? `${head} \xB7 ${active.content}` : head;
38731
38905
  }
38732
- function todoTreeLines(todos) {
38733
- if (todos.length === 0)
38734
- return [];
38735
- const done = todos.filter((todo) => todo.status === "completed").length;
38736
- if (done === todos.length)
38737
- return [];
38738
- const lines = [{
38739
- kind: "todo",
38740
- segments: [{
38741
- text: t("overlay.widgets.todosHeader", {
38742
- done,
38743
- total: todos.length
38744
- }),
38745
- tone: "running",
38746
- accent: "todo"
38747
- }]
38748
- }];
38749
- todos.forEach((todo, i) => {
38750
- const branch = i === todos.length - 1 ? "\u2514\u2500 " : "\u251C\u2500 ";
38751
- const glyph = TODO_STATUS_GLYPHS[todo.status] ?? TODO_STATUS_GLYPHS.pending;
38752
- lines.push({
38753
- kind: "todo",
38754
- segments: [{
38755
- text: `${branch}${glyph} ${todo.content}`,
38756
- tone: "running",
38757
- accent: "todo"
38758
- }]
38759
- });
38760
- });
38761
- return lines;
38762
- }
38763
38906
  function todoTabLines(rows, innerWidth, cursor = 0) {
38764
38907
  const data = {
38765
38908
  tools: [],
@@ -38895,29 +39038,6 @@ function DockTabStripView(props) {
38895
39038
  return _el$;
38896
39039
  })();
38897
39040
  }
38898
- function todoSetStartedAt(todos, now = Date.now()) {
38899
- const sig = todoSetSignature(todos);
38900
- const first = todoSetFirstSeen.get(sig);
38901
- if (first !== undefined)
38902
- return first;
38903
- todoSetFirstSeen.set(sig, now);
38904
- return now;
38905
- }
38906
- function todoBriefLine(todos, now = Date.now(), startedAt) {
38907
- if (todos.length === 0)
38908
- return "";
38909
- const done = todos.filter((todo) => todo.status === "completed").length;
38910
- const anchor = startedAt ?? todoSetStartedAt(todos, now);
38911
- const secs = Math.max(0, Math.floor((now - anchor) / 1000));
38912
- return t("overlay.widgets.todosBrief", {
38913
- done,
38914
- total: todos.length,
38915
- secs
38916
- });
38917
- }
38918
- function resetTodoBriefClock() {
38919
- todoSetFirstSeen.clear();
38920
- }
38921
39041
  function subagentBatchAnchor(running, now = Date.now()) {
38922
39042
  if (running === 0) {
38923
39043
  subagentBatchStartedAt = undefined;
@@ -38946,47 +39066,6 @@ function subagentBriefLine(running, now = Date.now()) {
38946
39066
  const elapsedSec = Math.max(0, Math.floor((now - anchor) / 1000));
38947
39067
  return subagentBriefText(running, elapsedSec);
38948
39068
  }
38949
- function toolMarker(status) {
38950
- return status === "running" ? "\u2699" : status === "failed" ? "\u2718" : "\u2714";
38951
- }
38952
- function toolLineText(row, spin, now = Date.now()) {
38953
- const subject = toolSubject(row.args);
38954
- const title = subject === "" ? row.name : `${row.name} ${subject}`;
38955
- const elapsed = row.status === "running" ? row.startedAt !== undefined ? ` \xB7 ${((now - row.startedAt) / 1000).toFixed(1)}s` : "" : row.elapsedSec !== undefined ? ` \xB7 ${row.elapsedSec.toFixed(1)}s` : "";
38956
- const marker = toolMarker(row.status);
38957
- spin();
38958
- const tail = row.status === "running" ? toolDetail(row.args) : toolResultLine(row.output);
38959
- const body = `${title}${elapsed}${tail !== "" ? ` \xB7 ${tail}` : ""}`;
38960
- return `${marker} ${body}`;
38961
- }
38962
- function thinkBlockLines(row, spin, maxLines = DOCK_WIDGET_MAX_LINES, now = Date.now()) {
38963
- const lines = row.text.replace(/\r/g, "").split(`
38964
- `).filter((line) => line.trim() !== "");
38965
- const n = Math.max(1, Math.floor(maxLines));
38966
- if (row.streaming === true) {
38967
- const secs = row.startedAt !== undefined ? `${((now - row.startedAt) / 1000).toFixed(1)}s` : "0.0s";
38968
- spin();
38969
- const picked = lines.length === 0 ? [""] : lines.slice(-n);
38970
- return picked.map((line, index) => index === 0 ? t("overlay.widgets.thinkStreaming", {
38971
- secs,
38972
- line
38973
- }) : ` ${line}`);
38974
- }
38975
- if (row.elapsedSec !== undefined) {
38976
- const secs = `${row.elapsedSec.toFixed(1)}s`;
38977
- const picked = lines.length === 0 ? [""] : lines.slice(-n);
38978
- return picked.map((line, index) => index === 0 ? t("overlay.widgets.thinkCollapsed", {
38979
- secs,
38980
- line
38981
- }) : ` ${line}`);
38982
- }
38983
- return [];
38984
- }
38985
- function activityScene(hasRunningSubagent, hasVisibleThink) {
38986
- if (hasRunningSubagent)
38987
- return "A";
38988
- return hasVisibleThink ? "B" : "C";
38989
- }
38990
39069
  function dockBlocks(rows, options = {}) {
38991
39070
  dockSpin();
38992
39071
  const now = options.now ?? Date.now();
@@ -39671,7 +39750,7 @@ function dockLineNode(line, width, ctx, fgFor, accentFg) {
39671
39750
  return _el$0;
39672
39751
  })();
39673
39752
  }
39674
- var SKIN_FADE_IN_MS = 400, SKIN_NOTICE_FADE_MS = 500, SKIN_PULSE_MS = 1200, SKIN_PULSE_CYCLES = 3, SKIN_PULSE_DIM = 0.45, SKIN_FAINT_MIX = 0.78, ACTIVITY_PANEL_GEARS, DEFAULT_ACTIVITY_PANEL_GEAR = "5", ACTIVITY_PANEL_ALL_LINES = 10, activityPanelGear, setActivityPanelGear, DOCK_HEIGHT_ANIM_MS = 200, dockHeightTween, setDockHeightTween, dockHeightSettled = undefined, dockFrameNow = 0, LINE_FIRST_SEEN_MAX = 512, lineFirstSeen, dockSpin, setDockSpin, mergedDockCursor, setMergedDockCursor, activityDockTab, setActivityDockTab, DOCK_TAB_ICON, DOCK_TAB_PADDING_STEPS, dockTabDigit = (label) => label.match(/^\d+/)?.[0] ?? "", todoSetSignature = (todos) => todos.map((todo) => todo.content).sort().join("\x01"), todoSetFirstSeen, subagentBatchStartedAt, prevSubagentRunning = 0, TODO_TOOL_NAMES, AUTO_POLE_LIGHT = "#ffffff", AUTO_POLE_DARK = "#000000", DOCK_ACCENT_STEPS, DOCK_ACCENT_HUES, DOCK_ACCENT_MIN_CONTRAST = 4.5, DOCK_ACCENT_FALLBACK, ACTIVITY_FRAME_DEFER_MS = 60, activityFrameLatch, COMPACT_TREE_MAX_LINES = 8;
39753
+ var SKIN_FADE_IN_MS = 400, SKIN_NOTICE_FADE_MS = 500, SKIN_PULSE_MS = 1200, SKIN_PULSE_CYCLES = 3, SKIN_PULSE_DIM = 0.45, SKIN_FAINT_MIX = 0.78, ACTIVITY_PANEL_GEARS, DEFAULT_ACTIVITY_PANEL_GEAR = "5", ACTIVITY_PANEL_ALL_LINES = 10, activityPanelGear, setActivityPanelGear, DOCK_HEIGHT_ANIM_MS = 200, dockHeightTween, setDockHeightTween, dockHeightSettled = undefined, dockFrameNow = 0, LINE_FIRST_SEEN_MAX = 512, lineFirstSeen, dockSpin, setDockSpin, mergedDockCursor, setMergedDockCursor, activityDockTab, setActivityDockTab, DOCK_TAB_ICON, DOCK_TAB_PADDING_STEPS, dockTabDigit = (label) => label.match(/^\d+/)?.[0] ?? "", subagentBatchStartedAt, prevSubagentRunning = 0, TODO_TOOL_NAMES, AUTO_POLE_LIGHT = "#ffffff", AUTO_POLE_DARK = "#000000", DOCK_ACCENT_STEPS, DOCK_ACCENT_HUES, DOCK_ACCENT_MIN_CONTRAST = 4.5, DOCK_ACCENT_FALLBACK, ACTIVITY_FRAME_DEFER_MS = 60, activityFrameLatch, COMPACT_TREE_MAX_LINES = 8;
39675
39754
  var init_widgets_dock = __esm(() => {
39676
39755
  init_index_bun();
39677
39756
  init_index_bun();
@@ -39696,8 +39775,10 @@ var init_widgets_dock = __esm(() => {
39696
39775
  init_dock_visibility();
39697
39776
  init_powerline();
39698
39777
  init_merged_dock();
39778
+ init_dock_line_primitives();
39699
39779
  init_keymap();
39700
39780
  init_input_ownership();
39781
+ init_dock_line_primitives();
39701
39782
  ACTIVITY_PANEL_GEARS = ["1", "5", "7", "10", "all"];
39702
39783
  [activityPanelGear, setActivityPanelGear] = createSignal(undefined);
39703
39784
  [dockHeightTween, setDockHeightTween] = createSignal(undefined);
@@ -39710,7 +39791,6 @@ var init_widgets_dock = __esm(() => {
39710
39791
  todo: "\uD83D\uDCCB"
39711
39792
  };
39712
39793
  DOCK_TAB_PADDING_STEPS = [2, 1, 0];
39713
- todoSetFirstSeen = new Map;
39714
39794
  TODO_TOOL_NAMES = new Set(["todowrite", "todo_write"]);
39715
39795
  DOCK_ACCENT_STEPS = {
39716
39796
  think: [200, 300, 100, 400, 500, 600, 700, 800, 900],
@@ -44368,26 +44448,7 @@ function journalToJSONL(entries) {
44368
44448
  }
44369
44449
  var init_export = () => {};
44370
44450
 
44371
- // ../tui-base/src/routes/session/commands.ts
44372
- import { mkdir as mkdir3, writeFile as writeFile3 } from "fs/promises";
44373
- import { dirname as dirname2 } from "path";
44374
- function persistHints(seam) {
44375
- try {
44376
- seam.configSave?.({ footerHints: footerHints(), lang: hintsLocale() });
44377
- } catch (error) {
44378
- console.error("[commands] hints persist failed:", error);
44379
- }
44380
- }
44381
- function persistLang(seam, lang) {
44382
- try {
44383
- seam.configSave?.({ lang });
44384
- } catch (error) {
44385
- console.error("[commands] language persist failed:", error);
44386
- }
44387
- }
44388
- function seamFailureReason(error) {
44389
- return String(error instanceof Error ? error.message : error).slice(0, 150);
44390
- }
44451
+ // ../tui-base/src/routes/session/command-families/prune.ts
44391
44452
  function pruneReasonLabel(reason) {
44392
44453
  const key = PRUNE_REASON_KEYS[reason];
44393
44454
  return key === undefined ? t("command.prune.reason.other", { reason }) : t(key);
@@ -44473,6 +44534,34 @@ function formatRestoreListRows(list) {
44473
44534
  }
44474
44535
  return rows;
44475
44536
  }
44537
+ var PRUNE_REASON_KEYS;
44538
+ var init_prune = __esm(() => {
44539
+ init_i18n();
44540
+ PRUNE_REASON_KEYS = {
44541
+ "retention-disabled": "command.prune.reason.retentionDisabled",
44542
+ "field-anomaly": "command.prune.reason.fieldAnomaly",
44543
+ current: "command.prune.reason.current",
44544
+ staged: "command.prune.reason.staged",
44545
+ "agent-available": "command.prune.reason.agentAvailable",
44546
+ running: "command.prune.reason.running",
44547
+ "missing-time": "command.prune.reason.missingTime",
44548
+ "future-time": "command.prune.reason.futureTime",
44549
+ "subtree-running": "command.prune.reason.subtreeRunning",
44550
+ unknown: "command.prune.reason.unknown",
44551
+ "no-location": "command.prune.reason.noLocation",
44552
+ "header-mismatch": "command.prune.reason.headerMismatch",
44553
+ "basename-mismatch": "command.prune.reason.basenameMismatch",
44554
+ "not-directory": "command.prune.reason.notDirectory",
44555
+ "escaped-root": "command.prune.reason.escapedRoot",
44556
+ "lock-fresh": "command.prune.reason.lockFresh",
44557
+ "lock-held": "command.prune.reason.lockHeld",
44558
+ "fresh-mtime": "command.prune.reason.freshMtime",
44559
+ "blank-grace": "command.prune.reason.blankGrace",
44560
+ "within-retention": "command.prune.reason.withinRetention"
44561
+ };
44562
+ });
44563
+
44564
+ // ../tui-base/src/routes/session/command-families/preset.ts
44476
44565
  function presetNextRow(rows, currentId) {
44477
44566
  if (rows.length <= 1)
44478
44567
  return;
@@ -44496,6 +44585,8 @@ function presetLabelFor(rows, currentId) {
44496
44585
  const marked = rows.find((row) => row.isDefault) ?? rows.find((row) => row.id === "standard");
44497
44586
  return (marked ?? rows[0])?.name;
44498
44587
  }
44588
+
44589
+ // ../tui-base/src/routes/session/command-families/permission-cwd.ts
44499
44590
  function isRiskPermissionPreset(value, name) {
44500
44591
  return /danger-full-access|full.?access|auto/i.test(`${value} ${name ?? ""}`);
44501
44592
  }
@@ -44508,6 +44599,27 @@ function cwdBasename(cwd) {
44508
44599
  const parts = trimmed.split(/[\\/]/);
44509
44600
  return parts[parts.length - 1] || trimmed;
44510
44601
  }
44602
+
44603
+ // ../tui-base/src/routes/session/commands.ts
44604
+ import { mkdir as mkdir3, writeFile as writeFile3 } from "fs/promises";
44605
+ import { dirname as dirname2 } from "path";
44606
+ function persistHints(seam) {
44607
+ try {
44608
+ seam.configSave?.({ footerHints: footerHints(), lang: hintsLocale() });
44609
+ } catch (error) {
44610
+ console.error("[commands] hints persist failed:", error);
44611
+ }
44612
+ }
44613
+ function persistLang(seam, lang) {
44614
+ try {
44615
+ seam.configSave?.({ lang });
44616
+ } catch (error) {
44617
+ console.error("[commands] language persist failed:", error);
44618
+ }
44619
+ }
44620
+ function seamFailureReason(error) {
44621
+ return String(error instanceof Error ? error.message : error).slice(0, 150);
44622
+ }
44511
44623
  async function applyRoutePlan(plan, settings, onFailure) {
44512
44624
  if (plan.kind === "invalid") {
44513
44625
  onFailure(plan.reason);
@@ -45870,7 +45982,7 @@ function dispatchLine(commands, line) {
45870
45982
  function unknownCommandRow(name) {
45871
45983
  return `unknown command: ${name} (try /help)`;
45872
45984
  }
45873
- var MODEL_DEFAULT_EFFORT_PICK = "__model_default__", PRUNE_REASON_KEYS;
45985
+ var MODEL_DEFAULT_EFFORT_PICK = "__model_default__";
45874
45986
  var init_commands = __esm(() => {
45875
45987
  init_i18n();
45876
45988
  init_hotkeys();
@@ -45879,28 +45991,8 @@ var init_commands = __esm(() => {
45879
45991
  init_hints_line();
45880
45992
  init_motion();
45881
45993
  init_export();
45882
- PRUNE_REASON_KEYS = {
45883
- "retention-disabled": "command.prune.reason.retentionDisabled",
45884
- "field-anomaly": "command.prune.reason.fieldAnomaly",
45885
- current: "command.prune.reason.current",
45886
- staged: "command.prune.reason.staged",
45887
- "agent-available": "command.prune.reason.agentAvailable",
45888
- running: "command.prune.reason.running",
45889
- "missing-time": "command.prune.reason.missingTime",
45890
- "future-time": "command.prune.reason.futureTime",
45891
- "subtree-running": "command.prune.reason.subtreeRunning",
45892
- unknown: "command.prune.reason.unknown",
45893
- "no-location": "command.prune.reason.noLocation",
45894
- "header-mismatch": "command.prune.reason.headerMismatch",
45895
- "basename-mismatch": "command.prune.reason.basenameMismatch",
45896
- "not-directory": "command.prune.reason.notDirectory",
45897
- "escaped-root": "command.prune.reason.escapedRoot",
45898
- "lock-fresh": "command.prune.reason.lockFresh",
45899
- "lock-held": "command.prune.reason.lockHeld",
45900
- "fresh-mtime": "command.prune.reason.freshMtime",
45901
- "blank-grace": "command.prune.reason.blankGrace",
45902
- "within-retention": "command.prune.reason.withinRetention"
45903
- };
45994
+ init_prune();
45995
+ init_prune();
45904
45996
  });
45905
45997
 
45906
45998
  // ../tui-base/src/routes/session/slash-complete.ts
@@ -55554,7 +55646,7 @@ var init_subagents_viewer = __esm(() => {
55554
55646
  import { TextAttributes as TextAttributes12 } from "@opentui/core";
55555
55647
  function resolveVersion() {
55556
55648
  try {
55557
- return "0.29.0";
55649
+ return "0.29.2";
55558
55650
  } catch {
55559
55651
  return "dev";
55560
55652
  }
@@ -60166,142 +60258,26 @@ var init_subagent_policy = __esm(() => {
60166
60258
  DEFAULT_SUBAGENT_ROUND_LIMITS = { maxRounds: DEFAULT_MAX_ROUNDS2, maxRoundsGrace: 0 };
60167
60259
  });
60168
60260
 
60169
- // src/client/bridge-session-seam.ts
60170
- import { existsSync as existsSync8, readFileSync as readFileSync9, readdirSync as readdirSync4 } from "fs";
60171
- import { join as join10 } from "path";
60172
- import { randomUUID as randomUUID3 } from "crypto";
60173
- function writeConfirmed(confirm) {
60174
- return typeof confirm === "object" && confirm !== null && confirm.__pluginWriteConfirm === true && typeof confirm.operation === "string";
60175
- }
60176
- function askTurnId(eventId) {
60177
- const i = eventId.lastIndexOf(":ask-");
60178
- return i === -1 ? "" : eventId.slice(0, i);
60179
- }
60180
- function optionalStringField(row, key) {
60181
- const value = row[key];
60182
- return typeof value === "string" && value !== "" ? value : undefined;
60183
- }
60184
- function parseAskRequest(value) {
60185
- const row = asRecord12(value);
60186
- const eventId = optionalStringField(row, "eventId");
60187
- const sessionId = optionalStringField(row, "sessionId");
60188
- const kind = row.kind;
60189
- if (eventId === undefined || sessionId === undefined || kind !== "approval" && kind !== "questions") {
60190
- return;
60191
- }
60192
- const out = { eventId, sessionId, kind };
60193
- for (const key of ["toolName", "callId", "reason", "childSessionId", "parentSessionId"]) {
60194
- const v = optionalStringField(row, key);
60195
- if (v !== undefined)
60196
- out[key] = v;
60197
- }
60198
- for (const key of ["deadlineAt", "detachGraceMs"]) {
60199
- const v = row[key];
60200
- if (typeof v === "number" && Number.isFinite(v))
60201
- out[key] = v;
60202
- }
60203
- if (row.escalation === true)
60204
- out.escalation = true;
60205
- if (Array.isArray(row.questions)) {
60206
- const questions = [];
60207
- for (const raw of row.questions) {
60208
- const q = asRecord12(raw);
60209
- const id = optionalStringField(q, "id");
60210
- const prompt = optionalStringField(q, "prompt");
60211
- if (id === undefined || prompt === undefined || !Array.isArray(q.options))
60212
- continue;
60213
- const options = [];
60214
- for (const rawOpt of q.options) {
60215
- const opt = asRecord12(rawOpt);
60216
- const label = optionalStringField(opt, "label");
60217
- if (label === undefined)
60218
- continue;
60219
- const description = optionalStringField(opt, "description");
60220
- options.push({ label, ...description !== undefined ? { description } : {} });
60221
- }
60222
- if (options.length === 0)
60223
- continue;
60224
- const question = { id, prompt, options };
60225
- for (const key of ["header", "description", "detail"]) {
60226
- const v = optionalStringField(q, key);
60227
- if (v !== undefined)
60228
- question[key] = v;
60229
- }
60230
- if (q.multiSelect === true)
60231
- question.multiSelect = true;
60232
- questions.push(question);
60261
+ // src/client/seam-projections/bridge-protocol-error.ts
60262
+ var BridgeProtocolError;
60263
+ var init_bridge_protocol_error = __esm(() => {
60264
+ BridgeProtocolError = class BridgeProtocolError extends Error {
60265
+ code;
60266
+ detail;
60267
+ constructor(code, message, detail) {
60268
+ super(message);
60269
+ this.name = "BridgeProtocolError";
60270
+ this.code = code;
60271
+ if (detail !== undefined)
60272
+ this.detail = detail;
60233
60273
  }
60234
- if (questions.length > 0)
60235
- out.questions = questions;
60236
- }
60237
- return out;
60238
- }
60239
- function approvalArgs(request) {
60240
- return {
60241
- ...request.callId !== undefined ? { callId: request.callId } : {},
60242
- ...request.reason !== undefined ? { reason: request.reason } : {},
60243
- ...request.parentSessionId !== undefined ? { eventId: request.eventId } : {}
60244
60274
  };
60245
- }
60246
- function approvalQuestion(request) {
60247
- const toolName = request.toolName ?? "tool";
60248
- return {
60249
- id: request.eventId,
60250
- prompt: request.reason ?? `Allow ${toolName}?`,
60251
- options: [{ label: "allow" }, { label: "deny" }],
60252
- header: "Approval",
60253
- ...request.callId !== undefined ? { detail: `callId: ${request.callId}` } : {}
60254
- };
60255
- }
60256
- function approvalVerdictFromPicks(request, picks) {
60257
- const pick = picks.find((p) => p.questionId === request.eventId);
60258
- const choice = pick?.custom ?? pick?.selections?.[0] ?? pick?.selected ?? "";
60259
- return /^(allow|allowed-once|yes|approve)$/i.test(choice) ? "allowed-once" : "rejected";
60260
- }
60261
- function answersFor(request, picks) {
60262
- const questions = request.questions ?? [];
60263
- if (questions.length === 0) {
60264
- return picks.map((pick) => ({
60265
- id: pick.questionId,
60266
- selected: pick.selections?.length ? [...pick.selections] : [pick.selected],
60267
- ...pick.custom !== undefined && pick.custom !== "" ? { custom: pick.custom } : {}
60268
- }));
60269
- }
60270
- return questions.map((q) => {
60271
- const pick = picks.find((p) => p.questionId === q.id);
60272
- if (pick?.custom !== undefined && pick.custom !== "")
60273
- return { id: q.id, selected: [], custom: pick.custom };
60274
- if (pick === undefined || pick.selected === "" && (pick.custom ?? "") === "") {
60275
- return { id: q.id, selected: [], custom: "declined" };
60276
- }
60277
- return {
60278
- id: q.id,
60279
- selected: pick.selections?.length ? [...pick.selections] : [pick.selected]
60280
- };
60281
- });
60282
- }
60283
- function unavailableResponse(request) {
60284
- return request.kind === "questions" ? { eventId: request.eventId, kind: "questions", verdict: "unavailable", answers: answersFor(request, []) } : { eventId: request.eventId, kind: "approval", verdict: "unavailable" };
60285
- }
60275
+ });
60276
+
60277
+ // src/client/seam-projections/prune-purge.ts
60286
60278
  function asRecord12(value) {
60287
60279
  return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
60288
60280
  }
60289
- function projectSeamAccountView(value) {
60290
- const v = asRecord12(value);
60291
- return {
60292
- status: typeof v.status === "string" && ACCOUNT_STATUSES.has(v.status) ? v.status : null,
60293
- attemptPhase: typeof v.attemptPhase === "string" && ACCOUNT_PHASES.has(v.attemptPhase) ? v.attemptPhase : null,
60294
- authorizeUrlReady: v.authorizeUrlReady === true,
60295
- linksPresent: v.linksPresent === true
60296
- };
60297
- }
60298
- function accountClientMeta() {
60299
- return {
60300
- version: "0.25-w1b",
60301
- locale: typeof Intl !== "undefined" ? Intl.DateTimeFormat().resolvedOptions().locale : "en",
60302
- timezoneOffsetSeconds: -new Date().getTimezoneOffset() * 60
60303
- };
60304
- }
60305
60281
  function projectBridgePrunePlan(value) {
60306
60282
  const record = asRecord12(value);
60307
60283
  if (!Array.isArray(record.entries)) {
@@ -60473,21 +60449,26 @@ function projectBridgePruneRestore(value) {
60473
60449
  }
60474
60450
  return { id: record.id, restored: true, opId: record.opId };
60475
60451
  }
60476
- function unsupported(capability) {
60477
- throw new BridgeProtocolError("UNSUPPORTED", `${capability} is not backed by the in-process bridge`, { capability });
60452
+ var init_prune_purge = __esm(() => {
60453
+ init_bridge_protocol_error();
60454
+ });
60455
+
60456
+ // src/client/seam-projections/session-list.ts
60457
+ function asRecord13(value) {
60458
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
60478
60459
  }
60479
60460
  function projectBridgeSessionList(items, limit = 12) {
60480
60461
  const rows = Array.isArray(items) ? items : [];
60481
60462
  const out = [];
60482
60463
  for (const item of rows) {
60483
- const row = asRecord12(item);
60464
+ const row = asRecord13(item);
60484
60465
  if (row.origin === "subagent")
60485
60466
  continue;
60486
60467
  const id = typeof row.sessionId === "string" ? row.sessionId : "";
60487
60468
  if (!id)
60488
60469
  continue;
60489
60470
  const updatedAt = typeof row.updatedAt === "number" ? String(row.updatedAt) : "";
60490
- const values = asRecord12(asRecord12(row.projections).values);
60471
+ const values = asRecord13(asRecord13(row.projections).values);
60491
60472
  const title = typeof values.title === "string" ? values.title : "";
60492
60473
  out.push({
60493
60474
  id,
@@ -60504,15 +60485,155 @@ function projectCurrentCwd(items, sessionId) {
60504
60485
  if (sessionId === undefined || sessionId === "" || !Array.isArray(items))
60505
60486
  return;
60506
60487
  for (const item of items) {
60507
- const row = asRecord12(item);
60488
+ const row = asRecord13(item);
60508
60489
  if (row.sessionId !== sessionId)
60509
60490
  continue;
60510
60491
  return typeof row.cwd === "string" && row.cwd !== "" ? row.cwd : undefined;
60511
60492
  }
60512
60493
  return;
60513
60494
  }
60495
+
60496
+ // src/client/bridge-session-seam.ts
60497
+ import { existsSync as existsSync8, readFileSync as readFileSync9, readdirSync as readdirSync4 } from "fs";
60498
+ import { join as join10 } from "path";
60499
+ import { randomUUID as randomUUID3 } from "crypto";
60500
+ function writeConfirmed(confirm) {
60501
+ return typeof confirm === "object" && confirm !== null && confirm.__pluginWriteConfirm === true && typeof confirm.operation === "string";
60502
+ }
60503
+ function askTurnId(eventId) {
60504
+ const i = eventId.lastIndexOf(":ask-");
60505
+ return i === -1 ? "" : eventId.slice(0, i);
60506
+ }
60507
+ function optionalStringField(row, key) {
60508
+ const value = row[key];
60509
+ return typeof value === "string" && value !== "" ? value : undefined;
60510
+ }
60511
+ function parseAskRequest(value) {
60512
+ const row = asRecord14(value);
60513
+ const eventId = optionalStringField(row, "eventId");
60514
+ const sessionId = optionalStringField(row, "sessionId");
60515
+ const kind = row.kind;
60516
+ if (eventId === undefined || sessionId === undefined || kind !== "approval" && kind !== "questions") {
60517
+ return;
60518
+ }
60519
+ const out = { eventId, sessionId, kind };
60520
+ for (const key of ["toolName", "callId", "reason", "childSessionId", "parentSessionId"]) {
60521
+ const v = optionalStringField(row, key);
60522
+ if (v !== undefined)
60523
+ out[key] = v;
60524
+ }
60525
+ for (const key of ["deadlineAt", "detachGraceMs"]) {
60526
+ const v = row[key];
60527
+ if (typeof v === "number" && Number.isFinite(v))
60528
+ out[key] = v;
60529
+ }
60530
+ if (row.escalation === true)
60531
+ out.escalation = true;
60532
+ if (Array.isArray(row.questions)) {
60533
+ const questions = [];
60534
+ for (const raw of row.questions) {
60535
+ const q = asRecord14(raw);
60536
+ const id = optionalStringField(q, "id");
60537
+ const prompt = optionalStringField(q, "prompt");
60538
+ if (id === undefined || prompt === undefined || !Array.isArray(q.options))
60539
+ continue;
60540
+ const options = [];
60541
+ for (const rawOpt of q.options) {
60542
+ const opt = asRecord14(rawOpt);
60543
+ const label = optionalStringField(opt, "label");
60544
+ if (label === undefined)
60545
+ continue;
60546
+ const description = optionalStringField(opt, "description");
60547
+ options.push({ label, ...description !== undefined ? { description } : {} });
60548
+ }
60549
+ if (options.length === 0)
60550
+ continue;
60551
+ const question = { id, prompt, options };
60552
+ for (const key of ["header", "description", "detail"]) {
60553
+ const v = optionalStringField(q, key);
60554
+ if (v !== undefined)
60555
+ question[key] = v;
60556
+ }
60557
+ if (q.multiSelect === true)
60558
+ question.multiSelect = true;
60559
+ questions.push(question);
60560
+ }
60561
+ if (questions.length > 0)
60562
+ out.questions = questions;
60563
+ }
60564
+ return out;
60565
+ }
60566
+ function approvalArgs(request) {
60567
+ return {
60568
+ ...request.callId !== undefined ? { callId: request.callId } : {},
60569
+ ...request.reason !== undefined ? { reason: request.reason } : {},
60570
+ ...request.parentSessionId !== undefined ? { eventId: request.eventId } : {}
60571
+ };
60572
+ }
60573
+ function approvalQuestion(request) {
60574
+ const toolName = request.toolName ?? "tool";
60575
+ return {
60576
+ id: request.eventId,
60577
+ prompt: request.reason ?? `Allow ${toolName}?`,
60578
+ options: [{ label: "allow" }, { label: "deny" }],
60579
+ header: "Approval",
60580
+ ...request.callId !== undefined ? { detail: `callId: ${request.callId}` } : {}
60581
+ };
60582
+ }
60583
+ function approvalVerdictFromPicks(request, picks) {
60584
+ const pick = picks.find((p) => p.questionId === request.eventId);
60585
+ const choice = pick?.custom ?? pick?.selections?.[0] ?? pick?.selected ?? "";
60586
+ return /^(allow|allowed-once|yes|approve)$/i.test(choice) ? "allowed-once" : "rejected";
60587
+ }
60588
+ function answersFor(request, picks) {
60589
+ const questions = request.questions ?? [];
60590
+ if (questions.length === 0) {
60591
+ return picks.map((pick) => ({
60592
+ id: pick.questionId,
60593
+ selected: pick.selections?.length ? [...pick.selections] : [pick.selected],
60594
+ ...pick.custom !== undefined && pick.custom !== "" ? { custom: pick.custom } : {}
60595
+ }));
60596
+ }
60597
+ return questions.map((q) => {
60598
+ const pick = picks.find((p) => p.questionId === q.id);
60599
+ if (pick?.custom !== undefined && pick.custom !== "")
60600
+ return { id: q.id, selected: [], custom: pick.custom };
60601
+ if (pick === undefined || pick.selected === "" && (pick.custom ?? "") === "") {
60602
+ return { id: q.id, selected: [], custom: "declined" };
60603
+ }
60604
+ return {
60605
+ id: q.id,
60606
+ selected: pick.selections?.length ? [...pick.selections] : [pick.selected]
60607
+ };
60608
+ });
60609
+ }
60610
+ function unavailableResponse(request) {
60611
+ return request.kind === "questions" ? { eventId: request.eventId, kind: "questions", verdict: "unavailable", answers: answersFor(request, []) } : { eventId: request.eventId, kind: "approval", verdict: "unavailable" };
60612
+ }
60613
+ function asRecord14(value) {
60614
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
60615
+ }
60616
+ function projectSeamAccountView(value) {
60617
+ const v = asRecord14(value);
60618
+ return {
60619
+ status: typeof v.status === "string" && ACCOUNT_STATUSES.has(v.status) ? v.status : null,
60620
+ attemptPhase: typeof v.attemptPhase === "string" && ACCOUNT_PHASES.has(v.attemptPhase) ? v.attemptPhase : null,
60621
+ authorizeUrlReady: v.authorizeUrlReady === true,
60622
+ linksPresent: v.linksPresent === true
60623
+ };
60624
+ }
60625
+ function accountClientMeta() {
60626
+ return {
60627
+ version: "0.25-w1b",
60628
+ locale: typeof Intl !== "undefined" ? Intl.DateTimeFormat().resolvedOptions().locale : "en",
60629
+ timezoneOffsetSeconds: -new Date().getTimezoneOffset() * 60
60630
+ };
60631
+ }
60632
+ function unsupported(capability) {
60633
+ throw new BridgeProtocolError("UNSUPPORTED", `${capability} is not backed by the in-process bridge`, { capability });
60634
+ }
60514
60635
  function routeFromSelection(value) {
60515
- const row = asRecord12(value);
60636
+ const row = asRecord14(value);
60516
60637
  const providerID = typeof row.providerID === "string" ? row.providerID : typeof row.provider === "string" ? row.provider : "";
60517
60638
  const modelID = typeof row.modelID === "string" ? row.modelID : typeof row.model === "string" ? row.model : "";
60518
60639
  if (!providerID || !modelID)
@@ -60521,15 +60642,15 @@ function routeFromSelection(value) {
60521
60642
  return { providerID, modelID, ...reasoningEffort !== undefined ? { reasoningEffort } : {} };
60522
60643
  }
60523
60644
  function routeFromSelectionEvent(payload) {
60524
- const data = asRecord12(payload);
60525
- const nested = asRecord12(data.data);
60645
+ const data = asRecord14(payload);
60646
+ const nested = asRecord14(data.data);
60526
60647
  return routeFromSelection(data.selection) ?? routeFromSelection(data) ?? routeFromSelection(nested.selection) ?? routeFromSelection(nested);
60527
60648
  }
60528
60649
  function routeFromHeader(payload) {
60529
- const data = asRecord12(payload);
60530
- const header = asRecord12(data.header);
60531
- const nested = asRecord12(data.data);
60532
- const nestedHeader = asRecord12(nested.header);
60650
+ const data = asRecord14(payload);
60651
+ const header = asRecord14(data.header);
60652
+ const nested = asRecord14(data.data);
60653
+ const nestedHeader = asRecord14(nested.header);
60533
60654
  for (const candidate of [header.config, nestedHeader.config, data.config, header, nestedHeader]) {
60534
60655
  const route = routeFromSelection(candidate);
60535
60656
  if (route !== undefined)
@@ -60538,7 +60659,7 @@ function routeFromHeader(payload) {
60538
60659
  return;
60539
60660
  }
60540
60661
  function routeFromContext(payload) {
60541
- const data = asRecord12(payload);
60662
+ const data = asRecord14(payload);
60542
60663
  const providerID = optionalStringField(data, "provider");
60543
60664
  const modelID = optionalStringField(data, "model");
60544
60665
  if (providerID === undefined || modelID === undefined)
@@ -60600,7 +60721,7 @@ function bridgeReplayRowsToSeamTranscript(rows, skip = 0, sessionId) {
60600
60721
  type: row.type,
60601
60722
  seq: row.seq,
60602
60723
  time: 0,
60603
- data: asRecord12(row.payload)
60724
+ data: asRecord14(row.payload)
60604
60725
  }));
60605
60726
  const durable = journalToTranscriptRows(entries, skip);
60606
60727
  const stored = durable.map((row) => {
@@ -60643,8 +60764,8 @@ function bridgeReplayRowsToSeamTranscript(rows, skip = 0, sessionId) {
60643
60764
  return merged;
60644
60765
  }
60645
60766
  function seamReplayEventKey(event) {
60646
- const details = asRecord12(event.details);
60647
- return `${event.type}:${String(details.id ?? details.messageID ?? "")}:${String(asRecord12(details.part).id ?? "")}`;
60767
+ const details = asRecord14(event.details);
60768
+ return `${event.type}:${String(details.id ?? details.messageID ?? "")}:${String(asRecord14(details.part).id ?? "")}`;
60648
60769
  }
60649
60770
  function askJournalKind(row, data) {
60650
60771
  if (typeof data.kind === "string" && data.kind !== "")
@@ -60658,7 +60779,7 @@ function deriveAskOutcomeNoticeViews(rows, sessionId) {
60658
60779
  const out = [];
60659
60780
  const terminals = new Map;
60660
60781
  for (const row of rows) {
60661
- const data = asRecord12(row.payload);
60782
+ const data = asRecord14(row.payload);
60662
60783
  const kind = askJournalKind(row, data);
60663
60784
  if (kind !== "ask.responded" && kind !== "ask.cancelled")
60664
60785
  continue;
@@ -60675,7 +60796,7 @@ function deriveAskOutcomeNoticeViews(rows, sessionId) {
60675
60796
  const ordered = [...group].sort((a, b) => a.seq - b.seq);
60676
60797
  const canonical = ordered[ordered.length - 1];
60677
60798
  const noticeOf = (row) => {
60678
- const data = asRecord12(row.payload);
60799
+ const data = asRecord14(row.payload);
60679
60800
  return deriveAskOutcomeNotice({
60680
60801
  eventId,
60681
60802
  sessionId,
@@ -60692,7 +60813,7 @@ function deriveAskOutcomeNoticeViews(rows, sessionId) {
60692
60813
  const canonicalNotice = noticeOf(canonical);
60693
60814
  if (canonicalNotice === undefined)
60694
60815
  continue;
60695
- const canonicalChild = optionalStringField(asRecord12(canonical.payload), "childSessionId");
60816
+ const canonicalChild = optionalStringField(asRecord14(canonical.payload), "childSessionId");
60696
60817
  out.push({
60697
60818
  id: canonicalNotice.id,
60698
60819
  text: canonicalNotice.text,
@@ -60708,7 +60829,7 @@ function deriveAskOutcomeNoticeViews(rows, sessionId) {
60708
60829
  if (other === undefined || seenText.has(other.text))
60709
60830
  continue;
60710
60831
  seenText.add(other.text);
60711
- const childSessionId = optionalStringField(asRecord12(row.payload), "childSessionId");
60832
+ const childSessionId = optionalStringField(asRecord14(row.payload), "childSessionId");
60712
60833
  out.push({
60713
60834
  id: `${other.id}:seq-${row.seq}`,
60714
60835
  text: `\u3010\u65E5\u5FD7\u7ED3\u5C40\u51B2\u7A81\u3011${other.text}`,
@@ -60723,7 +60844,7 @@ function deriveAskOutcomeNoticeViews(rows, sessionId) {
60723
60844
  for (const row of rows) {
60724
60845
  if (row.type !== "turn/end")
60725
60846
  continue;
60726
- const data = asRecord12(row.payload);
60847
+ const data = asRecord14(row.payload);
60727
60848
  const keys = [optionalStringField(data, "turnId")];
60728
60849
  if (typeof data.turn === "number" && Number.isFinite(data.turn))
60729
60850
  keys.push(String(data.turn));
@@ -60736,7 +60857,7 @@ function deriveAskOutcomeNoticeViews(rows, sessionId) {
60736
60857
  }
60737
60858
  }
60738
60859
  for (const row of rows) {
60739
- const data = asRecord12(row.payload);
60860
+ const data = asRecord14(row.payload);
60740
60861
  if (askJournalKind(row, data) !== "ask.requested")
60741
60862
  continue;
60742
60863
  const eventId = optionalStringField(data, "eventId");
@@ -60803,7 +60924,7 @@ function bridgeReplayRowsToSeamEvents(rows, sessionId) {
60803
60924
  };
60804
60925
  const toolCalls = new Map;
60805
60926
  for (const row of rows) {
60806
- const entry = { type: row.type, seq: row.seq, time: 0, data: asRecord12(row.payload) };
60927
+ const entry = { type: row.type, seq: row.seq, time: 0, data: asRecord14(row.payload) };
60807
60928
  for (const event of projectJournalRecord(entry, sessionId))
60808
60929
  push(event);
60809
60930
  const data = entry.data;
@@ -60817,7 +60938,7 @@ function bridgeReplayRowsToSeamEvents(rows, sessionId) {
60817
60938
  });
60818
60939
  }
60819
60940
  } else if (row.type === "tool/result") {
60820
- const message = asRecord12(data.message);
60941
+ const message = asRecord14(data.message);
60821
60942
  const callId = data.callId !== undefined ? String(data.callId) : message.toolCallId !== undefined ? String(message.toolCallId) : "";
60822
60943
  const call = callId ? toolCalls.get(callId) : undefined;
60823
60944
  if (call !== undefined) {
@@ -60875,7 +60996,7 @@ function bridgeSettleChild(existing, outcome, startedAt, now) {
60875
60996
  function bridgeFoldAgentRecord(children, runSeq, liveStarts, type, data, now, live) {
60876
60997
  const name = typeof data.name === "string" && data.name !== "" ? data.name : undefined;
60877
60998
  if (type === "user/message") {
60878
- const source = asRecord12(data.source);
60999
+ const source = asRecord14(data.source);
60879
61000
  if (source.kind !== BRIDGE_SUBAGENT_SETTLED)
60880
61001
  return false;
60881
61002
  const childId = typeof source.senderSessionId === "string" ? source.senderSessionId : "";
@@ -60982,7 +61103,7 @@ function bridgeSweepSettledChildIds(rows, parentId, locallyRunning) {
60982
61103
  return [];
60983
61104
  const settled = [];
60984
61105
  for (const raw of rows) {
60985
- const row = asRecord12(raw);
61106
+ const row = asRecord14(raw);
60986
61107
  if (row.origin !== "subagent")
60987
61108
  continue;
60988
61109
  if (row.parentSessionId !== parentId)
@@ -61032,16 +61153,16 @@ function bridgeChildJournalMeta(rows) {
61032
61153
  let contextModel;
61033
61154
  let descriptorModel;
61034
61155
  for (const row of rows) {
61035
- const data = asRecord12(row.payload);
61156
+ const data = asRecord14(row.payload);
61036
61157
  if (row.type === "assistant/message") {
61037
61158
  rounds += 1;
61038
- const message = asRecord12(data.message);
61159
+ const message = asRecord14(data.message);
61039
61160
  const tail = bridgeLastContentLine(bridgeBlocksText(message.content ?? data.content));
61040
61161
  if (tail !== undefined)
61041
61162
  lastLine = tail;
61042
61163
  } else if (row.type === "tool/result") {
61043
61164
  if (data.isError !== true) {
61044
- const message = asRecord12(data.message);
61165
+ const message = asRecord14(data.message);
61045
61166
  const tail = bridgeLastContentLine(bridgeBlocksText(message.content ?? data.content));
61046
61167
  if (tail !== undefined)
61047
61168
  lastLine = tail;
@@ -61099,7 +61220,7 @@ function capChildLog(lines) {
61099
61220
  return out;
61100
61221
  }
61101
61222
  function childTranscriptRowToLine(row) {
61102
- const r = asRecord12(row);
61223
+ const r = asRecord14(row);
61103
61224
  if (r.kind !== "assistant" && r.kind !== "tool")
61104
61225
  return "";
61105
61226
  const text = typeof r.text === "string" ? r.text : "";
@@ -61125,7 +61246,7 @@ function bridgeChildStopReason(rows) {
61125
61246
  const row = rows[i];
61126
61247
  if (row.type !== "user/message")
61127
61248
  continue;
61128
- const source = asRecord12(asRecord12(row.payload).source);
61249
+ const source = asRecord14(asRecord14(row.payload).source);
61129
61250
  if (source.kind !== BRIDGE_SUBAGENT_SETTLED)
61130
61251
  continue;
61131
61252
  const reason = source.stopReason;
@@ -61136,7 +61257,7 @@ function bridgeChildStopReason(rows) {
61136
61257
  const row = rows[i];
61137
61258
  if (row.type !== "turn/end")
61138
61259
  continue;
61139
- const reason = asRecord12(asRecord12(row.payload).reason);
61260
+ const reason = asRecord14(asRecord14(row.payload).reason);
61140
61261
  const kind = reason.kind;
61141
61262
  if (typeof kind === "string" && kind !== "")
61142
61263
  return kind;
@@ -61194,7 +61315,7 @@ function lastJournalTurnTerminal(rows, startOutsideWindow = false) {
61194
61315
  return latest;
61195
61316
  }
61196
61317
  function journalTurnId(row) {
61197
- const payload = asRecord12(row.payload);
61318
+ const payload = asRecord14(row.payload);
61198
61319
  if (typeof payload.turn === "number" && Number.isFinite(payload.turn))
61199
61320
  return payload.turn;
61200
61321
  if (typeof payload.turnId === "string" && payload.turnId !== "")
@@ -61202,7 +61323,7 @@ function journalTurnId(row) {
61202
61323
  return;
61203
61324
  }
61204
61325
  function projectBridgeEvent(frame, sessionId) {
61205
- const payload = asRecord12(frame.payload);
61326
+ const payload = asRecord14(frame.payload);
61206
61327
  const turnId = typeof payload.turnId === "string" ? payload.turnId : "";
61207
61328
  if (frame.type === "turn.start") {
61208
61329
  return [{ type: "session.updated", details: { sessionID: sessionId, turnId, turn: "starting" } }];
@@ -61224,7 +61345,7 @@ function projectBridgeEvent(frame, sessionId) {
61224
61345
  return [];
61225
61346
  }
61226
61347
  function parseUsage(value) {
61227
- const u = asRecord12(value);
61348
+ const u = asRecord14(value);
61228
61349
  const num = (...aliases) => {
61229
61350
  let present = false;
61230
61351
  let best = 0;
@@ -61253,7 +61374,7 @@ function parseUsage(value) {
61253
61374
  return out;
61254
61375
  }
61255
61376
  function journalUsage(payload) {
61256
- const usage = asRecord12(asRecord12(payload).usage);
61377
+ const usage = asRecord14(asRecord14(payload).usage);
61257
61378
  const parsed = parseUsage(usage);
61258
61379
  if (Object.keys(parsed).length === 0)
61259
61380
  return;
@@ -61263,7 +61384,7 @@ function journalUsage(payload) {
61263
61384
  return { ...parsed, total };
61264
61385
  }
61265
61386
  function asDeadCause(value) {
61266
- const r = asRecord12(value);
61387
+ const r = asRecord14(value);
61267
61388
  const stage = r.stage;
61268
61389
  const stages = ["spawn", "handshake", "runtime", "closed"];
61269
61390
  return {
@@ -61383,7 +61504,7 @@ class BridgeSessionSeam {
61383
61504
  cancelSignIn: async (attemptId) => projectSeamAccountView(await this.#transport.request("account.cancelSignIn", { attemptId })),
61384
61505
  signOut: async () => projectSeamAccountView(await this.#transport.request("account.signOut", { client: accountClientMeta() })),
61385
61506
  hasRunningAccountTasks: async () => {
61386
- const value = asRecord12(await this.#transport.request("account.hasRunningAccountTasks"));
61507
+ const value = asRecord14(await this.#transport.request("account.hasRunningAccountTasks"));
61387
61508
  return value.running === true;
61388
61509
  }
61389
61510
  };
@@ -61608,7 +61729,7 @@ class BridgeSessionSeam {
61608
61729
  return [];
61609
61730
  const out = [];
61610
61731
  for (const e of efforts) {
61611
- const row = asRecord12(e);
61732
+ const row = asRecord14(e);
61612
61733
  const id = typeof row.id === "string" ? row.id : "";
61613
61734
  const name = typeof row.name === "string" ? row.name : "";
61614
61735
  if (!id)
@@ -61730,7 +61851,7 @@ class BridgeSessionSeam {
61730
61851
  }
61731
61852
  async connect() {
61732
61853
  try {
61733
- const reply = asRecord12(await this.#transport.request("bridge.ping"));
61854
+ const reply = asRecord14(await this.#transport.request("bridge.ping"));
61734
61855
  this.#recordBridgeCapabilities(reply.capabilities);
61735
61856
  this.#connection = "connected";
61736
61857
  } catch (err) {
@@ -61768,7 +61889,7 @@ class BridgeSessionSeam {
61768
61889
  this.#currentSessionId = undefined;
61769
61890
  this.#resetModelRoute();
61770
61891
  this.#pendingOpen = { mode: "new" };
61771
- this.#settleSuspendedTurn();
61892
+ this.#settleSuspendedTurn({ code: "SESSION_CLOSED", reason: "session changed" });
61772
61893
  this.#deadInFlight = undefined;
61773
61894
  this.#inFlightPartial = "";
61774
61895
  }
@@ -61819,7 +61940,7 @@ class BridgeSessionSeam {
61819
61940
  this.#replayDrainPending = true;
61820
61941
  let opened;
61821
61942
  try {
61822
- opened = asRecord12(await this.#transport.request("session.open", { mode: "resume", id: sessionId }));
61943
+ opened = asRecord14(await this.#transport.request("session.open", { mode: "resume", id: sessionId }));
61823
61944
  } catch (err) {
61824
61945
  const code = err instanceof BridgeProtocolError ? err.code : "SESSION_OPEN_FAILED";
61825
61946
  const message = err instanceof Error ? err.message : String(err);
@@ -61829,7 +61950,7 @@ class BridgeSessionSeam {
61829
61950
  this.#bufferedPendingSnapshot = undefined;
61830
61951
  this.#replayDrainPending = false;
61831
61952
  this.#settleSuspendedTurn();
61832
- const errorDetail = err instanceof BridgeProtocolError ? asRecord12(err.detail) : {};
61953
+ const errorDetail = err instanceof BridgeProtocolError ? asRecord14(err.detail) : {};
61833
61954
  const holder = typeof errorDetail.holder === "string" && errorDetail.holder.trim() !== "" ? errorDetail.holder : undefined;
61834
61955
  const result = {
61835
61956
  state: "locked",
@@ -61907,12 +62028,12 @@ class BridgeSessionSeam {
61907
62028
  turnId: dead.turnId,
61908
62029
  seq: terminal.seq,
61909
62030
  terminalType: terminal.type,
61910
- reason: asRecord12(terminal.payload).reason,
62031
+ reason: asRecord14(terminal.payload).reason,
61911
62032
  payload: terminal.payload,
61912
62033
  source: "journal"
61913
62034
  }
61914
62035
  });
61915
- this.#settleSuspendedTurn();
62036
+ this.#settleSuspendedTurn({ terminalEmitted: true });
61916
62037
  } else {
61917
62038
  emit({
61918
62039
  type: "bridge.turn.interrupted",
@@ -61926,7 +62047,7 @@ class BridgeSessionSeam {
61926
62047
  source: "local"
61927
62048
  }
61928
62049
  });
61929
- this.#settleSuspendedTurn();
62050
+ this.#settleSuspendedTurn({ terminalEmitted: true });
61930
62051
  }
61931
62052
  }
61932
62053
  await new Promise((resolve) => setTimeout(resolve, 0));
@@ -61965,7 +62086,7 @@ class BridgeSessionSeam {
61965
62086
  const seen = new Set;
61966
62087
  const collected = [];
61967
62088
  for (;; ) {
61968
- const value = asRecord12(await this.#transport.request("journal.replay", { sessionId, from }));
62089
+ const value = asRecord14(await this.#transport.request("journal.replay", { sessionId, from }));
61969
62090
  const rawRows = Array.isArray(value.rows) ? value.rows : [];
61970
62091
  if (typeof value.cursor === "number" && Number.isFinite(value.cursor))
61971
62092
  cursor = value.cursor;
@@ -61978,7 +62099,7 @@ class BridgeSessionSeam {
61978
62099
  let added = 0;
61979
62100
  let pageMax = from - 1;
61980
62101
  for (const raw of rawRows) {
61981
- const row = asRecord12(raw);
62102
+ const row = asRecord14(raw);
61982
62103
  const seq = row.seq;
61983
62104
  if (typeof seq !== "number" || !Number.isFinite(seq) || seq < floor || seen.has(seq))
61984
62105
  continue;
@@ -62027,7 +62148,7 @@ class BridgeSessionSeam {
62027
62148
  };
62028
62149
  const attempt = (remaining) => {
62029
62150
  this.#transport.request("turn.abort", { turnId }).then((result) => {
62030
- if (asRecord12(result).noop === true) {
62151
+ if (asRecord14(result).noop === true) {
62031
62152
  fail(`turn.abort was a noop for turn ${turnId}; turn may still be running`, "TURN_ABORT_NOOP");
62032
62153
  }
62033
62154
  }).catch((err) => {
@@ -62165,7 +62286,7 @@ class BridgeSessionSeam {
62165
62286
  stats.contextTokens = usage.total;
62166
62287
  }
62167
62288
  } else if (row.type === "request/context") {
62168
- const data = asRecord12(row.payload);
62289
+ const data = asRecord14(row.payload);
62169
62290
  const window = data.contextWindow;
62170
62291
  if (typeof window === "number" && Number.isFinite(window) && window > 0) {
62171
62292
  const provider = typeof data.provider === "string" ? data.provider : "";
@@ -62310,7 +62431,7 @@ class BridgeSessionSeam {
62310
62431
  this.#interruptInFlight.set(childId, generation);
62311
62432
  let value;
62312
62433
  try {
62313
- value = asRecord12(await this.#transport.request("subagents.interrupt", { parentSessionId, childId }));
62434
+ value = asRecord14(await this.#transport.request("subagents.interrupt", { parentSessionId, childId }));
62314
62435
  } catch (err) {
62315
62436
  if (this.#interruptInFlight.get(childId) === generation)
62316
62437
  this.#interruptInFlight.delete(childId);
@@ -62336,13 +62457,13 @@ class BridgeSessionSeam {
62336
62457
  if (parentSessionId === undefined || parentSessionId === "") {
62337
62458
  throw new BridgeProtocolError("NO_SESSION", "cannot stop children: no session is bound to this bridge connection");
62338
62459
  }
62339
- const value = asRecord12(await this.#transport.request("subagents.stopChildren", { parentSessionId }));
62460
+ const value = asRecord14(await this.#transport.request("subagents.stopChildren", { parentSessionId }));
62340
62461
  const children = value.children;
62341
62462
  if (!Array.isArray(children))
62342
62463
  return [];
62343
62464
  const sessionAtStart = this.#subagentSessionId;
62344
62465
  const rows = children.map((row) => {
62345
- const r = asRecord12(row);
62466
+ const r = asRecord14(row);
62346
62467
  return {
62347
62468
  childId: typeof r.childId === "string" ? r.childId : "",
62348
62469
  disposition: typeof r.disposition === "string" ? r.disposition : "failed"
@@ -62368,10 +62489,10 @@ class BridgeSessionSeam {
62368
62489
  return;
62369
62490
  let stopped = false;
62370
62491
  try {
62371
- const items = asRecord12(await this.#transport.request("session.list", { _request: {} })).items;
62492
+ const items = asRecord14(await this.#transport.request("session.list", { _request: {} })).items;
62372
62493
  if (Array.isArray(items)) {
62373
62494
  stopped = items.some((row) => {
62374
- const item = asRecord12(row);
62495
+ const item = asRecord14(row);
62375
62496
  return item.sessionId === childId && item.running === false;
62376
62497
  });
62377
62498
  }
@@ -62381,7 +62502,7 @@ class BridgeSessionSeam {
62381
62502
  if (stopped) {
62382
62503
  let reason = "aborted";
62383
62504
  try {
62384
- const rows = asRecord12(await this.#transport.request("journal.replay", { sessionId: childId })).rows;
62505
+ const rows = asRecord14(await this.#transport.request("journal.replay", { sessionId: childId })).rows;
62385
62506
  if (Array.isArray(rows)) {
62386
62507
  const clean = rows.filter((row) => row !== null && typeof row === "object" && !Array.isArray(row));
62387
62508
  reason = bridgeChildStopReason(clean) ?? "aborted";
@@ -62441,7 +62562,7 @@ class BridgeSessionSeam {
62441
62562
  } catch {
62442
62563
  return;
62443
62564
  }
62444
- const items = asRecord12(value).items;
62565
+ const items = asRecord14(value).items;
62445
62566
  if (!Array.isArray(items))
62446
62567
  return;
62447
62568
  const locallyRunning = new Set;
@@ -62486,7 +62607,7 @@ class BridgeSessionSeam {
62486
62607
  this.#subagentJournalLoaded.add(key);
62487
62608
  const sessionAtStart = this.#subagentSessionId;
62488
62609
  try {
62489
- const value = asRecord12(await this.#transport.request("journal.replay", { sessionId: childId }));
62610
+ const value = asRecord14(await this.#transport.request("journal.replay", { sessionId: childId }));
62490
62611
  const rows = value.rows;
62491
62612
  if (!Array.isArray(rows)) {
62492
62613
  this.#subagentTranscriptReadFailed.add(childId);
@@ -62604,7 +62725,7 @@ class BridgeSessionSeam {
62604
62725
  }
62605
62726
  }
62606
62727
  #foldAgentFrame(frame) {
62607
- const payload = asRecord12(frame.payload);
62728
+ const payload = asRecord14(frame.payload);
62608
62729
  const frameSession = typeof payload.sessionId === "string" ? payload.sessionId : "";
62609
62730
  if (this.#subagentSessionId !== undefined && frameSession !== "" && frameSession !== this.#subagentSessionId)
62610
62731
  return;
@@ -62677,7 +62798,7 @@ class BridgeSessionSeam {
62677
62798
  this.#emitSubagentViews();
62678
62799
  }
62679
62800
  #foldAgentProgress(frame) {
62680
- const payload = asRecord12(frame.payload);
62801
+ const payload = asRecord14(frame.payload);
62681
62802
  const frameSession = typeof payload.sessionId === "string" ? payload.sessionId : "";
62682
62803
  if (this.#subagentSessionId !== undefined && frameSession !== "" && frameSession !== this.#subagentSessionId)
62683
62804
  return;
@@ -62704,7 +62825,7 @@ class BridgeSessionSeam {
62704
62825
  this.#emitSubagentViews();
62705
62826
  }
62706
62827
  #foldAgentTranscript(frame) {
62707
- const payload = asRecord12(frame.payload);
62828
+ const payload = asRecord14(frame.payload);
62708
62829
  const frameSession = typeof payload.sessionId === "string" ? payload.sessionId : "";
62709
62830
  const childId = typeof payload.childId === "string" ? payload.childId : "";
62710
62831
  const turnId = typeof payload.turnId === "string" ? payload.turnId : "";
@@ -62765,7 +62886,7 @@ class BridgeSessionSeam {
62765
62886
  let changed = false;
62766
62887
  const now = Date.now();
62767
62888
  for (const row of rows) {
62768
- if (this.#foldWithFrozenSettle(row.type, asRecord12(row.payload), now, false))
62889
+ if (this.#foldWithFrozenSettle(row.type, asRecord14(row.payload), now, false))
62769
62890
  changed = true;
62770
62891
  }
62771
62892
  if (rosterReset || changed) {
@@ -62800,7 +62921,7 @@ class BridgeSessionSeam {
62800
62921
  }
62801
62922
  async listSessions(limit) {
62802
62923
  const value = await this.#transport.request("session.list");
62803
- return projectBridgeSessionList(asRecord12(value).items, limit);
62924
+ return projectBridgeSessionList(asRecord14(value).items, limit);
62804
62925
  }
62805
62926
  async planPrune(params) {
62806
62927
  const staged = this.stagedSessionId();
@@ -62845,27 +62966,27 @@ class BridgeSessionSeam {
62845
62966
  if (sessionId === undefined || sessionId === "")
62846
62967
  return;
62847
62968
  const value = await this.#transport.request("session.list");
62848
- return projectCurrentCwd(asRecord12(value).items, sessionId);
62969
+ return projectCurrentCwd(asRecord14(value).items, sessionId);
62849
62970
  }
62850
62971
  async storedTranscript(id, skip = 0) {
62851
62972
  const value = await this.#transport.request("journal.replay", { sessionId: id });
62852
- const rows = Array.isArray(asRecord12(value).rows) ? asRecord12(value).rows : [];
62973
+ const rows = Array.isArray(asRecord14(value).rows) ? asRecord14(value).rows : [];
62853
62974
  this.#foldAgentReplayRows(rows, id);
62854
62975
  this.#sweepSubagents(id);
62855
62976
  return bridgeReplayRowsToSeamTranscript(rows, skip, id);
62856
62977
  }
62857
62978
  async sessionJournal(id) {
62858
62979
  const value = await this.#transport.request("journal.replay", { sessionId: id });
62859
- const rows = Array.isArray(asRecord12(value).rows) ? asRecord12(value).rows : [];
62980
+ const rows = Array.isArray(asRecord14(value).rows) ? asRecord14(value).rows : [];
62860
62981
  return rows.map((row) => ({
62861
62982
  type: row.type,
62862
62983
  seq: row.seq,
62863
62984
  time: 0,
62864
- data: asRecord12(row.payload)
62985
+ data: asRecord14(row.payload)
62865
62986
  }));
62866
62987
  }
62867
62988
  async forkSession(sessionId, seqEnd) {
62868
- const value = asRecord12(await this.#transport.request("session.fork", {
62989
+ const value = asRecord14(await this.#transport.request("session.fork", {
62869
62990
  sessionId,
62870
62991
  ...seqEnd !== undefined ? { atSeq: seqEnd } : {}
62871
62992
  }));
@@ -62970,7 +63091,7 @@ class BridgeSessionSeam {
62970
63091
  cache.complete = true;
62971
63092
  }
62972
63093
  #writeModelRouteReply(reply, expectedSessionId) {
62973
- const route = routeFromSelection(asRecord12(reply).selected);
63094
+ const route = routeFromSelection(asRecord14(reply).selected);
62974
63095
  if (route === undefined)
62975
63096
  return;
62976
63097
  const sessionId = this.#currentSessionId ?? this.stagedSessionId();
@@ -62992,9 +63113,23 @@ class BridgeSessionSeam {
62992
63113
  const fallback = await this.#defaultModelRoute();
62993
63114
  return fallback !== undefined ? { providerID: fallback.providerID, modelID: fallback.modelID } : undefined;
62994
63115
  }
62995
- #settleSuspendedTurn() {
63116
+ #settleSuspendedTurn(options) {
62996
63117
  const done = this.#turnDone;
62997
63118
  const endedTurnId = this.#inFlightTurnId;
63119
+ if (!(options?.terminalEmitted ?? false) && done !== undefined) {
63120
+ this.#emitEvent({
63121
+ type: "bridge.turn.interrupted",
63122
+ details: {
63123
+ sessionID: this.#currentSessionId ?? "",
63124
+ turnId: endedTurnId,
63125
+ partial: this.#inFlightPartial,
63126
+ reason: options?.reason ?? "turn interrupted before a terminal event",
63127
+ code: options?.code ?? "INTERRUPTED",
63128
+ seq: null,
63129
+ source: "local"
63130
+ }
63131
+ });
63132
+ }
62998
63133
  this.#turnDone = undefined;
62999
63134
  this.#activeCallbacks = undefined;
63000
63135
  this.#inFlightTurnId = undefined;
@@ -63036,7 +63171,7 @@ class BridgeSessionSeam {
63036
63171
  }
63037
63172
  const params = pending.mode === "resume" ? { mode: "resume", id: pending.id, ...this.#sessionAttached ? { replace: true } : {} } : { mode: "new" };
63038
63173
  try {
63039
- const opened = asRecord12(await this.#transport.request("session.open", params));
63174
+ const opened = asRecord14(await this.#transport.request("session.open", params));
63040
63175
  if (typeof opened.sessionId === "string")
63041
63176
  this.#currentSessionId = opened.sessionId;
63042
63177
  if (this.#lastAppliedSessionId !== this.#currentSessionId) {
@@ -63054,7 +63189,7 @@ class BridgeSessionSeam {
63054
63189
  const done = new Promise((resolve) => {
63055
63190
  this.#turnDone = resolve;
63056
63191
  });
63057
- const sent = asRecord12(await this.#transport.request("session.send", { text: userText }));
63192
+ const sent = asRecord14(await this.#transport.request("session.send", { text: userText }));
63058
63193
  if (typeof sent.turnId === "string") {
63059
63194
  this.#inFlightTurnId = sent.turnId;
63060
63195
  this.#emitEvent({
@@ -63154,10 +63289,10 @@ class BridgeSessionSeam {
63154
63289
  }
63155
63290
  }
63156
63291
  async searchSessions(query) {
63157
- const value = asRecord12(await this.#transport.request("session.search", { query }));
63292
+ const value = asRecord14(await this.#transport.request("session.search", { query }));
63158
63293
  const rows = Array.isArray(value.items) ? value.items : [];
63159
63294
  return rows.map((row) => {
63160
- const r = asRecord12(row);
63295
+ const r = asRecord14(row);
63161
63296
  return {
63162
63297
  id: typeof r.id === "string" ? r.id : "",
63163
63298
  snippet: typeof r.snippet === "string" ? r.snippet : ""
@@ -63167,8 +63302,29 @@ class BridgeSessionSeam {
63167
63302
  async renameSession(_title) {
63168
63303
  return unsupported("renameSession");
63169
63304
  }
63170
- steer(_text) {
63171
- this.#degrade("steer", "no session.steer frame; steer is a no-op");
63305
+ async steer(text) {
63306
+ if (!this.hasBridgeCapability("session.steer")) {
63307
+ return { accepted: false, reason: "UNSUPPORTED" };
63308
+ }
63309
+ let reply;
63310
+ try {
63311
+ reply = await this.#transport.request("session.steer", { text });
63312
+ } catch (err) {
63313
+ if (err instanceof BridgeProtocolError && STEER_REJECTION_CODES.has(err.code)) {
63314
+ const detail = asRecord14(err.detail);
63315
+ return {
63316
+ accepted: false,
63317
+ reason: err.code,
63318
+ ...typeof detail.turnId === "string" ? { turnId: detail.turnId } : {}
63319
+ };
63320
+ }
63321
+ throw err;
63322
+ }
63323
+ const result = asRecord14(reply);
63324
+ if (result.accepted !== true || typeof result.turnId !== "string") {
63325
+ throw new BridgeProtocolError("INTERNAL", "session.steer reply has no accepted:true turnId");
63326
+ }
63327
+ return { accepted: true, turnId: result.turnId };
63172
63328
  }
63173
63329
  registerAskProvider(onAsk) {
63174
63330
  this.#askProvider = onAsk;
@@ -63345,7 +63501,7 @@ class BridgeSessionSeam {
63345
63501
  return { ...request, sessionId: parent };
63346
63502
  }
63347
63503
  #onAskEvent(frame) {
63348
- const payload = asRecord12(frame.payload);
63504
+ const payload = asRecord14(frame.payload);
63349
63505
  if (frame.type === "ask.request" || frame.type === "ask.pending")
63350
63506
  this.#askFrameSeen = true;
63351
63507
  switch (frame.type) {
@@ -63433,7 +63589,7 @@ class BridgeSessionSeam {
63433
63589
  #onCapPushEvent(frame) {
63434
63590
  if (frame.type !== "cap.event" && frame.type !== "cap.end")
63435
63591
  return false;
63436
- const payload = asRecord12(frame.payload);
63592
+ const payload = asRecord14(frame.payload);
63437
63593
  const sessionId = optionalStringField(payload, "sessionId");
63438
63594
  if (sessionId === undefined || sessionId === "")
63439
63595
  return true;
@@ -63515,7 +63671,7 @@ class BridgeSessionSeam {
63515
63671
  }
63516
63672
  return;
63517
63673
  }
63518
- const payload = asRecord12(frame.payload);
63674
+ const payload = asRecord14(frame.payload);
63519
63675
  if (frame.type === "turn.start") {
63520
63676
  this.#turn = "starting";
63521
63677
  this.#decodeWindowStart = undefined;
@@ -63596,7 +63752,7 @@ class BridgeSessionSeam {
63596
63752
  }
63597
63753
  }
63598
63754
  }
63599
- var CONFIRM_REQUIRED = (method) => new BridgeProtocolError("CONFIRM_REQUIRED", `${method}: write requires a confirmed TUI modal token`), BridgeProtocolError, ACCOUNT_STATUSES, ACCOUNT_PHASES, ROUTE_ROW_TYPES, BRIDGE_AGENT_START = "tool-workflow/agent-start", BRIDGE_AGENT_END = "tool-workflow/agent-end", BRIDGE_SUBAGENT_CATALOG = "subagent/catalog", BRIDGE_SUBAGENT_SETTLED = "subagent-settled", BRIDGE_CATALOG_RUN_PREFIX = "catalog:", CHILD_TRANSCRIPT_MAX_LINES = 500, CHILD_TRANSCRIPT_MAX_BYTES, childTextEncoder, childStrictTextDecoder, CHILD_TRANSCRIPT_LINE_BUDGET, CHILD_TRANSCRIPT_TRUNCATION_MARKER = "\u2026", CHILD_TRANSCRIPT_TRUNCATION_MARKER_BYTES, CONFIRM_POLL_INITIAL_MS = 250, CONFIRM_POLL_MAX_MS = 1000, CONFIRM_TIMEOUT_MS = 45000, fmtTokens = (n) => n >= 1000 ? `${(n / 1000).toFixed(1)}k` : `${n}`;
63755
+ var CONFIRM_REQUIRED = (method) => new BridgeProtocolError("CONFIRM_REQUIRED", `${method}: write requires a confirmed TUI modal token`), ACCOUNT_STATUSES, ACCOUNT_PHASES, STEER_REJECTION_CODES, ROUTE_ROW_TYPES, BRIDGE_AGENT_START = "tool-workflow/agent-start", BRIDGE_AGENT_END = "tool-workflow/agent-end", BRIDGE_SUBAGENT_CATALOG = "subagent/catalog", BRIDGE_SUBAGENT_SETTLED = "subagent-settled", BRIDGE_CATALOG_RUN_PREFIX = "catalog:", CHILD_TRANSCRIPT_MAX_LINES = 500, CHILD_TRANSCRIPT_MAX_BYTES, childTextEncoder, childStrictTextDecoder, CHILD_TRANSCRIPT_LINE_BUDGET, CHILD_TRANSCRIPT_TRUNCATION_MARKER = "\u2026", CHILD_TRANSCRIPT_TRUNCATION_MARKER_BYTES, CONFIRM_POLL_INITIAL_MS = 250, CONFIRM_POLL_MAX_MS = 1000, CONFIRM_TIMEOUT_MS = 45000, fmtTokens = (n) => n >= 1000 ? `${(n / 1000).toFixed(1)}k` : `${n}`;
63600
63756
  var init_bridge_session_seam = __esm(() => {
63601
63757
  init_remote_session_ops();
63602
63758
  init_journal_projection();
@@ -63609,17 +63765,10 @@ var init_bridge_session_seam = __esm(() => {
63609
63765
  init_bridge_goals();
63610
63766
  init_bridge_settings_route();
63611
63767
  init_subagent_policy();
63612
- BridgeProtocolError = class BridgeProtocolError extends Error {
63613
- code;
63614
- detail;
63615
- constructor(code, message, detail) {
63616
- super(message);
63617
- this.name = "BridgeProtocolError";
63618
- this.code = code;
63619
- if (detail !== undefined)
63620
- this.detail = detail;
63621
- }
63622
- };
63768
+ init_bridge_protocol_error();
63769
+ init_prune_purge();
63770
+ init_bridge_protocol_error();
63771
+ init_prune_purge();
63623
63772
  ACCOUNT_STATUSES = new Set(["signed-out", "credential-stored"]);
63624
63773
  ACCOUNT_PHASES = new Set([
63625
63774
  "initializing",
@@ -63631,6 +63780,14 @@ var init_bridge_session_seam = __esm(() => {
63631
63780
  "expired",
63632
63781
  "failed"
63633
63782
  ]);
63783
+ STEER_REJECTION_CODES = new Set([
63784
+ "STEER_IDLE",
63785
+ "STEER_ENDED",
63786
+ "STEER_ABORTING",
63787
+ "SESSION_NOT_OPEN",
63788
+ "BAD_PARAMS",
63789
+ "UNSUPPORTED"
63790
+ ]);
63634
63791
  ROUTE_ROW_TYPES = new Set(["model/selection", "request/header", "request/context"]);
63635
63792
  CHILD_TRANSCRIPT_MAX_BYTES = 64 * 1024;
63636
63793
  childTextEncoder = new TextEncoder;
@@ -63743,11 +63900,11 @@ function toBridgeBootstrapError(err, fallbackCode = "BRIDGE_HANDSHAKE_FAILED") {
63743
63900
  const message = err instanceof Error ? err.message : String(err);
63744
63901
  return new BridgeBootstrapError({ code: fallbackCode, diagnosis: `bridge handshake failed: ${message}` });
63745
63902
  }
63746
- function asRecord13(value) {
63903
+ function asRecord15(value) {
63747
63904
  return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
63748
63905
  }
63749
63906
  function verifyBridgeFingerprint(hello, expectedProtocolVersion = BRIDGE_PROTOCOL_VERSION) {
63750
- const h = asRecord13(hello);
63907
+ const h = asRecord15(hello);
63751
63908
  const protocolVersion = h.protocolVersion;
63752
63909
  if (protocolVersion !== expectedProtocolVersion) {
63753
63910
  throw new BridgeBootstrapError({
@@ -63934,7 +64091,9 @@ function V2SessionPageBody(props) {
63934
64091
  "bridge.recovery.locked",
63935
64092
  "bridge.recovery.failed"
63936
64093
  ]);
64094
+ const turnTracker = new TurnOutcomeTracker;
63937
64095
  onCleanup(seam.onSessionEvent?.((event) => {
64096
+ turnTracker.onEvent(event);
63938
64097
  if (!recoveryEvents.has(event?.type))
63939
64098
  return;
63940
64099
  recovery.handleEvent(event);
@@ -64016,11 +64175,14 @@ function V2SessionPageBody(props) {
64016
64175
  const [lastRequest, setLastRequest] = createSignal();
64017
64176
  const [composerPending, setComposerPending] = createSignal([]);
64018
64177
  let turnAborted = false;
64019
- const send = (text) => {
64178
+ const send = (text, source) => {
64020
64179
  turnAborted = false;
64180
+ turnTracker.beginTurn();
64021
64181
  setTurnBusy(true);
64022
64182
  setLastRequest(text);
64023
- transcriptScroll?.scrollTo(Infinity);
64183
+ if (source !== "queue") {
64184
+ transcriptScroll?.scrollTo(Infinity);
64185
+ }
64024
64186
  const done = projection.send(text);
64025
64187
  done.finally(() => setTurnBusy(false));
64026
64188
  return done;
@@ -64527,7 +64689,8 @@ function V2SessionPageBody(props) {
64527
64689
  chooseDelivery: (text) => openDeliveryChoice(dialog, text),
64528
64690
  onPendingChange: (rows) => setComposerPending(rows),
64529
64691
  onQueuePaused: (info) => showNotice(`\u961F\u5217\u5DF2\u4FDD\u7559 ${info.remaining} \u6761:\u672C\u56DE\u5408${info.reason === "failed" ? "\u5931\u8D25" : "\u5DF2\u4E2D\u6B62"},\u4E0B\u56DE\u5408\u7ED3\u675F\u540E\u7EE7\u7EED\u53D1\u9001`, 8000),
64530
- isTurnAborted: () => turnAborted,
64692
+ isTurnAborted: () => turnAborted || turnTracker.isAborted(),
64693
+ isTurnFailed: () => turnTracker.isFailed(),
64531
64694
  slashKeyFilter: slash.slashKeyFilter,
64532
64695
  slashSync: (buffer) => slash.controller.sync(buffer, slash.commands),
64533
64696
  interceptSubmit: slash.interceptSubmit,
@@ -64869,7 +65032,7 @@ function recoveryCause(err, phase) {
64869
65032
  };
64870
65033
  }
64871
65034
  if (err instanceof BridgeProtocolError && err.code === "BRIDGE_DEAD") {
64872
- const detail = asRecord14(err.detail);
65035
+ const detail = asRecord16(err.detail);
64873
65036
  return {
64874
65037
  stage: phase,
64875
65038
  code: typeof detail.code === "number" ? detail.code : null,
@@ -64987,7 +65150,7 @@ class StdioBridgeTransport {
64987
65150
  } catch {
64988
65151
  return;
64989
65152
  }
64990
- const rec = asRecord14(frame);
65153
+ const rec = asRecord16(frame);
64991
65154
  if (typeof rec.id === "number") {
64992
65155
  const pending = this.#pending.get(rec.id);
64993
65156
  if (pending === undefined)
@@ -64999,7 +65162,7 @@ class StdioBridgeTransport {
64999
65162
  this.#setState("ready");
65000
65163
  pending.resolve(rec.result);
65001
65164
  } else {
65002
- const error = asRecord14(rec.error);
65165
+ const error = asRecord16(rec.error);
65003
65166
  pending.reject(new BridgeProtocolError(typeof error.code === "string" ? error.code : "BRIDGE_ERROR", typeof error.message === "string" ? error.message : "bridge request failed", error.detail));
65004
65167
  }
65005
65168
  return;
@@ -65131,7 +65294,7 @@ class StdioBridgeTransport {
65131
65294
  } catch {}
65132
65295
  }
65133
65296
  }
65134
- var asRecord14 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
65297
+ var asRecord16 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
65135
65298
  var init_bridge_transport = __esm(() => {
65136
65299
  init_bridge_session_seam();
65137
65300
  init_profile_constants();
@@ -65164,5 +65327,5 @@ if (import.meta.main) {
65164
65327
  main();
65165
65328
  }
65166
65329
 
65167
- //# debugId=2A5F7C9D91CE94DC64756E2164756E21
65330
+ //# debugId=24C78C0222CA1F8B64756E2164756E21
65168
65331
  //# sourceMappingURL=index.js.map