import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { getSettings } from "yt-dlp-transcript-common/lib/settings"; import { listChannelConfigs } from "yt-dlp-transcript-common/controller/channels"; import { pickCorpusBuild } from "yt-dlp-transcript-common/lib/report/draft/tasks/corpusSource"; import { editionGenerator, r4Steps, triageStep, type CountWindow, type TickDeps, } from "yt-dlp-transcript-common/controller/reportTick"; import type { ReportDraftDeps } from "yt-dlp-transcript-common/controller/reportDraft"; import { armReportSchedule } from "yt-dlp-transcript-common/controller/reportScheduleRunner"; import { enqueueLearn, handProver, learnStep } from "yt-dlp-transcript-common/controller/reportLearn"; import type { EnqueueLearnFn } from "yt-dlp-transcript-common/controller/reportScheduleOps"; import type { HandProver } from "yt-dlp-transcript-common/controller/learnedSpellings"; import { createCorpusTools } from "yt-dlp-transcript-mcp/callTool"; import { SourceRegistry, enumerate } from "yt-dlp-transcript-mcp/research"; import { refreshEditor, researchEditor } from "./_researchEditor"; // THE RECURRING REPORTS' EDITOR SIDE (umtool R5): the deps a tick runs on, // shared by the `report-schedule` route and the lane instrumentation.ts arms. // // generateEdition the existing generate path: a `report-draft` sweep over // the window, after the window check below // countWindow enumerate_matches' own scan (the MCP's, in process) over // the build a sweep would read (the newest holding the // channels): the schedule's terms, or any recording, in // the window. 0 is a quiet edition — unless the scan // was capped (R6.1: partial, the channels it did not read). // fetchAndBuild R4's stage 1 (controller/reportRefresh.ts fetchScope): // this editor's own paced fetches for the scope, then the // local build of the site holding it — through // refreshEditor, the same in-process door a refresh uses // refresh R4's `report-draft {"task":"refresh"}`, awaited; its // refresh.json's status is the tick's outcome // (common/controller/reportTick.ts r4Steps) // triage R6's cheap pass, `report-draft {"task":"triage"}` on // draft:local (or the extractor's draft:api), awaited; its // triage.json says whether to escalate (triageStep) // learn R6.3's proposal pass (learned spellings), before tier 0 // when one is due; awaited (learnStep). `enqueueLearn` is // the same pass for the ops action and a create or a // change of terms (not awaited) // proveSpelling release 32 R2: a spelling added by hand, counted over the // corpus a sweep would read and its proving line found — // code only (handProver), for `add-spelling` const countWindow: CountWindow = async (q) => { const paths = getPaths(); let dir: string; try { dir = (await pickCorpusBuild(q.channels, { exportBuildsDir: paths.exportBuildsDir })).dir; } catch (e) { return { error: (e as Error).message }; } const { source } = await new SourceRegistry({ kind: "local", dir }).resolve(); const e = await enumerate(source, { // No terms: any recording at all in the window. query: q.terms ?? ".", regex: q.terms ? q.regex === true : true, channels: q.channels, date_from: q.from, date_to: q.to, }); if ("error" in e) return { error: e.error }; // R6.1: a capped scan says so — 0 from it is not a quiet window. const c = e.result.coverage; const unreached = [...(c.channelStopped ? [`${c.channelStopped.channel} (stopped at page ${c.channelStopped.page} of ${c.channelStopped.pages})`] : []), ...c.channelsNotReached]; return { recordings: e.result.total, ...(e.result.truncated ? { partial: true, unreached } : {}) }; }; export function reportScheduleDeps(): TickDeps & { enqueueLearn: EnqueueLearnFn; proveSpelling: HandProver } { const paths = getPaths(); const draft: ReportDraftDeps = { paths, corpusTools: (source) => createCorpusTools({ source }), researchEditor, refreshEditor }; return { paths, settings: () => getSettings(), knownChannels: async () => (await listChannelConfigs(paths)).map((c) => c.slug), steps: { ...r4Steps(draft), generateEdition: editionGenerator({ draft, countWindow }), triage: triageStep(draft), learn: learnStep(draft), }, proveSpelling: handProver(draft), enqueueLearn: async (id, trigger) => { const out = await enqueueLearn(id, trigger, draft); if (!out.ok) return out; void out.result.stream.cancel(); return { ok: true, jobId: out.jobId, plan: out.plan }; }, }; } // Armed by instrumentation.ts below the idle gate (and refused on an idle // boot by the runner itself). See common/controller/reportScheduleRunner.ts. export function armReportScheduleLane(): boolean { return armReportSchedule({ deps: reportScheduleDeps(), log: (line) => console.log(line) }); }