-
Notifications
You must be signed in to change notification settings - Fork 0
feat(audio): the journalled serial transcription pipeline (4.8-4.11, 4.15, 4.17) #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { readSettings, type Language } from "../config/settings.js"; | ||
| import { projectVocabulary, DEFAULT_VOCABULARY_LIMIT } from "./vocabulary.js"; | ||
|
|
||
| /** | ||
| * What a transcription needs from the project, minus the credential (plan | ||
| * 4.10 and 4.15). | ||
| * | ||
| * **The credential is deliberately not here.** `config/secrets.ts` says it in | ||
| * as many words: the CLI, the hooks and the MCP process must not read the | ||
| * secret, because their stderr is consumed by an agent and travels to a model | ||
| * provider. Only the desktop application reads it, and it does so at the point | ||
| * it builds the provider. Everything *else* a transcription needs comes out of | ||
| * the project directory and is safe for anything to read — so it lives here, | ||
| * in one call, rather than being re-derived by each caller. | ||
| * | ||
| * The language reaches the provider as the hint | ||
| * (`adr:0008-content-language-is-a-setting-english-by-default`), rather than | ||
| * being left to detection. A provider guessing from the first thirty seconds | ||
| * of a Portuguese meeting that opened with English pleasantries gets it wrong | ||
| * for the whole chunk, and nothing downstream can tell. | ||
| */ | ||
| export interface TranscriptionInputs { | ||
| language: Language; | ||
| vocabulary: string[]; | ||
| } | ||
|
|
||
| export function transcriptionInputs( | ||
| projectRoot: string, | ||
| vocabularyLimit = DEFAULT_VOCABULARY_LIMIT, | ||
| ): TranscriptionInputs { | ||
| return { | ||
| language: readSettings(projectRoot).language, | ||
| vocabulary: projectVocabulary(projectRoot, vocabularyLimit), | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import { readWiki } from "../check/checks.js"; | ||
|
|
||
| /** | ||
| * The transcription vocabulary, seeded from the project's own pages (plan 4.10). | ||
| * | ||
| * **It is what stops the project's own name from coming out wrong.** A speech | ||
| * model has never heard "Fenix" and will write "Phoenix", every time, on every | ||
| * chunk — and the wiki that gets built from that transcript cites a project | ||
| * that does not exist. The names are already in the wiki: they are its page | ||
| * titles and the aliases each page lists. | ||
| * | ||
| * This reads pages and nothing else, so it lives here rather than in | ||
| * `@open-wiki/audio` — which would otherwise have to depend on this package to | ||
| * get at them, and this package already depends on that one for the time map. | ||
| */ | ||
|
|
||
| /** | ||
| * Whisper's prompt window holds only its last 224 tokens, so an unbounded list | ||
| * from a large wiki cannot all fit. This bounds how many names are *offered*; | ||
| * `vocabularyPrompt` in `@open-wiki/audio` bounds what is actually sent, in | ||
| * characters, and emits them so the best are the ones nearest the end — which | ||
| * is the end the window keeps. | ||
| */ | ||
| export const DEFAULT_VOCABULARY_LIMIT = 120; | ||
|
|
||
| /** | ||
| * No name is this long, and one that is came from a page in a project that | ||
| * arrived by clone. `vocabularyPrompt` clips to the same figure on its side; | ||
| * the number is repeated rather than imported because reaching into | ||
| * `@open-wiki/audio` for it would put a package that spawns subprocesses on | ||
| * this module's import graph. | ||
| */ | ||
| export const MAX_NAME_CHARS = 64; | ||
|
|
||
| /** Words a model already knows, and which crowd out the ones it does not. */ | ||
| const COMMON = new Set([ | ||
| "index", | ||
| "changelog", | ||
| "log", | ||
| "readme", | ||
| "notes", | ||
| "meeting", | ||
| "project", | ||
| "overview", | ||
| ]); | ||
|
|
||
| /** | ||
| * The names in a project's wiki, best first. | ||
| * | ||
| * "Best" is rarity: a title that is one unusual word is exactly what a model | ||
| * gets wrong, and a title that is a sentence is not a name at all. So single | ||
| * tokens that are not ordinary words come first, then the rest, and anything | ||
| * that reads as prose is dropped. | ||
| */ | ||
| export function projectVocabulary(projectRoot: string, limit = DEFAULT_VOCABULARY_LIMIT): string[] { | ||
| const names: string[] = []; | ||
| for (const page of readWiki(projectRoot)) { | ||
| const front = page.frontmatter; | ||
| if (!front) continue; | ||
| if (typeof front["title"] === "string") names.push(front["title"]); | ||
| const aliases = front["aliases"]; | ||
| if (Array.isArray(aliases)) { | ||
| for (const alias of aliases) if (typeof alias === "string") names.push(alias); | ||
| } | ||
| } | ||
| return rankNames(names, limit); | ||
| } | ||
|
|
||
| /** Deduplicate, drop what is not a name, and put the rare words first. */ | ||
| export function rankNames(names: readonly string[], limit = DEFAULT_VOCABULARY_LIMIT): string[] { | ||
| const seen = new Set<string>(); | ||
| const kept: string[] = []; | ||
| for (const raw of names) { | ||
| const name = raw.trim().replace(/\s+/g, " "); | ||
| if (!name) continue; | ||
| // Four words or more is a page title describing something, not a name a | ||
| // model needs help spelling — and it costs as much prompt as four names. | ||
| if (name.split(" ").length > 3) continue; | ||
| // A name longer than this is not a name. It came from a page in a project | ||
| // that arrived by clone, and it would otherwise become a megabyte of form | ||
| // field on the upload and a megabyte of argv on the local provider. | ||
| if (name.length > MAX_NAME_CHARS) continue; | ||
| if (COMMON.has(name.toLowerCase())) continue; | ||
| const key = name.toLowerCase(); | ||
| if (seen.has(key)) continue; | ||
| seen.add(key); | ||
| kept.push(name); | ||
| } | ||
| kept.sort((a, b) => wordCount(a) - wordCount(b) || a.localeCompare(b)); | ||
| return kept.slice(0, limit); | ||
| } | ||
|
|
||
| function wordCount(name: string): number { | ||
| return name.split(" ").length; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; | ||
| import { tmpdir } from "node:os"; | ||
| import { join } from "node:path"; | ||
| import { afterEach, beforeEach, describe, expect, it } from "vitest"; | ||
| import { projectVocabulary, rankNames } from "../src/sources/vocabulary.js"; | ||
| import { transcriptionInputs } from "../src/sources/transcription.js"; | ||
|
|
||
| let root: string; | ||
|
|
||
| beforeEach(() => { | ||
| root = mkdtempSync(join(tmpdir(), "ow-vocab-")); | ||
| mkdirSync(join(root, "wiki"), { recursive: true }); | ||
| }); | ||
|
|
||
| afterEach(() => rmSync(root, { recursive: true, force: true })); | ||
|
|
||
| function page(slug: string, front: Record<string, unknown>): void { | ||
| const yaml = Object.entries(front) | ||
| .map(([k, v]) => `${k}: ${JSON.stringify(v)}`) | ||
| .join("\n"); | ||
| writeFileSync(join(root, "wiki", `${slug}.md`), `---\n${yaml}\n---\n\nbody\n`, "utf8"); | ||
| } | ||
|
|
||
| describe("projectVocabulary (4.10)", () => { | ||
| it("collects the titles already in the wiki", () => { | ||
| // The names are the whole point: a speech model has never heard "Fenix" | ||
| // and writes "Phoenix", every time, on every chunk. | ||
| page("fenix", { title: "Fenix", aliases: [] }); | ||
| page("mateus", { title: "Mateus Andrade", aliases: [] }); | ||
| expect(projectVocabulary(root)).toContain("Fenix"); | ||
| expect(projectVocabulary(root)).toContain("Mateus Andrade"); | ||
| }); | ||
|
|
||
| it("collects the aliases each page lists, which is where the variants live", () => { | ||
| page("fenix", { title: "Fenix", aliases: ["Projeto Fenix", "FNX"] }); | ||
| const vocabulary = projectVocabulary(root); | ||
| expect(vocabulary).toContain("Projeto Fenix"); | ||
| expect(vocabulary).toContain("FNX"); | ||
| }); | ||
|
|
||
| it("is empty for a project with no pages yet", () => { | ||
| expect(projectVocabulary(root)).toEqual([]); | ||
| }); | ||
|
|
||
| it("skips a page whose frontmatter will not parse", () => { | ||
| writeFileSync(join(root, "wiki", "broken.md"), "no frontmatter here\n", "utf8"); | ||
| page("fenix", { title: "Fenix", aliases: [] }); | ||
| expect(projectVocabulary(root)).toEqual(["Fenix"]); | ||
| }); | ||
|
|
||
| it("bounds the list, because the prompt window holds only so much", () => { | ||
| for (let i = 0; i < 50; i++) page(`p${i}`, { title: `Name${i}`, aliases: [] }); | ||
| expect(projectVocabulary(root, 10)).toHaveLength(10); | ||
| }); | ||
| }); | ||
|
|
||
| describe("transcriptionInputs (4.15)", () => { | ||
| it("takes the language from the project's settings, not from detection", () => { | ||
| writeFileSync( | ||
| join(root, "ow.json"), | ||
| JSON.stringify({ language: "pt-BR", deleteWavAfterTranscription: true }), | ||
| "utf8", | ||
| ); | ||
| expect(transcriptionInputs(root).language).toBe("pt-BR"); | ||
| }); | ||
|
|
||
| it("defaults to English, which is what an unconfigured project produces", () => { | ||
| expect(transcriptionInputs(root).language).toBe("en"); | ||
| }); | ||
|
|
||
| it("carries the project's names alongside it", () => { | ||
| page("fenix", { title: "Fenix", aliases: [] }); | ||
| expect(transcriptionInputs(root).vocabulary).toEqual(["Fenix"]); | ||
| }); | ||
|
|
||
| it("carries no credential — the CLI and the hooks must never read one", () => { | ||
| // `config/secrets.ts`: their stderr is consumed by an agent and travels to | ||
| // a model provider. Only the desktop application reads the key. | ||
| expect(Object.keys(transcriptionInputs(root))).toEqual(["language", "vocabulary"]); | ||
| }); | ||
| }); | ||
|
|
||
| describe("rankNames", () => { | ||
| it("removes duplicates however they were cased", () => { | ||
| expect(rankNames(["Fenix", "fenix", "FENIX"])).toEqual(["Fenix"]); | ||
| }); | ||
|
|
||
| it("puts the single unusual words first, which are what a model gets wrong", () => { | ||
| expect(rankNames(["Mateus Andrade", "Fenix"])).toEqual(["Fenix", "Mateus Andrade"]); | ||
| }); | ||
|
|
||
| it("drops a title that is a sentence rather than a name", () => { | ||
| // Four words is a page describing something. It costs as much prompt as | ||
| // four names and helps with none of them. | ||
| expect(rankNames(["How the dispatcher routes requests"])).toEqual([]); | ||
| }); | ||
|
|
||
| it("drops words a model already knows", () => { | ||
| expect(rankNames(["index", "Changelog", "Fenix"])).toEqual(["Fenix"]); | ||
| }); | ||
|
|
||
| it("collapses the whitespace inside a name", () => { | ||
| expect(rankNames([" Mateus Andrade "])).toEqual(["Mateus Andrade"]); | ||
| }); | ||
|
|
||
| it("drops an empty name", () => { | ||
| expect(rankNames(["", " "])).toEqual([]); | ||
| }); | ||
|
|
||
| it("is stable, so two runs seed the same prompt", () => { | ||
| const names = ["Zeta", "Alpha", "Beta Gamma"]; | ||
| expect(rankNames(names)).toEqual(rankNames([...names].reverse())); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Prefer the terminal journal error.
When
journal.errorand a chunk error both exist,failedselects the first chunk error at line 88. The terminalfailedstate then hides the journal-level stop reason. Givejournal.errorprecedence and add a regression case with both error types.Proposed fix
🤖 Prompt for AI Agents