Skip to content

Commit 424d914

Browse files
committed
feat: import-graph test impact, git_error for diff_impact, agent-oriented docs
- BFS import closure for get_impacted_tests/suggest_tests; storage importers/imported - tool_coupling: numeric cochange/import/effective scores; diff_impact catches git failures - Risk breakdown: coverage_fraction; schemas/cli/next_steps updates; tests - README/CLAUDE/ARCHITECTURE/COMPLETE_PROJECT_DOCUMENTATION: solo multi-agent focus - wiki-local/spec-project.md and CONTRIBUTING aligned with MCP contracts Made-with: Cursor
1 parent 310e352 commit 424d914

16 files changed

Lines changed: 313 additions & 76 deletions

ARCHITECTURE.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
**Version:** 0.6.3 | **Python:** >= 3.11 | **Dependencies:** zero (stdlib only)
44

5-
Test impact analysis and code intelligence for LLM agents. Maps tests to code, code to git history, and answers: "what to run, what's risky, who touched it."
5+
Test impact analysis and code intelligence **for LLM agents**. The design target is **solo-maintained repos** where **multiple agent sessions or processes** (MCP clients, terminals, CI) may run `analyze` / read tools concurrently — hence **ProcessLock**, **WAL SQLite**, and **normalized paths** as core mechanics, not optional extras.
6+
7+
Questions Chisel answers for agents: **what tests matter for a change**, **where risk concentrates**, **what’s untested or stale**, and **git/blame context** when debugging — not headcount or org workflows.
68

79
## Core Data Model
810

@@ -54,10 +56,10 @@ ChiselEngine (engine.py) — main orchestrator
5456
│ ├── Ownership aggregation from blame blocks
5557
│ └── Co-change coupling detection
5658
├── ImpactAnalyzer (impact.py)
57-
│ ├── Impacted tests (direct + transitive via coupling)
59+
│ ├── Impacted tests (direct + co-change + import-graph reachability)
5860
│ ├── Risk scoring (5-component weighted formula)
5961
│ ├── Stale test detection (orphaned edge refs)
60-
│ └── Reviewer suggestions (commit-activity-based)
62+
│ └── Commit-activity hints (who_reviews; heuristic, not team routing)
6163
├── AST Utils (ast_utils.py)
6264
│ ├── Multi-language extraction (12 languages)
6365
│ ├── Pluggable extractor registry (tree-sitter/LSP hooks)

CLAUDE.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
Test impact analysis and code intelligence for LLM agents. Zero external dependencies.
44

5+
## Audience (how to read this project)
6+
7+
- **Primary user**: autonomous and semi-autonomous **coding agents** (MCP, CLI invoked by agents), not a stand-alone dashboard for engineering managers.
8+
- **Typical human**: **solo developer** orchestrating multiple agent sessions, parallel tasks, or long-running analyses — *not* “hand off to another engineer” workflows. Tools like `ownership` / `who_reviews` expose **git-derived context** (blame, commit activity) for debugging and risk heuristics; they are not org-chart features.
9+
- **Multi-agent safety** (see `project.py`, `ProcessLock`, `RWLock`) exists so **several processes** (agents, terminals, CI) can share one `.chisel/` database without corrupting reads/writes — treat this as a **first-class product requirement**, not an edge case.
10+
11+
When editing behavior or docs, prefer: **structured tool results**, **explicit statuses** (`no_data`, `no_changes`, `git_error`), **import-graph + test edges** over relying on git co-change alone, and **clear hints** when MCP would otherwise time out or mis-resolve `project_dir`.
12+
513
## Architecture
614

