MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / secondHop

Function secondHop

graph-ui/src/compiler/fact-recipes.ts:449–488  ·  view source on GitHub ↗

* The second hop, when the reader asked for it. * * One index question per seed and no more: a hop-two walk over a whole * repository is the closure view's job and not a chat answer's. The seeds are * the hop-one neighbours in their own order, so two runs of one question expand * the same six.

(
    source: RecipeSource,
    root: string,
    first: readonly NeighbourFact[],
    opts: ProviderQueryOptions,
    notes: string[],
)

Source from the content-addressed store, hash-verified

447 * the same six.
448 */
449async function secondHop(
450 source: RecipeSource,
451 root: string,
452 first: readonly NeighbourFact[],
453 opts: ProviderQueryOptions,
454 notes: string[],
455): Promise<NeighbourFact[]> {
456 const seeds = first.slice(0, NEIGHBOUR_HOP2_SEEDS);
457 if (first.length > seeds.length) {
458 notes.push(
459 `depth 2: only the first ${seeds.length} of ${first.length} neighbours were expanded.`,
460 );
461 }
462 const found: NeighbourFact[] = [];
463 for (const seed of seeds) {
464 const resolved = seed.filePath === undefined || seed.line === undefined
465 ? undefined
466 : await source
467 .resolveSymbolAt(root, seed.filePath, seed.line, opts)
468 .then((result) => (result.kind === 'ok' ? result.symbol : undefined))
469 .catch(() => undefined);
470 if (resolved === undefined) {
471 continue;
472 }
473 const via = seed.qualifiedName ?? seed.name;
474 const facts = await source
475 .getFacts(root, resolved, seed.direction === 'caller' ? ['callers'] : ['callees'], opts)
476 .catch((): SymbolFacts => ({}));
477 if (seed.direction === 'caller') {
478 for (const caller of facts.callers?.value ?? []) {
479 found.push(callerNeighbour(caller, via, 2));
480 }
481 } else {
482 for (const call of facts.callees?.value ?? []) {
483 found.push(calleeNeighbour(call, via, 2));
484 }
485 }
486 }
487 return boundNeighbours(found, notes, 2);
488}
489
490/**
491 * What the direct callees can raise.

Callers 1

compileFactsFunction · 0.85

Calls 6

callerNeighbourFunction · 0.85
calleeNeighbourFunction · 0.85
boundNeighboursFunction · 0.85
resolveSymbolAtMethod · 0.65
getFactsMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected