ts-knowledge-graph 0.1.2 → 0.1.4

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.
Files changed (255) hide show
  1. package/README.md +74 -34
  2. package/contribs/web_visualisation/README.md +28 -0
  3. package/contribs/web_visualisation/web/css/style.css +104 -0
  4. package/contribs/web_visualisation/web/data/.gitignore +1 -0
  5. package/contribs/web_visualisation/web/data/kind_descriptions.js +38 -0
  6. package/contribs/web_visualisation/web/index.html +20 -4
  7. package/contribs/web_visualisation/web/js/app.js +581 -35
  8. package/contribs/web_visualisation/web/tsconfig.json +18 -0
  9. package/contribs/web_visualisation/web/types/app_globals.d.ts +146 -0
  10. package/dist/benchmark/benchmark_stats.d.ts +41 -0
  11. package/dist/benchmark/benchmark_stats.d.ts.map +1 -0
  12. package/dist/benchmark/benchmark_stats.js +61 -0
  13. package/dist/benchmark/benchmark_stats.js.map +1 -0
  14. package/dist/benchmark/node_benchmark.d.ts +78 -0
  15. package/dist/benchmark/node_benchmark.d.ts.map +1 -0
  16. package/dist/benchmark/node_benchmark.js +112 -0
  17. package/dist/benchmark/node_benchmark.js.map +1 -0
  18. package/dist/cli.d.ts.map +1 -1
  19. package/dist/cli.js +10 -2
  20. package/dist/cli.js.map +1 -1
  21. package/dist/commands/benchmark_command.d.ts +11 -0
  22. package/dist/commands/benchmark_command.d.ts.map +1 -0
  23. package/dist/commands/benchmark_command.js +91 -0
  24. package/dist/commands/benchmark_command.js.map +1 -0
  25. package/dist/commands/blast_radius_command.js +1 -1
  26. package/dist/commands/blast_radius_command.js.map +1 -1
  27. package/dist/commands/cost_command.d.ts +13 -0
  28. package/dist/commands/cost_command.d.ts.map +1 -0
  29. package/dist/commands/cost_command.js +122 -0
  30. package/dist/commands/cost_command.js.map +1 -0
  31. package/dist/commands/{load.d.ts → enrich_command.d.ts} +3 -2
  32. package/dist/commands/enrich_command.d.ts.map +1 -0
  33. package/dist/commands/enrich_command.js +62 -0
  34. package/dist/commands/enrich_command.js.map +1 -0
  35. package/dist/commands/hotspots_command.d.ts +7 -0
  36. package/dist/commands/hotspots_command.d.ts.map +1 -0
  37. package/dist/commands/hotspots_command.js +67 -0
  38. package/dist/commands/hotspots_command.js.map +1 -0
  39. package/dist/commands/install_command.d.ts +2 -3
  40. package/dist/commands/install_command.d.ts.map +1 -1
  41. package/dist/commands/install_command.js +7 -8
  42. package/dist/commands/install_command.js.map +1 -1
  43. package/dist/commands/load_command.d.ts.map +1 -1
  44. package/dist/commands/load_command.js +2 -0
  45. package/dist/commands/load_command.js.map +1 -1
  46. package/dist/commands/verify_command.d.ts +8 -0
  47. package/dist/commands/verify_command.d.ts.map +1 -0
  48. package/dist/commands/verify_command.js +57 -0
  49. package/dist/commands/verify_command.js.map +1 -0
  50. package/dist/commands/web_command.d.ts +27 -0
  51. package/dist/commands/web_command.d.ts.map +1 -1
  52. package/dist/commands/web_command.js +109 -3
  53. package/dist/commands/web_command.js.map +1 -1
  54. package/dist/enrich/cpu_profile.d.ts +127 -0
  55. package/dist/enrich/cpu_profile.d.ts.map +1 -0
  56. package/dist/enrich/cpu_profile.js +97 -0
  57. package/dist/enrich/cpu_profile.js.map +1 -0
  58. package/dist/enrich/runtime_enricher.d.ts +56 -0
  59. package/dist/enrich/runtime_enricher.d.ts.map +1 -0
  60. package/dist/enrich/runtime_enricher.js +80 -0
  61. package/dist/enrich/runtime_enricher.js.map +1 -0
  62. package/dist/enrich/runtime_join.d.ts +100 -0
  63. package/dist/enrich/runtime_join.d.ts.map +1 -0
  64. package/dist/enrich/runtime_join.js +227 -0
  65. package/dist/enrich/runtime_join.js.map +1 -0
  66. package/dist/extract/api_extractor.d.ts +24 -0
  67. package/dist/extract/api_extractor.d.ts.map +1 -0
  68. package/dist/extract/api_extractor.js +71 -0
  69. package/dist/extract/api_extractor.js.map +1 -0
  70. package/dist/extract/config_extractor.d.ts +22 -0
  71. package/dist/extract/config_extractor.d.ts.map +1 -0
  72. package/dist/extract/config_extractor.js +61 -0
  73. package/dist/extract/config_extractor.js.map +1 -0
  74. package/dist/extract/endpoint_extractor.d.ts +36 -0
  75. package/dist/extract/endpoint_extractor.d.ts.map +1 -0
  76. package/dist/extract/endpoint_extractor.js +117 -0
  77. package/dist/extract/endpoint_extractor.js.map +1 -0
  78. package/dist/extract/graph_builder.d.ts +8 -0
  79. package/dist/extract/graph_builder.d.ts.map +1 -1
  80. package/dist/extract/graph_builder.js +23 -1
  81. package/dist/extract/graph_builder.js.map +1 -1
  82. package/dist/extract/node_id.d.ts +16 -0
  83. package/dist/extract/node_id.d.ts.map +1 -1
  84. package/dist/extract/node_id.js +22 -0
  85. package/dist/extract/node_id.js.map +1 -1
  86. package/dist/extract/scope_resolver.d.ts +22 -0
  87. package/dist/extract/scope_resolver.d.ts.map +1 -0
  88. package/dist/extract/scope_resolver.js +53 -0
  89. package/dist/extract/scope_resolver.js.map +1 -0
  90. package/dist/extract/semantic_extractor.d.ts +25 -0
  91. package/dist/extract/semantic_extractor.d.ts.map +1 -1
  92. package/dist/extract/semantic_extractor.js +96 -2
  93. package/dist/extract/semantic_extractor.js.map +1 -1
  94. package/dist/extract/structural_extractor.d.ts +6 -0
  95. package/dist/extract/structural_extractor.d.ts.map +1 -1
  96. package/dist/extract/structural_extractor.js +22 -12
  97. package/dist/extract/structural_extractor.js.map +1 -1
  98. package/dist/project_root.d.ts +7 -0
  99. package/dist/project_root.d.ts.map +1 -0
  100. package/dist/project_root.js +9 -0
  101. package/dist/project_root.js.map +1 -0
  102. package/dist/query/graph_query.d.ts +234 -0
  103. package/dist/query/graph_query.d.ts.map +1 -1
  104. package/dist/query/graph_query.js +522 -11
  105. package/dist/query/graph_query.js.map +1 -1
  106. package/dist/schema/edge.d.ts +40 -5
  107. package/dist/schema/edge.d.ts.map +1 -1
  108. package/dist/schema/edge.js +70 -0
  109. package/dist/schema/edge.js.map +1 -1
  110. package/dist/schema/node.d.ts +20 -5
  111. package/dist/schema/node.d.ts.map +1 -1
  112. package/dist/schema/node.js +36 -0
  113. package/dist/schema/node.js.map +1 -1
  114. package/dist/schema/runtime_manifest.d.ts +36 -0
  115. package/dist/schema/runtime_manifest.d.ts.map +1 -0
  116. package/dist/schema/runtime_manifest.js +23 -0
  117. package/dist/schema/runtime_manifest.js.map +1 -0
  118. package/dist/store/kuzu_store.d.ts +46 -0
  119. package/dist/store/kuzu_store.d.ts.map +1 -1
  120. package/dist/store/kuzu_store.js +95 -5
  121. package/dist/store/kuzu_store.js.map +1 -1
  122. package/dist/verify/project_verifier.d.ts +85 -0
  123. package/dist/verify/project_verifier.d.ts.map +1 -0
  124. package/dist/verify/project_verifier.js +138 -0
  125. package/dist/verify/project_verifier.js.map +1 -0
  126. package/{skills/ts-knowledge-graph → dotclaude_folder/skills/code-graph-query}/SKILL.md +2 -2
  127. package/package.json +86 -7
  128. package/.env-sample +0 -34
  129. package/dist/agent/agent-tools.d.ts +0 -13
  130. package/dist/agent/agent-tools.d.ts.map +0 -1
  131. package/dist/agent/agent-tools.js +0 -153
  132. package/dist/agent/agent-tools.js.map +0 -1
  133. package/dist/agent/agent_tools.d.ts +0 -13
  134. package/dist/agent/agent_tools.d.ts.map +0 -1
  135. package/dist/agent/agent_tools.js +0 -153
  136. package/dist/agent/agent_tools.js.map +0 -1
  137. package/dist/agent/code-editor.d.ts +0 -18
  138. package/dist/agent/code-editor.d.ts.map +0 -1
  139. package/dist/agent/code-editor.js +0 -43
  140. package/dist/agent/code-editor.js.map +0 -1
  141. package/dist/agent/code_editor.d.ts +0 -18
  142. package/dist/agent/code_editor.d.ts.map +0 -1
  143. package/dist/agent/code_editor.js +0 -43
  144. package/dist/agent/code_editor.js.map +0 -1
  145. package/dist/agent/optimizer-agent.d.ts +0 -30
  146. package/dist/agent/optimizer-agent.d.ts.map +0 -1
  147. package/dist/agent/optimizer-agent.js +0 -97
  148. package/dist/agent/optimizer-agent.js.map +0 -1
  149. package/dist/agent/optimizer_agent.d.ts +0 -30
  150. package/dist/agent/optimizer_agent.d.ts.map +0 -1
  151. package/dist/agent/optimizer_agent.js +0 -97
  152. package/dist/agent/optimizer_agent.js.map +0 -1
  153. package/dist/agent/verifier.d.ts +0 -9
  154. package/dist/agent/verifier.d.ts.map +0 -1
  155. package/dist/agent/verifier.js +0 -19
  156. package/dist/agent/verifier.js.map +0 -1
  157. package/dist/commands/blast-radius.d.ts +0 -5
  158. package/dist/commands/blast-radius.d.ts.map +0 -1
  159. package/dist/commands/blast-radius.js +0 -18
  160. package/dist/commands/blast-radius.js.map +0 -1
  161. package/dist/commands/blast_radius.d.ts +0 -5
  162. package/dist/commands/blast_radius.d.ts.map +0 -1
  163. package/dist/commands/blast_radius.js +0 -18
  164. package/dist/commands/blast_radius.js.map +0 -1
  165. package/dist/commands/calls.d.ts +0 -5
  166. package/dist/commands/calls.d.ts.map +0 -1
  167. package/dist/commands/calls.js +0 -7
  168. package/dist/commands/calls.js.map +0 -1
  169. package/dist/commands/command-helpers.d.ts +0 -15
  170. package/dist/commands/command-helpers.d.ts.map +0 -1
  171. package/dist/commands/command-helpers.js +0 -61
  172. package/dist/commands/command-helpers.js.map +0 -1
  173. package/dist/commands/dead-exports.d.ts +0 -5
  174. package/dist/commands/dead-exports.d.ts.map +0 -1
  175. package/dist/commands/dead-exports.js +0 -7
  176. package/dist/commands/dead-exports.js.map +0 -1
  177. package/dist/commands/dead_exports.d.ts +0 -5
  178. package/dist/commands/dead_exports.d.ts.map +0 -1
  179. package/dist/commands/dead_exports.js +0 -7
  180. package/dist/commands/dead_exports.js.map +0 -1
  181. package/dist/commands/extract.d.ts +0 -8
  182. package/dist/commands/extract.d.ts.map +0 -1
  183. package/dist/commands/extract.js +0 -49
  184. package/dist/commands/extract.js.map +0 -1
  185. package/dist/commands/find.d.ts +0 -5
  186. package/dist/commands/find.d.ts.map +0 -1
  187. package/dist/commands/find.js +0 -7
  188. package/dist/commands/find.js.map +0 -1
  189. package/dist/commands/load.d.ts.map +0 -1
  190. package/dist/commands/load.js +0 -28
  191. package/dist/commands/load.js.map +0 -1
  192. package/dist/commands/neighbors.d.ts +0 -5
  193. package/dist/commands/neighbors.d.ts.map +0 -1
  194. package/dist/commands/neighbors.js +0 -17
  195. package/dist/commands/neighbors.js.map +0 -1
  196. package/dist/commands/optimize.d.ts +0 -6
  197. package/dist/commands/optimize.d.ts.map +0 -1
  198. package/dist/commands/optimize.js +0 -59
  199. package/dist/commands/optimize.js.map +0 -1
  200. package/dist/commands/optimize_command.d.ts +0 -6
  201. package/dist/commands/optimize_command.d.ts.map +0 -1
  202. package/dist/commands/optimize_command.js +0 -59
  203. package/dist/commands/optimize_command.js.map +0 -1
  204. package/dist/commands/references.d.ts +0 -5
  205. package/dist/commands/references.d.ts.map +0 -1
  206. package/dist/commands/references.js +0 -17
  207. package/dist/commands/references.js.map +0 -1
  208. package/dist/commands/web.d.ts +0 -19
  209. package/dist/commands/web.d.ts.map +0 -1
  210. package/dist/commands/web.js +0 -120
  211. package/dist/commands/web.js.map +0 -1
  212. package/dist/commands/who-calls.d.ts +0 -5
  213. package/dist/commands/who-calls.d.ts.map +0 -1
  214. package/dist/commands/who-calls.js +0 -7
  215. package/dist/commands/who-calls.js.map +0 -1
  216. package/dist/commands/who_calls.d.ts +0 -5
  217. package/dist/commands/who_calls.d.ts.map +0 -1
  218. package/dist/commands/who_calls.js +0 -7
  219. package/dist/commands/who_calls.js.map +0 -1
  220. package/dist/extract/graph-builder.d.ts +0 -16
  221. package/dist/extract/graph-builder.d.ts.map +0 -1
  222. package/dist/extract/graph-builder.js +0 -39
  223. package/dist/extract/graph-builder.js.map +0 -1
  224. package/dist/extract/node-id.d.ts +0 -8
  225. package/dist/extract/node-id.d.ts.map +0 -1
  226. package/dist/extract/node-id.js +0 -22
  227. package/dist/extract/node-id.js.map +0 -1
  228. package/dist/extract/project-loader.d.ts +0 -5
  229. package/dist/extract/project-loader.d.ts.map +0 -1
  230. package/dist/extract/project-loader.js +0 -19
  231. package/dist/extract/project-loader.js.map +0 -1
  232. package/dist/extract/semantic-extractor.d.ts +0 -22
  233. package/dist/extract/semantic-extractor.d.ts.map +0 -1
  234. package/dist/extract/semantic-extractor.js +0 -254
  235. package/dist/extract/semantic-extractor.js.map +0 -1
  236. package/dist/extract/structural-extractor.d.ts +0 -18
  237. package/dist/extract/structural-extractor.d.ts.map +0 -1
  238. package/dist/extract/structural-extractor.js +0 -97
  239. package/dist/extract/structural-extractor.js.map +0 -1
  240. package/dist/query/graph-query.d.ts +0 -28
  241. package/dist/query/graph-query.d.ts.map +0 -1
  242. package/dist/query/graph-query.js +0 -93
  243. package/dist/query/graph-query.js.map +0 -1
  244. package/dist/store/jsonl-reader.d.ts +0 -11
  245. package/dist/store/jsonl-reader.d.ts.map +0 -1
  246. package/dist/store/jsonl-reader.js +0 -19
  247. package/dist/store/jsonl-reader.js.map +0 -1
  248. package/dist/store/jsonl-store.d.ts +0 -7
  249. package/dist/store/jsonl-store.d.ts.map +0 -1
  250. package/dist/store/jsonl-store.js +0 -13
  251. package/dist/store/jsonl-store.js.map +0 -1
  252. package/dist/store/kuzu-store.d.ts +0 -14
  253. package/dist/store/kuzu-store.d.ts.map +0 -1
  254. package/dist/store/kuzu-store.js +0 -52
  255. package/dist/store/kuzu-store.js.map +0 -1
package/README.md CHANGED
@@ -25,7 +25,9 @@ Compiler API) rather than a syntax-only parser.
25
25
  ## Graph model
26
26
 
27
27
  **Nodes** — `Module`, `Class`, `Interface`, `TypeAlias`, `Enum`, `Function`,
28
- `Method`, `Property`, `Parameter`, `Variable`, `ExternalModule`.
28
+ `Method`, `Property`, `Parameter`, `Variable`, `ExternalModule`, and the
29
+ system-level `ConfigFlag` (environment variables), `ExternalAPI` (outbound HTTP
30
+ hosts), and `Endpoint` (HTTP routes).
29
31
 
30
32
  **Edges**
31
33
 
@@ -34,9 +36,18 @@ Compiler API) rather than a syntax-only parser.
34
36
  | Structural | `CONTAINS`, `IMPORTS`, `EXPORTS` |
35
37
  | Type | `EXTENDS`, `IMPLEMENTS`, `USES_TYPE`, `RETURNS`, `PARAM_TYPE` |
36
38
  | Behavioral | `CALLS`, `INSTANTIATES`, `OVERRIDES`, `READS`, `WRITES` |
39
+ | System-level | `READS_CONFIG`, `CALLS_EXTERNAL`, `HANDLES` |
37
40
 
