Skip to content

Add parser corpus audit tooling - #81

Merged
TraderSamwise merged 2 commits into
masterfrom
test/chat-parser-audit-tooling
Jun 6, 2026
Merged

Add parser corpus audit tooling#81
TraderSamwise merged 2 commits into
masterfrom
test/chat-parser-audit-tooling

Conversation

@TraderSamwise

@TraderSamwise TraderSamwise commented Jun 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • add a parser corpus audit module for history/context snapshot scans
  • add a scripts/audit-agent-output-parser.mjs CLI and package script
  • cover audit flag counting and response-record filtering with tests

Verification

  • vitest run src/agent-output-parser-audit.test.ts src/agent-output-parser-fixtures.test.ts
  • tsc --noEmit
  • eslint src/ --max-warnings=0
  • yarn build
  • node scripts/audit-agent-output-parser.mjs --history /Users/sam/cs/aimux/.aimux/history --context /Users/sam/cs/aimux/.aimux/context --max 5
  • vitest run $(rg --color never --files src -g "*.test.ts" | grep -v "^src/daemon.test.ts$")

Note

  • Full vitest run is locally blocked by a live aimux-dev project service already listening on 127.0.0.1:49192, which src/daemon.test.ts uses as a fixed test port. The non-daemon suite passed.

Summary by CodeRabbit

  • New Features

    • Added agent output audit capability to detect and report suspicious patterns in parsed agent output, including status leaks and problematic blocks, with JSON and human-readable reporting options.
  • Tests

    • Added comprehensive test coverage for audit functionality.
  • Chores

    • Added audit:parser npm script for convenient command-line access to the audit tool.

@vercel

vercel Bot commented Jun 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
app Ready Ready Preview, Comment Jun 6, 2026 12:00pm

@coderabbitai

coderabbitai Bot commented Jun 6, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@TraderSamwise, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 1 minute and 8 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fe99381a-0413-441e-833d-ed5f5ef709f3

📥 Commits

Reviewing files that changed from the base of the PR and between 03a1912 and 1a17012.

📒 Files selected for processing (1)
  • package.json
📝 Walkthrough

Walkthrough

This PR introduces a new audit system that scans agent output stored in JSONL history and markdown context directories to detect suspicious patterns: raw blocks, status-leak responses, and actionable prompts from responses. It includes a Node.js CLI script with command-line options for directory selection, maximum findings, and JSON output, plus comprehensive test coverage.

Changes

Agent Output Parser Audit System

Layer / File(s) Summary
Audit data model and types
src/agent-output-parser-audit.ts
Exported types define ParserAuditFindingFlag, ParserAuditFinding, ParserAuditOptions, and ParserAuditSummary to structure audit inputs and findings.
Audit corpus scanning and detection
src/agent-output-parser-audit.ts
Internal helpers classify tools from file paths and detect actionable prompts; historyCandidates and contextCandidates generators read and yield records from JSONL and markdown sources; auditAgentOutputParserCorpus iterates through candidates, parses with parseAgentOutput, flags suspicious blocks (raw, status-leak patterns, actionable prompts from responses), maintains per-flag counts, and caps results by maxFindings.
CLI script and npm integration
scripts/audit-agent-output-parser.mjs, package.json
CLI script parses --history, --context, --max, --json, --fail-on-findings, and --help arguments with validation, defaults to .aimux/history and .aimux/context, invokes the audit function, and outputs either JSON or human-readable findings with per-flag aggregates; npm audit:parser script entry point calls the CLI; exit code set to 1 when findings exist and --fail-on-findings is enabled.
Audit behavior tests
src/agent-output-parser-audit.test.ts
Three tests with temporary directory fixtures validate that suspicious "status" text is flagged as status-leak-response in response blocks, non-response record types are filtered (zero scans), and maxFindings truncates the returned findings list while preserving per-flag counts.

Sequence Diagram

