Archilyzer · Source

archilyzer

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

commit 831b26669a1d688e77b16e888885e9e7a0d2f359
parent c3edc1323c2c0fb2e6ffa1b6f3a6d51e963a4942
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 14 Oct 2026 20:23:46 -0400

common, mcp: R6.2's pieces as small exported functions for R6.3 to build on — recordHasText and statHasText (delta.ts), splitByTranscript and nextSeen (tier0.ts), each unit-tested

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

Diffstat:
Mcommon/lib/report/draft/refresh/delta.ts | 10++++++++++
Mcommon/lib/report/draft/triage/tier0.ts | 40+++++++++++++++++++++++++++++-----------
Mcommon/lib/report/draft/triage/triage.test.ts | 20++++++++++++++++++++
Mmcp/src/enumerate.ts | 10+++-------
4 files changed, 62 insertions(+), 18 deletions(-)

diff --git a/common/lib/report/draft/refresh/delta.ts b/common/lib/report/draft/refresh/delta.ts @@ -58,6 +58,16 @@ export type EnumerateFn = (args: Record<string, unknown>) => Promise<EnumeratedA // not say (read as judge-able, as before R6.2). export type ListedRecording = { id: string; channel: string | null; channelSlug: string | null; date: string | null; title: string | null; hasTranscript?: boolean | null }; export type RecordingListing = { rows: ListedRecording[]; complete: boolean; unreached: string[]; problems: string[] }; + +/** R6.2: does a transcript record (a shard page's) carry transcript text — at least one cue? */ +export function recordHasText(rec: { cues?: unknown } | null | undefined): boolean { + return !!rec && Array.isArray(rec.cues) && rec.cues.length > 0; +} + +/** R6.2: a stats index entry's word on transcript text; null when there is no entry or it does not say. */ +export function statHasText(stat: { hasTranscript?: unknown } | null | undefined): boolean | null { + return stat && typeof stat.hasTranscript === "boolean" ? stat.hasTranscript : null; +} export type ListArgs = { channels?: string[]; date_from?: string; date_to?: string }; export type ListFn = (args: ListArgs) => Promise<RecordingListing>; diff --git a/common/lib/report/draft/triage/tier0.ts b/common/lib/report/draft/triage/tier0.ts @@ -94,6 +94,32 @@ export function tagMatches(tag: string, topic: string): boolean { return t === p || t.includes(p) || p.includes(t); } +/** + * R6.2: a listing split into what a triage can judge now and what waits for + * its transcript (`hasTranscript: false`). Unknown (null/absent) is judge-able. + */ +export function splitByTranscript<R extends { hasTranscript?: boolean | null }>(rows: readonly R[]): { judgeable: R[]; waiting: R[] } { + const judgeable: R[] = []; + const waiting: R[] = []; + for (const r of rows) (r.hasTranscript === false ? waiting : judgeable).push(r); + return { judgeable, waiting }; +} + +/** + * The set a run stores as seen.json (R6.1, R6.2): everything known, plus + * everything listed that can be judged — less the candidates past the cap + * (they stay new) and less what is listed without a transcript (new once + * transcribed; a known id among them, stored before R6.2, is dropped, so it + * heals). A PARTIAL run stores nothing (null): what it did not reach must not + * become known, so the next run falls back to the last complete run's set (or + * to its `since`). + */ +export function nextSeen(o: { partial: boolean; known: Iterable<string> | null; judgeable: Iterable<string>; cut: Iterable<string>; waiting: Iterable<string> }): string[] | null { + if (o.partial) return null; + const drop = new Set([...o.cut, ...o.waiting]); + return [...new Set([...(o.known ?? []), ...o.judgeable])].filter((id) => !drop.has(id)); +} + export async function triageCandidates(i: Tier0Input, d: Tier0Deps): Promise<Tier0Result> { const log = (l: string) => d.log?.(l); if (i.ids?.length) { @@ -115,9 +141,7 @@ export async function triageCandidates(i: Tier0Input, d: Tier0Deps): Promise<Tie const perQuery: TriageTier0["perQuery"] = [{ query: listing.by === "manifests" ? "(every recording, listed)" : "(any recording)", n: rows.length, partial: !listing.complete }]; // R6.2: listed with no transcript text yet — not judge-able, so not new and // not seen (new on the run after its transcript lands). - const waiting = rows.filter((r) => r.hasTranscript === false); - const waitingIds = new Set(waiting.map((r) => r.id)); - const judgeable = waiting.length ? rows.filter((r) => !waitingIds.has(r.id)) : rows; + const { judgeable, waiting } = splitByTranscript(rows); const isNew = (id: string, date: string | null) => (i.known ? !i.known.has(id) : since ? !!date && date >= since : true); const fresh = judgeable.filter((r) => isNew(r.id, ymdOf(r.date))); const byId = new Map(fresh.map((r) => [r.id, r])); @@ -201,15 +225,9 @@ export async function triageCandidates(i: Tier0Input, d: Tier0Deps): Promise<Tie ); const candidates = ranked.slice(0, i.max); const cut = ranked.slice(i.max).map((c) => c.id); - const cutSet = new Set(cut); const scannedIds = rows.map((r) => r.id); - // Seen: everything known, everything listed WITH TEXT, less what was cut - // (it stays new) and less what is listed without a transcript (R6.2: it is - // new once transcribed — a known id among them, stored before R6.2, is - // dropped too). A PARTIAL run stores nothing: what it did not reach must - // not become known, so the next run falls back to the last complete run's - // set (or to its `since`). - const seen = partial ? null : [...new Set([...(i.known ?? []), ...judgeable.map((r) => r.id)])].filter((id) => !cutSet.has(id) && !waitingIds.has(id)); + // Seen: nextSeen's rule (known + judge-able, less cut and waiting; partial: none). + const seen = nextSeen({ partial, known: i.known, judgeable: judgeable.map((r) => r.id), cut, waiting: waiting.map((r) => r.id) }); if (partial) log(`tier 0: PARTIAL${unreached.size ? ` — not reached: ${[...unreached].join(", ")}` : ""}: this run's seen set is not kept`); return { tier0: { diff --git a/common/lib/report/draft/triage/triage.test.ts b/common/lib/report/draft/triage/triage.test.ts @@ -436,6 +436,26 @@ test("R6.1 tier 0: the corpus tools' listRecordings is the default listing", asy // ─── R6.2: seen means judge-able — an untranscribed recording stays new ─── import { listedWords } from "./types"; +import { nextSeen, splitByTranscript } from "./tier0"; +import { recordHasText, statHasText } from "../refresh/delta"; + +test("R6.2 the pieces: recordHasText, statHasText, splitByTranscript, nextSeen", () => { + assert.equal(recordHasText({ cues: [{ start: 0, end: 1, text: "x" }] }), true); + assert.equal(recordHasText({ cues: [] }), false); + assert.equal(recordHasText({ cues: undefined }), false); + assert.equal(recordHasText(null), false); + assert.equal(statHasText({ hasTranscript: true }), true); + assert.equal(statHasText({ hasTranscript: false }), false); + assert.equal(statHasText({}), null, "an entry that does not say"); + assert.equal(statHasText(undefined), null, "no entry"); + const { judgeable, waiting } = splitByTranscript([{ id: "a", hasTranscript: true }, { id: "b", hasTranscript: false }, { id: "c", hasTranscript: null }, { id: "d" }]); + assert.deepEqual(judgeable.map((r) => r.id), ["a", "c", "d"], "unknown is judge-able"); + assert.deepEqual(waiting.map((r) => r.id), ["b"]); + // known + judge-able, less cut and waiting (a known id now waiting is dropped: it heals). + assert.deepEqual(nextSeen({ partial: false, known: new Set(["k", "b"]), judgeable: ["a", "c", "x"], cut: ["x"], waiting: ["b"] }), ["k", "a", "c"]); + assert.deepEqual(nextSeen({ partial: false, known: null, judgeable: ["a"], cut: [], waiting: [] }), ["a"]); + assert.equal(nextSeen({ partial: true, known: new Set(["k"]), judgeable: ["a"], cut: [], waiting: [] }), null, "a partial run stores nothing"); +}); test("R6.2 tier 0: a recording listed with no transcript yet is neither new nor seen; on the run after its transcript lands it is new (by id) and a candidate; the counts are said", async () => { // late-03 is listed by the build's manifests before its transcript lands. diff --git a/mcp/src/enumerate.ts b/mcp/src/enumerate.ts @@ -20,7 +20,7 @@ import { } from "yt-dlp-transcript-common/lib/availability"; import type { LayerScope } from "yt-dlp-transcript-common/lib/searchQuery"; import type { TranscriptDetail } from "yt-dlp-transcript-common/lib/transcripts"; -import type { ListArgs, ListedRecording, RecordingListing } from "yt-dlp-transcript-common/lib/report/draft/refresh/delta"; +import { recordHasText, statHasText, type ListArgs, type ListedRecording, type RecordingListing } from "yt-dlp-transcript-common/lib/report/draft/refresh/delta"; import type { ChannelRef, ShardSource } from "./source"; import { parseContentTypes, @@ -302,10 +302,6 @@ export async function listRecordings(source: ShardSource, args: ListArgs): Promi stats = null; } } - const textOf = (slug: string): boolean | null => { - const s = stats?.get(slug); - return s && typeof s.hasTranscript === "boolean" ? s.hasTranscript : null; - }; const rows: ListedRecording[] = []; const inRange = (d: string | null) => (!from || (d !== null && d >= from)) && (!to || (d !== null && d <= to)); for (const ch of sel.channels) { @@ -331,7 +327,7 @@ export async function listRecordings(source: ShardSource, args: ListArgs): Promi continue; } const date = ymd(rec.uploadDate); - if (inRange(date)) rows.push({ id, channel: ch.name, channelSlug: ch.slug, date, title: rec.title ?? null, hasTranscript: textOf(`${ch.slug}/${id}`) }); + if (inRange(date)) rows.push({ id, channel: ch.name, channelSlug: ch.slug, date, title: rec.title ?? null, hasTranscript: statHasText(stats?.get(`${ch.slug}/${id}`)) }); } let lost = 0; for (const [page, ids] of undated) { @@ -350,7 +346,7 @@ export async function listRecordings(source: ShardSource, args: ListArgs): Promi } const date = ymd(r.uploadDate); // The record is in hand: its own cues say, whatever the stats say. - if (inRange(date)) rows.push({ id, channel: ch.name, channelSlug: ch.slug, date, title: r.title ?? null, hasTranscript: Array.isArray(r.cues) && r.cues.length > 0 }); + if (inRange(date)) rows.push({ id, channel: ch.name, channelSlug: ch.slug, date, title: r.title ?? null, hasTranscript: recordHasText(r) }); } } if (lost) {