fix(sdk): support "auto" permission mode - #9003
Conversation
|
✅ Qwen Triage finished — CI landed green on ✅ Qwen Triage 已完成 —— |
|
Thanks for the PR!
Moving on to code review. 🔍 中文说明感谢贡献!
进入代码审查 🔍 — Qwen Code · qwen3.8-max Reviewed at |
Code reviewThe approach matches what I'd have done independently: add
One non-blocking note: the Test evidence (the PR's own CI — fork code is never run here)The Final CI results for
One row per check name (latest run); skipped checks omitted; failures sort first. / 每个检查名一行(取最新一次运行),省略 skipped,失败项排在最前。 中文说明代码审查方案与我独立设想的一致:把
一条非阻塞提醒: 测试证据(来自 PR 自身的 CI——此处不运行 fork 代码)
— Qwen Code · qwen3.8-max Reviewed at |
|
Confidence: 4/5 — clean, minimal parity fix with the change pinned by green CI; the only nit is the stale mode table in Stepping back: the problem was real — reported with the exact error message and confirmed against the base code — and the fix is the smallest possible one: widen the accepted set, its public type, the error message, and the README. That matches my independent proposal exactly; nothing in the diff is unnecessary. The new parametrized test genuinely pins the behavior, and the SDK Python jobs (3.10/3.11/3.12) ran it green on this commit, which is the signal that matters for a Python-only change. The Node unit suite is still running, so I'm not approving this second — approval is deferred until CI lands green on In six months this reads as a one-line fix with a test covering it — nothing to curse the author for. 中文说明置信度:4/5 —— 干净的最小 parity 修复,改动已被绿色的 CI 钉住;唯一的瑕疵是 退一步看:问题真实存在——报告里带了确切的报错信息,且已对照基线代码确认——修复也是最小可行方案:放宽合法值集合、公开类型、报错信息与 README。这与我独立设想的方案完全一致,diff 中没有多余内容。新的参数化测试确实钉住了行为,SDK Python 任务(3.10/3.11/3.12)在本提交上跑绿,对纯 Python 改动而言这就是关键信号。Node 单测套件仍在运行,所以此刻不批准——批准推迟到 CI 在 六个月后回头看,这是一行修复加一个覆盖它的测试——没什么可抱怨的。 — Qwen Code · qwen3.8-max Reviewed at |
qwen-code-ci-bot
left a comment
There was a problem hiding this comment.
Reviewed. Suggestions are inline.
Not explored to full depth (tool budget reached): This PR adds auto permission mode support to the Python...: none — all checks I started were completed within budget..
中文说明
已审查。 建议见行内评论。
未探索到全部深度(达到工具调用预算):This PR adds auto permission mode support to the Python...:none — all checks I started were completed within budget.。
— qwen3.8-max via Qwen Code /review (v0.21.10)
qwen-code-ci-bot
left a comment
There was a problem hiding this comment.
LGTM, looks ready to ship — CI landed green after the review. ✅
|
Qwen precheck requires maintainer approval before automated triage/review. Head SHA: Reason:
A maintainer with write access can inspect the PR and manually request a run with |
yiliang114
left a comment
There was a problem hiding this comment.
Approving. The accepted set now derives from the public PermissionMode type via set(get_args(PermissionMode)), so it can no longer drift from the documented list, and the parametrized test pins every mode. CI is green on the latest head (Python Ruff/Mypy/pytest plus the Node unit suite). Thanks for the parity fix.
chiga0
left a comment
There was a problem hiding this comment.
Tier: Standard — Targeted addition of "auto" permission mode across Python and Java SDKs, with a validation refactor.
What I verified
| Area | Check | Result |
|---|---|---|
| Python types | "auto" added to PermissionMode Literal |
✓ |
| Python validation | _VALID_PERMISSION_MODES = set(get_args(PermissionMode)) — no hand-maintained copy, cannot drift |
✓ |
| Python transport | transport.py:215-216 — args.extend(["--approval-mode", options.permission_mode]) forwards verbatim |
✓ |
| Java enum | AUTO("auto") in PermissionMode.java, .getValue() returns "auto" |
✓ |
| Java transport | TransportOptionsAdapter.java:76-78 — args.add(getPermissionMode().getValue()) → --approval-mode auto |
✓ |
| Python tests | Parametrized test covers all 5 modes; rejection test uses dynamic expected message with re.escape() |
✓ |
| Java tests | assertEquals("auto", PermissionMode.AUTO.getValue()) |
✓ |
| CI | Python 3.10/3.11/3.12, Java 11/17/21, Desktop Shell, Real daemon E2E, web-shell E2E — all green | ✓ |
The get_args() refactor (addresses the CI bot's round-1 concern) is a clear improvement: the accepted set and the error message now derive directly from the public type alias, making the three-way drift the previous approach had structurally impossible.
No blockers found.
|
Released in v0.22.0. |
What this PR does
The Python and Java SDKs now accept
autoas a permission mode in their startup options, aligning them with the CLI and the TypeScript SDK. In the Python SDK the accepted-values list, its validation error message, the public mode type, and the README are updated accordingly, and the validation tests now cover every accepted mode. In the Java SDK thePermissionModeenum gains theAUTOconstant, its protocol type definition and README are updated, and the enum test covers the new value.Why it's needed
The CLI supports an
autoapproval mode in which an LLM classifier approves tool calls, and the TypeScript SDK already exposes it end to end. The Python SDK's client-side validation rejected the value before it could reach the CLI, so Python users could not start a session in this mode — only switching modes at runtime worked, because that path skips local validation. The Java SDK'sPermissionModeenum had noAUTOconstant either. Reported in #9002, where fixing both SDKs in the same pass was requested so they stay consistent.Reviewer Test Plan
How to verify
This is a non-user-visible change (types + validation). For the Python SDK, install the package with dev extras (
pip install -e 'packages/sdk-python[dev]') and run the checks:python -m pytest -c packages/sdk-python/pyproject.toml packages/sdk-python/tests -q, plusruff format --checkandmypyon the package. All 165 tests pass locally, including new cases proving each documented mode is accepted and that an unknown mode is still rejected. Passingpermission_mode="auto"no longer raisesValidationErrorand is forwarded to the CLI as--approval-mode auto. For the Java SDK, runmvn testinpackages/sdk-java/qwencode: all 128 tests pass, including the extendedPermissionModeTestassertingPermissionMode.AUTO.getValue()is"auto"; the transport layer forwards the mode's value verbatim as--approval-mode, so no transport change was needed.Evidence (Before & After)
N/A (non-UI change). Before:
ValidationError: Invalid permission_mode: 'auto'. Expected one of: default, plan, auto-edit, yolo.After: the option is accepted and passed through to the CLI in both SDKs.Tested on
Environment (optional)
Python 3.12 virtual environment (uv) running pytest, mypy, and ruff against the package; OpenJDK 21 (Temurin) with Maven for the Java SDK.
Risk & Scope
Linked Issues
Closes #9002
中文说明
本次 PR 内容
Python 和 Java SDK 的启动选项现在都接受
auto权限模式,与 CLI 和 TypeScript SDK 对齐。Python SDK 的合法值列表、校验报错信息、公开的模式类型以及 README 都相应更新,校验测试现在覆盖了所有合法模式。Java SDK 的PermissionMode枚举新增AUTO常量,其协议类型定义和 README 同步更新,枚举测试覆盖了新取值。为什么需要
CLI 支持
auto审批模式(由 LLM 分类器审批工具调用),TypeScript SDK 已全链路支持。而 Python SDK 的客户端校验在该值到达 CLI 之前就拒绝了它,导致 Python 用户无法以该模式启动会话——只有运行时切换模式可行,因为那条路径跳过了本地校验。Java SDK 的PermissionMode枚举同样缺少AUTO常量。详见 #9002,其中要求两个 SDK 一并修复以保持一致。评审者测试计划
如何验证
这是非用户可见的改动(类型 + 校验)。Python SDK:安装开发依赖(
pip install -e 'packages/sdk-python[dev]')后运行python -m pytest -c packages/sdk-python/pyproject.toml packages/sdk-python/tests -q,外加对包执行ruff format --check和mypy。本地 165 个测试全部通过,其中包括证明每个文档记载的模式都被接受、未知模式仍被拒绝的新用例。传入permission_mode="auto"不再抛出ValidationError,并会作为--approval-mode auto转发给 CLI。Java SDK:在packages/sdk-java/qwencode下运行mvn test,128 个测试全部通过,包括扩展后的PermissionModeTest(断言PermissionMode.AUTO.getValue()为"auto");传输层原样透传模式取值作为--approval-mode,无需改动。前后对比
N/A(非 UI 改动)。改动前:
ValidationError: Invalid permission_mode: 'auto'. Expected one of: default, plan, auto-edit, yolo.;改动后:两个 SDK 中该选项都被接受并透传给 CLI。测试平台
仅在 Linux 上验证;macOS、Windows 未测试。
环境(可选)
Python 3.12 虚拟环境(uv),对包运行 pytest、mypy、ruff;Java SDK 使用 OpenJDK 21(Temurin)和 Maven。
风险与范围
关联 Issue
Closes #9002