scopecairn 0.7.0 → 0.8.0

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/README.md CHANGED
@@ -1,199 +1,204 @@
1
- # ScopeCairn
2
-
3
- Local-first codebase intelligence layer for AI coding agents.
4
- Understand the codebase, then give the agent only what it needs:
5
- a knowledge graph of the repository, the relevant context per task,
6
- change impact analysis, and enforced minimal-work scope.
7
- No MCP server, no embeddings, no network calls, no telemetry.
8
-
9
- > Understand before exploring. Retrieve before reading.
10
-
11
- ## Features
12
-
13
- - **Knowledge graph** — files, symbols (functions, classes, methods,
14
- interfaces, components, routes, models…), and typed relations
15
- (`IMPORTS`, `CALLS`, `EXTENDS`, `TESTS`, `ROUTES_TO`, `QUERIES`…)
16
- in local SQLite, fully deterministic.
17
- - **Graph retrieval, no embeddings** — token-matched seeds → weighted
18
- expansion → 5-signal ranking (seed, proximity, centrality, git
19
- recency, co-change). Weights configurable, calibrated by benchmark.
20
- - **Task scope control** — every complex task returns Required /
21
- Optional / Protected file lists plus Task Guard rules and a
22
- Definition of Done, so the agent changes only what matters.
23
- - **Change impact** — direct, indirect (2-hop), tests, and UI components
24
- affected by a file or symbol.
25
- - **Call path tracing** — `scopecairn path <A> <B>` shows the shortest
26
- multi-hop call/dependency chain between two symbols.
27
- - **Centrality ranking** — weighted PageRank + betweenness cached per
28
- symbol; `context` surfaces critical hotspots, `doctor` flags
29
- single points of failure.
30
- - **Community detection** — Louvain clustering finds real modules by
31
- link density (not just folders); `graph` shows each symbol's community.
32
- - **Cycle detection** — Tarjan SCC finds circular dependencies;
33
- reported by `doctor`, warned in `context`, listed in `GRAPH.md`.
34
- - **Auto-refresh** — `context` and `impact` re-index changed files first;
35
- run `scan` after editing to close the loop.
36
- - **Framework adapters** — Next.js (App + Pages Router routes),
37
- Prisma models, and Drizzle tables/queries detected automatically.
38
- - **Multi-language** — TypeScript, JavaScript, Python, Java, Go, Rust,
39
- PHP, C#, C/C++, Ruby, HTML (plus config/schema files as graph nodes).
40
- - **Multi-agent setup** — skills for Claude Code (plugin + marketplace
41
- ready), Antigravity, Cursor, Windsurf, Copilot, Kiro, and an OpenCode
42
- slash command. ScopeCairn never touches your `AGENTS.md`/`CLAUDE.md` —
43
- those hold your repo's details, not tool instructions.
44
- - **`GRAPH.md` knowledge file** — `.scopecairn/GRAPH.md` is a budgeted
45
- (±150 lines) frozen summary of the graph (modules, most-used symbols,
46
- PageRank hotspots, circular dependencies, routes, models, protected).
47
- Written on setup, rewritten only when the
48
- graph changes — for cold-start orientation; per-task precision still
49
- comes from `context`.
50
- - **`GRAPH.html` visual explorer** — offline, dependency-free Canvas
51
- explorer written next to `GRAPH.md` on every graph change.
52
- Cluster ↔ File ↔ Symbol hierarchy toggle, live search, type filter,
53
- click-for-details side panel (callers, callees, centrality scores).
54
- Nodes sized by symbols/PageRank, colored by Louvain community.
55
- Pan, zoom, hover inspect. Double-click to open, no server.
56
- - **`export` for external tools** — `scopecairn export --format
57
- mermaid|graphml|dot|json` writes `.scopecairn/graph.<ext>` for PR
58
- diagrams (Mermaid), Gephi/Cytoscape (GraphML), Graphviz (DOT),
59
- or custom scripts (JSON).
60
-
61
- ## Install
62
-
63
- ```bash
64
- npm install -g scopecairn
65
- ```
66
-
67
- Requires Node.js ≥ 20.
68
-
69
- Upgrade later with:
70
-
71
- ```bash
72
- scopecairn update # or: npm install -g scopecairn@latest
73
- scopecairn update --check # only check for a new version
74
- ```
75
-
76
- ## Agent-driven setup
77
-
78
- Install once, then just type `scopecairn ./` to your AI agent —
79
- it runs project setup itself.
80
-
81
- 1. Install the skill once (global):
82
- ```bash
83
- npx skills add <github-user>/scopecairn -g
84
- ```
85
- (fallback without a skill: add one line to your global agent
86
- instructions — `~/.claude/CLAUDE.md` or equivalent: *When the user
87
- writes "scopecairn \<path\>", run `scopecairn init \<path\>`.*)
88
- 2. In any project chat, type:
89
- ```
90
- scopecairn ./
91
- ```
92
- The agent runs `scopecairn init ./`, reports files indexed and
93
- integration files written. Approve the terminal command once;
94
- afterwards, add the printed allowlist so later calls need no approval.
95
-
96
- ## Quickstart (manual)
97
-
98
- ```bash
99
- cd your-repo
100
- scopecairn init # index + Antigravity Skill + Workflow
101
- ```
102
-
103
- Claude Code (project skill, committed with the repo):
104
-
105
- ```bash
106
- scopecairn claude install
107
- ```
108
-
109
- Or as a plugin from the bundled marketplace (this repo):
110
-
111
- ```
112
- /plugin marketplace add <github-user>/scopecairn
113
- /plugin install scopecairn@scopecairn
114
- ```
115
-
116
- After setup, your agent calls ScopeCairn automatically on every coding task.
117
- To query manually:
118
-
119
- ```bash
120
- scopecairn context "add approval workflow"
121
- scopecairn context ./ # repository orientation map
122
- scopecairn impact src/request/RequestService.ts
123
- scopecairn read symbol approveRequest
124
- scopecairn graph RequestService
125
- scopecairn path handleLogin dbQuery
126
- scopecairn export --format mermaid
127
- scopecairn doctor
128
- ```
129
-
130
- Per-agent installers (instead of `init --agents …`):
131
-
132
- ```bash
133
- scopecairn antigravity install # Skill + Workflow + allowlist guide
134
- scopecairn claude install # project skill .claude/skills (also: cursor, windsurf, copilot, kiro)
135
- scopecairn opencode install # /scopecairn slash command + permission snippet
136
- scopecairn claude uninstall # clean removal, user content preserved
137
- scopecairn agents list
138
- ```
139
-
140
- ## Commands
141
-
142
- | Command | Description |
143
- |---|---|
144
- | `init [path]` | Initial indexing + Skill, Workflow, detected agent skills (`--agents …\|all`; never writes `AGENTS.md`) |
145
- | `scan` / `rebuild` / `clean` | Manual index management (`scan` incremental; `rebuild` from scratch; `clean` removes `.scopecairn/`) |
146
- | `status` / `doctor` | Index status (incl. adapters, invocations) and health checks |
147
- | `context "<task>"` | Main entry point: context + scope (`--escalate`, `--no-refresh`, `--mode NORMAL|FAST|SAFE|AUDIT`); a path task returns an orientation map |
148
- | `impact <path\|symbol>` | Change impact: direct, indirect, tests, UI, queries, routes |
149
- | `graph <symbol>` | Symbol relations (+ PageRank, community, cycle status) |
150
- | `path <from> <to>` | Shortest multi-hop call/dependency path between two symbols |
151
- | `export --format <fmt>` | Graph export: `mermaid`, `graphml`, `dot`, or `json` (default `.scopecairn/graph.<ext>`, override with `--out`) |
152
- | `read symbol <name>` | Symbol-level source excerpt (not whole files) |
153
- | `<agent> install` | Per-agent setup: `antigravity`, `claude`, `gemini`, `cursor`, `windsurf`, `copilot`, `kiro` (each also `uninstall`; `agents list` to see all) |
154
- | `dashboard` | Generate local HTML dashboard at `.scopecairn/dashboard.html` |
155
- | `test-select <target>` | List test files affected by a file/symbol change target |
156
- | `doctor --verbose` | Also surface adapter/graph errors from `.scopecairn/last-run.log` to stderr |
157
- | `benchmark [--tune]` | Retrieval recall, irrelevant ratio, context reduction + weight calibration |
158
- | `update [--check]` | Update ScopeCairn to the latest npm release (`--check` only checks) |
159
-
160
- Agent commands (`context`, `impact`, `read`, `graph`, `status`, `doctor`)
161
- are read-only toward source and only write to `.scopecairn/` — safe to
162
- allowlist. `init`, `scan`, and `rebuild` are manual/user-side commands.
163
-
164
- ## Framework adapters
165
-
166
- Detected automatically during `scan` (shown in output and `status`).
167
- No configuration needed.
168
-
169
- | Adapter | Detects | Produces |
170
- |---|---|---|
171
- | `nextjs` | `app/`, `pages/`, `next.config.*` | Route symbols (`GET /api/x`, `PAGE /y` incl. route groups, dynamic segments), `ROUTES_TO` handler edges, `QUERIES` handler→model edges |
172
- | `prisma` | `schema.prisma` | `model` symbols for `QUERIES` resolution |
173
- | `drizzle` | `drizzle*` paths/config, `db/` schemas | `model` symbols from `pgTable`/`sqliteTable`/`mysqlTable`; `QUERIES` from `db.query.*` relational and `db.select/insert/update/delete` builder calls |
174
- | `express` | `package.json` deps | Route symbols from `app/router.METHOD(path)`, handler edges |
175
- | `fastapi` | `.py` routes, requirements/pyproject | Route symbols from `@app.METHOD("/path")` decorators |
176
- | `sqlalchemy` | requirements/pyproject | `model` symbols from `class X(Base)`/`__tablename__`; `QUERIES` from `session.query/select` |
177
- | `vue` | `.vue` SFCs, `package.json` deps | `component` symbols per SFC; `IMPORTS` edges from used components in template |
178
-
179
- Limits (honest): non-Prisma/Drizzle/SQLAlchemy ORMs, inter-table
180
- references, raw SQL strings, and fully dynamic table names are not mapped
181
- yet — those edges are skipped (and logged to `.scopecairn/last-run.log`),
182
- never hallucinated. Server Actions (`detectServerActions`) and middleware
183
- (`detectMiddleware`) are detected in `nextjs.ts`. QUERIES re-derive on
184
- every scan so new models resolve without a rebuild.
185
- Contributing a new adapter = one file + one registration line
186
- in `src/adapters/index.ts` (see `FrameworkAdapter` in `src/adapters/types.ts`).
187
-
188
- ## Typical loop
189
-
190
- ```
191
- prompt → scopecairn context (refresh at start) → agent edits code
192
- → scopecairn scan (refresh at end, incremental, ~instant)
193
- ```
194
-
195
- Measure retrieval quality anytime: `scopecairn benchmark [--tune]`.
196
-
197
- ## License
198
-
199
- MIT — see [LICENSE](./LICENSE).
1
+ # ScopeCairn
2
+
3
+ Local-first codebase intelligence layer for AI coding agents.
4
+ Understand the codebase, then give the agent only what it needs:
5
+ a knowledge graph of the repository, the relevant context per task,
6
+ change impact analysis, and enforced minimal-work scope.
7
+ No MCP server, no embeddings, no network calls, no telemetry.
8
+
9
+ > Understand before exploring. Retrieve before reading.
10
+
11
+ ## Features
12
+
13
+ - **Knowledge graph** — files, symbols (functions, classes, methods,
14
+ interfaces, components, routes, models…), and typed relations
15
+ (`IMPORTS`, `CALLS`, `EXTENDS`, `TESTS`, `ROUTES_TO`, `QUERIES`…)
16
+ in local SQLite, fully deterministic. Parsing uses Tree-sitter
17
+ grammars (bundled WASM); schema files without a grammar keep an
18
+ explicit fallback.
19
+ - **Graph retrieval, no embeddings** — token-matched seeds → weighted
20
+ expansion → 5-signal ranking (seed, proximity, centrality, git
21
+ recency, co-change). Weights configurable, calibrated by benchmark.
22
+ - **Task scope control** — every complex task returns Required /
23
+ Optional / Protected file lists plus Task Guard rules and a
24
+ Definition of Done, so the agent changes only what matters.
25
+ - **Change impact** — direct, indirect (2-hop), tests, and UI components
26
+ affected by a file or symbol.
27
+ - **Call path tracing** — `scopecairn path <A> <B>` shows the shortest
28
+ multi-hop call/dependency chain between two symbols.
29
+ - **Centrality ranking** — weighted PageRank + betweenness cached per
30
+ symbol; `context` surfaces critical hotspots, `doctor` flags
31
+ single points of failure.
32
+ - **Community detection** — Louvain clustering finds real modules by
33
+ link density (not just folders); `graph` shows each symbol's community.
34
+ - **Cycle detection** — Tarjan SCC finds circular dependencies;
35
+ reported by `doctor`, warned in `context`, listed in `GRAPH.md`.
36
+ - **Auto-refresh** — `context` and `impact` re-index changed files first;
37
+ run `scan` after editing to close the loop.
38
+ - **Framework adapters** — Next.js (App + Pages Router routes),
39
+ Prisma models, and Drizzle tables/queries detected automatically.
40
+ - **Multi-language** — TypeScript, JavaScript, Python, Java, Go, Rust,
41
+ PHP, C#, C/C++, Ruby, HTML, Vue SFC (plus config/schema files as
42
+ graph nodes).
43
+ - **Multi-agent setup** — skills for Claude Code (plugin + marketplace
44
+ ready), Antigravity, Cursor, Windsurf, Copilot, Kiro, and an OpenCode
45
+ slash command. ScopeCairn never touches your `AGENTS.md`/`CLAUDE.md` —
46
+ those hold your repo's details, not tool instructions.
47
+ - **`GRAPH.md` knowledge file** — `.scopecairn/GRAPH.md` is a budgeted
48
+ (±150 lines) frozen summary of the graph (modules, most-used symbols,
49
+ PageRank hotspots, circular dependencies, routes, models, protected).
50
+ Written on setup, rewritten only when the
51
+ graph changes — for cold-start orientation; per-task precision still
52
+ comes from `context`. `.scopecairn/ARCHAEOLOGY.md` (purely from local
53
+ `git log`: top author, bus factor, churn) is written once; delete it to
54
+ regenerate.
55
+ - **`GRAPH.html` visual explorer** — offline, dependency-free Canvas
56
+ explorer written next to `GRAPH.md` on every graph change.
57
+ Cluster ↔ File ↔ Symbol hierarchy toggle, live search, type filter,
58
+ click-for-details side panel (callers, callees, centrality scores).
59
+ Nodes sized by symbols/PageRank, colored by Louvain community.
60
+ Pan, zoom, hover inspect. Double-click to open, no server.
61
+ - **`export` for external tools** — `scopecairn export --format
62
+ mermaid|graphml|dot|json` writes `.scopecairn/graph.<ext>` for PR
63
+ diagrams (Mermaid), Gephi/Cytoscape (GraphML), Graphviz (DOT),
64
+ or custom scripts (JSON).
65
+
66
+ ## Install
67
+
68
+ ```bash
69
+ npm install -g scopecairn
70
+ ```
71
+
72
+ Requires Node.js ≥ 20.
73
+
74
+ Upgrade later with:
75
+
76
+ ```bash
77
+ scopecairn update # or: npm install -g scopecairn@latest
78
+ scopecairn update --check # only check for a new version
79
+ ```
80
+
81
+ ## Agent-driven setup
82
+
83
+ Install once, then just type `scopecairn ./` to your AI agent —
84
+ it runs project setup itself.
85
+
86
+ 1. Install the skill once (global):
87
+ ```bash
88
+ npx skills add <github-user>/scopecairn -g
89
+ ```
90
+ (fallback without a skill: add one line to your global agent
91
+ instructions — `~/.claude/CLAUDE.md` or equivalent: *When the user
92
+ writes "scopecairn \<path\>", run `scopecairn init \<path\>`.*)
93
+ 2. In any project chat, type:
94
+ ```
95
+ scopecairn ./
96
+ ```
97
+ The agent runs `scopecairn init ./`, reports files indexed and
98
+ integration files written. Approve the terminal command once;
99
+ afterwards, add the printed allowlist so later calls need no approval.
100
+
101
+ ## Quickstart (manual)
102
+
103
+ ```bash
104
+ cd your-repo
105
+ scopecairn init # index + Antigravity Skill + Workflow
106
+ ```
107
+
108
+ Claude Code (project skill, committed with the repo):
109
+
110
+ ```bash
111
+ scopecairn claude install
112
+ ```
113
+
114
+ Or as a plugin from the bundled marketplace (this repo):
115
+
116
+ ```
117
+ /plugin marketplace add <github-user>/scopecairn
118
+ /plugin install scopecairn@scopecairn
119
+ ```
120
+
121
+ After setup, your agent calls ScopeCairn automatically on every coding task.
122
+ To query manually:
123
+
124
+ ```bash
125
+ scopecairn context "add approval workflow"
126
+ scopecairn context ./ # repository orientation map
127
+ scopecairn impact src/request/RequestService.ts
128
+ scopecairn read symbol approveRequest
129
+ scopecairn graph RequestService
130
+ scopecairn path handleLogin dbQuery
131
+ scopecairn export --format mermaid
132
+ scopecairn doctor
133
+ ```
134
+
135
+ Per-agent installers (instead of `init --agents …`):
136
+
137
+ ```bash
138
+ scopecairn antigravity install # Skill + Workflow + allowlist guide
139
+ scopecairn claude install # project skill .claude/skills (also: cursor, windsurf, copilot, kiro)
140
+ scopecairn opencode install # /scopecairn slash command + permission snippet
141
+ scopecairn claude uninstall # clean removal, user content preserved
142
+ scopecairn agents list
143
+ ```
144
+
145
+ ## Commands
146
+
147
+ | Command | Description |
148
+ |---|---|
149
+ | `init [path]` | Initial indexing + Skill, Workflow, detected agent skills (`--agents …\|all`; never writes `AGENTS.md`) |
150
+ | `scan` / `rebuild` / `clean` | Manual index management (`scan` incremental; `rebuild` from scratch; `clean` removes `.scopecairn/`) |
151
+ | `status` / `doctor` | Index status (incl. adapters, invocations) and health checks |
152
+ | `context "<task>"` | Main entry point: context + scope (`--escalate`, `--no-refresh`, `--mode NORMAL|FAST|SAFE|AUDIT`, `--max-tokens N`); a path task returns an orientation map |
153
+ | `impact <path\|symbol>` | Change impact: direct, indirect, tests (via TESTS edges + static CALLS backward reachability), UI, queries, routes. Edge evidence tagged EXTRACTED/INFERRED/AMBIGUOUS |
154
+ | `graph <symbol>` | Symbol relations (+ PageRank, community, cycle status) |
155
+ | `path <from> <to>` | Shortest multi-hop call/dependency path between two symbols |
156
+ | `export --format <fmt>` | Graph export: `mermaid`, `graphml`, `dot`, or `json` (default `.scopecairn/graph.<ext>`, override with `--out`) |
157
+ | `read symbol <name>` | Symbol-level source excerpt (not whole files) |
158
+ | `<agent> install` | Per-agent setup: `antigravity`, `claude`, `gemini`, `cursor`, `windsurf`, `copilot`, `kiro` (each also `uninstall`; `agents list` to see all) |
159
+ | `dashboard` | Generate local HTML dashboard at `.scopecairn/dashboard.html` |
160
+ | `test-select <target>` | List test files affected by a file/symbol change target |
161
+ | `doctor --verbose` | Also surface adapter/graph errors from `.scopecairn/last-run.log` to stderr |
162
+ | `benchmark [--tune]` | Retrieval recall, irrelevant ratio, context reduction + weight calibration |
163
+ | `update [--check]` | Update ScopeCairn to the latest npm release (`--check` only checks) |
164
+
165
+ Agent commands (`context`, `impact`, `read`, `graph`, `status`, `doctor`)
166
+ are read-only toward source and only write to `.scopecairn/` — safe to
167
+ allowlist. `init`, `scan`, and `rebuild` are manual/user-side commands.
168
+
169
+ ## Framework adapters
170
+
171
+ Detected automatically during `scan` (shown in output and `status`).
172
+ No configuration needed.
173
+
174
+ | Adapter | Detects | Produces |
175
+ |---|---|---|
176
+ | `nextjs` | `app/`, `pages/`, `next.config.*` | Route symbols (`GET /api/x`, `PAGE /y` incl. route groups, dynamic segments), `ROUTES_TO` handler edges, `QUERIES` handler→model edges |
177
+ | `prisma` | `schema.prisma` | `model` symbols for `QUERIES` resolution |
178
+ | `drizzle` | `drizzle*` paths/config, `db/` schemas | `model` symbols from `pgTable`/`sqliteTable`/`mysqlTable`; `QUERIES` from `db.query.*` relational and `db.select/insert/update/delete` builder calls |
179
+ | `express` | `package.json` deps | Route symbols from `app/router.METHOD(path)`, handler edges |
180
+ | `fastapi` | `.py` routes, requirements/pyproject | Route symbols from `@app.METHOD("/path")` decorators |
181
+ | `sqlalchemy` | requirements/pyproject | `model` symbols from `class X(Base)`/`__tablename__`; `QUERIES` from `session.query/select` |
182
+ | `vue` | `.vue` SFCs, `package.json` deps | `component` symbols per SFC; `IMPORTS` edges from used components in template |
183
+
184
+ Limits (honest): non-Prisma/Drizzle/SQLAlchemy ORMs, inter-table
185
+ references, raw SQL strings, and fully dynamic table names are not mapped
186
+ yet — those edges are skipped (and logged to `.scopecairn/last-run.log`),
187
+ never hallucinated. Server Actions (`detectServerActions`) and middleware
188
+ (`detectMiddleware`) are detected in `nextjs.ts`. QUERIES re-derive on
189
+ every scan so new models resolve without a rebuild.
190
+ Contributing a new adapter = one file + one registration line
191
+ in `src/adapters/index.ts` (see `FrameworkAdapter` in `src/adapters/types.ts`).
192
+
193
+ ## Typical loop
194
+
195
+ ```
196
+ prompt → scopecairn context (refresh at start) → agent edits code
197
+ → scopecairn scan (refresh at end, incremental, ~instant)
198
+ ```
199
+
200
+ Measure retrieval quality anytime: `scopecairn benchmark [--tune]`.
201
+
202
+ ## License
203
+
204
+ MIT — see [LICENSE](./LICENSE).