Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,11 @@ extension RunnerTests {
}
return Self.reportingSchedule(execution.schedule, in: response)
case .gestureViewport:
let frame = try gestureViewportFrame(app: activeApp, includesKeyboard: command.includesKeyboard == true)
let frame = try gestureViewportFrame(
app: activeApp,
includesKeyboard: command.includesKeyboard == true,
displayViewport: command.displayViewport == true
)
guard !frame.isNull, !frame.isInfinite, !frame.isEmpty else {
return Response(ok: false, error: ErrorPayload(code: "COMMAND_FAILED", message: "Active app interaction viewport is unavailable"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ struct Command: Codable {
let textEntryMode: String?
let action: String?
let includesKeyboard: Bool?
let displayViewport: Bool?
let x: Double?
let y: Double?
let button: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,11 @@ extension RunnerTests {
/// context its record is routed through, so a tree with no window whose app provably fills its
/// sole screen plans on that screen, the same route a synthesized tap or scroll takes.
@MainActor
func gestureViewportFrame(app: XCUIApplication, includesKeyboard: Bool = false) throws -> CGRect {
func gestureViewportFrame(app: XCUIApplication, includesKeyboard: Bool = false, displayViewport: Bool = false) throws -> CGRect {
#if os(iOS)
if displayViewport {
return try requireRequestLitPanelSurface(app: app).geometry.digitizerBasis.rect
}
if let context = try synthesizedCoordinateContext(app: app) {
let frame = context.geometry.windowOnScreen.rect
return includesKeyboard || context.resolvedWindow == nil ? frame : frameAvoidingKeyboard(app: app, frame: frame)
Expand Down
1 change: 1 addition & 0 deletions contracts/fixtures/runner-requests.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
{"name": "ios-device.recording-stop.no-app", "producer": "src/__tests__/screen-recording-runner-requests.test.ts", "request": {"command": "recordStop"}},
{"name": "ios-device.recording-stop.session", "producer": "src/__tests__/screen-recording-runner-requests.test.ts", "request": {"command": "recordStop", "appBundleId": "com.example.app"}},
{"name": "ios-foldable.alert.get", "producer": "packages/platform-apple/src/__tests__/interactor-foldable-runner-requests.test.ts", "request": {"command": "alert", "action": "get", "appBundleId": "com.example.app", "timeoutMs": 10000, "commandId": "<commandId>"}},
{"name": "ios-foldable.interactions-gesture-viewport.display", "producer": "packages/platform-apple/src/__tests__/interactor-foldable-runner-requests.test.ts", "request": {"command": "gestureViewport", "appBundleId": "com.example.app", "displayViewport": true, "litPanel": {"displayId": 3, "widthPt": 669, "heightPt": 951}, "commandId": "<commandId>"}},
{"name": "ios-foldable.interactions-tap.synthesized", "producer": "packages/platform-apple/src/__tests__/interactor-foldable-runner-requests.test.ts", "request": {"command": "tap", "x": 10, "y": 20, "synthesized": true, "appBundleId": "com.example.app", "litPanel": {"displayId": 3, "widthPt": 669, "heightPt": 951}, "commandId": "<commandId>"}},
{"name": "ios-foldable.interactor-find-text.lit-panel", "producer": "packages/platform-apple/src/__tests__/interactor-foldable-runner-requests.test.ts", "request": {"command": "findText", "text": "Search", "appBundleId": "com.example.app", "litPanel": {"displayId": 3, "widthPt": 669, "heightPt": 951}, "commandId": "<commandId>"}},
{"name": "ios-foldable.interactor-keyboard-dismiss.lit-panel", "producer": "packages/platform-apple/src/__tests__/interactor-foldable-runner-requests.test.ts", "request": {"command": "keyboardDismiss", "appBundleId": "com.example.app", "litPanel": {"displayId": 3, "widthPt": 669, "heightPt": 951}, "commandId": "<commandId>"}},
Expand Down
1 change: 1 addition & 0 deletions packages/apple-runner/src/runner-command-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export type RunnerCommand = {
textEntryMode?: 'append' | 'replace';
action?: 'get' | 'accept' | 'dismiss';
includesKeyboard?: boolean;
displayViewport?: boolean;
x?: number;
y?: number;
button?: ClickButton;
Expand Down
2 changes: 1 addition & 1 deletion packages/command-surface/src/interaction/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ 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>, 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. 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) =>
Expand Down
8 changes: 5 additions & 3 deletions packages/contracts/src/gesture-plan-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,12 @@ export type SinglePointerTrajectory = {
/**
* Where a contact starts. `screen-edge` asks the platform to deliver the contact as a screen-edge
* touch, which edge gesture recognizers require. `split-view-edge` is a screen-edge touch that
* starts the system Split View gesture; only a foldable iOS simulator with its inner panel lit
* executes it.
* starts the system Split View gesture. `split-view-divider` starts an ordinary drag on the system
* divider. Only a foldable iOS simulator with its inner panel lit executes Split View gestures.
*/
export type GestureContactOrigin = 'screen-edge' | 'split-view-edge';
export type GestureContactOrigin = 'screen-edge' | 'split-view-edge' | 'split-view-divider';

export type GestureViewportScope = 'including-keyboard' | 'display';

export type SinglePointerGesturePlan = {
topology: 'single';
Expand Down
8 changes: 4 additions & 4 deletions packages/contracts/src/gesture-runtime.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { DeviceInfo } from '@agent-device/kernel/device';
import type { Rect } from '@agent-device/kernel/snapshot';
import type { GesturePlan } from './gesture-plan-types.ts';
import type { GesturePlan, GestureViewportScope } from './gesture-plan-types.ts';
import {
localInteractorSource,
providerInteractorSource,
Expand All @@ -26,7 +26,7 @@ export type GesturePlanInput = Readonly<{

/** Reading the gesture coordinate frame needs no plan — only the owner's authority. */
export type GestureViewportInput = Readonly<{
includesKeyboard?: true;
scope?: GestureViewportScope;
options?: Readonly<{ appBundleId?: string }>;
execution?: SnapshotRuntimeExecution;
}>;
Expand Down Expand Up @@ -152,8 +152,8 @@ function bindGestureOperations(
'Runtime owner advertised gestureViewport without an interactor implementation',
);
}
return input.includesKeyboard
? await interactor.gestureViewport(true)
return input.scope
? await interactor.gestureViewport(input.scope)
: await interactor.gestureViewport();
},
}
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/src/interactor-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { FillUnconfirmedVerification } from './fill-evidence.ts';
import type { ScrollDirection } from './scroll-gesture.ts';
import type { ScrollExecutionOptions } from './scroll-command.ts';
import type { TvRemoteButton } from './tv-remote.ts';
import type { GesturePlan } from './gesture-plan-types.ts';
import type { GesturePlan, GestureViewportScope } from './gesture-plan-types.ts';
import type { ReadSettingResult, SettingOptions } from './settings.ts';
import type { ReadableSetting } from './settings-catalog.ts';
import type { SessionSurface } from './session-surface.ts';
Expand Down Expand Up @@ -416,7 +416,7 @@ export type Interactor = {
): Promise<{
found: boolean;
}>;
gestureViewport?(includesKeyboard?: true): Promise<Rect>;
gestureViewport?(scope?: GestureViewportScope): Promise<Rect>;
back(mode?: BackMode): Promise<void>;
/**
* Optional (parity with `actionButton`): opens the springboard, a control not every owner
Expand Down
13 changes: 10 additions & 3 deletions packages/contracts/src/scroll-gesture.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AppError, type ReasonTable } from '@agent-device/kernel/errors';
import type { GestureContactOrigin } from './gesture-plan-types.ts';
import { SCROLL_REASONS } from './scroll-reasons.ts';
import { defineStringEnum } from './string-enum.ts';
import { isViewportRootNode } from './snapshot-visibility.ts';
Expand Down Expand Up @@ -28,12 +29,18 @@ export const SWIPE_PRESETS = [
'right-edge',
'split-view-left',
'split-view-right',
'split-view-exit',
] as const;
export type SwipePreset = (typeof SWIPE_PRESETS)[number];
/** Presets that move a full-screen app into one half of Split View on a foldable iOS simulator. */
/** Presets that enter or leave Split View on a foldable iOS simulator. */
export type SplitViewSwipePreset = Extract<SwipePreset, `split-view-${string}`>;
export function isSplitViewSwipePreset(preset: SwipePreset): preset is SplitViewSwipePreset {
return preset === 'split-view-left' || preset === 'split-view-right';
return preset.startsWith('split-view-');
}
export function isSplitViewContactOrigin(
origin: GestureContactOrigin | undefined,
): origin is 'split-view-edge' | 'split-view-divider' {
return origin === 'split-view-edge' || origin === 'split-view-divider';
}
/** Why a Split View swipe preset was refused before any touch went down. */
const SPLIT_VIEW_GESTURE_REASONS = {
Expand All @@ -49,7 +56,7 @@ export function splitViewUnavailableError(
...details,
reason: SPLIT_VIEW_GESTURE_REASONS.unavailable.reason,
dispatched: 'no',
hint: 'Use an iPhone Duo simulator with its inner panel lit (not closed), open the app full screen, then swipe again.',
hint: 'Use an iPhone Duo simulator with its inner panel lit.',
});
}
const SCREEN_EDGE_SWIPE_PRESETS: ReadonlySet<SwipePreset> = new Set(['left-edge', 'right-edge']);
Expand Down
51 changes: 33 additions & 18 deletions packages/daemon/src/core/gesture-runtime.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { gestureRefusalMessage } from '@agent-device/contracts/gesture-admission';
import type { GestureCommandInput, GesturePlan } from '@agent-device/contracts/gesture-plan-types';
import type {
GestureCommandInput,
GesturePlan,
GestureViewportScope,
} from '@agent-device/contracts/gesture-plan-types';
import type {
GesturePlanInput,
GestureRuntimeOperations,
Expand Down Expand Up @@ -122,18 +126,31 @@ export async function resolveBoundGestureRuntime(
});
if (admitted.type === 'response') return { ok: false, response: admitted.response };
// One bind, with the exactly-typed use the tier selected (ADR 0019 §9).
const includesKeyboard =
params.input.intent === 'pan' &&
(params.input.pointerCount ?? 1) === 1 &&
params.input.executionProfile !== 'endpoint-hold'
? true
: undefined;
return {
ok: true,
gestures: await bindGestureTier(admitted.bind, params.device, plan, includesKeyboard),
gestures: await bindGestureTier(
admitted.bind,
params.device,
plan,
gestureViewportScope(params.input),
),
};
}

function gestureViewportScope(input: GestureCommandInput): GestureViewportScope | undefined {
if (input.intent === 'fling' && 'preset' in input && input.preset === 'split-view-exit') {
return 'display';
}
if (
input.intent === 'pan' &&
(input.pointerCount ?? 1) === 1 &&
input.executionProfile !== 'endpoint-hold'
) {
return 'including-keyboard';
}
return undefined;
}

/**
* The ONE place each bound gesture tier executes (R52/R54, shared by `gesture` and `swipe`).
*
Expand All @@ -146,15 +163,15 @@ async function bindGestureTier(
bind: Extract<Awaited<ReturnType<typeof admitRuntimeOperations>>, { type: 'admitted' }>['bind'],
device: DeviceInfo,
plan: GestureRuntimePlan,
includesKeyboard?: true,
scope?: GestureViewportScope,
): Promise<BoundGestureExecutor> {
switch (plan.tier) {
case 'plan': {
const runtime = await bind(device, plan.use);
return {
performPlan: async (gesturePlan, context) =>
await runtime.operations.performGesturePlan(gesturePlanInput(gesturePlan, context)),
...selectGestureFrame(runtime, includesKeyboard),
...selectGestureFrame(runtime, scope),
...(runtime.operations.querySelector
? { querySelector: runtime.operations.querySelector }
: {}),
Expand Down Expand Up @@ -194,7 +211,7 @@ async function bindGestureTier(
gesturePlanInput(gesturePlan, context),
),
// A held pan reaches this tier too, and a pan's frame read includes the keyboard.
...selectGestureFrame(runtime, includesKeyboard),
...selectGestureFrame(runtime, scope),
...(runtime.operations.querySelector
? { querySelector: runtime.operations.querySelector }
: {}),
Expand All @@ -218,7 +235,7 @@ function selectGestureFrame(
gestureViewport?: GestureRuntimeOperations['gestureViewport'];
}>;
}>,
includesKeyboard?: true,
scope?: GestureViewportScope,
): Pick<BoundGestureExecutor, 'captureSnapshot' | 'gestureViewport'>;
function selectGestureFrame(
runtime: Readonly<{
Expand All @@ -227,7 +244,7 @@ function selectGestureFrame(
gestureViewport?: GestureRuntimeOperations['gestureViewport'];
}>;
}>,
includesKeyboard?: true,
scope?: GestureViewportScope,
): Partial<Pick<BoundGestureExecutor, 'captureSnapshot' | 'gestureViewport'>> {
const { gestureViewport } = runtime.operations;
const selectedCapture = runtime.operations.captureSnapshot
Expand All @@ -244,9 +261,7 @@ function selectGestureFrame(
...(selected
? {
gestureViewport: async (context: DaemonCommandContext) =>
await selected.operations.gestureViewport(
gestureViewportInput(context, includesKeyboard),
),
await selected.operations.gestureViewport(gestureViewportInput(context, scope)),
}
: {}),
});
Expand All @@ -261,9 +276,9 @@ function gesturePlanInput(plan: GesturePlan, context: DaemonCommandContext): Ges
};
}

function gestureViewportInput(context: DaemonCommandContext, includesKeyboard?: true) {
function gestureViewportInput(context: DaemonCommandContext, scope?: GestureViewportScope) {
return {
...(includesKeyboard ? { includesKeyboard } : {}),
...(scope ? { scope } : {}),
...(context.appBundleId === undefined ? {} : { options: { appBundleId: context.appBundleId } }),
execution: runtimeExecutionFromContext(context),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ const to = { x: 120, y: 320 };
const pan = { kind: 'pan', origin: from, delta: { x: 0, y: 100 }, durationMs: 500 };

test.each([
{ name: 'one-finger pan', command: 'gesture', input: pan, includesKeyboard: true },
{ name: 'one-finger pan', command: 'gesture', input: pan, scope: 'including-keyboard' },
{ name: 'two-finger pan', command: 'gesture', input: { ...pan, pointerCount: 2 } },
{ name: 'fling', command: 'gesture', input: { kind: 'fling', direction: 'down', origin: from } },
{ name: 'swipe', command: 'swipe', input: { from, to } },
{
name: 'Split View exit',
command: 'gesture',
input: { kind: 'swipe', preset: 'split-view-exit' },
scope: 'display',
},
{
name: 'Maestro coordinate swipe',
command: 'gesture',
Expand Down Expand Up @@ -64,8 +70,8 @@ test.each([

expect(response).toMatchObject({ ok: true });
expect(gestureViewport).toHaveBeenCalledOnce();
expect(gestureViewport.mock.calls[0]?.[0].includesKeyboard).toBe(
'includesKeyboard' in scenario ? scenario.includesKeyboard : undefined,
expect(gestureViewport.mock.calls[0]?.[0].scope).toBe(
'scope' in scenario ? scenario.scope : undefined,
);
});

Expand Down
37 changes: 28 additions & 9 deletions packages/gestures/src/gesture-plan-split-view.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,32 @@ test.each([
expect([samples[1]!.point, samples[2]!.point]).toEqual([middle, middle]);
});

test('a Split View preset off iOS is refused before planning a touch', () => {
expect(() =>
buildGesturePlan({ intent: 'fling', preset: 'split-view-left' }, viewport, 'android'),
).toThrow(
expect.objectContaining({
code: 'UNSUPPORTED_OPERATION',
details: expect.objectContaining({ reason: 'split_view_unavailable', dispatched: 'no' }),
}),
);
test('split-view-exit drags the divider from the center to the left edge', () => {
const display = { ...viewport, x: 20, y: 10 };
const plan = buildGesturePlan({ intent: 'fling', preset: 'split-view-exit' }, display, 'ios');
expect(plan).toMatchObject({
topology: 'single',
executionProfile: 'timed-pan',
contactOrigin: 'split-view-divider',
pointers: [
{
samples: [
{ offsetMs: 0, point: { x: 495.5, y: 344.5 } },
{ offsetMs: 700, point: { x: 21, y: 344.5 } },
],
},
],
});
});

test.each(['split-view-left', 'split-view-exit'] as const)(
'%s off iOS is refused before planning a touch',
(preset) => {
expect(() => buildGesturePlan({ intent: 'fling', preset }, viewport, 'android')).toThrow(
expect.objectContaining({
code: 'UNSUPPORTED_OPERATION',
details: expect.objectContaining({ reason: 'split_view_unavailable', dispatched: 'no' }),
}),
);
},
);
18 changes: 13 additions & 5 deletions packages/gestures/src/gesture-plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const GESTURE_VIEWPORT_INSET_PX = 1;
const DEFAULT_PAN_DURATION_MS = 500;
export const GESTURE_FLING_DURATION_MS = 100;
const SPLIT_VIEW_DURATION_MS = 2100;
const SPLIT_VIEW_EXIT_DURATION_MS = 700;
const SPLIT_VIEW_EDGE_INSET_PX = 1;
const DEFAULT_MULTI_TOUCH_DURATION_MS = 300;
const MAX_ROTATION_DEGREES_PER_SAMPLE = 3;
Expand Down Expand Up @@ -274,11 +275,6 @@ function buildFlingPlan(
);
}

/**
* The system Split View drag: up from the bottom edge to the middle, a hold that lifts the app
* window, then sideways toward the requested half. The sideways end stays short of the vertical
* travel, so the edge touch keeps its upward swipe direction.
*/
function buildSplitViewPlan(
preset: SplitViewSwipePreset,
viewport: Rect,
Expand All @@ -289,6 +285,18 @@ function buildSplitViewPlan(
}
const centerX = viewport.x + viewport.width / 2;
const middleY = viewport.y + viewport.height / 2;
if (preset === 'split-view-exit') {
const plan = buildSinglePointerPlan(
'fling',
{ x: centerX, y: middleY },
{ x: viewport.x + SPLIT_VIEW_EDGE_INSET_PX, y: middleY },
SPLIT_VIEW_EXIT_DURATION_MS,
viewport,
'timed-pan',
);
return { ...plan, contactOrigin: 'split-view-divider' };
}
// The sideways travel stays shorter than the initial lift so the edge touch stays upward.
const endX = viewport.x + viewport.width * (preset === 'split-view-left' ? 0.2 : 0.8);
const samples: SinglePointerTrajectory['samples'] = [
{
Expand Down
Loading
Loading