Skip to content

Commit bb41a01

Browse files
wongkclaude
andauthored
feat(code-review): add graph-aware Design Critic reviewer (#170)
* feat(code-review): add graph-aware Design Critic reviewer Add the Design Critic — an always-on, deep-tier conditional core reviewer that evaluates software-design craftsmanship (module depth, information hiding, SOLID, dependency direction, project structure), drawing on A Philosophy of Software Design, SOLID, and Clean Architecture. It is source:"core" (exempt from DOMAIN_CRITIC_CAP), runs on Sonnet, and emits category:"Code Quality" findings scoped to flaws this change introduces. - Cap domain critics uniformly at 3 (was 5) on both standard and deep; deep's extra breadth now comes from the Design Critic + Impact Analyzer. - Make the Design Critic graph-aware: spawn it on code-review-worker-graph and add get_architecture + query_graph to that worker so it can read the real module layout and dependency edges (falls back to grep when the graph is unavailable or review_root is set). - Remove the unused callsite_snippet_hash / snippet_hash_matched fields (LLMs cannot compute sha256; the field had no working consumer) — the verifier now content-matches the verbatim callsite snippet. - Render both conditional core reviewers (Impact Analyzer + Design Critic) on the fleet "Reviewers:" line by deriving the set from _SPAWN_CORE_ROLES instead of a hand-maintained tuple. - Comment/docstring accuracy fixes surfaced by a self-review. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * docs(code-review): update changelog and README for v3.1.0 Add the v3.1.0 CHANGELOG entry (Design Critic reviewer, uniform domain-critic cap of 3, graph-aware Design Critic, callsite_snippet_hash removal) and refresh the README: depth-tier table (cap 5→3, Design Critic row, Impact Analyzer now shipping), /deep description, the graph worker's consumers/tools, and the design_critic_suffix.txt prompt listing. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 5afd105 commit bb41a01

19 files changed

Lines changed: 557 additions & 213 deletions

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ All notable changes to the claude-plugins project will be documented in this fil
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). Entries are listed newest-first; each plugin section is treated as released when merged to `main`.
66

7+
### code-review v3.1.0
8+
9+
#### Added
10+
- New **Design Critic** reviewer — an always-on, deep-tier conditional core reviewer that evaluates software-design craftsmanship (module depth and information hiding, SOLID, dependency direction and layer boundaries, project structure), drawing on *A Philosophy of Software Design*, SOLID, and *Clean Architecture*. It is a `source: "core"` reviewer (exempt from the domain-critic cap), runs on Sonnet, and emits `category: "Code Quality"` findings scoped to design flaws a change introduces or worsens.
11+
- Both conditional core reviewers (the Design Critic and the Impact Analyzer) now appear on the operator-facing "Reviewers:" fleet-summary line. The non-partitioned core set is derived from `_SPAWN_CORE_ROLES` so future core reviewers are listed automatically.
12+
13+
#### Changed
14+
- The domain-critic cap is now a uniform 3 across both standard and deep reviews (previously 5). Deep-tier breadth comes from the always-on Design Critic and the signal-gated Impact Analyzer rather than a wider domain-critic allowance.
15+
- The Design Critic is graph-aware: it runs on the graph-enabled review worker and uses the `codebase-memory-mcp` knowledge graph (`get_architecture` for module/layer layout, `query_graph` for dependency direction and import cycles) when the repository is indexed, falling back to grep otherwise. The graph worker's tool set gained `get_architecture` and `query_graph`.
16+
17+
#### Removed
18+
- Removed the unused `callsite_snippet_hash` field from `external_impact[]` entries and the coupled `snippet_hash_matched` evidence-check field. Impact-analysis callsites are now validated by reading the cited file and content-matching the verbatim `callsite_snippet`.
19+
720
### code-review v3.0.0
821

922
#### Removed

