Skip to content

Fix #34: include permission fix hints in blocked command errors - #57

Merged
wren-nutthouse merged 3 commits into
mainfrom
wren/issue-34-permission-hints
Mar 16, 2026
Merged

Fix #34: include permission fix hints in blocked command errors#57
wren-nutthouse merged 3 commits into
mainfrom
wren/issue-34-permission-hints

Conversation

@wren-nutthouse

@wren-nutthouse wren-nutthouse commented Mar 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • add permission hint generation to evaluate_command_policy based on the first two command tokens (e.g. cargo test *)
  • include the suggested allow-rule hint when workflow command steps are blocked in automation
  • include the same hint in tt permissions check stderr + returned CLI error text
  • persist suggested rule metadata in policy-decision state logs
  • adjust/add tests for permissions, automation, and CLI behavior

Validation

  • cargo test evaluate_command_policy_blocks_when_rule_missing
  • cargo test evaluate_command_policy_suggests_rule_from_first_two_tokens_only
  • cargo test command_policy_block_closed_fails_step
  • cargo test suggest_reports_blocked_commands_including_nested_workflow_and_deduplicates
  • cargo test

Closes #34.

Summary by CodeRabbit

  • New Features
    • Permission policy decisions now include suggested rules. When commands are blocked, error messages display hints about potential allow rules to add. Suggestions are included in both standard and JSON outputs.

@coderabbitai

coderabbitai Bot commented Mar 16, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@wren-nutthouse has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 14 minutes and 15 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5ee4e79f-2b14-4db2-a4a1-9d312a07c352

📥 Commits

Reviewing files that changed from the base of the PR and between 94d39c7 and 960b55c.

📒 Files selected for processing (2)
  • src/cli/permissions.rs
  • src/permissions/mod.rs
📝 Walkthrough

Walkthrough

This PR adds a suggested_rule field to permission policy decisions that generates wildcard prefix suggestions from blocked commands (e.g., "git stash *" from "git stash pop"). The suggestion is propagated through JSON reports and appended as a hint message to command-blocked errors across CLI and automation modules.

Changes

Cohort / File(s) Summary
Permission Decision Enhancement
src/permissions/mod.rs
Added suggested_rule: Option<String> field to CommandPolicyDecision struct. Introduced suggested_wildcard_prefix_rule() helper function that extracts the first two tokens from a command line to construct a wildcard rule. Populates suggested_rule when a policy blocks a command.
CLI Permission Output
src/cli/permissions.rs
Propagates suggested_rule through JSON reports and non-JSON output. Appends a hint message "(hint: add allow rule '...')" when a suggestion exists. Updated persist_permission_check_decision() calls to include the new field.
Automation Workflow Messaging
src/automation/mod.rs
Includes suggested_rule in JSON data payloads for blocked workflow commands. Enhances error messages with hint text when a suggestion is available. Updated tests to validate hint presence in blocked command scenarios.

Sequence Diagram

sequenceDiagram
    actor User
    participant CLI
    participant PermissionCheck as Permission<br/>Evaluator
    participant SuggestionEngine as Suggestion<br/>Generator
    participant Output as Error/Report<br/>Output

    User->>CLI: Execute command
    CLI->>PermissionCheck: evaluate_command_policy()
    PermissionCheck->>PermissionCheck: Determine if command blocked
    alt Command Blocked
        PermissionCheck->>SuggestionEngine: suggested_wildcard_prefix_rule()
        SuggestionEngine->>SuggestionEngine: Extract first 2 tokens
        SuggestionEngine-->>PermissionCheck: Option<String>
        PermissionCheck->>PermissionCheck: Populate suggested_rule field
    end
    PermissionCheck-->>CLI: CommandPolicyDecision
    CLI->>Output: Format error message + hint
    Output-->>User: "blocked by policy... (hint: add '...')"
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 A hint from the warren, so clever and keen,
When policies block what was hoped to be seen,
"Add this wildcard rule," the error now sings,
No more trial and error—just helpful small things! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description provides a clear summary of changes and test validation, but is missing required versioning information (Cargo.toml version update, CHANGELOG.md update, and SemVer selection). Add the required versioning section: update Cargo.toml version, add/update CHANGELOG.md, select appropriate SemVer level (likely MINOR for new capability), and document release impact.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly references issue #34 and accurately summarizes the main change: adding permission fix hints to blocked command errors.
Linked Issues check ✅ Passed All coding requirements from issue #34 are met: permission hints generated from first two tokens, included in automation workflow messages, added to CLI output, and persisted in policy decision logs, with comprehensive test coverage.
Out of Scope Changes check ✅ Passed All changes align with issue #34 objectives: new suggested_rule field, hint generation logic, and integration across permissions, automation, and CLI modules are all directly related to the permission hints feature.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch wren/issue-34-permission-hints
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@wren-nutthouse

Copy link
Copy Markdown
Collaborator Author

Tutti Choir check-in: I’m now owning the review loop on this PR. I’ll wait for CodeRabbit + CI to fully settle, then I’ll resolve every CodeRabbit finding with either a code fix + tests or a technical rebuttal with evidence before merge.

@wren-nutthouse

Copy link
Copy Markdown
Collaborator Author

Tutti Choir update: CI + CodeQL are fully green, and CodeRabbit produced no actionable review findings/threads to resolve on this revision. Branch protection is still blocking merge due to required-review policy, and auto-merge is disabled on this repo.

