From 602bd46e7ce18b71d2b0793c06ef0cc520718679 Mon Sep 17 00:00:00 2001 From: "melodic-automation-lanes[bot]" <337595936+melodic-automation-lanes[bot]@users.noreply.github.com> Date: Sun, 18 Oct 2026 07:40:30 +0000 Subject: [PATCH 1/3] fix(knowledge): bias and repair video-digest ASR transcripts with the video's proper nouns Co-Authored-By: Claude Sonnet 5.5 --- ...ix-video-digest-asr-vocabulary-3d7a9c52.md | 7 +++ .../transcript/proper-noun-repair.js | 59 ++++++++--------- .../transcript/proper-noun-repair.test.js | 11 ++++ .../extraction/transcript/write-transcript.js | 46 ++++++++++---- .../transcript/write-transcript.test.js | 63 +++++++++++++++++++ 5 files changed, 146 insertions(+), 40 deletions(-) create mode 100644 .changes/knowledge/fix-video-digest-asr-vocabulary-3d7a9c52.md 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..cf15359b740 --- /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 vocabulary help captions do: the repair lexicon is built from the title, description and harvested links for every transcript strategy, passed to Whisper as the initial prompt, and the proper-noun 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..749ff6fc0d2 100644 --- a/plugins/knowledge/skills/video-digest/extraction/transcript/write-transcript.js +++ b/plugins/knowledge/skills/video-digest/extraction/transcript/write-transcript.js @@ -34,6 +34,28 @@ function countParagraphs(transcript) { return transcript ? transcript.split("\n\n").length : 0; } +/** + * Whisper keeps only the tail of a long initial prompt, so the terms go in + * lexicon order (title first) up to a character budget well inside its window. + */ +const INITIAL_PROMPT_MAX_CHARS = 800; + +/** + * @param {readonly string[]} lexicon + * @returns {string | null} the comma-joined leading terms, or null for an empty lexicon + */ +function buildInitialPrompt(lexicon) { + /** @type {string[]} */ + const kept = []; + let length = 0; + for (const term of lexicon) { + length += term.length + 2; + if (length > INITIAL_PROMPT_MAX_CHARS) break; + kept.push(term); + } + return kept.length > 0 ? kept.join(", ") : null; +} + const BOUNDARY_REPEAT_MIN_WORDS = 2; const BOUNDARY_REPEAT_MAX_WORDS = 12; const PARAGRAPH_STAMP = /^(\[[^\]]*\]\s*)([\s\S]*)$/; @@ -281,7 +303,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 +336,8 @@ 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, biased and 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 +394,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: captions+repair and ASR cues are repaired + // against it, and the ASR runner is biased with it. + const repairLexicon = buildRepairLexicon(metadata.description, harvestedLinks, metadata.title); + const initialPrompt = buildInitialPrompt(repairLexicon); /** @type {EnvelopeTranscriptEntry[]} */ const transcripts = []; @@ -409,6 +429,7 @@ export async function writeEnvelopeTranscriptArtifacts( const asr = await runAsr({ mediaPath: entry.mediaPath, python: /** @type {string} */ (asrDetection?.python), + initialPrompt, }); if (!asr.success || !asr.cues) { // An ASR failure degrades the entry explicitly rather than failing the @@ -419,13 +440,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..3646fce928d 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 passes the title and description proper nouns as initialPrompt", async () => { + /** @type {string | null | undefined} */ + let seenPrompt; + 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 {{initialPrompt?: string | null}} */ asrOptions) => { + seenPrompt = asrOptions.initialPrompt; + return { success: true, cues: [{ startSec: 0, endSec: 2, text: "hello" }], words: [] }; + }, + }, + ), + ); + + expect(result.transcripts[0].strategy).toBe("asr"); + expect(seenPrompt).toContain("Pstack"); + expect(seenPrompt).toContain("Claude Code"); + }); + + 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(), From f83017e8f7f99f7712476d8dc2ec81e61c6fc757 Mon Sep 17 00:00:00 2001 From: "melodic-automation-lanes[bot]" <337595936+melodic-automation-lanes[bot]@users.noreply.github.com> Date: Mon, 19 Oct 2026 02:30:35 +0000 Subject: [PATCH 2/3] fix(knowledge): keep video-digest ASR rung repair-only, no initial prompt Co-Authored-By: Claude Sonnet 5.5 --- .../extraction/transcript/write-transcript.js | 29 ++----------------- .../transcript/write-transcript.test.js | 14 ++++----- 2 files changed, 10 insertions(+), 33 deletions(-) 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 749ff6fc0d2..2f28da78266 100644 --- a/plugins/knowledge/skills/video-digest/extraction/transcript/write-transcript.js +++ b/plugins/knowledge/skills/video-digest/extraction/transcript/write-transcript.js @@ -34,28 +34,6 @@ function countParagraphs(transcript) { return transcript ? transcript.split("\n\n").length : 0; } -/** - * Whisper keeps only the tail of a long initial prompt, so the terms go in - * lexicon order (title first) up to a character budget well inside its window. - */ -const INITIAL_PROMPT_MAX_CHARS = 800; - -/** - * @param {readonly string[]} lexicon - * @returns {string | null} the comma-joined leading terms, or null for an empty lexicon - */ -function buildInitialPrompt(lexicon) { - /** @type {string[]} */ - const kept = []; - let length = 0; - for (const term of lexicon) { - length += term.length + 2; - if (length > INITIAL_PROMPT_MAX_CHARS) break; - kept.push(term); - } - return kept.length > 0 ? kept.join(", ") : null; -} - const BOUNDARY_REPEAT_MIN_WORDS = 2; const BOUNDARY_REPEAT_MAX_WORDS = 12; const PARAGRAPH_STAMP = /^(\[[^\]]*\]\s*)([\s\S]*)$/; @@ -394,10 +372,10 @@ export async function writeEnvelopeTranscriptArtifacts( requested === "asr" || entries.some((entry) => !entry.caption && entry.mediaPath); const asrDetection = needAsrProbe ? await detectAsr() : null; - // Every strategy gets the lexicon: captions+repair and ASR cues are repaired - // against it, and the ASR runner is biased with it. + // 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); - const initialPrompt = buildInitialPrompt(repairLexicon); /** @type {EnvelopeTranscriptEntry[]} */ const transcripts = []; @@ -429,7 +407,6 @@ export async function writeEnvelopeTranscriptArtifacts( const asr = await runAsr({ mediaPath: entry.mediaPath, python: /** @type {string} */ (asrDetection?.python), - initialPrompt, }); if (!asr.success || !asr.cues) { // An ASR failure degrades the entry explicitly rather than failing the 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 3646fce928d..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,9 +478,9 @@ so I opened clawed code today expect(files[path.join(sliceDir, "source", "transcript.txt")]).toContain("spoken words"); }); - it("the asr rung passes the title and description proper nouns as initialPrompt", async () => { - /** @type {string | null | undefined} */ - let seenPrompt; + 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( { @@ -497,8 +497,8 @@ so I opened clawed code today { readFile: async () => "", detectAsr: asrDetected, - runAsr: async (/** @type {{initialPrompt?: string | null}} */ asrOptions) => { - seenPrompt = asrOptions.initialPrompt; + runAsr: async (/** @type {Record} */ asrOptions) => { + seenOptions = asrOptions; return { success: true, cues: [{ startSec: 0, endSec: 2, text: "hello" }], words: [] }; }, }, @@ -506,8 +506,8 @@ so I opened clawed code today ); expect(result.transcripts[0].strategy).toBe("asr"); - expect(seenPrompt).toContain("Pstack"); - expect(seenPrompt).toContain("Claude Code"); + expect(seenOptions).toBeDefined(); + expect(seenOptions).not.toHaveProperty("initialPrompt"); }); it("asr cues pass through repairCues and repairedTermCount counts the repairs", async () => { From 2e6b4f87e384430d9a364e1149137498550ae3af Mon Sep 17 00:00:00 2001 From: Kyle Sexton <153232337+kyle-sexton@users.noreply.github.com> Date: Sun, 18 Oct 2026 22:43:06 -0400 Subject: [PATCH 3/3] docs(knowledge): describe video-digest ASR handling as repair only The owner decided this change repairs transcripts only, with no Whisper initial prompt. The changelog fragment, the writeEnvelopeTranscriptArtifacts docblock and the X source reference now say the lexicon (title, description, harvested links) repairs caption and ASR cues alike. Co-Authored-By: Claude Opus 5.5 --- .../fix-video-digest-asr-vocabulary-3d7a9c52.md | 2 +- .../extraction/transcript/write-transcript.js | 3 ++- .../skills/video-digest/reference/sources/x.md | 12 ++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.changes/knowledge/fix-video-digest-asr-vocabulary-3d7a9c52.md b/.changes/knowledge/fix-video-digest-asr-vocabulary-3d7a9c52.md index cf15359b740..bc5a3b72ea7 100644 --- a/.changes/knowledge/fix-video-digest-asr-vocabulary-3d7a9c52.md +++ b/.changes/knowledge/fix-video-digest-asr-vocabulary-3d7a9c52.md @@ -4,4 +4,4 @@ bump: patch ### Fixed -- `video-digest` ASR transcripts now get the same vocabulary help captions do: the repair lexicon is built from the title, description and harvested links for every transcript strategy, passed to Whisper as the initial prompt, and the proper-noun repair pass runs over ASR cues, so `repairedTermCount` counts their repairs. +- `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/write-transcript.js b/plugins/knowledge/skills/video-digest/extraction/transcript/write-transcript.js index 2f28da78266..51b5d2cd2d4 100644 --- a/plugins/knowledge/skills/video-digest/extraction/transcript/write-transcript.js +++ b/plugins/knowledge/skills/video-digest/extraction/transcript/write-transcript.js @@ -315,7 +315,8 @@ export function transcriptFilename(entryIndex, primaryEntryIndex) { * explicit pipeline override ({@link resolveTranscriptStrategy}): captions are * consumed as before, `captions+repair` layers proper-noun repair (lexicon = * title + post text + harvested links), and the `asr` rung runs the optional - * local toolchain, biased and repaired with the same lexicon — detected at runtime, never auto-installed. A degraded entry + * 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 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