7.0 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 outputs to its own subfolder (WinUI3Apps/AdvancedPaste/) rather than the shared WinUI3Apps/ folder. This isolates its resources.pri from other WinUI 3 apps due to a known WinUI bug.
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.
Sparse package identity (local development)
Advanced Paste uses the Windows AI APIs (Phi Silica / Microsoft.Windows.AI.Text.LanguageModel) which require package identity at runtime. PowerToys provides this via a shared sparse MSIX package (Microsoft.PowerToys.SparseApp).
Why is this needed?
- The
LanguageModelAPI requires a Limited Access Feature (LAF) unlock, which only succeeds when the calling process has a matching package identity. - Advanced Paste is an unpackaged, self-contained WinUI 3 app. The sparse package grants it identity without converting it to a full MSIX.
- There is a known WinUI bug where self-contained WinUI 3 apps with sparse identity only load
resources.priinstead of module-specific PRI files. To avoid conflicts with other WinUI apps, Advanced Paste outputs to its own subfolder (WinUI3Apps/AdvancedPaste/) and usesresources.prias its PRI filename.
One-time setup
-
Build the sparse package for your platform and configuration:
pwsh src/PackageIdentity/BuildSparsePackage.ps1 -Platform ARM64 -Configuration DebugThis generates
PowerToysSparse.msixinARM64\Debug\, creates a dev certificate, and signs the package. -
Trust the dev certificate (first time only):
Import-Certificate -FilePath "src/PackageIdentity/.user/PowerToysSparse.certificate.sample.cer" -CertStoreLocation Cert:\CurrentUser\TrustedPeople -
Register the sparse package for development by adding
-DevRegisterto the build command:pwsh src/PackageIdentity/BuildSparsePackage.ps1 -Platform ARM64 -Configuration Debug -DevRegisterThe
-DevRegisterflag automatically:- Removes any existing registration
- Creates a temporary copy of
AppxManifest.xmlwith the dev publisher - Registers it via
Add-AppxPackage -Registerwith-ExternalLocationpointing to your build output - Verifies the result
You can combine it with the initial build (step 1) in a single command.
-
Verify the registration:
$pkg = Get-AppxPackage -Name "*SparseApp*" $pkg.Publisher # Should be: CN=PowerToys Dev, O=PowerToys, L=Redmond, S=Washington, C=US $pkg.PublisherId # Should be: djwsxzxb4ksa8 $pkg.IsDevelopmentMode # Should be: True
Re-registration
Re-register after rebuilding the sparse package, changing AppxManifest.xml, or switching platforms/configurations:
pwsh src/PackageIdentity/BuildSparsePackage.ps1 -Platform ARM64 -Configuration Debug -DevRegister
Unregistering
pwsh src/PackageIdentity/BuildSparsePackage.ps1 -Unregister
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
Cannot locate resource from 'ms-appx:///Microsoft.UI.Xaml/Themes/themeresources.xaml' |
Sparse package not registered, or registered without -ExternalLocation |
Re-register using step 3 above |
IsDevelopmentMode is False after registration |
Used Add-AppxPackage -Path *.msix instead of -Register |
Remove and re-register using the -Register form |
LAF unlock returns Unavailable |
Publisher mismatch | Verify $pkg.PublisherId is djwsxzxb4ksa8 |
HRESULT 0x800B0109 (trust failure) |
Dev certificate not trusted | Run Import-Certificate (step 2) for both TrustedPeople and TrustedRoot |
How Settings UI checks Phi Silica availability
Settings UI does not have sparse package identity. To check whether Phi Silica is available, it launches Advanced Paste as a subprocess:
PowerToys.AdvancedPaste.exe --check-phi-silica
This flag skips the WinUI app and outputs one of:
Available(exit code 0) — model is readyNotReady(exit code 1) — model needs download via Windows UpdateNotSupported(exit code 2) — not a Copilot+ PC or API unavailable
See also
src/PackageIdentity/readme.md— full sparse package documentation- microsoft/microsoft-ui-xaml#10856 — the WinUI bug requiring separate output folder
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