(hop: TrailHop)
| 32 | * slow answer would otherwise put a 32-character hash in the trail bar. |
| 33 | */ |
| 34 | export 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 | |
| 46 | export function encodeTrail(hops: readonly TrailHop[]): string { |
| 47 | return hops.map((h) => DIR_TO_CHAR[h.dir] + encodeURIComponent(h.id)).join(','); |
no outgoing calls
no test coverage detected