Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit a22e13e9f105338db28a7cdfcf30048150fa17a4
parent 84aa044aaeb1a3a19ff8723287d03272b405125c
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 18 Nov 2026 01:50:45 -0500

editor: the pieces a streamed page is made of

A page that streams sends its heading and controls at once and each slow
section when its read is done. Shared by the pages that follow:

- StreamSkeleton: the box that holds a section's place until it arrives
  (a panel of a fixed height, or a table sized by a row count), and the
  wrapper of the section that replaces it, both named so e2e can compare
  the two boxes.
- streamDelay: a cookie a test server honours to hold every streamed
  section back, so a spec can see a skeleton at all. Inert without
  E2E_TEST_ROUTES=1; the cookie is not read.
- common: changelogPreview (the top of the newest entry, cut on a
  bullet), countAllJobs (how many jobs the list would show, from one
  readdir) and listChannelSlugs exported: what a skeleton is sized by
  before the slow read.

Co-Authored-By: Claude <noreply@anthropic.com>

Diffstat:
Mcommon/controller/channels.ts | 4+++-
Mcommon/jobs/listJobs.ts | 9+++++++++
Mcommon/lib/changelog.test.ts | 30++++++++++++++++++++++++++++++
Mcommon/lib/changelog.ts | 23+++++++++++++++++++++++
Aeditor/app/components/StreamSkeleton.tsx | 101+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aeditor/app/lib/streamDelay.ts | 23+++++++++++++++++++++++
6 files changed, 189 insertions(+), 1 deletion(-)

