char-slop/berry

multipurpose self-modifiable agentic harness

git clone https://git.t4t.associates/char-slop/berry

Charlotte Somsubagent: show compact lifecycle events2c34403

main
2.0 KiB58 linesraw
1import type { EntryRecord } from "@earendil-works/pi-durable";
2import type { JsonValue } from "@berry/api";
3import { extensionRenderers } from "./renderers.ts";
4
5/** An extension event, whether queued or already in the transcript. */
6export function event(data: EntryRecord["data"]): Node | null {
7  const { ext, event } = data as { ext: string; event: JsonValue };
8  const custom = extensionRenderers(ext)?.event?.(event);
9  if (custom === null) return null;
10  // the harness's own events are the codemode store's writes
11  if (ext === "berry" && custom === undefined) {
12    const write = event as { set: Record<string, JsonValue>; delete: string[] };
13    return (
14      <div class="event">
15        store · {[...Object.keys(write.set), ...write.delete.map((k) => `-${k}`)].join(
16          ", ",
17        )}
18      </div>
19    );
20  }
21  // and the machine and directory it works in
22  if (ext === "environment" && custom === undefined) {
23    const { environment, cwd } = event as { environment: string; cwd: string };
24    return (
25      <div class="event">
26        cd → <code>{environment === "local" ? cwd : `${environment}:${cwd}`}</code>
27      </div>
28    );
29  }
30  // and the models it delegates to
31  if (ext === "subagent" && custom === undefined) {
32    const { type, conversationId, models } = event as {
33      type?: string;
34      conversationId?: number;
35      models?: { provider: string; modelId: string }[];
36    };
37    if (type === "spawned" || type === "settled") {
38      return <div class="event">subagent {type} · conversation {String(conversationId)}</div>;
39    }
40    if (models !== undefined) {
41      return (
42        <div class="event">
43          subagent models → {models.length === 0
44            ? "those enabled in settings"
45            : <code>{models.map((m) => `${m.provider}/${m.modelId}`).join(", ")}</code>}
46        </div>
47      );
48    }
49  }
50  return (
51    <div class="event">
52      {custom ?? [
53        <span class="event-ext">{ext}</span>,
54        <code>{JSON.stringify(event)}</code>,
55      ]}
56    </div>
57  );
58}