Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/adr/0013-unified-gesture-plans.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Completed process history is in git history.
The planner does not clamp points, cache the viewport, or distort the requested components.
- Android touch execution never falls back to `adb input swipe`.
- On Android, gestures do not stop or restart the snapshot session.
- If `--settle` is set, wait for a quiet tree after the final repetition succeeds. Keep the completed action result if observation fails.
- Keep the positional `.ad` codec. One `PUBLIC_GESTURE_SYNTAX` table defines argument arity for the CLI argv parse and the `.ad` line parse.
- For repeated coordinate swipes, the combined planned gesture and pause schedule must fit within 60 seconds.
- `gesture tap` holds 2 to 5 stationary contacts; the motion intents keep exactly two (amended 2026-10).
Expand Down Expand Up @@ -271,6 +272,12 @@ Coordinate-authored gestures do not resolve selectors or refs and therefore cann
Before it enters the coordinate gesture executor, target-authored drag explicitly runs the shared selector/ref resolution preflight.
Its endpoint resolution and recording contracts are tested at that composition seam.

### Settle after gesture execution

With `--settle`, take the comparison baseline from the last observed session tree before dispatch. Start the quiet wait after the final successful repetition and record the gesture before the wait. Reuse the gesture's admitted capture binding under [ADR 0019](0019-request-bound-platform-runtime.md).

If observation returns an inconclusive verdict, include it with the completed action result. If observation throws, return the completed action result without a settle field. Issue refs only from a committed settle diff under [ADR 0014](0014-session-ref-frame-lifetime.md).

## Consequences

