@anusornneal/chat-relay 0.11.2 → 0.12.1

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/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 = 11;
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,66 @@ function statusStyle(value) {
57
111
  }
58
112
  }
59
113
 
114
+ function relayHealthStyle(health) {
115
+ const code = Number(health?.code);
116
+ if (Number.isFinite(code) && code >= 200 && code < 300) return STYLE.green;
117
+ switch (health?.state) {
118
+ case "reachable": return STYLE.green;
119
+ case "checking": return STYLE.yellow;
120
+ default: return STYLE.red;
121
+ }
122
+ }
123
+
124
+ function relayHealthText(health) {
125
+ const code = Number(health?.code);
126
+ if (Number.isFinite(code) && code >= 200 && code < 300) return `● HTTP ${code}`;
127
+ switch (health?.state) {
128
+ case "reachable": return "● Online";
129
+ case "checking": return "◐ Checking";
130
+ case "limited":
131
+ return health.code === 1027
132
+ ? "✕ Cloudflare 1027"
133
+ : `✕ Rate limited (${health.code || "429"})`;
134
+ case "cloudflare-error": return `✕ Cloudflare ${health.code || "error"}`;
135
+ case "unauthorized": return health.code === 403 ? "✕ Access denied" : "✕ Sign-in required";
136
+ case "reauthorize": return "✕ Agent reauthorization required";
137
+ case "agent-disabled": return "✕ Agent disabled";
138
+ case "agent-access": return "✕ Agent access required";
139
+ case "unavailable":
140
+ if (health.reason === "relay_unavailable") return "✕ Relay unavailable";
141
+ if (health.reason === "agent_offline") return "✕ Agent offline";
142
+ return `✕ ${health.code ? `HTTP ${health.code}` : "Unavailable"}`;
143
+ default: return "? Unknown";
144
+ }
145
+ }
146
+
147
+ function relayHealthAge(health, now = Date.now()) {
148
+ const checkedAt = Number(health?.checkedAt);
149
+ if (!Number.isFinite(checkedAt)) return "pending";
150
+ const ageSeconds = Math.max(0, Math.floor((now - checkedAt) / 1000));
151
+ if (ageSeconds < 10) return "just now";
152
+ if (ageSeconds < 60) return `${ageSeconds}s ago`;
153
+ const ageMinutes = Math.floor(ageSeconds / 60);
154
+ if (ageMinutes < 60) return `${ageMinutes}m ago`;
155
+ return `${Math.floor(ageMinutes / 60)}h ago`;
156
+ }
157
+
60
158
  export function formatTwoColumnHeader(state, width = 110, { color = false } = {}) {
61
159
  const usable = clamp(Number(width) || 110, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);
62
160
  const leftWidth = Math.floor((usable - GAP) / 2);
63
161
  const rightWidth = usable - GAP - leftWidth;
64
162
  const rows = [
65
163
  ["Account", state.account || "-", "Agent", state.agent || "-"],
66
- ["Status", statusText(state.status), "Relay", state.relay || "-"],
67
- ["Uptime", formatUptime(state.uptimeMs), "Reconnects", String(state.reconnects ?? 0)],
68
- ["Terminal", state.terminal ? "enabled" : "disabled", "Desktop", state.desktop ? "enabled" : "disabled"],
164
+ ["Agent link", statusText(state.status), "Relay", state.relay || "-"],
165
+ ["Relay API", relayHealthText(state.relayHealth), "Reconnects", String(state.reconnects ?? 0)],
166
+ ["Session up", formatUptime(state.uptimeMs), "Terminal", state.terminal ? "enabled" : "disabled"],
167
+ ["Desktop", state.desktop ? "enabled" : "disabled", "Checked", relayHealthAge(state.relayHealth)],
69
168
  ];
70
169
  return rows
71
170
  .map(([leftLabel, leftValue, rightLabel, rightValue]) => {
72
- const leftStyle = leftLabel === "Status" ? statusStyle(state.status) : null;
171
+ const leftStyle = leftLabel === "Agent link"
172
+ ? statusStyle(state.status)
173
+ : leftLabel === "Relay API" ? relayHealthStyle(state.relayHealth) : null;
73
174
  const rightStyle = rightLabel === "Reconnects" && Number(state.reconnects || 0) > 0 ? STYLE.yellow : null;
74
175
  return field(leftLabel, leftValue, leftWidth, color, leftStyle)
75
176
  + " ".repeat(GAP)
@@ -80,7 +181,7 @@ export function formatTwoColumnHeader(state, width = 110, { color = false } = {}
80
181
 
81
182
  function statusText(value) {
82
183
  switch (String(value || "").toLowerCase()) {
83
- case "connected": return "● Connected";
184
+ case "connected": return "● WebSocket open";
84
185
  case "connecting": return "◐ Connecting";
85
186
  case "reconnecting": return "◐ Reconnecting";
86
187
  case "stopping": return "○ Stopping";
@@ -139,27 +240,38 @@ function wrapText(value, width, maxLines = 3) {
139
240
  }
140
241
 
141
242
  export function formatTransactionRows(item, width = 110, { color = false } = {}) {
142
- const usable = clamp(Number(width) || 110, 60, 180);
143
- const status = item.status === "running" ? "●" : item.ok === false ? "✕" : "✓";
243
+ const requested = Number(width) || 110;
244
+ const usable = clamp(requested, Math.min(60, Math.max(1, requested)), 180);
245
+ const status = item.status === "running" ? "🟡" : item.ok === false ? "❌" : "✅";
246
+ if (usable < 32) {
247
+ const compact = truncateCells(`${clock(item.at)} ${status} ${item.summary || item.action || "Tool call"}`, usable);
248
+ if (!color) return [compact];
249
+ const glyphStyle = item.status === "running" ? STYLE.yellow : item.ok === false ? STYLE.red : STYLE.green;
250
+ return [paint(compact, glyphStyle)];
251
+ }
144
252
  const prefix = `${clock(item.at)} ${status} `;
145
- const continuationPrefix = " ".repeat(prefix.length);
253
+ const prefixWidth = terminalCellWidth(prefix);
254
+ const continuationPrefix = " ".repeat(prefixWidth);
146
255
  const duration = formatDuration(item.durationMs, item.status);
147
256
  const suffix = " " + duration.padStart(8);
148
- const summaryWidth = Math.max(18, usable - prefix.length - suffix.length);
257
+ const summaryWidth = Math.max(4, usable - prefixWidth - terminalCellWidth(suffix));
149
258
  const summaryLines = wrapText(item.summary || item.action || "Tool call", summaryWidth, 3);
150
259
 
151
260
  return summaryLines.map((line, index) => {
152
261
  if (index === 0) {
153
- if (!color) return prefix + line.padEnd(summaryWidth) + suffix;
262
+ const plainRow = prefix + line.padEnd(summaryWidth) + suffix;
263
+ if (!color) return plainRow;
264
+ if (item.ok === false) return paint(plainRow, STYLE.red);
154
265
  const time = paint(clock(item.at), STYLE.gray);
155
- const glyphStyle = item.status === "running" ? STYLE.yellow : item.ok === false ? STYLE.red : STYLE.green;
266
+ const glyphStyle = item.status === "running" ? STYLE.yellow : STYLE.green;
156
267
  const glyph = paint(status, glyphStyle, STYLE.bold);
157
268
  const summary = item.status === "running" ? paint(line.padEnd(summaryWidth), STYLE.bold) : line.padEnd(summaryWidth);
158
269
  const timing = paint(suffix, STYLE.gray);
159
270
  return `${time} ${glyph} ${summary}${timing}`;
160
271
  }
161
272
  if (!color) return continuationPrefix + line;
162
- return " ".repeat(prefix.length) + paint(line, STYLE.dim);
273
+ if (item.ok === false) return continuationPrefix + paint(line, STYLE.red);
274
+ return continuationPrefix + paint(line, STYLE.dim);
163
275
  });
164
276
  }
165
277
 
@@ -190,31 +302,69 @@ export function shouldUseColor(stdout = process.stdout, env = process.env) {
190
302
  }
191
303
 
192
304
  export class RemoteTui {
193
- constructor({ config, version, output = process.stdout }) {
305
+ constructor({
306
+ config,
307
+ version,
308
+ output = process.stdout,
309
+ input = process.stdin,
310
+ env = process.env,
311
+ onInterrupt = () => process.emit("SIGINT"),
312
+ }) {
194
313
  this.output = output;
314
+ this.input = input;
315
+ this.onInterrupt = onInterrupt;
195
316
  this.startedAt = Date.now();
196
317
  this.state = {
197
318
  account: config.user?.name || config.user?.login || "signed in",
198
319
  agent: config.agentName || config.agentId || "-",
199
320
  relay: normalizeRelay(config.relayUrl),
200
321
  status: "starting",
322
+ relayHealth: { state: "checking" },
201
323
  reconnects: 0,
202
324
  terminal: config.terminalEnabled !== false,
203
325
  desktop: config.desktopEnabled === true,
204
326
  };
205
327
  this.version = version || "-";
206
- this.colorEnabled = shouldUseColor(output);
328
+ this.colorEnabled = shouldUseColor(output, env);
207
329
  this.transactions = [];
208
330
  this.timer = null;
209
331
  this.closed = false;
210
332
  this.renderPending = false;
333
+ this.scrollOffset = 0;
334
+ this.unseenTransactions = 0;
335
+ this.inputWasRaw = false;
336
+ this.inputWasPaused = false;
337
+ this.inputFlowingState = null;
338
+ this.mouseEnabled = false;
339
+ this.onInput = (chunk) => this.handleInput(chunk);
211
340
  }
212
341
 
213
342
  start() {
214
343
  if (this.closed) return;
215
344
  // Use the terminal's alternate screen so periodic redraws never accumulate
216
- // in scrollback. Keep one column unused to avoid automatic line wrapping.
217
- this.output.write(ESC + "?1049h" + ESC + "?25l" + ESC + "2J" + ESC + "H");
345
+ // in scrollback. Mouse reporting is enabled only when stdin can actually
346
+ // consume the events, otherwise ordinary terminal scrollback remains usable.
347
+ const interactiveInput = Boolean(this.input?.isTTY && typeof this.input.setRawMode === "function");
348
+ if (interactiveInput) {
349
+ this.inputWasRaw = Boolean(this.input.isRaw);
350
+ this.inputWasPaused = Boolean(this.input.isPaused?.());
351
+ this.inputFlowingState = this.input.readableFlowing ?? null;
352
+ try {
353
+ this.input.setRawMode(true);
354
+ this.input.resume?.();
355
+ this.input.on?.("data", this.onInput);
356
+ this.mouseEnabled = true;
357
+ } catch {
358
+ this.mouseEnabled = false;
359
+ }
360
+ }
361
+ this.output.write(
362
+ ESC + "?1049h"
363
+ + ESC + "?25l"
364
+ + (this.mouseEnabled ? ESC + "?1000h" + ESC + "?1006h" : "")
365
+ + ESC + "2J"
366
+ + ESC + "H",
367
+ );
218
368
  this.render();
219
369
  this.timer = setInterval(() => this.render(), 1000);
220
370
  this.timer.unref?.();
@@ -225,7 +375,92 @@ export class RemoteTui {
225
375
  this.closed = true;
226
376
  if (this.timer) clearInterval(this.timer);
227
377
  this.timer = null;
228
- this.output.write(ESC + "?25h" + ESC + "?1049l");
378
+ this.input?.removeListener?.("data", this.onInput);
379
+ if (this.input?.isTTY && typeof this.input.setRawMode === "function" && !this.inputWasRaw) {
380
+ try { this.input.setRawMode(false); } catch {}
381
+ }
382
+ if (this.inputFlowingState !== true) this.input?.pause?.();
383
+ this.output.write(
384
+ (this.mouseEnabled ? ESC + "?1000l" + ESC + "?1006l" : "")
385
+ + ESC + "?25h"
386
+ + ESC + "?1049l",
387
+ );
388
+ this.mouseEnabled = false;
389
+ }
390
+
391
+ viewportMetrics() {
392
+ const terminalWidth = Number(this.output.columns) || 110;
393
+ const width = clamp(terminalWidth - 1, Math.min(MIN_FRAME_WIDTH, Math.max(1, terminalWidth - 1)), MAX_FRAME_WIDTH);
394
+ const height = Math.max(1, Number(this.output.rows) || 30);
395
+ const compact = height < 14;
396
+ const headerRows = compact ? Math.max(1, Math.min(2, height - 3)) : 5;
397
+ const fixedRows = compact ? 2 + headerRows : FRAME_FIXED_ROWS;
398
+ const availableRows = Math.max(1, height - fixedRows - FRAME_BOTTOM_MARGIN);
399
+ return { width, height, availableRows, compact, headerRows };
400
+ }
401
+
402
+ transactionRows(width) {
403
+ return this.transactions.flatMap((item) => formatTransactionRows(item, width, { color: this.colorEnabled }));
404
+ }
405
+
406
+ maxScrollOffset() {
407
+ const { width, availableRows } = this.viewportMetrics();
408
+ return Math.max(0, this.transactionRows(width).length - availableRows);
409
+ }
410
+
411
+ scrollBy(lines) {
412
+ const next = clamp(this.scrollOffset + Number(lines || 0), 0, this.maxScrollOffset());
413
+ if (next === this.scrollOffset) return;
414
+ this.scrollOffset = next;
415
+ if (this.scrollOffset === 0) this.unseenTransactions = 0;
416
+ this.scheduleRender();
417
+ }
418
+
419
+ handleInput(chunk) {
420
+ const data = Buffer.isBuffer(chunk) ? chunk.toString("utf8") : String(chunk || "");
421
+ if (!data) return;
422
+
423
+ // Raw mode turns Ctrl+C into input data, so forward it to the existing
424
+ // shutdown handler instead of swallowing it.
425
+ if (data.includes("\x03")) {
426
+ this.onInterrupt?.();
427
+ return;
428
+ }
429
+
430
+ let handledMouse = false;
431
+ const mouse = /\x1b\[<(\d+);\d+;\d+[Mm]/g;
432
+ let match;
433
+ while ((match = mouse.exec(data)) !== null) {
434
+ const button = Number(match[1]);
435
+ if ((button & 64) !== 64) continue;
436
+ this.scrollBy((button & 1) === 0 ? 3 : -3);
437
+ handledMouse = true;
438
+ }
439
+ if (handledMouse) return;
440
+
441
+ if (data.includes("\x1b[5~")) return this.scrollBy(this.viewportMetrics().availableRows);
442
+ if (data.includes("\x1b[6~")) return this.scrollBy(-this.viewportMetrics().availableRows);
443
+ if (data.includes("\x1b[H") || data.includes("\x1b[1~")) {
444
+ this.scrollOffset = this.maxScrollOffset();
445
+ return this.scheduleRender();
446
+ }
447
+ if (data.includes("\x1b[F") || data.includes("\x1b[4~")) {
448
+ this.scrollOffset = 0;
449
+ this.unseenTransactions = 0;
450
+ return this.scheduleRender();
451
+ }
452
+ if (data.includes("\x1b[A")) return this.scrollBy(1);
453
+ if (data.includes("\x1b[B")) return this.scrollBy(-1);
454
+ }
455
+
456
+ appendTransaction(item) {
457
+ if (this.scrollOffset > 0) {
458
+ const { width } = this.viewportMetrics();
459
+ this.scrollOffset += formatTransactionRows(item, width, { color: false }).length;
460
+ this.unseenTransactions += 1;
461
+ }
462
+ this.transactions.push(item);
463
+ if (this.transactions.length > 100) this.transactions.splice(0, this.transactions.length - 100);
229
464
  }
230
465
 
231
466
  handleMessage(message) {
@@ -234,7 +469,7 @@ export class RemoteTui {
234
469
  this.state.status = message.state || this.state.status;
235
470
  if (Number.isFinite(Number(message.reconnects))) this.state.reconnects = Number(message.reconnects);
236
471
  } else if (message.event === "tool:start") {
237
- this.transactions.push({
472
+ this.appendTransaction({
238
473
  requestId: message.requestId,
239
474
  at: message.at || new Date().toISOString(),
240
475
  action: message.action,
@@ -242,7 +477,6 @@ export class RemoteTui {
242
477
  status: "running",
243
478
  ok: null,
244
479
  });
245
- if (this.transactions.length > 100) this.transactions.splice(0, this.transactions.length - 100);
246
480
  } else if (message.event === "tool:end") {
247
481
  const item = [...this.transactions].reverse().find((entry) => entry.requestId === message.requestId);
248
482
  if (item) {
@@ -252,18 +486,26 @@ export class RemoteTui {
252
486
  if (message.error && message.ok === false) item.summary += ` · ${truncate(message.error, 48)}`;
253
487
  }
254
488
  } else if (message.event === "system") {
255
- this.transactions.push({
489
+ this.appendTransaction({
256
490
  requestId: "system-" + Date.now() + "-" + Math.random(),
257
491
  at: message.at || new Date().toISOString(),
258
492
  summary: message.message || "Agent event",
259
493
  status: "done",
260
494
  ok: message.level !== "error",
261
495
  });
262
- if (this.transactions.length > 100) this.transactions.splice(0, this.transactions.length - 100);
263
496
  }
264
497
  this.scheduleRender();
265
498
  }
266
499
 
500
+ setRelayHealth(health) {
501
+ if (this.closed) return;
502
+ this.state.relayHealth = {
503
+ ...(health && typeof health === "object" ? health : { state: "unavailable" }),
504
+ checkedAt: Date.now(),
505
+ };
506
+ this.scheduleRender();
507
+ }
508
+
267
509
  scheduleRender() {
268
510
  if (this.closed || this.renderPending) return;
269
511
  this.renderPending = true;
@@ -275,48 +517,51 @@ export class RemoteTui {
275
517
 
276
518
  render() {
277
519
  if (this.closed) return;
278
- const terminalWidth = Number(this.output.columns) || 110;
279
- const width = clamp(terminalWidth - 1, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);
280
- const height = Math.max(16, Number(this.output.rows) || 30);
520
+ const { width, height, availableRows, compact, headerRows } = this.viewportMetrics();
281
521
  const separator = "─".repeat(width);
282
- const header = formatTwoColumnHeader({
522
+ const headerState = {
283
523
  ...this.state,
284
524
  uptimeMs: Date.now() - this.startedAt,
285
- }, width, { color: this.colorEnabled });
286
- // Fixed frame content occupies 11 rows. Leave one spare row at the
287
- // bottom so Windows Terminal never scrolls the screen while repainting.
288
- const availableRows = Math.max(1, height - FRAME_FIXED_ROWS - FRAME_BOTTOM_MARGIN);
289
- const rows = [];
290
- for (let index = this.transactions.length - 1; index >= 0 && rows.length < availableRows; index--) {
291
- const group = formatTransactionRows(this.transactions[index], width, { color: this.colorEnabled });
292
- const remaining = availableRows - rows.length;
293
- if (group.length <= remaining) {
294
- rows.unshift(...group);
295
- } else if (rows.length === 0) {
296
- rows.unshift(...group.slice(0, remaining));
297
- } else {
298
- break;
299
- }
525
+ };
526
+ let headerLines;
527
+ if (width < MIN_FRAME_WIDTH) {
528
+ const compactHeader = [
529
+ truncateCells(`👤 ${headerState.account || "-"} · 💻 ${headerState.agent || "-"}`, width),
530
+ truncateCells(`🔗 ${statusText(headerState.status)} · ${relayHealthText(headerState.relayHealth)}`, width),
531
+ ];
532
+ headerLines = compactHeader.map((line) => this.colorEnabled ? paint(line, STYLE.gray) : line);
533
+ } else {
534
+ headerLines = formatTwoColumnHeader(headerState, width, { color: this.colorEnabled }).split("\n");
300
535
  }
536
+ if (compact) headerLines = headerLines.slice(0, headerRows);
537
+
538
+ const allRows = this.transactionRows(width);
539
+ const maxOffset = Math.max(0, allRows.length - availableRows);
540
+ this.scrollOffset = clamp(this.scrollOffset, 0, maxOffset);
541
+ const end = Math.max(0, allRows.length - this.scrollOffset);
542
+ const start = Math.max(0, end - availableRows);
543
+ const rows = allRows.slice(start, end);
301
544
  while (rows.length < Math.min(availableRows, 4)) rows.unshift("");
302
545
 
303
- const title = this.colorEnabled
304
- ? paint("Chat Relay", STYLE.bold, STYLE.cyan) + paint(` v${this.version}`, STYLE.gray)
305
- : `Chat Relay v${this.version}`;
546
+ const titleText = truncateCells(`🚀 Chat Relay v${this.version}`, width);
547
+ const title = this.colorEnabled ? paint(titleText, STYLE.bold, STYLE.cyan) : titleText;
306
548
  const divider = this.colorEnabled ? paint(separator, STYLE.gray) : separator;
307
- const section = this.colorEnabled ? paint("Transactions", STYLE.bold, STYLE.cyan) : "Transactions";
308
-
309
- const screen = [
310
- title,
311
- divider,
312
- "",
313
- header,
314
- "",
315
- divider,
316
- section,
317
- "",
318
- ...rows,
319
- ].join("\n");
549
+ const mode = this.scrollOffset === 0
550
+ ? "🟢 LIVE"
551
+ : this.unseenTransactions > 0
552
+ ? `📬 +${this.unseenTransactions} new`
553
+ : "📜 HISTORY";
554
+ const sectionText = truncateCells(
555
+ `📜 Transactions ${mode} · wheel/↑↓ scroll · End = live`,
556
+ width,
557
+ );
558
+ const section = this.colorEnabled ? paint(sectionText, STYLE.bold, STYLE.cyan) : sectionText;
559
+
560
+ const screenLines = compact
561
+ ? [title, ...headerLines, section, ...rows]
562
+ : [title, divider, "", ...headerLines, "", divider, section, "", ...rows];
563
+ const maxLines = Math.max(1, height - FRAME_BOTTOM_MARGIN);
564
+ const screen = screenLines.slice(0, maxLines).join("\n");
320
565
 
321
566
  this.output.write(ESC + "2J" + ESC + "H" + screen);
322
567
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anusornneal/chat-relay",
3
- "version": "0.11.2",
3
+ "version": "0.12.1",
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=test-caller --var ADMIN_TOKEN=test-admin",
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": {