MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / wireLayers

Method wireLayers

src/index.ts:183–233  ·  view source on GitHub ↗

* (Re)build the query/extraction/graph layers over the current `this.queries` * (which wraps `this.db`). Factored out of the constructor so `reopenIfReplaced` * can rebuild them against a fresh connection without duplicating the wiring. * The path-based `fileLock` is independent of the DB h

()

Source from the content-addressed store, hash-verified

181 * The path-based `fileLock` is independent of the DB handle, so it stays put.
182 */
183 private wireLayers(): void {
184 // Down-weight the project name as a query term in search ranking — it names
185 // the whole repo, not a symbol, so it has no discriminative value (#720).
186 try {
187 this.queries.setProjectNameTokens(deriveProjectNameTokens(this.projectRoot));
188 } catch {
189 // Best-effort: ranking still works without it.
190 }
191 // Down-weight the peripheral trees the project named in `codegraph.json`
192 // `deprioritize` — indexed and findable, but never outranking real code
193 // (#982). Ranking-only, so a bad pattern costs relevance, never recall.
194 //
195 // Read LAZILY, not once here: `wireLayers` runs from the constructor and
196 // from `reopenIfReplaced`, so a matcher built here would freeze at whatever
197 // the config said when the project opened. The MCP server caches one
198 // CodeGraph per root for its whole lifetime, so editing `codegraph.json`
199 // would appear to do nothing until the process restarted — `exclude` and
200 // `include` do not behave that way. `loadDeprioritizePatterns` is
201 // mtime-cached, so this costs one `stat`; the compiled matcher is memoized
202 // on the pattern array's identity, which the cache keeps stable.
203 let cachedPatterns: string[] | undefined;
204 let cachedMatcher: ReturnType<typeof ignore> | undefined;
205 this.queries.setDeprioritizedPathMatcher((filePath: string): boolean => {
206 try {
207 const patterns = loadDeprioritizePatterns(this.projectRoot);
208 if (patterns.length === 0) return false;
209 if (patterns !== cachedPatterns) {
210 cachedPatterns = patterns;
211 cachedMatcher = ignore().add(patterns);
212 }
213 const rel = path.isAbsolute(filePath)
214 ? path.relative(this.projectRoot, filePath)
215 : filePath;
216 if (!rel || rel.startsWith('..')) return false;
217 return cachedMatcher!.ignores(rel.split(path.sep).join('/'));
218 } catch {
219 // Ranking must never take the search down with it.
220 return false;
221 }
222 });
223
224 this.orchestrator = new ExtractionOrchestrator(this.projectRoot, this.queries);
225 this.resolver = createResolver(this.projectRoot, this.queries);
226 this.graphManager = new GraphQueryManager(this.queries);
227 this.traverser = new GraphTraverser(this.queries);
228 this.contextBuilder = createContextBuilder(
229 this.projectRoot,
230 this.queries,
231 this.traverser
232 );
233 }
234
235 /**
236 * Heal a stale database handle in place. If `.codegraph/` was removed and

Callers 2

constructorMethod · 0.95
reopenIfReplacedMethod · 0.95

Calls 8

deriveProjectNameTokensFunction · 0.90
loadDeprioritizePatternsFunction · 0.90
createResolverFunction · 0.90
createContextBuilderFunction · 0.90
setProjectNameTokensMethod · 0.80
ignoresMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected