@codragraph/cli 1.6.3 → 2.0.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.
Files changed (89) hide show
  1. package/README.md +50 -16
  2. package/dist/cli/ai-context.js +2 -2
  3. package/dist/cli/analyze.d.ts +22 -0
  4. package/dist/cli/analyze.js +111 -8
  5. package/dist/cli/compress-stats.d.ts +29 -0
  6. package/dist/cli/compress-stats.js +97 -0
  7. package/dist/cli/graphstore.d.ts +6 -2
  8. package/dist/cli/graphstore.js +24 -2
  9. package/dist/cli/index.js +17 -6
  10. package/dist/cli/profile-heap.d.ts +35 -0
  11. package/dist/cli/profile-heap.js +126 -0
  12. package/dist/cli/setup.d.ts +13 -0
  13. package/dist/cli/setup.js +75 -29
  14. package/dist/cli/skill-gen.d.ts +14 -2
  15. package/dist/cli/skill-gen.js +53 -20
  16. package/dist/cli/tool.js +4 -0
  17. package/dist/config/ignore-service.js +1 -1
  18. package/dist/core/embeddings/embedding-pipeline.js +24 -7
  19. package/dist/core/group/bridge-db.js +111 -24
  20. package/dist/core/group/extractors/grpc-patterns/proto.js +1 -12
  21. package/dist/core/ingestion/call-processor.js +2 -2
  22. package/dist/core/ingestion/cobol/cobol-preprocessor.js +1 -1
  23. package/dist/core/ingestion/cobol/jcl-parser.d.ts +1 -1
  24. package/dist/core/ingestion/cobol/jcl-parser.js +1 -1
  25. package/dist/core/ingestion/cobol-processor.d.ts +1 -1
  26. package/dist/core/ingestion/cobol-processor.js +1 -1
  27. package/dist/core/ingestion/heritage-extractors/generic.js +1 -1
  28. package/dist/core/ingestion/heritage-processor.js +1 -1
  29. package/dist/core/ingestion/import-processor.js +1 -1
  30. package/dist/core/ingestion/mro-processor.js +1 -1
  31. package/dist/core/ingestion/parsing-processor.js +1 -1
  32. package/dist/core/ingestion/type-extractors/c-cpp.js +1 -1
  33. package/dist/core/ingestion/type-extractors/python.js +1 -1
  34. package/dist/core/ingestion/type-extractors/shared.js +0 -3
  35. package/dist/core/lbug/content-read.d.ts +46 -0
  36. package/dist/core/lbug/content-read.js +64 -0
  37. package/dist/core/lbug/csv-generator.d.ts +2 -6
  38. package/dist/core/lbug/csv-generator.js +45 -12
  39. package/dist/core/lbug/lbug-adapter.d.ts +4 -1
  40. package/dist/core/lbug/lbug-adapter.js +157 -25
  41. package/dist/core/lbug/pool-adapter.js +51 -44
  42. package/dist/core/lbug/schema.d.ts +7 -7
  43. package/dist/core/lbug/schema.js +18 -0
  44. package/dist/core/run-analyze.d.ts +13 -0
  45. package/dist/core/run-analyze.js +91 -4
  46. package/dist/core/search/bm25-index.js +153 -12
  47. package/dist/core/wiki/generator.js +4 -4
  48. package/dist/mcp/local/local-backend.js +22 -5
  49. package/dist/mcp/resources.js +2 -3
  50. package/dist/server/api.js +4 -3
  51. package/dist/storage/repo-manager.d.ts +39 -0
  52. package/dist/storage/repo-manager.js +19 -0
  53. package/hooks/claude/codragraph-hook.cjs +108 -5
  54. package/hooks/claude/pre-tool-use.sh +6 -1
  55. package/package.json +4 -4
  56. package/scripts/build-tree-sitter-proto.cjs +15 -3
  57. package/scripts/patch-tree-sitter-swift.cjs +17 -4
  58. package/skills/codragraph-api-surface.md +110 -0
  59. package/skills/codragraph-cli.md +5 -5
  60. package/skills/codragraph-config-audit.md +146 -0
  61. package/skills/codragraph-cross-repo-impact.md +135 -0
  62. package/skills/codragraph-data-lineage.md +137 -0
  63. package/skills/codragraph-dead-code.md +119 -0
  64. package/skills/codragraph-debugging.md +1 -1
  65. package/skills/codragraph-exploring.md +1 -1
  66. package/skills/codragraph-gh-actions-debug.md +162 -0
  67. package/skills/codragraph-gh-issue-workflow.md +178 -0
  68. package/skills/codragraph-gh-pr-workflow.md +176 -0
  69. package/skills/codragraph-gh-release-workflow.md +187 -0
  70. package/skills/codragraph-git-bisect.md +176 -0
  71. package/skills/codragraph-git-force-push.md +147 -0
  72. package/skills/codragraph-git-history-rewrite.md +174 -0
  73. package/skills/codragraph-git-rebase-vs-merge.md +138 -0
  74. package/skills/codragraph-git-recovery.md +181 -0
  75. package/skills/codragraph-git-worktree.md +145 -0
  76. package/skills/codragraph-guide.md +1 -1
  77. package/skills/codragraph-impact-analysis.md +1 -1
  78. package/skills/codragraph-migration-tracking.md +130 -0
  79. package/skills/codragraph-notebook-context.md +136 -0
  80. package/skills/codragraph-observability-coverage.md +125 -0
  81. package/skills/codragraph-onboarding.md +129 -0
  82. package/skills/codragraph-perf-hotspots.md +132 -0
  83. package/skills/codragraph-pr-review.md +1 -1
  84. package/skills/codragraph-project-switcher.md +116 -0
  85. package/skills/codragraph-refactoring.md +1 -1
  86. package/skills/codragraph-security-audit.md +144 -0
  87. package/skills/codragraph-sql-tracing.md +122 -0
  88. package/skills/codragraph-supply-chain-audit.md +153 -0
  89. package/skills/codragraph-test-coverage.md +97 -0
@@ -12,8 +12,27 @@
12
12
  */
13
13
 
14
14
  const fs = require('fs');
15
+ const os = require('os');
15
16
  const path = require('path');
16
- const { spawnSync } = require('child_process');
17
+ const { spawnSync, spawn } = require('child_process');
18
+
19
+ /**
20
+ * Decide whether background auto-reindex is opted in. Two equivalent signals:
21
+ * 1. CODRAGRAPH_AUTO_REINDEX=1 in env (good for shells, CI)
22
+ * 2. `{ "autoReindex": true }` in ~/.codragraph/config.json (good for GUI
23
+ * editor launches on Windows, where shell env doesn't propagate to
24
+ * hook child processes reliably)
25
+ */
26
+ function isAutoReindexEnabled() {
27
+ if (process.env.CODRAGRAPH_AUTO_REINDEX === '1') return true;
28
+ try {
29
+ const configPath = path.join(os.homedir(), '.codragraph', 'config.json');
30
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
31
+ return config && config.autoReindex === true;
32
+ } catch {
33
+ return false;
34
+ }
35
+ }
17
36
 
18
37
  /**
19
38
  * Read JSON input from stdin synchronously.
@@ -133,8 +152,18 @@ function runCodraGraphCli(cliPath, args, cwd, timeout) {
133
152
  stdio: ['pipe', 'pipe', 'pipe'],
134
153
  });
135
154
  }
136
- // On Windows, invoke npx.cmd directly (no shell needed)
137
- return spawnSync(isWin ? 'npx.cmd' : 'npx', ['-y', '@codragraph/cli', ...args], {
155
+ // npx fallback: on Windows, Node 22's spawn refuses to launch `npx.cmd`
156
+ // directly (returns EINVAL), so route through `cmd /c` and let PATHEXT
157
+ // resolve the shim. POSIX direct-spawn is fine.
158
+ if (isWin) {
159
+ return spawnSync('cmd', ['/c', 'npx', '-y', '@codragraph/cli', ...args], {
160
+ encoding: 'utf-8',
161
+ timeout: timeout + 5000,
162
+ cwd,
163
+ stdio: ['pipe', 'pipe', 'pipe'],
164
+ });
165
+ }
166
+ return spawnSync('npx', ['-y', '@codragraph/cli', ...args], {
138
167
  encoding: 'utf-8',
139
168
  timeout: timeout + 5000,
140
169
  cwd,
@@ -239,11 +268,85 @@ function handlePostToolUse(input) {
239
268
  // If HEAD matches last indexed commit, no reindex needed
240
269
  if (currentHead && currentHead === lastCommit) return;
241
270
 
242
- const analyzeCmd = `npx codragraph analyze${hadEmbeddings ? ' --embeddings' : ''}`;
271
+ const analyzeCmd = `npx @codragraph/cli analyze${hadEmbeddings ? ' --embeddings' : ''}`;
272
+
273
+ // Opt-in background auto-reindex.
274
+ // Default stays as notification-only because spawning analyze while an MCP
275
+ // server holds LadybugDB will fail with a database-busy error — the
276
+ // notification path lets the agent reindex at a quiet moment instead.
277
+ // Power users who run MCP outside Claude Code's lifecycle can opt in via
278
+ // CODRAGRAPH_AUTO_REINDEX=1 or `{ "autoReindex": true }` in
279
+ // ~/.codragraph/config.json.
280
+ if (isAutoReindexEnabled()) {
281
+ // The "coalesce" file is a single-process gate: it exists only while a
282
+ // reindex is in flight. The spawned analyze removes it on exit (success or
283
+ // failure) via CODRAGRAPH_REINDEX_LOCK_PATH; the 10-min mtime fallback
284
+ // catches the rare crash that bypasses analyze's exit handler.
285
+ const coalescePath = path.join(gitNexusDir, '.reindex.coalesce');
286
+ const crashSafetyTtlMs = 10 * 60 * 1000;
287
+ let inFlight = false;
288
+ try {
289
+ const stat = fs.statSync(coalescePath);
290
+ if (Date.now() - stat.mtimeMs < crashSafetyTtlMs) inFlight = true;
291
+ } catch {
292
+ /* no coalesce file — no reindex in flight */
293
+ }
294
+
295
+ if (!inFlight) {
296
+ try {
297
+ fs.writeFileSync(coalescePath, String(process.pid));
298
+ } catch {
299
+ /* best-effort — gate is for coalescing, not correctness */
300
+ }
301
+
302
+ const cliPath = resolveCliPath();
303
+ const reindexArgs = hadEmbeddings
304
+ ? ['analyze', '--embeddings', '--no-setup']
305
+ : ['analyze', '--no-setup'];
306
+ const spawnEnv = { ...process.env, CODRAGRAPH_REINDEX_LOCK_PATH: coalescePath };
307
+ const spawnOpts = {
308
+ cwd,
309
+ detached: true,
310
+ stdio: 'ignore',
311
+ windowsHide: true,
312
+ env: spawnEnv,
313
+ };
314
+ try {
315
+ let child;
316
+ if (cliPath) {
317
+ child = spawn(process.execPath, [cliPath, ...reindexArgs], spawnOpts);
318
+ } else if (process.platform === 'win32') {
319
+ child = spawn('cmd', ['/c', 'npx', '-y', '@codragraph/cli', ...reindexArgs], spawnOpts);
320
+ } else {
321
+ child = spawn('npx', ['-y', '@codragraph/cli', ...reindexArgs], spawnOpts);
322
+ }
323
+ child.unref();
324
+ } catch {
325
+ /* spawn failed — fall through to notification */
326
+ }
327
+
328
+ sendHookResponse(
329
+ 'PostToolUse',
330
+ `CodraGraph: auto-reindex started in background ` +
331
+ `(HEAD ${lastCommit ? lastCommit.slice(0, 7) : 'never'} → ${currentHead.slice(0, 7)}). ` +
332
+ `If an MCP server is currently holding the database, the reindex will fail silently — ` +
333
+ `run \`${analyzeCmd}\` manually after closing the agent session.`,
334
+ );
335
+ return;
336
+ }
337
+
338
+ sendHookResponse(
339
+ 'PostToolUse',
340
+ `CodraGraph: auto-reindex coalesced — another reindex is in flight (will pick up your latest commit when it finishes).`,
341
+ );
342
+ return;
343
+ }
344
+
243
345
  sendHookResponse(
244
346
  'PostToolUse',
245
347
  `CodraGraph index is stale (last indexed: ${lastCommit ? lastCommit.slice(0, 7) : 'never'}). ` +
246
- `Run \`${analyzeCmd}\` to update the knowledge graph.`,
348
+ `Run \`${analyzeCmd}\` to update the knowledge graph. ` +
349
+ `Set CODRAGRAPH_AUTO_REINDEX=1 (or autoReindex: true in ~/.codragraph/config.json) for background auto-reindex.`,
247
350
  );
248
351
  }
249
352
 
@@ -64,7 +64,12 @@ fi
64
64
 
65
65
  # Run codragraph augment — must be fast (<500ms target)
66
66
  # augment writes to stderr (KuzuDB captures stdout at OS level), so capture stderr and discard stdout
67
- RESULT=$(cd "$CWD" && npx -y codragraph augment "$PATTERN" 2>&1 1>/dev/null)
67
+ # Prefer the global bin if present; fall back to npx (npm package is @codragraph/cli, bin is `codragraph`)
68
+ if command -v codragraph >/dev/null 2>&1; then
69
+ RESULT=$(cd "$CWD" && codragraph augment "$PATTERN" 2>&1 1>/dev/null)
70
+ else
71
+ RESULT=$(cd "$CWD" && npx -y @codragraph/cli augment "$PATTERN" 2>&1 1>/dev/null)
72
+ fi
68
73
 
69
74
  if [ -n "$RESULT" ]; then
70
75
  ESCAPED=$(echo "$RESULT" | jq -Rs .)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codragraph/cli",
3
- "version": "1.6.3",
3
+ "version": "2.0.0",
4
4
  "description": "Graph-powered code intelligence for AI agents. Index any codebase, query via MCP or CLI.",
5
5
  "author": {
6
6
  "name": "Anit Chaudhary",
@@ -56,10 +56,10 @@
56
56
  "prepack": "node scripts/build.js"
57
57
  },
58
58
  "dependencies": {
59
+ "@codragraph/graphstore": "^1.0.0",
59
60
  "@huggingface/transformers": "^4.1.0",
60
- "@ladybugdb/core": "^0.15.2",
61
+ "@ladybugdb/core": "^0.16.0",
61
62
  "@modelcontextprotocol/sdk": "^1.0.0",
62
- "@codragraph/graphstore": "*",
63
63
  "@scarf/scarf": "^1.4.0",
64
64
  "cli-progress": "^3.12.0",
65
65
  "commander": "^14.0.3",
@@ -99,6 +99,7 @@
99
99
  "tree-sitter-swift": "^0.6.0"
100
100
  },
101
101
  "devDependencies": {
102
+ "@codragraph/shared": "file:../codragraph-shared",
102
103
  "@types/cli-progress": "^3.11.6",
103
104
  "@types/cors": "^2.8.17",
104
105
  "@types/express": "^4.17.21",
@@ -106,7 +107,6 @@
106
107
  "@types/node": "^25.6.0",
107
108
  "@types/uuid": "^11.0.0",
108
109
  "@vitest/coverage-v8": "^4.0.18",
109
- "@codragraph/shared": "file:../codragraph-shared",
110
110
  "tsx": "^4.0.0",
111
111
  "typescript": "^5.4.5",
112
112
  "vitest": "^4.0.18"
@@ -34,14 +34,26 @@ const fs = require('fs');
34
34
  const path = require('path');
35
35
  const { execSync } = require('child_process');
36
36
 
37
- const protoDir = path.join(__dirname, '..', 'node_modules', 'tree-sitter-proto');
37
+ // Resolve tree-sitter-proto from BOTH the codragraph package itself AND any
38
+ // monorepo root that hoisted the dep. npm workspaces hoist optional deps to
39
+ // the workspace root, so the package-local path doesn't exist on a workspace
40
+ // install. Same trap as patch-tree-sitter-swift.cjs — see that file for the
41
+ // full failure mode.
42
+ const protoCandidates = [
43
+ path.join(__dirname, '..', 'node_modules', 'tree-sitter-proto'),
44
+ path.join(__dirname, '..', '..', 'node_modules', 'tree-sitter-proto'),
45
+ ];
46
+ const protoDir = protoCandidates.find((d) => fs.existsSync(path.join(d, 'binding.gyp')));
47
+ if (!protoDir) {
48
+ // tree-sitter-proto is an optionalDependency; absent when install
49
+ // skipped optional deps or the file: dep was not resolved.
50
+ process.exit(0);
51
+ }
38
52
  const bindingGyp = path.join(protoDir, 'binding.gyp');
39
53
  const bindingNode = path.join(protoDir, 'build', 'Release', 'tree_sitter_proto_binding.node');
40
54
 
41
55
  try {
42
56
  if (!fs.existsSync(bindingGyp)) {
43
- // tree-sitter-proto is an optionalDependency; absent when install
44
- // skipped optional deps or the file: dep was not resolved.
45
57
  process.exit(0);
46
58
  }
47
59
 
@@ -29,13 +29,26 @@ const fs = require('fs');
29
29
  const path = require('path');
30
30
  const { execSync } = require('child_process');
31
31
 
32
- const swiftDir = path.join(__dirname, '..', 'node_modules', 'tree-sitter-swift');
32
+ // Resolve tree-sitter-swift from BOTH the codragraph package itself AND any
33
+ // monorepo root that hoisted the dep. npm workspaces hoist optional deps to
34
+ // the workspace root, so `codragraph/node_modules/tree-sitter-swift` doesn't
35
+ // exist when this script runs as the codragraph postinstall — checking only
36
+ // that path silently no-ops, which is exactly the failure that left
37
+ // Windows Node 22.14 users without a Swift parser.
38
+ //
39
+ // Order matters: the package-local dir takes precedence (standalone install),
40
+ // then the parent monorepo root (workspace install).
41
+ const candidateDirs = [
42
+ path.join(__dirname, '..', 'node_modules', 'tree-sitter-swift'),
43
+ path.join(__dirname, '..', '..', 'node_modules', 'tree-sitter-swift'),
44
+ ];
45
+ const swiftDir = candidateDirs.find((d) => fs.existsSync(path.join(d, 'binding.gyp')));
46
+ if (!swiftDir) {
47
+ process.exit(0);
48
+ }
33
49
  const bindingPath = path.join(swiftDir, 'binding.gyp');
34
50
 
35
51
  try {
36
- if (!fs.existsSync(bindingPath)) {
37
- process.exit(0);
38
- }
39
52
 
40
53
  const content = fs.readFileSync(bindingPath, 'utf8');
41
54
  let needsRebuild = false;
@@ -0,0 +1,110 @@
1
+ ---
2
+ name: codragraph-api-surface
3
+ description: "Use when the user wants to enumerate the public API of a package or codebase, understand what's exported, audit breaking change risk, or compare API shapes across versions. Examples: \"what's our public API\", \"list exports\", \"API surface\", \"what would break if I remove X\", \"document the public interface\""
4
+ ---
5
+
6
+ # API Surface Audit with CodraGraph
7
+
8
+ ## When to Use
9
+
10
+ - "What's the public API of this package?"
11
+ - "List every exported function / class / type"
12
+ - "What would break if I remove or rename `<symbol>`?"
13
+ - Pre-release API freeze audit
14
+ - Generating API documentation from the graph
15
+ - Comparing API surface across versions (with `codragraph diff --semantic`)
16
+
17
+ ## Why CodraGraph helps here
18
+
19
+ Reading every `index.ts` / `__init__.py` / `mod.rs` by hand misses re-exports
20
+ and framework-magic exports (Next.js page routes, decorators, registered
21
+ plugins). CodraGraph's `isExported` property is computed by language-aware
22
+ export detection — covers default exports, named re-exports, `__all__`,
23
+ `pub use`, etc., consistently across all 16 supported languages.
24
+
25
+ ## Workflow
26
+
27
+ ```
28
+ 1. codragraph_cypher({query: `
29
+ MATCH (n) WHERE n.isExported = true
30
+ RETURN labels(n)[0] AS table, n.name, n.filePath, n.id
31
+ ORDER BY table, n.filePath, n.name
32
+ `})
33
+ → every exported symbol, grouped by table
34
+
35
+ 2. For each high-traffic export:
36
+ codragraph_impact({target: "<name>", direction: "upstream"})
37
+ → who depends on it (within this repo)
38
+
39
+ 3. For cross-repo audits (multi-repo group):
40
+ codragraph_impact({repo: "@<group>", target: "<name>", direction: "upstream"})
41
+ → blast radius across every group member
42
+
43
+ 4. Compare across versions:
44
+ codragraph diff <baseline> <head> --semantic --json
45
+ → addedAPIs / removedAPIs / classifiedModifications
46
+ → produces a versioned changelog of what your public surface gained / lost
47
+ ```
48
+
49
+ > Pair with `codragraph-pr-review` skill when reviewing a PR that touches
50
+ > exported symbols — the impact-across-group check is the difference between
51
+ > "breaks our consumers" and "internal refactor."
52
+
53
+ ## Checklist
54
+
55
+ ```
56
+ - [ ] Cypher query for n.isExported = true
57
+ - [ ] Group by file or by community (Leiden cluster)
58
+ - [ ] For each non-trivial export, run impact upstream
59
+ - [ ] If the package is in a group, run impact with repo: "@group" too
60
+ - [ ] Compare with previous release: codragraph diff <prev-tag> HEAD --semantic
61
+ - [ ] Flag exports with no documented consumers — candidates for visibility
62
+ reduction (export → internal)
63
+ ```
64
+
65
+ ## Example: "What's our public API?"
66
+
67
+ ```
68
+ 1. codragraph_cypher({
69
+ query: `MATCH (n) WHERE n.isExported = true
70
+ RETURN labels(n)[0] AS table, n.name, n.filePath`
71
+ })
72
+ → 47 exports: 22 Function, 12 Class, 8 Interface, 5 Constant
73
+
74
+ 2. Top-level functions:
75
+ - createClient (src/index.ts) ← 14 callers
76
+ - fetchUser (src/api.ts) ← 6 callers
77
+ - validate (src/utils.ts) ← 1 internal caller only ⚠ over-exported
78
+
79
+ 3. codragraph_impact({target: "validate", direction: "upstream"})
80
+ → d=1: only formatPayload (same package). No external consumers.
81
+ → Recommend: drop the `export` keyword. Internal-only.
82
+
83
+ 4. Compare with v1.5.3 release:
84
+ codragraph diff v1.5.3 HEAD --semantic
85
+ → +3 added APIs, -1 removed API (mappings.toCamelCase), ~2 modified
86
+ → Removed API is a SemVer major bump.
87
+ ```
88
+
89
+ ## Output Format
90
+
91
+ ```markdown
92
+ ## API Surface: <package>
93
+
94
+ ### Exports (47 total)
95
+ | Symbol | Table | File | Callers (internal) | Notes |
96
+ |--------|-------|------|-------------------:|-------|
97
+ | createClient | Function | src/index.ts | 14 | core entry |
98
+ | validate | Function | src/utils.ts | 1 | over-exported, suggest internal |
99
+ | ...
100
+
101
+ ### Diff vs <previous-tag>
102
+ - **Added (3):** `subscribe`, `unsubscribe`, `EventBus`
103
+ - **Removed (1):** `toCamelCase` ⚠ SemVer major
104
+ - **Modified (2):** `createClient` (param 3→4), `fetchUser` (return type)
105
+
106
+ ### Recommendations
107
+ - Reduce visibility on 4 over-exported internals
108
+ - Document the 3 new APIs in the release notes
109
+ - The removed `toCamelCase` requires a major version bump
110
+ ```
@@ -12,7 +12,7 @@ All commands work via `npx` — no global install required.
12
12
  ### analyze — Build or refresh the index
13
13
 
14
14
  ```bash
15
- npx codragraph analyze
15
+ npx @codragraph/cli analyze
16
16
  ```
17
17
 
18
18
  Run from the project root. This parses all source files, builds the knowledge graph, writes it to `.codragraph/`, and generates CLAUDE.md / AGENTS.md context files.
@@ -27,7 +27,7 @@ Run from the project root. This parses all source files, builds the knowledge gr
27
27
  ### status — Check index freshness
28
28
 
29
29
  ```bash
30
- npx codragraph status
30
+ npx @codragraph/cli status
31
31
  ```
32
32
 
33
33
  Shows whether the current repo has a CodraGraph index, when it was last updated, and symbol/relationship counts. Use this to check if re-indexing is needed.
@@ -35,7 +35,7 @@ Shows whether the current repo has a CodraGraph index, when it was last updated,
35
35
  ### clean — Delete the index
36
36
 
37
37
  ```bash
38
- npx codragraph clean
38
+ npx @codragraph/cli clean
39
39
  ```
40
40
 
41
41
  Deletes the `.codragraph/` directory and unregisters the repo from the global registry. Use before re-indexing if the index is corrupt or after removing CodraGraph from a project.
@@ -48,7 +48,7 @@ Deletes the `.codragraph/` directory and unregisters the repo from the global re
48
48
  ### wiki — Generate documentation from the graph
49
49
 
50
50
  ```bash
51
- npx codragraph wiki
51
+ npx @codragraph/cli wiki
52
52
  ```
53
53
 
54
54
  Generates repository documentation from the knowledge graph using an LLM. Requires an API key (saved to `~/.codragraph/config.json` on first use).
@@ -65,7 +65,7 @@ Generates repository documentation from the knowledge graph using an LLM. Requir
65
65
  ### list — Show all indexed repos
66
66
 
67
67
  ```bash
68
- npx codragraph list
68
+ npx @codragraph/cli list
69
69
  ```
70
70
 
71
71
  Lists all repositories registered in `~/.codragraph/registry.json`. The MCP `list_repos` tool provides the same information.
@@ -0,0 +1,146 @@
1
+ ---
2
+ name: codragraph-config-audit
3
+ description: "Use to audit how environment variables, config files, and feature flags are read and used across the codebase — find unused config, missing defaults, undocumented env vars, secrets read into logs. Examples: \"audit env vars\", \"unused config\", \"who reads FOO_BAR env\", \"feature flag usage\", \"config sprawl\""
4
+ ---
5
+
6
+ # Configuration Audit with CodraGraph
7
+
8
+ ## When to Use
9
+
10
+ - "Which env vars do we actually read?"
11
+ - "Which env vars are read but never set in deploy configs?"
12
+ - "Find the unused feature flags I can delete."
13
+ - "Who reads `STRIPE_SECRET_KEY`?"
14
+ - "Is `<config>` ever logged or sent to telemetry?"
15
+ - "Audit config sprawl before consolidating."
16
+
17
+ ## Why CodraGraph helps here
18
+
19
+ Configuration enters your code through a small set of helpers:
20
+ `process.env.X`, `os.getenv("X")`, `config.get("foo.bar")`,
21
+ `featureFlags.isEnabled("flag")`. CodraGraph indexes the calls to those
22
+ helpers and the literal arguments — so a `query` for the helper plus a
23
+ `context` of each call site produces a complete picture of which keys
24
+ are read where.
25
+
26
+ ## Workflow
27
+
28
+ ```
29
+ 1. Identify the config helpers (per-language patterns):
30
+ codragraph_query({query: "process.env getenv ConfigService featureFlags"})
31
+ → list of config-read helpers
32
+
33
+ 2. For each helper, find every call site and its key argument:
34
+ codragraph_cypher({query: `
35
+ MATCH (caller)-[:CALLS]->(helper {name: 'getenv'})
36
+ RETURN caller.name, caller.filePath
37
+ `})
38
+ → For richer key-extraction, read the bodies via context:
39
+ codragraph_context({name: "<caller>", content: true})
40
+ → look for the literal string passed to getenv()
41
+
42
+ 3. Cross-check with deploy configs:
43
+ - Read .env / .env.example / docker-compose.yml / k8s ConfigMaps
44
+ - Build the SET of keys actually defined
45
+ - For each key your code reads but isn't defined: undocumented env var
46
+ - For each key defined but no code reads: dead config — delete
47
+
48
+ 4. Feature-flag specific audit:
49
+ codragraph_query({query: "featureFlags.isEnabled flag.evaluate"})
50
+ → For each flag-read site: codragraph_impact upstream
51
+ → Flags with no callers can be removed
52
+ → Flags with one branch always returning true / false are stale
53
+
54
+ 5. Secret-leakage check:
55
+ codragraph_query({query: "STRIPE_SECRET DATABASE_URL API_KEY"})
56
+ → For each match: codragraph_context to confirm the value is not
57
+ piped to logger / tracer / metrics
58
+ ```
59
+
60
+ ## Audit dimensions
61
+
62
+ | Dimension | Question | CodraGraph approach |
63
+ |---|---|---|
64
+ | **Used** | Is this env var read anywhere? | `query` for the literal key |
65
+ | **Documented** | Is the key in `.env.example` / docs? | grep deploy files; subtract from used set |
66
+ | **Defaulted** | Does the read have a default? | `context` shows the surrounding code |
67
+ | **Validated** | Is the value parsed / type-checked? | `context` for `parseInt` / `URL` / Zod schema in the caller |
68
+ | **Logged** | Does the value flow to telemetry? | `impact` downstream from the read site → check telemetry helpers |
69
+ | **Stale flag** | Is the flag still toggled in production? | combine with deploy-config check |
70
+
71
+ ## Feature flag lifecycle audit
72
+
73
+ ```
74
+ codragraph_cypher({query: `
75
+ MATCH (caller)-[:CALLS]->(ff {name: 'isEnabled'})
76
+ RETURN caller.name, caller.filePath, count(*) AS uses
77
+ ORDER BY uses DESC
78
+ `})
79
+ → for each call site, codragraph_context to extract the flag NAME literal
80
+
81
+ # Then:
82
+ - Flag name read by 0 callers → remove
83
+ - Flag name with both branches identical → stale (always-true or always-false)
84
+ - Flag still wired in code, but config has it pinned `true` for >90 days → graduate
85
+ ```
86
+
87
+ ## Checklist
88
+
89
+ ```
90
+ - [ ] Listed config helpers (env / config / featureFlag readers)
91
+ - [ ] Built the read-set: { key: [ call sites ] }
92
+ - [ ] Built the defined-set from deploy configs
93
+ - [ ] Diff: undocumented (in code, not in config) + dead (in config, not in code)
94
+ - [ ] Spot-check defaults / validation / secret leakage on critical keys
95
+ - [ ] Feature-flag staleness check
96
+ - [ ] Output: read map + recommended deletions / required deploy changes
97
+ ```
98
+
99
+ ## Example: "Audit our feature flags"
100
+
101
+ ```
102
+ 1. codragraph_query({query: "featureFlags.isEnabled"})
103
+ → 47 call sites in 23 files
104
+
105
+ 2. For each call site, extract the flag string (codragraph_context):
106
+ - 'new_checkout' (12 sites)
107
+ - 'experimental_search' (4 sites)
108
+ - 'use_new_pricing' (8 sites)
109
+ - 'kill_legacy_admin' (1 site)
110
+ - 'canary_v3' (0 sites — defined in code dead)
111
+
112
+ 3. Cross-check deploys:
113
+ - 'new_checkout' set to TRUE for 100%% prod since 2026-01 (graduate it)
114
+ - 'experimental_search' set to TRUE for 5%% prod (active experiment, keep)
115
+ - 'use_new_pricing' set to TRUE for 100%% prod since 2026-03 (graduate)
116
+ - 'kill_legacy_admin' set to TRUE for 100%% prod since 2026-02 (graduate)
117
+ - 'canary_v3' not configured anywhere (truly dead)
118
+
119
+ 4. Findings:
120
+ - DELETE: 'canary_v3' (dead code, no callers, no config)
121
+ - GRADUATE: 'new_checkout', 'use_new_pricing', 'kill_legacy_admin' →
122
+ remove the flag check; keep the new behavior unconditionally
123
+ - KEEP: 'experimental_search'
124
+ - Codebase loses: 21 call sites, 1 unused flag definition
125
+ ```
126
+
127
+ ## Output Format
128
+
129
+ ```markdown
130
+ ## Config Audit: <scope>
131
+
132
+ ### Env vars / config keys
133
+ | Key | Read sites | Defined? | Default? | Validated? | Notes |
134
+ |---|--:|---|---|---|---|
135
+ | DATABASE_URL | 4 | ✓ | ✗ | ✗ | add Zod parse |
136
+ | EXPERIMENTAL_FOO | 1 | ✗ | ✓ ('false') | ✓ | undocumented; either document or delete |
137
+ | ... | ... | ... | ... | ... | ... |
138
+
139
+ ### Feature flags
140
+ - DELETE (no callers): canary_v3, legacy_dashboard_b
141
+ - GRADUATE (100%% production for >90 days): new_checkout, kill_legacy_admin
142
+ - KEEP (active experiment): experimental_search, ai_summarize_v2
143
+
144
+ ### Secret-leak check
145
+ - 0 paths from secret reads to logger/metrics/tracer found ✓
146
+ ```