refactor(codemode): modular SDK — remove internal LLM, add Executor interface#879
Merged
Conversation
🦋 Changeset detectedLatest commit: d9e8e4c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
mattzcarey
force-pushed
the
feat-remove-llm-codemode
branch
2 times, most recently
from
February 18, 2026 13:55
2726434 to
ba5a1e9
Compare
mattzcarey
marked this pull request as ready for review
February 18, 2026 13:55
Contributor
|
if this is ready for review, then please write a PR description that details what this is, what reviewers should look out for, just help me out here haha. Also please add a detailed changeset. |
…e app Replace the monolithic ai.ts with a modular structure: - executor.ts: Executor interface + DynamicWorkerExecutor using Workers RPC via ToolDispatcher (RpcTarget) instead of broken globalOutbound fetch - tool.ts: createCodeTool with AST-based code normalization (acorn), console log capture, timeout support, and error handling - types.ts: generateTypes + sanitizeToolName for type generation - index.ts: clean public API surface Key improvements: - globalOutbound defaults to null (runtime-enforced fetch/connect blocking) - Callers can pass a Fetcher for controlled outbound access - String concatenation module building (no template literal injection) - Comprehensive test suite (58 tests across 3 files) Redesign example app as "Planwise" task tracker with chat-first UI, collapsible tool cards, settings panel, and refined dark theme. Tools use AI SDK tool() wrapper.
mattzcarey
force-pushed
the
feat-remove-llm-codemode
branch
from
February 19, 2026 17:27
6be31f7 to
fb31717
Compare
… clarifying integration patterns
mattzcarey
force-pushed
the
feat-remove-llm-codemode
branch
from
February 19, 2026 17:46
47600ad to
f7ed0e0
Compare
commit: |
Replace mock-based tests with real Workers runtime tests: - Use defineWorkersConfig with a WorkerLoader binding - Delete cloudflare:workers mock — RpcTarget is now real - Executor tests use real DynamicWorkerExecutor + real WorkerLoader - Tests verify actual sandboxed execution, console capture, fetch blocking, timeout, template literals, and tool dispatch
mattzcarey
force-pushed
the
feat-remove-llm-codemode
branch
from
February 19, 2026 18:15
17289b5 to
516070e
Compare
…test.d.ts Rename src/test/ to src/tests/ for consistency. Add cloudflare-test.d.ts declaring ProvidedEnv with LOADER binding for IDE type resolution. Fix Mock contravariance in executor tests by using explicit ToolFns type. Replace broken @cloudflare/codemode/ai re-export in agents package with a runtime error directing users to createCodeTool().
Use Streamdown component for assistant text and reasoning blocks, replacing raw text rendering with proper markdown streaming support.
Refactor Codemode API and update docs and example app. Move the AI-dependent createCodeTool export to @cloudflare/codemode/ai and remove experimental_codemode/CodeModeProxy; introduce ToolDispatcher/DynamicWorkerExecutor and a minimal Executor/ExecuteResult interface. Revise docs to explain the new createCodeTool flow, network isolation, and configuration changes. Revamp the codemode example: replace UI with kumo/agents-ui components, simplify index.html, update client/server code (including renaming onStateUpdate -> onStateChanged), shrink CSS, and add e2e/playwright test scaffolding. Also update package metadata and build scripts to match the new structure.
Introduce a full Codemode example and playground demo, refactor agent/server logic, and ensure tools that require approval are excluded from code-execution toolsets. Key changes: - Add Codemode UI/demo to examples/playground and link it in the sidebar and routes; include a new CodemodeAgent for the playground. - Expand examples/codemode README and update client to use useAgentChat, ThemeProvider, and improved streaming/UI handling. - Refactor examples/codemode server: migrate Codemode to AIChatAgent, replace stateful DO message plumbing with agent chat streaming, use pruneMessages, and expose executor/type helpers. - Update createCodeTool to skip tools with needsApproval (helper hasNeedsApproval) and add tests covering this behavior. - Update packages/codemode exports/types and build script (d.ts handling and formatting), and add related dependency entries in example package.json files and config tweaks (vite, wrangler). - Document the current limitation: tools with needsApproval are not supported for codemode execution and should be invoked via the standard AI SDK flow.
threepointone
approved these changes
Feb 20, 2026
threepointone
left a comment
Contributor
There was a problem hiding this comment.
approving, but please test all the changes I've made
Contributor
|
I updated the PR:
please test all my changes and try out your example and the playground. tentatively stamping, land when you're happy with it |
Update examples/codemode/wrangler.jsonc to remove the "experimental" entry from compatibility_flags so the example only uses "nodejs_compat". This cleans up the example configuration and disables experimental compatibility features for the codemode demo.
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.
Summary
Rewrites
@cloudflare/codemodefrom a monolithicexperimental_codemode()+CodeModeProxyentrypoint into a modular, composable SDK with proper test coverage, documentation, and examples.What changed
Package (
@cloudflare/codemode):src/ai.ts— removesexperimental_codemode(),CodeModeProxy, the internal LLM call (generateObjectwith hardcodedgpt-4.1). The package no longer owns an LLM call or model choice.@cloudflare/codemode/aiexport —createCodeTool()returns a standard AI SDKTool. Users wire their own model viastreamText/generateText. The/aisubpath isolates theaipeer dependency — the root export (@cloudflare/codemode) contains executor, type generation, and utilities with noaidependency.Executorinterface — minimalexecute(code, fns) → ExecuteResultcontract. Implement it for any sandbox. ShipsDynamicWorkerExecutorfor Cloudflare Workers.ToolDispatcherreplacesCodeModeProxy— both use Workers RPC, butToolDispatcheris passed as a parameter toevaluate(dispatcher)instead of being injected as an env binding. No service bindings needed.globalOutbound: nullby default —fetch()andconnect()are blocked at the runtime level. Configurable per-executor.acornto parse LLM output into async arrow functions. Handles edge cases regex couldn't.sanitizeToolName()— converts MCP-style tool names (hyphens, dots) into valid JS identifiers.needsApprovalfiltering — tools withneedsApprovalare automatically excluded from codemode (both from type generation and the executor). They should be used via standard AI SDK tool calling instead. Full approval support is planned.console.log/warn/errorcaptured and returned inExecuteResult.logs.DynamicWorkerExecutorOptions.timeout(default 30s).fixedExtension: false,skipNodeModulesBundle: true,.js/.d.tsoutput,requirecondition in exports.Tests:
vitest-pool-workerswith a realWorkerLoaderbinding. No mocks. Tests cover executor, tool creation, type generation, code normalization,needsApprovalfiltering.wrangler devwith a real AI binding (@cf/zai-org/glm-4.7-flash). Full pipeline: user prompt → LLM generates code →DynamicWorkerExecutorruns it → tools called via RPC → result returned.Examples:
examples/codemode/) — rewritten withAIChatAgent+useAgentChat, Kumo design system,@cloudflare/agents-ui(ConnectionIndicator, ModeToggle, PoweredByAgents, ThemeProvider). Settings panel for switching executors. SQLite-backed project management tools.examples/playground/) — new Codemode demo under the AI category. UsesAIChatAgent, Kumo components, collapsible tool cards with code/result/console output.Documentation:
docs/codemode.md— full rewrite coveringcreateCodeTool,DynamicWorkerExecutor,Executorinterface, network isolation, API reference, agent integration, MCP tools, limitations.packages/codemode/README.md— updated for the new API with architecture diagram, configuration tables, and usage examples.Architecture
Required wrangler config:
{ "worker_loaders": [{ "binding": "LOADER" }] }One binding (
WorkerLoader) instead of three.The Executor interface
Import paths
Test plan
npm run testinpackages/codemode/— 55 tests pass (executor, tool, types, needsApproval) via vitest-pool-workersnpm run test:e2einpackages/codemode/— 5 e2e tests pass via Playwright + wrangler dev + real AI bindingnpm run build— package builds with clean.js/.d.tsoutputnpx tsc --noEmit— no type errors in package, examples, or playground