fix(tui): always show auth token and report accurate macOS memory usage

Pin the Token chip after URL in the System panel so it stays visible
(wrapping to a new row at narrow widths) instead of being pushed off-panel.
Switch system memory readings to os.availableMemory() so macOS no longer
reports ~96% used by ignoring reclaimable inactive/cached pages.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsxdsm
2026-04-28 21:57:47 -07:00
parent 7a4970e2d6
commit a6e6e36266
2 changed files with 29 additions and 8 deletions

View File

@@ -236,6 +236,15 @@ function SystemPanel({ state, isFocused }: { state: DashboardState; isFocused: b
<Text dimColor>URL</Text>
<Text color="cyanBright" wrap="truncate-end">{info.baseUrl}</Text>
</Box>
{info.authToken && (
// Pinned right after URL so the token is part of the primary
// identity row and wraps to a new line at narrow widths instead
// of being pushed off-panel.
<Box flexDirection="row" gap={1} flexShrink={0}>
<Text dimColor>Token</Text>
<Text color="yellow" wrap="truncate-end">{info.authToken}</Text>
</Box>
)}
<Box flexDirection="row" gap={1} flexShrink={0}>
<Text dimColor>Engine</Text>
{info.engineMode === "dev" && <Text color="yellow">dev</Text>}
@@ -258,12 +267,6 @@ function SystemPanel({ state, isFocused }: { state: DashboardState; isFocused: b
<Text dimColor>Uptime</Text>
<Text>{formatUptime(Date.now() - info.startTimeMs)}</Text>
</Box>
{info.authToken && (
<Box flexDirection="row" gap={1} flexShrink={0}>
<Text dimColor>Token</Text>
<Text color="yellow">{info.authToken}</Text>
</Box>
)}
</Box>
)}
</Panel>

View File

@@ -4,6 +4,24 @@ import { execSync } from "node:child_process";
import { appendFileSync } from "node:fs";
import { getCachedUpdateStatus } from "../../update-cache.js";
// `os.freemem()` on macOS only counts truly-free pages and excludes the large
// "inactive"/cached pool that the OS will reclaim on demand — so total-free
// reads ~95%+ used on an otherwise-idle machine. `os.availableMemory()` (Node
// 22+) reports memory the OS considers available, matching Activity Monitor's
// notion of "used". Fall back to freemem on older runtimes.
function getAvailableMemory(): number {
const fn = (os as unknown as { availableMemory?: () => number }).availableMemory;
if (typeof fn === "function") {
try {
const v = fn.call(os);
if (Number.isFinite(v) && v >= 0) return v;
} catch {
// fall through
}
}
return os.freemem();
}
const TUI_DEBUG_LOG = process.env.FUSION_TUI_DEBUG_LOG;
function tuiDebug(tag: string, data: Record<string, unknown>): void {
if (!TUI_DEBUG_LOG) return;
@@ -236,7 +254,7 @@ export class DashboardTUI {
loadAvg: [load[0] ?? 0, load[1] ?? 0, load[2] ?? 0],
cpuCount: os.cpus().length,
systemTotalMem: os.totalmem(),
systemFreeMem: os.freemem(),
systemFreeMem: getAvailableMemory(),
pid: process.pid,
nodeVersion: process.version,
platform: `${process.platform}/${process.arch}`,
@@ -244,7 +262,7 @@ export class DashboardTUI {
if (this.autoKillVitestOnPressure) {
const total = os.totalmem();
const free = os.freemem();
const free = getAvailableMemory();
if (total > 0) {
const usedRatio = (total - free) / total;
// 30s minimum gap between auto-kills — vitest restart and OS reclaim