@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.
- package/README.md +10 -10
- package/dist/ast-analysis/visitor.d.ts.map +1 -1
- package/dist/ast-analysis/visitor.js +14 -0
- package/dist/ast-analysis/visitor.js.map +1 -1
- package/dist/cli/commands/watch.d.ts.map +1 -1
- package/dist/cli/commands/watch.js +2 -0
- package/dist/cli/commands/watch.js.map +1 -1
- package/dist/cli.js +24 -1
- package/dist/cli.js.map +1 -1
- package/dist/domain/graph/builder/context.d.ts +17 -0
- package/dist/domain/graph/builder/context.d.ts.map +1 -1
- package/dist/domain/graph/builder/context.js +7 -0
- package/dist/domain/graph/builder/context.js.map +1 -1
- package/dist/domain/graph/builder/helpers.d.ts +13 -2
- package/dist/domain/graph/builder/helpers.d.ts.map +1 -1
- package/dist/domain/graph/builder/helpers.js +30 -4
- package/dist/domain/graph/builder/helpers.js.map +1 -1
- package/dist/domain/graph/builder/pipeline.d.ts.map +1 -1
- package/dist/domain/graph/builder/pipeline.js +221 -51
- package/dist/domain/graph/builder/pipeline.js.map +1 -1
- package/dist/domain/graph/builder/stages/build-edges.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/build-edges.js +67 -6
- package/dist/domain/graph/builder/stages/build-edges.js.map +1 -1
- package/dist/domain/graph/builder/stages/build-structure.js +2 -2
- package/dist/domain/graph/builder/stages/collect-files.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/collect-files.js +58 -26
- package/dist/domain/graph/builder/stages/collect-files.js.map +1 -1
- package/dist/domain/graph/builder/stages/detect-changes.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/detect-changes.js +105 -55
- package/dist/domain/graph/builder/stages/detect-changes.js.map +1 -1
- package/dist/domain/graph/builder/stages/finalize.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/finalize.js +27 -4
- package/dist/domain/graph/builder/stages/finalize.js.map +1 -1
- package/dist/domain/graph/builder/stages/run-analyses.d.ts.map +1 -1
- package/dist/domain/graph/builder/stages/run-analyses.js +5 -20
- package/dist/domain/graph/builder/stages/run-analyses.js.map +1 -1
- package/dist/domain/graph/journal.d.ts +15 -0
- package/dist/domain/graph/journal.d.ts.map +1 -1
- package/dist/domain/graph/journal.js +283 -28
- package/dist/domain/graph/journal.js.map +1 -1
- package/dist/domain/graph/watcher.d.ts +17 -0
- package/dist/domain/graph/watcher.d.ts.map +1 -1
- package/dist/domain/graph/watcher.js +23 -7
- package/dist/domain/graph/watcher.js.map +1 -1
- package/dist/domain/parser.d.ts +13 -4
- package/dist/domain/parser.d.ts.map +1 -1
- package/dist/domain/parser.js +174 -80
- package/dist/domain/parser.js.map +1 -1
- package/dist/domain/search/generator.d.ts.map +1 -1
- package/dist/domain/search/generator.js +28 -2
- package/dist/domain/search/generator.js.map +1 -1
- package/dist/domain/wasm-worker-entry.d.ts +24 -0
- package/dist/domain/wasm-worker-entry.d.ts.map +1 -0
- package/dist/domain/wasm-worker-entry.js +643 -0
- package/dist/domain/wasm-worker-entry.js.map +1 -0
- package/dist/domain/wasm-worker-pool.d.ts +59 -0
- package/dist/domain/wasm-worker-pool.d.ts.map +1 -0
- package/dist/domain/wasm-worker-pool.js +312 -0
- package/dist/domain/wasm-worker-pool.js.map +1 -0
- package/dist/domain/wasm-worker-protocol.d.ts +65 -0
- package/dist/domain/wasm-worker-protocol.d.ts.map +1 -0
- package/dist/domain/wasm-worker-protocol.js +13 -0
- package/dist/domain/wasm-worker-protocol.js.map +1 -0
- package/dist/extractors/javascript.js +265 -1
- package/dist/extractors/javascript.js.map +1 -1
- package/dist/features/boundaries.d.ts +2 -2
- package/dist/features/boundaries.d.ts.map +1 -1
- package/dist/features/boundaries.js +2 -31
- package/dist/features/boundaries.js.map +1 -1
- package/dist/features/snapshot.d.ts.map +1 -1
- package/dist/features/snapshot.js +99 -13
- package/dist/features/snapshot.js.map +1 -1
- package/dist/features/structure.d.ts.map +1 -1
- package/dist/features/structure.js +14 -1
- package/dist/features/structure.js.map +1 -1
- package/dist/graph/algorithms/louvain.d.ts.map +1 -1
- package/dist/graph/algorithms/louvain.js +2 -4
- package/dist/graph/algorithms/louvain.js.map +1 -1
- package/dist/infrastructure/config.d.ts.map +1 -1
- package/dist/infrastructure/config.js +12 -2
- package/dist/infrastructure/config.js.map +1 -1
- package/dist/shared/globs.d.ts +40 -0
- package/dist/shared/globs.d.ts.map +1 -0
- package/dist/shared/globs.js +126 -0
- package/dist/shared/globs.js.map +1 -0
- package/dist/types.d.ts +26 -1
- package/dist/types.d.ts.map +1 -1
- package/grammars/tree-sitter-c_sharp.wasm +0 -0
- package/package.json +7 -7
- package/src/ast-analysis/visitor.ts +15 -0
- package/src/cli/commands/watch.ts +2 -0
- package/src/cli.ts +31 -8
- package/src/domain/graph/builder/context.ts +19 -0
- package/src/domain/graph/builder/helpers.ts +53 -3
- package/src/domain/graph/builder/pipeline.ts +235 -49
- package/src/domain/graph/builder/stages/build-edges.ts +80 -6
- package/src/domain/graph/builder/stages/build-structure.ts +2 -2
- package/src/domain/graph/builder/stages/collect-files.ts +56 -26
- package/src/domain/graph/builder/stages/detect-changes.ts +118 -61
- package/src/domain/graph/builder/stages/finalize.ts +27 -4
- package/src/domain/graph/builder/stages/run-analyses.ts +5 -26
- package/src/domain/graph/journal.ts +284 -27
- package/src/domain/graph/watcher.ts +29 -9
- package/src/domain/parser.ts +166 -73
- package/src/domain/search/generator.ts +34 -2
- package/src/domain/wasm-worker-entry.ts +788 -0
- package/src/domain/wasm-worker-pool.ts +330 -0
- package/src/domain/wasm-worker-protocol.ts +81 -0
- package/src/extractors/javascript.ts +290 -1
- package/src/features/boundaries.ts +2 -27
- package/src/features/snapshot.ts +93 -14
- package/src/features/structure.ts +17 -1
- package/src/graph/algorithms/louvain.ts +2 -4
- package/src/infrastructure/config.ts +12 -2
- package/src/shared/globs.ts +121 -0
- 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:
|
|
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
|
|