diff --git a/AGENTS.md b/AGENTS.md index 6386769a..f4024869 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -63,7 +63,7 @@ svelte-check's native API path passes when a tsconfig matches no files, which `check:a11y` in temporary workspaces and requires it to fail on that case and when the native compiler cannot start. -After `npm run build`, `npm run size` enforces 334,105 raw bytes and 109,240 gzip bytes at level 9 for root `main.js` in the Test workflow's Build and sizes worker. `npm run size:data` reports a synthetic v2 stress library with 50 feeds, 2,000 history entries, and 200 saved episodes from frozen NPR metadata, including duplicated snapshots. Its 1.5 MB document goal is advisory. Pass an additive candidate JSON path to report optional-field overhead without changing existing data. In the isolated Obsidian instance, `npm run count:writes -- start`, `report`, and `stop` record writes to PodNotes' exact `data.json` path. Stop the recorder before stopping the instance, because recorder commands start a stopped instance; plugin reloads invalidate its counts. +After `npm run build`, `npm run size` enforces 334,165 raw bytes and 109,270 gzip bytes at level 9 for root `main.js` in the Test workflow's Build and sizes worker. `npm run size:data` reports a synthetic v2 stress library with 50 feeds, 2,000 history entries, and 200 saved episodes from frozen NPR metadata, including duplicated snapshots. Its 1.5 MB document goal is advisory. Pass an additive candidate JSON path to report optional-field overhead without changing existing data. In the isolated Obsidian instance, `npm run count:writes -- start`, `report`, and `stop` record writes to PodNotes' exact `data.json` path. Stop the recorder before stopping the instance, because recorder commands start a stopped instance; plugin reloads invalidate its counts. Before opening a PR or cutting a release, run the CI-equivalent checks locally: diff --git a/scripts/size-baseline.md b/scripts/size-baseline.md index 72a47c69..4d5f5f08 100644 --- a/scripts/size-baseline.md +++ b/scripts/size-baseline.md @@ -12,7 +12,7 @@ main.js raw: 307131 bytes; budget 330000 bytes; 22869 bytes remaining main.js gzip (level 9): 97161 bytes; budget 100000 bytes; 2839 bytes remaining ``` -The gzip budget is now 109,240 bytes, and the raw budget 334,105. On 2026-10-14 it rose from 100,000 for +The gzip budget is now 109,270 bytes, and the raw budget 334,165. On 2026-10-14 it rose from 100,000 for the full player's Transcript panel, which the owner approved at about 1.9 KB and which measured 2,576 bytes. The coordinator set 103,000 to keep the panel's Find and Follow chip and to leave room for fixes in flight. The @@ -109,6 +109,15 @@ main.js raw: 334105 bytes; budget 334105 bytes; 0 bytes remaining main.js gzip (level 9): 109240 bytes; budget 109240 bytes; 0 bytes remaining ``` +On 2026-11-21 both rose for "Transcribe current episode from audio" offline with +the user's own server, as the Transcript panel's button already ran: from 334,105 +raw by 60 bytes, and from 109,240 gzip by 30 bytes. With it: + +```text +main.js raw: 334165 bytes; budget 334165 bytes; 0 bytes remaining +main.js gzip (level 9): 109270 bytes; budget 109270 bytes; 0 bytes remaining +``` + Gzip uses Node's `gzipSync` at level 9, without a filename or timestamp. Budgets use decimal bytes. The brief's 96,533-byte reference is unexplained. This report fixes the compressor instead of comparing compressed sizes across diff --git a/scripts/size.mjs b/scripts/size.mjs index a10767a2..16dd0de1 100644 --- a/scripts/size.mjs +++ b/scripts/size.mjs @@ -9,8 +9,8 @@ try { const bundle = readFileSync(path); if (!bundle.length) throw new Error(`${path} is empty. Run npm run build first.`); const measurements = [ - { name: "raw", bytes: bundle.length, budget: 334_105 }, - { name: "gzip (level 9)", bytes: gzipSync(bundle, { level: 9 }).length, budget: 109_240 }, + { name: "raw", bytes: bundle.length, budget: 334_165 }, + { name: "gzip (level 9)", bytes: gzipSync(bundle, { level: 9 }).length, budget: 109_270 }, ]; const rows = measurements.map(({ name, bytes, budget }) => { const overage = Math.max(0, bytes - budget); diff --git a/scripts/size.test.ts b/scripts/size.test.ts index d725e70a..59597235 100644 --- a/scripts/size.test.ts +++ b/scripts/size.test.ts @@ -20,19 +20,19 @@ function check(name: string, contents: string | Buffer) { describe("bundle budget CLI", () => { it("allows the raw budget boundary and rejects one extra byte", () => { - expect(check("boundary.js", "a".repeat(334_105)).status).toBe(0); - const result = check("over.js", "a".repeat(334_106)); + expect(check("boundary.js", "a".repeat(334_165)).status).toBe(0); + const result = check("over.js", "a".repeat(334_166)); expect(result.status).toBe(1); - expect(result.stdout).toContain("budget 334105 bytes; OVER by 1 bytes"); + expect(result.stdout).toContain("budget 334165 bytes; OVER by 1 bytes"); }); it("rejects gzip growth even when raw bytes fit", () => { const result = check("gzip.js", randomBytes(110_000)); expect(result.status).toBe(1); expect(result.stdout).toMatch( - /gzip \(level 9\): \d+ bytes; budget 109240 bytes; OVER by \d+ bytes/, + /gzip \(level 9\): \d+ bytes; budget 109270 bytes; OVER by \d+ bytes/, ); - expect(result.stdout).toContain("budget 334105 bytes; 224105 bytes remaining"); + expect(result.stdout).toContain("budget 334165 bytes; 224165 bytes remaining"); }); it("fails on absent or empty artifacts instead of reporting a small build", () => { diff --git a/src/commands.test.ts b/src/commands.test.ts index 71bd29c9..98e065e6 100644 --- a/src/commands.test.ts +++ b/src/commands.test.ts @@ -1206,18 +1206,50 @@ describe("Reorder Queue", () => { }); describe("Transcribe", () => { + /** Loads the plugin online, and returns a check and a run for each command id. */ + async function transcribeCommands(data: Record) { + const online = vi.spyOn(navigator, "onLine", "get").mockReturnValue(true); + const { commands } = await loadPlugin(data); + const command = (id: string) => commands.find((each) => each.id === id)!; + return { + available: (id: string) => command(id).checkCallback!(true), + run: (id: string) => command(id).checkCallback!(false), + goOffline: () => { + online.mockReturnValue(false); + window.dispatchEvent(new Event("offline")); + }, + }; + } + it.each(["podnotes-transcribe", "podnotes-transcribe-audio"])( - "%s is available for an audio episode only while online", + "%s is available for an audio episode only while online with a hosted provider", async (id) => { - const online = vi.spyOn(navigator, "onLine", "get").mockReturnValue(true); - const { commands } = await loadPlugin(playing); - const available = () => - commands.find((command) => command.id === id)!.checkCallback!(true); - - expect(available()).toBe(true); - online.mockReturnValue(false); - window.dispatchEvent(new Event("offline")); - expect(available()).toBe(false); + const { available, goOffline } = await transcribeCommands(playing); + + expect(available(id)).toBe(true); + goOffline(); + expect(available(id)).toBe(false); }, ); + + it("runs from audio offline with the user's own server, as the Transcript panel does", async () => { + // No model yet, so the run stops at its Notice before any request. + const { available, run, goOffline } = await transcribeCommands({ + ...playing, + transcript: { + provider: "openai-compatible", + serverUrl: "http://192.168.1.20:8000/v1", + model: "", + }, + }); + goOffline(); + + // The plain command looks for the feed's published transcript first, which needs the network. + expect(available("podnotes-transcribe")).toBe(false); + expect(available("podnotes-transcribe-audio")).toBe(true); + run("podnotes-transcribe-audio"); + expect(said()).toEqual([ + "Enter a model for your OpenAI-compatible server in the transcript settings.", + ]); + }); }); diff --git a/src/commands.ts b/src/commands.ts index 5af55b07..d4eab554 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -8,6 +8,7 @@ import downloadEpisodeWithNotice from "src/downloadEpisode"; import getUniversalPodcastLink from "src/getUniversalPodcastLink"; import { getEpisodeMediaType } from "src/utility/mediaType"; import { TRANSCRIBE_FROM_AUDIO_COMMAND } from "src/services/TranscriptionService"; +import { transcriptionChoice } from "src/services/transcription"; import { notifyPrivateFeedUnavailable } from "src/services/privateFeeds"; import type PodNotes from "src/main"; @@ -280,10 +281,14 @@ export function registerCommands(plugin: PodNotes): void { }, }); - const canTranscribe = () => - get(plugin.online) && - !!plugin.api.podcast && - getEpisodeMediaType(plugin.api.podcast) === "audio"; + const playingAudio = () => + !!plugin.api.podcast && getEpisodeMediaType(plugin.api.podcast) === "audio"; + // The published transcript comes from the feed, so this command needs the network. + const canTranscribe = () => get(plugin.online) && playingAudio(); + // The user's own server can run on this computer, so offline it stays available, as the + // Transcript panel's button does. + const canTranscribeAudio = () => + (get(plugin.online) || !!transcriptionChoice(plugin.settings).server) && playingAudio(); plugin.addCommand({ id: "podnotes-transcribe", @@ -304,10 +309,10 @@ export function registerCommands(plugin: PodNotes): void { name: TRANSCRIBE_FROM_AUDIO_COMMAND, checkCallback: (checking) => { if (checking) { - return canTranscribe(); + return canTranscribeAudio(); } - if (canTranscribe()) { + if (canTranscribeAudio()) { plugin.getTranscriptionService().transcribeCurrentEpisodeFromAudio(); } },