@saluzi/codegraph 0.1.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 (189) hide show
  1. package/dist/bin/codegraph.d.ts +25 -0
  2. package/dist/bin/node-version-check.d.ts +37 -0
  3. package/dist/bin/uninstall.d.ts +14 -0
  4. package/dist/context/formatter.d.ts +33 -0
  5. package/dist/context/formatter.js +244 -0
  6. package/dist/context/index.d.ts +117 -0
  7. package/dist/context/index.js +1050 -0
  8. package/dist/db/index.d.ts +101 -0
  9. package/dist/db/index.js +250 -0
  10. package/dist/db/migrations.d.ts +47 -0
  11. package/dist/db/migrations.js +131 -0
  12. package/dist/db/queries.d.ts +291 -0
  13. package/dist/db/queries.js +1349 -0
  14. package/dist/db/schema.sql +151 -0
  15. package/dist/db/sqlite-adapter.d.ts +49 -0
  16. package/dist/db/sqlite-adapter.js +141 -0
  17. package/dist/directory.d.ts +62 -0
  18. package/dist/directory.js +264 -0
  19. package/dist/errors.d.ts +149 -0
  20. package/dist/errors.js +219 -0
  21. package/dist/extraction/dfm-extractor.d.ts +31 -0
  22. package/dist/extraction/dfm-extractor.js +151 -0
  23. package/dist/extraction/grammars.d.ts +94 -0
  24. package/dist/extraction/grammars.js +357 -0
  25. package/dist/extraction/index.d.ts +148 -0
  26. package/dist/extraction/index.js +1286 -0
  27. package/dist/extraction/languages/c-cpp.d.ts +4 -0
  28. package/dist/extraction/languages/c-cpp.js +126 -0
  29. package/dist/extraction/languages/csharp.d.ts +3 -0
  30. package/dist/extraction/languages/csharp.js +72 -0
  31. package/dist/extraction/languages/dart.d.ts +3 -0
  32. package/dist/extraction/languages/dart.js +192 -0
  33. package/dist/extraction/languages/go.d.ts +3 -0
  34. package/dist/extraction/languages/go.js +58 -0
  35. package/dist/extraction/languages/index.d.ts +10 -0
  36. package/dist/extraction/languages/index.js +49 -0
  37. package/dist/extraction/languages/java.d.ts +3 -0
  38. package/dist/extraction/languages/java.js +64 -0
  39. package/dist/extraction/languages/javascript.d.ts +3 -0
  40. package/dist/extraction/languages/javascript.js +90 -0
  41. package/dist/extraction/languages/kotlin.d.ts +3 -0
  42. package/dist/extraction/languages/kotlin.js +253 -0
  43. package/dist/extraction/languages/lua.d.ts +3 -0
  44. package/dist/extraction/languages/lua.js +150 -0
  45. package/dist/extraction/languages/luau.d.ts +3 -0
  46. package/dist/extraction/languages/luau.js +37 -0
  47. package/dist/extraction/languages/pascal.d.ts +3 -0
  48. package/dist/extraction/languages/pascal.js +66 -0
  49. package/dist/extraction/languages/php.d.ts +3 -0
  50. package/dist/extraction/languages/php.js +107 -0
  51. package/dist/extraction/languages/python.d.ts +3 -0
  52. package/dist/extraction/languages/python.js +56 -0
  53. package/dist/extraction/languages/ruby.d.ts +3 -0
  54. package/dist/extraction/languages/ruby.js +114 -0
  55. package/dist/extraction/languages/rust.d.ts +3 -0
  56. package/dist/extraction/languages/rust.js +109 -0
  57. package/dist/extraction/languages/scala.d.ts +3 -0
  58. package/dist/extraction/languages/scala.js +139 -0
  59. package/dist/extraction/languages/swift.d.ts +3 -0
  60. package/dist/extraction/languages/swift.js +91 -0
  61. package/dist/extraction/languages/typescript.d.ts +3 -0
  62. package/dist/extraction/languages/typescript.js +129 -0
  63. package/dist/extraction/liquid-extractor.d.ts +52 -0
  64. package/dist/extraction/liquid-extractor.js +313 -0
  65. package/dist/extraction/parse-worker.d.ts +8 -0
  66. package/dist/extraction/parse-worker.js +94 -0
  67. package/dist/extraction/svelte-extractor.d.ts +56 -0
  68. package/dist/extraction/svelte-extractor.js +272 -0
  69. package/dist/extraction/tree-sitter-helpers.d.ts +39 -0
  70. package/dist/extraction/tree-sitter-helpers.js +103 -0
  71. package/dist/extraction/tree-sitter-types.d.ts +191 -0
  72. package/dist/extraction/tree-sitter-types.js +10 -0
  73. package/dist/extraction/tree-sitter.d.ts +238 -0
  74. package/dist/extraction/tree-sitter.js +2430 -0
  75. package/dist/extraction/vue-extractor.d.ts +36 -0
  76. package/dist/extraction/vue-extractor.js +163 -0
  77. package/dist/extraction/wasm/tree-sitter-c.wasm +0 -0
  78. package/dist/extraction/wasm/tree-sitter-c_sharp.wasm +0 -0
  79. package/dist/extraction/wasm/tree-sitter-cpp.wasm +0 -0
  80. package/dist/extraction/wasm/tree-sitter-dart.wasm +0 -0
  81. package/dist/extraction/wasm/tree-sitter-go.wasm +0 -0
  82. package/dist/extraction/wasm/tree-sitter-java.wasm +0 -0
  83. package/dist/extraction/wasm/tree-sitter-javascript.wasm +0 -0
  84. package/dist/extraction/wasm/tree-sitter-kotlin.wasm +0 -0
  85. package/dist/extraction/wasm/tree-sitter-lua.wasm +0 -0
  86. package/dist/extraction/wasm/tree-sitter-luau.wasm +0 -0
  87. package/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
  88. package/dist/extraction/wasm/tree-sitter-php.wasm +0 -0
  89. package/dist/extraction/wasm/tree-sitter-python.wasm +0 -0
  90. package/dist/extraction/wasm/tree-sitter-ruby.wasm +0 -0
  91. package/dist/extraction/wasm/tree-sitter-rust.wasm +0 -0
  92. package/dist/extraction/wasm/tree-sitter-scala.wasm +0 -0
  93. package/dist/extraction/wasm/tree-sitter-swift.wasm +0 -0
  94. package/dist/extraction/wasm/tree-sitter-tsx.wasm +0 -0
  95. package/dist/extraction/wasm/tree-sitter-typescript.wasm +0 -0
  96. package/dist/extraction/wasm-runtime-flags.d.ts +46 -0
  97. package/dist/extraction/wasm-runtime-flags.js +105 -0
  98. package/dist/graph/index.d.ts +8 -0
  99. package/dist/graph/index.js +13 -0
  100. package/dist/graph/queries.d.ts +109 -0
  101. package/dist/graph/queries.js +366 -0
  102. package/dist/graph/traversal.d.ts +137 -0
  103. package/dist/graph/traversal.js +528 -0
  104. package/dist/index.d.ts +509 -0
  105. package/dist/index.js +800 -0
  106. package/dist/installer/claude-md-template.d.ts +19 -0
  107. package/dist/installer/config-writer.d.ts +29 -0
  108. package/dist/installer/index.d.ts +140 -0
  109. package/dist/installer/instructions-template.d.ts +30 -0
  110. package/dist/installer/targets/claude.d.ts +55 -0
  111. package/dist/installer/targets/codex.d.ts +18 -0
  112. package/dist/installer/targets/cursor.d.ts +35 -0
  113. package/dist/installer/targets/hermes.d.ts +18 -0
  114. package/dist/installer/targets/opencode.d.ts +30 -0
  115. package/dist/installer/targets/registry.d.ts +38 -0
  116. package/dist/installer/targets/shared.d.ts +92 -0
  117. package/dist/installer/targets/toml.d.ts +64 -0
  118. package/dist/installer/targets/types.d.ts +122 -0
  119. package/dist/mcp/index.d.ts +98 -0
  120. package/dist/mcp/server-instructions.d.ts +20 -0
  121. package/dist/mcp/tools.d.ts +269 -0
  122. package/dist/mcp/transport.d.ts +117 -0
  123. package/dist/resolution/frameworks/cargo-workspace.d.ts +20 -0
  124. package/dist/resolution/frameworks/cargo-workspace.js +225 -0
  125. package/dist/resolution/frameworks/csharp.d.ts +8 -0
  126. package/dist/resolution/frameworks/csharp.js +213 -0
  127. package/dist/resolution/frameworks/drupal.d.ts +51 -0
  128. package/dist/resolution/frameworks/drupal.js +335 -0
  129. package/dist/resolution/frameworks/express.d.ts +8 -0
  130. package/dist/resolution/frameworks/express.js +225 -0
  131. package/dist/resolution/frameworks/go.d.ts +8 -0
  132. package/dist/resolution/frameworks/go.js +158 -0
  133. package/dist/resolution/frameworks/index.d.ts +52 -0
  134. package/dist/resolution/frameworks/index.js +137 -0
  135. package/dist/resolution/frameworks/java.d.ts +8 -0
  136. package/dist/resolution/frameworks/java.js +177 -0
  137. package/dist/resolution/frameworks/laravel.d.ts +13 -0
  138. package/dist/resolution/frameworks/laravel.js +248 -0
  139. package/dist/resolution/frameworks/nestjs.d.ts +26 -0
  140. package/dist/resolution/frameworks/nestjs.js +374 -0
  141. package/dist/resolution/frameworks/python.d.ts +10 -0
  142. package/dist/resolution/frameworks/python.js +278 -0
  143. package/dist/resolution/frameworks/react.d.ts +8 -0
  144. package/dist/resolution/frameworks/react.js +272 -0
  145. package/dist/resolution/frameworks/ruby.d.ts +8 -0
  146. package/dist/resolution/frameworks/ruby.js +198 -0
  147. package/dist/resolution/frameworks/rust.d.ts +8 -0
  148. package/dist/resolution/frameworks/rust.js +207 -0
  149. package/dist/resolution/frameworks/svelte.d.ts +9 -0
  150. package/dist/resolution/frameworks/svelte.js +249 -0
  151. package/dist/resolution/frameworks/swift.d.ts +10 -0
  152. package/dist/resolution/frameworks/swift.js +376 -0
  153. package/dist/resolution/frameworks/vue.d.ts +9 -0
  154. package/dist/resolution/frameworks/vue.js +306 -0
  155. package/dist/resolution/import-resolver.d.ts +61 -0
  156. package/dist/resolution/import-resolver.js +663 -0
  157. package/dist/resolution/index.d.ts +118 -0
  158. package/dist/resolution/index.js +744 -0
  159. package/dist/resolution/lru-cache.d.ts +24 -0
  160. package/dist/resolution/lru-cache.js +62 -0
  161. package/dist/resolution/name-matcher.d.ts +50 -0
  162. package/dist/resolution/name-matcher.js +384 -0
  163. package/dist/resolution/path-aliases.d.ts +72 -0
  164. package/dist/resolution/path-aliases.js +238 -0
  165. package/dist/resolution/strip-comments.d.ts +40 -0
  166. package/dist/resolution/strip-comments.js +441 -0
  167. package/dist/resolution/types.d.ts +181 -0
  168. package/dist/resolution/types.js +8 -0
  169. package/dist/search/query-parser.d.ts +61 -0
  170. package/dist/search/query-parser.js +177 -0
  171. package/dist/search/query-utils.d.ts +59 -0
  172. package/dist/search/query-utils.js +383 -0
  173. package/dist/sync/git-hooks.d.ts +54 -0
  174. package/dist/sync/git-hooks.js +223 -0
  175. package/dist/sync/index.d.ts +25 -0
  176. package/dist/sync/index.js +28 -0
  177. package/dist/sync/watch-policy.d.ts +51 -0
  178. package/dist/sync/watch-policy.js +124 -0
  179. package/dist/sync/watcher.d.ts +83 -0
  180. package/dist/sync/watcher.js +192 -0
  181. package/dist/types.d.ts +433 -0
  182. package/dist/types.js +75 -0
  183. package/dist/ui/glyphs.d.ts +42 -0
  184. package/dist/ui/shimmer-progress.d.ts +11 -0
  185. package/dist/ui/shimmer-worker.d.ts +2 -0
  186. package/dist/ui/types.d.ts +20 -0
  187. package/dist/utils.d.ts +231 -0
  188. package/dist/utils.js +549 -0
  189. package/package.json +24 -0
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Glyph selection for CLI output.
3
+ *
4
+ * On Windows, console output is interpreted via the active output
5
+ * codepage. PowerShell 5.1 and cmd.exe default to OEM codepages
6
+ * (CP437, CP936, ...), so UTF-8 bytes written to the console render
7
+ * as mojibake (see #168). The shimmer worker is hit hardest because
8
+ * it uses `fs.writeSync(1, ...)` (raw bytes, no TTY-aware encoding
9
+ * conversion) to keep animation smooth while the main thread is
10
+ * blocked in SQLite. To stay readable everywhere, we fall back to
11
+ * ASCII glyphs whenever the terminal is not known to handle UTF-8.
12
+ *
13
+ * Detection is intentionally simple:
14
+ * - `CODEGRAPH_ASCII=1` -> ASCII (escape hatch for any terminal)
15
+ * - `CODEGRAPH_UNICODE=1` -> Unicode (opt-in on Windows)
16
+ * - Windows -> ASCII by default
17
+ * - Linux kernel console (`TERM=linux`) -> ASCII
18
+ * - Everything else -> Unicode
19
+ */
20
+ export declare function supportsUnicode(): boolean
21
+ export interface Glyphs {
22
+ ok: string
23
+ err: string
24
+ info: string
25
+ warn: string
26
+ spinner: string[]
27
+ barFilled: string
28
+ barEmpty: string
29
+ rail: string
30
+ phaseDone: string
31
+ dash: string
32
+ hLine: string
33
+ treeBranch: string
34
+ treeLast: string
35
+ treePipe: string
36
+ }
37
+ export declare const UNICODE_GLYPHS: Glyphs
38
+ export declare const ASCII_GLYPHS: Glyphs
39
+ export declare function getGlyphs(): Glyphs
40
+ /** Reset the cached glyph set. Test-only; production code should call `getGlyphs()`. */
41
+ export declare function _resetGlyphsCache(): void
42
+ //# sourceMappingURL=glyphs.d.ts.map
@@ -0,0 +1,11 @@
1
+ export interface IndexProgress {
2
+ phase: string
3
+ current: number
4
+ total: number
5
+ }
6
+ export interface ShimmerProgress {
7
+ onProgress: (progress: IndexProgress) => void
8
+ stop: () => Promise<void>
9
+ }
10
+ export declare function createShimmerProgress(): ShimmerProgress
11
+ //# sourceMappingURL=shimmer-progress.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {}
2
+ //# sourceMappingURL=shimmer-worker.d.ts.map
@@ -0,0 +1,20 @@
1
+ /** Messages from main thread to worker */
2
+ export type ShimmerWorkerMessage =
3
+ | {
4
+ type: 'update'
5
+ phase: string
6
+ phaseName: string
7
+ percent: number
8
+ count: number
9
+ }
10
+ | {
11
+ type: 'finish-phase'
12
+ }
13
+ | {
14
+ type: 'stop'
15
+ }
16
+ /** Messages from worker to main thread */
17
+ export type ShimmerMainMessage = {
18
+ type: 'stopped'
19
+ }
20
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,231 @@
1
+ /**
2
+ * CodeGraph Utilities
3
+ *
4
+ * Common utility functions for memory management, concurrency, batching,
5
+ * and security validation.
6
+ *
7
+ * @module utils
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { Mutex, processInBatches, MemoryMonitor, validatePathWithinRoot } from 'codegraph';
12
+ *
13
+ * // Use mutex for concurrent safety
14
+ * const mutex = new Mutex();
15
+ * await mutex.withLock(async () => {
16
+ * await performCriticalOperation();
17
+ * });
18
+ *
19
+ * // Process items in batches to manage memory
20
+ * const results = await processInBatches(items, 100, async (item) => {
21
+ * return await processItem(item);
22
+ * });
23
+ *
24
+ * // Monitor memory usage
25
+ * const monitor = new MemoryMonitor(512, (usage) => {
26
+ * console.warn(`Memory usage exceeded 512MB: ${usage / 1024 / 1024}MB`);
27
+ * });
28
+ * monitor.start();
29
+ * ```
30
+ */
31
+ /**
32
+ * Validate that a resolved file path stays within the project root.
33
+ * Prevents path traversal attacks (e.g. node.filePath = "../../etc/passwd").
34
+ *
35
+ * @param projectRoot - The project root directory
36
+ * @param filePath - The relative file path to validate
37
+ * @returns The resolved absolute path, or null if it escapes the root
38
+ */
39
+ export declare function validatePathWithinRoot(
40
+ projectRoot: string,
41
+ filePath: string,
42
+ ): string | null
43
+ /**
44
+ * Validate that a path is a safe project root directory.
45
+ *
46
+ * Rejects sensitive system directories and ensures the path is
47
+ * a real, existing directory. Used at MCP and API entry points
48
+ * to prevent arbitrary directory access.
49
+ *
50
+ * @param dirPath - The path to validate
51
+ * @returns An error message if invalid, or null if valid
52
+ */
53
+ export declare function validateProjectPath(dirPath: string): string | null
54
+ /**
55
+ * Check if a file path resolves to a location within the given root directory.
56
+ *
57
+ * Prevents path traversal attacks by ensuring the resolved absolute path
58
+ * starts with the resolved root path. Handles '..' sequences, symlink-like
59
+ * relative paths, and platform-specific separators.
60
+ *
61
+ * @param filePath - The path to check (can be relative or absolute)
62
+ * @param rootDir - The root directory that filePath must stay within
63
+ * @returns true if filePath resolves to a location within rootDir
64
+ */
65
+ export declare function isPathWithinRoot(
66
+ filePath: string,
67
+ rootDir: string,
68
+ ): boolean
69
+ /**
70
+ * Like isPathWithinRoot but also resolves symlinks via fs.realpathSync.
71
+ *
72
+ * This catches symlink escapes where the logical path appears to be within
73
+ * root but the real path on disk points elsewhere. Falls back to logical
74
+ * path checking if realpath resolution fails (e.g. broken symlink).
75
+ */
76
+ export declare function isPathWithinRootReal(
77
+ filePath: string,
78
+ rootDir: string,
79
+ ): boolean
80
+ /**
81
+ * Safely parse JSON with a fallback value.
82
+ * Prevents crashes from corrupted database metadata.
83
+ */
84
+ export declare function safeJsonParse<T>(value: string, fallback: T): T
85
+ /**
86
+ * Clamp a numeric value to a range.
87
+ * Used to enforce sane limits on MCP tool inputs.
88
+ */
89
+ export declare function clamp(value: number, min: number, max: number): number
90
+ /**
91
+ * Normalize a file path to use forward slashes.
92
+ * Fixes Windows backslash paths so glob matching works consistently.
93
+ */
94
+ export declare function normalizePath(filePath: string): string
95
+ /**
96
+ * Cross-process file lock using a lock file with PID tracking.
97
+ *
98
+ * Prevents multiple processes (e.g., git hooks, CLI, MCP server) from
99
+ * writing to the same database simultaneously.
100
+ */
101
+ export declare class FileLock {
102
+ private lockPath
103
+ private held
104
+ /** Locks older than this are considered stale regardless of PID status */
105
+ private static readonly STALE_TIMEOUT_MS
106
+ constructor(lockPath: string)
107
+ /**
108
+ * Acquire the lock. Throws if the lock is held by another live process.
109
+ */
110
+ acquire(): void
111
+ /**
112
+ * Release the lock
113
+ */
114
+ release(): void
115
+ /**
116
+ * Execute a function while holding the lock
117
+ */
118
+ withLock<T>(fn: () => T): T
119
+ /**
120
+ * Execute an async function while holding the lock
121
+ */
122
+ withLockAsync<T>(fn: () => Promise<T>): Promise<T>
123
+ /**
124
+ * Check if a process is still running
125
+ */
126
+ private isProcessAlive
127
+ }
128
+ /**
129
+ * Process items in batches to manage memory
130
+ *
131
+ * @param items - Array of items to process
132
+ * @param batchSize - Number of items per batch
133
+ * @param processor - Function to process each item
134
+ * @param onBatchComplete - Optional callback after each batch
135
+ * @returns Array of results
136
+ */
137
+ export declare function processInBatches<T, R>(
138
+ items: T[],
139
+ batchSize: number,
140
+ processor: (item: T, index: number) => Promise<R>,
141
+ onBatchComplete?: (completed: number, total: number) => void,
142
+ ): Promise<R[]>
143
+ /**
144
+ * Simple mutex lock for preventing concurrent operations
145
+ */
146
+ export declare class Mutex {
147
+ private locked
148
+ private waitQueue
149
+ /**
150
+ * Acquire the lock
151
+ *
152
+ * @returns A release function to call when done
153
+ */
154
+ acquire(): Promise<() => void>
155
+ /**
156
+ * Execute a function while holding the lock
157
+ */
158
+ withLock<T>(fn: () => Promise<T> | T): Promise<T>
159
+ /**
160
+ * Check if the lock is currently held
161
+ */
162
+ isLocked(): boolean
163
+ }
164
+ /**
165
+ * Chunked file reader for large files
166
+ *
167
+ * Reads a file in chunks to avoid loading entire file into memory.
168
+ */
169
+ export declare function readFileInChunks(
170
+ filePath: string,
171
+ chunkSize?: number,
172
+ ): AsyncGenerator<string, void, undefined>
173
+ /**
174
+ * Debounce a function
175
+ *
176
+ * @param fn - Function to debounce
177
+ * @param delay - Delay in milliseconds
178
+ * @returns Debounced function
179
+ */
180
+ export declare function debounce<T extends (...args: unknown[]) => unknown>(
181
+ fn: T,
182
+ delay: number,
183
+ ): (...args: Parameters<T>) => void
184
+ /**
185
+ * Throttle a function
186
+ *
187
+ * @param fn - Function to throttle
188
+ * @param limit - Minimum time between calls in milliseconds
189
+ * @returns Throttled function
190
+ */
191
+ export declare function throttle<T extends (...args: unknown[]) => unknown>(
192
+ fn: T,
193
+ limit: number,
194
+ ): (...args: Parameters<T>) => void
195
+ /**
196
+ * Estimate memory usage of an object (rough approximation)
197
+ *
198
+ * @param obj - Object to measure
199
+ * @returns Approximate size in bytes
200
+ */
201
+ export declare function estimateSize(obj: unknown): number
202
+ /**
203
+ * Memory monitor for tracking usage during operations
204
+ */
205
+ export declare class MemoryMonitor {
206
+ private checkInterval
207
+ private peakUsage
208
+ private threshold
209
+ private onThresholdExceeded?
210
+ constructor(
211
+ thresholdMB?: number,
212
+ onThresholdExceeded?: (usage: number) => void,
213
+ )
214
+ /**
215
+ * Start monitoring memory usage
216
+ */
217
+ start(intervalMs?: number): void
218
+ /**
219
+ * Stop monitoring
220
+ */
221
+ stop(): void
222
+ /**
223
+ * Get peak memory usage in bytes
224
+ */
225
+ getPeakUsage(): number
226
+ /**
227
+ * Get current memory usage in bytes
228
+ */
229
+ getCurrentUsage(): number
230
+ }
231
+ //# sourceMappingURL=utils.d.ts.map