Problem
apply.ts and list.ts load .thinktank/latest.json with no schema validation:
const result = JSON.parse(fs.readFileSync(..., "utf-8")) as EnsembleResult;
If the file is truncated (e.g. disk full mid-write), written by an older version, or manually edited, JSON.parse throws a generic syntax error and the user sees:
Error: No results found. Run thinktank first.
...with no indication of what actually went wrong.
Solution
Add lightweight schema validation using the existing TypeScript types. A minimal runtime check (not necessarily Zod) would verify:
result.agents is a non-empty array
- Each agent has
id, status, diff
result.recommendation is a valid agent id
function assertValidResult(data: unknown): asserts data is EnsembleResult {
if (!data || typeof data !== "object") throw new Error("Invalid result file: not an object");
const r = data as Record<string, unknown>;
if (!Array.isArray(r.agents) || r.agents.length === 0) {
throw new Error("Invalid result file: missing or empty agents array");
}
// ... etc
}
Acceptance criteria
Problem
apply.tsandlist.tsload.thinktank/latest.jsonwith no schema validation:If the file is truncated (e.g. disk full mid-write), written by an older version, or manually edited,
JSON.parsethrows a generic syntax error and the user sees:...with no indication of what actually went wrong.
Solution
Add lightweight schema validation using the existing TypeScript types. A minimal runtime check (not necessarily Zod) would verify:
result.agentsis a non-empty arrayid,status,diffresult.recommendationis a valid agent idAcceptance criteria
apply,list,compare, andstatsall use the same validation pathagentsfield, missingrecommendation