Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
6ab42db
feat: add hybrid code mode
DragonnZhang Sep 14, 2026
fda09c0
fix(core): address hybrid code mode review feedback
DragonnZhang Sep 15, 2026
9a0cd57
chore: merge main into code mode branch
DragonnZhang Sep 15, 2026
30b2a6c
fix(code-mode): address review feedback
DragonnZhang Sep 18, 2026
6c919b7
fix(web-shell): map tool mode setting alias
DragonnZhang Sep 18, 2026
02afce8
fix(core): align code mode bindings and reported tool surfaces
DragonnZhang Sep 20, 2026
2ecf53e
merge: sync main and preserve CodeMode context tests
DragonnZhang Sep 20, 2026
4a38632
merge: preserve hybrid execution with stable tool bridge
DragonnZhang Sep 21, 2026
3239c68
fix: repair web-shell alias tests and address code-mode review feedback
qwen-code-ci-bot Sep 22, 2026
f35beb1
Merge remote-tracking branch 'origin/main' into dragon/add-codemode
qwen-code-ci-bot Sep 22, 2026
28df8ee
fix: align hybrid tool guidance with available invocation surfaces
DragonnZhang Sep 22, 2026
a7315eb
fix: address code-mode review feedback on exec binding narrowing and …
qwen-code-ci-bot Sep 22, 2026
3c69762
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Sep 23, 2026
34711cf
fix(core): avoid unverified agent zoom hints and clarify tool exposure
DragonnZhang Sep 23, 2026
ce7e57d
Merge remote-tracking branch 'origin/main' into dragon/add-codemode
qwen-code-ci-bot Sep 23, 2026
fa457bd
fix(core): narrow MCP nested bindings by the agent tools allowlist
qwen-code-ci-bot Sep 23, 2026
ae35809
fix(core): keep CodeModeOnly exec expansion from bypassing MCP narrowing
qwen-code-ci-bot Sep 24, 2026
4c53574
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Sep 24, 2026
22a9a40
fix: preserve code-mode fork boundaries and update mode guidance
DragonnZhang Sep 26, 2026
779d689
merge: refresh main OAuth discovery before publishing code-mode fixes
DragonnZhang Sep 26, 2026
b1561b7
fix: preserve nested-only fork access and legacy mode resets
DragonnZhang Sep 27, 2026
e6fbdcd
fix(core): preserve empty tool policies when syncing main
DragonnZhang Sep 28, 2026
6edd151
fix: merge main and translate current tool mode settings
DragonnZhang Sep 28, 2026
f746b88
fix(core): merge main and preserve hybrid skill lifecycle
DragonnZhang Oct 1, 2026
ed2e58c
fix(core): merge main and preserve hybrid agent permissions
DragonnZhang Oct 3, 2026
4a72ef8
fix(core): align child skill routes and merge current main
DragonnZhang Oct 4, 2026
cad9407
fix(core): retain code-mode behavior with current main
DragonnZhang Oct 5, 2026
1df2386
fix(cli): align tool mode readouts and merge main
DragonnZhang Oct 6, 2026
71ab2c9
fix(core): preserve code mode policy when merging MCP rule fixes
DragonnZhang Oct 7, 2026
68ceea7
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Oct 7, 2026
f669bd7
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Oct 7, 2026
f183ce0
fix(core): align hybrid tool visibility and prompt budgets
DragonnZhang Oct 8, 2026
71b8502
fix(core): keep nested-only allowlists from revoking hybrid direct de…
Oct 8, 2026
4a122a6
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Oct 8, 2026
e81694c
fix(core): align Skill listings with exec permission bounds
DragonnZhang Oct 9, 2026
5afe0ce
fix(core): preserve direct Skill activation with nested restrictions
DragonnZhang Oct 9, 2026
e1d295c
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Oct 9, 2026
3dd719a
fix(core): gate the code-mode skill route on exec registration (#11854)
Oct 9, 2026
10d221a
Merge remote-tracking branch 'origin/main' into dragon/add-codemode
Oct 10, 2026
9b41dc0
fix(core): close CodeModeOnly skill-listing bypass without exec (#11854)
Oct 10, 2026
7faeea6
test(cli): align OpenTUI settings region tests with tools.mode (#11854)
Oct 10, 2026
f6ea27d
fix(core): close remaining CodeModeOnly skill-gate exec routes (#11854)
Oct 11, 2026
ecbb1ae
fix(core): close code-mode exec admission, container mode, and allowl…
Oct 11, 2026
b98c160
docs(sub-agents): restore fork_tools deny-all contract line (#11854)
Oct 12, 2026
9c5bf63
fix(core): migrate monitor startup tests to tool mode
DragonnZhang Oct 12, 2026
1658fc8
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Oct 12, 2026
fb4f947
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Oct 13, 2026
266a8d6
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Oct 13, 2026
4307ddc
fix(core): keep bundled guidance reachable in hybrid agents
DragonnZhang Oct 13, 2026
6a3ae09
Merge branch 'main' into dragon/add-codemode
Oct 13, 2026
dd262a9
test(cli): raise vi.waitFor timeouts on contention-exposed waits (#11…
Oct 13, 2026
6a3902b
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Oct 13, 2026
eb000e2
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Oct 14, 2026
a5d9ac1
docs: clarify persisted fork tool bounds
DragonnZhang Oct 14, 2026
ddd38e3
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Oct 14, 2026
f7bab3d
fix(core): close CodeModeOnly skill route when Skill is unregistered …
qwen-code-dev-bot Oct 14, 2026
48bed39
fix(core): tolerate registry-less stub Config in willHaveSkillTool (#…
qwen-code-dev-bot Oct 14, 2026
cd0dc35
Merge remote-tracking branch 'origin/main' into dragon/add-codemode
Oct 14, 2026
255e9a0
fix(core): align fork deny-all message and skill reminder with the ga…
Oct 14, 2026
b05ac71
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Oct 15, 2026
cc7f4c6
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Oct 15, 2026
209c593
Merge remote-tracking branch 'origin/main' into dragon/add-codemode
qwen-code-dev-bot Oct 19, 2026
5438ffd
test(cli): scope AppContainer Mod session mock to its config (#11854)
qwen-code-dev-bot Oct 19, 2026
3763118
chore: merge main and preserve hook timeout coverage
DragonnZhang Oct 20, 2026
a3dee29
chore: merge main and adapt interactive Mod test to toolMode (#11854)
Oct 20, 2026
8ec0228
chore: merge main and keep code-mode fork restrictions (#11854)
Oct 21, 2026
fb0e8e9
chore: merge main and preserve bundled reference coverage
DragonnZhang Oct 21, 2026
52a5114
chore: merge main and keep config-scoped Mod session mock (#11854)
Oct 21, 2026
b5aa642
chore: merge main and keep toolMode config surface (#11854)
Oct 27, 2026
44e02c2
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Oct 27, 2026
8f25c68
test(core): pin hybrid exec nested declaration signature (#11854)
Oct 28, 2026
4128ff6
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Oct 28, 2026
494d4a3
fix(core): derive the fork nested exec bound without the subagent fra…
Oct 28, 2026
b4b5e47
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Oct 28, 2026
02182f7
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Oct 29, 2026
1547568
fix(core): keep deferred Skill reachable past the eager veto (#11854)
Oct 29, 2026
4f6181d
Merge remote-tracking branch 'origin/main' into dragon/add-codemode
Oct 29, 2026
1ff2c86
fix(cli): keep operator code mode over a lower-scope tool mode (#11854)
Oct 29, 2026
e49421a
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Oct 29, 2026
382c141
docs(subagents): scope fork prompt-cache parity to direct mode (#11854)
qwen-code-dev-bot Oct 29, 2026
ceeec7d
test(web-shell): supply transcript coverage in managed recovery mock …
Oct 30, 2026
c5393c8
Merge remote-tracking branch 'origin/main' into dragon/add-codemode
Oct 30, 2026
887c031
chore: merge main configuration updates
DragonnZhang Nov 3, 2026
a92e069
Merge remote-tracking branch 'origin/main' into dragon/add-codemode
DragonnZhang Nov 4, 2026
d6527ff
test(cli): pin the declared MCP schema's billing row
DragonnZhang Nov 4, 2026
a6eabc7
fix: honour legacy direct pin and blocked skill bridge (#11854)
DragonnZhang Nov 4, 2026
70c78a2
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Nov 4, 2026
002d5fe
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Nov 4, 2026
d47bbf9
fix(core): gate the deferred bridge on the execution allowlist (#11854)
qwen-code-dev-bot Nov 4, 2026
aec647b
docs(core): scope the bridge allowlist comment to Direct and Hybrid (…
qwen-code-dev-bot Nov 4, 2026
b3154cf
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Nov 5, 2026
e4b1813
fix(core): preserve always-loaded exec skill capability
DragonnZhang Nov 5, 2026
d3b517d
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Nov 5, 2026
d304548
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Nov 5, 2026
88aa3d3
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Nov 5, 2026
78f08c1
fix(core): align the eager-hidden skill check with the declaration fi…
qwen-code-dev-bot Nov 5, 2026
3bb29e2
fix(core): recompute eager-hidden Skill in Direct mode (#11854)
qwen-code-dev-bot Nov 6, 2026
6dbcff3
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Nov 6, 2026
26385d2
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Nov 6, 2026
d896aa2
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Nov 6, 2026
9731e5b
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Nov 6, 2026
b03e659
fix(core): merge main while preserving code mode tool policy
DragonnZhang Nov 8, 2026
aea47f0
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Nov 8, 2026
9db2e51
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Nov 8, 2026
44302a0
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Nov 9, 2026
3bd332b
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Nov 9, 2026
c229a21
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Nov 9, 2026
7a7b405
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Nov 9, 2026
2ff3a71
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Nov 9, 2026
e9da544
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Nov 9, 2026
0a054d8
fix: align skill bridge gate, fork_tools docs, and tool-mode restore …
qwen-code-dev-bot Nov 10, 2026
14bc01c
fix: stop question acquire at its deadline and align nested skill gat…
qwen-code-dev-bot Nov 10, 2026
16da3cf
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Nov 10, 2026
d3eed9c
Merge branch 'main' into dragon/add-codemode
Nov 12, 2026
89bc755
style(cli): restore trailing newline in must-translate test
Nov 12, 2026
024cab5
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Nov 12, 2026
a111c36
fix(core): keep display_image out of fork exec bounds (#11854)
qwen-code-dev-bot Nov 12, 2026
8a5cb1a
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Nov 12, 2026
c97fb18
Merge remote-tracking branch 'origin/main' into dragon/add-codemode
qwen-code-dev-bot Nov 13, 2026
d4f5a76
test(core): align AgentCore tool-registry mocks with merged policy
qwen-code-dev-bot Nov 13, 2026
f42a1c5
test(managed-agent): align versioning retry count with main (#11854)
qwen-code-dev-bot Nov 13, 2026
119999a
chore(web-shell): regenerate NOTICES for current dependency tree (#11…
qwen-code-dev-bot Nov 13, 2026
2aa7947
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Nov 13, 2026
dd46d00
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Nov 13, 2026
56123df
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Nov 13, 2026
b918a9a
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Nov 13, 2026
6c143aa
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Nov 14, 2026
4f4e85b
fix(core): reach an eager-hidden skill through a declared bridge (#11…
qwen-code-dev-bot Nov 14, 2026
47ca708
Merge branch 'main' into dragon/add-codemode
qwen-code-dev-bot Nov 14, 2026
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
55 changes: 28 additions & 27 deletions docs/design/code-mode-only.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
# CodeModeOnly MVP

[English](code-mode-only.md) | [简体中文](code-mode-only.zh-CN.md)

## Status

Implemented for [#10377](https://github.com/QwenLM/qwen-code/issues/10377).
The feature is opt-in and defaults off.

## Goal

Add a `tools.codeModeOnly` setting that replaces the ordinary model-facing
tool surface with one `exec` JavaScript tool plus the small set of tools that
must remain direct control-plane calls. `exec` code can call ordinary tools
Add a `tools.mode: "code_mode_only"` setting that replaces the ordinary
model-facing tool surface with one `exec` JavaScript tool plus the small set of
tools that must remain direct control-plane calls. `exec` code can call ordinary tools
through `tools.<name>(args)` without bypassing Qwen Code's validation,
permissions, approvals, hooks, telemetry, cancellation, concurrency, or output
budgets.

Direct mode is a compatibility boundary: when the setting is false, tool
Direct mode is a compatibility boundary: when `tools.mode` is `direct`, tool
registration, deferred-tool behavior, provider requests, and execution remain
unchanged.

## Non-goals

- Hybrid direct/code exposure.
- Defining hybrid direct/code exposure; see [Code Mode](code-mode.md).
- Persistent cells, globals, or values between `exec` calls.
- Background jobs, `wait`, `yield`, `store`, or `load`.
- Raw/freeform provider calls.
Expand All @@ -32,27 +34,27 @@ unchanged.
```json
{
"tools": {
"codeModeOnly": true
"mode": "code_mode_only"
}
}
```
Comment thread
qwen-code-dev-bot marked this conversation as resolved.
Resolved

The setting resolves once to the effective `ToolMode` value `direct` or
`code_mode_only`. `ToolRegistry` and the execution surfaces consume that mode.
`exec` is only registered when the setting is enabled, so disabling the setting
also removes it from diagnostics and registry listings.
The setting resolves once to the effective `ToolMode` value. `ToolRegistry`
and the execution surfaces consume that mode. `exec` is only registered when a
code mode is enabled, so selecting `direct` also removes it from diagnostics
Comment thread
DragonnZhang marked this conversation as resolved.
Resolved
and registry listings.

## Exposure policy

The registry remains the source of truth. Exposure is a view over registered
tools, never a second registry.

| Category | Model top level | `tools.*` inside `exec` |
| ------------------------------------------ | ----------------- | ----------------------- |
| `exec` | CodeModeOnly only | No |
| Direct control | Yes | No |
| Ordinary registered tool | No | Yes |
| Hidden bridge (`tool_search`, `tool_call`) | No | No |
| Category | Model top level | `tools.*` inside `exec` |
| ------------------------------------------ | ------------------------------------- | ----------------------- |
| `exec` | CodeMode and CodeModeOnly | No |
| Direct control | Yes | No |
| Ordinary registered tool | CodeMode only | Yes |
| Hidden bridge (`tool_search`, `tool_call`) | Existing behavior outside strict mode | No |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Suggestion] R1-2: N06: The rewritten exposure row conditions the table's only statement about bridge exposure on "strict mode" — a term that exists nowhere in the mode vocabulary, the code, or any other English document — and it groups two tools the code exposes differently.

ToolMode has exactly three values, direct / code_mode / code_mode_only (packages/core/src/tools/code-mode.ts:22-26); no setting, code path, or EN doc defines a "strict mode", and a repo-wide grep over docs/ finds the phrase only on this line (the ZH twin's 严格模式 is glossed only in a different file, docs/design/code-mode.zh-CN.md:104: "tools.mode: "code_mode_only" 选择严格模式"). A user on tools.mode: "code_mode" therefore cannot tell from this table whether hybrid counts as strict, i.e. whether tool_search/tool_call are declared for their session — and the shipped rule splits the pair the row keeps together: tool_search is a top-level direct control under CodeModeOnly (DIRECT_ONLY_TOOLS, code-mode.ts:39-51, admitted by the exposure === 'direct-only' filter in getCodeModeFunctionDeclarations, tool-registry.ts:1126-1131), while tool_call is hidden in every mode (const HIDDEN_TOOLS = new Set<string>(['tool_call']);, code-mode.ts:38). The same file's unchanged Status paragraph states that split correctly ("tool_search is now a top-level direct control … tool_call stays hidden", code-mode-only.md:12-16), so the table and the Status paragraph disagree about whether the two bridge tools share a rule. Every other row in this table names modes explicitly ("CodeMode and CodeModeOnly", "CodeMode only"), making this the one cell a reader cannot resolve to a tools.mode value.

Witness:

`Source: [probe]` sweep — `grep -rn 'strict mode|strict \`|严格模式' **/*.md` over the whole worktree: as a **tool-mode** term the phrase occurs exactly **once** in EN docs (this row) and once in its ZH twin; every other hit is an unrelated domain (TypeScript strict mode, Ajv strict, screen-reader strict, `parseLastEventId`). `ToolMode` has three values (code-mode.ts:22-26) and no setting or code path names one "strict". Mitigation I found and the finder did not weigh: the sibling EN doc this same PR adds glosses it adjectivally — `code-mode.md:22` "the strict `CodeModeOnly` exposure policy" — and

Suggested fix: Replace the cell with mode names and split the pair, e.g. two rows — | tool_search | CodeModeOnly top level; existing Direct/CodeMode behavior | No | and | tool_call | Hidden in every mode | No | — and mirror the change in docs/design/code-mode-only.zh-CN.md:54.

The fix must not violate this existing fact: const HIDDEN_TOOLS = new Set<string>(['tool_call']); and const DIRECT_ONLY_TOOLS = new Set<string>([ToolNames.TOOL_SEARCH, …]) — packages/core/src/tools/code-mode.ts:38-51; the rewritten rows must keep tool_call hidden in every mode and tool_search top-level under CodeModeOnly, matching docs/design/code-mode-only.md:12-16.

Acceptance criterion: N/A (documentation prose; no guard, branch or behaviour to pin). Please prove it by removing the fix and confirming that test goes red.

中文说明

改写后的 exposure 表格行把该表唯一一句关于 bridge 暴露的说明限定在 "strict mode" 下——而这个词在模式词表、代码和其余文档中都不存在(真实枚举是 direct / code_mode / code_mode_only)。读者无法把它对应到任何可配置取值。

— qwen3.8-max via Qwen Code /review (v0.25.0)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Suggestion] R1-2: The new Chinese translation states the opposite of the English original (docs/design/code-mode-only.md:144-148) on Code Mode shell concurrency: EN says "Code Mode Bash calls bypass the read-only command classifier, with the model responsible for keeping dependent calls sequential. Other tools retain their existing concurrency classification"; ZH says the batch is "由现有的只读并发分类器处理" and drops the Bash carve-out entirely.

A reader working from the ZH design concludes that shell calls submitted together inside one exec (await Promise.all([...])) are serialized unless the read-only command checker classifies them as read-only. The shipped behavior is the reverse: packages/core/src/core/coreToolScheduler.ts:1557-1563 returns true for source === 'code_mode' + ToolNames.SHELL + Kind.Execute before isShellCommandReadOnly is ever consulted, so two dependent mutating Bash calls in one batch run in parallel. Someone reasoning about ordering safety, or reviewing a nested-call bug from the ZH doc, starts from a false premise; the ZH doc also contradicts docs/design/code-mode-concurrency.zh-CN.md:20-21 ("Code Mode 中的 Bash 调用跳过只读命令判定"), so the two Chinese designs disagree with each other.

Witness:

driving the real `isToolCallConcurrencySafe` (coreToolScheduler.ts:1546-1564) with the same args, varying only `source`: ``` mutating shell (npm install && git push origin main), source=code_mode -> true mutating shell (npm install && git push origin main), source=model -> false read-only shell (git log --oneline -5), source=code_mode -> true read-only shell (git log --oneline -5), source=model -> true ``` i.e. code-mode Bash is classified concurrency-safe *before* `isShellCommandReadOnly` is consulted — the EN sentence is right, the new ZH sentence is the inverse. ---

Suggested fix: Translate the two missing EN sentences into the ZH paragraph, e.g. replace "…Promise.all 调用会进入同一个 batch,由现有的只读并发分类器处理。" with "…Promise.all 调用会进入同一个 batch。Code Mode 中的 Bash 调用跳过只读命令判定,由模型负责让存在依赖的调用保持串行;其他工具沿用现有的并发分类。"

The fix must not violate this existing fact: packages/core/src/core/coreToolScheduler.ts:1557 — // Code Mode lets the model batch independent shell calls explicitly. guarding if (source === 'code_mode' && canonicalName === ToolNames.SHELL && kind === Kind.Execute) { return true; }; the corrected wording must not reassert read-only classification for code-mode Bash, which docs/design/code-mode-concurrency.zh-CN.md:20 also forbids.

Acceptance criterion: N/A (documentation text; no guard, branch, or behavior to pin). Please prove it by removing the fix and confirming that test goes red.

中文说明

新增中文翻译在 Code Mode shell 并发这一点上与英文原文相反:英文说 "Code Mode Bash calls bypass the read-only command classifier",中文写成"由现有的只读并发分类器处理",恰好把豁免说成了适用。同仓库的 code-mode-concurrency.zh-CN.md:21 与英文一致,可证这是翻译错误。实测 isToolCallConcurrencySafe 对同样的 mutating shell 命令在 source=code_mode 时返回 true、source=model 时返回 false。

— qwen3.8-max via Qwen Code /review (v0.25.0)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Deferred to the next round, not dropped: Critical-only mode is active on this PR and the previous round exhausted its time budget, so this round landed only the blocking agent-core fixes. This documentation correction stays open and is queued for the next round.

中文说明

本轮延后处理(并非忽略):本 PR 已处于仅处理 Critical 的模式(takeover 窗口从第 5 轮起算),且上一轮已耗尽时间预算,因此本轮只落地了阻断性的 agent-core 修复(R3-1:nested-only 白名单撤销 hybrid 直接声明;以及 exec 通道的列表/闸门分歧修复)。该建议保持开放,已排入下一轮队列。具体技术细节见上方英文正文。

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Deferred to the next round, not dropped: Critical-only mode is active on this PR and the previous round exhausted its time budget, so this round landed only the blocking agent-core fixes. This documentation correction stays open and is queued for the next round.

中文说明

本轮延后处理(并非忽略):本 PR 已处于仅处理 Critical 的模式(takeover 窗口从第 5 轮起算),且上一轮已耗尽时间预算,因此本轮只落地了阻断性的 agent-core 修复(R3-1:nested-only 白名单撤销 hybrid 直接声明;以及 exec 通道的列表/闸门分歧修复)。该建议保持开放,已排入下一轮队列。具体技术细节见上方英文正文。

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Deferred to the follow-up queue — recorded, not implemented in this PR: the exposure row's 'strict mode' terminology (docs/design/code-mode-only.md:64). The finding still stands at the current head (b98c160), but this PR is past its early review rounds, so only Critical fixes land here now (AGENTS.md review policy). It is recorded in this round's deferred-findings list, so it reaches the PR's follow-up issue and survives the merge.

中文说明

已推迟到后续跟进队列——已记录,不在本 PR 中实现:暴露表中自创的“strict mode”术语(docs/design/code-mode-only.md:64)。该发现在当前 head(b98c160)上仍然成立,但本 PR 已过早期评审轮次阶段,按 AGENTS.md 的评审策略现在只合入 Critical 修复。它已记录在本轮的 deferred-findings 列表中,会进入本 PR 的跟进 issue,不会随合并丢失。

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Deferred to the follow-up queue — recorded, not implemented in this PR: the ZH concurrency translation contradicting the EN original (code-mode-only.zh-CN.md:124) (same finding as the round-1 thread). The finding still stands at the current head (b98c160), but this PR is past its early review rounds, so only Critical fixes land here now (AGENTS.md review policy). It is recorded in this round's deferred-findings list, so it reaches the PR's follow-up issue and survives the merge.

中文说明

已推迟到后续跟进队列——已记录,不在本 PR 中实现:中文并发翻译与英文原文相反(code-mode-only.zh-CN.md:124)(与第 1 轮讨论串为同一发现)。该发现在当前 head(b98c160)上仍然成立,但本 PR 已过早期评审轮次阶段,按 AGENTS.md 的评审策略现在只合入 Critical 修复。它已记录在本轮的 deferred-findings 列表中,会进入本 PR 的跟进 issue,不会随合并丢失。

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Suggestion] R1-2: N06: The rewritten exposure row conditions the table's only statement about bridge exposure on "strict mode" — a term that exists nowhere in the mode vocabulary, the code, or any other English document — and it groups two tools the code exposes differently.

ToolMode has exactly three values, direct / code_mode / code_mode_only (packages/core/src/tools/code-mode.ts:22-26); no setting, code path, or EN doc defines a "strict mode", and a repo-wide grep over docs/ finds the phrase only on this line (the ZH twin's 严格模式 is glossed only in a different file, docs/design/code-mode.zh-CN.md:104: "tools.mode: "code_mode_only" 选择严格模式"). A user on tools.mode: "code_mode" therefore cannot tell from this table whether hybrid counts as strict, i.e. whether tool_search/tool_call are declared for their session — and the shipped rule splits the pair the row keeps together: tool_search is a top-level direct control under CodeModeOnly (DIRECT_ONLY_TOOLS, code-mode.ts:39-51, admitted by the exposure === 'direct-only' filter in getCodeModeFunctionDeclarations, tool-registry.ts:1126-1131), while tool_call is hidden in every mode (const HIDDEN_TOOLS = new Set<string>(['tool_call']);, code-mode.ts:38). The same file's unchanged Status paragraph states that split correctly ("tool_search is now a top-level direct control … tool_call stays hidden", code-mode-only.md:12-16), so the table and the Status paragraph disagree about whether the two bridge tools share a rule. Every other row in this table names modes explicitly ("CodeMode and CodeModeOnly", "CodeMode only"), making this the one cell a reader cannot resolve to a tools.mode value.

Witness:

`Source: [probe]` sweep — `grep -rn 'strict mode|strict \`|严格模式' **/*.md` over the whole worktree: as a **tool-mode** term the phrase occurs exactly **once** in EN docs (this row) and once in its ZH twin; every other hit is an unrelated domain (TypeScript strict mode, Ajv strict, screen-reader strict, `parseLastEventId`). `ToolMode` has three values (code-mode.ts:22-26) and no setting or code path names one "strict". Mitigation I found and the finder did not weigh: the sibling EN doc this same PR adds glosses it adjectivally — `code-mode.md:22` "the strict `CodeModeOnly` exposure policy" — and

Suggested fix: Replace the cell with mode names and split the pair, e.g. two rows — | tool_search | CodeModeOnly top level; existing Direct/CodeMode behavior | No | and | tool_call | Hidden in every mode | No | — and mirror the change in docs/design/code-mode-only.zh-CN.md:54.

The fix must not violate this existing fact: const HIDDEN_TOOLS = new Set<string>(['tool_call']); and const DIRECT_ONLY_TOOLS = new Set<string>([ToolNames.TOOL_SEARCH, …]) — packages/core/src/tools/code-mode.ts:38-51; the rewritten rows must keep tool_call hidden in every mode and tool_search top-level under CodeModeOnly, matching docs/design/code-mode-only.md:12-16.

Acceptance criterion: N/A (documentation prose; no guard, branch or behaviour to pin). Please prove it by removing the fix and confirming that test goes red.

中文说明

改写后的 exposure 表格行把该表唯一一句关于 bridge 暴露的说明限定在 "strict mode" 下——而这个词在模式词表、代码和其余文档中都不存在(真实枚举是 direct / code_mode / code_mode_only)。读者无法把它对应到任何可配置取值。

— qwen3.8-max via Qwen Code /review (v0.25.0)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Deferred to the next round, not dropped: Critical-only mode is active on this PR and the previous round exhausted its time budget, so this round landed only the blocking agent-core fixes. This documentation correction stays open and is queued for the next round.

中文说明

本轮延后处理(并非忽略):本 PR 已处于仅处理 Critical 的模式(takeover 窗口从第 5 轮起算),且上一轮已耗尽时间预算,因此本轮只落地了阻断性的 agent-core 修复(R3-1:nested-only 白名单撤销 hybrid 直接声明;以及 exec 通道的列表/闸门分歧修复)。该建议保持开放,已排入下一轮队列。具体技术细节见上方英文正文。

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Deferred to the follow-up queue — recorded, not implemented in this PR: the exposure row's 'strict mode' terminology (docs/design/code-mode-only.md:64) (same finding as the round-1 thread). The finding still stands at the current head (b98c160), but this PR is past its early review rounds, so only Critical fixes land here now (AGENTS.md review policy). It is recorded in this round's deferred-findings list, so it reaches the PR's follow-up issue and survives the merge.

中文说明

已推迟到后续跟进队列——已记录,不在本 PR 中实现:暴露表中自创的“strict mode”术语(docs/design/code-mode-only.md:64)(与第 1 轮讨论串为同一发现)。该发现在当前 head(b98c160)上仍然成立,但本 PR 已过早期评审轮次阶段,按 AGENTS.md 的评审策略现在只合入 Critical 修复。它已记录在本轮的 deferred-findings 列表中,会进入本 PR 的跟进 issue,不会随合并丢失。


The direct-control allowlist is centralized and deliberately small. It covers
user interaction (`ask_user_question`), delegation (`agent`), terminal output
Expand Down Expand Up @@ -155,14 +157,13 @@ OpenAI-compatible, and Anthropic adapters all receive the structured `exec`
declaration without provider-specific prompting.

Filtered subagent declarations apply the same policy. For a read-only teammate
or a fork with an execution allowlist, `exec` is the audited gateway while the
exact allowed nested names are carried in its invocation context. The same set
generates the description and is checked again before Core dispatch, so an
explicit allowlist can narrow code-mode-callable nested tools without becoming
prompt-only policy, exposing a hidden bridge, or making `exec` recursive.
For cache-compatible forks, an inherited `exec` declaration represents its
ordinary bindings: an omitted `fork_tools` inherits them, while an explicit
list replaces them with the requested subset.
or a fork with an execution allowlist, `exec` is the audited gateway and the
nested names carried in its invocation context are checked again before Core
dispatch. Explicit ordinary-tool entries narrow that nested set. An inherited
or explicitly allowed `exec` instead represents all surviving ordinary
code-mode-callable bindings, while the agent's own `tools` list still narrows
its direct surface. Hidden bridges remain unavailable and `exec` cannot call
itself.

## Failure and rollback

Expand All @@ -171,9 +172,9 @@ closed before scheduling. Invalid arguments continue to fail in the normal
execution chain. A sandbox startup, protocol, timeout, memory, or teardown
failure becomes an `exec` tool error.

Rollback is setting `tools.codeModeOnly` to false. No session migration or
registry cleanup is required because code mode has no persistent state and the
ordinary registry was never replaced.
Rollback is setting `tools.mode` to `direct`. No session migration or registry
cleanup is required because code mode has no persistent state and the ordinary
registry was never replaced.

## Verification

Expand Down
166 changes: 166 additions & 0 deletions docs/design/code-mode-only.zh-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# CodeModeOnly MVP

[English](code-mode-only.md) | [简体中文](code-mode-only.zh-CN.md)

## 状态

已为 [#10377](https://github.com/QwenLM/qwen-code/issues/10377) 实现。
该功能为可选功能,默认关闭。
Comment thread
qwen-code-review-bot marked this conversation as resolved.
Resolved

## 目标

新增 `tools.mode: "code_mode_only"` 设置,用一个 `exec` JavaScript 工具和少量
必须保留为直接调用的控制面工具,取代面向模型的普通工具面。`exec` 中的代码可通过
`tools.<name>(args)` 调用普通工具,同时不会绕过 Qwen Code 的校验、权限、审批、
hook、遥测、取消、并发或输出预算。

直接模式是兼容性边界:当 `tools.mode` 为 `direct` 时,工具注册、延迟工具行为、
provider 请求和执行均保持不变。

## 非目标

- 定义混合的直接调用和代码调用;详见 [Code Mode](code-mode.zh-CN.md)。
- 在多次 `exec` 调用间持久化 cell、全局变量或值。
- 后台任务、`wait`、`yield`、`store` 或 `load`。
- 原始/freeform provider 调用。
- 在 code mode 中提供 `tool_search` 或 `tool_call` bridge。
- 提供兼容 Node.js 的 sandbox。

## 配置

```json
{
"tools": {
"mode": "code_mode_only"
}
}
```

该设置会解析一次,得到有效的 `ToolMode` 值;`ToolRegistry` 和各执行面使用这一
模式。只有启用某个 code mode 时才注册 `exec`,因此选择 `direct` 也会将它从
诊断信息和 registry 列表中移除。

## 暴露策略

registry 仍是事实来源。暴露只是注册工具之上的视图,而不是第二套 registry。

| 类别 | 模型顶层调用 | `exec` 内的 `tools.*` |
| ----------------------------------------- | ------------------------ | --------------------- |
| `exec` | CodeMode 和 CodeModeOnly | 否 |
| 直接控制工具 | 是 | 否 |
| 已注册的普通工具 | 仅 CodeMode | 是 |
| 隐藏 bridge(`tool_search`、`tool_call`) | 严格模式之外沿用既有行为 | 否 |

直接控制 allowlist 集中维护且刻意保持精简。它覆盖用户交互
(`ask_user_question`)、委派(`agent`)、终止输出约定、
plan/goal/task/team/worktree/session 控制,以及生命周期无法安全隐藏在解释执行程序
后的 ACP host 控制。新工具默认可在 code mode 中调用;增加仅直接调用或隐藏工具时,
必须显式修改策略。

延迟工具保持注册状态和延迟 registry 状态,并可从 `exec` 调用。生成的 `exec`
描述仍会携带这些工具的完整 schema,以及它们在 `ALL_TOOLS` 中的名称和描述:
CodeModeOnly 会隐藏 `tool_search`,嵌套调用也不会以 `functionCall` 出现在历史记录
中,因此后续 reveal 无法补充描述里遗漏的 schema。CodeModeOnly 会跳过延迟预加载
和 ToolSearch 提醒,因为二者都不属于它面向模型的协议。

## 确定性的 JavaScript 接口

每次向 provider 同步工具前,都会从当前 registry 生成 `exec` 描述。工具按规范
名称排序。名称会通过替换无效标识符字符来规范化为 JavaScript 属性;如果名称以
数字开头,还会添加前缀。如果两个规范名称映射到同一个属性,则字典序靠前的名称
胜出,并用一条 warning 指出被省略的冲突项。

描述会定义:

- 全新的异步 JavaScript 执行环境;
- 用于嵌套调用的 `tools.<normalizedName>(args)`;
- 包含规范名称和 JavaScript 名称的 `ALL_TOOLS`;
- `text(value)`、`image(value)`、`audio(value)` 和 `exit()`;
- 从 JSON Schema 确定性生成的类 TypeScript 签名;
- 不提供 Node.js、import、网络 API、timer 和持久状态。
Comment thread
DragonnZhang marked this conversation as resolved.
Resolved

嵌套调用返回一个 JSON-safe 对象,其中包含真实 call id、工具名、状态、输出和
structured content。调用失败或取消时,guest promise 会使用 scheduler/ACP 错误
reject。

## Sandbox 与传输

`exec` 在独立子进程中运行编译为 WebAssembly 的 QuickJS。每次调用都会创建全新
的 QuickJS runtime 和 context。子进程通过 stdio 接收精简的 framed JSON 协议;
其中不包含工具实现或 Qwen 配置。父进程把 JavaScript 名称映射回规范 registry
名称,并分派每次调用。

guest 不提供 Node 全局变量、`require`、`process`、文件系统、socket、模块加载器、
`console`、timer、`Atomics`、`SharedArrayBuffer` 或 `WebAssembly`。由于没有安装
模块加载器,动态和静态 import 都会失败。runtime 的内存和 stack 限制固定。
QuickJS 的 interrupt hook 会限制 guest CPU 预算。当 guest 挂起等待已注册的 host
工具时,该预算和父进程的兜底 watchdog 会暂停;在 guest job 再次运行前恢复。
因此,长时间 build 可以继续使用工具声明的 timeout,同时 guest CPU 死循环无法
逃逸固定预算。源码、协议 frame、helper 输出和最终结果都有上限。

取消操作会中止所有嵌套调用并终止子进程。顶层 promise settled 后,也会在 teardown
前取消未 await 的嵌套调用。子进程、timer、promise handle 或 guest 全局变量都不
会在调用结束后存活。

子进程只接收最小化且经过清理的环境,guest 无法检查该环境。独立进程为解释器故障
提供纵深防御;QuickJS/WASM 是 guest 的 capability 边界。

## 重入式分派

`CoreToolScheduler.schedule()` 无法递归调用:子调用会排在仍在运行的父调用之后,
从而形成死锁。因此,scheduler 会在 invocation 边界绑定 async-local
`ToolCallRuntime` context,`exec` 只与该 context 通信。

scheduler runtime 会将同一 event-loop turn 中收到的嵌套调用合并为一批,并通过
使用相同 `Config` 和 observer 配置的 sibling scheduler 执行。这样无需直接调用
`tool.execute()`,仍能沿用现有的构建/校验、权限、确认、hook、执行、截断、遥测和
并发链路。guest 的连续 await 会生成连续 batch;`Promise.all` 调用会进入同一个
batch,由现有的只读并发分类器处理。嵌套 request id 包含父 id,并携带
Comment on lines +123 to +124

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Suggestion] R1-2: The new Chinese translation states the opposite of the English original (docs/design/code-mode-only.md:144-148) on Code Mode shell concurrency: EN says "Code Mode Bash calls bypass the read-only command classifier, with the model responsible for keeping dependent calls sequential. Other tools retain their existing concurrency classification"; ZH says the batch is "由现有的只读并发分类器处理" and drops the Bash carve-out entirely.

A reader working from the ZH design concludes that shell calls submitted together inside one exec (await Promise.all([...])) are serialized unless the read-only command checker classifies them as read-only. The shipped behavior is the reverse: packages/core/src/core/coreToolScheduler.ts:1557-1563 returns true for source === 'code_mode' + ToolNames.SHELL + Kind.Execute before isShellCommandReadOnly is ever consulted, so two dependent mutating Bash calls in one batch run in parallel. Someone reasoning about ordering safety, or reviewing a nested-call bug from the ZH doc, starts from a false premise; the ZH doc also contradicts docs/design/code-mode-concurrency.zh-CN.md:20-21 ("Code Mode 中的 Bash 调用跳过只读命令判定"), so the two Chinese designs disagree with each other.

Witness:

driving the real `isToolCallConcurrencySafe` (coreToolScheduler.ts:1546-1564) with the same args, varying only `source`: ``` mutating shell (npm install && git push origin main), source=code_mode -> true mutating shell (npm install && git push origin main), source=model -> false read-only shell (git log --oneline -5), source=code_mode -> true read-only shell (git log --oneline -5), source=model -> true ``` i.e. code-mode Bash is classified concurrency-safe *before* `isShellCommandReadOnly` is consulted — the EN sentence is right, the new ZH sentence is the inverse. ---

Suggested fix: Translate the two missing EN sentences into the ZH paragraph, e.g. replace "…Promise.all 调用会进入同一个 batch,由现有的只读并发分类器处理。" with "…Promise.all 调用会进入同一个 batch。Code Mode 中的 Bash 调用跳过只读命令判定,由模型负责让存在依赖的调用保持串行;其他工具沿用现有的并发分类。"

The fix must not violate this existing fact: packages/core/src/core/coreToolScheduler.ts:1557 — // Code Mode lets the model batch independent shell calls explicitly. guarding if (source === 'code_mode' && canonicalName === ToolNames.SHELL && kind === Kind.Execute) { return true; }; the corrected wording must not reassert read-only classification for code-mode Bash, which docs/design/code-mode-concurrency.zh-CN.md:20 also forbids.

Acceptance criterion: N/A (documentation text; no guard, branch, or behavior to pin). Please prove it by removing the fix and confirming that test goes red.

中文说明

新增中文翻译在 Code Mode shell 并发这一点上与英文原文相反:英文说 "Code Mode Bash calls bypass the read-only command classifier",中文写成"由现有的只读并发分类器处理",恰好把豁免说成了适用。同仓库的 code-mode-concurrency.zh-CN.md:21 与英文一致,可证这是翻译错误。实测 isToolCallConcurrencySafe 对同样的 mutating shell 命令在 source=code_mode 时返回 true、source=model 时返回 false。

— qwen3.8-max via Qwen Code /review (v0.25.0)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Deferred to the next round, not dropped: Critical-only mode is active on this PR and the previous round exhausted its time budget, so this round landed only the blocking agent-core fixes. This documentation correction stays open and is queued for the next round.

中文说明

本轮延后处理(并非忽略):本 PR 已处于仅处理 Critical 的模式(takeover 窗口从第 5 轮起算),且上一轮已耗尽时间预算,因此本轮只落地了阻断性的 agent-core 修复(R3-1:nested-only 白名单撤销 hybrid 直接声明;以及 exec 通道的列表/闸门分歧修复)。该建议保持开放,已排入下一轮队列。具体技术细节见上方英文正文。

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Deferred to the follow-up queue — recorded, not implemented in this PR: the ZH concurrency translation contradicting the EN original (code-mode-only.zh-CN.md:124). The finding still stands at the current head (b98c160), but this PR is past its early review rounds, so only Critical fixes land here now (AGENTS.md review policy). It is recorded in this round's deferred-findings list, so it reaches the PR's follow-up issue and survives the merge.

中文说明

已推迟到后续跟进队列——已记录,不在本 PR 中实现:中文并发翻译与英文原文相反(code-mode-only.zh-CN.md:124)。该发现在当前 head(b98c160)上仍然成立,但本 PR 已过早期评审轮次阶段,按 AGENTS.md 的评审策略现在只合入 Critical 修复。它已记录在本轮的 deferred-findings 列表中,会进入本 PR 的跟进 issue,不会随合并丢失。

`source: code_mode` 和 `parentCallId`。

嵌套 scheduler 更新会合并到所属 scheduler 的可见调用中,嵌套 id 的确认响应也会
委派给它。外层模型仍只接收完整的 `exec` 响应。

ACP 沿用其独立审计过的执行链。它的 invocation 边界会绑定相同的 runtime 接口,
嵌套分派通过 `Session.runTool` 重入。因此,ACP 顶层和嵌套调用使用相同的 ACP 权限、
审批、hook、遥测、持久化和取消机制,而不是借用 CLI scheduler 状态或直接执行工具。
ACP 会串行执行普通嵌套调用,与现有直接工具顺序一致;Core scheduler 则保留现有的
安全只读并行 batch。

## Provider 行为

所有 provider 继续使用 `ToolRegistry` 提供的 `FunctionDeclaration[]`。在 Direct
模式下,该数组与现有视图逐字节一致。在 CodeModeOnly 中,它是暴露策略生成的视图,
因此 Gemini/Qwen、OpenAI-compatible 和 Anthropic adapter 都会收到结构化的
`exec` declaration,不需要 provider 专用 prompt。

经过过滤的子智能体 declaration 使用相同策略。对于只读 teammate 或带执行
allowlist 的 fork,`exec` 是经过审计的 gateway,其 invocation context 中携带的嵌套
名称会在 Core 分派前再次校验。显式列出的普通工具会收窄该嵌套集合;继承或显式允许
的 `exec` 则代表所有仍可用的普通 code-mode-callable binding,而智能体自身的
`tools` 列表仍会收窄直接调用面。隐藏 bridge 始终不可用,`exec` 也不能调用自身。

## 失败与回滚

未知、冲突、隐藏、仅直接调用和递归请求的工具都会在调度前 fail closed。无效参数
继续在正常执行链中失败。sandbox 启动、协议、timeout、内存或 teardown 失败会转为
`exec` 工具错误。

回滚方式是将 `tools.mode` 设为 `direct`。无需迁移 session 或清理 registry,
因为 code mode 没有持久状态,且普通 registry 从未被替换。

## 验证

单元和集成测试必须覆盖:

- Direct 和 CodeModeOnly 暴露、延迟保留、冲突处理、确定性描述和显式子智能体过滤。
- 有效/无效 JavaScript、异步顺序、`Promise.all`、helper 输出、throw error、CPU
死循环、内存限制、import、不可用全局变量、隔离、输出限制、取消、未 await 工作和
递归调用。
- 嵌套权限、确认、Pre/Post hook、失败、输出预算、真实名称遥测/UI 更新、MCP 工具
和 scheduler 死锁回归。
- Gemini/Qwen、OpenAI-compatible、Anthropic、headless、interactive、subagent
和 ACP 调用面。

只有通过相关 package 测试、build、typecheck、E2E probe 和两轮干净的完整 diff
自审,才算实现完成。
87 changes: 87 additions & 0 deletions docs/design/code-mode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Code Mode

[English](code-mode.md) | [简体中文](code-mode.zh-CN.md)

## Status

Implemented. The feature is experimental and opt-in.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Suggestion] R1-6: The new hybrid design doc claims full implementation but records nowhere that the wait half of the referenced issue's hybrid mode is absent — wait does not exist in the codebase, and this doc (unlike its sibling) has no Non-goals section to say so.

Issue #10377 defines hybrid as | CodeMode | exec、wait 与直接工具并存 | and its acceptance line reads "Hybrid CodeMode 的 model-visible spec 与 direct + exec/wait 并存 golden tests 在 Phase 6 交付". I grepped the head: there is no ToolNames.WAIT, no name: 'wait' tool, and no yield_control/wait helper anywhere in packages/core/src/code-mode/ — the control plane the issue pairs with exec was never delivered (code-mode-only.md:34 lists it as a non-goal: "Background jobs, wait, yield, store, or load."). A maintainer verifying #10377's Phase 6 acceptance traces to docs/design/code-mode.md, reads "Implemented." plus an acceptance list that omits wait entirely, and ticks the hybrid checkbox on a partial delivery; the missing half is recorded in no document that a Phase-6 auditor would open.

Witness:

`gh issue view 10377 --repo QwenLM/qwen-code` returns the mode table `| CodeMode | `exec`、`wait` 与直接工具并存 | 灰度、调试和模型适配 |`, Phase 6 "增加 direct tools 与 `exec`/`wait` 并存的 Hybrid CodeMode", and the acceptance checkbox "Hybrid CodeMode 的 model-visible spec 与 direct + `exec`/`wait` 并存 golden tests 在 Phase 6 交付" — all exactly as the finding quotes. Against that: `grep "WAIT|EXEC|SKILL" packages/core/src/tools/tool-names.ts` → `EXEC: 'exec'`, `SKILL: 'skill'`, `THREAD_WAIT: 'thread_wait'` — **no `WAIT`/`wait` control tool** (the `\bwait\b` hits under `packages/core/src/code-mode/` are all `code-mode.te

Suggested fix: Add a Non-goals (or Scope) section to docs/design/code-mode.md mirroring the sibling doc — e.g. "- Background jobs, wait, yield, store, or load; hybrid ships exec alongside direct tools only." — and qualify the Status line ("Implemented for the exec half of #10377 Phase 6; wait is not delivered").

The fix must not violate this existing fact: AGENTS.md, General workflow §1: "Provide both an English <name>.md and a Chinese <name>.zh-CN.md version in the same directory … keep both versions complete and synchronized in the same change" — so docs/design/code-mode.zh-CN.md (added by this same diff, ## 状态 → 已实现。该功能为实验性功能,默认关闭。) must carry the identical Non-goals/scope text.

Acceptance criterion: N/A (docs-only; no guard, branch or behaviour to pin). Please prove it by removing the fix and confirming that test goes red.

中文说明

新增的 hybrid 设计文档声称"Implemented",却没有任何地方记录所关联 issue 中 hybrid 模式的 wait 一半并未交付——代码库中不存在 wait 工具,而其姊妹文档在 Non-goals 中明确列出了它。验收 #10377 Phase 6 的维护者会据本文档勾选一个只完成了一半的交付项。

— qwen3.8-max via Qwen Code /review (v0.25.0)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Suggestion] R1-6: The new hybrid design doc claims full implementation but records nowhere that the wait half of the referenced issue's hybrid mode is absent — wait does not exist in the codebase, and this doc (unlike its sibling) has no Non-goals section to say so.

Issue #10377 defines hybrid as | CodeMode | exec、wait 与直接工具并存 | and its acceptance line reads "Hybrid CodeMode 的 model-visible spec 与 direct + exec/wait 并存 golden tests 在 Phase 6 交付". I grepped the head: there is no ToolNames.WAIT, no name: 'wait' tool, and no yield_control/wait helper anywhere in packages/core/src/code-mode/ — the control plane the issue pairs with exec was never delivered (code-mode-only.md:34 lists it as a non-goal: "Background jobs, wait, yield, store, or load."). A maintainer verifying #10377's Phase 6 acceptance traces to docs/design/code-mode.md, reads "Implemented." plus an acceptance list that omits wait entirely, and ticks the hybrid checkbox on a partial delivery; the missing half is recorded in no document that a Phase-6 auditor would open.

Witness:

`gh issue view 10377 --repo QwenLM/qwen-code` returns the mode table `| CodeMode | `exec`、`wait` 与直接工具并存 | 灰度、调试和模型适配 |`, Phase 6 "增加 direct tools 与 `exec`/`wait` 并存的 Hybrid CodeMode", and the acceptance checkbox "Hybrid CodeMode 的 model-visible spec 与 direct + `exec`/`wait` 并存 golden tests 在 Phase 6 交付" — all exactly as the finding quotes. Against that: `grep "WAIT|EXEC|SKILL" packages/core/src/tools/tool-names.ts` → `EXEC: 'exec'`, `SKILL: 'skill'`, `THREAD_WAIT: 'thread_wait'` — **no `WAIT`/`wait` control tool** (the `\bwait\b` hits under `packages/core/src/code-mode/` are all `code-mode.te

Suggested fix: Add a Non-goals (or Scope) section to docs/design/code-mode.md mirroring the sibling doc — e.g. "- Background jobs, wait, yield, store, or load; hybrid ships exec alongside direct tools only." — and qualify the Status line ("Implemented for the exec half of #10377 Phase 6; wait is not delivered").

The fix must not violate this existing fact: AGENTS.md, General workflow §1: "Provide both an English <name>.md and a Chinese <name>.zh-CN.md version in the same directory … keep both versions complete and synchronized in the same change" — so docs/design/code-mode.zh-CN.md (added by this same diff, ## 状态 → 已实现。该功能为实验性功能,默认关闭。) must carry the identical Non-goals/scope text.

Acceptance criterion: N/A (docs-only; no guard, branch or behaviour to pin). Please prove it by removing the fix and confirming that test goes red.

中文说明

新增的 hybrid 设计文档声称"Implemented",却没有任何地方记录所关联 issue 中 hybrid 模式的 wait 一半并未交付——代码库中不存在 wait 工具,而其姊妹文档在 Non-goals 中明确列出了它。验收 #10377 Phase 6 的维护者会据本文档勾选一个只完成了一半的交付项。

— qwen3.8-max via Qwen Code /review (v0.25.0)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Deferred to the next round, not dropped: Critical-only mode is active on this PR and the previous round exhausted its time budget, so this round landed only the blocking agent-core fixes. This documentation correction stays open and is queued for the next round.

中文说明

本轮延后处理(并非忽略):本 PR 已处于仅处理 Critical 的模式(takeover 窗口从第 5 轮起算),且上一轮已耗尽时间预算,因此本轮只落地了阻断性的 agent-core 修复(R3-1:nested-only 白名单撤销 hybrid 直接声明;以及 exec 通道的列表/闸门分歧修复)。该建议保持开放,已排入下一轮队列。具体技术细节见上方英文正文。

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Deferred to the next round, not dropped: Critical-only mode is active on this PR and the previous round exhausted its time budget, so this round landed only the blocking agent-core fixes. This documentation correction stays open and is queued for the next round.

中文说明

本轮延后处理(并非忽略):本 PR 已处于仅处理 Critical 的模式(takeover 窗口从第 5 轮起算),且上一轮已耗尽时间预算,因此本轮只落地了阻断性的 agent-core 修复(R3-1:nested-only 白名单撤销 hybrid 直接声明;以及 exec 通道的列表/闸门分歧修复)。该建议保持开放,已排入下一轮队列。具体技术细节见上方英文正文。

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Deferred to the follow-up queue — recorded, not implemented in this PR: the unimplemented wait half never recorded (docs/design/code-mode.md:9). The finding still stands at the current head (b98c160), but this PR is past its early review rounds, so only Critical fixes land here now (AGENTS.md review policy). It is recorded in this round's deferred-findings list, so it reaches the PR's follow-up issue and survives the merge.

中文说明

已推迟到后续跟进队列——已记录,不在本 PR 中实现:未记录 wait 部分未实现(docs/design/code-mode.md:9)。该发现在当前 head(b98c160)上仍然成立,但本 PR 已过早期评审轮次阶段,按 AGENTS.md 的评审策略现在只合入 Critical 修复。它已记录在本轮的 deferred-findings 列表中,会进入本 PR 的跟进 issue,不会随合并丢失。

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Deferred to the follow-up queue — recorded, not implemented in this PR: the unimplemented wait half never recorded (docs/design/code-mode.md:9) (same finding as the round-1 thread). The finding still stands at the current head (b98c160), but this PR is past its early review rounds, so only Critical fixes land here now (AGENTS.md review policy). It is recorded in this round's deferred-findings list, so it reaches the PR's follow-up issue and survives the merge.

中文说明

已推迟到后续跟进队列——已记录,不在本 PR 中实现:未记录 wait 部分未实现(docs/design/code-mode.md:9)(与第 1 轮讨论串为同一发现)。该发现在当前 head(b98c160)上仍然成立,但本 PR 已过早期评审轮次阶段,按 AGENTS.md 的评审策略现在只合入 Critical 修复。它已记录在本轮的 deferred-findings 列表中,会进入本 PR 的跟进 issue,不会随合并丢失。


## Problem

Qwen Code currently supports direct tool calls and `CodeModeOnly`. The latter
replaces ordinary top-level tools with `exec`, which is useful for orchestration
but prevents a model from choosing direct calls when they are clearer or more
efficient. Codex models this as three tool modes: direct, hybrid Code Mode, and
CodeModeOnly.

## Goal

Add a hybrid `CodeMode` option without changing the existing default or
`CodeModeOnly` behavior.

## Configuration

```json
{
"tools": {
"mode": "code_mode"
}
}
```

The effective modes are:

| `tools.mode` value | Effective mode |
| ------------------ | ---------------- |
| omitted / `direct` | `direct` |
| `code_mode` | `code_mode` |
| `code_mode_only` | `code_mode_only` |

This follows Codex's `ToolMode` serialized values. Safe mode and bare mode
force `direct`.

## Exposure policy

| Surface | `direct` | `code_mode` | `code_mode_only` |
| -------------------- | ------------------------ | ------------------------------- | ---------------- |
| Ordinary eager tools | Direct | Direct and nested | Nested only |
| Deferred tools | `tool_search` | `tool_search` and nested | Nested only |
| Direct-control tools | Direct | Direct only | Direct only |
| `exec` | Hidden | Direct | Direct |
| Hidden bridge tools | Existing direct behavior | Direct where already applicable | Hidden |

In `code_mode`, ordinary visible tool descriptions gain an `exec` declaration
for that tool. The `exec` description keeps the complete `ALL_TOOLS` metadata
but does not duplicate every schema. Deferred tools gain their declaration when
their normal top-level declaration is revealed. In `code_mode_only`, the
existing behavior remains: all nested declarations live in the `exec`
description because no later top-level reveal is possible.

Filtered subagent declarations preserve the same mode. The agent's `tools`
list narrows its direct surface. Explicit ordinary-tool execution entries
narrow the nested set, while an inherited or explicitly allowed `exec` carries
all surviving code-mode-callable bindings.

## Constraints and risks

- Normal direct declarations must remain byte-for-byte unchanged in `direct`.
- Nested calls continue through the existing scheduler or ACP execution path;
the mode must not bypass validation, permissions, hooks, cancellation, or
telemetry.
- Duplicating every schema in hybrid mode would increase prompt size, so only
the per-tool nested declaration is appended there.

## Validation

- Verify mode resolution and safe/bare-mode fallback.
- Verify direct, hybrid, and CodeModeOnly declaration surfaces.
- Verify filtered subagent declarations and nested allowlists.
- Run focused Core and CLI tests, then build and typecheck.

## Acceptance criteria

- `tools.mode: "code_mode"` registers `exec` while retaining ordinary direct
tools and deferred discovery.
- Ordinary visible tools advertise their nested JavaScript signature.
- `tools.mode: "code_mode_only"` selects the stricter behavior.
- The default, safe-mode, and bare-mode surfaces remain direct-only.
Loading
Loading