Archilyzer · Source

archilyzer

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

commit a9cf3f98597e1d2376911f9dde233bbde4c16705
parent 4d99f594c87706720310f7bfc314871bbb32f161
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 14 Oct 2026 00:41:21 -0400

umtool: lib/hrefs.ts — one builder per page address, ?note= always last; e2e/urls.ts; an empty redirects.mjs in next.config

Every URL shape the app links to gets one pure builder (project ids
encoded per segment, note last for the MCP's decision hrefs), with unit
tests. e2e/urls.ts re-exports them for specs. redirects.mjs is the one
redirect table (Next's shape plus the phase that added a row), empty until
P3, answered by next.config.ts's redirects().

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Aumtool/e2e/urls.ts | 11+++++++++++
Aumtool/lib/hrefs.test.mjs | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/lib/hrefs.ts | 220+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/next.config.ts | 6++++++
Aumtool/redirects.mjs | 48++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 351 insertions(+), 0 deletions(-)

diff --git a/umtool/e2e/urls.ts b/umtool/e2e/urls.ts @@ -0,0 +1,11 @@ +// The page addresses a spec opens, from the same table the app links with. +// +// A spec that writes `page.goto("/browse/" + id)` by hand pins today's URL; one +// that writes `page.goto(urls.projectHref(id))` follows the app when P3 moves +// /browse to /projects. Old addresses keep working through redirects.mjs either +// way -- this is so a spec states WHERE it means to be, not where that was. +// +// Assertions on hrefs (`toHaveAttribute("href", …)`) should build the expected +// value here too, so a URL change is one edit in lib/hrefs.ts. +export * from "../lib/hrefs"; +export { REDIRECTS } from "../redirects.mjs"; diff --git a/umtool/lib/hrefs.test.mjs b/umtool/lib/hrefs.test.mjs @@ -0,0 +1,66 @@ +// node --test umtool/lib/hrefs.test.mjs (Node strips hrefs.ts's types itself) +import { test } from "node:test"; +import assert from "node:assert/strict"; +import * as H from "./hrefs.ts"; + +test("note is always the last parameter", () => { + assert.equal(H.articleHref({ site: "articles", id: "x" }, { note: "n1", tab: "source" }), "/articles/x?tab=source&note=n1"); + assert.equal(H.projectHref("a/b", { note: "n2", all: true }), "/browse/a/b?all=1&note=n2"); + assert.equal(H.withQuery("/p", { note: "sneaky", z: "1", a: "2" }, "n3"), "/p?z=1&a=2&note=n3"); + // A note passed in the query map never lands anywhere but the end -- and only via `note`. + assert.equal(H.withQuery("/p", { note: "sneaky", z: "1" }), "/p?z=1"); + for (const href of [ + H.clipBenchHref("p", "c04", { note: "n" }), + H.claimBenchHref("p", "k1", { note: "n" }), + H.takesHref("p", { note: "n" }), + H.narrationHref("p", { note: "n" }), + H.reviewHref("p", { note: "n" }), + H.projectAtHref("tools/x", { note: "n" }), + H.articleHref({ site: "jeralyzer", id: "r" }, { status: "draft", tab: "source", ws: "w", rel: "a.md", note: "n" }), + ]) { + assert.match(href, /[?&]note=n$/, href); + } +}); + +test("withNote re-points an href and keeps note last, and the fragment after it", () => { + assert.equal(H.withNote("/articles/x?note=old&tab=source", "new"), "/articles/x?tab=source&note=new"); + assert.equal(H.withNote("/browse/p", "n"), "/browse/p?note=n"); + assert.equal(H.withNote("/sites/s?ws=a#files", "n"), "/sites/s?ws=a&note=n#files"); +}); + +test("project ids are encoded per segment, slashes kept", () => { + assert.equal(H.projectHref("quartering-uh-song/videos/mortal-kombat"), "/browse/quartering-uh-song/videos/mortal-kombat"); + assert.equal(H.projectHref("a b/c?d"), "/browse/a%20b/c%3Fd"); + assert.equal(H.clipBenchHref("articles/x/i1", "c 04"), "/browse/articles/x/i1/clip/c%2004"); + assert.equal(H.encodePath("/lead//trail/"), "lead/trail"); +}); + +test("empty, null and false values are left out; true is 1", () => { + assert.equal(H.browseHref({}), "/browse"); + assert.equal(H.browseHref({ kind: "", state: undefined, q: "x y" }), "/browse?q=x+y"); + assert.equal(H.projectHref("p", { all: false }), "/browse/p"); + assert.equal(H.decisionsHref({ severity: "blocking", project: "a/b" }), "/browse/decisions?severity=blocking&project=a%2Fb"); +}); + +test("articles open in the store or on their site", () => { + assert.equal(H.articleHref({ site: "articles", id: "poker" }), "/articles/poker"); + assert.equal(H.articleHref({ site: "jeralyzer", id: "poker" }), "/sites/jeralyzer/poker"); + assert.equal(H.articleEvidenceHref({ site: "jeralyzer", id: "poker" }, { c: "3" }), "/sites/jeralyzer/poker/evidence?c=3"); + assert.equal(H.articleCompareHref("poker", { a: "1", b: "2" }), "/articles/poker/compare?a=1&b=2"); + assert.equal(H.newArticleHref(), "/articles/new"); +}); + +test("site pages, tools and piles", () => { + assert.equal(H.siteHref("jeralyzer"), "/sites/jeralyzer"); + assert.equal(H.siteHref("jeralyzer", { ws: "w", rel: "a/b.md" }), "/sites/jeralyzer?ws=w&rel=a%2Fb.md#files"); + assert.equal(H.sitesHref({ status: "draft" }), "/sites?status=draft"); + assert.equal(H.findHref({ q: "um" }), "/browse/find?q=um"); + assert.equal(H.facesHref({ cover: "c 1" }), "/browse/faces?cover=c+1"); + assert.equal(H.sourcesHref(), "/browse/sources"); + assert.equal(H.trimHref("hooks"), "/browse/trim/hooks"); + assert.equal(H.mixHref({ body: "/a/b.wav", from: "p", start: 1.5 }), "/mix?body=%2Fa%2Fb.wav&from=p&start=1.5"); + assert.equal(H.pileHref("sort", { limit: 5 }), "/sort?limit=5"); + assert.equal(H.cutHref("yoshi", "wide", { plan: "p1" }), "/browse/yoshi/wide?plan=p1"); + assert.equal(H.homeHref({ from: "ch/vid" }), "/?from=ch%2Fvid"); + assert.equal(H.homeHref(), "/"); +}); diff --git a/umtool/lib/hrefs.ts b/umtool/lib/hrefs.ts @@ -0,0 +1,220 @@ +// --------------------------------------------------------------------------- +// Every page address umtool links to, one builder per URL shape. +// +// The URLs are about to move (plans/umtool-redesign.md, P3: /browse becomes +// /work and /projects, the song tools go under /tools). When they do, the +// change is a body here and a row in redirects.mjs, not a grep across ~70 call +// sites with template literals in them. A link written as a literal from now on +// is a link P3 has to find by hand. +// +// Two contracts: +// - `?note=<id>` is ALWAYS the last parameter. The MCP's notes tool reads a +// decision's href and expects it to END in `note=<id>` +// (mcp/src/archivalTools.ts), so the builder puts it last whatever else the +// query carries. +// - Project ids are paths (`quartering-uh-song/videos/mortal-kombat`): each +// SEGMENT is encoded, the slashes are not. +// +// Pure and dependency-free (one .mjs constant), so a client component, a server +// page and an e2e spec (e2e/urls.ts) all import the same table, and +// `node --test lib/hrefs.test.mjs` runs it without a bundler. +// --------------------------------------------------------------------------- + +import { ARTICLES_KEY } from "./articles/key.mjs"; + +/** A query value; `undefined`, `null`, `false` and "" are left out. */ +export type QueryValue = string | number | boolean | null | undefined; +export type Query = Record<string, QueryValue>; + +/** Encode a path id segment by segment, keeping its slashes. */ +export function encodePath(id: string): string { + return id + .split("/") + .filter((s) => s.length > 0) + .map(encodeURIComponent) + .join("/"); +} + +/** + * `path` + its query, with `note` last. `true` is written as `1`, the form every + * flag here already takes (`?all=1`). + */ +export function withQuery(path: string, query: Query = {}, note?: string | null): string { + const sp = new URLSearchParams(); + for (const [k, v] of Object.entries(query)) { + if (k === "note") continue; // only ever through `note`, so it stays last + if (v === undefined || v === null || v === false || v === "") continue; + sp.set(k, v === true ? "1" : String(v)); + } + if (note) sp.set("note", note); + const q = sp.toString(); + return q ? `${path}?${q}` : path; +} + +/** Re-point an existing href at a note, keeping `note` last. */ +export function withNote(href: string, note: string): string { + const hash = href.indexOf("#"); + const frag = hash >= 0 ? href.slice(hash) : ""; + const bare = hash >= 0 ? href.slice(0, hash) : href; + const q = bare.indexOf("?"); + const path = q >= 0 ? bare.slice(0, q) : bare; + const sp = new URLSearchParams(q >= 0 ? bare.slice(q + 1) : ""); + sp.delete("note"); + sp.set("note", note); + return `${path}?${sp.toString()}${frag}`; +} + +type NoteOpt = { note?: string | null }; + +// ── home and the lists ────────────────────────────────────────────────────── + +/** The dashboard. `from` is the editor's "make a video" handoff (`/?from=<slug>/<id>`). */ +export function homeHref(q: { from?: string } = {}): string { + return withQuery("/", q); +} + +export type BrowseQuery = { + kind?: string; + template?: string; + state?: string; + open?: string; + q?: string; + sort?: string; + deleted?: string; +}; +/** Every project, filtered. */ +export function browseHref(q: BrowseQuery = {}): string { + return withQuery("/browse", q); +} + +export type DecisionsQuery = { severity?: string; kind?: string; project?: string }; +/** The decision list across every project. */ +export function decisionsHref(q: DecisionsQuery = {}): string { + return withQuery("/browse/decisions", q); +} + +export type ArticlesQuery = { status?: string; notes?: string; audience?: string; deleted?: string; freed?: string }; +/** The article store's list (release 26). */ +export function articlesHref(q: ArticlesQuery = {}): string { + return withQuery("/articles", q); +} + +/** A new article (release 27). */ +export function newArticleHref(): string { + return "/articles/new"; +} + +export type SitesQuery = { site?: string; status?: string; notes?: string }; +/** Every site's articles. */ +export function sitesHref(q: SitesQuery = {}): string { + return withQuery("/sites", q); +} + +/** One site's page; `ws`+`rel` open a workspace file, `#files` scrolls to it. */ +export function siteHref(site: string, q: { ws?: string; rel?: string } = {}): string { + const base = withQuery(`/sites/${encodeURIComponent(site)}`, q); + return q.ws || q.rel ? `${base}#files` : base; +} + +// ── articles ──────────────────────────────────────────────────────────────── + +export type ArticleRef = { site: string; id: string }; +export type ArticleQuery = { tab?: string; status?: string; ws?: string; rel?: string } & NoteOpt; + +function articleBase(a: ArticleRef): string { + return a.site === ARTICLES_KEY + ? `/articles/${encodeURIComponent(a.id)}` + : `/sites/${encodeURIComponent(a.site)}/${encodeURIComponent(a.id)}`; +} + +/** An article's page: `/articles/<id>` in the store, `/sites/<site>/<id>` on a site. */ +export function articleHref(a: ArticleRef, q: ArticleQuery = {}): string { + const { note, ...rest } = q; + return withQuery(articleBase(a), rest, note); +} + +/** The evidence walk of one article. */ +export function articleEvidenceHref(a: ArticleRef, q: { c?: string } = {}): string { + return withQuery(`${articleBase(a)}/evidence`, q); +} + +/** Two revisions of a store article side by side. */ +export function articleCompareHref(id: string, q: { a?: string; b?: string } = {}): string { + return withQuery(`/articles/${encodeURIComponent(id)}/compare`, q); +} + +// ── projects ──────────────────────────────────────────────────────────────── + +/** A project's page. `all` shows every row of a long list. */ +export function projectHref(id: string, q: { all?: boolean } & NoteOpt = {}): string { + const { note, ...rest } = q; + return withQuery(`/browse/${encodePath(id)}`, rest, note); +} + +/** A project by its path, for an id that a tool page shadows at its own URL. */ +export function projectAtHref(id: string, q: NoteOpt = {}): string { + return withQuery("/browse/at", { path: id }, q.note); +} + +/** The clip bench, one timeline entry. */ +export function clipBenchHref(project: string, clip: string, q: NoteOpt = {}): string { + return withQuery(`/browse/${encodePath(project)}/clip/${encodeURIComponent(clip)}`, {}, q.note); +} + +/** The claim bench, one ledger entry. */ +export function claimBenchHref(project: string, claim: string, q: NoteOpt = {}): string { + return withQuery(`/browse/${encodePath(project)}/claim/${encodeURIComponent(claim)}`, {}, q.note); +} + +/** Alternative renders of one part of a cut. */ +export function takesHref(project: string, q: NoteOpt = {}): string { + return withQuery(`/browse/${encodePath(project)}/takes`, {}, q.note); +} + +/** The narration script, card by card. */ +export function narrationHref(project: string, q: NoteOpt = {}): string { + return withQuery(`/browse/${encodePath(project)}/narration`, {}, q.note); +} + +/** The drafts review (release 28). */ +export function reviewHref(project: string, q: NoteOpt = {}): string { + return withQuery(`/browse/${encodePath(project)}/review`, {}, q.note); +} + +/** One cut of a song; `plan` opens a plan of it, `v` a variant row. */ +export function cutHref(song: string, cut: string, q: { plan?: string; v?: string } = {}): string { + return withQuery(`/browse/${encodePath(song)}/${encodeURIComponent(cut)}`, q); +} + +// ── tools ─────────────────────────────────────────────────────────────────── + +/** Every occurrence of a word across the corpus. */ +export function findHref(q: Query = {}): string { + return withQuery("/browse/find", q); +} + +/** The face judger; `cover` opens on one cover's corners. */ +export function facesHref(q: { cover?: string } = {}): string { + return withQuery("/browse/faces", q); +} + +/** Where the palette comes from, across every song. */ +export function sourcesHref(): string { + return "/browse/sources"; +} + +/** A trim set's bench. */ +export function trimHref(set: string): string { + return `/browse/trim/${encodeURIComponent(set)}`; +} + +export type MixQuery = { body?: string; start?: string | number; end?: string | number; from?: string; clip?: string }; +/** The mix bench; the deep link is resolved server-side (lib/mix-preset.ts). */ +export function mixHref(q: MixQuery = {}): string { + return withQuery("/mix", q); +} + +/** A song judging pile (`/sort`, `/salvage`, `/verify`, `/keeps`). */ +export function pileHref(mode: string, q: { limit?: number; only?: string } = {}): string { + return withQuery(`/${encodeURIComponent(mode)}`, q); +} diff --git a/umtool/next.config.ts b/umtool/next.config.ts @@ -1,5 +1,6 @@ import path from "node:path"; import type { NextConfig } from "next"; +import { nextRedirects } from "./redirects.mjs"; const nextConfig: NextConfig = { // A SECOND dev server for the e2e suite, alongside the one being used. @@ -18,6 +19,11 @@ const nextConfig: NextConfig = { // fail the whole module graph. Every page importing lib/projects then 500s // with "Can't resolve 'cbor-x'", which names a package nothing here uses. serverExternalPackages: ["lmdb"], + // Every old page address and where it lives now: ONE table, redirects.mjs, + // which e2e/redirects.spec.ts (P3) reads too. Empty until P3 moves a page. + async redirects() { + return nextRedirects(); + }, // No route's trace may list the e2e fixture (.e2e-song, where // e2e/fixtures/make-fixture.mjs links the song data; .e2e-song-media, the // storage spec's media root), the e2e server's own diff --git a/umtool/redirects.mjs b/umtool/redirects.mjs @@ -0,0 +1,48 @@ +// --------------------------------------------------------------------------- +// Every old umtool page address, and where it lives now. EMPTY until P3. +// +// ONE table, read by two things (plans/umtool-redesign.md, "Redirects"): +// - next.config.ts's `redirects()`, which answers them. Next checks redirects +// BEFORE the filesystem, so a row here beats a page still at the old path, +// and the query string is passed through to the destination unchanged. +// - e2e/redirects.spec.ts (P3), which requests every `source` with +// `maxRedirects: 0` and checks the status and the Location. +// +// A row is Next's own redirect shape +// (node_modules/next/dist/docs/01-app/03-api-reference/05-config/01-next-config-js/redirects.md): +// +// { +// source: "/browse/:path*", // path-to-regexp; `:x*` zero or more segments +// destination: "/projects/:path*", // matched parameters carry over +// permanent: false, // 307 until P6, then 308 -- a browser +// // caches a 308 forever, so a wrong one +// // cannot be taken back +// has: [{ type: "query", key: "from" }], // optional: only when the query has `from` +// phase: "P3", // ours, not Next's: which phase added it. +// // next.config.ts strips it. +// } +// +// ORDER MATTERS: Next takes the first match, so a reserved `/browse/<tool>` row +// goes BEFORE the `/browse/:path*` catch-all. Every page address lib/hrefs.ts +// builds is either still served or has a row here. +// --------------------------------------------------------------------------- + +/** @typedef {{ type: "query" | "header" | "cookie", key: string, value?: string }} RedirectMatch */ +/** + * @typedef {{ + * source: string, + * destination: string, + * permanent: boolean, + * has?: RedirectMatch[], + * missing?: RedirectMatch[], + * phase: string, + * }} RedirectRow + */ + +/** @type {RedirectRow[]} */ +export const REDIRECTS = []; + +/** The rows in the shape next.config.ts's `redirects()` returns. */ +export function nextRedirects() { + return REDIRECTS.map(({ phase: _phase, ...row }) => row); +}