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

Method boundaryCandidates

src/mcp/tools.ts:2301–2358  ·  view source on GitHub ↗

* Shortlist candidate runtime targets for a dispatch key surfaced by * buildDynamicBoundaries. Exact conventional names first (`save` → * `onSave`/`handleSave`; `CreateCmd` → `CreateCmdHandler`), then FTS, with a * normalized-containment post-filter (FTS camel-splitting is fuzzier t

(cg: CodeGraph, key: string, keyIsType: boolean, named: Map<string, Node>, selfId: string)

Source from the content-addressed store, hash-verified

2299 * are marked — that's the "you were right, here's the wiring" case.
2300 */
2301 private boundaryCandidates(cg: CodeGraph, key: string, keyIsType: boolean, named: Map<string, Node>, selfId: string): string {
2302 const CALLABLE = new Set(['method', 'function', 'component', 'constructor', 'class']);
2303 const norm = (s: string) => s.toLowerCase().replace(/[^a-z0-9]/g, '');
2304 const keyNorm = norm(key);
2305 if (keyNorm.length < 3) return '';
2306 const cands = new Map<string, Node>();
2307 const consider = (n: Node | undefined | null) => {
2308 if (!n || n.id === selfId || !CALLABLE.has(n.kind) || cands.has(n.id)) return;
2309 const nameNorm = norm(n.name || '');
2310 if (nameNorm.length < 3) return;
2311 if (!nameNorm.includes(keyNorm) && !keyNorm.includes(nameNorm)) return;
2312 cands.set(n.id, n);
2313 };
2314 const cap = key.charAt(0).toUpperCase() + key.slice(1);
2315 const probes = keyIsType
2316 ? [`${key}Handler`, key]
2317 : [key, `on${cap}`, `handle${cap}`, `${key}Handler`, `handle_${key}`];
2318 for (const p of probes) {
2319 try { for (const n of cg.getNodesByName(p)) consider(n); } catch { /* exact probe miss is fine */ }
2320 }
2321 let raw = 0;
2322 try {
2323 const results = cg.searchNodes(key, { limit: 12 });
2324 raw = results.length;
2325 for (const r of results) consider(r.node);
2326 } catch { /* FTS syntax edge — exact probes already ran */ }
2327 if (cands.size === 0) {
2328 return raw >= 12 && key.length < 5 ? `key \`${key}\` is too generic to shortlist (${raw}+ matches)` : '';
2329 }
2330 // A constructor candidate duplicates its class: extractors emit ctors as
2331 // METHOD nodes named like the class (C#/Java `Foo::Foo`) — keep the class.
2332 const all = [...cands.values()];
2333 const classKey = new Set(all.filter((n) => n.kind === 'class').map((n) => `${n.name}|${n.filePath}`));
2334 const namedNames = new Set([...named.values()].map((n) => n.name));
2335 const isNamed = (n: Node) => named.has(n.id) || namedNames.has(n.name); // the flow's named set holds callables only — transfer the mark to the class
2336 const list = all
2337 .filter((n) => !(n.kind !== 'class' && classKey.has(`${n.name}|${n.filePath}`)))
2338 .sort((a, b) => (isNamed(b) ? 1 : 0) - (isNamed(a) ? 1 : 0))
2339 .slice(0, 4)
2340 .map((n) => {
2341 // Typed-bus convention: the runtime target is the candidate class's
2342 // Handle/Execute/Consume method — name the exact node, not just the class.
2343 let display = n.qualifiedName || n.name;
2344 let at = `${n.filePath}:${n.startLine}`;
2345 if (keyIsType && n.kind === 'class') {
2346 try {
2347 const HANDLER_METHODS = /^(handle|handleAsync|execute|executeAsync|consume|consumeAsync|run|__invoke)$/i;
2348 const method = cg.getOutgoingEdges(n.id)
2349 .filter((e) => e.kind === 'contains')
2350 .map((e) => { try { return cg.getNode(e.target); } catch { return null; } })
2351 .find((c): c is Node => !!c && c.kind === 'method' && HANDLER_METHODS.test(c.name));
2352 if (method) { display = `${n.name}.${method.name}`; at = `${method.filePath}:${method.startLine}`; }
2353 } catch { /* class without resolvable members — show the class itself */ }
2354 }
2355 return `\`${display}\` (${at})${isNamed(n) ? ' ← you named this' : ''}`;
2356 });
2357 return `candidates for key \`${key}\`: ${list.join(', ')}`;
2358 }

Callers 1

Calls 8

considerFunction · 0.85
hasMethod · 0.80
getNodeMethod · 0.80
getNodesByNameMethod · 0.65
normFunction · 0.50
searchNodesMethod · 0.45
getOutgoingEdgesMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected