import type { EntryRecord } from "@earendil-works/pi-durable"; import type { JsonValue } from "@berry/api"; import { extensionRenderers } from "./renderers.ts"; /** An extension event, whether queued or already in the transcript. */ export function event(data: EntryRecord["data"]): Node | null { const { ext, event } = data as { ext: string; event: JsonValue }; const custom = extensionRenderers(ext)?.event?.(event); if (custom === null) return null; // the harness's own events are the codemode store's writes if (ext === "berry" && custom === undefined) { const write = event as { set: Record; delete: string[] }; return (
store · {[...Object.keys(write.set), ...write.delete.map((k) => `-${k}`)].join( ", ", )}
); } // and the machine and directory it works in if (ext === "environment" && custom === undefined) { const { environment, cwd } = event as { environment: string; cwd: string }; return (
cd → {environment === "local" ? cwd : `${environment}:${cwd}`}
); } // and the models it delegates to if (ext === "subagent" && custom === undefined) { const { type, conversationId, models } = event as { type?: string; conversationId?: number; models?: { provider: string; modelId: string }[]; }; if (type === "spawned" || type === "settled") { return
subagent {type} · conversation {String(conversationId)}
; } if (models !== undefined) { return (
subagent models → {models.length === 0 ? "those enabled in settings" : {models.map((m) => `${m.provider}/${m.modelId}`).join(", ")}}
); } } return (
{custom ?? [ {ext}, {JSON.stringify(event)}, ]}
); }