Skip to content

Commit 68351fd

Browse files
committed
feat: typed command results, batch 4 (keyboard) — Phase 2
Wire `keyboard` into the CommandResultMap spine, grounded in the dispatch handlers' literal returns (src/core/dispatch.ts handleAndroidKeyboardCommand / handleIosKeyboardCommand). Modeled as a flat closed shape (platform + action always present; the remaining keyboard-state / message fields appear per branch) rather than a five-way platform×action union — the per-branch field sets overlap heavily and the underlying Android keyboard-state types live in the platform layer (below the public contract). The Record index signature of the previous hand-written mirror is dropped and the spurious `| null`s removed (the handler never returns null). Moves from the open client-types.ts mirror into src/contracts/keyboard.ts, wired through CommandResult<'keyboard'>; public export name preserved (re-exported via client-types.ts -> index.ts), so no API break. Parity test pins all 13 migrated commands. Stacked on the batch 3 PR. Verified: tsc --noEmit, oxfmt + oxlint --deny-warnings, fallow audit clean, Layering Guard empty, 379 tests across core/contracts/client/commands/system pass.
1 parent 41358fe commit 68351fd

5 files changed

Lines changed: 42 additions & 19 deletions

File tree

‎src/client-types.ts‎

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export type {
6161
} from './contracts/navigation.ts';
6262
export type { ClipboardCommandResult } from './contracts/clipboard.ts';
6363
export type { AppStateCommandResult } from './contracts/app-state.ts';
64+
export type { KeyboardCommandResult } from './contracts/keyboard.ts';
6465