plugins/code-review/.claude-plugin/plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "code-review",
33
"description": "Code review plugin",
4-
"version": "3.0.0",
4+
"version": "3.1.0",
55
"author": {
66
"name": "ClosedLoop",
77
"email": "support@closedloop.ai"

plugins/code-review/README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ plugins/code-review/
2121
SCHEMA.md Canonical Finding + ResultEnvelope schema (PLN-719); §12 documents the golden fixture harness
2222
agents/
2323
code-review-worker.md Background worker agent used by every reviewer fleet spawn (Read, Write, Grep, Glob; permissions-stable across sessions)
24-
code-review-worker-graph.md Graph-aware variant for the cross-file reviewers (Impact Analyzer, Bug Hunter B, fast-path); adds read-only codebase-memory-mcp tools for cross-file usage discovery
24+
code-review-worker-graph.md Graph-aware variant for the cross-file and design reviewers (Impact Analyzer, Bug Hunter B, fast-path, Design Critic); adds read-only codebase-memory-mcp tools cross-file usage discovery for the cross-file roles, project-structure/dependency-graph analysis (get_architecture, query_graph) for the Design Critic
2525
commands/
2626
start.md Main /start command (orchestrator)
2727
prompts/
2828
github-review.md GitHub-mode constraints and output steps (loaded conditionally)
2929
tools/
3030
prompts/shared_prompt.txt Shared reviewer constraints injected into every agent prompt
3131
prompts/bha_suffix.txt Bug Hunter A reviewer persona and focus areas
32+
prompts/design_critic_suffix.txt Design Critic reviewer role (software-design craftsmanship; always-on at deep tier)
3233
python/code_review_schema.py Canonical Finding + ResultEnvelope schema + validators (PLN-719)
3334
python/test_code_review_schema.py Schema tests + round-trips
3435
python/code_review_helpers.py Deterministic helper CLI (parse-diff, hygiene, partition, route, validate, cache, finalize-result, arbitrate-budget, prepare-run, etc.)
@@ -125,7 +126,7 @@ Runs a comprehensive code review. Invokes the full pipeline: diff parsing, hygie
125126

126127
### `/shallow` and `/deep`
127128

128-
Thin command-file wrappers around `/start` with `--depth` pre-bound. `/shallow` invokes the built-in fleet only (BHA + BHB + unified_auditor + verifier; no `critic-gates.json` entries, no signal extraction). `/deep` invokes the standard fleet plus any reviewer tagged `min_depth: deep` in `stages.json` (reserved for the FEA-1401 Impact Analyzer slot — today equivalent to standard).
129+
Thin command-file wrappers around `/start` with `--depth` pre-bound. `/shallow` invokes the built-in fleet only (BHA + BHB + unified_auditor + verifier; no `critic-gates.json` entries, no signal extraction). `/deep` invokes the standard fleet plus the deep-tier reviewers: the **Design Critic** (always-on at deep — no signal trigger), and the FEA-1401 **Impact Analyzer** when signal extraction detects an exported-symbol change or symbol deletion.
129130

130131
### `/cost`
131132

@@ -161,12 +162,13 @@ Three tiers select which reviewer fleet runs:
161162
| `bug_hunter_a` (partitioned at >5000 LOC) ||||
162163
| `bug_hunter_b` ||||
163164
| `unified_auditor` ||||
164-
| `critic-gates.json` domain critics || ✓ (≤3 total) | ✓ (≤5 total) |
165+
| `critic-gates.json` domain critics || ✓ (≤3 total) | ✓ (≤3 total) |
165166
| Verifier ||||
166167
| `fast_path_reviewer` (auto on tiny PRs) | ✓ (auto) | ✓ (auto) | ✓ (auto) |
167-
| `impact_analyzer` (future FEA-1401) ||||
168+
| `design_critic` (always-on at deep) ||||
169+
| `impact_analyzer` (FEA-1401, on exported-symbol change/deletion) ||| ✓ (on signal) |
168170

169-
**Standard-mode budget arithmetic.** With PLN-807 Phase 4, `arbitrate-budget` reserves BHA partitions FIRST (from `_max_bha_partitions_by_loc`) and then allocates the remaining budget to critics and best-effort. The total domain-critic count across both required and best-effort buckets is capped depth-aware: standard runs keep the top `STANDARD_DOMAIN_CRITIC_CAP = 3` (by priority asc, reviewer asc), while deep runs keep the full `DOMAIN_CRITIC_CAP = 5`. Required-bucket critics dropped by the cap emit coverage-gap findings; cap-deferred entries carry `defer_reason: "domain_critic_cap"` in `deferred_for_budget`. PRs with sparse critic-gates rosters see identical fleet to pre-PLN-807.
171+
**Standard-mode budget arithmetic.** With PLN-807 Phase 4, `arbitrate-budget` reserves BHA partitions FIRST (from `_max_bha_partitions_by_loc`) and then allocates the remaining budget to critics and best-effort. The total domain-critic count across both required and best-effort buckets is capped uniformly at `DOMAIN_CRITIC_CAP = 3` (by priority asc, reviewer asc) for both standard and deep tiers. Required-bucket critics dropped by the cap emit coverage-gap findings; cap-deferred entries carry `defer_reason: "domain_critic_cap"` in `deferred_for_budget`. PRs with sparse critic-gates rosters see identical fleet to pre-PLN-807.
170172

171173
**Tier-mismatch nudge.** Shallow runs emit a single LOW system-scoped finding (`system_marker: "tier_mismatch_nudge"`) when the diff would benefit from a higher tier. Heuristics: diff > 3000 LOC; schema/migration paths (`/migrations/`, `/schemas/`, `/models/`); public API surface (`plugin.json`, `index.ts`, `__init__.py`, etc.).
172174

plugins/code-review/SCHEMA.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ shape. Producers may emit dicts directly; the Python convenience type lives in
8383
"line": <int>,
8484
"impact_type": "signature_mismatch | type_incompatibility | semantic_drift | deleted_reference | stale_string_reference | behavioral_change | guard_needed",
8585
"description": "<one sentence>",
86-
"callsite_snippet": "<verbatim>",
87-
"callsite_snippet_hash": "<sha256>",
86+
"callsite_snippet": "<verbatim source line at file:line>",
8887
"discovery": "grep | graph",
8988
"confidence": 0.0..1.0
9089
}
@@ -102,8 +101,7 @@ shape. Producers may emit dicts directly; the Python convenience type lives in
102101
{
103102
"claim": "<verbatim from finding.evidence[]>",
104103
"verified": <bool>,
105-
"actual_read": "<what verifier read at the cited location>",
106-
"snippet_hash_matched": <bool>
104+
"actual_read": "<what verifier read at the cited location>"
107105
}
108106
],
109107
"rejection_class": "evidence_not_found | guard_exists | unreachable | out_of_scope | severity_overstated | null",

