Repository navigation
feat(schema): zod at tool+viewer boundaries; ISO ts at the store reader (closes #15) - #31
Merged
Merged
Conversation
…ation at the store reader Shape gate, not a meaning gate (the 4-gate pipeline still owns semantics). Single source of truth: the JSON Schema handed to the model is GENERATED from the zod schemas (z.toJSONSchema, $schema stripped, empty required restored) — hand-written wire shapes next to runtime validators would recreate exactly the drift surface zod removes. test/boundaries.test.ts deep-equals all 13 registered tool inputs against a byte-capture taken from main: the model-facing contract did not move. - Tools: every execute() re-parses raw args; malformed calls get "invalid arguments ... nothing was done" naming the fields, instead of a gate message by coincidence or junk reaching appendMemory. z.coerce.number() for numerics (limit:"2" still works — strictly non-breaking); booleans deliberately STRICT: z.coerce.boolean is JS Boolean() and would flip dryRun:"false" into TRUE — a dry run mutating. Verified main's behavior with live probes (restore-entry with an empty body appended a row with empty type/scope/content and got 200; ts=hello loaded as an addressable row; tags was unchecked except where unrelated heuristics caught it). - Viewer: POST bodies are schema-parsed (400 on junk). Closes the restore-entry hole; String(body.ts) is gone, so an object ts can no longer become the row identity "[object Object]". /api/restore keeps its basename+grammar containment (#21) untouched — different job. - Store reader (#15): toMemory rejects a ts that is not an ISO instant (regex + Date.parse for impossible dates); rows are skipped, counted (memory_status/TUI show "N malformed", hidden at 0), warned once per file. logfmt stays a dumb parser; supersede chains, blocklist, undo, and viewer buttons can no longer key off arbitrary strings. - zod is a RUNTIME dependency (npm plugin installs fetch deps only). 14 new tests (wire contract x13 tools, tool-boundary rejects, coercion non-breaking, viewer 400s, reader skip/tally/impossible-date). Suite 235 pass / 4 skip / 0 fail; tsc clean; biome lint 0.
Supply-chain policy: dependencies AND devDependencies are exact-pinned. Consumers resolve our semver ranges at plugin-install time (a lockfile is not their install instruction), so carets, >= ranges, and "latest" were a standing window for any future — including compromised — release to land in every user's process. Updates are now deliberate acts (bun upgrade <pkg>, reviewed lockfile diff, CI). peerDependencies stay ranges by design: they declare tolerance for the host-provided environment (opencode ships the opentui/solid runtime itself), not a fetch target; pinning them would only break hosts on newer versions. optionalDeps codebase-memory-mcp was already exact. Pinned to the versions currently resolved in bun.lock — no upgrades sneaking in under the pin: zod 4.6.7, biome 2.6.2, @opencode/plugin 2.0.32, @OpenTui core+solid 0.6.6, @semantic-release/git 11.0.1, @types/bun 1.4.2 (was "latest"), semantic-release 25.0.9, solid-js 1.9.17, typescript 7.0.2. Suite 235 pass / 0 fail.
abogartz
force-pushed
the
feat/boundary-schemas
branch
from
October 22, 2026 15:59
b0d1ebd to
65fa73b
Compare
|
🎉 This PR is included in version 0.5.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #15. The zod tier from the 2026-10-21 review, kept exactly as scoped then: a shape gate at the input boundaries, nothing functional.
Design
One source of truth. The JSON Schema the model sees is now generated from the zod schemas (
z.toJSONSchema,$schemastripped, emptyrequiredrestored). zod-alongside-the-hand-builders would have been two descriptions of one contract — the drift surface we just buried in the artifact cleanup. The test proves the migration is invisible to the model: all 13 registered tool inputs deep-equal a byte-capture taken from main before any code changed.Coercion where intent-preserving, strict where not (the trap that decides this):
z.coerce.number()onlimit/olderThanDays/evidence-limit —limit: "2"means 2 and already worked by downstream accident; coercion cannot break a working flow.z.coerce.boolean()is JSBoolean(), sodryRun: "false"coerces to true — a dry-run call mutating the store. A rejected call returns a message the model can fix; a silent flip does not exist.contentis precisely the garbage-write hole.What lands
execute()re-parses raw args viavalidated(); malformed calls answerinvalid arguments to memory_X — nothing was done: <fields>. Verified against live main first: atagsstring today fails or not depending on unrelated gate heuristics; zod makes the boundary deterministic.: anyis gone from all tool bodies — tsc now checks them against the schema (types flow fromz.infer).POST /api/restore-entry {}returned 200 and appended a row with empty type/scope/content (probe output in commit message);String(body.ts ?? "")madets:{}the row identity"[object Object]"./api/restorekeeps its basename+grammar containment (viewer /api/restore joins raw body.name — files outside the store can be promoted into memory #21) — different job, untouched.toMemoryrejects atsthat is not an ISO instant (regex +Date.parsefor structurally-valid impossibilities like month 13). Malformed rows are skipped by every reader, counted (memory_status/TUI showN malformed, hidden at zero), warned once per file.logfmt.tsstays a dumb tokenizer — the shape check lives where the schema knowledge lives. Supersede chains, the blocklist, undo, and viewer buttons can no longer key off arbitrary identity strings.Deliberately excluded
Semantics (a well-shaped lie still passes — the gates own that),
/api/restorename grammar (containment, not shape), and any zod in the hot read path (a plain ISO check beats schemas over every row).Gate
14 new tests (wire-equality x13, boundary rejects incl. the dryRun string trap, coercion non-breaking, viewer 400s + happy path, reader skip/tally/impossible-date/clean-store-silent). 235 pass / 4 skip / 0 fail,
tsc --noEmitclean, biome lint 0. Probes of main's behavior are in the commit message, not a tracked doc.