feat(protocol): wire contract, canonical reducer and golden fixtures

- v1 envelope across browser/daemon/plugin
- SessionState model + reducer rules (pi events + pi2:* derived events)
- fixtures for basic turn, queue/todo/attention and abort/exit
- 9 conformance tests pinning the reducer
This commit is contained in:
yuez committed 2026-10-21 10:58:46 +08:00
commit 9d817f35b7
19 files changed
+2922

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
/**
* Regenerates `fixtures/<case>/expected.json` from the canonical reducer.
*
* pnpm tsx scripts/gen-expected.ts
*
* The generated files are reviewed and committed; both the TypeScript and the
* Lua reducers must reproduce them exactly (see `test/reducer.conformance.test.ts`
* and `pi2.nvim/tests/web_state_conformance_spec.lua`).
*/
import { readFileSync, writeFileSync, readdirSync, existsSync } from "node:fs";
import { join } from "node:path";
import { reduceAll } from "../src/protocol/reducer.js";
import type { SessionEvent } from "../src/protocol/types.js";
const root = join(import.meta.dirname, "..", "fixtures");
for (const name of readdirSync(root)) {
const dir = join(root, name);
const eventsPath = join(dir, "events.jsonl");
if (!existsSync(eventsPath)) continue;
const events = readFileSync(eventsPath, "utf8")
.split("\n")
.filter((line) => line.trim().length > 0)
.map((line) => JSON.parse(line) as SessionEvent);
const first = events[0]?.session as Record<string, unknown> | undefined;
const state = reduceAll(
{
sessionId: name,
workspaceId: "ws-fixture",
cwd: typeof first?.cwd === "string" ? first.cwd : "/repo",
},
events,
);
const out = join(dir, "expected.json");
writeFileSync(out, JSON.stringify(state, null, 2) + "\n");
console.log(`wrote ${out}`);
}