feat: compatibility contract, trace field, git-install ergonomics - #45
Conversation
theDakshJaitly
left a comment
There was a problem hiding this comment.
Mostly looks good — one real issue and two things worth knowing.
Please fix before merge
COMPATIBILITY.md lists LogOpts as a public type, but it's not actually exported from src/index.ts. The doc at line 23 includes `LogOpts` in the type surface, and the JSDoc for the new `trace` field references it, but `src/index.ts` only exports `EventEntry` and `EventKind` from `events.js`. The smoke test doesn't import `LogOpts` either, so the contract this PR documents drifts from the code on day one.
Fix one of:
- Add `LogOpts` to `src/index.ts` exports and to the `test/public-api.test.ts` type imports (preferred — `appendEvent` callers benefit from the typed opts shape), or
- Drop `LogOpts` from `COMPATIBILITY.md`.
Things worth knowing (not blockers)
-
preparescript runs on every localnpm installin this repo, not just consumer git-URL installs. A broken build will now block local installs andnpm publish. The trade-off is fine — just flagging it for future debugging when an install fails for a non-obvious reason. -
npm publishwill now auto-build becauseprepareruns in the pack step. So the publish flow becomes a singlenpm publish— no separatenpm run buildneeded. Worth noting in any release docs you keep.
What's good
EventEntry.traceis genuinely additive —readEventspreserves it when present, ignores it when absent, so olddecisions.jsonllines round-trip unchanged. The two new tests cover both cases.COMPATIBILITY.mdis well-scoped: hard vs. "soft" exports, embedder/mex boundary inside.mex/, explicit.mex/traces/and.mex/failures/carve-outs, honest about CLI-flag best-effort policy.preparescript genuinely fixes the git-URL install workflow that was broken before.
All 155 tests pass locally (153 prior + 2 new). CI green on Node 20/22.
theDakshJaitly
left a comment
There was a problem hiding this comment.
LGTM — LogOpts mismatch fixed, and binding the test opts as LogOpts means the contract drift can't recur silently. Approving and merging.
What
Three changes that round out the public-API work from #44:
COMPATIBILITY.mdat the repo root — written contract for embedders.Defines the public surface (everything re-exported from
src/index.ts),semver interpretation (additive minors, breaking majors), the "soft" exports
whose names are stable but contents aren't (
DEFAULT_SCAFFOLD_PATTERNS,DEFAULT_HEARTBEAT_PATTERNS), scaffold-directory ownership (which pathsinside
.mex/mex owns vs. reserves for embedders, including.mex/traces/and
.mex/failures/), the CLI-flag policy, and the deprecation window.EventEntry.trace?: string— optional field on event-log entries,pointing at a long-form trace document (free-form string, typically a path
under
.mex/traces/). Wired throughappendEvent(acceptstraceinLogOpts) andreadEvents(preserved when present, ignored when absent —so old log lines parse unchanged). Lets embedders that need richer context
per event link to it without forking the event format.
"prepare": "npm run build"inpackage.json— sonpm install github:<fork>/mexbuildsdist/automatically inside theconsumer's
node_modules. Without this, git-URL installs resolve but shipno
dist/, and the consumer has tocd node_modules/mex-agent && npm run buildmanually.
COMPATIBILITY.mdis also added to thefilesarray so it shipswith published packages.
Also re-adds the
COMPATIBILITY.mdJSDoc references insrc/index.tsandtest/public-api.test.tsthat were stripped during the review of #44 — thedoc didn't exist then; now it does.
Why
mex-agentinto something embedders candepend on without pinning exact versions or guessing at stability. The
scaffold-ownership section in particular prevents future namespace
collisions between mex and tools building on top of it.
tracefield is the minimum data-model change needed for tools thatcapture longer-form decision context to coexist with mex's event log.
Strictly additive —
traceis optional, defaults to absent, and old loglines round-trip unchanged.
prepareremoves the manualnpm run buildstep for anyone installingfrom a fork branch, which is the workflow embedders use during development
before a release is on npm.
Type of change
How to test
npm run typecheck— clean.npm test— 155 tests total; 2 new trace round-trip tests intest/public-api.test.tspass. Pre-existing Windows path-separatorfailures in
test/heartbeat.test.ts:38andtest/scanner.test.ts:56areunrelated to this PR (still failing on
main, pass on Linux CI).npm run build—dist/index.d.tsgrows slightly to include the newtrace?: stringfield onEventEntryandLogOpts.appendEvent(config, "msg", { kind: "decision", trace: ".mex/traces/foo.md" }),then
readEvents(config)— the trace string should come back. Appendanother event without
trace; reading it back,traceshould beundefined.Checklist
npm test) — 153 green; 2 pre-existing Windows failuresunrelated.
field, new script entry, new docs.
Windows.