11// The typed-flags request from contracts/, not the daemon's server-side refinement: these
22// descriptors read `command`, `positionals` and `flags` and never touch `internal`.
33import type { DispatchedCommand } from '@agent-device/contracts/command' ;
4+ import type {
5+ RuntimeUseStep ,
6+ RuntimeUseStepSelector ,
7+ } from '@agent-device/contracts/command-platform-execution' ;
48import type { RefFrameEffect } from '@agent-device/contracts/replay' ;
5- import { isReadOnlyFindAction , parseFindArgs } from '@agent-device/selectors' ;
9+ import {
10+ checkFindArgs ,
11+ isReadOnlyFindAction ,
12+ parseFindArgs ,
13+ type FindAction ,
14+ } from '@agent-device/selectors' ;
615import { resolveWaitBudgetMs } from '../wait-positionals.ts' ;
716import {
817 DEFAULT_TIMEOUT_POLICY ,
@@ -39,6 +48,7 @@ import {
3948 clipboardRuntimePlanUses ,
4049 deviceBootRuntimeUses ,
4150 fillRuntimeUses ,
51+ findRuntimeIntent ,
4252 findRuntimePlanUses ,
4353 focusRuntimeUse ,
4454 gestureRuntimePlanUses ,
@@ -50,6 +60,8 @@ import {
5060 orientationRuntimeUse ,
5161 perfRuntimePlanUses ,
5262 pressRuntimeUses ,
63+ resolveSelectorCaptureRuntimePlan ,
64+ resolveSnapshotRuntimePlan ,
5365 screenshotRuntimePlanUses ,
5466 scrollRuntimePlanUses ,
5567 selectorCaptureRuntimePlanUses ,
@@ -64,7 +76,6 @@ import {
6476 viewportRuntimeUse ,
6577 waitSelectorCaptureRuntimePlanUses ,
6678} from '@agent-device/contracts/platform-runtime-operations' ;
67- import { selectFindStepUses , selectSnapshotStepUses } from './step-use-selectors.ts' ;
6879import { assertRecordRuntimeExecution } from '@agent-device/contracts/record-runtime-execution' ;
6980import { screenRecordingRuntimePlanUses } from '@agent-device/contracts/screen-recording-runtime-plan' ;
7081import { readDeclaredPlatformExecution } from './platform-execution-entry.ts' ;
@@ -431,6 +442,44 @@ const DEPLOY_APP_COMMAND_DESCRIPTOR = {
431442 batchable : true ,
432443} as const ;
433444
445+ /**
446+ * Plan-time selectors for the commands whose declared alternatives differ in what they execute.
447+ * Each reads the daemon step exactly as its handler will (`flags` and `positionals`; a structured
448+ * `input` only when a caller kept one) and resolves the same plan the handler resolves, for both
449+ * sides of the active-app split the plan cannot know yet.
450+ */
451+ export const selectSnapshotStepUses : RuntimeUseStepSelector = ( step ) => {
452+ const customActions =
453+ step . flags ?. [ 'snapshotCustomActions' ] === true || step . input ?. [ 'customActions' ] === true ;
454+ return [ true , false ] . map (
455+ ( hasActiveApp ) => resolveSnapshotRuntimePlan ( { customActions, hasActiveApp } ) . use ,
456+ ) ;
457+ } ;
458+
459+ /**
460+ * `find` parses its action from positionals and defaults a missing one to click, so a step the
461+ * handler would not parse as a read-only, focus, or type action keeps every declared alternative
462+ * (fail closed), including a step whose positionals are not there to parse.
463+ */
464+ export const selectFindStepUses : RuntimeUseStepSelector = ( step ) => {
465+ const action = findStepAction ( step ) ;
466+ if ( action === undefined || ! plansOwnLeg ( action ) ) return findRuntimePlanUses ;
467+ const intent = findRuntimeIntent ( action ) ;
468+ return [ true , false ] . map (
469+ ( hasActiveApp ) => resolveSelectorCaptureRuntimePlan ( { hasActiveApp, intent } ) . use ,
470+ ) ;
471+ } ;
472+
473+ function plansOwnLeg ( action : FindAction [ 'kind' ] ) : boolean {
474+ return isReadOnlyFindAction ( action ) || action === 'focus' || action === 'type' ;
475+ }
476+
477+ function findStepAction ( step : RuntimeUseStep ) : FindAction [ 'kind' ] | undefined {
478+ if ( step . positionals === undefined ) return undefined ;
479+ const checked = checkFindArgs ( step . positionals , step . flags ) ;
480+ return checked . ok ? checked . parsed . action : undefined ;
481+ }
482+
434483export const RAW_COMMAND_DESCRIPTORS = [
435484 {
436485 name : 'human_control' ,
0 commit comments