workspace-graph 0.1.0__tar.gz
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.
- workspace_graph-0.1.0/.github/workflows/publish.yml +36 -0
- workspace_graph-0.1.0/.gitignore +8 -0
- workspace_graph-0.1.0/AGENTS.md +105 -0
- workspace_graph-0.1.0/PKG-INFO +250 -0
- workspace_graph-0.1.0/README.md +226 -0
- workspace_graph-0.1.0/TODOS.md +56 -0
- workspace_graph-0.1.0/pyproject.toml +77 -0
- workspace_graph-0.1.0/scripts/install.sh +127 -0
- workspace_graph-0.1.0/scripts/uninstall.sh +74 -0
- workspace_graph-0.1.0/src/codegraph/__init__.py +1 -0
- workspace_graph-0.1.0/src/codegraph/__main__.py +3 -0
- workspace_graph-0.1.0/src/codegraph/builder.py +300 -0
- workspace_graph-0.1.0/src/codegraph/cli.py +208 -0
- workspace_graph-0.1.0/src/codegraph/commands/__init__.py +0 -0
- workspace_graph-0.1.0/src/codegraph/commands/build.py +13 -0
- workspace_graph-0.1.0/src/codegraph/commands/callees.py +22 -0
- workspace_graph-0.1.0/src/codegraph/commands/callers.py +22 -0
- workspace_graph-0.1.0/src/codegraph/commands/clean.py +16 -0
- workspace_graph-0.1.0/src/codegraph/commands/context.py +51 -0
- workspace_graph-0.1.0/src/codegraph/commands/cross_service.py +41 -0
- workspace_graph-0.1.0/src/codegraph/commands/impact.py +23 -0
- workspace_graph-0.1.0/src/codegraph/commands/opencode_plugin.py +38 -0
- workspace_graph-0.1.0/src/codegraph/commands/orphans.py +33 -0
- workspace_graph-0.1.0/src/codegraph/commands/query_cmd.py +25 -0
- workspace_graph-0.1.0/src/codegraph/commands/routes.py +42 -0
- workspace_graph-0.1.0/src/codegraph/commands/status.py +77 -0
- workspace_graph-0.1.0/src/codegraph/commands/trace.py +19 -0
- workspace_graph-0.1.0/src/codegraph/config.py +81 -0
- workspace_graph-0.1.0/src/codegraph/cross_service.py +114 -0
- workspace_graph-0.1.0/src/codegraph/discover.py +167 -0
- workspace_graph-0.1.0/src/codegraph/graph/__init__.py +0 -0
- workspace_graph-0.1.0/src/codegraph/graph/serialize.py +141 -0
- workspace_graph-0.1.0/src/codegraph/graph/types.py +66 -0
- workspace_graph-0.1.0/src/codegraph/plugin.py +61 -0
- workspace_graph-0.1.0/src/codegraph/query.py +435 -0
- workspace_graph-0.1.0/src/codegraph/server.py +299 -0
- workspace_graph-0.1.0/tests/__init__.py +0 -0
- workspace_graph-0.1.0/tests/conftest.py +24 -0
- workspace_graph-0.1.0/tests/test_builder.py +190 -0
- workspace_graph-0.1.0/tests/test_config.py +85 -0
- workspace_graph-0.1.0/tests/test_cross_service.py +297 -0
- workspace_graph-0.1.0/tests/test_discover.py +181 -0
- workspace_graph-0.1.0/tests/test_opencode_plugin.py +54 -0
- workspace_graph-0.1.0/tests/test_plugins.py +91 -0
- workspace_graph-0.1.0/tests/test_query.py +248 -0
- workspace_graph-0.1.0/tests/test_serialize.py +85 -0
- workspace_graph-0.1.0/tests/test_server.py +217 -0
- workspace_graph-0.1.0/uv.lock +1242 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
id-token: write
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
publish:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v6.0.2
|
|
17
|
+
|
|
18
|
+
- name: Install uv
|
|
19
|
+
uses: astral-sh/setup-uv@v8.1.0
|
|
20
|
+
|
|
21
|
+
- name: Set up Python 3.11
|
|
22
|
+
uses: actions/setup-python@v6.2.0
|
|
23
|
+
with:
|
|
24
|
+
python-version: "3.11"
|
|
25
|
+
|
|
26
|
+
- name: Install dependencies
|
|
27
|
+
run: uv sync --group dev
|
|
28
|
+
|
|
29
|
+
- name: Run tests
|
|
30
|
+
run: uv run pytest
|
|
31
|
+
|
|
32
|
+
- name: Build
|
|
33
|
+
run: uv build
|
|
34
|
+
|
|
35
|
+
- name: Publish
|
|
36
|
+
run: uv publish --trusted-publishing always
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# codegraph — Project DNA
|
|
2
|
+
|
|
3
|
+
## Vision
|
|
4
|
+
A thin orchestration layer that sits at the root of a multi-language, multi-repository
|
|
5
|
+
workspace (monorepo or submodule-based). It auto-discovers every service, frontend,
|
|
6
|
+
gateway, and library, orchestrates builds using language-specific tools (gograph,
|
|
7
|
+
tsgraph, pygraph), merges all graph.json outputs into a single unified graph, and
|
|
8
|
+
exposes one MCP server for querying any symbol across any service.
|
|
9
|
+
|
|
10
|
+
## Design Philosophy (Orchestrator, not a parser)
|
|
11
|
+
codegraph is not an indexer — it orchestrates indexers. Key design points:
|
|
12
|
+
- **Language-agnostic** — no language is special. Every entry is equal in the schema.
|
|
13
|
+
- **Resilient** — one failed entry build doesn't block others. Partial results are useful.
|
|
14
|
+
- **Clean state** — single `.codegraph/` output directory. `codegraph clean` removes everything.
|
|
15
|
+
- **User-enriched** — auto-detection is best-effort; override via `codegraph.jsonc`.
|
|
16
|
+
- **Type classification** — entries get a `type` field (service, frontend, gateway, library,
|
|
17
|
+
proto, etc.) detected by heuristics and overridable by the user. Used as a query filter only.
|
|
18
|
+
- **Unbuilt languages** — Rust, Java, and other languages are detected and listed but not
|
|
19
|
+
indexed (no graph tool yet). The user sees them in `status` output.
|
|
20
|
+
|
|
21
|
+
### Boundaries
|
|
22
|
+
- **gograph/tsgraph/pygraph**: Own all per-language extraction (symbols, calls, routes,
|
|
23
|
+
HTTP client calls, errors, env reads, test edges). One tool per language.
|
|
24
|
+
- **codegraph**: Owns workspace orchestration, cross-service analysis, and unified MCP.
|
|
25
|
+
Does NOT duplicate per-language extraction that belongs in gograph/tsgraph/pygraph.
|
|
26
|
+
- If a capability is language-specific, it belongs in the per-language tool first.
|
|
27
|
+
codegraph only combines, correlates, and queries outputs from those tools.
|
|
28
|
+
|
|
29
|
+
## Tech Stack
|
|
30
|
+
- Runtime: Python 3.11+
|
|
31
|
+
- Package manager: `uv`
|
|
32
|
+
- CLI: `typer`
|
|
33
|
+
- MCP: `mcp` Python SDK
|
|
34
|
+
- Config parsing: `pydantic` for schema validation
|
|
35
|
+
- File scanning: `pathspec` for gitignore support
|
|
36
|
+
- Testing: `pytest` + `pytest-cov`
|
|
37
|
+
- Linting: `ruff`
|
|
38
|
+
- Type checking: `mypy` (strict mode)
|
|
39
|
+
|
|
40
|
+
## Installation (for AI Agents)
|
|
41
|
+
|
|
42
|
+
Install all tools:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# Python tools
|
|
46
|
+
pip install codegraph-mcp pygraph-mcp
|
|
47
|
+
|
|
48
|
+
# TypeScript tool
|
|
49
|
+
npm install -g @shvmgyl15/tsgraph
|
|
50
|
+
|
|
51
|
+
# Go tool
|
|
52
|
+
git clone https://github.com/shvmgyl15/gograph
|
|
53
|
+
cd gograph && go build -o ~/.local/bin/gograph ./cmd/gograph
|
|
54
|
+
|
|
55
|
+
# Verify
|
|
56
|
+
codegraph status
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Or install everything from git source in one step:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
git clone https://github.com/shvmgyl15/codegraph
|
|
63
|
+
cd codegraph && ./scripts/install.sh
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Agent Rules
|
|
67
|
+
|
|
68
|
+
### Task Management
|
|
69
|
+
- READ TODOS.md at session start to know what's done and what's next
|
|
70
|
+
- UPDATE TODOS.md when you start/finish a task (`[.]` in-progress, `[x]` done)
|
|
71
|
+
- Work in phase order unless a task has no blockers
|
|
72
|
+
- After a phase completes (all items `[x]`), run `git init` if not yet done,
|
|
73
|
+
then commit and push: `git add -A && git commit -m "phase N: <title>" && git push origin main`
|
|
74
|
+
|
|
75
|
+
### Orchestration
|
|
76
|
+
- This is a single-orchestrator project. When a task has multiple independent
|
|
77
|
+
sub-tasks, delegate via the `task` tool (`subagent_type: general`) rather
|
|
78
|
+
than doing them sequentially.
|
|
79
|
+
- For each delegated sub-task, specify:
|
|
80
|
+
1. Exact files the sub-agent may modify
|
|
81
|
+
2. Which phase from TODOS.md it belongs to
|
|
82
|
+
3. What to return (never let sub-agents commit or merge)
|
|
83
|
+
- After all sub-tasks complete, run `uv run pytest && uv run mypy src && uv run ruff check`
|
|
84
|
+
and fix any issues directly. Do NOT re-delegate broken builds.
|
|
85
|
+
|
|
86
|
+
### Quality
|
|
87
|
+
- Run `uv run pytest`, `uv run mypy src`, and `uv run ruff check` after every task completion
|
|
88
|
+
- Fix all failures before marking `[x]`
|
|
89
|
+
- If the project is already broken when you start, note it in TODOS.md and fix it first
|
|
90
|
+
|
|
91
|
+
### Research
|
|
92
|
+
- Use webfetch when unsure about an API — check Python `ast` docs, typer docs, mcp SDK docs
|
|
93
|
+
- Reference gograph, tsgraph, pygraph source for their graph.json output formats
|
|
94
|
+
- DO NOT guess API signatures
|
|
95
|
+
|
|
96
|
+
### Code Style
|
|
97
|
+
- No comments in source files unless logic is non-obvious
|
|
98
|
+
- Type annotations everywhere, avoid `Any`
|
|
99
|
+
- Follow patterns from adjacent files in the codebase
|
|
100
|
+
- No emojis in source code or commit messages
|
|
101
|
+
- Follow PEP 8 conventions (enforced by ruff)
|
|
102
|
+
|
|
103
|
+
### Communication
|
|
104
|
+
- Be concise. Use TODOS.md for status, respond with only what's needed.
|
|
105
|
+
- If stuck, explain the blocker clearly rather than overthinking.
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: workspace-graph
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Multi-language workspace code graph orchestrator
|
|
5
|
+
Project-URL: Homepage, https://github.com/shvmgyl15/codegraph
|
|
6
|
+
Project-URL: Repository, https://github.com/shvmgyl15/codegraph
|
|
7
|
+
Project-URL: Issues, https://github.com/shvmgyl15/codegraph/issues
|
|
8
|
+
Author-email: Shivam Goel <sg15rokz@gmail.com>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
17
|
+
Classifier: Topic :: Utilities
|
|
18
|
+
Requires-Python: >=3.11
|
|
19
|
+
Requires-Dist: mcp>=1.0
|
|
20
|
+
Requires-Dist: pathspec>=1.1.1
|
|
21
|
+
Requires-Dist: pydantic>=2.0
|
|
22
|
+
Requires-Dist: typer>=0.12
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# codegraph
|
|
26
|
+
|
|
27
|
+
Multi-language workspace code graph orchestrator.
|
|
28
|
+
|
|
29
|
+
Auto-discovers services, frontends, gateways, and libraries in a workspace,
|
|
30
|
+
orchestrates builds using language-specific tools ([gograph](https://github.com/shvmgyl15/gograph),
|
|
31
|
+
[tsgraph](https://github.com/shvmgyl15/tsgraph), [pygraph](https://github.com/shvmgyl15/pygraph)),
|
|
32
|
+
merges their graph.json outputs into a unified graph, and exposes a single MCP
|
|
33
|
+
server for querying any symbol across any service.
|
|
34
|
+
|
|
35
|
+
**Install from git source only.** Do not use PyPI or npm — there are unrelated
|
|
36
|
+
packages with the same names. All 4 repos must be installed together from
|
|
37
|
+
source to stay in sync.
|
|
38
|
+
|
|
39
|
+
## Quick Start
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
# 1. Clone all 4 repos as siblings
|
|
43
|
+
git clone https://github.com/shvmgyl15/gograph
|
|
44
|
+
git clone https://github.com/shvmgyl15/tsgraph
|
|
45
|
+
git clone https://github.com/shvmgyl15/pygraph
|
|
46
|
+
git clone https://github.com/shvmgyl15/codegraph
|
|
47
|
+
|
|
48
|
+
# 2. Run the install script (builds all tools from source)
|
|
49
|
+
cd codegraph && ./scripts/install.sh
|
|
50
|
+
|
|
51
|
+
# 3. Create workspace config
|
|
52
|
+
# (or run from a directory with go.mod/package.json/pyproject.toml subdirectories)
|
|
53
|
+
echo '{"version":1,"entries":[{"name":"frontend","path":"./frontend","language":"typescript","type":"frontend"},{"name":"api","path":"./api","language":"python","type":"service"}]}' > ../codegraph.json
|
|
54
|
+
|
|
55
|
+
# 4. Build the unified graph
|
|
56
|
+
codegraph build
|
|
57
|
+
|
|
58
|
+
# 5. Query across all services
|
|
59
|
+
codegraph query "getUser"
|
|
60
|
+
codegraph callers "get_user"
|
|
61
|
+
codegraph routes
|
|
62
|
+
codegraph orphans
|
|
63
|
+
|
|
64
|
+
# 6. Start MCP server for AI agents
|
|
65
|
+
codegraph mcp
|
|
66
|
+
|
|
67
|
+
# 7. Generate .opencode.json for AI agent integration
|
|
68
|
+
codegraph add-opencode-plugin
|
|
69
|
+
|
|
70
|
+
# 8. Clean up
|
|
71
|
+
codegraph clean
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Requirements
|
|
75
|
+
|
|
76
|
+
- Python 3.11+
|
|
77
|
+
- Go 1.22+ (for gograph)
|
|
78
|
+
- Node.js 20+ (for tsgraph)
|
|
79
|
+
- [uv](https://docs.astral.sh/uv/) (Python package manager)
|
|
80
|
+
|
|
81
|
+
## Install
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
# Install all tools from local git source:
|
|
85
|
+
./scripts/install.sh
|
|
86
|
+
|
|
87
|
+
# This builds:
|
|
88
|
+
# gograph → ~/.local/bin/gograph (from ../gograph)
|
|
89
|
+
# tsgraph → ~/.local/bin/tsgraph (from ../tsgraph)
|
|
90
|
+
# pygraph → ~/.local/bin/pygraph (from ../pygraph)
|
|
91
|
+
# codegraph → ~/.local/bin/codegraph (from current dir)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The script looks for sibling repos (`../gograph`, `../tsgraph`, `../pygraph`).
|
|
95
|
+
It builds each from source and installs binaries to `~/.local/bin/`.
|
|
96
|
+
|
|
97
|
+
## Uninstall
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
./scripts/uninstall.sh
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Removes all binaries from `~/.local/bin/`, all `.gograph`/`.tsgraph`/`.pygraph`/`.codegraph`
|
|
104
|
+
output directories, virtual envs, `node_modules`, caches, and lock files from all 4 repos.
|
|
105
|
+
|
|
106
|
+
## Configuration
|
|
107
|
+
|
|
108
|
+
Create `codegraph.jsonc` or `codegraph.json` at your workspace root:
|
|
109
|
+
|
|
110
|
+
```jsonc
|
|
111
|
+
{
|
|
112
|
+
"version": 1,
|
|
113
|
+
"auto_discover": true,
|
|
114
|
+
"entries": [
|
|
115
|
+
{ "name": "frontend", "path": "./frontend", "language": "typescript", "type": "frontend" },
|
|
116
|
+
{ "name": "api-gateway", "path": "./api-gateway", "language": "python", "type": "gateway" },
|
|
117
|
+
{ "name": "user-svc", "path": "./user-svc", "language": "go", "type": "service" },
|
|
118
|
+
{ "name": "py-common", "path": "./libs/py-common", "language": "python", "type": "library" }
|
|
119
|
+
],
|
|
120
|
+
"plugins": ["./scripts/custom_enrichment.py"]
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
When `auto_discover: true`, codegraph probes subdirectories for `go.mod`,
|
|
125
|
+
`package.json`, `pyproject.toml`, `Cargo.toml`, `pom.xml` etc.
|
|
126
|
+
|
|
127
|
+
### The `--root` parameter
|
|
128
|
+
|
|
129
|
+
`--root` specifies the **workspace root directory** — the same directory where
|
|
130
|
+
you ran `codegraph build`. It tells codegraph where to find the `.codegraph/`
|
|
131
|
+
output folder. It is NOT a query scope filter.
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
# Build in /home/user/myproject
|
|
135
|
+
codegraph build --root /home/user/myproject
|
|
136
|
+
|
|
137
|
+
# Query the same workspace
|
|
138
|
+
codegraph context get_user --root /home/user/myproject
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
If you pass the wrong `--root`, codegraph suggests the correct one.
|
|
142
|
+
|
|
143
|
+
## CLI Commands
|
|
144
|
+
|
|
145
|
+
| Command | Description |
|
|
146
|
+
|---|---|
|
|
147
|
+
| `status` | List discovered entries with build status |
|
|
148
|
+
| `build` | Build graph for all entries (`--entry` for one) |
|
|
149
|
+
| `clean` | Remove `.codegraph/` output directory |
|
|
150
|
+
| `query <pattern>` | Search symbols by regex or substring |
|
|
151
|
+
| `callers <name>` | Who calls a given symbol |
|
|
152
|
+
| `callees <name>` | What a symbol calls |
|
|
153
|
+
| `routes` | List all HTTP routes (`--entry`, `--type`) |
|
|
154
|
+
| `impact <name>` | BFS downstream blast radius (`--max-depth`) |
|
|
155
|
+
| `orphans` | Dead code detection (`--all`, `--exclude-type`) |
|
|
156
|
+
| `context <name>` | Full bundle: symbol + callers + callees + tests |
|
|
157
|
+
| `trace <message>` | Error flow search with reverse call chain |
|
|
158
|
+
| `cross-service` | Cross-service HTTP call edges |
|
|
159
|
+
| `add-opencode-plugin` | Generate `.opencode.json` for AI agent config |
|
|
160
|
+
| `mcp` | Start MCP stdio server |
|
|
161
|
+
|
|
162
|
+
## MCP Tools (for AI Agents)
|
|
163
|
+
|
|
164
|
+
All MCP tool responses include a `duration_ms` field showing how long the query
|
|
165
|
+
took. List responses are wrapped in `{"items": [...], "duration_ms": N}`.
|
|
166
|
+
|
|
167
|
+
| Tool | Description |
|
|
168
|
+
|---|---|
|
|
169
|
+
| `entry_status` | List entries with language, type, build status |
|
|
170
|
+
| `query_symbols` | Search symbols across all entries |
|
|
171
|
+
| `callers` / `callees` | Who calls / what a symbol calls |
|
|
172
|
+
| `context` | Symbol + callers + callees + tests |
|
|
173
|
+
| `routes` | HTTP routes with entry/type filters |
|
|
174
|
+
| `impact` | Blast radius with max depth |
|
|
175
|
+
| `orphans` | Dead code with include-public and exclude-type |
|
|
176
|
+
| `trace` | Error message search with backtrace |
|
|
177
|
+
| `cross_service_calls` | Cross-service HTTP call edges |
|
|
178
|
+
| `add_opencode_plugin` | Generate AI agent config |
|
|
179
|
+
|
|
180
|
+
## Performance
|
|
181
|
+
|
|
182
|
+
- **Build**: Entries are built in parallel (4 workers). Per-entry timing shown.
|
|
183
|
+
- **MCP queries**: The graph is loaded and indexed once, then cached in memory
|
|
184
|
+
for subsequent queries within the same MCP session. Each response includes
|
|
185
|
+
`duration_ms` so you can monitor performance.
|
|
186
|
+
|
|
187
|
+
## Plugin System
|
|
188
|
+
|
|
189
|
+
User-provided Python scripts that run post-merge to enrich the graph. Configured
|
|
190
|
+
in `codegraph.jsonc`:
|
|
191
|
+
|
|
192
|
+
```jsonc
|
|
193
|
+
{ "plugins": ["./scripts/enrich.py"] }
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Plugin script interface:
|
|
197
|
+
|
|
198
|
+
```python
|
|
199
|
+
from codegraph.graph.types import UnifiedGraph
|
|
200
|
+
|
|
201
|
+
def run(graph: UnifiedGraph) -> None:
|
|
202
|
+
# Mutate graph in-place
|
|
203
|
+
graph.cross_service_edges.append({
|
|
204
|
+
"source_entry": "frontend",
|
|
205
|
+
"source_file": "src/api.ts",
|
|
206
|
+
"source_line": 10,
|
|
207
|
+
"source_symbol": "loadUsers",
|
|
208
|
+
"method": "GET",
|
|
209
|
+
"url_pattern": "/api/users",
|
|
210
|
+
"target_entry": "api",
|
|
211
|
+
"target_route_path": "/api/users",
|
|
212
|
+
"target_route_handler": "get_users",
|
|
213
|
+
"confidence": "high",
|
|
214
|
+
})
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Troubleshooting
|
|
218
|
+
|
|
219
|
+
| Problem | Solution |
|
|
220
|
+
|---|---|
|
|
221
|
+
| `codegraph: command not found` | Run `./scripts/install.sh` — make sure `~/.local/bin` is on PATH |
|
|
222
|
+
| `Graph not found at ...` | You passed a wrong `--root`. Run `codegraph build` in your workspace root first, then use the same root for queries. |
|
|
223
|
+
| MCP queries are slow | First call loads and indexes the graph (takes a few seconds for large workspaces). Subsequent calls use the in-memory cache and are fast. |
|
|
224
|
+
| `pip install codegraph` installs wrong package | codegraph is NOT on PyPI. Use `./scripts/install.sh` from the git repo. |
|
|
225
|
+
| `npm install tsgraph` installs wrong package | tsgraph is NOT on npm. Use `./scripts/install.sh` from the git repo. |
|
|
226
|
+
|
|
227
|
+
## Architecture
|
|
228
|
+
|
|
229
|
+
```
|
|
230
|
+
codegraph (orchestrator)
|
|
231
|
+
├── gograph ─── indexes Go codebases
|
|
232
|
+
├── tsgraph ─── indexes TypeScript/Next.js codebases
|
|
233
|
+
└── pygraph ─── indexes Python/Flask codebases
|
|
234
|
+
|
|
235
|
+
Output: .codegraph/workspace.graph.json (merged)
|
|
236
|
+
.codegraph/manifest.json (entry metadata)
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
- Each per-language tool produces its own `graph.json`
|
|
240
|
+
- codegraph merges them, stamps entries with metadata
|
|
241
|
+
- Cross-service edges are detected via URL → route matching
|
|
242
|
+
- Plugins can enrich the graph post-merge
|
|
243
|
+
- Single MCP server exposes all query tools
|
|
244
|
+
- WorkspaceQuery is cached in memory across MCP calls
|
|
245
|
+
|
|
246
|
+
## Related
|
|
247
|
+
|
|
248
|
+
- [gograph](https://github.com/shvmgyl15/gograph) — Go codebase indexer
|
|
249
|
+
- [tsgraph](https://github.com/shvmgyl15/tsgraph) — TypeScript/React/Next.js indexer
|
|
250
|
+
- [pygraph](https://github.com/shvmgyl15/pygraph) — Python/Flask codebase indexer
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
# codegraph
|
|
2
|
+
|
|
3
|
+
Multi-language workspace code graph orchestrator.
|
|
4
|
+
|
|
5
|
+
Auto-discovers services, frontends, gateways, and libraries in a workspace,
|
|
6
|
+
orchestrates builds using language-specific tools ([gograph](https://github.com/shvmgyl15/gograph),
|
|
7
|
+
[tsgraph](https://github.com/shvmgyl15/tsgraph), [pygraph](https://github.com/shvmgyl15/pygraph)),
|
|
8
|
+
merges their graph.json outputs into a unified graph, and exposes a single MCP
|
|
9
|
+
server for querying any symbol across any service.
|
|
10
|
+
|
|
11
|
+
**Install from git source only.** Do not use PyPI or npm — there are unrelated
|
|
12
|
+
packages with the same names. All 4 repos must be installed together from
|
|
13
|
+
source to stay in sync.
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# 1. Clone all 4 repos as siblings
|
|
19
|
+
git clone https://github.com/shvmgyl15/gograph
|
|
20
|
+
git clone https://github.com/shvmgyl15/tsgraph
|
|
21
|
+
git clone https://github.com/shvmgyl15/pygraph
|
|
22
|
+
git clone https://github.com/shvmgyl15/codegraph
|
|
23
|
+
|
|
24
|
+
# 2. Run the install script (builds all tools from source)
|
|
25
|
+
cd codegraph && ./scripts/install.sh
|
|
26
|
+
|
|
27
|
+
# 3. Create workspace config
|
|
28
|
+
# (or run from a directory with go.mod/package.json/pyproject.toml subdirectories)
|
|
29
|
+
echo '{"version":1,"entries":[{"name":"frontend","path":"./frontend","language":"typescript","type":"frontend"},{"name":"api","path":"./api","language":"python","type":"service"}]}' > ../codegraph.json
|
|
30
|
+
|
|
31
|
+
# 4. Build the unified graph
|
|
32
|
+
codegraph build
|
|
33
|
+
|
|
34
|
+
# 5. Query across all services
|
|
35
|
+
codegraph query "getUser"
|
|
36
|
+
codegraph callers "get_user"
|
|
37
|
+
codegraph routes
|
|
38
|
+
codegraph orphans
|
|
39
|
+
|
|
40
|
+
# 6. Start MCP server for AI agents
|
|
41
|
+
codegraph mcp
|
|
42
|
+
|
|
43
|
+
# 7. Generate .opencode.json for AI agent integration
|
|
44
|
+
codegraph add-opencode-plugin
|
|
45
|
+
|
|
46
|
+
# 8. Clean up
|
|
47
|
+
codegraph clean
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Requirements
|
|
51
|
+
|
|
52
|
+
- Python 3.11+
|
|
53
|
+
- Go 1.22+ (for gograph)
|
|
54
|
+
- Node.js 20+ (for tsgraph)
|
|
55
|
+
- [uv](https://docs.astral.sh/uv/) (Python package manager)
|
|
56
|
+
|
|
57
|
+
## Install
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
# Install all tools from local git source:
|
|
61
|
+
./scripts/install.sh
|
|
62
|
+
|
|
63
|
+
# This builds:
|
|
64
|
+
# gograph → ~/.local/bin/gograph (from ../gograph)
|
|
65
|
+
# tsgraph → ~/.local/bin/tsgraph (from ../tsgraph)
|
|
66
|
+
# pygraph → ~/.local/bin/pygraph (from ../pygraph)
|
|
67
|
+
# codegraph → ~/.local/bin/codegraph (from current dir)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The script looks for sibling repos (`../gograph`, `../tsgraph`, `../pygraph`).
|
|
71
|
+
It builds each from source and installs binaries to `~/.local/bin/`.
|
|
72
|
+
|
|
73
|
+
## Uninstall
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
./scripts/uninstall.sh
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Removes all binaries from `~/.local/bin/`, all `.gograph`/`.tsgraph`/`.pygraph`/`.codegraph`
|
|
80
|
+
output directories, virtual envs, `node_modules`, caches, and lock files from all 4 repos.
|
|
81
|
+
|
|
82
|
+
## Configuration
|
|
83
|
+
|
|
84
|
+
Create `codegraph.jsonc` or `codegraph.json` at your workspace root:
|
|
85
|
+
|
|
86
|
+
```jsonc
|
|
87
|
+
{
|
|
88
|
+
"version": 1,
|
|
89
|
+
"auto_discover": true,
|
|
90
|
+
"entries": [
|
|
91
|
+
{ "name": "frontend", "path": "./frontend", "language": "typescript", "type": "frontend" },
|
|
92
|
+
{ "name": "api-gateway", "path": "./api-gateway", "language": "python", "type": "gateway" },
|
|
93
|
+
{ "name": "user-svc", "path": "./user-svc", "language": "go", "type": "service" },
|
|
94
|
+
{ "name": "py-common", "path": "./libs/py-common", "language": "python", "type": "library" }
|
|
95
|
+
],
|
|
96
|
+
"plugins": ["./scripts/custom_enrichment.py"]
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
When `auto_discover: true`, codegraph probes subdirectories for `go.mod`,
|
|
101
|
+
`package.json`, `pyproject.toml`, `Cargo.toml`, `pom.xml` etc.
|
|
102
|
+
|
|
103
|
+
### The `--root` parameter
|
|
104
|
+
|
|
105
|
+
`--root` specifies the **workspace root directory** — the same directory where
|
|
106
|
+
you ran `codegraph build`. It tells codegraph where to find the `.codegraph/`
|
|
107
|
+
output folder. It is NOT a query scope filter.
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
# Build in /home/user/myproject
|
|
111
|
+
codegraph build --root /home/user/myproject
|
|
112
|
+
|
|
113
|
+
# Query the same workspace
|
|
114
|
+
codegraph context get_user --root /home/user/myproject
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
If you pass the wrong `--root`, codegraph suggests the correct one.
|
|
118
|
+
|
|
119
|
+
## CLI Commands
|
|
120
|
+
|
|
121
|
+
| Command | Description |
|
|
122
|
+
|---|---|
|
|
123
|
+
| `status` | List discovered entries with build status |
|
|
124
|
+
| `build` | Build graph for all entries (`--entry` for one) |
|
|
125
|
+
| `clean` | Remove `.codegraph/` output directory |
|
|
126
|
+
| `query <pattern>` | Search symbols by regex or substring |
|
|
127
|
+
| `callers <name>` | Who calls a given symbol |
|
|
128
|
+
| `callees <name>` | What a symbol calls |
|
|
129
|
+
| `routes` | List all HTTP routes (`--entry`, `--type`) |
|
|
130
|
+
| `impact <name>` | BFS downstream blast radius (`--max-depth`) |
|
|
131
|
+
| `orphans` | Dead code detection (`--all`, `--exclude-type`) |
|
|
132
|
+
| `context <name>` | Full bundle: symbol + callers + callees + tests |
|
|
133
|
+
| `trace <message>` | Error flow search with reverse call chain |
|
|
134
|
+
| `cross-service` | Cross-service HTTP call edges |
|
|
135
|
+
| `add-opencode-plugin` | Generate `.opencode.json` for AI agent config |
|
|
136
|
+
| `mcp` | Start MCP stdio server |
|
|
137
|
+
|
|
138
|
+
## MCP Tools (for AI Agents)
|
|
139
|
+
|
|
140
|
+
All MCP tool responses include a `duration_ms` field showing how long the query
|
|
141
|
+
took. List responses are wrapped in `{"items": [...], "duration_ms": N}`.
|
|
142
|
+
|
|
143
|
+
| Tool | Description |
|
|
144
|
+
|---|---|
|
|
145
|
+
| `entry_status` | List entries with language, type, build status |
|
|
146
|
+
| `query_symbols` | Search symbols across all entries |
|
|
147
|
+
| `callers` / `callees` | Who calls / what a symbol calls |
|
|
148
|
+
| `context` | Symbol + callers + callees + tests |
|
|
149
|
+
| `routes` | HTTP routes with entry/type filters |
|
|
150
|
+
| `impact` | Blast radius with max depth |
|
|
151
|
+
| `orphans` | Dead code with include-public and exclude-type |
|
|
152
|
+
| `trace` | Error message search with backtrace |
|
|
153
|
+
| `cross_service_calls` | Cross-service HTTP call edges |
|
|
154
|
+
| `add_opencode_plugin` | Generate AI agent config |
|
|
155
|
+
|
|
156
|
+
## Performance
|
|
157
|
+
|
|
158
|
+
- **Build**: Entries are built in parallel (4 workers). Per-entry timing shown.
|
|
159
|
+
- **MCP queries**: The graph is loaded and indexed once, then cached in memory
|
|
160
|
+
for subsequent queries within the same MCP session. Each response includes
|
|
161
|
+
`duration_ms` so you can monitor performance.
|
|
162
|
+
|
|
163
|
+
## Plugin System
|
|
164
|
+
|
|
165
|
+
User-provided Python scripts that run post-merge to enrich the graph. Configured
|
|
166
|
+
in `codegraph.jsonc`:
|
|
167
|
+
|
|
168
|
+
```jsonc
|
|
169
|
+
{ "plugins": ["./scripts/enrich.py"] }
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Plugin script interface:
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
from codegraph.graph.types import UnifiedGraph
|
|
176
|
+
|
|
177
|
+
def run(graph: UnifiedGraph) -> None:
|
|
178
|
+
# Mutate graph in-place
|
|
179
|
+
graph.cross_service_edges.append({
|
|
180
|
+
"source_entry": "frontend",
|
|
181
|
+
"source_file": "src/api.ts",
|
|
182
|
+
"source_line": 10,
|
|
183
|
+
"source_symbol": "loadUsers",
|
|
184
|
+
"method": "GET",
|
|
185
|
+
"url_pattern": "/api/users",
|
|
186
|
+
"target_entry": "api",
|
|
187
|
+
"target_route_path": "/api/users",
|
|
188
|
+
"target_route_handler": "get_users",
|
|
189
|
+
"confidence": "high",
|
|
190
|
+
})
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Troubleshooting
|
|
194
|
+
|
|
195
|
+
| Problem | Solution |
|
|
196
|
+
|---|---|
|
|
197
|
+
| `codegraph: command not found` | Run `./scripts/install.sh` — make sure `~/.local/bin` is on PATH |
|
|
198
|
+
| `Graph not found at ...` | You passed a wrong `--root`. Run `codegraph build` in your workspace root first, then use the same root for queries. |
|
|
199
|
+
| MCP queries are slow | First call loads and indexes the graph (takes a few seconds for large workspaces). Subsequent calls use the in-memory cache and are fast. |
|
|
200
|
+
| `pip install codegraph` installs wrong package | codegraph is NOT on PyPI. Use `./scripts/install.sh` from the git repo. |
|
|
201
|
+
| `npm install tsgraph` installs wrong package | tsgraph is NOT on npm. Use `./scripts/install.sh` from the git repo. |
|
|
202
|
+
|
|
203
|
+
## Architecture
|
|
204
|
+
|
|
205
|
+
```
|
|
206
|
+
codegraph (orchestrator)
|
|
207
|
+
├── gograph ─── indexes Go codebases
|
|
208
|
+
├── tsgraph ─── indexes TypeScript/Next.js codebases
|
|
209
|
+
└── pygraph ─── indexes Python/Flask codebases
|
|
210
|
+
|
|
211
|
+
Output: .codegraph/workspace.graph.json (merged)
|
|
212
|
+
.codegraph/manifest.json (entry metadata)
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
- Each per-language tool produces its own `graph.json`
|
|
216
|
+
- codegraph merges them, stamps entries with metadata
|
|
217
|
+
- Cross-service edges are detected via URL → route matching
|
|
218
|
+
- Plugins can enrich the graph post-merge
|
|
219
|
+
- Single MCP server exposes all query tools
|
|
220
|
+
- WorkspaceQuery is cached in memory across MCP calls
|
|
221
|
+
|
|
222
|
+
## Related
|
|
223
|
+
|
|
224
|
+
- [gograph](https://github.com/shvmgyl15/gograph) — Go codebase indexer
|
|
225
|
+
- [tsgraph](https://github.com/shvmgyl15/tsgraph) — TypeScript/React/Next.js indexer
|
|
226
|
+
- [pygraph](https://github.com/shvmgyl15/pygraph) — Python/Flask codebase indexer
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# codegraph — Multi-language Workspace Code Graph
|
|
2
|
+
|
|
3
|
+
## Vision
|
|
4
|
+
|
|
5
|
+
`codegraph` is a thin orchestration layer that sits at the root of a multi-language,
|
|
6
|
+
multi-repository workspace (monorepo or submodule-based). It:
|
|
7
|
+
|
|
8
|
+
1. **Auto-discovers** every service, frontend, gateway, and library in the workspace
|
|
9
|
+
2. **Orchestrates builds** by shelling out to language-specific tools (`gograph`,
|
|
10
|
+
`tsgraph`, `pygraph`) in each entry's directory
|
|
11
|
+
3. **Merges** all per-entry `graph.json` outputs into a single unified graph
|
|
12
|
+
4. **Exposes a single MCP server** with tools that can query any symbol in any
|
|
13
|
+
service, regardless of language
|
|
14
|
+
|
|
15
|
+
### Design principles
|
|
16
|
+
|
|
17
|
+
- **Language-agnostic** — no language is special. All entries are equal in the schema.
|
|
18
|
+
- **Resilient** — one entry failing to build doesn't block others. Partial results are useful.
|
|
19
|
+
- **Clean state** — single `.codegraph/` output directory. `codegraph clean` removes everything.
|
|
20
|
+
- **User-enriched** — auto-detection is a best-effort default. The user overrides via `codegraph.jsonc`.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Completed
|
|
25
|
+
|
|
26
|
+
- [x] Phase 1: Scaffold + Config + Auto-Discovery
|
|
27
|
+
- [x] Phase 2: Merge + Query Engine
|
|
28
|
+
- [x] Phase 3: MCP Server
|
|
29
|
+
- [x] Phase 4: Cross-Service Edges
|
|
30
|
+
- [x] Phase 5: Plugin System + README + OpenCode
|
|
31
|
+
|
|
32
|
+
## Phase 6: Performance + Install/Uninstall Scripts
|
|
33
|
+
|
|
34
|
+
### Batch A — Performance fixes
|
|
35
|
+
|
|
36
|
+
MCP was slow because the full graph was deserialized and indexed on every tool call.
|
|
37
|
+
Build was slow because entries were built sequentially with no output.
|
|
38
|
+
|
|
39
|
+
- [x] A1: Cache WorkspaceQuery in MCP server by root path (loaded once per session)
|
|
40
|
+
- [x] A2: Return duration_ms in every MCP tool response
|
|
41
|
+
- [x] A3: Parallelize builds with ThreadPoolExecutor (max_workers=4)
|
|
42
|
+
- [x] A4: Print per-entry build progress with timing
|
|
43
|
+
- [x] A5: Improve `--root` error message (suggest where graph was actually built)
|
|
44
|
+
|
|
45
|
+
### Batch B — Install/Uninstall scripts (from git source, never PyPI/npm)
|
|
46
|
+
|
|
47
|
+
- [x] B1: `scripts/install.sh` — clone/build all 4 tools from git source, install to ~/.local/bin
|
|
48
|
+
- [x] B2: `scripts/uninstall.sh` — remove all tool binaries, .*graph/ output dirs, venvs, caches
|
|
49
|
+
|
|
50
|
+
### Batch C — README rewrite
|
|
51
|
+
|
|
52
|
+
- [x] C1: Replace `pip install` with `git clone + scripts/install.sh`
|
|
53
|
+
- [x] C2: Document `--root` clearly (workspace root, not query scope)
|
|
54
|
+
- [x] C3: Add troubleshooting section for performance
|
|
55
|
+
- [x] C4: Add uninstall instructions
|
|
56
|
+
- [x] C5: Run tests + lint, commit, push
|