Skip to content

Conversation

@were
Copy link
Contributor

@were were commented Jan 17, 2026

Summary

Fixed the permission evaluation order to ensure global rules take priority over workflow-specific permissions, with clear fall-through behavior and unified Telegram escalation. The previous implementation allowed workflow auto-allow to bypass global deny rules, which was a security concern.

Changes

  • Modified .claude-plugin/lib/permission/determine.py:435-491 to reorder evaluation flow:
    1. Global rules first (deny/allow return, ask falls through)
    2. Workflow auto-allow (allow returns, otherwise continue)
    3. Haiku LLM evaluation (deny/allow return, ask falls through)
    4. Telegram (single final escalation for ask)
  • Updated docs/feat/permissions/rules.md with explicit evaluation order diagram and stage documentation
  • Updated docs/feat/permissions/telegram.md to clarify Telegram as the final escalation point
  • Fixed docs/feat/core/handsoff.md to correct hook location and permission module paths
  • Added tests/cli/test-hook-permission-matching.sh:317-433 with 4 new ordering tests:
    • Test 30: Global deny overrides workflow allow
    • Test 31: Rule 'ask' falls through to workflow auto-allow
    • Test 32: Evaluation order validation via decision source
    • Test 33: Docstring verification for priority order
  • Added tests/fixtures/test-pre-tool-use-input.json with ordering test fixtures

Testing

  • All 70 existing tests pass with the new implementation
  • Added 4 new tests specifically for evaluation order validation:
    • Global deny rules properly override workflow auto-allow (rm -rf denied even with workflow session)
    • Rule 'ask' correctly falls through to workflow auto-allow
    • Decision source correctly reports 'rules' for global deny decisions
    • Docstring verification confirms priority order documentation matches implementation
  • Manually verified:
    1. Workflow auto-allow patterns still work when global rules return 'ask'
    2. Global deny rules block dangerous commands regardless of workflow state
    3. Error recovery preserves the correct evaluation order

Related Issue

Closes #488

Reorder permission evaluation flow to ensure global rules take priority
over workflow-specific permissions:
1. Global rules (deny/allow return, ask falls through)
2. Workflow auto-allow (allow returns, otherwise continue)
3. Haiku LLM (allow/deny return, ask falls through)
4. Telegram (single final escalation for ask)

Key changes:
- Global deny rules now always override workflow auto-allow
- 'ask' results fall through sequentially to next stage
- Telegram escalation unified at a single final point
- Documentation updated to reflect actual evaluation order
- Tests added for ordering validation

Fixes #488

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@were were added the agentize:pr PR created by agentize label Jan 17, 2026
Comment on lines +9 to +46
## Evaluation Order

Permission requests flow through these stages in order:

```
Tool Request
┌─────────────────────────────┐
│ 1. Global Rules │ ← First match wins (deny/allow/ask)
│ deny → DENY (stop) │
│ allow → ALLOW (stop) │
│ ask → fall through │
└─────────────────────────────┘
│ (ask or no match)
┌─────────────────────────────┐
│ 2. Workflow Auto-Allow │ ← Workflow-scoped patterns
│ allow → ALLOW (stop) │
│ none → fall through │
└─────────────────────────────┘
│ (no match)
┌─────────────────────────────┐
│ 3. Haiku LLM │ ← Context-aware evaluation
│ deny → DENY (stop) │
│ allow → ALLOW (stop) │
│ ask → fall through │
└─────────────────────────────┘
│ (ask)
┌─────────────────────────────┐
│ 4. Telegram Escalation │ ← Single final escalation
│ deny → DENY (stop) │
│ allow → ALLOW (stop) │
│ timeout → ASK (prompt) │
└─────────────────────────────┘
```
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why don't you make this a rich text mermaid?

@were were merged commit a065c62 into main Jan 17, 2026
4 checks passed
@were were deleted the issue-488 branch January 17, 2026 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agentize:pr PR created by agentize

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[plan][refactor]: Fix permission evaluation ordering with clear rule priority and unified Telegram escalation

2 participants