Clipboard Tools

Read, check, set, and clear the connected app device clipboard through guarded Ansight remote tools.

Clipboard tools operate on the connected app device’s system clipboard through the Ansight remote-tool transport. They do not access the developer workstation clipboard and do not depend on simctl, ADB, or an emulator service.

Tool Contract

Tool IDArgumentsSuccessful resultPolicy
clipboard.get_text{}{ "text": string or null, "hasText": boolean }Read
clipboard.has_text{}{ "hasText": boolean }Read
clipboard.set_text{ "text": string }{ "updated": true }Write
clipboard.clear{}{ "cleared": true }Write

Text is preserved exactly, including whitespace, Unicode, and empty strings. Reads and writes reject values larger than 65,536 UTF-8 bytes with clipboard_text_too_large; content is never truncated. An empty string is text and is distinct from clearing every clipboard item. Rich content, images, and URI coercion are outside this API.

Registration

The all-in-one SDK remote-tool suites include Clipboard. Existing tool guards still apply: read-only access can inspect the clipboard but cannot set or clear it.

SDKStandalone registrationAll-in-one behavior
.NET / MAUIAdd Ansight.Tools.Clipboard, then call WithClipboardTools()Included by WithAnsightSdk() and WithAnsightMaui()
AndroidAdd ai.ansight:ansight-tools-clipboard-android, then call withClipboardTools()Included by ai.ansight:ansight-android
iOS / SwiftAdd AnsightToolsClipboard, then call registerClipboardTools()Included by Ansight; omit with AnsightRemoteToolOptions(clipboard: false)
React NativeNative bridge registration; use withClipboardTools(false) to omitIncluded by native remote tools
FlutterConfigure AnsightRemoteToolsOptions(clipboard: false) to omitIncluded by native remote tools
Cordova / CapacitorSet remoteTools: { clipboard: false } to omitIncluded by native remote tools

.NET

dotnet add package Ansight.Tools.Clipboard --version 1.5.0
using Ansight.Tools.Clipboard;

var options = Options.CreateBuilder()
    .WithClipboardTools()
    .WithReadWriteToolAccess()
    .Build();

Android

dependencies {
    debugImplementation("ai.ansight:ansight-tools-clipboard-android:1.5.0")
}
val options = AnsightOptions.createBuilder()
    .withClipboardTools()
    .withReadWriteToolAccess()
    .build()

iOS

import AnsightCore
import AnsightToolsClipboard

try AnsightRuntime.shared.registerClipboardTools()

SwiftPM and CocoaPods both publish AnsightToolsClipboard at version 1.5.0.

Calling from the CLI

Query a connected session with the stable tool IDs. Write operations still depend on the app’s configured tool guard.

ansight app call <session-id> clipboard.get_text --arguments-json '{}' --json
ansight app call <session-id> clipboard.set_text \
  --arguments-json '{"text":"Hello from Ansight"}' --json
ansight app call <session-id> clipboard.clear --arguments-json '{}' --json

Tasks and Triggers

Workspace tasks expose the suite as app.clipboard:

await app.clipboard.setText({ text: "  Hello 世界\n" });
const response = await app.clipboard.getText();

if (response.responseType === "tool.result") {
  expect(response.payload.result.text, { id: "clipboard.text" })
    .toBe("  Hello 世界\n");
}

await app.clipboard.clear();

Task methods return the normal AppToolCallResult<T> envelope. Trigger methods construct a declarative AppToolAction. The host and app SDK must both contain Clipboard support; updating the host does not add the tools to an older app.

Platform Behavior

  • Android uses ClipboardManager. The app window must have input focus. True clearing requires Android API 28 or later.
  • iOS and Mac Catalyst use UIPasteboard on the main thread. The app must be active, and a read can invoke the operating system’s paste-permission flow.
  • Native macOS Swift uses NSPasteboard on the main thread.
  • Generic .NET can compile against the package but returns clipboard_platform_unsupported at runtime.

Clipboard operations are explicit: the SDK does not monitor, synchronize, or retain clipboard history. Host diagnostics redact text read or written by these tools, but task authors should still avoid persisting sensitive values in assertions or task output.