diff --git a/.changes/knowledge/fix-video-digest-asr-vocabulary-3d7a9c52.md b/.changes/knowledge/fix-video-digest-asr-vocabulary-3d7a9c52.md new file mode 100644 index 00000000000..bc5a3b72ea7 --- /dev/null +++ b/.changes/knowledge/fix-video-digest-asr-vocabulary-3d7a9c52.md @@ -0,0 +1,7 @@ +--- +bump: patch +--- + +### Fixed + +- `video-digest` ASR transcripts now get the same proper-noun repair captions do: the repair lexicon is built from the title, description and harvested links for every transcript strategy, and the repair pass runs over ASR cues, so `repairedTermCount` counts their repairs. diff --git a/plugins/knowledge/skills/video-digest/extraction/transcript/proper-noun-repair.js b/plugins/knowledge/skills/video-digest/extraction/transcript/proper-noun-repair.js index fecd1371ec4..750c207502f 100644 --- a/plugins/knowledge/skills/video-digest/extraction/transcript/proper-noun-repair.js +++ b/plugins/knowledge/skills/video-digest/extraction/transcript/proper-noun-repair.js @@ -70,15 +70,17 @@ function isProperNounShaped(word) { } /** - * Build the repair lexicon from the post text and its harvested links. - * Description terms win over link-derived terms on a key collision (the - * author's casing beats a lowercased URL slug). + * Build the repair lexicon from the video title, the post text and its + * harvested links. Title terms win over description terms, and both win over + * link-derived terms, on a key collision (the author's casing beats a + * lowercased URL slug). * * @param {string} description - the post text (yt-dlp `description`) * @param {readonly HarvestedLink[]} [harvestedLinks] + * @param {string} [title] - the video title (yt-dlp `title`) * @returns {string[]} lexicon terms, single words and multi-word phrases */ -export function buildRepairLexicon(description, harvestedLinks = []) { +export function buildRepairLexicon(description, harvestedLinks = [], title = "") { /** @type {Map} */ const byKey = new Map(); /** @param {string} term */ @@ -88,33 +90,34 @@ export function buildRepairLexicon(description, harvestedLinks = []) { if (!byKey.has(key)) byKey.set(key, term); }; - const tokens = (description ?? "") - .split(/\s+/) - .map(stripEdgePunctuation) - .filter(Boolean); + // Each text is its own pass, so a capitalized run never spans the title and + // the description. + for (const text of [title, description]) { + const tokens = (text ?? "").split(/\s+/).map(stripEdgePunctuation).filter(Boolean); - // Runs of consecutive capitalized words form phrases ("Claude Code") — the - // multi-word shape single-token extraction misses. Phrases go in FIRST so - // the author's spaced phrasing wins a key collision with a compacted form - // of the same name (e.g. the "#ClaudeCode" hashtag). - /** @type {string[]} */ - let run = []; - const flushRun = () => { - if (run.length >= 2) add(run.join(" ")); - run = []; - }; - for (const token of tokens) { - if (/^[A-Z][A-Za-z0-9'’.-]*$/.test(token) && !STOPWORDS.has(token.toLowerCase())) { - run.push(token); - } else { - flushRun(); + // Runs of consecutive capitalized words form phrases ("Claude Code") — the + // multi-word shape single-token extraction misses. Phrases go in FIRST so + // the author's spaced phrasing wins a key collision with a compacted form + // of the same name (e.g. the "#ClaudeCode" hashtag). + /** @type {string[]} */ + let run = []; + const flushRun = () => { + if (run.length >= 2) add(run.join(" ")); + run = []; + }; + for (const token of tokens) { + if (/^[A-Z][A-Za-z0-9'’.-]*$/.test(token) && !STOPWORDS.has(token.toLowerCase())) { + run.push(token); + } else { + flushRun(); + } } - } - flushRun(); + flushRun(); - for (const token of tokens) { - if (isProperNounShaped(token)) { - add(token.replace(/^[@#]/, "")); + for (const token of tokens) { + if (isProperNounShaped(token)) { + add(token.replace(/^[@#]/, "")); + } } } diff --git a/plugins/knowledge/skills/video-digest/extraction/transcript/proper-noun-repair.test.js b/plugins/knowledge/skills/video-digest/extraction/transcript/proper-noun-repair.test.js index 12dc92ddbe1..69e4955f18f 100644 --- a/plugins/knowledge/skills/video-digest/extraction/transcript/proper-noun-repair.test.js +++ b/plugins/knowledge/skills/video-digest/extraction/transcript/proper-noun-repair.test.js @@ -41,6 +41,17 @@ describe("buildRepairLexicon", () => { expect(lexicon).toContain("claude-code"); }); + it("includes a term that appears only in the title", () => { + const lexicon = buildRepairLexicon("nothing notable here", [], "Building with Pstack and Claude Code"); + expect(lexicon).toContain("Pstack"); + expect(lexicon).toContain("Claude Code"); + }); + + it("does not join a capitalized run across the title and the description", () => { + const lexicon = buildRepairLexicon("Code review notes", [], "Intro to Claude"); + expect(lexicon).not.toContain("Claude Code"); + }); + it("prefers the author's casing over a link slug on a key collision", () => { const lexicon = buildRepairLexicon("GitHub is where it lives", [ { url: "https://github.com/x", source: "description" }, diff --git a/plugins/knowledge/skills/video-digest/extraction/transcript/write-transcript.js b/plugins/knowledge/skills/video-digest/extraction/transcript/write-transcript.js index 9c82287180a..51b5d2cd2d4 100644 --- a/plugins/knowledge/skills/video-digest/extraction/transcript/write-transcript.js +++ b/plugins/knowledge/skills/video-digest/extraction/transcript/write-transcript.js @@ -281,7 +281,7 @@ export function transcriptFilename(entryIndex, primaryEntryIndex) { * @property {number} paragraphCount * @property {boolean} cleanedAutoCaptions * @property {TranscriptStrategy} strategy - the strategy that produced this transcript - * @property {number} repairedTermCount - proper-noun repairs applied (`captions+repair`) + * @property {number} repairedTermCount - proper-noun repairs applied (`captions+repair` and `asr`) */ /** @@ -314,8 +314,9 @@ export function transcriptFilename(entryIndex, primaryEntryIndex) { * Per entry, the transcript strategy resolves from the adapter default and the * explicit pipeline override ({@link resolveTranscriptStrategy}): captions are * consumed as before, `captions+repair` layers proper-noun repair (lexicon = - * post text + harvested links), and the `asr` rung runs the optional local - * toolchain — detected at runtime, never auto-installed. A degraded entry + * title + post text + harvested links), and the `asr` rung runs the optional + * local toolchain, its cues repaired with the same lexicon — detected at + * runtime, never auto-installed. A degraded entry * (no transcript producible) is recorded in `transcriptDegradation`. * * @param {object} options @@ -372,12 +373,10 @@ export async function writeEnvelopeTranscriptArtifacts( requested === "asr" || entries.some((entry) => !entry.caption && entry.mediaPath); const asrDetection = needAsrProbe ? await detectAsr() : null; - // The adapter default can also resolve as the asr-unavailable fallback, so - // the lexicon is built whenever either route can reach `captions+repair`. - const repairLexicon = - requested === "captions+repair" || transcriptStrategy === "captions+repair" - ? buildRepairLexicon(metadata.description, harvestedLinks) - : null; + // Every strategy gets the lexicon, repair-only: captions+repair and ASR cues + // are repaired against it. It is never fed to ASR as an initial prompt (the + // probe in reference/sources/x.md showed no gain and a worse hallucination). + const repairLexicon = buildRepairLexicon(metadata.description, harvestedLinks, metadata.title); /** @type {EnvelopeTranscriptEntry[]} */ const transcripts = []; @@ -419,13 +418,14 @@ export async function writeEnvelopeTranscriptArtifacts( }); continue; } - const transcript = formatTranscript(asr.cues); + const repaired = repairCues(asr.cues, repairLexicon); + const transcript = formatTranscript(repaired.cues); built = { transcript, - cueCount: asr.cues.length, + cueCount: repaired.cues.length, paragraphCount: countParagraphs(transcript), cleanedAutoCaptions: false, - repairedTermCount: 0, + repairedTermCount: repaired.replacementCount, }; } else { const caption = /** @type {NonNullable} */ (entry.caption); diff --git a/plugins/knowledge/skills/video-digest/extraction/transcript/write-transcript.test.js b/plugins/knowledge/skills/video-digest/extraction/transcript/write-transcript.test.js index a4d1eaf9aa6..62d2dc13ac0 100644 --- a/plugins/knowledge/skills/video-digest/extraction/transcript/write-transcript.test.js +++ b/plugins/knowledge/skills/video-digest/extraction/transcript/write-transcript.test.js @@ -478,6 +478,69 @@ so I opened clawed code today expect(files[path.join(sliceDir, "source", "transcript.txt")]).toContain("spoken words"); }); + it("the asr rung runs without an initialPrompt (the lexicon is repair-only)", async () => { + /** @type {Record | undefined} */ + let seenOptions; + const options = asrCandidateOptions(); + const result = await writeEnvelopeTranscriptArtifacts( + { + ...options, + envelope: createAcquisitionEnvelope({ + entries: [entry({ mediaPath: "/w/a.mp4" })], + metadata: { ...metadata, title: "Building with Pstack", description: "Claude Code tips" }, + workDir: "/w", + }), + transcriptStrategy: "captions", + }, + fakeIo( + {}, + { + readFile: async () => "", + detectAsr: asrDetected, + runAsr: async (/** @type {Record} */ asrOptions) => { + seenOptions = asrOptions; + return { success: true, cues: [{ startSec: 0, endSec: 2, text: "hello" }], words: [] }; + }, + }, + ), + ); + + expect(result.transcripts[0].strategy).toBe("asr"); + expect(seenOptions).toBeDefined(); + expect(seenOptions).not.toHaveProperty("initialPrompt"); + }); + + it("asr cues pass through repairCues and repairedTermCount counts the repairs", async () => { + /** @type {Record} */ + const files = {}; + const options = asrCandidateOptions(); + const result = await writeEnvelopeTranscriptArtifacts( + { + ...options, + envelope: createAcquisitionEnvelope({ + entries: [entry({ mediaPath: "/w/a.mp4" })], + metadata: { ...metadata, description: "Claude Code ships today" }, + workDir: "/w", + }), + }, + fakeIo(files, { + readFile: async () => "", + detectAsr: asrDetected, + runAsr: async () => ({ + success: true, + cues: [{ startSec: 0, endSec: 2, text: "so I opened clawed code today" }], + words: [], + }), + }), + ); + + expect(result.transcripts[0].strategy).toBe("asr"); + expect(result.transcripts[0].repairedTermCount).toBe(1); + const transcript = files[path.join(sliceDir, "source", "transcript.txt")]; + expect(transcript).toContain("Claude Code"); + expect(transcript).not.toContain("clawed code"); + }); + it("caption-absent + capability absent degrades explicitly in the named provenance field", async () => { const result = await writeEnvelopeTranscriptArtifacts( asrCandidateOptions(), diff --git a/plugins/knowledge/skills/video-digest/reference/sources/x.md b/plugins/knowledge/skills/video-digest/reference/sources/x.md index e1edac876f0..30a076d42d4 100644 --- a/plugins/knowledge/skills/video-digest/reference/sources/x.md +++ b/plugins/knowledge/skills/video-digest/reference/sources/x.md @@ -119,12 +119,12 @@ Declared strategy default: `captions+repair`. Selection resolves per entry: The media conjunct is required: the `transcript` action never downloads media, so the ASR rung cannot run there at all. A caption-absent `transcript` run always degrades. -`captions+repair` runs proper-noun repair over the platform VTT, using the post text -(`description`) plus harvested links as the lexicon. The ASR rung is faster-whisper large-v3 at -`batch_size=8`, an optional closed-by-default capability delivered as a documented prerequisite -plus runtime detection, **never auto-installed**. The lexicon is repair-only: feeding it to ASR -as an `initial_prompt` was probed and yielded no net proper-noun gain while worsening a -hallucination, so the rung runs without one. +`captions+repair` runs proper-noun repair over the platform VTT, using the title, the post text +(`description`) and harvested links as the lexicon; ASR cues get the same repair. The ASR rung is +faster-whisper large-v3 at `batch_size=8`, an optional closed-by-default capability delivered as a +documented prerequisite plus runtime detection, **never auto-installed**. The lexicon is +repair-only: feeding it to ASR as an `initial_prompt` was probed and yielded no net proper-noun gain +while worsening a hallucination, so the rung runs without one. ## Failure patterns