Task API Reference

Reference for repository task descriptors, invocation types, host evidence APIs, app-tool suites, result envelopes, and named assertions.

CLI v0.23.1

Repository tasks use the generated ansight/tasks/ansight-task.d.ts contract. That declaration file is the authoritative API for the installed Ansight version; this page is its navigable reference.

Run ansight workspace init . to create or refresh the declaration in a new workspace. Existing customized support files are preserved unless --force is supplied.

Module shape

Every task exports a JSON-compatible descriptor and one default function:

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

type Input = { automationId: string };
type Output = { matchCount: number };

export const task = {
  schemaVersion: 1,
  title: "Verify home",
  description: "Proves that the signed-in home screen is visible."
} satisfies TaskDefinition;

export default async function run(
  { run, input, ansight, app, check }: TaskInvocation<Input>
): Promise<Output> {
  const result = await ansight.ui.assert({
    automationId: input.automationId,
    exists: true
  });

  check.ok(result.passed, "home-visible");
  return { matchCount: result.matchCount };
}

TaskDefinition

FieldTypeRequiredContract
schemaVersion1NoDefaults to version 1.
appIdstringNoExact optional app scope.
titlestringYesShort discovery label.
descriptionstringYesComplete workflow and authoritative result.
featurestringNoFocused discovery domain such as map.
keywordsstring[]NoAt most 32 discovery terms.
inputSchemaJsonSchemaNoValidates the object supplied as input and applies defaults.
outputSchemaJsonSchemaNoDescribes returned output; version 1 does not enforce it.
hostToolsstring[]NoExtra Studio tools callable through ansight.callTool; maximum 32.
timeoutSecondsnumberNoWhole run: 1–300 seconds; default 120.
maximumActionsnumberNoHost and app calls: 1–100; default 64.

The descriptor must be a static object literal. Do not use functions, variables, spreads, or computed values inside it.

TaskInvocation<TInput>

PropertyTypeMeaning
runReadonly<TaskRun>Host-owned run identity and effective limits.
inputReadonly<TInput>Validated input after schema defaults are applied.
ansightAnsightHostSession-pinned host evidence and control methods.
appTaskAppContextStandard app-tool suites and custom-tool bridge.
checkTaskCheckContextNamed assertions that establish pass or failure.

TaskRun

PropertyTypeMeaning
runIdstringUnique run ID.
taskIdstringRepository-relative task ID.
appIdstringExact app scope enforced by the host.
sessionIdstringLive session enforced for every call.
repositoryRootPathstringAbsolute connected repository root.
timeoutSecondsnumberEffective whole-task timeout.
maximumActionsnumberEffective action limit.

ansight: host API

Host methods are bound to run.sessionId. Target fields supplied by task code are discarded and the selected session is injected.

NamespaceMethodsMain result contracts
ansight.sessiongetAppState(), getProperties<T>(), getTimeline(args?)SessionAppStateResult, SessionPropertiesResult<T>, SessionTimelineResult
ansight.uifind(args?), waitFor(args?), assert(args?), tap(args?), typeText(args), swipe(args?), scroll(args?), back(args?), getLiveVisualTree(args?), getVisualTreeSnapshot(args?), searchVisualTree(args?)UiFindResult, UiWaitResult, UiAssertResult, UiActionResult, visual-tree contracts
ansight.logsget(args?), search(args), getContext(args?), getFacets(args?), getTimeline(args?), summarizeWindow(args?), extractExceptions(args?)Captured log, context, facet, timeline, summary, and exception contracts
ansight.artifactsgetNearest(args?), getSession(args?), listFiles(args?), readFile(args)Artifact descriptor and file contracts
ansight.screenshotstake(args?), getFrame(args?), assert(args?)Live capture envelope, persisted frame, and screenshot assertion
ansight.databaseassert(args)DatabaseAssertResult
ansight.telemetryget(args?), getTimeline(args?), summarizeWindow(args?)Telemetry samples, timeline, and summary
ansight.touchesgetTimeline(args?), getContext(args?), getGestureSegments(args?), findTapTargets(args?), getHeatmap(args?), findDead(args?), getArtifacts(args?), summarizeFlow(args?)Touch, gesture, heatmap, dead-touch, evidence, and flow contracts
ansight.annotationsget(args?)AnnotationsResult
ansight.appToolslist()AppToolListResult
ansight.lifecyclelaunch(), terminate()AppLifecycleResult
ansight.devicesetLocation(args), clearLocation()Device location results
ansightcallTool<TResult>(name, args?)Structured result of an extra declared host tool

UI selectors

UiSelector is shared by find, wait, assert, and UI actions:

