@causyne/agent 1.20.5 → 1.20.8

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.
@@ -24,6 +24,7 @@ import { barBlock } from './block.js';
24
24
  import { composerWidth, openingRows, sessionRows } from './layout.js';
25
25
  import { sessionComposerWidth } from './sessionSidebar.js';
26
26
  import { chatProseWidth, wrappedChatRows } from './textLayout.js';
27
+ import { activityRows } from './activityLayout.js';
27
28
 
28
29
  // Bound the preview AFTER wrapping, not by source newlines: one 400 KB line of
29
30
  // minified output would otherwise become thousands of rows and lock the
@@ -420,6 +421,7 @@ export class ChatRenderer {
420
421
  this.stepCount = 0;
421
422
  this.stepStartedAt = null;
422
423
  this.turnStartedAt = Date.now();
424
+ this._activeReasoning = false;
423
425
  this.status.reset();
424
426
  }
425
427
 
@@ -619,6 +621,12 @@ export class ChatRenderer {
619
621
  const elapsedMs = Number(msg.elapsedMs) || 0;
620
622
  const durationText = elapsedMs > 0 ? formatDuration(elapsedMs) : '';
621
623
 
624
+ const tailIsReasoning = !this.transcript
625
+ || this.transcript.frames?.at(-1)?.meta?.reasoning === true;
626
+ if (this._activeReasoning && !tailIsReasoning) {
627
+ this._activeReasoning = false;
628
+ }
629
+
622
630
  if (isStreaming) {
623
631
  if (!this._activeReasoning) {
624
632
  this._activeReasoning = true;
@@ -668,10 +676,15 @@ export class ChatRenderer {
668
676
  }
669
677
 
670
678
  onAgentActivity(msg) {
671
- const text = safeDisplay(msg.activity || msg.message || '').trim();
679
+ const text = String(msg.activity || msg.message || '').trim();
672
680
  if (!text) return;
673
681
  this.frame('notice', () => {
674
- this.write(`${paint('accent', GLYPHS.arrow || '▸')} ${dim(text)}`);
682
+ const prefix = `${GLYPHS.arrow || '▸'} `;
683
+ for (const [index, row] of activityRows(text, this.width(), prefix).entries()) {
684
+ this.write(index === 0
685
+ ? `${paint('accent', GLYPHS.arrow || '▸')} ${dim(row.slice(prefix.length))}`
686
+ : dim(row));
687
+ }
675
688
  }, { activity: true });
676
689
  }
677
690
 
@@ -48,7 +48,17 @@ export class CodeStreamRenderer extends ChatRenderer {
48
48
  transcript.changed();
49
49
  return true;
50
50
  }
51
+ resetTurn() {
52
+ this._activeReasoning = false;
53
+ this.activeCode = null;
54
+ this.modelNote = '';
55
+ this.lastReasoning = '';
56
+ super.resetTurn();
57
+ }
51
58
  handle(message) {
59
+ if (message?.type === 'notice' && message.nativeStep === true) {
60
+ this.stepCount = (this.stepCount || 0) + 1;
61
+ }
52
62
  if (message?.type === 'code_progress') {
53
63
  this.onCodeProgress(message);
54
64
  return true;
@@ -57,6 +67,11 @@ export class CodeStreamRenderer extends ChatRenderer {
57
67
  const content = typeof message.content === 'string' ? message.content : '';
58
68
  if (content)
59
69
  this.lastReasoning = content;
70
+ const transcript = this.transcript;
71
+ const tailIsReasoning = transcript?.frames.at(-1)?.meta?.reasoning === true;
72
+ if (this._activeReasoning && transcript && !tailIsReasoning) {
73
+ this._activeReasoning = false;
74
+ }
60
75
  if (this.activeCode && this.transcript) {
61
76
  const note = content.trim().split('\n').at(-1) || '';
62
77
  this.modelNote = note.slice(-140);
@@ -65,6 +80,7 @@ export class CodeStreamRenderer extends ChatRenderer {
65
80
  }
66
81
  }
67
82
  if (['agent_message', 'step_start', 'task_complete', 'error'].includes(message?.type || '')) {
83
+ this._activeReasoning = false;
68
84
  this.activeCode = null;
69
85
  this.modelNote = '';
70
86
  if (message.type === 'task_complete' || message.type === 'error')
@@ -62,7 +62,18 @@ export class CodeStreamRenderer extends ChatRenderer {
62
62
  return true;
63
63
  }
64
64
 
65
+ override resetTurn(): void {
66
+ this._activeReasoning = false;
67
+ this.activeCode = null;
68
+ this.modelNote = '';
69
+ this.lastReasoning = '';
70
+ super.resetTurn();
71
+ }
72
+
65
73
  override handle(message: RendererEvent): boolean {
74
+ if (message?.type === 'notice' && message.nativeStep === true) {
75
+ this.stepCount = (this.stepCount || 0) + 1;
76
+ }
66
77
  if (message?.type === 'code_progress') {
67
78
  this.onCodeProgress(message as unknown as CodeProgressEvent);
68
79
  return true;
@@ -70,6 +81,11 @@ export class CodeStreamRenderer extends ChatRenderer {
70
81
  if (message?.type === 'agent_reasoning') {
71
82
  const content = typeof message.content === 'string' ? message.content : '';
72
83
  if (content) this.lastReasoning = content;
84
+ const transcript = this.transcript as unknown as CodeTranscript | null;
85
+ const tailIsReasoning = transcript?.frames.at(-1)?.meta?.reasoning === true;
86
+ if (this._activeReasoning && transcript && !tailIsReasoning) {
87
+ this._activeReasoning = false;
88
+ }
73
89
  if (this.activeCode && this.transcript) {
74
90
  const note = content.trim().split('\n').at(-1) || '';
75
91
  this.modelNote = note.slice(-140);
@@ -78,6 +94,7 @@ export class CodeStreamRenderer extends ChatRenderer {
78
94
  }
79
95
  }
80
96
  if (['agent_message', 'step_start', 'task_complete', 'error'].includes(message?.type || '')) {
97
+ this._activeReasoning = false;
81
98
  this.activeCode = null;
82
99
  this.modelNote = '';
83
100
  if (message.type === 'task_complete' || message.type === 'error') this.lastReasoning = '';
@@ -64,3 +64,68 @@ export function openVariantControl(prompt) {
64
64
  }
65
65
  }));
66
66
  }
67
+ export function resetTurnInterruptState(prompt, busy) {
68
+ prompt.interruptedTurn = false;
69
+ if (!busy) {
70
+ prompt.statusMessage = '';
71
+ prompt.notice = '';
72
+ }
73
+ }
74
+ export function shouldAcceptStatusUpdate(prompt) {
75
+ return !(prompt.busy && prompt.interruptedTurn);
76
+ }
77
+ export function triggerTurnInterrupt(prompt, formatInterruptedRow, options = {}) {
78
+ if (Array.isArray(prompt.queue)) {
79
+ prompt.queue.length = 0;
80
+ }
81
+ prompt.statusMessage = 'interrupting…';
82
+ if (!prompt.interruptedTurn) {
83
+ prompt.interruptedTurn = true;
84
+ prompt.erase();
85
+ prompt.commit('notice', () => formatInterruptedRow());
86
+ prompt.notice = options.viaCtrlC ? 'interrupting… press Ctrl+C again to exit' : '';
87
+ }
88
+ else {
89
+ prompt.notice = 'interrupting… press Ctrl+C again to exit';
90
+ }
91
+ prompt.onInterrupt();
92
+ prompt.scheduleDraw();
93
+ }
94
+ export function handlePromptCtrlC(prompt, formatInterruptedRow, windowMs = 2000, now = Date.now()) {
95
+ if (!prompt.editor.isEmpty) {
96
+ prompt.editor.clear();
97
+ prompt.completion = null;
98
+ return;
99
+ }
100
+ if (prompt.busy) {
101
+ if (prompt.interruptedTurn && now - prompt.lastCtrlC < windowMs) {
102
+ prompt.onInterrupt();
103
+ prompt.onExit();
104
+ return;
105
+ }
106
+ prompt.lastCtrlC = now;
107
+ triggerTurnInterrupt(prompt, formatInterruptedRow, { viaCtrlC: true });
108
+ return;
109
+ }
110
+ if (now - prompt.lastCtrlC < windowMs) {
111
+ prompt.onExit();
112
+ return;
113
+ }
114
+ prompt.lastCtrlC = now;
115
+ prompt.notice = 'press Ctrl+C again to exit';
116
+ }
117
+ export function handlePromptEscape(prompt, formatInterruptedRow) {
118
+ if (prompt.completion) {
119
+ prompt.completion = null;
120
+ if (prompt.editor.getText().startsWith('/')) {
121
+ prompt.editor.clear();
122
+ }
123
+ prompt.scheduleDraw();
124
+ return;
125
+ }
126
+ if (prompt.busy) {
127
+ triggerTurnInterrupt(prompt, formatInterruptedRow, { viaCtrlC: false });
128
+ return;
129
+ }
130
+ prompt.editor.clear();
131
+ }
@@ -76,3 +76,109 @@ export function openVariantControl(prompt: ControlPrompt): void {
76
76
  }
77
77
  }));
78
78
  }
79
+
80
+ export interface InterruptiblePrompt {
81
+ busy: boolean;
82
+ interruptedTurn?: boolean;
83
+ lastCtrlC: number;
84
+ notice: string;
85
+ statusMessage: string;
86
+ queue?: unknown[];
87
+ completion: unknown;
88
+ editor: {
89
+ isEmpty: boolean;
90
+ getText(): string;
91
+ clear(): void;
92
+ };
93
+ erase(): void;
94
+ commit(kind: string, produce: (width: number) => string[]): void;
95
+ onInterrupt(): void;
96
+ onExit(): void;
97
+ scheduleDraw(): void;
98
+ }
99
+
100
+ export function resetTurnInterruptState(
101
+ prompt: { interruptedTurn?: boolean; statusMessage?: string; notice?: string },
102
+ busy: boolean
103
+ ): void {
104
+ prompt.interruptedTurn = false;
105
+ if (!busy) {
106
+ prompt.statusMessage = '';
107
+ prompt.notice = '';
108
+ }
109
+ }
110
+
111
+ export function shouldAcceptStatusUpdate(
112
+ prompt: { busy?: boolean; interruptedTurn?: boolean }
113
+ ): boolean {
114
+ return !(prompt.busy && prompt.interruptedTurn);
115
+ }
116
+
117
+ export function triggerTurnInterrupt(
118
+ prompt: InterruptiblePrompt,
119
+ formatInterruptedRow: () => string[],
120
+ options: { viaCtrlC?: boolean } = {}
121
+ ): void {
122
+ if (Array.isArray(prompt.queue)) {
123
+ prompt.queue.length = 0;
124
+ }
125
+ prompt.statusMessage = 'interrupting…';
126
+ if (!prompt.interruptedTurn) {
127
+ prompt.interruptedTurn = true;
128
+ prompt.erase();
129
+ prompt.commit('notice', () => formatInterruptedRow());
130
+ prompt.notice = options.viaCtrlC ? 'interrupting… press Ctrl+C again to exit' : '';
131
+ } else {
132
+ prompt.notice = 'interrupting… press Ctrl+C again to exit';
133
+ }
134
+ prompt.onInterrupt();
135
+ prompt.scheduleDraw();
136
+ }
137
+
138
+ export function handlePromptCtrlC(
139
+ prompt: InterruptiblePrompt,
140
+ formatInterruptedRow: () => string[],
141
+ windowMs = 2000,
142
+ now = Date.now()
143
+ ): void {
144
+ if (!prompt.editor.isEmpty) {
145
+ prompt.editor.clear();
146
+ prompt.completion = null;
147
+ return;
148
+ }
149
+ if (prompt.busy) {
150
+ if (prompt.interruptedTurn && now - prompt.lastCtrlC < windowMs) {
151
+ prompt.onInterrupt();
152
+ prompt.onExit();
153
+ return;
154
+ }
155
+ prompt.lastCtrlC = now;
156
+ triggerTurnInterrupt(prompt, formatInterruptedRow, { viaCtrlC: true });
157
+ return;
158
+ }
159
+ if (now - prompt.lastCtrlC < windowMs) {
160
+ prompt.onExit();
161
+ return;
162
+ }
163
+ prompt.lastCtrlC = now;
164
+ prompt.notice = 'press Ctrl+C again to exit';
165
+ }
166
+
167
+ export function handlePromptEscape(
168
+ prompt: InterruptiblePrompt,
169
+ formatInterruptedRow: () => string[]
170
+ ): void {
171
+ if (prompt.completion) {
172
+ prompt.completion = null;
173
+ if (prompt.editor.getText().startsWith('/')) {
174
+ prompt.editor.clear();
175
+ }
176
+ prompt.scheduleDraw();
177
+ return;
178
+ }
179
+ if (prompt.busy) {
180
+ triggerTurnInterrupt(prompt, formatInterruptedRow, { viaCtrlC: false });
181
+ return;
182
+ }
183
+ prompt.editor.clear();
184
+ }