@causyne/agent 1.20.50 → 1.20.54

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.
@@ -21,6 +21,58 @@ export function calculateThinkingLineCount(content, width) {
21
21
  const contentBudget = Math.max(10, safeWidth - 4);
22
22
  return wrapBlock(text, contentBudget).length;
23
23
  }
24
+ /**
25
+ * Resolves dynamic contextual activity labels for streaming and completed badges.
26
+ */
27
+ export function resolveActivityLabels(options) {
28
+ const raw = (options.activity || options.title || 'thinking')
29
+ .replace(/…|\.\.\.$/, '')
30
+ .trim()
31
+ .toLowerCase();
32
+ let active = options.title ? options.title.trim() : `${raw}…`;
33
+ if (!options.title) {
34
+ if (raw === 'thinking')
35
+ active = 'thinking…';
36
+ else if (raw === 'analyzing')
37
+ active = 'analyzing…';
38
+ else if (raw === 'executing')
39
+ active = 'executing…';
40
+ else if (raw === 'editing')
41
+ active = 'editing…';
42
+ else if (raw === 'planning')
43
+ active = 'planning…';
44
+ else if (raw === 'researching')
45
+ active = 'researching…';
46
+ else if (raw === 'synthesizing')
47
+ active = 'synthesizing…';
48
+ else if (raw === 'processing')
49
+ active = 'processing…';
50
+ else
51
+ active = `${raw}…`;
52
+ }
53
+ let completed = options.completedTitle ? options.completedTitle.trim() : '';
54
+ if (!completed) {
55
+ if (raw === 'thinking')
56
+ completed = 'Thought';
57
+ else if (raw === 'analyzing')
58
+ completed = 'Analyzed';
59
+ else if (raw === 'executing')
60
+ completed = 'Executed';
61
+ else if (raw === 'editing')
62
+ completed = 'Edited';
63
+ else if (raw === 'planning')
64
+ completed = 'Planned';
65
+ else if (raw === 'researching')
66
+ completed = 'Researched';
67
+ else if (raw === 'synthesizing')
68
+ completed = 'Synthesized';
69
+ else if (raw === 'processing')
70
+ completed = 'Processed';
71
+ else
72
+ completed = raw.charAt(0).toUpperCase() + raw.slice(1);
73
+ }
74
+ return { activeLabel: active, completedLabel: completed };
75
+ }
24
76
  /**
25
77
  * Single-line compact badge for collapsed reasoning frames.
26
78
  */
@@ -28,13 +80,14 @@ export function renderCollapsedThinkingBadge(options, totalLines) {
28
80
  const isStreaming = Boolean(options.streaming);
29
81
  const durationText = options.durationText ? String(options.durationText).trim() : '';
30
82
  const arrow = HAS_UNICODE ? '▸' : '>';
83
+ const { activeLabel, completedLabel } = resolveActivityLabels(options);
31
84
  if (isStreaming) {
32
85
  const timePart = durationText ? ` · ${durationText}` : '';
33
- return ` ${paint('warn', arrow)} ${bold(paint('warn', 'thinking…'))}${dim(timePart)} ${dim('· click to expand')}`;
86
+ return ` ${paint('warn', arrow)} ${bold(paint('warn', activeLabel))}${dim(timePart)} ${dim('· click to expand')}`;
34
87
  }
35
88
  const timePart = durationText ? ` for ${durationText}` : '';
36
89
  const lineWord = totalLines === 1 ? 'line' : 'lines';
37
- return ` ${paint('muted', arrow)} ${dim(`Thought${timePart}`)} ${dim(`(${totalLines} ${lineWord})`)} ${dim('· click to expand')}`;
90
+ return ` ${paint('muted', arrow)} ${dim(`${completedLabel}${timePart}`)} ${dim(`(${totalLines} ${lineWord})`)} ${dim('· click to expand')}`;
38
91
  }
