feat(codemode): add built-in static code validators#9
Open
AntoniTok wants to merge 4 commits into
Open
Conversation
added 4 commits
July 15, 2026 16:38
… add exhaustive tests
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.
feat(codemode): add built-in static code validators
Summary
validateCodevalidators on top of the pluggable API from feat(codemode): add pluggable runtime validators cloudflare/agents#1750syntaxValidator()— reject code that cannot parse (invalid JS, or TS-only syntax the executor can't run)semanticValidator()— reject code that parses but references things that don't exist:codemodeprovider, or an ambient globalcheckMethods: false)workerd-oxc), so it runs inside the Workers runtime with no external serviceWhy
Generated code currently only fails once the
DynamicWorkerExecutorisolate has started, andnormalize.tseven swallows its own parse failure and ships unparseable code onward. These validators move the obvious "this cannot run" cases ahead of that cost — no execution is created for code that was never going to run.API
syntaxValidator({ name?, language?: "js" | "ts", maxIssues? })— parses as JS by default (the executor runs plain JS with no type-strip step)semanticValidator({ name?, allowedGlobals?, checkMethods?, maxIssues? })—allowedGlobalslists extra injected identifiers (e.g. custom provider names)Both are
validateCode-only, so per cloudflare#1750 they are not recorded as resume-required.Notes
JSON/Math/fetch/etc. as unresolved. The validator subtracts a curated set of standard JS + Workers globals (AMBIENT_SANDBOX_GLOBALS) plus thecodemodeprovider.<connector>.<method>()and static<connector>["<method>"]()calls on a genuine connector global are checked; local variables that shadow a connector name, dynamic access, and empty-descriptor connectors are skipped to avoid false positives.Verification
pnpm run check— sherif, export checks, oxfmt, oxlint, all 104 projects typecheckpnpm --filter @cloudflare/codemode teststatus: "error",executionId: "", creates no execution; valid code still executes)New dependency
Adds
workerd-oxcto@cloudflare/codemode— prebuilt zero-import.wasm(no native/FFI), same Oxc engine the repo already uses for fmt/lint, active only inside workerd. Flagging per the "ask before adding package dependencies" guideline.