Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,10 @@ codegraph batch --json targets.json # Batch from a JSON file
codegraph check # Run manifesto rules on whole codebase
codegraph check --staged # Check staged changes (diff predicates)
codegraph check --staged --rules # Run both diff predicates AND manifesto rules
codegraph check --no-new-cycles # Fail if staged changes introduce cycles
codegraph check --max-complexity 30 # Fail if any function exceeds complexity threshold
codegraph check --max-blast-radius 50 # Fail if blast radius exceeds limit
codegraph check --no-boundary-violations # Fail on architecture boundary violations
codegraph check --staged --cycles # Fail if staged changes introduce cycles
codegraph check --staged --blast-radius 50 # Fail if blast radius exceeds limit
codegraph check --staged --boundaries # Fail on architecture boundary violations
codegraph check --staged --signatures # Fail if an exported declaration's line was modified
codegraph check main # Check current branch vs main
```

Expand Down
10 changes: 5 additions & 5 deletions docs/contributing/harness-engineering.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Zero-tolerance enforcement: the agent cannot proceed until all checks pass. No w
```bash
# Example: codegraph pre-commit gate
codegraph build
codegraph check --staged --no-new-cycles --max-blast-radius 50 -T
codegraph check --staged --cycles --blast-radius 50 -T
```

### Layer 2: AI Review
Expand Down Expand Up @@ -119,7 +119,7 @@ With codegraph, this is built-in:

```bash
# codegraph check provides actionable output
codegraph check --staged --no-new-cycles --max-blast-radius 50 -T
codegraph check --staged --cycles --blast-radius 50 -T
# Output: "Cycle detected: A -> B -> C -> A. Break the cycle by..."
# Output: "Blast radius 67 exceeds threshold 50. Function X affects..."
```
Expand Down Expand Up @@ -154,7 +154,7 @@ Types -> Config -> Repo -> Service -> Runtime -> UI
```

**Enforcement tools:**
- `codegraph check --no-boundary-violations` — blocks imports that violate layer direction
- `codegraph check --staged --boundaries` — blocks imports that violate layer direction
- `codegraph cycles` — detects circular dependencies
- Custom ESLint rules or `dependency-cruiser` for additional constraints
- CI gates that fail the build on violations
Expand Down Expand Up @@ -259,7 +259,7 @@ Codegraph already implements most of these practices. Here's how they map:
|---|---|
| Deterministic guardrails | `codegraph check` pre-commit gates, cycle detection, blast radius thresholds |
| Remediation-focused errors | `codegraph check` output includes what violated and where |
| Mechanical architecture | `codegraph check --no-boundary-violations`, `codegraph cycles` |
| Mechanical architecture | `codegraph check --staged --boundaries`, `codegraph cycles` |
| Silent success / loud failure | Claude Code hooks exit silently on success |
| AGENTS.md | `CLAUDE.md` with codegraph workflow commands |
| Progress tracking | Titan Paradigm skills with state files |
Expand All @@ -274,7 +274,7 @@ To add harness engineering to an existing codegraph project:
1. **Create `CLAUDE.md`** with build commands and your top 5 failure-driven rules
2. **Add pre-commit hooks** using codegraph check:
```bash
codegraph check --staged --no-new-cycles --max-blast-radius 50 -T
codegraph check --staged --cycles --blast-radius 50 -T
```
3. **Configure CI gates** with `codegraph check -T` in your pipeline
4. **Set up Claude Code hooks** — see [Claude Code Hooks Guide](../examples/claude-code-hooks/README.md) for ready-to-use scripts
Expand Down
31 changes: 17 additions & 14 deletions docs/examples/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ Cycles whose only closing edge is a low-confidence dynamic call (resolved via
a resolver heuristic rather than confirmed statically) are marked
`[speculative]` rather than reported as confirmed structural cycles. Pass
`--exclude-speculative` to drop them from the output entirely, or `--json` to
get a `speculative: boolean` field per cycle. `codegraph check --cycles` and
get a `speculative: boolean` field per cycle. `codegraph check --staged --cycles` and
the manifesto `noCycles` rule ignore speculative-only cycles by default (see
`check.excludeSpeculativeCycles` in [configuration](../guides/configuration.md)).

