Writer Studio (standalone writing editor) (part 3)
Part 3 of the Writer Studio page: the four AI capabilities the editor ships — selection edits and their review flow, options-mode variants, inline ghost-text autocomplete, and the chat assistant with its suggested edits, persisted history and attached context.
On this page
What it is
This is part 3 of the Writer Studio (standalone writing editor) page. It covers the four AI capabilities the editor ships — selection edits and their review flow, options-mode variants, inline ghost-text autocomplete, and the chat assistant with its suggested edits, persisted history and attached context.
Where to find it
Writer Studio opens from the Writer virtual project in the sidebar, and the parent page covers gating, surfaces and first-run setup. The selection bubble menu and the AI menu in the document header (Writing guidance, Apply guidance to document, Options mode (Rewrite options), Autocomplete and the Assistant) are all in the writer view itself; the payer order (your own AI only, with no Writer daily budget) that sits behind every one of them is described below.
How it behaves
Selection edits (AI — Plan 2)
How it works — Selection edits
Select any text in the editor — nothing opens over the writing — then open the Assistant panel (the header's sparkle button, or Alt+Ctrl+/) and stay on its Fix tab: the passage you highlighted is named at the top, then one-click fixes in four rows split by a thin line, then a box to describe your own fix. These are quick edits to the highlight; the rest of the panel's tabs are separate tools.
| Row | Fixes | What they do |
|---|---|---|
| Fix | Spelling & grammar · Improve · Simpler | Correct the text, sharpen it, or make it easier to read |
| Length | Shorten · Expand · Summarize | Make it shorter, fuller, or a summary |
| Tone | Friendlier · More formal · Punchier | Change the tone without changing the meaning |
| Language | Translate… | Opens the Translate view (below) |
| (box) | Describe a quick fix | Type a short instruction, such as "Make the tone friendlier" |
The list lives in src/renderer/src/features/writer/lib/selection-presets.ts. Simpler and the
tone fixes reuse the custom action with a canned English instruction. Every fix lands in the
review flow below.
Translate
Translate… swaps the fixes for a small Translate view with two language pickers:
- From is filled in with the language detected in the highlight (offline, by the shared
detectLanguagehelper, no AI call) and marked Detected. A highlight too short to tell stays on Auto-detect, and the AI works out the language itself. The user can change it. - To is any language on the shared list in
src/shared/writer-translate-languages.ts, shown in the interface language. The last choice is remembered while the app is open. - Translate sends the
translateaction with the two language codes. The translation replaces the highlight through the same review step as every other fix. Back or Esc returns to the fixes; changing the highlight does too.
Translation runs on the Writer's AI model setting, like every edit. The languages travel as codes from the shared list, never as free text, and the main process names them in the prompt and drops the "write in the input's language" rule every other edit carries.
Choosing an action calls writer:ai-edit on the main process, which calls the
Anthropic Messages API or OpenRouter (the model is the user-selected Writer Studio model — default Luna) and returns the rewritten text.
The document is not touched at this point.
Review flow
The client word-diffs the original selection against the rewritten version (using
the diff package) and renders a ReviewPanel showing additions and deletions
inline. The panel is positioned at the viewport coordinates of the selection start
(editor.view.coordsAtPos(review.from)) and clamped to the window via
containToViewport so it never renders off-screen. Press Esc to reject without
reaching for the mouse.
- Accept — replaces the captured selection range with the rewritten text, read as
markdown, so the AI's headings, bold, italics, bullets and paragraph breaks arrive as
real formatting rather than literal
##,**or-(replaceRangeWithMarkdown). A rewrite in the middle of a sentence stays in that sentence, text inside a code block is inserted exactly as written, and a link whose address is not a web or mail address keeps its words but loses the link. The editor briefly flashes an accent outline (600 ms, suppressed underprefers-reduced-motion) to confirm the change landed. - Reject — discards the rewritten text; the editor is unchanged.
Nothing is written to the document until you click Accept.
Credentials — your own AI only
writer:ai-edit runs only on your own connected AI. The payer order is decided in one place
(writer-payer-ladder.ts; the writer rule in src/shared/ai-payer.ts lists only user-key and
user-account) and is the same for every Writer text AI action:
- Your Claude sign-in — Omniscio runs the request through
claude -p(the same one-shot bridge the Council uses) on your Claude plan. No API key is needed. This is the sanctioned path (it is Claude Code); the Messages API still rejects OAuth tokens directly, so this path spawns the CLI instead of calling the API. - Your own API keys (Anthropic, OpenRouter, Gemini), in the order you set in Settings → My API Keys. A sign-in that is refused or out of usage moves on to your keys; a request that timed out never moves on.
There is no Omniscio-credits fallback and no bundled company key: Omniscio does not pay for your AI. When neither a sign-in nor a key is usable, nothing is sent and Writer says "AI editing needs your own AI account. Sign in to Claude, or add an API key in Settings > My API Keys." (an own-key credential or billing refusal reports the invalid-key message instead). It never crashes.
No daily budget
Writer has no daily AI budget or cost cap. The writerCostCapUsd setting and
writerCreditsNoticeAccepted are retired (kept in the schema, ignored), and the Cost Control panel
has no Writer row. Every successful edit is still logged with trackApiCost(accountId, 'writer', …),
the estimated cost of a Claude sign-in call included, so the spend readout shows it.
The model is resolveWriterModel('edit') — the user-selected writerModel (default Automatic = Luna); no streaming. Typical edits cost fractions of a
cent.
Feature gating
Selection edits are part of the ai-writer gated surface — they are only available
when the Writer Studio feature itself is visible (see "How it is gated" above).
Options mode (AI — Plan 3)
How it works — Options mode
Enable Options mode with Rewrite options in the header's AI menu. With Options mode ON, selecting
text triggers the SelectionMenu (a Tiptap BubbleMenu) to show N alternative
versions of the selected segment inline. The scope (sentence vs paragraph) is
derived automatically by deriveOptionsScope from the selection — it is never a
user-facing tab. Press Esc to dismiss.
The order does not matter: select first and then click the toggle, or the other way
round. Clicking the toggle moves focus to the header button, and a BubbleMenu hides
whenever the editor loses focus, so the toggle hands focus straight back to the editor
whenever text is selected (handleToggleOptionsMode in WriterView.tsx). Without that
step the alternatives were requested — and paid for — but rendered into a hidden menu.
Alternatives are generated on demand when a non-empty selection is made (NOT on a
bare caret click, NOT pre-generated in a background queue). The client caches
results by scope:contentHash(text), so re-selecting the same text instantly
re-shows the same options at no cost. The Refresh button bypasses the cache
and regenerates.
Picking an alternative replaces exactly the selected segment's range in the editor, read as markdown the same way an accepted edit is — nothing outside the active scope is touched. The Undo on the "Alternative applied" toast puts back exactly what was there, formatting included, and does nothing if that text has been edited since.
Scope detection
Scope is derived from the selection by deriveOptionsScope: if the selection fits
within a single sentence (detected via Intl.Segmenter, granularity 'sentence'),
the scope is 'sentence'; otherwise it is 'paragraph' (the full ProseMirror text
block).
IPC channel
writer:ai-options (WRITER_AI_OPTIONS) receives the selected text and scope, calls
the AI provider (OpenRouter for Luna, Anthropic for Claude models), and parses the
response by splitting on --- separators to produce N distinct alternatives. The
response is plain text (no streaming).
Credential and cost guardrails — Options mode
writer:ai-options shares all the same guardrails as selection edits:
- Resolves credentials through the same payer order as edits: your Claude sign-in
(
claude -p), then your own API keys. No usable account → humanized error, no crash, nothing sent. - Logs cost under the
'writer'source on all paths; there is no daily cap. The cache means cached hits never incur a new call. - Model:
resolveWriterModel('options')— user-selectedwriterModel(default Luna). No streaming.
Offline testing — Options mode
The E2E spec uses AMC_WRITER_AI_FAKE=1, which makes the service return
deterministic fake alternatives without calling the real API.
Inline autocomplete (AI — Plan 4)
How it works — Inline autocomplete
Enable Autocomplete in the header's AI menu (or Settings → Writer Studio →
Autocomplete; writerAutocompleteEnabled, default OFF). When enabled, after
a ~300 ms typing pause with the cursor at the end of a paragraph that is at least
15 characters long, Omniscio calls writer:ai-autocomplete and renders the returned
continuation as grey ghost text inline in the editor (a ProseMirror widget
decoration styled .writer-ghost-text / data-writer-ghost).
- Tab — accepts the suggestion, inserting it at the cursor and clearing the ghost text. The next suggestion is asked for right away, without waiting for the typing pause, so writing with Tab flows from one suggestion to the next.
- Typing the same letters as the ghost text — keeps the rest of it showing and asks for nothing new (type-through). Typing it all clears it.
- Ctrl/Cmd+Right — accepts one word; the rest stays showing.
- Any other document change, selection move, or Escape — immediately clears the ghost text without inserting anything.
The suggestion is intentionally short (model: your Utility AI model, Haiku when it is
Automatic; max_tokens 40) — it is a sentence-completion nudge, not a paragraph generator.
Guardrails
- Off by default — the toggle must be explicitly enabled; no autocomplete fires on a fresh install.
- Trigger conditions — selection must be collapsed (no range selection) and positioned at the very end of the paragraph; the paragraph must be ≥15 characters. Neither the debounce (~300 ms) nor the min-length check can be bypassed.
- Stale-drop — a monotonically increasing sequence counter is incremented on every request; responses that arrive for an earlier counter value are silently discarded, preventing out-of-order flicker.
- No background pre-generation — no speculative calls are made while the user is not typing. The one exception is the request made right after Tab accepts a suggestion (contract I14).
Credential and cost guardrails — Inline autocomplete
writer:ai-autocomplete pays like every other Writer AI action (contract I7b): your
Claude sign-in first, then your own API keys, and nothing else; with nothing usable it
simply shows no suggestion.
- On a Claude sign-in it uses one kept-warm Claude Code process (contract I7d,
src/main/services/writer/writer-warm-claude.ts). Starting Claude Code costs about a second, so instead of a freshclaude -pper suggestion, one long-lived process in stream-json input mode answers every suggestion and is cleared (/clear) after each one, so no earlier paragraph rides along. It carries the same private, quick launch as the one-off call (no saved transcript, no personal Claude Code setup, Writer's own instructions, no thinking, low effort, 40-token cap) because both are built bybuildSignInLaunchinsubscription-oneshot.ts. - When it starts and stops — it starts when a Writer editor with autocomplete on
opens (
writer:ai-autocomplete-warm), stops when the last Writer editor closes, after 5 idle minutes, and when the app quits. It restarts on its own after a crash, a refreshed sign-in token, a different account or model, and once when the sign-in is refused. Three crashes in ten minutes, a failed start, orAMC_WRITER_WARM_AUTOCOMPLETE=0hand the sign-in step back to the one-off call. - Typing cancels — a newer keystroke cancels the request at once. A suggestion the process was already writing finishes, is thrown away, and its estimated cost is still recorded.
- Speed — measured with the real Claude Code program against a local stand-in AI:
about 0.3 s to get ready once, then 12–58 ms of overhead per suggestion, against about
1 s of start-up for every one-off call. Each served suggestion records its time, the
payer step and
via(warmorone-shot) in theai-operationevent. - Logs cost under the
'writer'source on every path; there is no daily cap. No usable account → empty suggestion (no toast).
Silent failure — no toast storm
Unlike writer:ai-edit and writer:ai-options, the autocomplete handler never
surfaces a toast or error message on failure. Any soft error (no key, cap hit, rate
limit, network error) returns an empty string so the ghost text simply does not
appear. This prevents a toast storm on every keystroke when, for example, no API
key is configured.
Offline testing — Inline autocomplete
The E2E spec (tests/e2e/ui/writer-autocomplete.spec.ts) uses
AMC_WRITER_AI_FAKE=1, which makes the service return a deterministic fake
continuation without calling the real API.
Chat assistant (AI — Plan 5)
The panel
A ChatPanel slides in on the right side of the editor when you click the
Assistant toggle in the header. The panel is resizable — drag its left
edge to set the width (300–720px), double-click the edge to reset to the 400px
default, and the chosen width is remembered across sessions (the
writerAssistantWidth setting, driven by the shared useResizeSidebar hook).
Toggling hides/shows the panel without losing the conversation. The chat input
receives autoFocus on mount so you can start typing immediately after opening.
If an AI request fails, an inline error bubble appears in the chat history with a
"Try again" button that replays the last user message (retryChat in the store).
The store's aiStatus field also drives the ambient AI banner (see above).
While the assistant works
The panel behaves like a session. Until the answer is complete it shows the same thinking line a session shows — a small robot icon, a flowing Thinking… label and a live seconds counter (after about 20 seconds the label becomes "Still working, this is taking longer than usual…"). The reply bubble appears once the first whole paragraph is ready and grows a paragraph at a time; it never types out word by word, and the hidden markup the assistant uses to separate its reply from its suggested edits never reaches the screen. When the answer finishes, the thinking line goes away and the suggested edits appear under the reply (writer-contract I16b).
Stopping an answer
While the assistant is writing, a Cancel button sits under the thinking line. Cancel stops the request rather than abandoning it: the running provider call is aborted, the question leaves the panel, and nothing is written to the document's history — so the question does not come back with the next message. A stop is not a failure, so no error bubble and no "Try again" appears; the panel simply returns to idle (writer-contract I22/I22a).
The same stop is reachable without the panel: writer:ai-cancel over IPC, and
POST /writer/ai/cancel over the CLI, both taking a requestId and answering
whether anything was actually stopped. The request id is the one the caller put on
POST /writer/ai/edit or POST /writer/ai/chat; those routes answer a stopped
request with 200 { ok: true, data: { cancelled: true } } rather than a 502.
Protocol
Each user turn is sent to writer:ai-chat (WRITER_AI_CHAT). The handler calls
the Anthropic Messages API (the user-selected Writer Studio model (writerModel); default
Automatic = Sonnet for chat — low-frequency and capped at 2048 tokens, so the
stronger model is used for reliable, applicable edits) and returns a structured
response. The model is instructed to wrap its reply in two XML
sections:
<conversation>
…free-form reply to the user…
</conversation>
<suggested_edits>
<edit>
<search>exact text to find in the document</search>
<replace>replacement text</replace>
</edit>
…additional edits…
</suggested_edits>
The parseChatResponse helper parses this into { conversation: string, edits: SuggestedEdit[] }. If the model omits <suggested_edits>, edits is an empty array. Malformed XML or a dropped <conversation> wrapper is treated as a pure conversation reply. The conversation text is rendered as markdown in the assistant bubble (via the shared sanitized ProseBlock renderer — headings, lists, bold, links, code, tables); user messages stay plain text.
The assistant can see only the open document (plus the linked vault note, when the document has one). Asked to read or use any other document, it says so plainly and suggests pasting the relevant text into the document so it can see it.
Suggested edits through the review flow
Each SuggestedEdit in the response shows an "Apply suggested edit" button
that previews what the change becomes (→ <replace>, or → (delete)).
Clicking it calls findTextRangeInDoc, which searches the ProseMirror document
for the <search> text. The search reads the paragraphs joined by line breaks —
the same form the chat sends the document to the model in — so a suggestion that
spans several paragraphs (say, reformatting a whole section of a script) is found
just like a single sentence. It first tries an exact match; if that fails it
falls back to a tolerant match (runs of whitespace, blank spacing paragraphs,
letter case, and straight-vs-smart quotes/dashes are all treated as equivalent) so
a near-miss quote from the model still applies, landing on the real document
characters. When found, the match range is passed to the EXISTING Plan 2 review
flow: the store transitions to review state and the same ReviewPanel
renders, showing the diff between the original and replacement text. The user clicks:
- Accept — the range is re-checked against the live document (and found again
if you typed in the meantime), a pre-AI version is saved, and the
<replace>text replaces it as formatted Markdown (**bold**arrives as bold). - Reject — the store returns to idle; the document is unchanged.
There is no second review UI for chat-suggested edits — they go through the identical ReviewPanel path as bubble-menu selection edits. The one other review surface is the whole-document DocumentReviewPanel used by Apply guidance to document (see the parent page), which lets you skip individual changes.
If the search text is not found in the document even after the tolerant match
(e.g. the user rewrote that passage since the response arrived),
applySuggestedEdit returns false and a friendly toast is shown instead of
opening the review panel — never a silent no-op.
Persisted history (per document)
Chat messages are persisted per document in the writer_chat_messages table
(a child of writer_documents). Each turn — your message plus the assistant's
reply — is saved by the writer:ai-chat handler on success (a failed turn
saves nothing, so retrying it never creates a duplicate). Switching to another
document loads that document's saved conversation; reopening a document you
chatted in before restores the whole conversation, including the assistant's
"Apply" buttons (the suggested edits are stored alongside each reply). A new,
never-chatted document opens with an empty panel.
Each document keeps up to ~200 messages; older messages beyond that are trimmed
automatically. Documents are global per install — chat history has no
account_id and is the same regardless of which Anthropic account is active.
Deleting a document hides its chat history along with it (and restoring the
document brings the conversation back).
Context the AI receives
The edit, rewrite options and chat calls receive two kinds of extra context, when available:
- Attached context — the ContextDock (Local) bundles and documents attached to the document in its Context row (see below and Writer context). It is loaded on this computer from the saved document, only while the in-development Writer Studio Context switch is on.
- Sender engagement signals — if the document's Audience field contains an email
address or name that matches a known sender in SuperMail, the assistant receives a
brief "Relationship context" summary (reply frequency, engagement level, last reply date).
This helps it calibrate formality and familiarity. Resolved via
readSenderScores(), which is filed under the signed-in Omniscio user (resolveUserDataKey()), never the active Claude credential; with nobody signed in the key isLOCAL_INSTALL_DATA_KEY(local-install), so SuperMail's signed-out learning still applies. An unknown sender comes back as a zero score, which produces no injection. The summary names the recipient only as "this recipient" — no sender-controlled text (a display name in particular) can reach the prompt.
The sender summary is resolved by resolveWriterSenderContext(audience)
(src/main/services/writer/voice-context.ts), called before each Writer AI call in
src/main/ipc/writer/writer-ai-handlers.ts and the matching /writer/ai/* command-line routes.
Writer no longer uses Voiceprint. Until 2026-11-15 every Writer AI call also read the user's
Voiceprint email style guide, and the panel showed a Voiceprint line with a Show me how guide.
Both are gone: a writer's voice now comes from the context they attach. Voiceprint itself still
serves Agent Email and meeting notes. The chat request no longer accepts a voiceGuide field (it
was always overwritten), so a command-line caller that still sends one gets a 400.
The Context row in the Writing guidance panel
The row shows only while Writer Studio Context is on (Settings → Lab, off by default), and it
sits under the Tone field where the Voiceprint line used to be
(src/renderer/src/features/writer/components/WriterContextRow.tsx). It reads the document's view
from writer:context-attachments-get: each attached item with its name, an approximate size in
words and a Full / Short chip, the total size, and the warning the loader would give right
now for the Writer model's budget.
- Nothing attached says so and offers Attach context.
- ContextDock (Local) is off says context needs it, with a button that opens its setting.
- A removed item shows struck through with "Removed from ContextDock" and keeps its Remove button; the next AI action names it once in a notice.
- Too large shows the loader's warning, naming the items cut to short versions or left out.
- On the phone and the web view the row is one read-only line, "Context isn't available on mobile yet", and makes no calls.
Attach context opens the attach picker (WriterContextPicker.tsx): it opens with the search box
focused, lists recently attached items first and bundles before documents, shows each item's size,
never lists Omni memory notes, and saves the checked items in order. A new document made from a
template starts with that template's Default context... (each template's menu in the template
picker, stored in the writerTemplateContextDefaults setting). A blank document shows a
non-blocking Attach context / Skip banner until something is typed or attached.
Each guidance field (Goal, Audience, Tone) saves when it loses focus. The typed draft stays on screen until the saved value comes back from the document, so a failed save never throws the text away; if no saved value arrives within 5 seconds the field turns red and shows "Could not save. Try again." The panel opens and closes instantly; a height or fade transition is an open polish item (F151) that needs the content kept mounted and clipped instead of rendered conditionally.
Credential and cost guardrails — Chat assistant
writer:ai-chat shares all the same guardrails as the other AI capabilities:
- Resolves credentials through the same payer order as edits: your Claude sign-in
(
claude -p), then your own API keys. No usable account → humanized error in the chat panel, no crash, nothing sent. - Logs cost under the
'writer'source on every path; there is no daily cap. - Model:
resolveWriterModel('chat')— user-selectedwriterModel(default Sonnet). No streaming.
Offline testing — Chat assistant
The E2E spec (tests/e2e/ui/writer-chat.spec.ts) uses AMC_WRITER_AI_FAKE=1,
which makes the service return a deterministic fake response (a markdown
conversation plus a <suggested_edits> block) without calling the real API.
Panel resize persistence has its own spec, tests/e2e/ui/writer-assistant-resize.spec.ts.
Related
The editor these capabilities act on is in part 2, the exports and integrations around them in part 4, and the IPC channels they call in part 5; the Writer Studio (standalone writing editor) page is the parent.
Last verified 2026-11-15