Skip to content

feat(permission-manager): layered user rule files with validation and cached merge - #256

Merged
st0nefish-ci[bot] merged 1 commit into
masterfrom
worktree-feature-permission-manager-layered-rules
Nov 24, 2026
Merged

st0nefish-ci[bot] merged 1 commit into
masterfrom
worktree-feature-permission-manager-layered-rules

Conversation

@St0nefish

Copy link
Copy Markdown
Owner

Summary

Adds layered rule files to permission-manager so local policy survives plugin updates (#255). With no layer files, behaviour and cost are unchanged.

  • Layers: shipped < system (/etc/claude-code/permission-manager.d) < user ($XDG_CONFIG_HOME/permission-manager/rules.d) < project (.claude/permission-manager, opt-in via PERMISSION_MANAGER_PROJECT_RULES=1, ask/deny only, no override/disable). PERMISSION_MANAGER_RULES_PATH replaces system+user. A system/user layer directory inside the repository being worked in is ignored, since a repo can set hook env vars.
  • validate.jq: known keys, sections per layer, owner.name ids, compiling regexes, known clause keys, and the field shapes engine.jq dereferences. An invalid file is skipped by itself.
  • merge.jq + gate.sh: one merge, cached under XDG_CACHE_HOME (dir 700, files 600) keyed on file content; any failure falls back to the shipped rules; one stderr note and a RULES_ERROR audit line per session.
  • engine.jq: new push_target_re and flag_with_pos clauses.
  • Tests: test-gate.sh gains --rules-dir and --cases, plus layer precedence, project restrictions, malformed-file, wrong-typed-field, cache and push-target checks, with fixtures and layer-cases/release.tsv.
  • README documents the layers; plugin bumped to 3.2.0.

Review

Three review passes. Fixes include: wrong-typed fields no longer silence the gate; a bad regex name no longer drops every layer; push_target_re is barred from allow entries and not; overrides are validated like added entries; the cache key hashes content (symlinked rule files tracked); the push target is trusted only for a plain git push, so cd, -C and git checkout master && git push ask.

Decision D1 (accepted): the push target is resolved before the engine run and only when a loaded rule uses push_target_re, instead of after the run as the issue describes. Same behaviour, no second engine pass.

Left open as nits: regex backtracking in layer files, cache prune by build age (30 days), the example gh api rule also asks on -X GET.

Test plan

  • bash tests/permission-manager/test-gate.sh: 1692 pass, 2 fail. The two oversize: 250 harmless commands / 150-stage read-only pipeline checks also fail on unmodified master in this environment.
  • bash .github/scripts/lint-shell.sh passes; rumdl is clean for the plugin.
  • validate-all.sh markdown failures are all in session spine files this PR does not touch.

Closes #255

🤖 Generated with Claude Code

https://claude.ai/code/session_018KC1pVN4bq5bqbeVZwNVDQ

… cached merge

Rules could only be changed by forking: gate.sh hard-coded scripts/rules and
edits to the installed copy are lost on update. Add system, user and project
rule layers so local policy survives updates.

- layers: shipped < system (/etc/claude-code/permission-manager.d) < user
  (XDG config rules.d) < project (.claude/permission-manager, opt-in via
  PERMISSION_MANAGER_PROJECT_RULES=1, ask/deny only); PERMISSION_MANAGER_RULES_PATH
  replaces system+user; layer dirs inside the working repo are ignored
- validate.jq checks keys, sections per layer, id format, regexes, clause keys
  and the field shapes engine.jq dereferences, so a bad file is skipped alone
- merge.jq applies adds, id overrides (position kept) and disables
- gate.sh merges once, caches under XDG_CACHE_HOME keyed on file content,
  falls back to shipped rules on any failure, notes once per session and
  writes a RULES_ERROR audit line; no layer files means no extra work
- engine.jq: new push_target_re and flag_with_pos clauses
- test-gate.sh: --rules-dir and --cases options and layer, project, malformed
  file and cache checks, with fixtures and release cases
- README documents the layers; plugin bumped to 3.2.0

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018KC1pVN4bq5bqbeVZwNVDQ
@st0nefish-ci
st0nefish-ci Bot enabled auto-merge November 24, 2026 16:39
@st0nefish-ci
st0nefish-ci Bot merged commit 447fc17 into master Nov 24, 2026
8 checks passed
@st0nefish-ci
st0nefish-ci Bot deleted the worktree-feature-permission-manager-layered-rules branch November 24, 2026 16:45
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.

permission-manager: layered user rule files (system / user / project) with id overrides and target-aware clauses

1 participant