refactor: collapse duplicated guards and helpers onto canonical modules - #348
Conversation
Round 1 of a repo-wide simplification pass: ~30 hand-rolled isRecord copies now import the strict-json/client-helpers canonicals, freeze.ts and sameRuntimeBinding each get one home, validateCommands/validateRules merge into one parameterized validator, Effect.gen wrappers move to Effect.fnUntraced per the v4 docs, and dead branches in the workbench MCP client are removed. Also caches sqlite prepared statements per store, parallelizes dev rebuild directory walks, and adds reconnect backoff plus a consent-poll render guard in the Workbench.
POSIX path helpers get one home in core/paths.ts (toPosixPath/ toPosixRelative plus exists/resolveContained), key-shape guards consolidate onto hasExactOwnKeys and a new hasOnlyOwnKeys canonical, and the state drivers share their input validators via state/contract. Removes the dead Mcp component-set guard, the sqlite #commit rebinding block (Effect.gen self idiom), the Lease double-cast, a triplicated abortError, duplicated routes AST helpers, and the scaffolder's hardcoded default-targets literal. Audiobook example consolidates errorMessage and probes inventory files concurrently.
Document depth/node-count limits get one source shared by snapshotting, JSON budgets, and Flight decode; Ajv issue plumbing collapses into schemas/ajv-issues.ts; mount/index.ts replaces callback-threaded module state with a slot factory; and exists/resolveContained/expectRevision validators join their canonicals. Route-graph compile now reads each module once, Workbench trace lists cache pretty-printed JSON in WeakMaps, and the rebuild directory walks are bounded to eight concurrent readdirs after review flagged EMFILE risk in the unbounded fan-out.
Ten residual record guards move onto the strict-json canonicals per the verified semantics catalog: plain C1 guards (eval-routes, codex-events, claude adapter, skills parse-ir) onto isRecord, plain-or-null-prototype C3b guards (eval config, config validate, build manifest and inspect-bundler, host-profiles config extensions, workbench runtime-model) onto isPlainRecord/isJsonRecord, with retyped aliases where JSON-narrowing call sites depend on it. Prototype-only C3a hardening guards and package-boundary copies stay by design.
The guard-catalog swap re-exported isMcpAppConsentCapability through contracts/mcp-apps.ts from mcp-app-sandbox.ts, dragging the sandbox's node:crypto/http/net imports into the Workbench browser bundle. Move the capability vocabulary into the browser-safe mcp-app-consent.ts module and re-export it from the sandbox for its server-side consumers.
Main's bin-entry emission (landed after this branch diverged) called the node:path relative directly; the round-2 consolidation removed that import in favor of the canonical helper. Swap the new call site onto the helper.
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…utput-neutral refactor)
…thout one (#410) * chore(changesets): backfill changesets for merged PRs that shipped without one Thirteen merged PRs changed a publishable package's shipped surface without a changeset. Each gets a patch entry named for the PR (backfill-pr-<N>.md) with a user-facing summary and the PR reference, per .changeset/README.md. * chore(changesets): rewrite backfill summaries in imperative, consumer-first form * chore(changesets): drop test-only detail from the #118 backfill summary * chore(changesets): scope the #164 backfill to the runtime and name the surfaces behind dependency bumps * chore(changesets): drop create-agent-bundle from the #348 backfill (output-neutral refactor)
Summary
Lands the four-round cross-cutting dedup from the multi-model review fleet, rebased onto current main (the stale canvas commit was dropped — the
docs/canvasescopy on main via #342 is newer and authoritative):isRecord,isPlainRecord,hasOnly/hasExactOwnKeys,exists,toPosixRelative,errorMessage,isErrno,sleep,canonicalJson, ajv issue mapping,deepFreeze, npm-pack JSON parsing) onto canonical modules incore/,contracts/,schemas/ajv-issues.ts, workbenchclient-helpers.ts, andscripts/npm-pack-json.mjs.as consttuple with a shared type guard.walkConcurrency = 8), logs-page reconnect backoff, render-identity preservation to stop 4 Hz workbench re-renders.Rebase-crossing fixes (added on top)
fix(contracts): the guard re-export throughcontracts/mcp-apps.tspulledmcp-app-sandbox.ts'snode:*imports into the Workbench browser bundle; the capability vocabulary now lives in browser-safemcp-app-consent.ts.fix(build): main's new bin-entry emission used therelativeimport the consolidation removed; routed through canonicaltoPosixRelative.binrecovery hint, doctor host-contract validators,isValidPackageNamein the Claude adapter.Local gates (authoritative, all green)
pnpm check: build, unit, route-unit, projection, integration, rslint (0/1027 files), typecheckpnpm test:packed(packed-surface scripts were touched)