diff --git a/common/controller/channels.ts b/common/controller/channels.ts @@ -413,7 +413,9 @@ export type ChannelBrief = { snapshot: ChannelSnapshot | null; }; -async function listChannelSlugs(paths: Paths): Promise<string[]> { +// Exported for a page that sizes a skeleton by the channel count before it +// reads any channel (one readdir). +export async function listChannelSlugs(paths: Paths): Promise<string[]> { try { const entries = await readdir(paths.channelsDir, { withFileTypes: true }); return entries.filter((e) => e.isDirectory()).map((e) => e.name); diff --git a/common/jobs/listJobs.ts b/common/jobs/listJobs.ts @@ -216,6 +216,15 @@ export async function listAllJobs( return { entries, hasMore, total: candidates.size }; } +// HOW MANY JOBS listAllJobs WOULD LIST, without reading one of them: the size +// of the same candidate set (every log file ∪ every registry record) from one +// readdir. For a page that sizes a placeholder before it reads the rows. +export async function countAllJobs(paths: Paths): Promise<number> { + const ids = await readLogIds(paths); + for (const r of getRegistry().list()) ids.add(r.id); + return ids.size; +} + // Resolve a single job by id for the detail page — avoids listing every job. // Null when neither the registry nor an `<id>.log` file knows the id. export async function getJobEntry( diff --git a/common/lib/changelog.test.ts b/common/lib/changelog.test.ts @@ -5,6 +5,7 @@ import { bumpVersion, changelogAnchor, changelogAnchorPages, + changelogPreview, changelogPageOf, clampChangelogPage, compareVersions, @@ -352,3 +353,32 @@ test("withdrawing the latest release puts its bullets back under [Unreleased]", "# Changelog\n\n## [Unreleased]\n- a\n", ); }); + +test("changelogPreview is the top of the newest entry, cut on a bullet", () => { + const bullet = (n: number) => `- **Change ${n}.** ${"words ".repeat(60)}\n - a nested line of change ${n}\n`; + const newest = `## [Unreleased]\n${[1, 2, 3, 4, 5, 6].map(bullet).join("")}`; + const source = `# Changelog\n\n${newest}\n## [1.0.0] - 2026-01-01\n- older\n`; + + // An entry that fits is the whole entry, and never the older ones. + const whole = changelogPreview(source, 100_000); + assert.ok(whole.includes("Change 6.")); + assert.ok(!whole.includes("older")); + + // Cut: whole top-level bullets only, in order, within the budget. + const cut = changelogPreview(source, 1000); + assert.ok(cut.length <= 1000, String(cut.length)); + assert.ok(cut.startsWith("# Changelog\n\n## [Unreleased]\n- **Change 1.**")); + assert.ok(cut.includes("a nested line of change 2")); + assert.ok(!cut.includes("Change 3.")); + assert.ok(cut.endsWith("a nested line of change 2\n")); + + // A first bullet longer than the budget is still shown whole. + const tiny = changelogPreview(source, 50); + assert.ok(tiny.includes("a nested line of change 1")); + assert.ok(!tiny.includes("Change 2.")); + + // One bullet, however long, is the entry. + const one = `# Changelog\n\n## [Unreleased]\n- ${"x".repeat(9000)}\n`; + assert.equal(changelogPreview(one, 6000), one); + assert.equal(changelogPreview("", 6000), ""); +}); diff --git a/common/lib/changelog.ts b/common/lib/changelog.ts @@ -23,6 +23,29 @@ export function sliceTopEntries(source: string, limit: number): string { return source.slice(0, indexes[limit]).trimEnd() + "\n"; } +// THE TOP OF THE NEWEST ENTRY, for a box that shows only its first lines (the +// dashboard's "Recent changes" card is 12rem tall and clipped). The newest +// entry can run to a hundred kilobytes, and a caller that hands the whole of +// it to a client component pays for it three times: in the document, in the +// component payload and in a markdown parse on each side. This is the entry's +// heading and as many of its top-level bullets as fit in `maxChars`, cut ON a +// bullet boundary so no bullet is ever shown half-written — and always at +// least the first bullet, however long. An entry that fits is returned whole. +export function changelogPreview(source: string, maxChars = 6000): string { + const top = sliceTopEntries(source, 1); + if (top.length <= maxChars) return top; + // Top-level bullets only: a nested bullet is indented. + const starts: number[] = []; + for (const m of top.matchAll(/^[-*] /gm)) starts.push(m.index ?? 0); + if (starts.length < 2) return top; + let cut = starts[1]; + for (const at of starts.slice(1)) { + if (at > maxChars) break; + cut = at; + } + return top.slice(0, cut).trimEnd() + "\n"; +} + export function getLatestReleasedVersion(source: string): string | null { const match = source.match(RELEASED_HEADING); return match ? match[1] : null; diff --git a/editor/app/components/StreamSkeleton.tsx b/editor/app/components/StreamSkeleton.tsx @@ -0,0 +1,101 @@ +import type { CSSProperties, ReactNode } from "react"; + +// WHAT A STREAMED SECTION SHOWS UNTIL ITS READ IS DONE. +// +// A page that streams sends its heading and controls at once and each slow +// section when it is ready. Until then the section's place is held by one of +// these: a box the size of what is coming, so nothing below it moves when the +// content arrives. The size comes from what is known without the slow read — +// a fixed height for a panel, a row count for a table. +// +// Every skeleton carries `data-stream-skeleton="<name>"` and the section that +// replaces it `data-stream-filled="<name>"` (StreamFilled below), which is how +// e2e/streaming.spec.ts compares the two boxes. Hidden from assistive +// technology: `aria-busy` on a live region would announce on every refresh, +// and there is nothing here to read. +// +// No "use client": plain markup, usable from a server page and from a client +// component's Suspense fallback alike. + +const PULSE = "animate-pulse rounded bg-muted"; + +// One panel-shaped block of a fixed height (in px). +export function SkeletonPanel({ + name, + height, + className = "", +}: { + name: string; + height: number; + className?: string; +}) { + return ( + <div + data-stream-skeleton={name} + aria-hidden="true" + style={{ height }} + className={`rounded-md border border-border bg-card ${className}`} + > + <div className="flex h-full flex-col gap-3 px-4 py-4"> + <div className={`${PULSE} h-3 w-32`} /> + <div className={`${PULSE} min-h-0 flex-1`} /> + </div> + </div> + ); +} + +// A table-shaped block: a header band and `rows` rows of `rowHeight` px each. +// `head` is the header's height in px. +export function SkeletonRows({ + name, + rows, + rowHeight, + head = 0, + className = "", + style, +}: { + name: string; + rows: number; + rowHeight: number; + head?: number; + className?: string; + style?: CSSProperties; +}) { + return ( + <div + data-stream-skeleton={name} + aria-hidden="true" + style={{ height: head + rows * rowHeight, ...style }} + className={`overflow-hidden ${className}`} + > + {head > 0 && <div style={{ height: head }} className="bg-muted" />} + {Array.from({ length: Math.min(rows, 40) }, (_, n) => ( + <div + key={n} + style={{ height: rowHeight }} + className="flex items-center border-t border-border px-2" + > + <div className={`${PULSE} h-3 w-full`} /> + </div> + ))} + </div> + ); +} + +// The wrapper of a section that streamed in: the box a skeleton of the same +// name is compared against. +export function StreamFilled({ + name, + className, + children, +}: { + name: string; + className?: string; + children: ReactNode; +}) { + return ( + <div data-stream-filled={name} className={className}> + {children} + </div> + ); +} diff --git a/editor/app/lib/streamDelay.ts b/editor/app/lib/streamDelay.ts @@ -0,0 +1,23 @@ +import { cookies } from "next/headers"; + +// A TEST SERVER'S WAY TO HOLD A STREAMED SECTION BACK. +// +// The pages that stream (the dashboard, /jobs, /settings, /storage, /channels) +// send their shell first and each slow section when its read is done. Against +// the e2e fixture every read is over in milliseconds, so a spec could never +// see a skeleton, measure its box against the box of what replaces it, or +// prove that a refresh does not bring it back. A spec sets this cookie to a +// number of milliseconds and every streamed section waits that long before it +// reads. +// +// INERT OUTSIDE A TEST SERVER: without E2E_TEST_ROUTES=1 (the test server's +// identity, api/test/_guard.ts) the cookie is not even read. +export const STREAM_DELAY_COOKIE = "e2e-stream-delay"; +const MAX_DELAY_MS = 5_000; + +export async function e2eStreamDelay(): Promise<void> { + if (process.env.E2E_TEST_ROUTES !== "1") return; + const raw = (await cookies()).get(STREAM_DELAY_COOKIE)?.value; + const ms = Math.min(Number(raw) || 0, MAX_DELAY_MS); + if (ms > 0) await new Promise((resolve) => setTimeout(resolve, ms)); +}