Commit e1fed2d
feat(graph): config_refs — env var read sites as queryable graph data
Extracts environment-variable read sites (process.env.X, os.getenv,
os.environ, os.Getenv, System.getenv, ENV[...], env!, std::env::var)
into a new config_refs table and surfaces them via a new
codegraph_config MCP tool. Answers "what reads OBSIDIAN_PORT?" and
"what config does this codebase read?" without grep noise.
## Why a separate table, not graph nodes/edges
Env vars don't have a single source-of-truth file (they're a global
namespace), so giving them a synthetic file_path would pollute the
main graph. The table is queried via a dedicated MCP tool and via
augmented codegraph_node output.
## Spike validation (mcp-obsidian-extended)
Reproduces the spike's empirical numbers exactly when indexed with
this PR's build:
TOOL_PRESET 8 reads
OBSIDIAN_PORT 8
OBSIDIAN_SCHEME 7
INCLUDE_TOOLS 7
TOOL_MODE 6
OBSIDIAN_CONFIG 5
OBSIDIAN_DEBUG 4
These are central config knobs an agent should know about when
editing this codebase. The codegraph repo itself is sparse (4 reads)
because it's a CLI with file-based config — this feature shines on
service-style codebases.
## What's added
**Parser** (src/config-refs/index.ts)
- Per-language regex catalogue: TS/JS, Python, Go, Java/Kotlin,
Ruby, Rust. Upper-case-only keys filter out dynamic accesses
(`process.env.foo`) and lower-case identifiers.
- Pre-filter `line.includes('env'|'Env'|'ENV')` skips 99% of lines
cheaply before running per-language regexes.
- Pure I/O + regex: caller owns DB writes via applyConfigRefs.
**Schema migration v4** with `CREATE TABLE IF NOT EXISTS config_refs
(id, config_kind, config_key, source_node_id, file_path, line)`,
with FK to nodes for cascade-delete on node removal. Defensive
ensureConfigRefsTable() guard at every persistence path so a
botched merge with a peer v4 doesn't silently lose the table.
**Wiring** (CodeGraph.runConfigRefsPass)
- indexAll: full rescan, clearConfigRefs + extract every indexed file.
- sync: incremental — invalidate rows for every changed file via
deleteConfigRefsForPaths, then re-extract. Also runs when files
were removed (sync's changedFilePaths excludes deletions);
pruneOrphanedConfigRefs sweeps stale rows.
- Per-pass enclosing-function resolver cache: Map<filePath, sorted
span list> — avoids O(reads × symbols) DB scans on big files.
- enableConfigRefs config flag (default true) for opt-out.
**MCP tool** codegraph_config
- No `key` arg → top-N keys with read counts (the "what config does
this codebase read?" question).
- With `key` → all read sites + enclosing function (the "what reads
OBSIDIAN_PORT?" question).
## Tests
399 pass total, **19 new**:
- Parser per-language (7): TS, JS, Python, Go, Java/Kotlin, Ruby, Rust
- Parser correctness (5): upper-case-only filter, unsupported lang,
line-number 1-indexed, resolveEnclosing closure threading,
missing file
- End-to-end CodeGraph (7): basic + enclosing-function attribution,
reverse-view (getConfigKeysForNode), enableConfigRefs:false,
incremental sync replace, **regression for empty-rows
data-corruption bug** (file edited to remove last env read),
deletion sweep, **v4-collision defense** (drop table after init)
## Reviewer pass
Independent reviewer ran once. One REQUEST_CHANGES + two INFO addressed:
- **Data-corruption bug:** `applyConfigRefs([])` early-returned
without deleting stale rows for the file. A file edited to remove
its last env read kept the orphan row forever. Fixed by adding
`deleteConfigRefsForPaths` and calling it in runConfigRefsPass
BEFORE re-extraction. Regression test asserts the fix.
- Pre-filter heuristic: documented as quick-reject, not exact gate.
## Coexistence with #112 (centrality-and-churn) and #113 (issue-history)
All three PRs target migration v4. Whichever lands second/third
renumbers their migration in the array — standard merge-time
rebase. As insurance, ensureConfigRefsTable() at every persistence
path creates the table on demand so a botched merge doesn't silently
swallow data.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 2dc4bc3 commit e1fed2d
10 files changed
Lines changed: 912 additions & 3 deletions
File tree
- __tests__
- src
- config-refs
- db
- mcp
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
305 | 305 | | |
306 | 306 | | |
307 | 307 | | |
308 | | - | |
| 308 | + | |
309 | 309 | | |
310 | 310 | | |
311 | 311 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
299 | 299 | | |
300 | 300 | | |
301 | 301 | | |
302 | | - | |
| 302 | + | |
303 | 303 | | |
304 | 304 | | |
305 | 305 | | |
| |||
0 commit comments