plugins/code-review/agents/code-review-worker-graph.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
---
22
name: code-review-worker-graph
3-
description: Graph-aware code review worker for the cross-file reviewers (Impact Analyzer, Bug Hunter B, fast-path). Identical to code-review-worker but adds read-only codebase-memory-mcp tools for precise cross-file usage discovery. Use only for reviewers whose role prompt loads the codebase knowledge graph protocol.
4-
tools: Read, Write, Grep, Glob, mcp__codebase-memory-mcp__search_graph, mcp__codebase-memory-mcp__trace_path, mcp__codebase-memory-mcp__get_code_snippet, mcp__codebase-memory-mcp__search_code
3+
description: Graph-aware code review worker for the cross-file and design reviewers (Impact Analyzer, Bug Hunter B, fast-path, Design Critic). Identical to code-review-worker but adds read-only codebase-memory-mcp tools for precise cross-file usage discovery and project-structure / dependency-graph analysis. Use only for reviewers whose role prompt loads the codebase knowledge graph protocol.
4+
tools: Read, Write, Grep, Glob, mcp__codebase-memory-mcp__search_graph, mcp__codebase-memory-mcp__trace_path, mcp__codebase-memory-mcp__get_code_snippet, mcp__codebase-memory-mcp__search_code, mcp__codebase-memory-mcp__get_architecture, mcp__codebase-memory-mcp__query_graph
55
effort: high # pinned so a lowered session effort can't cut reviewer reasoning depth (no per-Task override; frontmatter is the only lever). Not redundant with the default — do not remove. Rationale: start.md "Orchestrator model (cost)".
66
---
77

