Skip to content

Commit 60b5f18

Browse files
committed
Updating docs for new --explain feature
1 parent 9791ea6 commit 60b5f18

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

ARCHITECTURE.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ Stage by stage:
137137

138138
Three plugin roles drive the middle of the pipeline — **extractors** (source → facts), **explainers** (facts → insights), and **renderers** (snapshot → artifacts). Each is a small Go interface with a registry, so adding a language or an analysis is a self-contained addition rather than a change to the engine.
139139

140+
**One-shot explain mode.** `enola --explain [repo_path]` is an alternative exit path through the pipeline: stages 1–6 run normally, but instead of proceeding to stage 7 (Renderer) and stage 8 (Artifacts), `pkg/explain.Compute()` reads the fact store, produces a `Report` struct, and `report.Render()` prints a human-readable statistical summary to stdout. No artifacts are written; `.enola/` is not touched. See [The explain package (`pkg/explain`)](#the-explain-package-pkgexplain) below.
141+
140142
---
141143

142144
## Insights (explainers)
@@ -149,6 +151,36 @@ Explainers turn raw facts into architectural observations. Each insight carries
149151

150152
---
151153

154+
## The explain package (`pkg/explain`)
155+
156+
`pkg/explain` ([`pkg/explain/explain.go`](pkg/explain/explain.go)) is a **public** package rather than `internal/` for one reason: `enola-enterprise` imports it to append its own license-gated sections (dead code, package metrics) to the base `Report` before rendering. It is the only package in the OSS codebase with that cross-module consumer.
157+
158+
### `Report` and `Compute()`
159+
160+
`Compute(eng *bootstrap.Engine) *Report` reads the engine's current fact store and snapshot — it does not generate a snapshot; callers do that first. The fields it populates map directly to the seven output sections:
161+
162+
| Report field(s) | Output section |
163+
|---|---|
164+
| `RepoPath`, `GeneratedAt`, `Duration`, `Extractors`, `TotalFacts` | Overview |
165+
| `KindCounts` | Architectural kinds |
166+
| `SymbolKinds` | Symbol breakdown |
167+
| `Routes`, `RoutesByMethod`, `Storage` | API & data surface |
168+
| `DepSources` | Dependencies |
169+
| `Architecture`, `ArchConfidence`, `Cycles`, `LayerViolations`, `CrossRepoEdges` | Architecture |
170+
| `Modules`, `HighCriticality`, `MediumCriticality`, `Hotspots`, `CouplingUnresolved` | Impact analysis (hotspots) |
171+
172+
`CouplingUnresolved` is a special flag: it is set when dependency facts exist but no import edge resolved to a module, meaning coupling analysis is unavailable rather than genuinely zero. The renderer surfaces this as an explanatory note instead of implying the codebase has no coupling.
173+
174+
### Extensibility via `ExtraSections`
175+
176+
`Report.ExtraSections []Section` is the extension point for enterprise code. After calling `Compute()`, enterprise calls `report.AddSection(title, body)` (or directly appends `explain.Section{...}`) and then calls `report.Render()`. The renderer appends the extra sections after the seven base sections, using the same plain-text format. This design means `enola-enterprise` only depends on the exported `pkg/explain` surface and never needs to import `internal/facts` or `internal/engine` directly.
177+
178+
### Output format
179+
180+
`Render()` produces plain aligned text (not Markdown), designed to read well in a terminal without paging. Sections are separated by `` rule lines (60 characters). Key-value pairs use `fmt.Fprintf` with a 20-character label width; tables (hotspots) use fixed-width column formats. No color codes — output is safe to pipe or capture in CI.
181+
182+
---
183+
152184
## The tools
153185

154186
enola is a stdio [MCP](https://modelcontextprotocol.io/) server. It exposes **seven tools** and no MCP resources — everything flows through tool calls. The tools defined in [`internal/server/server.go`](internal/server/server.go) are listed below, each leading with the question it answers.

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,38 @@ Artifacts are written to the configured `output.dir` (default `.enola/`). Config
186186

187187
---
188188

189+
## Explain a repository at a glance
190+
191+
`enola --explain [repo_path]` is a one-shot mode that generates a snapshot, computes statistics over the fact graph, and prints a human-readable report to stdout — no MCP server started, no artifacts written to `.enola/`.
192+
193+
**When to use it:**
194+
- New contributor getting a first orientation — module count, architecture pattern, hottest packages.
195+
- Pre-refactor sanity check — cycles, layer violations, blast radius of top modules.
196+
- Quick audit without spinning up an AI agent.
197+
198+
```bash
199+
# Use the config in the current directory (mcp-arch.yaml)
200+
enola --explain
201+
202+
# Analyze a specific repository path
203+
enola --explain /path/to/repo
204+
```
205+
206+
**The report covers seven sections:**
207+
- **Overview** — path, analysis time, active languages, total fact count
208+
- **Architectural kinds** — counts of modules, symbols, routes, storage, dependencies, services
209+
- **Symbol breakdown** — functions, methods, structs, interfaces, and other kinds
210+
- **API & data surface** — route count broken down by HTTP method, plus storage count
211+
- **Dependencies** — external, internal, and stdlib import counts
212+
- **Architecture** — detected pattern with confidence, cyclic dependencies, layer violations, cross-repo edges
213+
- **Impact analysis (hotspots)** — top modules ranked by fan-in + fan-out coupling, with criticality tier and blast radius
214+
215+
No artifacts are written; `.enola/` is not touched. For a persistent snapshot with agent-readable output, use `--generate` or the MCP server.
216+
217+
For interactive per-module blast-radius queries with configurable depth, see the `impact_analysis` tool reference in **[ARCHITECTURE.md → The tools](ARCHITECTURE.md#the-tools)**.
218+
219+
---
220+
189221
## Learn more
190222

191223
- **[ARCHITECTURE.md](ARCHITECTURE.md)** — the concept, the fact model, the pipeline, and the full tool reference.

0 commit comments

Comments
 (0)