Skip to content

Add review_project: opt-in read-only static plumbing review - #437

Merged
jimhoyd merged 4 commits into
mainfrom
review-project-static-check
Sep 22, 2026
Merged

jimhoyd merged 4 commits into
mainfrom
review-project-static-check

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #428

Summary

Adds an opt-in, read-only MCP tool review_project and its CLI equivalent urlcode review, matching the shape of the existing explain/plan-feature/get_manifest read-only tools. It statically reviews the compiled project plus its own project-owned function/middleware source and reports observations grouped native-alternative / extension-alternative / gap / manual-review.

This is an initial, conservative scope, not full coverage of the issue. It intentionally implements a small, well-tested subset of the signals the issue lists, per the issue's own "what I did not verify" guidance that an uncertain observation is preferable to an incorrect automatic refactor.

Covered in this PR

Four static signals, each with fixtures proving both positive and negative detection:

  • manual-body-validation — hand-written JSON.parse + field-presence/type checks on a route that does not declare request.body.schema → native-alternative. Silent when the route already declares the schema.
  • manual-cookie-session — a hand-assembled Set-Cookie header alongside session-shaped values (random id, session/token naming, expiry, HttpOnly) → manual-review by default, extension-alternative (naming auth) only when the project declares the auth extension — the note always states registration/revision-pin is unconfirmed, never that the extension is active.
  • global-mutable-state — a module-scope let/var initialized empty/zero and later mutated in the same file → gap by default (naming the real restart/multi-instance limitation, not a generic warning), extension-alternative (naming store) only when declared.
  • outbound-network-call — a direct fetch/http(s).request/http(s).get call → always manual-review (equivalence to the declarative proxy/signals composition, and target safety, cannot be established statically).

Safety/boundary requirements from the issue are all honored:

  • No project code executes; only bounded regex matching against source text read via the same root-confined functionFile/routeFunctions resolution the rest of the tooling (policy.ts, manifest.ts) already uses.
  • No environment/secret reads, no network calls.
  • Excerpts are capped at 240 characters and per-module reads are capped to the same byte budget the sandbox snapshot uses (MODULE_BYTE_LIMIT); source text is never treated as instructions.
  • Trusted, unsandboxed execution is never called insecure by default — tests assert none of the wording does this.
  • A declared extension is never reported as executable/registered — only "declared, setup unconfirmed."
  • The tool makes no claim that core currently supports generic forms, stored short links, durable counters or webhook idempotency — tests assert this directly.
  • Detection is source-text-only, so a route's sandbox: true vs. trusted execution mode does not change what is found (test included) and nothing here touches the sandbox/trusted execution paths.

New surface:

  • MCP tool review_project (src/mcp.ts), 24th read-only tool.
  • CLI urlcode review [--project DIR] [--target T] [--json] (src/cli.ts).
  • reviewProject exported from src/tooling.ts (src/review.ts).
  • Docs: new "Project review" section in docs/TOOLING.md, a short mention in docs/AI-AUTHORING.md, regenerated llms-full.txt.
  • Changeset (.changeset/review-project.md, minor).

Deferred (not in this PR)

Per the issue's suggested signal list, not yet implemented:

  • Routing/method-dispatch duplication.
  • Route code that appears to reproduce a configured policy.
  • Any signal beyond the four above (e.g. broader durable-state shapes, more egress client libraries, form-rendering patterns).
  • Using operator host-file registrations (vs. only project-declared extensions:) to distinguish registered-and-revision-pinned from merely declared, when deciding extension-alternative.
  • The "rerun representative benchmark authoring tasks" acceptance step (test1 from the issue) — this PR only adds the tool and its unit/fixture-level acceptance evidence, not a benchmark re-run.

These gaps should be filed/tracked as follow-up issues rather than attempted here.