interface UiSelector {
  nodeId?: string;
  automationId?: string;
  text?: string;
  role?: string;
  type?: string;
  ancestorAutomationId?: string;
  action?: string;
  visible?: boolean;
  enabled?: boolean;
  exact?: boolean;
  caseSensitive?: boolean;
  index?: number;
}

Use ansight.ui.assert for evidence-producing expectations and waitFor for a bounded state transition. UiAssertArguments additionally supports expectedCount, expectedText, expectedValue, expectedVisible, expectedEnabled, and an optional actionId.

Time windows

Log, telemetry, touch, annotation, artifact, and timeline methods accept their typed argument contracts from ansight-task.d.ts. Time-bound contracts use ISO-8601 UTC timestamps and bounded result limits. Prefer typed methods over ansight.callTool because they inject the task session and return stable named contracts.

app: live app API

Every standard app method returns Promise<AppToolCallResult<TResult>>. The host pins the request to the task session, while the connected app enforces tool availability, grants, argument schemas, and critical-operation policy.

NamespaceMethods
app.artifactsquery(args?), request(args)
app.uigetVisualTree(args?), getScreenshot(args?), inspectNode(args?), showOverlay(args?), getOverlay(args?), queryOverlays(args?), updateOverlay(args?), removeOverlay(args?), clearOverlays(args?)
app.fileslistDirectory(args?), readFile(args?), getChecksum(args?), download(args?), beginBinaryDownload(args?), push(args?), copy(args?), move(args?), delete(args?)
app.fileDescriptorslistOpen(args?), countOpen(args?), inspect(args?), getUsage(args?)
app.jniReferencescaptureGraph(args?)
app.preferenceslistKeys(args?), get(args?), set(args?), remove(args?)
app.secureStorageget(args?), set(args?), remove(args?)
app.datalistDatabases(args?), describeSchema(args?), query(args?)
app.reflectionlistRoots(args?), inspectObject(args?), describeType(args?), setMemberValue(args?), invokeMethod(args?)
app.mauigetCurrentPage(args?), getVisualTree(args?), findElements(args?), getElement(args?), getBindableProperty(args?), setBindableProperty(args?), clearBindableProperty(args?), inflateXaml(args?), addElement(args?), removeElement(args?), setAppTheme(args?), getBindingContext(args?), getBindings(args?), getResourceState(args?), getNavigationState(args?), invokeElementAction(args?), waitForUi(args?), getLayoutDiagnostics(args?), getHandlerDiagnostics(args?), invokeBindingContextCommand(args?), setBindingContextProperty(args?)
app.reactgetComponentTree(args?), getShadowTree(args?), findComponents(args?), getComponent(args?), getNavigationState(args?), invokeComponentAction(args?)
app.fluttergetWidgetTree(args?), inspectWidget(args?), findWidgets(args?), getNavigationState(args?)
app.capacitorgetDocument(args?), inspectNode(args?), querySelector(args?), invokeAction(args?)
appcallTool<TResult>(toolId, args?) for an app-defined tool

Standard suites require the corresponding SDK tool registration. A method can exist in the TypeScript contract while being unavailable in the selected app or denied by its runtime guard.

AppToolCallResult<TResult>

App results use a discriminated envelope:

type AppToolCallResult<TResult> =
  | {
      responseType: "tool.result";
      sessionId: string;
      appId: string;
      toolId: string;
      payload: {
        success: true;
        toolId: string;
        result: TResult;
        message?: string | null;
      };
    }
  | {
      responseType: "tool.error";
      sessionId: string;
      appId: string;
      toolId: string;
      payload: {
        success?: false;
        code: string;
        message: string;
        retryable: boolean;
        details?: JsonValue | null;
      };
    };

The full envelope can also contain Studio-applied defaults, associated artifacts, and persisted-visual-tree metadata. Narrow on responseType before reading the typed success result.

check: named assertions

MethodBehavior
check.ok(actual, id, message?)Passes for a truthy value; returns the non-null value.
check.equal(actual, expected, id, message?)Uses deterministic deep equality.
check.notEqual(actual, expected, id, message?)Requires deterministic inequality.
check.includes(actual, expected, id, message?)Checks string inclusion or exact array membership.
check.fail(id, message, actual?)Records failure and terminates the function.

Assertion IDs must be stable and unique. At least one assertion must pass and none may fail for the task status to be Passed. Returning normally without an assertion produces Inconclusive.

Execution rules

  • Await host and app calls serially; overlapping calls are rejected.
  • Standard host APIs need no hostTools declaration.
  • ansight.callTool accepts only names declared in task.hostTools.
  • app.callTool targets app-defined tools and needs no descriptor declaration.
  • Every call counts toward maximumActions.
  • Tasks can access only the enforced live session through Ansight APIs.
  • Repository TypeScript is trusted local code, not a filesystem or network sandbox.