Skip to content

feat(cli): add --dir filter option to runok audit#207

Merged
fohte merged 3 commits intomainfrom
fohte/audit-cwd-filter
Mar 14, 2026
Merged

feat(cli): add --dir filter option to runok audit#207
fohte merged 3 commits intomainfrom
fohte/audit-cwd-filter

Conversation

@fohte
Copy link
Owner

@fohte fohte commented Mar 14, 2026

Why

  • runok audit should support filtering entries by the project directory where commands were executed
    • Each audit log entry already records metadata.cwd, but the CLI had no way to filter by it

What

  • Add --dir <path> option to show only commands executed in the specified directory or its subdirectories
    • The path is canonicalized before matching, so relative paths and symlinks are handled correctly
# Show logs from the current directory only
runok audit --dir .

# Show logs from a specific project
runok audit --dir /home/user/myproject

Open with Devin

fohte added 2 commits March 14, 2026 18:43
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.
@gemini-code-assist
Copy link

Summary of Changes

Hello, 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 runok audit command by enabling directory-specific filtering of audit logs. This feature addresses the need for users to easily isolate and review command executions within particular project contexts, leveraging existing metadata.cwd information. The implementation ensures robust path handling, making the filtering reliable and user-friendly for various directory structures.

Highlights

  • New --dir filter option: Introduced a new --dir <path> option for the runok audit command, allowing users to filter audit log entries by the working directory where commands were executed.
  • Directory-based filtering: The new filter matches entries executed in the specified directory or any of its subdirectories, providing granular control over audit log visibility.
  • Path canonicalization: The provided directory path is canonicalized (resolved to its absolute, symlink-resolved form) before matching, ensuring correct filtering regardless of relative paths or symlinks used in the input.
Changelog
  • docs/src/content/docs/cli/audit.md
    • Documented the new --dir option for the runok audit command, explaining its functionality and path resolution behavior.
  • src/audit/filter.rs
    • Added a cwd field to the AuditFilter struct to store the directory filter criterion.
    • Updated the Default implementation for AuditFilter to initialize the new cwd field as None.
    • Added a test case to ensure the cwd field is None by default.
  • src/audit/reader.rs
    • Introduced a ResolvedFilter struct to encapsulate all resolved filter criteria, improving parameter passing to filtering functions.
    • Modified read_file and matches_filter functions to accept the new ResolvedFilter struct, streamlining filter application.
    • Implemented the core logic within matches_filter to perform working directory (cwd) filtering, checking for exact matches or subdirectory prefixes.
    • Added new test cases (filter_by_cwd and filter_by_cwd_no_false_prefix_match) to validate the correctness of the directory filtering functionality.
  • src/cli/mod.rs
    • Added the --dir argument to the AuditArgs struct, making it available as a command-line option.
    • Updated existing test cases for AuditArgs parsing to include the new dir field, ensuring proper command-line argument handling.
  • src/main.rs
    • Implemented logic in run_audit to parse the --dir command-line argument.
    • Added functionality to canonicalize the provided directory path, converting it to an absolute, symlink-resolved form.
    • Integrated the canonicalized directory path into the AuditFilter for use in the audit log reading process.
    • Included error handling for cases where the provided directory path cannot be resolved.
Activity
  • No specific activity (comments, reviews, progress updates) was provided in the context for this pull request.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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
Copy link

codecov bot commented Mar 14, 2026

Codecov Report

❌ Patch coverage is 86.04651% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.69%. Comparing base (cfafb18) to head (7c211c4).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/main.rs 25.00% 6 Missing ⚠️
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     
Flag Coverage Δ
Linux 89.56% <86.04%> (-0.06%) ⬇️
macOS 90.87% <86.04%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

devin-ai-integration[bot]

This comment was marked as resolved.

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".
@fohte fohte merged commit 71b768e into main Mar 14, 2026
10 checks passed
@fohte fohte deleted the fohte/audit-cwd-filter branch March 14, 2026 09:59
@fohte-bot fohte-bot bot mentioned this pull request Mar 14, 2026
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.

1 participant