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

Function buildFlow

src/ui-server/api/flow.ts:669–819  ·  view source on GitHub ↗
(
  cg: CodeGraph,
  projectRoot: string,
  query: URLSearchParams
)

Source from the content-addressed store, hash-verified

667}
668
669export async function buildFlow(
670 cg: CodeGraph,
671 projectRoot: string,
672 query: URLSearchParams
673): Promise<WireFlowPayload> {
674 const started = Date.now();
675 const parsed = parseFlowQuery(query);
676 const maxFlows = intParam(query, 'limit', { min: 1, max: MAX_FLOWS, default: MAX_FLOWS });
677 const stats = cg.getStats();
678 const cache = new Map<string, FileCache>();
679
680 const base = {
681 flows: [] as WireFlow[],
682 ambiguous: [] as WireFlowAmbiguity[],
683 unresolved: [] as string[],
684 reason: null as string | null,
685 index: {
686 lastIndexedAt: cg.getLastIndexedAt() ?? null,
687 edges: stats.edgeCount,
688 files: stats.fileCount,
689 },
690 };
691
692 if (parsed.kind === 'trail') {
693 const byId = cg.getNodesByIds(parsed.hops.map((h) => h.id));
694 const raw: RawHop[] = [];
695 const missing: string[] = [];
696 for (const hop of parsed.hops) {
697 const node = byId.get(hop.id);
698 if (!node) {
699 missing.push(hop.id);
700 continue;
701 }
702 const previous = raw[raw.length - 1];
703 const link = previous ? edgeBetween(cg, previous.node, node) : null;
704 raw.push({ node, edge: link?.edge ?? null, upward: link?.upward ?? hop.dir === 'up' });
705 }
706 const flows = raw.length >= 2 ? [await toWireFlow(cg, projectRoot, cache, raw)] : [];
707 return {
708 ...base,
709 query: { kind: 'trail', from: null, to: null, symbols: [] },
710 flows,
711 unresolved: missing,
712 reason:
713 flows.length > 0
714 ? null
715 : 'None of the symbols on this trail are still in the index. Re-index, or start a new trail.',
716 timing: { elapsedMs: Date.now() - started },
717 };
718 }
719
720 const directed = parsed.kind === 'directed';
721 const text = directed ? `${parsed.from} ${parsed.to}` : parsed.text;
722 const flow = resolveNamedSymbolFlow(
723 cg,
724 text,
725 directed
726 ? { mode: 'directed', from: parsed.from, to: parsed.to, maxChains: maxFlows }

Callers 2

handlerFunction · 0.90

Calls 15

intParamFunction · 0.90
resolveNamedSymbolFlowFunction · 0.90
findDynamicBoundariesFunction · 0.90
edgeBetweenFunction · 0.85
toWireFlowFunction · 0.85
uncoveredNamedFunction · 0.85
buildBoundaryFunction · 0.85
boundarySeedsFunction · 0.85
ambiguitiesOfFunction · 0.85
noFlowReasonFunction · 0.85
mapMethod · 0.80
pushMethod · 0.80

Tested by

no test coverage detected