@optave/codegraph 3.12.0 → 3.13.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 (144) hide show
  1. package/README.md +71 -35
  2. package/dist/cli/commands/audit.d.ts.map +1 -1
  3. package/dist/cli/commands/audit.js +2 -1
  4. package/dist/cli/commands/audit.js.map +1 -1
  5. package/dist/cli/commands/batch.d.ts.map +1 -1
  6. package/dist/cli/commands/batch.js +1 -0
  7. package/dist/cli/commands/batch.js.map +1 -1
  8. package/dist/cli/commands/build.d.ts.map +1 -1
  9. package/dist/cli/commands/build.js +6 -1
  10. package/dist/cli/commands/build.js.map +1 -1
  11. package/dist/cli/commands/config.d.ts +3 -0
  12. package/dist/cli/commands/config.d.ts.map +1 -0
  13. package/dist/cli/commands/config.js +272 -0
  14. package/dist/cli/commands/config.js.map +1 -0
  15. package/dist/cli/commands/triage.js +1 -1
  16. package/dist/cli/commands/triage.js.map +1 -1
  17. package/dist/cli/index.d.ts.map +1 -1
  18. package/dist/cli/index.js +10 -0
  19. package/dist/cli/index.js.map +1 -1
  20. package/dist/cli/shared/options.d.ts +2 -1
  21. package/dist/cli/shared/options.d.ts.map +1 -1
  22. package/dist/cli/shared/options.js +11 -1
  23. package/dist/cli/shared/options.js.map +1 -1
  24. package/dist/cli/types.d.ts +2 -0
  25. package/dist/cli/types.d.ts.map +1 -1
  26. package/dist/db/migrations.js +1 -1
  27. package/dist/db/migrations.js.map +1 -1
  28. package/dist/domain/graph/builder/call-resolver.d.ts +12 -8
  29. package/dist/domain/graph/builder/call-resolver.d.ts.map +1 -1
  30. package/dist/domain/graph/builder/call-resolver.js +93 -38
  31. package/dist/domain/graph/builder/call-resolver.js.map +1 -1
  32. package/dist/domain/graph/builder/cha.d.ts +9 -1
  33. package/dist/domain/graph/builder/cha.d.ts.map +1 -1
  34. package/dist/domain/graph/builder/cha.js +17 -2
  35. package/dist/domain/graph/builder/cha.js.map +1 -1
  36. package/dist/domain/graph/builder/helpers.d.ts +8 -0
  37. package/dist/domain/graph/builder/helpers.d.ts.map +1 -1
  38. package/dist/domain/graph/builder/helpers.js +22 -3
  39. package/dist/domain/graph/builder/helpers.js.map +1 -1
  40. package/dist/domain/graph/builder/incremental.d.ts.map +1 -1
  41. package/dist/domain/graph/builder/incremental.js +1 -1
  42. package/dist/domain/graph/builder/incremental.js.map +1 -1
  43. package/dist/domain/graph/builder/pipeline.d.ts.map +1 -1
  44. package/dist/domain/graph/builder/pipeline.js +37 -2
  45. package/dist/domain/graph/builder/pipeline.js.map +1 -1
  46. package/dist/domain/graph/builder/stages/build-edges.d.ts +0 -2
  47. package/dist/domain/graph/builder/stages/build-edges.d.ts.map +1 -1
  48. package/dist/domain/graph/builder/stages/build-edges.js +88 -318
  49. package/dist/domain/graph/builder/stages/build-edges.js.map +1 -1
  50. package/dist/domain/graph/builder/stages/detect-changes.js +1 -1
  51. package/dist/domain/graph/builder/stages/detect-changes.js.map +1 -1
  52. package/dist/domain/graph/builder/stages/finalize.d.ts.map +1 -1
  53. package/dist/domain/graph/builder/stages/finalize.js +4 -0
  54. package/dist/domain/graph/builder/stages/finalize.js.map +1 -1
  55. package/dist/domain/graph/builder/stages/native-orchestrator.d.ts.map +1 -1
  56. package/dist/domain/graph/builder/stages/native-orchestrator.js +341 -82
  57. package/dist/domain/graph/builder/stages/native-orchestrator.js.map +1 -1
  58. package/dist/domain/graph/builder/stages/resolve-imports.js +1 -1
  59. package/dist/domain/graph/builder/stages/resolve-imports.js.map +1 -1
  60. package/dist/domain/parser.d.ts +4 -5
  61. package/dist/domain/parser.d.ts.map +1 -1
  62. package/dist/domain/parser.js +46 -15
  63. package/dist/domain/parser.js.map +1 -1
  64. package/dist/domain/wasm-worker-entry.js +10 -2
  65. package/dist/domain/wasm-worker-entry.js.map +1 -1
  66. package/dist/domain/wasm-worker-pool.d.ts.map +1 -1
  67. package/dist/domain/wasm-worker-pool.js +2 -0
  68. package/dist/domain/wasm-worker-pool.js.map +1 -1
  69. package/dist/domain/wasm-worker-protocol.d.ts +1 -0
  70. package/dist/domain/wasm-worker-protocol.d.ts.map +1 -1
  71. package/dist/extractors/cpp.d.ts.map +1 -1
  72. package/dist/extractors/cpp.js +42 -1
  73. package/dist/extractors/cpp.js.map +1 -1
  74. package/dist/extractors/cuda.d.ts.map +1 -1
  75. package/dist/extractors/cuda.js +42 -1
  76. package/dist/extractors/cuda.js.map +1 -1
  77. package/dist/extractors/helpers.d.ts +11 -0
  78. package/dist/extractors/helpers.d.ts.map +1 -1
  79. package/dist/extractors/helpers.js +40 -0
  80. package/dist/extractors/helpers.js.map +1 -1
  81. package/dist/extractors/java.d.ts.map +1 -1
  82. package/dist/extractors/java.js +8 -7
  83. package/dist/extractors/java.js.map +1 -1
  84. package/dist/extractors/javascript.js +137 -6
  85. package/dist/extractors/javascript.js.map +1 -1
  86. package/dist/features/structure-query.d.ts +1 -1
  87. package/dist/features/structure-query.d.ts.map +1 -1
  88. package/dist/features/structure-query.js +6 -6
  89. package/dist/features/structure-query.js.map +1 -1
  90. package/dist/index.d.ts +1 -1
  91. package/dist/index.d.ts.map +1 -1
  92. package/dist/index.js +1 -1
  93. package/dist/index.js.map +1 -1
  94. package/dist/infrastructure/config.d.ts +77 -4
  95. package/dist/infrastructure/config.d.ts.map +1 -1
  96. package/dist/infrastructure/config.js +395 -21
  97. package/dist/infrastructure/config.js.map +1 -1
  98. package/dist/infrastructure/registry.d.ts +27 -0
  99. package/dist/infrastructure/registry.d.ts.map +1 -1
  100. package/dist/infrastructure/registry.js +59 -1
  101. package/dist/infrastructure/registry.js.map +1 -1
  102. package/dist/presentation/structure.d.ts +1 -1
  103. package/dist/presentation/structure.d.ts.map +1 -1
  104. package/dist/presentation/structure.js +2 -2
  105. package/dist/presentation/structure.js.map +1 -1
  106. package/dist/types.d.ts +37 -0
  107. package/dist/types.d.ts.map +1 -1
  108. package/grammars/tree-sitter-gleam.wasm +0 -0
  109. package/package.json +7 -8
  110. package/src/cli/commands/audit.ts +2 -1
  111. package/src/cli/commands/batch.ts +1 -0
  112. package/src/cli/commands/build.ts +6 -1
  113. package/src/cli/commands/config.ts +353 -0
  114. package/src/cli/commands/triage.ts +1 -1
  115. package/src/cli/index.ts +10 -0
  116. package/src/cli/shared/options.ts +11 -1
  117. package/src/cli/types.ts +2 -0
  118. package/src/db/migrations.ts +1 -1
  119. package/src/domain/graph/builder/call-resolver.ts +99 -41
  120. package/src/domain/graph/builder/cha.ts +18 -1
  121. package/src/domain/graph/builder/helpers.ts +24 -4
  122. package/src/domain/graph/builder/incremental.ts +1 -0
  123. package/src/domain/graph/builder/pipeline.ts +49 -2
  124. package/src/domain/graph/builder/stages/build-edges.ts +130 -399
  125. package/src/domain/graph/builder/stages/detect-changes.ts +1 -1
  126. package/src/domain/graph/builder/stages/finalize.ts +4 -0
  127. package/src/domain/graph/builder/stages/native-orchestrator.ts +396 -92
  128. package/src/domain/graph/builder/stages/resolve-imports.ts +1 -1
  129. package/src/domain/parser.ts +45 -14
  130. package/src/domain/wasm-worker-entry.ts +10 -2
  131. package/src/domain/wasm-worker-pool.ts +1 -0
  132. package/src/domain/wasm-worker-protocol.ts +1 -0
  133. package/src/extractors/cpp.ts +44 -1
  134. package/src/extractors/cuda.ts +44 -1
  135. package/src/extractors/helpers.ts +43 -0
  136. package/src/extractors/java.ts +8 -7
  137. package/src/extractors/javascript.ts +127 -6
  138. package/src/features/structure-query.ts +7 -7
  139. package/src/index.ts +5 -1
  140. package/src/infrastructure/config.ts +481 -22
  141. package/src/infrastructure/registry.ts +82 -1
  142. package/src/presentation/structure.ts +3 -3
  143. package/src/types.ts +41 -0
  144. package/grammars/tree-sitter-erlang.wasm +0 -0
