Copy Buttons
Template-driven handoff from implementation plans to PTY terminals and external tools.
Copy buttons bridge planning and execution by resolving template placeholders against the active plan, then delivering the result to PTY sessions or the system clipboard. Each action is tied to job metadata for complete audit trails, enabling teams to trace exactly what was sent to agents.
Template resolution flow
How button templates pull task context, plan XML, and model settings before handoff.
Template Configuration Sources
Copy button templates follow a layered configuration model. Server defaults provide baseline templates, project-level overrides customize for team workflows, and task-specific configurations handle one-off scenarios.
Server Defaults
Shared templates from /api/config/desktop-runtime-config. Includes button labels, template strings, target (terminal or clipboard), and visibility conditions.
Project Overrides
Templates stored in SQLite project_settings table. Merged at runtime with server defaults to customize for team standards.
Task-Specific
Per-task_model_config templates for specialized workflows. Enables custom handoff patterns without modifying global settings.
Placeholder Resolution
Templates use double-brace placeholders that are resolved against the active plan and session context at click time. The resolution engine supports nested context access and conditional sections.
// Example template with placeholders
You are an AI coding assistant. Execute the following plan:
{{IMPLEMENTATION_PLAN}}
Working on task: {{TASK_DESCRIPTION}}
Selected files for context:
{{SELECTED_FILES}}
Model: {{MODEL_NAME}}
Session: {{SESSION_ID}}Available Placeholders
{{IMPLEMENTATION_PLAN}}Full merged plan XML content{{STEP_CONTENT}}Content of a specific plan step by index{{TASK_DESCRIPTION}}The refined task specification{{PROJECT_CONTEXT}}File paths, directory structure, and repo summary{{SELECTED_FILES}}List of files included in the plan{{MODEL_NAME}}Currently selected model identifier{{SESSION_ID}}Active session UUID for traceability{{COMMANDS}}Extracted shell commands from plan steps{{STEPS_SECTION}}Plan steps without agent instructions{{REQUIREMENTS}}Task requirements and constraintsResolution order: Job metadata first, then plan content, then session context. Undefined placeholders are preserved in the output for debugging.
Template Processing Pipeline
When a button is clicked, the template processor executes a multi-step pipeline: placeholder extraction, context lookup, value substitution, and output formatting.
Extract Placeholders
Regex scan for {{...}} patterns in the template string
Lookup Context
Query job metadata, plan content, and session state for values
Substitute Values
Replace placeholders with resolved values, preserving formatting
Format Output
Apply target-specific escaping (shell for terminal, plain for clipboard)
Large Plan Chunking
Plans exceeding 100KB are automatically chunked into sequential segments with clear boundaries to avoid overloading terminal buffers or clipboard limits. Each chunk is prefixed with its position (e.g., "[Part 1/3]").
PTY Terminal Handoff
Buttons configured for terminal handoff write directly to the PTY session input buffer. The resolved template appears as if typed by the user, triggering agent execution immediately.
// Terminal handoff implementation
async fn handoff_to_terminal(
session_id: &str,
content: &str,
template_id: &str,
) -> Result<HandoffResult> {
// Get PTY writer for session
let writer = terminal_manager.get_writer(session_id)?;
// Write content to PTY input buffer
writer.write_all(content.as_bytes()).await?;
// Log the action for audit
copy_button_actions.insert(CopyButtonAction {
session_id: session_id.to_string(),
template_id: template_id.to_string(),
content_hash: sha256(content),
created_at: Utc::now(),
})?;
Ok(HandoffResult::Terminal { session_id })
}Handoff Details
- • Content written via
master.take_writer() - • Supports multi-line input and escape sequences
- • UI displays first 100 characters as confirmation preview
Clipboard Handoff
Buttons configured for clipboard copy the resolved template to the system clipboard using the Tauri clipboard API. This enables handoff to external tools like IDE terminals or web-based agents.
Cross-Platform API
Uses tauri::api::clipboard::set_text() for consistent clipboard access across macOS, Windows, and Linux.
User Feedback
Toast notification confirms the copy with a preview of the content and token count estimate for the target model.
Job Metadata and Audit Trail
Every copy button action is linked to job metadata for complete traceability. The audit record includes the source plan, target session, resolved content hash, and user context.
-- copy_button_actions table schema
CREATE TABLE copy_button_actions (
action_id TEXT PRIMARY KEY,
plan_id TEXT NOT NULL REFERENCES implementation_plans(id),
job_id TEXT REFERENCES background_jobs(id),
session_id TEXT REFERENCES terminal_sessions(session_id),
template_id TEXT NOT NULL,
content_hash TEXT NOT NULL, -- SHA-256 for integrity verification
created_at TEXT NOT NULL
);
-- Query to trace plan handoffs
SELECT * FROM copy_button_actions
WHERE plan_id = ?
ORDER BY created_at DESC;Audit Record Fields
action_idUnique identifier for this handoff actionplan_idSource implementation plan referencejob_idAssociated background job if applicablesession_idTarget terminal session or null for clipboardtemplate_idTemplate configuration that was usedcontent_hashSHA-256 of resolved content for integritycreated_atTimestamp of the actionRetention: Audit records are retained for 90 days by default, configurable in project settings.
Default Copy Buttons
PlanToCode ships with several default copy buttons that cover common workflows. These can be customized or extended through project settings.
Use Full Planuse-full-planCopies the entire implementation plan XML content. Best for agents that accept structured plan input.
Use This Stepuse-stepCopies only the currently selected step content. Useful for incremental execution or reviewing specific changes.
Use Commandsuse-commandsExtracts and copies only the shell commands from the plan steps. Ideal for quick terminal execution.
Use Steps Onlyuse-steps-onlyCopies the plan steps without agent instructions or metadata. Cleaner output for human review.
Customizing Copy Buttons
Copy buttons can be customized at multiple levels: global defaults, project-level overrides, and per-task configurations.
Global Defaults
Server-side configuration in /api/config/desktop-runtime-config defines the base set of copy buttons. These are loaded when the desktop app starts and cached for offline use.
Project-Level Customization
Each project can override the default buttons through the Settings panel. Project-specific buttons are stored in SQLite and merged with server defaults at runtime.
Task-Level Configuration
Individual tasks can have their own copy button configurations. This allows different button sets for implementation plans, code reviews, or documentation tasks.
The copy button editor in Settings allows drag-and-drop reordering, inline label editing, and template content modification. Changes are debounced and persisted automatically.
UI Integration and Safety
Copy buttons appear in plan viewers and terminal headers. Each button shows a preview popover with the resolved content and token estimate before execution.
Token Estimation
Token estimates help reviewers validate that the prompt fits within the target model's context window before handoff. Displayed alongside the preview.
Full Preview Modal
Clicking the preview icon opens a modal with the full resolved template, syntax highlighting, and diff view if the template has changed since last use.
Disabled State
Buttons are disabled when required context is missing (e.g., no active plan, missing session). Tooltips explain what context is needed to enable the button.
Mobile Integration
Copy buttons work across desktop and mobile clients with consistent behavior. The iOS client uses the same placeholder resolution logic and can send content to linked terminals.
Device Link Support
When a mobile device is linked to a desktop session, copy buttons can target the desktop terminal directly. The resolved content is sent through the device link WebSocket connection.
Mobile-Specific Buttons
Mobile clients support the same button customization as desktop. Button configurations sync through the server to maintain consistency across devices.
Trace handoff to execution
Terminal sessions show where copy button output lands and how it is logged.