import type { Child } from 'hono/jsx' import type { BranchInfo, RepoHeader, TagInfo, TraceBar, TraceModel } from './model.ts' import { PLY_SHA, PLY_WEB_SHA, plyBuildValue } from '../version.ts' import { atIndex } from '../absent.ts' /** Hex digits of each commit shown in the footer. */ const BUILD_SHA_CHARS = 12 import { viewerHref } from './url.ts' import { bannerClass, buttonClass, KUMO_BADGE_DANGER, KUMO_BADGE_INFO, KUMO_BADGE_NEUTRAL, KUMO_BADGE_OUTLINE, KUMO_BADGE_SUCCESS, KUMO_BADGE_WARNING, KUMO_BREADCRUMBS, KUMO_BREADCRUMB_CURRENT, KUMO_BREADCRUMB_LINK, KUMO_BREADCRUMB_SEPARATOR, KUMO_BUTTON_FOCUS, KUMO_BUTTON_SECONDARY, KUMO_BUTTON_SIZE_SM, KUMO_INPUT_SM, KUMO_LAYER_CARD, KUMO_LAYER_CARD_PRIMARY, KUMO_LAYER_CARD_SECONDARY, type BannerTone, type ButtonSize, type ButtonVariant, } from './kumo-classes.ts' import { exactTime, formatBytes, formatDuration, percentClass } from './format.ts' import { repoIdentity } from './identity.ts' import { LAYOUT } from './layout.ts' import { VIEWER_CSS_PATH } from './styles.ts' export function Button(props: { variant: ButtonVariant; size: ButtonSize; type: 'submit' | 'button' | null; children: Child }) { const tone = props.variant === 'primary' ? 'is-primary' : 'is-secondary' const type = props.type === null ? 'submit' : props.type return } export function Banner(props: { tone: BannerTone; children: Child }) { return

{props.children}

} export function Time(props: { iso: string; tz: string; now: number }) { const exact = exactTime(props.iso, props.tz, props.now) return } // ── icons ─────────────────────────────────────────────────────────────────────────────────────────────────────── // One inline sprite per page; every icon is a of it (img-src is 'none', so no data: URIs). 16×16 grid. const ICONS: Record = { dir: 'M1.5 3.25c0-.69.56-1.25 1.25-1.25h3.4c.33 0 .65.13.88.37L8.2 3.5h5.05c.69 0 1.25.56 1.25 1.25v7.5c0 .69-.56 1.25-1.25 1.25H2.75c-.69 0-1.25-.56-1.25-1.25z', file: 'M4 1.5h5.1L12.5 4.9v9.1a.5.5 0 0 1-.5.5H4a.5.5 0 0 1-.5-.5V2a.5.5 0 0 1 .5-.5zM9 1.75V5h3.25', link: 'M6.5 9.5l3-3M7.3 4.7l1.1-1.1a2.5 2.5 0 0 1 3.5 3.5l-1.1 1.1M8.7 11.3l-1.1 1.1a2.5 2.5 0 0 1-3.5-3.5l1.1-1.1', module: 'M2 4.5L8 1.75l6 2.75v7L8 14.25 2 11.5zM2 4.5l6 2.75 6-2.75M8 7.25v7', branch: 'M5 2.5v7.25M5 9.75a2 2 0 1 0 0 4 2 2 0 0 0 0-4zM5 2.5a1.5 1.5 0 1 0 0 .01M11 3.25a1.75 1.75 0 1 0 0 3.5 1.75 1.75 0 0 0 0-3.5zM11 6.75c0 2.5-6 1.5-6 3', book: 'M8 3.5C6.8 2.6 5 2.25 2.25 2.25v10c2.75 0 4.55.35 5.75 1.25 1.2-.9 3-1.25 5.75-1.25v-10C11 2.25 9.2 2.6 8 3.5zM8 3.5v10', history: 'M2.25 8A5.75 5.75 0 1 0 4 3.9M2.25 2v2.75H5M8 5v3.25l2.25 1.5', pulse: 'M1.5 8.5h2.75L6 4l3 8 1.75-3.5h3.75', chevron: 'M4.5 6.25L8 9.75l3.5-3.5', up: 'M8 13V3.5M4.25 7.25L8 3.5l3.75 3.75', raw: 'M5.5 4.5L2 8l3.5 3.5M10.5 4.5L14 8l-3.5 3.5', } export function Sprite() { return ( ) } export function Icon(props: { name: keyof typeof ICONS; class: string | null }) { return } export function IconFolder() { return } export function IconFile() { return } // ── page frame ────────────────────────────────────────────────────────────────────────────────────────────────── export function Document(props: { title: string; children: Child }) { return ( {props.title}
{props.children}
) } /** Kumo LayerCard: an elevated frame, an optional header strip (Secondary), and the raised panel (Primary). */ export function Card(props: { head: Child | null; id: string | null; class: string | null; children: Child }) { return (
{props.head ?
{props.head}
: null}
{props.children}
) } export function Badge(props: { tone: 'neutral' | 'outline' | 'success' | 'info' | 'warning' | 'danger'; title: string | null; children: Child }) { const cls = { neutral: KUMO_BADGE_NEUTRAL, outline: KUMO_BADGE_OUTLINE, success: KUMO_BADGE_SUCCESS, info: KUMO_BADGE_INFO, warning: KUMO_BADGE_WARNING, danger: KUMO_BADGE_DANGER }[props.tone] return {props.children} } export function Signed() { return Signed } // ── repository header ─────────────────────────────────────────────────────────────────────────────────────────── function shortRef(ref: string): string { return ref.replace(/^refs\/heads\//, '').replace(/^refs\/tags\//, '') } export function RepoIdentity(props: { host: string; repoPath: string; ref: string | null }) { const id = repoIdentity(props.host, props.repoPath) const root = viewerHref(props.host, props.repoPath, props.ref ? { ref: props.ref } : {}) return (