@@ -48,6 +48,13 @@ export const BUILTIN_RECEIVERS: Set<string> = new Set([
48
48
  'require',
49
49
  ]);
50
50
 
51
+ /** Phase 8.6: confidence penalty applied to CHA-dispatch edges. */
52
+ export const CHA_DISPATCH_PENALTY = 0.1;
53
+ /** Phase 8.6: fixed confidence for typed-receiver (interface/CHA) dispatch edges.
54
+ * File proximity is not meaningful for virtual dispatch — all three engine paths
55
+ * (WASM inline, WASM post-pass, native post-pass) must agree on this value. */
56
+ export const CHA_TYPED_DISPATCH_CONFIDENCE = 0.8;
57
+
51
58
  /** Check if a directory entry should be skipped (ignored dirs, dotfiles). */
52
59
  function shouldSkipEntry(entry: fs.Dirent, extraIgnore: Set<string> | null): boolean {
53
60
  if (entry.name.startsWith('.') && entry.name !== '.') {
@@ -361,6 +368,9 @@ export function batchInsertEdges(db: BetterSqlite3Database, rows: unknown[][]):
361
368
  }
362
369
  }
363
370
 
371
+ /** Confidence assigned to CHA-expanded interface/abstract dispatch edges. */
372
+ export const CHA_DISPATCH_CONFIDENCE = 0.8;
373
+
364
374
  /**
365
375
  * CHA (Class Hierarchy Analysis) post-pass.
366
376
  *
@@ -454,13 +464,15 @@ export function runChaPostPass(db: BetterSqlite3Database): number {
454
464
 
455
465
  const callToMethods = db
456
466
  .prepare(
457
- `SELECT e.source_id, tgt.name AS method_name
467
+ `SELECT e.source_id, src.name AS caller_name, tgt.name AS method_name
458
468
  FROM edges e
459
469
  JOIN nodes tgt ON e.target_id = tgt.id
470
+ JOIN nodes src ON e.source_id = src.id
460
471
  WHERE e.kind = 'calls' AND tgt.kind = 'method'
461
- AND INSTR(tgt.name, '.') > 0`,
472
+ AND INSTR(tgt.name, '.') > 0
473
+ AND (e.technique IS NULL OR e.technique != 'cha-expanded')`,
462
474
  )
463
- .all() as Array<{ source_id: number; method_name: string }>;
475
+ .all() as Array<{ source_id: number; caller_name: string; method_name: string }>;
464
476
 
465
477
  const seen = new Set<string>();
466
478
  // Scope deduplication to only the source_ids we are about to expand, avoiding
@@ -511,10 +523,18 @@ export function runChaPostPass(db: BetterSqlite3Database): number {
511
523
  const qualifiedName = `${cls}.${methodSuffix}`;
512
524
  const methodNodes = findMethodStmt.all(qualifiedName) as Array<{ id: number }>;
513
525
  for (const methodNode of methodNodes) {
526
+ if (methodNode.id === source_id) continue; // skip self-loops
514
527
  const key = `${source_id}|${methodNode.id}`;
515
528
  if (seen.has(key)) continue;
516
529
  seen.add(key);
517
- newEdges.push([source_id, methodNode.id, 'calls', 0.8, 0, 'cha']);
530
+ newEdges.push([
531
+ source_id,
532
+ methodNode.id,
533
+ 'calls',
534
+ CHA_TYPED_DISPATCH_CONFIDENCE,
535
+ 0,
536
+ 'cha-expanded',
537
+ ]);
518
538
  }
519
539
  }
520
540
 
@@ -620,6 +620,7 @@ function buildCallEdges(
620
620
  relPath,
621
621
  typeMap,
622
622
  seenCallEdges,
623
+ importedNames,
623
624
  );
624
625
  if (recv) {
625
626
  stmts.insertEdge.run(recv.callerId, recv.receiverId, 'receiver', recv.confidence, 0);
@@ -15,7 +15,14 @@ import {
15
15
  MIGRATIONS,
16
16
  openDb,
17
17
  } from '../../../db/index.js';
18
- import { detectWorkspaces, loadConfig } from '../../../infrastructure/config.js';
18
+ import {
19
+ computeConfigHash,
20
+ detectWorkspaces,
21
+ getLastAppliedGlobalConfig,
22
+ getLastAppliedGlobalPath,
23
+ loadConfig,
24
+ promptForConsentIfNeeded,
25
+ } from '../../../infrastructure/config.js';
19
26
  import { debug, info, warn } from '../../../infrastructure/logger.js';
20
27
  import { loadNative } from '../../../infrastructure/native.js';
21
28
  import { toErrorMessage } from '../../../shared/errors.js';
@@ -114,6 +121,16 @@ function checkEngineSchemaMismatch(ctx: PipelineContext): void {
114
121
  );
115
122
  ctx.forceFullRebuild = true;
116
123
  }
124
+
125
+ // Config hash — promotes to full rebuild when build-relevant config changes
126
+ // (include/exclude/ignoreDirs/extensions/aliases/build.*).
127
+ // This closes the pre-existing config-change gap and covers the new global-config layer.
128
+ const currentConfigHash = computeConfigHash(ctx.config);
129
+ const prevConfigHash = meta('config_hash');
130
+ if (prevConfigHash && prevConfigHash !== currentConfigHash) {
131
+ info('Build-relevant config changed, promoting to full rebuild.');
132
+ ctx.forceFullRebuild = true;
133
+ }
117
134
  }
118
135
 
119
136
  function warnOnEmbeddingsWipe(ctx: PipelineContext): void {
@@ -172,7 +189,7 @@ function setupPipeline(ctx: PipelineContext): void {
172
189
  ctx.db = openDb(ctx.dbPath);
173
190
  initSchema(ctx.db);
174
191
 
175
- ctx.config = loadConfig(ctx.rootDir);
192
+ ctx.config = loadConfig(ctx.rootDir, { userConfig: ctx.opts.userConfig });
176
193
  // Merge caller-supplied excludes on top of the file-config excludes so
177
194
  // programmatic callers (e.g. benchmark scripts) can extend exclusion
178
195
  // without mutating .codegraphrc.json. Native orchestrator picks this up
@@ -186,6 +203,30 @@ function setupPipeline(ctx: PipelineContext): void {
186
203
  ctx.incremental =
187
204
  ctx.opts.incremental !== false && ctx.config.build && ctx.config.build.incremental !== false;
188
205
 
206
+ // ── Build-time global-config notice ──────────────────────────────
207
+ // Use the already-parsed and sanitized global config cached by loadConfig —
208
+ // avoids a second disk read and the TOCTOU window between loadConfig and here.
209
+ const appliedGlobalPath = getLastAppliedGlobalPath();
210
+ if (appliedGlobalPath) {
211
+ const buildAffectingKeys = [
212
+ 'include',
213
+ 'exclude',
214
+ 'ignoreDirs',
215
+ 'extensions',
216
+ 'aliases',
217
+ 'build',
218
+ ];
219
+ const globalData = getLastAppliedGlobalConfig();
220
+ if (globalData) {
221
+ const injectedKeys = buildAffectingKeys.filter((k) => k in globalData);
222
+ if (injectedKeys.length > 0) {
223
+ process.stderr.write(
224
+ `ℹ global config applied (${appliedGlobalPath}) — injecting: ${injectedKeys.join(', ')} · --no-user-config to ignore\n`,
225
+ );
226
+ }
227
+ }
228
+ }
229
+
189
230
  initializeEngine(ctx);
190
231
  checkEngineSchemaMismatch(ctx);
191
232
  warnOnEmbeddingsWipe(ctx);
@@ -348,6 +389,12 @@ export async function buildGraph(
348
389
  ctx.rootDir = rootDir;
349
390
 
350
391
  try {
392
+ // Interactive consent prompt — only fires when the caller opts in (build
393
+ // command with TTY), a global file exists, and the repo is undecided.
394
+ if (opts.promptForConsent) {
395
+ await promptForConsentIfNeeded(rootDir);
396
+ }
397
+
351
398
  setupPipeline(ctx);
352
399
 
353
400
  // ── JS-side fast-skip for native incremental (#1054) ──────────────