39
92
  /**
40
93
  * Builds the top, bottom, and side frame borders for the thinking box.
@@ -105,14 +158,16 @@ export function renderThinkingFrame(content, options = {}) {
105
158
  if (isStreaming) {
106
159
  const maxLines = options.maxVisibleLines ?? DEFAULT_MAX_STREAMING_LINES;
107
160
  const timePart = durationText ? ` · ${durationText}` : '';
108
- const title = `${bold(paint('warn', 'thinking…'))}${dim(timePart)}`;
161
+ const { activeLabel } = resolveActivityLabels(options);
162
+ const title = `${bold(paint('warn', activeLabel))}${dim(timePart)}`;
109
163
  const footer = collapseHint;
110
164
  const { top, bottom, wrapRow } = buildThinkingBoxBorders(title, footer, width, role);
111
165
  const rows = [top];
112
166
  if (totalLines > maxLines) {
113
167
  const hiddenCount = totalLines - (maxLines - 1);
114
168
  const scrollIndicator = HAS_UNICODE ? '↑' : '^';
115
- const hiddenNotice = `${paint('rule', scrollIndicator)} ${dim(`${hiddenCount} earlier thinking line${hiddenCount === 1 ? '' : 's'} scrolled`)}`;
169
+ const activityWord = options.activity || options.title ? `${(options.activity || options.title || '').replace(/…|\.\.\.$/, '').trim()} ` : 'thinking ';
170
+ const hiddenNotice = `${paint('rule', scrollIndicator)} ${dim(`${hiddenCount} earlier ${activityWord}line${hiddenCount === 1 ? '' : 's'} scrolled`)}`;
116
171
  rows.push(wrapRow(hiddenNotice));
117
172
  const tailRows = allRows.slice(totalLines - (maxLines - 1));
118
173
  for (const row of tailRows) {
@@ -130,7 +185,14 @@ export function renderThinkingFrame(content, options = {}) {
130
185
  // Completed Expanded Mode
131
186
  const maxLines = options.maxVisibleLines ?? DEFAULT_MAX_EXPANDED_LINES;
132
187
  const timePart = durationText ? ` · ${durationText}` : '';
133
- const title = `${paint('muted', 'thinking')}${dim(timePart)} ${dim(`(${totalLines} line${totalLines === 1 ? '' : 's'})`)}`;
188
+ const raw = (options.activity || options.title || 'thinking')
189
+ .replace(/…|\.\.\.$/, '')
190
+ .trim()
191
+ .toLowerCase();
192
+ const expandedTitleLabel = options.completedTitle
193
+ ? options.completedTitle.toLowerCase()
194
+ : (raw === 'thinking' ? 'thinking' : raw);
195
+ const title = `${paint('muted', expandedTitleLabel)}${dim(timePart)} ${dim(`(${totalLines} line${totalLines === 1 ? '' : 's'})`)}`;
134
196
  const { top, bottom, wrapRow } = buildThinkingBoxBorders(title, collapseHint, width, 'rule');
135
197
  const rows = [top];
136
198
  if (totalLines > maxLines) {
@@ -18,6 +18,9 @@ export interface ThinkingFrameOptions {
18
18
  maxVisibleLines?: number;
19
19
  role?: string;
20
20
  startLine?: number;
21
+ activity?: string;
22
+ title?: string;
23
+ completedTitle?: string;
21
24
  }
22
25
 
23
26
  export const DEFAULT_MAX_STREAMING_LINES = 8;
@@ -34,6 +37,47 @@ export function calculateThinkingLineCount(content: string, width: number): numb
34
37
  return wrapBlock(text, contentBudget).length;
35
38
  }
36
39
 
40
+ /**
41
+ * Resolves dynamic contextual activity labels for streaming and completed badges.
42
+ */
43
+ export function resolveActivityLabels(options: ThinkingFrameOptions): {
44
+ activeLabel: string;
45
+ completedLabel: string;
46
+ } {
47
+ const raw = (options.activity || options.title || 'thinking')
48
+ .replace(/…|\.\.\.$/, '')
49
+ .trim()
50
+ .toLowerCase();
51
+
52
+ let active = options.title ? options.title.trim() : `${raw}…`;
53
+ if (!options.title) {
54
+ if (raw === 'thinking') active = 'thinking…';
55
+ else if (raw === 'analyzing') active = 'analyzing…';
56
+ else if (raw === 'executing') active = 'executing…';
57
+ else if (raw === 'editing') active = 'editing…';
58
+ else if (raw === 'planning') active = 'planning…';
59
+ else if (raw === 'researching') active = 'researching…';
60
+ else if (raw === 'synthesizing') active = 'synthesizing…';
61
+ else if (raw === 'processing') active = 'processing…';
62
+ else active = `${raw}…`;
63
+ }
64
+
65
+ let completed = options.completedTitle ? options.completedTitle.trim() : '';
66
+ if (!completed) {
67
+ if (raw === 'thinking') completed = 'Thought';
68
+ else if (raw === 'analyzing') completed = 'Analyzed';
69
+ else if (raw === 'executing') completed = 'Executed';
70
+ else if (raw === 'editing') completed = 'Edited';
71
+ else if (raw === 'planning') completed = 'Planned';
72
+ else if (raw === 'researching') completed = 'Researched';
73
+ else if (raw === 'synthesizing') completed = 'Synthesized';
74
+ else if (raw === 'processing') completed = 'Processed';
75
+ else completed = raw.charAt(0).toUpperCase() + raw.slice(1);
76
+ }
77
+
78
+ return { activeLabel: active, completedLabel: completed };
79
+ }
80
+
37
81
  /**
38
82
  * Single-line compact badge for collapsed reasoning frames.
39
83
  */
