main
1import { rawSafe } from './safehtml.ts'
2import { ALLOWED_HOSTS, viewerHref } from './url.ts'
3import { atIndex, captureGroup, recordGet, textAt } from '../absent.ts'
4import { unwrapOr } from '../option.ts'
5import { VIEWER_CAPS } from './limits.ts'
6import { classifyHref, renderMarkdown, type MarkdownOptions } from './markdown.ts'
7import type { CommitInfo, RepoHeader, TraceModel, TreeEntry } from './model.ts'
8import type { PackObjectView } from './packmap.ts'
9import type { FileLoaded, PackLoaded, TreeLoaded, ViewerDocument } from './document.ts'
10import { commitProse, formatBytes, percentClass, portions, shortOid } from './format.ts'
11import { LAYOUT } from './layout.ts'
12import { KUMO_BUTTON_FOCUS, KUMO_BUTTON_SECONDARY, KUMO_BUTTON_SIZE_SM, KUMO_INPUT, KUMO_SURFACE } from './kumo-classes.ts'
13import { repoIdentity } from './identity.ts'
14import { Badge, Banner, Button, Card, Diagnostics, Document, Footer, Icon, PathCrumbs, PlyStrip, RepoIdentity, RepoTitle, Signed, Time } from './ui.tsx'
15import { PUBLIC_NAMESPACE, type PublicRepoList } from '../public.ts'
16import type { ViewerHint } from './hint.ts'
18// One per forge: the same client speaks to each one's git server (checked 2026-11-06, all 200).
19const EXAMPLES = [
20 ['curl/curl', '/view/github.com/curl/curl'],
21 ['gitlab.com/gitlab-org/cli', '/view/gitlab.com/gitlab-org/cli'],
22 ['codeberg.org/dnkl/foot', '/view/codeberg.org/dnkl/foot'],
23 ['ply itself', '/r/ply'],
24] as const
26const PACK_SWATCH: Record<string, string> = {
27 header: 'bg-kumo-fill',
28 commit: 'bg-kumo-info',
29 tree: 'bg-kumo-success',
30 blob: 'bg-neutral-500',
31 tag: 'bg-kumo-badge-purple',
32 ofs_delta: 'bg-kumo-warning',
33 ref_delta: 'bg-kumo-danger',
34 trailer: 'bg-kumo-fill',
35}
37function PublicRepos(props: { list: PublicRepoList }) {
38 const names = props.list.names
39 return (
40 <Card id="public" class={null} head={<><Icon name="book" class={null} /><span class="card-title">Public repositories</span><span class="card-count">{PUBLIC_NAMESPACE}</span></>}>
41 {names.length
42 ? <ul class="repo-list">{names.map(name => <li><a href={`/r/${encodeURIComponent(name)}`}><Icon name="dir" class={null} />{name}<span class="go">/r/{name}</span></a></li>)}</ul>
43 : props.list.unavailable
44 ? <p class="empty">The repository list is unavailable right now.</p>
45 : <p class="empty">No repositories are published in this namespace yet.</p>}
46 <p class="empty">Served read-only from the <span class="mono">{PUBLIC_NAMESPACE}</span> Artifacts namespace. No token needed.</p>
47 </Card>
48 )
49}
51function Home(props: { error: string | null; publicRepos: PublicRepoList }) {
52 const caps = VIEWER_CAPS
53 return (
54 <>
55 <div class="hero">
56 <p class="kicker">ply · git over the wire, in a Worker</p>
57 <h1 class="display">Read a public git repository</h1>
58 <p class="lede">Every page here is rendered by <a href="https://github.com/ivarvong/ply">ply</a>, a zero-dependency TypeScript git client, speaking git's smart-HTTP protocol from a Cloudflare Worker: no clone, no git binary. Each page shows every round trip it made: the call, bytes, cache tier and time.</p>
59 <p class="lede">Paste a URL, <span class="mono">github.com/owner/repo</span>, or <span class="mono">owner/repo</span>.</p>
60 <form class="stack-form" action="/view" method="get">
61 <input class={`control ${KUMO_INPUT}`} type="text" name="remote" required placeholder="octocat/Hello-World" aria-label="Git URL" autocomplete="off" autocapitalize="off" spellcheck={false} />
62 <Button variant="primary" size="base" type={null}>Open</Button>
63 </form>
64 {props.error ? <div class="note"><Banner tone="error">{props.error}</Banner></div> : null}
65 <nav class="chips" aria-label="Example repositories">
66 {EXAMPLES.map(([label, href]) => <a class="chip" href={href}>{label}</a>)}
67 </nav>
68 </div>
69 <PublicRepos list={props.publicRepos} />
70 <div class="steps">
71 <div class="step"><strong>Paste</strong><span>A public https URL on an allowlisted host. A username or password in the URL is rejected and never forwarded.</span></div>
72 <div class="step"><strong>Browse</strong><span>Branches, trees, files and READMEs, rendered on the server.</span></div>
73 <div class="step"><strong>Inspect</strong><span>Every page shows its git round trips as a waterfall; the pack map shows how the server deltified objects.</span></div>
74 </div>
75 <div class="card-grid">
76 <Card id={null} class={null} head={<span class="card-title">Supported hosts</span>}>
77 <div class="pad">
78 <ul class="host-list">{ALLOWED_HOSTS.map(host => <li>{host}</li>)}</ul>
79 <p class="note">https, no username or password, port 443. A trailing dot or a lookalike host is rejected.</p>
80 </div>
81 </Card>
82 <Card id="limits" class={null} head={<span class="card-title">Limits</span>}>
83 <dl class="limits pad">
84 <div><dt>Upstream</dt><dd>{formatBytes(caps.maxUpstreamBytes)} / page</dd></div>
85 <div><dt>Pack</dt><dd>{formatBytes(caps.maxPackBytes)} · {caps.maxPackObjects} objects</dd></div>
86 <div><dt>File</dt><dd>{formatBytes(caps.maxFileDisplayBytes)}</dd></div>
87 <div><dt>Calls</dt><dd>{caps.maxSubrequests} · {caps.requestTimeoutMs / LAYOUT.msPerSecond}s each</dd></div>
88 <div><dt>Page</dt><dd>{caps.pageTimeoutMs / LAYOUT.msPerSecond}s</dd></div>
89 <div><dt>Rate</dt><dd>{caps.ratePerMinute}/min · packs {caps.packRatePerMinute}/min</dd></div>
90 </dl>
91 </Card>
92 </div>
93 </>
94 )
95}
97function initials(name: string): string {
98 const parts = name.trim().split(/\s+/).filter(part => part.length > 0)
99 const firstPart = atIndex(parts, 0)
100 const first = firstPart.tag === 'some' ? unwrapOr(textAt(firstPart.value, 0), '?') : '?'
101 const lastPart = atIndex(parts, parts.length - 1)
102 const last = parts.length > 1 && lastPart.tag === 'some' ? unwrapOr(textAt(lastPart.value, 0), '') : ''
103 return (first + last).toUpperCase()
104}
106function Avatar(props: { name: string }) {
107 return <span class="avatar" aria-hidden="true">{initials(props.name)}</span>
108}
110function TrailerValue(props: { value: string }) {
111 const email = captureGroup(/^(.*?)\s*<[^>]+>$/.exec(props.value), 1)
112 if (email.tag === 'some' && email.value) return <span title={props.value}>{email.value}</span>
113 const href = /^https:\/\/\S+$/.test(props.value) ? classifyHref(props.value) : null
114 return href ? <a href={href} rel="noopener noreferrer nofollow">{props.value}</a> : <span>{props.value}</span>
115}
117function CommitMessage(props: { message: string }) {
118 const prose = commitProse(props.message)
119 if (!prose.paragraphs.length && !prose.trailers.length) return null
120 return (
121 <div class="msg-body">
122 {prose.paragraphs.map(paragraph => <p class="msg-p">{paragraph}</p>)}
123 {prose.trailers.length ? (
124 <dl class="trailers">
125 {prose.trailers.map(trailer => <div><dt>{trailer.key}</dt><dd><TrailerValue value={trailer.value} /></dd></div>)}
126 </dl>
127 ) : null}
128 </div>
129 )
130}
132/** The card header: who, when, which commit; the subject, and the full message one tap away. */
133function CommitHead(props: { commit: CommitInfo; header: RepoHeader; now: number }) {
134 const prose = commitProse(props.commit.message)
135 const subject = prose.subject || '(no message)'
136 const hasBody = prose.paragraphs.length > 0 || prose.trailers.length > 0
137 return (
138 <div class="lc" data-commit={props.commit.oid}>
139 <div class="lc-by">
140 <Avatar name={props.commit.authorName} />
141 <span class="lc-author">{props.commit.authorName || 'unknown'}</span>
142 <Time iso={props.commit.authorTime} tz={props.commit.authorTz} now={props.now} />
143 <span class="lc-right">
144 {props.commit.signed ? <Signed /> : null}
145 <a class="sha" href={viewerHref(props.header.host, props.header.repoPath, { ref: props.commit.oid })} title={props.commit.oid}>{shortOid(props.commit.oid)}</a>
146 </span>
147 </div>
148 {hasBody ? (
149 <details class="lc-msg">
150 <summary><span class="lc-subject">{subject}</span><span class="more" aria-label="Show the full message">···</span></summary>
151 <CommitMessage message={props.commit.message} />
152 </details>
153 ) : <p class="lc-subject lc-only">{subject}</p>}
154 </div>
155 )
156}
158function EntryIcon(props: { entry: TreeEntry }) {
159 if (props.entry.type === 'tree') return <Icon name="dir" class={null} />
160 if (props.entry.mode === '160000') return <Icon name="module" class="i-module" />
161 if (props.entry.mode === '120000') return <Icon name="link" class={null} />
162 return <Icon name="file" class={null} />
163}
165function EntryNote(props: { entry: TreeEntry }) {
166 if (props.entry.mode === '160000') return <Badge tone="neutral" title={null}>submodule</Badge>
167 if (props.entry.mode === '120000') return <Badge tone="neutral" title={null}>symlink</Badge>
168 if (props.entry.mode === '100755') return <Badge tone="neutral" title={null}>exec</Badge>
169 return null
170}
172function parentPath(path: string): string {
173 const at = path.lastIndexOf('/')
174 return at === -1 ? '' : path.slice(0, at)
175}
177function TreePage(props: { loaded: TreeLoaded; trace: TraceModel; now: number }) {
178 const { header } = props.loaded
179 const id = repoIdentity(header.host, header.repoPath)
180 const path = props.loaded.path
181 const count = props.loaded.entries.length + props.loaded.entriesTruncated
182 return (
183 <Document title={path ? `${path} · ${id.name}` : `${id.scope ? `${id.scope}/` : ''}${id.name}`}>
184 <RepoTitle header={header} path={path} branches={props.loaded.branches} tags={props.loaded.tags} />
185 <PathCrumbs header={header} path={path} />
186 <PlyStrip trace={props.trace} header={header} />
187 <Card id={null} head={<CommitHead commit={props.loaded.commit} header={header} now={props.now} />} class="tree-card">
188 {props.loaded.entries.length === 0 && !path ? <p class="empty">This directory is empty.</p> : (
189 // Stable scraping contract (README "Machine-readable markup"): one li[data-oid] per entry shown.
190 <ul class="files" aria-label={`${count} ${count === 1 ? 'entry' : 'entries'}`} data-path={path} data-entries={String(count)} data-shown={String(props.loaded.entries.length)}>
191 {path ? (
192 <li><a class="row" href={viewerHref(header.host, header.repoPath, { ref: header.ref, path: parentPath(path) })} aria-label="Parent directory">
193 <Icon name="up" class={null} /><span class="name">..</span>
194 </a></li>
195 ) : null}
196 {props.loaded.entries.map(entry => {
197 const child = path ? `${path}/${entry.name}` : entry.name
198 return (
199 <li data-oid={entry.oid} data-mode={entry.mode} data-type={entry.type} data-name={entry.name}><a class="row" href={viewerHref(header.host, header.repoPath, { ref: header.ref, path: child })}>
200 <EntryIcon entry={entry} />
201 <span class="name">{entry.name}</span>
202 <EntryNote entry={entry} />
203 <span class="oid" title={entry.oid}>{shortOid(entry.oid)}</span>
204 </a></li>
205 )
206 })}
207 </ul>
208 )}
209 {props.loaded.entriesTruncated ? <p class="empty">Showing {props.loaded.entries.length} of {count} entries.</p> : null}
210 </Card>
211 <Readme loaded={props.loaded} />
212 <Log loaded={props.loaded} now={props.now} />
213 <Diagnostics trace={props.trace} header={header} host={null} repoPath={null} ref={null} open={true} />
214 </Document>
215 )
216}
218function markdownOptions(header: RepoHeader, docPath: string): MarkdownOptions {
219 return {
220 base: parentPath(docPath),
221 resolve: (path, kind) => viewerHref(header.host, header.repoPath, { ref: header.ref, path, raw: kind === 'image' ? '1' : '' }),
222 }
223}
225function Readme(props: { loaded: TreeLoaded }) {
226 const readme = props.loaded.readme
227 if (!readme) return null
228 const header = props.loaded.header
229 const docPath = props.loaded.path ? `${props.loaded.path}/${readme.name}` : readme.name
230 const head = (
231 <>
232 <Icon name="book" class={null} />
233 <a class="card-title" href={viewerHref(header.host, header.repoPath, { ref: header.ref, path: docPath })}>{readme.name}</a>
234 </>
235 )
236 if ('tooBig' in readme) {
237 return (
238 <Card id={null} class={null} head={head}>
239 <div class="pad"><Banner tone="alert">This README is binary or larger than {formatBytes(VIEWER_CAPS.maxFileDisplayBytes)}, so it is not rendered. Open the file to see the size.</Banner></div>
240 </Card>
241 )
242 }
243 return (
244 <Card id={null} class={null} head={head}>
245 <article class="md">{rawSafe(renderMarkdown(readme.text, markdownOptions(header, docPath)))}</article>
246 </Card>
247 )
248}
250function subjectOf(message: string): string {
251 return unwrapOr(atIndex(message.split('\n'), 0), '').slice(0, LAYOUT.logSubjectChars) || '(no message)'
252}
254function Log(props: { loaded: TreeLoaded; now: number }) {
255 const log = props.loaded.log
256 if (!log.length) return null
257 const header = props.loaded.header
258 return (
259 <Card id={null} class={null} head={<><Icon name="history" class={null} /><span class="card-title">Recent commits</span><span class="card-count">{log.length}</span></>}>
260 <ol class="log">
261 {log.map(commit => (
262 <li><a class="log-row" href={viewerHref(header.host, header.repoPath, { ref: commit.oid })}>
263 <span class="log-subject">{subjectOf(commit.message)}</span>
264 <span class="log-meta">
265 <span class="sha">{shortOid(commit.oid)}</span>
266 <span class="dot-sep" aria-hidden="true">·</span>
267 <span class="log-author">{commit.authorName}</span>
268 <span class="dot-sep" aria-hidden="true">·</span>
269 <Time iso={commit.authorTime} tz={commit.authorTz} now={props.now} />
270 </span>
271 </a></li>
272 ))}
273 </ol>
274 {props.loaded.logStopped ? <p class="empty">Older history is not loaded on this page. Open the oldest commit above to keep going.</p> : null}
275 </Card>
276 )
277}
279function isMarkdown(path: string): boolean {
280 return /\.(md|markdown|mdown|mkd)$/i.test(path)
281}
283function FilePage(props: { loaded: FileLoaded; trace: TraceModel; now: number }) {
284 const { header } = props.loaded
285 const id = repoIdentity(header.host, header.repoPath)
286 const rawHref = viewerHref(header.host, header.repoPath, { ref: header.ref, path: props.loaded.path, raw: '1' })
287 const pathParts = props.loaded.path.split('/')
288 const name = unwrapOr(atIndex(pathParts, pathParts.length - 1), props.loaded.path)
289 const text = props.loaded.note !== 'text' ? null : props.loaded.text === null ? '' : props.loaded.text
290 const lineCount = text === null ? 0 : text.split('\n').length - (text.endsWith('\n') ? 1 : 0)
291 const md = text !== null && isMarkdown(props.loaded.path)
292 const head = (
293 <>
294 <span class="file-meta">
295 {text !== null ? <span>{lineCount} {lineCount === 1 ? 'line' : 'lines'}</span> : null}
296 <span>{formatBytes(props.loaded.size)}</span>
297 {props.loaded.mode !== '100644' ? <Badge tone="neutral" title={null}>{props.loaded.mode === '100755' ? 'executable' : props.loaded.mode}</Badge> : null}
298 </span>
299 {md ? (
300 <nav class="seg-tabs" aria-label="View">
301 <a href="#preview" class="tab tab-preview">Preview</a>
302 <a href="#code" class="tab tab-code">Code</a>
303 </nav>
304 ) : null}
305 <a class={`raw-link ${KUMO_BUTTON_SIZE_SM} ${KUMO_BUTTON_SECONDARY} ${KUMO_BUTTON_FOCUS}`} href={rawHref}><Icon name="raw" class={null} />Raw</a>
306 </>
307 )
308 return (
309 <Document title={`${name} · ${id.name}`}>
310 <RepoTitle header={header} path={props.loaded.path} branches={props.loaded.branches} tags={props.loaded.tags} />
311 <PathCrumbs header={header} path={props.loaded.path} />
312 <PlyStrip trace={props.trace} header={header} />
313 <Card id={null} head={head} class={md ? 'file-card has-md' : 'file-card'}>
314 {md ? <span id="preview" class="anchor"></span> : null}
315 {md ? <article class="md md-view">{rawSafe(renderMarkdown(text === null ? '' : text, markdownOptions(header, props.loaded.path)))}</article> : null}
316 {md ? <span id="code" class="anchor"></span> : null}
317 <FileBody loaded={props.loaded} rawHref={rawHref} />
318 </Card>
319 <Diagnostics trace={props.trace} header={header} host={null} repoPath={null} ref={null} open={true} />
320 </Document>
321 )
322}
324function FileBody(props: { loaded: FileLoaded; rawHref: string }) {
325 const loaded = props.loaded
326 if (loaded.note === 'submodule') return <div class="pad"><Banner tone="info">This is a submodule (gitlink) {loaded.blob}. The blob is not in this repository.</Banner></div>
327 if (loaded.note === 'too-big') return <div class="pad"><Banner tone="alert">This file is {formatBytes(loaded.size)}, over the {formatBytes(VIEWER_CAPS.maxFileDisplayBytes)} display cap. It was not buffered. Open a smaller file, or fetch it with git.</Banner></div>
328 if (loaded.note === 'binary') return <div class="pad"><Banner tone="alert">Binary file, {formatBytes(loaded.size)}. Not shown as text. <a href={props.rawHref}>Download raw bytes</a> (not HTML).</Banner></div>
329 const text = loaded.text === null ? '' : loaded.text
330 const lines = text.split('\n')
331 if (text.endsWith('\n')) lines.pop()
332 const shown = lines.slice(0, VIEWER_CAPS.maxLineRows)
333 return (
334 <div class="code-wrap">
335 {lines.length > shown.length ? <p class="empty">Showing {shown.length} of {lines.length} lines.</p> : null}
336 <div class="code-bar">
337 <label class="wrap-toggle"><input type="checkbox" /> Wrap lines</label>
338 </div>
339 <div class="code" tabIndex={0} role="table" aria-label="File contents">
340 {shown.map((line, index) => {
341 const n = index + 1
342 return (
343 <div class="line" id={`L${n}`}>
344 <a class="ln" href={`#L${n}`} aria-label={`Line ${n}`}>{n}</a>
345 <span class="src">{line}</span>
346 </div>
347 )
348 })}
349 </div>
350 </div>
351 )
352}
354function PackPage(props: { loaded: PackLoaded; trace: TraceModel; now: number }) {
355 const map = props.loaded.map
356 const header = props.loaded.header
357 const selected = props.loaded.offset === null ? null : packObjectAt(map.objects, props.loaded.offset)
358 const lengths = [map.headerLength, ...map.objects.map(obj => obj.length), map.trailerLength]
359 const widths = portions(lengths)
360 const choice = map.ofsDelta === 0 && map.refDelta === 0
361 ? 'The server sent full objects only — no ofs-delta and no ref-delta.'
362 : `The server used ${map.ofsDelta} ofs-delta and ${map.refDelta} ref-delta object${map.refDelta === 1 ? '' : 's'}.`
363 const legend = ['header', 'commit', 'tree', 'blob', 'tag', 'ofs_delta', 'ref_delta', 'trailer'] as const
364 return (
365 <Document title={`pack ${shortOid(props.loaded.want)}`}>
366 <RepoTitle header={header} path="" branches={[]} tags={[]} />
367 <h2 class="section-title">Pack map</h2>
368 <div class="stats">
369 <span><strong>{map.count}</strong> {map.count === 1 ? 'object' : 'objects'}</span>
370 <span><strong>{formatBytes(map.bytes)}</strong></span>
371 <span>version {map.version}</span>
372 <span>max chain {map.maxChain}</span>
373 <span>{map.thin ? 'thin pack' : 'not thin'}</span>
374 </div>
375 <p class="note">want <span class="mono">{shortOid(props.loaded.want)}</span> · asked {props.loaded.filterRequested} · honoured {props.loaded.filterHonoured} · client asked for ofs-delta and did not ask for a thin pack</p>
376 <p class="note">{choice} Choose a segment to jump to its row.</p>
377 <div class="legend">
378 {legend.map(name => <span><i class={`sw ${swatch(name)}`}></i>{name.replace('_', ' ')}</span>)}
379 </div>
380 <div class="packbar" role="img" aria-label="Pack layout by object type">
381 <PackSegment cls={swatch('header')} width={widthAt(widths, 0)} offset={null} on={false} tip={`pack header · ${formatBytes(map.headerLength)}`} />
382 {map.objects.map((obj, index) => (
383 <PackSegment
384 cls={swatch(obj.wireType)}
385 width={widthAt(widths, index + 1)}
386 offset={obj.offset}
387 on={selected !== null && selected.offset === obj.offset}
388 tip={`${obj.wireType.replaceAll('_', ' ')} @${obj.offset} · ${formatBytes(obj.compressed)} compressed · ${formatBytes(obj.inflated)} inflated${obj.baseOffset !== null ? ` · base @${obj.baseOffset}` : ''}`}
389 />
390 ))}
391 <PackSegment cls={swatch('trailer')} width={widthAt(widths, widths.length - 1)} offset={null} on={false} tip={`checksum trailer · ${formatBytes(map.trailerLength)}`} />
392 </div>
393 {selected ? <ObjectDetail obj={selected} /> : <p class="note">Select a region to inspect that object.</p>}
394 <section class={KUMO_SURFACE}>
395 <div class="pack-list">
396 {map.objects.map(obj => {
397 const wire = obj.wireType.replaceAll('_', ' ')
398 const resolved = obj.resolvedType && obj.resolvedType !== obj.wireType ? obj.resolvedType : ''
399 const object = obj.oid ? shortOid(obj.oid) : obj.baseOid ? `base ${shortOid(obj.baseOid)}` : obj.baseOffset !== null ? `@${obj.baseOffset}` : ''
400 return (
401 <div id={`o${obj.offset}`} {...(obj.baseOffset !== null ? { 'data-base': String(obj.baseOffset) } : {})} class={selected !== null && selected.offset === obj.offset ? 'pack-row on' : 'pack-row'}>
402 <a class="pack-off" href={`#o${obj.offset}`}><span class="meta-k">offset</span>{obj.offset}</a>
403 <span>{wire}{resolved ? ` · ${resolved}` : ''}</span>
404 <span class="oid">{object}</span>
405 <span class="sub">{formatBytes(obj.compressed)} compressed · {formatBytes(obj.inflated)} inflated · chain {obj.chain}</span>
406 </div>
407 )
408 })}
409 </div>
410 </section>
411 <h2 class="section-label">Delta chains</h2>
412 <ul class="plain-list">
413 {map.links.length === 0 ? <li><span class="note">no deltas</span></li> : map.links.map(link => (
414 <li>
415 <a href={`#o${link.deltaOffset}`}>delta @{link.deltaOffset}</a>
416 <span class="msg">{link.baseOffset !== null ? <a href={`#o${link.baseOffset}`}>base @{link.baseOffset}</a> : <>base {shortOid(link.baseOid === null ? '' : link.baseOid)}</>} · depth {link.depth}</span>
417 </li>
418 ))}
419 </ul>
420 <Diagnostics trace={props.trace} header={header} host={null} repoPath={null} ref={null} open={true} />
421 </Document>
422 )
423}
425function swatch(name: string): string {
426 return unwrapOr(recordGet(PACK_SWATCH, name), '')
427}
429function widthAt(widths: readonly number[], index: number): number {
430 return unwrapOr(atIndex(widths, index), 0)
431}
433function packObjectAt(objects: readonly PackObjectView[], offset: number): PackObjectView | null {
434 for (const obj of objects) if (obj.offset === offset) return obj
435 return null
436}
438function PackSegment(props: { cls: string; width: number; offset: number | null; tip: string; on: boolean }) {
439 if (!props.width) return null
440 const klass = `${props.cls} ${percentClass('w', props.width)}${props.on ? ' on' : ''}`
441 if (props.offset === null) return <span class={klass} title={props.tip}></span>
442 return <a class={klass} href={`#o${props.offset}`} title={props.tip} aria-label={props.tip}></a>
443}
445function ObjectDetail(props: { obj: PackObjectView }) {
446 const obj = props.obj
447 const preview = obj.preview
448 return (
449 <section class={`${KUMO_SURFACE} surface-pad`} id={`detail-${obj.offset}`}>
450 <h2 class="subject">Object at {obj.offset}</h2>
451 <p>wire {obj.wireType.replace('_', ' ')} · resolved {obj.resolvedType === null ? 'unresolved' : obj.resolvedType} · oid <span class="mono">{obj.oid === null ? 'n/a' : obj.oid}</span></p>
452 <p class="note">header {formatBytes(obj.headerBytes)} · compressed {formatBytes(obj.compressed)} · inflated {formatBytes(obj.inflated)} · chain {obj.chain}{obj.baseOffset !== null ? ` · base @${obj.baseOffset}` : ''}{obj.baseOid ? ` · base ${shortOid(obj.baseOid)}` : ''}</p>
453 {preview !== null && preview.kind === 'commit' ? <p>{preview.summary}<span class="note"> tree {shortOid(preview.tree)} · parents {preview.parents.map(shortOid).join(' ') || 'none'}</span></p> : null}
454 {preview !== null && preview.kind === 'tree' ? <p class="note">{preview.names.join(', ') || '(empty tree)'}</p> : null}
455 {preview !== null && preview.kind === 'blob' ? (preview.text !== null ? <pre class="detail">{preview.text}</pre> : <p>Binary or large blob, {formatBytes(obj.inflated)} inflated.</p>) : null}
456 {preview !== null && preview.kind === 'tag' ? <pre class="detail">{preview.text}</pre> : null}
457 {preview !== null && preview.kind === 'unresolved' ? <p>The delta base is not in this pack.</p> : null}
458 </section>
459 )
460}
462function errorTitle(code: string, status: number): string {
463 if (code === 'rate_limited' || status === 429) return 'Too many requests'
464 if (code === 'not_found' || status === 404) return 'Not found'
465 if (code === 'auth' || status === 401 || status === 403) return 'Repository not found, or private'
466 if (code === 'limit_exceeded' || status === 413) return 'Too big for this viewer'
467 if (code === 'timeout' || status === 504) return 'The git host timed out'
468 if (code === 'unavailable' || status === 503) return 'Viewer unavailable'
469 if (code === 'bad_request' || status === 400) return 'That URL is not supported'
470 return 'Something went wrong'
471}
473function errorHint(code: string, status: number, message: string): string {
474 if (code === 'rate_limited' || status === 429) return 'Wait for the retry window, then open the repository again. The limit is per client.'
475 if (code === 'unavailable' || status === 503) return 'The rate limiter is not available, so the viewer stops rather than fetching without a limit.'
476 if (code === 'limit_exceeded' || status === 413) return 'Open a smaller path or a single file. Huge repositories and packs are refused on purpose.'
477 if (code === 'timeout' || status === 504) return 'The git host did not answer in time. Try the same URL again.'
478 if (/credentials/.test(message)) return 'Remove the username and password from the URL and paste it again. Credentials are never forwarded.'
479 if (/allowlisted|Supported hosts/.test(message)) return 'Use one of the supported hosts. owner/repo by itself means github.com.'
480 return 'Go back to the viewer and paste a public repository URL.'
481}
483const PRIVATE_HINT = 'Private repositories are not visible here. GitHub answers 401 for a missing repository and a private one.'
485function RefHint(props: { host: string; repoPath: string; hint: ViewerHint }) {
486 const links = props.hint.nearby
487 const intro = 'That name is not a branch or tag. Open the ref picker on the repository root'
488 if (!links.length) return <>{intro}.</>
489 return (
490 <>
491 {intro}, or try{' '}
492 {links.map((item, index) => (
493 <>
494 {index > 0 ? ', ' : null}
495 <a href={viewerHref(props.host, props.repoPath, { ref: item.ref })}>{item.label}</a>
496 </>
497 ))}
498 .
499 </>
500 )
501}
503function PathHint(props: { host: string; repoPath: string; ref: string | null; hint: ViewerHint }) {
504 const cue = props.hint.path
505 const missing = cue === null ? 'that entry' : cue.missing
506 const existing = cue === null ? '' : cue.existingPath
507 const where = existing.length > 0 ? existing : 'the repository root'
508 const href = viewerHref(props.host, props.repoPath, { ref: props.ref === null ? '' : props.ref, path: existing })
509 if (cue !== null && cue.notDirectory) return <>{missing} is a file, not a directory. Open <a href={href}>{where}</a>.</>
510 return <>No entry named {missing}. The deepest directory that exists is <a href={href}>{where}</a>.</>
511}
513function FailureBanner(props: Extract<ViewerDocument, { kind: 'error' }>) {
514 const tone = errorTone(props.code, props.status)
515 // The banner is a flex row (Kumo's icon + text). One span keeps the sentence and its links on the same line.
516 if (props.code === 'auth') return <Banner tone="info"><span>{PRIVATE_HINT}</span></Banner>
517 if (props.part === 'ref') return <Banner tone="info"><span><RefHint host={props.host} repoPath={props.repoPath} hint={props.hint} /></span></Banner>
518 if (props.part === 'path') return <Banner tone="info"><span><PathHint host={props.host} repoPath={props.repoPath} ref={props.ref} hint={props.hint} /></span></Banner>
519 if (notInNamespace(props)) return <Banner tone="info"><span>That name is not in this namespace. Open the <a href="/r">repository index</a>.</span></Banner>
520 if (props.part === 'repo') return <Banner tone="info"><span>This repository could not be opened.</span></Banner>
521 return <Banner tone={tone}><span>{errorHint(props.code, props.status, props.message)}</span></Banner>
522}
524/** A /r/<name> that the public namespace does not have. */
525function notInNamespace(props: { part: string; message: string }): boolean {
526 return props.part === 'repo' && /no repository |not a repository/.test(props.message)
527}
529/**
530 * The way back up from an error. A missing repository has no root to go back to: a public-namespace name links to the
531 * namespace index, any other missing repo gets only "Back to the viewer".
532 */
533function UpLink(props: Extract<ViewerDocument, { kind: 'error' }>) {
534 if (notInNamespace(props)) return <><a href="/r">Repository index</a> · </>
535 if (props.part === 'repo' || props.host.length === 0 || props.repoPath.length === 0) return null
536 return <><a href={viewerHref(props.host, props.repoPath, {})}>Repository root</a> · </>
537}
539function errorTone(code: string, status: number): 'alert' | 'info' {
540 if (code === 'not_found' || status === 404 || code === 'auth' || status === 401 || status === 403) return 'info'
541 return 'alert'
542}
544function supportedHosts(message: string): readonly string[] {
545 const marker = 'Supported hosts:'
546 const at = message.indexOf(marker)
547 if (at < 0) return []
548 return message.slice(at + marker.length).replace(/\.$/, '').split(',').map(host => host.trim()).filter(host => host.length > 0)
549}
551function ErrorPage(props: Extract<ViewerDocument, { kind: 'error' }>) {
552 const title = errorTitle(props.code, props.status)
553 const hosts = supportedHosts(props.message)
554 const specific = props.part === 'repo' || props.part === 'ref' || props.part === 'path'
555 const headline = specific ? props.summary : title
556 const knownRepo = props.host.length > 0 && props.repoPath.length > 0
557 return (
558 <Document title={headline}>
559 {knownRepo ? (
560 <header class="repo-head">
561 <RepoIdentity host={props.host} repoPath={props.repoPath} ref={null} />
562 </header>
563 ) : null}
564 {knownRepo && props.part !== 'ref' && props.ref ? <PathCrumbs header={{ host: props.host, repoPath: props.repoPath, ref: props.ref }} path={props.path} /> : null}
565 <article class={`${KUMO_SURFACE} error-card`}>
566 <p class="error-kicker">HTTP {props.status} · {props.part}</p>
567 <h1 class="display">{headline}</h1>
568 <FailureBanner {...props} />
569 {hosts.length ? <ul class="host-list" aria-label="Supported hosts">{hosts.map(host => <li>{host}</li>)}</ul> : null}
570 <p class="lede"><UpLink {...props} /><a href="/view">Back to the viewer</a></p>
571 <details class="reason">
572 <summary>Why this was refused</summary>
573 <p>{props.message}</p>
574 </details>
575 </article>
576 <Footer trace={props.trace} header={null} host={props.host} repoPath={props.repoPath} ref={props.ref} open={false} />
577 </Document>
578 )
579}
581export function ViewerPage(props: { doc: ViewerDocument }) {
582 const doc = props.doc
583 if (doc.kind === 'home') {
584 return (
585 <Document title="ply viewer">
586 <Home error={doc.error} publicRepos={doc.publicRepos} />
587 </Document>
588 )
589 }
590 if (doc.kind === 'tree') return <TreePage loaded={doc.loaded} trace={doc.trace} now={doc.now} />
591 if (doc.kind === 'file') return <FilePage loaded={doc.loaded} trace={doc.trace} now={doc.now} />
592 if (doc.kind === 'pack') return <PackPage loaded={doc.loaded} trace={doc.trace} now={doc.now} />
593 if (doc.kind === 'namespace') {
594 return (
595 <Document title={`${PUBLIC_NAMESPACE} repositories`}>
596 <div class="hero">
597 <p class="kicker">Public namespace</p>
598 <h1 class="display">{PUBLIC_NAMESPACE}</h1>
599 <p class="lede">Read-only repositories in this namespace. Open one below, or paste any public repository on <a href="/view">the viewer</a>.</p>
600 </div>
601 <PublicRepos list={doc.publicRepos} />
602 </Document>
603 )
604 }
605 return <ErrorPage {...doc} />
606}
Diagnostics4 git calls · 32 ms
CallStatusSizeTime032 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200145 B · hit4 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=4 git.response.bytes=145 git.response.cache=HIT git.response.duration_ms=4 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=145 git.pkt.payload.max=76 git.ls_refs.count=2 git.ls_refs.head=refs/heads/main
fetchblob:none · deepen 1020040 KiB · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=41349 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=526b305930b8ef382f2d7a1f9c0238730a585921 git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=6 git.pkt.data=4 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=41349 git.pkt.payload.max=41254 git.sideband.band1.bytes=41253 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=61 git.pack.bytes=41253 git.pack.ofs_delta=0 git.pack.ref_delta=0 git.pack.chain.max=0 git.pack.trailer=ab60efef4b7243678c75de64a4386986ee885c1c git.pack.full=61Open pack map
fetch2009.3 KiB · hit26 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=26 git.response.bytes=9561 git.response.cache=HIT git.response.duration_ms=26 git.fetch.wants=fe3575dd9474cc613ea1aebf853131fc5a197489 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=9561 git.pkt.payload.max=9540 git.sideband.band1.bytes=9539 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
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.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/ply-web.git
- Ref
- refs/heads/main
- Commit
- 526b305930b8ef382f2d7a1f9c0238730a585921
- cf-ray
- a5e36160af46b86e
- Request
- 2b42e4fb…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format