agent-device 0.21.21 → 0.21.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.21.apk → agent-device-android-ime-helper-0.21.23.apk} +0 -0
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.23.apk.sha256 +1 -0
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.21.manifest.json → agent-device-android-ime-helper-0.21.23.manifest.json} +4 -4
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.23.apk +0 -0
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.23.apk.sha256 +1 -0
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.21.21.manifest.json → agent-device-android-snapshot-helper-0.21.23.manifest.json} +6 -6
- package/dist/src/android-input-ownership.js +1 -1
- package/dist/src/app-log-reconnect.js +1 -1
- package/dist/src/app-log-runtime2.js +3 -3
- package/dist/src/back-mode.js +1 -1
- package/dist/src/client-metro-companion.js +1 -1
- package/dist/src/client-metro.js +1 -1
- package/dist/src/client-options.js +3 -3
- package/dist/src/cloud-artifacts.d.ts +6 -0
- package/dist/src/code-signature-cache.js +1 -1
- package/dist/src/connection-runtime.js +1 -1
- package/dist/src/daemon-registration-owner.js +1 -1
- package/dist/src/device-session.js +3 -1
- package/dist/src/dispatch-resolve.js +1 -1
- package/dist/src/doctor-facade.js +1 -1
- package/dist/src/durable-capture-resource.js +1 -1
- package/dist/src/file.js +1 -1
- package/dist/src/helper.js +2 -2
- package/dist/src/ime-rebind.js +1 -0
- package/dist/src/ime-state.js +1 -0
- package/dist/src/instance-client.js +1 -1
- package/dist/src/interactor.js +1 -1
- package/dist/src/internal/bin.js +1 -1
- package/dist/src/internal/daemon.js +1 -1
- package/dist/src/ios-client.js +4 -4
- package/dist/src/ios-settings.js +1 -1
- package/dist/src/ios-snapshot-engine.js +1 -1
- package/dist/src/log-stream.js +33 -0
- package/dist/src/mechanics.js +16 -16
- package/dist/src/node-http.js +1 -0
- package/dist/src/owner-identity.js +1 -1
- package/dist/src/perf-runtime-plan.js +1 -1
- package/dist/src/platform-runtime-app-log-process.js +1 -1
- package/dist/src/platform-runtime-operation-host.js +1 -1
- package/dist/src/platform-runtime-screen-recording-process-host.js +1 -1
- package/dist/src/process.js +1 -1
- package/dist/src/proxy.js +2 -2
- package/dist/src/registry.js +1 -1
- package/dist/src/runner-client.js +1 -1
- package/dist/src/runner-disposal.js +1 -1
- package/dist/src/runner-operations-facade.js +1 -1
- package/dist/src/runner-start-budget.js +1 -1
- package/dist/src/runtime10.js +1 -1
- package/dist/src/screenshot-overlay-draw.js +1 -1
- package/dist/src/screenshot-runtime.js +1 -1
- package/dist/src/script.js +1 -1
- package/dist/src/sdk-batch.js +2 -2
- package/dist/src/sdk-contracts.d.ts +5 -4
- package/dist/src/simctl-settings.js +1 -1
- package/dist/src/store.js +1 -1
- package/package.json +11 -8
- package/server.json +2 -2
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.21.apk.sha256 +0 -1
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.21.apk +0 -0
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.21.apk.sha256 +0 -1
- package/dist/src/session-stream.js +0 -27
package/dist/src/script.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{M as e,P as t}from"./sdk-contracts.js";import{c as n,s as r,t as i}from"./capture.js";import{m as a}from"./sdk-batch-runner.js";import{i as o}from"./sdk-device.js";import{nr as s,tr as c}from"./sdk-batch.js";import{i as l}from"./recording-export-quality.js";import{n as u,s as d}from"./scroll-gesture.js";import{t as f}from"./gesture-plan-types.js";const p=[`pan`,`fling`,`swipe`,`pinch`,`rotate`,`transform`,`drag`];function m(e){let n=g(e),r=x(n,`kind`,p);if(r===`pan`)return{kind:r,origin:_(n,`origin`),delta:_(n,`delta`),pointerCount:a(n,`pointerCount`,{min:1,max:2}),durationMs:h(n)};if(r===`drag`)return ee(n);if(n.pointerCount!==void 0)throw new t(`INVALID_ARGS`,`pointerCount is supported only for gesture pan`);if(r===`fling`){if(n.durationMs!==void 0)throw new t(`INVALID_ARGS`,`gesture fling does not accept durationMs; use gesture pan for timed movement`);return{kind:r,direction:x(n,`direction`,u),origin:_(n,`origin`),distance:a(n,`distance`,{min:0})}}if(r===`swipe`){if(n.durationMs!==void 0)throw new t(`INVALID_ARGS`,`gesture swipe does not accept durationMs; use gesture pan for timed movement`);return{kind:r,preset:x(n,`preset`,d)}}if(r===`pinch`)return{kind:r,scale:y(n,`scale`),origin:v(n,`origin`)};if(r===`rotate`){if(n.velocity!==void 0)throw new t(`INVALID_ARGS`,`gesture rotate does not accept velocity; rotation pacing derives from degrees`);return{kind:r,degrees:y(n,`degrees`),origin:v(n,`origin`)}}return{kind:r,origin:_(n,`origin`),delta:_(n,`delta`),scale:y(n,`scale`),degrees:y(n,`degrees`),durationMs:h(n)}}function ee(e){let n=a(e,`sourceHoldMs`,{min:1,max:1e4}),r=a(e,`moveMs`,{min:16,max:1e4}),i=a(e,`destinationHoldMs`,{min:0,max:1e4});if((n??800)+(r??500)+(i??0)>1e4)throw new t(`INVALID_ARGS`,`gesture drag total duration must be at most ${f}`);return{kind:`drag`,source:b(e,`source`),destination:b(e,`destination`),sourceHoldMs:n,moveMs:r,destinationHoldMs:i}}function h(e){let n=a(e,`durationMs`);if(n!==void 0){if(n<16||n>1e4)throw new t(`INVALID_ARGS`,`Expected durationMs to be an integer between 16 and ${f}.`);return n}}function g(e){if(!e||typeof e!=`object`||Array.isArray(e))throw new t(`INVALID_ARGS`,`gesture requires structured object input`);return e}function _(e,t){let n=g(e[t]);return{x:y(n,`x`),y:y(n,`y`)}}function v(e,t){return e[t]===void 0?void 0:_(e,t)}function y(e,n){let r=e[n];if(typeof r!=`number`||!Number.isFinite(r))throw new t(`INVALID_ARGS`,`Expected ${n} to be a finite number.`);return r}function b(e,n){let r=e[n];if(typeof r!=`string`||r.trim().length===0)throw new t(`INVALID_ARGS`,`Expected ${n} to be a non-empty string.`);return r.trim()}function x(e,n,r){let i=e[n];if(typeof i!=`string`||!r.includes(i))throw new t(`INVALID_ARGS`,`Expected ${n} to be one of: ${r.join(`, `)}.`);return i}const S={swipe:{max:4,usage:`swipe accepts 4 arguments: x1 y1 x2 y2`,retired:{positional:`durationMs`,migrate:te}},"gesture pan":{max:5,usage:`gesture pan accepts at most 5 arguments: x y dx dy [durationMs]`},"gesture fling":{max:4,usage:`gesture fling accepts at most 4 arguments: direction x y [distance]`,retired:{positional:`durationMs`,migrate:(e,t)=>`use "${t}", or gesture pan for timed movement.`}},"gesture swipe":{max:1,usage:`gesture swipe accepts 1 argument: preset`,retired:{positional:`durationMs`,migrate:(e,t)=>`use "${t}", or gesture pan for timed movement.`}},"gesture pinch":{max:3,usage:`gesture pinch accepts at most 3 arguments: scale [x] [y]`},"gesture rotate":{max:3,usage:`gesture rotate accepts at most 3 arguments: degrees [x] [y]`,retired:{positional:`velocity`,migrate:(e,t)=>`use "${t}"; rotation pacing derives from degrees.`}},"gesture transform":{max:7,usage:`gesture transform accepts at most 7 arguments: x y dx dy scale degrees [durationMs]`},"gesture drag":{max:5,usage:`gesture drag accepts at most 5 arguments: source destination [sourceHoldMs] [moveMs] [destinationHoldMs]`}};function te(e,t){let[n,r,i,a,o]=e,s=C(n,i),c=C(r,a);return s===void 0||c===void 0?`use "gesture pan x1 y1 dx dy durationMs" for the same timed drag, or "${t}" for a default-duration swipe.`:`use "gesture pan ${n} ${r} ${s} ${c} ${o}" for the same timed drag, or "${t}" for a default-duration swipe.`}function C(e,t){let n=Number(t)-Number(e);return Number.isFinite(n)?n:void 0}function w(e,t){let n=S[e];if(t.length<=n.max)return;let r=n.retired;if(!r||t.length!==n.max+1||!ne(t[n.max]))return{usage:n.usage};let i=`${e} ${t.slice(0,n.max).join(` `)}`;return{usage:n.usage,migration:`The trailing ${r.positional} positional was removed: ${r.migrate(t,i)}`}}function ne(e){return e===void 0||e.trim().length===0?!1:e.startsWith("${")||Number.isFinite(Number(e))}function re(e){if(!(!e||typeof e!=`object`||Array.isArray(e))&&e.durationMs!==void 0)throw new t(`INVALID_ARGS`,`swipe does not accept durationMs; use gesture pan for timed movement`)}function T(e,t){let n=t?`${e.usage} (${t})`:e.usage;return e.migration?`${n}. ${e.migration}`:`${n}.`}function E(e,n){let r=w(e,n);if(r)throw new t(`INVALID_ARGS`,T(r))}function ie(e,t,n){let r=ae(e,t);return r?T(r,n):void 0}function ae(e,t){if(e===`swipe`)return w(`swipe`,t);if(e!==`gesture`)return;let n=`gesture ${t[0]}`;if(Object.hasOwn(S,n))return w(n,t.slice(1))}function D(e){return{origin:{x:Number(e[0]),y:Number(e[1])},delta:{x:Number(e[2]),y:Number(e[3])}}}function O(e,t){let n=e[0],r=e.slice(1);switch(n){case`pan`:{E(`gesture pan`,r);let{origin:e,delta:i}=D(r);return m({kind:n,origin:e,delta:i,pointerCount:t,durationMs:k(r[4])})}case`fling`:return E(`gesture fling`,r),m({kind:n,direction:r[0],origin:{x:Number(r[1]),y:Number(r[2])},distance:k(r[3])});case`swipe`:return E(`gesture swipe`,r),m({kind:n,preset:r[0]});case`pinch`:return E(`gesture pinch`,r),m({kind:n,scale:Number(r[0]),origin:A(r[1],r[2])});case`rotate`:return E(`gesture rotate`,r),m({kind:n,degrees:Number(r[0]),origin:A(r[1],r[2])});case`transform`:{E(`gesture transform`,r);let{origin:e,delta:t}=D(r);return m({kind:n,origin:e,delta:t,scale:Number(r[4]),degrees:Number(r[5]),durationMs:k(r[6])})}case`drag`:return E(`gesture drag`,r),m({kind:n,source:r[0],destination:r[1],sourceHoldMs:k(r[2]),moveMs:k(r[3]),destinationHoldMs:k(r[4])});default:return m({kind:n})}}function oe(e){if(e[0]!==`drag`)return;let t=O(e);return t.kind===`drag`?t:void 0}function se(e){switch(e.kind){case`pan`:return j([e.kind,e.origin.x,e.origin.y,e.delta.x,e.delta.y,e.durationMs]);case`fling`:return j([e.kind,e.direction,e.origin.x,e.origin.y,e.distance]);case`swipe`:return[e.kind,e.preset];case`pinch`:return j([e.kind,e.scale,e.origin?.x,e.origin?.y]);case`rotate`:return e.origin?j([e.kind,e.degrees,e.origin.x,e.origin.y]):[e.kind,String(e.degrees)];case`transform`:return j([e.kind,e.origin.x,e.origin.y,e.delta.x,e.delta.y,e.scale,e.degrees,e.durationMs]);case`drag`:return[e.kind,e.source,e.destination,String(e.sourceHoldMs??800),String(e.moveMs??500),String(e.destinationHoldMs??0)]}}function ce(e,t={}){return E(`swipe`,e),{from:{x:Number(e[0]),y:Number(e[1])},to:{x:Number(e[2]),y:Number(e[3])},...t.count===void 0?{}:{count:t.count},...t.pauseMs===void 0?{}:{pauseMs:t.pauseMs},...t.pattern===void 0?{}:{pattern:t.pattern}}}function le(e){switch(e.kind){case`pan`:return{gesture:{intent:`pan`,origin:e.origin,delta:e.delta,pointerCount:e.pointerCount,durationMs:e.durationMs}};case`fling`:return{gesture:{intent:`fling`,direction:e.direction,origin:e.origin,distance:e.distance}};case`swipe`:return{gesture:{intent:`fling`,preset:e.preset}};case`pinch`:return{gesture:{intent:`pinch`,origin:e.origin,scale:e.scale}};case`rotate`:return{gesture:{intent:`rotate`,origin:e.origin,degrees:e.degrees}};case`transform`:return{gesture:{intent:`transform`,origin:e.origin,delta:e.delta,scale:e.scale,degrees:e.degrees,durationMs:e.durationMs}};case`drag`:throw new t(`INVALID_ARGS`,`gesture drag targets must be resolved before coordinate normalization`)}}function ue(e){return e.kind===`drag`?{intent:`drag`,source:e.source,destination:e.destination,sourceHoldMs:e.sourceHoldMs,moveMs:e.moveMs,destinationHoldMs:e.destinationHoldMs}:le(e).gesture}function de(e){return{gesture:{intent:`fling`,from:e.from,to:e.to}}}function k(e){return e===void 0?void 0:Number(e)}function A(e,n){if(e===void 0!=(n===void 0))throw new t(`INVALID_ARGS`,`gesture origin requires both x and y coordinates`);return e===void 0?void 0:{x:Number(e),y:Number(n)}}function j(e){return e.filter(e=>e!==void 0).map(String)}const fe={ios:!0,android:!0,harmonyos:!0};function M(e){return typeof e==`string`&&Object.hasOwn(fe,e)}function N(t){return t.startsWith(`@`)?e(t)?.base??t:t}const P=/^-?\d+(\.\d+)?$/,pe=/^[^\s"'\\][^\s"\\]*$/,me=new Map([[`--count`,`count`],[`--interval-ms`,`intervalMs`],[`--hold-ms`,`holdMs`],[`--jitter-px`,`jitterPx`]]),he=new Map([[`--count`,`count`],[`--pause-ms`,`pauseMs`]]),ge=new Map([[`--pointer-count`,`pointerCount`]]),_e=new Map([[`--delay-ms`,`delayMs`]]),F={scroll:new Map([[`--until`,{key:`until`,kind:`string`}]]),wait:new Map([[`--raw`,{key:`snapshotRaw`,kind:`boolean`}],[`--depth`,{key:`snapshotDepth`,kind:`int`}],[`--scope`,{key:`snapshotScope`,kind:`string`}]])};Object.keys(F);function I(e,t){let n=[],r={},i=F[e];for(let e=0;e<t.length;e+=1){let a=t[e],o=i.get(a),s=t[e+1];if(o===void 0||o.kind!==`boolean`&&s===void 0){n.push(a);continue}if(o.kind===`boolean`){Object.assign(r,{[o.key]:!0});continue}if(o.kind===`int`){let e=J(s);if(e===null){n.push(a);continue}Object.assign(r,{[o.key]:e})}else Object.assign(r,{[o.key]:s});e+=1}return{positionals:n,flags:r}}function L(e){return e===`click`||e===`press`}function ve(e){return L(e)||e===`longpress`||e===`hover`}function R(e){return e===`type`||e===`fill`}function z(e){return H(e,ye)}function B(e){return JSON.stringify(e)}function V(e){return H(e,U)}function H(e,t){return t(e)?e:B(e)}function ye(e){return U(e)&&e.startsWith(`@`)||P.test(e)}function U(e){return pe.test(e)}const be=new Set([`fill`,`type`]);function xe(e){if(!be.has(e.command)){let t=(e.positionals??[]).map(e=>z(e));return[e.command,...t].join(` `)}let t=Se(e).map(e=>z(e)).join(` `);return[e.command,t,`<text>`].filter(e=>e.length>0).join(` `)}function Se(e){if(e.command===`type`)return[];let t=e.positionals??[],n=t[0];return n===void 0?[]:n.startsWith(`@`)?[n]:t.length>=3&&P.test(n)&&P.test(t[1]??``)?[n,t[1]]:[n]}function W(e,t){let n=t.flags??{};if(L(t.command)){typeof n.count==`number`&&e.push(`--count`,String(n.count)),typeof n.intervalMs==`number`&&e.push(`--interval-ms`,String(n.intervalMs)),typeof n.holdMs==`number`&&e.push(`--hold-ms`,String(n.holdMs)),typeof n.jitterPx==`number`&&e.push(`--jitter-px`,String(n.jitterPx)),n.doubleTap===!0&&e.push(`--double-tap`);let t=n.clickButton;t&&t!==`primary`&&e.push(`--button`,t);return}if(t.command===`swipe`){typeof n.count==`number`&&e.push(`--count`,String(n.count)),typeof n.pauseMs==`number`&&e.push(`--pause-ms`,String(n.pauseMs)),(n.pattern===`one-way`||n.pattern===`ping-pong`)&&e.push(`--pattern`,n.pattern);return}if(t.command===`gesture`){typeof n.pointerCount==`number`&&e.push(`--pointer-count`,String(n.pointerCount));return}R(t.command)&&typeof n.delayMs==`number`&&e.push(`--delay-ms`,String(n.delayMs))}function G(e,t){t&&(M(t.platform)&&e.push(`--platform`,t.platform),typeof t.metroHost==`string`&&t.metroHost.length>0&&e.push(`--metro-host`,V(t.metroHost)),typeof t.metroPort==`number`&&e.push(`--metro-port`,String(t.metroPort)),typeof t.bundleUrl==`string`&&t.bundleUrl.length>0&&e.push(`--bundle-url`,V(t.bundleUrl)),typeof t.launchUrl==`string`&&t.launchUrl.length>0&&e.push(`--launch-url`,V(t.launchUrl)))}function Ce(e,t){let[n,...r]=t.positionals??[];n&&e.push(V(n));for(let t of r)e.push(z(t));typeof t.flags?.fps==`number`&&e.push(`--fps`,String(t.flags.fps)),(typeof t.flags?.quality==`number`||typeof t.flags?.quality==`string`)&&e.push(`--quality`,String(t.flags.quality)),t.flags?.hideTouches&&e.push(`--hide-touches`)}function we(e,t){t.flags?.snapshotInteractiveOnly&&e.push(`-i`),typeof t.flags?.snapshotDepth==`number`&&e.push(`-d`,String(t.flags.snapshotDepth)),t.flags?.snapshotScope&&e.push(`-s`,z(t.flags.snapshotScope)),t.flags?.snapshotRaw&&e.push(`--raw`)}function Te(e,t){for(let n of t.positionals??[])e.push(z(n));let n=t.flags?.screenshotCropOn;typeof n==`string`&&n.length>0&&e.push(`--crop-on`,V(n)),r(e,t.flags)}function Ee(e,t,n={}){let r=t.positionals??[],i=n.includeAllPositionals?r:r.slice(0,1);for(let t of i)e.push(V(t));G(e,t.flags)}function De(e,t){for(let n of t.positionals??[])e.push(z(t.command===`wait`?N(n):n));t.command===`fold`&&t.flags?.keyframes!==void 0&&e.push(`--keyframes`,z(t.flags.keyframes)),t.command===`scroll`&&typeof t.flags?.until==`string`&&e.push(`--until`,z(t.flags.until)),t.command===`wait`&&Oe(e,t.flags),W(e,t)}function Oe(e,t){t&&(t.snapshotRaw===!0&&e.push(`--raw`),typeof t.snapshotDepth==`number`&&e.push(`--depth`,String(t.snapshotDepth)),typeof t.snapshotScope==`string`&&e.push(`--scope`,z(t.snapshotScope)))}function K(e,t){let n=[],r={},i=L(e)?me:e===`swipe`?he:e===`gesture`?ge:R(e)?_e:void 0;for(let a=0;a<t.length;a+=1){let o=t[a];if(L(e)&&o===`--double-tap`){r.doubleTap=!0;continue}let s=t[a+1];if(e===`fold`&&o===`--keyframes`&&s!==void 0){r.keyframes=s,a+=1;continue}if(L(e)&&o===`--button`&&s!==void 0){let e=s;(e===`primary`||e===`secondary`||e===`middle`)&&(r.clickButton=e),a+=1;continue}let c=i?.get(o);if(c&&s!==void 0){let e=J(s);if(e!==null){r[c]=e,a+=1;continue}}if(e===`swipe`&&o===`--pattern`&&s!==void 0){let e=s;(e===`one-way`||e===`ping-pong`)&&(r.pattern=e),a+=1;continue}n.push(o)}return{positionals:n,flags:r}}function q(e){let t=[],n={};for(let r=0;r<e.length;r+=1){let i=e[r],a=e[r+1];if(i===`--platform`&&a!==void 0){let e=a;M(e)&&(n.platform=e),r+=1;continue}if(i===`--metro-host`&&a!==void 0){n.metroHost=a,r+=1;continue}if(i===`--metro-port`&&a!==void 0){let e=J(a);e!==null&&(n.metroPort=e),r+=1;continue}if(i===`--bundle-url`&&a!==void 0){n.bundleUrl=a,r+=1;continue}if(i===`--launch-url`&&a!==void 0){n.launchUrl=a,r+=1;continue}t.push(i)}return{positionals:t,flags:n}}function J(e){if(!e)return null;let t=Number(e);return!Number.isFinite(t)||t<0?null:Math.floor(t)}function ke(e){let t;for(let n of e){if(n.command===`runtime`&&typeof n.flags.platform==`string`){t=n.flags.platform;continue}if(n.command===`open`)return n.runtime?.platform??t}return t}function Ae(e,t){for(let n of t.positionals??[])e.push(z(n));t.flags?.relaunch&&e.push(`--relaunch`),t.flags?.testIme===!0?e.push(`--test-ime`):t.flags?.testIme===!1&&e.push(`--no-test-ime`),G(e,t.runtime)}function je(e){let t=[],n={};for(let r of e){if(r===`--relaunch`){n.relaunch=!0;continue}if(r===`--test-ime`){n.testIme=!0;continue}if(r===`--no-test-ime`){n.testIme=!1;continue}t.push(r)}let r=q(t);return{positionals:r.positionals,flags:n,runtime:Me(r.flags)?r.flags:void 0}}function Me(e){return!!(e.platform||e.metroHost||e.metroPort!==void 0||e.bundleUrl||e.launchUrl)}const Y=/^[A-Z_][A-Z0-9_]*$/,Ne=new Set(o.filter(e=>e!==`web`)),Pe=new Set([`mobile`,`tv`,`desktop`]);function Fe(e){let n=[],r=[],i=e.split(/\r?\n/),a=!1,o,l=(e,n,r)=>{let i=e.kind===`multiple`?`targets-v1`:`target-v1`;throw new t(`INVALID_ARGS`,`${i} annotation on line ${e.line} must be immediately followed by its action line (line ${n+1} ${r}).`)};for(let[e,u]of i.entries()){let i=u.trim();if(i.length===0){o&&l(o,e,`is blank`);continue}if(i.startsWith(`#`)){let t=c(i);if(t.kind===`v1`){o&&l(o,e,`is another target annotation`),o={kind:`multiple`,evidence:t.evidence,line:e+1};continue}let n=s(i);if(n.kind===`v1`){o&&l(o,e,`is another target annotation`),o={kind:`single`,evidence:n.evidence,line:e+1};continue}o&&l(o,e,`is a comment`);continue}if(X(i)){if(o&&l(o,e,`is an env directive`),a)throw new t(`INVALID_ARGS`,`env directives must precede all actions (line ${e+1}).`);continue}let d=Be(u);if(!d){o&&l(o,e,`did not parse as an action`);continue}let f=ie(d.command,d.positionals??[],`line ${e+1}`);if(f)throw new t(`INVALID_ARGS`,f);o&&=(o.kind===`single`?d.targetEvidence=o.evidence:d.targetEvidences=o.evidence,void 0),n.push(d),r.push(e+1),a=!0}if(o){let e=o.kind===`multiple`?`targets-v1`:`target-v1`;throw new t(`INVALID_ARGS`,`${e} annotation on line ${o.line} must be immediately followed by its action line (end of script reached).`)}return{actions:n,actionLines:r}}function Ie(e){let t=e.split(/\r?\n/),n={};for(let[e,r]of t.entries()){let t=r.trim();if(t.length===0||t.startsWith(`#`))continue;if(X(t)){ze(n,t,e+1);continue}if(!t.startsWith(`context `))break;let i=t.match(/(?:^|\s)platform=([^\s]+)/);if(i){let e=i[1];e&&Ne.has(e)&&Z(n,`platform`,e)}let a=t.match(/(?:^|\s)target=([^\s]+)/);if(a){let e=a[1];e&&Pe.has(e)&&Z(n,`target`,e)}let o=t.match(/(?:^|\s)timeout=(\d+)/);if(o){let e=Number(o[1]);Number.isFinite(e)&&e>=1&&Z(n,`timeoutMs`,Math.floor(e))}let s=t.match(/(?:^|\s)retries=(\d+)/);if(s){let e=Number(s[1]);Number.isFinite(e)&&e>=0&&Z(n,`retries`,Math.floor(e))}}return n}function X(e){return e===`env`||e.startsWith(`env `)||e.startsWith(`env `)}function Le(e,n){let r=e.slice(3).replace(/^[\s]+/,``),i=r.indexOf(`=`);if(i<=0)throw new t(`INVALID_ARGS`,`Invalid env directive on line ${n}: expected "env KEY=VALUE".`);let a=r.slice(0,i);if(!Y.test(a))throw new t(`INVALID_ARGS`,`Invalid env key "${a}" on line ${n}: keys must be uppercase letters, digits, and underscores (e.g. APP_ID).`);if(a.startsWith(`AD_`))throw new t(`INVALID_ARGS`,`Invalid env key "${a}" on line ${n}: the AD_* namespace is reserved for built-in variables. Rename ${a} to avoid the AD_ prefix.`);return{key:a,value:Re(r.slice(i+1),n)}}function Re(e,n){if(e.length===0)return``;if(e.startsWith(`"`))try{let t=JSON.parse(e);if(typeof t!=`string`)throw Error(`not a string literal`);return t}catch{throw new t(`INVALID_ARGS`,`Invalid quoted env value on line ${n}.`)}return e}function ze(e,n,r){let{key:i,value:a}=Le(n,r),o=e.env??{};if(Object.prototype.hasOwnProperty.call(o,i))throw new t(`INVALID_ARGS`,`Duplicate env directive "${i}" on line ${r}.`);o[i]=a,e.env=o}function Z(e,n,r){let i=e[n];if(i!==void 0){let e=i===r?`Duplicate replay test metadata "${n}" in context header.`:`Conflicting replay test metadata "${n}" in context header: ${String(i)} vs ${String(r)}.`;throw new t(`INVALID_ARGS`,e)}e[n]=r}function Be(e){let r=e.trim();if(r.length===0||r.startsWith(`#`))return null;let[a,...o]=He(r);if(a===void 0||a===`context`)return null;let s={ts:Date.now(),command:a,positionals:[],flags:{}};if(a===`snapshot`){s.positionals=[];for(let e=0;e<o.length;e+=1){let t=o[e];if(t===`-i`){s.flags.snapshotInteractiveOnly=!0;continue}if(t!==`-c`){if(t===`--raw`){s.flags.snapshotRaw=!0;continue}if(t===`--force-full`){s.flags.snapshotForceFull=!0;continue}if((t===`-d`||t===`--depth`)&&e+1<o.length){let t=Number(o[e+1]);Number.isFinite(t)&&t>=0&&(s.flags.snapshotDepth=Math.floor(t)),e+=1;continue}if((t===`-s`||t===`--scope`)&&e+1<o.length){s.flags.snapshotScope=o[e+1],e+=1;continue}if(t===`--backend`&&e+1<o.length){e+=1;continue}}}return s}if(a===`open`){let e=je(o);return s.positionals=e.positionals,Object.assign(s.flags,e.flags),s.runtime=e.runtime,s}if(a===`runtime`){let e=q(o);return s.positionals=e.positionals,Object.assign(s.flags,e.flags),s}if(L(a)){let e=K(a,o);Object.assign(s.flags,e.flags);let t=e.positionals[0];if(t===void 0)return s;if(t.startsWith(`@`))return s.positionals=[N(t)],e.positionals[1]&&(s.result={refLabel:e.positionals[1]}),s;let n=e.positionals[0],r=e.positionals[1];return Q(n)&&Q(r)&&e.positionals.length>=2?(s.positionals=[n,r],s):(s.positionals=[e.positionals.join(` `)],s)}if(a===`fill`){let e=K(a,o);if(Object.assign(s.flags,e.flags),!Ve(e.positionals))return s.positionals=e.positionals,s;let[t,n,...r]=e.positionals;if(Q(t)&&Q(n))return s.positionals=[t,n,r.join(` `)],s;let[i,c,...l]=e.positionals;if(i.startsWith(`@`)){let e=N(i);return l.length>0?(s.positionals=[e,l.join(` `)],s.result={refLabel:c},s):(s.positionals=[e,c],s)}return s.positionals=[i,[c,...l].join(` `)],s}if(a===`get`){let e=o[0],t=o[1];return e===void 0||t===void 0?(s.positionals=o,s):t.startsWith(`@`)?(s.positionals=[e,N(t)],o[2]&&(s.result={refLabel:o[2]}),s):(s.positionals=[e,o.slice(1).join(` `)],s)}if(a===`swipe`||a===`type`||a===`gesture`||a===`fold`){let e=K(a,o);return Object.assign(s.flags,e.flags),s.positionals=e.positionals,s}if(a===`record`){let e=[];for(let n=0;n<o.length;n+=1){let r=o[n];if(r===i.cliToken)throw new t(`INVALID_ARGS`,i.migration.record);if(r===`--hide-touches`){s.flags.hideTouches=!0;continue}if(r===`--fps`&&n+1<o.length){let e=Number(o[n+1]);Number.isFinite(e)&&(s.flags.fps=Math.floor(e)),n+=1;continue}if(r===`--quality`&&n+1<o.length){let e=o[n+1],t=l(e);t!==void 0&&(s.flags.quality=t),n+=1;continue}e.push(r)}return s.positionals=e,s}if(a===`screenshot`){let e=[];for(let t=0;t<o.length;t+=1){let r=o[t],i=n({args:o,index:t,flags:s.flags});if(i.handled){t=i.nextIndex;continue}e.push(r)}return s.positionals=e,s}if(a===`scroll`||a===`wait`){let e=I(a,o);return Object.assign(s.flags,e.flags),s.positionals=e.positionals.map(e=>N(e)),s}return s.positionals=a===`longpress`||a===`hover`?o.map(e=>N(e)):o,s}function Ve(e){return e.length>=2}function Q(e){return e?!Number.isNaN(Number(e)):!1}function He(e){let t=[],n=0;for(;n<e.length&&(n=Ue(e,n),!(n>=e.length));){let r=e[n]===`"`?We(e,n):$(e,n)??Ye(e,n);t.push(r.value),n=r.nextCursor}return t}function Ue(e,t){let n=t;for(;n<e.length&&/\s/.test(e.charAt(n));)n+=1;return n}function We(e,n){let r=n+1,i=!1,a=r;for(;a<e.length;a+=1){let t=e.charAt(a);if(t===`"`&&!i)break;if(i){i=!1;continue}i=t===`\\`}if(a>=e.length)throw new t(`INVALID_ARGS`,`Invalid replay script line: ${e}`);let o=e.slice(n,a+1),s;try{s=JSON.parse(o)}catch{throw new t(`INVALID_ARGS`,`Invalid quoted value ${o} in replay script line: ${e}`,{hint:`Quoted replay values are JSON strings: escape backslashes, quotes, tabs, and newlines (\\\\, \\", \\t, \\n).`})}return{value:s,nextCursor:a+1}}function $(e,t){if(e[t]!==`'`)return null;let n=Ge(e,t+1);return n===-1||!qe(e,n+1)?null:{value:Je(e.slice(t+1,n)),nextCursor:n+1}}function Ge(e,t){let n=t;for(;n<e.length;){let t=e.indexOf(`'`,n);if(t===-1)return-1;if(!Ke(e,t))return t;n=t+1}return-1}function Ke(e,t){let n=0;for(;t>0&&e.charAt(t-1)===`\\`;)n+=1,--t;return n%2==1}function qe(e,t){return t>=e.length||/\s/.test(e.charAt(t))}function Je(e){return e.replaceAll(String.raw`\'`,`'`)}function Ye(e,t){let n=t;for(;n<e.length&&!/\s/.test(e.charAt(n));)n+=1;return{value:e.slice(t,n),nextCursor:n}}export{de as C,m as E,ue as S,p as T,N as _,ke as a,O as b,Ee as c,we as d,xe as f,ve as g,L as h,Ae as i,Te as l,B as m,Fe as n,De as o,z as p,Ie as r,Ce as s,Y as t,W as u,re as v,ce as w,se as x,oe as y};
|
|
1
|
+
import{M as e,P as t}from"./sdk-contracts.js";import{c as n,s as r,t as i}from"./capture.js";import{m as a}from"./sdk-batch-runner.js";import{i as o}from"./sdk-device.js";import{nr as s,tr as c}from"./sdk-batch.js";import{i as l}from"./recording-export-quality.js";import{n as u,s as d}from"./scroll-gesture.js";import{t as f}from"./gesture-plan-types.js";const p=[`pan`,`fling`,`swipe`,`pinch`,`rotate`,`transform`,`drag`];function m(e){let n=g(e),r=x(n,`kind`,p);if(r===`pan`)return{kind:r,origin:_(n,`origin`),delta:_(n,`delta`),pointerCount:a(n,`pointerCount`,{min:1,max:2}),durationMs:h(n)};if(r===`drag`)return ee(n);if(n.pointerCount!==void 0)throw new t(`INVALID_ARGS`,`pointerCount is supported only for gesture pan`);if(r===`fling`){if(n.durationMs!==void 0)throw new t(`INVALID_ARGS`,`gesture fling does not accept durationMs; use gesture pan for timed movement`);return{kind:r,direction:x(n,`direction`,u),origin:_(n,`origin`),distance:a(n,`distance`,{min:0})}}if(r===`swipe`){if(n.durationMs!==void 0)throw new t(`INVALID_ARGS`,`gesture swipe does not accept durationMs; use gesture pan for timed movement`);return{kind:r,preset:x(n,`preset`,d)}}if(r===`pinch`)return{kind:r,scale:y(n,`scale`),origin:v(n,`origin`)};if(r===`rotate`){if(n.velocity!==void 0)throw new t(`INVALID_ARGS`,`gesture rotate does not accept velocity; rotation pacing derives from degrees`);return{kind:r,degrees:y(n,`degrees`),origin:v(n,`origin`)}}return{kind:r,origin:_(n,`origin`),delta:_(n,`delta`),scale:y(n,`scale`),degrees:y(n,`degrees`),durationMs:h(n)}}function ee(e){let n=a(e,`sourceHoldMs`,{min:1,max:1e4}),r=a(e,`moveMs`,{min:16,max:1e4}),i=a(e,`destinationHoldMs`,{min:0,max:1e4});if((n??800)+(r??500)+(i??0)>1e4)throw new t(`INVALID_ARGS`,`gesture drag total duration must be at most ${f}`);return{kind:`drag`,source:b(e,`source`),destination:b(e,`destination`),sourceHoldMs:n,moveMs:r,destinationHoldMs:i}}function h(e){let n=a(e,`durationMs`);if(n!==void 0){if(n<16||n>1e4)throw new t(`INVALID_ARGS`,`Expected durationMs to be an integer between 16 and ${f}.`);return n}}function g(e){if(!e||typeof e!=`object`||Array.isArray(e))throw new t(`INVALID_ARGS`,`gesture requires structured object input`);return e}function _(e,t){let n=g(e[t]);return{x:y(n,`x`),y:y(n,`y`)}}function v(e,t){return e[t]===void 0?void 0:_(e,t)}function y(e,n){let r=e[n];if(typeof r!=`number`||!Number.isFinite(r))throw new t(`INVALID_ARGS`,`Expected ${n} to be a finite number.`);return r}function b(e,n){let r=e[n];if(typeof r!=`string`||r.trim().length===0)throw new t(`INVALID_ARGS`,`Expected ${n} to be a non-empty string.`);return r.trim()}function x(e,n,r){let i=e[n];if(typeof i!=`string`||!r.includes(i))throw new t(`INVALID_ARGS`,`Expected ${n} to be one of: ${r.join(`, `)}.`);return i}const S={swipe:{max:4,usage:`swipe accepts 4 arguments: x1 y1 x2 y2`,retired:{positional:`durationMs`,migrate:te}},"gesture pan":{max:5,usage:`gesture pan accepts at most 5 arguments: x y dx dy [durationMs]`},"gesture fling":{max:4,usage:`gesture fling accepts at most 4 arguments: direction x y [distance]`,retired:{positional:`durationMs`,migrate:(e,t)=>`use "${t}", or gesture pan for timed movement.`}},"gesture swipe":{max:1,usage:`gesture swipe accepts 1 argument: preset`,retired:{positional:`durationMs`,migrate:(e,t)=>`use "${t}", or gesture pan for timed movement.`}},"gesture pinch":{max:3,usage:`gesture pinch accepts at most 3 arguments: scale [x] [y]`},"gesture rotate":{max:3,usage:`gesture rotate accepts at most 3 arguments: degrees [x] [y]`,retired:{positional:`velocity`,migrate:(e,t)=>`use "${t}"; rotation pacing derives from degrees.`}},"gesture transform":{max:7,usage:`gesture transform accepts at most 7 arguments: x y dx dy scale degrees [durationMs]`},"gesture drag":{max:5,usage:`gesture drag accepts at most 5 arguments: source destination [sourceHoldMs] [moveMs] [destinationHoldMs]`}};function te(e,t){let[n,r,i,a,o]=e,s=C(n,i),c=C(r,a);return s===void 0||c===void 0?`use "gesture pan x1 y1 dx dy durationMs" for the same timed drag, or "${t}" for a default-duration swipe.`:`use "gesture pan ${n} ${r} ${s} ${c} ${o}" for the same timed drag, or "${t}" for a default-duration swipe.`}function C(e,t){let n=Number(t)-Number(e);return Number.isFinite(n)?n:void 0}function w(e,t){let n=S[e];if(t.length<=n.max)return;let r=n.retired;if(!r||t.length!==n.max+1||!ne(t[n.max]))return{usage:n.usage};let i=`${e} ${t.slice(0,n.max).join(` `)}`;return{usage:n.usage,migration:`The trailing ${r.positional} positional was removed: ${r.migrate(t,i)}`}}function ne(e){return e===void 0||e.trim().length===0?!1:e.startsWith("${")||Number.isFinite(Number(e))}function re(e){if(!(!e||typeof e!=`object`||Array.isArray(e))&&e.durationMs!==void 0)throw new t(`INVALID_ARGS`,`swipe does not accept durationMs; use gesture pan for timed movement`)}function T(e,t){let n=t?`${e.usage} (${t})`:e.usage;return e.migration?`${n}. ${e.migration}`:`${n}.`}function E(e,n){let r=w(e,n);if(r)throw new t(`INVALID_ARGS`,T(r))}function ie(e,t,n){let r=ae(e,t);return r?T(r,n):void 0}function ae(e,t){if(e===`swipe`)return w(`swipe`,t);if(e!==`gesture`)return;let n=`gesture ${t[0]}`;if(Object.hasOwn(S,n))return w(n,t.slice(1))}function D(e){return{origin:{x:Number(e[0]),y:Number(e[1])},delta:{x:Number(e[2]),y:Number(e[3])}}}function O(e,t){let n=e[0],r=e.slice(1);switch(n){case`pan`:{E(`gesture pan`,r);let{origin:e,delta:i}=D(r);return m({kind:n,origin:e,delta:i,pointerCount:t,durationMs:k(r[4])})}case`fling`:return E(`gesture fling`,r),m({kind:n,direction:r[0],origin:{x:Number(r[1]),y:Number(r[2])},distance:k(r[3])});case`swipe`:return E(`gesture swipe`,r),m({kind:n,preset:r[0]});case`pinch`:return E(`gesture pinch`,r),m({kind:n,scale:Number(r[0]),origin:A(r[1],r[2])});case`rotate`:return E(`gesture rotate`,r),m({kind:n,degrees:Number(r[0]),origin:A(r[1],r[2])});case`transform`:{E(`gesture transform`,r);let{origin:e,delta:t}=D(r);return m({kind:n,origin:e,delta:t,scale:Number(r[4]),degrees:Number(r[5]),durationMs:k(r[6])})}case`drag`:return E(`gesture drag`,r),m({kind:n,source:r[0],destination:r[1],sourceHoldMs:k(r[2]),moveMs:k(r[3]),destinationHoldMs:k(r[4])});default:return m({kind:n})}}function oe(e){if(e[0]!==`drag`)return;let t=O(e);return t.kind===`drag`?t:void 0}function se(e){switch(e.kind){case`pan`:return j([e.kind,e.origin.x,e.origin.y,e.delta.x,e.delta.y,e.durationMs]);case`fling`:return j([e.kind,e.direction,e.origin.x,e.origin.y,e.distance]);case`swipe`:return[e.kind,e.preset];case`pinch`:return j([e.kind,e.scale,e.origin?.x,e.origin?.y]);case`rotate`:return e.origin?j([e.kind,e.degrees,e.origin.x,e.origin.y]):[e.kind,String(e.degrees)];case`transform`:return j([e.kind,e.origin.x,e.origin.y,e.delta.x,e.delta.y,e.scale,e.degrees,e.durationMs]);case`drag`:return[e.kind,e.source,e.destination,String(e.sourceHoldMs??800),String(e.moveMs??500),String(e.destinationHoldMs??0)]}}function ce(e,t={}){return E(`swipe`,e),{from:{x:Number(e[0]),y:Number(e[1])},to:{x:Number(e[2]),y:Number(e[3])},...t.count===void 0?{}:{count:t.count},...t.pauseMs===void 0?{}:{pauseMs:t.pauseMs},...t.pattern===void 0?{}:{pattern:t.pattern}}}function le(e){switch(e.kind){case`pan`:return{gesture:{intent:`pan`,origin:e.origin,delta:e.delta,pointerCount:e.pointerCount,durationMs:e.durationMs}};case`fling`:return{gesture:{intent:`fling`,direction:e.direction,origin:e.origin,distance:e.distance}};case`swipe`:return{gesture:{intent:`fling`,preset:e.preset}};case`pinch`:return{gesture:{intent:`pinch`,origin:e.origin,scale:e.scale}};case`rotate`:return{gesture:{intent:`rotate`,origin:e.origin,degrees:e.degrees}};case`transform`:return{gesture:{intent:`transform`,origin:e.origin,delta:e.delta,scale:e.scale,degrees:e.degrees,durationMs:e.durationMs}};case`drag`:throw new t(`INVALID_ARGS`,`gesture drag targets must be resolved before coordinate normalization`)}}function ue(e){return e.kind===`drag`?{intent:`drag`,source:e.source,destination:e.destination,sourceHoldMs:e.sourceHoldMs,moveMs:e.moveMs,destinationHoldMs:e.destinationHoldMs}:le(e).gesture}function de(e){return{gesture:{intent:`fling`,from:e.from,to:e.to}}}function k(e){return e===void 0?void 0:Number(e)}function A(e,n){if(e===void 0!=(n===void 0))throw new t(`INVALID_ARGS`,`gesture origin requires both x and y coordinates`);return e===void 0?void 0:{x:Number(e),y:Number(n)}}function j(e){return e.filter(e=>e!==void 0).map(String)}const fe={ios:!0,android:!0,harmonyos:!0};function M(e){return typeof e==`string`&&Object.hasOwn(fe,e)}function N(t){return t.startsWith(`@`)?e(t)?.base??t:t}const P=/^-?\d+(\.\d+)?$/,pe=/^[^\s"'\\][^\s"\\]*$/,me=new Map([[`--count`,`count`],[`--interval-ms`,`intervalMs`],[`--hold-ms`,`holdMs`],[`--jitter-px`,`jitterPx`]]),he=new Map([[`--count`,`count`],[`--pause-ms`,`pauseMs`]]),ge=new Map([[`--pointer-count`,`pointerCount`]]),_e=new Map([[`--delay-ms`,`delayMs`]]),F={scroll:new Map([[`--until`,{key:`until`,kind:`string`}]]),wait:new Map([[`--raw`,{key:`snapshotRaw`,kind:`boolean`}],[`--depth`,{key:`snapshotDepth`,kind:`int`}],[`--scope`,{key:`snapshotScope`,kind:`string`}]])};Object.keys(F);function ve(e,t){let n=[],r={},i=F[e];for(let e=0;e<t.length;e+=1){let a=t[e],o=i.get(a),s=t[e+1];if(o===void 0||o.kind!==`boolean`&&s===void 0){n.push(a);continue}if(o.kind===`boolean`){Object.assign(r,{[o.key]:!0});continue}if(o.kind===`int`){let e=q(s);if(e===null){n.push(a);continue}Object.assign(r,{[o.key]:e})}else Object.assign(r,{[o.key]:s});e+=1}return{positionals:n,flags:r}}function I(e){return e===`click`||e===`press`}function ye(e){return I(e)||e===`longpress`||e===`hover`}function L(e){return e===`type`||e===`fill`}function R(e){return V(e,be)}function z(e){return JSON.stringify(e)}function B(e){return V(e,H)}function V(e,t){return t(e)?e:z(e)}function be(e){return H(e)&&e.startsWith(`@`)||P.test(e)}function H(e){return pe.test(e)}const xe=new Set([`fill`,`type`]);function Se(e){if(!xe.has(e.command)){let t=(e.positionals??[]).map(e=>R(e));return[e.command,...t].join(` `)}let t=Ce(e).map(e=>R(e)).join(` `);return[e.command,t,`<text>`].filter(e=>e.length>0).join(` `)}function Ce(e){if(e.command===`type`)return[];let t=e.positionals??[],n=t[0];return n===void 0?[]:n.startsWith(`@`)?[n]:t.length>=3&&P.test(n)&&P.test(t[1]??``)?[n,t[1]]:[n]}function U(e,t){let n=t.flags??{};if(I(t.command)){typeof n.count==`number`&&e.push(`--count`,String(n.count)),typeof n.intervalMs==`number`&&e.push(`--interval-ms`,String(n.intervalMs)),typeof n.holdMs==`number`&&e.push(`--hold-ms`,String(n.holdMs)),typeof n.jitterPx==`number`&&e.push(`--jitter-px`,String(n.jitterPx)),n.doubleTap===!0&&e.push(`--double-tap`);let t=n.clickButton;t&&t!==`primary`&&e.push(`--button`,t);return}if(t.command===`swipe`){typeof n.count==`number`&&e.push(`--count`,String(n.count)),typeof n.pauseMs==`number`&&e.push(`--pause-ms`,String(n.pauseMs)),(n.pattern===`one-way`||n.pattern===`ping-pong`)&&e.push(`--pattern`,n.pattern);return}if(t.command===`gesture`){typeof n.pointerCount==`number`&&e.push(`--pointer-count`,String(n.pointerCount));return}L(t.command)&&typeof n.delayMs==`number`&&e.push(`--delay-ms`,String(n.delayMs))}function W(e,t){t&&(M(t.platform)&&e.push(`--platform`,t.platform),typeof t.metroHost==`string`&&t.metroHost.length>0&&e.push(`--metro-host`,B(t.metroHost)),typeof t.metroPort==`number`&&e.push(`--metro-port`,String(t.metroPort)),typeof t.bundleUrl==`string`&&t.bundleUrl.length>0&&e.push(`--bundle-url`,B(t.bundleUrl)),typeof t.launchUrl==`string`&&t.launchUrl.length>0&&e.push(`--launch-url`,B(t.launchUrl)))}function we(e,t){let[n,...r]=t.positionals??[];n&&e.push(B(n));for(let t of r)e.push(R(t));typeof t.flags?.fps==`number`&&e.push(`--fps`,String(t.flags.fps)),(typeof t.flags?.quality==`number`||typeof t.flags?.quality==`string`)&&e.push(`--quality`,String(t.flags.quality)),t.flags?.hideTouches&&e.push(`--hide-touches`)}function Te(e,t){t.flags?.snapshotInteractiveOnly&&e.push(`-i`),typeof t.flags?.snapshotDepth==`number`&&e.push(`-d`,String(t.flags.snapshotDepth)),t.flags?.snapshotScope&&e.push(`-s`,R(t.flags.snapshotScope)),t.flags?.snapshotRaw&&e.push(`--raw`)}function Ee(e,t){for(let n of t.positionals??[])e.push(R(n));let n=t.flags?.screenshotCropOn;typeof n==`string`&&n.length>0&&e.push(`--crop-on`,B(n)),r(e,t.flags)}function De(e,t,n={}){let r=t.positionals??[],i=n.includeAllPositionals?r:r.slice(0,1);for(let t of i)e.push(B(t));W(e,t.flags)}function Oe(e,t){for(let n of t.positionals??[])e.push(R(t.command===`wait`?N(n):n));t.command===`fold`&&t.flags?.keyframes!==void 0&&e.push(`--keyframes`,R(t.flags.keyframes)),t.command===`scroll`&&typeof t.flags?.until==`string`&&e.push(`--until`,R(t.flags.until)),t.command===`wait`&&ke(e,t.flags),U(e,t)}function ke(e,t){t&&(t.snapshotRaw===!0&&e.push(`--raw`),typeof t.snapshotDepth==`number`&&e.push(`--depth`,String(t.snapshotDepth)),typeof t.snapshotScope==`string`&&e.push(`--scope`,R(t.snapshotScope)))}function G(e,t){let n=[],r={},i=I(e)?me:e===`swipe`?he:e===`gesture`?ge:L(e)?_e:void 0;for(let a=0;a<t.length;a+=1){let o=t[a];if(I(e)&&o===`--double-tap`){r.doubleTap=!0;continue}let s=t[a+1];if(e===`fold`&&o===`--keyframes`&&s!==void 0){r.keyframes=s,a+=1;continue}if(I(e)&&o===`--button`&&s!==void 0){let e=s;(e===`primary`||e===`secondary`||e===`middle`)&&(r.clickButton=e),a+=1;continue}let c=i?.get(o);if(c&&s!==void 0){let e=q(s);if(e!==null){r[c]=e,a+=1;continue}}if(e===`swipe`&&o===`--pattern`&&s!==void 0){let e=s;(e===`one-way`||e===`ping-pong`)&&(r.pattern=e),a+=1;continue}n.push(o)}return{positionals:n,flags:r}}function K(e){let t=[],n={};for(let r=0;r<e.length;r+=1){let i=e[r],a=e[r+1];if(i===`--platform`&&a!==void 0){let e=a;M(e)&&(n.platform=e),r+=1;continue}if(i===`--metro-host`&&a!==void 0){n.metroHost=a,r+=1;continue}if(i===`--metro-port`&&a!==void 0){let e=q(a);e!==null&&(n.metroPort=e),r+=1;continue}if(i===`--bundle-url`&&a!==void 0){n.bundleUrl=a,r+=1;continue}if(i===`--launch-url`&&a!==void 0){n.launchUrl=a,r+=1;continue}t.push(i)}return{positionals:t,flags:n}}function q(e){if(!e)return null;let t=Number(e);return!Number.isFinite(t)||t<0?null:Math.floor(t)}function Ae(e){let t;for(let n of e){if(n.command===`runtime`&&typeof n.flags.platform==`string`){t=n.flags.platform;continue}if(n.command===`open`)return n.runtime?.platform??t}return t}function je(e,t){for(let n of t.positionals??[])e.push(R(n));t.flags?.relaunch&&e.push(`--relaunch`),t.flags?.surface!==void 0&&e.push(`--surface`,t.flags.surface),t.flags?.testIme===!0?e.push(`--test-ime`):t.flags?.testIme===!1&&e.push(`--no-test-ime`),W(e,t.runtime)}function Me(e){let t=[],n={};for(let r=0;r<e.length;r+=1){let i=e[r];if(i===`--surface`){n.surface=Pe(e[r+1]),r+=1;continue}if(i===`--relaunch`){n.relaunch=!0;continue}if(i===`--test-ime`){n.testIme=!0;continue}if(i===`--no-test-ime`){n.testIme=!1;continue}t.push(i)}let r=K(t);return{positionals:r.positionals,flags:n,runtime:Fe(r.flags)?r.flags:void 0}}const J={app:!0,"frontmost-app":!0,desktop:!0,menubar:!0};function Ne(e){return Object.hasOwn(J,e)}function Pe(e){let n=e?.trim().toLowerCase();if(n!==void 0&&Ne(n))return n;throw new t(`INVALID_ARGS`,`Invalid surface: ${e}. Use ${Object.keys(J).join(`|`)}.`)}function Fe(e){return!!(e.platform||e.metroHost||e.metroPort!==void 0||e.bundleUrl||e.launchUrl)}const Y=/^[A-Z_][A-Z0-9_]*$/,Ie=new Set(o.filter(e=>e!==`web`)),Le=new Set([`mobile`,`tv`,`desktop`]);function Re(e){let n=[],r=[],i=e.split(/\r?\n/),a=!1,o,l=(e,n,r)=>{let i=e.kind===`multiple`?`targets-v1`:`target-v1`;throw new t(`INVALID_ARGS`,`${i} annotation on line ${e.line} must be immediately followed by its action line (line ${n+1} ${r}).`)};for(let[e,u]of i.entries()){let i=u.trim();if(i.length===0){o&&l(o,e,`is blank`);continue}if(i.startsWith(`#`)){let t=c(i);if(t.kind===`v1`){o&&l(o,e,`is another target annotation`),o={kind:`multiple`,evidence:t.evidence,line:e+1};continue}let n=s(i);if(n.kind===`v1`){o&&l(o,e,`is another target annotation`),o={kind:`single`,evidence:n.evidence,line:e+1};continue}o&&l(o,e,`is a comment`);continue}if(X(i)){if(o&&l(o,e,`is an env directive`),a)throw new t(`INVALID_ARGS`,`env directives must precede all actions (line ${e+1}).`);continue}let d=Q(u);if(!d){o&&l(o,e,`did not parse as an action`);continue}let f=ie(d.command,d.positionals??[],`line ${e+1}`);if(f)throw new t(`INVALID_ARGS`,f);o&&=(o.kind===`single`?d.targetEvidence=o.evidence:d.targetEvidences=o.evidence,void 0),n.push(d),r.push(e+1),a=!0}if(o){let e=o.kind===`multiple`?`targets-v1`:`target-v1`;throw new t(`INVALID_ARGS`,`${e} annotation on line ${o.line} must be immediately followed by its action line (end of script reached).`)}return{actions:n,actionLines:r}}function ze(e){let t=e.split(/\r?\n/),n={};for(let[e,r]of t.entries()){let t=r.trim();if(t.length===0||t.startsWith(`#`))continue;if(X(t)){He(n,t,e+1);continue}if(!t.startsWith(`context `))break;let i=t.match(/(?:^|\s)platform=([^\s]+)/);if(i){let e=i[1];e&&Ie.has(e)&&Z(n,`platform`,e)}let a=t.match(/(?:^|\s)target=([^\s]+)/);if(a){let e=a[1];e&&Le.has(e)&&Z(n,`target`,e)}let o=t.match(/(?:^|\s)timeout=(\d+)/);if(o){let e=Number(o[1]);Number.isFinite(e)&&e>=1&&Z(n,`timeoutMs`,Math.floor(e))}let s=t.match(/(?:^|\s)retries=(\d+)/);if(s){let e=Number(s[1]);Number.isFinite(e)&&e>=0&&Z(n,`retries`,Math.floor(e))}}return n}function X(e){return e===`env`||e.startsWith(`env `)||e.startsWith(`env `)}function Be(e,n){let r=e.slice(3).replace(/^[\s]+/,``),i=r.indexOf(`=`);if(i<=0)throw new t(`INVALID_ARGS`,`Invalid env directive on line ${n}: expected "env KEY=VALUE".`);let a=r.slice(0,i);if(!Y.test(a))throw new t(`INVALID_ARGS`,`Invalid env key "${a}" on line ${n}: keys must be uppercase letters, digits, and underscores (e.g. APP_ID).`);if(a.startsWith(`AD_`))throw new t(`INVALID_ARGS`,`Invalid env key "${a}" on line ${n}: the AD_* namespace is reserved for built-in variables. Rename ${a} to avoid the AD_ prefix.`);return{key:a,value:Ve(r.slice(i+1),n)}}function Ve(e,n){if(e.length===0)return``;if(e.startsWith(`"`))try{let t=JSON.parse(e);if(typeof t!=`string`)throw Error(`not a string literal`);return t}catch{throw new t(`INVALID_ARGS`,`Invalid quoted env value on line ${n}.`)}return e}function He(e,n,r){let{key:i,value:a}=Be(n,r),o=e.env??{};if(Object.prototype.hasOwnProperty.call(o,i))throw new t(`INVALID_ARGS`,`Duplicate env directive "${i}" on line ${r}.`);o[i]=a,e.env=o}function Z(e,n,r){let i=e[n];if(i!==void 0){let e=i===r?`Duplicate replay test metadata "${n}" in context header.`:`Conflicting replay test metadata "${n}" in context header: ${String(i)} vs ${String(r)}.`;throw new t(`INVALID_ARGS`,e)}e[n]=r}function Q(e){let r=e.trim();if(r.length===0||r.startsWith(`#`))return null;let[a,...o]=We(r);if(a===void 0||a===`context`)return null;let s={ts:Date.now(),command:a,positionals:[],flags:{}};if(a===`snapshot`){s.positionals=[];for(let e=0;e<o.length;e+=1){let t=o[e];if(t===`-i`){s.flags.snapshotInteractiveOnly=!0;continue}if(t!==`-c`){if(t===`--raw`){s.flags.snapshotRaw=!0;continue}if(t===`--force-full`){s.flags.snapshotForceFull=!0;continue}if((t===`-d`||t===`--depth`)&&e+1<o.length){let t=Number(o[e+1]);Number.isFinite(t)&&t>=0&&(s.flags.snapshotDepth=Math.floor(t)),e+=1;continue}if((t===`-s`||t===`--scope`)&&e+1<o.length){s.flags.snapshotScope=o[e+1],e+=1;continue}if(t===`--backend`&&e+1<o.length){e+=1;continue}}}return s}if(a===`open`){let e=Me(o);return s.positionals=e.positionals,Object.assign(s.flags,e.flags),s.runtime=e.runtime,s}if(a===`runtime`){let e=K(o);return s.positionals=e.positionals,Object.assign(s.flags,e.flags),s}if(I(a)){let e=G(a,o);Object.assign(s.flags,e.flags);let t=e.positionals[0];if(t===void 0)return s;if(t.startsWith(`@`))return s.positionals=[N(t)],e.positionals[1]&&(s.result={refLabel:e.positionals[1]}),s;let n=e.positionals[0],r=e.positionals[1];return $(n)&&$(r)&&e.positionals.length>=2?(s.positionals=[n,r],s):(s.positionals=[e.positionals.join(` `)],s)}if(a===`fill`){let e=G(a,o);if(Object.assign(s.flags,e.flags),!Ue(e.positionals))return s.positionals=e.positionals,s;let[t,n,...r]=e.positionals;if($(t)&&$(n))return s.positionals=[t,n,r.join(` `)],s;let[i,c,...l]=e.positionals;if(i.startsWith(`@`)){let e=N(i);return l.length>0?(s.positionals=[e,l.join(` `)],s.result={refLabel:c},s):(s.positionals=[e,c],s)}return s.positionals=[i,[c,...l].join(` `)],s}if(a===`get`){let e=o[0],t=o[1];return e===void 0||t===void 0?(s.positionals=o,s):t.startsWith(`@`)?(s.positionals=[e,N(t)],o[2]&&(s.result={refLabel:o[2]}),s):(s.positionals=[e,o.slice(1).join(` `)],s)}if(a===`swipe`||a===`type`||a===`gesture`||a===`fold`){let e=G(a,o);return Object.assign(s.flags,e.flags),s.positionals=e.positionals,s}if(a===`record`){let e=[];for(let n=0;n<o.length;n+=1){let r=o[n];if(r===i.cliToken)throw new t(`INVALID_ARGS`,i.migration.record);if(r===`--hide-touches`){s.flags.hideTouches=!0;continue}if(r===`--fps`&&n+1<o.length){let e=Number(o[n+1]);Number.isFinite(e)&&(s.flags.fps=Math.floor(e)),n+=1;continue}if(r===`--quality`&&n+1<o.length){let e=o[n+1],t=l(e);t!==void 0&&(s.flags.quality=t),n+=1;continue}e.push(r)}return s.positionals=e,s}if(a===`screenshot`){let e=[];for(let t=0;t<o.length;t+=1){let r=o[t],i=n({args:o,index:t,flags:s.flags});if(i.handled){t=i.nextIndex;continue}e.push(r)}return s.positionals=e,s}if(a===`scroll`||a===`wait`){let e=ve(a,o);return Object.assign(s.flags,e.flags),s.positionals=e.positionals.map(e=>N(e)),s}return s.positionals=a===`longpress`||a===`hover`?o.map(e=>N(e)):o,s}function Ue(e){return e.length>=2}function $(e){return e?!Number.isNaN(Number(e)):!1}function We(e){let t=[],n=0;for(;n<e.length&&(n=Ge(e,n),!(n>=e.length));){let r=e[n]===`"`?Ke(e,n):qe(e,n)??Qe(e,n);t.push(r.value),n=r.nextCursor}return t}function Ge(e,t){let n=t;for(;n<e.length&&/\s/.test(e.charAt(n));)n+=1;return n}function Ke(e,n){let r=n+1,i=!1,a=r;for(;a<e.length;a+=1){let t=e.charAt(a);if(t===`"`&&!i)break;if(i){i=!1;continue}i=t===`\\`}if(a>=e.length)throw new t(`INVALID_ARGS`,`Invalid replay script line: ${e}`);let o=e.slice(n,a+1),s;try{s=JSON.parse(o)}catch{throw new t(`INVALID_ARGS`,`Invalid quoted value ${o} in replay script line: ${e}`,{hint:`Quoted replay values are JSON strings: escape backslashes, quotes, tabs, and newlines (\\\\, \\", \\t, \\n).`})}return{value:s,nextCursor:a+1}}function qe(e,t){if(e[t]!==`'`)return null;let n=Je(e,t+1);return n===-1||!Xe(e,n+1)?null:{value:Ze(e.slice(t+1,n)),nextCursor:n+1}}function Je(e,t){let n=t;for(;n<e.length;){let t=e.indexOf(`'`,n);if(t===-1)return-1;if(!Ye(e,t))return t;n=t+1}return-1}function Ye(e,t){let n=0;for(;t>0&&e.charAt(t-1)===`\\`;)n+=1,--t;return n%2==1}function Xe(e,t){return t>=e.length||/\s/.test(e.charAt(t))}function Ze(e){return e.replaceAll(String.raw`\'`,`'`)}function Qe(e,t){let n=t;for(;n<e.length&&!/\s/.test(e.charAt(n));)n+=1;return{value:e.slice(t,n),nextCursor:n}}export{de as C,m as E,ue as S,p as T,N as _,Ae as a,O as b,De as c,Te as d,Se as f,ye as g,I as h,je as i,Ee as l,z as m,Re as n,Oe as o,R as p,ze as r,we as s,Y as t,U as u,re as v,ce as w,se as x,oe as y};
|
package/dist/src/sdk-batch.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{P as e,S as t,b as n}from"./sdk-contracts.js";import{g as r,r as i}from"./sdk-device.js";function a(e,t){return{ok:!1,code:`INVALID_ARGS`,message:e,...t?{hint:t}:{}}}const o=[`visible`,`hidden`,`exists`,`absent`,`editable`,`selected`,`focused`,`text`],s={x:-Number.MAX_VALUE/2,y:-Number.MAX_VALUE/2,width:Number.MAX_VALUE,height:Number.MAX_VALUE};function c(e){return e.x===s.x&&e.y===s.y&&e.width===s.width&&e.height===s.height}function l(e){if(!e)return!1;let{x:t,y:n,width:r,height:i}=e;return![t,n,r,i].every(Number.isFinite)||!Number.isFinite(t+r)||!Number.isFinite(n+i)||r<=0||i<=0?!1:!c(e)}function u(e,t){return e>=s.width||t>=s.height}function d(e){if(l(e)&&!u(e.width,e.height))return{width:e.width,height:e.height}}function ee(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let{x:t,y:n,width:r,height:i}=e;if(typeof r==`number`&&typeof i==`number`&&(t===void 0||typeof t==`number`)&&(n===void 0||typeof n==`number`))return d({x:t??0,y:n??0,width:r,height:i})}function te(e,t){return t.x>=e.x&&t.y>=e.y&&t.x+t.width<=e.x+e.width&&t.y+t.height<=e.y+e.height}function ne(e){return e.width*e.height}function re(e,t,n){return t>=e.x&&t<=e.x+e.width&&n>=e.y&&n<=e.y+e.height}function
|
|
2
|
-
`],[`r`,`\r`],[`t`,` `]]);function v(t){let n=t.trim();if(!n)throw new e(`INVALID_ARGS`,`Selector expression cannot be empty`);let r=ze(n);if(r.length===0)throw new e(`INVALID_ARGS`,`Selector expression cannot be empty`);return{raw:n,selectors:r.map(e=>Le(e))}}function y(e){try{return v(e)}catch{return null}}function b(e){let t=e.trim();if(!t)return!1;if(t===`||`)return!0;let n=t.indexOf(`=`);if(n!==-1){let e=t.slice(0,n).trim().toLowerCase();return _.has(e)}return _.has(t.toLowerCase())}function Ie(e){let t=e.trim(),n=t.indexOf(`=`);if(n===-1)return null;let r=t.slice(0,n).trim().toLowerCase();if(!r||_.has(r))return null;let i=t.slice(n+1).trim();if(!i)return null;let a=S(i).trim();return a?{key:r,value:a}:null}function x(e,t={}){if(e.length===0)return null;let n=t.preferTrailingValue??!1,r=0,i=[];for(;r<e.length;){let t=e[r];if(t===void 0||!b(t))break;r+=1;let n=e.slice(0,r).join(` `).trim();n&&y(n)&&i.push(r)}if(i.length===0)return null;let a=i.at(-1);if(a===void 0)return null;let o=a;if(n)for(let t=i.length-1;t>=0;--t){let n=i[t];if(n!==void 0&&n<e.length){o=n;break}}let s=e.slice(0,o).join(` `).trim();return s?{selectorExpression:s,rest:e.slice(o)}:null}function Le(t){let n=t.trim();if(!n)throw new e(`INVALID_ARGS`,`Selector segment cannot be empty`);let r=Be(n);if(r.length===0)throw new e(`INVALID_ARGS`,`Invalid selector segment: ${t}`);return{raw:n,terms:r.map(Re)}}function Re(t){let n=t.trim();if(!n)throw new e(`INVALID_ARGS`,`Empty selector term`);let r=n.indexOf(`=`);if(r===-1){let r=n.toLowerCase();if(!je.has(r))throw new e(`INVALID_ARGS`,`Invalid selector term "${t}", expected key=value`);return{key:r,value:!0}}let i=n.slice(0,r).trim().toLowerCase(),a=n.slice(r+1).trim();if(!_.has(i))throw new e(`INVALID_ARGS`,`Unknown selector key: ${i}`);if(!a)throw new e(`INVALID_ARGS`,`Missing selector value for key: ${i}`);if(je.has(i)){let t=We(a);if(t===null)throw new e(`INVALID_ARGS`,`Invalid boolean value for ${i}: ${a}`);return{key:i,value:t}}return{key:i,value:S(a)}}function ze(t){let n=[],r=``,i=null;for(let a=0;a<t.length;a+=1){let o=t[a];if((o===`"`||o===`'`)&&!Ge(t,a)){i=Ve(i,o),r+=o;continue}if(!i&&o===`|`&&t[a+1]===`|`){let i=r.trim();if(!i)throw new e(`INVALID_ARGS`,`Invalid selector fallback expression: ${t}`);n.push(i),r=``,a+=1;continue}r+=o}let a=r.trim();if(!a)throw new e(`INVALID_ARGS`,`Invalid selector fallback expression: ${t}`);return n.push(a),n}function Be(t){let n=[],r=``,i=null;for(let e=0;e<t.length;e+=1){let a=t.charAt(e);if((a===`"`||a===`'`)&&!Ge(t,e)){i=Ve(i,a),r+=a;continue}if(!i&&/\s/.test(a)){r.trim()&&n.push(r.trim()),r=``;continue}r+=a}if(i)throw new e(`INVALID_ARGS`,`Unclosed quote in selector: ${t}`);return r.trim()&&n.push(r.trim()),n}function Ve(e,t){return e?e===t?null:e:t}function S(e){let t=e.trim();return t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`)?He(t.slice(1,-1)):t}function He(e){let t=``,n=0;for(;n<e.length;){let r=e.charAt(n);if(r!==`\\`){t+=r,n+=1;continue}let i=e.charAt(n+1);if(!i){t+=r,n+=1;continue}let a=Ue(i);if(a!==null){t+=a,n+=2;continue}if(i===`u`){let r=e.slice(n+2,n+6);if(/^[0-9a-fA-F]{4}$/.test(r)){t+=String.fromCharCode(Number.parseInt(r,16)),n+=6;continue}}t+=r,n+=1}return t}function Ue(e){return Fe.get(e)??null}function We(e){let t=S(e).toLowerCase();return t===`true`||t!==`false`&&null}function Ge(e,t){let n=0;for(let r=t-1;r>=0&&e[r]===`\\`;--r)n+=1;return n%2==1}function C(e){return o.includes(e)}const Ke=`is requires predicate: ${o.join(`|`)}`;function qe(e){let t=e.toLowerCase();return C(t)?{ok:!0,predicate:t}:a(Ke,Je)}const Je=`Use "is <predicate> <selector>" or "is <selector> <predicate>". visible|hidden|editable|selected|focused double as selector keys: a bare predicate token after the selector is read as the predicate, so write key=true (e.g. visible=true) inside the selector to use it as a filter instead.`;function Ye(e){if(C((e[0]??``).toLowerCase()))return e;for(let t=1;t<e.length;t+=1){let n=(e[t]??``).toLowerCase();if(C(n)&&y(e.slice(0,t).join(` `)))return[n,...e.slice(0,t),...e.slice(t+1)]}return e}function Xe(e){let{predicate:t,node:n,visibility:r,expectedText:i,platform:a}=e,o=m(n),s=Oe(n,a),c=n.selected===!0,l=n.focused===!0,u=t===`text`?g(n):Qe(n,r,a),d=!1;switch(t){case`visible`:d=u;break;case`hidden`:d=!u;break;case`editable`:d=s;break;case`selected`:d=c;break;case`focused`:d=l;break;case`text`:d=o===(i??``);break;default:return Ze(t)}let ee=t===`text`?`expected="${i??``}" actual="${o}"`:`actual=${JSON.stringify({visible:u,editable:s,selected:c,focused:l})}`;return{pass:d,actualText:o,details:ee}}function Ze(e){throw Error(`Unhandled is predicate: ${String(e)}`)}function Qe(e,t,n){if(n===`android`&&e.visibleToUser===!1)return!1;if(l(e.rect))return t.isVisibleInEffectiveViewport(e);if(e.rect)return!1;if(n!==`android`&&e.hittable===!0)return!0;let r=$e(e,t,n);return r?l(r.rect)?t.isVisibleInEffectiveViewport(r):n!==`android`&&r.hittable===!0:!1}function $e(e,t,n){return t.findAncestor(e,e=>De(e,n)?e:null)}function et(e){let t=Ye(e),n=t[0]??``;return{predicate:n,split:x(t.slice(1),{preferTrailingValue:n===`text`})}}const tt=`is requires a selector expression`,nt=`is text requires expected text value`;function rt(e){let{predicate:t,split:n}=et([...e]),r=qe(t);if(!r.ok)return r;if(!n)return a(tt);let i=n.rest.join(` `).trim();return r.predicate===`text`&&!i?a(nt):r.predicate!==`text`&&n.rest.length>0?a(`is ${r.predicate} does not accept trailing values`):{ok:!0,predicate:r.predicate,selectorExpression:n.selectorExpression,expectedText:i}}function it(e){return e===`text`||e===`attrs`?{ok:!0,format:e}:a(`get only supports text or attrs`)}function at(e){let t=e[0];if(t?.startsWith(`@`)){let n=e.slice(1).join(` `).trim();return{ok:!0,ref:t,...n?{label:n}:{}}}let n=e.join(` `).trim();return n?{ok:!0,selector:n}:a(`get requires @ref or selector expression`)}function ot(e){return e?{ok:!0,text:e}:a(`wait requires text`)}function st(e){return Array.from(new Set(e))}function ct(e){return JSON.stringify(lt(e))}function lt(e){if(Array.isArray(e))return e.map(lt);if(!e||typeof e!=`object`)return e;let t=e;return Object.fromEntries(Object.keys(t).sort().map(e=>[e,lt(t[e])]))}function ut(e){let t=0,n=e.length;for(;t<n&&e[t]===`-`;)t+=1;for(;n>t&&e[n-1]===`-`;)--n;return e.slice(t,n)}const dt=/^#\s*agent-device:target-v(\d+)(?:\s+(\S.*))?$/,ft=/^#\s*agent-device:targets-v(\d+)(?:\s+(\S.*))?$/,pt=4096;function mt(e){return e.normalize(`NFC`)}function ht(e){if(e===void 0)return;let t=mt(e);return t.length>0?t:void 0}function gt(e){return mt(e)}function _t(e){if(e===void 0)return;let t=mt(e).trim().replaceAll(/\s+/g,` `);return t.length>0?t:void 0}function w(e){return Buffer.byteLength(e,`utf8`)}function T(e,t){if(w(e)<=t)return e;let n=e.length;for(;n>0&&w(e.slice(0,n))>t;)--n;if(n>0){let t=e.charCodeAt(n-1);t>=55296&&t<=56319&&--n}return e.slice(0,n)}function vt(e){let t={};return e.id!==void 0&&(t.id=e.id),t.role=e.role,e.label!==void 0&&(t.label=e.label),t.ancestry=e.ancestry.map(yt),t.sibling=e.sibling,t.viewportOrder=e.viewportOrder,e.scrollRegion&&(t.scrollRegion=bt(e.scrollRegion)),e.rect&&(t.rect=xt(e.rect)),t.verification=e.verification,t}function yt(e){let t={role:e.role};return e.label!==void 0&&(t.label=e.label),t}function bt(e){let t={role:e.role};return e.id!==void 0&&(t.id=e.id),e.label!==void 0&&(t.label=e.label),t}function xt(e){return{x:e.x,y:e.y,width:e.width,height:e.height}}function St(e){return JSON.stringify(vt(e))}function Ct(e){return`# agent-device:target-v1 ${St(e)}`}function wt(e){return JSON.stringify({source:vt(e.source),destination:vt(e.destination)})}function Tt(e){return`# agent-device:targets-v1 ${wt(e)}`}function Et(e){let t=e.trim(),n=ft.exec(t);return n?Number(n[1])===1?{kind:`v1`,evidence:Dt((n[2]??``).trim())}:{kind:`future-version`}:{kind:`none`}}function Dt(t){if(w(t)>8320)throw new e(`INVALID_ARGS`,`targets-v1 annotation exceeds the 8320-byte payload cap.`);let n;try{n=JSON.parse(t)}catch{throw new e(`INVALID_ARGS`,`targets-v1 annotation is not valid JSON.`)}if(typeof n!=`object`||!n||Array.isArray(n))throw new e(`INVALID_ARGS`,`targets-v1 annotation must be a JSON object.`);let r=n;if(r.source===void 0||r.destination===void 0)throw new e(`INVALID_ARGS`,`targets-v1 annotation requires source and destination evidence.`);return{source:kt(JSON.stringify(r.source)),destination:kt(JSON.stringify(r.destination))}}function Ot(e){let t=e.trim();if(!t.startsWith(`#`))return{kind:`none`};let n=dt.exec(t);return n?Number(n[1])===1?{kind:`v1`,evidence:kt((n[2]??``).trim())}:{kind:`future-version`}:{kind:`none`}}function kt(t){if(w(t)>4096)throw new e(`INVALID_ARGS`,`target-v1 annotation exceeds the ${pt}-byte payload cap.`);let n;try{n=JSON.parse(t)}catch{throw new e(`INVALID_ARGS`,`target-v1 annotation is not valid JSON.`)}if(typeof n!=`object`||!n||Array.isArray(n))throw new e(`INVALID_ARGS`,`target-v1 annotation must be a JSON object.`);let r=n,i=At(r.role,`role`),a=jt(r.id,`id`),o=Mt(r.label,`label`),s=Pt(r.ancestry),c=It(r.sibling,`sibling`,0),l=It(r.viewportOrder,`viewportOrder`,0),u=Lt(r.scrollRegion),d=Rt(r.rect),ee=zt(r.verification);return{...a===void 0?{}:{id:a},role:i,...o===void 0?{}:{label:o},ancestry:s,sibling:c,viewportOrder:l,...u?{scrollRegion:u}:{},...d?{rect:d}:{},verification:ee}}function At(t,n){if(t===void 0)throw new e(`INVALID_ARGS`,`target-v1 "${n}" is required.`);if(typeof t!=`string`)throw new e(`INVALID_ARGS`,`target-v1 "${n}" must be a string.`);return Nt(gt(t),n)}function jt(t,n){if(t===void 0)return;if(typeof t!=`string`)throw new e(`INVALID_ARGS`,`target-v1 "${n}" must be a string.`);let r=ht(t);return r===void 0?void 0:Nt(r,n)}function Mt(t,n){if(t===void 0)return;if(typeof t!=`string`)throw new e(`INVALID_ARGS`,`target-v1 "${n}" must be a string.`);let r=_t(t);return r===void 0?void 0:Nt(r,n)}function Nt(t,n){if(w(t)>256)throw new e(`INVALID_ARGS`,`target-v1 "${n}" exceeds the 256-byte field cap.`);return t}function Pt(t){if(t===void 0)return[];if(!Array.isArray(t))throw new e(`INVALID_ARGS`,`target-v1 "ancestry" must be an array.`);if(t.length>8)throw new e(`INVALID_ARGS`,`target-v1 "ancestry" exceeds the 8-entry cap.`);return t.map((e,t)=>Ft(e,t))}function Ft(t,n){if(typeof t!=`object`||!t||Array.isArray(t))throw new e(`INVALID_ARGS`,`target-v1 "ancestry[${n}]" must be an object.`);let r=t,i=At(r.role,`ancestry[${n}].role`),a=Mt(r.label,`ancestry[${n}].label`);return{role:i,...a===void 0?{}:{label:a}}}function It(t,n,r){if(t===void 0)return r;if(typeof t!=`number`||!Number.isSafeInteger(t)||t<0)throw new e(`INVALID_ARGS`,`target-v1 "${n}" must be a non-negative integer.`);return t}function Lt(t){if(t===void 0)return;if(typeof t!=`object`||!t||Array.isArray(t))throw new e(`INVALID_ARGS`,`target-v1 "scrollRegion" must be an object.`);let n=t,r=At(n.role,`scrollRegion.role`),i=jt(n.id,`id`),a=Mt(n.label,`scrollRegion.label`);return{role:r,...i===void 0?{}:{id:i},...a===void 0?{}:{label:a}}}function Rt(t){if(t===void 0)return;if(typeof t!=`object`||!t||Array.isArray(t))throw new e(`INVALID_ARGS`,`target-v1 "rect" must be an object.`);let n=t;return{x:E(n.x,`rect.x`),y:E(n.y,`rect.y`),width:E(n.width,`rect.width`),height:E(n.height,`rect.height`)}}function E(t,n){if(typeof t!=`number`||!Number.isFinite(t))throw new e(`INVALID_ARGS`,`target-v1 "${n}" must be a finite number.`);return t}function zt(t){if(t===`verified`||t===`unverifiable`)return t;throw new e(`INVALID_ARGS`,`target-v1 "verification" must be "verified" or "unverifiable".`)}function Bt(e){let t=gt(p(e.type??``)),n=ht(e.identifier),r=_t(e.label);return{...n===void 0?{}:{id:T(n,256)},role:T(t,256),...r===void 0?{}:{label:T(r,256)}}}function Vt(e,t){return e.id===t.id&&e.role===t.role&&e.label===t.label}function Ht(e,t){let n=0;for(let r of e)Bt(r).id===t&&(n+=1);return n}function Ut(e,t){if(e.id===void 0||Ht(t,e.id)<=1)return e;let{role:n,label:r}=e;return{role:n,...r===void 0?{}:{label:r}}}function Wt(e,t){let n=0;for(let r of e)if(r.parentIndex===t.parentIndex){if(r.index===t.index)return n;n+=1}return 0}function Gt(e,t){return{documentOrder:e.index,sibling:Wt(t,e)}}function Kt(e,t){return e.documentOrder===t.documentOrder&&e.sibling===t.sibling}function qt(e){return{...e.id===void 0?{}:{id:e.id},role:e.role,...e.label===void 0?{}:{label:e.label}}}function Jt(e,t){return t.id===void 0?e.role===t.role&&e.label===t.label:e.id===t.id}function Yt(e,t){if(e.length<t.length)return!1;for(let[n,r]of t.entries()){let t=e[n];if(!t||t.role!==r.role||r.label!==void 0&&t.label!==r.label)return!1}return!0}function Xt(e,t){let n=[];return e.id!==t.id&&n.push(`id: recorded=${e.id??`(none)`} observed=${t.id??`(none)`}`),e.role!==t.role&&n.push(`role: recorded=${e.role} observed=${t.role}`),e.label!==t.label&&n.push(`label: recorded=${e.label??`(none)`} observed=${t.label??`(none)`}`),n}function Zt(e){return e?`${e.role}${e.label?`/${e.label}`:``}`:`(missing)`}function Qt(e,t){return!t||t.role!==e.role||e.label!==void 0&&t.label!==e.label}function $t(e,t){for(let[n,r]of e.entries()){let e=t[n];if(Qt(r,e))return[`ancestry[${n}]: recorded=${Zt(r)} observed=${Zt(e)}`]}return[]}function en(e,t,n={}){let r=[],i=p(e.type??``),a=tn(e,n.nodes),o=O(e.label),s=O(e.value),c=O(m(e)),l=n.action===`fill`;a&&r.push(`id=${D(a)}`),i&&o&&r.push(l?`role=${D(i)} label=${D(o)} editable=true`:`role=${D(i)} label=${D(o)}`),o&&r.push(l?`label=${D(o)} editable=true`:`label=${D(o)}`),s&&r.push(l?`value=${D(s)} editable=true`:`value=${D(s)}`),c&&c!==o&&c!==s&&r.push(l?`text=${D(c)} editable=true`:`text=${D(c)}`),i&&l&&!r.some(e=>e.includes(`editable=true`))&&r.push(`role=${D(i)} editable=true`);let u=st(r);return u.length===0&&i&&u.push(l?`role=${D(i)} editable=true`:`role=${D(i)}`),u.length===0&&g(e)&&u.push(`visible=true`),u}function tn(e,t){let n=O(e.identifier);if(!n||!t)return n;let r=Bt(e).id;return r===void 0?n:Ht(t,r)>1?null:n}function D(e){return JSON.stringify(e)}function O(e){return e&&e.trim()||null}const nn=[`any`,`text`,`label`,`value`,`role`,`id`],rn=[`text`,`label`,`value`,`role`,`id`];function an(e){let t=e?.toLowerCase();return t===`press`||t===`tap`?`click`:t}function on(e){return e===`exists`||e===`wait`||e===`get_text`||e===`get_attrs`||e===`list`}function sn(e,t,n,r={}){let i=A(n);if(!i)return{matches:[],score:0};let a=0,o=[];for(let n of e){if(r.requireRect&&!n.rect)continue;let e=cn(n,t,i);if(!(e<=0)){if(e>a){a=e,o.length=0,o.push(n);continue}e===a&&o.push(n)}}return{matches:o,score:a}}function cn(e,t,n){switch(t){case`role`:return ln(e,n);case`label`:return k(e.label,n);case`value`:return k(e.value,n);case`id`:return k(e.identifier,n);default:return Math.max(k(e.label,n),k(e.value,n),k(e.identifier,n))}}function k(e,t){let n=A(e??``);return n?n===t?2:+!!n.includes(t):0}function ln(e,t){let n=ke(e);return n.some(e=>A(e)===t)?2:+!!n.some(e=>un(e).includes(t))}function un(e){let t=e.lastIndexOf(`.`);return t===-1?e:e.slice(t+1)}function A(e){return e.trim().toLowerCase().replaceAll(/\s+/g,` `)}const dn=`find requires a value`,fn=`find actions: click (default; press/tap are aliases), list, focus, fill, type, exists, wait, get text, get attrs — there is no longpress/swipe find action. Run find "<text>" list to inspect every match with its @ref without acting, then dispatch the gesture on the chosen ref, e.g. longpress @eNN.`;function pn(e,t){if(e.length===0)return{ok:!1,code:`INVALID_ARGS`,message:`find requires a locator or text`};let n=gn([...e]);return n.query?t?.findFirst&&t?.findLast?{ok:!1,code:`INVALID_ARGS`,message:`find accepts only one of --first or --last`}:{ok:!0,parsed:n}:{ok:!1,code:`INVALID_ARGS`,message:dn}}const mn=[`exists`,`list`,`click`,`focus`];function hn(e){return mn.includes(e)}function gn(t){let n=`any`,r=0;rn.includes(t[0])&&(n=t[0],r=1);let i=t[r]??``,a=t.slice(r+1);if(a.length===0)return{locator:n,query:i,action:`click`};let o=an(a[0]);if(hn(o))return{locator:n,query:i,action:o};if(o===`get`)return{locator:n,query:i,action:_n(a[1])};if(o===`wait`){let e=yn(a[1]);return{locator:n,query:i,action:`wait`,timeoutMs:e??void 0}}if(o===`fill`||o===`type`){let e=a.slice(1);return{locator:n,query:i,action:o,value:e.length===0?void 0:e.join(` `)}}throw new e(`INVALID_ARGS`,`Unsupported find action: ${a[0]}`,{hint:fn})}function _n(t){let n=t?.toLowerCase();if(n===`text`)return`get_text`;if(n===`attrs`)return`get_attrs`;throw new e(`INVALID_ARGS`,`find get only supports text or attrs`)}function vn(e,t){return e!==`any`||!t.includes(`=`)&&!t.includes(`||`)?null:y(t)?t:null}function yn(e){if(!e)return null;let t=Number(e);return Number.isFinite(t)?t:null}function bn(e,t,n){return t.terms.every(t=>xn(e,t,n))}function xn(e,t,n){switch(t.key){case`id`:return j(e.identifier,String(t.value));case`role`:return Sn(e,String(t.value));case`label`:return j(e.label,String(t.value));case`value`:return j(e.value,String(t.value));case`text`:return j(m(e),String(t.value));case`appname`:return j(e.appName,String(t.value));case`windowtitle`:return j(e.windowTitle,String(t.value));case`visible`:return g(e)===!!t.value;case`hidden`:return!g(e)==!!t.value;case`editable`:return Oe(e,n)===!!t.value;case`selected`:return e.selected===!0==!!t.value;case`focused`:return e.focused===!0==!!t.value;case`enabled`:return e.enabled!==!1==!!t.value;case`hittable`:return e.hittable===!0==!!t.value;default:return!1}}function j(e,t){return A(e??``)===A(t)}function Sn(e,t){let n=A(t);return ke(e).some(e=>A(e)===n)}function Cn(e,t,n){let r=n.requireRect??!1,i=n.requireUnique??!0,a=[],o=null;for(let[s,c]of t.selectors.entries()){let t=An(e,c,n.platform,r);if(a.push({selector:c.raw,matches:t.count}),!(t.count===0||!t.firstNode)){if(o??={selector:c,selectorIndex:s,matchedNodes:t.candidates},i&&t.count!==1){if(!n.disambiguateAmbiguous||!t.disambiguated||!t.tiebreak)continue;return{matchedNodes:t.candidates,firstMatch:o,resolution:{node:t.disambiguated,selector:c,selectorIndex:s,matches:t.count,diagnostics:a,disambiguation:{matchCount:t.count,tiebreak:t.tiebreak,alternatives:t.candidates.filter(e=>e!==t.disambiguated)}}}}return{matchedNodes:t.candidates,firstMatch:o,resolution:{node:t.firstNode,selector:c,selectorIndex:s,matches:t.count,diagnostics:a}}}}return{resolution:null,matchedNodes:o?.matchedNodes??[],firstMatch:o}}function wn(e,t,n){return Cn(e,t,n).resolution}function Tn(e,t,n){let r=n.requireRect??!1;for(let[i,a]of t.selectors.entries()){let t=e.filter(e=>r&&!e.rect?!1:bn(e,a,n.platform));if(t.length>0)return{selector:a,selectorIndex:i,matchedNodes:t}}return null}function En(e,t,n){let r=n.requireRect??!1,i=[];for(let[a,o]of t.selectors.entries()){let t=Pn(e,o,n.platform,r);if(i.push({selector:o.raw,matches:t}),t>0)return{selectorIndex:a,selector:o,matches:t,diagnostics:i}}return null}const Dn=`Snapshot refs expire when the UI changes. Run snapshot -i and retry with a fresh @ref.`;function On(e){return e.some(e=>e.matches>1)?`Add more terms to disambiguate (e.g. role=button text="Sign in"), use an @ref from snapshot -i, or use find <text> --first/--last.`:`Selector text/label values match exactly (quote multi-word values: text="Sign in"). Run snapshot -i to see current elements and refs, or use find <text> for contains matching.`}function kn(e,t,n){if(t.length===0)return`Selector did not match: ${e}`;let r=t.map(e=>`${e.selector} -> ${e.matches}`).join(`, `);return n.unique??!0?`Selector did not resolve uniquely (${r})`:`Selector did not match (${r})`}function An(e,t,n,r){let i=0,a=null,o=[],s={best:null,bestVisible:!1,tie:!1},c=be(e).isVisibleOnScreen;for(let l of e)r&&!l.rect||bn(l,t,n)&&(i+=1,a??=l,o.push(l),jn(s,l,c));return{count:i,firstNode:a,disambiguated:s.tie?null:s.best,tiebreak:s.tie?null:Mn(o,s.best,c),candidates:o}}function jn(e,t,n){if(!e.best){e.best=t;return}e.bestVisible||=n(e.best);let r=n(t);if(r!==e.bestVisible){r&&(e.best=t,e.bestVisible=!0,e.tie=!1);return}let i=Fn(t,e.best);i.result>0?(e.best=t,e.tie=!1):i.result===0&&(e.tie=!0)}function Mn(e,t,n){if(!t)return null;let r=null;for(let i of e)i!==t&&(!r||Nn(i,r,n).result>0)&&(r=i);return r?Nn(t,r,n).criterion:null}function Nn(e,t,n){let r=n(e);return r===n(t)?Fn(e,t):{result:r?1:-1,criterion:`visible`}}function Pn(e,t,n,r){let i=0;for(let a of e)r&&!a.rect||bn(a,t,n)&&(i+=1);return i}function Fn(e,t){let n=e.depth??0,r=t.depth??0;if(n!==r)return{result:n>r?1:-1,criterion:`deepest`};let i=In(e),a=In(t);return i===a?{result:0,criterion:null}:{result:i<a?1:-1,criterion:`smallest-area`}}function In(e){return e.rect?e.rect.width*e.rect.height:1/0}const Ln={act:{ambiguity:`reject-candidates`,requireRect:!0},actCoveredDiagnosis:{ambiguity:`first-match`,requireRect:!0},readText:{ambiguity:`disambiguate`,requireRect:!1},readUnique:{ambiguity:`fail-closed`,requireRect:!1},readAny:{ambiguity:`first-match`,requireRect:!1},wait:{ambiguity:`first-match`,requireRect:!1},findAct:{ambiguity:`reject-candidates`,requireRect:!0},readList:{ambiguity:`reject-candidates`,requireRect:!1},cropTarget:{ambiguity:`fail-closed`,requireRect:!0}};function Rn(e){return e.ambiguity===`first-match`?{requireRect:e.requireRect,requireUnique:!1}:{requireRect:e.requireRect,requireUnique:!0,disambiguateAmbiguous:e.ambiguity===`disambiguate`}}function zn(e,t){let n=e===`is`?et([...t]).split:x([...t]);return n?y(n.selectorExpression)?{kind:`expression`,expression:n.selectorExpression,rest:n.rest}:{kind:`invalid`}:{kind:`not-applicable`}}function Bn(e){return{platform:e.platform,...Rn({ambiguity:e.allowDisambiguation?`disambiguate`:`fail-closed`,requireRect:e.requireRect})}}function Vn(e,t,n){let r=y(e);if(!r)return{kind:`unresolved`,reason:`parse-invalid`,matchedNodes:[]};let{resolution:i,matchedNodes:a}=Cn(t,r,Bn(n));return i?{kind:`resolved`,winner:i.node,matchedNodes:a,matchCount:a.length,...i.disambiguation?{disambiguation:{tiebreak:i.disambiguation.tiebreak,matchCount:i.disambiguation.matchCount,alternatives:i.disambiguation.alternatives}}:{}}:{kind:`unresolved`,reason:a.length>0?`ambiguous`:`no-match`,matchedNodes:a}}function Hn(e,t,n={}){return en(e,t,n)}function Un(e,t,n){let r=y(e);if(!r)return;let i=wn(t,r,Bn(n));if(i)return{node:i.node,basis:Gn(i.selector)}}function Wn(e){if(!e)return;let t=y(e);if(!t)return;let n=t.selectors.flatMap(e=>e.terms.flatMap(e=>(e.key===`label`||e.key===`text`||e.key===`id`)&&typeof e.value==`string`?[e.value]:[]));if(n.length===0)return;let r=n[0];return r&&n.every(e=>e===r)?r:void 0}function Gn(e){let t=new Set(e.terms.map(e=>e.key));if(t.has(`id`))return`id`;let n=t.has(`role`),r=t.has(`label`)||t.has(`text`);return n&&r?`role-label`:r||t.has(`value`)?`label`:`other`}function Kn(e,t){let n=y(e);if(!n)return e.includes(`=`)||e.includes(`||`)?null:e;let r=new Set(t.textKeys),i=t.textAliases??{};return n.selectors.length>1?qn(n.selectors,r,i):Jn(n.selectors[0],r,new Set(t.booleanKeys),i)}function qn(e,t,n){let r=e.map(e=>{let r=e.terms.length===1?e.terms[0]:void 0;return r&&Yn(r.key,t,n)&&typeof r.value==`string`?r.value:void 0}),i=r[0];return i!==void 0&&r.every(e=>e===i)?i:null}function Jn(e,t,n,r){if(!e)return null;let i={},a=0;for(let o of e.terms){if(Yn(o.key,t,r)&&typeof o.value==`string`)a+=1;else if(!Xn(o,n,`boolean`))return null;i[r[o.key]??o.key]=o.value}return a<=1&&Object.keys(i).length>0?i:null}function Yn(e,t,n){return t.has(e)||n[e]!==void 0}function Xn(e,t,n){return t.has(e.key)&&typeof e.value===n}function Zn(e){let t=y(e);if(!t||t.selectors.length!==1)return null;let n=t.selectors[0];if(!n||n.terms.length!==1)return null;let r=n.terms[0];return!r||typeof r.value!=`string`||r.key!==`id`&&r.key!==`label`&&r.key!==`text`&&r.key!==`value`?null:{key:r.key,value:r.value,raw:n.raw}}function Qn(e,t){if(!t)return!1;let n=y(e);return n?n.selectors.some(e=>e.terms.some(e=>(e.key===`text`||e.key===`label`||e.key===`value`)&&typeof e.value==`string`&&e.value.includes(t))):!1}function $n(e,t){return y(e)?.selectors.some(e=>e.terms.some(e=>e.key===t))??!1}function er(e){return v(e).selectors.map(e=>e.raw)}function tr(e){return y(e)!==null}function nr(e){v(e)}function M(e){if(!e)return null;let t=Number(e);return Number.isFinite(t)?t:null}const rr=new Set([`exists`,`present`,`appears`,`gone`,`disappears`]);function ir(e){let t=e[0];if(t===void 0)return null;let n=M(t);if(n!==null)return{kind:`sleep`,durationMs:n};let r=M(e.at(-1));return t===`text`?ar(e,r):t===`stable`?or(e):t===`absent`?sr(e,r):t.startsWith(`@`)?{kind:`ref`,rawRef:t,timeoutMs:r}:lr(e,r)}function ar(e,t){return{kind:`text`,text:(t===null?e.slice(1).join(` `):e.slice(1,-1).join(` `)).trim(),timeoutMs:t}}function or(e){let t=e.slice(1),n=t.length>1?M(t[1]):null;return{kind:`stable`,quietMs:t.length>0?M(t[0]):null,timeoutMs:n}}function sr(e,t){let n=t===null?e.slice(1):e.slice(1,-1),r=x(n);return n.length>0&&r?.rest.length===0&&tr(r.selectorExpression)?{kind:`absent`,selectorExpression:r.selectorExpression,timeoutMs:t}:{kind:`invalid`,reason:`absent-selector-required`,message:cr(n)}}function cr(e){let t=e.join(` `);return t.length>0?`wait absent requires one valid selector; received "${t}". Use wait absent '<selector>' [timeoutMs].`:`wait absent requires <selector> [timeoutMs].`}function lr(e,t){let n=t===null?e.slice():e.slice(0,-1),r=x(n);return r&&r.rest.length===0&&tr(r.selectorExpression)?{kind:`selector`,selectorExpression:r.selectorExpression,timeoutMs:t}:ur(n,r)||{kind:`text`,text:(t===null?e.join(` `):e.slice(0,-1).join(` `)).trim(),timeoutMs:t}}function ur(e,t){for(let t of e){let n=Ie(t);if(n)return{kind:`invalid`,reason:`unknown-selector-key`,message:dr(n,e)}}return t&&t.rest.length>0?{kind:`invalid`,reason:`selector-shaped-text`,message:fr(t,e)}:e.some(e=>b(e))?{kind:`invalid`,reason:`selector-shaped-text`,message:pr(e)}:null}function dr(e,t){let n=t.join(` `),r=Pe(e.key)?`role=${e.key} label="${e.value}"`:`label="${e.value}"`;return`Unknown selector key "${e.key}" in "${n}". Supported: ${Me.join(`, `)}. Use wait '${r}' [timeoutMs] to wait for the selector, or wait text '${n}' [timeoutMs] to wait for the literal text "${n}".`}function fr(e,t){let n=t.join(` `);return`Selector ${e.selectorExpression} is followed by unexpected extra arguments: "${e.rest.join(` `)}". Selector values with spaces need quotes, e.g. label="Sign in". Use wait '<selector>' [timeoutMs], or wait text '${n}' [timeoutMs] to wait for the literal text "${n}".`}function pr(e){let t=e.join(` `),n=e.filter(e=>!b(e)),r=e.filter(e=>b(e));if(n.length>0){let e=n[0],i=rr.has(e.toLowerCase())?` "${e}" describes a condition, not a selector key. Use the selector form: `+(e.toLowerCase()===`gone`||e.toLowerCase()===`disappears`?`wait absent '${r.join(` `)}' [timeoutMs] to wait for zero matches.`:`wait '${r.join(` `)}' [timeoutMs] to wait for it to appear.`):` "${e}" is not a recognized selector key (${Me.join(`, `)}).`;return`"${t}" mixes plain word "${e}" with selector-shaped "${r.join(` `)}", so it is neither a valid selector nor safe as literal text.${i} Use wait '<selector>' [timeoutMs] for a selector, or wait text '${t}' [timeoutMs] to wait for the literal text "${t}".`}return`"${t}" looks like a selector key but is not a valid selector expression. Use wait '<selector>' [timeoutMs], e.g. wait '${e[0]}="value"' [timeoutMs], or wait text '${t}' [timeoutMs] to wait for the literal text "${t}".`}function mr(e){let t=ir(e);return t?t.kind===`sleep`?t.durationMs:t.kind===`invalid`?null:t.timeoutMs:null}const hr=3e4,gr=24e4,_r=3e5,N={budget:{source:`none`},envelopeMs:9e4,onTimeout:`reset-daemon`},vr={budget:{source:`none`},envelopeMs:255e3,onTimeout:`reset-daemon`};function yr(e,t){if(e.envelopeMs===`unbounded`)return;let n={...e,envelopeMs:e.envelopeMs};return(xr(n,t.positionals??[])??Sr(n,t.flags)??n.envelopeMs)+br(e,t.flags)}function br(e,t){if(e.targetReadiness!==`budgeted`)return 0;let n=t?.readinessTimeoutMs;return typeof n!=`number`||!Number.isInteger(n)||n<=0?0:Math.min(n,2e3)}function xr(e,t){if(e.budget.source!==`positional-parser`)return;let n=e.budget.parser(t);return n===null?void 0:Tr(e,n)}function Sr(e,t){if(e.budget.source===`flag`)return e.budget.envelope===`widen`?wr(e,e.budget,t):e.budget.envelope===`margin`?Cr(e,t):typeof t?.timeoutMs==`number`?t.timeoutMs:e.envelopeMs}function Cr(e,t){let n=typeof t?.timeoutMs==`number`?Tr(e,t.timeoutMs):e.envelopeMs;return typeof t?.waitMs==`number`?Er({...e,envelopeMs:n},t.waitMs):n}function wr(e,t,n){if(n?.settle!==!0)return e.envelopeMs;let r=typeof n.timeoutMs==`number`?n.timeoutMs:t.defaultBudgetMs;return typeof r==`number`?Er(e,r):e.envelopeMs}function Tr(e,t){return Math.max(e.envelopeMs,t+hr)}function Er(e,t){return Math.max(e.envelopeMs,e.envelopeMs+t+hr)}const Dr={click:`settle-and-verify`,press:`settle-and-verify`,fill:`settle-and-verify`,longpress:`settle`,hover:`settle`,scroll:`settle`,back:`settle`};function Or(e){if(e!==void 0)return Dr[e]}function P(t){return new e(`COMMAND_FAILED`,t,{reason:`runtime-contract-invalid`,hint:`This is an agent-device runtime contract bug; report the selected device and command.`})}function kr(e){if(!r(e))throw TypeError(`Unknown local runtime family: ${String(e)}`);return Object.freeze({kind:`local-family`,family:e})}function Ar(e,t){let n=e.trim(),r=t.trim();if(n.length===0||r.length===0)throw TypeError(`Provider runtime owner requires non-empty provider and instance identities`);return Object.freeze({kind:`provider-runtime`,provider:n,instance:r})}function jr(e){let t=e.trim();if(t.length===0)throw TypeError(`Managed local runtime owner requires a non-empty allocator instance identity`);return Object.freeze({kind:`managed-local`,instance:t})}function Mr(e){switch(e.kind){case`local-family`:return`local:${e.family}`;case`managed-local`:return`managed:${JSON.stringify([e.instance])}`;case`provider-runtime`:return`provider:${JSON.stringify([e.provider,e.instance])}`}}function Nr(e,t){return Mr(e)===Mr(t)}function Pr(e,t){return e.available?t():{}}function Fr(e){if(!F(e.requesterId)||!F(e.identityIncarnationId)||!Lr(e.requestGeneration))throw TypeError(`Managed binding fence requires non-empty requester and identity incarnation ids and a non-negative integer request generation`);return Object.freeze({token:JSON.stringify([e.requesterId,e.identityIncarnationId]),generation:e.requestGeneration})}function Ir(e){let t=Rr(e.token);if(!t||t.length!==2)return null;let[n,r]=t;if(!F(n)||!F(r)||!Lr(e.generation))return null;let i=Object.freeze({requesterId:n,requestGeneration:e.generation,identityIncarnationId:r});return Fr(i).token===e.token?i:null}function Lr(e){return Number.isInteger(e)&&e>=0}function F(e){return typeof e==`string`&&e.trim().length>0}function Rr(e){try{let t=JSON.parse(e);return Array.isArray(t)?t:null}catch{return null}}function zr(e,t){let n={},r={};for(let i of t.required){let t=Br(e.facts.operations,i);if(n[i]=t,!t.available)throw Gr(i,t);r[i]=Ur(e.operations,i)}for(let i of t.preferred){let t=Br(e.facts.operations,i);n[i]=t,t.available&&(r[i]=Ur(e.operations,i))}for(let i of t.conditional??[]){let t=Br(e.facts.operations,i);n[i]=t,t.available&&(r[i]=Ur(e.operations,i))}return Object.freeze({device:e.device,owner:e.owner,facts:Object.freeze(n),operations:Object.freeze(r)})}function Br(e,t){let n=e[t];if(!Vr(n))throw P(`Runtime owner omitted the ${t} fact`);let r=Hr(n);if(r)return r;throw P(`Runtime owner returned an invalid ${t} fact`)}function Vr(e){return typeof e==`object`&&!!e&&`available`in e}function Hr(e){if(e.available===!0)return Object.freeze({available:!0});if(e.available===!1&&Wr(e.reason)&&(e.hint===void 0||typeof e.hint==`string`))return Object.freeze({available:!1,reason:e.reason,...e.hint===void 0?{}:{hint:e.hint}})}function Ur(e,t){let n=e[t];if(typeof n!=`function`)throw P(`Runtime owner advertised ${t} without an implementation`);return n}function Wr(e){return e===`unsupported-platform-leaf`||e===`unsupported-device-kind`||e===`unsupported-device-backend`||e===`unsupported-device-scope`||e===`unsupported-provider-mode`||e===`owner-capability-missing`}function Gr(t,n){return new e(`UNSUPPORTED_OPERATION`,`Runtime operation ${t} is unavailable`,{reason:n.reason,hint:n.hint})}function Kr(e){return JSON.stringify({required:[...e.required].sort(),preferred:[...e.preferred].sort(),conditional:[...e.conditional??[]].sort()})}function qr(){return e=>{let t=Jr(e.required,`required`),n=Jr(e.preferred??[],`preferred`),r=Jr(e.conditional??[],`conditional`),i=[[`required`,t],[`preferred`,n],[`conditional`,r]];for(let e=0;e<i.length;e+=1){let t=i[e];if(t)for(let n of i.slice(e+1)){let e=n[1].find(e=>t[1].includes(e));if(e!==void 0)throw TypeError(`Runtime operation cannot be both ${t[0]} and ${n[0]}: ${e}`)}}return Object.freeze(r.length===0?{required:t,preferred:n}:{required:t,preferred:n,conditional:r})}}function Jr(e,t){let n=[...e];if(new Set(n).size!==n.length)throw TypeError(`Runtime use contains duplicate ${t} operations`);return Object.freeze(n)}const I=qr(),Yr=I({required:[`bootTarget`]}),Xr=I({required:[`bootTargetHeadless`]}),Zr=I({required:[`ensureReady`,`listApps`]}),Qr=I({required:[`captureSnapshot`]}),$r=I({required:[`setViewport`]}),ei=I({required:[`focusPoint`]}),ti=I({required:[`typeText`]}),ni=I({required:[`back`]}),ri=I({required:[`home`]}),ii=I({required:[`setOrientation`]}),ai=I({required:[`setFoldPose`]}),oi=I({required:[`tvRemote`]}),si=I({required:[`keyboardStatus`]}),ci=I({required:[`keyboardDismiss`]}),li=I({required:[`keyboardEnter`]}),ui=I({required:[`appSwitcher`]}),di=I({required:[`actionButton`]}),fi=I({required:[`triggerAppEvent`]}),pi=I({required:[`setSetting`]}),mi=I({required:[`readSetting`]}),hi=I({required:[`readAlert`]}),gi=I({required:[`awaitAlert`]}),_i=I({required:[`acceptAlert`]}),vi=I({required:[`dismissAlert`]}),yi=I({required:[`readClipboard`]}),bi=I({required:[`writeClipboard`]}),xi=I({required:[`perfFrames`]}),Si=I({required:[`perfMemorySample`]}),Ci=I({required:[`perfMemorySnapshot`]}),wi=I({required:[`perfNativeCaptureStart`]}),Ti=I({required:[`perfNativeCaptureReattach`,`perfNativeCaptureCleanup`]}),Ei=I({required:[`perfProfileReport`]}),Di=Object.freeze([xi,Si,Ci,wi,Ti,Ei]),L=I({required:[`tapPoint`]}),Oi=I({required:[`captureSnapshot`,`tapPoint`],preferred:[`tapRef`],conditional:[`tapElementSelector`]}),ki=I({required:[`longPressPoint`]}),Ai=I({required:[`captureSnapshot`,`longPressPoint`]}),ji=I({required:[`hoverPoint`]}),Mi=I({required:[`captureSnapshot`,`hoverPoint`],preferred:[`hoverRef`]}),Ni=I({required:[`fillPoint`]}),Pi=I({required:[`captureSnapshot`,`fillPoint`],preferred:[`fillRef`]}),Fi=Object.freeze([L,Oi]),Ii=Fi,Li=Object.freeze([ki,Ai]),Ri=Object.freeze([ji,Mi]),zi=Object.freeze([Ni,Pi]);function Bi(e,t){switch(e){case`click`:case`press`:return t?{kind:`captured-tap`,use:Oi}:{kind:`tap-point`,use:L};case`fill`:return t?{kind:`captured-fill`,use:Pi}:{kind:`fill-point`,use:Ni};case`longpress`:return t?{kind:`captured-long-press`,use:Ai}:{kind:`long-press-point`,use:ki};case`hover`:return t?{kind:`captured-hover`,use:Mi}:{kind:`hover-point`,use:ji}}}const Vi=I({required:[`performGesturePlan`,`captureSnapshot`],preferred:[`gestureViewport`]}),Hi=I({required:[`performDirectionalFlingPlan`,`captureSnapshot`],preferred:[`gestureViewport`]}),Ui=I({required:[`performMultiTouchGesturePlan`,`captureSnapshot`],preferred:[`gestureViewport`]}),Wi=I({required:[`performTargetAuthoredDrag`,`captureSnapshot`],preferred:[`gestureViewport`]}),Gi=I({required:[`gestureViewport`]}),Ki=I({required:[`scrollDirection`],conditional:[`captureSnapshot`]}),qi=I({required:[`scrollDirection`,`captureSnapshot`]}),Ji=Object.freeze({plan:Vi,"directional-fling":Hi,"multi-touch":Ui,"target-authored-drag":Wi}),Yi=Object.freeze([Vi,Hi,Ui,Wi]),Xi=Object.freeze([Vi]),Zi=Object.freeze([Ki,qi]);function Qi(e){return e.intent===`pan`?(`pointerCount`in e?e.pointerCount:1)===2:e.intent===`pinch`||e.intent===`rotate`||e.intent===`transform`}function $i(e){return e.intent===`drag`?`target-authored-drag`:Qi(e)?`multi-touch`:e.intent===`fling`&&`direction`in e?`directional-fling`:`plan`}function ea(e){let t=$i(e);switch(t){case`plan`:return R(t);case`directional-fling`:return R(t);case`multi-touch`:return R(t);case`target-authored-drag`:return R(t)}}function R(e){let t=Ji[e];return Object.freeze({tier:e,operation:t.required[0],use:t})}function ta(e){return e.until===void 0?e.edge===void 0?Object.freeze({kind:`direction`,use:Ki}):Object.freeze({kind:`edge`,edge:e.edge,use:qi}):Object.freeze({kind:`until`,until:e.until,use:qi})}const na=I({required:[`captureSnapshot`,`captureSnapshotWithCustomActions`]}),ra=I({required:[`captureSnapshot`,`captureSnapshotWithoutActiveApp`]}),ia=I({required:[`captureSnapshot`,`captureSnapshotWithCustomActions`,`captureSnapshotWithoutActiveApp`]}),aa=I({required:[`captureSnapshot`]}),oa=I({required:[`captureSnapshot`,`captureSnapshotWithoutActiveApp`]}),sa=I({required:[`captureSnapshot`],preferred:[`readTextAtPoint`]}),ca=I({required:[`captureSnapshot`,`captureSnapshotWithoutActiveApp`],preferred:[`readTextAtPoint`]}),la=I({required:[`captureSnapshot`],conditional:[`findText`]}),ua=I({required:[`captureSnapshot`,`captureSnapshotWithoutActiveApp`],conditional:[`findText`]}),da=Object.freeze([aa,oa]),fa=Object.freeze([sa,ca]),pa=I({required:[`captureSnapshot`,`focusPoint`]}),ma=I({required:[`captureSnapshot`,`captureSnapshotWithoutActiveApp`,`focusPoint`]}),ha=I({required:[`captureSnapshot`,`focusPoint`,`typeText`]}),ga=I({required:[`captureSnapshot`,`captureSnapshotWithoutActiveApp`,`focusPoint`,`typeText`]}),_a=Object.freeze([sa,ca,aa,oa,pa,ma,ha,ga]),va=Object.freeze([la,ua]),ya=Object.freeze([Qr,na,ra,ia]),z=Object.freeze({"capture-only":da,"element-text":fa,"wait-observation":va,"find-focus":Object.freeze([pa,ma]),"find-type":Object.freeze([ha,ga])});function ba(e){return e===`focus`?`find-focus`:e===`type`?`find-type`:`capture-only`}function xa(e){switch(e.intent){case`capture-only`:return B(e.hasActiveApp,e.intent,z[e.intent]);case`element-text`:return B(e.hasActiveApp,e.intent,z[e.intent]);case`wait-observation`:return B(e.hasActiveApp,e.intent,z[e.intent]);case`find-focus`:return B(e.hasActiveApp,e.intent,z[e.intent]);case`find-type`:return B(e.hasActiveApp,e.intent,z[e.intent])}}function B(e,t,n){return Object.freeze(e?{kind:`selector-active-app`,intent:t,operation:`captureSnapshot`,use:n[0]}:{kind:`selector-without-active-app`,intent:t,operation:`captureSnapshotWithoutActiveApp`,use:n[1]})}function Sa(e){return e.customActions?e.hasActiveApp?Object.freeze({kind:`custom-actions-active-app`,operation:`captureSnapshotWithCustomActions`,use:na}):Object.freeze({kind:`custom-actions-without-active-app`,operation:`captureSnapshotWithCustomActions`,use:ia}):e.hasActiveApp?Object.freeze({kind:`active-app`,operation:`captureSnapshot`,use:Qr}):Object.freeze({kind:`without-active-app`,operation:`captureSnapshotWithoutActiveApp`,use:ra})}const Ca=I({required:[`captureScreenshot`]}),wa=I({required:[`captureScreenshot`,`captureSnapshot`]}),Ta=Object.freeze([Ca,wa]);function Ea(e){return e.cropOn?Object.freeze({kind:`capture-with-crop-on`,use:wa}):e.overlayRefs?Object.freeze({kind:`capture-with-overlay-refs`,use:wa}):Object.freeze({kind:`capture`,use:Ca})}const Da=Object.freeze([Yr,Xr]),Oa=Object.freeze({kind:`boot-target`,operation:`bootTarget`,use:Yr}),ka=Object.freeze({kind:`boot-target-headless`,operation:`bootTargetHeadless`,use:Xr});function Aa(e){return e.headless?ka:Oa}const ja=I({required:[`ensureReady`,`appState`]}),Ma=Object.freeze([ja]),Na=I({required:[`shutdownTarget`]}),Pa=Object.freeze([yi,bi]),Fa=Object.freeze([pi,mi]),Ia=[`text-size`],La=Object.freeze({kind:`write`,use:pi});function Ra(e){let t=za(e?.[0]);return e?.length!==1||t===void 0?La:Ia.includes(t)?Object.freeze({kind:`read`,setting:t,use:mi}):La}function za(e){let t=e?.trim().toLowerCase();return Ia.find(e=>e===t)}const Ba=Object.freeze([hi,gi,_i,vi]),Va=Object.freeze([si,ci,li]),Ha=I({required:[`deployApp`]}),Ua=I({required:[`ensureReady`,`materializeAppSource`,`deployMaterializedApp`]}),Wa=I({required:[`ensureReady`,`sendPushNotification`]}),Ga=I({required:[`resolveOpenTarget`,`prepareApplicationOpen`,`openApplication`]}),Ka=I({required:[`resolveOpenTarget`,`prepareApplicationOpen`,`openApplication`,`applyRuntimeHints`]}),qa=I({required:[`resolveOpenTarget`,`prepareApplicationOpen`,`openApplication`,`clearRuntimeHints`]}),Ja=I({required:[`resolveOpenTarget`,`prepareApplicationOpen`,`openApplication`,`applyRuntimeHints`,`clearRuntimeHints`]});function Ya(e){return e.applyRuntimeHints&&e.clearRemovedRuntimeHints?Object.freeze({kind:`open-apply-and-clear-runtime-hints`,use:Ja}):e.applyRuntimeHints?Object.freeze({kind:`open-apply-runtime-hints`,use:Ka}):e.clearRemovedRuntimeHints?Object.freeze({kind:`open-clear-runtime-hints`,use:qa}):Object.freeze({kind:`open`,use:Ga})}const Xa=Object.freeze([Ga,Ka,qa,Ja]),Za=I({required:[`closeApplication`,`finalizeApplicationClose`]}),Qa=I({required:[`closeApplication`,`finalizeApplicationClose`,`clearRuntimeHints`]}),$a=Object.freeze([Za,Qa]),eo=I({required:[`finalizeApplicationClose`]}),to=I({required:[`finalizeApplicationClose`,`clearRuntimeHints`]}),no=I({required:[`prepareAppleRunner`]}),ro=I({required:[`clearRuntimeHints`]}),io=I({required:[`configureProviderPortReverse`]}),ao=Object.freeze([ro,io]),V=I({required:[`appLogInspect`]}),oo=I({required:[`appLogInspect`,`appLogDoctor`]}),so=I({required:[`appLogInspect`,`appLogStart`]}),co=I({required:[],preferred:[`appLogInspect`]}),lo=Object.freeze([V,oo,so]);function uo(t){let n=(t.action??`path`).toLowerCase();if(t.restart&&n!==`clear`)throw new e(`INVALID_ARGS`,`logs --restart is only supported with logs clear`);switch(n){case`path`:return Object.freeze({kind:`path`,requiresAppSession:!1,use:V});case`start`:return Object.freeze({kind:`start`,requiresAppSession:!0,use:so});case`stop`:return Object.freeze({kind:`stop`,requiresAppSession:!1,use:V});case`doctor`:return Object.freeze({kind:`doctor`,requiresAppSession:!1,use:oo});case`mark`:return Object.freeze({kind:`mark`,marker:t.marker??``,requiresAppSession:!1,use:V});case`clear`:return t.restart?Object.freeze({kind:`clear-restart`,requiresAppSession:!0,use:so}):Object.freeze({kind:`clear`,requiresAppSession:!1,use:V});default:throw new e(`INVALID_ARGS`,`logs requires path, start, stop, doctor, mark, or clear`)}}const fo=I({required:[`audioProbeStart`]}),po=I({required:[`audioProbeReattach`,`audioProbeCleanup`]}),mo=I({required:[`audioProbeQuery`]}),ho=Object.freeze([fo,po,mo]);function go(e){if(e.mode===`query`)return Object.freeze({kind:`query`,action:e.probeAction,use:mo});switch(e.probeAction){case`start`:return Object.freeze({kind:`capture-start`,use:fo});case`status`:return Object.freeze({kind:`capture-status`});case`stop`:return Object.freeze({kind:`capture-stop`})}}const _o=[`probe`],vo=[`start`,`status`,`stop`];function yo(t){let n=(t?.[0]??`probe`).toLowerCase();if(!_o.includes(n))throw new e(`INVALID_ARGS`,`audio requires probe`);let r=(t?.[1]??`status`).toLowerCase();if(!vo.includes(r))throw new e(`INVALID_ARGS`,`audio probe requires ${vo.join(`, `)}`);if(r!==`start`&&t&&t.length>2)throw new e(`INVALID_ARGS`,`audio probe duration and bucket are only supported with audio probe start`);return Object.freeze({probeAction:r,durationMs:bo(t?.[2],{defaultValue:1e4,min:100,max:12e4,message:`audio probe duration must be an integer in range 100..120000 ms`}),bucketMs:bo(t?.[3],{defaultValue:1e3,min:100,max:1e4,message:`audio probe bucket must be an integer in range 100..10000 ms`})})}function bo(t,n){if(t===void 0)return n.defaultValue;let r=Number.parseInt(t,10);if(!Number.isInteger(r)||String(r)!==t||r<n.min||r>n.max)throw new e(`INVALID_ARGS`,n.message);return r}const xo=I({required:[`networkDump`]}),So=I({required:[],preferred:[`networkDump`]}),Co=[`dump`,`log`],wo=[`summary`,`headers`,`body`,`all`];function To(t){let n=(t.action??`dump`).toLowerCase(),r=(t.include??`summary`).toLowerCase();if(!Eo(n))throw new e(`INVALID_ARGS`,`network requires dump or log`);if(!Do(r))throw new e(`INVALID_ARGS`,`network --include must be summary, headers, body, or all`);return Object.freeze({action:n,include:r,use:xo})}function Eo(e){return Co.some(t=>t===e)}function Do(e){return wo.some(t=>t===e)}function Oo(e){let t=new Map;for(let n of e){if(!r(n.family))throw TypeError(`Unknown platform family registration: ${String(n.family)}`);if(t.has(n.family))throw TypeError(`Duplicate platform family registration: ${n.family}`);t.set(n.family,ko(n))}let n=i.filter(e=>!t.has(e));if(n.length>0)throw TypeError(`Missing platform family registrations: ${n.join(`, `)}`);let a=Object.freeze([...i]),o=Object.freeze(a.map(e=>Ao(t,e)));return Object.freeze({families:a,modules:o,get:e=>Ao(t,e)})}function ko(e){return Object.freeze({...e})}function Ao(e,t){let n=e.get(t);if(!n)throw TypeError(`Missing platform family registration: ${t}`);return n}const jo=Object.freeze({kind:`device-inventory`});function Mo(e){if(typeof e!=`object`||!e)throw zo();let t=e,n=Object.keys(t).sort();if(!(t.kind===`none`&&H(n,[`kind`]))&&!(t.kind===`host`&&H(n,[`kind`]))&&!(t.kind===`inventory`&&H(n,[`kind`,`use`])&&Po(t.use))&&!(t.kind===`device-runtime`&&H(n,[`kind`,`use`])&&Fo(t.use))&&!(t.kind===`device-runtime`&&(H(n,[`kind`,`uses`])||H(n,[`kind`,`selectUses`,`uses`])&&typeof t.selectUses==`function`)&&No(t.uses)))throw zo()}function No(e){if(!Array.isArray(e)||e.length===0||!e.every(Fo))return!1;let t=e.map(Kr);return new Set(t).size===t.length}function Po(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.kind===`device-inventory`&&H(Object.keys(t).sort(),[`kind`])}function Fo(e){if(typeof e!=`object`||!e)return!1;let t=e,n=[Lo(t.required),Lo(t.preferred),Lo(t.conditional??[])];if(!Io(n))return!1;let r=n.flat();return new Set(r).size===r.length&&H(Object.keys(t).sort(),t.conditional===void 0?[`preferred`,`required`]:[`conditional`,`preferred`,`required`])}function Io(e){return e.every(e=>e!==null&&Ro(e))}function Lo(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)?e:null}function Ro(e){return new Set(e).size===e.length}function H(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function zo(){return TypeError(`Command platform execution must declare exactly one of none, host, inventory, or device-runtime`)}const Bo=I({required:[`screenRecordingStart`]}),Vo=I({required:[`screenRecordingReattach`,`screenRecordingCleanup`]}),Ho=I({required:[]}),Uo=I({required:[],preferred:[`screenRecordingStart`]}),Wo=Object.freeze([Bo,Vo]);function Go(t){switch((t.action??``).toLowerCase()){case`start`:if(!Ko(t.scope??`app`))throw new e(`INVALID_ARGS`,`record scope must be app, device, or system`);return Object.freeze({kind:`start`,use:Bo});case`stop`:return t.hasLiveHandle===!0?Object.freeze({kind:`stop-live`,use:Ho}):Object.freeze({kind:`stop-recovery`,use:Vo});default:throw new e(`INVALID_ARGS`,`record requires start or stop`)}}function Ko(e){return e===`app`||e===`device`||e===`system`}function qo(e){if(Mo(e),e.kind!==`device-runtime`||!(`uses`in e))throw Jo();let t=e.uses.map(Kr),n=Wo.map(Kr),r=new Set(t),i=new Set(n);if(t.length!==n.length||r.size!==t.length||[...r].some(e=>!i.has(e)))throw Jo()}function Jo(){return TypeError(`Record runtime execution must declare exactly the uses selected by its two runtime-bearing plans`)}function Yo(e){let t=e.platformExecution;if(t===void 0)throw TypeError(`Command descriptor "${e.name}" must declare platformExecution (none, host, inventory, or device-runtime); there is no registry-entry default`);return Mo(t),t}const U={leaseAdmissionExempt:!0,sessionExecutionLockExempt:!0},W={leaseAdmissionExempt:!0,sessionExecutionLockExempt:!0,selectorValidationExempt:!0},Xo=()=>!0,Zo=e=>(e.positionals?.[0]??``).toLowerCase()===`start`,Qo=e=>e.command===`test`&&(typeof e.flags?.shardAll==`number`||typeof e.flags?.shardSplit==`number`),$o=e=>(e.positionals?.length??0)===0?{kind:`unconditional`}:void 0,es=e=>{let t=e.flags?.leaseProvider;return e.flags?.leaseId===void 0&&typeof t==`string`&&(e.flags?.platform===`android`||e.flags?.platform===`ios`)?{kind:`provider-app-catalog`,provider:t}:void 0},ts=new Set([`status`,`get`]),ns=e=>fs(e,ts,`status`),rs=new Set([`get`,`wait`]),is=e=>fs(e,rs,`get`),as=e=>G(e,ts,`status`),os=e=>G(e,rs,`get`),ss=e=>{try{return on(gn(e.positionals??[]).action)?`observes-app`:`mutates-app`}catch{return`mutates-app`}},cs=e=>G(e,new Set([`read`]),``),ls=e=>Ra(e.positionals).kind===`read`,us=e=>ls(e)?`observes-app`:`mutates-app`,ds=e=>ls(e)?`preserve`:`may-invalidate`;function fs(e,t,n){return t.has((e.positionals?.[0]??n).toLowerCase())?`preserve`:`may-invalidate`}function G(e,t,n){return t.has((e.positionals?.[0]??n).toLowerCase())?`observes-app`:`mutates-app`}const K={kind:`none`},ps={kind:`host`},q={recordsSessionAction:!0,recordingEffect:`mutates-app`,deviceClaimPolicy:`require-owner`,daemon:{route:`generic`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},timeoutPolicy:N,batchable:!0},J={targetIdentityVerification:`pre-dispatch`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,deviceClaimPolicy:`require-owner`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0}},Y={...N,onTimeout:`preserve-daemon`},ms={...N,envelopeMs:18e4},hs={...N,onTimeout:`preserve-daemon`},gs={...hs,envelopeMs:33e4},_s={...N,budget:{source:`flag`,envelope:`widen`,defaultBudgetMs:1e4},onTimeout:`preserve-daemon`},vs={fields:{count:{defaultValue:1,omitDefault:!0},intervalMs:{defaultValue:0,omitDefault:!0},holdMs:{defaultValue:0,omitDefault:!0},jitterPx:{defaultValue:0,omitDefault:!0},doubleTap:{defaultValue:!1,omitDefault:!0}}},ys={fields:{delayMs:{defaultValue:0}}};function X(e,t){return Or(e)===void 0?t:_s}function Z(e){let t=Or(e);if(t===void 0)throw Error(`Missing post-action observation descriptor support for ${e}`);return t}const bs={deviceClaimPolicy:`transient-exclusive`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`},platformExecution:{kind:`device-runtime`,use:Ha},timeoutPolicy:ms,batchable:!0},xs=e=>{let t=e.flags?.snapshotCustomActions===!0||e.input?.customActions===!0;return[!0,!1].map(e=>Sa({customActions:t,hasActiveApp:e}).use)},Ss=e=>{let t=ws(e);if(t===void 0||!Cs(t))return _a;let n=ba(t);return[!0,!1].map(e=>xa({hasActiveApp:e,intent:n}).use)};function Cs(e){return on(e)||e===`focus`||e===`type`}function ws(e){if(e.positionals===void 0)return;let t=pn(e.positionals,e.flags);return t.ok?t.parsed.action:void 0}const Ts=[{name:`human_control`,deviceClaimPolicy:`none`,catalog:{group:`internal`,key:`humanControl`},recordsSessionAction:!1,daemon:{route:`humanControl`,refFrameEffect:`preserve`,selectorValidationExempt:!0,skipSessionlessProviderDevice:Xo},timeoutPolicy:N,batchable:!1,platformExecution:K},{name:`lease_allocate`,deviceClaimPolicy:`none`,catalog:{group:`internal`,key:`leaseAllocate`},recordsSessionAction:!1,daemon:{route:`lease`,refFrameEffect:`preserve`,...U},timeoutPolicy:gs,batchable:!1,platformExecution:K},{name:`lease_heartbeat`,deviceClaimPolicy:`none`,catalog:{group:`internal`,key:`leaseHeartbeat`},recordsSessionAction:!1,daemon:{route:`lease`,refFrameEffect:`preserve`,...U,appLease:`allowed`},timeoutPolicy:hs,batchable:!1,platformExecution:K},{name:`lease_release`,deviceClaimPolicy:`none`,catalog:{group:`internal`,key:`leaseRelease`},recordsSessionAction:!1,daemon:{route:`lease`,refFrameEffect:`preserve`,...U,appLease:`allowed`},timeoutPolicy:hs,batchable:!1,platformExecution:K},{name:`artifacts`,deviceClaimPolicy:`none`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`lease`,refFrameEffect:`preserve`,...U},timeoutPolicy:N,batchable:!1,platformExecution:K},{name:`session_list`,deviceClaimPolicy:`none`,catalog:{group:`internal`,key:`sessionList`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,...W},timeoutPolicy:N,batchable:!1,platformExecution:K},{name:`session_save_script`,deviceClaimPolicy:`none`,catalog:{group:`internal`,key:`sessionSaveScript`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`publication`},timeoutPolicy:N,batchable:!1,platformExecution:K},{name:`devices`,deviceClaimPolicy:`observe`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,lockPolicySelectorOverride:!0,...W},timeoutPolicy:N,batchable:!0,platformExecution:{kind:`inventory`,use:jo}},{name:`capabilities`,deviceClaimPolicy:`observe`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,lockPolicySelectorOverride:!0,preferExplicitDeviceOverExistingSession:!0,...W},timeoutPolicy:N,batchable:!0,platformExecution:K},{name:`doctor`,deviceClaimPolicy:`observe`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,lockPolicySelectorOverride:!0,allowSessionlessDefaultDevice:Xo,...W},timeoutPolicy:N,batchable:!0,platformExecution:ps},{name:`apps`,deviceClaimPolicy:`observe`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,lockPolicySelectorOverride:!0,preferExplicitDeviceOverExistingSession:!0,sessionlessLeaseAdmissionExemption:es},platformExecution:{kind:`device-runtime`,uses:[Zr]},timeoutPolicy:N,batchable:!0},{name:`boot`,deviceClaimPolicy:`transient-exclusive`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`may-invalidate`,sessionKind:`state`},platformExecution:{kind:`device-runtime`,uses:Da},timeoutPolicy:{...N,budget:{source:`flag`,envelope:`margin`}},batchable:!0},{name:`shutdown`,deviceClaimPolicy:`transient-exclusive`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`may-invalidate`,sessionKind:`state`},platformExecution:{kind:`device-runtime`,use:Na},timeoutPolicy:N,batchable:!0},{name:`appstate`,deviceClaimPolicy:`observe`,catalog:{group:`public`,key:`appState`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`state`},platformExecution:{kind:`device-runtime`,uses:Ma},timeoutPolicy:N,batchable:!0},{name:`perf`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`},timeoutPolicy:N,batchable:!0,platformExecution:{kind:`device-runtime`,uses:Di}},{name:`logs`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`},platformExecution:{kind:`device-runtime`,uses:lo},timeoutPolicy:N,batchable:!0},{name:`events`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`,allowInvalidRecording:!0,...W},timeoutPolicy:N,batchable:!1,platformExecution:K},{name:`network`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`},platformExecution:{kind:`device-runtime`,use:xo},timeoutPolicy:N,batchable:!0},{name:`audio`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`},timeoutPolicy:N,batchable:!0,platformExecution:{kind:`device-runtime`,uses:ho}},{name:`replay`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`delegated`,sessionKind:`replay`,skipSessionlessProviderDevice:Qo,saveScriptFlagOwner:!0},timeoutPolicy:{...N,budget:{source:`flag`}},batchable:!1,platformExecution:K},{name:`test`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`delegated`,sessionKind:`replay`,skipSessionlessProviderDevice:Qo},timeoutPolicy:{...N,envelopeMs:`unbounded`},batchable:!0,platformExecution:K},{name:`runtime`,deviceClaimPolicy:`require-owner`,catalog:{group:`internal`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`},timeoutPolicy:N,batchable:!1,platformExecution:{kind:`device-runtime`,uses:[...ao,Gi]}},{name:`clipboard`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:cs,daemon:{route:`session`,refFrameEffect:`preserve`},timeoutPolicy:N,batchable:!0,platformExecution:{kind:`device-runtime`,uses:Pa}},{name:`keyboard`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:as,daemon:{route:`session`,refFrameEffect:ns,androidBlockingDialogGuard:!0},timeoutPolicy:N,batchable:!0,platformExecution:{kind:`device-runtime`,uses:Va}},{name:`install`,...bs},{name:`reinstall`,...bs},{name:`install_source`,deviceClaimPolicy:`transient-exclusive`,catalog:{group:`internal`,key:`installSource`,servesPublicCommand:`install-from-source`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`},platformExecution:{kind:`device-runtime`,use:Ua},timeoutPolicy:ms,batchable:!1},{name:`release_materialized_paths`,deviceClaimPolicy:`none`,catalog:{group:`internal`,key:`releaseMaterializedPaths`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,...W},timeoutPolicy:N,batchable:!1,platformExecution:K},{name:`push`,deviceClaimPolicy:`transient-exclusive`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`},platformExecution:{kind:`device-runtime`,use:Wa},timeoutPolicy:N,batchable:!0},{name:`trigger-app-event`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`,key:`triggerAppEvent`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`},timeoutPolicy:N,batchable:!0,platformExecution:{kind:`device-runtime`,uses:[fi]}},{name:`open`,deviceClaimPolicy:`acquire-session`,catalog:{group:`public`},frameworkTier:`core`,recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`,allowSessionlessDefaultDevice:Xo,saveScriptFlagOwner:!0,appLease:`allowed`},timeoutPolicy:{...N,budget:{source:`flag`,envelope:`margin`}},batchable:!0,platformExecution:{kind:`device-runtime`,uses:Xa}},{name:`prepare`,deviceClaimPolicy:`transient-exclusive`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`},timeoutPolicy:{budget:{source:`flag`,envelope:`margin`},envelopeMs:27e4,onTimeout:`reset-daemon`},batchable:!1,mcpExposed:!1,platformExecution:{kind:`device-runtime`,use:no}},{name:`batch`,deviceClaimPolicy:`none`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`delegated`,appLease:`allowed`},timeoutPolicy:N,batchable:!1,platformExecution:K},{name:`close`,deviceClaimPolicy:`release-session`,catalog:{group:`public`},frameworkTier:`core`,recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`,allowInvalidRecording:!0,saveScriptFlagOwner:!0,sessionlessLeaseAdmissionExemption:$o,appLease:`allowed`},timeoutPolicy:N,batchable:!0,platformExecution:{kind:`device-runtime`,uses:$a}},{name:`snapshot`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`core`,recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`snapshot`,refFrameEffect:`preserve`,appLease:`allowed`},timeoutPolicy:{...Y,budget:{source:`flag`}},batchable:!0,platformExecution:{kind:`device-runtime`,uses:ya,selectUses:xs}},{name:`diff`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`snapshot`,refFrameEffect:`preserve`},timeoutPolicy:N,batchable:!0,platformExecution:{kind:`device-runtime`,uses:ya,selectUses:xs}},{name:`wait`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`core`,recordsSessionAction:!0,recordingEffect:`observes-app`,targetIdentityVerification:`post-resolution`,daemon:{route:`snapshot`,refFrameEffect:`preserve`,appLease:`allowed`},timeoutPolicy:{...Y,budget:{source:`positional-parser`,parser:mr}},batchable:!0,platformExecution:{kind:`device-runtime`,uses:va}},{name:`alert`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`core`,recordsSessionAction:!0,recordingEffect:os,daemon:{route:`snapshot`,refFrameEffect:is},timeoutPolicy:N,batchable:!0,platformExecution:{kind:`device-runtime`,uses:Ba}},{name:`settings`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:us,daemon:{route:`snapshot`,refFrameEffect:ds},timeoutPolicy:N,batchable:!0,platformExecution:{kind:`device-runtime`,uses:Fa}},{name:`react-native`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`,key:`reactNative`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`reactNative`,refFrameEffect:`may-invalidate`},timeoutPolicy:N,batchable:!0,platformExecution:{kind:`device-runtime`,uses:[L]}},{name:`record`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`recordTrace`,refFrameEffect:`preserve`,allowInvalidRecording:!0,allowSessionlessDefaultDevice:Zo},platformExecution:{kind:`device-runtime`,uses:Wo},timeoutPolicy:Y,batchable:!0},{name:`trace`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`recordTrace`,refFrameEffect:`preserve`},timeoutPolicy:N,batchable:!0,platformExecution:K},{name:`find`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`core`,recordsSessionAction:!0,recordingEffect:ss,daemon:{route:`find`,refFrameEffect:`may-invalidate`,appLease:`allowed`},timeoutPolicy:Y,batchable:!0,platformExecution:{kind:`device-runtime`,uses:_a,selectUses:Ss}},{name:`click`,deviceClaimPolicy:`require-owner`,targetIdentityVerification:`pre-dispatch`,catalog:{group:`public`},frameworkTier:`core`,recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0,appLease:`allowed`},timeoutPolicy:X(`click`,Y),postActionObservation:Z(`click`),targetReadiness:`budgeted`,responseDataTransform:vs,batchable:!0,platformExecution:{kind:`device-runtime`,uses:Fi}},{name:`fill`,...J,daemon:{...J.daemon,appLease:`allowed`},frameworkTier:`core`,timeoutPolicy:X(`fill`,Y),postActionObservation:Z(`fill`),responseDataTransform:ys,batchable:!0,platformExecution:{kind:`device-runtime`,uses:zi}},{name:`longpress`,...J,catalog:{group:`public`,key:`longPress`},frameworkTier:`extended`,timeoutPolicy:{..._s,envelopeMs:21e4},postActionObservation:Z(`longpress`),targetReadiness:`budgeted`,batchable:!0,platformExecution:{kind:`device-runtime`,uses:Li}},{name:`hover`,deviceClaimPolicy:`require-owner`,targetIdentityVerification:`pre-dispatch`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`},timeoutPolicy:X(`hover`,Y),postActionObservation:Z(`hover`),batchable:!0,platformExecution:{kind:`device-runtime`,uses:Ri}},{name:`press`,...J,daemon:{...J.daemon,appLease:`allowed`},frameworkTier:`core`,timeoutPolicy:X(`press`,Y),postActionObservation:Z(`press`),targetReadiness:`budgeted`,responseDataTransform:vs,batchable:!0,platformExecution:{kind:`device-runtime`,uses:Ii}},{name:`type`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`core`,recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0,appLease:`allowed`},timeoutPolicy:X(`type`,Y),batchable:!0,platformExecution:{kind:`device-runtime`,uses:[ti]}},{name:`get`,deviceClaimPolicy:`require-owner`,targetIdentityVerification:`pre-dispatch`,catalog:{group:`public`},frameworkTier:`core`,recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`interaction`,refFrameEffect:`preserve`,appLease:`allowed`},timeoutPolicy:X(`get`,Y),batchable:!0,platformExecution:{kind:`device-runtime`,uses:fa}},{name:`is`,deviceClaimPolicy:`require-owner`,targetIdentityVerification:`pre-dispatch`,catalog:{group:`public`},frameworkTier:`core`,recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`interaction`,refFrameEffect:`preserve`,appLease:`allowed`},timeoutPolicy:X(`is`,Y),batchable:!0,platformExecution:{kind:`device-runtime`,uses:da}},{name:`back`,catalog:{group:`public`},frameworkTier:`core`,...q,timeoutPolicy:X(`back`,N),postActionObservation:Z(`back`),platformExecution:{kind:`device-runtime`,uses:[ni]}},{name:`gesture`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`mutates-app`,targetIdentityVerification:`pre-dispatch`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},timeoutPolicy:N,batchable:!0,platformExecution:{kind:`device-runtime`,uses:Yi}},{name:`home`,catalog:{group:`public`},frameworkTier:`extended`,...q,platformExecution:{kind:`device-runtime`,uses:[ri]}},{name:`tv-remote`,catalog:{group:`public`,key:`tvRemote`},frameworkTier:`extended`,...q,platformExecution:{kind:`device-runtime`,uses:[oi]}},{name:`orientation`,catalog:{group:`public`},frameworkTier:`extended`,...q,platformExecution:{kind:`device-runtime`,uses:[ii]}},{name:`fold`,catalog:{group:`public`},frameworkTier:`extended`,...q,timeoutPolicy:vr,platformExecution:{kind:`device-runtime`,uses:[ai]}},{name:`scroll`,catalog:{group:`public`},frameworkTier:`core`,...q,daemon:{...q.daemon,appLease:`allowed`},timeoutPolicy:X(`scroll`,N),postActionObservation:Z(`scroll`),platformExecution:{kind:`device-runtime`,uses:Zi}},{name:`swipe`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`core`,recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},timeoutPolicy:N,batchable:!0,platformExecution:{kind:`device-runtime`,uses:Xi}},{name:`focus`,catalog:{group:`public`},frameworkTier:`extended`,...q,daemon:{...q.daemon,appLease:`allowed`},platformExecution:{kind:`device-runtime`,uses:[ei]}},{name:`screenshot`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`core`,recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`generic`,refFrameEffect:`preserve`,appLease:`allowed`},timeoutPolicy:N,batchable:!0,platformExecution:{kind:`device-runtime`,uses:Ta}},{name:`viewport`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`generic`,refFrameEffect:`may-invalidate`},timeoutPolicy:N,batchable:!1,platformExecution:{kind:`device-runtime`,uses:[$r]}},{name:`app-switcher`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`,key:`appSwitcher`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`generic`,refFrameEffect:`may-invalidate`},timeoutPolicy:N,batchable:!0,platformExecution:{kind:`device-runtime`,uses:[ui]}},{name:`action-button`,catalog:{group:`public`,key:`actionButton`},frameworkTier:`extended`,...q,platformExecution:{kind:`device-runtime`,uses:[di]}},{name:`install-from-source`,deviceClaimPolicy:`none`,catalog:{group:`public`,key:`installFromSource`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`mutates-app`,platformExecution:{kind:`device-runtime`,use:Ua},timeoutPolicy:N,batchable:!0},{name:`debug`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,platformExecution:K},{name:`daemon`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,mcpExposed:!1,platformExecution:ps},{name:`device`,deviceClaimPolicy:`observe`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,mcpExposed:!1,platformExecution:K},{name:`metro`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,platformExecution:K},{name:`session`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,platformExecution:K},{name:`cdp`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,mcpExposed:!1,platformExecution:K},{name:`auth`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,mcpExposed:!1,platformExecution:K},{name:`plugins`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,mcpExposed:!1,platformExecution:K},{name:`connect`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,mcpExposed:!1,platformExecution:K},{name:`connection`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,mcpExposed:!1,platformExecution:K},{name:`disconnect`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,mcpExposed:!1,platformExecution:K},{name:`mcp`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,mcpExposed:!1,platformExecution:K},{name:`proxy`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,mcpExposed:!1,platformExecution:K},{name:`takeover`,deviceClaimPolicy:`observe`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,mcpExposed:!1,platformExecution:{kind:`inventory`,use:jo}},{name:`react-devtools`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`,key:`reactDevtools`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,mcpExposed:!1,platformExecution:K},{name:`web`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,mcpExposed:!1,platformExecution:ps}],Es=new Set([`public`,`local-cli`]),Ds=new Set(Ts.filter(e=>Es.has(Fs(e))).map(e=>e.name)),Q=Ts.map(e=>{let t=Yo(e);return e.name===`record`&&qo(t),{...e,mcpExposed:Ns(e),platformExecution:t}});function Os(e){return Q.filter(t=>Fs(t)===e).map(e=>[Is(e),e.name])}function ks(){return Q.filter(e=>Ps(e)).map(e=>e.name).sort()}function As(e){let t=Q.find(t=>t.name===e)?.platformExecution;if(t?.kind===`device-runtime`)return(`uses`in t?t.uses:[t.use]).map(e=>e.required)}function js(){return Q.filter(e=>e.catalog.group===`public`&&e.platformExecution.kind===`device-runtime`).map(e=>e.name).sort()}const $=new Map(Q.map(e=>[e.name,e]));function Ms(e){return Ds.has(e)}function Ns(e){return e.mcpExposed??Ds.has(e.name)}function Ps(e){return e.mcpExposed&&Ms(e.name)}function Fs(e){return e.catalog.group}function Is(e){return e.catalog.key??e.name}const Ls=new Map(Array.from($.values(),e=>[e.name,e.targetReadiness?{...e.timeoutPolicy,targetReadiness:e.targetReadiness}:e.timeoutPolicy])),Rs=new Map(Q.map(e=>[e.name,e.deviceClaimPolicy])),zs=new Map(Array.from($.values()).flatMap(e=>e.responseDataTransform?[[e.name,e.responseDataTransform]]:[]));function Bs(e){if(e!==void 0)return $.get(e)?.postActionObservation}function Vs(e){return Bs(e)!==void 0}function Hs(e){return e!==void 0&&$.get(e)?.targetReadiness===`budgeted`}function Us(e){return Bs(e)===`settle-and-verify`}function Ws(e){return e===void 0?N:Ls.get(e)??N}function Gs(e){return e===void 0?`require-owner`:Rs.get(e)??`require-owner`}function Ks(e){if(e!==void 0)return zs.get(e)}function qs(e){return e===void 0?!1:$.get(e)?.recordsSessionAction??!1}function Js(e){if(e!==void 0)return $.get(e)?.frameworkTier}function Ys(e){return $.get(e)?.targetIdentityVerification}function Xs(e){let t=$.get(e.command);if(t?.recordsSessionAction)return typeof t.recordingEffect==`function`?t.recordingEffect(e):t.recordingEffect}function Zs(){return[...new Set(Array.from(zs.values()).flatMap(e=>Object.keys(e.fields)))].sort()}const Qs={apps:{appsFilter:`user-installed`}};function $s(e,t){if(!e||!Ms(e))return!1;let n=Qs[e];if(!n)return!1;let r=!1;for(let e of Object.keys(n))t[e]===void 0&&(t[e]=n[e],r=!0);return r}function ec(e){let t=[];for(let n of e)n.daemon&&t.push({command:n.name,...n.daemon,replayScopedAction:n.recordsSessionAction});return t}function tc(e){return e.filter(e=>e.batchable).map(e=>e.name)}const nc=tc(Q),rc=new Set([`batch`,`replay`]),ic=[`command`,`positionals`,`input`,`flags`,`runtime`],ac=[`platform`,`target`,`device`,`udid`,`serial`,`verbose`,`out`,`testIme`],oc=`Session, daemon, connection, and host tooling commands are excluded from batch — they own lifecycle a batch cannot carry — and batch and replay never nest. Run an excluded command on its own; every other device command is available as a step.`,sc=new Set(nc);function cc(e){return sc.has(e)}function lc(e){return typeof e==`string`?e.trim().toLowerCase():``}function uc(e){let t=lc(e);return cc(t)?t:void 0}function dc(t,n,r=oc){let i=uc(t);if(i!==void 0)return i;throw new e(`INVALID_ARGS`,`Batch step ${n} command is not available through command batch: ${String(t)}`,{hint:r})}function fc(t,n){if(rc.has(t))throw new e(`INVALID_ARGS`,`Batch step ${n} cannot run ${t}.`)}export{di as $,Tt as $n,ne as $r,Ar as $t,Oo as A,nn as An,De as Ar,Ci as At,Qa as B,O as Bn,me as Br,Sa as Bt,qs as C,Dn as Cn,x as Cr,ci as Ct,Go as D,wn as Dn,be as Dr,ii as Dt,Ys as E,Tn as En,g as Er,ki as Et,go as F,on as Fn,_e as Fr,ea as Ft,Ja as G,Vt as Gn,ce as Gr,L as Gt,eo as H,Ut as Hn,ue as Hr,mi as Ht,co as I,an as In,ve as Ir,Ea as It,no as J,Bt as Jn,ie as Jr,$r as Jt,Ka as K,Yt as Kn,se as Kr,oi as Kt,uo as L,gn as Ln,p as Lr,ta as Lt,To as M,fn as Mn,Ce as Mr,wi as Mt,po as N,pn as Nn,m as Nr,Ei as Nt,Uo as O,Cn as On,Ee as Or,xi as Ot,yo as P,sn as Pn,ge as Pr,Aa as Pt,Wa as Q,pt as Qn,ee as Qr,zr as Qt,ro as R,vn as Rn,pe as Rr,xa as Rt,Xs as S,Rn as Sn,v as Sr,ji as St,Ws as T,kn as Tn,Oe as Tr,si as Tt,to as U,$t as Un,le as Ur,pi as Ut,io as V,qt as Vn,de as Vr,Bi as Vt,Ga as W,Xt as Wn,fe as Wr,Na as Wt,Ha as X,Wt as Xn,ae as Xr,kr as Xt,Ya as Y,Gt as Yn,l as Yr,Ir as Yt,Ua as Z,Kt as Zn,f as Zr,jr as Zt,Os as _,Wn as _n,Ye as _r,ba as _t,fc as a,gr as an,w as ar,ja as at,Gs as b,Un as bn,Pe as br,Gi as bt,uc as c,M as cn,st as cr,ni as ct,Hs as d,er as dn,at as dr,Ai as dt,te as ei,Mr as en,Ct as er,_i as et,Q as f,Zn as fn,it as fr,Oi as ft,Zs as g,Hn as gn,Xe as gr,Ni as gt,Us as h,nr as hn,qe as hr,I as ht,nc as i,_r as in,T as ir,fi as it,So as j,dn as jn,xe as jr,Ti as jt,Vo as k,On as kn,Te as kr,Si as kt,ec as l,tr as ln,nt as lr,Pi as lt,Vs as m,Qn as mn,ot as mr,bi as mt,ic as n,o as ni,Pr as nn,Ot as nr,hi as nt,lc as o,yr as on,ct as or,ui as ot,As as p,$n as pn,rt as pr,yi as pt,qa as q,Jt as qn,re as qr,ti as qt,ac as r,P as rn,St as rr,gi as rt,dc as s,ir as sn,ut as sr,Zr as st,oc as t,d as ti,Nr as tn,Et as tr,vi as tt,$s as u,Kn as un,tt as ur,Mi as ut,ks as v,zn as vn,Me as vr,ei as vt,Ks as w,En as wn,y as wr,li as wt,Js as x,Ln as xn,b as xr,ri as xt,js as y,Vn as yn,Ie as yr,ai as yt,Za as z,en as zn,he as zr,Ra as zt};
|
|
1
|
+
import{P as e,S as t,b as n}from"./sdk-contracts.js";import{g as r,r as i}from"./sdk-device.js";function a(e,t){return{ok:!1,code:`INVALID_ARGS`,message:e,...t?{hint:t}:{}}}const o=[`visible`,`hidden`,`exists`,`absent`,`editable`,`selected`,`focused`,`text`],s={x:-Number.MAX_VALUE/2,y:-Number.MAX_VALUE/2,width:Number.MAX_VALUE,height:Number.MAX_VALUE};function c(e){return e.x===s.x&&e.y===s.y&&e.width===s.width&&e.height===s.height}function l(e){if(!e)return!1;let{x:t,y:n,width:r,height:i}=e;return![t,n,r,i].every(Number.isFinite)||!Number.isFinite(t+r)||!Number.isFinite(n+i)||r<=0||i<=0?!1:!c(e)}function u(e,t){return e>=s.width||t>=s.height}function d(e){if(l(e)&&!u(e.width,e.height))return{width:e.width,height:e.height}}function ee(e){if(typeof e!=`object`||!e||Array.isArray(e))return;let{x:t,y:n,width:r,height:i}=e;if(typeof r==`number`&&typeof i==`number`&&(t===void 0||typeof t==`number`)&&(n===void 0||typeof n==`number`))return d({x:t??0,y:n??0,width:r,height:i})}function te(e,t){return t.x>=e.x&&t.y>=e.y&&t.x+t.width<=e.x+e.width&&t.y+t.height<=e.y+e.height}function ne(e){return e.width*e.height}function re(e){let t=e[0];if(t===void 0)throw Error(`unionRects requires at least one rect`);let n=t.x,r=t.y,i=t.x+t.width,a=t.y+t.height;for(let t of e.slice(1))n=Math.min(n,t.x),r=Math.min(r,t.y),i=Math.max(i,t.x+t.width),a=Math.max(a,t.y+t.height);return{x:n,y:r,width:i-n,height:a-r}}function ie(e,t,n){return t>=e.x&&t<=e.x+e.width&&n>=e.y&&n<=e.y+e.height}function ae(e,t,n){if(!e||!l(t))return!1;let r=t.x+t.width/2,i=t.y+t.height/2;return r>=n.x&&r<n.x+n.width&&i>=n.y&&i<n.y+n.height}function f(e){let t=null,n=-1;for(let r of e){let e=r.width*r.height;e>n&&(t=r,n=e)}return t}function oe(e,t){return se(e.x,e.x+e.width,t.x,t.x+t.width)&&se(e.y,e.y+e.height,t.y,t.y+t.height)}function se(e,t,n,r){return Math.max(e,n)<=Math.min(t,r)}function ce(e){let t=`${e??``}`.toLowerCase();return t.includes(`scroll`)||t.includes(`recyclerview`)||t.includes(`listview`)||t.includes(`gridview`)||t.includes(`collectionview`)||t===`table`}function le(e){return ce(e.type)?!0:`${e.role??``} ${e.subrole??``}`.toLowerCase().includes(`scroll`)}function ue(e){return e?.trim().toLowerCase()||null}function de(e,t){let n=ue(t);return n?[e.label,e.value,e.identifier].some(e=>(e??``).toLowerCase().includes(n)):!1}function fe(e,t,n=()=>!0){if(!ue(t))return null;for(let[r,i]of e.entries()){if(!de(i,t))continue;let a=i.depth??0,o=r+1;for(;o<e.length&&(e[o]?.depth??0)>a;)o+=1;let s={start:r,end:o};if(n(s))return s}return null}function pe(e,t=0){let n=new Map;for(let[t,r]of e.entries())n.set(r.index,t);return e.map((e,r)=>({...e,index:r,depth:Math.max(0,(e.depth??0)-t),parentIndex:typeof e.parentIndex==`number`?n.get(e.parentIndex):void 0}))}function me(e){return new Map(e.map(e=>[e.index,e]))}function he(e,t,n,r){let i=t,a=new Set;for(;typeof i.parentIndex==`number`&&!a.has(i.index);){if(a.add(i.index),i=n.get(i.parentIndex)??e[i.parentIndex],!i)return null;let t=r(i);if(t!==null)return t}return null}function ge(e,t,n){return he(e,t,me(e),e=>n(e)?e:null)}function p(e){let t=e.trim().replaceAll(/XCUIElementType/gi,``).replace(/^AX/,``).toLowerCase(),n=Math.max(t.lastIndexOf(`.`),t.lastIndexOf(`/`));return n!==-1&&(t=t.slice(n+1)),t}function _e(e,t){let n=p(e);return n?t===`android`?n.includes(`edittext`)||n.includes(`autocompletetextview`):n.includes(`textfield`)||n.includes(`securetextfield`)||n.includes(`searchfield`)||n.includes(`textview`)||n.includes(`textarea`)||n===`search`:!0}function ve(e){let t=e.trim();return!(!t||/^(true|false)$/i.test(t)||/^\d+$/.test(t))}function ye(e){if(typeof e!=`string`)return!1;let t=e.trim();return t?!/^(true|false)$/i.test(t):!1}function m(e){return[e.label,e.value,e.identifier].map(e=>typeof e==`string`?e.trim():``).filter(e=>e.length>0)[0]??``}const be=Symbol(`SnapshotVisibility`);function xe(e,t={}){let n,r,i=()=>(n||(n=me(e),t.onNodeMapBuilt?.()),n),a=()=>(r||(r=Ce(e),t.onViewportRectsCollected?.()),r),o=n=>h(e,n,a(),t.onContainingRectFallback),s=n=>{let r=De(n,i(),e=>!!e.rect)?.rect;if(r)return r;let o=a();return o.length===0?null:h(e,n.rect??{x:0,y:0,width:0,height:0},o,t.onContainingRectFallback)},c=e=>{if(!e.rect)return!0;let t=s(e);return!t||oe(e.rect,t)},l=e=>e.rect?c(e)?Ee(e.rect,o(e.rect)):!1:!0;return{[be]:!0,get nodeByIndex(){return i()},get viewportRects(){return a()},findAncestor(t,n){return he(e,t,i(),n)},isVisibleInEffectiveViewport:c,isVisibleOnScreen:l,resolveEffectiveViewport:s,resolveViewport:o}}function Se(e){let t=[e.type,e.role,e.subrole].map(e=>p(e??``)).join(` `);return t.includes(`application`)||t.includes(`window`)}function Ce(e){return e.flatMap(e=>Se(e)&&l(e.rect)?[e.rect]:[])}function we(e,t,n){return h(e,t,n??Ce(e))}function h(e,t,r,i){let a=n(t),o=e=>ie(e,a.x,a.y);return(f(r.filter(o))??f(r))||(i?.(),f(e.flatMap(e=>Te(e.rect)&&o(e.rect)?[e.rect]:[])))}function Te(e){return e?Number.isFinite(e.x)&&Number.isFinite(e.y)&&Number.isFinite(e.width)&&Number.isFinite(e.height):!1}function Ee(e,t){return!t||t.width<=0||t.height<=0||ie(t,e.x+e.width/2,e.y+e.height/2)}function De(e,t,n=()=>!0){let r=typeof e.parentIndex==`number`?t.get(e.parentIndex):void 0,i=new Set;for(;r&&!i.has(r.index);){if(i.add(r.index),n(r)&&le(r))return r;r=typeof r.parentIndex==`number`?t.get(r.parentIndex):void 0}return null}function Oe(e,t){if(t===`android`&&e.visibleToUser===!1)return!1;let n=p(e.type??``);return n.includes(`application`)||n.includes(`window`)||n.includes(`scrollview`)||n.includes(`tableview`)||n.includes(`collectionview`)||n===`table`||n===`list`||n===`listview`?!1:t===`android`?e.hittable===!0&&l(e.rect):e.hittable===!0||l(e.rect)}function g(e){return e.hittable===!0?!0:e.rect?e.rect.width>0&&e.rect.height>0:!1}function ke(e,t){return _e(e.type??``,t)&&e.enabled!==!1}function Ae(e){let n=e.kind??t(e.type??`Element`),r=p(e.type??``);return r&&r!==n?[n,r]:[n]}const je=new Set([`id`,`role`,`text`,`label`,`value`,`appname`,`windowtitle`]),Me=new Set([`visible`,`hidden`,`editable`,`selected`,`focused`,`enabled`,`hittable`]),_=new Set([...je,...Me]),v=[..._],Ne=new Set(`button.imagebutton.link.cell.statictext.checkedtextview.textfield.textbox.edittext.textarea.switch.slider.image.imageview.webview.framelayout.linearlayout.relativelayout.constraintlayout.viewgroup.view.listview.recyclerview.collectionview.list.searchfield.segmentedcontrol.group.window.checkbox.radio.menuitem.toolbar.scrollarea.scrollview.nestedscrollview.table.application.navigationbar.tabbar.tab.alert.dialog.header`.split(`.`));function Pe(e){return Ne.has(e.trim().toLowerCase())}const Fe=new Map([[`"`,`"`],[`'`,`'`],[`\\`,`\\`],[`/`,`/`],[`b`,`\b`],[`f`,`\f`],[`n`,`
|
|
2
|
+
`],[`r`,`\r`],[`t`,` `]]);function y(t){let n=t.trim();if(!n)throw new e(`INVALID_ARGS`,`Selector expression cannot be empty`);let r=ze(n);if(r.length===0)throw new e(`INVALID_ARGS`,`Selector expression cannot be empty`);return{raw:n,selectors:r.map(e=>Le(e))}}function b(e){try{return y(e)}catch{return null}}function x(e){let t=e.trim();if(!t)return!1;if(t===`||`)return!0;let n=t.indexOf(`=`);if(n!==-1){let e=t.slice(0,n).trim().toLowerCase();return _.has(e)}return _.has(t.toLowerCase())}function Ie(e){let t=e.trim(),n=t.indexOf(`=`);if(n===-1)return null;let r=t.slice(0,n).trim().toLowerCase();if(!r||_.has(r))return null;let i=t.slice(n+1).trim();if(!i)return null;let a=He(i).trim();return a?{key:r,value:a}:null}function S(e,t={}){if(e.length===0)return null;let n=t.preferTrailingValue??!1,r=0,i=[];for(;r<e.length;){let t=e[r];if(t===void 0||!x(t))break;r+=1;let n=e.slice(0,r).join(` `).trim();n&&b(n)&&i.push(r)}if(i.length===0)return null;let a=i.at(-1);if(a===void 0)return null;let o=a;if(n)for(let t=i.length-1;t>=0;--t){let n=i[t];if(n!==void 0&&n<e.length){o=n;break}}let s=e.slice(0,o).join(` `).trim();return s?{selectorExpression:s,rest:e.slice(o)}:null}function Le(t){let n=t.trim();if(!n)throw new e(`INVALID_ARGS`,`Selector segment cannot be empty`);let r=Be(n);if(r.length===0)throw new e(`INVALID_ARGS`,`Invalid selector segment: ${t}`);return{raw:n,terms:r.map(Re)}}function Re(t){let n=t.trim();if(!n)throw new e(`INVALID_ARGS`,`Empty selector term`);let r=n.indexOf(`=`);if(r===-1){let r=n.toLowerCase();if(!Me.has(r))throw new e(`INVALID_ARGS`,`Invalid selector term "${t}", expected key=value`);return{key:r,value:!0}}let i=n.slice(0,r).trim().toLowerCase(),a=n.slice(r+1).trim();if(!_.has(i))throw new e(`INVALID_ARGS`,`Unknown selector key: ${i}`);if(!a)throw new e(`INVALID_ARGS`,`Missing selector value for key: ${i}`);if(Me.has(i)){let t=Ge(a);if(t===null)throw new e(`INVALID_ARGS`,`Invalid boolean value for ${i}: ${a}`);return{key:i,value:t}}return{key:i,value:He(a)}}function ze(t){let n=[],r=``,i=null;for(let a=0;a<t.length;a+=1){let o=t[a];if((o===`"`||o===`'`)&&!Ke(t,a)){i=Ve(i,o),r+=o;continue}if(!i&&o===`|`&&t[a+1]===`|`){let i=r.trim();if(!i)throw new e(`INVALID_ARGS`,`Invalid selector fallback expression: ${t}`);n.push(i),r=``,a+=1;continue}r+=o}let a=r.trim();if(!a)throw new e(`INVALID_ARGS`,`Invalid selector fallback expression: ${t}`);return n.push(a),n}function Be(t){let n=[],r=``,i=null;for(let e=0;e<t.length;e+=1){let a=t.charAt(e);if((a===`"`||a===`'`)&&!Ke(t,e)){i=Ve(i,a),r+=a;continue}if(!i&&/\s/.test(a)){r.trim()&&n.push(r.trim()),r=``;continue}r+=a}if(i)throw new e(`INVALID_ARGS`,`Unclosed quote in selector: ${t}`);return r.trim()&&n.push(r.trim()),n}function Ve(e,t){return e?e===t?null:e:t}function He(e){let t=e.trim();return t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`)?Ue(t.slice(1,-1)):t}function Ue(e){let t=``,n=0;for(;n<e.length;){let r=e.charAt(n);if(r!==`\\`){t+=r,n+=1;continue}let i=e.charAt(n+1);if(!i){t+=r,n+=1;continue}let a=We(i);if(a!==null){t+=a,n+=2;continue}if(i===`u`){let r=e.slice(n+2,n+6);if(/^[0-9a-fA-F]{4}$/.test(r)){t+=String.fromCharCode(Number.parseInt(r,16)),n+=6;continue}}t+=r,n+=1}return t}function We(e){return Fe.get(e)??null}function Ge(e){let t=He(e).toLowerCase();return t===`true`||t!==`false`&&null}function Ke(e,t){let n=0;for(let r=t-1;r>=0&&e[r]===`\\`;--r)n+=1;return n%2==1}function qe(e){return o.includes(e)}const Je=`is requires predicate: ${o.join(`|`)}`;function Ye(e){let t=e.toLowerCase();return qe(t)?{ok:!0,predicate:t}:a(Je,Xe)}const Xe=`Use "is <predicate> <selector>" or "is <selector> <predicate>". visible|hidden|editable|selected|focused double as selector keys: a bare predicate token after the selector is read as the predicate, so write key=true (e.g. visible=true) inside the selector to use it as a filter instead.`;function Ze(e){if(qe((e[0]??``).toLowerCase()))return e;for(let t=1;t<e.length;t+=1){let n=(e[t]??``).toLowerCase();if(qe(n)&&b(e.slice(0,t).join(` `)))return[n,...e.slice(0,t),...e.slice(t+1)]}return e}function Qe(e){let{predicate:t,node:n,visibility:r,expectedText:i,platform:a}=e,o=m(n),s=ke(n,a),c=n.selected===!0,l=n.focused===!0,u=t===`text`?g(n):et(n,r,a),d=!1;switch(t){case`visible`:d=u;break;case`hidden`:d=!u;break;case`editable`:d=s;break;case`selected`:d=c;break;case`focused`:d=l;break;case`text`:d=o===(i??``);break;default:return $e(t)}let ee=t===`text`?`expected="${i??``}" actual="${o}"`:`actual=${JSON.stringify({visible:u,editable:s,selected:c,focused:l})}`;return{pass:d,actualText:o,details:ee}}function $e(e){throw Error(`Unhandled is predicate: ${String(e)}`)}function et(e,t,n){if(n===`android`&&e.visibleToUser===!1)return!1;if(l(e.rect))return t.isVisibleInEffectiveViewport(e);if(e.rect)return!1;if(n!==`android`&&e.hittable===!0)return!0;let r=tt(e,t,n);return r?l(r.rect)?t.isVisibleInEffectiveViewport(r):n!==`android`&&r.hittable===!0:!1}function tt(e,t,n){return t.findAncestor(e,e=>Oe(e,n)?e:null)}function nt(e){let t=Ze(e),n=t[0]??``;return{predicate:n,split:S(t.slice(1),{preferTrailingValue:n===`text`})}}const rt=`is requires a selector expression`,it=`is text requires expected text value`;function at(e){let{predicate:t,split:n}=nt([...e]),r=Ye(t);if(!r.ok)return r;if(!n)return a(rt);let i=n.rest.join(` `).trim();return r.predicate===`text`&&!i?a(it):r.predicate!==`text`&&n.rest.length>0?a(`is ${r.predicate} does not accept trailing values`):{ok:!0,predicate:r.predicate,selectorExpression:n.selectorExpression,expectedText:i}}function ot(e){return e===`text`||e===`attrs`?{ok:!0,format:e}:a(`get only supports text or attrs`)}function st(e){let t=e[0];if(t?.startsWith(`@`)){let n=e.slice(1).join(` `).trim();return{ok:!0,ref:t,...n?{label:n}:{}}}let n=e.join(` `).trim();return n?{ok:!0,selector:n}:a(`get requires @ref or selector expression`)}function ct(e){return e?{ok:!0,text:e}:a(`wait requires text`)}function lt(e){return Array.from(new Set(e))}function ut(e){return JSON.stringify(dt(e))}function dt(e){if(Array.isArray(e))return e.map(dt);if(!e||typeof e!=`object`)return e;let t=e;return Object.fromEntries(Object.keys(t).sort().map(e=>[e,dt(t[e])]))}function ft(e){let t=0,n=e.length;for(;t<n&&e[t]===`-`;)t+=1;for(;n>t&&e[n-1]===`-`;)--n;return e.slice(t,n)}const pt=/^#\s*agent-device:target-v(\d+)(?:\s+(\S.*))?$/,mt=/^#\s*agent-device:targets-v(\d+)(?:\s+(\S.*))?$/,ht=4096;function gt(e){return e.normalize(`NFC`)}function _t(e){if(e===void 0)return;let t=gt(e);return t.length>0?t:void 0}function vt(e){return gt(e)}function yt(e){if(e===void 0)return;let t=gt(e).trim().replaceAll(/\s+/g,` `);return t.length>0?t:void 0}function C(e){return Buffer.byteLength(e,`utf8`)}function w(e,t){if(C(e)<=t)return e;let n=e.length;for(;n>0&&C(e.slice(0,n))>t;)--n;if(n>0){let t=e.charCodeAt(n-1);t>=55296&&t<=56319&&--n}return e.slice(0,n)}function bt(e){let t={};return e.id!==void 0&&(t.id=e.id),t.role=e.role,e.label!==void 0&&(t.label=e.label),t.ancestry=e.ancestry.map(xt),t.sibling=e.sibling,t.viewportOrder=e.viewportOrder,e.scrollRegion&&(t.scrollRegion=St(e.scrollRegion)),e.rect&&(t.rect=Ct(e.rect)),t.verification=e.verification,t}function xt(e){let t={role:e.role};return e.label!==void 0&&(t.label=e.label),t}function St(e){let t={role:e.role};return e.id!==void 0&&(t.id=e.id),e.label!==void 0&&(t.label=e.label),t}function Ct(e){return{x:e.x,y:e.y,width:e.width,height:e.height}}function wt(e){return JSON.stringify(bt(e))}function Tt(e){return`# agent-device:target-v1 ${wt(e)}`}function Et(e){return JSON.stringify({source:bt(e.source),destination:bt(e.destination)})}function Dt(e){return`# agent-device:targets-v1 ${Et(e)}`}function Ot(e){let t=e.trim(),n=mt.exec(t);return n?Number(n[1])===1?{kind:`v1`,evidence:kt((n[2]??``).trim())}:{kind:`future-version`}:{kind:`none`}}function kt(t){if(C(t)>8320)throw new e(`INVALID_ARGS`,`targets-v1 annotation exceeds the 8320-byte payload cap.`);let n;try{n=JSON.parse(t)}catch{throw new e(`INVALID_ARGS`,`targets-v1 annotation is not valid JSON.`)}if(typeof n!=`object`||!n||Array.isArray(n))throw new e(`INVALID_ARGS`,`targets-v1 annotation must be a JSON object.`);let r=n;if(r.source===void 0||r.destination===void 0)throw new e(`INVALID_ARGS`,`targets-v1 annotation requires source and destination evidence.`);return{source:jt(JSON.stringify(r.source)),destination:jt(JSON.stringify(r.destination))}}function At(e){let t=e.trim();if(!t.startsWith(`#`))return{kind:`none`};let n=pt.exec(t);return n?Number(n[1])===1?{kind:`v1`,evidence:jt((n[2]??``).trim())}:{kind:`future-version`}:{kind:`none`}}function jt(t){if(C(t)>4096)throw new e(`INVALID_ARGS`,`target-v1 annotation exceeds the ${ht}-byte payload cap.`);let n;try{n=JSON.parse(t)}catch{throw new e(`INVALID_ARGS`,`target-v1 annotation is not valid JSON.`)}if(typeof n!=`object`||!n||Array.isArray(n))throw new e(`INVALID_ARGS`,`target-v1 annotation must be a JSON object.`);let r=n,i=Mt(r.role,`role`),a=Nt(r.id,`id`),o=Pt(r.label,`label`),s=It(r.ancestry),c=Rt(r.sibling,`sibling`,0),l=Rt(r.viewportOrder,`viewportOrder`,0),u=zt(r.scrollRegion),d=Bt(r.rect),ee=Vt(r.verification);return{...a===void 0?{}:{id:a},role:i,...o===void 0?{}:{label:o},ancestry:s,sibling:c,viewportOrder:l,...u?{scrollRegion:u}:{},...d?{rect:d}:{},verification:ee}}function Mt(t,n){if(t===void 0)throw new e(`INVALID_ARGS`,`target-v1 "${n}" is required.`);if(typeof t!=`string`)throw new e(`INVALID_ARGS`,`target-v1 "${n}" must be a string.`);return Ft(vt(t),n)}function Nt(t,n){if(t===void 0)return;if(typeof t!=`string`)throw new e(`INVALID_ARGS`,`target-v1 "${n}" must be a string.`);let r=_t(t);return r===void 0?void 0:Ft(r,n)}function Pt(t,n){if(t===void 0)return;if(typeof t!=`string`)throw new e(`INVALID_ARGS`,`target-v1 "${n}" must be a string.`);let r=yt(t);return r===void 0?void 0:Ft(r,n)}function Ft(t,n){if(C(t)>256)throw new e(`INVALID_ARGS`,`target-v1 "${n}" exceeds the 256-byte field cap.`);return t}function It(t){if(t===void 0)return[];if(!Array.isArray(t))throw new e(`INVALID_ARGS`,`target-v1 "ancestry" must be an array.`);if(t.length>8)throw new e(`INVALID_ARGS`,`target-v1 "ancestry" exceeds the 8-entry cap.`);return t.map((e,t)=>Lt(e,t))}function Lt(t,n){if(typeof t!=`object`||!t||Array.isArray(t))throw new e(`INVALID_ARGS`,`target-v1 "ancestry[${n}]" must be an object.`);let r=t,i=Mt(r.role,`ancestry[${n}].role`),a=Pt(r.label,`ancestry[${n}].label`);return{role:i,...a===void 0?{}:{label:a}}}function Rt(t,n,r){if(t===void 0)return r;if(typeof t!=`number`||!Number.isSafeInteger(t)||t<0)throw new e(`INVALID_ARGS`,`target-v1 "${n}" must be a non-negative integer.`);return t}function zt(t){if(t===void 0)return;if(typeof t!=`object`||!t||Array.isArray(t))throw new e(`INVALID_ARGS`,`target-v1 "scrollRegion" must be an object.`);let n=t,r=Mt(n.role,`scrollRegion.role`),i=Nt(n.id,`id`),a=Pt(n.label,`scrollRegion.label`);return{role:r,...i===void 0?{}:{id:i},...a===void 0?{}:{label:a}}}function Bt(t){if(t===void 0)return;if(typeof t!=`object`||!t||Array.isArray(t))throw new e(`INVALID_ARGS`,`target-v1 "rect" must be an object.`);let n=t;return{x:T(n.x,`rect.x`),y:T(n.y,`rect.y`),width:T(n.width,`rect.width`),height:T(n.height,`rect.height`)}}function T(t,n){if(typeof t!=`number`||!Number.isFinite(t))throw new e(`INVALID_ARGS`,`target-v1 "${n}" must be a finite number.`);return t}function Vt(t){if(t===`verified`||t===`unverifiable`)return t;throw new e(`INVALID_ARGS`,`target-v1 "verification" must be "verified" or "unverifiable".`)}function Ht(e){let t=vt(p(e.type??``)),n=_t(e.identifier),r=yt(e.label);return{...n===void 0?{}:{id:w(n,256)},role:w(t,256),...r===void 0?{}:{label:w(r,256)}}}function Ut(e,t){return e.id===t.id&&e.role===t.role&&e.label===t.label}function Wt(e,t){let n=0;for(let r of e)Ht(r).id===t&&(n+=1);return n}function Gt(e,t){if(e.id===void 0||Wt(t,e.id)<=1)return e;let{role:n,label:r}=e;return{role:n,...r===void 0?{}:{label:r}}}function Kt(e,t){let n=0;for(let r of e)if(r.parentIndex===t.parentIndex){if(r.index===t.index)return n;n+=1}return 0}function qt(e,t){return{documentOrder:e.index,sibling:Kt(t,e)}}function Jt(e,t){return e.documentOrder===t.documentOrder&&e.sibling===t.sibling}function Yt(e){return{...e.id===void 0?{}:{id:e.id},role:e.role,...e.label===void 0?{}:{label:e.label}}}function Xt(e,t){return t.id===void 0?e.role===t.role&&e.label===t.label:e.id===t.id}function Zt(e,t){if(e.length<t.length)return!1;for(let[n,r]of t.entries()){let t=e[n];if(!t||t.role!==r.role||r.label!==void 0&&t.label!==r.label)return!1}return!0}function Qt(e,t){let n=[];return e.id!==t.id&&n.push(`id: recorded=${e.id??`(none)`} observed=${t.id??`(none)`}`),e.role!==t.role&&n.push(`role: recorded=${e.role} observed=${t.role}`),e.label!==t.label&&n.push(`label: recorded=${e.label??`(none)`} observed=${t.label??`(none)`}`),n}function $t(e){return e?`${e.role}${e.label?`/${e.label}`:``}`:`(missing)`}function en(e,t){return!t||t.role!==e.role||e.label!==void 0&&t.label!==e.label}function tn(e,t){for(let[n,r]of e.entries()){let e=t[n];if(en(r,e))return[`ancestry[${n}]: recorded=${$t(r)} observed=${$t(e)}`]}return[]}function nn(e,t,n={}){let r=[],i=p(e.type??``),a=rn(e,n.nodes),o=D(e.label),s=D(e.value),c=D(m(e)),l=n.action===`fill`;a&&r.push(`id=${E(a)}`),i&&o&&r.push(l?`role=${E(i)} label=${E(o)} editable=true`:`role=${E(i)} label=${E(o)}`),o&&r.push(l?`label=${E(o)} editable=true`:`label=${E(o)}`),s&&r.push(l?`value=${E(s)} editable=true`:`value=${E(s)}`),c&&c!==o&&c!==s&&r.push(l?`text=${E(c)} editable=true`:`text=${E(c)}`),i&&l&&!r.some(e=>e.includes(`editable=true`))&&r.push(`role=${E(i)} editable=true`);let u=lt(r);return u.length===0&&i&&u.push(l?`role=${E(i)} editable=true`:`role=${E(i)}`),u.length===0&&g(e)&&u.push(`visible=true`),u}function rn(e,t){let n=D(e.identifier);if(!n||!t)return n;let r=Ht(e).id;return r===void 0?n:Wt(t,r)>1?null:n}function E(e){return JSON.stringify(e)}function D(e){return e&&e.trim()||null}const an=[`any`,`text`,`label`,`value`,`role`,`id`],on=[`text`,`label`,`value`,`role`,`id`];function sn(e){let t=e?.toLowerCase();return t===`press`||t===`tap`?`click`:t}function O(e){return e===`exists`||e===`wait`||e===`get_text`||e===`get_attrs`||e===`list`}function cn(e,t,n,r={}){let i=A(n);if(!i)return{matches:[],score:0};let a=0,o=[];for(let n of e){if(r.requireRect&&!n.rect)continue;let e=ln(n,t,i);if(!(e<=0)){if(e>a){a=e,o.length=0,o.push(n);continue}e===a&&o.push(n)}}return{matches:o,score:a}}function ln(e,t,n){switch(t){case`role`:return un(e,n);case`label`:return k(e.label,n);case`value`:return k(e.value,n);case`id`:return k(e.identifier,n);default:return Math.max(k(e.label,n),k(e.value,n),k(e.identifier,n))}}function k(e,t){let n=A(e??``);return n?n===t?2:+!!n.includes(t):0}function un(e,t){let n=Ae(e);return n.some(e=>A(e)===t)?2:+!!n.some(e=>dn(e).includes(t))}function dn(e){let t=e.lastIndexOf(`.`);return t===-1?e:e.slice(t+1)}function A(e){return e.trim().toLowerCase().replaceAll(/\s+/g,` `)}const fn=`find requires a value`,pn=`find actions: click (default; press/tap are aliases), list, focus, fill, type, exists, wait, get text, get attrs — there is no longpress/swipe find action. Run find "<text>" list to inspect every match with its @ref without acting, then dispatch the gesture on the chosen ref, e.g. longpress @eNN.`;function mn(e,t){if(e.length===0)return{ok:!1,code:`INVALID_ARGS`,message:`find requires a locator or text`};let n=_n([...e]);return n.query?t?.findFirst&&t?.findLast?{ok:!1,code:`INVALID_ARGS`,message:`find accepts only one of --first or --last`}:{ok:!0,parsed:n}:{ok:!1,code:`INVALID_ARGS`,message:fn}}const hn=[`exists`,`list`,`click`,`focus`];function gn(e){return hn.includes(e)}function _n(t){let n=`any`,r=0;on.includes(t[0])&&(n=t[0],r=1);let i=t[r]??``,a=t.slice(r+1);if(a.length===0)return{locator:n,query:i,action:`click`};let o=sn(a[0]);if(gn(o))return{locator:n,query:i,action:o};if(o===`get`)return{locator:n,query:i,action:vn(a[1])};if(o===`wait`){let e=bn(a[1]);return{locator:n,query:i,action:`wait`,timeoutMs:e??void 0}}if(o===`fill`||o===`type`){let e=a.slice(1);return{locator:n,query:i,action:o,value:e.length===0?void 0:e.join(` `)}}throw new e(`INVALID_ARGS`,`Unsupported find action: ${a[0]}`,{hint:pn})}function vn(t){let n=t?.toLowerCase();if(n===`text`)return`get_text`;if(n===`attrs`)return`get_attrs`;throw new e(`INVALID_ARGS`,`find get only supports text or attrs`)}function yn(e,t){return e!==`any`||!t.includes(`=`)&&!t.includes(`||`)?null:b(t)?t:null}function bn(e){if(!e)return null;let t=Number(e);return Number.isFinite(t)?t:null}function xn(e,t,n){return t.terms.every(t=>Sn(e,t,n))}function Sn(e,t,n){switch(t.key){case`id`:return j(e.identifier,String(t.value));case`role`:return Cn(e,String(t.value));case`label`:return j(e.label,String(t.value));case`value`:return j(e.value,String(t.value));case`text`:return j(m(e),String(t.value));case`appname`:return j(e.appName,String(t.value));case`windowtitle`:return j(e.windowTitle,String(t.value));case`visible`:return g(e)===!!t.value;case`hidden`:return!g(e)==!!t.value;case`editable`:return ke(e,n)===!!t.value;case`selected`:return e.selected===!0==!!t.value;case`focused`:return e.focused===!0==!!t.value;case`enabled`:return e.enabled!==!1==!!t.value;case`hittable`:return e.hittable===!0==!!t.value;default:return!1}}function j(e,t){return A(e??``)===A(t)}function Cn(e,t){let n=A(t);return Ae(e).some(e=>A(e)===n)}function wn(e,t,n){let r=n.requireRect??!1,i=n.requireUnique??!0,a=[],o=null;for(let[s,c]of t.selectors.entries()){let t=jn(e,c,n.platform,r);if(a.push({selector:c.raw,matches:t.count}),!(t.count===0||!t.firstNode)){if(o??={selector:c,selectorIndex:s,matchedNodes:t.candidates},i&&t.count!==1){if(!n.disambiguateAmbiguous||!t.disambiguated||!t.tiebreak)continue;return{matchedNodes:t.candidates,firstMatch:o,resolution:{node:t.disambiguated,selector:c,selectorIndex:s,matches:t.count,diagnostics:a,disambiguation:{matchCount:t.count,tiebreak:t.tiebreak,alternatives:t.candidates.filter(e=>e!==t.disambiguated)}}}}return{matchedNodes:t.candidates,firstMatch:o,resolution:{node:t.firstNode,selector:c,selectorIndex:s,matches:t.count,diagnostics:a}}}}return{resolution:null,matchedNodes:o?.matchedNodes??[],firstMatch:o}}function Tn(e,t,n){return wn(e,t,n).resolution}function En(e,t,n){let r=n.requireRect??!1;for(let[i,a]of t.selectors.entries()){let t=e.filter(e=>r&&!e.rect?!1:xn(e,a,n.platform));if(t.length>0)return{selector:a,selectorIndex:i,matchedNodes:t}}return null}function Dn(e,t,n){let r=n.requireRect??!1,i=[];for(let[a,o]of t.selectors.entries()){let t=Fn(e,o,n.platform,r);if(i.push({selector:o.raw,matches:t}),t>0)return{selectorIndex:a,selector:o,matches:t,diagnostics:i}}return null}const On=`Snapshot refs expire when the UI changes. Run snapshot -i and retry with a fresh @ref.`;function kn(e){return e.some(e=>e.matches>1)?`Add more terms to disambiguate (e.g. role=button text="Sign in"), use an @ref from snapshot -i, or use find <text> --first/--last.`:`Selector text/label values match exactly (quote multi-word values: text="Sign in"). Run snapshot -i to see current elements and refs, or use find <text> for contains matching.`}function An(e,t,n){if(t.length===0)return`Selector did not match: ${e}`;let r=t.map(e=>`${e.selector} -> ${e.matches}`).join(`, `);return n.unique??!0?`Selector did not resolve uniquely (${r})`:`Selector did not match (${r})`}function jn(e,t,n,r){let i=0,a=null,o=[],s={best:null,bestVisible:!1,tie:!1},c=xe(e).isVisibleOnScreen;for(let l of e)r&&!l.rect||xn(l,t,n)&&(i+=1,a??=l,o.push(l),Mn(s,l,c));return{count:i,firstNode:a,disambiguated:s.tie?null:s.best,tiebreak:s.tie?null:Nn(o,s.best,c),candidates:o}}function Mn(e,t,n){if(!e.best){e.best=t;return}e.bestVisible||=n(e.best);let r=n(t);if(r!==e.bestVisible){r&&(e.best=t,e.bestVisible=!0,e.tie=!1);return}let i=In(t,e.best);i.result>0?(e.best=t,e.tie=!1):i.result===0&&(e.tie=!0)}function Nn(e,t,n){if(!t)return null;let r=null;for(let i of e)i!==t&&(!r||Pn(i,r,n).result>0)&&(r=i);return r?Pn(t,r,n).criterion:null}function Pn(e,t,n){let r=n(e);return r===n(t)?In(e,t):{result:r?1:-1,criterion:`visible`}}function Fn(e,t,n,r){let i=0;for(let a of e)r&&!a.rect||xn(a,t,n)&&(i+=1);return i}function In(e,t){let n=e.depth??0,r=t.depth??0;if(n!==r)return{result:n>r?1:-1,criterion:`deepest`};let i=Ln(e),a=Ln(t);return i===a?{result:0,criterion:null}:{result:i<a?1:-1,criterion:`smallest-area`}}function Ln(e){return e.rect?e.rect.width*e.rect.height:1/0}const Rn={act:{ambiguity:`reject-candidates`,requireRect:!0},actCoveredDiagnosis:{ambiguity:`first-match`,requireRect:!0},readText:{ambiguity:`disambiguate`,requireRect:!1},readUnique:{ambiguity:`fail-closed`,requireRect:!1},readAny:{ambiguity:`first-match`,requireRect:!1},wait:{ambiguity:`first-match`,requireRect:!1},findAct:{ambiguity:`reject-candidates`,requireRect:!0},readList:{ambiguity:`reject-candidates`,requireRect:!1},cropTarget:{ambiguity:`fail-closed`,requireRect:!0}};function zn(e){return e.ambiguity===`first-match`?{requireRect:e.requireRect,requireUnique:!1}:{requireRect:e.requireRect,requireUnique:!0,disambiguateAmbiguous:e.ambiguity===`disambiguate`}}function Bn(e,t){let n=e===`is`?nt([...t]).split:S([...t]);return n?b(n.selectorExpression)?{kind:`expression`,expression:n.selectorExpression,rest:n.rest}:{kind:`invalid`}:{kind:`not-applicable`}}function Vn(e){return{platform:e.platform,...zn({ambiguity:e.allowDisambiguation?`disambiguate`:`fail-closed`,requireRect:e.requireRect})}}function Hn(e,t,n){let r=b(e);if(!r)return{kind:`unresolved`,reason:`parse-invalid`,matchedNodes:[]};let{resolution:i,matchedNodes:a}=wn(t,r,Vn(n));return i?{kind:`resolved`,winner:i.node,matchedNodes:a,matchCount:a.length,...i.disambiguation?{disambiguation:{tiebreak:i.disambiguation.tiebreak,matchCount:i.disambiguation.matchCount,alternatives:i.disambiguation.alternatives}}:{}}:{kind:`unresolved`,reason:a.length>0?`ambiguous`:`no-match`,matchedNodes:a}}function Un(e,t,n={}){return nn(e,t,n)}function Wn(e,t,n){let r=b(e);if(!r)return;let i=Tn(t,r,Vn(n));if(i)return{node:i.node,basis:Kn(i.selector)}}function Gn(e){if(!e)return;let t=b(e);if(!t)return;let n=t.selectors.flatMap(e=>e.terms.flatMap(e=>(e.key===`label`||e.key===`text`||e.key===`id`)&&typeof e.value==`string`?[e.value]:[]));if(n.length===0)return;let r=n[0];return r&&n.every(e=>e===r)?r:void 0}function Kn(e){let t=new Set(e.terms.map(e=>e.key));if(t.has(`id`))return`id`;let n=t.has(`role`),r=t.has(`label`)||t.has(`text`);return n&&r?`role-label`:r||t.has(`value`)?`label`:`other`}function qn(e,t){let n=b(e);if(!n)return e.includes(`=`)||e.includes(`||`)?null:e;let r=new Set(t.textKeys),i=t.textAliases??{};return n.selectors.length>1?Jn(n.selectors,r,i):Yn(n.selectors[0],r,new Set(t.booleanKeys),i)}function Jn(e,t,n){let r=e.map(e=>{let r=e.terms.length===1?e.terms[0]:void 0;return r&&Xn(r.key,t,n)&&typeof r.value==`string`?r.value:void 0}),i=r[0];return i!==void 0&&r.every(e=>e===i)?i:null}function Yn(e,t,n,r){if(!e)return null;let i={},a=0;for(let o of e.terms){if(Xn(o.key,t,r)&&typeof o.value==`string`)a+=1;else if(!Zn(o,n,`boolean`))return null;i[r[o.key]??o.key]=o.value}return a<=1&&Object.keys(i).length>0?i:null}function Xn(e,t,n){return t.has(e)||n[e]!==void 0}function Zn(e,t,n){return t.has(e.key)&&typeof e.value===n}function Qn(e){let t=b(e);if(!t||t.selectors.length!==1)return null;let n=t.selectors[0];if(!n||n.terms.length!==1)return null;let r=n.terms[0];return!r||typeof r.value!=`string`||r.key!==`id`&&r.key!==`label`&&r.key!==`text`&&r.key!==`value`?null:{key:r.key,value:r.value,raw:n.raw}}function $n(e,t){if(!t)return!1;let n=b(e);return n?n.selectors.some(e=>e.terms.some(e=>(e.key===`text`||e.key===`label`||e.key===`value`)&&typeof e.value==`string`&&e.value.includes(t))):!1}function er(e,t){return b(e)?.selectors.some(e=>e.terms.some(e=>e.key===t))??!1}function tr(e){return y(e).selectors.map(e=>e.raw)}function nr(e){return b(e)!==null}function rr(e){y(e)}function M(e){if(!e)return null;let t=Number(e);return Number.isFinite(t)?t:null}const ir=new Set([`exists`,`present`,`appears`,`gone`,`disappears`]);function ar(e){let t=e[0];if(t===void 0)return null;let n=M(t);if(n!==null)return{kind:`sleep`,durationMs:n};let r=M(e.at(-1));return t===`text`?or(e,r):t===`stable`?sr(e):t===`absent`?cr(e,r):t.startsWith(`@`)?{kind:`ref`,rawRef:t,timeoutMs:r}:ur(e,r)}function or(e,t){return{kind:`text`,text:(t===null?e.slice(1).join(` `):e.slice(1,-1).join(` `)).trim(),timeoutMs:t}}function sr(e){let t=e.slice(1),n=t.length>1?M(t[1]):null;return{kind:`stable`,quietMs:t.length>0?M(t[0]):null,timeoutMs:n}}function cr(e,t){let n=t===null?e.slice(1):e.slice(1,-1),r=S(n);return n.length>0&&r?.rest.length===0&&nr(r.selectorExpression)?{kind:`absent`,selectorExpression:r.selectorExpression,timeoutMs:t}:{kind:`invalid`,reason:`absent-selector-required`,message:lr(n)}}function lr(e){let t=e.join(` `);return t.length>0?`wait absent requires one valid selector; received "${t}". Use wait absent '<selector>' [timeoutMs].`:`wait absent requires <selector> [timeoutMs].`}function ur(e,t){let n=t===null?e.slice():e.slice(0,-1),r=S(n);return r&&r.rest.length===0&&nr(r.selectorExpression)?{kind:`selector`,selectorExpression:r.selectorExpression,timeoutMs:t}:dr(n,r)||{kind:`text`,text:(t===null?e.join(` `):e.slice(0,-1).join(` `)).trim(),timeoutMs:t}}function dr(e,t){for(let t of e){let n=Ie(t);if(n)return{kind:`invalid`,reason:`unknown-selector-key`,message:fr(n,e)}}return t&&t.rest.length>0?{kind:`invalid`,reason:`selector-shaped-text`,message:pr(t,e)}:e.some(e=>x(e))?{kind:`invalid`,reason:`selector-shaped-text`,message:mr(e)}:null}function fr(e,t){let n=t.join(` `),r=Pe(e.key)?`role=${e.key} label="${e.value}"`:`label="${e.value}"`;return`Unknown selector key "${e.key}" in "${n}". Supported: ${v.join(`, `)}. Use wait '${r}' [timeoutMs] to wait for the selector, or wait text '${n}' [timeoutMs] to wait for the literal text "${n}".`}function pr(e,t){let n=t.join(` `);return`Selector ${e.selectorExpression} is followed by unexpected extra arguments: "${e.rest.join(` `)}". Selector values with spaces need quotes, e.g. label="Sign in". Use wait '<selector>' [timeoutMs], or wait text '${n}' [timeoutMs] to wait for the literal text "${n}".`}function mr(e){let t=e.join(` `),n=e.filter(e=>!x(e)),r=e.filter(e=>x(e));if(n.length>0){let e=n[0],i=ir.has(e.toLowerCase())?` "${e}" describes a condition, not a selector key. Use the selector form: `+(e.toLowerCase()===`gone`||e.toLowerCase()===`disappears`?`wait absent '${r.join(` `)}' [timeoutMs] to wait for zero matches.`:`wait '${r.join(` `)}' [timeoutMs] to wait for it to appear.`):` "${e}" is not a recognized selector key (${v.join(`, `)}).`;return`"${t}" mixes plain word "${e}" with selector-shaped "${r.join(` `)}", so it is neither a valid selector nor safe as literal text.${i} Use wait '<selector>' [timeoutMs] for a selector, or wait text '${t}' [timeoutMs] to wait for the literal text "${t}".`}return`"${t}" looks like a selector key but is not a valid selector expression. Use wait '<selector>' [timeoutMs], e.g. wait '${e[0]}="value"' [timeoutMs], or wait text '${t}' [timeoutMs] to wait for the literal text "${t}".`}function hr(e){let t=ar(e);return t?t.kind===`sleep`?t.durationMs:t.kind===`invalid`?null:t.timeoutMs:null}const gr=3e4,_r=24e4,vr=3e5,N={budget:{source:`none`},envelopeMs:9e4,onTimeout:`reset-daemon`},yr={budget:{source:`none`},envelopeMs:255e3,onTimeout:`reset-daemon`};function br(e,t){if(e.envelopeMs===`unbounded`)return;let n={...e,envelopeMs:e.envelopeMs};return(Sr(n,t.positionals??[])??Cr(n,t.flags)??n.envelopeMs)+xr(e,t.flags)}function xr(e,t){if(e.targetReadiness!==`budgeted`)return 0;let n=t?.readinessTimeoutMs;return typeof n!=`number`||!Number.isInteger(n)||n<=0?0:Math.min(n,2e3)}function Sr(e,t){if(e.budget.source!==`positional-parser`)return;let n=e.budget.parser(t);return n===null?void 0:Er(e,n)}function Cr(e,t){if(e.budget.source===`flag`)return e.budget.envelope===`widen`?Tr(e,e.budget,t):e.budget.envelope===`margin`?wr(e,t):typeof t?.timeoutMs==`number`?t.timeoutMs:e.envelopeMs}function wr(e,t){let n=typeof t?.timeoutMs==`number`?Er(e,t.timeoutMs):e.envelopeMs;return typeof t?.waitMs==`number`?Dr({...e,envelopeMs:n},t.waitMs):n}function Tr(e,t,n){if(n?.settle!==!0)return e.envelopeMs;let r=typeof n.timeoutMs==`number`?n.timeoutMs:t.defaultBudgetMs;return typeof r==`number`?Dr(e,r):e.envelopeMs}function Er(e,t){return Math.max(e.envelopeMs,t+gr)}function Dr(e,t){return Math.max(e.envelopeMs,e.envelopeMs+t+gr)}const Or={click:`settle-and-verify`,press:`settle-and-verify`,fill:`settle-and-verify`,longpress:`settle`,hover:`settle`,scroll:`settle`,back:`settle`};function kr(e){if(e!==void 0)return Or[e]}function P(t){return new e(`COMMAND_FAILED`,t,{reason:`runtime-contract-invalid`,hint:`This is an agent-device runtime contract bug; report the selected device and command.`})}function Ar(e){if(!r(e))throw TypeError(`Unknown local runtime family: ${String(e)}`);return Object.freeze({kind:`local-family`,family:e})}function jr(e,t){let n=e.trim(),r=t.trim();if(n.length===0||r.length===0)throw TypeError(`Provider runtime owner requires non-empty provider and instance identities`);return Object.freeze({kind:`provider-runtime`,provider:n,instance:r})}function Mr(e){let t=e.trim();if(t.length===0)throw TypeError(`Managed local runtime owner requires a non-empty allocator instance identity`);return Object.freeze({kind:`managed-local`,instance:t})}function Nr(e){switch(e.kind){case`local-family`:return`local:${e.family}`;case`managed-local`:return`managed:${JSON.stringify([e.instance])}`;case`provider-runtime`:return`provider:${JSON.stringify([e.provider,e.instance])}`}}function Pr(e,t){return Nr(e)===Nr(t)}function Fr(e,t){return e.available?t():{}}function Ir(e){if(!F(e.requesterId)||!F(e.identityIncarnationId)||!Rr(e.requestGeneration))throw TypeError(`Managed binding fence requires non-empty requester and identity incarnation ids and a non-negative integer request generation`);return Object.freeze({token:JSON.stringify([e.requesterId,e.identityIncarnationId]),generation:e.requestGeneration})}function Lr(e){let t=zr(e.token);if(!t||t.length!==2)return null;let[n,r]=t;if(!F(n)||!F(r)||!Rr(e.generation))return null;let i=Object.freeze({requesterId:n,requestGeneration:e.generation,identityIncarnationId:r});return Ir(i).token===e.token?i:null}function Rr(e){return Number.isInteger(e)&&e>=0}function F(e){return typeof e==`string`&&e.trim().length>0}function zr(e){try{let t=JSON.parse(e);return Array.isArray(t)?t:null}catch{return null}}function Br(e,t){let n={},r={};for(let i of t.required){let t=Vr(e.facts.operations,i);if(n[i]=t,!t.available)throw Kr(i,t);r[i]=Wr(e.operations,i)}for(let i of t.preferred){let t=Vr(e.facts.operations,i);n[i]=t,t.available&&(r[i]=Wr(e.operations,i))}for(let i of t.conditional??[]){let t=Vr(e.facts.operations,i);n[i]=t,t.available&&(r[i]=Wr(e.operations,i))}return Object.freeze({device:e.device,owner:e.owner,facts:Object.freeze(n),operations:Object.freeze(r)})}function Vr(e,t){let n=e[t];if(!Hr(n))throw P(`Runtime owner omitted the ${t} fact`);let r=Ur(n);if(r)return r;throw P(`Runtime owner returned an invalid ${t} fact`)}function Hr(e){return typeof e==`object`&&!!e&&`available`in e}function Ur(e){if(e.available===!0)return Object.freeze({available:!0});if(e.available===!1&&Gr(e.reason)&&(e.hint===void 0||typeof e.hint==`string`))return Object.freeze({available:!1,reason:e.reason,...e.hint===void 0?{}:{hint:e.hint}})}function Wr(e,t){let n=e[t];if(typeof n!=`function`)throw P(`Runtime owner advertised ${t} without an implementation`);return n}function Gr(e){return e===`unsupported-platform-leaf`||e===`unsupported-device-kind`||e===`unsupported-device-backend`||e===`unsupported-device-scope`||e===`unsupported-provider-mode`||e===`owner-capability-missing`}function Kr(t,n){return new e(`UNSUPPORTED_OPERATION`,`Runtime operation ${t} is unavailable`,{reason:n.reason,hint:n.hint})}function qr(e){return JSON.stringify({required:[...e.required].sort(),preferred:[...e.preferred].sort(),conditional:[...e.conditional??[]].sort()})}function Jr(){return e=>{let t=Yr(e.required,`required`),n=Yr(e.preferred??[],`preferred`),r=Yr(e.conditional??[],`conditional`),i=[[`required`,t],[`preferred`,n],[`conditional`,r]];for(let e=0;e<i.length;e+=1){let t=i[e];if(t)for(let n of i.slice(e+1)){let e=n[1].find(e=>t[1].includes(e));if(e!==void 0)throw TypeError(`Runtime operation cannot be both ${t[0]} and ${n[0]}: ${e}`)}}return Object.freeze(r.length===0?{required:t,preferred:n}:{required:t,preferred:n,conditional:r})}}function Yr(e,t){let n=[...e];if(new Set(n).size!==n.length)throw TypeError(`Runtime use contains duplicate ${t} operations`);return Object.freeze(n)}const I=Jr(),Xr=I({required:[`bootTarget`]}),Zr=I({required:[`bootTargetHeadless`]}),Qr=I({required:[`ensureReady`,`listApps`]}),$r=I({required:[`captureSnapshot`]}),ei=I({required:[`setViewport`]}),ti=I({required:[`focusPoint`]}),ni=I({required:[`typeText`]}),ri=I({required:[`back`]}),ii=I({required:[`home`]}),ai=I({required:[`setOrientation`]}),oi=I({required:[`setFoldPose`]}),si=I({required:[`tvRemote`]}),ci=I({required:[`keyboardStatus`]}),li=I({required:[`keyboardDismiss`]}),ui=I({required:[`keyboardEnter`]}),di=I({required:[`appSwitcher`]}),fi=I({required:[`actionButton`]}),pi=I({required:[`triggerAppEvent`]}),mi=I({required:[`setSetting`]}),hi=I({required:[`readSetting`]}),gi=I({required:[`readAlert`]}),_i=I({required:[`awaitAlert`]}),vi=I({required:[`acceptAlert`]}),yi=I({required:[`dismissAlert`]}),bi=I({required:[`readClipboard`]}),xi=I({required:[`writeClipboard`]}),Si=I({required:[`perfFrames`]}),Ci=I({required:[`perfMemorySample`]}),wi=I({required:[`perfMemorySnapshot`]}),Ti=I({required:[`perfNativeCaptureStart`]}),Ei=I({required:[`perfNativeCaptureReattach`,`perfNativeCaptureCleanup`]}),Di=I({required:[`perfProfileReport`]}),Oi=Object.freeze([Si,Ci,wi,Ti,Ei,Di]),L=I({required:[`tapPoint`]}),ki=I({required:[`captureSnapshot`,`tapPoint`],preferred:[`tapRef`],conditional:[`tapElementSelector`]}),Ai=I({required:[`longPressPoint`]}),ji=I({required:[`captureSnapshot`,`longPressPoint`]}),Mi=I({required:[`hoverPoint`]}),R=I({required:[`captureSnapshot`,`hoverPoint`],preferred:[`hoverRef`]}),Ni=I({required:[`fillPoint`]}),Pi=I({required:[`captureSnapshot`,`fillPoint`],preferred:[`fillRef`]}),Fi=Object.freeze([L,ki]),Ii=Fi,Li=Object.freeze([Ai,ji]),Ri=Object.freeze([Mi,R]),zi=Object.freeze([Ni,Pi]);function Bi(e,t){switch(e){case`click`:case`press`:return t?{kind:`captured-tap`,use:ki}:{kind:`tap-point`,use:L};case`fill`:return t?{kind:`captured-fill`,use:Pi}:{kind:`fill-point`,use:Ni};case`longpress`:return t?{kind:`captured-long-press`,use:ji}:{kind:`long-press-point`,use:Ai};case`hover`:return t?{kind:`captured-hover`,use:R}:{kind:`hover-point`,use:Mi}}}const Vi=I({required:[`performGesturePlan`,`captureSnapshot`],preferred:[`gestureViewport`]}),Hi=I({required:[`performDirectionalFlingPlan`,`captureSnapshot`],preferred:[`gestureViewport`]}),Ui=I({required:[`performMultiTouchGesturePlan`,`captureSnapshot`],preferred:[`gestureViewport`]}),Wi=I({required:[`performTargetAuthoredDrag`,`captureSnapshot`],preferred:[`gestureViewport`]}),Gi=I({required:[`gestureViewport`]}),Ki=I({required:[`scrollDirection`],conditional:[`captureSnapshot`]}),qi=I({required:[`scrollDirection`,`captureSnapshot`]}),Ji=Object.freeze({plan:Vi,"directional-fling":Hi,"multi-touch":Ui,"target-authored-drag":Wi}),Yi=Object.freeze([Vi,Hi,Ui,Wi]),Xi=Object.freeze([Vi]),Zi=Object.freeze([Ki,qi]);function Qi(e){return e.intent===`pan`?(`pointerCount`in e?e.pointerCount:1)===2:e.intent===`pinch`||e.intent===`rotate`||e.intent===`transform`}function $i(e){return e.intent===`drag`?`target-authored-drag`:Qi(e)?`multi-touch`:e.intent===`fling`&&`direction`in e?`directional-fling`:`plan`}function ea(e){let t=$i(e);switch(t){case`plan`:return z(t);case`directional-fling`:return z(t);case`multi-touch`:return z(t);case`target-authored-drag`:return z(t)}}function z(e){let t=Ji[e];return Object.freeze({tier:e,operation:t.required[0],use:t})}function ta(e){return e.until===void 0?e.edge===void 0?Object.freeze({kind:`direction`,use:Ki}):Object.freeze({kind:`edge`,edge:e.edge,use:qi}):Object.freeze({kind:`until`,until:e.until,use:qi})}const na=I({required:[`captureSnapshot`,`captureSnapshotWithCustomActions`]}),ra=I({required:[`captureSnapshot`,`captureSnapshotWithoutActiveApp`]}),ia=I({required:[`captureSnapshot`,`captureSnapshotWithCustomActions`,`captureSnapshotWithoutActiveApp`]}),aa=I({required:[`captureSnapshot`]}),oa=I({required:[`captureSnapshot`,`captureSnapshotWithoutActiveApp`]}),sa=I({required:[`captureSnapshot`],preferred:[`readTextAtPoint`]}),ca=I({required:[`captureSnapshot`,`captureSnapshotWithoutActiveApp`],preferred:[`readTextAtPoint`]}),la=I({required:[`captureSnapshot`],conditional:[`findText`]}),ua=I({required:[`captureSnapshot`,`captureSnapshotWithoutActiveApp`],conditional:[`findText`]}),da=Object.freeze([aa,oa]),fa=Object.freeze([sa,ca]),pa=I({required:[`captureSnapshot`,`focusPoint`]}),ma=I({required:[`captureSnapshot`,`captureSnapshotWithoutActiveApp`,`focusPoint`]}),ha=I({required:[`captureSnapshot`,`focusPoint`,`typeText`]}),ga=I({required:[`captureSnapshot`,`captureSnapshotWithoutActiveApp`,`focusPoint`,`typeText`]}),_a=Object.freeze([sa,ca,aa,oa,pa,ma,ha,ga]),va=Object.freeze([la,ua]),ya=Object.freeze([$r,na,ra,ia]),B=Object.freeze({"capture-only":da,"element-text":fa,"wait-observation":va,"find-focus":Object.freeze([pa,ma]),"find-type":Object.freeze([ha,ga])});function ba(e){return e===`focus`?`find-focus`:e===`type`?`find-type`:`capture-only`}function xa(e){switch(e.intent){case`capture-only`:return V(e.hasActiveApp,e.intent,B[e.intent]);case`element-text`:return V(e.hasActiveApp,e.intent,B[e.intent]);case`wait-observation`:return V(e.hasActiveApp,e.intent,B[e.intent]);case`find-focus`:return V(e.hasActiveApp,e.intent,B[e.intent]);case`find-type`:return V(e.hasActiveApp,e.intent,B[e.intent])}}function V(e,t,n){return Object.freeze(e?{kind:`selector-active-app`,intent:t,operation:`captureSnapshot`,use:n[0]}:{kind:`selector-without-active-app`,intent:t,operation:`captureSnapshotWithoutActiveApp`,use:n[1]})}function Sa(e){return e.customActions?e.hasActiveApp?Object.freeze({kind:`custom-actions-active-app`,operation:`captureSnapshotWithCustomActions`,use:na}):Object.freeze({kind:`custom-actions-without-active-app`,operation:`captureSnapshotWithCustomActions`,use:ia}):e.hasActiveApp?Object.freeze({kind:`active-app`,operation:`captureSnapshot`,use:$r}):Object.freeze({kind:`without-active-app`,operation:`captureSnapshotWithoutActiveApp`,use:ra})}const Ca=I({required:[`captureScreenshot`]}),wa=I({required:[`captureScreenshot`,`captureSnapshot`]}),Ta=Object.freeze([Ca,wa]);function Ea(e){return e.cropOn?Object.freeze({kind:`capture-with-crop-on`,use:wa}):e.overlayRefs?Object.freeze({kind:`capture-with-overlay-refs`,use:wa}):Object.freeze({kind:`capture`,use:Ca})}const Da=Object.freeze([Xr,Zr]),Oa=Object.freeze({kind:`boot-target`,operation:`bootTarget`,use:Xr}),ka=Object.freeze({kind:`boot-target-headless`,operation:`bootTargetHeadless`,use:Zr});function Aa(e){return e.headless?ka:Oa}const ja=I({required:[`ensureReady`,`appState`]}),Ma=Object.freeze([ja]),Na=I({required:[`shutdownTarget`]}),Pa=Object.freeze([bi,xi]),Fa=Object.freeze([mi,hi]),Ia=[`text-size`],La=Object.freeze({kind:`write`,use:mi});function Ra(e){let t=za(e?.[0]);return e?.length!==1||t===void 0?La:Ia.includes(t)?Object.freeze({kind:`read`,setting:t,use:hi}):La}function za(e){let t=e?.trim().toLowerCase();return Ia.find(e=>e===t)}const Ba=Object.freeze([gi,_i,vi,yi]),Va=Object.freeze([ci,li,ui]),Ha=I({required:[`deployApp`]}),Ua=I({required:[`ensureReady`,`materializeAppSource`,`deployMaterializedApp`]}),Wa=I({required:[`ensureReady`,`sendPushNotification`]}),Ga=I({required:[`resolveOpenTarget`,`prepareApplicationOpen`,`openApplication`]}),Ka=I({required:[`resolveOpenTarget`,`prepareApplicationOpen`,`openApplication`,`applyRuntimeHints`]}),qa=I({required:[`resolveOpenTarget`,`prepareApplicationOpen`,`openApplication`,`clearRuntimeHints`]}),Ja=I({required:[`resolveOpenTarget`,`prepareApplicationOpen`,`openApplication`,`applyRuntimeHints`,`clearRuntimeHints`]});function Ya(e){return e.applyRuntimeHints&&e.clearRemovedRuntimeHints?Object.freeze({kind:`open-apply-and-clear-runtime-hints`,use:Ja}):e.applyRuntimeHints?Object.freeze({kind:`open-apply-runtime-hints`,use:Ka}):e.clearRemovedRuntimeHints?Object.freeze({kind:`open-clear-runtime-hints`,use:qa}):Object.freeze({kind:`open`,use:Ga})}const Xa=Object.freeze([Ga,Ka,qa,Ja]),Za=I({required:[`closeApplication`,`finalizeApplicationClose`]}),Qa=I({required:[`closeApplication`,`finalizeApplicationClose`,`clearRuntimeHints`]}),$a=Object.freeze([Za,Qa]),eo=I({required:[`finalizeApplicationClose`]}),to=I({required:[`finalizeApplicationClose`,`clearRuntimeHints`]}),no=I({required:[`prepareAppleRunner`]}),ro=I({required:[`clearRuntimeHints`]}),io=I({required:[`configureProviderPortReverse`]}),ao=Object.freeze([ro,io]),H=I({required:[`appLogInspect`]}),oo=I({required:[`appLogInspect`,`appLogDoctor`]}),so=I({required:[`appLogInspect`,`appLogStart`]}),co=I({required:[],preferred:[`appLogInspect`]}),lo=Object.freeze([H,oo,so]);function uo(t){let n=(t.action??`path`).toLowerCase();if(t.restart&&n!==`clear`)throw new e(`INVALID_ARGS`,`logs --restart is only supported with logs clear`);switch(n){case`path`:return Object.freeze({kind:`path`,requiresAppSession:!1,use:H});case`start`:return Object.freeze({kind:`start`,requiresAppSession:!0,use:so});case`stop`:return Object.freeze({kind:`stop`,requiresAppSession:!1,use:H});case`doctor`:return Object.freeze({kind:`doctor`,requiresAppSession:!1,use:oo});case`mark`:return Object.freeze({kind:`mark`,marker:t.marker??``,requiresAppSession:!1,use:H});case`clear`:return t.restart?Object.freeze({kind:`clear-restart`,requiresAppSession:!0,use:so}):Object.freeze({kind:`clear`,requiresAppSession:!1,use:H});default:throw new e(`INVALID_ARGS`,`logs requires path, start, stop, doctor, mark, or clear`)}}const fo=I({required:[`audioProbeStart`]}),po=I({required:[`audioProbeReattach`,`audioProbeCleanup`]}),mo=I({required:[`audioProbeQuery`]}),ho=Object.freeze([fo,po,mo]);function go(e){if(e.mode===`query`)return Object.freeze({kind:`query`,action:e.probeAction,use:mo});switch(e.probeAction){case`start`:return Object.freeze({kind:`capture-start`,use:fo});case`status`:return Object.freeze({kind:`capture-status`});case`stop`:return Object.freeze({kind:`capture-stop`})}}const _o=[`probe`],vo=[`start`,`status`,`stop`];function yo(t){let n=(t?.[0]??`probe`).toLowerCase();if(!_o.includes(n))throw new e(`INVALID_ARGS`,`audio requires probe`);let r=(t?.[1]??`status`).toLowerCase();if(!vo.includes(r))throw new e(`INVALID_ARGS`,`audio probe requires ${vo.join(`, `)}`);if(r!==`start`&&t&&t.length>2)throw new e(`INVALID_ARGS`,`audio probe duration and bucket are only supported with audio probe start`);return Object.freeze({probeAction:r,durationMs:bo(t?.[2],{defaultValue:1e4,min:100,max:12e4,message:`audio probe duration must be an integer in range 100..120000 ms`}),bucketMs:bo(t?.[3],{defaultValue:1e3,min:100,max:1e4,message:`audio probe bucket must be an integer in range 100..10000 ms`})})}function bo(t,n){if(t===void 0)return n.defaultValue;let r=Number.parseInt(t,10);if(!Number.isInteger(r)||String(r)!==t||r<n.min||r>n.max)throw new e(`INVALID_ARGS`,n.message);return r}const xo=I({required:[`networkDump`]}),So=I({required:[],preferred:[`networkDump`]}),Co=[`dump`,`log`],wo=[`summary`,`headers`,`body`,`all`];function To(t){let n=(t.action??`dump`).toLowerCase(),r=(t.include??`summary`).toLowerCase();if(!Eo(n))throw new e(`INVALID_ARGS`,`network requires dump or log`);if(!Do(r))throw new e(`INVALID_ARGS`,`network --include must be summary, headers, body, or all`);return Object.freeze({action:n,include:r,use:xo})}function Eo(e){return Co.some(t=>t===e)}function Do(e){return wo.some(t=>t===e)}function Oo(e){let t=new Map;for(let n of e){if(!r(n.family))throw TypeError(`Unknown platform family registration: ${String(n.family)}`);if(t.has(n.family))throw TypeError(`Duplicate platform family registration: ${n.family}`);t.set(n.family,ko(n))}let n=i.filter(e=>!t.has(e));if(n.length>0)throw TypeError(`Missing platform family registrations: ${n.join(`, `)}`);let a=Object.freeze([...i]),o=Object.freeze(a.map(e=>Ao(t,e)));return Object.freeze({families:a,modules:o,get:e=>Ao(t,e)})}function ko(e){return Object.freeze({...e})}function Ao(e,t){let n=e.get(t);if(!n)throw TypeError(`Missing platform family registration: ${t}`);return n}const jo=Object.freeze({kind:`device-inventory`});function Mo(e){if(typeof e!=`object`||!e)throw zo();let t=e,n=Object.keys(t).sort();if(!(t.kind===`none`&&U(n,[`kind`]))&&!(t.kind===`host`&&U(n,[`kind`]))&&!(t.kind===`inventory`&&U(n,[`kind`,`use`])&&Po(t.use))&&!(t.kind===`device-runtime`&&U(n,[`kind`,`use`])&&Fo(t.use))&&!(t.kind===`device-runtime`&&(U(n,[`kind`,`uses`])||U(n,[`kind`,`selectUses`,`uses`])&&typeof t.selectUses==`function`)&&No(t.uses)))throw zo()}function No(e){if(!Array.isArray(e)||e.length===0||!e.every(Fo))return!1;let t=e.map(qr);return new Set(t).size===t.length}function Po(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.kind===`device-inventory`&&U(Object.keys(t).sort(),[`kind`])}function Fo(e){if(typeof e!=`object`||!e)return!1;let t=e,n=[Lo(t.required),Lo(t.preferred),Lo(t.conditional??[])];if(!Io(n))return!1;let r=n.flat();return new Set(r).size===r.length&&U(Object.keys(t).sort(),t.conditional===void 0?[`preferred`,`required`]:[`conditional`,`preferred`,`required`])}function Io(e){return e.every(e=>e!==null&&Ro(e))}function Lo(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)?e:null}function Ro(e){return new Set(e).size===e.length}function U(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function zo(){return TypeError(`Command platform execution must declare exactly one of none, host, inventory, or device-runtime`)}const Bo=I({required:[`screenRecordingStart`]}),Vo=I({required:[`screenRecordingReattach`,`screenRecordingCleanup`]}),Ho=I({required:[]}),Uo=I({required:[],preferred:[`screenRecordingStart`]}),Wo=Object.freeze([Bo,Vo]);function Go(t){switch((t.action??``).toLowerCase()){case`start`:if(!Ko(t.scope??`app`))throw new e(`INVALID_ARGS`,`record scope must be app, device, or system`);return Object.freeze({kind:`start`,use:Bo});case`stop`:return t.hasLiveHandle===!0?Object.freeze({kind:`stop-live`,use:Ho}):Object.freeze({kind:`stop-recovery`,use:Vo});default:throw new e(`INVALID_ARGS`,`record requires start or stop`)}}function Ko(e){return e===`app`||e===`device`||e===`system`}function qo(e){if(Mo(e),e.kind!==`device-runtime`||!(`uses`in e))throw Jo();let t=e.uses.map(qr),n=Wo.map(qr),r=new Set(t),i=new Set(n);if(t.length!==n.length||r.size!==t.length||[...r].some(e=>!i.has(e)))throw Jo()}function Jo(){return TypeError(`Record runtime execution must declare exactly the uses selected by its two runtime-bearing plans`)}function Yo(e){let t=e.platformExecution;if(t===void 0)throw TypeError(`Command descriptor "${e.name}" must declare platformExecution (none, host, inventory, or device-runtime); there is no registry-entry default`);return Mo(t),t}const W={leaseAdmissionExempt:!0,sessionExecutionLockExempt:!0},G={leaseAdmissionExempt:!0,sessionExecutionLockExempt:!0,selectorValidationExempt:!0},Xo=()=>!0,Zo=e=>(e.positionals?.[0]??``).toLowerCase()===`start`,Qo=e=>e.command===`test`&&(typeof e.flags?.shardAll==`number`||typeof e.flags?.shardSplit==`number`),$o=e=>(e.positionals?.length??0)===0?{kind:`unconditional`}:void 0,es=e=>{let t=e.flags?.leaseProvider;return e.flags?.leaseId===void 0&&typeof t==`string`&&(e.flags?.platform===`android`||e.flags?.platform===`ios`)?{kind:`provider-app-catalog`,provider:t}:void 0},ts=new Set([`status`,`get`]),ns=e=>fs(e,ts,`status`),rs=new Set([`get`,`wait`]),is=e=>fs(e,rs,`get`),as=e=>ps(e,ts,`status`),os=e=>ps(e,rs,`get`),ss=e=>{try{return O(_n(e.positionals??[]).action)?`observes-app`:`mutates-app`}catch{return`mutates-app`}},cs=e=>ps(e,new Set([`read`]),``),ls=e=>Ra(e.positionals).kind===`read`,us=e=>ls(e)?`observes-app`:`mutates-app`,ds=e=>ls(e)?`preserve`:`may-invalidate`;function fs(e,t,n){return t.has((e.positionals?.[0]??n).toLowerCase())?`preserve`:`may-invalidate`}function ps(e,t,n){return t.has((e.positionals?.[0]??n).toLowerCase())?`observes-app`:`mutates-app`}const K={kind:`none`},ms={kind:`host`},q={recordsSessionAction:!0,recordingEffect:`mutates-app`,deviceClaimPolicy:`require-owner`,daemon:{route:`generic`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},timeoutPolicy:N,batchable:!0},J={targetIdentityVerification:`pre-dispatch`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,deviceClaimPolicy:`require-owner`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0}},Y={...N,onTimeout:`preserve-daemon`},hs={...N,envelopeMs:18e4},gs={...N,onTimeout:`preserve-daemon`},_s={...gs,envelopeMs:33e4},vs={...N,budget:{source:`flag`,envelope:`widen`,defaultBudgetMs:1e4},onTimeout:`preserve-daemon`},ys={fields:{count:{defaultValue:1,omitDefault:!0},intervalMs:{defaultValue:0,omitDefault:!0},holdMs:{defaultValue:0,omitDefault:!0},jitterPx:{defaultValue:0,omitDefault:!0},doubleTap:{defaultValue:!1,omitDefault:!0}}},bs={fields:{delayMs:{defaultValue:0}}};function X(e,t){return kr(e)===void 0?t:vs}function Z(e){let t=kr(e);if(t===void 0)throw Error(`Missing post-action observation descriptor support for ${e}`);return t}const xs={deviceClaimPolicy:`transient-exclusive`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`},platformExecution:{kind:`device-runtime`,use:Ha},timeoutPolicy:hs,batchable:!0},Ss=e=>{let t=e.flags?.snapshotCustomActions===!0||e.input?.customActions===!0;return[!0,!1].map(e=>Sa({customActions:t,hasActiveApp:e}).use)},Cs=e=>{let t=Ts(e);if(t===void 0||!ws(t))return _a;let n=ba(t);return[!0,!1].map(e=>xa({hasActiveApp:e,intent:n}).use)};function ws(e){return O(e)||e===`focus`||e===`type`}function Ts(e){if(e.positionals===void 0)return;let t=mn(e.positionals,e.flags);return t.ok?t.parsed.action:void 0}const Es=[{name:`human_control`,deviceClaimPolicy:`none`,catalog:{group:`internal`,key:`humanControl`},recordsSessionAction:!1,daemon:{route:`humanControl`,refFrameEffect:`preserve`,selectorValidationExempt:!0,skipSessionlessProviderDevice:Xo},timeoutPolicy:N,batchable:!1,platformExecution:K},{name:`lease_allocate`,deviceClaimPolicy:`none`,catalog:{group:`internal`,key:`leaseAllocate`},recordsSessionAction:!1,daemon:{route:`lease`,refFrameEffect:`preserve`,...W},timeoutPolicy:_s,batchable:!1,platformExecution:K},{name:`lease_heartbeat`,deviceClaimPolicy:`none`,catalog:{group:`internal`,key:`leaseHeartbeat`},recordsSessionAction:!1,daemon:{route:`lease`,refFrameEffect:`preserve`,...W,appLease:`allowed`},timeoutPolicy:gs,batchable:!1,platformExecution:K},{name:`lease_release`,deviceClaimPolicy:`none`,catalog:{group:`internal`,key:`leaseRelease`},recordsSessionAction:!1,daemon:{route:`lease`,refFrameEffect:`preserve`,...W,appLease:`allowed`},timeoutPolicy:gs,batchable:!1,platformExecution:K},{name:`artifacts`,deviceClaimPolicy:`none`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`lease`,refFrameEffect:`preserve`,...W},timeoutPolicy:N,batchable:!1,platformExecution:K},{name:`session_list`,deviceClaimPolicy:`none`,catalog:{group:`internal`,key:`sessionList`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,...G},timeoutPolicy:N,batchable:!1,platformExecution:K},{name:`session_save_script`,deviceClaimPolicy:`none`,catalog:{group:`internal`,key:`sessionSaveScript`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`publication`},timeoutPolicy:N,batchable:!1,platformExecution:K},{name:`devices`,deviceClaimPolicy:`observe`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,lockPolicySelectorOverride:!0,...G},timeoutPolicy:N,batchable:!0,platformExecution:{kind:`inventory`,use:jo}},{name:`capabilities`,deviceClaimPolicy:`observe`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,lockPolicySelectorOverride:!0,preferExplicitDeviceOverExistingSession:!0,...G},timeoutPolicy:N,batchable:!0,platformExecution:K},{name:`doctor`,deviceClaimPolicy:`observe`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,lockPolicySelectorOverride:!0,allowSessionlessDefaultDevice:Xo,...G},timeoutPolicy:N,batchable:!0,platformExecution:ms},{name:`apps`,deviceClaimPolicy:`observe`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,lockPolicySelectorOverride:!0,preferExplicitDeviceOverExistingSession:!0,sessionlessLeaseAdmissionExemption:es},platformExecution:{kind:`device-runtime`,uses:[Qr]},timeoutPolicy:N,batchable:!0},{name:`boot`,deviceClaimPolicy:`transient-exclusive`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`may-invalidate`,sessionKind:`state`},platformExecution:{kind:`device-runtime`,uses:Da},timeoutPolicy:{...N,budget:{source:`flag`,envelope:`margin`}},batchable:!0},{name:`shutdown`,deviceClaimPolicy:`transient-exclusive`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`may-invalidate`,sessionKind:`state`},platformExecution:{kind:`device-runtime`,use:Na},timeoutPolicy:N,batchable:!0},{name:`appstate`,deviceClaimPolicy:`observe`,catalog:{group:`public`,key:`appState`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`state`},platformExecution:{kind:`device-runtime`,uses:Ma},timeoutPolicy:N,batchable:!0},{name:`perf`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`},timeoutPolicy:N,batchable:!0,platformExecution:{kind:`device-runtime`,uses:Oi}},{name:`logs`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`},platformExecution:{kind:`device-runtime`,uses:lo},timeoutPolicy:N,batchable:!0},{name:`events`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`,allowInvalidRecording:!0,...G},timeoutPolicy:N,batchable:!1,platformExecution:K},{name:`network`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`},platformExecution:{kind:`device-runtime`,use:xo},timeoutPolicy:N,batchable:!0},{name:`audio`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`},timeoutPolicy:N,batchable:!0,platformExecution:{kind:`device-runtime`,uses:ho}},{name:`replay`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`delegated`,sessionKind:`replay`,skipSessionlessProviderDevice:Qo,saveScriptFlagOwner:!0},timeoutPolicy:{...N,budget:{source:`flag`}},batchable:!1,platformExecution:K},{name:`test`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`delegated`,sessionKind:`replay`,skipSessionlessProviderDevice:Qo},timeoutPolicy:{...N,envelopeMs:`unbounded`},batchable:!0,platformExecution:K},{name:`runtime`,deviceClaimPolicy:`require-owner`,catalog:{group:`internal`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`},timeoutPolicy:N,batchable:!1,platformExecution:{kind:`device-runtime`,uses:[...ao,Gi]}},{name:`clipboard`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:cs,daemon:{route:`session`,refFrameEffect:`preserve`},timeoutPolicy:N,batchable:!0,platformExecution:{kind:`device-runtime`,uses:Pa}},{name:`keyboard`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:as,daemon:{route:`session`,refFrameEffect:ns,androidBlockingDialogGuard:!0},timeoutPolicy:N,batchable:!0,platformExecution:{kind:`device-runtime`,uses:Va}},{name:`install`,...xs},{name:`reinstall`,...xs},{name:`install_source`,deviceClaimPolicy:`transient-exclusive`,catalog:{group:`internal`,key:`installSource`,servesPublicCommand:`install-from-source`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`},platformExecution:{kind:`device-runtime`,use:Ua},timeoutPolicy:hs,batchable:!1},{name:`release_materialized_paths`,deviceClaimPolicy:`none`,catalog:{group:`internal`,key:`releaseMaterializedPaths`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,...G},timeoutPolicy:N,batchable:!1,platformExecution:K},{name:`push`,deviceClaimPolicy:`transient-exclusive`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`},platformExecution:{kind:`device-runtime`,use:Wa},timeoutPolicy:N,batchable:!0},{name:`trigger-app-event`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`,key:`triggerAppEvent`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`},timeoutPolicy:N,batchable:!0,platformExecution:{kind:`device-runtime`,uses:[pi]}},{name:`open`,deviceClaimPolicy:`acquire-session`,catalog:{group:`public`},frameworkTier:`core`,recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`,allowSessionlessDefaultDevice:Xo,saveScriptFlagOwner:!0,appLease:`allowed`},timeoutPolicy:{...N,budget:{source:`flag`,envelope:`margin`}},batchable:!0,platformExecution:{kind:`device-runtime`,uses:Xa}},{name:`prepare`,deviceClaimPolicy:`transient-exclusive`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`},timeoutPolicy:{budget:{source:`flag`,envelope:`margin`},envelopeMs:27e4,onTimeout:`reset-daemon`},batchable:!1,mcpExposed:!1,platformExecution:{kind:`device-runtime`,use:no}},{name:`batch`,deviceClaimPolicy:`none`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`delegated`,appLease:`allowed`},timeoutPolicy:N,batchable:!1,platformExecution:K},{name:`close`,deviceClaimPolicy:`release-session`,catalog:{group:`public`},frameworkTier:`core`,recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`,allowInvalidRecording:!0,saveScriptFlagOwner:!0,sessionlessLeaseAdmissionExemption:$o,appLease:`allowed`},timeoutPolicy:N,batchable:!0,platformExecution:{kind:`device-runtime`,uses:$a}},{name:`snapshot`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`core`,recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`snapshot`,refFrameEffect:`preserve`,appLease:`allowed`},timeoutPolicy:{...Y,budget:{source:`flag`}},batchable:!0,platformExecution:{kind:`device-runtime`,uses:ya,selectUses:Ss}},{name:`diff`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`snapshot`,refFrameEffect:`preserve`},timeoutPolicy:N,batchable:!0,platformExecution:{kind:`device-runtime`,uses:ya,selectUses:Ss}},{name:`wait`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`core`,recordsSessionAction:!0,recordingEffect:`observes-app`,targetIdentityVerification:`post-resolution`,daemon:{route:`snapshot`,refFrameEffect:`preserve`,appLease:`allowed`},timeoutPolicy:{...Y,budget:{source:`positional-parser`,parser:hr}},batchable:!0,platformExecution:{kind:`device-runtime`,uses:va}},{name:`alert`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`core`,recordsSessionAction:!0,recordingEffect:os,daemon:{route:`snapshot`,refFrameEffect:is},timeoutPolicy:N,batchable:!0,platformExecution:{kind:`device-runtime`,uses:Ba}},{name:`settings`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:us,daemon:{route:`snapshot`,refFrameEffect:ds},timeoutPolicy:N,batchable:!0,platformExecution:{kind:`device-runtime`,uses:Fa}},{name:`react-native`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`,key:`reactNative`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`reactNative`,refFrameEffect:`may-invalidate`},timeoutPolicy:N,batchable:!0,platformExecution:{kind:`device-runtime`,uses:[L]}},{name:`record`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`recordTrace`,refFrameEffect:`preserve`,allowInvalidRecording:!0,allowSessionlessDefaultDevice:Zo},platformExecution:{kind:`device-runtime`,uses:Wo},timeoutPolicy:Y,batchable:!0},{name:`trace`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`recordTrace`,refFrameEffect:`preserve`},timeoutPolicy:N,batchable:!0,platformExecution:K},{name:`find`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`core`,recordsSessionAction:!0,recordingEffect:ss,daemon:{route:`find`,refFrameEffect:`may-invalidate`,appLease:`allowed`},timeoutPolicy:Y,batchable:!0,platformExecution:{kind:`device-runtime`,uses:_a,selectUses:Cs}},{name:`click`,deviceClaimPolicy:`require-owner`,targetIdentityVerification:`pre-dispatch`,catalog:{group:`public`},frameworkTier:`core`,recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0,appLease:`allowed`},timeoutPolicy:X(`click`,Y),postActionObservation:Z(`click`),targetReadiness:`budgeted`,responseDataTransform:ys,batchable:!0,platformExecution:{kind:`device-runtime`,uses:Fi}},{name:`fill`,...J,daemon:{...J.daemon,appLease:`allowed`},frameworkTier:`core`,timeoutPolicy:X(`fill`,Y),postActionObservation:Z(`fill`),responseDataTransform:bs,batchable:!0,platformExecution:{kind:`device-runtime`,uses:zi}},{name:`longpress`,...J,catalog:{group:`public`,key:`longPress`},frameworkTier:`extended`,timeoutPolicy:{...vs,envelopeMs:21e4},postActionObservation:Z(`longpress`),targetReadiness:`budgeted`,batchable:!0,platformExecution:{kind:`device-runtime`,uses:Li}},{name:`hover`,deviceClaimPolicy:`require-owner`,targetIdentityVerification:`pre-dispatch`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`},timeoutPolicy:X(`hover`,Y),postActionObservation:Z(`hover`),batchable:!0,platformExecution:{kind:`device-runtime`,uses:Ri}},{name:`press`,...J,daemon:{...J.daemon,appLease:`allowed`},frameworkTier:`core`,timeoutPolicy:X(`press`,Y),postActionObservation:Z(`press`),targetReadiness:`budgeted`,responseDataTransform:ys,batchable:!0,platformExecution:{kind:`device-runtime`,uses:Ii}},{name:`type`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`core`,recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0,appLease:`allowed`},timeoutPolicy:X(`type`,Y),batchable:!0,platformExecution:{kind:`device-runtime`,uses:[ni]}},{name:`get`,deviceClaimPolicy:`require-owner`,targetIdentityVerification:`pre-dispatch`,catalog:{group:`public`},frameworkTier:`core`,recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`interaction`,refFrameEffect:`preserve`,appLease:`allowed`},timeoutPolicy:X(`get`,Y),batchable:!0,platformExecution:{kind:`device-runtime`,uses:fa}},{name:`is`,deviceClaimPolicy:`require-owner`,targetIdentityVerification:`pre-dispatch`,catalog:{group:`public`},frameworkTier:`core`,recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`interaction`,refFrameEffect:`preserve`,appLease:`allowed`},timeoutPolicy:X(`is`,Y),batchable:!0,platformExecution:{kind:`device-runtime`,uses:da}},{name:`back`,catalog:{group:`public`},frameworkTier:`core`,...q,timeoutPolicy:X(`back`,N),postActionObservation:Z(`back`),platformExecution:{kind:`device-runtime`,uses:[ri]}},{name:`gesture`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`mutates-app`,targetIdentityVerification:`pre-dispatch`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},timeoutPolicy:N,batchable:!0,platformExecution:{kind:`device-runtime`,uses:Yi}},{name:`home`,catalog:{group:`public`},frameworkTier:`extended`,...q,platformExecution:{kind:`device-runtime`,uses:[ii]}},{name:`tv-remote`,catalog:{group:`public`,key:`tvRemote`},frameworkTier:`extended`,...q,platformExecution:{kind:`device-runtime`,uses:[si]}},{name:`orientation`,catalog:{group:`public`},frameworkTier:`extended`,...q,platformExecution:{kind:`device-runtime`,uses:[ai]}},{name:`fold`,catalog:{group:`public`},frameworkTier:`extended`,...q,timeoutPolicy:yr,platformExecution:{kind:`device-runtime`,uses:[oi]}},{name:`scroll`,catalog:{group:`public`},frameworkTier:`core`,...q,daemon:{...q.daemon,appLease:`allowed`},timeoutPolicy:X(`scroll`,N),postActionObservation:Z(`scroll`),platformExecution:{kind:`device-runtime`,uses:Zi}},{name:`swipe`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`core`,recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},timeoutPolicy:N,batchable:!0,platformExecution:{kind:`device-runtime`,uses:Xi}},{name:`focus`,catalog:{group:`public`},frameworkTier:`extended`,...q,daemon:{...q.daemon,appLease:`allowed`},platformExecution:{kind:`device-runtime`,uses:[ti]}},{name:`screenshot`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`core`,recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`generic`,refFrameEffect:`preserve`,appLease:`allowed`},timeoutPolicy:N,batchable:!0,platformExecution:{kind:`device-runtime`,uses:Ta}},{name:`viewport`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`generic`,refFrameEffect:`may-invalidate`},timeoutPolicy:N,batchable:!1,platformExecution:{kind:`device-runtime`,uses:[ei]}},{name:`app-switcher`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`,key:`appSwitcher`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`generic`,refFrameEffect:`may-invalidate`},timeoutPolicy:N,batchable:!0,platformExecution:{kind:`device-runtime`,uses:[di]}},{name:`action-button`,catalog:{group:`public`,key:`actionButton`},frameworkTier:`extended`,...q,platformExecution:{kind:`device-runtime`,uses:[fi]}},{name:`install-from-source`,deviceClaimPolicy:`none`,catalog:{group:`public`,key:`installFromSource`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`mutates-app`,platformExecution:{kind:`device-runtime`,use:Ua},timeoutPolicy:N,batchable:!0},{name:`debug`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,platformExecution:K},{name:`daemon`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,mcpExposed:!1,platformExecution:ms},{name:`device`,deviceClaimPolicy:`observe`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,mcpExposed:!1,platformExecution:K},{name:`metro`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,platformExecution:K},{name:`session`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,platformExecution:K},{name:`cdp`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,mcpExposed:!1,platformExecution:K},{name:`auth`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,mcpExposed:!1,platformExecution:K},{name:`plugins`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,mcpExposed:!1,platformExecution:K},{name:`connect`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,mcpExposed:!1,platformExecution:K},{name:`connection`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,mcpExposed:!1,platformExecution:K},{name:`disconnect`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,mcpExposed:!1,platformExecution:K},{name:`mcp`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,mcpExposed:!1,platformExecution:K},{name:`proxy`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,mcpExposed:!1,platformExecution:K},{name:`takeover`,deviceClaimPolicy:`observe`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,mcpExposed:!1,platformExecution:{kind:`inventory`,use:jo}},{name:`react-devtools`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`,key:`reactDevtools`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,mcpExposed:!1,platformExecution:K},{name:`web`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:N,batchable:!1,mcpExposed:!1,platformExecution:ms}],Ds=new Set([`public`,`local-cli`]),Os=new Set(Es.filter(e=>Ds.has(Is(e))).map(e=>e.name)),Q=Es.map(e=>{let t=Yo(e);return e.name===`record`&&qo(t),{...e,mcpExposed:Ps(e),platformExecution:t}});function ks(e){return Q.filter(t=>Is(t)===e).map(e=>[Ls(e),e.name])}function As(){return Q.filter(e=>Fs(e)).map(e=>e.name).sort()}function js(e){let t=Q.find(t=>t.name===e)?.platformExecution;if(t?.kind===`device-runtime`)return(`uses`in t?t.uses:[t.use]).map(e=>e.required)}function Ms(){return Q.filter(e=>e.catalog.group===`public`&&e.platformExecution.kind===`device-runtime`).map(e=>e.name).sort()}const $=new Map(Q.map(e=>[e.name,e]));function Ns(e){return Os.has(e)}function Ps(e){return e.mcpExposed??Os.has(e.name)}function Fs(e){return e.mcpExposed&&Ns(e.name)}function Is(e){return e.catalog.group}function Ls(e){return e.catalog.key??e.name}const Rs=new Map(Array.from($.values(),e=>[e.name,e.targetReadiness?{...e.timeoutPolicy,targetReadiness:e.targetReadiness}:e.timeoutPolicy])),zs=new Map(Q.map(e=>[e.name,e.deviceClaimPolicy])),Bs=new Map(Array.from($.values()).flatMap(e=>e.responseDataTransform?[[e.name,e.responseDataTransform]]:[]));function Vs(e){if(e!==void 0)return $.get(e)?.postActionObservation}function Hs(e){return Vs(e)!==void 0}function Us(e){return e!==void 0&&$.get(e)?.targetReadiness===`budgeted`}function Ws(e){return Vs(e)===`settle-and-verify`}function Gs(e){return e===void 0?N:Rs.get(e)??N}function Ks(e){return e===void 0?`require-owner`:zs.get(e)??`require-owner`}function qs(e){if(e!==void 0)return Bs.get(e)}function Js(e){return e===void 0?!1:$.get(e)?.recordsSessionAction??!1}function Ys(e){if(e!==void 0)return $.get(e)?.frameworkTier}function Xs(e){return $.get(e)?.targetIdentityVerification}function Zs(e){let t=$.get(e.command);if(t?.recordsSessionAction)return typeof t.recordingEffect==`function`?t.recordingEffect(e):t.recordingEffect}function Qs(){return[...new Set(Array.from(Bs.values()).flatMap(e=>Object.keys(e.fields)))].sort()}const $s={apps:{appsFilter:`user-installed`}};function ec(e,t){if(!e||!Ns(e))return!1;let n=$s[e];if(!n)return!1;let r=!1;for(let e of Object.keys(n))t[e]===void 0&&(t[e]=n[e],r=!0);return r}function tc(e){let t=[];for(let n of e)n.daemon&&t.push({command:n.name,...n.daemon,replayScopedAction:n.recordsSessionAction});return t}function nc(e){return e.filter(e=>e.batchable).map(e=>e.name)}const rc=nc(Q),ic=new Set([`batch`,`replay`]),ac=[`command`,`positionals`,`input`,`flags`,`runtime`],oc=[`platform`,`target`,`device`,`udid`,`serial`,`verbose`,`out`,`testIme`],sc=`Session, daemon, connection, and host tooling commands are excluded from batch — they own lifecycle a batch cannot carry — and batch and replay never nest. Run an excluded command on its own; every other device command is available as a step.`,cc=new Set(rc);function lc(e){return cc.has(e)}function uc(e){return typeof e==`string`?e.trim().toLowerCase():``}function dc(e){let t=uc(e);return lc(t)?t:void 0}function fc(t,n,r=sc){let i=dc(t);if(i!==void 0)return i;throw new e(`INVALID_ARGS`,`Batch step ${n} command is not available through command batch: ${String(t)}`,{hint:r})}function pc(t,n){if(ic.has(t))throw new e(`INVALID_ARGS`,`Batch step ${n} cannot run ${t}.`)}export{fi as $,Dt as $n,ne as $r,jr as $t,Oo as A,an as An,Oe as Ar,wi as At,Qa as B,D as Bn,he as Br,Sa as Bt,Js as C,On as Cn,S as Cr,li as Ct,Go as D,Tn as Dn,xe as Dr,ai as Dt,Xs as E,En,g as Er,Ai as Et,go as F,O as Fn,ve as Fr,ea as Ft,Ja as G,Ut as Gn,le as Gr,L as Gt,eo as H,Gt as Hn,de as Hr,hi as Ht,co as I,sn as In,ye as Ir,Ea as It,no as J,Ht as Jn,ae as Jr,ei as Jt,Ka as K,Zt as Kn,ce as Kr,si as Kt,uo as L,_n as Ln,p as Lr,ta as Lt,To as M,pn as Mn,we as Mr,Ti as Mt,po as N,mn as Nn,m as Nr,Di as Nt,Uo as O,wn as On,De as Or,Si as Ot,yo as P,cn as Pn,_e as Pr,Aa as Pt,Wa as Q,ht as Qn,ee as Qr,Br as Qt,ro as R,yn as Rn,me as Rr,xa as Rt,Zs as S,zn as Sn,y as Sr,Mi as St,Gs as T,An as Tn,ke as Tr,ci as Tt,to as U,tn as Un,ue as Ur,mi as Ut,io as V,Yt as Vn,fe as Vr,Bi as Vt,Ga as W,Qt as Wn,pe as Wr,Na as Wt,Ha as X,Kt as Xn,oe as Xr,Ar as Xt,Ya as Y,qt as Yn,l as Yr,Lr as Yt,Ua as Z,Jt as Zn,f as Zr,Mr as Zt,ks as _,Gn as _n,Ze as _r,ba as _t,pc as a,_r as an,C as ar,ja as at,Ks as b,Wn as bn,Pe as br,Gi as bt,dc as c,M as cn,lt as cr,ri as ct,Us as d,tr as dn,st as dr,ji as dt,te as ei,Nr as en,Tt as er,vi as et,Q as f,Qn as fn,ot as fr,ki as ft,Qs as g,Un as gn,Qe as gr,Ni as gt,Ws as h,rr as hn,Ye as hr,I as ht,rc as i,vr as in,w as ir,pi as it,So as j,fn as jn,Se as jr,Ei as jt,Vo as k,kn,Ee as kr,Ci as kt,tc as l,nr as ln,it as lr,Pi as lt,Hs as m,$n as mn,ct as mr,xi as mt,ac as n,re as ni,Fr as nn,At as nr,gi as nt,uc as o,br as on,ut as or,di as ot,js as p,er as pn,at as pr,bi as pt,qa as q,Xt as qn,ie as qr,ni as qt,oc as r,o as ri,P as rn,wt as rr,_i as rt,fc as s,ar as sn,ft as sr,Qr as st,sc as t,d as ti,Pr as tn,Ot as tr,yi as tt,ec as u,qn as un,rt as ur,R as ut,As as v,Bn as vn,v as vr,ti as vt,qs as w,Dn as wn,b as wr,ui as wt,Ys as x,Rn as xn,x as xr,ii as xt,Ms as y,Hn as yn,Ie as yr,oi as yt,Za as z,nn as zn,ge as zr,Ra as zt};
|
|
@@ -339,7 +339,8 @@ type RawSnapshotNode = {
|
|
|
339
339
|
* A keyboard is its own system surface, so it never reaches the tree as a covering sibling of app
|
|
340
340
|
* content, and a consumer that wants to refuse a tap behind it has to learn where it is from
|
|
341
341
|
* somewhere (#2589). A producer that can measure the band directly — the Apple runner, from its
|
|
342
|
-
* `app.keyboards` query
|
|
342
|
+
* `app.keyboards` query, and the Android helper, from the input method window in the window list it
|
|
343
|
+
* captures — publishes one fact per capture and says nothing else about it. A consumer therefore gets three
|
|
343
344
|
* answers and no fourth: a band in the same space as every node rect, a proven absence, or a
|
|
344
345
|
* producer that could not look.
|
|
345
346
|
*
|
|
@@ -529,9 +530,9 @@ type SnapshotState = {
|
|
|
529
530
|
*/
|
|
530
531
|
iosSystemSurfaceBundleId?: string;
|
|
531
532
|
/**
|
|
532
|
-
* iOS: the keyboard band this capture's producer measured, when it measured one. The
|
|
533
|
-
* keyboard guard prefers this over the band it would otherwise derive from `nodes`,
|
|
534
|
-
* producer that can query the keyboard directly answers in the
|
|
533
|
+
* iOS and Android: the keyboard band this capture's producer measured, when it measured one. The
|
|
534
|
+
* tap-path keyboard guard prefers this over the band it would otherwise derive from `nodes`,
|
|
535
|
+
* because a producer that can query the keyboard directly answers in the tree's own space and
|
|
535
536
|
* needs no geometry to be plausible (#2660). Absent means the guard measures the tree as before.
|
|
536
537
|
*/
|
|
537
538
|
keyboard?: SnapshotKeyboardBandFact;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{$ as e,P as t}from"./sdk-contracts.js";import{_ as n,b as r,v as i,y as a}from"./settings.js";import{n as o}from"./location-coordinates.js";async function s(e){switch(e.setting){case`appearance`:return await c(e);case`permission`:return await l(e);case`location`:return await u(e)}}async function c({runSimctl:e,udid:r,state:i}){let a=n(i),o;if(a===`toggle`){let n=await e([`ui`,r,`appearance`]),i=m(n.stdout,n.stderr);if(!i)throw new t(`COMMAND_FAILED`,`Unable to determine current iOS appearance for toggle`,{stdout:n.stdout,stderr:n.stderr});o=i===`dark`?`light`:`dark`}else o=a;await e([`ui`,r,`appearance`,o])}async function l(e){let{runSimctl:t,udid:n,
|
|
1
|
+
import{$ as e,P as t}from"./sdk-contracts.js";import{_ as n,b as r,v as i,y as a}from"./settings.js";import{n as o}from"./location-coordinates.js";async function s(e){switch(e.setting){case`appearance`:return await c(e);case`permission`:return await l(e);case`location`:return await u(e)}}async function c({runSimctl:e,udid:r,state:i}){let a=n(i),o;if(a===`toggle`){let n=await e([`ui`,r,`appearance`]),i=m(n.stdout,n.stderr);if(!i)throw new t(`COMMAND_FAILED`,`Unable to determine current iOS appearance for toggle`,{stdout:n.stdout,stderr:n.stderr});o=i===`dark`?`light`:`dark`}else o=a;await e([`ui`,r,`appearance`,o])}async function l(e){let{runSimctl:t,udid:n,deviceId:r,state:a,options:o}=e,s=d(e),c=i(a),l=c===`deny`?`revoke`:c,u=p(o?.permissionTarget,o?.permissionMode);try{await t([`privacy`,n,l,u,s])}catch(e){throw h(e)?g(l,u,s,r,e):e}}async function u(e){let{runSimctl:t,udid:n,state:i,options:a}=e;if(i.toLowerCase()===`set`){let{latitude:e,longitude:r}=o(a);return await t([`location`,n,`set`,`${e},${r}`]),{latitude:e,longitude:r}}await t([`privacy`,n,r(i)?`grant`:`revoke`,`location`,d(e)])}function d({setting:n,appBundleId:r}){if(r)return r;throw new t(`INVALID_ARGS`,`${n} setting requires an active app in session`,e())}const f={all:`all`,camera:`camera`,microphone:`microphone`,contacts:`contacts`,"contacts-limited":`contacts-limited`,notifications:`notifications`,calendar:`calendar`,location:`location`,"location-always":`location-always`,"media-library":`media-library`,motion:`motion`,reminders:`reminders`,siri:`siri`};function p(e,n){let r=a(e);if(r===`photos`){let e=n?.trim().toLowerCase();if(!e||e===`full`)return`photos`;if(e===`limited`)return`photos-add`;throw new t(`INVALID_ARGS`,`Invalid photos mode: ${n}. Use full|limited.`)}if(n?.trim())throw new t(`INVALID_ARGS`,`Permission mode is only supported for photos. Received: ${n}.`);return f[r]}function m(e,t){let n=/\b(light|dark|unsupported|unknown)\b/i.exec(`${e}\n${t}`);if(!n)return null;let r=n[1]?.toLowerCase();return r===`dark`?`dark`:r===`light`?`light`:null}function h(e){if(!(e instanceof t)||e.code!==`COMMAND_FAILED`)return!1;let n=String(e.details?.stderr??``).toLowerCase();return/failed to (set|grant|revoke|reset) access/.test(n)&&n.includes(`operation not permitted`)}function g(e,n,r,i,a){return e===`reset`?new t(`UNSUPPORTED_OPERATION`,`iOS simulator does not support resetting ${n} permission via simctl privacy on this runtime.`,{deviceId:i,appBundleId:r,hint:`Use reinstall to force a fresh prompt, or reset simulator content and settings.`},a):new t(`UNSUPPORTED_OPERATION`,`iOS simulator does not support setting ${n} permission via simctl privacy on this runtime.`,{deviceId:i,appBundleId:r,hint:"Privacy support varies by Xcode runtime: run `xcrun simctl privacy help` for its documented services, or use the `all` target, which applies the action to every service this runtime can change."},a)}export{s as t};
|
package/dist/src/store.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{J as e,P as t}from"./sdk-contracts.js";import{v as n}from"./sdk-batch-runner.js";import{
|
|
1
|
+
import{J as e,P as t}from"./sdk-contracts.js";import{v as n}from"./sdk-batch-runner.js";import{j as r,o as i}from"./owner-identity.js";import{l as a}from"./exec.js";import{t as o}from"./file.js";import"./command.js";import"./process.js";import{n as s}from"./cli-config.js";import c from"node:crypto";import l from"node:fs";import u from"node:path";function d(e,n){let r=new Set(n);for(let n of e){let e=n.agentDevicePlugin.provider;if(r.has(e))throw new t(`INVALID_ARGS`,`Duplicate provider plugin: ${e}`);r.add(e)}}function f(e){let n;try{let t=u.join(e,`package.json`);n=JSON.parse(l.readFileSync(t,`utf8`))}catch(n){throw new t(`INVALID_ARGS`,`Cannot read plugin manifest: ${e}`,{},n)}let r=n?.agentDevicePlugin;if(typeof n?.name!=`string`||typeof n?.version!=`string`||!r||r.apiVersion!==1||typeof r.provider!=`string`||!/^[a-z][a-z0-9-]*$/.test(r.provider)||typeof r.entry!=`string`||!r.entry.startsWith(`./`))throw new t(`INVALID_ARGS`,`Package does not declare a compatible provider plugin`,{reason:`incompatible_plugin`,apiVersion:1,hint:`Install a plugin release supporting agentDevicePlugin.apiVersion 1.`});return p(e,r.entry),n}function p(e,n){try{let t=l.realpathSync(e),r=l.realpathSync(u.resolve(e,n));if(r.startsWith(`${t}${u.sep}`)&&l.statSync(r).isFile())return r}catch{}throw new t(`INVALID_ARGS`,`Plugin entry must be a readable file inside its package`,{directory:e,entry:n})}function m(e){let r=s(e);try{let e=JSON.parse(l.readFileSync(r,`utf8`));if(!n(e)||e.plugins!==void 0&&!n(e.plugins))throw new t(`INVALID_ARGS`,`Plugin config must contain an object`);return e}catch(e){if(e.code===`ENOENT`)return{};throw e instanceof SyntaxError?new t(`INVALID_ARGS`,`Invalid plugin JSON: ${r}`,{},e):e}}function h(e,r){if(!S(e)||!n(r)||typeof r.installation!=`string`||!/^[a-f0-9-]{36}$/.test(r.installation)||r.version!==void 0&&!C(r.version)||r.options!==void 0&&!n(r.options))throw new t(`INVALID_ARGS`,`Invalid plugin selection: ${e}`)}function g(e){let t=u.dirname(s(e));return Object.entries(m(e).plugins??{}).map(([e,n])=>_(t,e,n))}function _(e,n,r){h(n,r);let i=u.join(e,`plugins`,r.installation,`node_modules`,n),a=f(i);if(a.name!==n)throw new t(`INVALID_ARGS`,`Plugin package identity mismatch: ${n}`);return{...a,directory:i,selection:r}}function v(t){let n=u.dirname(s(t));return Object.entries(m(t).plugins??{}).map(([t,r])=>{try{let e=_(n,t,r);return{name:t,version:e.version,provider:e.agentDevicePlugin.provider,compatible:!0}}catch(n){return{name:t,compatible:!1,error:e(n)}}})}function y(e,n){if(e===`remove`)return{name:n,version:void 0};let r=/^(@[a-z0-9][a-z0-9._-]*\/[a-z0-9][a-z0-9._-]*|[a-z0-9][a-z0-9._-]*)(?:@(.+))?$/.exec(n);if(!r||!r[1]||r[2]!==void 0&&!C(r[2]))throw new t(`INVALID_ARGS`,`Expected an npm package name, optionally followed by @version or @tag`);if(e===`update`&&r[2]!==void 0)throw new t(`INVALID_ARGS`,`update accepts a package name without a version`);return{name:r[1],version:r[2]}}async function b(e,n,r,i){let o=c.randomUUID(),s=u.join(e,`plugins`,o);l.mkdirSync(s,{recursive:!0,mode:448});try{l.writeFileSync(u.join(s,`package.json`),JSON.stringify({private:!0,dependencies:{[n]:r??`latest`}})),await a(`npm`,[`install`,`--ignore-scripts`,`--no-audit`,`--no-fund`,`--global=false`,`--prefix`,s,`--workspaces=false`,`--package-lock=true`],{cwd:s,env:i,timeoutMs:12e4});let e=f(u.join(s,`node_modules`,n));if(e.name!==n)throw new t(`INVALID_ARGS`,`Plugin package identity mismatch: ${n}`);return{installation:o,project:s,manifest:e}}catch(e){throw l.rmSync(s,{recursive:!0,force:!0}),e}}async function x(e,a,c=process.env,f=[]){let{name:p,version:h}=y(e,a),g=s(c),v=u.dirname(g);l.mkdirSync(v,{recursive:!0,mode:448});let x=await o({lockDirPath:u.join(v,`plugins.lock`),owner:{...i(),acquiredAtMs:Date.now()},description:`plugin installation`}),S;try{let i=m(c),a={...i.plugins},o=Object.hasOwn(a,p)?a[p]:void 0;if(e!==`add`&&!Object.hasOwn(a,p))throw new t(`INVALID_ARGS`,`Plugin is not installed: ${p}`);if(e===`remove`)delete a[p];else{let t=e===`update`&&C(o?.version)?o.version:h;S=await b(v,p,t,c),d([...Object.entries(a).filter(([e])=>e!==p).flatMap(([e,t])=>{try{return[_(v,e,t)]}catch{return[]}}),S.manifest],f),a[p]={installation:S.installation,version:t,...n(o?.options)?{options:o.options}:{}}}r({destination:g,contents:`${JSON.stringify({...i,plugins:a},null,2)}\n`,mode:384})}catch(e){throw S&&l.rmSync(S.project,{recursive:!0,force:!0}),e}finally{await x()}}function S(e){return/^(@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/.test(e)}function C(e){return typeof e==`string`&&/^[a-zA-Z0-9*^~<>=| .+-]+$/.test(e)&&e.trim().length>0}export{p as a,d as i,g as n,v as r,x as t};
|