Archilyzer · Source

archilyzer

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

commit 2764a36b58c1c637dce047d64fd8f5c5d7ad126f
parent 9d9b3d9fc630f41a2017e46db1d91290f58d30f9
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Fri, 16 Oct 2026 17:52:40 -0400

common: cuesAround moves to publish/citedCues.ts — controller/ may not import publish/ (the layering guard)

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

Diffstat:
Mcommon/controller/handEdits.test.ts | 11+----------
Mcommon/controller/handEdits.ts | 20--------------------
Acommon/publish/citedCues.test.ts | 43+++++++++++++++++++++++++++++++++++++++++++
Acommon/publish/citedCues.ts | 29+++++++++++++++++++++++++++++
Mumtool/app/api/articles/by-hand/route.ts | 4++--
5 files changed, 75 insertions(+), 32 deletions(-)

diff --git a/common/controller/handEdits.test.ts b/common/controller/handEdits.test.ts @@ -10,7 +10,7 @@ import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "nod import { tmpdir } from "node:os"; import path from "node:path"; import { createIteration, currentIteration, makeCurrent, readIteration, readIterations, updateIteration, writeIterationFile } from "../lib/report/iterations"; -import { addClaimByHand, cuesAround, defaultHandBase, HandEditError, parseMoment, startBlankArticle } from "./handEdits"; +import { addClaimByHand, defaultHandBase, HandEditError, parseMoment, startBlankArticle } from "./handEdits"; const ROOTS: string[] = []; after(() => { @@ -174,15 +174,6 @@ test("parseMoment: an archive link, the house citation, channel/id@time", () => assert.equal(parseMoment("not a moment"), null); }); -test("cuesAround: the record's cues in a window, and its title", async () => { - const paths = store(); - const got = await cuesAround(CHAN, "rec1", 13, 19, paths); - assert.equal(got?.title, "Synthetic stream"); - assert.deepEqual(got?.cues.map((c) => c.start), [10, 14, 18]); - assert.equal(await cuesAround(CHAN, "../x", 0, 10, paths), null); - assert.equal(await cuesAround(CHAN, "nope", 0, 10, paths), null); -}); - test("an article older than iterations: its report.json is the base; the claim's iteration is i1, no parent", async () => { const paths = store(); const { writeArticle } = await import("../lib/report/registry"); diff --git a/common/controller/handEdits.ts b/common/controller/handEdits.ts @@ -51,7 +51,6 @@ import { isVerdict, type Verdict } from "../lib/report/verdicts"; import { parseReport } from "../lib/report/validate"; import { MAX_CITATION_SPAN_SECONDS, REF_ID_RE, type Citation } from "../lib/citations/schema"; import { parseCitationHref, slugOf } from "../lib/report/convertShared"; -import { readCitedRecord } from "../publish/composeReports"; import { QUOTE_WARNING_STATUSES, verifyReportQuotes, type QuoteResult } from "../bin/reports-check"; export const HAND_MODEL = "hand"; @@ -397,23 +396,4 @@ export function parseMoment(text: string): MomentRead | null { return { channel: m[1]!, id: m[2]!, kind: "span", at, quote: null }; } -export type CueLine = { start: number; end: number; text: string }; - -/** The record's cues from `from` to `to` seconds (its best track: the one compose reads), and its title. */ -export async function cuesAround( - channel: string, - id: string, - from: number, - to: number, - paths: Pick<Paths, "channelsDir"> = getPaths(), -): Promise<{ title: string | null; cues: CueLine[] } | null> { - if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(channel) || !id || /[/\\]|^\.\.?$/.test(id)) return null; - const rec = await readCitedRecord(paths.channelsDir, channel, id).catch(() => null); - if (!rec) return null; - return { - title: rec.summary.title ?? null, - cues: rec.cues.filter((c) => c.end > from && c.start < to).map((c) => ({ start: c.start, end: c.end, text: c.text })), - }; -} - export { ArticleRegistryError }; diff --git a/common/publish/citedCues.test.ts b/common/publish/citedCues.test.ts @@ -0,0 +1,43 @@ +// The cues around a cited second (release 32 R2): the record's cues as compose +// reads them, in a window, and its title. A synthetic record in a temp dir. +// +// Run with: node_modules/.bin/tsx --test publish/citedCues.test.ts + +import { after, test } from "node:test"; +import assert from "node:assert/strict"; +import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import path from "node:path"; +import { cuesAround } from "./citedCues"; + +const root = mkdtempSync(path.join(tmpdir(), "cited-cues-")); +after(() => rmSync(root, { recursive: true, force: true })); + +const ts = (s: number) => new Date(s * 1000).toISOString().slice(11, 23); +const put = (file: string, text: string) => { + mkdirSync(path.dirname(file), { recursive: true }); + writeFileSync(file, text); +}; +const channelsDir = path.join(root, "channels"); +const dir = path.join(channelsDir, "synth-hand", "data", "rec1"); +put(path.join(dir, "metadata.info.json"), JSON.stringify({ id: "rec1", title: "Synthetic stream", channel: "synth-hand", upload_date: "20260110", duration: 600, webpage_url: "https://www.youtube.com/watch?v=rec1", extractor_key: "Youtube" })); +put( + path.join(dir, "transcript.en.vtt"), + "WEBVTT\nKind: captions\nLanguage: en\n\n" + + ([ + [10, 14, "The bakery opened in the spring of that year."], + [14, 18, "I was there for the first loaf, honestly."], + [18, 22, "Nobody believed the oven would hold up."], + [40, 44, "Much later."], + ] as const) + .map(([a, b, t]) => `${ts(a)} --> ${ts(b)}\n${t}\n`) + .join("\n"), +); + +test("cuesAround: the record's cues in a window, and its title; a bad id or no record is null", async () => { + const got = await cuesAround("synth-hand", "rec1", 13, 19, { channelsDir }); + assert.equal(got?.title, "Synthetic stream"); + assert.deepEqual(got?.cues.map((c) => c.start), [10, 14, 18]); + assert.equal(await cuesAround("synth-hand", "../x", 0, 10, { channelsDir }), null); + assert.equal(await cuesAround("synth-hand", "nope", 0, 10, { channelsDir }), null); +}); diff --git a/common/publish/citedCues.ts b/common/publish/citedCues.ts @@ -0,0 +1,29 @@ +// THE CUES AROUND A CITED SECOND (release 32 R2): what umtool's "Add a claim" +// lists to pick a quote from — the record's cues as compose reads them +// (readCitedRecord: the normalized cues, else whisper, else the English VTTs, +// en-orig first). Here, in publish/, because the reader is; the claim's writer +// (controller/handEdits.ts) may not import this layer. +// +// SERVER-ONLY. + +import { getPaths, type Paths } from "../lib/paths"; +import { readCitedRecord } from "./composeReports"; + +export type CueLine = { start: number; end: number; text: string }; + +/** The record's cues from `from` to `to` seconds (its best track: the one compose reads), and its title. */ +export async function cuesAround( + channel: string, + id: string, + from: number, + to: number, + paths: Pick<Paths, "channelsDir"> = getPaths(), +): Promise<{ title: string | null; cues: CueLine[] } | null> { + if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(channel) || !id || /[/\\]|^\.\.?$/.test(id)) return null; + const rec = await readCitedRecord(paths.channelsDir, channel, id).catch(() => null); + if (!rec) return null; + return { + title: rec.summary.title ?? null, + cues: rec.cues.filter((c) => c.end > from && c.start < to).map((c) => ({ start: c.start, end: c.end, text: c.text })), + }; +} diff --git a/umtool/app/api/articles/by-hand/route.ts b/umtool/app/api/articles/by-hand/route.ts @@ -1,6 +1,5 @@ import { addClaimByHand, - cuesAround, defaultHandBase, HandEditError, parseMoment, @@ -8,6 +7,7 @@ import { startBlankArticle, type HandClaimInput, } from "yt-dlp-transcript-common/controller/handEdits"; +import { cuesAround } from "yt-dlp-transcript-common/publish/citedCues"; import { readIterationFile } from "yt-dlp-transcript-common/lib/report/iterations"; import { ArticleRegistryError } from "yt-dlp-transcript-common/lib/report/registry"; import { isReportId, type Report } from "yt-dlp-transcript-common/lib/report/schema"; @@ -25,7 +25,7 @@ export const dynamic = "force-dynamic"; // GET ?article=<id>[&n=<iteration>] the report a claim would join: its // sections, citations and respellings (n // absent: the default base) -// GET ?moment=<text> a pasted moment (an archive link, the +// GET ?moment=<text> a pasted moment (common publish/citedCues.ts) (an archive link, the // house citation, <channel>/<id>@<m:ss>) // and the record's cues around it // GET ?channel=&id=&at= the cues around a second