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

Function hopLabel

ui/src/lib/trail-codec.ts:34–44  ·  view source on GitHub ↗
(hop: TrailHop)

Source from the content-addressed store, hash-verified

32 * slow answer would otherwise put a 32-character hash in the trail bar.
33 */
34export function hopLabel(hop: TrailHop): string {
35 if (hop.name) return hop.name;
36 const body = hop.id.includes(':') ? hop.id.slice(hop.id.indexOf(':') + 1) : hop.id;
37 // Path-shaped ids (`file:src/mcp/tools.ts`) read best as their basename.
38 const basename = body.slice(body.lastIndexOf('/') + 1);
39 if (basename.length === 0 || basename.length > 40) return `${body.slice(0, 8)}…`;
40 // A content hash is not a name: shown whole it is a wall of hex wide enough
41 // to push the rest of the trail off screen.
42 if (/^[0-9a-f]{16,}$/.test(basename)) return `${basename.slice(0, 8)}…`;
43 return basename;
44}
45
46export function encodeTrail(hops: readonly TrailHop[]): string {
47 return hops.map((h) => DIR_TO_CHAR[h.dir] + encodeURIComponent(h.id)).join(',');

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected