Done. This pass ran a fresh bug hunt on subsystems the prior four rounds hadn't examined — the native Ollama client, the media/generative tools, and the tool-result cache — and found four real robustness bugs, all fixed with tests, plus the recurring DRY ask. Pushed to PR #7.
Bugs fixed:
- Native Ollama streaming could die on one bad frame. The
/api/chat NDJSON parser did an unguarded JSON.parse per line, so a single malformed/partial frame threw out of the stream and killed the whole turn. The fable-compat SSE path already tolerated this; the native fallback now matches it (skip the bad frame, keep going). This matters because the native path is the resilience fallback — it shouldn't be more fragile than the primary.
- Corrupt tool-result cache threw on reread.
loadToolResult did a bare JSON.parse; a corrupt cache entry would throw on the reread_tool_result/summarize path. Now it returns null (a cache miss), never throws.
- Failed media downloads were saved as corrupt files. After Meshy/Luma reported success, the follow-up asset GET wrote its body without checking
response.ok — a 403 or HTML error page could land on disk as a .glb/.mp4 and be returned as a successful path (then fail opaquely in Three.js later). Now it throws on !ok, so no corrupt media is written.
- NaN duration poisoned request JSON.
generate_media's duration_seconds went through Number(x), and Number("foo") is NaN (truthy), which serialized to null in the API body. Non-finite durations now fall back to the default. I also guarded 3d_views against an empty image_path (it was reading the workspace root as if it were an image).
DRY (the recurring "dupe code" request): util/json-file.ts — writeJsonFile + readJsonFileSafe — replaces the hand-rolled mkdirSync + writeFileSync(JSON.stringify) pair in six stores (acceptance-gate, goal harness, preferences, interaction-ledger, config, WWM session). Indent is parameterized so each file keeps its exact on-disk format, and I verified dirname(path) equals each site's prior mkdir target so behavior is unchanged.
Verification: 1490 tests pass (new suites for the JSON helpers, native-stream resilience, and generative robustness), typecheck clean on core and app, exec smoke 10/10.
Two flagged items I deliberately did not touch, to protect quality: I left native tool_calls handling as-is (Ollama emits complete tool calls per NDJSON message, not fragments, so "accumulating" them would break current correct behavior), and I did not add workspace-path confinement / SSRF blocking to the file and web tools. That last one the audit rated high, but it's a real behavior change — the agent is trusted-local by design and legitimately reads files outside cwd and fetches localhost during development, so silently sandboxing it could break working workflows. That's a policy decision worth making explicitly rather than slipping into a "quality pass," so I'm surfacing it: if you want the file/web tools confined (workspace-root jail + block file:///metadata IPs), I'll implement it behind a config flag with tests — just say the word.