@causyne/agent 1.20.50 → 1.20.53
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 +1 -1
- package/src/agentLoop.js +35 -4
- package/src/agentLoop.ts +32 -4
- package/src/tui/block.js +56 -100
- package/src/tui/block.ts +139 -0
- package/src/tui/chatRenderer.d.ts +2 -2
- package/src/tui/chatRenderer.js +38 -8
- package/src/tui/codeStreamRenderer.js +57 -3
- package/src/tui/codeStreamRenderer.ts +57 -3
- package/src/tui/prompt.js +7 -4
- package/src/tui/stageSurface.js +27 -6
- package/src/tui/theme.js +3 -4
- package/src/tui/thinkingBox.js +67 -5
- package/src/tui/thinkingBox.ts +59 -5
- package/src/tui/turnRail.js +9 -0
- package/src/tui/turnRail.ts +10 -0
- package/src/tui/block.d.ts +0 -1
package/package.json
CHANGED
package/src/agentLoop.js
CHANGED
|
@@ -1290,6 +1290,28 @@ export class AgentLoop {
|
|
|
1290
1290
|
completed: this._implementationPlan.filter((item) => item.status === 'completed').length
|
|
1291
1291
|
});
|
|
1292
1292
|
}
|
|
1293
|
+
inferCurrentActivity() {
|
|
1294
|
+
if (this._implementationPlan && this._implementationPlan.length > 0) {
|
|
1295
|
+
const activeStep = this._implementationPlan.find((s) => s && (s.status === 'in_progress' || s.status === 'running'));
|
|
1296
|
+
const text = activeStep ? (activeStep.step || activeStep.text || activeStep.title || '') : '';
|
|
1297
|
+
if (text && typeof text === 'string') {
|
|
1298
|
+
const lower = text.toLowerCase();
|
|
1299
|
+
if (lower.includes('verify') || lower.includes('test'))
|
|
1300
|
+
return 'Verifying';
|
|
1301
|
+
if (lower.includes('implement') || lower.includes('build') || lower.includes('code'))
|
|
1302
|
+
return 'Implementing';
|
|
1303
|
+
if (lower.includes('scaffold') || lower.includes('setup'))
|
|
1304
|
+
return 'Scaffolding';
|
|
1305
|
+
if (lower.includes('plan'))
|
|
1306
|
+
return 'Planning';
|
|
1307
|
+
return text.slice(0, 30);
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
if (this.stepsCompleted > 0) {
|
|
1311
|
+
return 'Analyzing & executing';
|
|
1312
|
+
}
|
|
1313
|
+
return 'Analyzing & planning';
|
|
1314
|
+
}
|
|
1293
1315
|
seedTaskPhasePlanIfEmpty() {
|
|
1294
1316
|
if (this._implementationPlan.length > 0) {
|
|
1295
1317
|
this.emitEvent({
|
|
@@ -1840,7 +1862,8 @@ export class AgentLoop {
|
|
|
1840
1862
|
auditLog.log({ event: 'task_killed', taskId: this.taskId });
|
|
1841
1863
|
break;
|
|
1842
1864
|
}
|
|
1843
|
-
this.
|
|
1865
|
+
const currentActivity = this.inferCurrentActivity();
|
|
1866
|
+
this.emitEvent({ type: 'status', message: `${currentActivity}…` });
|
|
1844
1867
|
try {
|
|
1845
1868
|
this.smartToolsGovernor.beginModelStep();
|
|
1846
1869
|
// Insert at the model boundary, never between one assistant tool-call
|
|
@@ -2264,8 +2287,9 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
2264
2287
|
elapsedMs
|
|
2265
2288
|
});
|
|
2266
2289
|
};
|
|
2267
|
-
this.
|
|
2268
|
-
this.emitEvent({ type: '
|
|
2290
|
+
const currentActivity = this.inferCurrentActivity();
|
|
2291
|
+
this.emitEvent({ type: 'status', message: `${currentActivity}…` });
|
|
2292
|
+
this.emitEvent({ type: 'agent_activity', activity: `${currentActivity}…` });
|
|
2269
2293
|
const planStepStart = performance.now();
|
|
2270
2294
|
const nativeControl = new AbortController();
|
|
2271
2295
|
const invocation = ++modelCallIndex;
|
|
@@ -2488,7 +2512,14 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
2488
2512
|
}
|
|
2489
2513
|
else if (action.status === 'completed') {
|
|
2490
2514
|
this.emitEvent({ type: 'status', message: '' });
|
|
2491
|
-
this.emitEvent({
|
|
2515
|
+
this.emitEvent({
|
|
2516
|
+
type: 'notice',
|
|
2517
|
+
tone: 'muted',
|
|
2518
|
+
nativeStep: true,
|
|
2519
|
+
actionName: action.name,
|
|
2520
|
+
detail: action.detail,
|
|
2521
|
+
message: `${this.config.provider || 'Provider'} ${action.name}${detail}`
|
|
2522
|
+
});
|
|
2492
2523
|
}
|
|
2493
2524
|
else if (action.status === 'failed') {
|
|
2494
2525
|
this.emitEvent({ type: 'status', message: '' });
|
package/src/agentLoop.ts
CHANGED
|
@@ -1374,6 +1374,25 @@ export class AgentLoop {
|
|
|
1374
1374
|
});
|
|
1375
1375
|
}
|
|
1376
1376
|
|
|
1377
|
+
inferCurrentActivity(): string {
|
|
1378
|
+
if (this._implementationPlan && this._implementationPlan.length > 0) {
|
|
1379
|
+
const activeStep = this._implementationPlan.find((s: any) => s && (s.status === 'in_progress' || s.status === 'running'));
|
|
1380
|
+
const text = activeStep ? (activeStep.step || activeStep.text || activeStep.title || '') : '';
|
|
1381
|
+
if (text && typeof text === 'string') {
|
|
1382
|
+
const lower = text.toLowerCase();
|
|
1383
|
+
if (lower.includes('verify') || lower.includes('test')) return 'Verifying';
|
|
1384
|
+
if (lower.includes('implement') || lower.includes('build') || lower.includes('code')) return 'Implementing';
|
|
1385
|
+
if (lower.includes('scaffold') || lower.includes('setup')) return 'Scaffolding';
|
|
1386
|
+
if (lower.includes('plan')) return 'Planning';
|
|
1387
|
+
return text.slice(0, 30);
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
if (this.stepsCompleted > 0) {
|
|
1391
|
+
return 'Analyzing & executing';
|
|
1392
|
+
}
|
|
1393
|
+
return 'Analyzing & planning';
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1377
1396
|
seedTaskPhasePlanIfEmpty(): void {
|
|
1378
1397
|
if (this._implementationPlan.length > 0) {
|
|
1379
1398
|
this.emitEvent({
|
|
@@ -1929,7 +1948,8 @@ export class AgentLoop {
|
|
|
1929
1948
|
auditLog.log({ event: 'task_killed', taskId: this.taskId });
|
|
1930
1949
|
break;
|
|
1931
1950
|
}
|
|
1932
|
-
this.
|
|
1951
|
+
const currentActivity = this.inferCurrentActivity();
|
|
1952
|
+
this.emitEvent({ type: 'status', message: `${currentActivity}…` });
|
|
1933
1953
|
|
|
1934
1954
|
try {
|
|
1935
1955
|
this.smartToolsGovernor.beginModelStep();
|
|
@@ -2379,8 +2399,9 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
2379
2399
|
});
|
|
2380
2400
|
};
|
|
2381
2401
|
|
|
2382
|
-
this.
|
|
2383
|
-
this.emitEvent({ type: '
|
|
2402
|
+
const currentActivity = this.inferCurrentActivity();
|
|
2403
|
+
this.emitEvent({ type: 'status', message: `${currentActivity}…` });
|
|
2404
|
+
this.emitEvent({ type: 'agent_activity', activity: `${currentActivity}…` });
|
|
2384
2405
|
|
|
2385
2406
|
const planStepStart = performance.now();
|
|
2386
2407
|
const nativeControl = new AbortController();
|
|
@@ -2592,7 +2613,14 @@ You are operating in a text-and-code modality without direct image pixel renderi
|
|
|
2592
2613
|
this.emitEvent({ type: 'status', message: `Acting: ${action.name}${detail}` });
|
|
2593
2614
|
} else if (action.status === 'completed') {
|
|
2594
2615
|
this.emitEvent({ type: 'status', message: '' });
|
|
2595
|
-
this.emitEvent({
|
|
2616
|
+
this.emitEvent({
|
|
2617
|
+
type: 'notice',
|
|
2618
|
+
tone: 'muted',
|
|
2619
|
+
nativeStep: true,
|
|
2620
|
+
actionName: action.name,
|
|
2621
|
+
detail: action.detail,
|
|
2622
|
+
message: `${this.config.provider || 'Provider'} ${action.name}${detail}`
|
|
2623
|
+
});
|
|
2596
2624
|
} else if (action.status === 'failed') {
|
|
2597
2625
|
this.emitEvent({ type: 'status', message: '' });
|
|
2598
2626
|
this.emitEvent({ type: 'warning', message: `${this.config.provider || 'Provider'} could not ${action.name}${detail}` });
|
package/src/tui/block.js
CHANGED
|
@@ -21,62 +21,39 @@
|
|
|
21
21
|
// It degrades in two steps rather than one: without truecolor/256 there is no
|
|
22
22
|
// fill and the bar alone carries the block; without colour at all the bar is an
|
|
23
23
|
// ASCII `|`. A transcript piped to a file stays clean either way.
|
|
24
|
-
//
|
|
25
|
-
// Pure Node over ./theme.js and ./text.js. No dependency, no shell.
|
|
26
|
-
|
|
24
|
+
// @ts-expect-error theme.js has no TypeScript declaration yet.
|
|
27
25
|
import { paint, fill, dim, GLYPHS, HAS_COLOR } from './theme.js';
|
|
28
26
|
import { visibleWidth, padEnd, truncate, wrap } from './text.js';
|
|
29
|
-
|
|
30
27
|
// Columns between the bar and the text. opencode uses paddingLeft={2} inside its
|
|
31
28
|
// bordered box; one column belongs to the bar, so the gutter is one more.
|
|
32
29
|
const GUTTER = 1;
|
|
33
|
-
|
|
34
30
|
/**
|
|
35
31
|
* Render `lines` as one block with a left accent bar.
|
|
32
|
+
* Uses a continuous unbroken box-drawing heavy rule (barHeavy '┃')
|
|
33
|
+
* that dynamically spans the exact length of lines without gaps or bullet interruptions.
|
|
36
34
|
*
|
|
37
|
-
* @param
|
|
38
|
-
* @param
|
|
39
|
-
* @
|
|
40
|
-
* @param {string} options.role accent role for the bar (user, agent, accent…)
|
|
41
|
-
* @param {boolean} options.filled paint the surface behind the text
|
|
42
|
-
* @param {string} options.surface which surface role to fill with
|
|
43
|
-
* @returns {string[]} rows, each exactly `width` columns wide
|
|
35
|
+
* @param lines already-styled rows; NOT re-wrapped (see blockOf)
|
|
36
|
+
* @param options configuration options
|
|
37
|
+
* @returns rows, each exactly `width` columns wide
|
|
44
38
|
*/
|
|
45
|
-
export function barBlock(lines, {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const barWidth = visibleWidth(glyph);
|
|
64
|
-
const body = Math.max(1, width - barWidth - GUTTER);
|
|
65
|
-
const bar = paint(role, glyph);
|
|
66
|
-
const marked = paint(role, GLYPHS.bullet);
|
|
67
|
-
const gutter = ' '.repeat(GUTTER);
|
|
68
|
-
|
|
69
|
-
return lines.map((line, index) => {
|
|
70
|
-
// Clip first, then pad: a line longer than the block would otherwise push
|
|
71
|
-
// the fill past the right edge and wrap, which is the failure ChatPrompt
|
|
72
|
-
// clampRows() exists to prevent one layer up.
|
|
73
|
-
const clipped = visibleWidth(line) > body ? truncate(line, body, GLYPHS.ellipsis) : line;
|
|
74
|
-
const padded = padEnd(clipped, body);
|
|
75
|
-
const inner = filled ? fill(surface, gutter + padded) : gutter + padded;
|
|
76
|
-
return (index === middle ? marked : bar) + inner;
|
|
77
|
-
});
|
|
39
|
+
export function barBlock(lines, { width = 80, role = 'accent', filled = true, surface = 'surface', punctuate = false } = {}) {
|
|
40
|
+
// Use continuous heavy vertical line ('┃') for clean, solid, unbroken alignment.
|
|
41
|
+
// Box-drawing characters connect seamlessly across lines in all terminal fonts without line-height leading gaps.
|
|
42
|
+
const glyph = GLYPHS.barHeavy || GLYPHS.bar || '┃';
|
|
43
|
+
const barWidth = visibleWidth(glyph);
|
|
44
|
+
const body = Math.max(1, width - barWidth - GUTTER);
|
|
45
|
+
const bar = paint(role, glyph);
|
|
46
|
+
const gutter = ' '.repeat(GUTTER);
|
|
47
|
+
return lines.map((line) => {
|
|
48
|
+
// Clip first, then pad: a line longer than the block would otherwise push
|
|
49
|
+
// the fill past the right edge and wrap, which is the failure ChatPrompt
|
|
50
|
+
// clampRows() exists to prevent one layer up.
|
|
51
|
+
const clipped = visibleWidth(line) > body ? truncate(line, body, GLYPHS.ellipsis) : line;
|
|
52
|
+
const padded = padEnd(clipped, body);
|
|
53
|
+
const inner = filled ? fill(surface, gutter + padded) : gutter + padded;
|
|
54
|
+
return bar + inner;
|
|
55
|
+
});
|
|
78
56
|
}
|
|
79
|
-
|
|
80
57
|
/**
|
|
81
58
|
* Wrap `text` to the block's inner width, then render it as a block.
|
|
82
59
|
*
|
|
@@ -84,69 +61,48 @@ export function barBlock(lines, {
|
|
|
84
61
|
* rows individually (the prompt editor, a status row) use barBlock directly.
|
|
85
62
|
*/
|
|
86
63
|
export function blockOf(text, options = {}) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
64
|
+
const width = options.width || 80;
|
|
65
|
+
const glyph = GLYPHS.barHeavy || GLYPHS.bar || '┃';
|
|
66
|
+
const inner = Math.max(1, width - visibleWidth(glyph) - GUTTER);
|
|
67
|
+
const lines = wrap(String(text == null ? '' : text), inner);
|
|
68
|
+
return barBlock(lines.length ? lines : [''], options);
|
|
91
69
|
}
|
|
92
|
-
|
|
93
70
|
/**
|
|
94
71
|
* A bordered panel with its title inset into the top border.
|
|
95
|
-
*
|
|
96
|
-
* The session header used to be two horizontal rules with label/value rows
|
|
97
|
-
* between them, which reads as a table of settings rather than as a greeting.
|
|
98
|
-
* Both references open with a bordered panel instead — claude-code insets the
|
|
99
|
-
* product name and version into the top rule exactly this way.
|
|
100
|
-
*
|
|
101
|
-
* `rows` are already-styled strings. Returns rows of exactly `width` columns.
|
|
102
72
|
*/
|
|
103
73
|
export function panel(rows, { width = 80, title = '', role = 'rule' } = {}) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
return [top, ...middle, bottom];
|
|
74
|
+
const inner = Math.max(4, width - 2);
|
|
75
|
+
const h = GLYPHS.hLine;
|
|
76
|
+
const label = title ? ` ${title} ` : '';
|
|
77
|
+
const clippedLabel = visibleWidth(label) > inner - 2 ? '' : label;
|
|
78
|
+
const lead = clippedLabel ? h : '';
|
|
79
|
+
const trail = h.repeat(Math.max(0, inner - visibleWidth(clippedLabel) - visibleWidth(lead)));
|
|
80
|
+
const top = paint(role, GLYPHS.topLeft + lead)
|
|
81
|
+
+ (clippedLabel ? paint('accent', clippedLabel) : '')
|
|
82
|
+
+ paint(role, trail + GLYPHS.topRight);
|
|
83
|
+
const bottom = paint(role, GLYPHS.bottomLeft + h.repeat(inner) + GLYPHS.bottomRight);
|
|
84
|
+
const side = paint(role, GLYPHS.vLine);
|
|
85
|
+
const middle = rows.map((row) => {
|
|
86
|
+
const clipped = visibleWidth(row) > inner ? truncate(row, inner, GLYPHS.ellipsis) : row;
|
|
87
|
+
return side + padEnd(clipped, inner) + side;
|
|
88
|
+
});
|
|
89
|
+
return [top, ...middle, bottom];
|
|
123
90
|
}
|
|
124
|
-
|
|
125
91
|
/**
|
|
126
92
|
* `9.2K (5%)` — what the context window has left, at a glance.
|
|
127
|
-
*
|
|
128
|
-
* Returns '' rather than a misleading 0% when no limit is known: an invented
|
|
129
|
-
* denominator is worse than a missing number.
|
|
130
|
-
*
|
|
131
|
-
* BOTH ARGUMENTS MUST BE IN THE SAME UNIT. The caller was passing a cumulative
|
|
132
|
-
* TOKEN count and a CHARACTER pool, which is how a quarter-full window came to
|
|
133
|
-
* report 99%.
|
|
134
93
|
*/
|
|
135
94
|
export function contextMeter(usedTokens, limitTokens) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
// "over" is a meter that cannot report the only thing worth acting on.
|
|
149
|
-
return `${compact} (${Math.round((used / limit) * 100)}%)`;
|
|
95
|
+
const used = Number(usedTokens) || 0;
|
|
96
|
+
const limit = Number(limitTokens) || 0;
|
|
97
|
+
if (used <= 0)
|
|
98
|
+
return '';
|
|
99
|
+
const compact = used < 1000
|
|
100
|
+
? String(Math.round(used))
|
|
101
|
+
: used < 1000000
|
|
102
|
+
? `${(used / 1000).toFixed(used < 10000 ? 1 : 0)}K`
|
|
103
|
+
: `${(used / 1000000).toFixed(1)}M`;
|
|
104
|
+
if (limit <= 0)
|
|
105
|
+
return compact;
|
|
106
|
+
return `${compact} (${Math.round((used / limit) * 100)}%)`;
|
|
150
107
|
}
|
|
151
|
-
|
|
152
108
|
export { GUTTER };
|
package/src/tui/block.ts
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// Blocks: a left accent bar and a filled surface, the shape that makes a run of
|
|
2
|
+
// terminal rows read as ONE thing.
|
|
3
|
+
//
|
|
4
|
+
// Causyne's chat printed every kind of row the same way — the user's message, the
|
|
5
|
+
// agent's reply, an aside from the loop and the prompt itself were all just
|
|
6
|
+
// lines in the scrollback, distinguishable only by a leading glyph. On a busy
|
|
7
|
+
// turn there was no visual seam anywhere, which is the difference the reference
|
|
8
|
+
// tools actually make. opencode gives each of those a left border in the agent's
|
|
9
|
+
// colour and a background one step off the terminal's own
|
|
10
|
+
// (component/prompt/index.tsx:1353 — `border={["left"]}` + `borderColor` +
|
|
11
|
+
// `backgroundColor={theme.backgroundElement}` + `paddingLeft={2}`).
|
|
12
|
+
//
|
|
13
|
+
// Two properties make it work, and both are easy to get wrong:
|
|
14
|
+
//
|
|
15
|
+
// * EVERY ROW IS PADDED TO THE SAME WIDTH. A background only reads as a surface
|
|
16
|
+
// if it runs past the last character; ragged rows read as highlighted text.
|
|
17
|
+
// * THE PADDING IS MEASURED, NOT COUNTED. padEnd() on a coloured string pads by
|
|
18
|
+
// byte length, so the escape sequences count toward the column and the right
|
|
19
|
+
// edge of the block frays. text.js padEnd() measures visible width.
|
|
20
|
+
//
|
|
21
|
+
// It degrades in two steps rather than one: without truecolor/256 there is no
|
|
22
|
+
// fill and the bar alone carries the block; without colour at all the bar is an
|
|
23
|
+
// ASCII `|`. A transcript piped to a file stays clean either way.
|
|
24
|
+
|
|
25
|
+
// @ts-expect-error theme.js has no TypeScript declaration yet.
|
|
26
|
+
import { paint, fill, dim, GLYPHS, HAS_COLOR } from './theme.js';
|
|
27
|
+
import { visibleWidth, padEnd, truncate, wrap } from './text.js';
|
|
28
|
+
|
|
29
|
+
// Columns between the bar and the text. opencode uses paddingLeft={2} inside its
|
|
30
|
+
// bordered box; one column belongs to the bar, so the gutter is one more.
|
|
31
|
+
const GUTTER = 1;
|
|
32
|
+
|
|
33
|
+
export interface BarBlockOptions {
|
|
34
|
+
width?: number;
|
|
35
|
+
role?: string;
|
|
36
|
+
filled?: boolean;
|
|
37
|
+
surface?: string;
|
|
38
|
+
punctuate?: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Render `lines` as one block with a left accent bar.
|
|
43
|
+
* Uses a continuous unbroken box-drawing heavy rule (barHeavy '┃')
|
|
44
|
+
* that dynamically spans the exact length of lines without gaps or bullet interruptions.
|
|
45
|
+
*
|
|
46
|
+
* @param lines already-styled rows; NOT re-wrapped (see blockOf)
|
|
47
|
+
* @param options configuration options
|
|
48
|
+
* @returns rows, each exactly `width` columns wide
|
|
49
|
+
*/
|
|
50
|
+
export function barBlock(lines: string[], {
|
|
51
|
+
width = 80,
|
|
52
|
+
role = 'accent',
|
|
53
|
+
filled = true,
|
|
54
|
+
surface = 'surface',
|
|
55
|
+
punctuate = false
|
|
56
|
+
}: BarBlockOptions = {}): string[] {
|
|
57
|
+
// Use continuous heavy vertical line ('┃') for clean, solid, unbroken alignment.
|
|
58
|
+
// Box-drawing characters connect seamlessly across lines in all terminal fonts without line-height leading gaps.
|
|
59
|
+
const glyph = GLYPHS.barHeavy || GLYPHS.bar || '┃';
|
|
60
|
+
|
|
61
|
+
const barWidth = visibleWidth(glyph);
|
|
62
|
+
const body = Math.max(1, width - barWidth - GUTTER);
|
|
63
|
+
const bar = paint(role, glyph);
|
|
64
|
+
const gutter = ' '.repeat(GUTTER);
|
|
65
|
+
|
|
66
|
+
return lines.map((line) => {
|
|
67
|
+
// Clip first, then pad: a line longer than the block would otherwise push
|
|
68
|
+
// the fill past the right edge and wrap, which is the failure ChatPrompt
|
|
69
|
+
// clampRows() exists to prevent one layer up.
|
|
70
|
+
const clipped = visibleWidth(line) > body ? truncate(line, body, GLYPHS.ellipsis) : line;
|
|
71
|
+
const padded = padEnd(clipped, body);
|
|
72
|
+
const inner = filled ? fill(surface, gutter + padded) : gutter + padded;
|
|
73
|
+
return bar + inner;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Wrap `text` to the block's inner width, then render it as a block.
|
|
79
|
+
*
|
|
80
|
+
* The convenience form for plain prose. Callers that have already styled their
|
|
81
|
+
* rows individually (the prompt editor, a status row) use barBlock directly.
|
|
82
|
+
*/
|
|
83
|
+
export function blockOf(text: string, options: BarBlockOptions = {}): string[] {
|
|
84
|
+
const width = options.width || 80;
|
|
85
|
+
const glyph = GLYPHS.barHeavy || GLYPHS.bar || '┃';
|
|
86
|
+
const inner = Math.max(1, width - visibleWidth(glyph) - GUTTER);
|
|
87
|
+
const lines = wrap(String(text == null ? '' : text), inner);
|
|
88
|
+
return barBlock(lines.length ? lines : [''], options);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface PanelOptions {
|
|
92
|
+
width?: number;
|
|
93
|
+
title?: string;
|
|
94
|
+
role?: string;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* A bordered panel with its title inset into the top border.
|
|
99
|
+
*/
|
|
100
|
+
export function panel(rows: string[], { width = 80, title = '', role = 'rule' }: PanelOptions = {}): string[] {
|
|
101
|
+
const inner = Math.max(4, width - 2);
|
|
102
|
+
const h = GLYPHS.hLine;
|
|
103
|
+
const label = title ? ` ${title} ` : '';
|
|
104
|
+
const clippedLabel = visibleWidth(label) > inner - 2 ? '' : label;
|
|
105
|
+
const lead = clippedLabel ? h : '';
|
|
106
|
+
const trail = h.repeat(Math.max(0, inner - visibleWidth(clippedLabel) - visibleWidth(lead)));
|
|
107
|
+
|
|
108
|
+
const top = paint(role, GLYPHS.topLeft + lead)
|
|
109
|
+
+ (clippedLabel ? paint('accent', clippedLabel) : '')
|
|
110
|
+
+ paint(role, trail + GLYPHS.topRight);
|
|
111
|
+
const bottom = paint(role, GLYPHS.bottomLeft + h.repeat(inner) + GLYPHS.bottomRight);
|
|
112
|
+
|
|
113
|
+
const side = paint(role, GLYPHS.vLine);
|
|
114
|
+
const middle = rows.map((row) => {
|
|
115
|
+
const clipped = visibleWidth(row) > inner ? truncate(row, inner, GLYPHS.ellipsis) : row;
|
|
116
|
+
return side + padEnd(clipped, inner) + side;
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
return [top, ...middle, bottom];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* `9.2K (5%)` — what the context window has left, at a glance.
|
|
124
|
+
*/
|
|
125
|
+
export function contextMeter(usedTokens: number, limitTokens: number): string {
|
|
126
|
+
const used = Number(usedTokens) || 0;
|
|
127
|
+
const limit = Number(limitTokens) || 0;
|
|
128
|
+
if (used <= 0) return '';
|
|
129
|
+
const compact = used < 1000
|
|
130
|
+
? String(Math.round(used))
|
|
131
|
+
: used < 1000000
|
|
132
|
+
? `${(used / 1000).toFixed(used < 10000 ? 1 : 0)}K`
|
|
133
|
+
: `${(used / 1000000).toFixed(1)}M`;
|
|
134
|
+
if (limit <= 0) return compact;
|
|
135
|
+
return `${compact} (${Math.round((used / limit) * 100)}%)`;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export { GUTTER };
|
|
139
|
+
|
|
@@ -15,8 +15,8 @@ export class ChatRenderer {
|
|
|
15
15
|
handle(message: { type: string; [key: string]: unknown }): boolean;
|
|
16
16
|
resetTurn(): void;
|
|
17
17
|
turnFooter(durationMs?: number): void;
|
|
18
|
-
onAgentReasoning(message: { content?: string; streaming?: boolean; elapsedMs?: number }): void;
|
|
19
|
-
renderReasoning(content: string, options?: { streaming?: boolean; durationText?: string; collapsed?: boolean; startLine?: number }): void;
|
|
18
|
+
onAgentReasoning(message: { content?: string; streaming?: boolean; elapsedMs?: number; activity?: string; title?: string; completedTitle?: string }): void;
|
|
19
|
+
renderReasoning(content: string, options?: { streaming?: boolean; durationText?: string; collapsed?: boolean; startLine?: number; activity?: string; title?: string; completedTitle?: string }): void;
|
|
20
20
|
scrollThinkingPanel?(key: unknown, surface: unknown): boolean;
|
|
21
21
|
stopSpinner(): void;
|
|
22
22
|
frame(kind: string, produce: () => void, meta?: Record<string, unknown> | null): void;
|
package/src/tui/chatRenderer.js
CHANGED
|
@@ -505,8 +505,8 @@ export class ChatRenderer {
|
|
|
505
505
|
const width = this.transcript
|
|
506
506
|
? sessionComposerWidth(this.width())
|
|
507
507
|
: composerWidth(this.measure());
|
|
508
|
-
const blockWidth = Math.max(8, width
|
|
509
|
-
const innerWidth = Math.max(8, blockWidth - visibleWidth(GLYPHS.bar) - 1);
|
|
508
|
+
const blockWidth = Math.max(8, width);
|
|
509
|
+
const innerWidth = Math.max(8, blockWidth - visibleWidth(GLYPHS.barHeavy || GLYPHS.bar) - 1);
|
|
510
510
|
const rows = barBlock(
|
|
511
511
|
wrapBlock(safeDisplay(text), innerWidth),
|
|
512
512
|
{ width: blockWidth, role: 'user', filled: true, surface: 'surfaceHi' }
|
|
@@ -770,6 +770,9 @@ export class ChatRenderer {
|
|
|
770
770
|
const isStreaming = Boolean(msg.streaming);
|
|
771
771
|
const elapsedMs = Number(msg.elapsedMs) || 0;
|
|
772
772
|
const durationText = elapsedMs > 0 ? formatDuration(elapsedMs) : '';
|
|
773
|
+
const activity = typeof msg.activity === 'string' ? msg.activity : '';
|
|
774
|
+
const title = typeof msg.title === 'string' ? msg.title : '';
|
|
775
|
+
const completedTitle = typeof msg.completedTitle === 'string' ? msg.completedTitle : '';
|
|
773
776
|
|
|
774
777
|
const tailFrame = this.transcript?.frames?.at(-1);
|
|
775
778
|
const tailIsReasoning = !this.transcript
|
|
@@ -787,26 +790,38 @@ export class ChatRenderer {
|
|
|
787
790
|
streaming: true,
|
|
788
791
|
durationText,
|
|
789
792
|
content,
|
|
793
|
+
activity,
|
|
794
|
+
title,
|
|
795
|
+
completedTitle,
|
|
790
796
|
scrollStart: 0
|
|
791
797
|
};
|
|
792
798
|
this.frame('reasoning', () => this.renderReasoning(meta.content, {
|
|
793
799
|
streaming: Boolean(meta.streaming),
|
|
794
800
|
durationText: meta.durationText,
|
|
795
801
|
collapsed: Boolean(meta.collapsed),
|
|
796
|
-
startLine: Number(meta.scrollStart) || 0
|
|
802
|
+
startLine: Number(meta.scrollStart) || 0,
|
|
803
|
+
activity: meta.activity,
|
|
804
|
+
title: meta.title,
|
|
805
|
+
completedTitle: meta.completedTitle
|
|
797
806
|
}), meta);
|
|
798
807
|
} else {
|
|
799
808
|
const meta = tailFrame?.meta || { reasoning: true };
|
|
800
809
|
meta.streaming = true;
|
|
801
810
|
meta.durationText = durationText;
|
|
802
811
|
meta.content = content;
|
|
812
|
+
if (activity) meta.activity = activity;
|
|
813
|
+
if (title) meta.title = title;
|
|
814
|
+
if (completedTitle) meta.completedTitle = completedTitle;
|
|
803
815
|
if (meta.collapsed === undefined) meta.collapsed = false;
|
|
804
816
|
if (meta.scrollStart === undefined) meta.scrollStart = 0;
|
|
805
817
|
this.updateTailFrame('reasoning', () => this.renderReasoning(meta.content, {
|
|
806
818
|
streaming: Boolean(meta.streaming),
|
|
807
819
|
durationText: meta.durationText,
|
|
808
820
|
collapsed: Boolean(meta.collapsed),
|
|
809
|
-
startLine: Number(meta.scrollStart) || 0
|
|
821
|
+
startLine: Number(meta.scrollStart) || 0,
|
|
822
|
+
activity: meta.activity,
|
|
823
|
+
title: meta.title,
|
|
824
|
+
completedTitle: meta.completedTitle
|
|
810
825
|
}), meta);
|
|
811
826
|
}
|
|
812
827
|
return;
|
|
@@ -819,13 +834,19 @@ export class ChatRenderer {
|
|
|
819
834
|
meta.done = true;
|
|
820
835
|
meta.durationText = durationText;
|
|
821
836
|
meta.content = content;
|
|
837
|
+
if (activity) meta.activity = activity;
|
|
838
|
+
if (title) meta.title = title;
|
|
839
|
+
if (completedTitle) meta.completedTitle = completedTitle;
|
|
822
840
|
if (meta.collapsed === undefined) meta.collapsed = Boolean(msg.collapsed);
|
|
823
841
|
if (meta.scrollStart === undefined) meta.scrollStart = 0;
|
|
824
842
|
this.updateTailFrame('reasoning', () => this.renderReasoning(meta.content, {
|
|
825
843
|
streaming: Boolean(meta.streaming),
|
|
826
844
|
durationText: meta.durationText,
|
|
827
845
|
collapsed: Boolean(meta.collapsed),
|
|
828
|
-
startLine: Number(meta.scrollStart) || 0
|
|
846
|
+
startLine: Number(meta.scrollStart) || 0,
|
|
847
|
+
activity: meta.activity,
|
|
848
|
+
title: meta.title,
|
|
849
|
+
completedTitle: meta.completedTitle
|
|
829
850
|
}), meta);
|
|
830
851
|
} else if (content.trim()) {
|
|
831
852
|
const meta = {
|
|
@@ -834,6 +855,9 @@ export class ChatRenderer {
|
|
|
834
855
|
streaming: false,
|
|
835
856
|
durationText,
|
|
836
857
|
content,
|
|
858
|
+
activity,
|
|
859
|
+
title,
|
|
860
|
+
completedTitle,
|
|
837
861
|
collapsed: Boolean(msg.collapsed),
|
|
838
862
|
scrollStart: 0
|
|
839
863
|
};
|
|
@@ -841,19 +865,25 @@ export class ChatRenderer {
|
|
|
841
865
|
streaming: Boolean(meta.streaming),
|
|
842
866
|
durationText: meta.durationText,
|
|
843
867
|
collapsed: Boolean(meta.collapsed),
|
|
844
|
-
startLine: Number(meta.scrollStart) || 0
|
|
868
|
+
startLine: Number(meta.scrollStart) || 0,
|
|
869
|
+
activity: meta.activity,
|
|
870
|
+
title: meta.title,
|
|
871
|
+
completedTitle: meta.completedTitle
|
|
845
872
|
}), meta);
|
|
846
873
|
}
|
|
847
874
|
}
|
|
848
875
|
|
|
849
|
-
renderReasoning(content, { streaming = false, durationText = '', collapsed = false, startLine = 0 } = {}) {
|
|
876
|
+
renderReasoning(content, { streaming = false, durationText = '', collapsed = false, startLine = 0, activity = '', title = '', completedTitle = '' } = {}) {
|
|
850
877
|
const width = this.measure();
|
|
851
878
|
const rows = renderThinkingFrame(content, {
|
|
852
879
|
width,
|
|
853
880
|
streaming,
|
|
854
881
|
durationText,
|
|
855
882
|
collapsed,
|
|
856
|
-
startLine: Number(startLine) || 0
|
|
883
|
+
startLine: Number(startLine) || 0,
|
|
884
|
+
activity,
|
|
885
|
+
title,
|
|
886
|
+
completedTitle
|
|
857
887
|
});
|
|
858
888
|
|
|
859
889
|
if (rows.length === 0) return;
|
|
@@ -10,6 +10,7 @@ export class CodeStreamRenderer extends ChatRenderer {
|
|
|
10
10
|
activeCode = null;
|
|
11
11
|
modelNote = '';
|
|
12
12
|
lastReasoning = '';
|
|
13
|
+
currentActivity = 'thinking';
|
|
13
14
|
codePanels = new WeakMap();
|
|
14
15
|
/** Scroll only the code beneath the pointer; leave the chat viewport alone. */
|
|
15
16
|
scrollCodePanel(key, surface) {
|
|
@@ -113,8 +114,53 @@ export class CodeStreamRenderer extends ChatRenderer {
|
|
|
113
114
|
}
|
|
114
115
|
}
|
|
115
116
|
handle(message) {
|
|
117
|
+
if (message?.type === 'agent_activity') {
|
|
118
|
+
const rawActivity = String(message.activity || message.message || '').trim();
|
|
119
|
+
if (rawActivity) {
|
|
120
|
+
this.currentActivity = rawActivity.replace(/…|\.\.\.$/, '').trim();
|
|
121
|
+
if (this._activeReasoning && this.lastReasoning) {
|
|
122
|
+
super.onAgentReasoning({
|
|
123
|
+
content: this.lastReasoning,
|
|
124
|
+
streaming: true,
|
|
125
|
+
activity: this.currentActivity,
|
|
126
|
+
title: rawActivity
|
|
127
|
+
});
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
116
132
|
if (message?.type === 'notice' && message.nativeStep === true) {
|
|
117
133
|
this.stepCount = (this.stepCount || 0) + 1;
|
|
134
|
+
const stepLine = String(message.message || '').trim();
|
|
135
|
+
if (stepLine) {
|
|
136
|
+
const actionName = String(message.actionName || stepLine).toLowerCase();
|
|
137
|
+
let activity = this.currentActivity || 'processing';
|
|
138
|
+
if (['read_file', 'fs_read', 'view_file', 'cat', 'grep', 'find', 'ls'].some(k => actionName.includes(k))) {
|
|
139
|
+
activity = 'analyzing';
|
|
140
|
+
}
|
|
141
|
+
else if (['run_command', 'sysrun', 'bash', 'terminal', 'sh', 'exec'].some(k => actionName.includes(k))) {
|
|
142
|
+
activity = 'executing';
|
|
143
|
+
}
|
|
144
|
+
else if (['write_file', 'edit_file', 'multiedit', 'replace_file_content', 'fs_write'].some(k => actionName.includes(k))) {
|
|
145
|
+
activity = 'editing';
|
|
146
|
+
}
|
|
147
|
+
else if (['web_search', 'web_fetch', 'browse'].some(k => actionName.includes(k))) {
|
|
148
|
+
activity = 'researching';
|
|
149
|
+
}
|
|
150
|
+
else if (['plan', 'todo'].some(k => actionName.includes(k))) {
|
|
151
|
+
activity = 'planning';
|
|
152
|
+
}
|
|
153
|
+
this.currentActivity = activity;
|
|
154
|
+
const currentContent = this.lastReasoning ? `${this.lastReasoning}\n${stepLine}` : stepLine;
|
|
155
|
+
this.lastReasoning = currentContent;
|
|
156
|
+
super.onAgentReasoning({
|
|
157
|
+
content: currentContent,
|
|
158
|
+
streaming: true,
|
|
159
|
+
activity,
|
|
160
|
+
title: `${activity}…`
|
|
161
|
+
});
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
118
164
|
}
|
|
119
165
|
if (message?.type === 'code_progress') {
|
|
120
166
|
this.onCodeProgress(message);
|
|
@@ -138,15 +184,23 @@ export class CodeStreamRenderer extends ChatRenderer {
|
|
|
138
184
|
}
|
|
139
185
|
return true;
|
|
140
186
|
}
|
|
141
|
-
const handled = super.handle(
|
|
187
|
+
const handled = super.handle({
|
|
188
|
+
...message,
|
|
189
|
+
activity: message.activity || this.currentActivity
|
|
190
|
+
});
|
|
142
191
|
if (message.streaming === false) {
|
|
143
192
|
this.lastReasoning = '';
|
|
144
193
|
}
|
|
145
194
|
return handled;
|
|
146
195
|
}
|
|
147
|
-
if (['agent_message', '
|
|
196
|
+
if (['agent_message', 'budget_warning', 'step_start', 'task_complete', 'error', 'agent_plan'].includes(message?.type || '')
|
|
197
|
+
|| (message?.type === 'notice' && !message.nativeStep)) {
|
|
148
198
|
if (this._activeReasoning && this.lastReasoning) {
|
|
149
|
-
super.onAgentReasoning({
|
|
199
|
+
super.onAgentReasoning({
|
|
200
|
+
content: this.lastReasoning,
|
|
201
|
+
streaming: false,
|
|
202
|
+
activity: this.currentActivity
|
|
203
|
+
});
|
|
150
204
|
}
|
|
151
205
|
this._activeReasoning = false;
|
|
152
206
|
this.lastReasoning = '';
|
|
@@ -29,6 +29,7 @@ export class CodeStreamRenderer extends ChatRenderer {
|
|
|
29
29
|
private activeCode: CodeProgressEvent | null = null;
|
|
30
30
|
private modelNote = '';
|
|
31
31
|
private lastReasoning = '';
|
|
32
|
+
private currentActivity = 'thinking';
|
|
32
33
|
private readonly codePanels = new WeakMap<CodeFrame, CodePanelState>();
|
|
33
34
|
|
|
34
35
|
/** Scroll only the code beneath the pointer; leave the chat viewport alone. */
|
|
@@ -133,9 +134,54 @@ export class CodeStreamRenderer extends ChatRenderer {
|
|
|
133
134
|
}
|
|
134
135
|
|
|
135
136
|
override handle(message: RendererEvent): boolean {
|
|
137
|
+
if (message?.type === 'agent_activity') {
|
|
138
|
+
const rawActivity = String((message as any).activity || (message as any).message || '').trim();
|
|
139
|
+
if (rawActivity) {
|
|
140
|
+
this.currentActivity = rawActivity.replace(/…|\.\.\.$/, '').trim();
|
|
141
|
+
if (this._activeReasoning && this.lastReasoning) {
|
|
142
|
+
super.onAgentReasoning({
|
|
143
|
+
content: this.lastReasoning,
|
|
144
|
+
streaming: true,
|
|
145
|
+
activity: this.currentActivity,
|
|
146
|
+
title: rawActivity
|
|
147
|
+
});
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
136
153
|
if (message?.type === 'notice' && message.nativeStep === true) {
|
|
137
154
|
this.stepCount = (this.stepCount || 0) + 1;
|
|
155
|
+
const stepLine = String(message.message || '').trim();
|
|
156
|
+
if (stepLine) {
|
|
157
|
+
const actionName = String((message as any).actionName || stepLine).toLowerCase();
|
|
158
|
+
let activity = this.currentActivity || 'processing';
|
|
159
|
+
if (['read_file', 'fs_read', 'view_file', 'cat', 'grep', 'find', 'ls'].some(k => actionName.includes(k))) {
|
|
160
|
+
activity = 'analyzing';
|
|
161
|
+
} else if (['run_command', 'sysrun', 'bash', 'terminal', 'sh', 'exec'].some(k => actionName.includes(k))) {
|
|
162
|
+
activity = 'executing';
|
|
163
|
+
} else if (['write_file', 'edit_file', 'multiedit', 'replace_file_content', 'fs_write'].some(k => actionName.includes(k))) {
|
|
164
|
+
activity = 'editing';
|
|
165
|
+
} else if (['web_search', 'web_fetch', 'browse'].some(k => actionName.includes(k))) {
|
|
166
|
+
activity = 'researching';
|
|
167
|
+
} else if (['plan', 'todo'].some(k => actionName.includes(k))) {
|
|
168
|
+
activity = 'planning';
|
|
169
|
+
}
|
|
170
|
+
this.currentActivity = activity;
|
|
171
|
+
|
|
172
|
+
const currentContent = this.lastReasoning ? `${this.lastReasoning}\n${stepLine}` : stepLine;
|
|
173
|
+
this.lastReasoning = currentContent;
|
|
174
|
+
|
|
175
|
+
super.onAgentReasoning({
|
|
176
|
+
content: currentContent,
|
|
177
|
+
streaming: true,
|
|
178
|
+
activity,
|
|
179
|
+
title: `${activity}…`
|
|
180
|
+
});
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
138
183
|
}
|
|
184
|
+
|
|
139
185
|
if (message?.type === 'code_progress') {
|
|
140
186
|
this.onCodeProgress(message as unknown as CodeProgressEvent);
|
|
141
187
|
return true;
|
|
@@ -157,15 +203,23 @@ export class CodeStreamRenderer extends ChatRenderer {
|
|
|
157
203
|
}
|
|
158
204
|
return true;
|
|
159
205
|
}
|
|
160
|
-
const handled = super.handle(
|
|
206
|
+
const handled = super.handle({
|
|
207
|
+
...message,
|
|
208
|
+
activity: (message as any).activity || this.currentActivity
|
|
209
|
+
});
|
|
161
210
|
if (message.streaming === false) {
|
|
162
211
|
this.lastReasoning = '';
|
|
163
212
|
}
|
|
164
213
|
return handled;
|
|
165
214
|
}
|
|
166
|
-
if (['agent_message', '
|
|
215
|
+
if (['agent_message', 'budget_warning', 'step_start', 'task_complete', 'error', 'agent_plan'].includes(message?.type || '')
|
|
216
|
+
|| (message?.type === 'notice' && !message.nativeStep)) {
|
|
167
217
|
if (this._activeReasoning && this.lastReasoning) {
|
|
168
|
-
super.onAgentReasoning({
|
|
218
|
+
super.onAgentReasoning({
|
|
219
|
+
content: this.lastReasoning,
|
|
220
|
+
streaming: false,
|
|
221
|
+
activity: this.currentActivity
|
|
222
|
+
});
|
|
169
223
|
}
|
|
170
224
|
this._activeReasoning = false;
|
|
171
225
|
this.lastReasoning = '';
|
package/src/tui/prompt.js
CHANGED
|
@@ -667,9 +667,9 @@ export class ChatPrompt {
|
|
|
667
667
|
if (this.surface?.homeInfo) this.surface.leaveHome();
|
|
668
668
|
if (this.renderer?.renderUserMessage) this.renderer.renderUserMessage(text);
|
|
669
669
|
else this.commit('user', (width) => {
|
|
670
|
-
const blockWidth = Math.max(8, width
|
|
670
|
+
const blockWidth = Math.max(8, width);
|
|
671
671
|
return barBlock(
|
|
672
|
-
wrapBlock(safeDisplay(text), Math.max(8, blockWidth - visibleWidth(GLYPHS.bar) - GUTTER)),
|
|
672
|
+
wrapBlock(safeDisplay(text), Math.max(8, blockWidth - visibleWidth(GLYPHS.barHeavy || GLYPHS.bar) - GUTTER)),
|
|
673
673
|
{ width: blockWidth, role: 'user', filled: true, surface: 'surfaceHi' }
|
|
674
674
|
);
|
|
675
675
|
});
|
|
@@ -1389,7 +1389,7 @@ export class ChatPrompt {
|
|
|
1389
1389
|
role: this.busy ? 'accent' : 'user',
|
|
1390
1390
|
filled: true,
|
|
1391
1391
|
surface: 'surface',
|
|
1392
|
-
punctuate:
|
|
1392
|
+
punctuate: false
|
|
1393
1393
|
});
|
|
1394
1394
|
|
|
1395
1395
|
const planRows = this.planRows(width);
|
|
@@ -1414,8 +1414,11 @@ export class ChatPrompt {
|
|
|
1414
1414
|
if (this.pickerLayout) this.pickerLayout.totalPromptRows = all.length;
|
|
1415
1415
|
|
|
1416
1416
|
// Park the cursor where the user is typing, not at the end of the picker.
|
|
1417
|
+
const availableWidth = this.surface?.composeAvailableWidth
|
|
1418
|
+
? this.surface.composeAvailableWidth()
|
|
1419
|
+
: sessionMainWidth(this.surface?.width || terminalWidth());
|
|
1417
1420
|
const positioned = this.surface
|
|
1418
|
-
? (this.surface.homeInfo ? centerRows(all, this.surface.width) : sessionRows(all,
|
|
1421
|
+
? (this.surface.homeInfo ? centerRows(all, this.surface.width) : sessionRows(all, availableWidth))
|
|
1419
1422
|
: { rows: all, inset: 0 };
|
|
1420
1423
|
this.present(positioned.rows, planRows.length + caretRow + padTop, layout.cursorCol + inset + positioned.inset);
|
|
1421
1424
|
}
|
package/src/tui/stageSurface.js
CHANGED
|
@@ -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, resolveActiveTurnIndex } from './turnRail.js';
|
|
37
|
+
import { hasSessionTurns, 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.
|
|
@@ -199,11 +199,25 @@ export class StageSurface {
|
|
|
199
199
|
return this.stage.width();
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
+
composeAvailableWidth() {
|
|
203
|
+
if (this.homeInfo) return this.width;
|
|
204
|
+
const mainWidth = sessionMainWidth(this.width);
|
|
205
|
+
const rail = this.railEnabled(mainWidth);
|
|
206
|
+
const hasTurns = hasSessionTurns(this.transcript);
|
|
207
|
+
const turnRailBudget = (rail && hasTurns) ? 3 : 0;
|
|
208
|
+
return rail ? Math.max(20, mainWidth - RAIL_BUDGET - turnRailBudget) : mainWidth;
|
|
209
|
+
}
|
|
210
|
+
|
|
202
211
|
/** Home is compact; a session uses its full conversation column. */
|
|
203
212
|
composeWidth() {
|
|
204
|
-
return this.
|
|
205
|
-
|
|
206
|
-
|
|
213
|
+
if (this.homeInfo) return composerWidth(this.width);
|
|
214
|
+
const mainWidth = sessionMainWidth(this.width);
|
|
215
|
+
const rail = this.railEnabled(mainWidth);
|
|
216
|
+
const hasTurns = hasSessionTurns(this.transcript);
|
|
217
|
+
if (!hasTurns) return sessionComposerWidth(mainWidth);
|
|
218
|
+
const turnRailBudget = rail ? 3 : 0;
|
|
219
|
+
const contentWidth = rail ? Math.max(20, mainWidth - RAIL_BUDGET - turnRailBudget) : mainWidth;
|
|
220
|
+
return sessionComposerWidth(contentWidth);
|
|
207
221
|
}
|
|
208
222
|
|
|
209
223
|
/** Keep Home distinct from a selected or newly started conversation. */
|
|
@@ -395,12 +409,19 @@ export class StageSurface {
|
|
|
395
409
|
const sidebar = sidebarVisible(width);
|
|
396
410
|
const mainWidth = sessionMainWidth(width);
|
|
397
411
|
const rail = this.railEnabled(mainWidth);
|
|
398
|
-
const hasTurns =
|
|
412
|
+
const hasTurns = hasSessionTurns(this.transcript);
|
|
399
413
|
const turnRailBudget = (rail && hasTurns) ? 3 : 0;
|
|
400
414
|
const contentWidth = rail ? Math.max(20, mainWidth - RAIL_BUDGET - turnRailBudget) : mainWidth;
|
|
401
415
|
|
|
402
416
|
let block = promptRows;
|
|
403
417
|
let caretRow = caret && Number.isFinite(caret.row) ? caret.row : Math.max(0, block.length - 1);
|
|
418
|
+
let caretCol = caret ? caret.col : 0;
|
|
419
|
+
|
|
420
|
+
if (turnRailBudget > 0) {
|
|
421
|
+
const railGutter = ' '.repeat(turnRailBudget);
|
|
422
|
+
block = block.map(row => (row ? railGutter + row : row));
|
|
423
|
+
caretCol += turnRailBudget;
|
|
424
|
+
}
|
|
404
425
|
|
|
405
426
|
// Grow the band to what there is to show, before deciding anything else.
|
|
406
427
|
//
|
|
@@ -485,7 +506,7 @@ export class StageSurface {
|
|
|
485
506
|
const painted = sidebar ? joinSessionSidebar(mainRows, panelRows, mainWidth) : mainRows;
|
|
486
507
|
return this.stage.paint(painted, {
|
|
487
508
|
row: rows.length + caretRow,
|
|
488
|
-
col:
|
|
509
|
+
col: caretCol
|
|
489
510
|
});
|
|
490
511
|
}
|
|
491
512
|
|
package/src/tui/theme.js
CHANGED
|
@@ -250,10 +250,9 @@ export const GLYPHS = HAS_UNICODE
|
|
|
250
250
|
arrow: '▸', check: '✓', cross: '✕', dot: '·', bullet: '•',
|
|
251
251
|
spinner: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'],
|
|
252
252
|
hLine: '─', vLine: '│', corner: '└', tee: '├', ellipsis: '…',
|
|
253
|
-
// The left accent bar of a block.
|
|
254
|
-
//
|
|
255
|
-
|
|
256
|
-
bar: '▌', step: '▪',
|
|
253
|
+
// The left accent bar of a block. Uses box-drawing heavy vertical ('┃')
|
|
254
|
+
// so it joins seamlessly from row to row without font line-height leading gaps.
|
|
255
|
+
bar: '┃', step: '▪',
|
|
257
256
|
// The permission marker. opencode shows a warning triangle and NO risk
|
|
258
257
|
// word — the level is internal plumbing, and printing 'DANGEROUS' at
|
|
259
258
|
// someone just makes them numb to it. Colour still carries the tier.
|
package/src/tui/thinkingBox.js
CHANGED
|
@@ -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',
|
|
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(
|
|
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
|
|
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
|
|
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
|
|
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) {
|
package/src/tui/thinkingBox.ts
CHANGED
|
@@ -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',
|
|
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(
|
|
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
|
|
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
|
|
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
|
|
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];
|
package/src/tui/turnRail.js
CHANGED
|
@@ -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
|
*/
|
package/src/tui/turnRail.ts
CHANGED
|
@@ -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
|
*/
|
package/src/tui/block.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export function panel(rows: string[], options?: { width?: number; title?: string; role?: string }): string[];
|