715
```
@@ -34,9 +42,9 @@ chisel/
3442
- **Blame caching**: Cached by file content hash, invalidated on change.
3543
- **Incremental updates**: File content hashes tracked in `file_hashes` table.
3644
- **Persistent connection**: Storage uses a single SQLite connection (`check_same_thread=False`) with RWLock for thread safety.
37-
- **Multi-agent safety**: `project.py` provides: (1) `detect_project_root()` canonicalizes via git common dir so worktrees share identity, (2) `normalize_path()` ensures consistent relative paths, (3) `resolve_storage_dir()` defaults to project-local `.chisel/` (priority: explicit > env > project-local > ~/.chisel/), (4) `ProcessLock` for cross-process coordination — shared locks for reads, exclusive for writes. Cross-platform: `fcntl.flock` on Unix, `LockFileEx` on Windows.
45+
- **Multi-agent / multi-process safety** (solo dev + parallel agents): `project.py` provides: (1) `detect_project_root()` canonicalizes via git common dir so worktrees share identity, (2) `normalize_path()` ensures consistent relative paths, (3) `resolve_storage_dir()` defaults to project-local `.chisel/` (priority: explicit > env > project-local > ~/.chisel/), (4) `ProcessLock` for cross-process coordination — shared locks for reads, exclusive for writes — so concurrent agent runs and CLI `analyze`/`update` do not interleave destructive storage operations. Cross-platform: `fcntl.flock` on Unix, `LockFileEx` on Windows.
3846
- **SQLite concurrency**: 30s `busy_timeout` + exponential-backoff retry on `_execute` for cross-process SQLITE_BUSY.
39-
- **Ownership vs Reviewers**: `ownership` = blame-based (who wrote the code, `role: "original_author"`). `who_reviews` = commit-activity-based (who maintains it, `role: "suggested_reviewer"`).
47+
- **Ownership vs Reviewers**: `ownership` = blame-based (`role: "original_author"`). `who_reviews` = commit-activity-based (`role: "suggested_reviewer"`). Both are **git-derived signals** for agents (lineage, hot spots); they are not substitutes for team assignment in a solo workflow.
4048
- **Shared constants**: `_SKIP_DIRS` and `_EXTENSION_MAP` live in `ast_utils.py`. `_CODE_EXTENSIONS` in `engine.py` is derived from `_EXTENSION_MAP`. `_SKIP_DIRS` includes `coverage`, `.next`, `.nuxt` to exclude build/test output artifacts.
4149
- **Shared dispatch**: `dispatch_tool()` in `mcp_server.py` is used by both HTTP and stdio servers. Tool schemas and dispatch tables live in `schemas.py`.
4250
- **Edge weighting**: Test edges carry a weight (0.4-1.0) based on file proximity. `_compute_proximity_weight()` in `test_mapper.py`.

COMPLETE_PROJECT_DOCUMENTATION.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Chisel -- Complete Project Documentation
22

3-
Test impact analysis and code intelligence for LLM agents. Zero external dependencies.
3+
Test impact analysis and code intelligence for **LLM agents** in **solo-maintainer** workflows, with **multi-process / multi-agent** safety (shared `.chisel/` storage, locks). Zero external dependencies.
44

55
**Version:** 0.6.2
66
**PyPI:** `chisel-test-impact`
@@ -35,7 +35,7 @@ Test impact analysis and code intelligence for LLM agents. Zero external depende
3535
| `chisel/metrics.py` | Pure computation: churn scoring, ownership aggregation, co-change detection | `collections`, `datetime`, `itertools` | [glossary: churn score](wiki-local/glossary.md) |
3636
| `chisel/test_mapper.py` | Test file discovery, framework detection (pytest/Jest/Go/Rust/Playwright), dependency extraction, test edge building | `ast`, `os`, `re`, `pathlib`, `chisel.ast_utils`, `chisel.project` | [glossary: test edge](wiki-local/glossary.md) |
3737
| `chisel/impact.py` | Impact analysis, risk scoring, stale test detection, ownership queries, reviewer suggestions | `collections`, `datetime`, `chisel.metrics`, `chisel.storage` (via constructor injection) | [glossary: risk score](wiki-local/glossary.md) |
38-
| `chisel/project.py` | Multi-agent safety: project root detection (worktree-aware), path normalization, storage dir resolution, cross-platform file lock (ProcessLock) | `os`, `subprocess`, `sys`, `contextlib`; Unix: `fcntl`; Windows: `ctypes`, `msvcrt` | -- |
38+
| `chisel/project.py` | Multi-process / multi-agent safety: project root detection (worktree-aware), path normalization, storage dir resolution, cross-platform file lock (ProcessLock) for concurrent agents and CLI | `os`, `subprocess`, `sys`, `contextlib`; Unix: `fcntl`; Windows: `ctypes`, `msvcrt` | -- |
3939
| `chisel/engine.py` | Orchestrator -- owns Storage, GitAnalyzer, TestMapper, ImpactAnalyzer, RWLock, ProcessLock; exposes `tool_*()` methods for all 15 MCP tools | `os`, `chisel.ast_utils`, `chisel.git_analyzer`, `chisel.impact`, `chisel.project`, `chisel.rwlock`, `chisel.storage`, `chisel.test_mapper` | [spec-project](wiki-local/spec-project.md) |
4040
| `chisel/cli.py` | argparse CLI with 17 subcommands, dispatch table, output formatting | `argparse`, `json`, `os`, `chisel.engine` | [spec-project: CLI](wiki-local/spec-project.md) |
4141
| `chisel/mcp_server.py` | HTTP MCP server (GET /tools, /health; POST /call), ThreadedHTTPServer, shared `dispatch_tool()` | `json`, `logging`, `threading`, `http.server`, `socketserver`, `chisel.engine`, `chisel.schemas` | [spec-project: MCP tools](wiki-local/spec-project.md) |

CONTRIBUTING.md

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Contributing to Chisel
22

3+
Chisel is built for **LLM agents** and **solo developers** running **multiple agent sessions** on one repo. Contributions should preserve: **stdlib-only runtime**, **structured MCP responses** (status dicts, `next_steps` where applicable), **multi-process safety** (locks around storage), and **import-graph + test edges** as primary signals when git co-change is thin.
4+
35
## Prerequisites
46

57
- Python 3.11 or later
@@ -18,7 +20,7 @@ This installs Chisel in editable mode along with dev dependencies (pytest, pytes
1820
## Running Tests
1921

2022
```bash
21-
pytest tests/ -v --tb=short # full suite (567 tests)
23+
pytest tests/ -v --tb=short # full suite
2224
pytest tests/test_engine.py # single module
2325
pytest -k "test_risk" # by name pattern
2426
```
@@ -37,25 +39,26 @@ Configuration lives in `pyproject.toml` under `[tool.ruff]`.
3739

3840
## Architecture Overview
3941

40-
See `CLAUDE.md` for the full module map and dependency graph, and `ARCHITECTURE.md` for detailed design documentation.
42+
See `CLAUDE.md` for the full module map and dependency graph, `ARCHITECTURE.md` for the data model, and `wiki-local/spec-project.md` for MCP tool contracts.
4143

4244
The core modules are:
4345

4446
| Module | Role |
4547
|---|---|
46-
| `engine.py` | Orchestrator; owns all subsystems |
48+
| `engine.py` | Orchestrator; owns all subsystems; `tool_*()` for MCP |
4749
| `storage.py` | SQLite persistence (WAL mode, single persistent connection, batch queries) |
4850
| `ast_utils.py` | Multi-language AST extraction (12 languages) + pluggable extractor registry |
4951
| `git_analyzer.py` | Git log/blame parsing via subprocess |
5052
| `metrics.py` | Pure computation: churn scoring, ownership, co-change detection |
5153
| `test_mapper.py` | Test discovery, framework detection, dependency extraction, edge building |
52-
| `impact.py` | Impact analysis, risk scoring, stale test detection, reviewer suggestions |
53-
| `project.py` | Project root detection, path normalization, cross-platform ProcessLock |
54-
| `schemas.py` | JSON Schema definitions for all 15 tools + dispatch table |
55-
| `cli.py` | argparse CLI (17 subcommands) |
56-
| `mcp_server.py` | HTTP MCP server |
54+
| `impact.py` | Impact analysis (direct + co-change + import-graph tests), risk scoring, stale tests, git-derived ownership/review hints |
55+
| `project.py` | Project root, path normalization, **ProcessLock** (multi-process / multi-agent) |
56+
| `schemas.py` | JSON Schema + dispatch for **22 MCP tools** (core + advisory file locks) |
57+
| `next_steps.py` | Contextual follow-up hints for agent clients |
58+
| `cli.py` | argparse CLI (core tools + serve + lock subcommands) |
59+
| `mcp_server.py` | HTTP MCP server (`dispatch_tool`, `next_steps`) |
5760
| `mcp_stdio.py` | stdio MCP server |
58-
| `rwlock.py` | Read-write lock for concurrent access |
61+
| `rwlock.py` | In-process read/write lock (pairs with ProcessLock) |
5962

6063
## Guidelines
6164

@@ -82,12 +85,14 @@ Do not add runtime dependencies.
8285

8386
### Adding a New MCP Tool
8487

85-
To add a new tool, wire it through four layers:
88+
To add a new tool, wire it through these layers:
89+
90+
1. **Engine method**: Add `tool_<name>(self, ...)` in `engine.py`. Wrap with `self._process_lock.shared()` + `self.lock.read_lock()` for reads, or `exclusive()` + `write_lock()` for writes. Prefer **explicit statuses** (`no_data`, `git_error`, etc.) over ambiguous empty lists for agents.
91+
2. **Schema + dispatch**: Add the tool schema to `_TOOL_SCHEMAS` and the dispatch entry to `_TOOL_DISPATCH` in `schemas.py`. Use **prescriptive** descriptions (“Use when…”). Both HTTP and stdio servers import these automatically; HTTP responses include **`next_steps`** — add a handler in `next_steps.py` if the new tool should suggest follow-ups.
92+
3. **CLI handler**: Add a subcommand in `cli.py` when the tool should be human-invokable from the terminal (optional for agent-only tools).
93+
4. **Tests**: Add tests in `tests/` — at minimum an engine integration test; add CLI tests if you added a subcommand.
8694

87-
1. **Engine method**: Add `tool_<name>(self, ...)` in `engine.py`. Wrap with `self._process_lock.shared()` + `self.lock.read_lock()` for reads, or `exclusive()` + `write_lock()` for writes.
88-
2. **Schema + dispatch**: Add the tool schema to `_TOOL_SCHEMAS` and the dispatch entry to `_TOOL_DISPATCH` in `schemas.py`. Both HTTP and stdio servers import these automatically.
89-
3. **CLI handler**: Add a subcommand in `cli.py` that calls the engine method and formats output.
90-
4. **Tests**: Add tests in `tests/` — at minimum an engine integration test and a CLI mock test.
95+
Keep **multi-agent safety** in mind: long-running writes (`analyze`, `update`) must stay under the process exclusive lock; readers should not block writers longer than necessary.
9196

9297
### Adding a Custom Extractor
9398

LLM_Development.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ Chronological record of development activity on the Chisel project.
44

55
---
66

7+
## 2026-03-27 -- Product re-orientation (agentic + multi-agent solo)
8+
9+
### Summary
10+
Re-oriented README, CLAUDE.md, ARCHITECTURE.md, and COMPLETE_PROJECT_DOCUMENTATION.md toward **LLM agents** and **solo developers** running **multiple agent sessions** — emphasizing MCP-first usage, multi-process safety (locks, shared storage), and reframing git-derived “ownership” / “reviewer” tools as audit/heuristic signals rather than team workflows. Updated ecosystem and coupling copy to center import-graph and structured tool results.
11+
12+
### Follow-up
13+
Aligned **`wiki-local/spec-project.md`** (tool specs, 22 tools, import-graph impact, `triage`, locks, `next_steps`, `git_error`) and **`CONTRIBUTING.md`** (agent/solo preamble, architecture table, MCP/tool wiring guidance) to the same positioning.
14+
15+
---
16+
717
## v0.6.2 -- 2026-03-22 -- Scale Validation on Grafana (21k files)
818

919
### Summary

README.md

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
# Chisel
22

3-
Test impact analysis and code intelligence for LLM agents.
3+
Test impact analysis and code intelligence **built for LLM agents** — especially when **several agents or sessions** touch the same repo (solo developer, multi-agent workflow).
44

5-
Chisel maps tests to code, code to git history, and answers: **"what to run, what's risky, who touched it."**
5+
Chisel maps tests to code, code to git history, and answers: **what to run, whats risky, and where attention should go** — including blame-based lineage when you need audit context (not “team roster” features).
66

77
![Chisel analyzing a real project — risk map, churn, ownership, test gaps, and agent interpretation](docs/chisel-demo.png)
88

9+
## Who this is for
10+
11+
- **Solo developers** using Cursor, Claude Code, or other MCP clients — not a substitute for human code review queues.
12+
- **Multi-agent usage**: parallel agent runs, background tasks, or sequential sessions that share one project. Chisel keeps **one consistent graph** (project-local `.chisel/` storage, cross-process locks) so agents don’t corrupt analysis mid-write.
13+
- **Primary interface**: MCP tools and structured responses (`next_steps`, diagnostic statuses), not dashboards for managers.
14+
915
## The Problem
1016

1117
An LLM agent changes `engine.py:store_document()`. It then either:
1218
- Runs **all** 287 tests (slow, wasteful), or
1319
- Guesses with `-k "test_store"` (misses regressions)
1420

15-
When multiple agents (or agents + humans) work on the same codebase, changes in one area silently break another. Chisel gives agents the intelligence to understand the blast radius of their changes before they commit.
21+
When **multiple agent runs** (or agents plus you) work on the same codebase, changes in one area can break another. Chisel gives each agent **test impact, import-aware suggestions, and risk signals** so they narrow what to run and where regressions may hide — before you merge or ship.
1622

1723
## Install
1824

@@ -51,7 +57,7 @@ Or run the HTTP server for any MCP-compatible client:
5157
chisel serve --port 8377
5258
```
5359

