@causyne/agent 1.20.5 → 1.20.7

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.
@@ -417,6 +417,7 @@ export function mapNativeToolToCausyne(
417
417
 
418
418
  export class AntigravityProvider extends LLMProvider {
419
419
  command: string;
420
+ printTimeout: string;
420
421
  currentConversationId: string | null = null;
421
422
  lastTaskId: string | null = null;
422
423
 
@@ -424,6 +425,9 @@ export class AntigravityProvider extends LLMProvider {
424
425
  super(config);
425
426
  this.model = config.model || 'Gemini 3.8 Flash (Low)';
426
427
  this.command = config.command || resolveAgyBinary();
428
+ this.printTimeout = typeof config.printTimeout === 'string' && config.printTimeout.trim()
429
+ ? config.printTimeout.trim()
430
+ : '1800s';
427
431
  this.visionModels = ['*'];
428
432
  this.audioModels = [];
429
433
  }
@@ -669,10 +673,10 @@ export class AntigravityProvider extends LLMProvider {
669
673
  }
670
674
 
671
675
  async _executeOnce(messages: any[], options: ChatOptions = {}): Promise<ChatResponse> {
672
- const currentTaskId = (options as any).taskId || (options as any).conversationId || null;
673
- if (currentTaskId && currentTaskId !== this.lastTaskId) {
676
+ const currentSessionKey = (options as any).conversationId || (options as any).taskId || null;
677
+ if (currentSessionKey && currentSessionKey !== this.lastTaskId) {
674
678
  this.currentConversationId = null;
675
- this.lastTaskId = currentTaskId;
679
+ this.lastTaskId = currentSessionKey;
676
680
  }
677
681
  if (messages.length <= 1) {
678
682
  this.currentConversationId = null;
@@ -734,7 +738,7 @@ export class AntigravityProvider extends LLMProvider {
734
738
  'stream-json',
735
739
  '--disable-slash-commands',
736
740
  '--print-timeout',
737
- launchOnly ? '90s' : '300s',
741
+ launchOnly ? '90s' : this.printTimeout,
738
742
  '--model',
739
743
  modelSlug,
740
744
  '--effort',
@@ -758,6 +762,7 @@ export class AntigravityProvider extends LLMProvider {
758
762
  let stderrBuffer = '';
759
763
  let streamedResponse = '';
760
764
  let finalResultObj: any = null;
765
+ let sawToolAfterLastText = false;
761
766
  const nativeActions: ChatResponseAction[] = [];
762
767
  const attemptedNativeTools: {
763
768
  name: string;
@@ -797,7 +802,9 @@ export class AntigravityProvider extends LLMProvider {
797
802
  } catch {
798
803
  // ignore kill errors
799
804
  }
800
- safeReject(new Error('Turn aborted by user or timeout.'));
805
+ const abortErr = new Error('Turn aborted by user or timeout.');
806
+ abortErr.name = 'AbortError';
807
+ safeReject(abortErr);
801
808
  };
802
809
 
803
810
  if (options.signal) {
@@ -871,6 +878,7 @@ export class AntigravityProvider extends LLMProvider {
871
878
  }
872
879
 
873
880
  if (name && (state === 'ACTIVE' || state === 'DONE' || state === 'ERROR')) {
881
+ sawToolAfterLastText = true;
874
882
  const detail = describeNativeAction(toolInfo) || describeNativeAction({ parameters: rawParams });
875
883
  const action: ChatResponseAction = {
876
884
  name,
@@ -898,6 +906,15 @@ export class AntigravityProvider extends LLMProvider {
898
906
  options.onReasoningChunk(delta);
899
907
  }
900
908
  } else {
909
+ if (sawToolAfterLastText && streamedResponse.length > 0 && !/\s$/.test(streamedResponse) && !/^\s/.test(delta)) {
910
+ streamedResponse += '\n';
911
+ if (typeof options.onChunk === 'function') {
912
+ options.onChunk('\n');
913
+ }
914
+ }
915
+ if (delta.trim().length > 0) {
916
+ sawToolAfterLastText = false;
917
+ }
901
918
  streamedResponse += delta;
902
919
  if (typeof options.onChunk === 'function') {
903
920
  options.onChunk(delta);
@@ -1037,6 +1054,13 @@ export class AntigravityProvider extends LLMProvider {
1037
1054
  return;
1038
1055
  }
1039
1056
 
1057
+ const timedOutMidTurn = /print timeout after .* with turn in progress|returning partial output/i.test(stderrBuffer);
1058
+ const finalResponseText = typeof finalResultObj?.response === 'string' ? finalResultObj.response.trim() : '';
1059
+ const endedAfterToolWithoutFinalResponse =
1060
+ sawToolAfterLastText && !finalResponseText && deniedActions.length === 0 && toolCalls.length === 0;
1061
+ const missingResultEvent =
1062
+ finalResultObj === null && deniedActions.length === 0 && toolCalls.length === 0;
1063
+
1040
1064
  const promptTokens = Number(finalResultObj?.usage?.input_tokens) || Math.ceil(promptText.length / 4);
1041
1065
  const completionTokens = Number(finalResultObj?.usage?.output_tokens) || Math.ceil(rawContent.length / 4);
1042
1066
  const thinkingTokens = Number(finalResultObj?.usage?.thinking_tokens) || 0;
@@ -1062,6 +1086,10 @@ export class AntigravityProvider extends LLMProvider {
1062
1086
  response.externalActions = nativeActions.filter((a: ChatResponseAction) => a.status !== 'running');
1063
1087
  }
1064
1088
 
1089
+ if (timedOutMidTurn || endedAfterToolWithoutFinalResponse || missingResultEvent) {
1090
+ response.incompleteTurn = true;
1091
+ }
1092
+
1065
1093
  safeResolve(response);
1066
1094
  });
1067
1095
  });
@@ -1071,10 +1099,16 @@ export class AntigravityProvider extends LLMProvider {
1071
1099
  const maxRetries = options.maxRetries ?? ((options as any).taskIntent === 'launch' ? 1 : 2);
1072
1100
  let attempt = 0;
1073
1101
  while (attempt <= maxRetries) {
1102
+ const hadConversation = Boolean(this.currentConversationId);
1074
1103
  try {
1075
1104
  return await this._executeOnce(messages, options);
1076
1105
  } catch (err: any) {
1077
- if (attempt < maxRetries && this._isTransientError(err.message)) {
1106
+ if (options.signal?.aborted || err?.name === 'AbortError') {
1107
+ throw err;
1108
+ }
1109
+ const canRetryResetConversation =
1110
+ hadConversation && !this.currentConversationId && (err as any)?.code !== 'AGY_NATIVE_ACTION_DENIED';
1111
+ if (attempt < maxRetries && (this._isTransientError(err.message) || canRetryResetConversation)) {
1078
1112
  attempt++;
1079
1113
  const delay = attempt * 1200;
1080
1114
  await new Promise(r => setTimeout(r, delay));
@@ -41,6 +41,7 @@ export interface ChatResponse {
41
41
  reasoningContent?: string | undefined;
42
42
  thinkingBlocks?: any[] | undefined;
43
43
  externalActions?: ChatResponseAction[] | undefined;
44
+ incompleteTurn?: boolean | undefined;
44
45
  }
45
46
 
46
47
  export interface ChatOptions {
@@ -70,7 +70,11 @@ export class PiProvider extends LLMProvider {
70
70
  toolCalls: this.formatter.extractToolCalls(raw)
71
71
  });
72
72
  };
73
- const abort = () => fail(new Error('Pi request aborted'));
73
+ const abort = () => {
74
+ const err = new Error('Pi request aborted');
75
+ err.name = 'AbortError';
76
+ fail(err);
77
+ };
74
78
  if (options.signal?.aborted) {
75
79
  abort();
76
80
  return;
@@ -73,7 +73,11 @@ export class PiProvider extends LLMProvider {
73
73
  toolCalls: this.formatter.extractToolCalls(raw)
74
74
  });
75
75
  };
76
- const abort = (): void => fail(new Error('Pi request aborted'));
76
+ const abort = (): void => {
77
+ const err = new Error('Pi request aborted');
78
+ err.name = 'AbortError';
79
+ fail(err);
80
+ };
77
81
  if (options.signal?.aborted) { abort(); return; }
78
82
  options.signal?.addEventListener('abort', abort, { once: true });
79
83
 
@@ -0,0 +1,9 @@
1
+ import { safeDisplay, visibleWidth, wrapBlock } from './text.js';
2
+ /** Render provider activity inside the conversation column, including multiline commands. */
3
+ export function activityRows(message, columns, prefix = '▸ ') {
4
+ const width = Number.isFinite(columns) ? Math.max(20, Math.floor(columns)) : 80;
5
+ const inset = visibleWidth(prefix);
6
+ const bodyWidth = Math.max(1, width - inset - 1);
7
+ const lines = wrapBlock(safeDisplay(message).trim(), bodyWidth, { hang: 2 });
8
+ return lines.map((line, index) => `${index === 0 ? prefix : ' '.repeat(inset)}${line}`);
9
+ }
@@ -0,0 +1,10 @@
1
+ import { safeDisplay, visibleWidth, wrapBlock } from './text.js';
2
+
3
+ /** Render provider activity inside the conversation column, including multiline commands. */
4
+ export function activityRows(message: string, columns: number, prefix = '▸ '): string[] {
5
+ const width = Number.isFinite(columns) ? Math.max(20, Math.floor(columns)) : 80;
6
+ const inset = visibleWidth(prefix);
7
+ const bodyWidth = Math.max(1, width - inset - 1);
8
+ const lines = wrapBlock(safeDisplay(message).trim(), bodyWidth, { hang: 2 });
9
+ return lines.map((line, index) => `${index === 0 ? prefix : ' '.repeat(inset)}${line}`);
10
+ }
@@ -10,8 +10,10 @@ export interface ChatTranscript {
10
10
  export class ChatRenderer {
11
11
  constructor(options?: Record<string, unknown>);
12
12
  transcript: ChatTranscript | null;
13
+ stepCount: number;
13
14
  _activeReasoning?: boolean;
14
15
  handle(message: { type: string; [key: string]: unknown }): boolean;
16
+ resetTurn(): void;
15
17
  onAgentReasoning(message: { content?: string; streaming?: boolean; elapsedMs?: number }): void;
16
18
  stopSpinner(): void;
17
19
  frame(kind: string, produce: () => void, meta?: Record<string, unknown> | null): void;
@@ -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
+ }
package/src/tui/prompt.js CHANGED
@@ -35,6 +35,13 @@ import { settleStageResize } from './resizeRecovery.js';
35
35
  import { sidebarVisible, sessionMainWidth } from './sessionSidebar.js';
36
36
  import { isStartupDialog, startupDialogView } from './homeView.js';
37
37
  import { handleMessageMouse, handleMessageActionMenuMouse, isMouseMotion } from './messageInteraction.js';
38
+ import {
39
+ resetTurnInterruptState,
40
+ shouldAcceptStatusUpdate,
41
+ triggerTurnInterrupt,
42
+ handlePromptCtrlC,
43
+ handlePromptEscape
44
+ } from './composerControls.js';
38
45
 
39
46
  const CTRL_C_WINDOW_MS = 2000;
40
47
 
@@ -154,6 +161,7 @@ export class ChatPrompt {
154
161
  this.completion = null;
155
162
  this.selected = 0;
156
163
  this.lastCtrlC = 0;
164
+ this.interruptedTurn = false;
157
165
  this.notice = '';
158
166
  this.redrawScheduled = false;
159
167
  this.resizeTimer = null;
@@ -281,6 +289,7 @@ export class ChatPrompt {
281
289
  if (this.surface) this.surface.sidebarStatus = renderer.status;
282
290
  renderer.quietStatus = true;
283
291
  renderer.onStatusChange = (message) => {
292
+ if (!shouldAcceptStatusUpdate(this)) return;
284
293
  this.statusMessage = message;
285
294
  this.scheduleDraw();
286
295
  };
@@ -604,7 +613,7 @@ export class ChatPrompt {
604
613
 
605
614
  setBusy(busy) {
606
615
  this.busy = busy;
607
- if (!busy) this.notice = '';
616
+ resetTurnInterruptState(this, busy);
608
617
  if (busy) this.startTick(); else this.stopTick();
609
618
  this.draw();
610
619
  }
@@ -924,36 +933,25 @@ export class ChatPrompt {
924
933
  }
925
934
 
926
935
  handleCtrlC() {
927
- const now = Date.now();
928
- if (!this.editor.isEmpty) {
929
- this.editor.clear();
930
- this.completion = null;
931
- return;
932
- }
933
- if (this.busy) { this.interrupt(); return; }
934
- if (now - this.lastCtrlC < CTRL_C_WINDOW_MS) return this.onExit();
935
- this.lastCtrlC = now;
936
- this.notice = 'press Ctrl+C again to exit';
936
+ handlePromptCtrlC(
937
+ this,
938
+ () => [`${paint('warn', GLYPHS.cross)} ${dim('interrupted')}`],
939
+ CTRL_C_WINDOW_MS
940
+ );
937
941
  }
938
942
 
939
943
  handleEscape() {
940
- if (this.completion) {
941
- this.completion = null;
942
- if (this.editor.getText().startsWith('/')) {
943
- this.editor.clear();
944
- }
945
- this.scheduleDraw();
946
- return;
947
- }
948
- if (this.busy) return this.interrupt();
949
- this.editor.clear();
944
+ handlePromptEscape(
945
+ this,
946
+ () => [`${paint('warn', GLYPHS.cross)} ${dim('interrupted')}`]
947
+ );
950
948
  }
951
949
 
952
950
  interrupt() {
953
- this.erase();
954
- this.commit('notice', () => [`${paint('warn', GLYPHS.cross)} ${dim('interrupted')}`]);
955
- this.notice = '';
956
- this.onInterrupt();
951
+ triggerTurnInterrupt(
952
+ this,
953
+ () => [`${paint('warn', GLYPHS.cross)} ${dim('interrupted')}`]
954
+ );
957
955
  }
958
956
 
959
957
  /** Show the last tool output in full, above the prompt. */
package/src/tui/text.d.ts CHANGED
@@ -2,4 +2,5 @@ export function safeDisplay(value: string): string;
2
2
  export function truncate(value: string, width: number, ellipsis?: string): string;
3
3
  export function padEnd(value: string, width: number): string;
4
4
  export function visibleWidth(value: string): number;
5
- export function wrap(value: string, width: number): string[];
5
+ export function wrap(value: string, width: number, options?: { hang?: number }): string[];
6
+ export function wrapBlock(value: string, width: number, options?: { hang?: number }): string[];