/** * /lvrged-factory slash commands — human-facing dashboard. All heavy lifting * is in the lvrged_factory_* tools; commands read the same registry. * * Naming convention: factory-general commands live at the top level * (/lvrged-factory setup), domain-specific ones under their domain * (/lvrged-factory gpu status, /lvrged-factory gpu deploy, ...). */ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent"; import { loadProviders, loadDeployments, loadJobs, loadPolicy, monthSpendUsd, todaySpendUsd, fmtUsd } from "./registry.js"; export function registerFactoryCommands(pi: ExtensionAPI) { pi.registerCommand("lvrged-factory", { description: "lvrged-factory dashboard — /lvrged-factory setup · gpu: status, deploy , jobs, spend, stop , policy, onboard", handler: async (args, ctx) => { const a = args.trim(); const [ns, ...rest] = a.split(/\s+/); const sub = rest.join(" "); if (!a) return ctx.ui.notify(factoryDashboard(), "info"); if (ns === "setup" || ns === "s") { return ctx.ui.notify( "Run /lvrged-factory setup (or ask the agent to run lvrged_factory_setup) to detect provider CLIs and authentication.", "info", ); } if (ns === "gpu") { const out = !sub || sub === "dashboard" ? gpuDashboard() : sub === "status" || sub === "st" ? statusView() : sub === "jobs" || sub === "j" ? jobsView() : sub === "spend" ? spendView() : sub === "policy" ? policyView() : sub === "onboard" || sub === "ob" ? onboardCard() : sub.startsWith("stop") || sub.startsWith("destroy") ? `Destroy ${sub.split(/\s+/)[1] || ""}: ask the agent to run lvrged_factory_pod action=destroy (it will confirm spend first).` : sub.startsWith("deploy") ? `Deploy ${sub.split(/\s+/)[1] || ""}: ask the agent to run lvrged_factory_ensure model= — it will find or provision the cheapest fitting deployment.` : gpuDashboard(); return ctx.ui.notify(out, "info"); } return ctx.ui.notify(factoryDashboard(), "info"); }, }); } function factoryDashboard(): string { const gpu = gpuDashboard(); return [ "LVRGED FACTORY", "─────────────", "Domains", " gpu — provision & run GPU video workloads (RunPod — more via adapters)", "", "Commands: /lvrged-factory setup · /lvrged-factory gpu (dashboard) · /lvrged-factory gpu deploy ", "", gpu, ].join("\n"); } function gpuDashboard(): string { const providers = loadProviders(); const deployments = loadDeployments(); const jobs = loadJobs(); const policy = loadPolicy(); const lines = [ "LVRGED-FACTORY GPU", "─────────────────", "Providers", ...providers.map((p) => ` ${p.name.padEnd(10)} ${p.installed && p.authenticated ? "✓" : p.installed ? "○ needs auth" : "○ not installed"}`), "Deployments", ...(deployments.length ? deployments.map((d) => { const dot = d.status === "ready" ? "●" : d.status === "provisioning" ? "◐" : d.status === "stopped" ? "○" : "✕"; return ` ${dot} ${d.id.padEnd(14)} ${d.model || d.runtime} ${d.gpu} @ ${d.provider} ${d.endpoint || ""} (${fmtUsd(d.cost_hr)}/hr)`; }) : [" (none — ask the agent to deploy a model)"]), `Jobs ${jobs.filter((j) => j.status === "running").length} running · ${jobs.filter((j) => j.status === "queued").length} queued · ${jobs.filter((j) => j.status === "completed").length} completed`, `Spend Today ${fmtUsd(todaySpendUsd())} · Month ${fmtUsd(monthSpendUsd())} (ceiling ${fmtUsd(policy.ceiling_monthly_usd)})`, "Commands: /lvrged-factory gpu status · /lvrged-factory gpu deploy · /lvrged-factory gpu jobs · /lvrged-factory gpu spend · /lvrged-factory gpu stop · /lvrged-factory gpu policy", ]; return lines.join("\n"); } function statusView(): string { const providers = loadProviders(); const deployments = loadDeployments(); const lines = [ "STATUS", providers.map((p) => ` ${p.name}: ${p.installed ? (p.authenticated ? "ready" : "installed, needs auth") : "not installed"}`).join("\n"), "", deployments.length ? deployments.map((d) => ` ${d.id} ${d.status.toUpperCase()} ${d.gpu} @ ${d.provider} ${d.endpoint || ""} ${fmtUsd(d.cost_hr)}/hr`).join("\n") : " no deployments", ]; return lines.join("\n"); } function jobsView(): string { const jobs = loadJobs().slice(-15).reverse(); return jobs.length ? jobs.map((j) => `${j.id} ${j.status.padEnd(9)} ${j.workflow} ${j.duration_s ? j.duration_s + "s" : ""} ${j.cost_usd !== undefined ? fmtUsd(j.cost_usd) : ""}`).join("\n") : "No jobs yet."; } function spendView(): string { return `SPEND\n Today: ${fmtUsd(todaySpendUsd())}\n Month: ${fmtUsd(monthSpendUsd())}`; } function policyView(): string { const p = loadPolicy(); return `SPEND POLICY\n per-job ${fmtUsd(p.ceiling_per_job_usd)} · daily ${fmtUsd(p.ceiling_daily_usd)} · monthly ${fmtUsd(p.ceiling_monthly_usd)} · confirm above ${fmtUsd(p.confirm_above_usd)} · idle shutdown after ${p.idle_shutdown_after_min} min`; } function onboardCard(): string { return [ "H3 PRODUCTION — planning numbers (2026-08-12, session-verified where marked)", " 1 finished minute = 4 × 15s clips chained by last-frame carryover", " stack: Turbo LoRA v4 step600 EMA @ 8 steps euler/beta + SageAttention2 + INT8 — never vanilla 20-step", " image: runpod/comfyui:cuda13.0 (official cu130 build; Sage built at install; cu128 is ~2x slower for INT8)", " price (verified): PRO 6000 community $1.69/hr (usually out of stock) · secure $2.09/hr (what you'll pay)", " per finished minute at the 107s/8-step anchor: ~$0.25 secure · $15 buys ~60 min (vs Higgsfield ~1 min)", "Lane: RunPod RTX PRO 6000, 80GB container disk, no network volume. That's it — zero other choices.", "Ask the agent to run the lvrged-factory-gpu-onboarding skill for the full first-run flow.", "Detail: docs/h3-economics.md (benchmark protocol v1 included)", ].join("\n"); }