54-
Once connected, Claude Code can use all 15 tools directly`analyze`, `diff_impact`, `suggest_tests`, `risk_map`, and more. Run `analyze` first to build the project graph, then `diff_impact` before each commit to know exactly which tests to run.
60+
Once connected, agents can call the full tool surface`analyze`, `diff_impact`, `suggest_tests`, `risk_map`, `triage`, and more. Run `analyze` first to build the project graph, then `diff_impact` after edits to narrow which tests to run. For long analyses on large repos, prefer `chisel analyze` / `chisel update` in a terminal so MCP clients don’t time out.
5561

5662
## Use with Cursor / Other MCP Clients
5763

@@ -109,25 +115,28 @@ chisel test-gaps
109115
chisel stats
110116
```
111117

112-
## 15 Tools
118+
## MCP tools (core)
119+
120+
Core query and write tools below; the MCP server also exposes **advisory file-lock** helpers for multi-process coordination. See `schemas.py` / `chisel serve` for the full list.
113121

114122
| Tool | What it does |
115123
|------|-------------|
116124
| `analyze` | Full project scan — code units, tests, git history, edges |
117125
| `update` | Incremental re-analysis of changed files only |
118126
| `impact` | Which tests cover these files/functions? |
119127
| `diff_impact` | Auto-detect changes from `git diff`, return impacted tests |
120-
| `suggest_tests` | Rank tests by relevance + historical failure rate |
128+
| `suggest_tests` | Rank tests by relevance (edges, co-change, import graph) + failure rate |
121129
| `churn` | How often does this file/function change? |
122-
| `ownership` | Who wrote this code? (blame-based) |
123-
| `who_reviews` | Who maintains this code? (commit-activity-based) |
124-
| `coupling` | What files always change together? |
130+
| `ownership` | Blame-based authors (useful for audit / “who wrote this line”) |
131+
| `who_reviews` | Recent commit activity on the file (heuristic “hot spots”, not org chart) |
132+
| `coupling` | Co-change partners + **import-graph** neighbors and numeric scores |
125133
| `risk_map` | Risk scores for all files (churn + coupling + coverage gaps) |
126134
| `stale_tests` | Tests pointing at code that no longer exists |
127135
| `test_gaps` | Code units with zero test coverage, sorted by risk |
128136
| `history` | Commit history for a specific file |
129137
| `record_result` | Record test pass/fail for future prioritization |
130138
| `stats` | Database summary counts |
139+
| `triage` | Composite: top risk + gaps + stale tests in one call |
131140

132141
## Features
133142

@@ -142,19 +151,19 @@ chisel stats
142151

143152
## Ecosystem
144153

145-
Chisel works standalone or alongside [Stele](https://github.com/IronAdamant/Stele) for multi-agent code coordination. Chisel handles test intelligence; Stele handles document-level context and conflict prevention.
154+
Chisel is designed to sit **in the agent loop** (MCP): impact → tests → record results → refresh analysis. It works standalone or alongside tools like [Stele](https://github.com/IronAdamant/Stele) for semantic code context — Chisel stays focused on **test graph, git signals, and static imports** for blast-radius reasoning.
146155

147156
## Design Notes
148157

149158
### Coupling: co-change vs. import-graph
150159

151-
Chisel's `coupling` tool has two coupling sources:
160+
Chisel's `coupling` tool exposes two coupling sources:
152161

153-
1. **Co-change coupling** (`co_change_partners`) — files that frequently appear in the same git commits. This signal requires **multiple agents or multiple human collaborators** making separate commits. In solo-agent workflows, there is no co-change signal and this returns 0.0.
162+
1. **Co-change coupling** (`co_change_partners`) — files that often appear in the same git commits. Stronger when **history has many small commits** (including a solo dev committing often, or multiple agents landing separate commits). Sparse history → thin co-change signal.
154163

155-
2. **Import-graph coupling** (`import_partners`) — static `import`/`require` edges between source files. This works in any project and provides structural coupling data even when co-change is absent.
164+
2. **Import-graph coupling** (`import_partners`, plus numeric `import_coupling` / `effective_coupling`) — static `import`/`require` edges. **Always available** after analysis and is the main structural signal for single-author repos.
156165

157-
When co-change is 0.0, import coupling still provides meaningful structural data. The `risk_map` tool uses the maximum of the two coupling sources.
166+
`risk_map` and impact tools combine both; import graph also powers **transitive test suggestions** (e.g. facade tests covering inner modules).
158167

159168
### Coverage Gap: Graduated Scoring
160169

0 commit comments

Comments
 (0)