feat: context-aware path checking for destructive commands#54
Open
dgerlanc wants to merge 19 commits into
Open
feat: context-aware path checking for destructive commands#54dgerlanc wants to merge 19 commits into
dgerlanc wants to merge 19 commits into
Conversation
Adds a spec for making mmi approval decisions directory-aware, so destructive commands like rm can be scoped to the project tree.
- Add data flow section showing paths from TOML through Pattern to SafeResult - Disallow paths on regex patterns (no descriptor lookup possible) - Specify conflict resolution for overlapping patterns - Add tilde expansion handling (~/ → $HOME) - Add -- (end-of-options) handling in all descriptors - Specify chmod mode and chown owner parsing heuristics - Specify PATH_VIOLATION uses ask decision (not deny) - Name new package: internal/cmdpath - Document cwd absolute path assumption - List SPEC.md sections requiring updates
Git -C doesn't fit the same descriptor model as rm/mv — it shifts working context rather than targeting files. Deferred to future work. Initial scope is now: rm, mv, chmod, chown (destructive only).
A command appearing in both path-constrained and unconstrained patterns is now a hard error at config load, not a warning.
Adds worked examples for rm showing the full flow from core command through arg extraction, path resolution, and prefix checking. Covers flags, relative paths, --, and unresolvable variables.
Worktrees at arbitrary locations (e.g., /tmp/my-worktree) are not under $PROJECT_ROOT, so users need paths = ["$PROJECT_ROOT", "$PROJECT"] to cover both the main repo and the worktree.
11 tasks covering: Pattern.Paths field, audit structs, command descriptor registry, target extraction (rm/mv/chmod/chown), path resolution, config parsing/validation, hook integration, e2e tests, and SPEC.md updates.
Add extractChmodTargets and extractChownTargets with regex-based heuristics to distinguish mode/owner arguments from filesystem targets, sharing a common extractWithFirstArgSkip helper. Remove stub implementations from extract.go.
Parse the optional `paths` field from TOML simple patterns, thread it through to patterns.Pattern, and reject paths on regex/subcommand patterns. Validate that commands with paths have registered descriptors and detect conflicting patterns where the same command appears with and without path constraints.
- Fail closed if cwd is not absolute (spec requirement) - Document chmod compound mode regex gap (fail-closed) - Document chown owner pattern filename matching edge case
- Add Path Constraints section with config examples and variables - Add path violation audit log example - Update How It Works and Security Model sections - Add paths to segment field reference - Add Key Packages section to CLAUDE.md
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.
Summary
rm,mv,chmod,chown) can be scoped to specific directories via a per-patternpathsfield in configinternal/cmdpathpackage with command descriptor registry, target extraction, path resolution, and prefix checkingpathsusage (only on simple patterns, requires registered descriptor, detects conflicting constraints)$PROJECT(cwd) and$PROJECT_ROOT(git repo root, worktree-aware) variables for path expressions~userpaths are rejectedPATH_VIOLATIONrejection code andPathCheckaudit struct for observabilityExample config
Test plan
--, variables, mode/owner parsingProcessWithResult(approved, violated, unresolved, no-paths)main_test.gocovering 8 scenarios