Repository navigation
[Advanced Paste] Add headless CLI for Advanced Paste actions - #50834
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b3724233-2e72-4bce-9fe2-317d1c94af37
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b3724233-2e72-4bce-9fe2-317d1c94af37
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b3724233-2e72-4bce-9fe2-317d1c94af37
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b3724233-2e72-4bce-9fe2-317d1c94af37
Expose built-in, AI, and custom Advanced Paste actions through the headless CLI while preserving the existing UI action pipeline. Add rich input/output adapters and make clipboard output the default. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b3724233-2e72-4bce-9fe2-317d1c94af37
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3feb5faf-8352-4a5f-a3f0-1136ec506fcd
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3feb5faf-8352-4a5f-a3f0-1136ec506fcd
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3feb5faf-8352-4a5f-a3f0-1136ec506fcd
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3feb5faf-8352-4a5f-a3f0-1136ec506fcd
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3feb5faf-8352-4a5f-a3f0-1136ec506fcd
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3feb5faf-8352-4a5f-a3f0-1136ec506fcd
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3feb5faf-8352-4a5f-a3f0-1136ec506fcd
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3feb5faf-8352-4a5f-a3f0-1136ec506fcd
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3feb5faf-8352-4a5f-a3f0-1136ec506fcd
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3feb5faf-8352-4a5f-a3f0-1136ec506fcd
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3feb5faf-8352-4a5f-a3f0-1136ec506fcd
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3feb5faf-8352-4a5f-a3f0-1136ec506fcd
🧭 PR intakeVisual evidence: Required — The pull request changes product UI files, so reviewers need to see the visible result. Visual evidence is currently missing. Author actionMuyuan Li (@MuyuanMS), please update the following before review:
See the contribution guide for the full checklist. If there is no author response within 7 days, this PR will be automatically closed. Automated PR intake; PowerToys maintainers make final decisions. |
|
Muyuan Li (@MuyuanMS) is telemtry included? Aka to track if the CLI is used or not (thats fine for now, we dont need much more) |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
HTML-to-Markdown conversion can expose CF_HTML metadata in CLI output.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Adds a headless Advanced Paste CLI sharing the existing transformation engine, settings, providers, policy enforcement, and packaging infrastructure.
Changes:
- Adds CLI parsing, input/output adapters, action execution, and JSON contracts.
- Extracts reusable Core and Engine projects.
- Adds tests, documentation, signing, package identity, shim, and installer integration.
| File | Description |
|---|---|
tools/CliShim/CliShimManifest.props |
Maps the PATH shim. |
src/PackageIdentity/AppxManifest.xml |
Adds sparse-package identity. |
src/modules/AdvancedPaste/AdvancedPaste/ViewModels/OptionsViewModel.cs |
Passes clipboard input explicitly and shares policy checks. |
src/modules/AdvancedPaste/AdvancedPaste/Services/PasteFormatExecutor.cs |
Accepts explicit input packages. |
src/modules/AdvancedPaste/AdvancedPaste/Services/KernelServiceBase.cs |
Redacts logged AI content. |
src/modules/AdvancedPaste/AdvancedPaste/Services/IPasteFormatExecutor.cs |
Updates the executor contract. |
src/modules/AdvancedPaste/AdvancedPaste/Models/PasteActionSource.cs |
Adds command-line action origin. |
src/modules/AdvancedPaste/AdvancedPaste/Helpers/UserSettings.cs |
Supports snapshot-only settings. |
src/modules/AdvancedPaste/AdvancedPaste/Helpers/TransformHelpers.cs |
Adds cancellation and managed temporary files. |
src/modules/AdvancedPaste/AdvancedPaste/Helpers/TranscodeHelpers.cs |
Uses managed temporary directories. |
src/modules/AdvancedPaste/AdvancedPaste/Helpers/MarkdownHelper.cs |
Delegates Markdown conversion to Core. |
src/modules/AdvancedPaste/AdvancedPaste/Helpers/JsonHelper.cs |
Delegates JSON conversion to Core. |
src/modules/AdvancedPaste/AdvancedPaste/Helpers/DataPackageHelpers.cs |
Cleans owned temporary directories. |
src/modules/AdvancedPaste/AdvancedPaste/AdvancedPasteXAML/App.xaml.cs |
Uses shared engine registration. |
src/modules/AdvancedPaste/AdvancedPaste/AdvancedPaste.csproj |
References extracted projects. |
src/modules/AdvancedPaste/AdvancedPaste.UnitTests/AdvancedPaste.UnitTests.csproj |
References the engine. |
src/modules/AdvancedPaste/AdvancedPaste.FuzzTests/OneFuzzConfig.json |
Updates fuzzing artifacts. |
src/modules/AdvancedPaste/AdvancedPaste.FuzzTests/FuzzTests.cs |
Fuzzes the Core converter. |
src/modules/AdvancedPaste/AdvancedPaste.FuzzTests/AdvancedPaste.FuzzTests.csproj |
References Core. |
src/modules/AdvancedPaste/AdvancedPaste.Engine/AdvancedPasteTempFileManager.cs |
Manages owned temporary files. |
src/modules/AdvancedPaste/AdvancedPaste.Engine/AdvancedPasteServiceCollectionExtensions.cs |
Centralizes dependency registration. |
src/modules/AdvancedPaste/AdvancedPaste.Engine/AdvancedPastePolicy.cs |
Centralizes policy checks. |
src/modules/AdvancedPaste/AdvancedPaste.Engine/AdvancedPaste.Engine.csproj |
Defines the shared engine. |
src/modules/AdvancedPaste/AdvancedPaste.Core/MarkdownConverter.cs |
Implements reusable Markdown conversion. |
src/modules/AdvancedPaste/AdvancedPaste.Core/JsonConverter.cs |
Implements reusable JSON conversion. |
src/modules/AdvancedPaste/AdvancedPaste.Core/HeadlessTransformService.cs |
Exposes deterministic transforms. |
src/modules/AdvancedPaste/AdvancedPaste.Core/HeadlessTransformFormat.cs |
Defines headless formats. |
src/modules/AdvancedPaste/AdvancedPaste.Core/AdvancedPaste.Core.csproj |
Defines the Core library. |
src/modules/AdvancedPaste/AdvancedPaste.CLI/UnsupportedOutputException.cs |
Adds output validation exception. |
src/modules/AdvancedPaste/AdvancedPaste.CLI/SystemClipboardAdapter.cs |
Adds STA clipboard access. |
src/modules/AdvancedPaste/AdvancedPaste.CLI/SmokeTest.ps1 |
Adds CLI smoke coverage. |
src/modules/AdvancedPaste/AdvancedPaste.CLI/Program.cs |
Implements commands and result contracts. |
src/modules/AdvancedPaste/AdvancedPaste.CLI/InputTooLargeException.cs |
Represents input-size failures. |
src/modules/AdvancedPaste/AdvancedPaste.CLI/IClipboardAdapter.cs |
Abstracts clipboard operations. |
src/modules/AdvancedPaste/AdvancedPaste.CLI/IAdvancedPasteRuntime.cs |
Abstracts action execution. |
src/modules/AdvancedPaste/AdvancedPaste.CLI/E2E/Run-E2E.ps1 |
Adds fixture-based E2E checks. |
src/modules/AdvancedPaste/AdvancedPaste.CLI/E2E/README.md |
Documents E2E scenarios. |
src/modules/AdvancedPaste/AdvancedPaste.CLI/E2E/plain.txt |
Adds plain-text fixture. |
src/modules/AdvancedPaste/AdvancedPaste.CLI/E2E/people.csv |
Adds CSV fixture. |
src/modules/AdvancedPaste/AdvancedPaste.CLI/E2E/note.xml |
Adds XML fixture. |
src/modules/AdvancedPaste/AdvancedPaste.CLI/E2E/existing.json |
Adds JSON fixture. |
src/modules/AdvancedPaste/AdvancedPaste.CLI/E2E/empty.txt |
Adds empty-input fixture. |
src/modules/AdvancedPaste/AdvancedPaste.CLI/E2E/config.ini |
Adds INI fixture. |
src/modules/AdvancedPaste/AdvancedPaste.CLI/E2E/article.html |
Adds HTML fixture. |
src/modules/AdvancedPaste/AdvancedPaste.CLI/CliOutputWriter.cs |
Routes and atomically writes outputs. |
src/modules/AdvancedPaste/AdvancedPaste.CLI/CliOutputResult.cs |
Models output results. |
src/modules/AdvancedPaste/AdvancedPaste.CLI/CliInputReader.cs |
Adapts files, stdin, and clipboard. |
src/modules/AdvancedPaste/AdvancedPaste.CLI/CliActionUnavailableException.cs |
Represents unavailable actions. |
src/modules/AdvancedPaste/AdvancedPaste.CLI/CliActionResolutionException.cs |
Represents action resolution errors. |
src/modules/AdvancedPaste/AdvancedPaste.CLI/CliActionRequest.cs |
Models action requests. |
src/modules/AdvancedPaste/AdvancedPaste.CLI/CliActionDescriptor.cs |
Models listed actions. |
src/modules/AdvancedPaste/AdvancedPaste.CLI/AdvancedPasteRuntime.cs |
Resolves and executes actions. |
src/modules/AdvancedPaste/AdvancedPaste.CLI/AdvancedPaste.CLI.prod.manifest |
Adds production identity manifest. |
src/modules/AdvancedPaste/AdvancedPaste.CLI/AdvancedPaste.CLI.dev.manifest |
Adds development identity manifest. |
src/modules/AdvancedPaste/AdvancedPaste.CLI/AdvancedPaste.CLI.csproj |
Defines the self-contained CLI. |
src/modules/AdvancedPaste/AdvancedPaste.Cli.UnitTests/SystemClipboardAdapterTests.cs |
Tests STA and flush behavior. |
src/modules/AdvancedPaste/AdvancedPaste.Cli.UnitTests/ProgramTests.cs |
Tests command and output behavior. |
src/modules/AdvancedPaste/AdvancedPaste.Cli.UnitTests/HeadlessTransformServiceTests.cs |
Tests deterministic transforms. |
src/modules/AdvancedPaste/AdvancedPaste.Cli.UnitTests/CliInputReaderTests.cs |
Tests file input handling. |
src/modules/AdvancedPaste/AdvancedPaste.Cli.UnitTests/AdvancedPasteTempFileManagerTests.cs |
Tests temporary-file ownership. |
src/modules/AdvancedPaste/AdvancedPaste.Cli.UnitTests/AdvancedPasteRuntimeTests.cs |
Tests policy and action resolution. |
src/modules/AdvancedPaste/AdvancedPaste.Cli.UnitTests/AdvancedPaste.Cli.UnitTests.csproj |
Defines the CLI test project. |
PowerToys.slnx |
Registers new projects. |
installer/PowerToysSetupVNext/CliShims.wxs |
Installs the PATH shim. |
installer/PowerToysSetupCustomActionsVNext/CustomAction.cpp |
Terminates the CLI during servicing. |
doc/devdocs/modules/advancedpaste.md |
Documents the CLI contract. |
.pipelines/ESRPSigning_core.json |
Adds binaries to signing. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b3724233-2e72-4bce-9fe2-317d1c94af37
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Ignore only four history methods while recurring Windows 11 CI setup failures are investigated. Document observed capture/activation failures and the condition for re-enabling coverage. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b3724233-2e72-4bce-9fe2-317d1c94af37
…er desktop Dispatch AdvancedPaste.UITests.Next through the existing non-elevated interactive launcher, verify the fixture desktop context, and remove the four clipboard-history ignores without weakening their assertions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Restore the complete PR tree after the temporary checkout's failed long-path checkout staged unrelated deletions. The resulting PR delta remains limited to the five Advanced Paste UI-test coverage and dispatch files. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…e window readiness Activate Windows clipboard history through the OS settings workflow and seed real editor copies. Preserve exact history identities, deletion and disable assertions; add repeated enable/disable capture coverage. Rebind Settings windows and handle measured Shell readiness and clipboard fixture contention without retrying product output assertions. Local Release validation: 69/69 tests on Windows 10 and 11 under both default and constrained resource profiles; x64 and ARM64 builds passed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…and record broker failures Open the supported Win+V history surface before creating fixtures, while retaining exact per-copy Windows history ID assertions. Add read-only service state diagnostics on history failures without changing policy or service configuration. Full default and constrained suites pass 69/69 on Windows 10 and Windows 11. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… failures Replace process-existence warmup with failure-time native panel inspection, screenshots, and API observations. Verify empty and copied native history in the repeated-transition regression without bypassing product assertions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Public CI confirms that Win+V is genuinely empty on the failing Windows 11 image. Remove the newly added success-path OS popup checks: a missed Win+V chord on Windows 10 must not gate otherwise correct product/history API verification. Retain screenshots, UIA trees and before/after API observations on failures. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keep the five native clipboard-history cases explicitly ignored as requested. Preserve their assertions and diagnostic plumbing; document verified native Win+V empty-state evidence, image-version correlation and unresolved cause, cross-platform coverage loss, and re-enable criteria. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Correct text/binary input classification, policy and moderation guards, HTML-only actions, and clipboard-aware temporary file cleanup. Propagate the native GPO implementation through engine build and publish outputs. Add focused regression coverage. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b3724233-2e72-4bce-9fe2-317d1c94af37
Read a single copied text file using the existing bounded input reader, retain rich/binary clipboard formats, and protect original file-drop paths during cleanup. Default unspecified input to clipboard and document explicit stdin selection. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b3724233-2e72-4bce-9fe2-317d1c94af37
Keep provider selection invocation-local through nested and cached AI tools, enforce resolved-provider policy at request boundaries, and make policy denials terminal. Add safe provider listing, explicit provider validation, comprehensive action help, and CLI convention error-handling coverage. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b3724233-2e72-4bce-9fe2-317d1c94af37
## Summary of the Pull Request Add a true headless Advanced Paste CLI (Closes #49902). The PATH-visible `PowerToys.AdvancedPaste.CLI.exe` shim launches the self-contained `WinUI3Apps\PowerToys.AdvancedPaste.Cli.exe`, which calls a shared Advanced Paste action engine directly. The CLI does not open the Advanced Paste window, communicate with Runner, or simulate keyboard input. The UI and CLI share the existing `DataPackageView -> DataPackage` transformation pipeline, AI provider configuration, policy checks, Credential Vault integration, OCR, file generation, and media transcoding. ## PR Checklist - [x] Closes: #49902 - [x] Tests: CLI parser/adapter/action tests and existing Advanced Paste unit tests pass; four clipboard-history UI methods are temporarily ignored as disclosed below - [x] Localization: CLI help and diagnostics are English-only, consistent with the current CLI convention; no new UI strings - [x] Dev docs: commands, actions, input/output behavior, JSON envelopes, exit codes, and E2E examples documented - [x] New binaries: CLI and shared engine binaries added to signing, solution, sparse-package identity, CLI shim, and installer integration ## Command Surface ```text PowerToys.AdvancedPaste.CLI.exe actions list [--json] PowerToys.AdvancedPaste.CLI.exe providers list [--json] PowerToys.AdvancedPaste.CLI.exe transform (--action <name> | --custom-action <id-or-name>) [--input <path> | --stdin | --clipboard] [--output <path> | --stdout | --output-clipboard] [--prompt <text>] [--provider <id>] [--json] ``` Clipboard is the default input and output when their respective options are omitted. Choose at most one input mode (`--input`, `--stdin`, or `--clipboard`) and at most one output mode (`--output`, `--stdout`, or `--output-clipboard`); conflicting modes return exit 2 before clipboard access. Piped text requires `--stdin` and does not override the clipboard default. `--format` remains an alias for `--action`. Built-in actions: - `plain-text`, `markdown`, `json` - `fix-spelling-and-grammar`, `paste-with-ai` - `image-to-text` - `paste-as-txt-file`, `paste-as-png-file`, `paste-as-html-file` - `transcode-to-mp3`, `transcode-to-mp4` Saved custom actions can be selected by ID or case-insensitive name. AI actions use the configured provider by default. A provider is a configured AI service/model entry, not a built-in action; run `providers list` to discover its ID. `--provider <id>` applies only to `paste-with-ai`, `fix-spelling-and-grammar`, and saved custom actions. IDs are case-insensitive; unknown explicit IDs return exit 2 rather than silently falling back. Existing GPO/provider checks apply to the actual resolved provider, including nested tools and cached action chains. ## Example PowerShell Session ```powershell PS> $cli = 'PowerToys.AdvancedPaste.CLI.exe' # Default output is the clipboard PS> 'Hello from stdin' | & $cli transform --action plain-text --stdin PS> $LASTEXITCODE 0 PS> Get-Clipboard Hello from stdin # Explicit stdout remains script-friendly PS> Get-Clipboard | & $cli transform --action markdown --stdin --stdout Hello **PowerToys** PS> $LASTEXITCODE 0 # OCR does not require the UI PS> & $cli transform --action image-to-text --input .\screenshot.png --stdout This is an image with text PS> $LASTEXITCODE 0 # File-producing actions can target an explicit path PS> & $cli transform --action transcode-to-mp3 --input .\recording.wav --output .\recording.mp3 PS> Test-Path .\recording.mp3 True # Paste with AI and saved custom actions reuse Advanced Paste settings PS> Set-Clipboard 'Long text to summarize' PS> & $cli transform --action paste-with-ai --prompt 'Summarize in one sentence' --clipboard PS> Get-Clipboard <provider result> PS> & $cli actions list built-in: plain-text ... custom: Translate to French (3) PS> & $cli transform --custom-action 3 --clipboard # Stable machine-readable result PS> 'hello' | & $cli transform --action plain-text --stdin --stdout --json {"status":"success","action":"plain-text","resultKind":"text","outputPath":null,"outputClipboard":false,"output":"hello\r\n"} # Stable argument error and exit code PS> 'hello' | & $cli transform --action unknown --stdin --json 2>&1 {"status":"error","code":"unsupported_action","message":"Supported actions are ...","usage":"Usage: PowerToys.AdvancedPaste.CLI.exe transform ..."} PS> $LASTEXITCODE 2 ``` ## Visual Evidence This is a CLI-only feature with no visible changes to the Advanced Paste window. The simulated PowerShell session above demonstrates the user-visible command surface, clipboard behavior, file generation, AI/custom actions, JSON output, and exit codes. Exit codes are `0` for success, `1` for input/I/O/clipboard/provider/transformation failures, and `2` for parser or validation errors. Text input is bounded to 16,777,216 characters. Raw input, prompts, and transformed output are never logged. CLI usage telemetry follows the existing PowerToys CLI pattern. `AdvancedPaste_CLICommand` records only a bounded command name (`transform`, `actions list`, `providers list`, `help`, or `unknown`) and whether the invocation succeeded. It never records action/custom-action names, providers, prompts, paths, clipboard/input content, or transformed output. ## Refactor and Layered Architecture The implementation deliberately keeps the existing `DataPackageView -> DataPackage` action pipeline rather than translating every action into a new CLI-specific model. This minimizes regression risk for the WinUI app and avoids duplicating AI, OCR, file-generation, and transcoding behavior. ```text PowerToys.AdvancedPaste.CLI.exe -> CLI input layer stdin / file / rich Windows clipboard -> DataPackageView -> shared AdvancedPaste.Engine action layer built-in actions / AI / saved custom actions -> CLI output layer DataPackage -> clipboard (default) / stdout / output file ``` ### Shared action layer - `AdvancedPaste.Engine` owns the existing non-UI helpers, models, settings, providers, policy checks, telemetry types, and action services. - The existing implementation files are compiled into the shared engine and excluded from duplicate compilation in the app; action internals were not rewritten for the CLI. - `AddAdvancedPasteEngine()` centralizes service registration so the WinUI app and CLI resolve the same executor, AI providers, settings, Credential Vault integration, moderation, caching, and transformations. - `IPasteFormatExecutor` now receives a `DataPackageView` explicitly instead of reading the system clipboard internally. The WinUI app still passes `Clipboard.GetContent()` at its existing call site, preserving UI behavior. - Shared GPO/provider checks were extracted to `AdvancedPastePolicy`, so the UI and CLI enforce the same policy decisions. ### CLI input, runtime, and output layers - `CliInputReader` adapts exactly one of stdin, a file, or the rich Windows clipboard (default) into `DataPackageView`. Text/HTML and storage-item formats are preserved for actions that need them. - `AdvancedPasteRuntime` resolves built-in actions, saved custom actions, prompts, and configured provider overrides, then delegates to the shared executor. - `CliOutputWriter` routes text or generated-file results to the clipboard, stdout, or an explicit output path. It rejects incompatible combinations such as sending a generated file to stdout. - `SystemClipboardAdapter` uses the full-trust Win32/OLE clipboard on an STA thread, preserving text, HTML, bitmap, and file-drop formats without requiring a foreground app window. - File-producing actions use managed temporary directories so clipboard file references survive CLI exit; copied outputs are cleaned immediately and stale clipboard files are cleaned only when clipboard input supplies a snapshot, protecting its original file-drop paths and the selected output directory. Ownership markers prevent cleanup from deleting unrelated directories that happen to share the temp prefix. - File outputs are written via same-directory temporary files and replace the destination only after a successful write, so cancellation does not leave a partial result or destroy an existing destination. - The CLI checks the Advanced Paste enablement policy and AI enablement/provider policy before running actions. It does not create a file watcher for settings in its short-lived headless process. ### Packaging and process model - The CLI remains self-contained and is launched through the standard PATH-visible `PowerToys.CliShim.exe` mapping. - Runner IPC and the Advanced Paste window are not prerequisites. - Sparse-package identity is declared for the CLI so package-dependent providers such as Phi Silica can use the same integration as the app. ## Validation Steps Performed - Built `AdvancedPaste.CLI`, `AdvancedPaste.Engine`, the Advanced Paste WinUI app, both unit-test projects, `CliShim`, and `PackageIdentity` with repository build scripts on current `main` (x64 Debug). - CLI tests: 79 passed, including action/policy resolution, ambiguity handling, bounded file input, output cancellation/atomicity, temp-file ownership, startup errors, clipboard retry/STA behavior, redirected Unicode input, cancellation-aware CSV parsing, and privacy-safe CLI telemetry. - Existing Advanced Paste tests: 56 passed, 14 skipped environment/provider-dependent integration cases. - `SmokeTest.ps1` and `E2E\Run-E2E.ps1` passed against the updated branch. - Process-level checks passed for help, stdin/stdout, file/file, JSON success/error, invalid arguments, unsupported actions, default text/file clipboard output, OCR, TXT/HTML/PNG generation, and WAV-to-MP3 transcoding. - Built the CLI with the production manifest selected (`CIBuild=true`), the Advanced Paste WinUI app, and CliShim. - `git diff --check` is clean. ### Temporary clipboard-history UI-test quarantine Only these four methods in `AdvancedPasteClipboardHistoryTests.cs` have a method-level `[Ignore]` with a shared explanation: - `SelectingANonFirstEntryUpdatesClipboardWithoutChangingHistoryIdentity` - `DeletingAnEntryRemovesOnlyItsExactWindowsHistoryId` - `DisablingClipboardHistoryThroughSettingsHidesHistoryAccess` - `FullHistoryCanBeResetBeforeAddingNewFixtureEntries` In [CI build 390487](https://dev.azure.com/shine-oss/62769a65-d989-45e3-803c-9ad21fcf2ea2/_build/results?buildId=390487), the Windows 11 history fixture copies text successfully to the current clipboard, but Windows history never captures the entry. Subsequent fixtures cannot enable history. The same failures recur on different workers and independent PRs (builds 390445, 390416, and 390420); the exact service, policy, or fixture-activation cause is not yet established. This is a temporary coverage reduction, not a fix for the underlying clipboard-history setup failure. **These four methods are skipped on every OS and architecture**, not just Windows 11. The class and categories are not ignored; all other tests remain enabled, and pipeline behavior and production code are unchanged. Before this quarantine, build 390487 passed the other 64 UI cases on Windows 11 and all 68 on Windows 10 and ARM64. Re-enable the four methods once CI clipboard-history activation and capture are reliable, including repeated enable/disable and restoration. The UI-test project was rebuilt successfully for x64 Release after this change. The UI suite was not rerun locally for this quarantine. AI/custom-action success depends on a configured provider and credentials. MP4 uses the unchanged UI transcoding implementation; a local video fixture was not available for an additional process-level smoke test. ## Clipboard Input Follow-up Commit `78cff9c3fb` makes omitted input options select the clipboard, matching the existing clipboard output default. It also fixes Explorer file copies: a single copied CSV/text/HTML file is read with the same bounded reader as `--input`, so CSV-to-JSON and HTML-to-Markdown work without opening the file to copy its text. ```powershell # Copy people.csv in Explorer, then run either command. PowerToys.AdvancedPaste.CLI.exe transform --action json --stdout PowerToys.AdvancedPaste.CLI.exe transform --action json --clipboard --stdout ``` Existing clipboard text, HTML, or bitmap takes precedence. Images/media and malformed UTF-8 retain file representations; folders and multiple-file selections are not combined or converted to text. Text files do not advertise image attachments. Cleanup still protects paths from the original clipboard snapshot after file content is normalized, and explicit file/stdin commands and action listing do not read the clipboard. Latest validation: rebuilt the x64 Debug CLI/UI dependency chain, passed all 95 targeted input/parser/clipboard/cleanup unit cases and the non-clipboard fixture E2E suite, and reproduced then exercised the copied demo CSV with explicit and default clipboard input. The CSV remained unchanged and stdout examples did not write the clipboard. Real provider traffic and destructive clipboard-history checks were not performed for this follow-up. ## Provider Routing, Discovery, and Help Follow-up Commit `ad5fe5f615` fixes nested Advanced AI tools and cached action chains silently reverting to the active provider instead of the invocation's selected provider. The resolved provider is stored per kernel invocation, including concurrent calls. Shared services enforce its policy before credential access, moderation, provider creation, or network requests. Policy denials remain terminal even if an assistant recovers from a tool error or another tool has produced output. The CLI returns a stable `action_unavailable` error for these denials. Existing UI behavior for removed saved-provider IDs remains unchanged. `providers list [--json]` exposes configured IDs, names, service types, models, default status, and policy availability without reading the clipboard, contacting providers, or exposing credentials, endpoints, or system prompts. Provider setup remains in PowerToys Settings > Advanced Paste; this PR does not add AI setup/enablement commands. Root, transform, and actions-list help describe every built-in action. Transform help covers AI-only provider overrides, provider/custom-action discovery, clipboard defaults, mutually exclusive I/O modes, generated-file limitations, JSON output, cancellation, input limits, exit codes, and runnable examples. Built-in action listings also include descriptions. Help writes through the selected output stream and remains available without creating an application host or reading settings. Final validation for this follow-up: - Rebuilt both x64 Debug test projects and the CLI/UI dependency chain with repository build scripts. - Passed 101 targeted CLI/parser/runtime/policy cases and 25 shared provider-routing/policy/executor/moderation cases, including concurrent invocation isolation and terminal policy-denial regressions. - Passed the existing non-clipboard fixture E2E suite and exercised all help routes, safe provider listing, unknown-ID errors, and a synthetic local Ollama request using an explicit discovered ID. No clipboard writes or cloud/paid requests were made for this follow-up. - Relaunched the rebuilt local Runner, Advanced Paste, and Settings processes and confirmed they respond. - Rechecked `doc/devdocs/cli-conventions.md`: System.CommandLine parsing, brief root description, kebab-case options, complete help, outer startup exception handling, dedicated early logging, privacy-safe dual console/log errors, exit codes, self-contained properties, signing entries, CLI shim mapping, and matching WiX references are wired consistently. Help/setup exceptions are now inside the startup catch; error logging records bounded codes rather than raw input/output. This audit verifies source integration and exercised x64 behavior, not a full installer run or ARM64 runtime certification. Those deployment checks, the existing clipboard-history quarantine, and provider-dependent/manual UI scenarios remain outstanding as described above. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Gleb Khmyznikov <gkhmyznikov@microsoft.com> Copilot-Session: b3724233-2e72-4bce-9fe2-317d1c94af37 Copilot-Session: 3feb5faf-8352-4a5f-a3f0-1136ec506fcd (cherry picked from commit 68231fd) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request Migrate AdvancedPaste.CLI from the System.CommandLine beta4 API to the centrally pinned 2.0.1 API. This fixes the main-branch compilation failure after #50884, which upgraded the dependency after #50834 introduced this CLI. Preserve the existing commands, parameter names and aliases, help text, JSON output, clipboard defaults, and exit codes. Add regression coverage for aliases and help-like option values. <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [ ] Closes: N/A (build regression involving #50834 and #50884) <!-- - [ ] Closes: #yyy (add separate lines for additional resolved issues) --> - [x] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [x] **Tests:** Added/updated and all pass - [x] **Localization:** All end-user-facing strings can be localized - [x] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: N/A <!-- Provide a more detailed description of the PR, other things fixed, or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments ### Cause and scope [Main CI 390858](https://dev.azure.com/shine-oss/PowerToys/_build/results?buildId=390858) and [390863](https://dev.azure.com/shine-oss/PowerToys/_build/results?buildId=390863) fail on both architectures with missing `System.CommandLine.IO`, `IConsole`, and `IStandardStreamWriter`. AdvancedPaste.CLI also still used beta4 option constructors, command registration, parsing, and value/result lookup APIs. - `src/modules/AdvancedPaste/AdvancedPaste.CLI/Program.cs`: use `Options`/`Subcommands`, `RootCommand.Parse`, `ParseResult.GetValue`/`GetResult`, and `InvocationConfiguration.Output`/`Error`. Define option names/aliases separately from `Description` and remove the obsolete console adapter. - Keep recognizing help-like values belonging to an option, rather than interpreting a prompt or path such as `-h` as a help request. - `src/modules/AdvancedPaste/AdvancedPaste.Cli.UnitTests/ProgramTests.cs`: cover both action aliases, long/short file options, all existing help aliases, and help-like prompt values. Existing JSON, error, cancellation, policy, and clipboard-adapter tests remain intact. - `doc/devdocs/modules/advancedpaste.md`: document the parser API and the help-token invariant. No dependency downgrade, new binaries, installer changes, policy changes, test suppression, or pipeline changes. User-facing text is unchanged; the localization checkbox denotes preservation of existing behavior. New-binary and external user-documentation checklist items are N/A. This PR targets **main only**. It does not cherry-pick to stable, queue a signed release, or publish a release. <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed ### Build scope and environment limitation The ordinary documented build command was attempted: ```powershell Set-Location 'D:\PT102-CommandLineFix\src\modules\AdvancedPaste\AdvancedPaste.Cli.UnitTests' & 'D:\PT102-CommandLineFix\tools\build\build.ps1' -Platform x64 -Configuration Release -Path . -ExtraArgs '/p:CIBuild=false' ``` **Blocked before source compilation, exit 1:** the local Visual Studio installation cannot resolve `Microsoft.NET.Sdk`. Explicitly selecting the installed SDK then fails in `ProcessFrameworkReferences` with MSB4018 loading `Microsoft.Deployment.DotNet.Releases, Version=2.0.0.0`. A task-local .NET 10.0.303 SDK can restore the real project graph, but its Core MSBuild host cannot execute the native VC tasks. No tracked build settings or system installation were changed to bypass these failures. To validate the changed code despite that host issue, rebuilt the **actual CLI and unit-test `.csproj` files**, with their repository analyzers and warnings-as-errors, using unchanged dependency binaries from successful [CI 390854](https://dev.azure.com/shine-oss/PowerToys/_build/results?buildId=390854), source `26b99a0a01af48b87a6aacd341e2c355ea3c6d1e`. The source of the reused managed dependency projects is unchanged from that build to this PR's base `863ff53e9b87790cf2885d5ef527587534e1fecf`. An **uncommitted, local-only** `ReuseCiDependencies.targets` replaces project references with those dependency assemblies. The CLI itself and all CLI test sources were compiled from this worktree against System.CommandLine **2.0.1**; neither the parser nor the CLI implementation was stubbed. This is dependency-reuse validation, **not** a successful clean build of the full dependency graph. ```powershell $repo = 'D:\PT102-CommandLineFix' $validation = "$repo\artifacts\commandline-fix" $dotnet = "$validation\dotnet\dotnet.exe" $env:DOTNET_ROOT = "$validation\dotnet" $env:MSBuildEnableWorkloadResolver = 'false' $buildArgs = @( '/t:Build', '/p:Platform=x64', '/p:Configuration=Release', "/p:SolutionDir=$repo\", '/p:CIBuild=false', '/p:SkipLongPathsCheck=true', '/p:BuildProjectReferences=false', '/p:DisableTransitiveProjectReferences=true', "/p:CustomAfterMicrosoftCommonTargets=$validation\ReuseCiDependencies.targets", '/v:minimal', '/nologo' ) & $dotnet msbuild "$repo\src\modules\AdvancedPaste\AdvancedPaste.CLI\AdvancedPaste.CLI.csproj" @buildArgs & $dotnet msbuild "$repo\src\modules\AdvancedPaste\AdvancedPaste.Cli.UnitTests\AdvancedPaste.Cli.UnitTests.csproj" @buildArgs ``` **Both passed, exit 0.** `SkipLongPathsCheck` is the existing developer option; the machine-wide long-path registry setting was not modified. ### Tests and executable smoke checks ```powershell Set-Location "$repo\x64\Release\tests\AdvancedPaste.Cli.UnitTests" & $dotnet '.\AdvancedPaste.Cli.UnitTests.dll' --filter 'FullyQualifiedName~ProgramTests' --report-trx ``` **Passed, exit 0: 91/91, zero skipped.** ```powershell & $dotnet '.\AdvancedPaste.Cli.UnitTests.dll' --report-trx ``` **Passed, exit 0: 151/151, zero skipped**, including the nine additional regression cases. ```powershell & "$repo\src\modules\AdvancedPaste\AdvancedPaste.CLI\SmokeTest.ps1" ` -Executable "$repo\x64\Release\WinUI3Apps\PowerToys.AdvancedPaste.Cli.exe" ``` **Passed, exit 0:** existing executable smoke checks for help, stdin/stdout, file conversion, JSON output, conflicting input modes, and unsupported actions. Unchanged runtime dependencies and `PowerToys.AdvancedPaste.pri` were supplied from the same successful CI build. No real clipboard writes or AI-provider calls were performed. ```powershell git -C D:\PT102-CommandLineFix diff --check ``` **Passed.** ARM64 compilation, UI automation, a clean native dependency build, and an official signed release build were **not completed locally**. Public PR CI remains the full integration gate. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request Migrate AdvancedPaste.CLI from the System.CommandLine beta4 API to the centrally pinned 2.0.1 API. This fixes the main-branch compilation failure after #50884, which upgraded the dependency after #50834 introduced this CLI. Preserve the existing commands, parameter names and aliases, help text, JSON output, clipboard defaults, and exit codes. Add regression coverage for aliases and help-like option values. <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [ ] Closes: N/A (build regression involving #50834 and #50884) <!-- - [ ] Closes: #yyy (add separate lines for additional resolved issues) --> - [x] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [x] **Tests:** Added/updated and all pass - [x] **Localization:** All end-user-facing strings can be localized - [x] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: N/A <!-- Provide a more detailed description of the PR, other things fixed, or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments ### Cause and scope [Main CI 390858](https://dev.azure.com/shine-oss/PowerToys/_build/results?buildId=390858) and [390863](https://dev.azure.com/shine-oss/PowerToys/_build/results?buildId=390863) fail on both architectures with missing `System.CommandLine.IO`, `IConsole`, and `IStandardStreamWriter`. AdvancedPaste.CLI also still used beta4 option constructors, command registration, parsing, and value/result lookup APIs. - `src/modules/AdvancedPaste/AdvancedPaste.CLI/Program.cs`: use `Options`/`Subcommands`, `RootCommand.Parse`, `ParseResult.GetValue`/`GetResult`, and `InvocationConfiguration.Output`/`Error`. Define option names/aliases separately from `Description` and remove the obsolete console adapter. - Keep recognizing help-like values belonging to an option, rather than interpreting a prompt or path such as `-h` as a help request. - `src/modules/AdvancedPaste/AdvancedPaste.Cli.UnitTests/ProgramTests.cs`: cover both action aliases, long/short file options, all existing help aliases, and help-like prompt values. Existing JSON, error, cancellation, policy, and clipboard-adapter tests remain intact. - `doc/devdocs/modules/advancedpaste.md`: document the parser API and the help-token invariant. No dependency downgrade, new binaries, installer changes, policy changes, test suppression, or pipeline changes. User-facing text is unchanged; the localization checkbox denotes preservation of existing behavior. New-binary and external user-documentation checklist items are N/A. This PR targets **main only**. It does not cherry-pick to stable, queue a signed release, or publish a release. <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed ### Build scope and environment limitation The ordinary documented build command was attempted: ```powershell Set-Location 'D:\PT102-CommandLineFix\src\modules\AdvancedPaste\AdvancedPaste.Cli.UnitTests' & 'D:\PT102-CommandLineFix\tools\build\build.ps1' -Platform x64 -Configuration Release -Path . -ExtraArgs '/p:CIBuild=false' ``` **Blocked before source compilation, exit 1:** the local Visual Studio installation cannot resolve `Microsoft.NET.Sdk`. Explicitly selecting the installed SDK then fails in `ProcessFrameworkReferences` with MSB4018 loading `Microsoft.Deployment.DotNet.Releases, Version=2.0.0.0`. A task-local .NET 10.0.303 SDK can restore the real project graph, but its Core MSBuild host cannot execute the native VC tasks. No tracked build settings or system installation were changed to bypass these failures. To validate the changed code despite that host issue, rebuilt the **actual CLI and unit-test `.csproj` files**, with their repository analyzers and warnings-as-errors, using unchanged dependency binaries from successful [CI 390854](https://dev.azure.com/shine-oss/PowerToys/_build/results?buildId=390854), source `26b99a0a01af48b87a6aacd341e2c355ea3c6d1e`. The source of the reused managed dependency projects is unchanged from that build to this PR's base `863ff53e9b87790cf2885d5ef527587534e1fecf`. An **uncommitted, local-only** `ReuseCiDependencies.targets` replaces project references with those dependency assemblies. The CLI itself and all CLI test sources were compiled from this worktree against System.CommandLine **2.0.1**; neither the parser nor the CLI implementation was stubbed. This is dependency-reuse validation, **not** a successful clean build of the full dependency graph. ```powershell $repo = 'D:\PT102-CommandLineFix' $validation = "$repo\artifacts\commandline-fix" $dotnet = "$validation\dotnet\dotnet.exe" $env:DOTNET_ROOT = "$validation\dotnet" $env:MSBuildEnableWorkloadResolver = 'false' $buildArgs = @( '/t:Build', '/p:Platform=x64', '/p:Configuration=Release', "/p:SolutionDir=$repo\", '/p:CIBuild=false', '/p:SkipLongPathsCheck=true', '/p:BuildProjectReferences=false', '/p:DisableTransitiveProjectReferences=true', "/p:CustomAfterMicrosoftCommonTargets=$validation\ReuseCiDependencies.targets", '/v:minimal', '/nologo' ) & $dotnet msbuild "$repo\src\modules\AdvancedPaste\AdvancedPaste.CLI\AdvancedPaste.CLI.csproj" @buildArgs & $dotnet msbuild "$repo\src\modules\AdvancedPaste\AdvancedPaste.Cli.UnitTests\AdvancedPaste.Cli.UnitTests.csproj" @buildArgs ``` **Both passed, exit 0.** `SkipLongPathsCheck` is the existing developer option; the machine-wide long-path registry setting was not modified. ### Tests and executable smoke checks ```powershell Set-Location "$repo\x64\Release\tests\AdvancedPaste.Cli.UnitTests" & $dotnet '.\AdvancedPaste.Cli.UnitTests.dll' --filter 'FullyQualifiedName~ProgramTests' --report-trx ``` **Passed, exit 0: 91/91, zero skipped.** ```powershell & $dotnet '.\AdvancedPaste.Cli.UnitTests.dll' --report-trx ``` **Passed, exit 0: 151/151, zero skipped**, including the nine additional regression cases. ```powershell & "$repo\src\modules\AdvancedPaste\AdvancedPaste.CLI\SmokeTest.ps1" ` -Executable "$repo\x64\Release\WinUI3Apps\PowerToys.AdvancedPaste.Cli.exe" ``` **Passed, exit 0:** existing executable smoke checks for help, stdin/stdout, file conversion, JSON output, conflicting input modes, and unsupported actions. Unchanged runtime dependencies and `PowerToys.AdvancedPaste.pri` were supplied from the same successful CI build. No real clipboard writes or AI-provider calls were performed. ```powershell git -C D:\PT102-CommandLineFix diff --check ``` **Passed.** ARM64 compilation, UI automation, a clean native dependency build, and an official signed release build were **not completed locally**. Public PR CI remains the full integration gate. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> (cherry picked from commit 31de368)

