patlas/ docs

HTTP Debug artifacts (HAR)

Drop a .har into an issue body. It is optimized in the browser, stored content
addressed, referenced as a link and rendered as a label. Clicking the label opens
a popup left drawer with the HTTP debug view.

Locked decisions

Storage

flowchart LR
  drop["drop .har in editor"] --> optimize["lib/har.ts optimizeHar() in browser"]
  optimize --> size{"optimized <= 2 MB?"}
  size -- no --> reject["reject with a message"]
  size -- yes --> upload["POST /api/board/:slug/hars"]
  upload --> write[".project/hars/<sha1-base64url>.har"]
  write --> commit["mutate() commit"]
  commit --> link["insert [HTTP Debug - example.com #1](../hars/<hash>.har)"]

The label still carries the domain. Only the file and the query use the hash.
#n counts distinct HAR files already referenced in the document, so two
different dumps from example.com read #1 and #2.

The optimizer

New file lib/har.ts, pure and testable, and imported by the browser bundle the
same way lib/http.ts is. Input raw HAR text, output optimized text plus stats.

optimizeHar(raw: string): {
  text: string;          // compact JSON, one line
  stats: HarStats;       // { target, entries, bytes, duration }
};

Stats are returned for the label, they are never written to the file.

Spec-validity rule

HAR types request.url and response.redirectURL as absolute URLs, so those
stay absolute. Everything the spec treats as an opaque string is fair game, which
covers header values and body text. This gives most of the size win without
making the file invalid, and the file still opens in Chrome DevTools.

Target

target is the dominant host: the host with the most entries, ties broken by
first appearance. It is not written into the file. Export harTarget(har) from
lib/har.ts and call it in both places that need it, the optimizer and the
viewer, so display-time shortening uses the same definition.

Opaque values

Headers

Redact by name: authorization, proxy-authorization, cookie, set-cookie,
and anything matching /(^|[-_])(token|secret|api[-_]?key|auth)/i. Value becomes
[redacted], which is still a valid string.

Dropped fields

Derivable or junk, safe to remove:

Bodies

Order matters: collapse data URLs to [DataURL base64] and swap target prefixes
for [self] first, then cap. A body that is one large data URL shrinks to a
placeholder before the cap applies, so it survives intact.

Compact

JSON.stringify(optimized) with no indentation. One line.

Server

Client

Drop

Extend onDrop in issue-editor.tsx to accept .har files beside image/*.
Read as text, run optimizeHar, reject over 2 MB, upload, then insert the link at
the caret, built from the ref the server returns:

[HTTP Debug - example.com #1](../hars/<hash>.har)

The client does not hash. crypto.subtle is unavailable on insecure origins, and
the server has to recompute the digest anyway, so the hash arrives in the upload
response.

Markdown chip

case "link" in markdown.tsx: when href starts with ../hars/, render a
button.document-ref.har-ref chip instead of an <a>. Clicking calls
ctx.onOpenHar?.(id) which navigates to ?issue-id=...&issue-har=<hash>. With no
handler, fall through to a normal link to the served file.

Two props join imageBase: harBase (/p/:slug/files/hars) for the fallback
link, and onOpenHar(id). Both go on MarkdownProps and RenderContext. Note
that ChatTranscript builds its own RenderContext and currently drops the
interactive props, so harBase and onOpenHar must be threaded through there
too, or HAR links inside chat blocks lose their chip.

Sidebar of the issue popup

flowchart TB
  overlay[".modal-overlay (flex row)"] --> drawer[".har-drawer sidebar"]
  overlay --> modal[".modal issue popup"]
  drawer --> tabs["tab strip: HTTP Debug"]
  drawer --> body["single column of collapsible exchanges (wire format via lib/http.ts)"]

First paint note: reactive children nested inside a jsxIf result get stringified
by this renderer, so the detail pane is inflated imperatively into a stable host,
the same pattern the issue body uses.

Display-time shortening

Since storage keeps absolute URLs, the viewer does the earlier cosmetic work when
rendering: a URL whose host equals target shows as its path, other hosts show as
//host/path, and header values get target occurrences swapped for [self].
Readable output, valid file.

Router and state

Tests

Milestones

  1. lib/har.ts optimizer plus tests.
  2. storeIssueHar, the two routes, tests.
  3. Client drop, optimize, size gate, link insert.
  4. Markdown chip.
  5. Drawer shell, tab, router query.
  6. Viewer layout with display-time shortening, reuse lib/http.ts.
  7. Build, deploy, verify.