38
- The structural layer is cheap and always emitted. The type + behavioral layers
39
- require symbol resolution and are emitted with `--semantic`.
41
+ The structural layer plus the always-on config and outbound-HTTP surfaces
42
+ (`ConfigFlag` / `READS_CONFIG`, `ExternalAPI` / `CALLS_EXTERNAL`) is cheap and
43
+ needs no symbol resolution. The type, behavioral, and endpoint (`Endpoint` /
44
+ `HANDLES`) layers require symbol resolution and are emitted with `--semantic`.
45
+
46
+ `ConfigFlag` nodes come from `process.env.X` reads; `ExternalAPI` nodes from
47
+ `fetch(...)` call sites (one per host); `Endpoint` nodes from route registrations
48
+ like `app.get('/users', handler)`, each with a `HANDLES` edge to the handler
49
+ function. These are the system-level kinds tracked in
50
+ [#31](https://github.com/jeromeetienne/ts_knowledge_graph/issues/31).
40
51
 
41
52
  ## Usage
42
53
 
@@ -69,6 +80,9 @@ npm run dev -- blast-radius <id> --depth 10 # transitive callers (impact set)
69
80
  npm run dev -- references <id> # everything that references a symbol/type
70
81
  npm run dev -- dead-exports # exported symbols with no inbound refs
71
82
  npm run dev -- neighbors <id> # one-hop neighbourhood (in + out)
83
+ npm run dev -- hotspots --by self-time # rank nodes by optimization leverage
84
+ npm run dev -- cost # inclusive cost + share-of-total (causal)
85
+ npm run dev -- cost <id> # where one node's cost goes / who causes it
72
86
  ```
73
87
 
74
88
  Every query command accepts `--json` to emit machine-readable output — this is
@@ -76,8 +90,8 @@ the shape the optimization agent consumes. Node ids come from `find` or another
76
90
  query's results; do not hand-write them.
77
91
 
78
92
  The query methods on `GraphQuery` (`whoCalls`, `blastRadius`, `deadExports`,
79
- `neighborhood`, …) are designed to map one-to-one onto agent tools: JSON in,
80
- JSON out.
93
+ `hotspots`, `costRanking`, `costAttribution`, `neighborhood`, …) are designed to
94
+ map one-to-one onto agent tools: JSON in, JSON out.
81
95
 
82
96
  For a task-oriented walk-through of these commands — using them by hand to
83
97
  answer impact, dead-code, and dependency questions — see the
@@ -103,26 +117,36 @@ npm run web -- --db ./outputs/graph.kuzu --port 8080
103
117
  ### The optimization agent
104
118
 
105
119
  The end goal: an agent that uses the graph to find and apply optimizations,
106
- verifying each one before keeping it.
107
-
108
- ```bash
109
- cp .env-sample .env # pick a provider block, set key + model
110
- npm run dev -- optimize --db ./outputs/graph.kuzu
111
- npm run dev -- optimize "Inline the single-use helper X" --db ./outputs/graph.kuzu --model gpt-5.1
120
+ verifying each one before keeping it. It ships as a [Claude Code](https://claude.com/claude-code)
121
+ slash command, `/code-graph-optimize`, defined in
122
+ [`dotclaude_folder/commands/code-graph-optimize.md`](dotclaude_folder/commands/code-graph-optimize.md)
123
+ so the agent runtime is your Claude Code subscription, with no API key or
124
+ provider configuration to set up.
125
+
126
+ ```text
127
+ /code-graph-optimize
128
+ /code-graph-optimize Inline the single-use helper X
112
129
  ```
113
130
 
114
- The LLM layer sits on the **OpenAI-compatible chat-completions API**, so any
115
- provider exposing that surface works OpenAI, OpenRouter, Ollama, LM Studio,
116
- vLLM — configured entirely through `OPENAI_API_KEY`, `OPENAI_BASE_URL`, and
117
- `OPENAI_MODEL` (see [.env-sample](.env-sample)).
118
-
119
- The agent runs a tool-calling loop. Its tools are the read-only `GraphQuery`
120
- methods plus `read_file`; it gathers context, confirms blast radius, then calls
121
- `propose_optimization`. The harness **applies the edit, runs `tsc --noEmit`,
122
- and keeps it only if type-checking passes** otherwise it reverts and hands
123
- the compiler errors back for another attempt. Edits are unique-match
124
- find/replace with in-memory backups; run on a clean git tree so you can review
125
- (and `git checkout`) what it kept.
131
+ With no argument the command runs its default mission: find one genuinely dead
132
+ exported symbol, confirm it has zero inbound references, and remove it safely.
133
+
134
+ The command drives a find → confirm → edit → verify loop. It queries the graph
135
+ through this CLI (`dead-exports`, `references`, `who-calls`, `blast-radius`) to
136
+ gather context and confirm blast radius, makes exactly one edit, then runs
137
+ [`ts-knowledge-graph verify`](docs/commands/verify.md) the type-check **and**
138
+ the test suite as a single gate. **If verify passes the edit stands; if it fails
139
+ the edit is reverted with `git restore`** and the change is abandoned or retried.
140
+ On a project with no test script verify degrades to type-check-only and the agent
141
+ says so, rather than implying the change was behaviourally verified. Run it on a
142
+ clean git tree so you can review (and `git checkout`) what it kept.
143
+
144
+ A companion command, `/code-graph-interview`
145
+ ([`code-graph-interview.md`](dotclaude_folder/commands/code-graph-interview.md)),
146
+ is read-only: it interviews you to scope a measurable optimization target and
147
+ grounds each candidate in the graph, producing tasks you can then hand to
148
+ `/code-graph-optimize`. Both commands, plus the `code-graph-query` skill, live
149
+ under [`dotclaude_folder/`](dotclaude_folder) and are mirrored into `.claude/`.
126
150
 
127
151
  ## Architecture
128
152
 
@@ -141,14 +165,15 @@ src/
141
165
  kuzu_store.ts load the graph into embedded Kùzu, run Cypher
142
166
  query/
143
167
  graph_query.ts the agent's query tools (who-calls, blast-radius…)
144
- agent/
145
- agent_tools.ts graph queries + read_file + propose_optimization, as LLM tools
146
- code_editor.ts unique-match find/replace with in-memory backup + revert
147
- verifier.ts runs `tsc --noEmit`, returns pass/fail + output
148
- optimizer_agent.ts the LLM tool-calling loop (propose → verify → keep/revert)
149
- cli.ts extract / load / query / optimize commands
168
+ commands/ one file per CLI command (extract, load, query, web, install)
169
+ cli.ts wires the commands into the ts-knowledge-graph CLI
150
170
  ```
151
171
 
172
+ The optimization agent is not part of this `src/` tree — it is the
173
+ `/code-graph-optimize` Claude Code command under
174
+ [`dotclaude_folder/commands/`](dotclaude_folder/commands), which drives the same
175
+ queries through the CLI.
176
+
152
177
  Node ids are derived purely from the declaration (`kind:relPath#name@line`), so
153
178
  any extractor computes the same id for the same symbol without a shared
154
179
  registry — that is what lets the semantic layer link a call site to the exact
@@ -165,10 +190,25 @@ declaration node the structural layer emitted.
165
190
  contained member is referenced.
166
191
  - [x] **Value-reference (`READS`) edges** — value-identifier usage, so exported
167
192
  `const`s (e.g. schemas) are no longer false-positive dead exports.
168
- - [x] **Optimization agent** — an LLM tool-calling loop (OpenAI-compatible API,
169
- provider-agnostic) that proposes edits and keeps them only if `tsc --noEmit`
170
- passes (otherwise reverts).
171
- - [ ] **Test verification** — run the test suite alongside `tsc` in the verify
172
- step, so behavior-changing edits are caught, not just type errors.
193
+ - [x] **Runtime enrichment** — the [`enrich`](docs/commands/enrich.md) command
194
+ ingests a V8 CPU profile and attaches measured self time / sample count onto
195
+ nodes as `metadata.runtime`, joining frames to nodes by enclosing range.
196
+ - [x] **Hotspot / leverage ranking** — the [`hotspots`](docs/commands/hotspots.md)
197
+ command ranks nodes by optimization value (runtime self-time, fan-in,
198
+ call-count, or transitive blast radius), defaulting to measured self time when
199
+ enriched and degrading gracefully to static fan-in when not.
200
+ - [x] **Optimization agent** — the `/code-graph-optimize` Claude Code command,
201
+ which proposes one edit and keeps it only if [`verify`](docs/commands/verify.md)
202
+ (type-check **and** tests) passes (otherwise reverts with `git restore`).
203
+ - [x] **Test verification** — the [`verify`](docs/commands/verify.md) command runs
204
+ the project's `typecheck` and `test` scripts as one keep/revert gate, so
205
+ behavior-changing edits are caught, not just type errors. A project with no test
206
+ script degrades to type-check-only, reported honestly (`behaviorVerified: false`).
207
+ - [x] **Benchmark verification** — the [`benchmark`](docs/commands/benchmark.md)
208
+ command measures a target node's runtime metric (profile → enrich → cost) over
209
+ N runs and reports the median + spread, with an advisory baseline→after delta —
210
+ so an optimization is reported by its *measured* impact (e.g. −57% self-time on
211
+ `titleCase`) rather than a guess. Advisory by design, distinct from the hard
212
+ `verify` gate.
173
213
  - [ ] **Vector index** — embed per-node summaries for hybrid graph + semantic
174
214
  retrieval, so the agent can find candidates by meaning, not just by name.
@@ -49,7 +49,35 @@ npx serve # or: python3 -m http.server
49
49
  - **Edge colors**: red `CALLS`, green/teal type edges (`USES_TYPE`, `RETURNS`,
50
50
  `PARAM_TYPE`), yellow `READS`, violet heritage, gray structure
51
51
  (`CONTAINS`, `IMPORTS`).
52
+ - **Edge width** scales with call-site count — how many times the call / import /
53
+ read occurs between the two symbols (shown as `×N` in the detail panel). Thick
54
+ edges are the hot connections.
52
55
  - Uncheck noisy kinds (`CONTAINS`, `IMPORTS`) to see the behavioral core;
53
56
  enable **hide isolated nodes** to drop whatever the filter disconnected.
57
+ - The **all** checkbox atop Node kinds / Edge kinds toggles every kind at once —
58
+ hide all, then re-check just the few you want to isolate (it shows a dash when
59
+ only some kinds are visible).
54
60
  - Click a node to fade everything outside its neighborhood and list its edges
55
61
  in the sidebar — the links navigate the graph.
62
+ - **Fold any sidebar section** by clicking its header (Runtime, Hotspots, Node
63
+ kinds, Edge kinds, …); the collapsed state is remembered across reloads.
64
+
65
+ ## Runtime hotspots
66
+
67
+ When the graph has been enriched (`ts-knowledge-graph enrich <profile.cpuprofile>`),
68
+ each measured symbol carries `metadata.runtime` (self-time + sample count). The
69
+ sidebar's **Runtime** panel surfaces it:
70
+
71
+ - **Coverage line** — how many nodes were measured and the total self-time, so a
72
+ partial profile reads as partial.
73
+ - **Heat map toggle** — re-encodes the graph by measured self-time: nodes are
74
+ **sized and heat-coloured** (cool → yellow → red) by how hot they are, instead
75
+ of by kind/degree. Toggle off to return to the structural view.
76
+ - **Hotspots list** — the top symbols ranked by self-time; click one to focus it.
77
+ - **Only measured nodes** — hides the un-enriched nodes so only the measured
78
+ subgraph remains, to focus on where the cost actually is.
79
+ - Selecting any node adds a **runtime** block (self-time, samples, source) to the
80
+ detail panel.
81
+
82
+ Un-measured nodes render at a neutral, dashed baseline — "no metric" means
83
+ *inlined or not sampled*, not "free".
@@ -24,6 +24,28 @@ body { display: flex; }
24
24
  #sidebar h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #64748b; margin: 16px 0 6px; }
25
25
  #sidebar section { margin-top: 8px; }
26
26
 
27
+ #sidebar .foldable {
28
+ display: flex;
29
+ align-items: center;
30
+ gap: 7px;
31
+ line-height: 1;
32
+ cursor: pointer;
33
+ user-select: none;
34
+ }
35
+ #sidebar .foldable:hover { color: #94a3b8; }
36
+ #sidebar .foldable::before {
37
+ content: '';
38
+ flex: none;
39
+ width: 0;
40
+ height: 0;
41
+ border-left: 5px solid currentColor;
42
+ border-top: 4px solid transparent;
43
+ border-bottom: 4px solid transparent;
44
+ transition: transform .12s ease;
45
+ }
46
+ #sidebar .foldable:not(.collapsed)::before { transform: rotate(90deg); }
47
+ #sidebar .foldable.collapsed ~ * { display: none; }
48
+
27
49
  #status { font-size: 11px; color: #64748b; margin-bottom: 10px; }
