Skip to content

computer: Make the codemode module scheme configurable - #323

Merged
aron-cf merged 1 commit into
mainfrom
custom-scheme
Nov 12, 2026
Merged

aron-cf merged 1 commit into
mainfrom
custom-scheme

Conversation

@aron-cf

@aron-cf aron-cf commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

CodemodeBackend serves host modules, and the libraries a host provides,
only under codemode:*. A host that presents these modules to a model as
its own, such as agent:git and agent:web, has no way to name them so.

The backend now takes scheme, which replaces codemode everywhere
the scheme was fixed: the specifiers host modules and host libraries
must use, the imports a source module may make by name, the error for
code that imports an unconfigured module under the scheme, and the
module names reserved for Workspace internals. Under another scheme,
codemode:* is an ordinary bare name. The scheme is checked when the
backend is constructed: a lowercase letter followed by lowercase
letters, digits, or dashes, and not one the Workers runtime or URLs
already give a meaning, such as node or https. It defaults to codemode,
and a backend without the option behaves as before.

createBrowserModule() names its own specifier and codemode:tools in the
description it gives the model, so it takes specifier and
toolsSpecifier for a host that serves the browser or the agent's tools
under other names. Its errors name its specifier too.


Devin Review

CodemodeBackend serves host modules, and the libraries a host provides,
only under codemode:*. A host that presents these modules to a model as
its own, such as agent:git and agent:web, has no way to name them so.

The backend now takes scheme, which replaces codemode everywhere
the scheme was fixed: the specifiers host modules and host libraries
must use, the imports a source module may make by name, the error for
code that imports an unconfigured module under the scheme, and the
module names reserved for Workspace internals. Under another scheme,
codemode:* is an ordinary bare name. The scheme is checked when the
backend is constructed: a lowercase letter followed by lowercase
letters, digits, or dashes, and not one the Workers runtime or URLs
already give a meaning, such as node or https. It defaults to codemode,
and a backend without the option behaves as before.

createBrowserModule() names its own specifier and codemode:tools in the
description it gives the model, so it takes specifier and
toolsSpecifier for a host that serves the browser or the agent's tools
under other names. Its errors name its specifier too.
@changeset-bot

changeset-bot Bot commented Nov 12, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b9b2004

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@cloudflare/computer Patch
@cloudflare/dofs Patch
@cloudflare/computer-rpc Patch
@cloudflare/computerd Patch
@cloudflare/remote-exec Patch

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

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 potential issues.

Devin Review

for (const site of sites) {
const imported = site.specifier;
if (imported.startsWith("codemode:")) {
if (imported.startsWith(`${scheme}:`)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Cross-scheme library imports fail

With scheme: "agent", prepareSourceModules leaves imports of configured codemode:* libraries unchanged. The Loader treats these names as URLs, while buildModuleGraph stores the libraries under __modules__/. Executions importing them from another configured library fail to load.

Learn more

The backend permits a configured source library outside its selected scheme and rewrites caller imports to the module directory. A configured source library that imports that library by name passes preparation unchanged unless the imported name begins with the selected scheme. The Loader treats colon-bearing names as URLs, not as paths to the module directory, so loading the graph fails. buildModuleGraph places every configured library in that directory.

Example: Configure scheme: "agent" with "codemode:lib": "export const value = 1" and "agent:facade": "import { value } from 'codemode:lib'; export { value }". A run importing agent:facade cannot load its codemode:lib dependency, even though both libraries are configured.

Recommended fix: In prepareSourceModules, rewrite imports of all configured source names to relative module-directory paths, including names with a different scheme. Preserve the existing missing-module check for imports under the selected scheme, and test a source-to-source import across schemes.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

* `-`, and not one the Workers runtime or URLs already use, such as
* `node`, `cloudflare`, `http` or `file`.
*/
scheme?: string;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 New scheme has no consumer example

Adding scheme changes the public backend API, but no runnable example uses it. The repository requires examples to accompany public API changes, leaving custom module names unexercised in a consumer.

Learn more

The repository's agent guidelines require updating examples when a public API changes. scheme is a new public backend option, and createBrowserModule also gains public naming options. The existing codemode example still uses the default backend with no modules; none of the runnable consumers demonstrate the new configuration.

Example: A user following the codemode example sees no working configuration for scheme: "agent" or for importing agent:git from code, despite the new public option.

Recommended fix: Add a runnable consumer example that configures a custom scheme, registers a matching host module, and imports it; include browser specifiers if the consumer uses the browser module.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@pkg-pr-new

pkg-pr-new Bot commented Nov 12, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@cloudflare/computer@323

commit: b9b2004

@aron-cf
aron-cf merged commit de44ba6 into main Nov 12, 2026
31 checks passed
@aron-cf
aron-cf deleted the custom-scheme branch November 12, 2026 15:21
@github-actions github-actions Bot mentioned this pull request Nov 12, 2026
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