Task API Reference

Choose task APIs by iOS or Android, virtual or physical device, SDK or device mode, and app framework.

Repository tasks execute known operations against one live Ansight session and prove their outcome with named assertions. Start here to choose compatible APIs, then use the focused references for arguments, results, and examples.

Tasks use the generated ansight/tasks/ansight-task.d.ts contract. ansight workspace init . installs the support files; existing files are preserved unless --force is supplied. Author against your installed CLI’s declaration and check the availability notes below before choosing a method.

Compatibility

Four independent choices determine what a task can do:

DimensionValuesWhat it controls
Platformios, androidNative operations, permission names, and platform tools
Device kindvirtual, physicalSimulator/emulator features versus real hardware
Execution modesdk, deviceConnected SDK tools versus external automation
App frameworkMAUI, React Native, Flutter, Capacitor, native, and other declared framework valuesFramework-specific inspection and actions

Virtual means an iOS Simulator or Android Emulator. Physical means a real iPhone/iPad or Android device. Either kind can use SDK mode; device mode also supports both kinds when the external provider is configured. run.executionMode === "device" does not mean a physical phone.

TargetExternal/device-mode providerSDK-mode app tools
iOS SimulatormacOS, Xcode, simulator capture and inputRegistered iOS/framework SDK tools
Physical iOSAppium/XCUITest and signed WebDriverAgentRegistered iOS/framework SDK tools
Android EmulatorADB and emulator toolingRegistered Android/framework SDK tools
Physical AndroidAuthorized ADB device and UIAutomatorRegistered Android/framework SDK tools

SDK pairing does not provision host input, permission, or simulation tools. See capture modes and external monitoring setup for prerequisites.

Check mode and method support separately

Use schemaVersion: 1, or omit it, in either mode. Declare essential requires.capabilities and requires.appTools so the host checks the selected session before importing the module. Omitting requirements does not imply an SDK dependency or grant access to every API: individual methods still enforce platform, device, and provider restrictions.

API familySDK modeDevice mode
Visible UI actions, keyboard, live screenshotsSupported provider requiredSupported provider required
Lifecycle and native permissionsPlatform/device restrictionsPlatform/device restrictions
Logs, telemetry, retained artifacts and annotationsAvailable evidenceAvailable evidence
External sandbox ansight.filesUnavailableSupported external file provider
SDK app.* tools and framework navigationRegistered, executable app toolsUnavailable
Location, motion, audio, network conditioningSupported virtual targetCurrently unavailable to task calls
HTTP, connectivity and touch readers; database and screenshot assertionsRelevant provider/data requiredCurrently unavailable to task calls

The ansight prefix means a host API, not that it works without the SDK. Broad capabilities such as lifecycle or evidence.read do not guarantee every method in a family. The host method index labels individual mode restrictions. The device support matrix distinguishes iOS/Android and virtual/physical support per operation.

For example, clearLocation() is iOS Simulator only, playAccelerometer() is Android Emulator only, and native permission control supports physical Android but not physical iOS. Framework suites require their matching SDK adapter, regardless of whether the device is virtual or physical.

Module shape

Every task exports a static descriptor and one default function. This example supports SDK or device sessions with semantic UI support:

import type { TaskDefinition, TaskInvocation } from "./ansight-task.d.ts";

export const task = {
  "schemaVersion": 1,
  "title": "Verify home",
  "description": "Proves that the signed-in home screen is visible.",
  "startingState": "The app is signed in and showing its home screen.",
  "successState": "The home screen remains visible.",
  "platforms": ["ios", "android"],
  "deviceKinds": ["virtual", "physical"],
  "requires": { "capabilities": ["ui.semantic"] }
} satisfies TaskDefinition;

export default async function run({ ansight, expect }: TaskInvocation) {
  const result = await ansight.ui.assert({
    automationId: "home",
    exists: true,
    expectedVisible: true
  });
  expect(result.passed, { id: "home-visible" }).toBe(true);
  return { matchCount: result.matchCount };
}

Replace home with an ID observed in the selected provider’s UI tree. The task does not sign in or navigate automatically: state hints describe prerequisites and outcomes, and the assertion verifies them. Await host and app calls serially. A normal return without a named assertion is Inconclusive.

Find a reference

Existing links to sections of this page lead to the corresponding reference below.

ReferenceTopics
Task Definition and ExecutionComplete descriptor fields, TaskInvocation, TaskRun, secrets, target constraints
Requirements, composition and assertionsCapability checks, child tasks, named expect, result status, execution limits
UI AutomationSelectors, accessibility and SDK trees, gestures, keyboard, screenshots
Device ControlsSupport matrix, lifecycle, permissions, location, motion, audio, network conditioning
EvidenceFiles, spans, HTTP, connectivity, logs, telemetry, artifacts, annotations
App Tool APICommon SDK suites, framework-specific tools, registration and result handling
Host API MethodsComplete host-method index with execution-mode availability

ansight: host API

ansight methods run through the resident host and are pinned to run.sessionId. Target overrides from task code are discarded. Standard typed methods need no hostTools declaration. ansight.callTool<TResult>(name, args?) is for extra task-callable host tools explicitly named in the descriptor.

Host methods return inspection data or action results; check their relevant fields with a named assertion. Read the method index and the focused UI, device, and evidence references above.

app: live app API

app.available indicates whether an SDK tool provider is connected. Each app.* method additionally needs the tool to be registered, granted, and executable. Use ansight.appTools.list() to discover exact tool IDs and schemas; declare essential IDs in requires.appTools in the task descriptor.

app.maui, app.react, app.flutter, and app.capacitor require their matching framework adapter. app.jniReferences is Android-specific. Common SDK suites and their availability are described in the App Tool API.

App methods return AppToolCallResult<TResult>; narrow on responseType before reading payload.result. See the result envelope.