- CLI, Node.js, MCP, runtime, and platform adapters share one normalization and planning model.
Expand Down
2 changes: 2 additions & 0 deletions packages/command-output/src/cli-output.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const FORMATTER_COMMANDS = [
'fill',
'find',
'fold',
'gesture',
'get',
'hardware-button',
'home',
Expand Down Expand Up @@ -77,6 +78,7 @@ const FORMATTER_COMMANDS = [
'shake',
'shutdown',
'snapshot',
'swipe',
'telephony',
'tv-remote',
'viewport',
Expand Down
2 changes: 2 additions & 0 deletions packages/command-output/src/interaction/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ export const interactionCliOutputFormatters = withSettleCapableNotes({
longpress: messageOutput,
hover: messageOutput,
scroll: messageOutput,
swipe: messageOutput,
gesture: messageOutput,
get: ({ input, result }) =>
getCliOutput({
result: result as CommandRequestResult,
Expand Down
2 changes: 2 additions & 0 deletions packages/command-output/src/settle-output.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const SETTLE_OBSERVATION_COMMANDS = [
PUBLIC_COMMANDS.hover,
PUBLIC_COMMANDS.press,
PUBLIC_COMMANDS.scroll,
PUBLIC_COMMANDS.swipe,
PUBLIC_COMMANDS.gesture,
PUBLIC_COMMANDS.back,
] as const;

Expand Down
17 changes: 2 additions & 15 deletions packages/command-output/src/settle-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ function messageWithSettledNotes(formatter: CliOutputFormatter): CliOutputFormat
}

function withSettledNotes(output: CliOutput): CliOutput {
return {
data: output.data,
text: appendResponseNotes(output.text, output.data as Record<string, unknown>),
};
const notes = formatSettleText((output.data as Record<string, unknown>)?.settle);
return notes ? { ...output, text: `${output.text ?? ''}${notes}` } : output;
}

/**
Expand All @@ -59,17 +57,6 @@ export function withSettleCapableNotes<Formatters extends Record<string, CliOutp
return derived as Formatters;
}

/**
* The settled diff only: response warnings are appended once by `formatCliOutput`, routed by the
* command's descriptor (#2682), so this wrapper cannot be the place a warning appears twice.
*/
function appendResponseNotes(
text: string | null | undefined,
data: Record<string, unknown>,
): string {
return `${text ?? ''}${formatSettleText(data.settle)}`;
}

function formatSettleText(settle: unknown): string {
if (!settle || typeof settle !== 'object') return '';
const view = settle as SettleTextView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,8 @@ export const DEVICE_OPERATION_COMMAND_DESCRIPTORS = {
// R52 retires this command's capability bucket: admission is the owner's gesture-tier facts,
// which the retired `requireGestureSupported` used to decide inside the daemon. The declared
// uses are the four tiers one gesture input can select between (ADR 0019 §9).
timeoutPolicy: DEFAULT_TIMEOUT_POLICY,
timeoutPolicy: postActionObservationTimeoutPolicy('gesture', DEFAULT_TIMEOUT_POLICY),
postActionObservation: postActionObservation('gesture'),
batchable: true,
compositeResource: 'none',
platformExecution: { kind: 'device-runtime', uses: gestureRuntimePlanUses },
Expand Down Expand Up @@ -510,7 +511,8 @@ export const DEVICE_OPERATION_COMMAND_DESCRIPTORS = {
},
// R54 retires this command's capability bucket. A swipe always normalizes to a coordinate
// fling, so it declares only the one-contact plan it can select.
timeoutPolicy: DEFAULT_TIMEOUT_POLICY,
timeoutPolicy: postActionObservationTimeoutPolicy('swipe', DEFAULT_TIMEOUT_POLICY),
postActionObservation: postActionObservation('swipe'),
batchable: true,
compositeResource: 'none',
platformExecution: { kind: 'device-runtime', uses: swipeRuntimePlanUses },
Expand Down
2 changes: 2 additions & 0 deletions packages/command-registry/src/post-action-observation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const POST_ACTION_OBSERVATION_BY_COMMAND = {
// settled diff is the observation; nothing to re-digest into --verify.
hover: 'settle',
scroll: 'settle',
swipe: 'settle',
gesture: 'settle',
back: 'settle',
} as const satisfies Record<string, PostActionObservationSupport>;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import assert from 'node:assert/strict';
import { test } from 'vitest';
import { commandSupportsSettleObservation } from '@agent-device/command-registry/registry';
import { ownerFilesForCommand } from '@agent-device/command-registry/owner-files';
import { INTERACTION_COMMAND_OUTPUT_SCHEMAS } from './interaction/index.ts';
import { COMMAND_OUTPUT_SCHEMAS } from './command-output-schemas.ts';
Expand All @@ -8,14 +9,9 @@ const INTERACTION_COMMANDS = Object.keys(INTERACTION_COMMAND_OUTPUT_SCHEMAS) as
keyof typeof INTERACTION_COMMAND_OUTPUT_SCHEMAS
>;

// press, click, fill, longpress, and hover carry the post-action observation trait (#1652): the
// composed map grafts a `settle` property onto a COPY, so they are not reference-equal to the
// module's own object. find carries no such trait.
const SETTLE_DERIVED_COMMANDS = new Set(['press', 'click', 'fill', 'longpress', 'hover']);

test('MCP interaction family output schemas are the family module entries, not copies', () => {
for (const command of INTERACTION_COMMANDS) {
if (SETTLE_DERIVED_COMMANDS.has(command)) continue;
if (commandSupportsSettleObservation(command)) continue;
assert.equal(
COMMAND_OUTPUT_SCHEMAS[command],
INTERACTION_COMMAND_OUTPUT_SCHEMAS[command],
Expand Down
22 changes: 8 additions & 14 deletions packages/command-surface/src/command-output-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,9 @@ import { SYSTEM_COMMAND_OUTPUT_SCHEMAS } from './system/index.ts';

/**
* Registry of per-command MCP `outputSchema`s, keyed by the daemon command
* NAME. It is type-tied to the typed-result spine `CommandResultMap`
* (@agent-device/command-registry/command-result) via
* `satisfies Record<keyof CommandResultMap, JsonSchema>`, so the one-for-one
* invariant is compiler-enforced: a new `CommandResultMap` entry without a schema
* here is a missing-key error, and a typo'd/extra key is an excess-property error.
* The genuinely-dynamic commands (snapshot overlays, gestures, perf, logs, …) are
* absent from BOTH maps — their tools stay byte-identical to today (no
* `outputSchema` key), exactly as `CommandResultMap` omits them rather than
* inventing a shape.
* NAME. Every closed contract in `CommandResultMap` has a schema here.
* Gesture and swipe keep dynamic SDK results and advertise the known fields,
* including the opt-in settle observation, to MCP callers.
*
* There is no type→JSON-Schema generator in this repo. Schemas are hand-authored from
* matching contract types, using the shared JSON-Schema primitives in
Expand Down Expand Up @@ -147,11 +141,11 @@ function withSettleObservation(schema: JsonSchema): JsonSchema {
* Copies only — press and click share one base schema object, so an in-place
* graft would leak across them.
*/
function deriveSettleObservationSchemas(
schemas: Record<keyof CommandResultMap, JsonSchema>,
): Record<keyof CommandResultMap, JsonSchema> {
const derived: Record<keyof CommandResultMap, JsonSchema> = { ...schemas };
for (const command of Object.keys(derived) as Array<keyof CommandResultMap>) {
function deriveSettleObservationSchemas<Command extends string>(
schemas: Record<Command, JsonSchema>,
): Record<Command, JsonSchema> {
const derived = { ...schemas };
for (const command of Object.keys(derived) as Command[]) {
if (!commandSupportsSettleObservation(command)) continue;
derived[command] = withSettleObservation(derived[command]);
}
Expand Down
46 changes: 39 additions & 7 deletions packages/command-surface/src/interaction/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {
SwipeOptions,
TypeTextOptions,
} from '@agent-device/contracts/client';
import { SWIPE_PATTERNS } from '@agent-device/contracts/scroll-gesture';
import type { CommandSchemaOverride } from '@agent-device/command-registry/command-schema';
import type { FlagKey } from '@agent-device/command-registry/flag-types';
import { readGesturePayload } from '@agent-device/gestures/gesture-payload-reader';
Expand Down Expand Up @@ -300,14 +301,33 @@ const unconfirmedFillResponseSchema = interactionResponseDataSchema({
required: ['text', 'verification', 'requested', 'before', 'after', 'target'],
});

const gesturePointResponse = objectSchema({ x: numberSchema(), y: numberSchema() }, ['x', 'y']);
const gestureResponseProperties = {
kind: stringSchema(),
durationMs: numberSchema(),
pointerCount: numberSchema(),
from: gesturePointResponse,
to: gesturePointResponse,
};
const gestureResponseRequired = Object.keys(gestureResponseProperties);

/**
* This family's advertised MCP `outputSchema`s, keyed by daemon command name and projected into
* the command map by `command-output-schemas.ts`. Non-strict like every other entry: no
* `additionalProperties: false`, so additive response fields such as `settle`/`cost` keep
* validating. #1652: the opt-in `settle` observation is NOT listed here — the trait derivation
* pass in that file grafts it onto settle-capable entries.
* validating. The registry adds `settle` to commands with the post-action observation trait.
*/
export const INTERACTION_COMMAND_OUTPUT_SCHEMAS = {
gesture: objectSchema(gestureResponseProperties, gestureResponseRequired),
swipe: objectSchema(
{
...gestureResponseProperties,
count: numberSchema(),
pauseMs: numberSchema(),
pattern: enumSchema(SWIPE_PATTERNS),
},
[...gestureResponseRequired, 'count', 'pauseMs', 'pattern'],
),
press: tapInteractionResponseDataSchema,
click: tapInteractionResponseDataSchema,
fill: {
Expand Down Expand Up @@ -357,7 +377,8 @@ export const INTERACTION_COMMAND_OUTPUT_SCHEMAS = {
} satisfies Pick<
Record<keyof CommandResultMap, JsonSchema>,
'press' | 'click' | 'fill' | 'longpress' | 'hover' | 'find'
>;
> &
Record<'gesture' | 'swipe', JsonSchema>;

/** The `.ad` preflight owns the same table, so `gesture pinch --count 3` is refused on both paths. */
const GESTURE_FLAGS_BY_ACTION: Readonly<Record<string, readonly FlagKey[]>> = GESTURE_FLAGS_BY_KIND;
Expand Down Expand Up @@ -428,15 +449,21 @@ const interactionCliSchemas = {
// Arity is enforced by swipePayloadFromPositionals (assertGestureArity), so
// an extra positional reaches that migration-hint error, not this schema's.
allowsExtraPositionals: true,
allowedFlags: ['count', 'pauseMs', 'pattern', 'postGestureStabilization'],
allowedFlags: [
'count',
'pauseMs',
'pattern',
'postGestureStabilization',
...postActionObservationCliFlags('swipe'),
],
},
gesture: {
usageOverride: 'gesture <pan|fling|swipe|pinch|rotate|transform|tap|drag> ...',
usageFlags: [],
listUsageOverride: 'gesture <pan|fling|swipe|pinch|rotate|transform|tap|drag> ...',
positionalArgs: ['pan|fling|swipe|pinch|rotate|transform|tap|drag', 'args?'],
allowsExtraPositionals: true,
allowedFlags: GESTURE_CLI_FLAGS,
allowedFlags: [...GESTURE_CLI_FLAGS, ...postActionObservationCliFlags('gesture')],
flagsByAction: GESTURE_FLAGS_BY_ACTION,
},
focus: {
Expand Down Expand Up @@ -565,7 +592,7 @@ const swipeCommandFacet = defineCommandFacet({
summary: 'Fling between coordinates',
searchHint: 'flick slide carousel page',
cliDetail:
'A swipe never pauses on the start point, so it does not engage a hold-to-reorder handle -- use gesture drag @src @dst for a held move. The first read after a swipe waits for two captures to agree. --no-post-gesture-stabilization skips that wait for a caller whose own polling verifies the screen.',
'A swipe never pauses on the start point, so it does not engage a hold-to-reorder handle -- use gesture drag @src @dst for a held move. Use --settle to wait for the UI to go quiet after the last repetition and compare with the last observed tree. The first read after a swipe waits for two captures to agree. --no-post-gesture-stabilization skips that wait for a caller whose own polling verifies the screen.',
},
metadata: metadata('swipe'),
run: (client, input) => client.interactions.swipe(input as SwipeOptions),
Expand Down Expand Up @@ -667,13 +694,18 @@ const gestureCommandFacet = defineCommandFacet({
summary: 'Run pan, fling, swipe, pinch, rotate, transform, tap, or drag gestures',
searchHint: 'reorder zoom multi-touch',
cliDetail:
'Argument shapes: pan <x> <y> <dx> <dy> [durationMs], fling <up|down|left|right> <x> <y> [distance], swipe <left|right|left-edge|right-edge|split-view-left|split-view-right|split-view-exit>, pinch <scale> [x y | @ref|selector] (centered on the screen when neither is given), rotate <degrees> [x] [y], transform <x> <y> <dx> <dy> <scale> <degrees> [durationMs], tap <x1> <y1> <x2> <y2> [... <x5> <y5>] [--hold-ms <ms>] [--count <n>] [--pause-ms <ms>], or drag <source-selector|pinned-ref> <destination-selector|pinned-ref> [sourceHoldMs] [moveMs] [destinationHoldMs]; drag holds the source down first (800 ms by default) before moving, which is what engages a reorder handle. For command plans, output only command lines. Android transform verification should use all app-observable effects, for example wait text "pan changed yes", wait text "pinch changed yes", and wait text "rotate changed yes", not exact transform values. gesture swipe accepts --no-post-gesture-stabilization to skip the stabilization wait before the next read, for a caller whose own polling verifies the screen.',
'Argument shapes: pan <x> <y> <dx> <dy> [durationMs], fling <up|down|left|right> <x> <y> [distance], swipe <left|right|left-edge|right-edge|split-view-left|split-view-right|split-view-exit>, pinch <scale> [x y | @ref|selector] (centered on the screen when neither is given), rotate <degrees> [x] [y], transform <x> <y> <dx> <dy> <scale> <degrees> [durationMs], tap <x1> <y1> <x2> <y2> [... <x5> <y5>] [--hold-ms <ms>] [--count <n>] [--pause-ms <ms>], or drag <source-selector|pinned-ref> <destination-selector|pinned-ref> [sourceHoldMs] [moveMs] [destinationHoldMs]; drag holds the source down first (800 ms by default) before moving, which is what engages a reorder handle. For command plans, output only command lines. Android transform verification should use all app-observable effects, for example wait text "pan changed yes", wait text "pinch changed yes", and wait text "rotate changed yes", not exact transform values. Use --settle to wait for the UI to go quiet after the last repetition and compare with the last observed tree. gesture swipe accepts --no-post-gesture-stabilization to skip the stabilization wait before the next read, for a caller whose own polling verifies the screen.',
},
metadata: metadata('gesture'),
run: (client, input) =>
client.interactions.gesture({
...readGesturePayload(input),
...commonToClientOptions(input),
...(input.settle !== undefined ||
input.settleQuietMs !== undefined ||
input.timeoutMs !== undefined
? toSettleOptions(input)
: undefined),
...(input.postGestureStabilization === false ? { postGestureStabilization: false } : {}),
}),
cliSchema: interactionCliSchemas.gesture,
Expand Down
Loading
Loading