fix(agent-core): keep session approval for commands with special chars (#325)#496
Open
fancive wants to merge 1 commit into
Open
fix(agent-core): keep session approval for commands with special chars (#325)#496fancive wants to merge 1 commit into
fancive wants to merge 1 commit into
Conversation
MoonshotAI#325) Session-level "Approved for this session" stopped working for Bash commands containing quotes/parens/pipes: the command would be re-prompted every time. Root cause: escapeRuleSubjectLiteral() backslash-escapes glob metacharacters when storing the approval rule, but matchesGlobRuleSubject() re-matches the stored pattern through picomatch (globMatch). picomatch drops the double quotes adjacent to the escaped parens, so e.g. the stored rule Bash(python -c "print\('1'\)") never matches the command it was created from python -c "print('1')" and the user is asked to approve the identical command again. Fix: add an exact-literal fast path in matchesGlobRuleSubject() — if the stored rule subject unescapes back to a literal byte-for-byte equal to the command, treat it as a match before handing the string to picomatch. Genuine glob rules (no escaped metacharacters) are unchanged and still fall through to globMatch. Adds regression tests covering quoted parentheses and quoted pipelines that assert the second identical call reuses the session approval (no re-prompt) and that a changed command still prompts. Change-Id: I04846520621185bc0848cc92b3d01a1979de37a6
🦋 Changeset detectedLatest commit: a7f4f22 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Summary
Fixes #325. Session-level "Approve for this session" stopped working for
Bashcommands containing quotes, parentheses, or pipes — the user was prompted to approve the identical command on every call.Root cause
When a command is approved for the session, the rule subject is stored with glob metacharacters backslash-escaped via
escapeRuleSubjectLiteral(). On the next call,matchesGlobRuleSubject()re-matches the stored pattern through picomatch (globMatch). picomatch drops the double quotes adjacent to the escaped parens, so the stored rulenever matches the command it was created from
and the session approval is effectively ignored.
Fix
Add an exact-literal fast path in
matchesGlobRuleSubject(): if the stored rule subject unescapes back to a literal that is byte-for-byte equal to the command, treat it as a match before handing the string to picomatch. Genuine glob rules (which contain no escaped metacharacters) are unchanged and still fall through toglobMatch, so wildcard rules keep working.Tests
Added regression coverage in
packages/agent-core/test/agent/permission.test.tsforBashcommands containing quotes + parentheses and quotes + pipes, asserting that:Verified locally:
@moonshot-ai/agent-coresuite 2495 passed / 0 failed, full monorepopnpm test5995 passed / 0 failed,typecheckandlintclean.