4.7 KiB
Advanced Paste
Public overview - Microsoft Learn
Quick Links
Overview
Advanced Paste is a PowerToys module that provides enhanced clipboard pasting with formatting options and additional functionality.
Implementation Details
TODO: Add implementation details
Paste with AI Preview
The "Show preview" setting (ShowCustomPreview) controls whether AI-generated results are displayed in a preview window before pasting. The preview feature does not consume additional AI credits—the preview displays the same AI response that was already generated, cached locally from a single API call.
The implementation flow:
- User initiates "Paste with AI" action
- A single AI API call is made via
ExecutePasteFormatAsync - The result is cached in
GeneratedResponses - If preview is enabled, the cached result is displayed in the preview UI
- User can paste the cached result without any additional API calls
See the ExecutePasteFormatAsync(PasteFormat, PasteActionSource) method in OptionsViewModel.cs for the implementation.
Debugging
Advanced Paste is packaged as a self-contained MSIX with its own identity (Microsoft.PowerToys.AdvancedPaste). This gives it native package identity for Windows AI APIs (Phi Silica) and clean ms-appx:/// resource resolution without workarounds.
The MSIX is output to WinUI3Apps/AdvancedPaste/ and registered by the module interface at runtime (or by the installer on release builds).
Running and attaching the debugger
- Set the Runner project (
src/runner) as the startup project in Visual Studio. - Launch the Runner (F5). This starts the PowerToys tray icon and loads all module interfaces.
- Open Settings (right-click tray icon → Settings) and enable the Advanced Paste module if it isn't already. The module launches
PowerToys.AdvancedPaste.exein the background immediately. - In Visual Studio, go to Debug → Attach to Process (
Ctrl+Alt+P) and attach toPowerToys.AdvancedPaste.exe(select Managed (.NET Core) debugger).
Alternatively, use the VS Code launch configuration "Run AdvancedPaste" from .vscode/launch.json to launch the exe directly — but note that without the Runner, IPC and hotkeys won't work.
MSIX package identity
Advanced Paste uses the Windows AI APIs (Phi Silica / Microsoft.Windows.AI.Text.LanguageModel) which require package identity at runtime. The app is packaged as a self-contained MSIX (following the same pattern as Command Palette).
How it works
- Build: The csproj has
EnableMsixTooling=trueandGenerateAppxPackageOnBuild=true(CI builds). This produces an MSIX inAppPackages/. - Local dev: VS registers the package automatically via
Add-AppxPackage -Register AppxManifest.xmlwhen you build. - Installer: The WiX installer deploys the MSIX file and a custom action (
InstallAdvancedPastePackageCA) registers it viaPackageManager.
Local development setup
For local debug builds, Visual Studio handles MSIX registration automatically. Select the "PowerToys.AdvancedPaste (Package)" launch profile in the debug dropdown.
To manually register:
Add-AppxPackage -Register "ARM64\Debug\WinUI3Apps\AdvancedPaste\AppxManifest.xml"
Verify:
$pkg = Get-AppxPackage -Name "*AdvancedPaste*"
$pkg.Name # Microsoft.PowerToys.AdvancedPaste.Dev
$pkg.IsDevelopmentMode # True
How Settings UI checks Phi Silica availability
Settings UI does not have MSIX package identity. To check whether Phi Silica is available, it queries the running Advanced Paste process via a named pipe (powertoys_advancedpaste_phi_status).
Advanced Paste checks LAF + GetReadyState() once on startup (with MSIX identity), caches the result, and serves it to any client that connects. Settings connects with a 5-second timeout and reads one of:
Available— model is readyNotReady— model needs download via Windows UpdateNotSupported— not a Copilot+ PC, API unavailable, or Advanced Paste not running
Settings
| Setting | Description |
|---|---|
ShowCustomPreview |
When enabled, shows AI-generated results in a preview window before pasting. Does not affect AI credit consumption. |
Future Improvements
TODO: Add potential future improvements