Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
fix(stt): stop truncating custom dictionary prompts on models without Groq's limit (#1632)
Joshua895e33f88622
diff --git a/src/components/DictionaryView.tsx b/src/components/DictionaryView.tsxindex abd54b8a5..e369872e9 100644--- a/src/components/DictionaryView.tsx+++ b/src/components/DictionaryView.tsx@@ -20,10 +20,12 @@ import SnippetsView from "./SnippetsView";import { useSettings } from "../hooks/useSettings";import { getAgentName } from "../utils/agentName";import { parseDictionaryImportText } from "../helpers/dictionaryImport";+import { getDictionaryHintWords } from "../utils/snippets";+import { WHISPER_DECODER_PROMPT_CHARS } from "../utils/dictionaryPromptCap";export default function DictionaryView() {const { t } = useTranslation();- const { customDictionary, updateCustomDictionary } = useSettings();+ const { customDictionary, updateCustomDictionary, snippets } = useSettings();const agentName = getAgentName();const { toast } = useToast();@@ -37,6 +39,14 @@ export default function DictionaryView() {const pendingImportCount = useMemo(() => parseDictionaryImportText(bulkText).length, [bulkText]);+ // Length of the prompt string the STT request builds (words + snippet+ // triggers, comma-joined), so the warning fires on real request size. A+ // Chinese script bias adds ~21 chars on top for zh-CN / zh-TW users.+ const promptChars = useMemo(+ () => getDictionaryHintWords({ customDictionary, snippets }).join(", ").length,+ [customDictionary, snippets]+ );+// Same membership rule as agentNameDictionaryChanges: a stored spelling that// differs only by case is still the agent name's entry, so keep it hidden.const userWords = useMemo(() => {@@ -328,6 +338,13 @@ export default function DictionaryView() {</ul>)}</div>++ {/* ─── Provider prompt-limit notice ─── */}+ {promptChars > WHISPER_DECODER_PROMPT_CHARS && (+ <p className="text-xs text-foreground/30 leading-relaxed">+ {t("dictionary.promptLimitNotice", { chars: promptChars })}+ </p>+ )}</div></TabsContent>diff --git a/src/helpers/audioManager.js b/src/helpers/audioManager.jsindex 9685d9aff..ac4feaf16 100644--- a/src/helpers/audioManager.js+++ b/src/helpers/audioManager.js@@ -102,6 +102,7 @@ import {matchesDictionaryPrompt,payloadSendsDictionaryBias,} from "../utils/dictionaryEchoFilter.js";+import { dictionaryPromptLimit, trimDictionaryPrompt } from "../utils/dictionaryPromptCap.js";import { getDictionaryHintWords } from "../utils/snippets";import { normalizeAgentSelectionContext } from "../utils/agentSelectionContext";import { shouldDisplayDictationPreview } from "../utils/transcriptionPreview";@@ -3501,21 +3502,23 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);const endpoint = this.getTranscriptionEndpoint(model);- // Groq rejects prompts > 896 chars (incl. when reached via "custom" provider).- // 890 leaves margin for UTF-16 vs codepoint counting drift.- const isGroqEndpoint = provider === "groq" || endpoint.includes("api.groq.com");- const MAX_PROMPT_CHARS = isGroqEndpoint ? 890 : 900;- let dictionaryPrompt = this.getWhisperPrompt(apiSettings);+ // Prompt budgets follow each provider's real limit (see dictionaryPromptCap):+ // Groq's 896-char request cap, the Whisper decoders' window, and a far+ // larger context guard for the 4o transcribe models, which are LLMs and+ // read the whole thing. The cut is a request bound, not a priority rule:+ // Whisper decoders read the tail of whatever they are given.+ const MAX_PROMPT_CHARS = dictionaryPromptLimit({ provider, endpoint, model });+ const trimmedPrompt = trimDictionaryPrompt(+ this.getWhisperPrompt(apiSettings),+ MAX_PROMPT_CHARS+ );+ const dictionaryPrompt = trimmedPrompt.prompt;if (dictionaryPrompt) {- if (dictionaryPrompt.length > MAX_PROMPT_CHARS) {- const originalLength = dictionaryPrompt.length;- const truncated = dictionaryPrompt.slice(0, MAX_PROMPT_CHARS);- const lastComma = truncated.lastIndexOf(",");- dictionaryPrompt = lastComma > 0 ? truncated.slice(0, lastComma) : truncated;+ if (trimmedPrompt.truncated) {logger.debug("Custom dictionary prompt truncated",{- originalLength,+ originalLength: trimmedPrompt.originalLength,truncatedLength: dictionaryPrompt.length,maxChars: MAX_PROMPT_CHARS,},diff --git a/src/locales/de/translation.json b/src/locales/de/translation.jsonindex 41d54a6a6..20159ab6b 100644--- a/src/locales/de/translation.json+++ b/src/locales/de/translation.json@@ -3431,6 +3431,7 @@"wordsReady_other": "{{count}} Wörter bereit","import": "Importieren","yourDictionary": "Dein Wörterbuch",+ "promptLimitNotice": "Dein Wörterbuch umfasst {{chars}} Zeichen. Groq- und Whisper-Modelle lesen davon nur die letzten paar hundert Zeichen – eine kürzere Liste funktioniert dort besser. Andere Modelle erhalten die vollständige Liste.","exportDictionary": "Wörterbuch exportieren","exportFailed": "Export fehlgeschlagen","editWord": "{{word}} bearbeiten",diff --git a/src/locales/en/translation.json b/src/locales/en/translation.jsonindex 34b2bde89..2b5cbf11f 100644--- a/src/locales/en/translation.json+++ b/src/locales/en/translation.json@@ -3431,6 +3431,7 @@"wordsReady_other": "{{count}} words ready","import": "Import","yourDictionary": "Your dictionary",+ "promptLimitNotice": "Your dictionary is {{chars}} characters. Groq and Whisper models read only the last few hundred characters of it, so a shorter list works better there. Other models get the full list.","exportDictionary": "Export dictionary","exportFailed": "Export failed","editWord": "Edit {{word}}",diff --git a/src/locales/es/translation.json b/src/locales/es/translation.jsonindex e912da894..4a62971bf 100644--- a/src/locales/es/translation.json+++ b/src/locales/es/translation.json@@ -3228,6 +3228,7 @@"wordsReady_other": "{{count}} palabras listas","import": "Importar","yourDictionary": "Tu diccionario",+ "promptLimitNotice": "Tu diccionario tiene {{chars}} caracteres. Los modelos de Groq y Whisper solo leen los últimos cientos de caracteres, así que allí funciona mejor una lista más corta. Los demás modelos reciben la lista completa.","exportDictionary": "Exportar diccionario","exportFailed": "Error al exportar","editWord": "Editar {{word}}",diff --git a/src/locales/fr/translation.json b/src/locales/fr/translation.jsonindex 325d7f69f..b920cb89c 100644--- a/src/locales/fr/translation.json+++ b/src/locales/fr/translation.json@@ -3431,6 +3431,7 @@"wordsReady_other": "{{count}} mots prêts","import": "Importer","yourDictionary": "Votre dictionnaire",+ "promptLimitNotice": "Votre dictionnaire compte {{chars}} caractères. Les modèles Groq et Whisper n'en lisent que les dernières centaines de caractères : une liste plus courte y fonctionne mieux. Les autres modèles reçoivent la liste complète.","exportDictionary": "Exporter le dictionnaire","exportFailed": "Échec de l'exportation","editWord": "Modifier {{word}}",diff --git a/src/locales/it/translation.json b/src/locales/it/translation.jsonindex 1ef3aa308..4e2a61b1a 100644--- a/src/locales/it/translation.json+++ b/src/locales/it/translation.json@@ -3180,6 +3180,7 @@"wordsReady_other": "{{count}} parole pronte","import": "Importa","yourDictionary": "Il tuo dizionario",+ "promptLimitNotice": "Il tuo dizionario contiene {{chars}} caratteri. I modelli Groq e Whisper ne leggono solo le ultime centinaia di caratteri, quindi lì conviene un elenco più corto. Gli altri modelli ricevono l'elenco completo.","exportDictionary": "Esporta dizionario","exportFailed": "Esportazione non riuscita","editWord": "Modifica {{word}}",diff --git a/src/locales/ja/translation.json b/src/locales/ja/translation.jsonindex 349f13b6a..f7156f8ca 100644--- a/src/locales/ja/translation.json+++ b/src/locales/ja/translation.json@@ -3107,6 +3107,7 @@"wordsReady_other": "{{count}} 個の単語が準備完了","import": "インポート","yourDictionary": "あなたの辞書",+ "promptLimitNotice": "辞書は現在{{chars}}文字です。GroqとWhisperのモデルはその末尾の数百文字しか読み取らないため、リストは短いほうが効果的です。その他のモデルには全リストが送信されます。","exportDictionary": "辞書をエクスポート","exportFailed": "エクスポートに失敗しました","editWord": "{{word}} を編集",diff --git a/src/locales/pt/translation.json b/src/locales/pt/translation.jsonindex c7130642e..d6574aa56 100644--- a/src/locales/pt/translation.json+++ b/src/locales/pt/translation.json@@ -3180,6 +3180,7 @@"wordsReady_other": "{{count}} palavras prontas","import": "Importar","yourDictionary": "Seu dicionário",+ "promptLimitNotice": "Seu dicionário tem {{chars}} caracteres. Os modelos Groq e Whisper leem apenas as últimas centenas de caracteres, portanto uma lista mais curta funciona melhor ali. Os demais modelos recebem a lista completa.","exportDictionary": "Exportar dicionário","exportFailed": "Falha ao exportar","editWord": "Editar {{word}}",diff --git a/src/locales/ru/translation.json b/src/locales/ru/translation.jsonindex 9326320c8..bb2f1baae 100644--- a/src/locales/ru/translation.json+++ b/src/locales/ru/translation.json@@ -3208,6 +3208,7 @@"wordsReady_other": "{{count}} слова готово","import": "Импортировать","yourDictionary": "Ваш словарь",+ "promptLimitNotice": "В вашем словаре {{chars}} символов. Модели Groq и Whisper читают только последние несколько сотен символов, поэтому там лучше работает более короткий список. Остальные модели получают список целиком.","exportDictionary": "Экспортировать словарь","exportFailed": "Не удалось экспортировать","editWord": "Изменить {{word}}",diff --git a/src/locales/zh-CN/translation.json b/src/locales/zh-CN/translation.jsonindex 32cd4bddf..83ade7134 100644--- a/src/locales/zh-CN/translation.json+++ b/src/locales/zh-CN/translation.json@@ -3179,6 +3179,7 @@"wordsReady_other": "{{count}} 个词语就绪","import": "导入","yourDictionary": "你的词典",+ "promptLimitNotice": "词典当前共 {{chars}} 个字符。Groq 和 Whisper 模型只会读取其中最后几百个字符,因此列表越短效果越好;其他模型会收到完整列表。","exportDictionary": "导出词典","exportFailed": "导出失败","editWord": "编辑 {{word}}",diff --git a/src/locales/zh-TW/translation.json b/src/locales/zh-TW/translation.jsonindex 9b0354ace..2afe742d6 100644--- a/src/locales/zh-TW/translation.json+++ b/src/locales/zh-TW/translation.json@@ -3179,6 +3179,7 @@"wordsReady_other": "{{count}} 個詞語就緒","import": "匯入","yourDictionary": "你的詞典",+ "promptLimitNotice": "字典目前共 {{chars}} 個字元。Groq 與 Whisper 模型只會讀取其中最後幾百個字元,因此清單越短效果越好;其他模型會收到完整清單。","exportDictionary": "匯出詞典","exportFailed": "匯出失敗","editWord": "編輯 {{word}}",diff --git a/src/utils/dictionaryPromptCap.js b/src/utils/dictionaryPromptCap.jsnew file mode 100644index 000000000..564df1de0--- /dev/null+++ b/src/utils/dictionaryPromptCap.js@@ -0,0 +1,56 @@+// Per-provider budgets for the custom-dictionary STT prompt on the direct-API+// path, plus the decoder window the dictionary UI warns against. One place, so+// the request bound and the warning cannot drift apart.++// Groq rejects prompts > 896 chars (incl. when reached via a custom endpoint);+// 890 leaves margin for UTF-16 vs codepoint counting drift.+export const GROQ_PROMPT_CHARS = 890;++// Whisper-family decoders (whisper-1, Groq's whisper-large-v3, whisper.cpp) read+// at most 223 prompt tokens and keep the TAIL of anything longer, silently. 900+// chars is the historical client-side cut for them: it is well above what the+// decoder reads, so it only bounds the request, never which words survive.+export const WHISPER_PROMPT_CHARS = 900;++// What the decoder's 223-token window is actually worth in characters. A+// comma-separated list of names and technical terms tokenizes at ~2.3-2.9+// chars/token (measured against Whisper's own BPE) — far denser than the ~4+// chars/token rule of thumb for prose, because every ", " costs a token and+// rare proper nouns fragment. Used to warn in the UI, not to trim: the true+// budget is tokens, and no character count is right for every language.+export const WHISPER_DECODER_PROMPT_CHARS = 550;++// gpt-4o-transcribe / gpt-4o-mini-transcribe are LLMs, not Whisper decoders: no+// 223-token prompt window, and verified live to 40k chars. The only hard limit+// is the 16k-token context shared with the audio, so this is a guard against an+// absurd list crowding out a long dictation, not a limit anyone should hit.+export const TRANSCRIBE_PROMPT_CHARS = 8000;++// Only the 4o transcribe family is known to read past a Whisper decoder's+// prompt window, so it alone earns the generous budget. Everything else falls+// back to the Whisper budget on purpose: custom and self-hosted endpoints take+// whatever model name the user typed, and most of those servers are+// Whisper-family under a name that never says "whisper".+export function dictionaryPromptLimit({ provider = "", endpoint = "", model = "" } = {}) {+ if (provider === "groq" || endpoint.includes("api.groq.com")) return GROQ_PROMPT_CHARS;+ if (model.toLowerCase().startsWith("gpt-4o")) return TRANSCRIBE_PROMPT_CHARS;+ return WHISPER_PROMPT_CHARS;+}++// Cuts at the last comma inside the budget so no entry is sent half-spelled.+// Returns the (possibly shorter) prompt plus what changed, for logging.+// Callers must classify dictionary echoes against the returned prompt, not the+// original: the echo filter needs 70% of the prompt's words back, which a full+// echo of a trimmed prompt only clears when measured against the same string.+export function trimDictionaryPrompt(prompt, maxChars) {+ if (!prompt || prompt.length <= maxChars) {+ return { prompt, originalLength: prompt ? prompt.length : 0, truncated: false };+ }+ const head = prompt.slice(0, maxChars);+ const lastComma = head.lastIndexOf(",");+ return {+ prompt: lastComma > 0 ? head.slice(0, lastComma) : head,+ originalLength: prompt.length,+ truncated: true,+ };+}diff --git a/test/helpers/audioManagerDictionaryPromptCap.test.js b/test/helpers/audioManagerDictionaryPromptCap.test.jsnew file mode 100644index 000000000..cc5790a4e--- /dev/null+++ b/test/helpers/audioManagerDictionaryPromptCap.test.js@@ -0,0 +1,208 @@+const test = require("node:test");+const assert = require("node:assert/strict");+const { loadAudioManager: loadSharedAudioManager } = require("./harness/audioManager");++// Every case drives a prototype-only manager through the shared renderer+// harness; only the model, endpoint and dictionary prompt differ per case.+async function loadAudioManager(t, opts) {+ const loaded = await loadSharedAudioManager(t, opts);+ return {+ ...loaded,+ createManager: (overrides = {}) =>+ loaded.createManager({+ getEffectiveSttLanguage: () => "auto",+ getTranscriptionModel: () => "whisper-1",+ getAPIKey: async () => "test-key",+ getWhisperPrompt: () => null,+ getKeyterms: () => [],+ shouldStreamTranscription: () => false,+ isDictionaryEcho: () => false,+ processTranscription: async (text) => text,+ isReasoningAvailable: async () => false,+ ...overrides,+ }),+ };+}++// Captures the prompt field each transcription request actually sent.+function capturePrompts(t) {+ const originalFetch = globalThis.fetch;+ const prompts = [];+ globalThis.fetch = async (endpoint, init) => {+ prompts.push(init.body.get("prompt"));+ return {+ ok: true,+ status: 200,+ headers: { get: () => "application/json" },+ text: async () => JSON.stringify({ text: "transcribed text" }),+ };+ };+ t.after(() => {+ globalThis.fetch = originalFetch;+ });+ return prompts;+}++// A ~100-term custom dictionary joined the way getCustomDictionaryPrompt does,+// mirroring the 1633-char report in #CUS-49 (1633 -> 899 at maxChars 900).+function buildLongDictionaryPrompt(count = 100) {+ const words = [];+ for (let i = 0; i < count; i++) {+ words.push(`SpecializedTerm${String(i).padStart(3, "0")}`);+ }+ return words.join(", ");+}++test("custom dictionary prompt caps follow the provider's real limit", async (t) => {+ const { setSettings, createManager } = await loadAudioManager(t, {+ cachePrefix: "openwhispr-dictionary-prompt-cap-test-",+ settingsKey: "__dictionaryPromptCapSettings",+ });++ const audioBlob = new Blob([new ArrayBuffer(8)], { type: "audio/webm" });+ const longPrompt = buildLongDictionaryPrompt();+ assert.ok(longPrompt.length > 1600, "fixture must exceed the historical 900-char cap");++ await t.test("gpt-4o-mini-transcribe sends the dictionary whole", async () => {+ setSettings({+ useLocalWhisper: false,+ allowLocalFallback: false,+ cloudTranscriptionProvider: "openai",+ });+ const prompts = capturePrompts(t);+ const manager = createManager({+ getTranscriptionModel: () => "gpt-4o-mini-transcribe",+ getTranscriptionEndpoint: () => "https://api.openai.com/v1/audio/transcriptions",+ getWhisperPrompt: () => longPrompt,+ });++ const result = await manager.processWithOpenAIAPI(audioBlob, {});+ assert.equal(result.success, true);+ assert.equal(prompts.length, 1);+ assert.equal(+ prompts[0],+ longPrompt,+ "16k-context transcribe models must not lose dictionary words to the Groq-era cap"+ );+ });++ await t.test("groq stays under its documented 896-char limit", async () => {+ setSettings({+ useLocalWhisper: false,+ allowLocalFallback: false,+ cloudTranscriptionProvider: "groq",+ });+ const prompts = capturePrompts(t);+ const manager = createManager({+ getTranscriptionModel: () => "whisper-large-v3-turbo",+ getTranscriptionEndpoint: () => "https://api.groq.com/openai/v1/audio/transcriptions",+ getWhisperPrompt: () => longPrompt,+ });++ await manager.processWithOpenAIAPI(audioBlob, {});+ assert.equal(prompts.length, 1);+ assert.ok(prompts[0].length <= 890, `groq prompt must stay capped, got ${prompts[0].length}`);+ assert.ok(longPrompt.startsWith(prompts[0]), "truncation must keep the head of the list");+ assert.equal(+ longPrompt[prompts[0].length],+ ",",+ "truncation must end on a whole dictionary entry"+ );+ });++ await t.test("whisper-1 keeps the ~224-token (900-char) cap", async () => {+ setSettings({+ useLocalWhisper: false,+ allowLocalFallback: false,+ cloudTranscriptionProvider: "openai",+ });+ const prompts = capturePrompts(t);+ const manager = createManager({+ getTranscriptionModel: () => "whisper-1",+ getTranscriptionEndpoint: () => "https://api.openai.com/v1/audio/transcriptions",+ getWhisperPrompt: () => longPrompt,+ });++ await manager.processWithOpenAIAPI(audioBlob, {});+ assert.equal(prompts.length, 1);+ assert.ok(+ prompts[0].length <= 900,+ `whisper-1 prompt must stay capped, got ${prompts[0].length}`+ );+ assert.ok(longPrompt.startsWith(prompts[0]), "truncation must keep the head of the list");+ });++ await t.test(+ "a self-hosted server with a free-text model name is treated as Whisper",+ async () => {+ setSettings({+ useLocalWhisper: false,+ allowLocalFallback: false,+ cloudTranscriptionProvider: "custom",+ });+ const prompts = capturePrompts(t);+ // Self-hosted and custom endpoints take whatever model name the user typed;+ // most such servers are Whisper-family under a name that never says so.+ const manager = createManager({+ getTranscriptionModel: () => "Systran/faster-distil-large-v3",+ getTranscriptionEndpoint: () => "https://stt.internal.example/v1/audio/transcriptions",+ getWhisperPrompt: () => longPrompt,+ });++ await manager.processWithOpenAIAPI(audioBlob, {});+ assert.equal(prompts.length, 1);+ assert.ok(+ prompts[0].length <= 900,+ `an unrecognized model must not get the 4o budget, got ${prompts[0].length}`+ );+ }+ );++ await t.test("4o transcribe still gets a context guard on absurd lists", async () => {+ setSettings({+ useLocalWhisper: false,+ allowLocalFallback: false,+ cloudTranscriptionProvider: "openai",+ });+ const hugePrompt = buildLongDictionaryPrompt(700); // ~13k chars+ assert.ok(hugePrompt.length > 12000);+ const prompts = capturePrompts(t);+ const manager = createManager({+ getTranscriptionModel: () => "gpt-4o-transcribe",+ getTranscriptionEndpoint: () => "https://api.openai.com/v1/audio/transcriptions",+ getWhisperPrompt: () => hugePrompt,+ });++ await manager.processWithOpenAIAPI(audioBlob, {});+ assert.equal(prompts.length, 1);+ assert.ok(prompts[0].length <= 8000, `4o guard must hold, got ${prompts[0].length}`);+ assert.ok(prompts[0].length > 7000, "guard must be generous, not the Groq-era 900");+ assert.ok(hugePrompt.startsWith(prompts[0]), "truncation must keep the head of the list");+ });+});++test("local whisper receives the dictionary whole, and echo checks see what it sent", async (t) => {+ const { window, setSettings, createManager } = await loadAudioManager(t, {+ cachePrefix: "openwhispr-dictionary-prompt-cap-local-test-",+ settingsKey: "__dictionaryPromptCapLocalSettings",+ });+ setSettings({ useLocalWhisper: true, localTranscriptionProvider: "whisper" });++ const audioBlob = new Blob([new ArrayBuffer(8)], { type: "audio/webm" });+ const longPrompt = buildLongDictionaryPrompt();+ const seen = [];+ window.electronAPI.transcribeLocalWhisper = async (_buf, options) => {+ seen.push(options.initialPrompt);+ return { success: true, text: "transcribed text" };+ };+ const manager = createManager({ getWhisperPrompt: () => longPrompt });++ const result = await manager.processWithLocalWhisper(audioBlob, "base", {});+ assert.equal(result.success, true);+ assert.equal(seen.length, 1);+ // A client-side character cut cannot give the head priority here: whisper.cpp+ // reads ~223 prompt tokens and keeps the TAIL of anything longer, so trimming+ // to 900 chars would only pick a different middle slice — and would leave the+ // echo recovery classifying against a string the decoder never saw.+ assert.equal(seen[0], longPrompt, "local whisper must receive the dictionary uncut");+});diff --git a/test/helpers/chineseScript.test.js b/test/helpers/chineseScript.test.jsindex e324dc5b7..4bf096932 100644--- a/test/helpers/chineseScript.test.js+++ b/test/helpers/chineseScript.test.js@@ -133,14 +133,16 @@ test("Whisper prompt bias and merge", async () => {test("mergeWhisperPrompt puts the bias first so prompt truncation keeps it", async () => {const { mergeWhisperPrompt, getChineseScriptPromptBias } = await load();+ const { GROQ_PROMPT_CHARS } = await import("../../src/utils/dictionaryPromptCap.js");const bias = getChineseScriptPromptBias("simplified");const dictionary = Array.from({ length: 400 }, (_, i) => `term${i}`).join(", ");const prompt = mergeWhisperPrompt(dictionary, "simplified");assert.equal(prompt.startsWith(bias), true);- // audioManager truncates to MAX_PROMPT_CHARS then back to the last comma;- // the bias sits ahead of every dictionary word, so it always survives.- const MAX_PROMPT_CHARS = 890;+ // audioManager truncates to the provider's budget then back to the last+ // comma; the bias sits ahead of every dictionary word, so it always survives.+ // Groq's is the tightest, so it is the one worth pinning here.+ const MAX_PROMPT_CHARS = GROQ_PROMPT_CHARS;assert.equal(prompt.length > MAX_PROMPT_CHARS, true);const truncated = prompt.slice(0, MAX_PROMPT_CHARS);assert.equal(truncated.slice(0, truncated.lastIndexOf(",")).startsWith(bias), true);