@anusornneal/chat-relay 0.11.2 → 0.12.0
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/README.md +21 -2
- package/agent/capability-scheduler.mjs +3 -1
- package/agent/connection-state.mjs +19 -0
- package/agent/lifecycle.mjs +68 -4
- package/agent/local-agent.mjs +34 -10
- package/cli/config.mjs +45 -9
- package/cli/index.mjs +37 -5
- package/cli/relay-health.mjs +185 -0
- package/cli/remote.mjs +37 -5
- package/cli/secret-store.mjs +223 -0
- package/cli/self-update.mjs +88 -0
- package/cli/tui.mjs +289 -52
- package/package.json +8 -2
package/cli/tui.mjs
CHANGED
|
@@ -16,7 +16,7 @@ const LABEL_WIDTH = 12;
|
|
|
16
16
|
const GAP = 3;
|
|
17
17
|
const MIN_FRAME_WIDTH = 60;
|
|
18
18
|
const MAX_FRAME_WIDTH = 179;
|
|
19
|
-
const FRAME_FIXED_ROWS =
|
|
19
|
+
const FRAME_FIXED_ROWS = 12;
|
|
20
20
|
const FRAME_BOTTOM_MARGIN = 1;
|
|
21
21
|
|
|
22
22
|
function clamp(value, min, max) {
|
|
@@ -31,6 +31,60 @@ function truncate(value, width) {
|
|
|
31
31
|
return text.slice(0, width - 1) + "…";
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
function codePointCellWidth(codePoint) {
|
|
35
|
+
if (codePoint === 0) return 0;
|
|
36
|
+
if (codePoint < 32 || (codePoint >= 0x7f && codePoint < 0xa0)) return 0;
|
|
37
|
+
if (
|
|
38
|
+
(codePoint >= 0x0300 && codePoint <= 0x036f)
|
|
39
|
+
|| (codePoint >= 0x1ab0 && codePoint <= 0x1aff)
|
|
40
|
+
|| (codePoint >= 0x1dc0 && codePoint <= 0x1dff)
|
|
41
|
+
|| (codePoint >= 0x20d0 && codePoint <= 0x20ff)
|
|
42
|
+
|| (codePoint >= 0xfe20 && codePoint <= 0xfe2f)
|
|
43
|
+
|| codePoint === 0xfe0f
|
|
44
|
+
|| codePoint === 0x200d
|
|
45
|
+
) return 0;
|
|
46
|
+
if (
|
|
47
|
+
codePoint >= 0x1100 && (
|
|
48
|
+
codePoint <= 0x115f
|
|
49
|
+
|| codePoint === 0x2329
|
|
50
|
+
|| codePoint === 0x232a
|
|
51
|
+
|| (codePoint >= 0x2e80 && codePoint <= 0xa4cf && codePoint !== 0x303f)
|
|
52
|
+
|| (codePoint >= 0xac00 && codePoint <= 0xd7a3)
|
|
53
|
+
|| (codePoint >= 0xf900 && codePoint <= 0xfaff)
|
|
54
|
+
|| (codePoint >= 0xfe10 && codePoint <= 0xfe19)
|
|
55
|
+
|| (codePoint >= 0xfe30 && codePoint <= 0xfe6f)
|
|
56
|
+
|| (codePoint >= 0xff00 && codePoint <= 0xff60)
|
|
57
|
+
|| (codePoint >= 0xffe0 && codePoint <= 0xffe6)
|
|
58
|
+
|| (codePoint >= 0x1f000 && codePoint <= 0x1faff)
|
|
59
|
+
|| (codePoint >= 0x20000 && codePoint <= 0x3fffd)
|
|
60
|
+
)
|
|
61
|
+
) return 2;
|
|
62
|
+
return 1;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function terminalCellWidth(value) {
|
|
66
|
+
let width = 0;
|
|
67
|
+
for (const char of String(value ?? "")) width += codePointCellWidth(char.codePointAt(0));
|
|
68
|
+
return width;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function truncateCells(value, width) {
|
|
72
|
+
const text = String(value ?? "");
|
|
73
|
+
const limit = Math.max(0, Number(width) || 0);
|
|
74
|
+
if (limit === 0) return "";
|
|
75
|
+
if (terminalCellWidth(text) <= limit) return text;
|
|
76
|
+
if (limit === 1) return "…";
|
|
77
|
+
let output = "";
|
|
78
|
+
let used = 0;
|
|
79
|
+
for (const char of text) {
|
|
80
|
+
const cells = codePointCellWidth(char.codePointAt(0));
|
|
81
|
+
if (used + cells > limit - 1) break;
|
|
82
|
+
output += char;
|
|
83
|
+
used += cells;
|
|
84
|
+
}
|
|
85
|
+
return output + "…";
|
|
86
|
+
}
|
|
87
|
+
|
|
34
88
|
function paint(value, ...styles) {
|
|
35
89
|
if (!styles.length) return String(value ?? "");
|
|
36
90
|
return styles.join("") + String(value ?? "") + RESET;
|
|
@@ -57,19 +111,62 @@ function statusStyle(value) {
|
|
|
57
111
|
}
|
|
58
112
|
}
|
|
59
113
|
|
|
114
|
+
function relayHealthStyle(health) {
|
|
115
|
+
switch (health?.state) {
|
|
116
|
+
case "reachable": return STYLE.green;
|
|
117
|
+
case "checking": return STYLE.yellow;
|
|
118
|
+
default: return STYLE.red;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function relayHealthText(health) {
|
|
123
|
+
switch (health?.state) {
|
|
124
|
+
case "reachable": return "● Online";
|
|
125
|
+
case "checking": return "◐ Checking";
|
|
126
|
+
case "limited":
|
|
127
|
+
return health.code === 1027
|
|
128
|
+
? "✕ Cloudflare 1027"
|
|
129
|
+
: `✕ Rate limited (${health.code || "429"})`;
|
|
130
|
+
case "cloudflare-error": return `✕ Cloudflare ${health.code || "error"}`;
|
|
131
|
+
case "unauthorized": return health.code === 403 ? "✕ Access denied" : "✕ Sign-in required";
|
|
132
|
+
case "reauthorize": return "✕ Agent reauthorization required";
|
|
133
|
+
case "agent-disabled": return "✕ Agent disabled";
|
|
134
|
+
case "agent-access": return "✕ Agent access required";
|
|
135
|
+
case "unavailable":
|
|
136
|
+
if (health.reason === "relay_unavailable") return "✕ Relay unavailable";
|
|
137
|
+
if (health.reason === "agent_offline") return "✕ Agent offline";
|
|
138
|
+
return `✕ ${health.code ? `HTTP ${health.code}` : "Unavailable"}`;
|
|
139
|
+
default: return "? Unknown";
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function relayHealthAge(health, now = Date.now()) {
|
|
144
|
+
const checkedAt = Number(health?.checkedAt);
|
|
145
|
+
if (!Number.isFinite(checkedAt)) return "pending";
|
|
146
|
+
const ageSeconds = Math.max(0, Math.floor((now - checkedAt) / 1000));
|
|
147
|
+
if (ageSeconds < 10) return "just now";
|
|
148
|
+
if (ageSeconds < 60) return `${ageSeconds}s ago`;
|
|
149
|
+
const ageMinutes = Math.floor(ageSeconds / 60);
|
|
150
|
+
if (ageMinutes < 60) return `${ageMinutes}m ago`;
|
|
151
|
+
return `${Math.floor(ageMinutes / 60)}h ago`;
|
|
152
|
+
}
|
|
153
|
+
|
|
60
154
|
export function formatTwoColumnHeader(state, width = 110, { color = false } = {}) {
|
|
61
155
|
const usable = clamp(Number(width) || 110, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);
|
|
62
156
|
const leftWidth = Math.floor((usable - GAP) / 2);
|
|
63
157
|
const rightWidth = usable - GAP - leftWidth;
|
|
64
158
|
const rows = [
|
|
65
159
|
["Account", state.account || "-", "Agent", state.agent || "-"],
|
|
66
|
-
["
|
|
67
|
-
["
|
|
68
|
-
["
|
|
160
|
+
["Agent link", statusText(state.status), "Relay", state.relay || "-"],
|
|
161
|
+
["Relay API", relayHealthText(state.relayHealth), "Reconnects", String(state.reconnects ?? 0)],
|
|
162
|
+
["Session up", formatUptime(state.uptimeMs), "Terminal", state.terminal ? "enabled" : "disabled"],
|
|
163
|
+
["Desktop", state.desktop ? "enabled" : "disabled", "Checked", relayHealthAge(state.relayHealth)],
|
|
69
164
|
];
|
|
70
165
|
return rows
|
|
71
166
|
.map(([leftLabel, leftValue, rightLabel, rightValue]) => {
|
|
72
|
-
const leftStyle = leftLabel === "
|
|
167
|
+
const leftStyle = leftLabel === "Agent link"
|
|
168
|
+
? statusStyle(state.status)
|
|
169
|
+
: leftLabel === "Relay API" ? relayHealthStyle(state.relayHealth) : null;
|
|
73
170
|
const rightStyle = rightLabel === "Reconnects" && Number(state.reconnects || 0) > 0 ? STYLE.yellow : null;
|
|
74
171
|
return field(leftLabel, leftValue, leftWidth, color, leftStyle)
|
|
75
172
|
+ " ".repeat(GAP)
|
|
@@ -80,7 +177,7 @@ export function formatTwoColumnHeader(state, width = 110, { color = false } = {}
|
|
|
80
177
|
|
|
81
178
|
function statusText(value) {
|
|
82
179
|
switch (String(value || "").toLowerCase()) {
|
|
83
|
-
case "connected": return "●
|
|
180
|
+
case "connected": return "● WebSocket open";
|
|
84
181
|
case "connecting": return "◐ Connecting";
|
|
85
182
|
case "reconnecting": return "◐ Reconnecting";
|
|
86
183
|
case "stopping": return "○ Stopping";
|
|
@@ -139,13 +236,20 @@ function wrapText(value, width, maxLines = 3) {
|
|
|
139
236
|
}
|
|
140
237
|
|
|
141
238
|
export function formatTransactionRows(item, width = 110, { color = false } = {}) {
|
|
142
|
-
const
|
|
239
|
+
const requested = Number(width) || 110;
|
|
240
|
+
const usable = clamp(requested, Math.min(60, Math.max(1, requested)), 180);
|
|
143
241
|
const status = item.status === "running" ? "●" : item.ok === false ? "✕" : "✓";
|
|
242
|
+
if (usable < 32) {
|
|
243
|
+
const compact = truncateCells(`${clock(item.at)} ${status} ${item.summary || item.action || "Tool call"}`, usable);
|
|
244
|
+
if (!color) return [compact];
|
|
245
|
+
const glyphStyle = item.status === "running" ? STYLE.yellow : item.ok === false ? STYLE.red : STYLE.green;
|
|
246
|
+
return [paint(compact, glyphStyle)];
|
|
247
|
+
}
|
|
144
248
|
const prefix = `${clock(item.at)} ${status} `;
|
|
145
249
|
const continuationPrefix = " ".repeat(prefix.length);
|
|
146
250
|
const duration = formatDuration(item.durationMs, item.status);
|
|
147
251
|
const suffix = " " + duration.padStart(8);
|
|
148
|
-
const summaryWidth = Math.max(
|
|
252
|
+
const summaryWidth = Math.max(4, usable - prefix.length - suffix.length);
|
|
149
253
|
const summaryLines = wrapText(item.summary || item.action || "Tool call", summaryWidth, 3);
|
|
150
254
|
|
|
151
255
|
return summaryLines.map((line, index) => {
|
|
@@ -190,31 +294,69 @@ export function shouldUseColor(stdout = process.stdout, env = process.env) {
|
|
|
190
294
|
}
|
|
191
295
|
|
|
192
296
|
export class RemoteTui {
|
|
193
|
-
constructor({
|
|
297
|
+
constructor({
|
|
298
|
+
config,
|
|
299
|
+
version,
|
|
300
|
+
output = process.stdout,
|
|
301
|
+
input = process.stdin,
|
|
302
|
+
env = process.env,
|
|
303
|
+
onInterrupt = () => process.emit("SIGINT"),
|
|
304
|
+
}) {
|
|
194
305
|
this.output = output;
|
|
306
|
+
this.input = input;
|
|
307
|
+
this.onInterrupt = onInterrupt;
|
|
195
308
|
this.startedAt = Date.now();
|
|
196
309
|
this.state = {
|
|
197
310
|
account: config.user?.name || config.user?.login || "signed in",
|
|
198
311
|
agent: config.agentName || config.agentId || "-",
|
|
199
312
|
relay: normalizeRelay(config.relayUrl),
|
|
200
313
|
status: "starting",
|
|
314
|
+
relayHealth: { state: "checking" },
|
|
201
315
|
reconnects: 0,
|
|
202
316
|
terminal: config.terminalEnabled !== false,
|
|
203
317
|
desktop: config.desktopEnabled === true,
|
|
204
318
|
};
|
|
205
319
|
this.version = version || "-";
|
|
206
|
-
this.colorEnabled = shouldUseColor(output);
|
|
320
|
+
this.colorEnabled = shouldUseColor(output, env);
|
|
207
321
|
this.transactions = [];
|
|
208
322
|
this.timer = null;
|
|
209
323
|
this.closed = false;
|
|
210
324
|
this.renderPending = false;
|
|
325
|
+
this.scrollOffset = 0;
|
|
326
|
+
this.unseenTransactions = 0;
|
|
327
|
+
this.inputWasRaw = false;
|
|
328
|
+
this.inputWasPaused = false;
|
|
329
|
+
this.inputFlowingState = null;
|
|
330
|
+
this.mouseEnabled = false;
|
|
331
|
+
this.onInput = (chunk) => this.handleInput(chunk);
|
|
211
332
|
}
|
|
212
333
|
|
|
213
334
|
start() {
|
|
214
335
|
if (this.closed) return;
|
|
215
336
|
// Use the terminal's alternate screen so periodic redraws never accumulate
|
|
216
|
-
// in scrollback.
|
|
217
|
-
|
|
337
|
+
// in scrollback. Mouse reporting is enabled only when stdin can actually
|
|
338
|
+
// consume the events, otherwise ordinary terminal scrollback remains usable.
|
|
339
|
+
const interactiveInput = Boolean(this.input?.isTTY && typeof this.input.setRawMode === "function");
|
|
340
|
+
if (interactiveInput) {
|
|
341
|
+
this.inputWasRaw = Boolean(this.input.isRaw);
|
|
342
|
+
this.inputWasPaused = Boolean(this.input.isPaused?.());
|
|
343
|
+
this.inputFlowingState = this.input.readableFlowing ?? null;
|
|
344
|
+
try {
|
|
345
|
+
this.input.setRawMode(true);
|
|
346
|
+
this.input.resume?.();
|
|
347
|
+
this.input.on?.("data", this.onInput);
|
|
348
|
+
this.mouseEnabled = true;
|
|
349
|
+
} catch {
|
|
350
|
+
this.mouseEnabled = false;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
this.output.write(
|
|
354
|
+
ESC + "?1049h"
|
|
355
|
+
+ ESC + "?25l"
|
|
356
|
+
+ (this.mouseEnabled ? ESC + "?1000h" + ESC + "?1006h" : "")
|
|
357
|
+
+ ESC + "2J"
|
|
358
|
+
+ ESC + "H",
|
|
359
|
+
);
|
|
218
360
|
this.render();
|
|
219
361
|
this.timer = setInterval(() => this.render(), 1000);
|
|
220
362
|
this.timer.unref?.();
|
|
@@ -225,7 +367,92 @@ export class RemoteTui {
|
|
|
225
367
|
this.closed = true;
|
|
226
368
|
if (this.timer) clearInterval(this.timer);
|
|
227
369
|
this.timer = null;
|
|
228
|
-
this.
|
|
370
|
+
this.input?.removeListener?.("data", this.onInput);
|
|
371
|
+
if (this.input?.isTTY && typeof this.input.setRawMode === "function" && !this.inputWasRaw) {
|
|
372
|
+
try { this.input.setRawMode(false); } catch {}
|
|
373
|
+
}
|
|
374
|
+
if (this.inputFlowingState !== true) this.input?.pause?.();
|
|
375
|
+
this.output.write(
|
|
376
|
+
(this.mouseEnabled ? ESC + "?1000l" + ESC + "?1006l" : "")
|
|
377
|
+
+ ESC + "?25h"
|
|
378
|
+
+ ESC + "?1049l",
|
|
379
|
+
);
|
|
380
|
+
this.mouseEnabled = false;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
viewportMetrics() {
|
|
384
|
+
const terminalWidth = Number(this.output.columns) || 110;
|
|
385
|
+
const width = clamp(terminalWidth - 1, Math.min(MIN_FRAME_WIDTH, Math.max(1, terminalWidth - 1)), MAX_FRAME_WIDTH);
|
|
386
|
+
const height = Math.max(1, Number(this.output.rows) || 30);
|
|
387
|
+
const compact = height < 14;
|
|
388
|
+
const headerRows = compact ? Math.max(1, Math.min(2, height - 3)) : 5;
|
|
389
|
+
const fixedRows = compact ? 2 + headerRows : FRAME_FIXED_ROWS;
|
|
390
|
+
const availableRows = Math.max(1, height - fixedRows - FRAME_BOTTOM_MARGIN);
|
|
391
|
+
return { width, height, availableRows, compact, headerRows };
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
transactionRows(width) {
|
|
395
|
+
return this.transactions.flatMap((item) => formatTransactionRows(item, width, { color: this.colorEnabled }));
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
maxScrollOffset() {
|
|
399
|
+
const { width, availableRows } = this.viewportMetrics();
|
|
400
|
+
return Math.max(0, this.transactionRows(width).length - availableRows);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
scrollBy(lines) {
|
|
404
|
+
const next = clamp(this.scrollOffset + Number(lines || 0), 0, this.maxScrollOffset());
|
|
405
|
+
if (next === this.scrollOffset) return;
|
|
406
|
+
this.scrollOffset = next;
|
|
407
|
+
if (this.scrollOffset === 0) this.unseenTransactions = 0;
|
|
408
|
+
this.scheduleRender();
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
handleInput(chunk) {
|
|
412
|
+
const data = Buffer.isBuffer(chunk) ? chunk.toString("utf8") : String(chunk || "");
|
|
413
|
+
if (!data) return;
|
|
414
|
+
|
|
415
|
+
// Raw mode turns Ctrl+C into input data, so forward it to the existing
|
|
416
|
+
// shutdown handler instead of swallowing it.
|
|
417
|
+
if (data.includes("\x03")) {
|
|
418
|
+
this.onInterrupt?.();
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
let handledMouse = false;
|
|
423
|
+
const mouse = /\x1b\[<(\d+);\d+;\d+[Mm]/g;
|
|
424
|
+
let match;
|
|
425
|
+
while ((match = mouse.exec(data)) !== null) {
|
|
426
|
+
const button = Number(match[1]);
|
|
427
|
+
if ((button & 64) !== 64) continue;
|
|
428
|
+
this.scrollBy((button & 1) === 0 ? 3 : -3);
|
|
429
|
+
handledMouse = true;
|
|
430
|
+
}
|
|
431
|
+
if (handledMouse) return;
|
|
432
|
+
|
|
433
|
+
if (data.includes("\x1b[5~")) return this.scrollBy(this.viewportMetrics().availableRows);
|
|
434
|
+
if (data.includes("\x1b[6~")) return this.scrollBy(-this.viewportMetrics().availableRows);
|
|
435
|
+
if (data.includes("\x1b[H") || data.includes("\x1b[1~")) {
|
|
436
|
+
this.scrollOffset = this.maxScrollOffset();
|
|
437
|
+
return this.scheduleRender();
|
|
438
|
+
}
|
|
439
|
+
if (data.includes("\x1b[F") || data.includes("\x1b[4~")) {
|
|
440
|
+
this.scrollOffset = 0;
|
|
441
|
+
this.unseenTransactions = 0;
|
|
442
|
+
return this.scheduleRender();
|
|
443
|
+
}
|
|
444
|
+
if (data.includes("\x1b[A")) return this.scrollBy(1);
|
|
445
|
+
if (data.includes("\x1b[B")) return this.scrollBy(-1);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
appendTransaction(item) {
|
|
449
|
+
if (this.scrollOffset > 0) {
|
|
450
|
+
const { width } = this.viewportMetrics();
|
|
451
|
+
this.scrollOffset += formatTransactionRows(item, width, { color: false }).length;
|
|
452
|
+
this.unseenTransactions += 1;
|
|
453
|
+
}
|
|
454
|
+
this.transactions.push(item);
|
|
455
|
+
if (this.transactions.length > 100) this.transactions.splice(0, this.transactions.length - 100);
|
|
229
456
|
}
|
|
230
457
|
|
|
231
458
|
handleMessage(message) {
|
|
@@ -234,7 +461,7 @@ export class RemoteTui {
|
|
|
234
461
|
this.state.status = message.state || this.state.status;
|
|
235
462
|
if (Number.isFinite(Number(message.reconnects))) this.state.reconnects = Number(message.reconnects);
|
|
236
463
|
} else if (message.event === "tool:start") {
|
|
237
|
-
this.
|
|
464
|
+
this.appendTransaction({
|
|
238
465
|
requestId: message.requestId,
|
|
239
466
|
at: message.at || new Date().toISOString(),
|
|
240
467
|
action: message.action,
|
|
@@ -242,7 +469,6 @@ export class RemoteTui {
|
|
|
242
469
|
status: "running",
|
|
243
470
|
ok: null,
|
|
244
471
|
});
|
|
245
|
-
if (this.transactions.length > 100) this.transactions.splice(0, this.transactions.length - 100);
|
|
246
472
|
} else if (message.event === "tool:end") {
|
|
247
473
|
const item = [...this.transactions].reverse().find((entry) => entry.requestId === message.requestId);
|
|
248
474
|
if (item) {
|
|
@@ -252,18 +478,26 @@ export class RemoteTui {
|
|
|
252
478
|
if (message.error && message.ok === false) item.summary += ` · ${truncate(message.error, 48)}`;
|
|
253
479
|
}
|
|
254
480
|
} else if (message.event === "system") {
|
|
255
|
-
this.
|
|
481
|
+
this.appendTransaction({
|
|
256
482
|
requestId: "system-" + Date.now() + "-" + Math.random(),
|
|
257
483
|
at: message.at || new Date().toISOString(),
|
|
258
484
|
summary: message.message || "Agent event",
|
|
259
485
|
status: "done",
|
|
260
486
|
ok: message.level !== "error",
|
|
261
487
|
});
|
|
262
|
-
if (this.transactions.length > 100) this.transactions.splice(0, this.transactions.length - 100);
|
|
263
488
|
}
|
|
264
489
|
this.scheduleRender();
|
|
265
490
|
}
|
|
266
491
|
|
|
492
|
+
setRelayHealth(health) {
|
|
493
|
+
if (this.closed) return;
|
|
494
|
+
this.state.relayHealth = {
|
|
495
|
+
...(health && typeof health === "object" ? health : { state: "unavailable" }),
|
|
496
|
+
checkedAt: Date.now(),
|
|
497
|
+
};
|
|
498
|
+
this.scheduleRender();
|
|
499
|
+
}
|
|
500
|
+
|
|
267
501
|
scheduleRender() {
|
|
268
502
|
if (this.closed || this.renderPending) return;
|
|
269
503
|
this.renderPending = true;
|
|
@@ -275,48 +509,51 @@ export class RemoteTui {
|
|
|
275
509
|
|
|
276
510
|
render() {
|
|
277
511
|
if (this.closed) return;
|
|
278
|
-
const
|
|
279
|
-
const width = clamp(terminalWidth - 1, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);
|
|
280
|
-
const height = Math.max(16, Number(this.output.rows) || 30);
|
|
512
|
+
const { width, height, availableRows, compact, headerRows } = this.viewportMetrics();
|
|
281
513
|
const separator = "─".repeat(width);
|
|
282
|
-
const
|
|
514
|
+
const headerState = {
|
|
283
515
|
...this.state,
|
|
284
516
|
uptimeMs: Date.now() - this.startedAt,
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
} else if (rows.length === 0) {
|
|
296
|
-
rows.unshift(...group.slice(0, remaining));
|
|
297
|
-
} else {
|
|
298
|
-
break;
|
|
299
|
-
}
|
|
517
|
+
};
|
|
518
|
+
let headerLines;
|
|
519
|
+
if (width < MIN_FRAME_WIDTH) {
|
|
520
|
+
const compactHeader = [
|
|
521
|
+
truncateCells(`👤 ${headerState.account || "-"} · 💻 ${headerState.agent || "-"}`, width),
|
|
522
|
+
truncateCells(`🔗 ${statusText(headerState.status)} · ${relayHealthText(headerState.relayHealth)}`, width),
|
|
523
|
+
];
|
|
524
|
+
headerLines = compactHeader.map((line) => this.colorEnabled ? paint(line, STYLE.gray) : line);
|
|
525
|
+
} else {
|
|
526
|
+
headerLines = formatTwoColumnHeader(headerState, width, { color: this.colorEnabled }).split("\n");
|
|
300
527
|
}
|
|
528
|
+
if (compact) headerLines = headerLines.slice(0, headerRows);
|
|
529
|
+
|
|
530
|
+
const allRows = this.transactionRows(width);
|
|
531
|
+
const maxOffset = Math.max(0, allRows.length - availableRows);
|
|
532
|
+
this.scrollOffset = clamp(this.scrollOffset, 0, maxOffset);
|
|
533
|
+
const end = Math.max(0, allRows.length - this.scrollOffset);
|
|
534
|
+
const start = Math.max(0, end - availableRows);
|
|
535
|
+
const rows = allRows.slice(start, end);
|
|
301
536
|
while (rows.length < Math.min(availableRows, 4)) rows.unshift("");
|
|
302
537
|
|
|
303
|
-
const
|
|
304
|
-
|
|
305
|
-
: `Chat Relay v${this.version}`;
|
|
538
|
+
const titleText = truncateCells(`🚀 Chat Relay v${this.version}`, width);
|
|
539
|
+
const title = this.colorEnabled ? paint(titleText, STYLE.bold, STYLE.cyan) : titleText;
|
|
306
540
|
const divider = this.colorEnabled ? paint(separator, STYLE.gray) : separator;
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
541
|
+
const mode = this.scrollOffset === 0
|
|
542
|
+
? "🟢 LIVE"
|
|
543
|
+
: this.unseenTransactions > 0
|
|
544
|
+
? `📬 +${this.unseenTransactions} new`
|
|
545
|
+
: "📜 HISTORY";
|
|
546
|
+
const sectionText = truncateCells(
|
|
547
|
+
`📜 Transactions ${mode} · wheel/↑↓ scroll · End = live`,
|
|
548
|
+
width,
|
|
549
|
+
);
|
|
550
|
+
const section = this.colorEnabled ? paint(sectionText, STYLE.bold, STYLE.cyan) : sectionText;
|
|
551
|
+
|
|
552
|
+
const screenLines = compact
|
|
553
|
+
? [title, ...headerLines, section, ...rows]
|
|
554
|
+
: [title, divider, "", ...headerLines, "", divider, section, "", ...rows];
|
|
555
|
+
const maxLines = Math.max(1, height - FRAME_BOTTOM_MARGIN);
|
|
556
|
+
const screen = screenLines.slice(0, maxLines).join("\n");
|
|
320
557
|
|
|
321
558
|
this.output.write(ESC + "2J" + ESC + "H" + screen);
|
|
322
559
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anusornneal/chat-relay",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Zero-checkout remote MCP agent for ChatGPT with terminal, filesystem, process, multi-user, and multi-agent support.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"logout": "node bin/chat-relay.js logout",
|
|
26
26
|
"status": "node bin/chat-relay.js status",
|
|
27
27
|
"dev": "wrangler dev",
|
|
28
|
-
"dev:test": "wrangler dev --local --port 8790 --var AGENT_TOKEN:test-agent --var CALLER_TOKEN
|
|
28
|
+
"dev:test": "wrangler dev --local --port 8790 --var AGENT_TOKEN:test-agent --var CALLER_TOKEN:test-caller --var ADMIN_TOKEN:test-admin --var OPENAI_APPS_CHALLENGE:test-openai-apps-challenge",
|
|
29
29
|
"deploy": "wrangler deploy",
|
|
30
30
|
"agent": "node --env-file-if-exists=.dev.vars agent/local-agent.mjs",
|
|
31
31
|
"admin": "node scripts/admin.mjs",
|
|
@@ -50,6 +50,12 @@
|
|
|
50
50
|
"test:device-management": "node test/device-management-smoke.mjs",
|
|
51
51
|
"test:submission": "node test/submission-smoke.mjs",
|
|
52
52
|
"test:agent-state": "node --experimental-strip-types --test test/agent-state.test.mjs",
|
|
53
|
+
"test:tui": "node --test test/cli-tui.test.mjs",
|
|
54
|
+
"test:config-security": "node --test test/config-security.test.mjs",
|
|
55
|
+
"test:self-update": "node --test test/self-update.test.mjs test/agent-lifecycle-upgrade.test.mjs",
|
|
56
|
+
"test:budget": "node --test test/relay-health.test.mjs test/usage-budget.test.mjs",
|
|
57
|
+
"test:soak": "node test/soak-smoke.mjs",
|
|
58
|
+
"test:hardening": "npm run test:tui && npm run test:config-security && npm run test:self-update && npm run test:budget && node --test test/connection-generation.test.mjs && npm run test:agent-state && node test/heartbeat-ack-watchdog.test.mjs && npm run test:usage-storage && npm run test:soak",
|
|
53
59
|
"verify:review": "node scripts/verify-review-artifacts.mjs"
|
|
54
60
|
},
|
|
55
61
|
"dependencies": {
|