Skip to content

feat(audit): improve audit subcommand output with table format and colors#200

Merged
fohte merged 3 commits intomainfrom
fohte/audit-tac
Mar 13, 2026
Merged

feat(audit): improve audit subcommand output with table format and colors#200
fohte merged 3 commits intomainfrom
fohte/audit-tac

Conversation

@fohte
Copy link
Owner

@fohte fohte commented Mar 13, 2026

Why

  • runok audit text output is hard to read
    • No color coding, making it difficult to visually distinguish actions (allow/deny/ask)
    • Commands containing newlines break the one-line-per-entry layout
    • Entries sorted in descending order (newest first), contrary to typical terminal conventions
    • Timestamps displayed in UTC rather than local time

What

  • Introduce a gh CLI-style table formatter to improve audit subcommand output
    • TTY: column-aligned table with colored action labels and terminal-width-aware command truncation
    • Non-TTY: tab-separated values suitable for piping
  • Display timestamps in local time
  • Change sort order to ascending (oldest first) so the most recent entry appears at the bottom
  • Escape newlines in commands to guarantee one entry per line

Open with Devin

…colors

Replace plain text output with a gh CLI-style table formatter:
- TTY: aligned table with colored action labels and terminal-width-aware
  command truncation
- Non-TTY: tab-separated values for piping
- Timestamps displayed in local time instead of UTC
- Newlines in commands escaped to maintain one-line-per-entry
- Sort order changed to ascending (newest last) for natural terminal reading

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@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 user experience of the audit subcommand by revamping its output. The changes introduce a modern, colored, and well-formatted table view for interactive terminal use, while also providing a machine-readable tab-separated format for scripting. These improvements address previous readability issues, making audit logs easier to parse and analyze for users.

Highlights

  • Improved audit subcommand output: The audit subcommand now provides a more readable output format, featuring a gh CLI-style table with colored action labels and terminal-width-aware command truncation when run in a TTY environment.
  • Non-TTY output format: For non-TTY environments, the audit subcommand now outputs tab-separated values, making it suitable for piping to other tools.
  • Local timestamps and ascending sort order: Timestamps in the audit output are now displayed in local time instead of UTC, and audit entries are sorted in ascending order (oldest first) for better chronological readability.
  • Newline handling in commands: Commands containing newlines are now properly escaped (\n, \r) to ensure each audit entry is displayed on a single line, preventing layout breakage.
  • New dependencies for terminal features: New Rust crates owo-colors and terminal_size were added to enable advanced terminal output features like coloring and dynamic column sizing.
Changelog
  • Cargo.lock
    • Updated windows-sys dependency to version 0.61.2.
    • Added new dependencies: hermit-abi, is-terminal, is_ci, owo-colors, terminal_size, supports-color (multiple versions), windows-targets, and various windows_* platform-specific crates.
  • Cargo.toml
    • Added owo-colors and terminal_size as new dependencies.
    • Enabled the clock feature for the chrono crate.
  • src/audit/formatter.rs
    • Added new module for formatting audit entries.
    • Implemented print_entries to conditionally format output as a table (TTY) or tab-separated values (non-TTY).
    • Included functions for local timestamp formatting, newline escaping, and colored table rendering with command truncation.
    • Added unit tests for action string conversion, newline escaping, and TSV/table output behavior.
  • src/audit/mod.rs
    • Exposed the new formatter module as public.
  • src/audit/reader.rs
    • Modified the sorting logic for audit entries to be in ascending order (oldest first).
    • Updated test case name read_entries_sorted_descending to read_entries_sorted_ascending and adjusted its assertions to match the new sort order.
  • src/main.rs
    • Replaced manual audit entry printing with a call to the new runok::audit::formatter::print_entries function.
  • tests/e2e/audit.rs
    • Updated end-to-end tests to reflect the new ascending sort order and TSV output format for the audit subcommand in non-TTY contexts.
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.

gemini-code-assist[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@codecov
Copy link

codecov bot commented Mar 13, 2026

Codecov Report

❌ Patch coverage is 87.13450% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.23%. Comparing base (25c6749) to head (e61c93a).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/audit/formatter.rs 86.74% 22 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #200      +/-   ##
==========================================
- Coverage   89.26%   89.23%   -0.03%     
==========================================
  Files          47       48       +1     
  Lines        9046     9209     +163     
==========================================
+ Hits         8075     8218     +143     
- Misses        971      991      +20     
Flag Coverage Δ
Linux 89.13% <87.13%> (-0.03%) ⬇️
macOS 90.52% <87.13%> (-0.09%) ⬇️

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.

Byte-level string slicing could panic when truncating a command
containing multi-byte UTF-8 characters (e.g., CJK, emoji) at a
position that falls mid-character. Use `is_char_boundary` to find
safe slice points.

Also update the doc comment on `AuditReader::read()` to reflect the
new ascending sort order, and update docs/cli/audit.md to document
the new table/TSV output format and local timestamps.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
devin-ai-integration[bot]

This comment was marked as resolved.

Tab characters in command strings would corrupt TSV column parsing
since tab is the column delimiter. Escape \t along with \n and \r.
Rename the function from escape_newlines to escape_control_chars to
reflect the broader scope.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@fohte fohte merged commit 490e206 into main Mar 13, 2026
10 checks passed
@fohte fohte deleted the fohte/audit-tac branch March 13, 2026 16:42
@fohte-bot fohte-bot bot mentioned this pull request Mar 13, 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