Archilyzer · Source

archilyzer

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

commit 9d9b3d9fc630f41a2017e46db1d91290f58d30f9
parent 23121878c4c7cb5fd9d5225b5bf46b6ee57db595
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Fri, 16 Oct 2026 17:29:36 -0400

common, umtool: an article older than iterations is written by hand too — its report.json is the claim's base and the claim's iteration its first (no parent); the by-hand tools show on it, working on "the article's report"

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

Diffstat:
Mcommon/controller/handEdits.test.ts | 13+++++++++++++
Mcommon/controller/handEdits.ts | 47++++++++++++++++++++++++++++++++++++++---------
Mumtool/app/api/articles/by-hand/route.ts | 21++++++++++++++-------
Mumtool/components/articles/HandTools.tsx | 18+++++++++++++++---
Mumtool/components/articles/IterationsView.tsx | 2+-
5 files changed, 81 insertions(+), 20 deletions(-)

diff --git a/common/controller/handEdits.test.ts b/common/controller/handEdits.test.ts @@ -182,3 +182,16 @@ test("cuesAround: the record's cues in a window, and its title", async () => { 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"); + await writeArticle({ format: "archilyzer-report", version: 1, id: "older", kind: "factcheck", title: "Older", sections: [{ id: "s1", title: "One", claims: [{ id: "c1", text: "First." }] }] }, { paths }); + assert.equal(await defaultHandBase("older", paths), null); + const r = await addClaimByHand("older", { section: { id: "s1" }, claim: { text: "Second." } }, paths, NOW); + assert.deepEqual([r.n, r.amended, r.claim], [1, false, "c2"]); + const i1 = (await readIterations("older", paths)).iterations[0]!; + assert.deepEqual([i1.kind, i1.parent, i1.status], ["hand", null, "done"]); + assert.match(i1.feedback ?? "", /^from the article's report\.json: added c2/); + assert.equal(reportOf(paths, "older", 1).sections[0].claims.length, 2); +}); diff --git a/common/controller/handEdits.ts b/common/controller/handEdits.ts @@ -17,7 +17,9 @@ // no proposal. // // WHERE A CLAIM GOES. The base is an iteration with a report (default: the one -// the article's report came from, else the newest done one with a report). A +// the article's report came from, else the newest done one with a report); an +// article older than iterations (a report.json, no iteration) is its own base, +// and the claim's iteration is its first (no parent). A // base of kind `hand` that is no one's current (report or video) and has no // video project is AMENDED in place — a person filling a blank article adds to // one draft, not one iteration per claim; its `feedback` gains a line. Any @@ -41,7 +43,8 @@ import { writeIterationFile, type Iteration, } from "../lib/report/iterations"; -import { ArticleRegistryError, assertArticleId } from "../lib/report/registry"; +import { readFile } from "node:fs/promises"; +import { ArticleRegistryError, articleFile, assertArticleId } from "../lib/report/registry"; import { REPORT_FORMAT, REPORT_VERSION, REPORT_KINDS, type Claim, type Report, type ReportKind } from "../lib/report/schema"; import { RESERVED_ANCHOR_IDS } from "../lib/report/slideRules"; import { isVerdict, type Verdict } from "../lib/report/verdicts"; @@ -242,17 +245,38 @@ async function readReportOf(id: string, n: number, paths: HandPaths): Promise<Re return raw as Report; } +/** The article's own report.json, parsed (raw, its key order kept). */ +export async function readArticleReport(id: string, paths: HandPaths = getPaths()): Promise<Report> { + const file = articleFile(paths, id); + let raw: unknown; + try { + raw = JSON.parse(await readFile(file, "utf8")); + } catch { + fail(`"${id}"'s report.json does not read`); + } + const parsed = parseReport(raw, { id }); + if (!parsed.ok) fail(`"${id}"'s report does not read`, parsed.problems.map((p) => `${p.path || "(root)"}: ${p.message}`)); + return raw as Report; +} + /** ADD A CLAIM BY HAND (see the header). Throws HandEditError (input) or ArticleRegistryError (the store). */ export async function addClaimByHand(id: string, input: HandClaimInput, paths: HandPaths = getPaths(), now: Date = new Date()): Promise<HandClaimResult> { assertArticleId(id); const text = str(input.claim?.text); if (!text) fail("the claim's text is the claim, as stated"); const base = input.base ?? (await defaultHandBase(id, paths)); - if (base === null || base === undefined) fail(`"${id}" has no report to add to: start it blank first`); - const baseIt = await readIteration(id, base!, paths); - if (!baseIt) fail(`"${id}" has no iteration ${iterationLabel(base!)}`); - if (baseIt!.status !== "done") fail(`${iterationLabel(base!)} is ${baseIt!.status}: add to a done iteration`); - const report = await readReportOf(id, base!, paths); + let baseIt: Iteration | null = null; + let report: Report; + if (base === null || base === undefined) { + // An article older than iterations: its report.json is the base. + if (!(await hasArticleReport(id, paths)) || (await readIterations(id, paths)).iterations.length) fail(`"${id}" has no report to add to: start it blank first`); + report = await readArticleReport(id, paths); + } else { + baseIt = await readIteration(id, base, paths); + if (!baseIt) fail(`"${id}" has no iteration ${iterationLabel(base)}`); + if (baseIt!.status !== "done") fail(`${iterationLabel(base)} is ${baseIt!.status}: add to a done iteration`); + report = await readReportOf(id, base, paths); + } const verdict = input.claim.verdict ?? null; if (verdict !== null && !isVerdict(verdict)) fail(`"${String(verdict)}" is not a verdict`); @@ -321,14 +345,19 @@ export async function addClaimByHand(id: string, input: HandClaimInput, paths: H const line = `added ${cidClaim} to “${sections[si]!.title}”${added.length ? ` (${added.length} new citation${added.length === 1 ? "" : "s"})` : ""}`; const cur = await currentIteration(id, paths); - const amend = baseIt!.kind === "hand" && cur.report !== base && cur.reportFrom !== base && cur.video !== base && !baseIt!.projectDir; + const amend = !!baseIt && baseIt.kind === "hand" && cur.report !== base && cur.reportFrom !== base && cur.video !== base && !baseIt.projectDir; let n: number; if (amend) { n = base!; await writeIterationFile(id, n, "report.json", next, paths); await updateIteration(id, n, (it) => ({ feedback: it.feedback ? `${it.feedback}\n${line}` : line }), paths, now); } else { - const it = await createIteration(id, { kind: "hand", model: HAND_MODEL, parent: base!, feedback: line, status: "running" }, paths, now); + const it = await createIteration( + id, + { kind: "hand", model: HAND_MODEL, parent: baseIt ? base! : null, feedback: baseIt ? line : `from the article's report.json: ${line}`, status: "running" }, + paths, + now, + ); n = it.n; await finishHand(id, n, next, paths, now); } diff --git a/umtool/app/api/articles/by-hand/route.ts b/umtool/app/api/articles/by-hand/route.ts @@ -4,6 +4,7 @@ import { defaultHandBase, HandEditError, parseMoment, + readArticleReport, startBlankArticle, type HandClaimInput, } from "yt-dlp-transcript-common/controller/handEdits"; @@ -45,14 +46,20 @@ async function baseView(article: string, n: number | null): Promise<HandBaseView const paths = sitesPaths(); const at = n ?? (await defaultHandBase(article, paths)); const empty: HandBaseView = { article, n: at, reportKind: null, title: null, sections: [], citations: [], respellings: [] }; - if (at === null) return empty; - const text = await readIterationFile(article, at, "report.json", paths); - if (text === null) return empty; let r: Report; - try { - r = JSON.parse(text) as Report; - } catch { - return empty; + if (at === null) { + // An article older than iterations: its own report.json. + const own = await readArticleReport(article, paths).catch(() => null); + if (!own) return empty; + r = own; + } else { + const text = await readIterationFile(article, at, "report.json", paths); + if (text === null) return empty; + try { + r = JSON.parse(text) as Report; + } catch { + return empty; + } } return { article, diff --git a/umtool/components/articles/HandTools.tsx b/umtool/components/articles/HandTools.tsx @@ -516,7 +516,18 @@ function ClaimForm({ article, view, onDone }: { article: string; view: HandBaseV // ─── the tools ─── -export default function HandTools({ article, bases, initialBase }: { article: string; bases: HandBase[]; initialBase: number | null }) { +export default function HandTools({ + article, + bases, + initialBase, + ownReport = false, +}: { + article: string; + bases: HandBase[]; + initialBase: number | null; + /** An article older than iterations: its report.json is what both tools work on. */ + ownReport?: boolean; +}) { const router = useRouter(); const [n, setN] = useState<number | null>(initialBase); const [open, setOpen] = useState<"respell" | "claim" | null>(null); @@ -537,7 +548,7 @@ export default function HandTools({ article, bases, initialBase }: { article: st router.refresh(); }, [article, router]); const known = useMemo(() => bases.slice().sort((a, b) => b.n - a.n), [bases]); - if (!known.length) return null; + if (!known.length && !ownReport) return null; return ( <section aria-label="by hand" data-hand-tools={article} className="rounded-[3px] border border-seam bg-panel px-4 py-3"> <div className="flex flex-wrap items-center gap-2"> @@ -551,6 +562,7 @@ export default function HandTools({ article, bases, initialBase }: { article: st <label className="ml-auto flex items-center gap-1.5 text-[12px] text-muted"> on <Select aria-label="iteration to work on" value={n ?? ""} onChange={(e) => setN(e.target.value ? Number(e.target.value) : null)} className="py-[2px] text-[12px]"> + {!known.length && <option value="">the article&apos;s report</option>} {known.map((b) => ( <option key={b.n} value={b.n}> {b.label} · {b.kind} @@ -595,7 +607,7 @@ export default function HandTools({ article, bases, initialBase }: { article: st /> </div> ) : ( - <p className="mb-0 mt-2 text-[12px] text-muted">reading i{n}…</p> + <p className="mb-0 mt-2 text-[12px] text-muted">reading {n !== null ? `i${n}` : "the report"}…</p> ))} </section> ); diff --git a/umtool/components/articles/IterationsView.tsx b/umtool/components/articles/IterationsView.tsx @@ -22,7 +22,7 @@ export default async function IterationsView({ article }: { article: string }) { const initialBase = initial.current.reportFrom ?? bases[0]?.n ?? null; return ( <> - <HandTools article={article} bases={bases} initialBase={initialBase} /> + <HandTools article={article} bases={bases} initialBase={initialBase} ownReport={!initial.pending && !initial.iterations.length} /> <IterationsTab initial={initial} policy={policy} today={today} /> </> );