Files
loki/scripts/generate-bash-state-vocab.ts
T
Mao NakamotoandClaude Opus 4.8 7432f16053 refactor(runner): rename daemon→runner across the live system, keep legacy contracts
The bash daemon was deleted in Session 4 of killing-the-bash-daemon; Fleet
Runner (the desktop poller) is the local executor now. This retires the
'daemon' name from everything describing the live system — constants
(DAEMON_*→RUNNER_*), types (DaemonStateKey→RunnerStateKey), the status
banner component, state-derivation fns, control props, CSS classes
(ui-control-fleet-daemon→-runner), and comments/UI strings.

Backward-compat shims (no breakage to deployed Fleet Runner installs):
- src/lib/constants/daemon.ts re-exports RUNNER_* under the old DAEMON_*
  names for the desktop Electron build until it points at the runner path.
- Fleet Doctor reads runner.env, falls back to legacy daemon.env.

Deliberately KEPT as 'daemon' (they name the genuinely-dead/legacy thing):
the deprecated DAEMON_TOKEN bearer contract, the /api/agent/daemon 410
tombstone, the legacyDaemon developer download, and historical
killing-the-bash-daemon references. systemctl daemon-reload / NX_DAEMON
left untouched (not ours).

tsc clean · eslint 0 errors · test:home 97/97 · smoke 44/44

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-15 01:05:12 +02:00

74 lines
2.9 KiB
TypeScript

#!/usr/bin/env -S npx tsx
/**
* Generate scripts/control-states.generated.sh from the TS SSOT in
* src/lib/control-states.ts. The bash side sources the generated file and
* uses the variables for user-visible state strings — so adding a state in
* TS keeps the runner, hooks, and UI talking about it with the same words.
*
* Run: npx tsx scripts/generate-bash-state-vocab.ts
* Wired into npm run build via the build:vocab step.
*/
import { writeFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import path from "node:path";
import { PROJECT_STATES, STATE_DEFINITIONS } from "../src/lib/control-states.ts";
const __filename = fileURLToPath(import.meta.url);
const REPO_ROOT = path.resolve(path.dirname(__filename), "..");
const OUT_PATH = path.join(REPO_ROOT, "scripts", "control-states.generated.sh");
function shellQuote(value: string): string {
// Single-quote and escape any embedded single quotes the bash way.
return `'${value.replace(/'/g, `'\\''`)}'`;
}
function bashKey(stateKey: string): string {
// Bash variable names cannot contain hyphens; states use snake_case
// already, so just uppercase.
return stateKey.toUpperCase();
}
const HEADER = `#!/usr/bin/env bash
# GENERATED FILE — DO NOT EDIT BY HAND.
# Source of truth: src/lib/control-states.ts (STATE_DEFINITIONS).
# Regenerate: npx tsx scripts/generate-bash-state-vocab.ts
#
# Variables exposed:
# FC_STATE_KEYS — space-separated list of all state keys
# FC_LABEL_<KEY> — short human label (badge text)
# FC_DESCRIPTION_<KEY> — one-line WHY this state is true
# FC_COUNTER_CATEGORY_<KEY> — chip bucket: working|waiting|idle|offline
#
# Usage from bash:
# source "$(dirname "$0")/control-states.generated.sh"
# echo "$FC_LABEL_OFFLINE" # → "Offline"
# echo "$FC_DESCRIPTION_OPEN_IDLE" # → "Agent process detected …"
`;
const lines: string[] = [HEADER, ""];
lines.push(`FC_STATE_KEYS=${shellQuote(PROJECT_STATES.join(" "))}`);
lines.push("");
for (const key of PROJECT_STATES) {
const def = STATE_DEFINITIONS[key];
const bk = bashKey(key);
lines.push(`FC_LABEL_${bk}=${shellQuote(def.label)}`);
lines.push(`FC_DESCRIPTION_${bk}=${shellQuote(def.description)}`);
lines.push(`FC_COUNTER_CATEGORY_${bk}=${shellQuote(def.counterCategory)}`);
lines.push("");
}
// Sentinel function the runner can call to fail loudly if the generated
// file is out of date with the TS source. Compares the count of state
// keys against an expected number a caller can pin if needed.
lines.push(`# Returns 0 if the generated file looks structurally sane,`);
lines.push(`# 1 if the FC_STATE_KEYS variable is missing or empty.`);
lines.push(`fc_state_vocab_sanity_check() {`);
lines.push(` [ -n "\${FC_STATE_KEYS:-}" ] || return 1`);
lines.push(` return 0`);
lines.push(`}`);
lines.push("");
writeFileSync(OUT_PATH, lines.join("\n"), { mode: 0o644 });
console.log(`✓ wrote ${OUT_PATH} (${PROJECT_STATES.length} states)`);