Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ await sandbox.destroy();
| `AskUser` | Ask user clarifying questions | `askUser: true` |
| `EnterPlanMode` | Enter planning/exploration mode | `planMode: true` |
| `ExitPlanMode` | Exit planning mode with a plan | `planMode: true` |
| `codemode` | Write code to orchestrate selected tools via Cloudflare Codemode | `codemode: { executor }` |
| `Skill` | Execute skills | `skill: { skills }` |
| `WebSearch` | Search the web | `webSearch: { apiKey }` |
| `WebFetch` | Fetch URL and process with AI | `webFetch: { apiKey, model }` |
Expand Down Expand Up @@ -233,6 +234,10 @@ const { tools, planModeState } = createAgentTools(sandbox, {
apiKey: process.env.PARALLEL_API_KEY,
model: anthropic('claude-haiku-4'),
},
codemode: {
executor: new DynamicWorkerExecutor({ loader: env.LOADER }),
includeTools: ['Read', 'Glob', 'Grep'], // Opt into write tools explicitly
},

// Tool-specific config
tools: {
Expand All @@ -251,6 +256,49 @@ const { tools, planModeState } = createAgentTools(sandbox, {
});
```

### Codemode

BashKit can expose a Cloudflare Codemode tool so the model writes code that orchestrates BashKit tools instead of making many individual tool calls. Install `@cloudflare/codemode`, provide an executor, and enable `codemode`:

Cloudflare Codemode currently targets AI SDK v6. BashKit's codemode adapter follows that path; AI SDK v5 support is intentionally not a compatibility goal for codemode.

```typescript
import { DynamicWorkerExecutor } from '@cloudflare/codemode';
import { createAgentTools, createPrepareStep } from 'bashkit';
import { streamText } from 'ai';

const { tools, planModeState } = await createAgentTools(sandbox, {
planMode: true,
context: { executionPolicy: {} },
codemode: {
executor: new DynamicWorkerExecutor({ loader: env.LOADER }),
includeTools: ['Read', 'Glob', 'Grep', 'Bash'],
tools: {
// Extra AI SDK tools exposed inside the default bashkit.* namespace
},
providers: [
{
name: 'repo',
tools: {
// Extra tools exposed as repo.*
},
},
],
},
});

await streamText({
model,
tools,
messages,
prepareStep: createPrepareStep({ planModeState }),
});
```

By default, generated code calls BashKit tools through BashKit's `bashkit.*` namespace, for example `await bashkit.Grep(...)`. Use `providers` when you want additional named tool groups such as `repo.SummarizeFile(...)`.

Client-intervention tools are excluded from codemode automatically: `AskUser`, `EnterPlanMode`, `ExitPlanMode`, tools without `execute`, and tools with `needsApproval`. Top-level `includeTools` narrows the default `bashkit.*` namespace. Named providers can define their own `includeTools` or `excludeTools`.

### Configuration Options

#### Global Config
Expand Down Expand Up @@ -1003,6 +1051,7 @@ Creates a set of agent tools bound to a sandbox instance.
### Optional Tools (also available via config)

- `createAskUserTool(config?)` - Emit a deferred AskUser tool call for the client
- `createCodemodeTool(tools, config)` - Create a Cloudflare Codemode tool from a filtered tool set
- `createEnterPlanModeTool(state)` - Enter planning/exploration mode
- `createExitPlanModeTool(state, onPlanSubmit?)` - Exit planning mode with a plan
- `createSkillTool(skills)` - Execute loaded skills
Expand Down
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions docs/src/app/MobileNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const links = [
{ href: "/", label: "Overview" },
{ href: "/getting-started", label: "Getting Started" },
{ href: "/tools", label: "Tools" },
{ href: "/codemode", label: "Codemode" },
{ href: "/sandboxes", label: "Sandboxes" },
{ href: "/context", label: "Context" },
{ href: "/api-reference", label: "API Reference" },
Expand Down
11 changes: 11 additions & 0 deletions docs/src/app/SideNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ const links: {
{ id: "todowrite", text: "TodoWrite" },
],
},
{
href: "/codemode",
label: "Codemode",
items: [
{ id: "overview", text: "Overview" },
{ id: "setup", text: "Setup" },
{ id: "batched-workflows", text: "Batched Workflows" },
{ id: "tool-selection", text: "Tool Selection" },
{ id: "policy", text: "Policy" },
],
},
{
href: "/sandboxes",
label: "Sandboxes",
Expand Down
7 changes: 7 additions & 0 deletions docs/src/app/api-reference/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ const { tools, budget } = await createAgentTools(sandbox, {
Web search configuration. Presence enables WebSearch and WebFetch
tools.
</Prop>
<Prop name="codemode" type="CodemodeConfig">
Cloudflare Codemode adapter. Adds a single <code>codemode</code>{" "}
tool that can orchestrate selected executable tools. Excludes
client-intervention tools and tools with{" "}
<code>needsApproval</code>. Supports extra default-namespace tools
and named providers.
</Prop>
<Prop name="cache" type="boolean | CacheConfig">
Enable tool result caching. Pass <code>true</code> for defaults or
an object for fine-grained control.
Expand Down
Loading
Loading