@sofer_agent/cli 0.3.7 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/tui.d.ts +2 -4
- package/dist/tui.d.ts.map +1 -1
- package/dist/tui.js +112 -143
- package/dist/tui.js.map +1 -1
- package/package.json +1 -1
- package/src/tui.ts +121 -164
package/dist/tui.d.ts
CHANGED
|
@@ -16,7 +16,8 @@ export declare class SoferTui {
|
|
|
16
16
|
private columns;
|
|
17
17
|
private rows;
|
|
18
18
|
private chatW;
|
|
19
|
-
private
|
|
19
|
+
private sideW;
|
|
20
|
+
private bodyH;
|
|
20
21
|
private scrollOff;
|
|
21
22
|
private status;
|
|
22
23
|
private spinnerFrame;
|
|
@@ -32,7 +33,6 @@ export declare class SoferTui {
|
|
|
32
33
|
setInfo(info: Partial<TuiInfo>): void;
|
|
33
34
|
private startSpinner;
|
|
34
35
|
private stopSpinner;
|
|
35
|
-
/** Start the interactive TUI loop. */
|
|
36
36
|
run(onLine: (line: string, signal?: AbortSignal) => Promise<void>): Promise<void>;
|
|
37
37
|
private shutdown;
|
|
38
38
|
private handleInput;
|
|
@@ -42,8 +42,6 @@ export declare class SoferTui {
|
|
|
42
42
|
private buildFrame;
|
|
43
43
|
private wrapMessage;
|
|
44
44
|
private roleLabel;
|
|
45
|
-
private pad;
|
|
46
|
-
private sidebarRow;
|
|
47
45
|
private buildSidebar;
|
|
48
46
|
}
|
|
49
47
|
//# sourceMappingURL=tui.d.ts.map
|
package/dist/tui.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tui.d.ts","sourceRoot":"","sources":["../src/tui.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"tui.d.ts","sourceRoot":"","sources":["../src/tui.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,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AE,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAWvF,OAAO,CAAC,QAAQ;IAahB,OAAO,CAAC,WAAW,CA6BjB;YAEY,MAAM;IAmBpB,OAAO,CAAC,YAAY,CAAkD;IAEtE,MAAM,IAAI,IAAI;IAKd,OAAO,CAAC,UAAU;IAqElB,OAAO,CAAC,WAAW;IASnB,OAAO,CAAC,SAAS;IAWjB,OAAO,CAAC,YAAY;CAyBrB"}
|
package/dist/tui.js
CHANGED
|
@@ -1,20 +1,27 @@
|
|
|
1
|
-
const SIDEBAR_W =
|
|
2
|
-
const MIN_CHAT_W =
|
|
1
|
+
const SIDEBAR_W = 28;
|
|
2
|
+
const MIN_CHAT_W = 34;
|
|
3
3
|
const GUTTER = " ";
|
|
4
4
|
const LABEL_W = 6;
|
|
5
5
|
const INDENT = `${GUTTER}${" ".repeat(LABEL_W + 1)}`;
|
|
6
6
|
const SPINNER_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
7
7
|
const SPINNER_MS = 80;
|
|
8
|
+
// Box-drawing: ╭ ─ ╮ │ ╰ ╯ ├ ┤ ┬ ┴ ┼
|
|
9
|
+
const B = {
|
|
10
|
+
tl: "╭", tr: "╮", bl: "╰", br: "╯",
|
|
11
|
+
h: "─", v: "│",
|
|
12
|
+
lt: "├", rt: "┤", tt: "┬", bt: "┴",
|
|
13
|
+
};
|
|
8
14
|
export class SoferTui {
|
|
9
15
|
agent;
|
|
10
16
|
config;
|
|
11
17
|
state = [];
|
|
12
18
|
inputBuf = "";
|
|
13
19
|
cursor = 0;
|
|
14
|
-
columns =
|
|
15
|
-
rows =
|
|
16
|
-
chatW =
|
|
17
|
-
|
|
20
|
+
columns = 90;
|
|
21
|
+
rows = 28;
|
|
22
|
+
chatW = 58;
|
|
23
|
+
sideW = 26;
|
|
24
|
+
bodyH = 22;
|
|
18
25
|
scrollOff = 0;
|
|
19
26
|
// spinner
|
|
20
27
|
status = "idle";
|
|
@@ -23,7 +30,7 @@ export class SoferTui {
|
|
|
23
30
|
turnStartedAt = 0;
|
|
24
31
|
// interrupt
|
|
25
32
|
abortCtrl = null;
|
|
26
|
-
// sidebar
|
|
33
|
+
// sidebar
|
|
27
34
|
info = { lastTurnIn: 0, lastTurnOut: 0 };
|
|
28
35
|
// callbacks
|
|
29
36
|
resolve = null;
|
|
@@ -33,10 +40,11 @@ export class SoferTui {
|
|
|
33
40
|
this.config = config;
|
|
34
41
|
}
|
|
35
42
|
measure() {
|
|
36
|
-
this.columns = process.stdout.columns ?? 80;
|
|
37
|
-
this.rows = process.stdout.rows ?? 24;
|
|
38
|
-
this.chatW = Math.max(MIN_CHAT_W, this.columns - SIDEBAR_W -
|
|
39
|
-
this.
|
|
43
|
+
this.columns = Math.max(80, process.stdout.columns ?? 80);
|
|
44
|
+
this.rows = Math.max(24, process.stdout.rows ?? 24);
|
|
45
|
+
this.chatW = Math.max(MIN_CHAT_W, this.columns - SIDEBAR_W - 3);
|
|
46
|
+
this.sideW = this.columns - this.chatW - 3;
|
|
47
|
+
this.bodyH = this.rows - 5; // top border, input box(3), footer(1)
|
|
40
48
|
}
|
|
41
49
|
addMessage(role, text) {
|
|
42
50
|
this.state.push({ role, text });
|
|
@@ -63,7 +71,6 @@ export class SoferTui {
|
|
|
63
71
|
this.spinnerTimer = null;
|
|
64
72
|
}
|
|
65
73
|
}
|
|
66
|
-
/** Start the interactive TUI loop. */
|
|
67
74
|
async run(onLine) {
|
|
68
75
|
this.onLine = onLine;
|
|
69
76
|
this.measure();
|
|
@@ -73,9 +80,7 @@ export class SoferTui {
|
|
|
73
80
|
process.stdout.on("resize", this.handleResize);
|
|
74
81
|
process.on("SIGWINCH", this.handleResize);
|
|
75
82
|
this.render();
|
|
76
|
-
return new Promise((resolve) => {
|
|
77
|
-
this.resolve = resolve;
|
|
78
|
-
});
|
|
83
|
+
return new Promise((resolve) => { this.resolve = resolve; });
|
|
79
84
|
}
|
|
80
85
|
shutdown() {
|
|
81
86
|
this.stopSpinner();
|
|
@@ -95,33 +100,30 @@ export class SoferTui {
|
|
|
95
100
|
if (code === 3) {
|
|
96
101
|
this.shutdown();
|
|
97
102
|
return;
|
|
98
|
-
}
|
|
103
|
+
}
|
|
99
104
|
if (code === 4 && this.inputBuf.length === 0) {
|
|
100
105
|
this.shutdown();
|
|
101
106
|
return;
|
|
102
|
-
}
|
|
107
|
+
}
|
|
103
108
|
if (code === 27) {
|
|
104
|
-
// Escape
|
|
105
109
|
if (this.status === "thinking" && this.abortCtrl) {
|
|
106
110
|
this.abortCtrl.abort();
|
|
107
111
|
return;
|
|
108
112
|
}
|
|
109
|
-
this.inputBuf = "";
|
|
113
|
+
this.inputBuf = "";
|
|
110
114
|
this.cursor = 0;
|
|
111
115
|
this.render();
|
|
112
116
|
return;
|
|
113
117
|
}
|
|
114
118
|
if (this.status === "thinking")
|
|
115
|
-
continue;
|
|
119
|
+
continue;
|
|
116
120
|
if (code === 13) {
|
|
117
121
|
this.submit();
|
|
118
122
|
return;
|
|
119
|
-
}
|
|
123
|
+
}
|
|
120
124
|
if (code === 127) {
|
|
121
|
-
// Backspace
|
|
122
125
|
if (this.cursor > 0) {
|
|
123
|
-
this.inputBuf =
|
|
124
|
-
this.inputBuf.slice(0, this.cursor - 1) + this.inputBuf.slice(this.cursor);
|
|
126
|
+
this.inputBuf = this.inputBuf.slice(0, this.cursor - 1) + this.inputBuf.slice(this.cursor);
|
|
125
127
|
this.cursor--;
|
|
126
128
|
}
|
|
127
129
|
this.render();
|
|
@@ -157,140 +159,106 @@ export class SoferTui {
|
|
|
157
159
|
this.render();
|
|
158
160
|
}
|
|
159
161
|
// ── Rendering ───────────────────────────────────────────────────────────
|
|
160
|
-
handleResize = () => {
|
|
161
|
-
this.measure();
|
|
162
|
-
this.render();
|
|
163
|
-
};
|
|
162
|
+
handleResize = () => { this.measure(); this.render(); };
|
|
164
163
|
render() {
|
|
165
164
|
this.measure();
|
|
166
|
-
|
|
167
|
-
out.write("\x1b[?25l");
|
|
168
|
-
out.write("\x1b[H");
|
|
169
|
-
out.write(this.buildFrame());
|
|
170
|
-
out.write("\x1b[?25h");
|
|
165
|
+
process.stdout.write("\x1b[?25l\x1b[H" + this.buildFrame() + "\x1b[?25h");
|
|
171
166
|
}
|
|
172
167
|
buildFrame() {
|
|
173
|
-
const { chatW,
|
|
174
|
-
const
|
|
168
|
+
const { columns, chatW, sideW, bodyH } = this;
|
|
169
|
+
const innerSideW = sideW - 2;
|
|
170
|
+
const sep = `${B.lt}${B.h.repeat(chatW)}${B.bt}${B.h.repeat(sideW)}${B.rt}`;
|
|
171
|
+
const inputW = columns - 2; // inside border
|
|
175
172
|
let buf = "";
|
|
176
|
-
// ──
|
|
173
|
+
// ── Top border ────────────────────────────────────────────────────────
|
|
174
|
+
buf += `${B.tl}${B.h.repeat(chatW)}${B.tt}${B.h.repeat(sideW)}${B.tr}\n`;
|
|
175
|
+
// ── Body ──────────────────────────────────────────────────────────────
|
|
177
176
|
const wrapped = this.state.flatMap((m) => this.wrapMessage(m, chatW));
|
|
178
|
-
const maxScroll = Math.max(0, wrapped.length -
|
|
177
|
+
const maxScroll = Math.max(0, wrapped.length - bodyH);
|
|
179
178
|
if (this.scrollOff > maxScroll)
|
|
180
179
|
this.scrollOff = maxScroll;
|
|
181
180
|
if (this.scrollOff < 0)
|
|
182
181
|
this.scrollOff = 0;
|
|
183
|
-
const visible = wrapped.slice(this.scrollOff, this.scrollOff +
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
else
|
|
195
|
-
buf += "│";
|
|
196
|
-
buf += this.sidebarRow(r, chatH, rightW);
|
|
197
|
-
buf += "\n";
|
|
182
|
+
const visible = wrapped.slice(this.scrollOff, this.scrollOff + bodyH);
|
|
183
|
+
const sidebarLines = this.buildSidebar(innerSideW);
|
|
184
|
+
const sbTop = Math.max(0, Math.floor((bodyH - sidebarLines.length) / 2));
|
|
185
|
+
for (let r = 0; r < bodyH; r++) {
|
|
186
|
+
buf += B.v;
|
|
187
|
+
buf += visible[r] ? padTrunc(visible[r], chatW) : " ".repeat(chatW);
|
|
188
|
+
buf += B.v;
|
|
189
|
+
const sbIdx = r - sbTop;
|
|
190
|
+
const sbLine = (sbIdx >= 0 && sbIdx < sidebarLines.length) ? sidebarLines[sbIdx] : "";
|
|
191
|
+
buf += ` ${padRight(sbLine, innerSideW)} `;
|
|
192
|
+
buf += `${B.v}\n`;
|
|
198
193
|
}
|
|
199
|
-
// ──
|
|
200
|
-
buf += `${
|
|
194
|
+
// ── Separator ─────────────────────────────────────────────────────────
|
|
195
|
+
buf += `${sep}\n`;
|
|
201
196
|
// ── Spinner row ───────────────────────────────────────────────────────
|
|
202
197
|
if (this.status === "thinking") {
|
|
203
198
|
const frame = SPINNER_FRAMES[this.spinnerFrame];
|
|
204
199
|
const elapsed = this.turnStartedAt ? formatElapsed(Date.now() - this.turnStartedAt) : "";
|
|
205
|
-
buf +=
|
|
200
|
+
buf += `${B.v} \x1b[36m${frame} thinking…${elapsed ? ` ${elapsed}` : ""} (esc to interrupt)\x1b[0m${" ".repeat(Math.max(0, inputW - 28 - elapsed.length))}${B.v}\n`;
|
|
206
201
|
}
|
|
207
|
-
// ── Input bar
|
|
208
|
-
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
202
|
+
// ── Input bar (bordered box) ─────────────────────────────────────────
|
|
203
|
+
buf += `${B.tl}${B.h.repeat(inputW)}${B.tr}\n`;
|
|
204
|
+
const cursorCh = this.status === "idle" ? "\x1b[5m▋\x1b[25m" : "";
|
|
205
|
+
const inputMaxW = inputW - 3; // "> " prefix + 1 padding
|
|
206
|
+
const visibleInput = this.inputBuf.length > inputMaxW
|
|
207
|
+
? this.inputBuf.slice(this.inputBuf.length - inputMaxW)
|
|
208
|
+
: this.inputBuf;
|
|
209
|
+
const inputPad = inputMaxW - visibleInput.length;
|
|
210
|
+
buf += `${B.v} \x1b[36m>\x1b[0m ${visibleInput}${cursorCh}${" ".repeat(Math.max(0, inputPad))} ${B.v}\n`;
|
|
211
|
+
buf += `${B.bl}${B.h.repeat(inputW)}${B.br}\n`;
|
|
212
|
+
// ── Footer ────────────────────────────────────────────────────────────
|
|
212
213
|
const totalIn = this.agent.usage.tokens.inputTokens;
|
|
213
214
|
const totalOut = this.agent.usage.tokens.outputTokens;
|
|
214
215
|
const cost = this.agent.usage.costUsd.toFixed(4);
|
|
215
|
-
const
|
|
216
|
-
buf +=
|
|
217
|
-
//
|
|
218
|
-
const
|
|
219
|
-
|
|
216
|
+
const ft = `\x1b[90m${this.agent.address.slice(0, 10)}… · in ${totalIn} out ${totalOut} $${cost} /exit\x1b[0m`;
|
|
217
|
+
buf += `${padTrunc(ft, columns)}\n`;
|
|
218
|
+
// ── Cursor position ───────────────────────────────────────────────────
|
|
219
|
+
const cursorRow = bodyH + 1 + (this.status === "thinking" ? 1 : 0) + 1; // body + sep + spinner? + input
|
|
220
|
+
const cursorCol = 4 + Math.min(this.cursor, inputMaxW);
|
|
221
|
+
buf += `\x1b[${cursorRow};${cursorCol}H`;
|
|
220
222
|
return buf;
|
|
221
223
|
}
|
|
222
|
-
// ──
|
|
224
|
+
// ── Messages ────────────────────────────────────────────────────────────
|
|
223
225
|
wrapMessage(msg, width) {
|
|
224
226
|
const label = this.roleLabel(msg.role);
|
|
225
|
-
const bodyWidth = width - GUTTER.length - LABEL_W - 1;
|
|
227
|
+
const bodyWidth = Math.max(10, width - GUTTER.length - LABEL_W - 1);
|
|
226
228
|
const lines = wrapText(msg.text, bodyWidth);
|
|
227
|
-
return lines.map((l, i) => {
|
|
228
|
-
if (i === 0)
|
|
229
|
-
return `${GUTTER}${label} ${l}`;
|
|
230
|
-
return `${INDENT}${l}`;
|
|
231
|
-
});
|
|
229
|
+
return lines.map((l, i) => i === 0 ? `${GUTTER}${label} ${l}` : `${INDENT}${l}`);
|
|
232
230
|
}
|
|
233
231
|
roleLabel(role) {
|
|
234
232
|
switch (role) {
|
|
235
|
-
case "you":
|
|
236
|
-
|
|
237
|
-
case "
|
|
238
|
-
|
|
239
|
-
case "system":
|
|
240
|
-
return "\x1b[90msys \x1b[0m";
|
|
241
|
-
case "error":
|
|
242
|
-
return "\x1b[31merr \x1b[0m";
|
|
233
|
+
case "you": return "\x1b[36myou \x1b[0m";
|
|
234
|
+
case "agent": return `\x1b[32m${this.agent.name.toLowerCase().padEnd(LABEL_W)}\x1b[0m`;
|
|
235
|
+
case "system": return "\x1b[90msys \x1b[0m";
|
|
236
|
+
case "error": return "\x1b[31merr \x1b[0m";
|
|
243
237
|
}
|
|
244
238
|
}
|
|
245
|
-
pad(s, w) {
|
|
246
|
-
const stripped = stripAnsi(s);
|
|
247
|
-
const padW = Math.max(0, w - visibleLen(stripped));
|
|
248
|
-
return s + " ".repeat(padW);
|
|
249
|
-
}
|
|
250
239
|
// ── Sidebar ─────────────────────────────────────────────────────────────
|
|
251
|
-
sidebarRow(row, total, width) {
|
|
252
|
-
const innerW = width - 2;
|
|
253
|
-
const lines = this.buildSidebar(innerW);
|
|
254
|
-
const gap = Math.max(0, total - lines.length);
|
|
255
|
-
const topPad = Math.floor(gap / 2);
|
|
256
|
-
const idx = row - topPad;
|
|
257
|
-
if (idx < 0 || idx >= lines.length)
|
|
258
|
-
return " ".repeat(width);
|
|
259
|
-
const line = lines[idx];
|
|
260
|
-
if (!line)
|
|
261
|
-
return " ".repeat(width);
|
|
262
|
-
const padded = padRight(line, innerW);
|
|
263
|
-
return ` ${padded} `;
|
|
264
|
-
}
|
|
265
240
|
buildSidebar(width) {
|
|
266
241
|
const { agent, config, info } = this;
|
|
267
242
|
const addr = `${agent.address.slice(0, 6)}…${agent.address.slice(-4)}`;
|
|
268
|
-
const hbar = "─".repeat(width);
|
|
269
|
-
const thinBar = "·".repeat(width);
|
|
270
243
|
const totalIn = agent.usage.tokens.inputTokens;
|
|
271
244
|
const totalOut = agent.usage.tokens.outputTokens;
|
|
272
|
-
const cost = agent.usage.costUsd.toFixed(
|
|
245
|
+
const cost = agent.usage.costUsd.toFixed(6);
|
|
273
246
|
return [
|
|
274
|
-
hbar,
|
|
275
247
|
`\x1b[1;36m${agent.name}\x1b[0m`,
|
|
276
248
|
`\x1b[90m${addr}\x1b[0m`,
|
|
277
249
|
"",
|
|
250
|
+
`${B.h.repeat(width)}`,
|
|
278
251
|
`\x1b[90mnetwork\x1b[0m ${config.network}`,
|
|
279
252
|
`\x1b[90mmodel\x1b[0m ${shortModel(config.brain.model)}`,
|
|
280
|
-
|
|
281
|
-
`\x1b[
|
|
282
|
-
`
|
|
283
|
-
`
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
`
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
`\x1b[90maddress\x1b[0m`,
|
|
290
|
-
` ${agent.address.slice(0, 16)}`,
|
|
291
|
-
` ${agent.address.slice(16, 32)}`,
|
|
292
|
-
` ${agent.address.slice(32)}`,
|
|
293
|
-
hbar,
|
|
253
|
+
"",
|
|
254
|
+
`\x1b[90m▸ last turn\x1b[0m`,
|
|
255
|
+
` in ${info.lastTurnIn}`,
|
|
256
|
+
` out ${info.lastTurnOut}`,
|
|
257
|
+
"",
|
|
258
|
+
`\x1b[90m▸ total\x1b[0m`,
|
|
259
|
+
` in ${totalIn}`,
|
|
260
|
+
` out ${totalOut}`,
|
|
261
|
+
` \x1b[33m$${cost}\x1b[0m`,
|
|
294
262
|
];
|
|
295
263
|
}
|
|
296
264
|
}
|
|
@@ -300,18 +268,17 @@ function wrapText(text, width) {
|
|
|
300
268
|
return [""];
|
|
301
269
|
const lines = [];
|
|
302
270
|
const words = text.split(" ");
|
|
303
|
-
let
|
|
304
|
-
for (const
|
|
305
|
-
if (
|
|
306
|
-
lines.push(
|
|
307
|
-
|
|
308
|
-
}
|
|
309
|
-
else {
|
|
310
|
-
current = current ? `${current} ${word}` : word;
|
|
271
|
+
let cur = "";
|
|
272
|
+
for (const w of words) {
|
|
273
|
+
if (cur && cur.length + 1 + w.length > width) {
|
|
274
|
+
lines.push(cur);
|
|
275
|
+
cur = w;
|
|
311
276
|
}
|
|
277
|
+
else
|
|
278
|
+
cur = cur ? `${cur} ${w}` : w;
|
|
312
279
|
}
|
|
313
|
-
if (
|
|
314
|
-
lines.push(
|
|
280
|
+
if (cur)
|
|
281
|
+
lines.push(cur);
|
|
315
282
|
return lines.length > 0 ? lines : [""];
|
|
316
283
|
}
|
|
317
284
|
function stripAnsi(s) {
|
|
@@ -320,31 +287,33 @@ function stripAnsi(s) {
|
|
|
320
287
|
}
|
|
321
288
|
function visibleLen(s) {
|
|
322
289
|
// biome-ignore lint/suspicious/noControlCharactersInRegex: ANSI escape stripping
|
|
323
|
-
const
|
|
290
|
+
const re = /\x1b\[\d*;?\d*m/g;
|
|
324
291
|
let len = 0;
|
|
325
|
-
let
|
|
326
|
-
let
|
|
327
|
-
while (
|
|
328
|
-
len +=
|
|
329
|
-
|
|
330
|
-
|
|
292
|
+
let last = 0;
|
|
293
|
+
let m = re.exec(s);
|
|
294
|
+
while (m !== null) {
|
|
295
|
+
len += m.index - last;
|
|
296
|
+
last = m.index + m[0].length;
|
|
297
|
+
m = re.exec(s);
|
|
331
298
|
}
|
|
332
|
-
len
|
|
333
|
-
|
|
299
|
+
return len + s.length - last;
|
|
300
|
+
}
|
|
301
|
+
function padRight(s, w) {
|
|
302
|
+
const vl = visibleLen(s);
|
|
303
|
+
return vl >= w ? s : s + " ".repeat(w - vl);
|
|
334
304
|
}
|
|
335
|
-
function
|
|
336
|
-
const
|
|
337
|
-
if (
|
|
338
|
-
return s;
|
|
339
|
-
return
|
|
305
|
+
function padTrunc(s, w) {
|
|
306
|
+
const stripped = stripAnsi(s);
|
|
307
|
+
if (stripped.length <= w)
|
|
308
|
+
return s + " ".repeat(w - stripped.length);
|
|
309
|
+
return stripped.slice(0, w);
|
|
340
310
|
}
|
|
341
311
|
function formatElapsed(ms) {
|
|
342
312
|
const sec = Math.floor(ms / 1000);
|
|
343
313
|
if (sec < 60)
|
|
344
314
|
return `${sec}s`;
|
|
345
315
|
const m = Math.floor(sec / 60);
|
|
346
|
-
|
|
347
|
-
return `${m}m${String(s).padStart(2, "0")}s`;
|
|
316
|
+
return `${m}m${String(sec % 60).padStart(2, "0")}s`;
|
|
348
317
|
}
|
|
349
318
|
function shortModel(model) {
|
|
350
319
|
const m = model.toLowerCase();
|
package/dist/tui.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tui.js","sourceRoot":"","sources":["../src/tui.ts"],"names":[],"mappings":"AAEA,MAAM,SAAS,GAAG,EAAE,CAAC;AACrB,MAAM,UAAU,GAAG,EAAE,CAAC;AACtB,MAAM,MAAM,GAAG,IAAI,CAAC;AACpB,MAAM,OAAO,GAAG,CAAC,CAAC;AAClB,MAAM,MAAM,GAAG,GAAG,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,OAAO,GAAG,CAAC,CAAC,EAAE,CAAC;AACrD,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAC1E,MAAM,UAAU,GAAG,EAAE,CAAC;AAYtB,MAAM,OAAO,QAAQ;IAuBA;IACA;IAvBX,KAAK,GAAe,EAAE,CAAC;IACvB,QAAQ,GAAG,EAAE,CAAC;IACd,MAAM,GAAG,CAAC,CAAC;IACX,OAAO,GAAG,EAAE,CAAC;IACb,IAAI,GAAG,EAAE,CAAC;IACV,KAAK,GAAG,EAAE,CAAC;IACX,KAAK,GAAG,EAAE,CAAC;IACX,SAAS,GAAG,CAAC,CAAC;IACtB,UAAU;IACF,MAAM,GAAwB,MAAM,CAAC;IACrC,YAAY,GAAG,CAAC,CAAC;IACjB,YAAY,GA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AE,CAAC,CAAC;IAC/B,OAAO,GAAG,CAAC,IAAI,MAAM,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC;AACtD,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,MAAM,CAAC,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;IAC9B,IAAI,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,OAAO,UAAU,CAAC;IAC5C,IAAI,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC;QAAE,OAAO,OAAO,CAAC;IACxC,IAAI,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,QAAQ,CAAC;IACxC,IAAI,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC;QAAE,OAAO,SAAS,CAAC;IAC1C,OAAO,KAAK,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC;AAC9D,CAAC"}
|
package/package.json
CHANGED
package/src/tui.ts
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import type { SoferAgent, SoferConfig } from "@sofer_agent/core";
|
|
2
2
|
|
|
3
|
-
const SIDEBAR_W =
|
|
4
|
-
const MIN_CHAT_W =
|
|
3
|
+
const SIDEBAR_W = 28;
|
|
4
|
+
const MIN_CHAT_W = 34;
|
|
5
5
|
const GUTTER = " ";
|
|
6
6
|
const LABEL_W = 6;
|
|
7
7
|
const INDENT = `${GUTTER}${" ".repeat(LABEL_W + 1)}`;
|
|
8
8
|
const SPINNER_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
9
9
|
const SPINNER_MS = 80;
|
|
10
10
|
|
|
11
|
+
// Box-drawing: ╭ ─ ╮ │ ╰ ╯ ├ ┤ ┬ ┴ ┼
|
|
12
|
+
const B = {
|
|
13
|
+
tl: "╭", tr: "╮", bl: "╰", br: "╯",
|
|
14
|
+
h: "─", v: "│",
|
|
15
|
+
lt: "├", rt: "┤", tt: "┬", bt: "┴",
|
|
16
|
+
};
|
|
17
|
+
|
|
11
18
|
export interface ChatLine {
|
|
12
19
|
role: "you" | "agent" | "system" | "error";
|
|
13
20
|
text: string;
|
|
@@ -22,10 +29,11 @@ export class SoferTui {
|
|
|
22
29
|
private state: ChatLine[] = [];
|
|
23
30
|
private inputBuf = "";
|
|
24
31
|
private cursor = 0;
|
|
25
|
-
private columns =
|
|
26
|
-
private rows =
|
|
27
|
-
private chatW =
|
|
28
|
-
private
|
|
32
|
+
private columns = 90;
|
|
33
|
+
private rows = 28;
|
|
34
|
+
private chatW = 58;
|
|
35
|
+
private sideW = 26;
|
|
36
|
+
private bodyH = 22;
|
|
29
37
|
private scrollOff = 0;
|
|
30
38
|
// spinner
|
|
31
39
|
private status: "idle" | "thinking" = "idle";
|
|
@@ -34,7 +42,7 @@ export class SoferTui {
|
|
|
34
42
|
private turnStartedAt = 0;
|
|
35
43
|
// interrupt
|
|
36
44
|
private abortCtrl: AbortController | null = null;
|
|
37
|
-
// sidebar
|
|
45
|
+
// sidebar
|
|
38
46
|
private info: TuiInfo = { lastTurnIn: 0, lastTurnOut: 0 };
|
|
39
47
|
// callbacks
|
|
40
48
|
private resolve: (() => void) | null = null;
|
|
@@ -46,10 +54,11 @@ export class SoferTui {
|
|
|
46
54
|
) {}
|
|
47
55
|
|
|
48
56
|
private measure(): void {
|
|
49
|
-
this.columns = process.stdout.columns ?? 80;
|
|
50
|
-
this.rows = process.stdout.rows ?? 24;
|
|
51
|
-
this.chatW = Math.max(MIN_CHAT_W, this.columns - SIDEBAR_W -
|
|
52
|
-
this.
|
|
57
|
+
this.columns = Math.max(80, process.stdout.columns ?? 80);
|
|
58
|
+
this.rows = Math.max(24, process.stdout.rows ?? 24);
|
|
59
|
+
this.chatW = Math.max(MIN_CHAT_W, this.columns - SIDEBAR_W - 3);
|
|
60
|
+
this.sideW = this.columns - this.chatW - 3;
|
|
61
|
+
this.bodyH = this.rows - 5; // top border, input box(3), footer(1)
|
|
53
62
|
}
|
|
54
63
|
|
|
55
64
|
addMessage(role: ChatLine["role"], text: string): void {
|
|
@@ -80,20 +89,15 @@ export class SoferTui {
|
|
|
80
89
|
}
|
|
81
90
|
}
|
|
82
91
|
|
|
83
|
-
/** Start the interactive TUI loop. */
|
|
84
92
|
async run(onLine: (line: string, signal?: AbortSignal) => Promise<void>): Promise<void> {
|
|
85
93
|
this.onLine = onLine;
|
|
86
94
|
this.measure();
|
|
87
|
-
|
|
88
95
|
if (process.stdin.isTTY) process.stdin.setRawMode?.(true);
|
|
89
96
|
process.stdin.on("data", this.handleInput);
|
|
90
97
|
process.stdout.on("resize", this.handleResize);
|
|
91
98
|
process.on("SIGWINCH", this.handleResize);
|
|
92
|
-
|
|
93
99
|
this.render();
|
|
94
|
-
return new Promise<void>((resolve) => {
|
|
95
|
-
this.resolve = resolve;
|
|
96
|
-
});
|
|
100
|
+
return new Promise<void>((resolve) => { this.resolve = resolve; });
|
|
97
101
|
}
|
|
98
102
|
|
|
99
103
|
private shutdown(): void {
|
|
@@ -113,35 +117,20 @@ export class SoferTui {
|
|
|
113
117
|
const str = data.toString();
|
|
114
118
|
for (const ch of str) {
|
|
115
119
|
const code = ch.charCodeAt(0);
|
|
116
|
-
if (code === 3) {
|
|
117
|
-
|
|
118
|
-
return;
|
|
119
|
-
} // Ctrl-C
|
|
120
|
-
if (code === 4 && this.inputBuf.length === 0) {
|
|
121
|
-
this.shutdown();
|
|
122
|
-
return;
|
|
123
|
-
} // Ctrl-D
|
|
120
|
+
if (code === 3) { this.shutdown(); return; }
|
|
121
|
+
if (code === 4 && this.inputBuf.length === 0) { this.shutdown(); return; }
|
|
124
122
|
if (code === 27) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
this.abortCtrl.abort();
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
this.inputBuf = ""; // clear input on Esc when idle
|
|
123
|
+
if (this.status === "thinking" && this.abortCtrl) { this.abortCtrl.abort(); return; }
|
|
124
|
+
this.inputBuf = "";
|
|
131
125
|
this.cursor = 0;
|
|
132
126
|
this.render();
|
|
133
127
|
return;
|
|
134
128
|
}
|
|
135
|
-
if (this.status === "thinking") continue;
|
|
136
|
-
if (code === 13) {
|
|
137
|
-
this.submit();
|
|
138
|
-
return;
|
|
139
|
-
} // Enter
|
|
129
|
+
if (this.status === "thinking") continue;
|
|
130
|
+
if (code === 13) { this.submit(); return; }
|
|
140
131
|
if (code === 127) {
|
|
141
|
-
// Backspace
|
|
142
132
|
if (this.cursor > 0) {
|
|
143
|
-
this.inputBuf =
|
|
144
|
-
this.inputBuf.slice(0, this.cursor - 1) + this.inputBuf.slice(this.cursor);
|
|
133
|
+
this.inputBuf = this.inputBuf.slice(0, this.cursor - 1) + this.inputBuf.slice(this.cursor);
|
|
145
134
|
this.cursor--;
|
|
146
135
|
}
|
|
147
136
|
this.render();
|
|
@@ -159,171 +148,140 @@ export class SoferTui {
|
|
|
159
148
|
const line = this.inputBuf.trim();
|
|
160
149
|
this.inputBuf = "";
|
|
161
150
|
this.cursor = 0;
|
|
162
|
-
if (!line) {
|
|
163
|
-
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
if (line === "/exit" || line === "/quit") {
|
|
167
|
-
this.shutdown();
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
|
|
151
|
+
if (!line) { this.render(); return; }
|
|
152
|
+
if (line === "/exit" || line === "/quit") { this.shutdown(); return; }
|
|
171
153
|
this.addMessage("you", line);
|
|
172
154
|
this.scrollOff = 0;
|
|
173
155
|
this.abortCtrl = new AbortController();
|
|
174
156
|
this.startSpinner();
|
|
175
157
|
this.render();
|
|
176
|
-
|
|
177
158
|
await this.onLine?.(line, this.abortCtrl.signal);
|
|
178
|
-
|
|
179
159
|
this.abortCtrl = null;
|
|
180
160
|
this.stopSpinner();
|
|
181
161
|
this.render();
|
|
182
162
|
}
|
|
183
163
|
|
|
184
164
|
// ── Rendering ───────────────────────────────────────────────────────────
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
this.render();
|
|
188
|
-
};
|
|
165
|
+
|
|
166
|
+
private handleResize = (): void => { this.measure(); this.render(); };
|
|
189
167
|
|
|
190
168
|
render(): void {
|
|
191
169
|
this.measure();
|
|
192
|
-
|
|
193
|
-
out.write("\x1b[?25l");
|
|
194
|
-
out.write("\x1b[H");
|
|
195
|
-
out.write(this.buildFrame());
|
|
196
|
-
out.write("\x1b[?25h");
|
|
170
|
+
process.stdout.write("\x1b[?25l\x1b[H" + this.buildFrame() + "\x1b[?25h");
|
|
197
171
|
}
|
|
198
172
|
|
|
199
173
|
private buildFrame(): string {
|
|
200
|
-
const { chatW,
|
|
201
|
-
const
|
|
174
|
+
const { columns, chatW, sideW, bodyH } = this;
|
|
175
|
+
const innerSideW = sideW - 2;
|
|
176
|
+
const sep = `${B.lt}${B.h.repeat(chatW)}${B.bt}${B.h.repeat(sideW)}${B.rt}`;
|
|
177
|
+
const inputW = columns - 2; // inside border
|
|
178
|
+
|
|
202
179
|
let buf = "";
|
|
203
180
|
|
|
204
|
-
// ──
|
|
181
|
+
// ── Top border ────────────────────────────────────────────────────────
|
|
182
|
+
buf += `${B.tl}${B.h.repeat(chatW)}${B.tt}${B.h.repeat(sideW)}${B.tr}\n`;
|
|
183
|
+
|
|
184
|
+
// ── Body ──────────────────────────────────────────────────────────────
|
|
205
185
|
const wrapped = this.state.flatMap((m) => this.wrapMessage(m, chatW));
|
|
206
|
-
const maxScroll = Math.max(0, wrapped.length -
|
|
186
|
+
const maxScroll = Math.max(0, wrapped.length - bodyH);
|
|
207
187
|
if (this.scrollOff > maxScroll) this.scrollOff = maxScroll;
|
|
208
188
|
if (this.scrollOff < 0) this.scrollOff = 0;
|
|
209
|
-
const visible = wrapped.slice(this.scrollOff, this.scrollOff +
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
189
|
+
const visible = wrapped.slice(this.scrollOff, this.scrollOff + bodyH);
|
|
190
|
+
|
|
191
|
+
const sidebarLines = this.buildSidebar(innerSideW);
|
|
192
|
+
const sbTop = Math.max(0, Math.floor((bodyH - sidebarLines.length) / 2));
|
|
193
|
+
|
|
194
|
+
for (let r = 0; r < bodyH; r++) {
|
|
195
|
+
buf += B.v;
|
|
196
|
+
buf += visible[r] ? padTrunc(visible[r]!, chatW) : " ".repeat(chatW);
|
|
197
|
+
buf += B.v;
|
|
198
|
+
const sbIdx = r - sbTop;
|
|
199
|
+
const sbLine = (sbIdx >= 0 && sbIdx < sidebarLines.length) ? sidebarLines[sbIdx]! : "";
|
|
200
|
+
buf += ` ${padRight(sbLine, innerSideW)} `;
|
|
201
|
+
buf += `${B.v}\n`;
|
|
220
202
|
}
|
|
221
203
|
|
|
222
|
-
// ──
|
|
223
|
-
buf += `${
|
|
204
|
+
// ── Separator ─────────────────────────────────────────────────────────
|
|
205
|
+
buf += `${sep}\n`;
|
|
224
206
|
|
|
225
207
|
// ── Spinner row ───────────────────────────────────────────────────────
|
|
226
208
|
if (this.status === "thinking") {
|
|
227
|
-
const frame = SPINNER_FRAMES[this.spinnerFrame]
|
|
209
|
+
const frame = SPINNER_FRAMES[this.spinnerFrame]!;
|
|
228
210
|
const elapsed = this.turnStartedAt ? formatElapsed(Date.now() - this.turnStartedAt) : "";
|
|
229
|
-
buf +=
|
|
211
|
+
buf += `${B.v} \x1b[36m${frame} thinking…${elapsed ? ` ${elapsed}` : ""} (esc to interrupt)\x1b[0m${" ".repeat(Math.max(0, inputW - 28 - elapsed.length))}${B.v}\n`;
|
|
230
212
|
}
|
|
231
213
|
|
|
232
|
-
// ── Input bar
|
|
233
|
-
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
214
|
+
// ── Input bar (bordered box) ─────────────────────────────────────────
|
|
215
|
+
buf += `${B.tl}${B.h.repeat(inputW)}${B.tr}\n`;
|
|
216
|
+
const cursorCh = this.status === "idle" ? "\x1b[5m▋\x1b[25m" : "";
|
|
217
|
+
const inputMaxW = inputW - 3; // "> " prefix + 1 padding
|
|
218
|
+
const visibleInput = this.inputBuf.length > inputMaxW
|
|
219
|
+
? this.inputBuf.slice(this.inputBuf.length - inputMaxW)
|
|
220
|
+
: this.inputBuf;
|
|
221
|
+
const inputPad = inputMaxW - visibleInput.length;
|
|
222
|
+
buf += `${B.v} \x1b[36m>\x1b[0m ${visibleInput}${cursorCh}${" ".repeat(Math.max(0, inputPad))} ${B.v}\n`;
|
|
223
|
+
buf += `${B.bl}${B.h.repeat(inputW)}${B.br}\n`;
|
|
224
|
+
|
|
225
|
+
// ── Footer ────────────────────────────────────────────────────────────
|
|
238
226
|
const totalIn = this.agent.usage.tokens.inputTokens;
|
|
239
227
|
const totalOut = this.agent.usage.tokens.outputTokens;
|
|
240
228
|
const cost = this.agent.usage.costUsd.toFixed(4);
|
|
241
|
-
const
|
|
242
|
-
buf +=
|
|
229
|
+
const ft = `\x1b[90m${this.agent.address.slice(0, 10)}… · in ${totalIn} out ${totalOut} $${cost} /exit\x1b[0m`;
|
|
230
|
+
buf += `${padTrunc(ft, columns)}\n`;
|
|
243
231
|
|
|
244
|
-
//
|
|
245
|
-
const
|
|
246
|
-
|
|
232
|
+
// ── Cursor position ───────────────────────────────────────────────────
|
|
233
|
+
const cursorRow = bodyH + 1 + (this.status === "thinking" ? 1 : 0) + 1; // body + sep + spinner? + input
|
|
234
|
+
const cursorCol = 4 + Math.min(this.cursor, inputMaxW);
|
|
235
|
+
buf += `\x1b[${cursorRow};${cursorCol}H`;
|
|
247
236
|
|
|
248
237
|
return buf;
|
|
249
238
|
}
|
|
250
239
|
|
|
251
|
-
// ──
|
|
240
|
+
// ── Messages ────────────────────────────────────────────────────────────
|
|
252
241
|
|
|
253
242
|
private wrapMessage(msg: ChatLine, width: number): string[] {
|
|
254
243
|
const label = this.roleLabel(msg.role);
|
|
255
|
-
const bodyWidth = width - GUTTER.length - LABEL_W - 1;
|
|
244
|
+
const bodyWidth = Math.max(10, width - GUTTER.length - LABEL_W - 1);
|
|
256
245
|
const lines = wrapText(msg.text, bodyWidth);
|
|
257
|
-
return lines.map((l, i) =>
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
});
|
|
246
|
+
return lines.map((l, i) =>
|
|
247
|
+
i === 0 ? `${GUTTER}${label} ${l}` : `${INDENT}${l}`,
|
|
248
|
+
);
|
|
261
249
|
}
|
|
262
250
|
|
|
263
251
|
private roleLabel(role: ChatLine["role"]): string {
|
|
264
252
|
switch (role) {
|
|
265
|
-
case "you":
|
|
266
|
-
|
|
267
|
-
case "
|
|
268
|
-
|
|
269
|
-
case "system":
|
|
270
|
-
return "\x1b[90msys \x1b[0m";
|
|
271
|
-
case "error":
|
|
272
|
-
return "\x1b[31merr \x1b[0m";
|
|
253
|
+
case "you": return "\x1b[36myou \x1b[0m";
|
|
254
|
+
case "agent": return `\x1b[32m${this.agent.name.toLowerCase().padEnd(LABEL_W)}\x1b[0m`;
|
|
255
|
+
case "system": return "\x1b[90msys \x1b[0m";
|
|
256
|
+
case "error": return "\x1b[31merr \x1b[0m";
|
|
273
257
|
}
|
|
274
258
|
}
|
|
275
259
|
|
|
276
|
-
private pad(s: string, w: number): string {
|
|
277
|
-
const stripped = stripAnsi(s);
|
|
278
|
-
const padW = Math.max(0, w - visibleLen(stripped));
|
|
279
|
-
return s + " ".repeat(padW);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
260
|
// ── Sidebar ─────────────────────────────────────────────────────────────
|
|
283
261
|
|
|
284
|
-
private sidebarRow(row: number, total: number, width: number): string {
|
|
285
|
-
const innerW = width - 2;
|
|
286
|
-
const lines = this.buildSidebar(innerW);
|
|
287
|
-
const gap = Math.max(0, total - lines.length);
|
|
288
|
-
const topPad = Math.floor(gap / 2);
|
|
289
|
-
const idx = row - topPad;
|
|
290
|
-
if (idx < 0 || idx >= lines.length) return " ".repeat(width);
|
|
291
|
-
const line = lines[idx];
|
|
292
|
-
if (!line) return " ".repeat(width);
|
|
293
|
-
const padded = padRight(line, innerW);
|
|
294
|
-
return ` ${padded} `;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
262
|
private buildSidebar(width: number): string[] {
|
|
298
263
|
const { agent, config, info } = this;
|
|
299
264
|
const addr = `${agent.address.slice(0, 6)}…${agent.address.slice(-4)}`;
|
|
300
|
-
const hbar = "─".repeat(width);
|
|
301
|
-
const thinBar = "·".repeat(width);
|
|
302
265
|
const totalIn = agent.usage.tokens.inputTokens;
|
|
303
266
|
const totalOut = agent.usage.tokens.outputTokens;
|
|
304
|
-
const cost = agent.usage.costUsd.toFixed(
|
|
267
|
+
const cost = agent.usage.costUsd.toFixed(6);
|
|
305
268
|
|
|
306
269
|
return [
|
|
307
|
-
hbar,
|
|
308
270
|
`\x1b[1;36m${agent.name}\x1b[0m`,
|
|
309
271
|
`\x1b[90m${addr}\x1b[0m`,
|
|
310
272
|
"",
|
|
273
|
+
`${B.h.repeat(width)}`,
|
|
311
274
|
`\x1b[90mnetwork\x1b[0m ${config.network}`,
|
|
312
275
|
`\x1b[90mmodel\x1b[0m ${shortModel(config.brain.model)}`,
|
|
313
|
-
|
|
314
|
-
`\x1b[
|
|
315
|
-
`
|
|
316
|
-
`
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
`
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
`\x1b[90maddress\x1b[0m`,
|
|
323
|
-
` ${agent.address.slice(0, 16)}`,
|
|
324
|
-
` ${agent.address.slice(16, 32)}`,
|
|
325
|
-
` ${agent.address.slice(32)}`,
|
|
326
|
-
hbar,
|
|
276
|
+
"",
|
|
277
|
+
`\x1b[90m▸ last turn\x1b[0m`,
|
|
278
|
+
` in ${info.lastTurnIn}`,
|
|
279
|
+
` out ${info.lastTurnOut}`,
|
|
280
|
+
"",
|
|
281
|
+
`\x1b[90m▸ total\x1b[0m`,
|
|
282
|
+
` in ${totalIn}`,
|
|
283
|
+
` out ${totalOut}`,
|
|
284
|
+
` \x1b[33m$${cost}\x1b[0m`,
|
|
327
285
|
];
|
|
328
286
|
}
|
|
329
287
|
}
|
|
@@ -334,16 +292,12 @@ function wrapText(text: string, width: number): string[] {
|
|
|
334
292
|
if (!text) return [""];
|
|
335
293
|
const lines: string[] = [];
|
|
336
294
|
const words = text.split(" ");
|
|
337
|
-
let
|
|
338
|
-
for (const
|
|
339
|
-
if (
|
|
340
|
-
|
|
341
|
-
current = word;
|
|
342
|
-
} else {
|
|
343
|
-
current = current ? `${current} ${word}` : word;
|
|
344
|
-
}
|
|
295
|
+
let cur = "";
|
|
296
|
+
for (const w of words) {
|
|
297
|
+
if (cur && cur.length + 1 + w.length > width) { lines.push(cur); cur = w; }
|
|
298
|
+
else cur = cur ? `${cur} ${w}` : w;
|
|
345
299
|
}
|
|
346
|
-
if (
|
|
300
|
+
if (cur) lines.push(cur);
|
|
347
301
|
return lines.length > 0 ? lines : [""];
|
|
348
302
|
}
|
|
349
303
|
|
|
@@ -354,31 +308,34 @@ function stripAnsi(s: string): string {
|
|
|
354
308
|
|
|
355
309
|
function visibleLen(s: string): number {
|
|
356
310
|
// biome-ignore lint/suspicious/noControlCharactersInRegex: ANSI escape stripping
|
|
357
|
-
const
|
|
311
|
+
const re = /\x1b\[\d*;?\d*m/g;
|
|
358
312
|
let len = 0;
|
|
359
|
-
let
|
|
360
|
-
let
|
|
361
|
-
while (
|
|
362
|
-
len +=
|
|
363
|
-
|
|
364
|
-
|
|
313
|
+
let last = 0;
|
|
314
|
+
let m = re.exec(s);
|
|
315
|
+
while (m !== null) {
|
|
316
|
+
len += m.index - last;
|
|
317
|
+
last = m.index + m[0].length;
|
|
318
|
+
m = re.exec(s);
|
|
365
319
|
}
|
|
366
|
-
len
|
|
367
|
-
|
|
320
|
+
return len + s.length - last;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function padRight(s: string, w: number): string {
|
|
324
|
+
const vl = visibleLen(s);
|
|
325
|
+
return vl >= w ? s : s + " ".repeat(w - vl);
|
|
368
326
|
}
|
|
369
327
|
|
|
370
|
-
function
|
|
371
|
-
const
|
|
372
|
-
if (
|
|
373
|
-
return
|
|
328
|
+
function padTrunc(s: string, w: number): string {
|
|
329
|
+
const stripped = stripAnsi(s);
|
|
330
|
+
if (stripped.length <= w) return s + " ".repeat(w - stripped.length);
|
|
331
|
+
return stripped.slice(0, w);
|
|
374
332
|
}
|
|
375
333
|
|
|
376
334
|
function formatElapsed(ms: number): string {
|
|
377
335
|
const sec = Math.floor(ms / 1000);
|
|
378
336
|
if (sec < 60) return `${sec}s`;
|
|
379
337
|
const m = Math.floor(sec / 60);
|
|
380
|
-
|
|
381
|
-
return `${m}m${String(s).padStart(2, "0")}s`;
|
|
338
|
+
return `${m}m${String(sec % 60).padStart(2, "0")}s`;
|
|
382
339
|
}
|
|
383
340
|
|
|
384
341
|
function shortModel(model: string): string {
|