assistgraph 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Andy Williamson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,321 @@
1
+ # assistgraph
2
+
3
+ > File-level dependency knowledge graph for JavaScript, TypeScript, and Python codebases. Produces a JSON graph, an Obsidian vault, and an MCP server so agents like Claude and Codex can query your repo without grepping.
4
+
5
+ ## What it does
6
+
7
+ Run `assistgraph build` in any repo (or subfolder) and you get:
8
+
9
+ - **`assistgraph/graph.json`** — a machine-readable dependency graph of every file and every import
10
+ - **`assistgraph/vault/`** — an Obsidian-compatible knowledge vault with wiki links, pre-configured colour groups, and community pages
11
+ - **`assistgraph/audit.md`** (via `assistgraph audit`) — cycles, orphans, hubs, and cross-folder coupling
12
+ - **An MCP stdio server** (via `assistgraph mcp`) — 11 tools so Claude Code / Codex can query the graph directly
13
+
14
+ All parsing is deterministic and offline. Zero LLM calls, zero databases, zero Python runtime required.
15
+
16
+ ## Why
17
+
18
+ Large codebases burn agent tokens fast. "Who imports `UserService`?" normally means opening dozens of files and grepping each. With assistgraph, that same question is a single MCP call returning a few hundred tokens — O(1) graph lookup instead of O(N) file reads.
19
+
20
+ The same structural view also powers migrations: feature boundaries, blast-radius of a change, dead code, cycles, and cross-folder coupling are all one call away.
21
+
22
+ ## Features
23
+
24
+ - **Languages:** TypeScript, TSX, JavaScript, JSX, MJS, CJS, Python
25
+ - **Strict `.gitignore` enforcement:** anything in `.gitignore` is invisible to assistgraph, including wildcard patterns
26
+ - **CWD is the scan root:** run it anywhere — at the repo root for the full picture, or in a subfolder for a focused graph
27
+ - **Works in monorepos:** respects the topmost `tsconfig.json` above the scan root, stopping at parent project boundaries
28
+ - **Folder-based communities:** folders become feature communities automatically, mirroring your codebase structure
29
+ - **Cycle detection:** iterative Tarjan SCC — doesn't blow the JS stack on deep dependency chains
30
+ - **Hub/bloat metrics:** top imported files, top bloat candidates
31
+ - **Cross-folder coupling:** shows you exactly how tangled up `ui/` and `app/` really are
32
+ - **Orphan detection with entrypoint heuristics:** dead code is separated from legitimate entrypoints (`index.ts`, `main.py`, `manage.py`, etc.)
33
+ - **Content hashing:** every node has a stable hash for future incremental builds
34
+ - **Obsidian colour groups:** each top-level folder gets its own colour automatically so your graph view pops from the first click
35
+
36
+ ## Requirements
37
+
38
+ - **Node 18+** or **Bun 1.0+**
39
+ - No Python runtime required even for Python projects — parsing is pure JavaScript
40
+
41
+ ## Install
42
+
43
+ The fastest way to run assistgraph is via `npx` — no install needed:
44
+
45
+ ```bash
46
+ cd your-project
47
+ npx -y assistgraph build
48
+ ```
49
+
50
+ Or install a persistent global binary:
51
+
52
+ ```bash
53
+ # Node / npm
54
+ npm install -g assistgraph
55
+
56
+ # Bun
57
+ bun install -g assistgraph
58
+ ```
59
+
60
+ `oxc-parser` ships platform-specific native bindings that npm picks automatically on install. Once installed globally, drop the `npx -y` prefix from every command below.
61
+
62
+ ## Quick start
63
+
64
+ ```bash
65
+ # Build the graph + Obsidian vault in any repo
66
+ cd your-project
67
+ npx -y assistgraph build
68
+
69
+ # Peek at the stats
70
+ npx -y assistgraph stats
71
+
72
+ # Show what a file imports and who imports it
73
+ npx -y assistgraph query src/features/auth/Login.tsx
74
+
75
+ # Full audit: cycles, orphans, hubs, coupling → also writes assistgraph/audit.md
76
+ npx -y assistgraph audit
77
+
78
+ # Install Claude + Codex skills so agents know to prefer the graph
79
+ npx -y assistgraph install-skills
80
+
81
+ # Start the MCP server (for Claude Code / Codex)
82
+ npx -y assistgraph mcp
83
+ ```
84
+
85
+ Then point Obsidian at `./assistgraph/vault/` to see the graph visually.
86
+
87
+ ## CLI reference
88
+
89
+ ```
90
+ assistgraph build [--root <dir>] [--no-vault] Scan CWD → assistgraph/graph.json + vault/
91
+ assistgraph query <path> Deps + dependents for a file
92
+ assistgraph stats Graph stats
93
+ assistgraph audit [--out <path>] Cycles, orphans, hubs, coupling (+ audit.md)
94
+ assistgraph mcp Start MCP stdio server
95
+ assistgraph install-skills [--force] [--claude-only] [--codex-only]
96
+ Install Claude + Codex skill files
97
+ assistgraph init Create assistgraph.config.json
98
+ ```
99
+
100
+ ## Output layout
101
+
102
+ ```
103
+ <cwd>/
104
+ ├── assistgraph.config.json ← optional, check into git
105
+ └── assistgraph/ ← generated, add to .gitignore
106
+ ├── graph.json ← canonical graph
107
+ ├── audit.md ← generated by `assistgraph audit`
108
+ └── vault/ ← Obsidian-compatible vault
109
+ ├── .obsidian/graph.json ← pre-configured colour groups
110
+ ├── README.md ← entry MOC
111
+ ├── _communities/ ← one MOC per folder community
112
+ ├── _externals/ ← one stub per external package
113
+ └── <mirror of your source tree>/*.md
114
+ ```
115
+
116
+ ## Claude Code / Codex integration
117
+
118
+ ### MCP server config
119
+
120
+ Add one of the following to your Claude Code / Codex / Cursor MCP config. The `npx` / `bunx` variants require **no pre-install** — the package is fetched on first run and cached for subsequent launches.
121
+
122
+ **Node / npm (recommended):**
123
+
124
+ ```json
125
+ {
126
+ "mcpServers": {
127
+ "assistgraph": {
128
+ "command": "npx",
129
+ "args": ["-y", "assistgraph", "mcp"]
130
+ }
131
+ }
132
+ }
133
+ ```
134
+
135
+ **Bun:**
136
+
137
+ ```json
138
+ {
139
+ "mcpServers": {
140
+ "assistgraph": {
141
+ "command": "bunx",
142
+ "args": ["assistgraph", "mcp"]
143
+ }
144
+ }
145
+ }
146
+ ```
147
+
148
+ **Globally installed binary:**
149
+
150
+ ```json
151
+ {
152
+ "mcpServers": {
153
+ "assistgraph": {
154
+ "command": "assistgraph",
155
+ "args": ["mcp"]
156
+ }
157
+ }
158
+ }
159
+ ```
160
+
161
+ The MCP server reads `./assistgraph/graph.json` from the agent's current working directory and holds it in memory. Re-run `assistgraph build` whenever you want the graph to reflect new or moved files — the server picks up the new file on its next spawn.
162
+
163
+ ### One-time skill install
164
+
165
+ ```bash
166
+ npx -y assistgraph install-skills
167
+ ```
168
+
169
+ Writes:
170
+ - `~/.claude/skills/assistgraph/SKILL.md`
171
+ - `~/.codex/skills/assistgraph/SKILL.md`
172
+
173
+ The Claude skill tells Claude Code when to prefer `mcp__assistgraph__*` tools over grepping imports.
174
+
175
+ ### Tools exposed by the MCP server
176
+
177
+ | Tool | Purpose |
178
+ |---|---|
179
+ | `graph_stats` | Node/edge/language counts |
180
+ | `list_files` | Paginated file summaries, optional language filter |
181
+ | `get_file` | Full metadata for one file |
182
+ | `get_dependencies` | Transitive deps with optional depth |
183
+ | `get_dependents` | Transitive dependents with optional depth |
184
+ | `find_path` | Shortest dependency path between two files |
185
+ | `search_files` | Fuzzy file search by basename or path |
186
+ | `list_communities` | All folder communities |
187
+ | `get_community` | Members of a community |
188
+ | `find_cycles` | All dependency cycles (Tarjan SCC) |
189
+ | `find_orphans` | Orphan files, with `isLikelyEntrypoint` flag |
190
+
191
+ ## Obsidian integration
192
+
193
+ Point Obsidian at `./assistgraph/vault/` and open the graph view. Colour groups are pre-configured so each top-level folder gets its own colour, with language colours as a fallback.
194
+
195
+ To customise colours manually: **Graph view → Settings (gear) → Groups**. Your changes are preserved on subsequent `assistgraph build` runs — the default config is only written when no custom colour groups exist.
196
+
197
+ Each file note contains:
198
+ - YAML frontmatter (path, language, community, loc, exports, tags)
199
+ - `## Exports` — named + default exports
200
+ - `## Imports` — wiki-linked to sibling files + external stubs
201
+ - `## Imported By` — reverse index
202
+ - `## Metrics` — LOC, size, import/dependent counts, content hash
203
+
204
+ ## Configuration
205
+
206
+ Optional `assistgraph.config.json` at the scan root:
207
+
208
+ ```json
209
+ {
210
+ "include": ["**/*"],
211
+ "exclude": [
212
+ "assistgraph/**",
213
+ "node_modules/**",
214
+ "dist/**",
215
+ "build/**",
216
+ "__pycache__/**",
217
+ ".venv/**"
218
+ ],
219
+ "resolver": {
220
+ "tsconfig": null,
221
+ "pythonRoots": ["."]
222
+ },
223
+ "output": {
224
+ "dir": "assistgraph"
225
+ }
226
+ }
227
+ ```
228
+
229
+ Everything has sensible defaults. You only need this file if the defaults don't fit your project.
230
+
231
+ ## Running in a subfolder
232
+
233
+ ```bash
234
+ cd src/features/auth
235
+ npx -y assistgraph build
236
+ ```
237
+
238
+ The scan root becomes the current folder. Imports that leave the scan root become external leaf nodes (with their absolute path preserved). This lets you build a focused graph for a single feature or component folder.
239
+
240
+ When scanning a subfolder, assistgraph still walks up to find the nearest `tsconfig.json`, stopping at any parent `package.json` — so `@/...` and `@shared/...` aliases keep resolving correctly.
241
+
242
+ ## Graph schema
243
+
244
+ ```ts
245
+ interface Graph {
246
+ version: '1.0';
247
+ generatedAt: string;
248
+ scanRoot: string;
249
+ stats: { nodes; edges; orphans; cycles; languages };
250
+ nodes: Record<string, GraphNode>;
251
+ edges: GraphEdge[];
252
+ communities: Record<string, GraphCommunity>;
253
+ cycles: GraphCycle[];
254
+ }
255
+
256
+ interface GraphNode {
257
+ id: string; // scan-root-relative path
258
+ name: string; // basename
259
+ path: string;
260
+ absolutePath: string;
261
+ language: 'ts' | 'tsx' | 'js' | 'jsx' | 'mjs' | 'cjs' | 'py' | 'external';
262
+ isExternal: boolean;
263
+ loc: number;
264
+ sizeBytes: number;
265
+ exports: string[];
266
+ imports: ImportRef[];
267
+ community: string;
268
+ contentHash: string;
269
+ }
270
+
271
+ interface ImportRef {
272
+ raw: string; // the literal specifier, e.g. "./foo" or "@/lib/bar"
273
+ resolved: string | null;
274
+ symbols: string[]; // named bindings pulled in — symbol-aware, migration-ready
275
+ kind: 'static' | 'dynamic' | 'type' | 'require' | 'reexport' | 'python';
276
+ }
277
+
278
+ interface GraphEdge {
279
+ from: string;
280
+ to: string;
281
+ kind: ImportRef['kind'];
282
+ }
283
+
284
+ interface GraphCommunity {
285
+ id: string; // folder path, e.g. "src/features/auth"
286
+ members: string[];
287
+ parent: string | null;
288
+ }
289
+
290
+ interface GraphCycle {
291
+ members: string[];
292
+ length: number;
293
+ }
294
+ ```
295
+
296
+ ## What assistgraph does NOT do
297
+
298
+ - Function- or class-level resolution — file-level imports only
299
+ - Runtime analysis — static AST parsing only
300
+ - Type inference beyond what's declared in imports
301
+ - HTML or Vue SFC or Astro parsing
302
+ - Call graph construction
303
+ - LLM-based enrichment (roadmap)
304
+
305
+ ## FAQ
306
+
307
+ **Why are all the files the same colour in Obsidian's graph view?**
308
+ Obsidian starts every vault with no colour groups. `assistgraph build` writes `.obsidian/graph.json` with sensible defaults (one colour per top-level folder). If you already had the vault open, quit Obsidian fully (⌘Q), re-run `assistgraph build`, then reopen — Obsidian caches the settings in memory and overwrites the file on close.
309
+
310
+ **Why aren't my `ui/` and `app/` folders visually split?**
311
+ Obsidian uses a force-directed layout; folder structure isn't an input. If `ui/` and `app/` are intermingled, they're geometrically intertwined because of edges between them. Run `assistgraph audit` and check the "Cross-folder Coupling" section to see exactly how many edges cross the boundary.
312
+
313
+ **Does this work in a monorepo?**
314
+ Yes. Run `assistgraph build` at the repo root for a unified view, or in a specific package for a focused view. The resolver stops at parent `package.json` boundaries so a nested package's `tsconfig.json` takes priority over the monorepo root.
315
+
316
+ **Does this replace `dependency-cruiser` / `madge`?**
317
+ No — those are richer JS-only tools. assistgraph trades depth for breadth: one tool across JS/TS + Python, an Obsidian vault for humans, and an MCP server for agents.
318
+
319
+ ## License
320
+
321
+ MIT.