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

Function encodeResolvedRun

src/ui-server/api/trails.ts:224–257  ·  view source on GitHub ↗
(hops: readonly WireTrailHop[])

Source from the content-addressed store, hash-verified

222 * nothing the viewer can draw.
223 */
224export function encodeResolvedRun(hops: readonly WireTrailHop[]): {
225 encoded: string | null;
226 openFrom: number;
227 openCount: number;
228 openId: string | null;
229} {
230 let bestStart = -1;
231 let bestLength = 0;
232 let start = -1;
233 for (let i = 0; i <= hops.length; i += 1) {
234 const resolved = i < hops.length && (hops[i] as WireTrailHop).id !== null;
235 if (resolved) {
236 if (start < 0) start = i;
237 continue;
238 }
239 if (start >= 0 && i - start > bestLength) {
240 bestStart = start;
241 bestLength = i - start;
242 }
243 start = -1;
244 }
245 if (bestLength === 0) return { encoded: null, openFrom: 0, openCount: 0, openId: null };
246
247 const run = hops.slice(bestStart, bestStart + bestLength);
248 const encoded = run
249 .map((hop, index) => `${index === 0 ? 's' : DIR_CHAR[hop.dir]}${encodeURIComponent(hop.id as string)}`)
250 .join(',');
251 return {
252 encoded,
253 openFrom: bestStart + 1,
254 openCount: bestLength,
255 openId: (run[run.length - 1] as WireTrailHop).id,
256 };
257}
258
259export function resolveTrail(cg: CodeGraph, stored: StoredTrail): WireTrail {
260 const hops = stored.hops.map((hop) => resolveHop(cg, hop));

Callers 2

ui-trails.test.tsFile · 0.90
resolveTrailFunction · 0.85

Calls 2

mapMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected