fix(claude-code): preflight subagent model access - #3043
Conversation
Signed-off-by: ZJPex <3258236335@qq.com>
|
| Filename | Overview |
|---|---|
| apps/desktop/src/main/maker-host/subagent-model-access-policy.ts | 实现基于实际 provider、凭证模式和权威 XD 快照的三态判定,非权威或非 XD 目录缺席均不会产生硬拒绝。 |
| apps/desktop/src/main/model-access/index.ts | 模型同步生命周期会在刷新开始和认证失效时撤销负向证明,仅同认证世代的成功响应恢复 authoritative 状态。 |
| packages/maker-core/src/agents/claude-code/subagent-model-access.ts | 新增本地 Agent/Task PreToolUse guard,统一处理强制模型、显式模型、inherit、异常降级和拒绝文案。 |
| packages/maker-core/src/agents/claude-code/index.ts | 将实时 resolver 接入本地 hook 与远程回调,并携带会话 provider、父模型和有效凭证模式。 |
| packages/maker-cc-manager/src/session-registry.ts | 远程 daemon 在 Agent/Task 执行前反向查询 Desktop,明确 denied 时阻止调用,查询异常按 unknown 放行。 |
| packages/maker-cc-manager/src/protocol.ts | 新增模型准入反向 RPC 类型与方法,并通过协议 v4 阻止不具备该执行边界的旧 daemon 继续连接。 |
Sequence Diagram
sequenceDiagram
participant CC as Claude Code SDK
participant Guard as PreToolUse Guard
participant Manager as cc-manager
participant Desktop as Desktop Resolver
participant Snapshot as XD /models Snapshot
CC->>Guard: Agent/Task(model)
alt 本地会话
Guard->>Desktop: resolve(model, provider, credential)
else 远程会话
Guard->>Manager: resolve(model)
Manager->>Desktop: subagent/model-access
end
Desktop->>Snapshot: 读取当前 authoritative 状态与模型
alt 权威快照明确缺少模型
Desktop-->>Guard: denied
Guard-->>CC: "permissionDecision=deny"
else 包含模型
Desktop-->>Guard: allowed
Guard-->>CC: continue
else 非权威、失败或无法确认
Desktop-->>Guard: unknown
Guard-->>CC: continue
end
Reviews (1): Last reviewed commit: "fix(claude-code): preflight subagent mod..." | Re-trigger Greptile
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 73d963268a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
⏸️ 维护者确认门(arch)已触发。 原因:核心路径改动 728 行,新增子任务模型访问预检子系统(policy 模块 + cc-manager 反向 RPC + 三态校验),跨 maker-core / cc-manager / maker-host 三个包。 讨论 issue 已创建,等维护者在本 PR 上 Approve 后自动放行。 讨论 issue:#3044 |
|
@ZJPex 👋 这个 PR 还有 1 条 review conversation 没 resolve(apps/desktop/src/main/maker-host/subagent-model-access-policy.ts),auto-review 因此暂时跳过、没法继续审查 / 合并。 如果你已经按评论改完或回应了,请到对应 thread 上点 Resolve conversation;全部 resolve 后,下一轮 auto-review 会自动重新审查这个 PR。 |
MagicLizi
left a comment
There was a problem hiding this comment.
Code review passed. Well-designed preflight check with tri-state model access gate, correct fail-open defaults, and good test coverage. Approving to release signoff gate (confirmed bugfix — adds missing model access validation).
|
Nice work on this one — the tri-state classification design (allowed/denied/unknown) with fail-open defaults is exactly the right call for a preflight gate that touches live sessions. 🎯 |
这次改了什么
摘要
Claude Code 的原生
Agent/Task工具允许显式传入sonnet、opus等模型,但 Cindy 过去只做目录诊断,没有在任务启动前结合当前账号的权威模型快照校验。即使 Full access 开启,工具调用也会直接进入 SDK,最终在后台请求阶段才返回 403。本 PR 在 Claude Code
PreToolUse边界增加按调用实时解析的三态预检:/models快照明确排除目标模型时,立即拒绝该 Agent/Task 调用,并建议省略model使用 Agent 原生默认选择。[1m]wire 后缀统一归一化匹配。unknown并放行,避免误拦合法模型。sonnet/opus,也不改变省略model时的既有默认选择逻辑。变更类型
feat新功能fix缺陷修复refactor/perf重构或性能优化docs/test/chore文档、测试或工程维护范围
UI 变化
不涉及:仅修改 Claude Code 工具调用预检、模型目录状态和内部 manager 协议,无视觉、交互或 UI 文案路径变化。
怎么验证的
自动验证
手工验证
不涉及真实付费模型请求;使用生产调用边界的确定性回归测试复现并验证:
model: sonnet且权威快照明确无权限:修复前仍放行,修复后在PreToolUse拒绝。[1m]、省略 model、强制默认模型、账号切换和刷新失败均有覆盖。未执行的验证
/models权威响应,行为由生产边界回归测试覆盖。tsc --noEmit仍受仓库现有无关类型错误影响;本次变更文件未产生新增类型错误。风险
风险分类
影响与回滚
提交前检查
git commit -s,见 DCO)