Expand Down Expand Up @@ -1172,43 +1172,46 @@ Configurable pass/fail gates. Exit code 0 = pass, 1 = fail.
- `check --staged --rules` — runs both diff predicates AND manifesto rules

```bash
codegraph check --staged --no-new-cycles --max-complexity 30
codegraph check --staged --cycles
```

```
# Check Results

✓ no-new-cycles — no new cycles introduced
✗ max-complexity (30) — 3 functions exceed threshold:
buildGraph (cognitive=495) src/builder.js:335
extractJavaSymbols (cognitive=208) src/extractors/java.js
extractSymbolsWalk (cognitive=197) src/extractors/javascript.js
Changed files: 4 New files: 1 Deleted files: 0

Result: FAIL (exit code 1)
[PASS] cycles

1 predicates | 1 passed | 0 failed
```

```bash
codegraph check --staged --max-blast-radius 50
codegraph check --staged --blast-radius 50
```

```
# Check Results

✓ max-blast-radius (50) — max blast radius is 1
Changed files: 4 New files: 1 Deleted files: 0

Result: PASS (exit code 0)
[FAIL] blast-radius
buildGraph (function) at src/builder.js:335 — 67 callers (max: 50)

1 predicates | 0 passed | 1 failed
```

```bash
codegraph check --no-boundary-violations -T
codegraph check --staged --boundaries -T
```

```
# Check Results

✓ no-boundary-violations — no architecture boundary violations
Changed files: 4 New files: 1 Deleted files: 0

[PASS] boundaries

Result: PASS (exit code 0)
1 predicates | 1 passed | 0 failed
```

---
Expand Down
21 changes: 11 additions & 10 deletions docs/examples/MCP.md
Original file line number Diff line number Diff line change
Expand Up @@ -946,36 +946,37 @@ Configurable pass/fail gates. Returns structured results with exit status.
```json
{
"tool": "check",
"arguments": { "staged": true, "no_new_cycles": true, "max_complexity": 30 }
"arguments": { "staged": true, "cycles": true, "blast_radius": 50 }
}
```

```json
{
"checks": [
{ "name": "no-new-cycles", "passed": true, "detail": "no new cycles introduced" },
{ "name": "max-complexity", "passed": false, "threshold": 30, "violations": [
{ "name": "buildGraph", "file": "src/builder.js", "line": 335, "cognitive": 495 },
{ "name": "extractJavaSymbols", "file": "src/extractors/java.js", "cognitive": 208 }
"predicates": [
{ "name": "cycles", "passed": true },
{ "name": "blast-radius", "passed": false, "threshold": 50, "violations": [
{ "name": "buildGraph", "kind": "function", "file": "src/builder.js", "line": 335, "transitiveCallers": 67 }
]}
],
"summary": { "changedFiles": 4, "newFiles": 1, "deletedFiles": 0, "total": 2, "passed": 1, "failed": 1 },
"passed": false
}
```

```json
{
"tool": "check",
"arguments": { "staged": true, "max_blast_radius": 50, "no_boundary_violations": true }
"arguments": { "staged": true, "boundaries": true, "signatures": true }
}
```

```json
{
"checks": [
{ "name": "max-blast-radius", "passed": true, "detail": "max blast radius is 1" },
{ "name": "no-boundary-violations", "passed": true, "detail": "no violations" }
"predicates": [
{ "name": "boundaries", "passed": true },
{ "name": "signatures", "passed": true }
],
"summary": { "changedFiles": 4, "newFiles": 1, "deletedFiles": 0, "total": 2, "passed": 2, "failed": 0 },
"passed": true
}
```
Expand Down
10 changes: 5 additions & 5 deletions docs/guides/ai-agent-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,14 +441,14 @@ codegraph batch target1 target2 target3 -T --json
Configurable pass/fail gates with exit code 0 (pass) or 1 (fail).

```bash
codegraph check --staged --no-new-cycles --max-complexity 30
codegraph check --staged --max-blast-radius 50 --no-boundary-violations
codegraph check --staged --cycles
codegraph check --staged --blast-radius 50 --boundaries --signatures
```

