omp packages

pi-c-review1.0.2

C code review and auto-correction extension for pi.dev

bravetux.com Published 11 days ago MIT ~713 downloads/mo

Untested on omp

This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.

Did it work for you?

Result

One report per person. A new report replaces your old one.

Reports 0

No reports yet.

Readme

pi-c-review

C Code Review & Auto-Correction Extension for pi.dev

pi-c-review is a specialized extension for Pi Coding Agent (@earendil-works/pi-coding-agent). It enables developers to audit C source files against strict custom requirements, safety profiles (memory safety, buffer security, MISRA-C guidelines), and immediately obtain dual human/machine reports, targeted section reviews, and selective compilation-ready fixes with alternate file outputs.


Features

  • Custom User Requirements: Enforce project-wide guidelines via .creviewrc.json or pass ad-hoc rules directly in slash commands (e.g., "/c-review main.c 'Ensure all mallocs have NULL checks and proper cleanup'").
  • Built-in Safety Presets:
    • memory-safety: Dynamic allocation hygiene, NULL pointer checks, double-free and use-after-free prevention.
    • buffer-security: Banned functions (gets, strcpy, strcat, sprintf), buffer overrun prevention, explicit null termination.
    • embedded-misra: Core MISRA-C principles, fixed-width types (<stdint.h>), explicit variable initialization, switch default: clauses, and resource status validation.
  • Slash Commands:
    • /c-review <filepath> [--func <name>] [--lines <start>-<end>] [custom requirement]: Instant local static scan + deep LLM audit with compliance score, targeted section slicing, and automated dual report generation (.md and .json) in the workspace root.
    • /c-fix <filepath> [1,3 | --issues 1,2 | --rules RULE-ID] [--out <alt_file>]: Selectively or comprehensively fixes diagnosed violations in-place (with .bak backup) or outputs to an alternate target file.
    • /c-review-all [directory] [--report <dir>]: Recursively scans all .c and .h files, generating per-file dual reports and a final rollup summary (c-review-summary.md and .json) in the workspace root.
    • /c-rules [list | init | presets]: Manages project rule configurations and preset definitions.
  • Dual Human & Machine Reports:
    • Markdown report (<file>.review.md & c-review-summary.md): Clean GitHub Flavored Markdown with compliance scorecards, visual progress bars, issue snippets, and quick-fix commands.
    • JSON report (<file>.review.json & c-review-summary.json): Structured machine-readable schema for CI/CD gates, automation, and tooling.
  • Targeted Section & Function Reviews: Restrict audits to specific functions (--func <name>) or line numbers (--lines <start>-<end> or <file>:<start>-<end>).
  • Selective Auto-Fixes: Fix only specific chosen violations (by index numbers like 1,3 or rule IDs like MEM-01) without modifying or reformatting other parts of the file.
  • Alternate Output Destination: Write corrected code to a new file with --out <path> / -o <path>, leaving the original source file completely untouched.
  • Local Static Pre-Scanner: Sub-10ms pattern analyzer detecting banned functions (gets, strcpy, strcat, sprintf, atoi), contextual NULL allocation checks, dangling pointers after free(), unbraced control flow, and non-fixed-width types.
  • Inline Suppression: Fully supports // NOLINT and // NOLINT(RULE-ID) comments to selectively bypass specific rules.
  • Compliance Scoring & Dashboard: Quantitative 0-100 scoring with letter grades (A through F) and visual terminal progress bars.
  • Agent Tool (c_review_and_fix): LLM-callable tool enabling Pi to autonomously audit and fix C snippets or files during multi-turn agent sessions.
  • Auto-Detection Hook: Automatically listens for edits on .c and .h files and alerts the developer when compliance verification is recommended.

Installation

Option 1: Local Development / Project-Local

Place or link this extension in your project's .pi/extensions/ or run:

pi install /path/to/pidev

Option 2: Global Pi Extension Directory

Copy the compiled extension into your global Pi extension folder:

cp -r /path/to/pidev ~/.pi/agent/extensions/pi-c-review

Inside Pi, execute /reload to load the extension.

Option 3: Via npm (when published)

pi install npm:pi-c-review

Usage

1. Review C Code (Full File, Function, or Line Range)

Run /c-review with a file path:

# Full file audit (generates server.c.review.md and server.c.review.json in workspace root)
/c-review src/server.c

# Review only a specific function
/c-review src/server.c --func handle_packet

# Review only a specific line range
/c-review src/server.c --lines 50-120

# Shorthand line range syntax
/c-review src/server.c:50-120 "Ensure socket timeouts"

The extension audits the targeted section, lists categorized violations with indexed numbers ([1], [2], ...), outputs the dual reports, and sends the scoped review to the agent.

2. Selective Auto-Fixes & Alternate File Output

Run /c-fix to apply fixes:

# Fix all violations in-place (creates src/buffer.c.bak)
/c-fix src/buffer.c

# Fix ONLY issues #1 and #3 from the review report
/c-fix src/buffer.c 1,3

# Fix ONLY memory allocation issues by rule ID
/c-fix src/buffer.c --rules MEM-01

# Apply fixes to a NEW file, keeping original buffer.c untouched
/c-fix src/buffer.c 1,2 --out src/buffer_fixed.c

3. Project-Wide Audit & Rollup Reports

Scan an entire project or directory:

/c-review-all src/

Generates:

  1. Individual reports for every .c/.h file: <basename>.review.md and <basename>.review.json
  2. Final project rollup summary: c-review-summary.md and c-review-summary.json

4. Initialize Project Rules

Create a project-specific .creviewrc.json file in your workspace root:

/c-rules init

Example .creviewrc.json:

{
  "presets": ["memory-safety", "buffer-security", "embedded-misra"],
  "customRules": [
    "Every pointer returned from malloc/calloc must be checked against NULL immediately",
    "All file handles opened with fopen must be closed before returning on all error paths",
    "Do not use magic numbers; use uppercase enum or #define constants"
  ],
  "createBackup": true,
  "strictMode": false
}

Check active rules anytime with:

/c-rules list

Documentation

For comprehensive technical specifications, consult the project documentation:


Development & Testing

# Install dependencies
npm install

# Run unit tests (82 tests across 11 test suites)
npm test

# Build TypeScript
npm run build

Author

Vignesh Kumar B (aka Bravetux) (ic19939@gmail.com)


License

MIT © 2026 Vignesh Kumar B (aka Bravetux)