@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.
- 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 +73 -5
- package/src/tui/codeStreamRenderer.ts +80 -6
- package/src/tui/prompt.js +9 -6
- package/src/tui/scrollInteraction.js +93 -5
- package/src/tui/scrollInteraction.ts +113 -5
- 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/viewport.js +6 -0
- package/src/tui/viewport.ts +7 -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;
|