Repository navigation
Add review_project: opt-in read-only static plumbing review - #437
Merged
Merged
Conversation
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]>
This was referenced Sep 22, 2026
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]>
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.
Refs #428
Summary
Adds an opt-in, read-only MCP tool
review_projectand its CLI equivalenturlcode review, matching the shape of the existingexplain/plan-feature/get_manifestread-only tools. It statically reviews the compiled project plus its own project-ownedfunction/middlewaresource and reports observations groupednative-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-writtenJSON.parse+ field-presence/type checks on a route that does not declarerequest.body.schema→native-alternative. Silent when the route already declares the schema.manual-cookie-session— a hand-assembledSet-Cookieheader alongside session-shaped values (random id,session/tokennaming, expiry,HttpOnly) →manual-reviewby default,extension-alternative(namingauth) 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-scopelet/varinitialized empty/zero and later mutated in the same file →gapby default (naming the real restart/multi-instance limitation, not a generic warning),extension-alternative(namingstore) only when declared.outbound-network-call— a directfetch/http(s).request/http(s).getcall → alwaysmanual-review(equivalence to the declarativeproxy/signalscomposition, and target safety, cannot be established statically).Safety/boundary requirements from the issue are all honored:
functionFile/routeFunctionsresolution the rest of the tooling (policy.ts,manifest.ts) already uses.MODULE_BYTE_LIMIT); source text is never treated as instructions.sandbox: truevs. trusted execution mode does not change what is found (test included) and nothing here touches the sandbox/trusted execution paths.New surface:
review_project(src/mcp.ts), 24th read-only tool.urlcode review [--project DIR] [--target T] [--json](src/cli.ts).reviewProjectexported fromsrc/tooling.ts(src/review.ts).docs/TOOLING.md, a short mention indocs/AI-AUTHORING.md, regeneratedllms-full.txt..changeset/review-project.md, minor).Deferred (not in this PR)
Per the issue's suggested signal list, not yet implemented:
extensions:) to distinguish registered-and-revision-pinned from merely declared, when decidingextension-alternative.test1from 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 regeneratedllms-full.txtcheck).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.npm test— 730/737 pass. The 6 failures are pre-existing and unrelated to this change (confirmed by error text, not by this diff):installertests fail because this worktree checkout has no localnode_modules/typescript, whichscripts/build.tsrequires directly (npm run typecheck/lintsucceed because npm's ancestor-node_modules/.binPATH lookup findstscelsewhere;build.tsresolves 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-existingcheck-workspace-linkssymlink mismatch this worktree'spackages/*already have (they resolve@jimhoyd/urlcodeto the main checkout, not this worktree) — reproducible withnpm run check:codeindependent of any file this PR touches.npm run verify/verify:workspacesfor the same reason (workspace symlinks in this git-worktree checkout do not point at the worktree itself).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:packageschecks initially failed: the packed@jimhoyd/urlcodetarball exceeded the 520 KiB budget by ~2 KB. Fixed in two follow-up commits on this branch:review_project's footprint (no behavior change —test/review.test.tsstill 13/13 green): condensedsrc/review.ts's comments and per-signalreason/notestrings, 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 thedocs/AI-AUTHORING.mdmention (and itsllms-full.txtcopy) sincedocs/TOOLING.md's "Project review" section is the source of truth and isn't packed.src/review.tswent from 12215 to ~7.1 KB.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:builtpasses (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 fullnpm testsuite (737 tests) passes with 0 failures.