feat(cli): add --dir filter option to runok audit#207
Conversation
Audit logs record `metadata.cwd` for each entry, but there was no way to filter by it from the CLI. This makes it difficult to view only the commands executed in a specific project directory. Add `--cwd <path>` flag that filters entries whose recorded cwd matches the given path or is a subdirectory of it. The path is canonicalized before matching to handle relative paths and symlinks correctly. Also introduce `ResolvedFilter` struct to reduce parameter count on `read_file` and `matches_filter`, fixing a clippy too_many_arguments warning.
`--cwd` implies "current working directory" which is misleading for an option that takes an arbitrary path as a value. `--dir` is a more accurate name for filtering by directory.
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds a useful --dir filter option to runok audit, allowing users to filter audit logs by the directory where commands were executed. The implementation is solid, including correct path canonicalization and comprehensive tests. The documentation has also been updated accordingly. The suggestion to improve the path matching logic for better readability and idiomaticity remains valid.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #207 +/- ##
==========================================
- Coverage 89.73% 89.69% -0.05%
==========================================
Files 50 50
Lines 10171 10186 +15
==========================================
+ Hits 9127 9136 +9
- Misses 1044 1050 +6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
String-based prefix match with format!("{filter_cwd}/") broke when the
filter path was root "/" — it produced "//" which never matches any
standard Unix path, incorrectly excluding all subdirectory entries.
Path::starts_with handles component-level matching correctly for all
paths including root, and also prevents false prefix matches like
"/home/user/project2" matching "/home/user/project".
Why
runok auditshould support filtering entries by the project directory where commands were executedmetadata.cwd, but the CLI had no way to filter by itWhat
--dir <path>option to show only commands executed in the specified directory or its subdirectories