Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (codex): bound the PTY capture buffer, add non-symlink timezone fallback
[._.]/ Adam Eivyc83340817226
diff --git a/server/lib/tuiUsageScrape.js b/server/lib/tuiUsageScrape.jsindex 404825cd2c..a7362bf682 100644--- a/server/lib/tuiUsageScrape.js+++ b/server/lib/tuiUsageScrape.js@@ -50,6 +50,12 @@ const DEFAULT_IDLE_MS = 2500; // "screen finished rendering" = no outputconst DEFAULT_RENDER_CAP_MS = 12000; // hard cap on waiting for the panel after the commandconst DEFAULT_HARD_TIMEOUT_MS = 45000; // absolute backstop for the whole scrape+// Bounded tail for the PTY capture: slice back to CAP once it exceeds HEADROOM+// (slicing on a headroom margin, not every chunk, keeps the common case free of+// repeated reallocations). 512KB holds many repaints of a quota panel.+const RAW_BUFFER_CAP = 512 * 1024;+const RAW_BUFFER_HEADROOM = RAW_BUFFER_CAP * 2;+/*** Spawn a TUI, send `slashCommand`, and resolve with the ANSI-stripped screen.*@@ -104,10 +110,19 @@ export async function scrapeTuiUsage({throw new Error(`Failed to spawn TUI '${command}': ${err.message}`);}+ // Keep only a bounded tail of the capture: the quota panel renders near the+ // end and the parsers take the latest value per key, so the tail is what+ // matters. Without this, a runaway/noisy TUI that repaints continuously could+ // grow `raw` to hundreds of MB before the render cap / hard timeout and trip+ // PM2's memory restart just from loading Usage (mirrors tuiPromptRunner's cap).let raw = '';let lastDataAt = Date.now();let exited = false;- pty.onData((d) => { raw += d; lastDataAt = Date.now(); });+ pty.onData((d) => {+ raw += d;+ if (raw.length > RAW_BUFFER_HEADROOM) raw = raw.slice(-RAW_BUFFER_CAP);+ lastDataAt = Date.now();+ });pty.onExit(() => { exited = true; });const killPty = () => { try { if (!exited) pty.kill(); } catch { /* already gone */ } };diff --git a/server/services/claudeCodeUsage.js b/server/services/claudeCodeUsage.jsindex ced1923bcd..fb83b742c1 100644--- a/server/services/claudeCodeUsage.js+++ b/server/services/claudeCodeUsage.js@@ -1,5 +1,5 @@import { spawn } from 'child_process';-import { existsSync, lstatSync, readlinkSync } from 'fs';+import { existsSync, lstatSync, readlinkSync, readFileSync } from 'fs';import { stripAnsi } from '../lib/ansiStrip.js';/**@@ -51,12 +51,28 @@ export function zoneFromLocaltimeLink(link) {let cachedSystemTz;export function systemTimeZone() {if (cachedSystemTz !== undefined) return cachedSystemTz;- cachedSystemTz = existsSync('/etc/localtime') && lstatSync('/etc/localtime').isSymbolicLink()- ? zoneFromLocaltimeLink(readlinkSync('/etc/localtime'))- : null;+ cachedSystemTz = resolveSystemTimeZone();return cachedSystemTz;}+// Resolve the machine's IANA zone WITHOUT trusting `process.env.TZ` (which PM2+// forces to UTC). Order: the `/etc/localtime` symlink target (macOS + most+// Linux), then the Debian/Ubuntu `/etc/timezone` file (a plain zone name, used+// when `/etc/localtime` is a regular-file copy rather than a symlink). Windows+// has no equivalent file, so it stays null (best-effort — reset times fall back+// to the child's own TZ, same as before). Pure-ish; memoized by the caller.+function resolveSystemTimeZone() {+ if (existsSync('/etc/localtime') && lstatSync('/etc/localtime').isSymbolicLink()) {+ const zone = zoneFromLocaltimeLink(readlinkSync('/etc/localtime'));+ if (zone) return zone;+ }+ if (existsSync('/etc/timezone')) {+ const zone = readFileSync('/etc/timezone', 'utf-8').trim();+ if (/^[A-Za-z]+\/[A-Za-z0-9_+\-/]+$/.test(zone)) return zone;+ }+ return null;+}+/*** Parse one `Current …: N% used · resets <when> (<tz>)` limit line.* Returns null when the line isn't a limit line.