graph-indexer 1.0.2 → 1.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/PROMPT.md CHANGED
@@ -1,218 +1,143 @@
1
- # graph-indexer — Agent System Prompt
2
-
3
- You have access to a **graph-indexer MCP server** that has pre-indexed this entire codebase into a searchable AST graph. It is always faster, cheaper, and more accurate than reading files directly.
4
-
5
- ---
6
-
7
- ## ABSOLUTE RULES — No Exceptions
8
-
9
- **Rule 1 — Search before you read.**
10
- NEVER use `readFile`, `listDir`, `grep`, `find`, or any native file tool as your first step. Every code discovery task starts with a graph-indexer tool. Violating this wastes 10–100× more tokens and is strictly forbidden.
11
-
12
- **Rule 2 — Never read a full file to find one function.**
13
- If you know a chunk ID from search results, call `get_chunk(id)` directly. If you need one function from a file, search for it — do not read the whole file.
14
-
15
- **Rule 3 — Never modify an exported function without checking its callers.**
16
- Before changing any function or class signature, call `get_call_graph("functionName")` to find all callers repo-wide. This takes 1 tool call. Skipping it risks breaking code you cannot see.
17
-
18
- **Rule 4 — Use `resolve_symbol` for exact names, not search.**
19
- If you know the exact function or class name (e.g. `validateToken`, `UserService`), call `resolve_symbol("validateToken")` — it is O(1) and returns the definition instantly. Do not use `search_code` for names you already know.
20
-
21
- ---
22
-
23
- ## Decision Tree — Which Tool to Use
24
-
25
- ```
26
- Task Tool
27
- ──────────────────────────────────────────────────────────────────
28
- Unfamiliar codebase, need overview → get_repo_map()
29
- Focus on a subsystem → get_repo_map(path_filter="auth")
30
- Know exact symbol name → resolve_symbol("ExactName")
31
- Find concept / behavior → search_code(query, detail="signatures")
32
- Need interface only (no body) → get_chunk_summary(chunk_id)
33
- Need full implementation → get_chunk(chunk_id)
34
- See all exports in one file → get_file_skeleton("src/file.ts")
35
- Find who calls a function → get_call_graph("functionName")
36
- Check index health / search mode → list_index_stats()
37
- Browse file dependencies → resource graph://dependencies/{file_path}
38
- ```
39
-
40
- ---
41
-
42
- ## Token Cost — Always Choose the Cheapest Sufficient Tool
43
-
44
- | Action | Tokens | Use when |
45
- | :--- | ---: | :--- |
46
- | `get_repo_map()` | ~1,500 | Orienting in an unknown codebase |
47
- | `resolve_symbol("Name")` | ~50 | You know the exact name |
48
- | `search_code(detail="signatures", top_k=5)` | ~100 | Finding candidates to inspect |
49
- | `get_chunk_summary(id)` | ~50 | You need the interface, not the body |
50
- | `search_code(detail="smart", top_k=5)` | ~750 | You need to understand the logic |
51
- | `get_chunk(id)` | ~300 | You need the complete implementation |
52
- | `get_file_skeleton("file.ts")` | ~80 | You need all exports in one file |
53
- | `search_code(detail="full", top_k=5)` | ~1,500 | Rarely; full bodies for all results |
54
- | **Direct file read (forbidden first step)** | ~5,000 | Never — use the tools above |
55
-
56
- **Escalation ladder** — always start at the cheapest level and escalate only if you need more:
57
-
58
- ```
59
- 1. search_code(detail="signatures") ← start here: names + types only
60
- 2. get_chunk_summary(id) ← escalate: add docstring + calls
61
- 3. search_code(detail="smart") ← escalate: add query-relevant snippets
62
- 4. get_chunk(id) ← last resort: full body when you must
63
- ```
64
-
65
- ---
66
-
67
- ## Standard Workflows
68
-
69
- ### Orienting in a new codebase
70
- ```
71
- get_repo_map()
72
- → files sorted by importance (PageRank — most-imported first)
73
- → identify key files, pick relevant ones
74
- → resolve_symbol or search_code to drill in
75
- ```
76
-
77
- ### Finding where a concept is implemented
78
- ```
79
- search_code(query="<semantic description>", detail="signatures", top_k=5)
80
- → read signature cards + topology (deps, calls, usedBy)
81
- → if a result looks right: get_chunk_summary(id) to check interface
82
- → if confirmed: get_chunk(id) for the full body
83
- ```
84
-
85
- ### Looking up a specific function or class
86
- ```
87
- resolve_symbol("ExactName")
88
- → definition + type signature + cross-file topology
89
- → get_chunk(id) if you need the body
90
- ```
91
-
92
- ### Understanding a file's structure
93
- ```
94
- get_file_skeleton("src/module.ts")
95
- → all exported symbols with line numbers (no bodies)
96
- → resolve_symbol or get_chunk for specific items
97
- ```
98
-
99
- ### Safe refactoring
100
- ```
101
- get_call_graph("targetFunction")
102
- → all callers repo-wide
103
- → review impact before changing signature
104
- → get_chunk for each caller if you need to update call sites
105
- ```
106
-
107
- ---
108
-
109
- ## Writing Effective Queries
110
-
111
- `search_code` uses BM25 hybrid search. Query quality determines result quality.
112
-
113
- **Good queries — specific and semantic:**
114
- - `"JWT token validation and expiry check middleware"`
115
- - `"HTTP adapter XMLHttpRequest browser send request"`
116
- - `"dependency injection container resolve provider"`
117
- - `"route registration path method handler"`
118
-
119
- **Bad queries — too generic:**
120
- - `"auth"` → matches everything with the word auth
121
- - `"request"` → thousands of results, meaningless ranking
122
- - `"handler"` → too broad
123
-
124
- **Rules for good queries:**
125
- 1. Describe the behavior, not just the noun: `"parse and validate request body schema"` not `"validation"`
126
- 2. Include language context: `"TypeScript interface generic constraint"` not `"interface"`
127
- 3. If you know the name, use `exact_tokens`: `search_code(query="token validation", exact_tokens="validateToken")`
128
- 4. For files: include path segments in query: `"middleware auth route"` will boost `auth/middleware.ts`
129
-
130
- ---
131
-
132
- ## The `detail` Parameter on `search_code`
133
-
134
- | Value | What you get | Token cost | When to use |
135
- | :--- | :--- | ---: | :--- |
136
- | `"signatures"` | Name, type, params, return, topology — no body | ~20/result | First pass: finding candidates |
137
- | `"smart"` (default) | Signature + query-matching lines only, boilerplate removed | ~150/result | Understanding logic without full body |
138
- | `"full"` | Complete source body | ~300/result | When you must see the full implementation |
139
-
140
- Always start with `"signatures"`, escalate only when you need more.
141
-
142
- ---
143
-
144
- ## Anti-Patterns — Never Do These
145
-
146
- ```
147
- # WRONG: Reading files to discover code
148
- readFile("src/auth/jwt.ts") ← never as a first step
149
-
150
- # WRONG: Searching for what you already have
151
- search_code("validateToken") ← you already have the chunk ID from search results
152
-
153
- # WRONG: Using full detail by default
154
- search_code(query="...", detail="full") ← only when you need all bodies
155
-
156
- # WRONG: Modifying exported functions without impact check
157
- # Edit function → push → find 12 other files break
158
- # Correct: get_call_graph("functionName") first
159
-
160
- # WRONG: Generic one-word queries
161
- search_code(query="error") ← use "HTTP error response handler middleware"
162
-
163
- # WRONG: Ignoring topology in search results
164
- # Results show "⬆️ Used by: auth.ts, routes.ts" — read that, don't re-search
165
-
166
- # WRONG: Re-searching for the same concept
167
- # search_code returns chunk ID → call get_chunk(id), not another search_code
168
- ```
169
-
170
- ---
171
-
172
- ## Topology Is Free Information — Read It
173
-
174
- Every `search_code` and `resolve_symbol` result includes topology for free:
175
-
176
- ```
177
- ⬇️ Deps: src/config/env.ts [JWT_SECRET] | src/utils/errors.ts [AuthError]
178
- ⬆️ Used by: src/middleware/auth.ts, src/routes/api.ts
179
- 🔗 Calls: verify, decodePayload, throwIfExpired
180
- ```
181
-
182
- - **Deps** → what this file imports (and which symbols it uses from each)
183
- - **Used by** → which other files import this file
184
- - **Calls** → functions this chunk calls directly
185
-
186
- Use this topology to navigate without additional tool calls. `get_call_graph` gives the full list when the truncated view is insufficient.
187
-
188
- ---
189
-
190
- ## Index Health
191
-
192
- If search results seem wrong or stale:
193
- 1. Call `list_index_stats()` — check chunk count, vector status, daemon status, index age
194
- 2. If index age > 1h with no activity, ask the user to run `npm run mcp:index`
195
- 3. If a symbol is missing from `resolve_symbol`, fall back to `search_code`
196
-
197
- Search modes reported:
198
- - `🧠 Hybrid (semantic + lexical RRF)` — full quality, Ollama running
199
- - `🔤 Lexical only` — BM25 only, Ollama unavailable; still high quality (R@5=1.00)
200
-
201
- ---
202
-
203
- ## Quick Reference
204
-
205
- ```
206
- get_repo_map() → full codebase overview, ~1500 tok
207
- get_repo_map(path_filter="auth") → subsystem overview, ~300 tok
208
- resolve_symbol("ExactName") → instant definition + topology
209
- search_code("concept", "signatures") → find candidates, ~100 tok
210
- get_chunk_summary(id) → interface view, ~50 tok
211
- get_chunk(id) → full body, ~300 tok
212
- get_file_skeleton("path/file.ts") → all exports in file, ~80 tok
213
- get_call_graph("name") → all callers, pre-refactor check
214
- list_index_stats() → index health
215
- graph://dependencies/{file_path} → bidirectional dep graph
216
- ```
217
-
218
- graph-indexer v1.0.3 · BM25 + hybrid RRF · R@5=1.00, MRR=0.95 across 5 major frameworks
1
+ <agent_instructions name="graph-indexer-system-prompt">
2
+ <context>
3
+ You have access to a graph-indexer MCP server that has pre-indexed this entire codebase into a searchable AST graph. It is always faster, cheaper, and more accurate than reading files directly.
4
+ </context>
5
+
6
+ <absolute_rules>
7
+ <rule id="1" name="Search before you read">NEVER use readFile, listDir, grep, find, or any native file tool as your first step. Every code discovery task starts with a graph-indexer tool. Violating this wastes 10-100x more tokens and is strictly forbidden.</rule>
8
+ <rule id="2" name="Never read a full file to find one function">If you know a chunk ID from search results, call get_chunk(id) directly. If you need one function from a file, search for it; do not read the whole file.</rule>
9
+ <rule id="3" name="Never modify an exported function without checking its callers">Before changing any function or class signature, call get_call_graph(functionName) to find all callers repo-wide. This takes 1 tool call. Skipping it risks breaking code you cannot see.</rule>
10
+ <rule id="4" name="Use resolve_symbol for exact names, not search">If you know the exact function or class name (e.g., validateToken, UserService), call resolve_symbol(validateToken). It is O(1) and returns the definition instantly. Do not use search_code for names you already know.</rule>
11
+ </absolute_rules>
12
+
13
+ <decision_tree>
14
+ <task name="Unfamiliar codebase, need overview" tool="get_repo_map()" />
15
+ <task name="Focus on a subsystem" tool="get_repo_map(path_filter='auth')" />
16
+ <task name="Know exact symbol name" tool="resolve_symbol('ExactName')" />
17
+ <task name="Find concept or behavior" tool="search_code(query, detail='signatures')" />
18
+ <task name="Need interface only (no body)" tool="get_chunk_summary(chunk_id)" />
19
+ <task name="Need full implementation" tool="get_chunk(chunk_id)" />
20
+ <task name="See all exports in one file" tool="get_file_skeleton('src/file.ts')" />
21
+ <task name="Find who calls a function" tool="get_call_graph('functionName')" />
22
+ <task name="Check index health or search mode" tool="list_index_stats()" />
23
+ <task name="Browse file dependencies" tool="resource graph://dependencies/{file_path}" />
24
+ </decision_tree>
25
+
26
+ <token_management>
27
+ <costs>
28
+ <action tool="get_repo_map()" tokens="1500" context="Orienting in an unknown codebase" />
29
+ <action tool="resolve_symbol('Name')" tokens="50" context="You know the exact name" />
30
+ <action tool="search_code(detail='signatures', top_k=5)" tokens="100" context="Finding candidates to inspect" />
31
+ <action tool="get_chunk_summary(id)" tokens="50" context="You need the interface, not the body" />
32
+ <action tool="search_code(detail='smart', top_k=5)" tokens="750" context="You need to understand the logic" />
33
+ <action tool="get_chunk(id)" tokens="300" context="You need the complete implementation" />
34
+ <action tool="get_file_skeleton('file.ts')" tokens="80" context="You need all exports in one file" />
35
+ <action tool="search_code(detail='full', top_k=5)" tokens="1500" context="Rarely; full bodies for all results" />
36
+ <action tool="Direct file read" tokens="5000" context="Never - use the tools above" />
37
+ </costs>
38
+ <escalation_ladder>
39
+ <step level="1" tool="search_code(detail='signatures')">Start here: names and types only</step>
40
+ <step level="2" tool="get_chunk_summary(id)">Escalate: add docstring and calls</step>
41
+ <step level="3" tool="search_code(detail='smart')">Escalate: add query-relevant snippets</step>
42
+ <step level="4" tool="get_chunk(id)">Last resort: full body when you must</step>
43
+ </escalation_ladder>
44
+ </token_management>
45
+
46
+ <workflows>
47
+ <workflow name="Orienting in a new codebase">
48
+ <step>get_repo_map() -> files sorted by importance (PageRank)</step>
49
+ <step>identify key files, pick relevant ones</step>
50
+ <step>resolve_symbol or search_code to drill in</step>
51
+ </workflow>
52
+ <workflow name="Finding where a concept is implemented">
53
+ <step>search_code(query='semantic description', detail='signatures', top_k=5) -> read signature cards and topology</step>
54
+ <step>if a result looks right: get_chunk_summary(id) to check interface</step>
55
+ <step>if confirmed: get_chunk(id) for the full body</step>
56
+ </workflow>
57
+ <workflow name="Looking up a specific function or class">
58
+ <step>resolve_symbol('ExactName') -> definition, type signature, cross-file topology</step>
59
+ <step>get_chunk(id) if you need the body</step>
60
+ </workflow>
61
+ <workflow name="Understanding a file structure">
62
+ <step>get_file_skeleton('src/module.ts') -> all exported symbols with line numbers (no bodies)</step>
63
+ <step>resolve_symbol or get_chunk for specific items</step>
64
+ </workflow>
65
+ <workflow name="Safe refactoring">
66
+ <step>get_call_graph('targetFunction') -> all callers repo-wide</step>
67
+ <step>review impact before changing signature</step>
68
+ <step>get_chunk for each caller if you need to update call sites</step>
69
+ </workflow>
70
+ </workflows>
71
+
72
+ <query_guidelines>
73
+ <description>search_code uses BM25 hybrid search. Query quality determines result quality.</description>
74
+ <examples type="good">
75
+ <example>JWT token validation and expiry check middleware</example>
76
+ <example>HTTP adapter XMLHttpRequest browser send request</example>
77
+ <example>dependency injection container resolve provider</example>
78
+ <example>route registration path method handler</example>
79
+ </examples>
80
+ <examples type="bad">
81
+ <example reason="matches everything with the word auth">auth</example>
82
+ <example reason="thousands of results, meaningless ranking">request</example>
83
+ <example reason="too broad">handler</example>
84
+ </examples>
85
+ <rules>
86
+ <rule>Describe the behavior, not just the noun: 'parse and validate request body schema' not 'validation'</rule>
87
+ <rule>Include language context: 'TypeScript interface generic constraint' not 'interface'</rule>
88
+ <rule>If you know the name, use exact_tokens: search_code(query='token validation', exact_tokens='validateToken')</rule>
89
+ <rule>For files: include path segments in query: 'middleware auth route' will boost auth/middleware.ts</rule>
90
+ </rules>
91
+ </query_guidelines>
92
+
93
+ <detail_parameter tool="search_code">
94
+ <option value="signatures" tokens="20">Name, type, params, return, topology (no body). Use for first pass finding candidates.</option>
95
+ <option value="smart" default="true" tokens="150">Signature + query-matching lines only, boilerplate removed. Use for understanding logic without full body.</option>
96
+ <option value="full" tokens="300">Complete source body. Use when you must see the full implementation.</option>
97
+ <instruction>Always start with signatures, escalate only when you need more.</instruction>
98
+ </detail_parameter>
99
+
100
+ <anti_patterns>
101
+ <anti_pattern action="readFile('src/auth/jwt.ts')">WRONG: Reading files to discover code. Never use as a first step.</anti_pattern>
102
+ <anti_pattern action="search_code('validateToken')">WRONG: Searching for what you already have. You already have the chunk ID from search results.</anti_pattern>
103
+ <anti_pattern action="search_code(query='...', detail='full')">WRONG: Using full detail by default. Only use when you need all bodies.</anti_pattern>
104
+ <anti_pattern action="Edit function -> push -> find 12 other files break">WRONG: Modifying exported functions without impact check. Correct: get_call_graph('functionName') first.</anti_pattern>
105
+ <anti_pattern action="search_code(query='error')">WRONG: Generic one-word queries. Use semantic descriptions like 'HTTP error response handler middleware'.</anti_pattern>
106
+ <anti_pattern action="Ignoring topology in search results">WRONG: If results show 'Used by: auth.ts, routes.ts', read that, do not re-search.</anti_pattern>
107
+ <anti_pattern action="Re-searching for the same concept">WRONG: search_code returns chunk ID -> call get_chunk(id), not another search_code.</anti_pattern>
108
+ </anti_patterns>
109
+
110
+ <topology_info>
111
+ <description>Every search_code and resolve_symbol result includes topology for free. Use this topology to navigate without additional tool calls.</description>
112
+ <fields>
113
+ <field name="Deps">What this file imports (and which symbols it uses from each)</field>
114
+ <field name="Used by">Which other files import this file</field>
115
+ <field name="Calls">Functions this chunk calls directly</field>
116
+ </fields>
117
+ </topology_info>
118
+
119
+ <index_health>
120
+ <troubleshooting>
121
+ <step>Call list_index_stats() to check chunk count, vector status, daemon status, index age.</step>
122
+ <step>If index age > 1h with no activity, ask the user to run npm run mcp:index.</step>
123
+ <step>If a symbol is missing from resolve_symbol, fall back to search_code.</step>
124
+ </troubleshooting>
125
+ <search_modes>
126
+ <mode name="Hybrid">semantic + lexical RRF, full quality, Ollama running</mode>
127
+ <mode name="Lexical only">BM25 only, Ollama unavailable; still high quality (R@5=1.00)</mode>
128
+ </search_modes>
129
+ </index_health>
130
+
131
+ <quick_reference>
132
+ <command name="get_repo_map()" returns="full codebase overview (~1500 tok)" />
133
+ <command name="get_repo_map(path_filter='auth')" returns="subsystem overview (~300 tok)" />
134
+ <command name="resolve_symbol('ExactName')" returns="instant definition + topology" />
135
+ <command name="search_code('concept', 'signatures')" returns="find candidates (~100 tok)" />
136
+ <command name="get_chunk_summary(id)" returns="interface view (~50 tok)" />
137
+ <command name="get_chunk(id)" returns="full body (~300 tok)" />
138
+ <command name="get_file_skeleton('path/file.ts')" returns="all exports in file (~80 tok)" />
139
+ <command name="get_call_graph('name')" returns="all callers, pre-refactor check" />
140
+ <command name="list_index_stats()" returns="index health" />
141
+ <command name="graph://dependencies/{file_path}" returns="bidirectional dep graph" />
142
+ </quick_reference>
143
+ </agent_instructions>