28
50
 
29
51
  #search {
@@ -64,6 +86,49 @@ body { display: flex; }
64
86
  flex: none;
65
87
  }
66
88
  .legend .count { margin-left: auto; color: #64748b; font-size: 11px; }
89
+ .legend .help-badge {
90
+ flex: none;
91
+ width: 13px;
92
+ height: 13px;
93
+ border-radius: 50%;
94
+ border: 1px solid #475569;
95
+ color: #94a3b8;
96
+ font-size: 9px;
97
+ font-weight: 600;
98
+ line-height: 11px;
99
+ text-align: center;
100
+ user-select: none;
101
+ }
102
+ .legend .help-badge:hover,
103
+ .legend .help-badge:focus {
104
+ background: #334155;
105
+ color: #e2e8f0;
106
+ border-color: #64748b;
107
+ outline: none;
108
+ }
109
+ .legend label.master {
110
+ margin-bottom: 4px;
111
+ padding-bottom: 4px;
112
+ border-bottom: 1px solid #1e293b;
113
+ color: #94a3b8;
114
+ }
115
+ .legend .swatch.spacer { background: transparent; }
116
+
117
+ .kind-tooltip {
118
+ position: fixed;
119
+ z-index: 1000;
120
+ max-width: 260px;
121
+ padding: 6px 9px;
122
+ border-radius: 6px;
123
+ background: #0b1424;
124
+ border: 1px solid #334155;
125
+ color: #e2e8f0;
126
+ font-size: 11px;
127
+ line-height: 1.4;
128
+ box-shadow: 0 4px 14px rgba(0, 0, 0, .45);
129
+ pointer-events: none;
130
+ }
131
+ .kind-tooltip[hidden] { display: none; }
67
132
 
68
133
  .row { display: flex; align-items: center; gap: 6px; margin: 4px 0; }
69
134
 
@@ -92,8 +157,47 @@ select { flex: 1; }
92
157
  #details-body h3 { font-size: 11px; color: #64748b; margin: 10px 0 3px; }
93
158
  #details-body .edge-row { padding: 1px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
94
159
  #details-body .edge-kind { color: #64748b; font-size: 10px; }
160
+ #details-body .edge-count { color: #f59e0b; font-size: 10px; font-variant-numeric: tabular-nums; }
95
161
  #details-body a { color: #7db2ff; cursor: pointer; text-decoration: none; }
96
162
  #details-body a:hover { text-decoration: underline; }
163
+ #details-body a.file-link { text-decoration: underline; word-break: break-all; }
164
+ #details-body a.file-link::after { content: '↗'; margin-left: 3px; font-size: 9px; opacity: 0.7; }
165
+
166
+ #runtime.empty .heat-legend,
167
+ #runtime.empty .heat-note,
168
+ #runtime.empty .hotspots-title,
169
+ #runtime.empty #hotspots,
170
+ #runtime.empty label.row { display: none; }
171
+
172
+ #coverage { font-size: 11px; color: #94a3b8; margin: 2px 0 6px; }
173
+
174
+ #runtime label.row { font-size: 12px; }
175
+
176
+ .heat-legend { display: flex; align-items: center; gap: 6px; margin: 8px 0 4px; }
177
+ .heat-bar { flex: 1; height: 10px; border-radius: 3px; background: linear-gradient(90deg, #64748b, #fde047, #dc2626); }
178
+ .heat-legend .heat-min, .heat-legend .heat-max { font-size: 10px; color: #64748b; }
179
+
180
+ .heat-note { display: flex; align-items: center; gap: 6px; font-size: 10px; color: #64748b; }
181
+ .heat-swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; display: inline-block; }
182
+ .heat-swatch.unmeasured { background: #243044; border: 1px dashed #475569; }
183
+
184
+ .hotspots-title { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #64748b; margin: 12px 0 4px; }
185
+ #hotspots .hotspot {
186
+ display: flex;
187
+ align-items: center;
188
+ gap: 6px;
189
+ padding: 2px 4px;
190
+ border-radius: 4px;
191
+ cursor: pointer;
192
+ font-size: 12px;
193
+ }
194
+ #hotspots .hotspot:hover { background: #1e293b; }
195
+ .hotspot-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
196
+ .hotspot-ms { margin-left: auto; flex: none; color: #f59e0b; font-size: 11px; font-variant-numeric: tabular-nums; }
197
+
198
+ #details-body .runtime-block { margin-top: 8px; }
199
+ #details-body .runtime-block .metric { display: flex; justify-content: space-between; gap: 8px; padding: 1px 0; }
200
+ #details-body .runtime-block .metric span { color: #64748b; }
97
201
 
98
202
  #cy { flex: 1; height: 100%; }
99
203
 
@@ -1,2 +1,3 @@
1
1
  *
2
2
  !.gitignore
3
+ !kind_descriptions.js
@@ -0,0 +1,38 @@
1
+ // @ts-nocheck
2
+ // Generated from src/schema by scripts/build-data.ts. Do not edit by hand.
3
+ window.KIND_DESCRIPTIONS = {
4
+ "nodes": {
5
+ "Module": "A source file in the codebase.",
6
+ "Class": "A class declaration.",
7
+ "Interface": "An interface declaration.",
8
+ "TypeAlias": "A type alias declaration.",
9
+ "Enum": "An enum declaration.",
10
+ "Function": "A standalone, module-level function.",
11
+ "Method": "A function that belongs to a class or interface.",
12
+ "Property": "A field declared on a class or interface.",
13
+ "Parameter": "A parameter of a function or method.",
14
+ "Variable": "A module- or block-level variable binding.",
15
+ "ExternalModule": "An imported third-party or Node.js module, recorded as one opaque node per import specifier.",
16
+ "ConfigFlag": "An environment-variable configuration flag, detected from process.env reads.",
17
+ "ExternalAPI": "An outbound HTTP host called through fetch(), with one node per host.",
18
+ "Endpoint": "An HTTP route registered by the app, such as app.get(\"/users\", handler)."
19
+ },
20
+ "edges": {
21
+ "CONTAINS": "Structural nesting: the source declares or encloses the target (a module contains a class, which contains a method).",
22
+ "IMPORTS": "The source module imports the target.",
23
+ "EXPORTS": "The source module exports the target symbol.",
24
+ "EXTENDS": "The source class or interface extends the target (inheritance).",
25
+ "IMPLEMENTS": "The source class implements the target interface.",
26
+ "USES_TYPE": "The source references the target in a type position.",
27
+ "RETURNS": "The target type appears in the source function or method return type.",
28
+ "PARAM_TYPE": "The target type appears in one of the source parameter types.",
29
+ "CALLS": "The source function or method calls the target.",
30
+ "INSTANTIATES": "The source constructs the target class with new.",
31
+ "OVERRIDES": "The source method overrides the base-class member it replaces.",
32
+ "READS": "The source reads the value of the target variable or property.",
33
+ "WRITES": "The source assigns to the target variable or property.",
34
+ "READS_CONFIG": "The source reads the target configuration flag (an environment variable).",
35
+ "CALLS_EXTERNAL": "The source makes an outbound HTTP call to the target external API.",
36
+ "HANDLES": "Links an HTTP endpoint to the function that handles it (route to handler)."
37
+ }
38
+ };
@@ -14,18 +14,33 @@
14
14
  <input id="search" type="search" placeholder="Search symbol or file… (Enter)" autocomplete="off">
15
15
  <div id="search-results"></div>
16
16
 
17
+ <section id="runtime" class="empty">
18
+ <h2 class="foldable" data-fold="runtime">Runtime</h2>
19
+ <div id="coverage">no runtime data</div>
20
+ <label class="row"><input id="runtime-heat" type="checkbox"> heat map (size + colour by self-time)</label>
21
+ <label class="row"><input id="only-measured" type="checkbox"> only measured nodes</label>
22
+ <div class="heat-legend">
23
+ <span class="heat-min">cold</span>
24
+ <span class="heat-bar"></span>
25
+ <span class="heat-max">hot</span>
26
+ </div>
27
+ <div class="heat-note"><span class="heat-swatch unmeasured"></span> not measured</div>
28
+ <h3 class="hotspots-title foldable" data-fold="hotspots">Hotspots</h3>
29
+ <div id="hotspots"></div>
30
+ </section>
31
+
17
32
  <section>
18
- <h2>Node kinds</h2>
33
+ <h2 class="foldable" data-fold="node-kinds">Node kinds</h2>
19
34
  <div id="node-kinds" class="legend"></div>
20
35
  </section>
21
36
 
22
37
  <section>
23
- <h2>Edge kinds</h2>
38
+ <h2 class="foldable" data-fold="edge-kinds">Edge kinds</h2>
24
39
  <div id="edge-kinds" class="legend"></div>
25
40
  </section>
26
41
 
27
42
  <section>
28
- <h2>Options</h2>
43
+ <h2 class="foldable" data-fold="options">Options</h2>
29
44
  <label class="row"><input id="hide-isolated" type="checkbox"> hide isolated nodes</label>
30
45
  <div class="row">
31
46
  <select id="layout-select">
@@ -40,7 +55,7 @@
40
55
  </section>
41
56
 
42
57
  <section id="details" class="empty">
43
- <h2>Selection</h2>
58
+ <h2 class="foldable" data-fold="selection">Selection</h2>
44
59
  <div id="details-body">click a node</div>
45
60
  </section>
46
61
  </aside>
@@ -52,6 +67,7 @@
52
67
  </div>
53
68
 
54
69
  <script src="./data/graph_data.js"></script>
70
+ <script src="./data/kind_descriptions.js"></script>
55
71
  <script src="https://unpkg.com/cytoscape@3/dist/cytoscape.min.js"></script>
56
72
  <script src="./js/app.js"></script>
57
73
  </body>