88
# Code Review Worker (graph-aware)
99

10-
You are a code review worker agent for the cross-file reviewers. Your job is the
11-
same as the generic `code-review-worker` — read pre-extracted patch files, analyze
12-
changed code, and write structured findings to a JSON file on disk — but you also
13-
have read-only access to the `codebase-memory-mcp` knowledge graph for precise
14-
cross-file usage discovery.
10+
You are a code review worker agent for the cross-file and design reviewers. Your
11+
job is the same as the generic `code-review-worker` — read pre-extracted patch
12+
files, analyze changed code, and write structured findings to a JSON file on disk
13+
— but you also have read-only access to the `codebase-memory-mcp` knowledge graph
14+
for precise cross-file usage discovery and project-structure / dependency-graph
15+
analysis.
1516

1617
## Workflow
1718

@@ -25,8 +26,11 @@ cross-file usage discovery.
2526

2627
- **Read / Write / Grep / Glob**: same as the generic worker.
2728
- **Graph tools** (`search_graph`, `trace_path`, `get_code_snippet`,
28-
`search_code` — each prefixed `mcp__codebase-memory-mcp__` in the allowlist):
29-
read-only context aids. Use them ONLY per the "Optional: codebase knowledge
29+
`search_code`, `get_architecture`, `query_graph` — each prefixed
30+
`mcp__codebase-memory-mcp__` in the allowlist): read-only context aids.
31+
`get_architecture` and `query_graph` serve project-structure and
32+
dependency-graph analysis (the Design Critic's substrate); the other four serve
33+
cross-file usage discovery. Use them ONLY per the "Optional: codebase knowledge
3034
graph" protocol in `shared_prompt.txt`:
3135
- They are usable ONLY when your task prompt provides a non-empty
3236
`GRAPH_PROJECT` value (the orchestrator resolved it to THIS repo's indexed

plugins/code-review/agents/code-review-worker.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ You are a code review worker agent. Your job is to read pre-extracted patch file
2626

2727
Do NOT use Bash. All data you need is available via Read.
2828

29-
> Graph-aware roles (Impact Analyzer, Bug Hunter B, and the fast-path reviewer)
30-
> run as the separate `code-review-worker-graph` agent, which adds read-only `codebase-memory-mcp`
31-
> tools. This generic worker — used by every other reviewer plus the verifier
32-
> fleet and the PLN-725 singletons — deliberately has NO graph access, keeping
33-
> the trust boundary tight for adversarial/verification roles.
29+
> Graph-aware roles (Impact Analyzer, Bug Hunter B, the Design Critic, and the
30+
> fast-path reviewer) run as the separate `code-review-worker-graph` agent, which
31+
> adds read-only `codebase-memory-mcp` tools. This generic worker — used by every
32+
> other reviewer plus the verifier fleet and the PLN-725 singletons — deliberately
33+
> has NO graph access, keeping the trust boundary tight for adversarial/verification
34+
> roles.

plugins/code-review/commands/deep.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
description: Deep code review — standard fleet plus Impact Analyzer (FEA-1401) when changed exported symbols are detected
2+
description: Deep code review — standard fleet plus the always-on Design Critic and the Impact Analyzer (FEA-1401) when changed exported symbols are detected
33
argument-hint: "[scope] [--github] [--base <ref>] [--since-last-review] [--full-review]"
44
---
55

@@ -11,14 +11,22 @@ This command is shorthand for `/start --depth deep`. Follow every instruction in
1111

1212
## What deep does
1313

14-
Deep produces the standard fleet plus the **Impact Analyzer** (FEA-1401) when signal extraction detects `exported_symbol_change` or `symbol_deletion` in the diff. The analyzer identifies changed exported symbols (function signatures, type definitions, exported constants, class API, schema fields, deletions), greps the codebase for external usages outside the diff, and emits findings whose `external_impact[]` array lists every callsite that breaks under the new signature.
14+
Deep produces the standard fleet plus two deep-only conditional core reviewers: the always-on **Design Critic** and the signal-gated **Impact Analyzer** (FEA-1401).
15+
16+
The **Design Critic** runs on **every** deep review (no trigger required). It evaluates the change for software-design craftsmanship — module depth and information hiding, SOLID adherence, dependency direction and layer boundaries, and project/package structure — drawing on *A Philosophy of Software Design*, the SOLID principles, and *Clean Architecture*. It flags only design flaws this change introduces or demonstrably worsens (a new shallow module, a wrong-direction dependency, a god-class this PR grew, a type-switch it extended), runs on Sonnet, and is **exempt from the domain-critic cap** (it is a `source: "core"` reviewer, not a project-specific critic). Like the Impact Analyzer it is graph-aware: when the repo is indexed it queries the `codebase-memory-mcp` knowledge graph (`get_architecture` for module/layer layout, `query_graph` for dependency direction and import cycles), falling back to grep otherwise. Findings carry `category: "Code Quality"`.
17+
18+
The **Impact Analyzer** (FEA-1401) spawns when signal extraction detects `exported_symbol_change` or `symbol_deletion` in the diff. It identifies changed exported symbols (function signatures, type definitions, exported constants, class API, schema fields, deletions), greps the codebase for external usages outside the diff, and emits findings whose `external_impact[]` array lists every callsite that breaks under the new signature.
1519

1620
| Component | shallow | standard | deep |
1721
|---|---|---|---|
1822
| All standard reviewers | (subset) |||
23+
| Domain critics (from `critic-gates.json`) || ✓ (≤3) | ✓ (≤3) |
24+
| Design Critic ||| ✓ (always) |
1925
| Impact Analyzer (FEA-1401) ||| ✓ (when triggered) |
2026

21-
The Impact Analyzer is **conditional**: it only spawns when at least one trigger signal fires above the recommended confidence floor (`exported_symbol_change ≥ 0.8`, `symbol_deletion ≥ 0.85`). A deep run on a docs-only diff or an internal refactor that exposes no new external surface will skip the analyzer entirely. Findings carry `category: "ImpactAnalysis"` and are verifier-audited per callsite (snippet-hash check, grep query replayed for the first 5 findings per batch). ≥2 verified BLOCKING/HIGH Impact findings escalate the verdict to `NEEDS_ATTENTION` (Rule 6).
27+
The per-source **domain-critic cap is 3** on both standard and deep — deep's extra breadth now comes from the always-on Design Critic and the Impact Analyzer rather than from a wider domain-critic allowance.
28+
29+
The Impact Analyzer is **conditional**: it only spawns when at least one trigger signal fires above the recommended confidence floor (`exported_symbol_change ≥ 0.8`, `symbol_deletion ≥ 0.85`). A deep run on a docs-only diff or an internal refactor that exposes no new external surface will skip the analyzer entirely. Findings carry `category: "ImpactAnalysis"` and are verifier-audited per callsite (cited callsite read and content-matched, grep query replayed for the first 5 findings per batch). ≥2 verified BLOCKING/HIGH Impact findings escalate the verdict to `NEEDS_ATTENTION` (Rule 6).
2230

2331
Cost containment: 30 symbols × 50 callsites per symbol hard cap, 5-minute wall budget, 100 grep ops (soft), 250 read ops (soft). Deferred symbols beyond cap surface in the Coverage Plan footer so operators see what was sampled vs analyzed.
2432

0 commit comments

Comments
 (0)