sequenceDiagram
  participant CLI as audit:parser CLI
  participant AuditFn as auditAgentOutputParserCorpus
  participant HistoryScan as historyCandidates
  participant ContextScan as contextCandidates
  participant Parser as parseAgentOutput
  participant Detector as Block inspector
  CLI->>AuditFn: invoke with historyDirs, contextDirs, maxFindings
  AuditFn->>HistoryScan: scan history directories
  HistoryScan->>AuditFn: yield candidate records
  AuditFn->>ContextScan: scan context directories
  ContextScan->>AuditFn: yield candidate files
  AuditFn->>Parser: parse candidate content
  Parser->>Detector: return parsed blocks
  Detector->>AuditFn: identify raw blocks, status-leak patterns, actionable prompts
  AuditFn->>AuditFn: accumulate findings, maintain counts by flag
  AuditFn->>CLI: return summary with scanned count, findings, countsByFlag
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly Related PRs

  • TraderSamwise/aimux#77: Related through shared parseAgentOutput parser logic and status/activity-spinner pattern detection that feeds the audit flags.

Poem

🐰 A rabbit hops through history deep,
Finding status leaks in output heaps,
Raw blocks flagged, prompts confirmed—
The audit's vigilance has earned,
A CLI to keep them clean! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add parser corpus audit tooling' clearly and concisely describes the main change: introducing new audit functionality for scanning agent output parser corpus.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/chat-parser-audit-tooling

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/agent-output-parser-audit.test.ts (1)

22-81: ⚡ Quick win

Consider adding test coverage for context directory scanning.

The current tests validate historyCandidates (JSONL files) but do not exercise contextCandidates (live.md/summary.md files). Since context scanning is a parallel code path with its own recursive directory logic, adding at least one test case would improve confidence in that behavior.

📋 Example test case for context directory scanning
it("scans context markdown files for suspicious patterns", () => {
  const dir = makeTempDir();
  const contextSubdir = join(dir, "context-subdir");
  mkdirSync(contextSubdir);
  writeFileSync(
    join(contextSubdir, "live.md"),
    "Some content with terminal-notifier status leak",
  );

  const summary = auditAgentOutputParserCorpus({ contextDirs: [dir] });

  expect(summary.scanned).toBe(1);
  expect(summary.findings.length).toBeGreaterThan(0);
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/agent-output-parser-audit.test.ts` around lines 22 - 81, Add a test
exercising the contextDirs path of auditAgentOutputParserCorpus: create a
temporary dir and a nested subdir, write a live.md or summary.md containing a
suspicious marker (e.g., "terminal-notifier"), call
auditAgentOutputParserCorpus({ contextDirs: [dir] }) and assert that
summary.scanned increments and summary.findings contains the expected flag(s);
this ensures the contextCandidates branch (the recursive markdown scanning
logic) is covered alongside the existing historyCandidates JSONL tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@package.json`:
- Line 39: The "audit:parser" npm script currently runs Node directly against
compiled files and can execute stale or missing dist output; update the
"audit:parser" script so it prepends "yarn build &&" before the Node invocation
to ensure TypeScript is compiled to dist (the script that imports
dist/agent-output-parser-audit.js) before running; modify the package.json
"audit:parser" entry to include this build step.

---

Nitpick comments:
In `@src/agent-output-parser-audit.test.ts`:
- Around line 22-81: Add a test exercising the contextDirs path of
auditAgentOutputParserCorpus: create a temporary dir and a nested subdir, write
a live.md or summary.md containing a suspicious marker (e.g.,
"terminal-notifier"), call auditAgentOutputParserCorpus({ contextDirs: [dir] })
and assert that summary.scanned increments and summary.findings contains the
expected flag(s); this ensures the contextCandidates branch (the recursive
markdown scanning logic) is covered alongside the existing historyCandidates
JSONL tests.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c129fb35-d146-46e1-bd15-0a32b3f2b014

📥 Commits

Reviewing files that changed from the base of the PR and between e5c95ab and 03a1912.

📒 Files selected for processing (4)
  • package.json
  • scripts/audit-agent-output-parser.mjs
  • src/agent-output-parser-audit.test.ts
  • src/agent-output-parser-audit.ts

Comment thread package.json Outdated
@TraderSamwise
TraderSamwise merged commit 47bc074 into master Jun 6, 2026
3 checks passed
@TraderSamwise
TraderSamwise deleted the test/chat-parser-audit-tooling branch June 6, 2026 12:01
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