Skip to content

Commit e9b3cf8

Browse files
authored
Add IDE-style semantic navigation for agents (#155)
* Add workspace symbol lookup surfaces * Add type hierarchy and implementation lookup * Add bounded call hierarchy navigation * Add safe semantic rename previews * Add refactor evidence planning workflow * Address semantic navigation review findings * Address final semantic navigation review findings * Bound semantic implementation diagnostics * Cover composed symbol filters and overload identity * Assert overload implementation ownership * Fix deterministic workspace symbol ranking * Cache sorted call hierarchy adjacency * Use deterministic call hierarchy ordering
1 parent fad8113 commit e9b3cf8

83 files changed

Lines changed: 10177 additions & 87 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,18 @@ Use Codegraph alongside text search and compilers: text search finds exact strin
3131

3232
## What you can do
3333

34-
| Question | Start here | What comes back |
35-
| --------------------------------------- | ----------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
36-
| "Where should I start in this repo?" | `codegraph orient --root . --budget small --pretty` | Central modules, a bounded tree, and copyable follow-ups |
37-
| "How does this feature work?" | `codegraph explore "<question>" --root . --pretty` | Ranked anchors, source packets, dependency paths, blast radius, and likely tests |
38-
| "What could this change break?" | `codegraph review --base HEAD --head WORKTREE --summary` | Changed symbols, risk signals, candidate tests, duplicate leads, and review tasks |
39-
| "What depends on this file?" | `codegraph rdeps src/file.ts --json` | Reverse dependencies from the resolved project graph |
40-
| "Where is this symbol defined or used?" | `codegraph goto <file> <line> <column>` and `codegraph refs ...` | Semantic definitions and references across supported languages |
41-
| "Is the architecture drifting?" | `codegraph drift ./src --base origin/main --head HEAD --pretty` | New cycles, hotspot changes, unresolved imports, API changes, and graph deltas |
42-
| "Where is code duplicated?" | `codegraph duplicates ./src --min-confidence medium` | Ranked exact and near-duplicate groups with locations and confidence |
43-
| "Can another tool consume the graph?" | `codegraph graph --root . ./src --compact-json --output codegraph.json` | JSON, Mermaid, DOT, or SQLite output |
34+
| Question | Start here | What comes back |
35+
| -------------------------------------------- | ----------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
36+
| "Where should I start in this repo?" | `codegraph orient --root . --budget small --pretty` | Central modules, a bounded tree, and copyable follow-ups |
37+
| "How does this feature work?" | `codegraph explore "<question>" --root . --pretty` | Ranked anchors, source packets, dependency paths, blast radius, and likely tests |
38+
| "What could this change break?" | `codegraph review --base HEAD --head WORKTREE --summary` | Changed symbols, risk signals, candidate tests, duplicate leads, and review tasks |
39+
| "What depends on this file?" | `codegraph rdeps src/file.ts --json` | Reverse dependencies from the resolved project graph |
40+
| "Where is this symbol defined or used?" | `codegraph goto <file> <line> <column>` and `codegraph refs ...` | Semantic definitions and references across supported languages |
41+
| "Which declaration matches this name?" | `codegraph symbols "CodeReviewSession" --root . --pretty` | Ranked symbols with portable handles, exact ranges, provenance, and omissions |
42+
| "What evidence do I need before a refactor?" | `codegraph refactor-plan <symbol-handle> --pretty` | References, call and type relationships, candidate tests, omissions, and copyable follow-ups |
43+
| "Is the architecture drifting?" | `codegraph drift ./src --base origin/main --head HEAD --pretty` | New cycles, hotspot changes, unresolved imports, API changes, and graph deltas |
44+
| "Where is code duplicated?" | `codegraph duplicates ./src --min-confidence medium` | Ranked exact and near-duplicate groups with locations and confidence |
45+
| "Can another tool consume the graph?" | `codegraph graph --root . ./src --compact-json --output codegraph.json` | JSON, Mermaid, DOT, or SQLite output |
4446

4547
Human-readable output uses `--pretty` or `--summary`. JSON, MCP tools, and library APIs preserve stable fields, ranges, handles, reasons, confidence, and omission counts for automation.
4648

codegraph-skill/codegraph/SKILL.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,31 @@ Use `--root` to define the boundary for config lookup, cache scope, path confine
4343

4444
- answer a question with bounded evidence: `codegraph explore "how does auth reach db?" --root . --pretty`
4545
- find a ranked anchor: `codegraph search "auth user" --json`
46+
- resolve a known symbol identity: `codegraph symbols "CodeReviewSession" --root . --pretty`
4647
- explain a known target: `codegraph explain <file|symbol|sql-object|handle>`
4748
- retrieve bounded indexed context: `codegraph packet get <file|symbol|sql-object|handle> --pretty`
4849
- read current disk content: `codegraph file <path> --offset 1 --limit 200 --pretty`
4950

5051
`explore` returns ranked anchors, bounded packets, dependency paths, blast radius, candidate tests, explicit limits, omission counts, and copyable follow-ups. Hybrid search is code-first by default; search, explain, explore, and review output preserve analysis labels so reduced or mixed runs remain visible.
5152

53+
Use `symbols` instead of hybrid `search` when only declarations should compete. It supports `--kind <kind,...>`, `--exported`, `--include-imports`, project-relative `--file-glob`, and `--limit <0-500>`; imports default off, and only named/default aliases that resolve to concrete declarations are returned.
54+
55+
Use the portable callable handle from `symbols` with `codegraph callers <handle>` or `codegraph callees <handle>`. Depth defaults to 1 and caps at 5, the symbol limit defaults to 100 and caps at 500, JSON is the default, and `--pretty` prints grouped exact callsites.
56+
57+
Call hierarchy contains resolved semantic `calls` edges only. `--include-heuristic` is accepted but currently adds no guessed dynamic calls; use `refs` for all references and `deps` or `rdeps` for file relationships.
58+
59+
Use the portable handle from `symbols` with `codegraph supertypes <handle>`, `codegraph subtypes <handle>`, or `codegraph implementations <handle>`. Hierarchy depth defaults to 1 and caps at 10; all result limits default to 100 and cap at 500, and `--pretty` is the concise human-readable form.
60+
61+
Hierarchy results contain only proven indexed `extends` and `implements` relationships. Implementation targets are interfaces, traits, abstract types, and members with proven implementation or override relationships; exact declarations are returned, while overloads, dynamic or structural conformance, unrelated same-name methods, and unresolved external bases are not guessed.
62+
63+
Use `codegraph rename-preview <handle> <new-name> --json` to plan a semantic rename without changing files. Add `--include-comments`, `--include-strings`, or `--include-filenames` only when needed, and use `--max-edits <1-10000>` to bound the plan.
64+
65+
Treat `safe: false`, conflicts, unsafe sites, and omissions as blockers. Eligible exported class, interface, and type filename results are suggestions only; Codegraph has no apply command or tool.
66+
67+
Use `codegraph refactor-plan <handle> --pretty` to compose references, direct callers and callees, hierarchy, implementations, section issues, candidate tests, omissions, and copyable follow-ups from one snapshot. It accepts portable search or workspace-symbol handles and exact internal review or impact symbol handles; add `--rename <new-name>` only when the packet should include the authoritative nested rename preview.
68+
69+
The independent `--max-references`, `--max-callers`, and `--max-hierarchy` bounds accept 0 to 500, and `--include-source` opts reference context into output. Treat `sectionIssues`, omissions, and nested `rename.safe` as authoritative; the packet is read-only and has no apply action.
70+
5271
### Navigate
5372

5473
- dependencies: `codegraph deps <file>`
@@ -111,7 +130,12 @@ Sensitive-file rules:
111130

112131
## MCP and Freshness
113132

114-
If MCP tools are available, prefer them over repeated CLI invocations. Use `explore`, `orient`, `search`, `get_file`, `packet_get`, `goto`, `refs`, `deps`, `rdeps`, `path`, `impact`, `review`, and `query_sqlite`; fall back to the CLI when MCP is unavailable.
133+
If MCP tools are available, prefer them over repeated CLI invocations. Use `explore`, `orient`, `workspace_symbols`, `search`, `get_file`, `packet_get`, `goto`, `refs`, `rename_preview`, `refactor_plan`, `callers`, `callees`, `deps`, `rdeps`, `path`, `impact`, `review`, and `query_sqlite`; fall back to the CLI when MCP is unavailable.
134+
Use `refactor_plan` with flat `handle`, optional `renameTo`, independent optional `maxReferences`, `maxCallers`, and `maxHierarchy` bounds from 0 to 500, and optional `includeSource`. It reuses the configured server root and one session snapshot, returns portable targets and follow-ups even for exact internal review handles, exposes unsupported implementation sections in `sectionIssues`, preserves nested `rename.safe`, and never writes.
135+
Use `workspace_symbols` for deterministic symbol identities and exact ranges; use `search` when paths, prose, SQL, snippets, or graph evidence should participate.
136+
Use `supertypes`, `subtypes`, and `implementations` with portable symbol handles for repeated hierarchy queries; their schemas are flat and use the same 10-depth and 500-result caps as the CLI.
137+
Use `callers` and `callees` with portable callable handles for repeated call hierarchy queries. Their flat schemas accept `handle`, `depth`, `limit`, and `includeHeuristic`, reuse the MCP freshness gate, and cap depth at 5 and symbols at 500; current results remain semantic-only.
138+
Use `rename_preview` with `handle`, `newName`, optional boolean inclusion fields, and optional `maxEdits`. It remains available in read-only mode, reuses the MCP session, never changes files, and has no apply counterpart.
115139

116140
Keep live and indexed evidence distinct:
117141

docs/agent-workflows.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,46 @@ Orientation returns summary bullets, ranked `focus` targets, a bounded tree, bud
9393
Use `orient --pretty` or MCP `orient` for compact model-readable triage and `orient --json` when follow-up tools need exact focus reasons, limits, or omission counts.
9494
Small orientation packets default to cheap health analysis; use larger budgets only when cycle, unresolved-import, or duplicate counts matter.
9595

96+
## Workspace-symbol identities
97+
98+
Use `symbols` when the question is "which declaration has this identity?" and follow with the returned portable handle. It is deterministic and filterable; use hybrid `search` instead when paths, prose, SQL, snippets, or graph evidence should participate.
99+
100+
```bash
101+
codegraph symbols "CodeReviewSession" --root . --pretty
102+
codegraph symbols "src/session.ts::CodeReviewSession" --json
103+
codegraph explain "<handle-from-symbols>" --json
104+
```
105+
106+
Imports are excluded unless `--include-imports` is explicit. Compose `--kind`, `--exported`, and project-relative `--file-glob` filters to narrow large workspaces; the limit defaults to 50 and caps at 500.
107+
108+
## Read-only rename planning
109+
110+
Resolve the declaration with `symbols`, then pass its portable handle to rename preview:
111+
112+
```bash
113+
codegraph rename-preview "<type-handle-from-symbols>" RenamedService --include-filenames --json
114+
```
115+
116+
Treat `safe: false`, conflicts, unsafe sites, and omitted edits as blockers rather than silently applying a partial plan. Comment and string edits are opt-in low-confidence candidates; eligible exported type filename results are suggestions only, Codegraph never changes files, and no apply command or tool exists.
117+
118+
Repeated library calls should use `previewRenameWithSession` or `tool_previewRename` with one caller-owned `AgentSession`. MCP hosts should use `rename_preview`, which stays available in read-only mode and reuses the server session.
119+
120+
## Search or review handoff to a refactor plan
121+
122+
Keep the exact symbol handle returned by search or the changed-symbol handle returned by review or impact, then pass it directly to `refactor-plan`:
123+
124+
```bash
125+
codegraph search "service dispatch" --mode symbol --json
126+
codegraph refactor-plan "<exact-handle-from-search>" --max-references 200 --pretty
127+
128+
codegraph review --base HEAD --head WORKTREE --json
129+
codegraph refactor-plan "<exact-changed-symbol-handle-from-review>" --rename RenamedService --json
130+
```
131+
132+
The packet reuses one snapshot and freshness decision for references, direct calls, hierarchy, implementations, candidate tests, and follow-ups. Review and impact may expose internal symbol handles, but the packet returns a portable target handle and uses it in copyable commands.
133+
134+
Treat nested `rename.safe` as authoritative when `--rename` is present. Limits are independent, omissions remain explicit, source context is opt-in with `--include-source`, and refactor planning never writes or exposes an apply action.
135+
96136
## Search anchors
97137

98138
Use `search` when an agent has a query but no file target or search handle and needs a compact starting point before calling `goto`, `refs`, `deps`, `rdeps`, `chunk`, or later explanation tooling:

docs/benchmarks/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ npm run bench:docs
2020

2121
This command rebuilds stale `dist` output when needed, runs every scenario and both variants serially, requires complete anchor evidence, rewrites `results.example.json` and the generated table below, and prints the median table. The fixtures are local and the run makes no network requests.
2222

23+
### Focused semantic regression fixture
24+
25+
`tests/refactor-plan-performance.test.ts` uses the deterministic TypeScript fixture under `tests/fixtures/refactor-plan-performance`. It records runtime metadata, operation samples for exact workspace lookup, direct and depth-3 calls, hierarchy and implementations, rename preview at 10, 100, and 1000 references, repeated warm plans, and hierarchy-index peak RSS.
26+
27+
The test asserts result structure, one-session and adjacency-cache behavior, plus deliberately generous environment-scoped time and memory ceilings. It is a regression guard, is not part of the checked comparison table below, and does not establish universal latency or scale claims.
28+
2329
## Workflows and metrics
2430

2531
Each checked scenario in [`scenarios.json`](./scenarios.json) defines a local fixture, a task, ordered expected anchors, and the exact steps for both variants. The scenarios cover TypeScript request paths, Python imports, SQL migration and application coupling, and Markdown-to-TypeScript request paths.

0 commit comments

Comments
 (0)