Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

feat(tone-style): write assistant and chat drafts in your tone (#2655)

void2aaa7bcb2369
diff --git a/CLAUDE.md b/CLAUDE.md
index bba483520..8f7b9780c 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -788,10 +788,11 @@ Rows in the `actions` table (built-ins seeded from `src/helpers/builtinActions.j
### 20. Tone & Style
-Dictation cleanup writes in the tone the user picked for the kind of app they are dictating into: personal messages (formal, casual, very casual), work messages, email and everything else (formal, casual, excited). Off by default (cleanup keeps the speaker's own tone, the standard tone); turned on by finishing the setup dialog or the Tones & voices switch in Settings > Tone & Style. Only the cleanup route uses it: wake-word agent, voice assistant and translation dictations write in their own voice.
+Dictation cleanup writes in the tone the user picked for the kind of app they are dictating into: personal messages (formal, casual, very casual), work messages, email and everything else (formal, casual, excited). Off by default (cleanup keeps the speaker's own tone, the standard tone); turned on by finishing the setup dialog or the Tones & voices switch in Settings > Tone & Style. The assistant and chats also write drafts (messages, emails, replies, posts) in the tone of the kind of text the request is for. Translation keeps its source's tone.
- **Detection** (main, at dictation start): `capture-dictation-app-category` reads the captured target through `selectionManager.getTargetAppContext()` and classifies it with `toneAppCategories.js`. macOS: `macos-text-monitor --app-context <pid>` prints the app name, bundle id, focused window title (accessibility, no Screen Recording needed) and, for a browser page, the URL host. Windows: `windows-fast-paste --detect-only` also prints `WINDOW_TITLE` (an older helper without it classifies by exe only). Linux: the window title is read on demand (`xdotool`/`kdotool getwindowname`) or taken from Hyprland's active window; an AT-SPI target's comes from `linux-fast-paste --atspi-target` (`WINDOW_TITLE_B64`, the active window's accessible name; an older helper prints none). Titles are kept beside the captured target (`_targetTitles`), never on it, since capture results reach the renderer. A browser (and a Windows UWP frame) is judged by its page or app title (its host, else the site name the title ends with; on a host not listed, only a site name the host carries, so a Notion page titled "Hey" stays `other`); native apps by whole-token app identity. Titles and hosts never leave the main process or reach the logs; only the category does
-- **Cleanup**: `useAudioRecording` starts `audioManager.beginToneStyleCapture()` for plain dictation while Tone & Style and cleanup are on; the cleanup route's `consumeToneStyle()` (1.5 s guard, unknown app reads as `other`) puts `toneStyle` on the reasoning config. Cloud cleanup sends `tone` + `appCategory` on `/api/reason`, and in the combined Orukeet cleanup's `pipelineOptions`: its prompt is fixed when the session is minted, so `startStreamingRecording` waits for the classification until 250 ms after the capture began (overlapping the mic opening, so the start cue isn't held back after it) before minting, returns without minting if the start was cancelled meanwhile, and holds the audio captured meanwhile until the session has started. An app still unknown then (a Wayland AT-SPI target takes about a second) gets no combined cleanup, and `/api/reason` cleans up in its tone at stop. Warmup mints for the app the last start learned in time (`lastToneAppCategory`), and without combined cleanup while none is known; BYOK and local append `appendToneStyleSuffix` (`src/config/prompts/toneStyle.ts`) after the dictionary suffix. Its sentences are verbatim copies of openwhispr-api's `lib/prompts.ts` (English in every locale, as on the server); the mobile app's `composerPrompt.ts` copies the tone and priority sentences too, so change all three together
+- **Cleanup**: `useAudioRecording` starts `audioManager.beginToneStyleCapture()` for every non-translation recording while Tone & Style is on; the cleanup route's `consumeToneStyle()` (1.5 s guard, unknown app reads as `other`) puts `toneStyle` on the reasoning config. Cloud cleanup sends `tone` + `appCategory` on `/api/reason`, and in the combined Orukeet cleanup's `pipelineOptions`: its prompt is fixed when the session is minted, so `startStreamingRecording` waits for the classification until 250 ms after the capture began (overlapping the mic opening, so the start cue isn't held back after it) before minting, returns without minting if the start was cancelled meanwhile, and holds the audio captured meanwhile until the session has started. An app still unknown then (a Wayland AT-SPI target takes about a second) gets no combined cleanup, and `/api/reason` cleans up in its tone at stop. Warmup mints for the app the last start learned in time (`lastToneAppCategory`), and without combined cleanup while none is known; BYOK and local append `appendToneStyleSuffix` (`src/config/prompts/toneStyle.ts`) after the dictionary suffix. Its sentences are verbatim copies of openwhispr-api's `lib/prompts.ts` (English in every locale, as on the server); the mobile app's `composerPrompt.ts` copies the tone and priority sentences too, so change all three together
+- **Assistant and chat**: `getAgentSystemPrompt`'s `writingStyle` option adds a WRITING STYLE block (`buildWritingStyleBlock`) to every chat surface's prompt while Tone & Style is on: the model works out from the request, the recipient and the tool (an `email_draft` body is an email) which kind of text it writes, and uses the user's tone for it; its own answers keep its voice, a tone the user asks for wins, and code is never restyled. A voice-assistant answer pasted at a verified caret writes its reply for that app (text written through a tool, such as an `email_draft` body, still takes its own kind's style): `processAgentCommand` consumes the capture and banks `deliveryAppCategory`, which reaches the send as `destinationAppCategory` through the paste delivery. Before pasting, `deliverAssistantResponse` replaces the answer's em dashes, except in ranges (which take an en dash), code, links and non-Latin scripts. Selection edits get one sentence (`selectionEditToneSentence`) that applies the selection's app style only to a prose rewrite asked for without a tone. The desktop builds every agent prompt itself, so the API needs nothing here
- **UI**: Home banner (`ToneStyleBanner`, cleanup-off copy turns cleanup on) and the setup dialog (`ToneStyleSetupDialog`: intro plus one step per category), offered once the user has dictated `TONE_STYLE_PROMPT_MIN_WORDS` (70, `src/config/toneStyle.ts`) words of local history; the dialog opens by itself once, the banner stays until set up or "Not now" (`useToneStylePrompt`). Settings > Tone & Style (`settings/ToneStyleSection.tsx`) has a Tones & voices switch (`toneStyleEnabled`); while it's off, the picks and Save Changes are grayed out. App badges live in `src/assets/icons/apps/`
## Development Guidelines
diff --git a/src/components/chat/useChatStreaming.ts b/src/components/chat/useChatStreaming.ts
index 006c37161..e82068623 100644
--- a/src/components/chat/useChatStreaming.ts
+++ b/src/components/chat/useChatStreaming.ts
@@ -34,6 +34,7 @@ import {
getAgentSystemPrompt,
} from "../../config/prompts";
import { resolveUnavailableCapabilities } from "../../config/agentCapabilities";
+import type { ToneAppCategory } from "../../config/toneStyle";
import { getDictionaryHintWords } from "../../utils/snippets";
import { noteAttendeesContext, withoutAttendeesFence } from "../../utils/noteAttendees";
import { FULL_TRANSCRIPT_MAX_TOKENS } from "../../utils/transcriptEvidence";
@@ -175,6 +176,8 @@ export interface SendToAIOptions {
suppressResponseContent?: boolean;
/** Asks the model for plain prose because the answer will be pasted into a plain-text app. */
plainTextResponse?: boolean;
+ /** Tone & Style: the kind of app a caret-destined answer will be typed into. */
+ destinationAppCategory?: ToneAppCategory;
/** Per-request completion hook used to deliver a finished voice response. */
onComplete?: (result: {
assistantId: string;
@@ -529,6 +532,9 @@ export function useChatStreaming({
openNote: openNoteContext || undefined,
openNoteTranscriptPreview: currentNote.transcriptPreview,
userName: userNameRef.current,
+ writingStyle: settings.toneStyleEnabled
+ ? { tones: settings.toneStyles, destination: options?.destinationAppCategory }
+ : undefined,
}),
getDictionaryHintWords(settings),
settings.uiLanguage
diff --git a/src/components/dictation/assistantCommandOptions.ts b/src/components/dictation/assistantCommandOptions.ts
index 280fefcae..f52c93092 100644
--- a/src/components/dictation/assistantCommandOptions.ts
+++ b/src/components/dictation/assistantCommandOptions.ts
@@ -51,6 +51,7 @@ export function buildAssistantCommandSendOptions(
suppressResponseContent: delivery?.mode === "paste",
// A caret in a markdown-friendly app still keeps the compact pill.
plainTextResponse: delivery?.mode === "paste" && delivery.plainText,
+ destinationAppCategory: delivery?.mode === "paste" ? delivery.appCategory : undefined,
onApprovalRequested: () => holdInPanel(),
onHoldDelivery: holdInPanel,
onComplete: delivery
diff --git a/src/config/prompts.ts b/src/config/prompts.ts
index ef639f0a1..9cfdc028b 100644
--- a/src/config/prompts.ts
+++ b/src/config/prompts.ts
@@ -1,6 +1,6 @@
import { resolvePrompt } from "./prompts/index";
-import { appendToneStyleSuffix } from "./prompts/toneStyle";
-import type { DictationToneStyle } from "./toneStyle";
+import { appendToneStyleSuffix, buildWritingStyleBlock } from "./prompts/toneStyle";
+import type { DictationToneStyle, ToneAppCategory, ToneStyles } from "./toneStyle";
import { SOURCE_FIDELITY_RULE } from "../helpers/sourceFidelity.js";
import {
CONNECTOR_NAMES,
@@ -171,6 +171,8 @@ export interface AgentSystemPromptOptions {
openNoteTranscriptPreview?: boolean;
/** The signed-in user's name, so drafts are signed with it instead of a placeholder. */
userName?: string | null;
+ /** Tone & Style: the user's tones, and the kind of app a pasted answer lands in. */
+ writingStyle?: { tones: ToneStyles; destination?: ToneAppCategory | null };
}
function toolGroup(tool: PromptTool): string {
@@ -219,6 +221,10 @@ export function getAgentSystemPrompt(
if (unavailable) prompt += "\n\n" + unavailable;
prompt += "\n\n" + signOffRule(options.userName);
+ if (options.writingStyle) {
+ prompt +=
+ "\n\n" + buildWritingStyleBlock(options.writingStyle.tones, options.writingStyle.destination);
+ }
prompt += "\n\n" + SOURCE_FIDELITY_RULE;
if (options.openNote) {
diff --git a/src/config/prompts/toneStyle.ts b/src/config/prompts/toneStyle.ts
index 5f30e8b72..70ca579ea 100644
--- a/src/config/prompts/toneStyle.ts
+++ b/src/config/prompts/toneStyle.ts
@@ -1,20 +1,31 @@
-import type { DictationTone, DictationToneStyle, ToneAppCategory } from "../toneStyle";
+import {
+ TONE_APP_CATEGORIES,
+ type DictationTone,
+ type DictationToneStyle,
+ type ToneAppCategory,
+ type ToneStyles,
+} from "../toneStyle";
-// Verbatim copies of TONE_INSTRUCTIONS, APP_CATEGORY_INSTRUCTIONS and
-// TONE_PRIORITY_INSTRUCTION in openwhispr-api's lib/prompts.ts, which Cloud
-// cleanup appends for the same `tone` and `appCategory`; change both together.
-// English in every locale, as on the server.
-const TONE_INSTRUCTIONS: Record<DictationTone, string> = {
+// What each tone does. Cleanup wraps it into the exact TONE_INSTRUCTIONS
+// sentences of openwhispr-api's lib/prompts.ts (with APP_CATEGORY_INSTRUCTIONS
+// and TONE_PRIORITY_INSTRUCTION copied verbatim below), which Cloud cleanup
+// appends for the same `tone` and `appCategory`; change both together. The
+// chat's writing-style block lists the rules as they are. English in every
+// locale, as on the server.
+const TONE_RULES: Record<DictationTone, string> = {
formal:
- "Apply this tone: formal and polished. Use complete sentences with standard capitalization and full punctuation, spell out informal contractions (in English: I will, do not) but keep any the language's grammar requires, and leave out slang, filler, texting shorthand, emoji and em dashes. Restyle only; do not add or remove information.",
+ "formal and polished. Use complete sentences with standard capitalization and full punctuation, spell out informal contractions (in English: I will, do not) but keep any the language's grammar requires, and leave out slang, filler, texting shorthand, emoji and em dashes.",
casual:
- "Apply this tone: casual and friendly, like a quick note to a colleague. Use the language's everyday contractions (in English: I'll, it's, don't) and everyday wording, standard capitalization and light punctuation with no semicolons or em dashes; a final period can be dropped. Restyle only; do not add or remove information.",
+ "casual and friendly, like a quick note to a colleague. Use the language's everyday contractions (in English: I'll, it's, don't) and everyday wording, standard capitalization and light punctuation with no semicolons or em dashes; a final period can be dropped.",
very_casual:
- 'Apply this tone: very casual, like texting a friend. Write in all lowercase and keep punctuation light: a question still ends with a question mark, but drop the final period and never use em dashes. Use texting shorthand common in the output language only where it stands for the exact words (in English: "u" for you, "lmk" for let me know). Restyle only; do not add or remove information.',
+ 'very casual, like texting a friend. Write in all lowercase and keep punctuation light: a question still ends with a question mark, but drop the final period and never use em dashes. Use texting shorthand common in the output language only where it stands for the exact words (in English: "u" for you, "lmk" for let me know).',
excited:
- "Apply this tone: upbeat and enthusiastic. Use standard capitalization and warm, energetic wording, and end positive or friendly sentences with an exclamation mark, without overdoing it. Use commas or periods, never semicolons or em dashes, and no emoji. Restyle only; do not add or remove information.",
+ "upbeat and enthusiastic. Use standard capitalization and warm, energetic wording, and end positive or friendly sentences with an exclamation mark, without overdoing it. Use commas or periods, never semicolons or em dashes, and no emoji.",
};
+const toneInstruction = (tone: DictationTone) =>
+ `Apply this tone: ${TONE_RULES[tone]} Restyle only; do not add or remove information.`;
+
const APP_CATEGORY_INSTRUCTIONS: Partial<Record<ToneAppCategory, string>> = {
personal: "The text is a personal chat message.",
work: "The text is a work chat message.",
@@ -30,10 +41,91 @@ export function appendToneStyleSuffix(prompt: string, toneStyle?: DictationToneS
if (!toneStyle) return prompt;
const instruction = [
APP_CATEGORY_INSTRUCTIONS[toneStyle.appCategory],
- TONE_INSTRUCTIONS[toneStyle.tone],
+ toneInstruction(toneStyle.tone),
TONE_PRIORITY_INSTRUCTION,
]
.filter(Boolean)
.join(" ");
return `${prompt}\n\n${instruction}`;
}
+
+const WRITING_KINDS: Record<
+ ToneAppCategory,
+ { label: string; examples: string; style: string; destination: string }
+> = {
+ personal: {
+ label: "Personal messages",
+ examples: "texts, WhatsApp, iMessage, Telegram, Instagram",
+ style: "personal message",
+ destination: "a personal messaging app",
+ },
+ work: {
+ label: "Work messages",
+ examples: "Slack, Teams, Google Chat, LinkedIn",
+ style: "work message",
+ destination: "a work chat app",
+ },
+ email: {
+ label: "Emails",
+ examples: "any email, including an email_draft body",
+ style: "email",
+ destination: "an email app",
+ },
+ other: {
+ label: "Everything else",
+ examples: "posts, notes, documents, issues and comments",
+ style: "general writing",
+ destination: "an app other than chat or email",
+ },
+};
+
+// Cleanup's priority sentence keeps these exact under any tone; the chat and
+// selection edits use the rules without it, so they say it themselves.
+const KEEP_NAMES =
+ "Names, acronyms and dictionary terms keep their exact spelling and capitalization.";
+
+// IDEs and terminals count as "other", so a rewrite there is often code.
+const KEEP_CODE =
+ "A tone applies to prose only: code and commands, with their strings and comments, are never restyled.";
+
+const WRITING_STYLE_RULES = `${KEEP_NAMES} ${KEEP_CODE} Never sign or add a name to a personal or work message. Never use em dashes in text written as the user's own words. A tone the user asks for always wins.`;
+
+function writingKindList(tones: ToneStyles): string[] {
+ return TONE_APP_CATEGORIES.map(
+ (category) =>
+ `- ${WRITING_KINDS[category].label} (${WRITING_KINDS[category].examples}): ${TONE_RULES[tones[category]]}`
+ );
+}
+
+/**
+ * The chat's guide to writing in the user's own tone. With `destination`, the
+ * kind of app the assistant will type its answer into, that app's style is the
+ * one for the reply; text written through a tool still goes by its own kind.
+ * Otherwise the model works out which kind of text a request is for from the
+ * request, the recipient and the tool, and picks its style.
+ */
+export function buildWritingStyleBlock(
+ tones: ToneStyles,
+ destination?: ToneAppCategory | null
+): string {
+ if (destination) {
+ const kind = WRITING_KINDS[destination];
+ return [
+ `WRITING STYLE: Your reply will be typed at the user's cursor in ${kind.destination}, as their own words. Write the reply as only the text that goes there (no subject line or label), in the user's ${kind.style} style: ${TONE_RULES[tones[destination]]}`,
+ "That style is for the reply only. Text you write through a tool (an email_draft body, a message you send) takes the user's style for its own kind:",
+ ...writingKindList(tones),
+ WRITING_STYLE_RULES,
+ ].join("\n");
+ }
+ return [
+ "WRITING STYLE: When you write something the user will send or keep as their own words (a message, email, reply, post, comment or note), write it the way they write that kind of text. Work out which kind it is from the request, the recipient and the tool you use, and use only that kind's style:",
+ ...writingKindList(tones),
+ `${WRITING_STYLE_RULES} Your own answers, explanations and summaries keep your usual voice.`,
+ ].join("\n");
+}
+
+// For an in-place edit of selected text: only a rewrite the user asked for
+// without a tone takes the style of the app the selection is in.
+export function selectionEditToneSentence(toneStyle: DictationToneStyle): string {
+ return `If the instruction asks you to rewrite, reword or draft the text and names no tone, write it in the user's ${WRITING_KINDS[toneStyle.appCategory].style} style: ${TONE_RULES[toneStyle.tone]} ${KEEP_NAMES} ${KEEP_CODE}`;
+}
diff --git a/src/helpers/assistantResponseDelivery.ts b/src/helpers/assistantResponseDelivery.ts
index 3894e87e6..d76a5c79b 100644
--- a/src/helpers/assistantResponseDelivery.ts
+++ b/src/helpers/assistantResponseDelivery.ts
@@ -1,4 +1,5 @@
import { markdownToPlainText } from "./markdownToPlainText";
+import type { ToneAppCategory } from "../config/toneStyle";
export type AssistantResponseDelivery =
| {
@@ -8,6 +9,8 @@ export type AssistantResponseDelivery =
allowClipboardFallback: boolean;
/** Ask for prose and strip markdown before pasting. False for a markdown-friendly target. */
plainText: boolean;
+ /** Tone & Style: the kind of app the answer is pasted into, when known. */
+ appCategory?: ToneAppCategory;
}
| { mode: "clipboard" };
@@ -33,12 +36,14 @@ export function createAssistantResponseDelivery({
autoPasteEnabled,
deliverySessionId,
acceptsMarkdown,
+ appCategory,
restoreClipboard,
allowClipboardFallback,
}: {
autoPasteEnabled: boolean;
deliverySessionId?: string;
acceptsMarkdown?: boolean;
+ appCategory?: ToneAppCategory;
restoreClipboard: boolean;
allowClipboardFallback: boolean;
}): AssistantResponseDelivery | null {
@@ -51,6 +56,7 @@ export function createAssistantResponseDelivery({
restoreClipboard,
allowClipboardFallback,
plainText: !acceptsMarkdown,
+ ...(appCategory ? { appCategory } : {}),
};
}
@@ -75,6 +81,49 @@ async function copyAssistantResponse(
}
}
+// A run of em dashes with the spaces around it, on one line.
+const EM_DASH_RUN = /[^\S\r\n]*\u2014(?:[^\S\r\n]*\u2014)*[^\S\r\n]*/g;
+// Code and links keep their dashes.
+const LITERAL_TEXT = /```[\s\S]*?```|`[^`\n]*`|\bhttps?:\/\/\S+/g;
+const NON_LATIN_LETTER = /(?!\p{Script=Latin})\p{L}/u;
+const DIGIT = /\p{Nd}/u;
+const CLOSES_CLAUSE = /[,.;:!?)\]}\u201d\u2019\u00bb]/;
+const OPENS = /[([{\u201c\u2018\u00ab]/;
+const PUNCTUATION = /[,.;:!?]/;
+
+function replaceEmDashRun(run: string, before: string, after: string): string {
+ // Russian, Chinese and other scripts use the dash in their own grammar.
+ if (NON_LATIN_LETTER.test(before) || NON_LATIN_LETTER.test(after)) return run;
+ // A range (1990\u20142000, Q3\u2014Q4) is not a pause, so it takes an en dash.
+ const unspaced = run.trim() === run;
+ if (
+ (DIGIT.test(before) && DIGIT.test(after)) ||
+ (unspaced && (DIGIT.test(before) || DIGIT.test(after)) && /\w/.test(before + after))
+ ) {
+ return run.replace(/\u2014(?:[^\S\r\n]*\u2014)*/, "\u2013");
+ }
+ if (!after || after === "\n" || after === "\r" || CLOSES_CLAUSE.test(after)) return "";
+ if (!before || before === "\n" || before === "\r" || OPENS.test(before)) return "";
+ return PUNCTUATION.test(before) ? " " : ", ";
+}
+
+// An answer typed in the user's Tone & Style is their own words, which no tone
+// writes with em dashes. The prompt says so, but models still use them, so a
+// dash between words becomes a comma; one at a line's edge or beside
+// punctuation or a bracket is dropped. Ranges, code, links and non-Latin
+// scripts keep theirs, since there the dash carries meaning.
+function withoutEmDashes(text: string): string {
+ const literals = [...text.matchAll(LITERAL_TEXT)].map((match) => [
+ match.index,
+ match.index + match[0].length,
+ ]);
+ return text.replace(EM_DASH_RUN, (run: string, offset: number) =>
+ literals.some(([start, end]) => offset >= start && offset < end)
+ ? run
+ : replaceEmDashRun(run, text[offset - 1] ?? "", text[offset + run.length] ?? "")
+ );
+}
+
export async function deliverAssistantResponse(
delivery: AssistantResponseDelivery,
content: string,
@@ -84,9 +133,10 @@ export async function deliverAssistantResponse(
const clipboard = dependencies.clipboard ?? navigator.clipboard;
if (delivery.mode === "paste") {
- // The strip also covers the clipboard fallback (the user pastes into the
- // same field by hand); an answer it empties entirely is pasted raw.
- const text = delivery.plainText ? markdownToPlainText(content) || content : content;
+ // Both strips also cover the clipboard fallback (the user pastes into the
+ // same field by hand); an answer the markdown strip empties is pasted raw.
+ const body = delivery.plainText ? markdownToPlainText(content) || content : content;
+ const text = delivery.appCategory ? withoutEmDashes(body) : body;
try {
const result = await electronAPI?.pasteAtCapturedTarget?.(delivery.sessionId, text, {
restoreClipboard: delivery.restoreClipboard,
diff --git a/src/helpers/audioManager.js b/src/helpers/audioManager.js
index cdeb95180..f60c8f461 100644
--- a/src/helpers/audioManager.js
+++ b/src/helpers/audioManager.js
@@ -128,6 +128,7 @@ import { providerSupportsImages } from "../services/ai/inferenceProviders";
import { resolveDictationTranslationInference } from "./dictationTranslationInference";
import { resolvePrompt, appendScreenContextSuffix } from "../config/prompts";
import { resolveDictationToneStyle } from "../config/toneStyle";
+import { selectionEditToneSentence } from "../config/prompts/toneStyle";
import { syncService } from "../services/SyncService.js";
import { evaluateFinishedRecording, withSalvageWarning } from "./recordingValidation";
import { isEmptyRecording } from "./recordingGuard";
@@ -1087,8 +1088,9 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);
this.toneStyleStartDeadline = performance.now() + 250;
}
- // Consumed by the cleanup route only; the agent and translation routes
- // write in their own voice.
+ // Consumed by the cleanup route, and by an agent command for an answer
+ // typed at the caret or a rewrite of the selection. Translation keeps its
+ // source's tone.
async consumeToneStyle() {
const pending = this.toneStylePromise;
this.toneStylePromise = null;
@@ -2891,7 +2893,8 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);
// and previews stay truthful.
_bankAssistantDirective(transcript, config, options = {}) {
if (!this.isProcessing) return;
- const { selectedContext, deliverySessionId, deliveryAcceptsMarkdown } = options || {};
+ const { selectedContext, deliverySessionId, deliveryAcceptsMarkdown, deliveryAppCategory } =
+ options || {};
this.pendingAssistantConversation = {
transcript,
// resolveReasoningRoute mirrors an attached screenContext into
@@ -2901,6 +2904,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);
screenContext: config?.rawScreenContext ?? null,
...(selectedContext ? { selectedContext } : {}),
...(deliverySessionId ? { deliverySessionId, deliveryAcceptsMarkdown } : {}),
+ ...(deliveryAppCategory ? { deliveryAppCategory } : {}),
};
}
@@ -2926,7 +2930,13 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);
text,
agentName,
config,
- { selectedContext, selectedText, deliverySessionId, deliveryAcceptsMarkdown } = {}
+ {
+ selectedContext,
+ selectedText,
+ deliverySessionId,
+ deliveryAcceptsMarkdown,
+ deliveryAppCategory,
+ } = {}
) {
this.assertAgentAllowedByPolicy();
const settings = getSettings();
@@ -2943,6 +2953,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);
selectedContext,
deliverySessionId,
deliveryAcceptsMarkdown,
+ deliveryAppCategory,
});
return text;
}
@@ -2981,6 +2992,8 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);
? capture.sessionId
: undefined;
const deliveryAcceptsMarkdown = capture?.acceptsMarkdown === true;
+ const toneStyle = await this.consumeToneStyle();
+ const deliveryAppCategory = deliverySessionId ? toneStyle?.appCategory : undefined;
if (!config?.selectionEditReachable) {
// No in-place editor: the panel never types, so only a readable
@@ -2992,6 +3005,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);
: undefined,
deliverySessionId,
deliveryAcceptsMarkdown,
+ deliveryAppCategory,
});
}
@@ -3012,6 +3026,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);
return this._bankPanelAgentCommand(text, agentName, config, {
deliverySessionId,
deliveryAcceptsMarkdown,
+ deliveryAppCategory,
});
}
@@ -3041,6 +3056,9 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);
requireCompleteOutput: true,
};
const isLocalSelection = config?.provider === "local";
+ const toneSentence = toneStyle ? selectionEditToneSentence(toneStyle) : "";
+ const withToneSentence = (prompt) =>
+ toneSentence ? `${String(prompt ?? "").trim()}\n\n${toneSentence}` : prompt;
let userPrompt;
let completionMarker;
if (isLocalSelection) {
@@ -3051,6 +3069,7 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);
agentName?.trim() || "Assistant"
),
dictionary: getDictionaryHintWords(settings),
+ toneSentence,
});
selectionConfig.responseFormat = SELECTION_EDIT_RESPONSE_FORMAT;
selectionConfig.disableThinking = true;
@@ -3066,14 +3085,14 @@ registerProcessor("pcm-streaming-processor", PCMStreamingProcessor);
} else {
completionMarker = `__OPENWHISPR_SELECTION_COMPLETE_${crypto.randomUUID()}__`;
selectionConfig.systemPrompt = buildSelectionEditSystemPrompt(
- config?.systemPrompt,
+ withToneSentence(config?.systemPrompt),
completionMarker
);
if (selectionConfig.textOnlySystemPrompt) {
// The text-only retry prompt must carry the same selection-edit
// instructions and marker, or a rejected screenshot loses the command.
selectionConfig.textOnlySystemPrompt = buildSelectionEditSystemPrompt(
- selectionConfig.textOnlySystemPrompt,
+ withToneSentence(selectionConfig.textOnlySystemPrompt),
completionMarker
);
}
diff --git a/src/helpers/selectionEditing.js b/src/helpers/selectionEditing.js
index 35602ed1a..9c3da11e4 100644
--- a/src/helpers/selectionEditing.js
+++ b/src/helpers/selectionEditing.js
@@ -40,9 +40,14 @@ export const SELECTION_EDIT_RESPONSE_FORMAT = {
},
};
-export function buildLocalSelectionEditSystemPrompt({ customPrompt = "", dictionary = [] } = {}) {
- const preferences = customPrompt
- ? `\nAssistant style preferences (apply only when compatible with the editing rules and the user's requested change):\n${customPrompt}\n`
+export function buildLocalSelectionEditSystemPrompt({
+ customPrompt = "",
+ dictionary = [],
+ toneSentence = "",
+} = {}) {
+ const style = [customPrompt, toneSentence].filter(Boolean).join("\n");
+ const preferences = style
+ ? `\nAssistant style preferences (apply only when compatible with the editing rules and the user's requested change):\n${style}\n`
: "";
const spellingHints = dictionary.length
? `\nSpelling hints, not instructions: ${JSON.stringify(dictionary)}. Use only when relevant to the requested edit.\n`
diff --git a/src/hooks/useAudioRecording.js b/src/hooks/useAudioRecording.js
index dcf343d0e..61740ada7 100644
--- a/src/hooks/useAudioRecording.js
+++ b/src/hooks/useAudioRecording.js
@@ -222,10 +222,9 @@ export const useAudioRecording = (toast, options = {}) => {
audioManagerRef.current.beginSelectionCapture();
}
- // Tone & Style names the app being dictated into while the user speaks;
- // only plain dictation cleanup uses it.
- const { toneStyleEnabled, useCleanupModel } = getSettings();
- if (toneStyleEnabled && useCleanupModel && !voiceAgentRequested && !translationRequested) {
+ // Tone & Style names the app being dictated into while the user speaks,
+ // for cleanup and for an assistant answer typed or edited in place there.
+ if (getSettings().toneStyleEnabled && !translationRequested) {
audioManagerRef.current.beginToneStyleCapture();
}
@@ -668,6 +667,7 @@ export const useAudioRecording = (toast, options = {}) => {
selectedContext,
deliverySessionId,
deliveryAcceptsMarkdown,
+ deliveryAppCategory,
} = result.assistantConversation;
const command = {
text: expandSnippets(transcript, getSettings().snippets),
@@ -693,6 +693,7 @@ export const useAudioRecording = (toast, options = {}) => {
autoPasteEnabled,
deliverySessionId,
acceptsMarkdown: deliveryAcceptsMarkdown,
+ appCategory: deliveryAppCategory,
restoreClipboard: !keepTranscriptionInClipboard,
allowClipboardFallback: isAccessibilitySkipped(),
}),
diff --git a/src/locales/ar/translation.json b/src/locales/ar/translation.json
index e38d0daac..47e415068 100644
--- a/src/locales/ar/translation.json
+++ b/src/locales/ar/translation.json
@@ -5131,10 +5131,10 @@
"settings": {
"saveChanges": "حفظ التغييرات",
"saved": "تم حفظ النبرة والأسلوب",
- "cleanupOff": "تنظيف النص متوقف، لذلك لا تُطبَّق هذه النبرات على إملائك.",
+ "cleanupOff": "تنظيف النص متوقف، لذلك لا تُطبَّق هذه النبرات على إملائك. لكن المساعد والمحادثات لا يزالان يستخدمانها.",
"turnOnCleanup": "تشغيل تنظيف النص",
"enabled": "النبرات والأصوات مفعّلة",
- "enabledDescription": "يستخدم تنظيف النص نبرتك لكل نوع من التطبيقات. عند الإيقاف، تُستخدم النبرة القياسية."
+ "enabledDescription": "يستخدم تنظيف النص والمساعد والمحادثات نبرتك لكل نوع من التطبيقات. عند الإيقاف، تُستخدم النبرة القياسية."
}
},
"productHelp": {
diff --git a/src/locales/de/translation.json b/src/locales/de/translation.json
index a9a11e3f1..800c126b6 100644
--- a/src/locales/de/translation.json
+++ b/src/locales/de/translation.json
@@ -5009,10 +5009,10 @@
"settings": {
"saveChanges": "Änderungen speichern",
"saved": "Ton & Stil gespeichert",
- "cleanupOff": "Die Textbereinigung ist deaktiviert, daher werden diese Einstellungen nicht auf Ihre Diktate angewendet.",
+ "cleanupOff": "Die Textbereinigung ist deaktiviert, daher werden diese Einstellungen nicht auf Ihre Diktate angewendet. Der Assistent und Chats verwenden sie weiterhin.",
"turnOnCleanup": "Textbereinigung aktivieren",
"enabled": "Ton & Stimme aktiviert",
- "enabledDescription": "Die Textbereinigung verwendet Ihren Ton für jede Art von App. Wenn deaktiviert, gilt der Standardton."
+ "enabledDescription": "Die Textbereinigung, der Assistent und Chats verwenden Ihren Ton für jede Art von App. Wenn deaktiviert, gilt der Standardton."
}
},
"productHelp": {
diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json
index e353cf99f..2c0de2e10 100644
--- a/src/locales/en/translation.json
+++ b/src/locales/en/translation.json
@@ -5009,10 +5009,10 @@
"settings": {
"saveChanges": "Save Changes",
"saved": "Tone & Style saved",
- "cleanupOff": "AI cleanup is off, so these tones aren't applied to your dictation.",
+ "cleanupOff": "AI cleanup is off, so these tones aren't applied to your dictation. The assistant and chats still use them.",
"turnOnCleanup": "Turn on AI cleanup",
"enabled": "Tones & voices enabled",
- "enabledDescription": "AI cleanup uses your tone for each kind of app. When this is off, it uses the standard tone."
+ "enabledDescription": "AI cleanup, the assistant and chats use your tone for each kind of app. When this is off, they use the standard tone."
}
},
"productHelp": {
diff --git a/src/locales/es/translation.json b/src/locales/es/translation.json
index 98662ac91..74e51cc14 100644
--- a/src/locales/es/translation.json
+++ b/src/locales/es/translation.json
@@ -5009,10 +5009,10 @@
"settings": {
"saveChanges": "Guardar cambios",
"saved": "Tono y estilo guardados",
- "cleanupOff": "La corrección de texto está desactivada, así que estos tonos no se aplican a tu dictado.",
+ "cleanupOff": "La corrección de texto está desactivada, así que estos tonos no se aplican a tu dictado. El asistente y los chats sí los usan.",
"turnOnCleanup": "Activar corrección de texto",
"enabled": "Tonos y voces activados",
- "enabledDescription": "La corrección de texto usa tu tono para cada tipo de app. Si está desactivado, usa el tono estándar."
+ "enabledDescription": "La corrección de texto, el asistente y los chats usan tu tono para cada tipo de app. Si está desactivado, usan el tono estándar."
}
},
"productHelp": {
diff --git a/src/locales/fr/translation.json b/src/locales/fr/translation.json
index 393a6cf67..40ec737c0 100644
--- a/src/locales/fr/translation.json
+++ b/src/locales/fr/translation.json
@@ -5009,10 +5009,10 @@
"settings": {
"saveChanges": "Enregistrer les modifications",
"saved": "Ton et style enregistrés",
- "cleanupOff": "La correction de texte est désactivée, donc ces tons ne s'appliquent pas à votre dictée.",
+ "cleanupOff": "La correction de texte est désactivée, donc ces tons ne s'appliquent pas à votre dictée. L'assistant et les chats les utilisent toujours.",
"turnOnCleanup": "Activer la correction de texte",
"enabled": "Tons et voix activés",
- "enabledDescription": "La correction de texte utilise votre ton pour chaque type d'app. Si c'est désactivé, le ton standard s'applique."
+ "enabledDescription": "La correction de texte, l'assistant et les chats utilisent votre ton pour chaque type d'app. Si c'est désactivé, le ton standard s'applique."
}
},
"productHelp": {
diff --git a/src/locales/it/translation.json b/src/locales/it/translation.json
index 47d0a47f7..81eda6140 100644
--- a/src/locales/it/translation.json
+++ b/src/locales/it/translation.json
@@ -5009,10 +5009,10 @@
"settings": {
"saveChanges": "Salva modifiche",
"saved": "Tono e stile salvati",
- "cleanupOff": "La correzione testo è disattivata, quindi questi toni non vengono applicati alla dettatura.",
+ "cleanupOff": "La correzione testo è disattivata, quindi questi toni non vengono applicati alla dettatura. L'assistente e le chat li usano comunque.",
"turnOnCleanup": "Attiva correzione testo",
"enabled": "Toni e voci attivi",
- "enabledDescription": "La correzione testo usa il tuo tono per ogni tipo di app. Se disattivato, usa il tono standard."
+ "enabledDescription": "La correzione testo, l'assistente e le chat usano il tuo tono per ogni tipo di app. Se disattivato, usano il tono standard."
}
},
"productHelp": {
diff --git a/src/locales/ja/translation.json b/src/locales/ja/translation.json
index c91487818..f5344e512 100644
--- a/src/locales/ja/translation.json
+++ b/src/locales/ja/translation.json
@@ -5009,10 +5009,10 @@
"settings": {
"saveChanges": "変更を保存",
"saved": "トーンとスタイルを保存しました",
- "cleanupOff": "テキスト補正がオフのため、これらのトーンは音声入力に反映されません。",
+ "cleanupOff": "テキスト補正がオフのため、これらのトーンは音声入力に反映されません。アシスタントとチャットでは引き続き使われます。",
"turnOnCleanup": "テキスト補正をオンにする",
"enabled": "トーンとボイスを有効化",
- "enabledDescription": "テキスト補正がアプリの種類ごとにあなたのトーンを使います。オフのときは標準のトーンになります。"
+ "enabledDescription": "テキスト補正、アシスタント、チャットがアプリの種類ごとにあなたのトーンを使います。オフのときは標準のトーンになります。"
}
},
"productHelp": {
diff --git a/src/locales/pt/translation.json b/src/locales/pt/translation.json
index 65088eb63..e3689a223 100644
--- a/src/locales/pt/translation.json
+++ b/src/locales/pt/translation.json
@@ -5009,10 +5009,10 @@
"settings": {
"saveChanges": "Salvar alterações",
"saved": "Tom e estilo salvos",
- "cleanupOff": "A limpeza de texto está desativada, então esses tons não são aplicados ao seu ditado.",
+ "cleanupOff": "A limpeza de texto está desativada, então esses tons não são aplicados ao seu ditado. O assistente e os chats continuam usando-os.",
"turnOnCleanup": "Ativar limpeza de texto",
"enabled": "Tons e vozes ativados",
- "enabledDescription": "A limpeza de texto usa seu tom para cada tipo de app. Desativado, usa o tom padrão."
+ "enabledDescription": "A limpeza de texto, o assistente e os chats usam seu tom para cada tipo de app. Desativado, usam o tom padrão."
}
},
"productHelp": {
diff --git a/src/locales/ru/translation.json b/src/locales/ru/translation.json
index b20260bdb..c3b1a09d3 100644
--- a/src/locales/ru/translation.json
+++ b/src/locales/ru/translation.json
@@ -5055,10 +5055,10 @@
"settings": {
"saveChanges": "Сохранить изменения",
"saved": "Тон и стиль сохранены",
- "cleanupOff": "Очистка текста выключена, поэтому эти тоны не применяются к диктовке.",
+ "cleanupOff": "Очистка текста выключена, поэтому эти тоны не применяются к диктовке. Ассистент и чаты по-прежнему их используют.",
"turnOnCleanup": "Включить очистку текста",
"enabled": "Тон и голос включены",
- "enabledDescription": "Очистка текста использует ваш тон для каждого типа приложений. Если выключено, используется стандартный тон."
+ "enabledDescription": "Очистка текста, ассистент и чаты используют ваш тон для каждого типа приложений. Если выключено, используется стандартный тон."
}
},
"productHelp": {
diff --git a/src/locales/zh-CN/translation.json b/src/locales/zh-CN/translation.json
index 135168572..8f9bf3b8d 100644
--- a/src/locales/zh-CN/translation.json
+++ b/src/locales/zh-CN/translation.json
@@ -5009,10 +5009,10 @@
"settings": {
"saveChanges": "保存更改",
"saved": "语气与风格已保存",
- "cleanupOff": "文本整理已关闭,因此这些语气不会应用到你的听写中。",
+ "cleanupOff": "文本整理已关闭,因此这些语气不会应用到你的听写中。助手和聊天仍会使用它们。",
"turnOnCleanup": "开启文本整理",
"enabled": "启用语气与声音",
- "enabledDescription": "文本整理会为每类应用使用你的语气。关闭时使用标准语气。"
+ "enabledDescription": "文本整理、助手和聊天会为每类应用使用你的语气。关闭时使用标准语气。"
}
},
"productHelp": {
diff --git a/src/locales/zh-TW/translation.json b/src/locales/zh-TW/translation.json
index 2c7887add..8d5009a70 100644
--- a/src/locales/zh-TW/translation.json
+++ b/src/locales/zh-TW/translation.json
@@ -5009,10 +5009,10 @@
"settings": {
"saveChanges": "儲存變更",
"saved": "語氣與風格已儲存",
- "cleanupOff": "文字整理已關閉,因此這些語氣不會套用到你的聽寫。",
+ "cleanupOff": "文字整理已關閉,因此這些語氣不會套用到你的聽寫。助理和聊天仍會使用它們。",
"turnOnCleanup": "開啟文字整理",
"enabled": "啟用語氣與聲音",
- "enabledDescription": "文字整理會為每類應用程式使用你的語氣。關閉時使用標準語氣。"
+ "enabledDescription": "文字整理、助理和聊天會為每類應用程式使用你的語氣。關閉時使用標準語氣。"
}
},
"productHelp": {
diff --git a/test/config/agentSystemPrompt.test.js b/test/config/agentSystemPrompt.test.js
index 9dd527b1d..27aad4bd6 100644
--- a/test/config/agentSystemPrompt.test.js
+++ b/test/config/agentSystemPrompt.test.js
@@ -182,3 +182,62 @@ test("the name joins the prompt as one plain line", async () => {
const long = getAgentSystemPrompt([], undefined, { userName: "A".repeat(500) });
assert.match(long, /The user's name is A{100}\./);
});
+
+const TONES = { personal: "very_casual", work: "casual", email: "formal", other: "excited" };
+
+test("Tone & Style lists the user's style for each kind of writing, after the sign-off rule", async () => {
+ const { getAgentSystemPrompt } = await load();
+ const prompt = getAgentSystemPrompt([], undefined, {
+ userName: "Alex",
+ writingStyle: { tones: TONES },
+ });
+
+ assert.match(prompt, /WRITING STYLE: When you write something the user will send/);
+ assert.match(prompt, /^- Personal messages \([^)]*\): very casual, like texting a friend\./m);
+ assert.match(prompt, /^- Work messages \([^)]*\): casual and friendly/m);
+ assert.match(prompt, /^- Emails \([^)]*email_draft[^)]*\): formal and polished\./m);
+ assert.match(prompt, /^- Everything else \([^)]*\): upbeat and enthusiastic\./m);
+ assert.match(prompt, /Your own answers, explanations and summaries keep your usual voice\./);
+ assert.match(
+ prompt,
+ /Names, acronyms and dictionary terms keep their exact spelling and capitalization\./
+ );
+ assert.ok(prompt.indexOf("sign it with their name") < prompt.indexOf("WRITING STYLE"));
+});
+
+test("an answer typed at the cursor gets that app's style, and tool text keeps its own kind", async () => {
+ const { getAgentSystemPrompt } = await load();
+ const prompt = getAgentSystemPrompt([], undefined, {
+ writingStyle: { tones: TONES, destination: "work" },
+ });
+
+ assert.match(
+ prompt,
+ /WRITING STYLE: Your reply will be typed at the user's cursor in a work chat app, as their own words\. Write the reply as only the text that goes there \(no subject line or label\), in the user's work message style: casual and friendly/
+ );
+ // An email_draft spoken with the cursor in Slack is still written as an email.
+ const replyOnly = prompt.indexOf("That style is for the reply only.");
+ assert.ok(replyOnly > 0);
+ assert.ok(
+ prompt.indexOf("- Emails (any email, including an email_draft body): formal") > replyOnly
+ );
+});
+
+test("an answer typed at the cursor in another app reads naturally", async () => {
+ const { getAgentSystemPrompt } = await load();
+ const prompt = getAgentSystemPrompt([], undefined, {
+ writingStyle: { tones: TONES, destination: "other" },
+ });
+
+ assert.match(
+ prompt,
+ /cursor in an app other than chat or email, as their own words\. .* in the user's general writing style: upbeat and enthusiastic\./
+ );
+ assert.doesNotMatch(prompt, /Everything else style|cursor in an app,/);
+ assert.match(prompt, /code and commands, with their strings and comments, are never restyled/);
+});
+
+test("without Tone & Style the prompt has no writing style", async () => {
+ const { getAgentSystemPrompt } = await load();
+ assert.doesNotMatch(getAgentSystemPrompt([], undefined, {}), /WRITING STYLE/);
+});
diff --git a/test/helpers/assistantCommandOptions.test.js b/test/helpers/assistantCommandOptions.test.js
index 4611dedba..9addc9958 100644
--- a/test/helpers/assistantCommandOptions.test.js
+++ b/test/helpers/assistantCommandOptions.test.js
@@ -166,3 +166,16 @@ test("a panel command still opens for an approval and has no delivery hook", asy
built.options.onApprovalRequested();
assert.equal(h.calls.opened, 1);
});
+
+test("a caret-delivered command tells the chat which kind of app it writes into", async () => {
+ const { buildAssistantCommandSendOptions } = await load();
+ const send = (delivery) =>
+ buildAssistantCommandSendOptions(
+ { attachment: null, selectedContext: null, delivery },
+ handlers().value
+ ).options.destinationAppCategory;
+
+ assert.equal(send({ ...PASTE, appCategory: "email" }), "email");
+ assert.equal(send(PASTE), undefined);
+ assert.equal(send({ mode: "clipboard" }), undefined);
+});
diff --git a/test/helpers/assistantResponseDelivery.test.js b/test/helpers/assistantResponseDelivery.test.js
index 5ee31197e..6b4e4afdc 100644
--- a/test/helpers/assistantResponseDelivery.test.js
+++ b/test/helpers/assistantResponseDelivery.test.js
@@ -172,3 +172,88 @@ test("a clipboard-only delivery keeps the response verbatim", async () => {
await deliverAssistantResponse({ mode: "clipboard" }, MARKDOWN_RESPONSE, dependencies);
assert.deepEqual(writes, [MARKDOWN_RESPONSE]);
});
+
+test("a paste delivery keeps the kind of app the caret is in", async () => {
+ const { createAssistantResponseDelivery } = await deliveryModule;
+ const delivery = createAssistantResponseDelivery({
+ autoPasteEnabled: true,
+ deliverySessionId: "caret-session",
+ appCategory: "work",
+ ...PASTE_OPTIONS,
+ });
+ assert.equal(delivery.appCategory, "work");
+});
+
+const DASHED_RESPONSE = [
+ "hey, how's the figma config\u2014\u2014going ok?",
+ "ask your issuer\u00a0\u2014 they know",
+ "want lunch? \u2014i'm free",
+ "yes, \u2014 really",
+ "so \u2014, yeah",
+ "wait\u2014",
+ "",
+ " \u2014\u2014 one more",
+].join("\n");
+
+test("an answer typed in the user's Tone & Style, and its clipboard fallback, lose their em dashes", async () => {
+ const { deliverAssistantResponse } = await deliveryModule;
+ const toneDelivery = { ...PASTE_DELIVERY, appCategory: "personal" };
+ const expected = [
+ "hey, how's the figma config, going ok?",
+ "ask your issuer, they know",
+ "want lunch? i'm free",
+ "yes, really",
+ "so, yeah",
+ "wait",
+ "",
+ "one more",
+ ].join("\n");
+
+ const pasted = createDeliveryHarness(true);
+ await deliverAssistantResponse(toneDelivery, DASHED_RESPONSE, pasted.dependencies);
+ assert.equal(pasted.pastes[0].text, expected);
+
+ const refused = createDeliveryHarness(false);
+ await deliverAssistantResponse(toneDelivery, DASHED_RESPONSE, refused.dependencies);
+ assert.deepEqual(refused.writes, [expected]);
+});
+
+test("without Tone & Style an answer keeps its em dashes", async () => {
+ const { deliverAssistantResponse } = await deliveryModule;
+ const { dependencies, pastes } = createDeliveryHarness(true);
+
+ await deliverAssistantResponse(PASTE_DELIVERY, DASHED_RESPONSE, dependencies);
+ assert.equal(pastes[0].text, DASHED_RESPONSE);
+});
+
+test("em dashes that carry meaning survive the Tone & Style strip", async () => {
+ const { deliverAssistantResponse } = await deliveryModule;
+ const toneDelivery = { ...PASTE_DELIVERY, plainText: false, appCategory: "other" };
+ const cases = [
+ // Ranges take an en dash rather than turning into a list.
+ ["from 1990\u20142000", "from 1990\u20132000"],
+ ["pages 10 \u2014 20", "pages 10 \u2013 20"],
+ ["Q3\u2014Q4 plan", "Q3\u2013Q4 plan"],
+ ["call at 5 \u2014 or later", "call at 5, or later"],
+ // Scripts that use the dash in their grammar keep it.
+ ["Это \u2014 книга", "Это \u2014 книга"],
+ ["«\u2014 Да, \u2014 сказал он.»", "«\u2014 Да, \u2014 сказал он.»"],
+ ["我们\u2014\u2014就是你们", "我们\u2014\u2014就是你们"],
+ // Brackets and quotes count as punctuation.
+ ["the end \u2014)", "the end)"],
+ ["(\u2014 a note)", "(a note)"],
+ ['"done" \u2014 then', '"done", then'],
+ ["wait \u2014 \u2014 what", "wait, what"],
+ // Code and links are left as written.
+ ["run `a\u2014b` now", "run `a\u2014b` now"],
+ ["```\nx\u2014y\n```", "```\nx\u2014y\n```"],
+ ["`npm test` \u2014 then", "`npm test`, then"],
+ ["see https://example.com/a\u2014b", "see https://example.com/a\u2014b"],
+ ];
+
+ for (const [input, expected] of cases) {
+ const { dependencies, pastes } = createDeliveryHarness(true);
+ await deliverAssistantResponse(toneDelivery, input, dependencies);
+ assert.equal(pastes[0].text, expected, input);
+ }
+});
diff --git a/test/helpers/audioManagerAssistantDirective.test.js b/test/helpers/audioManagerAssistantDirective.test.js
index 1bf98111c..5a340bfbb 100644
--- a/test/helpers/audioManagerAssistantDirective.test.js
+++ b/test/helpers/audioManagerAssistantDirective.test.js
@@ -415,3 +415,88 @@ test("a question verdict arriving after cancellation banks nothing", async (t) =
assert.equal(manager.pendingAssistantConversation, null);
assert.ok(!manager.pendingSelectionEdit);
});
+
+// Tone & Style: the app captured at recording start rides with a caret
+// delivery, so the panel writes the answer in that app's style.
+const TONE_SETTINGS = {
+ autoPasteEnabled: true,
+ toneStyleEnabled: true,
+ toneStyles: { personal: "very_casual", work: "casual", email: "formal", other: "formal" },
+};
+
+test("a caret delivery carries the kind of app the answer lands in", async (t) => {
+ const { createManager } = await loadAudioManagerHarness(t, {
+ cachePrefix: "openwhispr-assistant-caret-tone-",
+ settingsKey: "__assistantCaretToneSettings",
+ settings: TONE_SETTINGS,
+ mockModules: {
+ "/services/ReasoningService": 'export default { processText: async () => "" };',
+ },
+ });
+ const { manager } = managerWithCapture(createManager, {
+ status: "editable",
+ sessionId: "caret-session",
+ });
+ manager.toneStylePromise = Promise.resolve("work");
+
+ await manager.processAgentCommand("tell them the deploy is done", "gpt", "Aria", {
+ selectionEditReachable: true,
+ });
+
+ assert.equal(manager.pendingAssistantConversation.deliveryAppCategory, "work");
+ assert.equal(manager.toneStylePromise, null, "the capture is consumed once");
+});
+
+test("a panel-only answer carries no app to write for", async (t) => {
+ const { createManager } = await loadAudioManagerHarness(t, {
+ cachePrefix: "openwhispr-assistant-panel-tone-",
+ settingsKey: "__assistantPanelToneSettings",
+ settings: TONE_SETTINGS,
+ mockModules: {
+ "/services/ReasoningService": 'export default { processText: async () => "" };',
+ },
+ });
+ const { manager } = managerWithCapture(createManager, null);
+ manager.toneStylePromise = Promise.resolve("work");
+
+ await manager.processAgentCommand("what's on my calendar", "gpt", "Aria", {
+ selectionEditReachable: true,
+ });
+
+ assert.equal("deliveryAppCategory" in manager.pendingAssistantConversation, false);
+});
+
+test("a selection edit asks for the selection's app style only on a rewrite", async (t) => {
+ const { createManager } = await loadAudioManagerHarness(t, {
+ cachePrefix: "openwhispr-assistant-sel-tone-",
+ settingsKey: "__assistantSelToneSettings",
+ settings: TONE_SETTINGS,
+ mockModules: {
+ "/services/ReasoningService": 'export default { processText: async () => "" };',
+ },
+ });
+ const capture = { status: "selected", text: "the selected paragraph", sessionId: "s1" };
+ const { manager, modelCalls } = managerWithCapture(createManager, capture);
+ manager.toneStylePromise = Promise.resolve("email");
+
+ try {
+ await manager.processAgentCommand("rewrite this", "gpt", "Aria", {
+ selectionEditReachable: true,
+ systemPrompt: "base prompt",
+ textOnlySystemPrompt: "base prompt",
+ });
+ } catch {
+ // The mocked result has no completion marker; only the request matters here.
+ }
+
+ const { systemPrompt, textOnlySystemPrompt } = modelCalls[0][3];
+ for (const prompt of [systemPrompt, textOnlySystemPrompt]) {
+ assert.match(
+ prompt,
+ /^base prompt\n\nIf the instruction asks you to rewrite, reword or draft the text and names no tone, write it in the user's email style: formal and polished\./
+ );
+ // IDEs count as "other", so a rewrite there may be code the tone must not touch.
+ assert.match(prompt, /code and commands, with their strings and comments, are never restyled/);
+ assert.ok(prompt.indexOf("If the instruction asks") < prompt.indexOf("SELECTION EDITING MODE"));
+ }
+});
diff --git a/test/helpers/selectionEditing.test.js b/test/helpers/selectionEditing.test.js
index 763495c5d..8efd2426f 100644
--- a/test/helpers/selectionEditing.test.js
+++ b/test/helpers/selectionEditing.test.js
@@ -189,3 +189,19 @@ test("a question verdict is recognised in every shape the edit paths return it",
assert.equal(isSelectionQuestionResponse(response, marker), false, String(response));
}
});
+
+test("a local edit takes a tone sentence as a style preference beside the custom prompt", async () => {
+ const { buildLocalSelectionEditSystemPrompt } = await load();
+ const prompt = buildLocalSelectionEditSystemPrompt({
+ customPrompt: "Keep it short.",
+ toneSentence: "If the instruction asks you to rewrite, use the Work messages style.",
+ });
+ assert.match(
+ prompt,
+ /style preferences[^\n]*:\nKeep it short\.\nIf the instruction asks you to rewrite, use the Work messages style\.\n/
+ );
+ assert.equal(
+ buildLocalSelectionEditSystemPrompt({ toneSentence: "" }),
+ buildLocalSelectionEditSystemPrompt()
+ );
+});
diff --git a/test/helpers/useChatStreamingTools.test.js b/test/helpers/useChatStreamingTools.test.js
index 5a3c4d3ad..79625bb90 100644
--- a/test/helpers/useChatStreamingTools.test.js
+++ b/test/helpers/useChatStreamingTools.test.js
@@ -1287,3 +1287,25 @@ test("with no account name the prompt asks for no signature rather than a placeh
assert.doesNotMatch(prompts[0], /The user's name is/);
assert.match(prompts[0], /You don't know the user's name/);
});
+
+test("Tone & Style gives every send the user's writing style, and a pasted answer its app", async (t) => {
+ const tones = { personal: "very_casual", work: "casual", email: "formal", other: "excited" };
+ const { captured, sentMessages } = await renderChatStreaming(t, CONNECTOR_SURFACE, {
+ settings: { toneStyleEnabled: true, toneStyles: tones },
+ });
+ await captured.sendToAI("Email Josh that I'm in", []);
+ await captured.sendToAI("Tell them it's shipped", [], { destinationAppCategory: "work" });
+
+ const [typed, pasted] = sentMessages.map((messages) => messages[0].content);
+ assert.match(typed, /WRITING STYLE: When you write something the user will send/);
+ assert.match(pasted, /typed at the user's cursor in a work chat app/);
+ assert.match(pasted, /work message style: casual and friendly/);
+});
+
+test("without Tone & Style no send carries a writing style", async (t) => {
+ const { captured, sentMessages } = await renderChatStreaming(t, CONNECTOR_SURFACE, {
+ settings: { toneStyleEnabled: false },
+ });
+ await captured.sendToAI("Tell them it's shipped", [], { destinationAppCategory: "work" });
+ assert.doesNotMatch(sentMessages[0][0].content, /WRITING STYLE/);
+});
diff --git a/test/services/toneStyleCleanup.test.js b/test/services/toneStyleCleanup.test.js
index c6b983ba3..4451fbcb8 100644
--- a/test/services/toneStyleCleanup.test.js
+++ b/test/services/toneStyleCleanup.test.js
@@ -38,6 +38,30 @@ test("the cleanup prompt ends with the app's medium, the tone and its priority",
assert.doesNotMatch(other, /The text is/);
});
+// openwhispr-api's lib/prompts.ts TONE_INSTRUCTIONS, which Cloud cleanup
+// appends for the same tone: BYOK and local cleanup must send the same words.
+const SERVER_TONE_SENTENCES = {
+ formal:
+ "Apply this tone: formal and polished. Use complete sentences with standard capitalization and full punctuation, spell out informal contractions (in English: I will, do not) but keep any the language's grammar requires, and leave out slang, filler, texting shorthand, emoji and em dashes. Restyle only; do not add or remove information.",
+ casual:
+ "Apply this tone: casual and friendly, like a quick note to a colleague. Use the language's everyday contractions (in English: I'll, it's, don't) and everyday wording, standard capitalization and light punctuation with no semicolons or em dashes; a final period can be dropped. Restyle only; do not add or remove information.",
+ very_casual:
+ 'Apply this tone: very casual, like texting a friend. Write in all lowercase and keep punctuation light: a question still ends with a question mark, but drop the final period and never use em dashes. Use texting shorthand common in the output language only where it stands for the exact words (in English: "u" for you, "lmk" for let me know). Restyle only; do not add or remove information.',
+ excited:
+ "Apply this tone: upbeat and enthusiastic. Use standard capitalization and warm, energetic wording, and end positive or friendly sentences with an exclamation mark, without overdoing it. Use commas or periods, never semicolons or em dashes, and no emoji. Restyle only; do not add or remove information.",
+};
+
+test("local cleanup sends the server's exact tone sentences", async (t) => {
+ const { prompts } = await loadModules(t);
+ for (const [tone, sentence] of Object.entries(SERVER_TONE_SENTENCES)) {
+ const prompt = prompts.getCleanupSystemPrompt(null, [], "en", "en", {
+ appCategory: "other",
+ tone,
+ });
+ assert.ok(prompt.includes(`\n\n${sentence} This tone overrides`), tone);
+ }
+});
+
test("Cloud cleanup sends the tone and category only for a toned dictation", async (t) => {
const { window, openwhispr } = await loadModules(t);
const requests = [];