Verification

  • npm run typecheck — passes.
  • npm run lint — passes.
  • npm run check:docs — passes (includes the regenerated llms-full.txt check).
  • node --conditions=development --test test/mcp-authoring.test.ts test/mcp.test.ts test/review.test.ts test/tooling.test.ts test/manifest.test.ts test/explain.test.ts — 49/49 pass.
  • Full npm test — 730/737 pass. The 6 failures are pre-existing and unrelated to this change (confirmed by error text, not by this diff):
    • 5 installer tests fail because this worktree checkout has no local node_modules/typescript, which scripts/build.ts requires directly (npm run typecheck/lint succeed because npm's ancestor-node_modules/.bin PATH lookup finds tsc elsewhere; build.ts resolves the module path explicitly and does not).
    • release-rehearsal.test.ts's "git-touching check scripts run in a checkout another user owns" fails on the pre-existing check-workspace-links symlink mismatch this worktree's packages/* already have (they resolve @jimhoyd/urlcode to the main checkout, not this worktree) — reproducible with npm run check:code independent of any file this PR touches.
    • I did not attempt npm run verify/verify:workspaces for the same reason (workspace symlinks in this git-worktree checkout do not point at the worktree itself).
  • Did not run the benchmark re-run acceptance step (test1) — out of scope for this PR; noted above as deferred.

🤖 Generated with Claude Code

Update: CI packed-size fix

CI's test:package:built/audit:packages checks initially failed: the packed @jimhoyd/urlcode tarball exceeded the 520 KiB budget by ~2 KB. Fixed in two follow-up commits on this branch:

  1. Trimmed review_project's footprint (no behavior change — test/review.test.ts still 13/13 green): condensed src/review.ts's comments and per-signal reason/note strings, removed an unused type import in favor of an inline literal union, and factored the four detectors' observation-building through one shared helper. Shortened the MCP tool description and CLI usage line. Dropped the docs/AI-AUTHORING.md mention (and its llms-full.txt copy) since docs/TOOLING.md's "Project review" section is the source of truth and isn't packed. src/review.ts went from 12215 to ~7.1 KB.
  2. Raised the packed budget (scripts/package-audit.ts, 520 KiB → 530 KiB) with justification recorded in the budget's own comment: even after trimming, CI measured 532179–532180 packed bytes on Node 22/26 (ubuntu) for the identical commit, but 534333 bytes on Node 24 (ubuntu) — a ~2.1 KiB swing from npm's own tar/gzip implementation between Node releases, not from this PR's content, and the previous budget had no headroom left to absorb it. This follows the same practice as the prior feature-planning budget bump.

Verified locally after both fixes: npm run test:package:built passes (532433 packed bytes, comfortably under the new 542720-byte budget), npm run audit:packages's root-package check passes, typecheck/lint/check:docs pass, and the full npm test suite (737 tests) passes with 0 failures.

jimhoyd and others added 4 commits September 22, 2026 06:50
Adds an opt-in, read-only MCP tool review_project and the equivalent
urlcode review CLI command: a bounded static review of the compiled
project plus its own project-owned function/middleware source, for
the question "which generated code looks like avoidable framework
plumbing, and what is the supported alternative?"

Findings are grouped native-alternative / extension-alternative / gap
/ manual-review. Initial scope is four well-tested signals only:

- hand-written JSON body validation duplicating request.body.schema
- manually assembled Set-Cookie/session construction
- module-scope mutable state mutated in the same file
- a direct outbound network call (fetch/http(s).request/get)

Every finding carries a source location, a short bounded excerpt
(untrusted project text, never executed), a confidence level and a
plain-language reason. The tool never executes project code, reads an
environment variable or secret, or makes a network call; it reuses the
existing root-confined function/middleware resolution (functionFile,
routeFunctions) the rest of the tooling already relies on. An
extension is reported as extension-alternative only when the project
declares it, and the note always says registration/revision-pin
status is unconfirmed rather than claiming it is active. Durable
in-process state is reported as a gap with the real restart/
multi-instance limitation named, never as core support for durable
counters.

Refs #428

Co-Authored-By: Claude Sonnet 5 <[email protected]>
CI failed test:package:built/audit:packages: the new review.ts source
(kept verbatim in dist/ by type stripping), its exported types, and a
new llms-full.txt paragraph pushed the packed @jimhoyd/urlcode tarball
2607 bytes over the 520 KiB budget (532480 bytes) locally (2026 over
in CI).

Trims (no behavior change, all review.test.ts fixtures still pass):
- Condensed review.ts's comments and per-signal reason/note strings,
  and removed the CapabilityName import in favor of an inline literal
  union, cutting the source from 12215 to ~7100 bytes.
- Factored the four detectors' `push(...)` calls through a shared
  helper so source/line/excerpt aren't repeated per signal.
- Shortened the MCP tool description and CLI usage line.
- Dropped the AI-AUTHORING.md mention (and its llms-full.txt copy);
  docs/TOOLING.md's "Project review" section remains the source of
  truth and is not packed (docs/ isn't in the package's roots list).

Local `test:package:built` now reports 532433 packed bytes (47 bytes
under budget) and passes; the budget in scripts/package-audit.ts was
not changed.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…iance

After trimming review_project's footprint (previous commit), the packed
tarball still failed CI on ubuntu-latest/Node 24 (checks (ubuntu-latest,
24, true)): 534333 bytes, over the 520 KiB (532480 byte) budget by 1853
bytes -- while the identical commit packed to 532179-532180 bytes on
Node 22 and Node 26 (same OS), comfortably under budget. That is a
~2.1 KiB swing from npm's own tar/gzip output between Node releases
alone, not from source content, and the previous budget had no headroom
left to absorb it (it was already right at the edge before this PR).

Raised the packed budget from 520 KiB to 530 KiB (532480 -> 542720
bytes) with the measured evidence recorded in the budget's comment, per
the same practice as the prior feature-planning bump. This keeps the
review_project addition itself minimal (already trimmed) while giving
every supported Node release real margin instead of chasing
gzip-implementation noise byte by byte.

Verified locally: `npm run test:package:built` passes (532433 packed
bytes, ~10 KiB under the new budget); typecheck, lint and the review/mcp
test files still pass.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@jimhoyd
jimhoyd merged commit 1769be2 into main Sep 22, 2026
60 checks passed
@jimhoyd
jimhoyd deleted the review-project-static-check branch September 22, 2026 13:33
jimhoyd added a commit that referenced this pull request Sep 22, 2026
…y duplication, extension registration) (#449)

PR #437 shipped review_project with 4 signals and explicitly deferred the
rest of #428's scope. This closes the remaining signals:

- method-dispatch: hand-written request.method branching/switch, reported
  as native-alternative pointing at per-method routes (get_capability
  "methods"); URLCode has no per-method-function YAML shape, per
  YAML-REFERENCE.md's explicit "a methods: map... is not implemented".
- manual-rate-limit / manual-security-headers: hand-rolled counting+429 and
  hand-set security headers, cross-referenced against each route's actual
  *effective* policies.throttle/policies.security (via compilePolicies'
  own effectivePolicies resolution) so the finding reads "you could declare
  this" (native-alternative) when the policy isn't declared for the route,
  or "this duplicates what's already declared" (manual-review) when it is
  — never a false duplication claim.
- Registered-vs-declared extension distinction: manual-cookie-session and
  global-mutable-state's extension-alternative findings now carry
  registered/revisionPinned booleans when the caller supplies operator
  registrations (InspectOptions.extensions, the same shape explain/
  plan-feature already accept from --host-file/MCP host). Wired
  `urlcode review --host-file` and the MCP host through to reviewProject.
  Without registrations, or when the named extension isn't found in them,
  the wording stays the existing conservative "declared, setup unconfirmed"
  — a declaration is never reported as active or executable, and a stale
  (non-revision-pinned) registration is reported as such, not as current.

Skipped: hand-written conditional-redirect-vs-match/conditional detection.
Ordinary business-logic branching that happens to end in a redirect is too
common and too disconnected from routing configuration for a bounded
source-text signal to avoid false positives; an uncertain observation beats
an incorrect automatic refactor (docs/TOOLING.md now states this).

Adds positive/negative fixtures for all three new signals plus the
registered/revision-pinned wording, following the existing test pattern.
Updates docs/TOOLING.md's Project review section and regenerates
llms-full.txt.

Co-authored-by: Claude Sonnet 5 <[email protected]>
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