Pre pr audit

From sd0xdev/sd0x-dev-flow · View interactive version

Pre pr audit is an AI agent skill from the GitHub repository sd0xdev/sd0x-dev-flow. Pre-PR confidence audit with 5-dimension scoring. Use when: final check before commit/push/PR, evaluating PR readiness, assessing test quality + risk + coverage holistically. Triggers: pre-pr, readiness check, confidence audit, final verification, ready to PR, how confident. Not for: code review (us

How to use this skill

Skill file

Pre-PR Audit

Pre-deploy ultimate verification. Aggregates test quality, coverage, risk, and AC traceability into a single confidence index (0-100).

When NOT to Use

| Need | Use Instead |

|------|-------------|

| Code review | /codex-review-fast |

| Post-deploy runtime verification | /feature-verify |

| Periodic project health | /project-audit |

| Just run tests | /verify |

| Just check risk | /risk-assess |

Positioning

auto-loop done → [user invokes] /pre-pr-audit → /smart-commit → /push-ci → /create-pr
                                     ↑
                        Pre-deploy ultimate verification

Prohibited

❌ git add | git commit | git push — per @rules/git-workflow.md

This skill audits and reports. It does not modify code or commit.

Arguments

| Arg | Description | Default |

|-----|-------------|---------|

| --mode fast\|deep | Execution depth | fast |

| --strict | Non-zero exit on ⛔ PR-Blocked | off |

| --json | Machine-readable JSON output | off |

| --base <ref> | Compare against ref | HEAD |

Workflow

sequenceDiagram
    participant U as User
    participant PA as /pre-pr-audit
    participant RA as /risk-assess
    participant TR as /codex-test-review
    participant CC as /check-coverage
    participant ST as State / Artifacts

    U->>PA: /pre-pr-audit [--mode fast|deep]

    par Phase A: Collect
        PA->>ST: [Background Agent] Read precommit/verify state (freshness)
        PA->>RA: [Foreground — blocking] risk-analyze.js --json --base <base>
        PA->>PA: [Background Agent] Detect changed files + map to tests
    end

    Note over PA,RA: A2 (/risk-assess) must complete before Phase B — Module Selection depends on top_affected

    par Phase B: Targeted
        PA->>TR: [Foreground] /codex-test-review (top-N risky modules)
        PA->>CC: [Background Agent: coverage-analyst] /check-coverage (deep mode only)
        PA->>PA: [Background Agent] AC trace (if request doc exists)
    end

    PA->>PA: Phase C: Aggregate + hard-fail + gate
    PA->>U: Phase D: Report + confidence index

Phase A: Collect (parallel with dispatch annotations)

| Step | Dispatch | Action | Source |

|------|----------|--------|--------|

| A1 | Background Agent | Read precommit gate state | node scripts/review-state.js check --format=json(installed copy first: .claude/scripts/review-state.js)— precommit.passed is content-addressed, so no separate freshness check; checker absent → report "no verdict source", never a pass |

| A2 | Foreground (blocking) | Run the /risk-assess analyzer for <base> | bash "${CLAUDE_PLUGIN_ROOT}/scripts/run-skill.sh" risk-assess risk-analyze.js --json --mode fast --base <base>, run from the audited repository (the runner is the plugin's, so its path is never repo-relative) — the JSON itself, not the skill's report, which omits fields needed here: base, risk_level, overall_score, dimensions.blast_radius.top_affected. Exit 1 (High) and 2 (Critical) are results, not failures. No parseable JSON, or a base other than <base> → /risk-assess is unavailable (Module Selection step 5) |

| A3 | Background Agent | Map the change inventory to test files | Inventory → match against test/ patterns |

Change inventory = git diff --name-only <base> ∪ git ls-files --others --exclude-standard. An

untracked module is part of the change; a plain git diff never lists it.

<base> is the --base ref, resolved once at the start (default HEAD) and used everywhere the

change is measured — A2, A3, Module Selection's supplement and its fallback. Measuring one of them

against HEAD while the audit was asked for --base main hides committed changes, and with them

the consumer and output paths § Key Evidence is about.

A2 MUST stay foreground: Phase B Module Selection depends on top_affected from /risk-assess output. A1 and A3 dispatch as background Agents and run in parallel with A2.

Phase B: Targeted (parallel, mode-dependent, with dispatch annotations)

| Step | Dispatch | fast | deep | Action |

|------|----------|------|------|--------|

| B1 | Foreground | top-3 | top-10 + supplement | /codex-test-review on selected modules (see Module Selection) |

| B2 | Background Agent (coverage-analyst) | skip | ✅ | /check-coverage for pyramid balance |

| B3 | Background Agent | skip | ✅ (if request doc) | AC trace: parse ## Acceptance Criteria → map to test evidence |

B2 uses coverage-analyst agent (agents/coverage-analyst.md) for background execution. B3 dispatches as a background Agent for AC parsing. B1 stays foreground as the primary assessment.

Module Selection (deterministic)

  1. Source: A2's JSON dimensions.blast_radius.top_affected array (each: file + dependent_count)
  2. Sort: dependent_count descending, tie-break file ascending (stable sort)
  3. Select: N=3 (fast) or N=10 (deep)
  4. Deep supplement: change-inventory files beyond the top_affected cap
  5. Fallback: if /risk-assess is unavailable, the change inventory sorted by lines changed, descending — git diff --numstat <base> (added + deleted), and for an untracked file its whole line count

Phase C: Aggregate

  1. Score each dimension per references/scoring-model.md
  2. Apply evidence confidence cap
  3. Check hard-fail overrides
  4. Compute final index

Phase D: Output

Output report per references/output-template.md. Include:

Summary Integrity

The user-facing summary is what most readers see. It never reads better than the evidence:

| Rule | Detail |

|------|--------|

| Final, not raw | The headline number is final_index (raw × cap). The raw score appears only beside its cap — raw 92 × cap 0.6 = 55 — never alone |

| Hard-fails stay on top | Any triggered hard-fail is named in the first lines of the summary with ⛔ PR-Blocked (hard-fail), whatever the score |

| Missing key evidence is listed | Every item of § Key Evidence that is missing appears under Not Verified, in the summary itself — not only in the findings |

| No readiness without key evidence | With any key evidence missing, the gate is at most ⚠️ PR-Caution, whatever the index |

| N/A is not a pass | A check is N/A only when it does not apply to this change. A consumer-path or output-path check that applies but has no evidence is missing: scored as a fail, not excluded. Missing test execution keeps the scoring model's own treatment (Static-only cap 0.6) and is listed as missing too |

| Short forms too | A one-line or --json summary carries the gate, the final index, the cap, the triggered hard-fails and the missing-evidence count (missing_evidence.length in --json) |

Key Evidence

| Key evidence | Missing when |

|--------------|--------------|

| Test execution | No test run data for the current tree (Execution Integrity has nothing to read) |

| Consumer paths | A changed function, export, schema or CLI flag has callers or readers, and no test exercises the change through one of them |

| Output paths | The change alters something the system emits — a file, report, API response, event, exit code — and no test asserts on that output |

| Risk input | Module Selection used its line-count fallback: /risk-assess did not run, failed, or returned a different base |

5 Dimensions

| # | Dimension | Weight | Checks |

|---|-----------|--------|--------|

| 1 | Execution Integrity | 25% | All tests pass, precommit passed, HEAD freshness, no flaky indicators |

| 2 | Coverage Adequacy | 25% | Unit/Integration/E2E pyramid balance, per-module gap analysis |

| 3 | Test Quality | 20% | AAA compliance, naming, assertion depth, edge cases (per @rules/testing.md) |

| 4 | Risk-to-Test Alignment | 20% | High-risk files have tests, risk level ↔ test depth proportional |

| 5 | Evidence Governance | 10% | AC traceability, exception policy compliance, expiry check |

Gate

User-Facing (3-tier)

| Gate | Score | Sentinel |

|------|-------|----------|

| ✅ Ready | >=85 | ✅ PR-Ready |

| ⚠️ Needs attention | 60-84 | ⚠️ PR-Caution |

| ⛔ Not ready | <60 | ⛔ PR-Blocked |

Hard-Fail Overrides (force ⛔ regardless of score)

Before the four exception checks sourced from the testing contract, Read @skills/test-review/references/testing-contract.md; if that Read fails,

stop the audit before scoring and report that no readiness verdict can be given — never emit a

PR-Ready, PR-Caution or PR-Blocked sentinel with the hard-fail checks unrun, and never judge

an exception from memory.

| Override | Condition | Source |

|----------|-----------|--------|

| Precommit stale | Not passed after latest edit | Auto-loop state |

| Prohibited domain exception | Security/data-integrity/regression AC uses manual exception | rules/testing.md § Evidence Model |

| Exception cap exceeded | Exception count > AC-count-based cap | @skills/test-review/references/testing-contract.md § Evidence Model |

| Expired exception | Past ISO 8601 expiry date | @skills/test-review/references/testing-contract.md § Evidence Model |

| Invalid reason class | Non-enum reason in exception | @skills/test-review/references/testing-contract.md § Evidence Model |

| Unverified exception | No Codex VALID_EXCEPTION verdict | @skills/test-review/references/testing-contract.md § Evidence Model |

| Evidence stale | Artifacts HEAD SHA ≠ current HEAD | Freshness check |

| Critical untested | /risk-assess HIGH+ on zero-coverage files | Risk alignment |

Scoring

See references/scoring-model.md for formulas. Summary:

Verification

References

Examples

Input: /pre-pr-audit
Action: fast mode → collect state + risk → test-review top-3 → aggregate → 85/100 ✅ PR-Ready

Input: /pre-pr-audit --mode deep
Action: deep mode → collect + risk → test-review top-10 + coverage + AC trace → aggregate → 72/100 ⚠️ PR-Caution

Input: /pre-pr-audit   (all present checks pass; the changed exporter's output file has no test)
Action: raw 96 × cap 1.0 = 96, but output-path evidence is missing → ⚠️ PR-Caution, "Not Verified: output path of exportReport()"

Input: /pre-pr-audit --strict
Action: fast mode → score 55 → ⛔ PR-Blocked → exit code 1
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.