Skip to content

Commit 6e46e9d

Browse files
author
igor
committed
agent-helpers: expose upstream-pr-prep as a safe-agent-action subcommand
Problem: invoking agent-helpers/upstream-pr-prep.sh directly does not match the PreToolUse auto-approval hook's regex (which matches only 'safe-agent-action.sh'), so every call prompted the operator for permission. Fix: add an 'upstream-pr-prep' case to the wrapper that execs the helper script with all args passed through. The agent-facing invocation is now: agent-helpers/safe-agent-action.sh upstream-pr-prep --commit X ... which the auto-approval hook matches on 'safe-agent-action.sh' in the command string. The wrapper's exec replaces the shell process with the helper script, so all internal git/make subprocesses run inside the single Bash tool call — no further prompts. The helper script at agent-helpers/upstream-pr-prep.sh is unchanged and still directly executable (operators debugging it will see a one-time prompt per invocation, which is acceptable for debugging). Also updates the wrapper's 'help' text and agents.md to document the new subcommand as the canonical invocation path.
1 parent 4302628 commit 6e46e9d

2 files changed

Lines changed: 38 additions & 3 deletions

File tree

agent-helpers/safe-agent-action.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,25 @@ EOF
336336
exit 2
337337
;;
338338

339+
# ====================================================================
340+
# Upstream PR prep (wrapper dispatch to upstream-pr-prep.sh)
341+
# ====================================================================
342+
#
343+
# Why this exists as a subcommand: the auto-approval PreToolUse hook
344+
# matches 'safe-agent-action.sh' in the command string. If the agent
345+
# calls upstream-pr-prep.sh directly, the hook doesn't match and the
346+
# agent gets prompted on every invocation. Dispatching through this
347+
# subcommand means the agent-facing invocation is
348+
# 'safe-agent-action.sh upstream-pr-prep ...' which the hook approves
349+
# automatically. The helper script itself stays intact and directly
350+
# executable for operator debugging.
351+
352+
upstream-pr-prep)
353+
# PURPOSE: Repeatable upstream LinuxCNC PR prep via cherry-pick.
354+
# See agent-helpers/upstream-pr-prep.sh --help for full usage.
355+
exec "$SCRIPT_DIR/upstream-pr-prep.sh" "$@"
356+
;;
357+
339358
# ====================================================================
340359
# Process inspection (read-only)
341360
# ====================================================================
@@ -557,6 +576,15 @@ Branch-per-session workflow:
557576
session-push Push current branch to origin. Refuses on main/master.
558577
session-merge <name> Prints the merge sequence (does NOT execute).
559578
579+
Upstream PR prep:
580+
upstream-pr-prep <args>...
581+
Dispatch to agent-helpers/upstream-pr-prep.sh.
582+
Cherry-picks a fork commit onto a clean branch
583+
based on upstream/master via git worktree, with
584+
dynamic gh-api-user author and strict diff
585+
verification. Mode flags: --build --push --cleanup
586+
--dry-run. Run with --help for full usage.
587+
560588
Process inspection (read-only):
561589
ps [pattern] ps aux, optionally filtered
562590
pgrep <pattern> pgrep -af

agents.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,18 +204,25 @@ cd src && ./configure --with-realtime=uspace && make clean && make -j$(nproc) &&
204204
## Upstream PR prep
205205

206206
When a fix exists on fork `master` and needs to go upstream as a PR
207-
against `LinuxCNC/linuxcnc`, use the helper script — not raw cherry-pick
208-
commands:
207+
against `LinuxCNC/linuxcnc`, use the helper via the wrapper subcommand —
208+
not raw cherry-pick commands, and not the helper script directly (the
209+
latter bypasses the PreToolUse auto-approval hook and prompts per call):
209210

210211
```bash
211-
agent-helpers/upstream-pr-prep.sh \
212+
agent-helpers/safe-agent-action.sh upstream-pr-prep \
212213
--commit <fork-sha> \
213214
--branch <pr-branch-name> \
214215
--message /tmp/upstream-commit-msg.txt \
215216
--worktree /var/tmp/linuxcnc-pr-<branch> \
216217
[--build] [--push] [--cleanup] [--dry-run]
217218
```
218219

220+
The wrapper's `upstream-pr-prep` subcommand is a thin `exec` dispatch to
221+
`agent-helpers/upstream-pr-prep.sh` — the script stays intact and
222+
directly executable for operator debugging, but the agent-facing
223+
invocation should always go through the wrapper so the auto-approval
224+
hook covers it.
225+
219226
Default (no mode flag) runs prep: `git fetch upstream`, `git worktree add`
220227
off `upstream/master`, `git cherry-pick --no-commit`, strict diff
221228
verification, commit with dynamically-resolved GitHub-noreply author

0 commit comments

Comments
 (0)