Skip to content

Commit 08c1c51

Browse files
Merge origin/main into fix/shutdown-secrets-after-channel-stop
2 parents b41aaa3 + c903ca8 commit 08c1c51

11 files changed

Lines changed: 111 additions & 53 deletions

File tree

‎docs/docs_map.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9908,7 +9908,7 @@ Do not edit it by hand; run `pnpm docs:map:gen`.
99089908
- H2: What it does
99099909
- H2: Why use it
99109910
- H2: Quickstart
9911-
- H3: Enable Code Mode
9911+
- H3: Defaults and overrides
99129912
- H3: What the model does
99139913
- H3: Verify the active surface
99149914
- H2: Use Swarm for agent fan-out

‎docs/gateway/config-tools.md‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,23 @@ Without that sandbox-layer entry, the MCP server can still load successfully whi
8484

8585
### `tools.codeMode`
8686

87-
`tools.codeMode` enables the generic OpenClaw code-mode surface. When enabled
87+
`tools.codeMode` gates the generic OpenClaw code-mode surface. When engaged
8888
for a run with tools, normal OpenClaw tools move behind the in-sandbox `tools.*`
8989
catalog bridge, and MCP tools are available through the generated `MCP`
9090
namespace. The model normally sees `exec` and `wait`; tools such as `computer`
9191
whose structured results cannot cross the JSON-only bridge stay direct.
9292