@@ -44,15 +88,16 @@ export function renderCollapsedThinkingBadge(
44
88
  const isStreaming = Boolean(options.streaming);
45
89
  const durationText = options.durationText ? String(options.durationText).trim() : '';
46
90
  const arrow = HAS_UNICODE ? '▸' : '>';
91
+ const { activeLabel, completedLabel } = resolveActivityLabels(options);
47
92
 
48
93
  if (isStreaming) {
49
94
  const timePart = durationText ? ` · ${durationText}` : '';
50
- return ` ${paint('warn', arrow)} ${bold(paint('warn', 'thinking…'))}${dim(timePart)} ${dim('· click to expand')}`;
95
+ return ` ${paint('warn', arrow)} ${bold(paint('warn', activeLabel))}${dim(timePart)} ${dim('· click to expand')}`;
51
96
  }
52
97
 
53
98
  const timePart = durationText ? ` for ${durationText}` : '';
54
99
  const lineWord = totalLines === 1 ? 'line' : 'lines';
55
- return ` ${paint('muted', arrow)} ${dim(`Thought${timePart}`)} ${dim(`(${totalLines} ${lineWord})`)} ${dim('· click to expand')}`;
100
+ return ` ${paint('muted', arrow)} ${dim(`${completedLabel}${timePart}`)} ${dim(`(${totalLines} ${lineWord})`)} ${dim('· click to expand')}`;
56
101
  }
57
102
 
58
103
  /**
@@ -149,7 +194,8 @@ export function renderThinkingFrame(
149
194
  if (isStreaming) {
150
195
  const maxLines = options.maxVisibleLines ?? DEFAULT_MAX_STREAMING_LINES;
151
196
  const timePart = durationText ? ` · ${durationText}` : '';
152
- const title = `${bold(paint('warn', 'thinking…'))}${dim(timePart)}`;
197
+ const { activeLabel } = resolveActivityLabels(options);
198
+ const title = `${bold(paint('warn', activeLabel))}${dim(timePart)}`;
153
199
  const footer = collapseHint;
154
200
 
155
201
  const { top, bottom, wrapRow } = buildThinkingBoxBorders(title, footer, width, role);
@@ -158,7 +204,8 @@ export function renderThinkingFrame(
158
204
  if (totalLines > maxLines) {
159
205
  const hiddenCount = totalLines - (maxLines - 1);
160
206
  const scrollIndicator = HAS_UNICODE ? '↑' : '^';
161
- const hiddenNotice = `${paint('rule', scrollIndicator)} ${dim(`${hiddenCount} earlier thinking line${hiddenCount === 1 ? '' : 's'} scrolled`)}`;
207
+ const activityWord = options.activity || options.title ? `${(options.activity || options.title || '').replace(/…|\.\.\.$/, '').trim()} ` : 'thinking ';
208
+ const hiddenNotice = `${paint('rule', scrollIndicator)} ${dim(`${hiddenCount} earlier ${activityWord}line${hiddenCount === 1 ? '' : 's'} scrolled`)}`;
162
209
  rows.push(wrapRow(hiddenNotice));
163
210
 
164
211
  const tailRows = allRows.slice(totalLines - (maxLines - 1));
@@ -178,7 +225,14 @@ export function renderThinkingFrame(
178
225
  // Completed Expanded Mode
179
226
  const maxLines = options.maxVisibleLines ?? DEFAULT_MAX_EXPANDED_LINES;
180
227
  const timePart = durationText ? ` · ${durationText}` : '';
181
- const title = `${paint('muted', 'thinking')}${dim(timePart)} ${dim(`(${totalLines} line${totalLines === 1 ? '' : 's'})`)}`;
228
+ const raw = (options.activity || options.title || 'thinking')
229
+ .replace(/…|\.\.\.$/, '')
230
+ .trim()
231
+ .toLowerCase();
232
+ const expandedTitleLabel = options.completedTitle
233
+ ? options.completedTitle.toLowerCase()
234
+ : (raw === 'thinking' ? 'thinking' : raw);
235
+ const title = `${paint('muted', expandedTitleLabel)}${dim(timePart)} ${dim(`(${totalLines} line${totalLines === 1 ? '' : 's'})`)}`;
182
236
 
183
237
  const { top, bottom, wrapRow } = buildThinkingBoxBorders(title, collapseHint, width, 'rule');
184
238
  const rows: string[] = [top];
@@ -16,6 +16,15 @@ export function formatTurnTimestamp(ts) {
16
16
  const dateStr = date.toLocaleDateString('en-US', { month: 'long', day: 'numeric', year: 'numeric' });
17
17
  return `${dateStr} at ${timeStr}`;
18
18
  }
19
+ /**
20
+ * Fast O(N) check for whether user turns exist without flattening or rendering frames.
21
+ */
22
+ export function hasSessionTurns(transcript) {
23
+ if (!transcript || !Array.isArray(transcript.frames) || transcript.frames.length === 0) {
24
+ return false;
25
+ }
26
+ return transcript.frames.some((f) => f && f.kind === 'user');
27
+ }
19
28
  /**
20
29
  * Collect all user turns from transcript frames.
21
30
  */
