Extract adapter registry across CLI, server, and UI

Refactor monolithic heartbeat service, AgentConfigForm, and CLI
heartbeat-run into a proper adapter registry pattern. Each adapter
type (process, claude-local, codex-local, http) gets its own module
with server-side execution logic, CLI invocation, and UI config form.
Significantly reduces file sizes and enables adding new adapters
without touching core code.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Forgotten 2026-02-18 13:53:03 -06:00
parent 3a91ecbae3
commit 47ccd946b6
52 changed files with 1961 additions and 1361 deletions

View file

@ -0,0 +1,56 @@
import pc from "picocolors";
export function printCodexStreamEvent(raw: string, _debug: boolean): void {
const line = raw.trim();
if (!line) return;
let parsed: Record<string, unknown> | null = null;
try {
parsed = JSON.parse(line) as Record<string, unknown>;
} catch {
console.log(line);
return;
}
const type = typeof parsed.type === "string" ? parsed.type : "";
if (type === "thread.started") {
const threadId = typeof parsed.thread_id === "string" ? parsed.thread_id : "";
console.log(pc.blue(`Codex thread started${threadId ? ` (session: ${threadId})` : ""}`));
return;
}
if (type === "item.completed") {
const item =
typeof parsed.item === "object" && parsed.item !== null && !Array.isArray(parsed.item)
? (parsed.item as Record<string, unknown>)
: null;
if (item) {
const itemType = typeof item.type === "string" ? item.type : "";
if (itemType === "agent_message") {
const text = typeof item.text === "string" ? item.text : "";
if (text) console.log(pc.green(`assistant: ${text}`));
} else if (itemType === "tool_use") {
const name = typeof item.name === "string" ? item.name : "unknown";
console.log(pc.yellow(`tool_call: ${name}`));
}
}
return;
}
if (type === "turn.completed") {
const usage =
typeof parsed.usage === "object" && parsed.usage !== null && !Array.isArray(parsed.usage)
? (parsed.usage as Record<string, unknown>)
: {};
const input = Number(usage.input_tokens ?? 0);
const output = Number(usage.output_tokens ?? 0);
const cached = Number(usage.cached_input_tokens ?? 0);
console.log(
pc.blue(`tokens: in=${input} out=${output} cached=${cached}`),
);
return;
}
console.log(line);
}