fix: 自动注入 settings.local.json 解决 bot 场景 Bash 权限失败#257
Conversation
在 bot/飞书场景下,项目级 .claude/settings.json 的 permissions.allow 白名单过严会导致 Bash 写命令触发交互式权限审批,但无终端环境下 审批请求无法送达,报 "Stream closed" 错误。 现在 setupWorkspace 在 clone 完成后自动注入 .claude/settings.local.json, 预置 git/npm/npx/gh 等基础命令的白名单,覆盖项目级限制。 已存在的 settings.local.json 不会被覆盖。 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Claude finished @lishuceo's task in 4m 1s —— View job Code Review: 自动注入 settings.local.jsonVerdict: ✅ Approved — clean, well-scoped fix. One test-quality suggestion + a couple of minor notes below.
AssessmentThe fix is sound. Worth noting for context: 🟡 Test does not exercise the real function (confidence: 80)
Suggestion: Minor notes (non-blocking)
|
|
Claude finished @lishuceo's task in 2m 37s —— View job Code Review (re-review on synchronize): 自动注入 settings.local.json
Verdict: Production code — ✅ good
🟡 Test still re-implements logic instead of calling the real function (confidence: 85)This was flagged in the prior review and is not yet addressed in the current revision:
Consequence: the assertions pass against locally-constructed objects, so if the real allowlist in Suggested fix:
Minor notes (non-blocking, unchanged from prior review)
I can apply the export + test rewrite if you'd like — just say the word. |
Review 指出测试重新实现了逻辑而非调用真实函数,导致无法检测漂移。 现在导出 injectLocalSettings 并在测试中直接 import 调用,覆盖: - 文件创建 + 白名单内容验证 - .claude 目录不存在时自动创建 - 已存在文件不被覆盖 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Claude finished @lishuceo's task in 2m 53s —— View job Re-review (synchronize): 自动注入 settings.local.json
Verdict: ✅ Approved — 1 previous issue fixed. No new issues. Previously-flagged issue — ✅ ResolvedThe "test re-implements logic instead of calling the real function" finding from the prior two reviews is now properly addressed:
Coverage is solid and exercises the actual code path:
This now satisfies CLAUDE.md's testing policy (新功能必须附带单元测试 against the real implementation). Production code — ✅ good (unchanged from prior reviews)
Minor notes (non-blocking, carried over — author's discretion)
|
Summary
.claude/settings.local.json,预置 git/npm/npx/gh 等基础命令白名单settings.local.json不会被覆盖,保留用户自定义配置Root Cause
SDK 的
permissionMode: 'acceptEdits'只自动批准 Edit/Write。对于不在项目permissions.allow中的 Bash 命令,SDK 会尝试交互式权限审批,在无终端的飞书 bot 环境下直接失败。Test plan
.claude/settings.local.json存在且包含正确白名单settings.local.json的 workspace 不被覆盖git add/git commit不再报 Stream closed🤖 Generated with Claude Code