Files
loki/home/render.ts
CatoandClaude Fable 5.1 95c40a9cd8 refactor: rename the product from FleetCrown to Loki (#695)
The product, its assistant, the repo, the host and every unit on the box now
share one name. 638 files, ~3,000 mentions: UI copy, config, env keys
(FLEETCROWN_* -> LOKI_*), systemd units (fleetcrown-* -> loki-*), docs,
articles, the deploy workflow other repos reuse, and nine file names.

- Three article slugs carried the old name and had been shared; permanent
  redirects keep those links alive (next.config.ts).
- test-no-retired-name.sh now also forbids the old product name across the
  whole repo, so the rename cannot creep back through templates and examples.
- ASSISTANT_STACK collapses the product and the assistant into one entry,
  because they are now the same name.

Infra was cut over ahead of this merge: /opt/loki, loki-* units, the `loki`
database and role, loki.orangecat.ch (old host 308s to it; /api, /widget,
/embed keep proxying), GitHub repos bitbaum/loki and bitbaum/loki-releases.
The Resend sending domain stays fleetcrown.orangecat.ch until the new domain
is verified in DNS.


Claude-Session: https://claude.ai/code/session_016YJVAanfj8keVSXyZnTemh

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-13 16:13:10 -07:00

149 lines
5.3 KiB
TypeScript

/**
* Render a dispatch prompt.
*
* Reuses src/lib/orchestration/renderers.ts:renderTaskForAdapter as the SSOT
* for the prompt text — duplicating the per-intent bodies in home/ would
* diverge from the existing system as either side evolves. This module is
* a thin adapter: home/-side input shape in, plain string out.
*
* Why thin: the worker layer (M7+ next milestone) will inject this string
* directly into a zellij tab via send-text. No further transformation in
* between.
*/
import type { AdapterId, OrchestrationTaskIntentId } from "@/lib/orchestration";
import { ORCHESTRATION_TASK_INTENT_IDS, renderTaskForAdapter } from "@/lib/orchestration";
export type RenderInput = {
/** Project name from the events (zellij tab / display name). */
project: string;
/** Filesystem path. Falls back to project name if absent — the renderer uses
* this in lines like "Work on the project at <path>"; an agent already in
* the right cwd doesn't strictly need it, but real paths read better. */
projectPath?: string;
/** Which intent the brain decided on. Must be one of the canonical ids. */
intent: OrchestrationTaskIntentId;
/** Adapter the worker uses. Default claude — same as the current dispatch. */
adapter?: AdapterId;
/** Free-form prompt body when intent === 'custom' (queue items, ad-hoc text). */
customInstructions?: string;
/** Optional snapshot of the user's prompt queue for this project. Threaded
* through to renderTaskForAdapter so the dispatched prompt body surfaces
* "User's prompt queue for this project" — symmetric with the cloud
* /api/orchestration/run path (RunOrchestrationBody.queue). Without this,
* home/'s autonomous dispatches would render the bare next_best scan
* instruction with no queue context. */
queue?: string[];
};
export function renderPromptForDispatch(input: RenderInput): string {
return renderTaskForAdapter({
projectKey: input.project,
projectPath: input.projectPath ?? input.project,
adapter: input.adapter ?? "claude",
intent: input.intent,
customInstructions: input.customInstructions,
queue: input.queue,
});
}
// ── Self-test ────────────────────────────────────────────────────────────────
// Run with: npx tsx home/render.ts
// Asserts every canonical intent produces a non-empty string, "custom"
// echoes its customInstructions, and the queue field threads through to
// renderQueueBlock in the underlying renderTaskForAdapter.
function selfTest() {
let pass = 0,
fail = 0;
for (const intent of ORCHESTRATION_TASK_INTENT_IDS) {
const customBody = intent === "custom" ? "run security audit on Loki" : undefined;
const out = renderPromptForDispatch({
project: "Loki",
projectPath: "/home/g/dev/loki",
intent,
customInstructions: customBody,
});
const ok = out.length > 0 && (intent !== "custom" || out.includes("security audit"));
if (ok) {
console.log(` ✓ ${intent}`);
pass++;
} else {
console.log(` ✗ ${intent} → got: ${JSON.stringify(out).slice(0, 100)}`);
fail++;
}
}
// Queue-block regression coverage — pins the contract that 1cacfd2 +
// e6bd03b rely on. If a future change to renderQueueBlock breaks the
// "User's prompt queue" header or the item ordering, these tests fail.
const queueCases: { name: string; check: () => boolean }[] = [
{
name: "queue items render under 'User's prompt queue for this project'",
check: () => {
const out = renderPromptForDispatch({
project: "Loki",
intent: "next_best",
queue: ["fix tests", "ship the docs"],
});
return (
out.includes("User's prompt queue for this project") &&
out.includes("1. fix tests") &&
out.includes("2. ship the docs")
);
},
},
{
name: "empty queue → no queue block rendered",
check: () => {
const out = renderPromptForDispatch({
project: "Loki",
intent: "next_best",
queue: [],
});
return !out.includes("User's prompt queue");
},
},
{
name: "undefined queue → no queue block rendered (back-compat)",
check: () => {
const out = renderPromptForDispatch({ project: "Loki", intent: "next_best" });
return !out.includes("User's prompt queue");
},
},
{
name: "queue > 10 items shows the first 10 plus an overflow indicator",
check: () => {
const items = Array.from({ length: 13 }, (_, i) => `item ${i + 1}`);
const out = renderPromptForDispatch({
project: "Loki",
intent: "next_best",
queue: items,
});
return (
out.includes("1. item 1") &&
out.includes("10. item 10") &&
!out.includes("11. item 11") &&
out.includes("…and 3 more")
);
},
},
];
for (const c of queueCases) {
if (c.check()) {
console.log(` ✓ ${c.name}`);
pass++;
} else {
console.log(` ✗ ${c.name}`);
fail++;
}
}
console.log(`\n${pass}/${pass + fail} intents render`);
if (fail > 0) process.exit(1);
}
if (import.meta.url === `file://${process.argv[1]}`) {
selfTest();
}