mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 08:47:02 +01:00
* chore: add a formatter, matching the style this repo already writes singleQuote=false was chosen by counting this repo's own imports, not by fleet decree. The fleet is genuinely split and the two repos that already had a .prettierrc disagreed with each other, so there was no standard to restore. Quote style does not cross repo boundaries; having a gate does. Markdown is ignored for now — prettier rewraps prose, which would bury the real diff. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * style: format with prettier (1062 files) Mechanical. No behaviour change. This SHA is listed in .git-blame-ignore-revs so `git blame` skips it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * chore: teach git blame to skip the reformat Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * fix(lint): reattach two guards the reformat detached Both effects were one-liners, so a trailing eslint-disable-line covered the setState call: useEffect(() => { setSelected(new Set()); }, [q.length]); // eslint-disable-line ... prettier expanded the block. The comment stayed on the closing line while the call moved above it, so the guard protected nothing and the rule its author had deliberately silenced failed the build. This is the second shape of the same defect — hirnli had the eslint-disable-NEXT-line variant. Both come from the same fact: an eslint directive binds to a line number, so reformatting can silently unbind it, which makes 'mechanical, no behaviour change' false for any bulk reformat. * chore(desktop): bump the runner version the reformat requires desktop-release-drift enforces that anything built into Fleet Runner which differs from the last released tag must carry a version ahead of that tag — main read 0.8.15 and fleet-runner-v0.8.15 already shipped. A whole-repo reformat changes bytes under desktop/, so the gate fires. The alternative was adding desktop/ to .prettierignore, which would buy a quiet PR by carving a permanent hole in the formatter's coverage — the precise shape of silent drift this test was written to catch. Bumping is what the rule asks for and costs one patch release whose only content is whitespace. * chore: merge main and re-format A whole-repo reformat conflicts with any concurrent commit, and a conflicting PR runs no checks at all while reporting nothing. Conflicts resolved to main, which is correct because this branch changes formatting and nothing else. * chore: leave desktop/ out of this reformat desktop-release-drift is right to refuse this. Everything under desktop/ is built into Fleet Runner, so changing it means shipping: bump the version AND add a FLEET_RUNNER_RELEASES entry, whose stated audience is 'person who installed Fleet Runner and wants to know what changed'. For a whitespace-only build the honest answer is 'nothing', so that release should not exist — and I should not write release notes claiming otherwise. I had bumped to 0.8.16 to get the gate green. That was the wrong direction: publishing a build to three OS runners to keep a formatting PR quiet. Reverted. desktop/ is excluded in .prettierignore with the reasoning recorded there, to be formatted alongside the next real runner change, where the bump and the notes are true anyway. --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
141 lines
5.1 KiB
TypeScript
141 lines
5.1 KiB
TypeScript
/**
|
|
* 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 { readFileSync } from "fs";
|
|
import { dirname, join } from "path";
|
|
import { fileURLToPath } from "url";
|
|
import {
|
|
startPoller,
|
|
stopPoller,
|
|
onPollerStatus,
|
|
formatTrayTooltip,
|
|
} from "../desktop/src/main/poller";
|
|
import { pushNow, startPusher, stopPusher } from "../desktop/src/main/pusher";
|
|
import { loadToken } from "../desktop/src/main/token-store";
|
|
import { APP_URL } from "@/config/brand";
|
|
import { startWatcher } from "../home/watcher";
|
|
|
|
/**
|
|
* Version comes from the deployed code itself (desktop/package.json — the
|
|
* modules this runner actually executes), never from a hand-maintained env.
|
|
* The systemd unit pinned FLEETCROWN_RUNNER_VERSION=box-0.8.9 and nobody
|
|
* bumped it across three releases, so Settings showed a version the box was
|
|
* not running. Env stays as fallback only for the odd manual invocation.
|
|
*/
|
|
function boxRunnerVersion(): string {
|
|
try {
|
|
const pkgPath = join(dirname(fileURLToPath(import.meta.url)), "..", "desktop", "package.json");
|
|
const pkg = JSON.parse(readFileSync(pkgPath, "utf8")) as { version?: string };
|
|
if (pkg.version) return `box-${pkg.version}`;
|
|
} catch {
|
|
/* fall through to env */
|
|
}
|
|
return process.env.FLEETCROWN_RUNNER_VERSION ?? "box";
|
|
}
|
|
|
|
const VERSION = boxRunnerVersion();
|
|
// The pusher reports whatever this env holds (lazily) — publish the derived
|
|
// version so the heartbeat and Settings agree with the log line below.
|
|
process.env.FLEETCROWN_RUNNER_VERSION = VERSION;
|
|
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"})`,
|
|
);
|
|
|
|
// The desktop refreshes a tray tooltip from every poller status event
|
|
// (~every 2s). Headless, that verbatim stream wrote "connected · last poll
|
|
// 0s ago" to journald 40k times a day. Log only when the STATE changes
|
|
// (ignoring the volatile "last poll Ns ago" segment), plus a 15-minute
|
|
// liveness heartbeat so a quiet journal still proves the runner is alive.
|
|
let lastStatusLine = "";
|
|
let lastHeartbeatMs = 0;
|
|
onPollerStatus((s) => {
|
|
const line = formatTrayTooltip(s);
|
|
const stable = line.replace(/ · last poll \d+s ago/, "");
|
|
const now = Date.now();
|
|
if (stable !== lastStatusLine || now - lastHeartbeatMs > 15 * 60 * 1000) {
|
|
lastStatusLine = stable;
|
|
lastHeartbeatMs = now;
|
|
log(line);
|
|
}
|
|
});
|
|
|
|
// Unlike the desktop, the box has no static projects.conf: its projects are
|
|
// cloned on demand. Watch every FleetCrown-owned handoff and push immediately
|
|
// so a completed run never waits for the five-minute liveness heartbeat.
|
|
const watcher = startWatcher({
|
|
acceptUnregistered: true,
|
|
onIdle: () => {
|
|
void pushNow();
|
|
},
|
|
});
|
|
|
|
// Poller starts the bridge subscriber (presence + fast-path wake) itself; the
|
|
// pusher publishes runtime state and the watcher pushes completion handoffs.
|
|
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 */
|
|
}
|
|
try {
|
|
watcher.close();
|
|
} 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();
|