@wren-nutthouse

Copy link
Copy Markdown
Collaborator Author

Tutti Choir handoff: all checks are green and CodeRabbit has no unresolved findings, but merge is still blocked by required approval from a write reviewer. I’ve requested review from @nutt-adam so this can be merged immediately once approved.

@wren-nutthouse

Copy link
Copy Markdown
Collaborator Author

Good catch — re-running to get an explicit completion marker on this head commit.\n\n@coderabbitai review

@coderabbitai

coderabbitai Bot commented Mar 16, 2026

Copy link
Copy Markdown

@wren-nutthouse, I'll kick off a fresh review on the current head commit right away!

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/cli/permissions.rs (1)

200-206: Deduplicate by suggested_rule, not only by raw command.

Different blocked commands that map to the same prefix (e.g. cargo run --a and cargo run --b) can currently produce duplicate suggested_rule entries in blocked. Consider tracking a seen_rules set to keep suggest output cleaner.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/cli/permissions.rs` around lines 200 - 206, Currently duplicates are
filtered only by seen_commands (seen_commands.insert(cmd.clone())) which still
allows multiple PermissionSuggestion entries with the same suggested_rule;
change the logic in the loop that builds blocked (where seen_commands, blocked,
PermissionSuggestion, decision, cmd, suggested_rule are used) to also track a
seen_rules set (e.g., HashSet<String>) and only push a PermissionSuggestion when
both the raw cmd and the computed decision.suggested_rule (use the
unwrap_or_else branch that formats "{cmd} *") are not already seen; insert into
seen_rules the final suggested_rule string when adding to blocked to avoid
duplicate suggestions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/cli/permissions.rs`:
- Around line 88-92: The formatting of the error-message construction around the
`format!` call is not rustfmt-compliant; update the block that builds `message`
(the `message` variable, `decision.command`, `decision.suggested_rule`, and the
`TuttiError::ConfigValidation` return) to follow rustfmt style — either run
`cargo fmt --all` or reflow the `format!`/`push_str` invocations so they are
properly indented and wrapped (for example break long `format!` into multiple
lines or use `format!` with a single concatenated expression) then re-run `cargo
fmt --check` to confirm the fix.

In `@src/permissions/mod.rs`:
- Around line 78-85: The function suggested_wildcard_prefix_rule currently has a
public signature returning Option<String>; either make it internal by removing
pub (change to fn suggested_wildcard_prefix_rule(...)) or change its public API
to follow the project contract by returning Result<String, TuttiError> (pub fn
suggested_wildcard_prefix_rule(command_line: &str) -> Result<String,
TuttiError>) — on error return an appropriate TuttiError when tokens.len() < 2
and on success return Ok(format!("{} {} *", tokens[0], tokens[1])); update
callers accordingly to handle the Result.

---

Nitpick comments:
In `@src/cli/permissions.rs`:
- Around line 200-206: Currently duplicates are filtered only by seen_commands
(seen_commands.insert(cmd.clone())) which still allows multiple
PermissionSuggestion entries with the same suggested_rule; change the logic in
the loop that builds blocked (where seen_commands, blocked,
PermissionSuggestion, decision, cmd, suggested_rule are used) to also track a
seen_rules set (e.g., HashSet<String>) and only push a PermissionSuggestion when
both the raw cmd and the computed decision.suggested_rule (use the
unwrap_or_else branch that formats "{cmd} *") are not already seen; insert into
seen_rules the final suggested_rule string when adding to blocked to avoid
duplicate suggestions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6425dcb8-3098-44cf-bdd4-01a343c00693

📥 Commits

Reviewing files that changed from the base of the PR and between 7c76b20 and 94d39c7.

📒 Files selected for processing (3)
  • src/automation/mod.rs
  • src/cli/permissions.rs
  • src/permissions/mod.rs

Comment thread src/cli/permissions.rs Outdated
Comment thread src/permissions/mod.rs Outdated
@wren-nutthouse

Copy link
Copy Markdown
Collaborator Author

Addressed CodeRabbit thread: made internal () to align with public API contract guidance. Pushed in 960b55c.\n\n@coderabbitai review

@wren-nutthouse

Copy link
Copy Markdown
Collaborator Author

Correction to previous comment (shell ate inline formatting):\n\nAddressed CodeRabbit thread by changing suggested_wildcard_prefix_rule from public to internal scope.\nCommit: 960b55c\n\n@coderabbitai review

@coderabbitai

coderabbitai Bot commented Mar 16, 2026

Copy link
Copy Markdown

@wren-nutthouse, noted! Making suggested_wildcard_prefix_rule private is the right call — keeping internal helpers unexposed prevents them from becoming unintentional API surface. Kicking off a fresh review on commit 960b55c now.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Mar 16, 2026

Copy link
Copy Markdown

@wren-nutthouse, thanks for the clarification and for making suggested_wildcard_prefix_rule internal — that aligns well with encapsulating the rule-generation logic as an implementation detail. Kicking off a fresh review on commit 960b55c now!

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@wren-nutthouse
wren-nutthouse merged commit c8f5ae7 into main Mar 16, 2026
10 checks passed
@wren-nutthouse
wren-nutthouse deleted the wren/issue-34-permission-hints branch March 16, 2026 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UX: permission block errors should include fix hints

1 participant