Add mechanicus-banner extension — custom top header

Replaces pi's default header (logo + keybind hints) with a centered
banner featuring:

- Brass frame with rust ⚙ cog bookends on each horizontal rail
- Top line: rust cog-tooth hints (▲▲▲) flanking gold ✠ crosses and a
  blood-red "L E X  M E C H A N I C U S"
- Middle line: gold ☠ skulls flanking a muted "OMNISSIAH BE PRAISED ·
  DEUS EX MACHINA"
- Bottom line: dim "B I N A R Y   I S   B L E S S E D" between em dashes

Colors resolve through the active pi theme (border, borderAccent, accent,
warning, muted, dim) so the banner adapts if the theme changes, but it
was designed for the dark-mechanicus palette added earlier.

Toggle via /mechanicus-banner-on / /mechanicus-banner-off. Installed
automatically on session_start.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-23 21:42:20 +02:00
parent f16c41a47c
commit 3e46dae17d
2 changed files with 101 additions and 0 deletions
+1
View File
@@ -10,5 +10,6 @@
!/README.md
!/ai-server/
!/local-llama.ts
!/mechanicus-banner.ts
!/scripts/
!/themes/
+100
View File
@@ -0,0 +1,100 @@
import type { ExtensionAPI, Theme } from "@mariozechner/pi-coding-agent";
// ─── Banner renderer ─────────────────────────────────────────────────────
function renderBanner(theme: Theme, width: number): string[] {
const W = Math.max(width, 60);
const brass = (s: string) => theme.fg("border", s);
const rust = (s: string) => theme.fg("borderAccent", s);
const blood = (s: string) => theme.fg("accent", s);
const gold = (s: string) => theme.fg("warning", s);
const muted = (s: string) => theme.fg("muted", s);
const dim = (s: string) => theme.fg("dim", s);
// Top / bottom bars with ⚙ cog bookends and brass rails
const innerRail = Math.max(0, W - 8);
const top =
brass("╔═ ") + rust("⚙") + brass(" " + "═".repeat(innerRail) + " ") + rust("⚙") + brass(" ═╗");
const bot =
brass("╚═ ") + rust("⚙") + brass(" " + "═".repeat(innerRail) + " ") + rust("⚙") + brass(" ═╝");
// Centred interior line. `parts` is a list of [rawText, colorFn]; the raw
// length is used for padding so ANSI codes don't break centering.
const line = (parts: Array<[string, (s: string) => string]>): string => {
const rawLen = parts.reduce((acc, [t]) => acc + t.length, 0);
const inner = Math.max(0, W - 2);
const leftPad = Math.max(0, Math.floor((inner - rawLen) / 2));
const rightPad = Math.max(0, inner - rawLen - leftPad);
const body = parts.map(([t, f]) => f(t)).join("");
return brass("║") + " ".repeat(leftPad) + body + " ".repeat(rightPad) + brass("║");
};
const blank = brass("║") + " ".repeat(Math.max(0, W - 2)) + brass("║");
// Cog teeth hint on either side of the skull glyph — the half-cog feel
// without committing to multi-line ASCII art.
const cogTeeth = "▲▲▲";
return [
top,
blank,
line([
[cogTeeth + " ", rust],
["✠ ", gold],
["L E X M E C H A N I C U S", blood],
[" ✠", gold],
[" " + cogTeeth, rust],
]),
line([
["☠ ", gold],
["OMNISSIAH BE PRAISED · DEUS EX MACHINA", muted],
[" ☠", gold],
]),
line([
["── ", dim],
["B I N A R Y I S B L E S S E D", dim],
[" ──", dim],
]),
blank,
bot,
];
}
// ─── Extension ───────────────────────────────────────────────────────────
export default function (pi: ExtensionAPI) {
let installed = false;
const install = (ctx: any) => {
if (!ctx.hasUI) return;
ctx.ui.setHeader((_tui: unknown, theme: Theme) => ({
render(width: number): string[] {
return renderBanner(theme, width);
},
invalidate() {},
}));
installed = true;
};
pi.on("session_start", async (_event, ctx) => {
install(ctx);
});
pi.registerCommand("mechanicus-banner-on", {
description: "Show the dark-mechanicus banner at the top of the TUI",
handler: async (_args, ctx) => {
install(ctx);
ctx.ui.notify("Banner active — Omnissiah be praised.", "info");
},
});
pi.registerCommand("mechanicus-banner-off", {
description: "Restore pi's default header",
handler: async (_args, ctx) => {
ctx.ui.setHeader(undefined);
installed = false;
ctx.ui.notify("Default header restored.", "info");
},
});
}