feat(runner): headless box-runner scaffolding (P1) — Electron-free core + entry

Make the desktop runner core runnable headless on the box. pusher.ts loses its
lone Electron dependency (app.getVersion() → FLEETCROWN_RUNNER_VERSION env, set
by the desktop in index.ts so its behavior is unchanged). scripts/box-runner.ts
is the systemd entry: reuses the EXACT desktop poller + pusher (claim → execute
in owned PTY → stream → ack, presence via bridge SSE), graceful shutdown, run
via tsx from /opt/fleetcrown/runner. See docs/architecture/box-owned-pty-executor.md.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Mao NakamotoandClaude Opus 4.8 committed 2026-06-26 11:13:10 +02:00
1 parent b5cd3e343c
commit b62e3aeb19
3 files changed
+80 -2

No files matched your search

+5
View File
@@ -839,6 +839,11 @@ app.whenReady().then(async () => {
// Set app user model id for windows
electronApp.setAppUserModelId('com.fleetcrown.fleet-runner')
// Hand the desktop's version to the now-Electron-free pusher (it reads this
// env so the same module runs in the headless box-runner). Set before any
// pusher start below.
process.env.FLEETCROWN_RUNNER_VERSION = app.getVersion()
// Crash reporting via Sentry — opt-in. The SDK is no-op until a DSN is
// present in the environment (SENTRY_DSN or VITE_SENTRY_DSN), so this
// ships silent by default. When the Sentry project is created and the
+7 -2
View File
@@ -28,7 +28,6 @@
* the pusher's 30s cadence would slip. Two timers, two responsibilities.
*/
import { app } from 'electron'
import { getZellijTabs } from '@/lib/zellij'
import { APP_URL } from '@/config/brand'
import { DAEMON_HEARTBEAT_MS } from '@/lib/constants/daemon'
@@ -39,6 +38,12 @@ import type { PaneRecord } from '@/db/schema/runtime-snapshots'
import { loadToken, clearToken, isDevBaseOverride } from './token-store'
import { listPtyTabs } from './pty-runtime'
// Runner version is reported in the runtime-state heartbeat. The desktop sets
// FLEETCROWN_RUNNER_VERSION from app.getVersion() before starting the pusher
// (so this module stays Electron-free and importable by the headless
// box-runner); the box-runner sets it from systemd. Fallback keeps it defined.
const RUNNER_VERSION = process.env.FLEETCROWN_RUNNER_VERSION ?? 'dev'
const DEFAULT_SESSION_NAME = 'fleet'
// v0.6 — liveness heartbeat ONLY. Actual state changes are pushed via
@@ -104,7 +109,7 @@ async function pushOnce(): Promise<void> {
installedAgents,
projects,
panes,
runnerVersion: app.getVersion(),
runnerVersion: RUNNER_VERSION,
observedAt: Date.now(),
}),
// Bound the push. Without this, a single hung runtime-state request never
+68
View File
@@ -0,0 +1,68 @@
/**
* Headless FleetCrown box-runner.
*
* The desktop Fleet Runner's core — poller (drains pending_commands), pusher
* (runtime-state heartbeat), bridge subscriber (fast-path wake + presence), and
* owned PTYs (LocalPtyExecutor) — running as a systemd service on the always-on
* box, with NO Electron, window, or tray. This is the piece that deletes the
* "laptop must be on" dependency: dispatches execute server-side in
* FleetCrown-owned PTYs, presence stays online via the bridge SSE connection,
* and it survives web-app deploys because it is its own service.
*
* It reuses the EXACT desktop modules (desktop/src/main/{poller,pusher,...}) —
* that core is already Electron-free (pusher's lone app.getVersion() was lifted
* to FLEETCROWN_RUNNER_VERSION). Same control-plane contract as the desktop:
* HTTP + a ck_ runner token, no direct DB. Run via tsx from
* /opt/fleetcrown/runner. See docs/architecture/box-owned-pty-executor.md.
*/
import { startPoller, stopPoller, onPollerStatus, formatTrayTooltip } from "../desktop/src/main/poller";
import { startPusher, stopPusher } from "../desktop/src/main/pusher";
import { loadToken } from "../desktop/src/main/token-store";
import { APP_URL } from "@/config/brand";
const VERSION = process.env.FLEETCROWN_RUNNER_VERSION ?? "box";
const WEB = (process.env.FLEETCROWN_WEB_URL || "").trim() || APP_URL;
function log(msg: string): void {
// journald captures stdout; keep a stable prefix for `journalctl -u`.
console.log(`[box-runner] ${msg}`);
}
function main(): void {
const token = loadToken();
if (!token) {
console.error(
"[box-runner] no runner token at ~/.config/fleetcrown/fleet-runner-token — cannot authenticate. Exiting.",
);
process.exit(1);
}
log(`v${VERSION} → ${WEB} (token ${token.slice(0, 9)}…, PTY=${process.env.FLEETCROWN_RUNNER_PTY !== "false"})`);
onPollerStatus((s) => log(formatTrayTooltip(s)));
// Poller starts the bridge subscriber (presence + fast-path wake) itself; the
// pusher publishes the runtime-state heartbeat. Together they are the whole
// runner: claim → execute in an owned PTY → stream → ack, presence online.
startPoller();
startPusher();
log("poller + pusher started; presence via bridge SSE");
let shuttingDown = false;
const shutdown = (sig: string): void => {
if (shuttingDown) return;
shuttingDown = true;
log(`${sig} → draining`);
try { stopPoller(); } catch { /* best-effort */ }
try { stopPusher(); } catch { /* best-effort */ }
// Let in-flight stop work settle, then exit so systemd sees a clean stop.
setTimeout(() => process.exit(0), 300);
};
process.on("SIGTERM", () => shutdown("SIGTERM"));
process.on("SIGINT", () => shutdown("SIGINT"));
// Nothing else holds the event loop open (poller/pusher run on timers), so
// keep the process alive explicitly until a signal arrives.
setInterval(() => { /* keep-alive */ }, 1 << 30);
}
main();