93+
`enabled` defaults to `"auto"`, which engages code mode only for models whose
94+
catalog entry flags `compat.codeMode: "preferred"`. See
95+
[Code Mode - automatic per-model activation](/tools/code-mode#automatic-per-model-activation).
96+
97+
To opt out for every run:
98+
9399
```json5
94100
{
95101
tools: {
96102
codeMode: {
97-
enabled: true,
103+
enabled: false,
98104
},
99105
},
100106
}
@@ -104,13 +110,12 @@ The shorthand is also accepted:
104110

105111
```json5
106112
{
107-
tools: { codeMode: true },
113+
tools: { codeMode: false },
108114
}
109115
```
110116

111-
`enabled` also accepts `"auto"`, which engages code mode only for models whose
112-
catalog entry flags `compat.codeMode: "preferred"`. See
113-
[Code Mode - automatic per-model activation](/tools/code-mode#automatic-per-model-activation).
117+
`enabled: true` forces code mode on for every tool-capable run, regardless of
118+
model.
114119

115120
MCP declarations are exposed through the read-only virtual API file surface in
116121
code mode. Guest code can call `API.list("mcp")` and

‎docs/tools/code-mode.md‎

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ read_when:
99
- You are reviewing the MCP namespace bridge or virtual API declarations
1010
---
1111

12-
Code mode is an experimental, opt-in OpenClaw agent-runtime feature. When
13-
enabled, the model no longer sees every enabled tool schema; instead, it sees
12+
Code mode is an experimental OpenClaw agent-runtime feature. It defaults to the
13+
`"auto"` tier, which engages only models whose catalog marks them as preferred
14+
code-mode performers; every other model keeps normal tool exposure. When
15+
engaged, the model no longer sees every enabled tool schema; instead, it sees
1416
`exec`, `wait`, and any direct-only tool whose structured result cannot cross
1517
the JSON-only guest bridge. The model writes a small JavaScript or TypeScript
1618
program that searches, describes, and calls the hidden tool catalog.
@@ -23,8 +25,8 @@ separate implementations:
2325
freeform-grammar tool: the model writes raw JavaScript source (optionally
2426
prefixed by a `// @exec: {...}` pragma line for execution options), executed
2527
in Codex's in-process V8 Code Mode runtime.
26-
- OpenClaw code mode runs in the generic OpenClaw agent runtime and is
27-
disabled unless `tools.codeMode.enabled` is `true` or `"auto"`. Its `exec`
28+
- OpenClaw code mode runs in the generic OpenClaw agent runtime, gated by
29+
`tools.codeMode.enabled` (default `"auto"`, per-model activation). Its `exec`
2830
tool takes a JSON `{ code, language }` payload, executed in a QuickJS-WASI
2931
worker.
3032

@@ -89,44 +91,37 @@ the QuickJS-WASI guest.
8991

9092
## Quickstart
9193

92-
### Enable Code Mode
94+
### Defaults and overrides
9395

94-
```json5
95-
{
96-
tools: {
97-
codeMode: {
98-
enabled: true,
99-
},
100-
},
101-
}
102-
```
96+
Code mode ships enabled in the `"auto"` tier: it engages only when the run's
97+
model is flagged as a preferred code-mode performer in its provider catalog,
98+
and every other model keeps normal tool exposure. No configuration is needed.
99+
See [Automatic per-model activation](#automatic-per-model-activation) for the
100+
exact semantics and the shipped model list.
103101

104-
Shorthand:
102+
To opt out for every run:
105103

106104
```json5
107105
{
108106
tools: {
109-
codeMode: true,
107+
codeMode: false,
110108
},
111109
}
112110
```
113111

114-
Code mode stays off when `tools.codeMode` is omitted, `false`, or an object
115-
without `enabled: true` or `enabled: "auto"`.
116-
117-
To engage code mode only for models whose catalog marks them as strong code-mode
118-
performers, use the `"auto"` tier instead of `true`:
112+
To force code mode on for every tool-capable run, regardless of model:
119113

120114
```json5
121115
{
122116
tools: {
123-
codeMode: "auto",
117+
codeMode: true,
124118
},
125119
}
126120
```
127121

128-
See [Automatic per-model activation](#automatic-per-model-activation) for the
129-
exact semantics and the shipped model list.
122+
Object form works too: `tools.codeMode.enabled` accepts the same `false`,
123+
`true`, and `"auto"` values. An object without `enabled` keeps the `"auto"`
124+
default.
130125

131126
If you use sandboxed agents with configured MCP servers, also allow the
132127
bundled MCP plugin in the sandbox tool policy, for example
@@ -205,7 +200,7 @@ validating high-risk deployments.
205200
| | |
206201
| ------------------- | ------------------------------------------------------------------------------------------- |
207202
| Runtime | [`quickjs-wasi`](https://github.com/vercel-labs/quickjs-wasi) |
208-
| Default state | disabled |
203+
| Default state | `"auto"` (engages only catalog-preferred models) |
209204
| Stability | experimental OpenClaw surface (Codex Code Mode is a separate, stable Codex harness surface) |
210205
| Target surface | generic OpenClaw agent runs |
211206
| Security posture | model code is hostile |
@@ -252,7 +247,7 @@ enable the feature on its own.
252247

253248
| Field | Default | Clamp |
254249
| --------------------- | ------------------------------ | ----------------------------------------------- |
255-
| `enabled` | `false` | `false`, `true`, or `"auto"` (per-model) |
250+
| `enabled` | `"auto"` | `false`, `true`, or `"auto"` (per-model) |
256251
| `runtime` | `"quickjs-wasi"` | only supported value |
257252
| `mode` | `"only"` | exposes control/direct tools, catalogs the rest |
258253
| `languages` | `["javascript", "typescript"]` | any subset of the two |
@@ -274,13 +269,13 @@ an engaged run never silently falls back to broad direct tool exposure.
274269

275270
`tools.codeMode.enabled` accepts three values:
276271

277-
- `false` (default): code mode is off for every run.
272+
- `"auto"` (default): code mode engages only when the run's model is flagged
273+
as a preferred code-mode performer in its provider catalog.
274+
- `false`: code mode is off for every run.
278275
- `true`: code mode engages for every tool-capable run, regardless of model.
279-
- `"auto"`: code mode engages only when the run's model is flagged as a
280-
preferred code-mode performer in its provider catalog.
281276

282-
`false` and `true` behave exactly as before the `"auto"` tier existed; `"auto"`
283-
is purely additive.
277+
`false` and `true` are absolute overrides and behave exactly as before the
278+
`"auto"` tier existed.
284279

285280
### The `compat.codeMode` catalog flag
286281

@@ -327,8 +322,9 @@ replacing many full tool schemas and per-tool round trips with one compact
327322
program surface. Models below the preferred tier showed no consistent win and
328323
sometimes regressed, which is why `"auto"` leaves them on direct tools.
329324

330-
Use `"auto"` when agents switch between models: strong models get the compact
331-
surface, weaker or local ones keep the exposure they handle best. Use `true`
325+
The default `"auto"` fits agents that switch between models: strong models get
326+
the compact surface, weaker or local ones keep the exposure they handle best.
327+
Use `true`
332328
when you have verified a specific unflagged model performs well with code
333329
mode; global force-on is most predictable for single-model deployments. For
334330
open-weight or uncached serving where every prompt token is billed or

‎src/agents/code-mode-runtime.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ describe("Code Mode master switch resolution", () => {
1313
{ name: "boolean shorthand false", codeMode: false, enabled: false },
1414
{ name: "auto shorthand", codeMode: "auto", enabled: "auto" },
1515
{ name: "object enabled auto", codeMode: { enabled: "auto" }, enabled: "auto" },
16-
{ name: "object without enabled", codeMode: { timeoutMs: 5000 }, enabled: false },
17-
{ name: "omitted", codeMode: undefined, enabled: false },
16+
{ name: "object without enabled", codeMode: { timeoutMs: 5000 }, enabled: "auto" },
17+
{ name: "omitted", codeMode: undefined, enabled: "auto" },
1818
])("resolves enabled for $name", ({ codeMode, enabled }) => {
1919
expect(resolveCodeModeConfig({ tools: { codeMode } } as never).enabled).toBe(enabled);
2020
});

‎src/agents/code-mode-runtime.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ function readCodeModeRawConfig(config?: OpenClawConfig, agentId?: string): Recor
119119
}
120120

121121
function readEnabled(value: unknown): boolean | "auto" {
122-
return typeof value === "boolean" || value === "auto" ? value : false;
122+
// Shipped default is "auto": code mode engages only for catalog-preferred
123+
// models, so unevaluated models keep normal tool exposure by construction.
124+
return typeof value === "boolean" || value === "auto" ? value : "auto";
123125
}
124126

125127
export function readPositiveInteger(value: unknown, fallback: number): number {

‎src/agents/code-mode.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ describe("Code Mode", () => {
203203
},
204204
},
205205
} as never);
206-
expect(resolved.enabled).toBe(false);
206+
expect(resolved.enabled).toBe("auto");
207207
expect(resolveCodeModeConfig({ tools: { codeMode: { enabled: true } } } as never).enabled).toBe(
208208
true,
209209
);

‎src/config/schema.help.runtime.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export const RUNTIME_FIELD_HELP: Record<string, string> = {
112112
"tools.codeMode":
113113
"Generic OpenClaw code mode. When enabled, agent runs expose only `exec` and `wait` to the model and hide normal tools behind a QuickJS-WASI catalog bridge.",
114114
"tools.codeMode.enabled":
115-
'Enables generic code mode. Default is off. `true` engages every tool-capable run and fails closed if the runtime is unavailable instead of exposing the full tool list. `"auto"` engages only models whose catalog flags `compat.codeMode: "preferred"`.',
115+
'Enables generic code mode. Default is `"auto"`, which engages only models whose catalog flags `compat.codeMode: "preferred"`. `true` engages every tool-capable run and fails closed if the runtime is unavailable instead of exposing the full tool list. `false` turns code mode off for every run.',
116116
"tools.codeMode.runtime": 'Guest JavaScript runtime. Only "quickjs-wasi" is supported.',
117117
"tools.codeMode.mode":
118118
'Model-facing surface. Only "only" is supported: expose code-mode `exec` and `wait` and hide normal tools.',

‎src/config/types.tools.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export type CodeModeConfig =
181181
| boolean
182182
| "auto"
183183
| {
184-
/** Enable generic OpenClaw code mode. Default: false. "auto" engages it only for models whose catalog compat flags `codeMode: "preferred"`. */
184+
/** Enable generic OpenClaw code mode. Default: "auto", which engages it only for models whose catalog compat flags `codeMode: "preferred"`. */
185185
enabled?: boolean | "auto";
186186
/** Guest runtime. Only quickjs-wasi is supported. */
187187
runtime?: "quickjs-wasi";

‎ui/src/i18n/locales/en.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2406,7 +2406,8 @@ export const en: TranslationMap = {
24062406
saveFailed: "The feature setting could not be saved.",
24072407
codeMode: {
24082408
title: "Code Mode",
2409-
description: "Let agents combine tools in compact, sandboxed JavaScript workflows.",
2409+
description:
2410+
"Let agents combine tools in compact, sandboxed JavaScript workflows. Auto engages code mode only for models evaluated as strong code-mode performers.",
24102411
},
24112412
swarm: {
24122413
title: "Swarm",

‎ui/src/pages/labs/labs-page.test.ts‎

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,12 @@ describe("LabsPage", () => {
130130

131131
it.each([
132132
{
133+
// The on position restores the shipped "auto" tier, never `true`: Labs
134+
// offers Auto/Off, and force-on stays a config-only power-user state.
133135
label: "Code Mode",
134136
index: 0,
135137
sourceConfig: { tools: { codeMode: { enabled: false } } },
136-
expectedPatch: { tools: { codeMode: { enabled: true } } },
138+
expectedPatch: { tools: { codeMode: { enabled: "auto" } } },
137139
note: "labs: update codeMode",
138140
},
139141
{
@@ -169,7 +171,7 @@ describe("LabsPage", () => {
169171
expectedPatch: { logging: { audit: { messages: "direct" } } },
170172
note: "labs: update auditMessages",
171173
},
172-
])("writes true at the registered config path when enabling $label", async (testCase) => {
174+
])("writes the on value at the registered config path when enabling $label", async (testCase) => {
173175
const { page, runtimeConfig } = await mountPage(testCase.sourceConfig);
174176
const toggle = labToggle(page, testCase.index, testCase.label);
175177

@@ -228,6 +230,47 @@ describe("LabsPage", () => {
228230
});
229231
});
230232

233+
describe("LabsPage code mode enablement", () => {
234+
// Mirrors resolveCodeModeConfig: the shipped default is "auto", so the row
235+
// reads as on until an explicit `false` opts out. `true` stays a valid
236+
// config-only force-on and must also read as on.
237+
it.each([
238+
{ label: "unset", config: {}, expected: true },
239+
{
240+
label: "object without enabled",
241+
config: { tools: { codeMode: { timeoutMs: 5000 } } },
242+
expected: true,
243+
},
244+
{ label: "explicit true", config: { tools: { codeMode: { enabled: true } } }, expected: true },
245+
{
246+
label: "explicit disabled",
247+
config: { tools: { codeMode: { enabled: false } } },
248+
expected: false,
249+
},
250+
{ label: "boolean shorthand false", config: { tools: { codeMode: false } }, expected: false },
251+
{ label: "auto shorthand", config: { tools: { codeMode: "auto" } }, expected: true },
252+
])("reads $label as $expected", async ({ config, expected }) => {
253+
const { page, provider } = await mountPage(config);
254+
255+
expect(codeModeToggle(page).checked).toBe(expected);
256+
provider.remove();
257+
});
258+
259+
it("writes an explicit false when disabling the shipped default", async () => {
260+
const { page, runtimeConfig } = await mountPage({});
261+
const toggle = codeModeToggle(page);
262+
263+
toggle.checked = false;
264+
toggle.dispatchEvent(new Event("change", { bubbles: true, composed: true }));
265+
266+
await vi.waitFor(() => expect(runtimeConfig.patch).toHaveBeenCalledOnce());
267+
expect(runtimeConfig.patch).toHaveBeenCalledWith({
268+
raw: { tools: { codeMode: { enabled: false } } },
269+
note: "labs: update codeMode",
270+
});
271+
});
272+
});
273+
231274
describe("LabsPage tool search enablement", () => {
232275
const toolSearchIndex = LAB_FEATURES.findIndex((feature) => feature.id === "toolSearch");
233276

0 commit comments

Comments
 (0)