@@ -4,11 +4,7 @@ import { semanticClientCommands } from './semantic-client-commands.ts';
44import type { JsonSchema } from './semantic-contract.ts' ;
55import { bootSemanticCommand } from './semantic-device.ts' ;
66import { interactionSemanticCommands } from './semantic-interactions.ts' ;
7- import {
8- isSemanticBatchCommand as isSemanticGrammarBatchCommand ,
9- semanticBatchCommandNames ,
10- type SemanticBatchCommand ,
11- } from './semantic-grammar.ts' ;
7+ import { semanticBatchCommandNames , type SemanticBatchCommand } from './semantic-grammar.ts' ;
128
139type AnySemanticCommandDefinition = {
1410 name : string ;
@@ -18,123 +14,29 @@ type AnySemanticCommandDefinition = {
1814 invoke : ( client : AgentDeviceClient , input : unknown ) => Promise < unknown > ;
1915} ;
2016
21- type CommandSurfaceEntry < TDefinition extends AnySemanticCommandDefinition > = {
22- definition : TDefinition ;
23- batch : boolean ;
24- genericCli : boolean ;
25- } ;
26-
27- function commandSurfaceEntry <
28- TDefinition extends AnySemanticCommandDefinition ,
29- const TMetadata extends Omit < CommandSurfaceEntry < TDefinition > , 'definition' > ,
30- > ( definition : TDefinition , metadata : TMetadata ) : { definition : TDefinition } & TMetadata {
31- return { definition, ...metadata } ;
32- }
33-
34- const semanticGenericCliCommandNames = [
35- 'boot' ,
36- 'push' ,
37- 'perf' ,
38- 'click' ,
39- 'get' ,
40- 'replay' ,
41- 'test' ,
42- 'batch' ,
43- 'press' ,
44- 'longpress' ,
45- 'swipe' ,
46- 'gesture' ,
47- 'focus' ,
48- 'type' ,
49- 'fill' ,
50- 'scroll' ,
51- 'trigger-app-event' ,
52- 'record' ,
53- 'trace' ,
54- 'logs' ,
55- 'network' ,
56- 'react-native' ,
57- 'find' ,
58- 'is' ,
59- 'settings' ,
60- ] as const ;
61-
62- const semanticDedicatedCliCommandNames = [
63- 'wait' ,
64- 'alert' ,
65- 'appstate' ,
66- 'back' ,
67- 'home' ,
68- 'rotate' ,
69- 'app-switcher' ,
70- 'keyboard' ,
71- 'clipboard' ,
72- 'devices' ,
73- 'apps' ,
74- 'session' ,
75- 'open' ,
76- 'close' ,
77- 'install' ,
78- 'reinstall' ,
79- 'install-from-source' ,
80- 'snapshot' ,
81- 'screenshot' ,
82- 'diff' ,
83- 'metro' ,
84- ] as const ;
85-
86- const semanticCliCommandNames = [
87- ...semanticGenericCliCommandNames ,
88- ...semanticDedicatedCliCommandNames ,
89- ] as const ;
90-
91- const genericCliNames = commandNameSet ( semanticGenericCliCommandNames ) ;
92-
93- const baseCommandSurface = [
94- commandSurfaceEntry ( bootSemanticCommand , commandMetadata ( bootSemanticCommand . name ) ) ,
95- ...interactionSemanticCommands . map ( ( definition ) =>
96- commandSurfaceEntry ( definition , commandMetadata ( definition . name ) ) ,
97- ) ,
98- ...semanticClientCommands . map ( ( definition ) =>
99- commandSurfaceEntry ( definition , commandMetadata ( definition . name ) ) ,
100- ) ,
101- ] as const ;
102-
10317const batchSemanticCommand = createBatchSemanticCommand ( semanticBatchCommandNames ) ;
10418
10519const semanticCommandSurface = [
106- ...baseCommandSurface ,
107- commandSurfaceEntry ( batchSemanticCommand , {
108- batch : false ,
109- genericCli : true ,
110- } ) ,
20+ bootSemanticCommand ,
21+ ...interactionSemanticCommands ,
22+ ...semanticClientCommands ,
23+ batchSemanticCommand ,
11124] as const ;
11225
113- export type SemanticCommandName = ( typeof semanticCommandSurface ) [ number ] [ 'definition' ] [ ' name'] ;
114- export type SemanticCliCommand = ( typeof semanticCliCommandNames ) [ number ] ;
26+ export type SemanticCommandName = ( typeof semanticCommandSurface ) [ number ] [ 'name' ] ;
27+ export type SemanticCliCommand = SemanticCommandName ;
11528export type { SemanticBatchCommand } ;
11629
11730const semanticCommandMap = new Map (
118- semanticCommandSurface . map ( ( entry ) => [ entry . definition . name , entry . definition ] ) ,
31+ semanticCommandSurface . map ( ( definition ) => [ definition . name , definition ] ) ,
11932) ;
12033
121- function commandMetadata (
122- name : string ,
123- ) : Omit < CommandSurfaceEntry < AnySemanticCommandDefinition > , 'definition' > {
124- return {
125- batch : isSemanticGrammarBatchCommand ( name ) ,
126- genericCli : genericCliNames . has ( name ) ,
127- } ;
128- }
129-
13034export function listSemanticMcpToolDefinitions ( ) : AnySemanticCommandDefinition [ ] {
131- return semanticCommandSurface . map ( ( entry ) => entry . definition ) ;
35+ return [ ... semanticCommandSurface ] ;
13236}
13337
134- export function listSemanticGenericCliCommands ( ) : SemanticCliCommand [ ] {
135- return semanticCommandSurface
136- . filter ( ( entry ) => entry . genericCli )
137- . map ( ( entry ) => entry . definition . name as SemanticCliCommand ) ;
38+ export function listSemanticCommandNames ( ) : SemanticCommandName [ ] {
39+ return semanticCommandSurface . map ( ( definition ) => definition . name ) ;
13840}
13941
14042export function isSemanticCommandName ( name : string ) : name is SemanticCommandName {
@@ -152,7 +54,3 @@ export async function runSemanticCommand(
15254 }
15355 return await definition . invoke ( client , input ) ;
15456}
155-
156- function commandNameSet < const TName extends string > ( names : readonly TName [ ] ) : ReadonlySet < string > {
157- return new Set ( names ) ;
158- }
0 commit comments