@optave/codegraph 3.9.3 → 3.9.5

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 (116) hide show
  1. package/README.md +10 -10
  2. package/dist/ast-analysis/visitor.d.ts.map +1 -1
  3. package/dist/ast-analysis/visitor.js +14 -0
  4. package/dist/ast-analysis/visitor.js.map +1 -1
  5. package/dist/cli/commands/watch.d.ts.map +1 -1
  6. package/dist/cli/commands/watch.js +2 -0
  7. package/dist/cli/commands/watch.js.map +1 -1
  8. package/dist/cli.js +24 -1
  9. package/dist/cli.js.map +1 -1
  10. package/dist/domain/graph/builder/context.d.ts +17 -0
  11. package/dist/domain/graph/builder/context.d.ts.map +1 -1
  12. package/dist/domain/graph/builder/context.js +7 -0
  13. package/dist/domain/graph/builder/context.js.map +1 -1
  14. package/dist/domain/graph/builder/helpers.d.ts +13 -2
  15. package/dist/domain/graph/builder/helpers.d.ts.map +1 -1
  16. package/dist/domain/graph/builder/helpers.js +30 -4
  17. package/dist/domain/graph/builder/helpers.js.map +1 -1
  18. package/dist/domain/graph/builder/pipeline.d.ts.map +1 -1
  19. package/dist/domain/graph/builder/pipeline.js +221 -51
  20. package/dist/domain/graph/builder/pipeline.js.map +1 -1
  21. package/dist/domain/graph/builder/stages/build-edges.d.ts.map +1 -1
  22. package/dist/domain/graph/builder/stages/build-edges.js +67 -6
  23. package/dist/domain/graph/builder/stages/build-edges.js.map +1 -1
  24. package/dist/domain/graph/builder/stages/build-structure.js +2 -2
  25. package/dist/domain/graph/builder/stages/collect-files.d.ts.map +1 -1
  26. package/dist/domain/graph/builder/stages/collect-files.js +58 -26
  27. package/dist/domain/graph/builder/stages/collect-files.js.map +1 -1
  28. package/dist/domain/graph/builder/stages/detect-changes.d.ts.map +1 -1
  29. package/dist/domain/graph/builder/stages/detect-changes.js +105 -55
  30. package/dist/domain/graph/builder/stages/detect-changes.js.map +1 -1
  31. package/dist/domain/graph/builder/stages/finalize.d.ts.map +1 -1
  32. package/dist/domain/graph/builder/stages/finalize.js +27 -4
  33. package/dist/domain/graph/builder/stages/finalize.js.map +1 -1
  34. package/dist/domain/graph/builder/stages/run-analyses.d.ts.map +1 -1
  35. package/dist/domain/graph/builder/stages/run-analyses.js +5 -20
  36. package/dist/domain/graph/builder/stages/run-analyses.js.map +1 -1
  37. package/dist/domain/graph/journal.d.ts +15 -0
  38. package/dist/domain/graph/journal.d.ts.map +1 -1
  39. package/dist/domain/graph/journal.js +283 -28
  40. package/dist/domain/graph/journal.js.map +1 -1
  41. package/dist/domain/graph/watcher.d.ts +17 -0
  42. package/dist/domain/graph/watcher.d.ts.map +1 -1
  43. package/dist/domain/graph/watcher.js +23 -7
  44. package/dist/domain/graph/watcher.js.map +1 -1
  45. package/dist/domain/parser.d.ts +13 -4
  46. package/dist/domain/parser.d.ts.map +1 -1
  47. package/dist/domain/parser.js +174 -80
  48. package/dist/domain/parser.js.map +1 -1
  49. package/dist/domain/search/generator.d.ts.map +1 -1
  50. package/dist/domain/search/generator.js +28 -2
  51. package/dist/domain/search/generator.js.map +1 -1
  52. package/dist/domain/wasm-worker-entry.d.ts +24 -0
  53. package/dist/domain/wasm-worker-entry.d.ts.map +1 -0
  54. package/dist/domain/wasm-worker-entry.js +643 -0
  55. package/dist/domain/wasm-worker-entry.js.map +1 -0
  56. package/dist/domain/wasm-worker-pool.d.ts +59 -0
  57. package/dist/domain/wasm-worker-pool.d.ts.map +1 -0
  58. package/dist/domain/wasm-worker-pool.js +312 -0
  59. package/dist/domain/wasm-worker-pool.js.map +1 -0
  60. package/dist/domain/wasm-worker-protocol.d.ts +65 -0
  61. package/dist/domain/wasm-worker-protocol.d.ts.map +1 -0
  62. package/dist/domain/wasm-worker-protocol.js +13 -0
  63. package/dist/domain/wasm-worker-protocol.js.map +1 -0
  64. package/dist/extractors/javascript.js +265 -1
  65. package/dist/extractors/javascript.js.map +1 -1
  66. package/dist/features/boundaries.d.ts +2 -2
  67. package/dist/features/boundaries.d.ts.map +1 -1
  68. package/dist/features/boundaries.js +2 -31
  69. package/dist/features/boundaries.js.map +1 -1
  70. package/dist/features/snapshot.d.ts.map +1 -1
  71. package/dist/features/snapshot.js +99 -13
  72. package/dist/features/snapshot.js.map +1 -1
  73. package/dist/features/structure.d.ts.map +1 -1
  74. package/dist/features/structure.js +14 -1
  75. package/dist/features/structure.js.map +1 -1
  76. package/dist/graph/algorithms/louvain.d.ts.map +1 -1
  77. package/dist/graph/algorithms/louvain.js +2 -4
  78. package/dist/graph/algorithms/louvain.js.map +1 -1
  79. package/dist/infrastructure/config.d.ts.map +1 -1
  80. package/dist/infrastructure/config.js +12 -2
  81. package/dist/infrastructure/config.js.map +1 -1
  82. package/dist/shared/globs.d.ts +40 -0
  83. package/dist/shared/globs.d.ts.map +1 -0
  84. package/dist/shared/globs.js +126 -0
  85. package/dist/shared/globs.js.map +1 -0
  86. package/dist/types.d.ts +26 -1
  87. package/dist/types.d.ts.map +1 -1
  88. package/grammars/tree-sitter-c_sharp.wasm +0 -0
  89. package/package.json +7 -7
  90. package/src/ast-analysis/visitor.ts +15 -0
  91. package/src/cli/commands/watch.ts +2 -0
  92. package/src/cli.ts +31 -8
  93. package/src/domain/graph/builder/context.ts +19 -0
  94. package/src/domain/graph/builder/helpers.ts +53 -3
  95. package/src/domain/graph/builder/pipeline.ts +235 -49
  96. package/src/domain/graph/builder/stages/build-edges.ts +80 -6
  97. package/src/domain/graph/builder/stages/build-structure.ts +2 -2
  98. package/src/domain/graph/builder/stages/collect-files.ts +56 -26
  99. package/src/domain/graph/builder/stages/detect-changes.ts +118 -61
  100. package/src/domain/graph/builder/stages/finalize.ts +27 -4
  101. package/src/domain/graph/builder/stages/run-analyses.ts +5 -26
  102. package/src/domain/graph/journal.ts +284 -27
  103. package/src/domain/graph/watcher.ts +29 -9
  104. package/src/domain/parser.ts +166 -73
  105. package/src/domain/search/generator.ts +34 -2
  106. package/src/domain/wasm-worker-entry.ts +788 -0
  107. package/src/domain/wasm-worker-pool.ts +330 -0
  108. package/src/domain/wasm-worker-protocol.ts +81 -0
  109. package/src/extractors/javascript.ts +290 -1
  110. package/src/features/boundaries.ts +2 -27
  111. package/src/features/snapshot.ts +93 -14
  112. package/src/features/structure.ts +17 -1
  113. package/src/graph/algorithms/louvain.ts +2 -4
  114. package/src/infrastructure/config.ts +12 -2
  115. package/src/shared/globs.ts +121 -0
  116. package/src/types.ts +26 -1
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Glob → RegExp conversion utilities.
3
+ *
4
+ * Shared by boundary rules (`features/boundaries.ts`) and the file-collection
5
+ * include/exclude filters (`domain/graph/builder/helpers.ts`). Keeping a single
6
+ * implementation ensures users get consistent glob semantics everywhere.
7
+ *
8
+ * Supported syntax:
9
+ * - `**` matches any sequence of characters including `/`
10
+ * - `*` matches any sequence of characters except `/`
11
+ * - `?` matches a single non-slash character
12
+ * - other regex metacharacters are escaped literally
13
+ *
14
+ * Paths must use forward slashes (callers normalize before testing).
15
+ */
16
+
17
+ /**
18
+ * Compile a glob pattern into a `RegExp` anchored with `^…$`.
19
+ */
20
+ export function globToRegex(pattern: string): RegExp {
21
+ let re = '';
22
+ let i = 0;
23
+ while (i < pattern.length) {
24
+ const ch = pattern[i] as string;
25
+ if (ch === '*' && pattern[i + 1] === '*') {
26
+ i += 2;
27
+ if (pattern[i] === '/') {
28
+ // `**/` matches zero or more full path segments, preserving the
29
+ // directory boundary before the next segment. Without this, patterns
30
+ // like `**/foo.ts` would compile to `^.*foo\.ts$` and match
31
+ // `barfoo.ts`, diverging from Rust `globset` semantics.
32
+ re += '(?:[^/]+/)*';
33
+ i++;
34
+ } else {
35
+ // Bare `**` (e.g. `dir/**`, or trailing) matches anything.
36
+ re += '.*';
37
+ }
38
+ } else if (ch === '*') {
39
+ re += '[^/]*';
40
+ i++;
41
+ } else if (ch === '?') {
42
+ re += '[^/]';
43
+ i++;
44
+ } else if (/[.+^${}()|[\]\\]/.test(ch)) {
45
+ re += `\\${ch}`;
46
+ i++;
47
+ } else {
48
+ re += ch;
49
+ i++;
50
+ }
51
+ }
52
+ return new RegExp(`^${re}$`);
53
+ }
54
+
55
+ const EMPTY_REGEX_LIST: readonly RegExp[] = Object.freeze([]) as readonly RegExp[];
56
+
57
+ // Compile results are cached by pattern content so a long-running host
58
+ // (watch mode, MCP server) doesn't recompile on every buildGraph call.
59
+ // Capped to avoid unbounded growth when callers pass many distinct lists.
60
+ const COMPILE_CACHE_MAX = 32;
61
+ const compileCache = new Map<string, readonly RegExp[]>();
62
+
63
+ function buildCacheKey(patterns: readonly string[]): string {
64
+ // JSON.stringify avoids ambiguity when patterns legitimately contain any
65
+ // single character (including control characters or separators a caller
66
+ // might choose): ["a", "bc"] → '["a","bc"]' vs ["ab", "c"] → '["ab","c"]'.
67
+ return JSON.stringify(patterns);
68
+ }
69
+
70
+ /**
71
+ * Compile a list of glob patterns. Invalid / empty patterns are skipped.
72
+ *
73
+ * Results are memoized per pattern-content so repeated `buildGraph` calls
74
+ * with the same include/exclude lists reuse the compiled regexes. The
75
+ * returned array is shared across callers and must not be mutated.
76
+ */
77
+ export function compileGlobs(patterns: readonly string[] | undefined): readonly RegExp[] {
78
+ if (!patterns || patterns.length === 0) return EMPTY_REGEX_LIST;
79
+ const key = buildCacheKey(patterns);
80
+ const cached = compileCache.get(key);
81
+ if (cached) return cached;
82
+ const out: RegExp[] = [];
83
+ for (const p of patterns) {
84
+ if (typeof p !== 'string' || p.length === 0) continue;
85
+ try {
86
+ out.push(globToRegex(p));
87
+ } catch {
88
+ // Ignore malformed patterns rather than failing the whole build.
89
+ }
90
+ }
91
+ const frozen = Object.freeze(out) as readonly RegExp[];
92
+ if (compileCache.size >= COMPILE_CACHE_MAX) {
93
+ // FIFO eviction — Map iterates insertion order. Config pattern sets
94
+ // are small and stable, so a simple cap is sufficient.
95
+ const first = compileCache.keys().next().value;
96
+ if (first !== undefined) compileCache.delete(first);
97
+ }
98
+ compileCache.set(key, frozen);
99
+ return frozen;
100
+ }
101
+
102
+ /**
103
+ * Clear the compiled-glob cache. Intended for long-running hosts that
104
+ * need to reload config (e.g. watch mode after `.codegraphrc.json` edits)
105
+ * and for test isolation.
106
+ */
107
+ export function clearGlobCache(): void {
108
+ compileCache.clear();
109
+ }
110
+
111
+ /**
112
+ * `true` when at least one compiled pattern matches the given path.
113
+ *
114
+ * The path must already be normalized to forward slashes.
115
+ */
116
+ export function matchesAny(regexes: readonly RegExp[], path: string): boolean {
117
+ for (const re of regexes) {
118
+ if (re.test(path)) return true;
119
+ }
120
+ return false;
121
+ }
package/src/types.ts CHANGED
@@ -1033,7 +1033,23 @@ export interface PipelineContext {
1033
1033
  lineCountMap: Map<string, number>;
1034
1034
 
1035
1035
  // Phase timing
1036
- timing: Record<string, number>;
1036
+ timing: {
1037
+ setupMs?: number;
1038
+ collectMs?: number;
1039
+ detectMs?: number;
1040
+ parseMs?: number;
1041
+ insertMs?: number;
1042
+ resolveMs?: number;
1043
+ edgesMs?: number;
1044
+ structureMs?: number;
1045
+ rolesMs?: number;
1046
+ astMs?: number;
1047
+ complexityMs?: number;
1048
+ cfgMs?: number;
1049
+ dataflowMs?: number;
1050
+ finalizeMs?: number;
1051
+ [key: string]: number | undefined;
1052
+ };
1037
1053
  buildStart: number;
1038
1054
  }
1039
1055
 
@@ -1053,6 +1069,8 @@ export interface BuildGraphOpts {
1053
1069
  export interface BuildResult {
1054
1070
  phases: {
1055
1071
  setupMs: number;
1072
+ collectMs: number;
1073
+ detectMs: number;
1056
1074
  parseMs: number;
1057
1075
  insertMs: number;
1058
1076
  resolveMs: number;
@@ -1104,6 +1122,13 @@ export interface CodegraphConfig {
1104
1122
  model: string | null;
1105
1123
  baseUrl: string | null;
1106
1124
  apiKey: string | null;
1125
+ /**
1126
+ * Command that prints the API key to stdout. Must be a single string —
1127
+ * it is split on whitespace and executed via `execFileSync` with no shell,
1128
+ * so shell features like `$(...)`, pipes, globs, or variable expansion are
1129
+ * not supported. Example: `"op read op://vault/openai/api-key"`. Non-string
1130
+ * values are rejected with a `ConfigError` at load time.
1131
+ */
1107
1132
  apiKeyCommand: string | null;
1108
1133
  };
1109
1134