Turn repeatable app workflows into reusable tasks
Run known app workflows on demand with consistent steps, explicit checks, and results that people and agents can inspect.
Capture a workflow once so you or your coding agent can repeat it without working out the same steps each time. Repository tasks run known operations against a live app and check the outcome with named assertions. You can write a task directly or extract a draft from a recorded session and add the checks that establish success.
We recommend using the task extractor in the local Ansight host to extract or author tasks. Describe the workflow, inputs, and expected outcome, then review and edit the generated TypeScript, test it against a connected app, and save it to your workspace. The extractor uses session evidence and available task APIs to help turn your instructions into a reusable task.
A task is trusted local TypeScript, invoked explicitly by a user, agent, or CLI through its exact ID. It never runs in the background.
Use a task when the required steps and tool calls are already understood—for
example, query every map annotation and assert that the expected areas exist.
Use a workspace test with taskId and no prompt to
run that task with test-runner app launch, suites, and reporting. Add prompt
when a model should navigate and reason through a complete user journey.
To reuse tasks as required setup, list them under a test’s
preTasks. They run in
order once the app session is connected, and every setup task must pass before
the prompt or main task starts. Each entry can supply its own input mapping.
Create a task
Recommended: use the local host task extractor
Open the local host:
ansight host run --open
Link the app to its workspace, then open a live or recorded session that provides context for the task you want to create:
- Select the relevant timeline period and choose Extract test or task.
- Choose Ansight task. In What should the agent extract?, describe the behavior to author, the required starting state, any reusable inputs, and the assertions that will prove success. You can ask it to preserve a recorded interaction or author a task using the available app tools and evidence.
- Choose a reasoning mode and select Start agent extraction. The agent inspects the selected evidence, available tool references, and workspace support modules to write and validate the task.
- Review and edit the TypeScript in the task editor. Resolve diagnostics and check that the assertions verify the intended product outcome.
- Choose a connected session, supply task input if needed, and select Test draft. Once you have reviewed the result, choose Save to ansight/tasks.
For example, ask: “Use the app’s map tools to query every annotation, accept
the expected area names as task input, and assert that each area exists.”
Reference a published tool or artifact by typing @ in the instructions when
those references are available.
AI authoring requires a configured model provider. The generated task is still ordinary TypeScript: subsequent task runs execute its code without an AI authoring pass. A recorded session is enough to prepare the draft; testing it requires a connected app.
Author a task manually
Task modules live beneath ansight/tasks. A module’s relative path becomes its
ID: ansight/tasks/map/validate-areas.ts becomes map.validate-areas.
Only a .ts file that exports the static task descriptor is discovered as a
task. Other .ts and .d.ts files beneath ansight/tasks are support modules,
so task modules can import shared domain types and helper functions without
creating phantom tasks or discovery warnings. Session extraction also makes
these support modules available to its agent, compiler, and TypeScript editor so
generated tasks can reuse the workspace’s existing APIs.
To start from a template and write the task yourself, use the CLI:
ansight workspace add task . home.verify --app-id com.example.app
This also initializes the workspace support files if they do not exist yet.
Edit the generated TypeScript to define the steps and the check that proves the
result. For a custom title or description in the starter file, add --title
or --description when creating it.
You can also review discovered tasks from the local player’s Tests area.
Review the complete TypeScript declarations and task descriptor schema online, or download them from the source viewer.
Extract a task from a session
Use timeline extraction when a recorded session contains a specific interaction you want to preserve as a repeatable task. We recommend the local host task extractor for AI analysis, task authoring, editing, and testing in one place. Review the draft’s starting state and assertions before relying on it.
CLI extraction
The CLI can also generate a programmatic TypeScript draft from recorded interactions. This command does not run the local host’s AI task-authoring agent; use the local host workflow above when you want AI to author the task.
Find the recorded session and inspect the evidence around the behavior:
ansight session list --app-id com.example.app
ansight session show <session-id>
ansight session touches <session-id>
ansight session trees <session-id>
ansight session images <session-id>
Select a tight interval and pass its bounds as non-negative seconds from session start or as ISO-8601 timestamps:
ansight task extract <session-id> \
--start 12.5 \
--end 24.8 \
--workspace . \
--title "Complete checkout"
By default, the CLI writes a slugged TypeScript file to
ansight/tasks/<suggested-name>.ts. Use --output <path> to choose an exact
destination. Existing files are preserved unless you explicitly pass --force
(--overwrite is an alias). --repository <path> is accepted as an alias for
--workspace <path>.
The programmatic CLI extractor:
- groups the selected touch events into gestures;
- retains host-issued taps, long presses, Enter presses, and editor submissions from the
session’s action records, including injected taps with only an SDK
downevent; matching SDK touches do not create a second action; - generates taps and long presses only when nearby visual-tree evidence provides a stable automation ID or text selector;
- derives text changes from actual input values in retained trees, including empty strings; labels and placeholders are never treated as entered text;
- converts drags into directional swipe actions;
- preserves long-press hold durations from 500 through 10000 ms;
- reports unsupported hold durations, multi-touch, incomplete gestures, ambiguous
targets, and missing selectors as
REVIEW:diagnostics; and - adds a provisional final UI-stability assertion.
Recorded long presses become ansight.ui.longPress(...)
actions. Hold durations outside the supported range produce a review diagnostic
instead of a shortened gesture. A stationary hold remains one gesture even when
it emits no move events.
Host action recording applies to new sessions captured with an updated host.
Successful Enter and submit operations become ansight.keyboard.press({ key: "Enter" }) and ansight.keyboard.submit() in the draft. Failed or interrupted
delivery attempts produce review diagnostics. Include the complete action and
its surrounding UI evidence in the selected interval.
This records actions issued through Ansight’s UI and keyboard APIs. It does not automatically capture every manually pressed Search, Done, or Return key, and the extractor does not guess a submission from keyboard dismissal or a screen change. Older sessions without action records still use their existing touch and tree evidence.
The host action record contains timing, delivery status, an optional input point,
the requested long-press duration, and a link to UI evidence. It does not retain typed text. Text replay depends on
readable values already retained in the session; missing or redacted values
require explicit task input. Updated SDK tree providers preserve empty fields
as value: "", separately from their placeholders.
Open the generated file and resolve every diagnostic. Confirm or encode the required starting state, simplify selectors where necessary, and replace the provisional stability check with named assertions for the product outcome you actually care about. Extraction reads the stored session; the live app is only needed when you test the generated task.
npx tsc -p ansight/tasks/tsconfig.json
ansight task run <generated-task-id> \
--app-id com.example.app \
--repository . \
--session-id <connected-session-id>
The extraction command and every option are also listed in the CLI command reference.
Export a Maestro flow from a session
We recommend the local host’s extractor for creating a Maestro flow. Select a timeline period, choose Extract test or task, select Maestro flow, and choose Generate with AI. Add optional generation notes for the starting state, important steps, or expected outcome, and select a reasoning mode.
AI is the default in the local host UI. It analyzes the recorded journey, annotations, UI trees, and retained screenshots to author selectors, waits, and supported outcome assertions. Generation shows progress and checks the returned YAML, with repair attempts for invalid output. A configured model provider is required; a failed AI request is reported without silently returning a programmatic draft.
Review and edit the YAML, resolve any REVIEW: comments, and check the starting
state and product-outcome assertions. Use Validate, then Play test on a
connected device, and save the reviewed flow to the app’s registered workspace.
For AI extraction from the CLI, include --ai:
ansight task extract <session-id> \
--start 12.5 --end 24.8 \
--format maestro --ai \
--workspace . \
--title "Complete checkout"
The default destination is .maestro/<suggested-name>.yaml. Use --output for
another path and --force to replace an existing file. --reasoning fast,
balanced, or deep selects the configured reasoning mode; --model supplies
an optional model override.
AI remains opt-in on the CLI. Without --ai, the command generates a
programmatic draft from captured taps, drags, and visual-tree input changes.
Review selectors, coordinate fallbacks, and uncertain text changes in either
case. Run the reviewed flow on a connected device with
maestro test .maestro/<suggested-name>.yaml.
Export an Appium script from a session
We recommend the local host’s extractor for creating an Appium test. Select a timeline period, choose Extract test or task, select Appium test, and choose Generate with AI. AI generation is the default here too, using the recorded journey, annotations, UI trees, and retained screenshots. Generation notes and reasoning settings work the same way as for Maestro.
The result is a JavaScript test using WebdriverIO and Appium. Generation checks the recorded app ID and JavaScript syntax and asks the model to repair invalid output. Syntax validation does not execute the script or establish that it passes on a device. Review and edit the draft, use Validate and Play test, then download it or save it to the app’s registered workspace.
For AI extraction from the CLI, include --ai:
ansight task extract <session-id> \
--start 12.5 --end 24.8 \
--format appium --ai \
--workspace . \
--title "Complete checkout"
The default destination is appium/<suggested-name>.test.mjs. Use --reasoning
or --model to adjust AI generation. Without --ai, CLI extraction produces
the programmatic draft.
The draft maps recorded automation IDs to accessibility ID or Android resource
ID lookups, recorded labels to native text lookups, and taps and swipes without
stable targets to relative screen coordinates. Review the marked coordinates
and selectors, confirm the starting state, and verify or add the intended
outcome assertion. Set APPIUM_PLATFORM if the capture’s platform was unknown, and optionally set
APPIUM_SERVER_URL, APPIUM_UDID, or APPIUM_APP_ACTIVITY for your target.
After installing WebdriverIO and the appropriate Appium driver, run the script
with node --test appium/<suggested-name>.test.mjs.
Complete task example
Every task exports a static task descriptor and one default function:
import type { TaskDefinition, TaskInvocation } from "./ansight-task.d.ts";
type VerifyHomeInput = { automationId: string };
export const task = {
"schemaVersion": 1,
"title": "Verify signed-in home",
"description": "Checks that the signed-in home screen is visible.",
"feature": "onboarding",
"keywords": ["login", "home"],
"platforms": ["ios", "android"],
"deviceKinds": ["virtual", "physical"],
"frameworks": ["dotnet-maui"],
"inputSchema": {
"type": "object",
"properties": {
"automationId": {
"type": "string",
"default": "signed-in-home"
}
},
"additionalProperties": false
},
"outputSchema": {
"type": "object",
"properties": {
"matchCount": { "type": "number" }
},
"required": ["matchCount"],
"additionalProperties": false
},
"timeoutSeconds": 30,
"maximumActions": 1
} satisfies TaskDefinition;
export default async function verifySignedInHome(
{ input, ansight, expect }: TaskInvocation<VerifyHomeInput>
): Promise<{ matchCount: number }> {
const result = await ansight.ui.assert({
automationId: input.automationId,
exists: true,
expectedVisible: true
});
expect(result.passed, { id: "signed-in-home-visible" }).toBe(true);
return { matchCount: result.matchCount };
}
The descriptor must remain a JSON-compatible object literal. The host extracts it without importing or executing the module, so do not use variables, spreads, functions, or computed values inside the descriptor.
Descriptor fields
| Field | Required | Meaning |
|---|---|---|
schemaVersion | No | 1 (default). The same schema supports SDK and external device sessions. |
requires | No | Required capabilities and executable appTools IDs, checked before task code runs. |
enabled | No | Whether the task may run. Defaults to true; disabled tasks remain discoverable and reject execution. |
appId | No | Optional exact App ID scope. A registered host app or explicit CLI option normally supplies it. |
title | Yes | Short discovery label. |
description | Yes | Complete workflow and authoritative result. |
startingState | No | Advisory prerequisites, 1–1000 characters; task code must check them. |
successState | No | Advisory state established or preserved on success, 1–1000 characters; back it with named assertions. |
feature | No | Focused discovery category such as map or onboarding. |
keywords | No | Up to 32 focused search terms. |
platforms | No | Supported targets: ios, android, or both. Omit when platform-independent. |
deviceKinds | No | Supported targets: virtual, physical, or both. Omit when either kind works. |
frameworks | No | Supported app frameworks. Omit when framework-independent. |
inputSchema | No | Schema and defaults for the object passed as input. |
outputSchema | No | Discoverable description of the returned value. |
hostTools | No | Extra registered host tools used only through ansight.callTool; standard methods need no declaration. |
timeoutSeconds | No | Whole-run timeout from 1–300 seconds. Default: 120. |
maximumActions | No | Maximum Ansight, app, discovery, and child-task calls from 1–100. Default: 64. |
outputSchema is descriptive in contract version 1. The host exposes it during
discovery but does not reject a returned value that differs from the schema.
Target metadata is not task input. A workspace test links to the task with
taskId; the CLI runner validates these optional declarations before agent
execution. Framework values are dotnet-maui, dotnet-ios, dotnet-android,
react-native, flutter, capacitor, ios-uikit, ios-swiftui,
android-views, android-compose, and native-unknown.
Platform, virtual/physical device kind, SDK/device execution mode, and app framework are separate compatibility choices. See the Task API overview and Task Definition and Execution API for complete contracts and target examples.
Focused task discovery through ansight task list matches every query word against
the task ID, title, description, feature, keywords, and serialized declared
input schema. This includes property names, enum values, and defaults, so an
agent can find a task by a known input value even when that value is not repeated
in the title or keywords. Keep those values concise and domain-specific; every
query word must match the same task.
Input validation
Task input is always an object. Contract version 1 validates the root
properties, required, and additionalProperties fields, plus scalar
property type, enum, default, minimum, and maximum values. Defaults are
applied before the function starts.
Use a TypeScript type with TaskInvocation<TInput> so the editor understands
the validated input shape. The input and run objects passed to the function
are read-only.
Function API
The default function receives { run, input, secrets, ansight, app, expect }:
runidentifies the run, task, App ID, exact session, repository, timeout, and action limit.inputcontains validated input with defaults applied.secrets.get(alias)returns a value explicitly granted to the run, orundefined;secrets.require(alias)fails if the alias was not granted. Do not return or log secret values from a task.ansightexposes session-pinned resident-host methods.appexposes standardized app methods andcallToolfor user-defined tools.expectprovides Playwright-style named matchers that determine whether the task passed.
Tasks can discover and compose other tasks from the same workspace through
ansight.tasks. Discovery is read-only; execution reuses the caller’s exact
repository, App ID, and live session:
type OpenGuideOutput = { guideVisible: boolean };
const catalog = await ansight.tasks.list({ query: "open area 3D guide" });
const child = catalog.tasks.find(candidate => candidate.taskId === "map.open-guide");
if (!child) throw new Error("The guide task is unavailable.");
const result = await ansight.tasks.run<OpenGuideOutput>({
taskId: child.taskId,
input: { area: "Secret Garden" }
});
expect(result.output?.guideVisible, { id: "guide-opened" }).toBe(true);
The call rejects unless the child task passes. Child tasks keep independent assertions, timeouts, action budgets, audit trails, and persisted run results; the parent’s discovery or execution call counts as one parent action. The parent must still make its own named assertion. Self-calls, recursive cycles, and call chains deeper than eight task execution levels are rejected.
Call a host-owned task tool through its feature API:
await ansight.ui.assert({ automationId: "home", exists: true });
Current-session inspection and running-app controls marked as task-callable are
grouped under ansight.session, ansight.ui, ansight.logs,
ansight.artifacts, ansight.screenshots, ansight.telemetry, and the other
feature APIs. Workspace composition is exposed separately as
ansight.tasks.list(...) and ansight.tasks.run(...); it does not require a
hostTools declaration. For example, ansight_wait_for_ui is exposed as
ansight.ui.waitFor(...) without descriptor boilerplate, while
ansight.session.getProperties<TProperties>() returns the selected session’s
custom properties in a named SessionPropertiesResult<TProperties> contract. App registration,
pairing, cloud, repository
management, session mutation, audit, host diagnostics, import/export, and
profiling remain host-only. ansight.callTool(name, args) remains available for
extra host tools named in hostTools; the host validates those names against the
active task registry while loading the repository.
Call a custom tool published by the live app with:
await app.callTool("example.map.query_surface_contents", {
annotationKind: "point"
});
Standard app tools instead have discoverable API suites such as
app.artifacts.request(...), app.data.query(...),
app.maui.getVisualTree(...), app.react.getComponentTree(...),
app.flutter.inspectWidget(...), and app.capacitor.querySelector(...). These
methods and custom app.callTool(...) IDs need no descriptor declaration.
For an externally monitored session, use the available host APIs, including ansight.files for sandbox access. Check app.available
or declare required app-tool IDs before using SDK suites. Missing capabilities
reject execution. See Execution capabilities
for a portable descriptor and the runtime capability API.
Task-callable host methods discard caller-supplied sessionId, appId,
deviceId, and bundleIdentifier values and inject the task session. App tools
are also pinned to the selected live session and must be live, authorized, and
available there. Destructive app tools use their normal authorization and
approval policies.
Await calls serially. An undeclared ansight.callTool host call, overlapping
call, failed child task, failed tool guard, or exceeded maximumActions limit rejects the task.
Calls retain normal audit and timeout handling.
Diagnostic result retention
When a task runs inside an agent execution with trace capture enabled (the
default; use --no-trace to opt out), its API
calls retain input arguments and returned outputs or errors alongside start
and completion times, duration, and status. Composed task calls retain their
child call entries. In the local player’s test history, select the task in the
execution trace to open its results table, then select a call to inspect its
inputs and outputs. Payloads have bounded capture limits and report truncation;
without tracing, calls retain lightweight timing and outcome metadata.
A successful file_descriptors.list_open call also creates a durable
open-file-descriptors.json artifact snapshot on the selected session timeline.
The artifact preserves the complete app-tool response. The compact
file_descriptors.count_open and file_descriptors.get_usage calls remain
ordinary app-tool responses, so a task can return only their raw count or usage
summary. Continuous open-handle and JNI-reference counts remain telemetry; JNI
reference graphs are not currently exposed as an app tool.
Named assertions and status
The expect API uses a required metadata object so every result keeps its stable
Ansight assertion ID:
expect(actual, { id, message? }).toBe(expected)for strictObject.isequality.toEqual(expected)for strict deep equality.toBeTruthy(),.toBeFalsy(),.toBeDefined(),.toBeUndefined(), and.toBeNull().toContain(expected)and.toContainEqual(expected).not.<matcher>to negate a matcherexpect.soft(actual, metadata).<matcher>to record failure and continue
Use stable, unique assertion IDs. A hard failed assertion stops the function;
a soft failed assertion does not. Any recorded failure still fails the task,
including a hard assertion error caught by task code. Returning output is not
enough to pass: a task is Passed only when at least one named assertion passes
and none fail. A normal return without assertions is Inconclusive.
Other terminal statuses are Failed, Error, TimedOut, Cancelled, and
Rejected. The result includes validated input, returned output, duration,
assertions, standard error, and a per-tool-call audit.
Test a task with the local host
- Open the Test workspace and select the app beneath the active workspace.
- Open or create a module under
ansight/tasks. - Review the host-reported descriptor, schema, API, and assertion snippets.
- Select an open simulator session for the same App ID.
- Choose Save & test task.
- Review the terminal status, named assertions, tool calls, and standard error.
The task editor validates the static module shape before saving. A live task run uses the saved source and the exact selected session.
Discover and run from the CLI
Inspect tasks without running them:
ansight task list --app-id com.example.app --repository .
Task execution requires a resident host and an already connected app session:
ansight host run
ansight task run home.verify \
--app-id com.example.app \
--repository . \
--input '{"automationId":"signed-in-home"}' \
--secret login_password
Use --device-id or --session-id to select an exact connected target, and
--input-file for larger input. Without either target option, Ansight selects
the most recently updated connected session whose App ID matches exactly.
Pass --headless to task run or repo task run if any permitted host tools
invoked by the task should start virtual devices without opening native windows.
Windows are shown by default for new launches. This flag does not launch an
initial app session for the task, close existing windows, or restart a running
emulator. The connected-session prerequisite still applies. See
headless device launches.
Execution and security boundaries
Each task run starts with fresh module state. Module startup has a separate five-second limit. The execution environment is reduced, and hosted execution credentials are never added to it. Tool results, returned output, diagnostics, action count, and total duration are bounded.
Capability declarations restrict calls back into Ansight; they do not sandbox filesystem, process, or network access available to trusted local workspace code. Review a repository before running its tasks.
A repository can expose up to 256 tasks, and each executable module is limited to 1 MiB.