purecontext-mcp 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENT_INSTRUCTIONS.md +509 -0
- package/AGENT_INSTRUCTIONS_SHORT.md +97 -0
- package/CHANGELOG.md +212 -0
- package/docs/01-introduction.md +69 -0
- package/docs/02-installation.md +267 -0
- package/docs/03-quick-start.md +135 -0
- package/docs/04-configuration.md +214 -0
- package/docs/05-cli-reference.md +130 -0
- package/docs/06-tools-reference.md +499 -0
- package/docs/07-language-support.md +88 -0
- package/docs/08-framework-adapters.md +324 -0
- package/docs/09-dependency-graph.md +182 -0
- package/docs/10-semantic-search.md +153 -0
- package/docs/11-search-quality.md +110 -0
- package/docs/12-ai-summarization.md +106 -0
- package/docs/13-token-savings.md +110 -0
- package/docs/14-transport-modes.md +167 -0
- package/docs/15-team-setup.md +251 -0
- package/docs/16-docker.md +186 -0
- package/docs/17-web-ui.md +157 -0
- package/docs/18-git-history.md +157 -0
- package/docs/19-cross-repo.md +177 -0
- package/docs/20-architecture-analysis.md +228 -0
- package/docs/21-ecosystem-tools.md +189 -0
- package/docs/22-distribution.md +240 -0
- package/docs/23-performance.md +121 -0
- package/docs/24-security.md +144 -0
- package/docs/25-architecture-overview.md +240 -0
- package/docs/26-troubleshooting.md +234 -0
- package/docs/27-api-stability.md +114 -0
- package/docs/README.md +71 -0
- package/guide/README.md +57 -0
- package/guide/ai-summaries.md +127 -0
- package/guide/code-health.md +190 -0
- package/guide/code-history.md +149 -0
- package/guide/finding-code.md +157 -0
- package/guide/navigating-new-code.md +121 -0
- package/guide/safe-changes.md +156 -0
- package/guide/team-setup.md +191 -0
- package/guide/web-ui.md +154 -0
- package/guide/why-purecontext.md +73 -0
- package/guide/workflow-onboarding.md +114 -0
- package/guide/workflow-pr-review.md +199 -0
- package/guide/workflow-refactoring.md +172 -0
- package/package.json +9 -2
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# Git & History Integration
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
Git integration gives agents and the Web UI access to symbol-level history, diff analysis, and churn metrics — without requiring agents to run git commands themselves.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## How it works
|
|
9
|
+
|
|
10
|
+
During indexing, PureContext walks `git log` and maps commits to symbols using byte-range overlap:
|
|
11
|
+
|
|
12
|
+
1. For each commit, `git diff` is parsed to identify changed byte ranges per file
|
|
13
|
+
2. These ranges are matched against indexed symbol byte offsets
|
|
14
|
+
3. The mapping is stored in the `git_metadata` table in SQLite
|
|
15
|
+
|
|
16
|
+
This means you can ask "which commits touched `authenticateUser`?" and get an answer from the index — no git subprocess needed at query time.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Requirements
|
|
21
|
+
|
|
22
|
+
- `git` must be on PATH
|
|
23
|
+
- The indexed project must be a git repository
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Configuration
|
|
28
|
+
|
|
29
|
+
```json
|
|
30
|
+
{
|
|
31
|
+
"git": {
|
|
32
|
+
"enabled": true,
|
|
33
|
+
"maxCommits": 500,
|
|
34
|
+
"includeMergeCommits": false,
|
|
35
|
+
"branches": ["main", "develop"]
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
| Field | Default | Description |
|
|
41
|
+
|-------|---------|-------------|
|
|
42
|
+
| `git.enabled` | `true` | Enable git metadata indexing (if repo is a git repo) |
|
|
43
|
+
| `git.maxCommits` | `500` | Maximum commits to walk back from HEAD |
|
|
44
|
+
| `git.includeMergeCommits` | `false` | Include merge commits (usually noise) |
|
|
45
|
+
| `git.branches` | `["main"]` | Branches to index history from |
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## `get_symbol_history`
|
|
50
|
+
|
|
51
|
+
Symbol-level git history: which commits touched a symbol, and how.
|
|
52
|
+
|
|
53
|
+
**Parameters:**
|
|
54
|
+
|
|
55
|
+
| Parameter | Type | Default | Description |
|
|
56
|
+
|-----------|------|---------|-------------|
|
|
57
|
+
| `repoId` | `string` | required | Target repository |
|
|
58
|
+
| `symbolId` | `string` | required | Symbol to query |
|
|
59
|
+
| `limit` | `number` | `20` | Max commits to return |
|
|
60
|
+
|
|
61
|
+
**Response:**
|
|
62
|
+
|
|
63
|
+
```json
|
|
64
|
+
{
|
|
65
|
+
"symbol": {
|
|
66
|
+
"name": "authenticateUser",
|
|
67
|
+
"filePath": "src/auth/validator.ts"
|
|
68
|
+
},
|
|
69
|
+
"history": [
|
|
70
|
+
{
|
|
71
|
+
"hash": "a1b2c3d4",
|
|
72
|
+
"author": "alice",
|
|
73
|
+
"date": "2026-04-15T10:30:00Z",
|
|
74
|
+
"message": "Add MFA support to authenticateUser",
|
|
75
|
+
"diff": "@@ -12,6 +12,14 @@ ...",
|
|
76
|
+
"linesAdded": 14,
|
|
77
|
+
"linesRemoved": 3
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**Use cases:**
|
|
84
|
+
- "When was this function last changed?"
|
|
85
|
+
- "Who introduced this code?"
|
|
86
|
+
- "What changed in this function over the last month?"
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## `get_churn_metrics`
|
|
91
|
+
|
|
92
|
+
File and symbol churn metrics — how often things change.
|
|
93
|
+
|
|
94
|
+
**Parameters:**
|
|
95
|
+
|
|
96
|
+
| Parameter | Type | Default | Description |
|
|
97
|
+
|-----------|------|---------|-------------|
|
|
98
|
+
| `repoId` | `string` | required | Target repository |
|
|
99
|
+
| `filePath` | `string` | — | Scope to one file (optional) |
|
|
100
|
+
| `since` | `string` | — | ISO 8601 date — look back from this date |
|
|
101
|
+
|
|
102
|
+
**Response:**
|
|
103
|
+
|
|
104
|
+
```json
|
|
105
|
+
{
|
|
106
|
+
"files": [
|
|
107
|
+
{
|
|
108
|
+
"filePath": "src/auth/validator.ts",
|
|
109
|
+
"commits": 47,
|
|
110
|
+
"linesChanged": 820,
|
|
111
|
+
"authors": ["alice", "bob", "charlie"],
|
|
112
|
+
"churnScore": 8.4,
|
|
113
|
+
"lastChanged": "2026-04-20T14:00:00Z"
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**Interpreting `churnScore`:** Normalized metric (0–10+). High churn (> 6) indicates either: active development, frequent bug fixes, or instability. Use alongside quality metrics to distinguish "active feature" from "unstable code".
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## PR / diff analysis
|
|
124
|
+
|
|
125
|
+
Analyze what a branch or commit range changes at the symbol level:
|
|
126
|
+
|
|
127
|
+
**Parameters:**
|
|
128
|
+
|
|
129
|
+
| Parameter | Type | Description |
|
|
130
|
+
|-----------|------|-------------|
|
|
131
|
+
| `repoId` | `string` | Target repository |
|
|
132
|
+
| `base` | `string` | Base branch or commit hash |
|
|
133
|
+
| `head` | `string` | Head branch or commit hash |
|
|
134
|
+
|
|
135
|
+
**Response:** Symbols added, modified, deleted; blast radius of changed symbols.
|
|
136
|
+
|
|
137
|
+
**Use case:** Before reviewing a PR, call this to understand the symbol-level impact — not just which files changed, but which functions were modified and what else might be affected.
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## Git history in the Web UI
|
|
142
|
+
|
|
143
|
+
When git integration is enabled:
|
|
144
|
+
|
|
145
|
+
- **Heatmap overlay** in the file tree shows churn data
|
|
146
|
+
- **Symbol timeline** shows per-symbol history as a visual timeline
|
|
147
|
+
- High-churn files appear in a "Hot files" panel in the dashboard
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## Limitations
|
|
152
|
+
|
|
153
|
+
- History is indexed up to `git.maxCommits` — commits older than that are not tracked
|
|
154
|
+
- **Renames/moves:** git rename detection is best-effort. Symbols in renamed files start fresh history from the rename commit
|
|
155
|
+
- **Merge commits:** excluded by default to avoid noise from merge-only diffs
|
|
156
|
+
- **Rebased history:** rebase changes commit hashes — a re-index is needed to pick up rebased history accurately
|
|
157
|
+
- Git submodules are not indexed
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# Cross-Repo Intelligence
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
Cross-repo tools let agents search across multiple indexed repositories simultaneously and find semantically similar code regardless of which repo it lives in.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
When multiple repos are indexed (e.g., a microservices ecosystem or a monorepo with sub-projects), cross-repo tools provide a unified view. No special configuration is needed — all repos indexed in the same workspace are automatically eligible for cross-repo search.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## `search_cross_repo`
|
|
15
|
+
|
|
16
|
+
Search symbols across multiple repos with a single query.
|
|
17
|
+
|
|
18
|
+
**Parameters:**
|
|
19
|
+
|
|
20
|
+
| Parameter | Type | Default | Description |
|
|
21
|
+
|-----------|------|---------|-------------|
|
|
22
|
+
| `query` | `string` | required | Name fragment or natural language |
|
|
23
|
+
| `repoIds` | `string[]` | — | Repos to search. Omit to search all repos in workspace. |
|
|
24
|
+
| `kind` | `string` | — | Symbol kind filter |
|
|
25
|
+
| `limit` | `number` | `20` | Max results |
|
|
26
|
+
| `mode` | `string` | `"keyword"` | `"keyword"`, `"semantic"`, or `"hybrid"` |
|
|
27
|
+
|
|
28
|
+
**Response:**
|
|
29
|
+
|
|
30
|
+
```json
|
|
31
|
+
{
|
|
32
|
+
"symbols": [
|
|
33
|
+
{
|
|
34
|
+
"id": "abc123",
|
|
35
|
+
"name": "authenticate",
|
|
36
|
+
"kind": "function",
|
|
37
|
+
"filePath": "src/auth/user.ts",
|
|
38
|
+
"repoId": "a1b2c3d4",
|
|
39
|
+
"repoPath": "/projects/user-service",
|
|
40
|
+
"signature": "function authenticate(token: string): Promise<User>",
|
|
41
|
+
"summary": "Validates JWT token and returns authenticated user."
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"id": "def456",
|
|
45
|
+
"name": "authenticate",
|
|
46
|
+
"kind": "method",
|
|
47
|
+
"filePath": "app/services/auth_service.rb",
|
|
48
|
+
"repoId": "e5f6a7b8",
|
|
49
|
+
"repoPath": "/projects/api-gateway",
|
|
50
|
+
"signature": "def authenticate(credentials)",
|
|
51
|
+
"summary": "Rails service method for credential validation."
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Use cases:**
|
|
58
|
+
- "Find all `authenticate` functions across my microservices"
|
|
59
|
+
- "Which services have a `sendEmail` function?"
|
|
60
|
+
- "Where is the `UserProfile` type defined across all repos?"
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## `find_similar`
|
|
65
|
+
|
|
66
|
+
Find semantically similar code across repos — detect duplication, discover existing implementations, find patterns.
|
|
67
|
+
|
|
68
|
+
**Parameters:**
|
|
69
|
+
|
|
70
|
+
| Parameter | Type | Default | Description |
|
|
71
|
+
|-----------|------|---------|-------------|
|
|
72
|
+
| `symbolId` | `string` | required | Reference symbol |
|
|
73
|
+
| `repoId` | `string` | required | Repo of the reference symbol |
|
|
74
|
+
| `searchRepoIds` | `string[]` | — | Repos to search (default: all) |
|
|
75
|
+
| `minSimilarity` | `number` | `0.8` | Minimum cosine similarity (0–1) |
|
|
76
|
+
| `limit` | `number` | `10` | Max results |
|
|
77
|
+
|
|
78
|
+
**Response:**
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
{
|
|
82
|
+
"reference": {
|
|
83
|
+
"name": "formatCurrency",
|
|
84
|
+
"repoId": "a1b2c3d4",
|
|
85
|
+
"filePath": "src/utils/format.ts"
|
|
86
|
+
},
|
|
87
|
+
"similar": [
|
|
88
|
+
{
|
|
89
|
+
"id": "xyz789",
|
|
90
|
+
"name": "formatMoney",
|
|
91
|
+
"repoId": "e5f6a7b8",
|
|
92
|
+
"repoPath": "/projects/billing-service",
|
|
93
|
+
"filePath": "lib/helpers/currency.rb",
|
|
94
|
+
"similarity": 0.94,
|
|
95
|
+
"summary": "Formats a decimal value as a localized currency string."
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Requires:** Semantic search enabled in config (`semantic.enabled: true` with a provider configured).
|
|
102
|
+
|
|
103
|
+
**Use cases:**
|
|
104
|
+
- "Is there already a `formatCurrency` function somewhere in our codebase before I write a new one?"
|
|
105
|
+
- "Find all copy-pasted validation logic across repos"
|
|
106
|
+
- "Discover shared utilities that should be extracted into a common library"
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## Cross-repo dependency tracking
|
|
111
|
+
|
|
112
|
+
Track import relationships that cross repo boundaries. For example, in a monorepo or workspace where packages import each other.
|
|
113
|
+
|
|
114
|
+
Configure cross-repo dependencies in each project's `.purecontext.json`:
|
|
115
|
+
|
|
116
|
+
```json
|
|
117
|
+
{
|
|
118
|
+
"crossRepoDeps": ["@myorg/shared-utils", "@myorg/api-client"]
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
When these packages are also indexed repos, `get_blast_radius` with `crossRepo: true` will follow the dependency chain across repo boundaries.
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## MCP Resources
|
|
127
|
+
|
|
128
|
+
In addition to MCP Tools, PureContext exposes **MCP Resources** — a push-based subscription model where agents can subscribe to symbol content and receive updates when it changes.
|
|
129
|
+
|
|
130
|
+
### Resource URI format
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
purecontext://repo/{repoId}/symbol/{symbolId}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Using MCP Resources
|
|
137
|
+
|
|
138
|
+
List available resources:
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
GET purecontext://repo/{repoId}/symbols
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Subscribe to a resource (supported by MCP clients that implement `resources/subscribe`):
|
|
145
|
+
|
|
146
|
+
```json
|
|
147
|
+
{
|
|
148
|
+
"method": "resources/subscribe",
|
|
149
|
+
"params": {
|
|
150
|
+
"uri": "purecontext://repo/a1b2c3d4/symbol/8f3a2c1d"
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
The server sends a `resources/updated` notification whenever the symbol's source changes (detected by the file watcher).
|
|
156
|
+
|
|
157
|
+
### Use cases for MCP Resources
|
|
158
|
+
|
|
159
|
+
- Agents that monitor a critical function and react when it changes
|
|
160
|
+
- Live documentation tools that stay in sync with the code
|
|
161
|
+
- CI integrations that trigger when specific symbols are modified
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## Setting up cross-repo search
|
|
166
|
+
|
|
167
|
+
No special setup is required. Index each repo independently:
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
index_folder("/projects/user-service")
|
|
171
|
+
index_folder("/projects/billing-service")
|
|
172
|
+
index_folder("/projects/api-gateway")
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Then use `search_cross_repo` or `find_similar` — they automatically search all indexed repos in the workspace.
|
|
176
|
+
|
|
177
|
+
To restrict search to specific repos, pass their `repoIds` explicitly.
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# AI-Powered Architecture Analysis
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
Architecture analysis tools use the symbol graph and AI to surface quality metrics, detect anti-patterns, and generate documentation automatically.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## `get_quality_metrics`
|
|
9
|
+
|
|
10
|
+
Per-file and per-symbol quality scores based on static analysis of the dependency graph and symbol data.
|
|
11
|
+
|
|
12
|
+
**Parameters:** `{ repoId, filePath? }`
|
|
13
|
+
|
|
14
|
+
**Response:**
|
|
15
|
+
|
|
16
|
+
```json
|
|
17
|
+
{
|
|
18
|
+
"files": [
|
|
19
|
+
{
|
|
20
|
+
"filePath": "src/auth/validator.ts",
|
|
21
|
+
"complexity": 6.2,
|
|
22
|
+
"coupling": {
|
|
23
|
+
"fanIn": 14,
|
|
24
|
+
"fanOut": 8
|
|
25
|
+
},
|
|
26
|
+
"cohesion": 0.71,
|
|
27
|
+
"docCoverage": 0.85,
|
|
28
|
+
"score": 72
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
"summary": {
|
|
32
|
+
"averageScore": 68,
|
|
33
|
+
"worstFiles": ["src/legacy/processor.ts"],
|
|
34
|
+
"bestFiles": ["src/utils/format.ts"]
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**Metrics explained:**
|
|
40
|
+
|
|
41
|
+
| Metric | Meaning | Good range |
|
|
42
|
+
|--------|---------|-----------|
|
|
43
|
+
| `complexity` | Average cyclomatic complexity per function | < 5 |
|
|
44
|
+
| `coupling.fanIn` | Files that import this file | depends on role |
|
|
45
|
+
| `coupling.fanOut` | Files this file imports | < 10 |
|
|
46
|
+
| `cohesion` | How related the symbols in a file are (0–1) | > 0.6 |
|
|
47
|
+
| `docCoverage` | % of exported symbols with non-empty summaries | > 0.8 |
|
|
48
|
+
| `score` | Composite quality score (0–100) | > 70 |
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## `detect_antipatterns`
|
|
53
|
+
|
|
54
|
+
Scan a repo for common architectural anti-patterns.
|
|
55
|
+
|
|
56
|
+
**Parameters:**
|
|
57
|
+
|
|
58
|
+
| Parameter | Type | Default | Description |
|
|
59
|
+
|-----------|------|---------|-------------|
|
|
60
|
+
| `repoId` | `string` | required | Target repository |
|
|
61
|
+
| `patterns` | `string[]` | all | Specific patterns to check. Omit for all. |
|
|
62
|
+
|
|
63
|
+
**Available patterns:**
|
|
64
|
+
|
|
65
|
+
| Pattern | Description |
|
|
66
|
+
|---------|-------------|
|
|
67
|
+
| `god-class` | Class with > 20 methods or > 15 imports |
|
|
68
|
+
| `god-function` | Function with cyclomatic complexity > 15 |
|
|
69
|
+
| `high-coupling` | File with fan-out > 20 |
|
|
70
|
+
| `circular-deps` | Import cycles (A→B→C→A) |
|
|
71
|
+
| `dead-code` | Exported symbols with no importers |
|
|
72
|
+
| `missing-docs` | Exported symbols without summaries |
|
|
73
|
+
| `inconsistent-naming` | Mixed camelCase/snake_case in a single file |
|
|
74
|
+
| `deep-nesting` | Functions with nesting depth > 5 |
|
|
75
|
+
|
|
76
|
+
**Response:**
|
|
77
|
+
|
|
78
|
+
```json
|
|
79
|
+
{
|
|
80
|
+
"issues": [
|
|
81
|
+
{
|
|
82
|
+
"pattern": "god-class",
|
|
83
|
+
"filePath": "src/legacy/UserManager.ts",
|
|
84
|
+
"symbolId": "abc123",
|
|
85
|
+
"symbolName": "UserManager",
|
|
86
|
+
"severity": "warning",
|
|
87
|
+
"description": "UserManager has 34 methods. Consider splitting into smaller, focused classes.",
|
|
88
|
+
"metrics": { "methodCount": 34 }
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"pattern": "circular-deps",
|
|
92
|
+
"filePath": "src/core/index.ts",
|
|
93
|
+
"severity": "error",
|
|
94
|
+
"description": "Circular dependency: src/core/index.ts → src/utils/helpers.ts → src/core/index.ts",
|
|
95
|
+
"cycle": ["src/core/index.ts", "src/utils/helpers.ts"]
|
|
96
|
+
}
|
|
97
|
+
],
|
|
98
|
+
"summary": {
|
|
99
|
+
"total": 12,
|
|
100
|
+
"errors": 2,
|
|
101
|
+
"warnings": 10
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## `get_architecture_doc`
|
|
109
|
+
|
|
110
|
+
Auto-generate an architecture summary for the repo — useful for onboarding, design reviews, or keeping architecture documentation current.
|
|
111
|
+
|
|
112
|
+
**Parameters:**
|
|
113
|
+
|
|
114
|
+
| Parameter | Type | Default | Description |
|
|
115
|
+
|-----------|------|---------|-------------|
|
|
116
|
+
| `repoId` | `string` | required | Target repository |
|
|
117
|
+
| `format` | `string` | `"markdown"` | `"markdown"` or `"mermaid"` |
|
|
118
|
+
|
|
119
|
+
**Response (markdown):**
|
|
120
|
+
|
|
121
|
+
```json
|
|
122
|
+
{
|
|
123
|
+
"doc": "# Architecture Overview\n\n## Entry Points\n...\n## Module Structure\n...\n## Key Dependencies\n..."
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
**Response (mermaid):**
|
|
128
|
+
|
|
129
|
+
```json
|
|
130
|
+
{
|
|
131
|
+
"doc": "graph TD\n A[src/index.ts] --> B[src/core/]\n B --> C[src/handlers/]\n..."
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
The generated document includes:
|
|
136
|
+
- Top-level entry points
|
|
137
|
+
- Module/layer breakdown
|
|
138
|
+
- Key external dependencies
|
|
139
|
+
- Framework adapters detected
|
|
140
|
+
- High-level data flow
|
|
141
|
+
|
|
142
|
+
This uses AI (the configured `ai.provider`) to summarize the graph structure into natural language. Requires `ai.allowRemoteAI: true`.
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## Refactoring detector
|
|
147
|
+
|
|
148
|
+
Identify candidates for refactoring based on size, coupling, and duplication.
|
|
149
|
+
|
|
150
|
+
**Parameters:** `{ repoId }`
|
|
151
|
+
|
|
152
|
+
**Response:**
|
|
153
|
+
|
|
154
|
+
```json
|
|
155
|
+
{
|
|
156
|
+
"candidates": [
|
|
157
|
+
{
|
|
158
|
+
"type": "extract-function",
|
|
159
|
+
"filePath": "src/auth/processor.ts",
|
|
160
|
+
"symbolId": "abc123",
|
|
161
|
+
"symbolName": "processAuthRequest",
|
|
162
|
+
"reason": "Function has 120 lines and cyclomatic complexity of 18. Consider extracting validation and transformation logic.",
|
|
163
|
+
"priority": "high"
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
"type": "extract-module",
|
|
167
|
+
"filePath": "src/utils/helpers.ts",
|
|
168
|
+
"reason": "File contains 45 symbols across 8 unrelated concerns. Consider splitting by domain.",
|
|
169
|
+
"priority": "medium"
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
"type": "deduplicate",
|
|
173
|
+
"symbols": [
|
|
174
|
+
{ "repoId": "a1b2c3d4", "symbolId": "def456", "name": "formatDate" },
|
|
175
|
+
{ "repoId": "a1b2c3d4", "symbolId": "ghi789", "name": "formatDateLegacy" }
|
|
176
|
+
],
|
|
177
|
+
"similarity": 0.96,
|
|
178
|
+
"reason": "These two functions are 96% similar. Consider merging.",
|
|
179
|
+
"priority": "low"
|
|
180
|
+
}
|
|
181
|
+
]
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## Smart context bundling
|
|
188
|
+
|
|
189
|
+
An AI-powered enhancement of `get_context_bundle` that uses quality metrics and churn data to prioritize what context to include within a token budget.
|
|
190
|
+
|
|
191
|
+
**Parameters:**
|
|
192
|
+
|
|
193
|
+
| Parameter | Type | Default | Description |
|
|
194
|
+
|-----------|------|---------|-------------|
|
|
195
|
+
| `repoId` | `string` | required | Target repository |
|
|
196
|
+
| `symbolId` | `string` | required | Starting symbol |
|
|
197
|
+
| `maxTokens` | `number` | `4000` | Token budget |
|
|
198
|
+
| `strategy` | `string` | `"balanced"` | `"quality"`, `"churn"`, or `"balanced"` |
|
|
199
|
+
|
|
200
|
+
Strategies:
|
|
201
|
+
- **`quality`** — prioritize high-quality, well-documented dependencies
|
|
202
|
+
- **`churn`** — prioritize recently changed dependencies (likely most relevant)
|
|
203
|
+
- **`balanced`** — weighted combination of both
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## Using analysis tools together
|
|
208
|
+
|
|
209
|
+
A pre-refactoring workflow:
|
|
210
|
+
|
|
211
|
+
```
|
|
212
|
+
1. get_quality_metrics(repoId)
|
|
213
|
+
→ Find the lowest-scoring files
|
|
214
|
+
|
|
215
|
+
2. detect_antipatterns(repoId, patterns: ["god-class", "circular-deps"])
|
|
216
|
+
→ Find structural issues in those files
|
|
217
|
+
|
|
218
|
+
3. get_blast_radius(symbolId)
|
|
219
|
+
→ Understand the impact scope before changing a god class
|
|
220
|
+
|
|
221
|
+
4. get_architecture_doc(repoId, format: "mermaid")
|
|
222
|
+
→ Generate a before-picture for the design doc
|
|
223
|
+
|
|
224
|
+
5. (make the refactoring)
|
|
225
|
+
|
|
226
|
+
6. detect_antipatterns(repoId)
|
|
227
|
+
→ Verify the anti-patterns were resolved
|
|
228
|
+
```
|