fix: reduce false approval popups without policy changes - #3
Open
joejojoking-cloud wants to merge 1 commit into
Open
fix: reduce false approval popups without policy changes#3joejojoking-cloud wants to merge 1 commit into
joejojoking-cloud wants to merge 1 commit into
Conversation
Three safety-no-loss changes to the deterministic and classifier layers: - shell.ts: recognize PowerShell variable assignments ( = 5, = 'abc', = @'...'@) as assignment targets, not commands. A pure-literal RHS (reusing the tokenizer's own dynamic/glob flags; quoted interpolated words stay out) is allowed; any other RHS is assessed recursively through the full command machinery with redirection targets preserved. No dataflow analysis: ' = 5; Remove-Item ' still asks. Kills the 'command name is produced by a dynamic expansion' popups on routine assignment lines. - index.ts: LRU cache of final classifier verdicts (TTL 60s, 128 entries). Key is a sha256 of the FULL sanitized payload including trustedUserMessages and the model route, so a verdict conditioned on one session's user authorization can never be reused by another session's identical call. ask verdicts are never cached - caching them would bypass the approval popup. Repeated calls in a loop hit the classifier once. - index.ts: retry the classifier once before fail-closing to approval, so a transient timeout or network jitter no longer pops an approval request. An aborted tool call skips the retry and fails closed immediately. Config: classifierCacheTtlMs (60s), classifierCacheMaxEntries (128). Tests: 77 pass (11 new).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
Auto 权限模式在真实使用中审批弹窗偏频繁。三类误报(均不涉及判定策略本身的改动,只修误判、减冗余):
$x = 5、$x = 'abc'、$script = @'...'@等赋值语句的首词被 tokenizer 标记为 dynamic,走manualReview直接弹审批——实际是赋值目标而非命令,最常见的误报来源。改动
1. PowerShell 赋值识别(
shell.ts)$x = 5、$x = 'abc'、$script = @'...'@(多行 here-string)、$x = $null/$true/$false、$x = $y、$x = $env:PATH→ 直接 allow(RHS 不执行任何命令)$x = Get-ChildItem、$x = git commit、$x = Remove-Item $y)→ 递归走完整评估管线,删除检查、git 检查、分类器路由全部保留,重定向目标随递归保留"$y"、@"..."@、$(...)(opaque)绝不算字面量$x = 5; Remove-Item $x仍弹审批($x可能被其他路径修改)x=5语法不受影响2. 分类器判定缓存(新增
classifier-cache.ts+index.ts)classifierCacheTtlMs、classifierCacheMaxEntries(有默认值,现有{}配置无需改动)3. 分类器失败重试一次(
index.ts)exec.signal.aborted时跳过重试直接 fail-closed(工具已取消,重试无意义)测试
pnpm verify全绿:typecheck + build + 77 tests(新增 11 个:赋值识别 5 组、缓存单元 4、缓存/重试集成 5,含"跨会话不同 trustedUserMessages 不命中缓存"、"中止不重试"等安全用例)。