| | |
|---|---|
| **MCP tool** | `check` |
| **Key flags** | `--staged`, `--no-new-cycles`, `--max-complexity <n>`, `--max-blast-radius <n>`, `--no-boundary-violations`, `-T` (no tests) |
| **Key flags** | `--staged`, `--cycles`, `--blast-radius <n>`, `--boundaries`, `--signatures`, `-T` (no tests) |
| **When to use** | CI gates, state machines, rollback triggers — anywhere you need a pass/fail signal |
| **Output** | Per-predicate pass/fail results; exit code 0 or 1 |

Expand Down Expand Up @@ -894,7 +894,7 @@ This project uses codegraph for dependency analysis. The graph is at `.codegraph
- `codegraph diff-impact main -T` — impact of branch vs main
- `codegraph audit <target> -T` — structural summary + impact + health in one report
- `codegraph triage -T` — ranked audit priority queue
- `codegraph check --staged --no-new-cycles` — CI validation predicates (exit 0/1)
- `codegraph check --staged --cycles` — CI validation predicates (exit 0/1)
- `codegraph batch t1 t2 t3 -T --json` — batch query multiple targets

### Overview
Expand Down Expand Up @@ -1087,7 +1087,7 @@ fi
| Get a full risk report for a function | `codegraph audit <name> -T` |
| Get a ranked list of riskiest functions | `codegraph triage -T --limit 20` |
| Batch query multiple targets at once | `codegraph batch t1 t2 t3 -T --json` |
| Validate staged changes pass CI rules | `codegraph check --staged --no-new-cycles` |
| Validate staged changes pass CI rules | `codegraph check --staged --cycles` |
| Find who owns a piece of code | `codegraph owners <target>` |
| Checkpoint the graph before refactoring | `codegraph snapshot save <name>` |
| Restore graph after failed refactoring | `codegraph snapshot restore <name>` |
Expand Down
2 changes: 1 addition & 1 deletion docs/roadmap/BACKLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Non-breaking, ordered by problem-fit:
| 18 | ~~CODEOWNERS integration~~ | ~~Map graph nodes to CODEOWNERS entries. Show who owns each function, surface ownership boundaries in `diff-impact`. Inspired by CKB.~~ | Developer Experience | ~~`diff-impact` tells agents which teams to notify; ownership-aware impact analysis reduces missed reviews~~ | ✓ | ✓ | 3 | No | — | **DONE** — `src/owners.js` module with CODEOWNERS parser, matcher, and data functions. `codegraph owners [target]` CLI command with `--owner`, `--boundary`, `-f`, `-k`, `-T`, `-j` options. `code_owners` MCP tool. Integrated into `diff-impact` (affected owners + suggested reviewers). No new deps — glob patterns via ~30-line `patternToRegex`. PR #195. |
| 22 | ~~Manifesto-driven pass/fail~~ | ~~User-defined rule engine with custom thresholds (e.g. "cognitive > 15 = fail", "cyclomatic > 10 = fail", "imports > 10 = decompose"). Outputs pass/fail per function/file. Generalizes ID 13 (boundary rules) into a generic rule system.~~ | Analysis | ~~Enables autonomous multi-agent audit workflows (GAUNTLET pattern); CI integration for code health gates with configurable thresholds~~ | ✓ | ✓ | 3 | No | — | **DONE** — `codegraph manifesto` with 9 configurable rules (cognitive, cyclomatic, nesting, MI, Halstead volume/effort/bugs, fan-in, fan-out). Warn/fail thresholds via `.codegraphrc.json`. Exit code 1 on any fail-level breach — CI gate ready. PR #138. |
| 31 | ~~Graph snapshots~~ | ~~`codegraph snapshot save <name>` / `codegraph snapshot restore <name>` for lightweight SQLite DB backup and restore. Enables orchestrators to checkpoint before refactoring passes and instantly rollback without rebuilding. After Phase 4, also preserves embeddings and semantic metadata. Inspired by [Titan Paradigm](../docs/use-cases/titan-paradigm.md) STATE MACHINE phase.~~ | Orchestration | ~~Multi-agent workflows get instant rollback without re-running expensive builds or LLM calls — orchestrator checkpoints before each pass and restores on failure~~ | ✓ | ✓ | 3 | No | — | **DONE** — `codegraph snapshot` subcommand group with `save`, `restore`, `list`, `delete`. Uses SQLite `VACUUM INTO` for atomic, WAL-free snapshots in `.codegraph/snapshots/`. All 6 functions exported via programmatic API. PR #192. |
| 30 | ~~Change validation predicates~~ | ~~`codegraph check --staged` with configurable predicates: `--no-new-cycles`, `--max-blast-radius N`, `--no-signature-changes`, `--no-boundary-violations`. Returns exit code 0/1 for CI gates and state machines. Inspired by [Titan Paradigm](../docs/use-cases/titan-paradigm.md) STATE MACHINE phase.~~ | CI | ~~Automated rollback triggers without parsing JSON — orchestrators and CI pipelines get first-class pass/fail signals for blast radius, cycles, and contract changes~~ | ✓ | ✓ | 3 | No | — | **DONE** — `codegraph check` with `--no-new-cycles`, `--max-complexity N`, `--max-blast-radius N`, `--no-boundary-violations`, and `--staged`/ref support. Exit code 0/1 for CI gates. `check` MCP tool. PR #225 + #230. |
| 30 | ~~Change validation predicates~~ | ~~`codegraph check --staged` with configurable predicates: `--no-new-cycles`, `--max-blast-radius N`, `--no-signature-changes`, `--no-boundary-violations`. Returns exit code 0/1 for CI gates and state machines. Inspired by [Titan Paradigm](../docs/use-cases/titan-paradigm.md) STATE MACHINE phase.~~ | CI | ~~Automated rollback triggers without parsing JSON — orchestrators and CI pipelines get first-class pass/fail signals for blast radius, cycles, and contract changes~~ | ✓ | ✓ | 3 | No | — | **DONE** — `codegraph check` with `--cycles`, `--blast-radius N`, `--boundaries`, `--signatures`, and `--staged`/ref support. Exit code 0/1 for CI gates. `check` MCP tool. PR #225 + #230. |
| 6 | ~~Formal code health metrics~~ | ~~Cyclomatic complexity, Maintainability Index, and Halstead metrics per function — we already parse the AST, the data is there. Inspired by code-health-meter (published in ACM TOSEM 2025).~~ | Analysis | ~~Agents can prioritize refactoring targets; `hotspots` becomes richer with quantitative health scores per function~~ | ✓ | ✓ | 2 | No | — | **DONE** — `codegraph complexity` provides cognitive, cyclomatic, nesting depth, Halstead (volume, difficulty, effort, bugs), and Maintainability Index per function. `--health` for full Halstead view, `--sort mi` to rank by MI, `--above-threshold` for flagged functions. `function_complexity` DB table. `complexity` MCP tool. PR #130 + #139. |
| 11 | ~~Community detection~~ | ~~Leiden/Louvain algorithm to discover natural module boundaries vs actual file organization. Reveals which symbols are tightly coupled and whether the directory structure matches. Inspired by axon, GitNexus, CodeGraphMCPServer.~~ | Intelligence | ~~Surfaces architectural drift — when directory structure no longer matches actual dependency clusters; guides refactoring~~ | ✓ | ✓ | 2 | No | — | **DONE** — `codegraph communities` with Louvain algorithm. File-level and `--functions` function-level detection. `--drift` for drift analysis (split/merge candidates). `--resolution` tunable. `communities` MCP tool. PR #133/#134. |
| 21 | ~~Cognitive + cyclomatic complexity~~ | ~~Cognitive Complexity (SonarSource) as the primary readability metric — penalizes nesting, so it subsumes nesting depth analysis. Cyclomatic complexity (McCabe) as secondary testability metric. Both computed from existing tree-sitter AST in a single traversal. Cognitive > 15 or cyclomatic > 10 = flag for refactoring. Extends ID 6 with the two most actionable metrics.~~ | Analysis | ~~Agents can flag hard-to-understand and hard-to-test functions in one pass; cognitive complexity captures both decision complexity and nesting depth in a single score~~ | ✓ | ✓ | 2 | No | — | **DONE** — Subsumed by ID 6. `codegraph complexity` provides both cognitive and cyclomatic metrics (plus nesting depth, Halstead, MI) in a single command. PR #130. |
Expand Down
Loading
Loading