import { mkdirSync, writeFileSync, mkdtempSync, realpathSync } from "node:fs"; import { join } from "node:path"; import { tmpdir } from "node:os"; import { createReader } from "../../../../packages/conversation/src/reader.mjs"; const proj = realpathSync(mkdtempSync(join(tmpdir(), "fb-proj-"))); const dir = join(proj, ".pi", "state", "x", "sessions"); mkdirSync(dir, { recursive: true }); const L = (o) => JSON.stringify(o) + "\n"; const msg = (id, parentId, text) => L({ type: "message", id, parentId, timestamp: "2026-09-26T00:00:00Z", message: { role: "user", content: text } }); // a -> b is one branch. X (lost, malformed) was a child of a: a fork. y -> X. writeFileSync(join(dir, "s.jsonl"), L({ type: "session", id: "sess", cwd: proj, timestamp: "2026-09-26T00:00:00Z" }) + msg("a", null, "root") + msg("b", "a", "ON THE OTHER BRANCH") + '{"type":"message","id":"X","parentId":"a","timest\n' + msg("y", "X", "leaf")); const reader = createReader({ roots: [{ seat: "x", project: "p", projectRoot: proj, dir, harness: "pi", unsupportedReason: null, engineStartedAt: null }] }); const conv = reader.catalogue().conversations[0].conversation; const p = reader.open({ conversation: conv }); console.log("branches", JSON.stringify(p.view.branches)); for (const e of p.page.entries) console.log(e.branch, e.role, JSON.stringify(e.content[0].text).slice(0, 90));