{id.hostLabel} {id.scope ? <>{id.scopeHref ? {id.scope} : {id.scope}} : null}

{id.name}

) } export function RepoTitle(props: { header: RepoHeader; path: string; branches: readonly BranchInfo[]; tags: readonly TagInfo[] }) { return (
) } /** Kumo Breadcrumbs (sm) for the path inside the repository. The repository name is the first crumb. */ export function PathCrumbs(props: { header: { host: string; repoPath: string; ref: string }; path: string }) { if (!props.path) return null const id = repoIdentity(props.header.host, props.header.repoPath) const parts = props.path.split('/') const crumbs: { label: string; href: string }[] = [{ label: id.name, href: viewerHref(props.header.host, props.header.repoPath, { ref: props.header.ref }) }] let acc = '' for (const part of parts) { acc = acc ? `${acc}/${part}` : part crumbs.push({ label: part, href: viewerHref(props.header.host, props.header.repoPath, { ref: props.header.ref, path: acc }) }) } const last = crumbs.length - 1 return ( ) } function refOption(name: string, current: string, label: string, note: string) { const selected = name === current || shortRef(name) === current return } export function RefSwitcher(props: { header: RepoHeader; path: string; branches: readonly BranchInfo[]; tags: readonly TagInfo[] }) { const action = viewerHref(props.header.host, props.header.repoPath, {}) const known = props.branches.some(branch => branch.name === props.header.ref || shortRef(branch.name) === props.header.ref) || props.tags.some(tag => tag.name === props.header.ref || shortRef(tag.name) === props.header.ref) const current = /^[0-9a-f]{40}$/.test(props.header.ref) ? props.header.ref.slice(0, LAYOUT.shortOid) : shortRef(props.header.ref) return (
{current}
{props.path ? : null}
{props.path ? : null}
) } // ── diagnostics ───────────────────────────────────────────────────────────────────────────────────────────────── const COMMIT_HEX = /^[0-9a-f]{40}$/ /** A GitHub link for a build commit when it is a full id; otherwise plain text. */ function BuildLink(props: { repo: 'ply' | 'ply-web'; sha: string }) { const short = props.sha.slice(0, BUILD_SHA_CHARS) return COMMIT_HEX.test(props.sha) ? {props.repo}={short} : {props.repo}={short} } /** * The page's git work, one line under the title: how many round trips ply made, how long, how many bytes, how many * came from Workers Cache, and every call as a bar on one shared timeline. Links to the full waterfall below. */ export function PlyStrip(props: { trace: TraceModel; header: RepoHeader }) { const bars = props.trace.bars if (!bars.length) return null const span = Math.max(props.trace.totalMs, 1) const bytes = bars.reduce((sum, bar) => sum + (bar.bytes === null ? 0 : bar.bytes), 0) const hits = bars.filter(bar => bar.cache === 'HIT').length const server = props.header.server return ( ply {bars.length} git {bars.length === 1 ? 'call' : 'calls'} {formatDuration(props.trace.totalMs)} {formatBytes(bytes)} {hits ? {hits} cached : null} protocol v{server.protocol} ) } export function Protocol(props: { header: RepoHeader }) { const server = props.header.server return (
Protocol
v{server.protocol} · {server.objectFormat}
Agent
{server.agent || 'unknown'}
Filter
{server.filterAdvertised ? 'advertised' : 'not advertised'}
Fetch
{server.fetchFeatures.join(' ') || 'none'}
Capabilities
{server.caps.join(' ') || 'none'}
) } /** * A 400 to a narrow filter that a later call on this page answered with the blob:none fallback: the server's known * refusal (Cloudflare Artifacts refuses tree:0), which ply handled. Drawn as the fallback, not as a failure. */ function handledRefusal(bar: TraceBar, bars: readonly TraceBar[]): boolean { if (bar.httpStatus !== 400) return false const filter = lineValue(bar.lines, 'git.fetch.filter=') if (filter === null || filter === 'blob:none') return false const at = bars.indexOf(bar) return bars.slice(at + 1).some(next => next.httpStatus === 200 && lineValue(next.lines, 'git.fetch.filter.fallback=') === 'blob:none') } function barTone(bar: TraceBar, bars: readonly TraceBar[]): string { if (handledRefusal(bar, bars)) return 'c-fallback' if (bar.status === 'error' || (bar.httpStatus !== null && bar.httpStatus >= 400)) return 'c-err' if (bar.cache === 'HIT') return 'c-hit' if (bar.lines.some(line => line.startsWith('git.fetch.filter.fallback='))) return 'c-fallback' if (bar.name.includes('discover') || bar.name.includes('ls-refs')) return 'c-discover' return 'c-fetch' } function lineValue(lines: readonly string[], prefix: string): string | null { for (const line of lines) { if (!line.startsWith(prefix)) continue const value = atIndex(line.split('='), 1) return value.tag === 'some' ? value.value : null } return null } function callLabel(bar: TraceBar): { name: string; tag: string } { const name = bar.name.replace(/^git\.(upload-pack|receive-pack)\s+/, '').replace(/^git\./, '') const fallback = lineValue(bar.lines, 'git.fetch.filter.fallback=') const filter = fallback === null ? lineValue(bar.lines, 'git.fetch.filter=') : fallback const deepen = lineValue(bar.lines, 'git.fetch.deepen=') const tag = [filter, deepen !== null && deepen !== '0' ? `deepen ${deepen}` : ''].filter(Boolean).join(' · ') return { name, tag } } /** What each git call is for, in plain words (the row's title and the legend under the waterfall). */ function callPurpose(name: string): string { if (name === 'discover') return 'Capability handshake: which protocol and features the server speaks (GET info/refs)' if (name === 'ls-refs') return 'Branch and tag tips: names to commit ids (protocol v2 ls-refs)' if (name === 'fetch') return 'A packfile: the objects asked for by id, with the filter shown (protocol v2 fetch)' return 'One HTTP round trip to the git server' } export function Waterfall(props: { trace: TraceModel; host: string; repoPath: string; ref: string | null }) { const trace = props.trace if (!trace.bars.length) return null const span = Math.max(trace.totalMs, 1) return (
Call Status Size Time 0{formatDuration(trace.totalMs)}
{trace.bars.map(bar => { const left = Math.max(0, Math.min(LAYOUT.percentSteps, Math.round((bar.startMs / span) * LAYOUT.percentSteps))) let width = Math.max(bar.durMs > 0 ? 1 : 0, Math.round((bar.durMs / span) * LAYOUT.percentSteps)) if (left + width > LAYOUT.percentSteps) width = Math.max(1, LAYOUT.percentSteps - left) const failed = !handledRefusal(bar, trace.bars) && (bar.status === 'error' || (bar.httpStatus !== null && bar.httpStatus >= 400)) const label = callLabel(bar) const packHref = bar.packWant && bar.packFilter ? viewerHref(props.host, props.repoPath, { ref: props.ref === null ? '' : props.ref, want: bar.packWant, filter: bar.packFilter }) : null return (
{label.name}{label.tag ? {label.tag} : null} {bar.httpStatus === null ? '—' : String(bar.httpStatus)} {bar.bytes === null ? '—' : formatBytes(bar.bytes)}{bar.cache === 'HIT' ? · hit : null} {formatDuration(bar.durMs)}
{`${bar.name}\n${bar.lines.join('\n')}`}
{packHref ? Open pack map : null}
) })}

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

) } function shownId(id: string): string { if (!id) return 'n/a' if (id.length <= LAYOUT.requestIdShown) return id return `${id.slice(0, LAYOUT.requestIdShown)}…` } /** * Everything about how the page was fetched, collapsed by default (open with ?trace=1): the remote, the git calls * as a waterfall on one shared timeline, the protocol the server spoke, pack-map links, and request ids. */ export function Diagnostics(props: { trace: TraceModel; header: RepoHeader | null; host: string | null; repoPath: string | null; ref: string | null; open: boolean }) { const trace = props.trace const host = props.header === null ? (props.host === null ? '' : props.host) : props.header.host const repoPath = props.header === null ? (props.repoPath === null ? '' : props.repoPath) : props.header.repoPath const ref = props.header === null ? props.ref : props.header.ref const wide = trace.bars.filter(bar => bar.lines.some(line => line.startsWith('git.fetch.filter.fallback='))) // learned=true: this page saw the 400 and retried. learned=false: the isolate already knew, so it asked for blob:none. // A refusal on this page (any call: the history window is often the first to ask for tree:0) counts as a retry here. const refusedHere = trace.bars.some(bar => bar.lines.includes('http.response.status_code=400') && bar.lines.some(line => line.startsWith('git.fetch.filter=') && line !== 'git.fetch.filter=blob:none')) const fallbacks = wide.filter(bar => bar.lines.includes('git.fetch.filter.learned=true')).length || (refusedHere ? wide.length : 0) const known = wide.length - fallbacks const retry = fallbacks === 0 ? '' : fallbacks === 1 ? ' · 1 retry' : ` · ${fallbacks} retries` const calls = trace.bars.length const pill = calls ? `${calls} git ${calls === 1 ? 'call' : 'calls'} · ${formatDuration(trace.totalMs)}${retry}` : 'no git calls' const id = host && repoPath ? repoIdentity(host, repoPath) : null return (
Diagnostics {pill}
{fallbacks > 0 ? filter tree:0 was rejected. ply retried with blob:none. The calls are serial, which is why the waterfall is a staircase. : null} {fallbacks === 0 && known > 0 ? This server refuses filter tree:0 (learned earlier in this isolate), so ply asked for blob:none directly. That brings every tree under the commit, not just one. : null} {host ? : null}
{id ?
Remote
{id.remote}
: null} {ref ?
Ref
{ref}
: null} {props.header ?
Commit
{props.header.commit}
: null}
cf-ray
{trace.cfRay || 'n/a'}
Request
{shownId(trace.requestId)}
{props.header ? : null} {props.header ? ( ) : null}
Rendered by ply, a zero-dependency git client · read-only {/* Abbreviated commits, one unbreakable token each, so a narrow footer wraps between them (never at "ply-web"). The full value is the title and the x-ply-build header. */} Limits
) } /** Old name kept for the pages that only need the footer. */ export function Footer(props: { trace: TraceModel; header: RepoHeader | null; host: string | null; repoPath: string | null; ref: string | null; open: boolean }) { return }