Add Bash substitution rules#26
Merged
Merged
Conversation
Introduce action: substitute for deterministic PreToolUse Bash command rewrites. Substitute rules use regex replace templates, preserve the provider's full original tool_input, and return permissionDecision: allow with updatedInput so both Claude Code and Codex CLI can proceed without a retry loop. Use hookSpecificOutput.additionalContext as the model-visible explanation of what Nudge rewrote, while keeping systemMessage as the user-visible audit note. Block rules still take priority after substitution, so rewritten commands remain subject to existing policy. Update the rule docs, README, AGENTS/CLAUDE guidance, RFC notes, nudge test output, and CI check filtering so substitute rules do not require fake block messages or appear as file lint rules. Testing: cargo fmt --all; cargo test -p nudge; cargo run -p nudge --quiet -- claude docs >/tmp/nudge-docs.out && rg -n 'Substitution Rules|use-yarn-add|action: substitute|additionalContext' /tmp/nudge-docs.out
Clarify that nudge check only evaluates file-based block rules and ignores action: substitute rules, because substitutions require a live Bash hook payload and a provider that can receive updatedInput. Testing: cargo run -p nudge --quiet -- claude docs >/tmp/nudge-docs.out && rg -n 'CI note: nudge check ignores substitute rules|updatedInput' /tmp/nudge-docs.out; cargo test -p nudge
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.
Why this change
Issue #19 asks Nudge to avoid blocking and retrying when a rule can be handled by a deterministic mechanical Bash command rewrite, such as replacing
npm install foowithyarn add foo.Before this change, all
PreToolUsematches were blocking rule violations, even when the desired fix was a simple substitution. This added unnecessary round trips for agents and made project-specific command wrapper rules more cumbersome than they needed to be.This PR adds first-class
action: substitutesupport forPreToolUseBash rules. Substitute rules use regexreplace:templates, preserve the provider's full originaltool_input, returnpermissionDecision: "allow"withupdatedInput, and addhookSpecificOutput.additionalContextso both Claude Code and Codex CLI models can see what Nudge rewrote before the command runs.Block rules still run after substitution, so rewritten commands remain subject to normal policy checks.
nudge checkexplicitly ignores substitute rules because check mode scans repository files, while substitutions require a live Bash hook payload and a provider that can receiveupdatedInput.Fixes #19.
Testing steps performed