@causyne/agent 1.20.15 → 1.20.16

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.
package/src/toolsList.ts CHANGED
@@ -15,7 +15,7 @@
15
15
  * Authorship: Strict TypeScript (Causyne Agent).
16
16
  */
17
17
 
18
- export type ToolGroup = 'core' | 'system' | 'web' | 'media' | 'advanced' | 'game' | 'custom';
18
+ export type ToolGroup = 'core' | 'system' | 'web' | 'media' | 'advanced' | 'game' | 'reverse_engineering' | 'custom';
19
19
 
20
20
  export interface ToolListEntry {
21
21
  readonly name: string;
@@ -125,10 +125,13 @@ const CATALOGUE: Readonly<Record<Exclude<ToolGroup, 'custom'>, Readonly<Record<s
125
125
  game_data_forge: 'item and enemy data JSON',
126
126
  game_web_runtime_inspector: 'headless runtime error gate',
127
127
  game_canvas_audit: 'canvas render audit'
128
+ },
129
+ reverse_engineering: {
130
+ reverse_engineering: 'binary inspection, decompile, ASAR/bundle unpack, deobfuscate'
128
131
  }
129
132
  };
130
133
 
131
- const GROUP_ORDER: readonly Exclude<ToolGroup, 'custom'>[] = ['core', 'system', 'web', 'media', 'advanced', 'game'];
134
+ const GROUP_ORDER: readonly Exclude<ToolGroup, 'custom'>[] = ['core', 'system', 'web', 'media', 'advanced', 'game', 'reverse_engineering'];
132
135
 
133
136
  const CURATED_NAMES: ReadonlySet<string> = new Set(
134
137
  GROUP_ORDER.flatMap((group) => Object.keys(CATALOGUE[group]))
@@ -409,7 +409,7 @@ export class ChatRenderer {
409
409
  const parts = [];
410
410
  if (model) parts.push(paint('ink', model));
411
411
  parts.push(`${steps} step${steps === 1 ? '' : 's'}`);
412
- parts.push(formatDuration(durationMs));
412
+ if (durationMs > 0) parts.push(formatDuration(durationMs));
413
413
 
414
414
  const separator = dim(` ${GLYPHS.dot} `);
415
415
  this.write();
@@ -557,18 +557,117 @@ export class ChatRenderer {
557
557
  this.clearTranscript();
558
558
  this.latestPlan = [];
559
559
  this.onPlanChange?.([]);
560
+ this.resetTurn();
560
561
 
561
- if (sessionInfo && (sessionInfo.title || sessionInfo.id)) {
562
- this.renderSessionDivider(sessionInfo);
562
+ const info = sessionInfo ? { ...sessionInfo } : {};
563
+ if (info.messagesCount === undefined || info.messagesCount === null) {
564
+ info.messagesCount = messages.filter(m => m && m.role !== 'system').length;
563
565
  }
564
566
 
565
- for (const msg of messages) {
567
+ if (info.title || info.id) {
568
+ this.renderSessionDivider(info);
569
+ }
570
+
571
+ // Index tool results by tool_call_id to pair them with assistant tool_calls
572
+ const toolResultsById = new Map();
573
+ for (const m of messages) {
574
+ if (m && m.role === 'tool' && m.tool_call_id) {
575
+ toolResultsById.set(m.tool_call_id, m);
576
+ }
577
+ }
578
+
579
+ const renderedToolMessages = new Set();
580
+
581
+ for (let i = 0; i < messages.length; i++) {
582
+ const msg = messages[i];
566
583
  if (!msg) continue;
567
584
  const role = String(msg.role || '').toLowerCase();
585
+
568
586
  if (role === 'user') {
587
+ this.resetTurn();
569
588
  this.renderUserMessage(msg.content);
570
589
  } else if (role === 'assistant') {
571
- this.renderAssistantMessage(msg.content);
590
+ // If assistant has textual content, render it
591
+ const text = typeof msg.content === 'string'
592
+ ? msg.content
593
+ : (Array.isArray(msg.content)
594
+ ? msg.content.map(p => (typeof p === 'string' ? p : (p && p.text) || '')).filter(Boolean).join('\n')
595
+ : String(msg.content || ''));
596
+ if (text.trim()) {
597
+ this.renderAssistantMessage(text);
598
+ }
599
+
600
+ // If assistant invoked tool calls, render each tool step and pair with its result
601
+ if (Array.isArray(msg.tool_calls) && msg.tool_calls.length > 0) {
602
+ for (const call of msg.tool_calls) {
603
+ const toolName = call.function?.name || call.name || 'tool';
604
+ let args = {};
605
+ try {
606
+ args = typeof call.function?.arguments === 'string'
607
+ ? JSON.parse(call.function.arguments)
608
+ : (call.function?.arguments || {});
609
+ } catch {
610
+ args = {};
611
+ }
612
+
613
+ // Restore active implementation plan if update_plan was called
614
+ if (toolName === 'update_plan' && args && Array.isArray(args.plan)) {
615
+ this.onAgentPlan({ plan: args.plan });
616
+ }
617
+
618
+ this.onStepStart({ tool: toolName, args });
619
+
620
+ // Look up corresponding tool result
621
+ const toolMsg = call.id ? toolResultsById.get(call.id) : null;
622
+ if (toolMsg) {
623
+ renderedToolMessages.add(toolMsg);
624
+ let result = null;
625
+ if (typeof toolMsg.content === 'object' && toolMsg.content !== null) {
626
+ result = toolMsg.content;
627
+ } else if (typeof toolMsg.content === 'string') {
628
+ try {
629
+ result = JSON.parse(toolMsg.content);
630
+ } catch {
631
+ result = {
632
+ success: !toolMsg.content.toLowerCase().startsWith('error') && !toolMsg.content.toLowerCase().includes('failed'),
633
+ output: toolMsg.content
634
+ };
635
+ }
636
+ } else {
637
+ result = { success: true, output: '' };
638
+ }
639
+ if (result.success === undefined) result.success = true;
640
+ if (toolMsg.spillPath && !result.spillPath) result.spillPath = toolMsg.spillPath;
641
+ this.onStepComplete({ result, elapsed: '' });
642
+ }
643
+ }
644
+ }
645
+ } else if (role === 'tool') {
646
+ // Standalone or un-paired tool message (e.g. from compacted session turns)
647
+ if (!renderedToolMessages.has(msg)) {
648
+ renderedToolMessages.add(msg);
649
+ const toolName = msg.name || 'tool';
650
+ let result = null;
651
+ if (typeof msg.content === 'object' && msg.content !== null) {
652
+ result = msg.content;
653
+ } else if (typeof msg.content === 'string') {
654
+ try {
655
+ result = JSON.parse(msg.content);
656
+ } catch {
657
+ result = {
658
+ success: !msg.content.toLowerCase().startsWith('error') && !msg.content.toLowerCase().includes('failed'),
659
+ output: msg.content
660
+ };
661
+ }
662
+ } else {
663
+ result = { success: true, output: '' };
664
+ }
665
+ if (result.success === undefined) result.success = true;
666
+ if (msg.spillPath && !result.spillPath) result.spillPath = msg.spillPath;
667
+
668
+ this.onStepStart({ tool: toolName, args: {} });
669
+ this.onStepComplete({ result, elapsed: '' });
670
+ }
572
671
  } else if (role === 'system') {
573
672
  const text = typeof msg.content === 'string' ? msg.content : '';
574
673
  if (text.startsWith('[Continuum Context')) {
@@ -791,7 +890,9 @@ export class ChatRenderer {
791
890
  }
792
891
 
793
892
  onStepComplete(msg) {
794
- const elapsed = this.stepStartedAt ? formatDuration(Date.now() - this.stepStartedAt) : '';
893
+ const elapsed = typeof msg?.elapsed === 'string'
894
+ ? msg.elapsed
895
+ : (this.stepStartedAt ? formatDuration(Date.now() - this.stepStartedAt) : '');
795
896
  const result = msg.result || {};
796
897
 
797
898
  // Kept so Ctrl+O can show the whole thing, and set here rather than inside
@@ -801,7 +902,8 @@ export class ChatRenderer {
801
902
 
802
903
  this.frame('result', () => {
803
904
  if (result.success) {
804
- this.write(` ${paint('success', GLYPHS.check)} ${dim(elapsed)}`);
905
+ const elapsedText = elapsed ? ` ${dim(elapsed)}` : '';
906
+ this.write(` ${paint('success', GLYPHS.check)}${elapsedText}`);
805
907
  this.renderOutputPreview(result);
806
908
  return;
807
909
  }
@@ -124,6 +124,12 @@ export function handlePromptCtrlC(prompt, formatInterruptedRow, windowMs = 2000,
124
124
  prompt.notice = 'press Ctrl+C again to exit';
125
125
  }
126
126
  export function handlePromptEscape(prompt, formatInterruptedRow) {
127
+ if (prompt.surface?.hoveredTurnIndex !== null && prompt.surface?.hoveredTurnIndex !== undefined) {
128
+ prompt.surface.hoveredTurnIndex = null;
129
+ prompt.surface.hoveredTurnAnchorY = null;
130
+ prompt.scheduleDraw();
131
+ return;
132
+ }
127
133
  if (prompt.completion) {
128
134
  prompt.completion = null;
129
135
  if (prompt.editor.getText().startsWith('/')) {
@@ -177,6 +177,12 @@ export function handlePromptEscape(
177
177
  prompt: InterruptiblePrompt,
178
178
  formatInterruptedRow: () => string[]
179
179
  ): void {
180
+ if ((prompt as any).surface?.hoveredTurnIndex !== null && (prompt as any).surface?.hoveredTurnIndex !== undefined) {
181
+ (prompt as any).surface.hoveredTurnIndex = null;
182
+ (prompt as any).surface.hoveredTurnAnchorY = null;
183
+ prompt.scheduleDraw();
184
+ return;
185
+ }
180
186
  if (prompt.completion) {
181
187
  prompt.completion = null;
182
188
  if (prompt.editor.getText().startsWith('/')) {
@@ -51,6 +51,12 @@ export class MessageActionsLayer extends Layer {
51
51
  this.onPick(this.items[this.list.selected] ?? null);
52
52
  return 'close';
53
53
  }
54
+ const e = event;
55
+ if (!e.ctrl && !e.alt && (e.name.length === 1 || e.name === 'space' || e.name === 'backspace')) {
56
+ this.settled = true;
57
+ this.onPick(null);
58
+ return 'dismiss';
59
+ }
54
60
  return 'handled';
55
61
  }
56
62
  answer() {
@@ -88,7 +94,8 @@ export function messageAt(surface, point) {
88
94
  if (!surface?.stage.reserved || !Number.isFinite(point.x) || !Number.isFinite(point.y))
89
95
  return null;
90
96
  const mainWidth = sidebarVisible(surface.width) ? sessionMainWidth(surface.width) : surface.width;
91
- if (point.x < 0 || point.x >= Math.min(mainWidth, surface.viewport.width))
97
+ const leftGutter = (surface.turnRailLayout?.turns?.length ?? 0) > 0 ? 3 : 0;
98
+ if (point.x < leftGutter || point.x >= Math.min(mainWidth, surface.viewport.width))
92
99
  return null;
93
100
  const top = Math.max(0, (surface.out.rows || surface.stage.height) - surface.stage.height);
94
101
  const viewRow = point.y - top;
@@ -212,8 +219,9 @@ export function handleMessageActionMenuMouse(layer, event) {
212
219
  const { x, y, width, count } = layer.actionLayout;
213
220
  const { mouse } = event;
214
221
  const index = mouse.y - (y + 1); // only the frame precedes the two action rows
215
- if (mouse.x < x || mouse.x >= x + width || index < 0 || index >= count)
216
- return 'handled';
222
+ if (mouse.x < x || mouse.x >= x + width || index < 0 || index >= count) {
223
+ return mouse.button === 0 && mouse.pressed ? 'close' : 'handled';
224
+ }
217
225
  layer.list?.moveTo(index);
218
226
  if (isMouseMotion(event.sequence))
219
227
  return 'handled';
@@ -23,6 +23,7 @@ interface MessageSurface {
23
23
  viewport: { height: number; width: number; scrollTop: number; toBottom?: () => void };
24
24
  transcript: { flatten(width: number): { rows: string[]; markers: MessageMarker[] } };
25
25
  hoveredMessageFrameId?: number | null;
26
+ turnRailLayout?: { turns?: unknown[] } | null;
26
27
  }
27
28
 
28
29
  interface MessageHost {
@@ -92,6 +93,12 @@ export class MessageActionsLayer extends Layer {
92
93
  this.onPick(this.items[this.list.selected] ?? null);
93
94
  return 'close';
94
95
  }
96
+ const e = event as { name: string; ctrl?: boolean; alt?: boolean };
97
+ if (!e.ctrl && !e.alt && (e.name.length === 1 || e.name === 'space' || e.name === 'backspace')) {
98
+ this.settled = true;
99
+ this.onPick(null);
100
+ return 'dismiss';
101
+ }
95
102
  return 'handled';
96
103
  }
97
104
 
@@ -146,7 +153,8 @@ const isMessage = (marker: MessageMarker): boolean =>
146
153
  export function messageAt(surface: MessageSurface | null, point: MousePoint): MessageMarker | null {
147
154
  if (!surface?.stage.reserved || !Number.isFinite(point.x) || !Number.isFinite(point.y)) return null;
148
155
  const mainWidth = sidebarVisible(surface.width) ? sessionMainWidth(surface.width) : surface.width;
149
- if (point.x < 0 || point.x >= Math.min(mainWidth, surface.viewport.width)) return null;
156
+ const leftGutter = (surface.turnRailLayout?.turns?.length ?? 0) > 0 ? 3 : 0;
157
+ if (point.x < leftGutter || point.x >= Math.min(mainWidth, surface.viewport.width)) return null;
150
158
  const top = Math.max(0, (surface.out.rows || surface.stage.height) - surface.stage.height);
151
159
  const viewRow = point.y - top;
152
160
  if (viewRow < 0 || viewRow >= surface.viewport.height) return null;
@@ -268,7 +276,9 @@ export function handleMessageActionMenuMouse(
268
276
  const { x, y, width, count } = layer.actionLayout;
269
277
  const { mouse } = event;
270
278
  const index = mouse.y - (y + 1); // only the frame precedes the two action rows
271
- if (mouse.x < x || mouse.x >= x + width || index < 0 || index >= count) return 'handled';
279
+ if (mouse.x < x || mouse.x >= x + width || index < 0 || index >= count) {
280
+ return mouse.button === 0 && mouse.pressed ? 'close' : 'handled';
281
+ }
272
282
  layer.list?.moveTo(index);
273
283
  if (isMouseMotion(event.sequence)) return 'handled';
274
284
  return mouse.button === 0 && mouse.pressed ? layer.key({ name: 'enter' }) : 'handled';
package/src/tui/prompt.js CHANGED
@@ -685,9 +685,18 @@ export class ChatPrompt {
685
685
  handleKey(key) {
686
686
  // The wheel was handed to the terminal at the top of the band; the moment
687
687
  // the user types again they are driving this prompt, so take it back.
688
- if (key.name !== 'wheel' && key.name !== 'mouse'
689
- && this.surface && typeof this.surface.captureMouse === 'function') {
690
- if (this.surface.captureMouse() && this.notice.startsWith('top of this view')) this.notice = '';
688
+ if (key.name !== 'wheel' && key.name !== 'mouse') {
689
+ if (this.surface && typeof this.surface.captureMouse === 'function') {
690
+ if (this.surface.captureMouse() && this.notice.startsWith('top of this view')) this.notice = '';
691
+ }
692
+ if (this.surface) {
693
+ this.surface.turnRailHoverSuppressed = false;
694
+ if (this.surface.hoveredTurnIndex !== null && this.surface.hoveredTurnIndex !== undefined) {
695
+ this.surface.hoveredTurnIndex = null;
696
+ this.surface.hoveredTurnAnchorY = null;
697
+ this.scheduleDraw();
698
+ }
699
+ }
691
700
  }
692
701
 
693
702
  if (key.ctrl && key.name === 'c') {
@@ -918,10 +927,12 @@ export class ChatPrompt {
918
927
  if (!viewport) return false;
919
928
 
920
929
  if (key.name === 'pageup') {
930
+ if (this.surface) this.surface.activeTurnIndex = null;
921
931
  if (key.shift) viewport.toTop(); else viewport.pageUp();
922
932
  return true;
923
933
  }
924
934
  if (key.name === 'pagedown') {
935
+ if (this.surface) this.surface.activeTurnIndex = null;
925
936
  // Shift+PgDn is the way back to following, and it is spelled out in the
926
937
  // affordance the surface draws while the view is held away.
927
938
  if (key.shift) viewport.toBottom(); else viewport.pageDown();
@@ -929,16 +940,26 @@ export class ChatPrompt {
929
940
  }
930
941
  if (key.shift && key.name === 'up') {
931
942
  if (!this.editor.isEmpty) return false;
943
+ if (this.surface) this.surface.activeTurnIndex = null;
932
944
  viewport.lineUp();
933
945
  return true;
934
946
  }
935
947
  if (key.shift && key.name === 'down') {
936
948
  if (!this.editor.isEmpty) return false;
949
+ if (this.surface) this.surface.activeTurnIndex = null;
937
950
  viewport.lineDown();
938
951
  return true;
939
952
  }
940
- if (key.alt && key.ctrl && key.name === 'u') { viewport.halfPageUp(); return true; }
941
- if (key.alt && key.ctrl && key.name === 'd') { viewport.halfPageDown(); return true; }
953
+ if (key.alt && key.ctrl && key.name === 'u') {
954
+ if (this.surface) this.surface.activeTurnIndex = null;
955
+ viewport.halfPageUp();
956
+ return true;
957
+ }
958
+ if (key.alt && key.ctrl && key.name === 'd') {
959
+ if (this.surface) this.surface.activeTurnIndex = null;
960
+ viewport.halfPageDown();
961
+ return true;
962
+ }
942
963
 
943
964
  // Jump by structure, not by rows. The transcript knows where each frame
944
965
  // starts, so `,`/`.` step through tool calls and the shifted `<`/`>` on the
@@ -22,6 +22,10 @@ export function handleViewportWheel(key, viewport, surface, host) {
22
22
  host.notice = '';
23
23
  }
24
24
  }
25
+ // Clear manual turn override on wheel scroll so active indicator syncs with viewport
26
+ if (surface) {
27
+ surface.activeTurnIndex = null;
28
+ }
25
29
  // Pure isolated scrolling: clamp strictly inside [0, maxScrollTop]
26
30
  viewport.wheel(key.wheel.direction === 'down' ? 'down' : 'up');
27
31
  // Immediately draw updated viewport
@@ -37,6 +41,9 @@ export function handleScrollbarMouse(key, viewport, surface, host) {
37
41
  return false;
38
42
  if (key.mouse.button !== 0)
39
43
  return false; // Left click only
44
+ if (surface) {
45
+ surface.activeTurnIndex = null;
46
+ }
40
47
  // If completion picker is active, check if click was on the picker
41
48
  if (host.pickerLayout && Number.isFinite(key.mouse.y)) {
42
49
  const termRows = host.out?.rows || 24;
@@ -100,6 +100,11 @@ export function handleViewportWheel(
100
100
  }
101
101
  }
102
102
 
103
+ // Clear manual turn override on wheel scroll so active indicator syncs with viewport
104
+ if (surface) {
105
+ (surface as any).activeTurnIndex = null;
106
+ }
107
+
103
108
  // Pure isolated scrolling: clamp strictly inside [0, maxScrollTop]
104
109
  viewport.wheel(key.wheel.direction === 'down' ? 'down' : 'up');
105
110
 
@@ -121,6 +126,10 @@ export function handleScrollbarMouse(
121
126
  if (!viewport || !surface || !key.mouse || !key.mouse.pressed) return false;
122
127
  if (key.mouse.button !== 0) return false; // Left click only
123
128
 
129
+ if (surface) {
130
+ (surface as any).activeTurnIndex = null;
131
+ }
132
+
124
133
  // If completion picker is active, check if click was on the picker
125
134
  if (host.pickerLayout && Number.isFinite(key.mouse.y)) {
126
135
  const termRows = host.out?.rows || 24;
@@ -7,19 +7,12 @@ import { SelectLayer } from './dialogs.js';
7
7
  import { GLYPHS } from './theme.js';
8
8
  import { listSessions, getActiveSessionId, switchSession, createSession, forkSession } from '../sessionJournal.js';
9
9
  import { revokeAllAlways } from '../approvalGrants.js';
10
- /** The divider counts conversation turns that the history renderer can show. */
10
+ /** The divider counts conversation messages that the history renderer displays. */
11
11
  function visibleHistoryCount(messages) {
12
12
  return messages.filter((message) => {
13
- if (message.role !== 'user' && message.role !== 'assistant')
13
+ if (!message || message.role === 'system')
14
14
  return false;
15
- if (typeof message.content === 'string')
16
- return message.content.trim().length > 0;
17
- if (Array.isArray(message.content)) {
18
- return message.content.some((part) => typeof part === 'string' && part.trim().length > 0
19
- || !!part && typeof part === 'object' && 'text' in part
20
- && typeof part.text === 'string' && part.text.trim().length > 0);
21
- }
22
- return false;
15
+ return true;
23
16
  }).length;
24
17
  }
25
18
  function formatTimeAgo(timestamp) {
@@ -52,18 +52,11 @@ export interface InteractiveSessionPickerOptions {
52
52
  workspace?: string | undefined;
53
53
  }
54
54
 
55
- /** The divider counts conversation turns that the history renderer can show. */
55
+ /** The divider counts conversation messages that the history renderer displays. */
56
56
  function visibleHistoryCount(messages: Array<{ role: string; content?: unknown }>): number {
57
57
  return messages.filter((message) => {
58
- if (message.role !== 'user' && message.role !== 'assistant') return false;
59
- if (typeof message.content === 'string') return message.content.trim().length > 0;
60
- if (Array.isArray(message.content)) {
61
- return message.content.some((part: unknown) =>
62
- typeof part === 'string' && part.trim().length > 0
63
- || !!part && typeof part === 'object' && 'text' in part
64
- && typeof part.text === 'string' && part.text.trim().length > 0);
65
- }
66
- return false;
58
+ if (!message || message.role === 'system') return false;
59
+ return true;
67
60
  }).length;
68
61
  }
69
62
 
@@ -34,7 +34,7 @@ import { composerWidth } from './layout.js';
34
34
  import { placeHome, placeDialog } from './homeView.js';
35
35
  import { sidebarVisible, sessionMainWidth, sessionComposerWidth, sessionSidebarRows, joinSessionSidebar } from './sessionSidebar.js';
36
36
  import { sessionStageHeight, alignTranscriptRows } from './sessionLayout.js';
37
- import { collectSessionTurns, buildTurnRailCells, renderTurnPreviewCard, overlayTurnPreviewCard } from './turnRail.js';
37
+ import { collectSessionTurns, buildTurnRailCells, renderTurnPreviewCard, overlayTurnPreviewCard, resolveActiveTurnIndex } from './turnRail.js';
38
38
 
39
39
  // Rows of evicted transcript held for the exit log. Eviction only happens after
40
40
  // MAX_FRAMES, so this is a bound on a pathological session, not a working limit.
@@ -395,7 +395,9 @@ export class StageSurface {
395
395
  const sidebar = sidebarVisible(width);
396
396
  const mainWidth = sessionMainWidth(width);
397
397
  const rail = this.railEnabled(mainWidth);
398
- const contentWidth = rail ? Math.max(20, mainWidth - RAIL_BUDGET) : mainWidth;
398
+ const hasTurns = this.transcript && collectSessionTurns(this.transcript, mainWidth).length > 0;
399
+ const turnRailBudget = (rail && hasTurns) ? 3 : 0;
400
+ const contentWidth = rail ? Math.max(20, mainWidth - RAIL_BUDGET - turnRailBudget) : mainWidth;
399
401
 
400
402
  let block = promptRows;
401
403
  let caretRow = caret && Number.isFinite(caret.row) ? caret.row : Math.max(0, block.length - 1);
@@ -439,7 +441,7 @@ export class StageSurface {
439
441
  if (hoveredTurn) {
440
442
  const card = renderTurnPreviewCard(hoveredTurn, 52);
441
443
  const anchorY = this.hoveredTurnAnchorY ?? Math.floor(rows.length / 2);
442
- rows = overlayTurnPreviewCard(rows, card, anchorY, contentWidth + 1, mainWidth);
444
+ rows = overlayTurnPreviewCard(rows, card, anchorY, this.turnRailLayout?.railX ?? 1, mainWidth);
443
445
  }
444
446
  }
445
447
  if (this.messageActionOverlay) {
@@ -635,12 +637,15 @@ export class StageSurface {
635
637
  */
636
638
  attachRail(rows, contentWidth) {
637
639
  const turns = collectSessionTurns(this.transcript, contentWidth);
640
+ const isAtBottom = typeof this.viewport?.atBottom === 'function' ? this.viewport.atBottom() : false;
641
+ const activeTurn = this.activeTurnIndex || resolveActiveTurnIndex(turns, this.viewport.state().scrollTop, rows.length, isAtBottom);
638
642
  const railResult = turns.length > 0
639
- ? buildTurnRailCells(turns, rows.length, this.activeTurnIndex || turns.length, this.hoveredTurnIndex)
643
+ ? buildTurnRailCells(turns, rows.length, activeTurn, this.hoveredTurnIndex)
640
644
  : null;
641
645
 
646
+ const hasTurns = turns.length > 0;
642
647
  this.turnRailLayout = {
643
- railX: contentWidth + 1,
648
+ railX: hasTurns ? 1 : contentWidth + 1,
644
649
  stageTop: (this.out.rows || this.stage.height) - this.stage.height,
645
650
  viewportHeight: rows.length,
646
651
  dotRows: railResult?.layout?.dotRows || new Map(),
@@ -650,10 +655,13 @@ export class StageSurface {
650
655
 
651
656
  const rail = this.buildRail(rows.length, contentWidth);
652
657
  for (let i = 0; i < rows.length; i++) {
653
- const cell = railResult?.cells[i] && railResult.cells[i] !== ' '
654
- ? railResult.cells[i]
655
- : rail[i];
656
- rows[i] = `${padEnd(rows[i], contentWidth)} ${cell}`;
658
+ const rightCell = rail[i] || ' ';
659
+ if (hasTurns) {
660
+ const leftCell = railResult?.cells[i] || ' ';
661
+ rows[i] = ` ${leftCell} ${padEnd(rows[i], contentWidth)} ${rightCell}`;
662
+ } else {
663
+ rows[i] = `${padEnd(rows[i], contentWidth)} ${rightCell}`;
664
+ }
657
665
  }
658
666
  return rows;
659
667
  }
@@ -702,7 +710,11 @@ export function createStageSurface({ out = process.stdout, env = process.env, co
702
710
  if (env.CAUSYNE_SIMPLE_INPUT === '1') return null;
703
711
  if (stageHeight(out, env) < 1) return null;
704
712
 
705
- const surface = new StageSurface({ out, env, config, speed, openingWidth });
713
+ const effectiveEnv = env.CAUSYNE_MOUSE_HOVER === undefined
714
+ ? { ...env, CAUSYNE_MOUSE_HOVER: '1' }
715
+ : env;
716
+
717
+ const surface = new StageSurface({ out, env: effectiveEnv, config, speed, openingWidth });
706
718
  if (!surface.open()) return null;
707
719
  return surface;
708
720
  }