@causyne/agent 1.20.41 → 1.20.43

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@causyne/agent",
3
- "version": "1.20.41",
3
+ "version": "1.20.43",
4
4
  "description": "Agentic AI for software, tools, and computer workflows",
5
5
  "main": "bin/causyne.js",
6
6
  "type": "module",
@@ -15,7 +15,8 @@ export class ChatRenderer {
15
15
  handle(message: { type: string; [key: string]: unknown }): boolean;
16
16
  resetTurn(): void;
17
17
  onAgentReasoning(message: { content?: string; streaming?: boolean; elapsedMs?: number }): void;
18
- renderReasoning(content: string, options?: { streaming?: boolean; durationText?: string; collapsed?: boolean }): void;
18
+ renderReasoning(content: string, options?: { streaming?: boolean; durationText?: string; collapsed?: boolean; startLine?: number }): void;
19
+ scrollThinkingPanel?(key: unknown, surface: unknown): boolean;
19
20
  stopSpinner(): void;
20
21
  frame(kind: string, produce: () => void, meta?: Record<string, unknown> | null): void;
21
22
  updateTailFrame(kind: string, produce: () => void, meta?: Record<string, unknown> | null): void;
@@ -753,12 +753,14 @@ export class ChatRenderer {
753
753
  collapsed: false,
754
754
  streaming: true,
755
755
  durationText,
756
- content
756
+ content,
757
+ scrollStart: 0
757
758
  };
758
759
  this.frame('reasoning', () => this.renderReasoning(meta.content, {
759
760
  streaming: true,
760
761
  durationText: meta.durationText,
761
- collapsed: Boolean(meta.collapsed)
762
+ collapsed: Boolean(meta.collapsed),
763
+ startLine: Number(meta.scrollStart) || 0
762
764
  }), meta);
763
765
  } else {
764
766
  const meta = tailFrame?.meta || { reasoning: true };
@@ -766,10 +768,12 @@ export class ChatRenderer {
766
768
  meta.durationText = durationText;
767
769
  meta.content = content;
768
770
  if (meta.collapsed === undefined) meta.collapsed = false;
771
+ if (meta.scrollStart === undefined) meta.scrollStart = 0;
769
772
  this.updateTailFrame('reasoning', () => this.renderReasoning(meta.content, {
770
773
  streaming: true,
771
774
  durationText: meta.durationText,
772
- collapsed: Boolean(meta.collapsed)
775
+ collapsed: Boolean(meta.collapsed),
776
+ startLine: Number(meta.scrollStart) || 0
773
777
  }), meta);
774
778
  }
775
779
  return;
@@ -783,10 +787,12 @@ export class ChatRenderer {
783
787
  meta.durationText = durationText;
784
788
  meta.content = content;
785
789
  if (meta.collapsed === undefined) meta.collapsed = false;
790
+ if (meta.scrollStart === undefined) meta.scrollStart = 0;
786
791
  this.updateTailFrame('reasoning', () => this.renderReasoning(meta.content, {
787
792
  streaming: false,
788
793
  durationText: meta.durationText,
789
- collapsed: Boolean(meta.collapsed)
794
+ collapsed: Boolean(meta.collapsed),
795
+ startLine: Number(meta.scrollStart) || 0
790
796
  }), meta);
791
797
  } else if (content.trim()) {
792
798
  const meta = {
@@ -795,23 +801,26 @@ export class ChatRenderer {
795
801
  streaming: false,
796
802
  durationText,
797
803
  content,
798
- collapsed: false
804
+ collapsed: false,
805
+ scrollStart: 0
799
806
  };
800
807
  this.frame('reasoning', () => this.renderReasoning(meta.content, {
801
808
  streaming: false,
802
809
  durationText: meta.durationText,
803
- collapsed: Boolean(meta.collapsed)
810
+ collapsed: Boolean(meta.collapsed),
811
+ startLine: Number(meta.scrollStart) || 0
804
812
  }), meta);
805
813
  }
806
814
  }
807
815
 
808
- renderReasoning(content, { streaming = false, durationText = '', collapsed = false } = {}) {
816
+ renderReasoning(content, { streaming = false, durationText = '', collapsed = false, startLine = 0 } = {}) {
809
817
  const width = this.measure();
810
818
  const rows = renderThinkingFrame(content, {
811
819
  width,
812
820
  streaming,
813
821
  durationText,
814
- collapsed
822
+ collapsed,
823
+ startLine: Number(startLine) || 0
815
824
  });
816
825
 
817
826
  if (rows.length === 0) return;
@@ -823,6 +832,10 @@ export class ChatRenderer {
823
832
  this.write();
824
833
  }
825
834
 
835
+ scrollThinkingPanel(key, surface) {
836
+ return false;
837
+ }
838
+
826
839
  onAgentActivity(msg) {
827
840
  const text = String(msg.activity || msg.message || '').trim();
828
841
  if (!text) return;
@@ -1,5 +1,7 @@
1
1
  import { ChatRenderer } from './chatRenderer.js';
2
2
  import { CODE_PANEL_LINES, codePreviewLineCount, defaultPreviewStart, renderCodeProgress } from './codeProgress.js';
3
+ import { calculateThinkingLineCount, DEFAULT_MAX_EXPANDED_LINES } from './thinkingBox.js';
4
+ import { markerAt } from './messageInteraction.js';
3
5
  function lastStart(event) {
4
6
  return Math.max(0, codePreviewLineCount(event) - CODE_PANEL_LINES);
5
7
  }
@@ -11,34 +13,27 @@ export class CodeStreamRenderer extends ChatRenderer {
11
13
  codePanels = new WeakMap();
12
14
  /** Scroll only the code beneath the pointer; leave the chat viewport alone. */
13
15
  scrollCodePanel(key, surface) {
14
- const wheel = key.wheel;
15
- if (key.name !== 'wheel' || !wheel || !surface || !['up', 'down'].includes(wheel.direction))
16
+ const wheel = key?.wheel;
17
+ if (key?.name !== 'wheel' || !wheel || !surface || !['up', 'down'].includes(wheel.direction))
16
18
  return false;
17
- const transcript = this.transcript;
18
- if (!transcript || !Number.isFinite(surface.out.rows) || !Number.isFinite(wheel.x) || !Number.isFinite(wheel.y))
19
- return false;
20
- const viewport = surface.viewport;
21
- const screenTop = surface.out.rows - surface.stage.height;
22
- const localY = wheel.y - screenTop;
23
- if (localY < 0 || localY >= viewport.viewHeight || wheel.x < 0 || wheel.x >= Math.min(viewport.viewWidth, this.measure()))
19
+ const transcript = (this.transcript || surface.transcript);
20
+ if (!transcript)
24
21
  return false;
25
- const { markers } = transcript.flatten(viewport.viewWidth);
26
- const absoluteY = viewport.scrollTop + localY;
27
- const markerIndex = markers.findIndex((marker, index) => marker.row <= absoluteY
28
- && (index + 1 === markers.length || absoluteY < markers[index + 1].row));
29
- if (markerIndex < 0)
22
+ if (!surface.transcript)
23
+ surface.transcript = transcript;
24
+ const marker = markerAt(surface, { x: wheel.x, y: wheel.y });
25
+ if (!marker)
30
26
  return false;
31
- const marker = markers[markerIndex];
32
27
  const frame = transcript.frames.find(item => item.id === marker.id);
33
28
  const state = frame && this.codePanels.get(frame);
34
- if (!frame || !state || absoluteY >= marker.row + (frame.rows?.length || 0))
29
+ if (!frame || !state)
35
30
  return false;
36
31
  const limit = lastStart(state.event);
37
32
  if (limit === 0)
38
33
  return false;
39
34
  const next = Math.max(0, Math.min(limit, state.start + (wheel.direction === 'up' ? -3 : 3)));
40
35
  if (next === state.start)
41
- return false;
36
+ return true;
42
37
  state.start = next;
43
38
  state.followTail = next === limit;
44
39
  frame.rows = null;
@@ -48,6 +43,39 @@ export class CodeStreamRenderer extends ChatRenderer {
48
43
  transcript.changed();
49
44
  return true;
50
45
  }
46
+ /** Scroll only the thinking panel beneath the pointer; leave the chat viewport alone. */
47
+ scrollThinkingPanel(key, surface) {
48
+ const wheel = key?.wheel;
49
+ if (key?.name !== 'wheel' || !wheel || !surface || !['up', 'down'].includes(wheel.direction))
50
+ return false;
51
+ const transcript = (this.transcript || surface.transcript);
52
+ if (!transcript)
53
+ return false;
54
+ if (!surface.transcript)
55
+ surface.transcript = transcript;
56
+ const marker = markerAt(surface, { x: wheel.x, y: wheel.y });
57
+ if (!marker || marker.kind !== 'reasoning')
58
+ return false;
59
+ const frame = transcript.frames.find(item => item.id === marker.id);
60
+ if (!frame || frame.meta?.reasoning !== true || frame.meta?.collapsed)
61
+ return false;
62
+ const content = typeof frame.meta.content === 'string' ? frame.meta.content : '';
63
+ const totalLines = calculateThinkingLineCount(content, this.measure());
64
+ const limit = Math.max(0, totalLines - DEFAULT_MAX_EXPANDED_LINES);
65
+ if (limit === 0)
66
+ return false;
67
+ const currentStart = Number(frame.meta.scrollStart) || 0;
68
+ const next = Math.max(0, Math.min(limit, currentStart + (wheel.direction === 'up' ? -3 : 3)));
69
+ if (next === currentStart)
70
+ return true;
71
+ frame.meta.scrollStart = next;
72
+ frame.rows = null;
73
+ frame.renderedWidth = -1;
74
+ transcript.cache = null;
75
+ transcript.revision++;
76
+ transcript.changed();
77
+ return true;
78
+ }
51
79
  resetTurn() {
52
80
  this._activeReasoning = false;
53
81
  this.activeCode = null;
@@ -1,5 +1,7 @@
1
1
  import { ChatRenderer } from './chatRenderer.js';
2
2
  import { CODE_PANEL_LINES, codePreviewLineCount, defaultPreviewStart, renderCodeProgress, type CodeProgressEvent } from './codeProgress.js';
3
+ import { calculateThinkingLineCount, DEFAULT_MAX_EXPANDED_LINES } from './thinkingBox.js';
4
+ import { markerAt } from './messageInteraction.js';
3
5
 
4
6
  type RendererEvent = { type: string; [key: string]: unknown };
5
7
  type CodePanelState = { event: CodeProgressEvent; modelNote: string; start: number; followTail: boolean };
@@ -31,27 +33,25 @@ export class CodeStreamRenderer extends ChatRenderer {
31
33
 
32
34
  /** Scroll only the code beneath the pointer; leave the chat viewport alone. */
33
35
  scrollCodePanel(key: CodeWheel, surface: CodeSurface | null): boolean {
34
- const wheel = key.wheel;
35
- if (key.name !== 'wheel' || !wheel || !surface || !['up', 'down'].includes(wheel.direction)) return false;
36
- const transcript = this.transcript as unknown as CodeTranscript | null;
37
- if (!transcript || !Number.isFinite(surface.out.rows) || !Number.isFinite(wheel.x) || !Number.isFinite(wheel.y)) return false;
38
- const viewport = surface.viewport;
39
- const screenTop = (surface.out.rows as number) - surface.stage.height;
40
- const localY = wheel.y - screenTop;
41
- if (localY < 0 || localY >= viewport.viewHeight || wheel.x < 0 || wheel.x >= Math.min(viewport.viewWidth, this.measure())) return false;
42
- const { markers } = transcript.flatten(viewport.viewWidth);
43
- const absoluteY = viewport.scrollTop + localY;
44
- const markerIndex = markers.findIndex((marker, index) => marker.row <= absoluteY
45
- && (index + 1 === markers.length || absoluteY < markers[index + 1]!.row));
46
- if (markerIndex < 0) return false;
47
- const marker = markers[markerIndex]!;
36
+ const wheel = key?.wheel;
37
+ if (key?.name !== 'wheel' || !wheel || !surface || !['up', 'down'].includes(wheel.direction)) return false;
38
+ const transcript = (this.transcript || (surface as any).transcript) as unknown as CodeTranscript | null;
39
+ if (!transcript) return false;
40
+ if (!(surface as any).transcript) (surface as any).transcript = transcript;
41
+
42
+ const marker = markerAt(surface as any, { x: wheel.x, y: wheel.y });
43
+ if (!marker) return false;
44
+
48
45
  const frame = transcript.frames.find(item => item.id === marker.id);
49
46
  const state = frame && this.codePanels.get(frame);
50
- if (!frame || !state || absoluteY >= marker.row + (frame.rows?.length || 0)) return false;
47
+ if (!frame || !state) return false;
48
+
51
49
  const limit = lastStart(state.event);
52
50
  if (limit === 0) return false;
51
+
53
52
  const next = Math.max(0, Math.min(limit, state.start + (wheel.direction === 'up' ? -3 : 3)));
54
- if (next === state.start) return false;
53
+ if (next === state.start) return true;
54
+
55
55
  state.start = next;
56
56
  state.followTail = next === limit;
57
57
  frame.rows = null;
@@ -62,6 +62,38 @@ export class CodeStreamRenderer extends ChatRenderer {
62
62
  return true;
63
63
  }
64
64
 
65
+ /** Scroll only the thinking panel beneath the pointer; leave the chat viewport alone. */
66
+ override scrollThinkingPanel(key: CodeWheel, surface: CodeSurface | null): boolean {
67
+ const wheel = key?.wheel;
68
+ if (key?.name !== 'wheel' || !wheel || !surface || !['up', 'down'].includes(wheel.direction)) return false;
69
+ const transcript = (this.transcript || (surface as any).transcript) as unknown as CodeTranscript | null;
70
+ if (!transcript) return false;
71
+ if (!(surface as any).transcript) (surface as any).transcript = transcript;
72
+
73
+ const marker = markerAt(surface as any, { x: wheel.x, y: wheel.y });
74
+ if (!marker || marker.kind !== 'reasoning') return false;
75
+
76
+ const frame = transcript.frames.find(item => item.id === marker.id);
77
+ if (!frame || frame.meta?.reasoning !== true || frame.meta?.collapsed) return false;
78
+
79
+ const content = typeof frame.meta.content === 'string' ? frame.meta.content : '';
80
+ const totalLines = calculateThinkingLineCount(content, this.measure());
81
+ const limit = Math.max(0, totalLines - DEFAULT_MAX_EXPANDED_LINES);
82
+ if (limit === 0) return false;
83
+
84
+ const currentStart = Number(frame.meta.scrollStart) || 0;
85
+ const next = Math.max(0, Math.min(limit, currentStart + (wheel.direction === 'up' ? -3 : 3)));
86
+ if (next === currentStart) return true;
87
+
88
+ frame.meta.scrollStart = next;
89
+ frame.rows = null;
90
+ frame.renderedWidth = -1;
91
+ transcript.cache = null;
92
+ transcript.revision++;
93
+ transcript.changed();
94
+ return true;
95
+ }
96
+
65
97
  override resetTurn(): void {
66
98
  this._activeReasoning = false;
67
99
  this.activeCode = null;
package/src/tui/keys.js CHANGED
@@ -113,6 +113,24 @@ export class KeyDecoder {
113
113
 
114
114
  if (byte === 0x1b) return this.stepEscape(buffer, offset, events);
115
115
 
116
+ // Orphaned SGR mouse sequence: [ < b ; x ; y M|m
117
+ // Occurs when \x1b is consumed on a chunk boundary or dropped over PTY.
118
+ // Intercepting here prevents raw sequence strings like `[<64;119;43M` from
119
+ // leaking into the prompt input box as literal character keystrokes.
120
+ if (byte === 0x5b && buffer.length - offset >= 3 && buffer[offset + 1] === 0x3c) {
121
+ const text = buffer.toString('utf8', offset);
122
+ if (!/[Mm]/.test(text)) return 0; // Incomplete sequence; wait for subsequent bytes in this.pending
123
+ const match = /^\[<(\d+);(\d+);(\d+)([Mm])/.exec(text);
124
+ if (match) {
125
+ const code = parseInt(match[1], 10);
126
+ const col = parseInt(match[2], 10);
127
+ const row = parseInt(match[3], 10);
128
+ const pressed = match[4] === 'M';
129
+ this.emitMouse([code, col, row], pressed, match[0], events);
130
+ return match[0].length;
131
+ }
132
+ }
133
+
116
134
  if (byte === 0x0d || byte === 0x0a) {
117
135
  events.push(makeKey('enter', { sequence: String.fromCharCode(byte) }));
118
136
  return 1;
@@ -150,19 +150,26 @@ const isMessage = (marker) => (marker.kind === 'user' || marker.kind === 'assist
150
150
  && typeof marker.meta?.messageText === 'string';
151
151
  /** Resolve screen coordinates against the painted viewport to find any frame marker. */
152
152
  export function markerAt(surface, point) {
153
- if (!surface?.stage.reserved || !Number.isFinite(point.x) || !Number.isFinite(point.y))
153
+ if (!surface || surface.stage?.reserved === false || !Number.isFinite(point.x) || !Number.isFinite(point.y))
154
154
  return null;
155
- const mainWidth = sidebarVisible(surface.width) ? sessionMainWidth(surface.width) : surface.width;
155
+ const surfWidth = surface.width || surface.viewport?.viewWidth || surface.viewport?.width || 80;
156
+ const mainWidth = sidebarVisible(surfWidth) ? sessionMainWidth(surfWidth) : surfWidth;
156
157
  const leftGutter = (surface.turnRailLayout?.turns?.length ?? 0) > 0 ? 3 : 0;
157
- if (point.x < leftGutter || point.x >= Math.min(mainWidth, surface.viewport.width))
158
+ const viewWidth = surface.viewport?.viewWidth || surface.viewport?.width || surfWidth;
159
+ if (point.x < leftGutter || point.x >= Math.min(mainWidth, viewWidth + leftGutter))
158
160
  return null;
159
- const top = Math.max(0, (surface.out.rows || surface.stage.height) - surface.stage.height);
161
+ const stageHeight = surface.stage?.height ?? 24;
162
+ const top = Math.max(0, (surface.out?.rows || stageHeight) - stageHeight);
160
163
  const viewRow = point.y - top;
161
- if (viewRow < 0 || viewRow >= surface.viewport.height)
164
+ const viewHeight = surface.viewport?.viewHeight || surface.viewport?.height || stageHeight;
165
+ if (viewRow < 0 || viewRow >= viewHeight)
162
166
  return null;
163
- const flat = surface.transcript.flatten(surface.viewport.width);
164
- const visible = Math.max(0, Math.min(surface.viewport.height, flat.rows.length - surface.viewport.scrollTop));
165
- const padding = surface.viewport.height - visible;
167
+ const transcript = surface.transcript || surface.renderer?.transcript;
168
+ if (!transcript)
169
+ return null;
170
+ const flat = transcript.flatten(viewWidth);
171
+ const visible = Math.max(0, Math.min(viewHeight, flat.rows.length - surface.viewport.scrollTop));
172
+ const padding = viewHeight - visible;
166
173
  if (viewRow < padding)
167
174
  return null;
168
175
  const row = surface.viewport.scrollTop + viewRow - padding;
@@ -239,16 +239,22 @@ const isMessage = (marker: MessageMarker): boolean =>
239
239
 
240
240
  /** Resolve screen coordinates against the painted viewport to find any frame marker. */
241
241
  export function markerAt(surface: MessageSurface | null, point: MousePoint): MessageMarker | null {
242
- if (!surface?.stage.reserved || !Number.isFinite(point.x) || !Number.isFinite(point.y)) return null;
243
- const mainWidth = sidebarVisible(surface.width) ? sessionMainWidth(surface.width) : surface.width;
242
+ if (!surface || surface.stage?.reserved === false || !Number.isFinite(point.x) || !Number.isFinite(point.y)) return null;
243
+ const surfWidth = surface.width || (surface.viewport as any)?.viewWidth || surface.viewport?.width || 80;
244
+ const mainWidth = sidebarVisible(surfWidth) ? sessionMainWidth(surfWidth) : surfWidth;
244
245
  const leftGutter = (surface.turnRailLayout?.turns?.length ?? 0) > 0 ? 3 : 0;
245
- if (point.x < leftGutter || point.x >= Math.min(mainWidth, surface.viewport.width)) return null;
246
- const top = Math.max(0, (surface.out.rows || surface.stage.height) - surface.stage.height);
246
+ const viewWidth = (surface.viewport as any)?.viewWidth || surface.viewport?.width || surfWidth;
247
+ if (point.x < leftGutter || point.x >= Math.min(mainWidth, viewWidth + leftGutter)) return null;
248
+ const stageHeight = surface.stage?.height ?? 24;
249
+ const top = Math.max(0, ((surface.out?.rows as number) || stageHeight) - stageHeight);
247
250
  const viewRow = point.y - top;
248
- if (viewRow < 0 || viewRow >= surface.viewport.height) return null;
249
- const flat = surface.transcript.flatten(surface.viewport.width);
250
- const visible = Math.max(0, Math.min(surface.viewport.height, flat.rows.length - surface.viewport.scrollTop));
251
- const padding = surface.viewport.height - visible;
251
+ const viewHeight = (surface.viewport as any)?.viewHeight || surface.viewport?.height || stageHeight;
252
+ if (viewRow < 0 || viewRow >= viewHeight) return null;
253
+ const transcript = surface.transcript || (surface as any).renderer?.transcript;
254
+ if (!transcript) return null;
255
+ const flat = transcript.flatten(viewWidth);
256
+ const visible = Math.max(0, Math.min(viewHeight, flat.rows.length - surface.viewport.scrollTop));
257
+ const padding = viewHeight - visible;
252
258
  if (viewRow < padding) return null;
253
259
  const row = surface.viewport.scrollTop + viewRow - padding;
254
260
  for (let i = flat.markers.length - 1; i >= 0; i--) {
package/src/tui/prompt.js CHANGED
@@ -919,7 +919,14 @@ export class ChatPrompt {
919
919
  }
920
920
  if (key.name === 'wheel') {
921
921
  if (!viewport || !key.wheel) return true;
922
- if (this.renderer?.scrollCodePanel?.(key, this.surface)) return true;
922
+ if (this.renderer?.scrollCodePanel?.(key, this.surface)) {
923
+ this.draw();
924
+ return true;
925
+ }
926
+ if (this.renderer?.scrollThinkingPanel?.(key, this.surface)) {
927
+ this.draw();
928
+ return true;
929
+ }
923
930
 
924
931
  return handleViewportWheel(key, viewport, this.surface, this);
925
932
  }
@@ -10,6 +10,17 @@ import { paint, bold, dim, GLYPHS, HAS_UNICODE } from './theme.js';
10
10
  import { padEnd, truncate, visibleWidth, wrapBlock } from './text.js';
11
11
  export const DEFAULT_MAX_STREAMING_LINES = 8;
12
12
  export const DEFAULT_MAX_EXPANDED_LINES = 12;
13
+ /**
14
+ * Calculates total wrapped lines for reasoning content under the thinking box budget.
15
+ */
16
+ export function calculateThinkingLineCount(content, width) {
17
+ const text = String(content ?? '').trim();
18
+ if (!text)
19
+ return 0;
20
+ const safeWidth = Math.max(20, Math.floor(width));
21
+ const contentBudget = Math.max(10, safeWidth - 4);
22
+ return wrapBlock(text, contentBudget).length;
23
+ }
13
24
  /**
14
25
  * Single-line compact badge for collapsed reasoning frames.
15
26
  */
@@ -123,13 +134,25 @@ export function renderThinkingFrame(content, options = {}) {
123
134
  const { top, bottom, wrapRow } = buildThinkingBoxBorders(title, collapseHint, width, 'rule');
124
135
  const rows = [top];
125
136
  if (totalLines > maxLines) {
126
- const hiddenCount = totalLines - maxLines;
127
- const displayRows = allRows.slice(0, maxLines);
128
- for (const row of displayRows) {
137
+ const limit = Math.max(0, totalLines - maxLines);
138
+ const start = Math.max(0, Math.min(limit, Math.floor(options.startLine ?? 0)));
139
+ const visible = allRows.slice(start, start + maxLines);
140
+ for (const row of visible) {
129
141
  rows.push(wrapRow(dim(row)));
130
142
  }
131
- const moreNotice = `${GLYPHS.ellipsis || '…'} ${hiddenCount} more line${hiddenCount === 1 ? '' : 's'} of reasoning`;
132
- rows.push(wrapRow(dim(moreNotice)));
143
+ const hiddenBelow = totalLines - (start + visible.length);
144
+ if (hiddenBelow > 0) {
145
+ const moreNotice = `${GLYPHS.ellipsis || '…'} ${hiddenBelow} more line${hiddenBelow === 1 ? '' : 's'} of reasoning`;
146
+ rows.push(wrapRow(dim(moreNotice)));
147
+ }
148
+ else if (start > 0) {
149
+ const earlierNotice = `${HAS_UNICODE ? '↑' : '^'} ${start} earlier line${start === 1 ? '' : 's'} scrolled above`;
150
+ rows.push(wrapRow(dim(earlierNotice)));
151
+ }
152
+ const upArrow = start > 0 ? (HAS_UNICODE ? '↑ ' : '^ ') : '';
153
+ const downArrow = start + visible.length < totalLines ? (HAS_UNICODE ? ' ↓' : ' v') : '';
154
+ const scrollInfo = `${upArrow}lines ${start + 1}–${start + visible.length} of ${totalLines}${downArrow} · scroll over thinking`;
155
+ rows.push(wrapRow(dim(scrollInfo)));
133
156
  }
134
157
  else {
135
158
  for (const row of allRows) {
@@ -17,11 +17,23 @@ export interface ThinkingFrameOptions {
17
17
  collapsed?: boolean;
18
18
  maxVisibleLines?: number;
19
19
  role?: string;
20
+ startLine?: number;
20
21
  }
21
22
 
22
23
  export const DEFAULT_MAX_STREAMING_LINES = 8;
23
24
  export const DEFAULT_MAX_EXPANDED_LINES = 12;
24
25
 
26
+ /**
27
+ * Calculates total wrapped lines for reasoning content under the thinking box budget.
28
+ */
29
+ export function calculateThinkingLineCount(content: string, width: number): number {
30
+ const text = String(content ?? '').trim();
31
+ if (!text) return 0;
32
+ const safeWidth = Math.max(20, Math.floor(width));
33
+ const contentBudget = Math.max(10, safeWidth - 4);
34
+ return wrapBlock(text, contentBudget).length;
35
+ }
36
+
25
37
  /**
26
38
  * Single-line compact badge for collapsed reasoning frames.
27
39
  */
@@ -172,13 +184,27 @@ export function renderThinkingFrame(
172
184
  const rows: string[] = [top];
173
185
 
174
186
  if (totalLines > maxLines) {
175
- const hiddenCount = totalLines - maxLines;
176
- const displayRows = allRows.slice(0, maxLines);
177
- for (const row of displayRows) {
187
+ const limit = Math.max(0, totalLines - maxLines);
188
+ const start = Math.max(0, Math.min(limit, Math.floor(options.startLine ?? 0)));
189
+ const visible = allRows.slice(start, start + maxLines);
190
+
191
+ for (const row of visible) {
178
192
  rows.push(wrapRow(dim(row)));
179
193
  }
180
- const moreNotice = `${GLYPHS.ellipsis || '…'} ${hiddenCount} more line${hiddenCount === 1 ? '' : 's'} of reasoning`;
181
- rows.push(wrapRow(dim(moreNotice)));
194
+
195
+ const hiddenBelow = totalLines - (start + visible.length);
196
+ if (hiddenBelow > 0) {
197
+ const moreNotice = `${GLYPHS.ellipsis || '…'} ${hiddenBelow} more line${hiddenBelow === 1 ? '' : 's'} of reasoning`;
198
+ rows.push(wrapRow(dim(moreNotice)));
199
+ } else if (start > 0) {
200
+ const earlierNotice = `${HAS_UNICODE ? '↑' : '^'} ${start} earlier line${start === 1 ? '' : 's'} scrolled above`;
201
+ rows.push(wrapRow(dim(earlierNotice)));
202
+ }
203
+
204
+ const upArrow = start > 0 ? (HAS_UNICODE ? '↑ ' : '^ ') : '';
205
+ const downArrow = start + visible.length < totalLines ? (HAS_UNICODE ? ' ↓' : ' v') : '';
206
+ const scrollInfo = `${upArrow}lines ${start + 1}–${start + visible.length} of ${totalLines}${downArrow} · scroll over thinking`;
207
+ rows.push(wrapRow(dim(scrollInfo)));
182
208
  } else {
183
209
  for (const row of allRows) {
184
210
  rows.push(wrapRow(dim(row)));