Skip to content

refactor: collapse duplicated guards and helpers onto canonical modules - #348

Merged
ScriptedAlchemy merged 6 commits into
mainfrom
docs/platform-services-convention
Sep 3, 2026
Merged

refactor: collapse duplicated guards and helpers onto canonical modules#348
ScriptedAlchemy merged 6 commits into
mainfrom
docs/platform-services-convention

Conversation

@ScriptedAlchemy

Copy link
Copy Markdown
Owner

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/canvases copy on main via #342 is newer and authoritative):

  • Collapses ~40 duplicated local helpers (isRecord, isPlainRecord, hasOnly/hasExactOwnKeys, exists, toPosixRelative, errorMessage, isErrno, sleep, canonicalJson, ajv issue mapping, deepFreeze, npm-pack JSON parsing) onto canonical modules in core/, contracts/, schemas/ajv-issues.ts, workbench client-helpers.ts, and scripts/npm-pack-json.mjs.
  • Guard-catalog swaps verified equivalent one by one: loose vs prototype-checking record guards kept distinct; exact-key vs subset-key contracts kept distinct; the consent-capability vocabulary is now a single as const tuple with a shared type guard.
  • Hot-path fixes riding along: route-graph module text read once into a cache (no per-surface re-reads), sqlite prepared-statement cache, bounded-concurrency directory walks (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 through contracts/mcp-apps.ts pulled mcp-app-sandbox.ts's node:* imports into the Workbench browser bundle; the capability vocabulary now lives in browser-safe mcp-app-consent.ts.
  • fix(build): main's new bin-entry emission used the relative import the consolidation removed; routed through canonical toPosixRelative.
  • Conflict resolutions preserve main's newer behavior: payload-root realpath containment re-check, AB4741 bin recovery hint, doctor host-contract validators, isValidPackageName in the Claude adapter.

Local gates (authoritative, all green)

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.
@changeset-bot

changeset-bot Bot commented Sep 3, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: a6afc91

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@ScriptedAlchemy
ScriptedAlchemy merged commit 43c9126 into main Sep 3, 2026
4 checks passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-03T00:53:42.132326Z a6afc91 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ScriptedAlchemy
ScriptedAlchemy deleted the docs/platform-services-convention branch September 3, 2026 05:24
ScriptedAlchemy added a commit that referenced this pull request Sep 3, 2026
ScriptedAlchemy added a commit that referenced this pull request Sep 3, 2026
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant