feat: add composite audit command (Backlog #27) by carlos-alm · Pull Request #219 · optave/ops-codegraph-tool · GitHub
Skip to content

feat: add composite audit command (Backlog #27)#219

Merged
carlos-alm merged 1 commit into
mainfrom
feat/audit-command
Mar 2, 2026
Merged

feat: add composite audit command (Backlog #27)#219
carlos-alm merged 1 commit into
mainfrom
feat/audit-command

Conversation

@carlos-alm

Copy link
Copy Markdown
Contributor

Summary

  • Adds codegraph audit <file-or-function> combining explain + fn-impact + health metrics into a single call, reducing AI agent round-trips from 3-4 to 1
  • auditData() composes explainData + one supplementary DB open for full Halstead metrics, LOC/SLOC, BFS impact analysis, and manifesto threshold breach detection
  • CLI command with --depth, -f, -k, -T, -j options; MCP tool registered; programmatic API exported
  • Phase 4.4 fields (risk_score, complexity_notes, side_effects) read gracefully with null fallback until those columns are added

Test plan

  • 16 integration tests covering function/file targets, filters, health metrics, threshold breaches, impact levels, Phase 4.4 nulls, and edge cases
  • MCP tool list includes audit (27 tools total)
  • Full test suite passes (965 tests, 0 failures)
  • Lint passes on all changed files
  • Manual smoke: node src/cli.js audit buildGraph -T
  • Manual smoke: node src/cli.js audit src/queries.js
  • Manual smoke: node src/cli.js audit explainData -j -T

Closes #207

Single `codegraph audit <file-or-function>` call replaces 3-4 separate
invocations (explain, fn-impact, complexity) for AI agent workflows.

- `auditData()` composes explainData + DB enrichment for full Halstead
  metrics, LOC/SLOC, BFS impact analysis, and manifesto threshold
  breach detection
- CLI command with --depth, -f, -k, -T, -j options
- MCP tool registered in BASE_TOOLS with handler
- Programmatic API exported from index.js
- Phase 4.4 fields (risk_score, complexity_notes, side_effects) read
  gracefully with null fallback until those columns are added
- 16 integration tests covering function/file targets, filters, health
  metrics, threshold breaches, impact levels, and edge cases

Impact: 12 functions changed, 8 affected
@claude

claude Bot commented Mar 2, 2026

Copy link
Copy Markdown

@greptile-apps

greptile-apps Bot commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR implements a composite audit command that combines explain, fn-impact, and health metrics into a single API call, reducing round-trips for AI agents from 3-4 to 1.

Key Changes:

  • src/audit.js (new): Core implementation with auditData() composing explain + supplementary DB queries for full Halstead metrics, LOC/SLOC, BFS impact analysis, and manifesto threshold breach detection
  • CLI integration: Added codegraph audit <file-or-function> with options for depth, file filtering, kind filtering, and JSON output
  • MCP integration: Registered audit tool (27 total tools)
  • Programmatic API: Exported audit and auditData from index.js
  • Phase 4.4 forward compatibility: Gracefully handles risk_score, complexity_notes, side_effects columns with null fallback until added

Implementation Quality:

  • Clean composition pattern reusing explainData() and adding enrichments via supplementary queries
  • Proper error handling with graceful degradation (threshold resolution, complexity lookup, Phase 4.4 fields)
  • Correct BFS impact traversal following caller edges with cycle prevention
  • Consistent with existing CLI patterns (option naming, validation, output formatting)
  • Comprehensive test coverage: 16 integration tests covering all target types, filters, metrics, and edge cases

Confidence Score: 5/5

  • This PR is safe to merge with no identified issues
  • Clean implementation with comprehensive test coverage (16 integration tests), proper error handling with graceful degradation, correct BFS impact algorithm, consistent patterns with existing codebase, and forward compatibility for Phase 4.4 columns
  • No files require special attention

Important Files Changed

Filename Overview
src/audit.js New file implementing composite audit functionality combining explain, impact analysis, and health metrics with comprehensive error handling and graceful degradation
src/cli.js Added audit command with proper option validation and consistent CLI patterns matching existing commands
src/mcp.js Added audit tool definition and handler with proper schema and parameter mapping
tests/integration/audit.test.js Comprehensive test coverage with 16 tests covering function/file targets, filters, health metrics, threshold breaches, and edge cases

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[auditData target, opts] --> B{explainData with depth=0}
    B --> C{Target type?}
    C -->|file| D[Get publicApi + internal symbols]
    C -->|function| E[Get function results]
    D --> F{Apply filters}
    E --> F
    F --> G[Open DB for enrichment]
    G --> H{For each symbol/function}
    H --> I[Query node ID by name/file/line]
    I --> J[buildHealth: Query function_complexity table]
    I --> K[computeImpact: BFS traversal of callers]
    I --> L[readPhase44: Query risk_score, complexity_notes, side_effects]
    I --> M{File target only?}
    M -->|Yes| N[Query callers/callees edges]
    N --> O[Merge all enrichments]
    M -->|No| O
    J --> O
    K --> O
    L --> O
    O --> P[Return enriched function object]
    P --> H
    H --> Q[Close DB]
    Q --> R[Return target, kind, functions array]
Loading

Last reviewed commit: 142c282

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

6 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@carlos-alm carlos-alm merged commit 6530d27 into main Mar 2, 2026
17 checks passed
@carlos-alm carlos-alm deleted the feat/audit-command branch March 2, 2026 06:19
Zeeeepa pushed a commit to Zeeeepa/codegraph that referenced this pull request Jun 22, 2026
…th (optave#219)

Single `codegraph audit <file-or-function>` call replaces 3-4 separate
invocations (explain, fn-impact, complexity) for AI agent workflows.

- `auditData()` composes explainData + DB enrichment for full Halstead
  metrics, LOC/SLOC, BFS impact analysis, and manifesto threshold
  breach detection
- CLI command with --depth, -f, -k, -T, -j options
- MCP tool registered in BASE_TOOLS with handler
- Programmatic API exported from index.js
- Phase 4.4 fields (risk_score, complexity_notes, side_effects) read
  gracefully with null fallback until those columns are added
- 16 integration tests covering function/file targets, filters, health
  metrics, threshold breaches, impact levels, and edge cases

Impact: 12 functions changed, 8 affected
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