-
Notifications
You must be signed in to change notification settings - Fork 3k
fix(core): show edit/exec diffs when a PreToolUse hook returns ask #9441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yiliang114
wants to merge
16
commits into
main
Choose a base branch
from
fix/9434-hook-ask-diff
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,271
−748
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
70121e2
fix(core): show edit/exec diffs when a PreToolUse hook returns ask
yiliang114 e0e0617
fix(core): preserve hookAskReason when restricting bubbled edit/exec …
yiliang114 b996ea4
fix(core,cli): close PreToolUse ask-bounce abort/rendering gaps (#943…
yiliang114 1b7e768
test(core): pin hookAskReason passthrough in the approval restriction
yiliang114 4fbc8b3
Merge branch 'main' into fix/9434-hook-ask-diff
yiliang114 4585a3d
fix(shell): keep a user-confirmed sed edit across a re-entrant preview
yiliang114 b0558f8
fix(core): re-apply plan-shell policy in the PreToolUse ask bounce
yiliang114 60db259
fix(core): close round-4 ask-bounce findings (#9434)
yiliang114 2e64af9
fix(core): close round-5 ask-bounce findings (#9434)
yiliang114 611d995
fix(core): close round-6 ask-bounce findings (#9434)
yiliang114 c2bfc3b
fix(core): invalidate round-1 IDE diff on PreToolUse ask bounce (#9434)
yiliang114 57b6b90
fix(core): close round-8 ask-bounce findings (#9434)
yiliang114 b74c60a
Merge remote-tracking branch 'origin/main' into fix/9434-hook-ask-diff
yiliang114 adda82a
Merge remote-tracking branch 'origin/main' into HEAD
yiliang114 fd61782
test(core): remove duplicate scheduler stub
yiliang114 2b43f0c
test(cli): colocate permission-suggestions test with its module
yiliang114 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
85 changes: 85 additions & 0 deletions
85
packages/cli/src/nonInteractive/permission-suggestions.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2025 Qwen | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { describe, it, expect } from 'vitest'; | ||
| import { buildPermissionSuggestions } from './permission-suggestions.js'; | ||
|
yiliang114 marked this conversation as resolved.
|
||
|
|
||
| describe('buildPermissionSuggestions', () => { | ||
| it('prepends the hook ask reason on exec and edit suggestions', () => { | ||
| // A PreToolUse hook escalated these calls (#9434): the stream-json | ||
| // can_use_tool suggestions must carry the reason so a hook-forced | ||
| // prompt is distinguishable from an ordinary one off-TUI. | ||
| const exec = buildPermissionSuggestions({ | ||
| type: 'exec', | ||
| title: 'Confirm shell', | ||
| command: 'git status', | ||
| rootCommand: 'git', | ||
| hookAskReason: 'path requires human review', | ||
| onConfirm: async () => undefined, | ||
| }); | ||
| expect(exec?.[0]?.description).toBe( | ||
| 'Hook requested confirmation: path requires human review\nExecute: git status', | ||
| ); | ||
|
|
||
| const edit = buildPermissionSuggestions({ | ||
| type: 'edit', | ||
| title: 'Confirm edit', | ||
| fileName: 'a.txt', | ||
| filePath: '/tmp/a.txt', | ||
| fileDiff: 'diff', | ||
| originalContent: 'a', | ||
| newContent: 'b', | ||
| hookAskReason: 'path requires human review', | ||
| onConfirm: async () => undefined, | ||
| }); | ||
| expect(edit?.[0]?.description).toBe( | ||
| 'Hook requested confirmation: path requires human review\nEdit file: a.txt', | ||
| ); | ||
| }); | ||
|
|
||
| it('prepends the hook ask reason on info suggestions (ask-bounce fallback)', () => { | ||
| // Tools without a structured view land in the ask bounce's synthetic | ||
| // info prompt; the stream-json suggestions must carry the hook reason | ||
| // there too (#9434 review R5-2). | ||
| const info = buildPermissionSuggestions({ | ||
| type: 'info', | ||
| title: 'Hook requested confirmation to run web_fetch', | ||
| prompt: 'network egress requires human review', | ||
| hookAskReason: 'network egress requires human review', | ||
| onConfirm: async () => undefined, | ||
| }); | ||
| expect(info?.[0]?.description).toBe( | ||
| 'Hook requested confirmation: network egress requires human review\n' + | ||
| 'Hook requested confirmation to run web_fetch', | ||
| ); | ||
| }); | ||
|
|
||
| it('keeps warnings below the hook reason and above the description', () => { | ||
| const exec = buildPermissionSuggestions({ | ||
| type: 'exec', | ||
| title: 'Confirm shell', | ||
| command: 'curl $(evil)', | ||
| rootCommand: 'curl', | ||
| warnings: ['Contains command substitution'], | ||
| hookAskReason: 'network egress', | ||
| onConfirm: async () => undefined, | ||
| }); | ||
| expect(exec?.[0]?.description).toBe( | ||
| 'Hook requested confirmation: network egress\nContains command substitution\nExecute: curl $(evil)', | ||
| ); | ||
| }); | ||
|
|
||
| it('leaves ordinary suggestions unchanged without a hook reason', () => { | ||
| const exec = buildPermissionSuggestions({ | ||
| type: 'exec', | ||
| title: 'Confirm shell', | ||
| command: 'git status', | ||
| rootCommand: 'git', | ||
| onConfirm: async () => undefined, | ||
| }); | ||
| expect(exec?.[0]?.description).toBe('Execute: git status'); | ||
| }); | ||
| }); | ||
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.