@@ -36,6 +36,16 @@ export function formatTurnTimestamp(ts: number): string {
36
36
  return `${dateStr} at ${timeStr}`;
37
37
  }
38
38
 
39
+ /**
40
+ * Fast O(N) check for whether user turns exist without flattening or rendering frames.
41
+ */
42
+ export function hasSessionTurns(transcript: any): boolean {
43
+ if (!transcript || !Array.isArray(transcript.frames) || transcript.frames.length === 0) {
44
+ return false;
45
+ }
46
+ return transcript.frames.some((f: any) => f && f.kind === 'user');
47
+ }
48
+
39
49
  /**
40
50
  * Collect all user turns from transcript frames.
41
51
  */
@@ -94,6 +94,7 @@ export class Viewport {
94
94
  accumulator;
95
95
  unseen;
96
96
  lastWheelMoved;
97
+ lastWheelDirection;
97
98
  constructor({ transcript = null, height = 20, width = 80, speed = DEFAULT_SCROLL_SPEED, acceleration = null } = {}) {
98
99
  this.transcript = transcript;
99
100
  this.viewHeight = Math.max(1, Math.floor(height));
@@ -106,6 +107,7 @@ export class Viewport {
106
107
  this.accumulator = 0;
107
108
  this.unseen = 0;
108
109
  this.lastWheelMoved = false;
110
+ this.lastWheelDirection = null;
109
111
  }
110
112
  get height() { return this.viewHeight; }
111
113
  get width() { return this.viewWidth; }
@@ -200,6 +202,10 @@ export class Viewport {
200
202
  */
201
203
  wheel(direction, notches = 1, now = Date.now()) {
202
204
  const before = this.scrollTop;
205
+ if (this.lastWheelDirection && this.lastWheelDirection !== direction) {
206
+ this.accumulator = 0;
207
+ }
208
+ this.lastWheelDirection = direction;
203
209
  const multiplier = this.acceleration ? this.acceleration.tick(now) : 1;
204
210
  const amount = Math.abs(notches) * this.speed * multiplier;
205
211
  this.accumulator += direction === 'up' ? -amount : amount;
@@ -141,6 +141,7 @@ export class Viewport {
141
141
  accumulator: number;
142
142
  unseen: number;
143
143
  lastWheelMoved: boolean;
144
+ lastWheelDirection: 'up' | 'down' | null;
144
145
 
145
146
  constructor({
146
147
  transcript = null,
@@ -161,6 +162,7 @@ export class Viewport {
161
162
  this.accumulator = 0;
162
163
  this.unseen = 0;
163
164
  this.lastWheelMoved = false;
165
+ this.lastWheelDirection = null;
164
166
  }
165
167
 
166
168
  get height(): number { return this.viewHeight; }
@@ -261,6 +263,11 @@ export class Viewport {
261
263
  */
262
264
  wheel(direction: 'up' | 'down', notches: number = 1, now: number = Date.now()): number {
263
265
  const before = this.scrollTop;
266
+ if (this.lastWheelDirection && this.lastWheelDirection !== direction) {
267
+ this.accumulator = 0;
268
+ }
269
+ this.lastWheelDirection = direction;
270
+
264
271
  const multiplier = this.acceleration ? this.acceleration.tick(now) : 1;
265
272
  const amount = Math.abs(notches) * this.speed * multiplier;
266
273
  this.accumulator += direction === 'up' ? -amount : amount;
@@ -1 +0,0 @@
1
- export function panel(rows: string[], options?: { width?: number; title?: string; role?: string }): string[];