6566
export type AgentDeviceDaemonTransport = (
6667
req: Omit<DaemonRequest, 'token'>,
@@ -475,21 +476,6 @@ export type AlertCommandResult = DaemonResponseData & {
475476
items?: string[];
476477
};
477478

478-
export type KeyboardCommandResult = DaemonResponseData & {
479-
platform?: 'android' | 'ios';
480-
action?: 'status' | 'dismiss' | 'enter';
481-
visible?: boolean;
482-
inputType?: string | null;
483-
inputMethodPackage?: string | null;
484-
type?: string | null;
485-
focusedPackage?: string | null;
486-
focusedResourceId?: string | null;
487-
inputOwner?: 'app' | 'ime' | 'unknown';
488-
wasVisible?: boolean;
489-
dismissed?: boolean;
490-
attempts?: number;
491-
};
492-
493479
export type ReactNativeCommandOptions = DeviceCommandBaseOptions & {
494480
action: 'dismiss-overlay';
495481
};
@@ -512,7 +498,7 @@ export type AgentDeviceCommandClient = {
512498
home: (options?: HomeCommandOptions) => Promise<CommandResult<'home'>>;
513499
rotate: (options: RotateCommandOptions) => Promise<CommandResult<'rotate'>>;
514500
appSwitcher: (options?: AppSwitcherCommandOptions) => Promise<CommandResult<'app-switcher'>>;
515-
keyboard: (options?: KeyboardCommandOptions) => Promise<KeyboardCommandResult>;
501+
keyboard: (options?: KeyboardCommandOptions) => Promise<CommandResult<'keyboard'>>;
516502
clipboard: (options: ClipboardCommandOptions) => Promise<CommandResult<'clipboard'>>;
517503
reactNative: (options: ReactNativeCommandOptions) => Promise<CommandRequestResult>;
518504
prepare: (options: PrepareCommandOptions) => Promise<CommandRequestResult>;

‎src/client.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ export function createAgentDeviceClient(
110110
rotate: async (options) => await executeCommand<CommandResult<'rotate'>>('rotate', options),
111111
appSwitcher: async (options = {}) =>
112112
await executeCommand<CommandResult<'app-switcher'>>('app-switcher', options),
113-
keyboard: async (options = {}) => await executeCommand('keyboard', options),
113+
keyboard: async (options = {}) =>
114+
await executeCommand<CommandResult<'keyboard'>>('keyboard', options),
114115
clipboard: async (options) =>
115116
await executeCommand<CommandResult<'clipboard'>>('clipboard', options),
116117
reactNative: async (options) => await executeCommand('react-native', options),

‎src/contracts/keyboard.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Closed result of the `keyboard` command, grounded in the dispatch handlers'
3+
* literal returns (src/core/dispatch.ts `handleAndroidKeyboardCommand` /
4+
* `handleIosKeyboardCommand`).
5+
*
6+
* `platform` and `action` are always present; the remaining fields appear per
7+
* branch (Android `status`/`dismiss` carry the keyboard-state fields; `enter`
8+
* and iOS `dismiss` carry a `message`). It is kept as a flat closed shape rather
9+
* than a five-way `platform`×`action` union because the per-branch field sets
10+
* overlap heavily and the underlying Android keyboard-state types live in the
11+
* platform layer (below the public contract). The `Record` index signature of
12+
* the previous hand-written mirror is dropped, and the spurious `| null`s are
13+
* removed (the handler never returns `null` for these).
14+
*/
15+
export type KeyboardCommandResult = {
16+
platform: 'android' | 'ios';
17+
action: 'status' | 'dismiss' | 'enter';
18+
visible?: boolean;
19+
wasVisible?: boolean;
20+
dismissed?: boolean;
21+
attempts?: number;
22+
inputType?: string;
23+
type?: 'text' | 'number' | 'email' | 'phone' | 'password' | 'datetime' | 'unknown';
24+
inputMethodPackage?: string;
25+
focusedPackage?: string;
26+
focusedResourceId?: string;
27+
inputOwner?: 'app' | 'ime' | 'unknown';
28+
message?: string;
29+
};

‎src/core/command-descriptor/__tests__/command-result.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {
1414
} from '../../../contracts/navigation.ts';
1515
import type { ClipboardCommandResult } from '../../../contracts/clipboard.ts';
1616
import type { AppStateCommandResult } from '../../../contracts/app-state.ts';
17+
import type { KeyboardCommandResult } from '../../../contracts/keyboard.ts';
1718
import type { CommandResult, CommandResultMap } from '../command-result.ts';
1819

1920
/**
@@ -38,6 +39,7 @@ test('seeded CommandResult entries resolve to their existing contract result typ
3839
const appSwitcher: Equal<CommandResult<'app-switcher'>, AppSwitcherCommandResult> = true;
3940
const clipboard: Equal<CommandResult<'clipboard'>, ClipboardCommandResult> = true;
4041
const appstate: Equal<CommandResult<'appstate'>, AppStateCommandResult> = true;
42+
const keyboard: Equal<CommandResult<'keyboard'>, KeyboardCommandResult> = true;
4143
expect([
4244
press,
4345
fill,
@@ -51,7 +53,8 @@ test('seeded CommandResult entries resolve to their existing contract result typ
5153
appSwitcher,
5254
clipboard,
5355
appstate,
54-
]).toEqual([true, true, true, true, true, true, true, true, true, true, true, true]);
56+
keyboard,
57+
]).toEqual([true, true, true, true, true, true, true, true, true, true, true, true, true]);
5558
});
5659

5760
test('unmigrated commands fall back to the untyped Record bag, keeping the union total', () => {
@@ -76,6 +79,7 @@ test('CommandResultMap is seeded only from already-existing contract result type
7679
| 'app-switcher'
7780
| 'clipboard'
7881
| 'appstate'
82+
| 'keyboard'
7983
> = true;
8084
expect(keys).toBe(true);
8185
});

‎src/core/command-descriptor/command-result.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type {
1313
} from '../../contracts/navigation.ts';
1414
import type { ClipboardCommandResult } from '../../contracts/clipboard.ts';
1515
import type { AppStateCommandResult } from '../../contracts/app-state.ts';
16+
import type { KeyboardCommandResult } from '../../contracts/keyboard.ts';
1617

1718
/**
1819
* The additive typed-result spine (ADR-0008, Phase 1 step 6).
@@ -28,7 +29,8 @@ import type { AppStateCommandResult } from '../../contracts/app-state.ts';
2829
* commands `home` / `back` / `rotate` / `app-switcher` alongside the seed
2930
* interaction trio. Batch 3 adds `clipboard` (a closed `read`/`write` union) and
3031
* `appstate` (a closed `platform` union — Apple session state with the iOS-only
31-
* device locators, or Android package/activity). Each entry is grounded in a
32+
* device locators, or Android package/activity). Batch 4 adds `keyboard` (a
33+
* closed flat shape). Each entry is grounded in a
3234
* re-read of the handler's literal return; see the per-type docstrings.
3335
*/
3436
export interface CommandResultMap {
@@ -44,6 +46,7 @@ export interface CommandResultMap {
4446
'app-switcher': AppSwitcherCommandResult;
4547
clipboard: ClipboardCommandResult;
4648
appstate: AppStateCommandResult;
49+
keyboard: KeyboardCommandResult;
4750
}
4851

4952
/**

0 commit comments

Comments
 (0)