Skip to content

Commit 7616ba2

Browse files
committed
refactor(plan): keep the step-use selectors inside the registry
The eager-closure ratchet counts every module the registry loads; the selectors need nothing the registry does not already import, so they live beside find's recording-effect reader instead of adding a module to every entry that loads the registry.
1 parent e319193 commit 7616ba2

4 files changed

Lines changed: 53 additions & 55 deletions

File tree

‎src/core/command-descriptor/__tests__/find-runtime-execution.test.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
import { commandDescriptors, selectFindStepUses } from '../registry.ts';
12
import { expect, test } from 'vitest';
23
import { findRuntimePlanUses } from '@agent-device/contracts/platform-runtime-operations';
3-
import { selectFindStepUses } from '../step-use-selectors.ts';
4-
import { commandDescriptors } from '../registry.ts';
54

65
test('find descriptor declares its complete runtime uses with no legacy projection', () => {
76
const find = commandDescriptors.find(({ name }) => name === 'find');

‎src/core/command-descriptor/__tests__/snapshot-runtime-execution.test.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
import { commandDescriptors, selectSnapshotStepUses } from '../registry.ts';
12
import { snapshotRuntimePlanUses } from '@agent-device/contracts/platform-runtime-operations';
2-
import { selectSnapshotStepUses } from '../step-use-selectors.ts';
33
import { expect, test } from 'vitest';
4-
import { commandDescriptors } from '../registry.ts';
54

65
test('snapshot descriptor declares its complete planned capture uses with no legacy projection', () => {
76
const snapshot = commandDescriptors.find(({ name }) => name === 'snapshot');

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

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
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`.
33
import type { DispatchedCommand } from '@agent-device/contracts/command';
4+
import type {
5+
RuntimeUseStep,
6+
RuntimeUseStepSelector,
7+
} from '@agent-device/contracts/command-platform-execution';
48
import 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';
615
import { resolveWaitBudgetMs } from '../wait-positionals.ts';
716
import {
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';
6879
import { assertRecordRuntimeExecution } from '@agent-device/contracts/record-runtime-execution';
6980
import { screenRecordingRuntimePlanUses } from '@agent-device/contracts/screen-recording-runtime-plan';
7081
import { 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+
434483
export const RAW_COMMAND_DESCRIPTORS = [
435484
{
436485
name: 'human_control',

‎src/core/command-descriptor/step-use-selectors.ts‎

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)