Skip to content

feat(think): make platform tools native to code#1947

Open
mattzcarey wants to merge 8 commits into
mainfrom
feat/think-codemode-bash
Open

feat(think): make platform tools native to code#1947
mattzcarey wants to merge 8 commits into
mainfrom
feat/think-codemode-bash

Conversation

@mattzcarey

@mattzcarey mattzcarey commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Summary

  • make Think's built-in code tool a durable Code Mode runtime while keeping read, write, edit, and code as the four built-in model tools
  • expose Think platform capabilities inside code as workspace.*, context.*, skills.*, extensions.*, fetch.*, and one namespace per connected MCP server
  • separate MCP connection registration from direct model-tool exposure: Think no longer calls mcp.getAITools() while assembling a turn
  • cache explicit MCPClientManager.getAITools() conversion by live connection, server id, and catalog revision, without scattered invalidation branches
  • make Code Mode runtime ownership explicit: applications using custom bash, custom code, or createExecuteTool(this) set readonly codeTool = false
  • add Worker Loader defaults, migration docs, an updated coding starter, and a focused examples/think-codemode-mcp app

Why

Issue #1938 reproduces with a 313-tool MCP server. A normal Think turn currently calls getAITools() before activeTools filtering, recursively converting 626 input/output JSON Schemas into Zod graphs even when the application intends to use MCP only through Code Mode.

The regression registers 313 complex MCP tools, replaces getAITools() with a throwing/counting trap, and completes this flow through the real Durable Object transport and Dynamic Worker runtime:

  1. codemode.search() finds catalog.echo
  2. codemode.describe() generates its types on demand
  3. catalog.echo() executes over MCP RPC
  4. the model still receives only four built-in schemas
  5. getAITools() is called zero times

A separate MCP manager regression verifies that filtered and unfiltered getAITools() calls share converted schemas. Replacing the connection, changing its id, or replacing its catalog causes conversion exactly once for the new revision.

Compatibility boundary

This is a pre-1.0 minor change for @cloudflare/think:

  • the built-in tool is named code and accepts { code: string }; it does not accept POSIX shell syntax or the legacy { script, cwd } payload
  • readonly codeTool = false opts out of the built-in runtime and restores the direct workspace, context, skills, extensions, and fetch layout
  • custom bash, custom code, and createExecuteTool(this) do not opt out implicitly; Think rejects competing runtime owners with an actionable error
  • legacy workspaceBash configuration moves to codeTool or an explicit createWorkspaceTools() tool set
  • application getTools(), Think actions, and client tools remain direct because they have separate lifecycle and approval semantics
  • the built-in runtime requires worker_loaders: [{ binding: "LOADER" }]; generated Think config includes it, and custom Worker entries export CodemodeRuntime through @cloudflare/think/server-entry
  • the standalone createWorkspaceTools().bash remains a real just-bash POSIX shell

Structural audit

  • replaced the MCP manager's server-id cache and reconnect/rename/close invalidation branches with a WeakMap keyed by the live connection
  • removed runtime-handle identity inference from Think; codeTool is the sole ownership policy
  • moved the Workspace filesystem capability guard into @cloudflare/shell and deleted Think's duplicate adapter module
  • moved namespaced StateConnector type rendering into Shell's prompt module
  • replaced Think's string rewrite of the Agent Skills prompt with an explicit activation-guidance seam
  • rebuilt the native runtime after hibernation using the same MCP wait policy as inference

Verification

  • pnpm run build: all 26 targets passed
  • pnpm run check: exports, formatting, lint, and all 118 TypeScript projects passed
  • pnpm exec nx affected -t test --base=origin/main: all 19 affected projects passed
  • Agents: 2,280 tests passed
  • AI Chat: 728 tests passed
  • Code Mode: 373 tests passed
  • Shell: 251 passed, 1 skipped
  • Think: 923 Worker, 10 generated-entry, 10 Vite, 55 CLI, and 5 React tests passed
  • agent-think: 37 tests passed
  • focused MCP example production build passed

Fixes #1938

@changeset-bot

changeset-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 44e1c31

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

This PR includes changesets to release 5 packages
Name Type
agents Patch
@cloudflare/think Minor
@cloudflare/codemode Patch
@cloudflare/shell Patch
@cloudflare/agent-think 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

@pkg-pr-new

pkg-pr-new Bot commented Jul 14, 2026

Copy link
Copy Markdown

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@1947

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@1947

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@1947

create-think

npm i https://pkg.pr.new/create-think@1947

hono-agents

npm i https://pkg.pr.new/hono-agents@1947

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@1947

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@1947

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@1947

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@1947

commit: 44e1c31

@mattzcarey mattzcarey changed the title feat(think): make platform tools Code Mode native feat(think): make platform tools native to code Jul 15, 2026
@mattzcarey
mattzcarey force-pushed the feat/think-codemode-bash branch from 120efd8 to 6fac110 Compare July 15, 2026 16:01
@mattzcarey
mattzcarey marked this pull request as ready for review July 17, 2026 10:23

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

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.

Think repeatedly compiles large MCP tool catalogs into Zod schemas and exceeds Durable Object memory limits

1 participant