Back to Documentation
Product Guide

Text Improvement

How PlanToCode rewrites highlighted text without changing formatting and links the result back to your workspace.

•
7 min read
•

Refine text with AI context. Select text in any editor, trigger a background job, and get improved content that keeps your formatting intact.

Text improvement flow

Selection popover triggers improvement job and returns enhanced text.

Text improvement flow diagram
Click to expand
Selection popover to job pipeline overview.

Selection popover behaviour

The TextImprovementProvider listens for selection events on standard inputs and Monaco editors. When you highlight non-empty text it positions a popover near the cursor, stores the selected range, and tracks whether the popover should be visible. Clicking the button kicks off the job and disables the control until the result returns. When the job completes the provider applies the improved text back into the same selection and flushes any pending saves to keep session state in sync.

The popover itself is a minimal component rendered by TextImprovementPopover, which simply triggers the provider hook and shows a loading indicator while a rewrite is running. Because the provider registers global listeners, the popover appears in Monaco plan viewers, the plan terminal dictation field, and any task description inputs without extra wiring.

What happens when you trigger an improvement

Pressing the popover button calls createImproveTextJobAction. The action validates the selection, ensures a session identifier exists, and invokes the Rust command improve_text_command via Tauri. The command builds a TextImprovementPayload containing the original text and queues a background job against the active session.

On the backend, the TextImprovementProcessor resolves the configured model for the text_improvement task, wraps the selection in XML tags, and runs the request through the LlmTaskRunner without streaming. When the model response returns it records token usage, cost, and the system prompt template before emitting the improved text back to the UI. The default configuration ships with Claude Sonnet 4.5 and Gemini 3 Pro as the approved models, capped at 4,096 tokens with a temperature of 0.7.

The background jobs sidebar records the original text in job metadata, so you can review what was sent alongside the rewritten copy. If the selection changes while a job is running, the provider skips replacing the text to avoid clobbering manual edits.

Processor implementation details

The TextImprovementProcessor handles the text rewriting workflow on the Rust backend.

Processing steps

  1. Parse the incoming payload with original text and selection metadata
  2. Build the system prompt from the configured text_improvement template
  3. Submit the request to the LLM task runner without streaming
  4. Extract the improved text from the model response
  5. Record token usage, cost, and prompt template for billing
  6. Emit the result back to the UI via Tauri events

Inline rewriting behaviour

When the improved text returns, the provider automatically replaces the original selection. The rewriting preserves whitespace, line breaks, and any inline formatting present in the source. If the editor is Monaco-based, the change is applied as a single undo-able edit operation.

Supported contexts

  • Task description input fields
  • Plan terminal dictation area
  • Monaco plan viewers and editors
  • Any standard HTML input or textarea

Model configuration

Text improvement uses the text_improvement task configuration from the desktop runtime config. You can override the default model and parameters in the settings panel.

Configurable settings

  • Allowed models list (default: Claude Sonnet 4.5, Gemini 3 Pro)
  • Maximum token limit (default: 4096)
  • Temperature setting (default: 0.7)
  • System prompt template override

Voice transcription integration

Voice recordings use the useVoiceTranscription hook. It loads per-project transcription defaults, requests microphone access, and inserts transcribed text at the cursor inside the task description or terminal dictation buffer. The inserted text can be highlighted and passed through the improvement popover.

Language, model, and temperature preferences persist at the project level, so teams get consistent transcription quality before refining the copy. Silence detection warns about bad audio levels, and a ten-minute cap prevents oversized recordings from blocking improvement jobs with large payloads.

Key implementation files

  • desktop/src/contexts/TextImprovementProvider.tsx
  • desktop/src/components/TextImprovementPopover.tsx
  • desktop/src/actions/text-improvement/index.ts
  • desktop/src-tauri/src/jobs/processors/text_improvement.rs
  • server/src/config/task_model_config.rs

Video capture and prompt scaffolding

The video analysis dialog combines the current task description with an optional focus prompt wrapped in <description> and <video_attention_prompt> tags before sending the job. You can narrate while recording; the resulting summary can be pasted into the task description and refined with the improvement popover.

Video jobs include frame-rate controls, optional audio capture, and usage tracking. Results appear in the background jobs sidebar alongside text improvements.

Try text improvement in the desktop app

Download PlanToCode to combine voice capture, video context, and inline rewriting before you generate implementation plans.