Summary of the Pull Request
Add a true headless Advanced Paste CLI (Closes #49902). The PATH-visible
PowerToys.AdvancedPaste.CLI.exeshim launches the self-containedWinUI3Apps\PowerToys.AdvancedPaste.Cli.exe, which calls a shared Advanced Paste action engine directly.The CLI does not open the Advanced Paste window, communicate with Runner, or simulate keyboard input. The UI and CLI share the existing
DataPackageView -> DataPackagetransformation pipeline, AI provider configuration, policy checks, Credential Vault integration, OCR, file generation, and media transcoding.PR Checklist
Command Surface
Clipboard is the default input and output when their respective options are omitted. Choose at most one input mode (
--input,--stdin, or--clipboard) and at most one output mode (--output,--stdout, or--output-clipboard); conflicting modes return exit 2 before clipboard access. Piped text requires--stdinand does not override the clipboard default.--formatremains an alias for--action.Built-in actions:
plain-text,markdown,jsonfix-spelling-and-grammar,paste-with-aiimage-to-textpaste-as-txt-file,paste-as-png-file,paste-as-html-filetranscode-to-mp3,transcode-to-mp4Saved custom actions can be selected by ID or case-insensitive name. AI actions use the configured provider by default. A provider is a configured AI service/model entry, not a built-in action; run
providers listto discover its ID.--provider <id>applies only topaste-with-ai,fix-spelling-and-grammar, and saved custom actions. IDs are case-insensitive; unknown explicit IDs return exit 2 rather than silently falling back. Existing GPO/provider checks apply to the actual resolved provider, including nested tools and cached action chains.Example PowerShell Session
Visual Evidence
This is a CLI-only feature with no visible changes to the Advanced Paste window.
The simulated PowerShell session above demonstrates the user-visible command surface,
clipboard behavior, file generation, AI/custom actions, JSON output, and exit codes.
Exit codes are
0for success,1for input/I/O/clipboard/provider/transformation failures, and2for parser or validation errors. Text input is bounded to 16,777,216 characters. Raw input, prompts, and transformed output are never logged.CLI usage telemetry follows the existing PowerToys CLI pattern.
AdvancedPaste_CLICommandrecords only a bounded command name (
transform,actions list,providers list,help, orunknown)and whether the invocation succeeded. It never records action/custom-action names,
providers, prompts, paths, clipboard/input content, or transformed output.
Refactor and Layered Architecture
The implementation deliberately keeps the existing
DataPackageView -> DataPackageaction pipeline rather than translating every action into a new CLI-specific model.
This minimizes regression risk for the WinUI app and avoids duplicating AI, OCR,
file-generation, and transcoding behavior.
Shared action layer
AdvancedPaste.Engineowns the existing non-UI helpers, models, settings,providers, policy checks, telemetry types, and action services.
excluded from duplicate compilation in the app; action internals were not
rewritten for the CLI.
AddAdvancedPasteEngine()centralizes service registration so the WinUI appand CLI resolve the same executor, AI providers, settings, Credential Vault
integration, moderation, caching, and transformations.
IPasteFormatExecutornow receives aDataPackageViewexplicitly instead ofreading the system clipboard internally. The WinUI app still passes
Clipboard.GetContent()at its existing call site, preserving UI behavior.AdvancedPastePolicy, so the UIand CLI enforce the same policy decisions.
CLI input, runtime, and output layers
CliInputReaderadapts exactly one of stdin, a file, or the rich Windowsclipboard (default) into
DataPackageView. Text/HTML and storage-item formats arepreserved for actions that need them.
AdvancedPasteRuntimeresolves built-in actions, saved custom actions, prompts,and configured provider overrides, then delegates to the shared executor.
CliOutputWriterroutes text or generated-file results to the clipboard,stdout, or an explicit output path. It rejects incompatible combinations such
as sending a generated file to stdout.
SystemClipboardAdapteruses the full-trust Win32/OLE clipboard on an STAthread, preserving text, HTML, bitmap, and file-drop formats without requiring
a foreground app window.
references survive CLI exit; copied outputs are cleaned immediately and stale
clipboard files are cleaned only when clipboard input supplies a snapshot, protecting its original file-drop paths and the selected output directory. Ownership markers prevent cleanup
from deleting unrelated directories that happen to share the temp prefix.
destination only after a successful write, so cancellation does not leave a
partial result or destroy an existing destination.
policy before running actions. It does not create a file watcher for settings
in its short-lived headless process.
Packaging and process model
PATH-visible
PowerToys.CliShim.exemapping.such as Phi Silica can use the same integration as the app.
Validation Steps Performed
AdvancedPaste.CLI,AdvancedPaste.Engine, the Advanced Paste WinUI app, both unit-test projects,CliShim, andPackageIdentitywith repository build scripts on currentmain(x64 Debug).bounded file input, output cancellation/atomicity, temp-file ownership,
startup errors, clipboard retry/STA behavior, redirected Unicode input,
cancellation-aware CSV parsing, and privacy-safe CLI telemetry.
SmokeTest.ps1andE2E\Run-E2E.ps1passed against the updated branch.CIBuild=true), the Advanced Paste WinUI app, and CliShim.git diff --checkis clean.Temporary clipboard-history UI-test quarantine
Only these four methods in
AdvancedPasteClipboardHistoryTests.cshave amethod-level
[Ignore]with a shared explanation:SelectingANonFirstEntryUpdatesClipboardWithoutChangingHistoryIdentityDeletingAnEntryRemovesOnlyItsExactWindowsHistoryIdDisablingClipboardHistoryThroughSettingsHidesHistoryAccessFullHistoryCanBeResetBeforeAddingNewFixtureEntriesIn CI build 390487,
the Windows 11 history fixture copies text successfully to the current clipboard,
but Windows history never captures the entry. Subsequent fixtures cannot enable
history. The same failures recur on different workers and independent PRs
(builds 390445, 390416, and 390420); the exact service, policy, or fixture-activation
cause is not yet established. This is a temporary coverage reduction, not a fix
for the underlying clipboard-history setup failure.
These four methods are skipped on every OS and architecture, not just Windows
11. The class and categories are not ignored; all other tests remain enabled,
and pipeline behavior and production code are unchanged. Before this quarantine,
build 390487 passed the other 64 UI cases on Windows 11 and all 68 on Windows 10
and ARM64. Re-enable the four methods once CI clipboard-history activation and
capture are reliable, including repeated enable/disable and restoration.
The UI-test project was rebuilt successfully for x64 Release after this change.
The UI suite was not rerun locally for this quarantine.
AI/custom-action success depends on a configured provider and credentials. MP4 uses the unchanged UI transcoding implementation; a local video fixture was not available for an additional process-level smoke test.
Clipboard Input Follow-up
Commit
78cff9c3fbmakes omitted input options select the clipboard, matching the existing clipboard output default. It also fixes Explorer file copies: a single copied CSV/text/HTML file is read with the same bounded reader as--input, so CSV-to-JSON and HTML-to-Markdown work without opening the file to copy its text.Existing clipboard text, HTML, or bitmap takes precedence. Images/media and malformed UTF-8 retain file representations; folders and multiple-file selections are not combined or converted to text. Text files do not advertise image attachments. Cleanup still protects paths from the original clipboard snapshot after file content is normalized, and explicit file/stdin commands and action listing do not read the clipboard.
Latest validation: rebuilt the x64 Debug CLI/UI dependency chain, passed all 95 targeted input/parser/clipboard/cleanup unit cases and the non-clipboard fixture E2E suite, and reproduced then exercised the copied demo CSV with explicit and default clipboard input. The CSV remained unchanged and stdout examples did not write the clipboard. Real provider traffic and destructive clipboard-history checks were not performed for this follow-up.
Provider Routing, Discovery, and Help Follow-up
Commit
ad5fe5f615fixes nested Advanced AI tools and cached action chains silently reverting to the active provider instead of the invocation's selected provider. The resolved provider is stored per kernel invocation, including concurrent calls. Shared services enforce its policy before credential access, moderation, provider creation, or network requests. Policy denials remain terminal even if an assistant recovers from a tool error or another tool has produced output. The CLI returns a stableaction_unavailableerror for these denials. Existing UI behavior for removed saved-provider IDs remains unchanged.providers list [--json]exposes configured IDs, names, service types, models, default status, and policy availability without reading the clipboard, contacting providers, or exposing credentials, endpoints, or system prompts. Provider setup remains in PowerToys Settings > Advanced Paste; this PR does not add AI setup/enablement commands.Root, transform, and actions-list help describe every built-in action. Transform help covers AI-only provider overrides, provider/custom-action discovery, clipboard defaults, mutually exclusive I/O modes, generated-file limitations, JSON output, cancellation, input limits, exit codes, and runnable examples. Built-in action listings also include descriptions. Help writes through the selected output stream and remains available without creating an application host or reading settings.
Final validation for this follow-up:
doc/devdocs/cli-conventions.md: System.CommandLine parsing, brief root description, kebab-case options, complete help, outer startup exception handling, dedicated early logging, privacy-safe dual console/log errors, exit codes, self-contained properties, signing entries, CLI shim mapping, and matching WiX references are wired consistently. Help/setup exceptions are now inside the startup catch; error logging records bounded codes rather than raw input/output.This audit verifies source integration and exercised x64 behavior, not a full installer run or ARM64 runtime certification. Those deployment checks, the existing clipboard-history quarantine, and provider-dependent/manual UI scenarios remain outstanding as described above.