Skip to content

Commit 9ca489a

Browse files
committed
fix(mode): acceptEdits auto-allows read tools inside cwd (superset of default)
1 parent 1c6693e commit 9ca489a

2 files changed

Lines changed: 30 additions & 8 deletions

File tree

hooks/common.sh

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,9 @@ overlay_available() {
361361
#
362362
# Mode behavior:
363363
# bypassPermissions: always 0 (everything auto-allowed).
364-
# acceptEdits: 0 for Write/Edit/NotebookEdit/MultiEdit when the
365-
# target file_path resolves inside cwd. Non-edit tools
366-
# in acceptEdits return 1.
364+
# acceptEdits: superset of default. 0 for Write/Edit/NotebookEdit/
365+
# MultiEdit + Read/Grep/Glob/NotebookRead/LS when the
366+
# target path resolves inside cwd.
367367
# default (+ empty mode value): 0 for read-only tools
368368
# (Read/Grep/Glob/NotebookRead/LS) when the target path
369369
# is inside cwd. Everything else returns 1, including
@@ -408,6 +408,8 @@ permission_mode_auto_allows() {
408408

409409
case "$mode" in
410410
acceptEdits)
411+
# acceptEdits is a superset of default: everything default auto-allows
412+
# (Read/Grep/Glob/LS inside cwd) PLUS edit tools inside cwd.
411413
case "$tool_name" in
412414
Write|Edit|NotebookEdit|MultiEdit)
413415
local fp
@@ -417,6 +419,25 @@ permission_mode_auto_allows() {
417419
fi
418420
return 1
419421
;;
422+
Read|NotebookRead)
423+
local fp
424+
fp="$(jq -r '.file_path // .notebook_path // ""' <<<"$tool_input" 2>/dev/null || printf '')"
425+
if _pm_path_inside_cwd "$fp" "$cwd"; then
426+
return 0
427+
fi
428+
return 1
429+
;;
430+
Grep|Glob|LS)
431+
local gp
432+
gp="$(jq -r '.path // ""' <<<"$tool_input" 2>/dev/null || printf '')"
433+
if [ -z "$gp" ]; then
434+
return 0
435+
fi
436+
if _pm_path_inside_cwd "$gp" "$cwd"; then
437+
return 0
438+
fi
439+
return 1
440+
;;
420441
*)
421442
return 1
422443
;;

tests/hook_handler.bats

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -953,18 +953,19 @@ run_handler_in_stub_root() {
953953
[ "$decision" = "ask" ]
954954
}
955955

956-
@test "mode: acceptEdits + Read (non-edit tool) -> overlay path entered" {
957-
# Read is NOT in the acceptEdits allow-list; acceptEdits only covers
958-
# Write/Edit/NotebookEdit/MultiEdit. A Read call falls through to overlay.
959-
setup_overlay_stub "yes_once"
956+
@test "mode: acceptEdits + Read inside cwd -> mode auto-allow (superset of default)" {
957+
# acceptEdits is a superset of default: it auto-allows everything default
958+
# does (Read/Grep/Glob inside cwd) PLUS edit tools inside cwd.
960959
ti="$(jq -cn --arg fp "$PROJ_ROOT/src/foo.ts" '{file_path:$fp}')"
961960
payload="$(make_mode_payload 'Read' "$ti" 'acceptEdits' "$PROJ_ROOT")"
962-
run_handler_in_stub_root "$payload"
961+
run_handler "$payload"
963962
[ "$status" -eq 0 ]
964963
json_line="$(printf '%s\n' "$output" | grep -o '{"hookSpecificOutput".*}' | head -n1)"
965964
[ -n "$json_line" ]
966965
decision="$(jq -r '.hookSpecificOutput.permissionDecision' <<<"$json_line")"
967966
[ "$decision" = "allow" ]
967+
reason="$(jq -r '.hookSpecificOutput.permissionDecisionReason' <<<"$json_line")"
968+
[[ "$reason" == *"mode-allow"* ]]
968969
}
969970

970971
# default mode: all tools go to overlay ----------------------------------------

0 commit comments

Comments
 (0)