agent-device
Version:
Open source device layer for AI coding agents: a CLI, MCP server, and typed Node.js API to control mobile, web, TV, and desktop apps on devices and simulators, locally or in the cloud.
2 lines • 93.2 kB
JavaScript
import{r as e}from"./rolldown-runtime.js";import{T as t,ct as n,ot as r,v as i}from"./sdk-contracts.js";import{O as a,i as o}from"./sdk-device.js";import{scryptSync as s}from"node:crypto";function c(e){let t=`${e??``}`.toLowerCase();return t.includes(`scroll`)||t.includes(`recyclerview`)||t.includes(`listview`)||t.includes(`gridview`)||t.includes(`collectionview`)||t===`collection`||t===`table`}function l(e){return c(e.type)?!0:`${e.role??``} ${e.subrole??``}`.toLowerCase().includes(`scroll`)}function u(e){return e?.trim().toLowerCase()||null}function d(e,t){let n=u(t);return n?[e.label,e.value,e.identifier].some(e=>(e??``).toLowerCase().includes(n)):!1}function f(e,t,n=()=>!0){if(!u(t))return null;for(let[r,i]of e.entries()){if(!d(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 ee(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}))}var te=e({SNAPSHOT_PRODUCERS:()=>p,isSnapshotBackend:()=>re,snapshotProducerFacts:()=>ie,stampSnapshotIdentity:()=>ae});const ne={xctest:!0,android:!0,"harmonyos-arkui":!0,"macos-helper":!0,"linux-atspi":!0,web:!0};function re(e){return typeof e==`string`&&Object.hasOwn(ne,e)}const p={"apple-runner":{channels:[`xctest`],truncation:`available`,residue:`source-measured`,quietMs:500,refs:`dense`,sparseRootWarning:`xctest-query`},"simulator-ax-bridge":{channels:[`xctest`],truncation:`available`,residue:`source-measured`,quietMs:300,refs:`dense`,sparseRootWarning:`none`},"appium-source":{channels:[`xctest`,`android`],truncation:`unavailable`,residue:`provider-derived`,quietMs:500,refs:`dense`,sparseRootWarning:`appium-page-source`},"revyl-ios-tree":{channels:[`xctest`],truncation:`unavailable`,residue:`provider-derived`,quietMs:500,refs:`dense`,sparseRootWarning:`none`},"revyl-android-tree":{channels:[`android`],truncation:`unavailable`,residue:`provider-derived`,quietMs:500,refs:`dense`,sparseRootWarning:`none`},"android-uiautomator":{channels:[`android`],truncation:`available`,residue:`source-measured`,quietMs:500,refs:`dense`,sparseRootWarning:`none`},"cdp-dom":{channels:[`android`],truncation:`available`,residue:`source-measured`,quietMs:500,refs:`dense`,sparseRootWarning:`none`},"harmonyos-uitest":{channels:[`harmonyos-arkui`],truncation:`available`,residue:`source-measured`,quietMs:500,refs:`dense`,sparseRootWarning:`none`},"macos-helper":{channels:[`macos-helper`],truncation:`available`,residue:`source-measured`,quietMs:500,refs:`dense`,sparseRootWarning:`none`},"linux-atspi":{channels:[`linux-atspi`],truncation:`available`,residue:`source-measured`,quietMs:500,refs:`dense`,sparseRootWarning:`none`},"agent-browser":{channels:[`web`],truncation:`available`,residue:`source-measured`,quietMs:500,refs:`backend-issued`,sparseRootWarning:`none`}};function ie(e){return Object.hasOwn(p,e)?p[e]:void 0}function ae(e,t){return{...e,...t}}function oe(e){if(e===void 0||e.backend===void 0)return{};switch(e.backend){case`xctest`:return{backend:e.backend,producer:e.producer};case`android`:return{backend:e.backend,producer:e.producer};case`harmonyos-arkui`:return{backend:e.backend,producer:e.producer};case`macos-helper`:return{backend:e.backend,producer:e.producer};case`linux-atspi`:return{backend:e.backend,producer:e.producer};case`web`:return{backend:e.backend,producer:e.producer}}}function se(e){return e===void 0||e===`xctest`||e===`android`||e===`harmonyos-arkui`}const ce={unsettled:!0,"no-effect":!0,loading:!0};function le(e){if(typeof e!=`object`||!e)return;let{kind:t,gesture:n}=e;if(typeof t!=`string`||!Object.hasOwn(ce,t)||typeof n!=`object`||!n)return;let{action:r,positionals:i}=n;if(!(typeof r!=`string`||!Array.isArray(i))&&i.every(e=>typeof e==`string`))return{kind:t,gesture:{action:r,positionals:i}}}function ue(e){return e?.kind===`unsettled`||e?.kind===`loading`}function de(e,t){return t.postGestureOutcome??=e.postGestureOutcome,t}function fe(e){let t=e?.producer;return t===void 0?`dense`:ie(t)?.refs??`dense`}function pe(e){return new Map(e.map(e=>[e.index,e]))}function me(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 he(e,t,n){return me(e,t,pe(e),e=>n(e)?e:null)}const m={x:-Number.MAX_VALUE/2,y:-Number.MAX_VALUE/2,width:Number.MAX_VALUE,height:Number.MAX_VALUE};function ge(e){return e.x===m.x&&e.y===m.y&&e.width===m.width&&e.height===m.height}function h(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:!ge(e)}function _e(e,t){return e>=m.width||t>=m.height}function ve(e){if(h(e)&&!_e(e.width,e.height))return{width:e.width,height:e.height}}function ye(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 ve({x:t??0,y:n??0,width:r,height:i})}function be(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 xe(e,t){let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y),i=Math.min(e.x+e.width,t.x+t.width)-n,a=Math.min(e.y+e.height,t.y+t.height)-r;return i>0&&a>0?{x:n,y:r,width:i,height:a}:void 0}function Se(e){return e.width*e.height}function Ce(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 we(e,t,n){return t>=e.x&&t<=e.x+e.width&&n>=e.y&&n<=e.y+e.height}function Te(e,t,n){if(!e||!h(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 g(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 Ee(e,t){return De(e.x,e.x+e.width,t.x,t.x+t.width)&&De(e.y,e.y+e.height,t.y,t.y+t.height)}function De(e,t,n,r){return Math.max(e,n)<=Math.min(t,r)}function _(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}const Oe=[[`TabBar`,`tab-bar`],[`Toolbar`,`toolbar`],[`NavigationBar`,`navigation-bar`]],ke=[[`com.google.android.material.bottomnavigation.BottomNavigationView`,`bottom-navigation`],[`android.widget.Toolbar`,`toolbar`],[`androidx.appcompat.widget.Toolbar`,`toolbar`]];function Ae(e,t){if(t===`apple-runner`||t===`simulator-ax-bridge`||t===`macos-helper`){let t=[e.type,e.role,e.subrole].map(e=>e?.trim().replace(/^UIKit\./,``).replace(/^(?:XCUIElementType|UI|AX)/,``));return Oe.find(([e])=>t.includes(e))?.[1]}if(t===`android-uiautomator`){let t=[e.type,e.role,e.subrole];return ke.find(([e])=>t.includes(e))?.[1]}}function je(e,t){return(t===`apple-runner`||t===`simulator-ax-bridge`)&&Ae(e,t)!==void 0}function Me(e,t){let n=Ne(e);return t.some(e=>n.includes(e))}function Ne(e){return[e.type,e.role,e.subrole].map(e=>_(e??``)).join(` `)}function Pe(e,t){let n=_(e);return n?t===`android`?n.includes(`edittext`)||n.includes(`autocompletetextview`):t===`web`&&(n===`textbox`||n===`searchbox`)||n.includes(`textfield`)||n.includes(`securetextfield`)||n.includes(`searchfield`)||n.includes(`textview`)||n.includes(`textarea`)||n===`search`:!0}function Fe({type:e,text:t,editable:n,password:r,hintShowing:i}){if(n===!0||r===!0||_(e??``)&&Pe(e??``,`android`))return i===!0?``:t??void 0}function Ie(e){let t=e.trim();return!(!t||/^(true|false)$/i.test(t)||/^\d+$/.test(t))}function Le(e){if(typeof e!=`string`)return!1;let t=e.trim();return t?!/^(true|false)$/i.test(t):!1}function Re(e){return[e.label,e.value,e.identifier].map(e=>typeof e==`string`?e.trim():``).filter(e=>e.length>0)[0]??``}const ze=Symbol(`SnapshotVisibility`);function Be(e,t={}){let n,r,i=()=>(n||(n=pe(e),t.onNodeMapBuilt?.()),n),a=()=>(r||(r=He(e),t.onViewportRectsCollected?.()),r),o=n=>We(e,n,a(),t.onContainingRectFallback),s=n=>{let r=qe(n,i(),e=>!!e.rect)?.rect;if(r)return r;let o=a();return o.length===0?null:We(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||Ee(e.rect,t)},l=e=>e.rect?c(e)?Ke(e.rect,o(e.rect)):!1:!0;return{[ze]:!0,get nodeByIndex(){return i()},get viewportRects(){return a()},findAncestor(t,n){return me(e,t,i(),n)},isVisibleInEffectiveViewport:c,isVisibleOnScreen:l,resolveEffectiveViewport:s,resolveViewport:o}}function Ve(e){let t=[e.type,e.role,e.subrole].map(e=>_(e??``)).join(` `);return t.includes(`application`)||t.includes(`window`)}function He(e){return e.flatMap(e=>Ve(e)&&h(e.rect)?[e.rect]:[])}function Ue(e,t,n){return We(e,t,n??He(e))}function We(e,t,n,i){let a=r(t),o=e=>we(e,a.x,a.y);return(g(n.filter(o))??g(n))||(i?.(),g(e.flatMap(e=>Ge(e.rect)&&o(e.rect)?[e.rect]:[])))}function Ge(e){return e?Number.isFinite(e.x)&&Number.isFinite(e.y)&&Number.isFinite(e.width)&&Number.isFinite(e.height):!1}function Ke(e,t){return!t||t.width<=0||t.height<=0||we(t,e.x+e.width/2,e.y+e.height/2)}function qe(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)&&l(r))return r;r=typeof r.parentIndex==`number`?t.get(r.parentIndex):void 0}return null}function Je(e,t){if(t===`android`&&e.visibleToUser===!1)return!1;let n=_(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&&h(e.rect):e.hittable===!0||h(e.rect)}function v(e,t){return{ok:!1,code:`INVALID_ARGS`,message:e,...t?{hint:t}:{}}}const Ye=[`visible`,`hidden`,`exists`,`absent`,`editable`,`selected`,`checked`,`focused`,`text`];function y(e){return e.hittable===!0?!0:e.rect?e.rect.width>0&&e.rect.height>0:!1}function b(e,t){return e.enabled===!1?!1:e.editable??Pe(e.type??``,t)}function Xe(e,t,n){let r=e.hintShowing??e.value===e.placeholder;if(!b(e,n)||r)return d(e,t);let i=e.label===e.value?void 0:e.label;return d({identifier:e.identifier,label:i},t)}function Ze(e){let t=e.kind??n(e.type??`Element`),r=_(e.type??``);return r&&r!==t?[t,r]:[t]}const Qe=new Set([`id`,`role`,`text`,`label`,`value`,`appname`,`windowtitle`]),$e=new Set([`visible`,`hidden`,`editable`,`selected`,`checked`,`focused`,`enabled`,`hittable`]),x=new Set([...Qe,...$e]),et=[...x],tt=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 nt(e){return tt.has(e.trim().toLowerCase())}const rt=new Map([[`"`,`"`],[`'`,`'`],[`\\`,`\\`],[`/`,`/`],[`b`,`\b`],[`f`,`\f`],[`n`,`
`],[`r`,`\r`],[`t`,` `]]);function S(e){let t=e.trim();if(!t)throw new i(`INVALID_ARGS`,`Selector expression cannot be empty`);let n=st(t);if(n.length===0)throw new i(`INVALID_ARGS`,`Selector expression cannot be empty`);return{raw:t,selectors:n.map(e=>at(e))}}function C(e){try{return S(e)}catch{return null}}function w(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 x.has(e)}return x.has(t.toLowerCase())}function it(e){let t=e.trim(),n=t.indexOf(`=`);if(n===-1)return null;let r=t.slice(0,n).trim().toLowerCase();if(!r||x.has(r))return null;let i=t.slice(n+1).trim();if(!i)return null;let a=ut(i).trim();return a?{key:r,value:a}:null}function T(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||!w(t))break;r+=1;let n=e.slice(0,r).join(` `).trim();n&&C(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 at(e){let t=e.trim();if(!t)throw new i(`INVALID_ARGS`,`Selector segment cannot be empty`);let n=ct(t);if(n.length===0)throw new i(`INVALID_ARGS`,`Invalid selector segment: ${e}`);return{raw:t,terms:n.map(ot)}}function ot(e){let t=e.trim();if(!t)throw new i(`INVALID_ARGS`,`Empty selector term`);let n=t.indexOf(`=`);if(n===-1){let n=t.toLowerCase();if(!$e.has(n))throw new i(`INVALID_ARGS`,`Invalid selector term "${e}", expected key=value`);return{key:n,value:!0}}let r=t.slice(0,n).trim().toLowerCase(),a=t.slice(n+1).trim();if(!x.has(r))throw new i(`INVALID_ARGS`,`Unknown selector key: ${r}`);if(!a)throw new i(`INVALID_ARGS`,`Missing selector value for key: ${r}`);if($e.has(r)){let e=pt(a);if(e===null)throw new i(`INVALID_ARGS`,`Invalid boolean value for ${r}: ${a}`);return{key:r,value:e}}return{key:r,value:ut(a)}}function st(e){let t=[],n=``,r=null;for(let a=0;a<e.length;a+=1){let o=e[a];if((o===`"`||o===`'`)&&!mt(e,a)){r=lt(r,o),n+=o;continue}if(!r&&o===`|`&&e[a+1]===`|`){let r=n.trim();if(!r)throw new i(`INVALID_ARGS`,`Invalid selector fallback expression: ${e}`);t.push(r),n=``,a+=1;continue}n+=o}let a=n.trim();if(!a)throw new i(`INVALID_ARGS`,`Invalid selector fallback expression: ${e}`);return t.push(a),t}function ct(e){let t=[],n=``,r=null;for(let i=0;i<e.length;i+=1){let a=e.charAt(i);if((a===`"`||a===`'`)&&!mt(e,i)){r=lt(r,a),n+=a;continue}if(!r&&/\s/.test(a)){n.trim()&&t.push(n.trim()),n=``;continue}n+=a}if(r)throw new i(`INVALID_ARGS`,`Unclosed quote in selector: ${e}`);return n.trim()&&t.push(n.trim()),t}function lt(e,t){return e?e===t?null:e:t}function ut(e){let t=e.trim();return t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`)?dt(t.slice(1,-1)):t}function dt(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=ft(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 ft(e){return rt.get(e)??null}function pt(e){let t=ut(e).toLowerCase();return t===`true`||t!==`false`&&null}function mt(e,t){let n=0;for(let r=t-1;r>=0&&e[r]===`\\`;--r)n+=1;return n%2==1}function ht(e){return Ye.includes(e)}const gt=`is requires predicate: ${Ye.join(`|`)}`;function _t(e){let t=e.toLowerCase();return ht(t)?{ok:!0,predicate:t}:v(gt,vt)}const vt=`Use "is <predicate> <selector>" or "is <selector> <predicate>". visible|hidden|editable|selected|checked|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 yt(e){if(ht((e[0]??``).toLowerCase()))return e;for(let t=1;t<e.length;t+=1){let n=(e[t]??``).toLowerCase();if(ht(n)&&C(e.slice(0,t).join(` `)))return[n,...e.slice(0,t),...e.slice(t+1)]}return e}function bt(e){let{predicate:t,node:n,visibility:r,expectedText:i,platform:a}=e,o=Re(n),s=b(n,a),c=n.selected===!0,l=n.checked===!0,u=n.focused===!0,d=t===`text`?y(n):St(n,r,a),f=!1;switch(t){case`visible`:f=d;break;case`hidden`:f=!d;break;case`editable`:f=s;break;case`selected`:f=c;break;case`checked`:f=l;break;case`focused`:f=u;break;case`text`:f=o===(i??``);break;default:return xt(t)}let ee=t===`text`?`expected="${i??``}" actual="${o}"`:`actual=${JSON.stringify({visible:d,editable:s,selected:c,checked:l,focused:u})}`;return{pass:f,actualText:o,details:ee}}function xt(e){throw Error(`Unhandled is predicate: ${String(e)}`)}function St(e,t,n){if(n===`android`&&e.visibleToUser===!1)return!1;if(h(e.rect))return t.isVisibleInEffectiveViewport(e);if(e.rect)return!1;if(n!==`android`&&e.hittable===!0)return!0;let r=Ct(e,t,n);return r?h(r.rect)?t.isVisibleInEffectiveViewport(r):n!==`android`&&r.hittable===!0:!1}function Ct(e,t,n){return t.findAncestor(e,e=>Je(e,n)?e:null)}function wt(e){let t=yt(e),n=t[0]??``;return{predicate:n,split:T(t.slice(1),{preferTrailingValue:n===`text`})}}const Tt=`is requires a selector expression`,Et=`is text requires expected text value`;function Dt(e){let{predicate:t,split:n}=wt([...e]),r=_t(t);if(!r.ok)return r;if(!n)return v(Tt);let i=n.rest.join(` `).trim();return r.predicate===`text`&&!i?v(Et):r.predicate!==`text`&&n.rest.length>0?v(`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}:v(`get only supports text or attrs`)}function kt(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}:v(`get requires @ref or selector expression`)}function At(e){return e?{ok:!0,text:e}:v(`wait requires text`)}function jt(e){return Array.from(new Set(e))}function Mt(e){return JSON.stringify(Nt(e))}function Nt(e){if(Array.isArray(e))return e.map(Nt);if(!e||typeof e!=`object`)return e;let t=e;return Object.fromEntries(Object.keys(t).sort().map(e=>[e,Nt(t[e])]))}function Pt(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)}function Ft(e,t,n={}){let r=e[t];if(r===void 0)return;if(!Number.isInteger(r))throw new i(`INVALID_ARGS`,`Expected ${t} to be an integer.`);let a=r;if(n.min!==void 0&&a<n.min)throw new i(`INVALID_ARGS`,`Expected ${t} to be at least ${n.min}.`);if(n.max!==void 0&&a>n.max)throw new i(`INVALID_ARGS`,`Expected ${t} to be at most ${n.max}.`);return a}function It(e,t,n={}){let r=e[t];if(r!==void 0){if(typeof r!=`number`||!Number.isFinite(r))throw new i(`INVALID_ARGS`,`Expected ${t} to be a finite number.`);if(n.min!==void 0&&r<n.min)throw new i(`INVALID_ARGS`,`Expected ${t} to be at least ${n.min}.`);if(n.max!==void 0&&r>n.max)throw new i(`INVALID_ARGS`,`Expected ${t} to be at most ${n.max}.`);return r}}const Lt=`android_shell_text_unsupported`;function Rt(e){return typeof e==`string`?e.trim().toLowerCase():``}const zt=/^#\s*agent-device:target-v(\d+)(?:\s+(\S.*))?$/,Bt=/^#\s*agent-device:targets-v(\d+)(?:\s+(\S.*))?$/,Vt=4096;function Ht(e){return e.normalize(`NFC`)}function Ut(e){if(e===void 0)return;let t=Ht(e);return t.length>0?t:void 0}function Wt(e){return Ht(e)}function Gt(e){if(e===void 0)return;let t=Ht(e).trim().replaceAll(/\s+/g,` `);return t.length>0?t:void 0}function E(e){return Buffer.byteLength(e,`utf8`)}function D(e,t){if(E(e)<=t)return e;let n=e.length;for(;n>0&&E(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 Kt(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(qt),t.sibling=e.sibling,t.viewportOrder=e.viewportOrder,e.scrollRegion&&(t.scrollRegion=Jt(e.scrollRegion)),e.rect&&(t.rect=Yt(e.rect)),t.verification=e.verification,t}function qt(e){let t={role:e.role};return e.label!==void 0&&(t.label=e.label),t}function Jt(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 Yt(e){return{x:e.x,y:e.y,width:e.width,height:e.height}}function Xt(e){return JSON.stringify(Kt(e))}function Zt(e){let t=[e.role,e.id,e.label,...e.ancestry.flatMap(e=>[e.role,e.label]),e.scrollRegion?.role,e.scrollRegion?.id,e.scrollRegion?.label];return e.ancestry.length<=8&&t.every(e=>e===void 0||E(e)<=256)&&E(Xt(e))<=4096}function Qt(e){if(Zt(e))return e;let t={...e,verification:`unverifiable`},n=[e=>delete e.rect,e=>delete e.scrollRegion,e=>{e.ancestry=[]},e=>delete e.label];for(let e of n){if(Zt(t))return t;e(t)}if(Zt(t))return t;throw new i(`INVALID_ARGS`,`target annotation cannot fit with role and id retained`)}function $t(e){return Xt(Qt(e))}function en(e){return`# agent-device:target-v1 ${$t(e)}`}function tn(e){return JSON.stringify({source:Kt(Qt(e.source)),destination:Kt(Qt(e.destination))})}function nn(e){return`# agent-device:targets-v1 ${tn(e)}`}function rn(e){let t=e.trim(),n=Bt.exec(t);return n?Number(n[1])===1?{kind:`v1`,evidence:an((n[2]??``).trim())}:{kind:`future-version`}:{kind:`none`}}function an(e){if(E(e)>8320)throw new i(`INVALID_ARGS`,`targets-v1 annotation exceeds the 8320-byte payload cap.`);let t;try{t=JSON.parse(e)}catch{throw new i(`INVALID_ARGS`,`targets-v1 annotation is not valid JSON.`)}if(typeof t!=`object`||!t||Array.isArray(t))throw new i(`INVALID_ARGS`,`targets-v1 annotation must be a JSON object.`);let n=t;if(n.source===void 0||n.destination===void 0)throw new i(`INVALID_ARGS`,`targets-v1 annotation requires source and destination evidence.`);return{source:sn(JSON.stringify(n.source)),destination:sn(JSON.stringify(n.destination))}}function on(e){let t=e.trim();if(!t.startsWith(`#`))return{kind:`none`};let n=zt.exec(t);return n?Number(n[1])===1?{kind:`v1`,evidence:sn((n[2]??``).trim())}:{kind:`future-version`}:{kind:`none`}}function sn(e){if(E(e)>4096)throw new i(`INVALID_ARGS`,`target-v1 annotation exceeds the ${Vt}-byte payload cap.`);let t;try{t=JSON.parse(e)}catch{throw new i(`INVALID_ARGS`,`target-v1 annotation is not valid JSON.`)}if(typeof t!=`object`||!t||Array.isArray(t))throw new i(`INVALID_ARGS`,`target-v1 annotation must be a JSON object.`);let n=t,r=cn(n.role,`role`),a=ln(n.id,`id`),o=un(n.label,`label`),s=fn(n.ancestry),c=mn(n.sibling,`sibling`,0),l=mn(n.viewportOrder,`viewportOrder`,0),u=hn(n.scrollRegion),d=gn(n.rect),f=_n(n.verification);return{...a===void 0?{}:{id:a},role:r,...o===void 0?{}:{label:o},ancestry:s,sibling:c,viewportOrder:l,...u?{scrollRegion:u}:{},...d?{rect:d}:{},verification:f}}function cn(e,t){if(e===void 0)throw new i(`INVALID_ARGS`,`target-v1 "${t}" is required.`);if(typeof e!=`string`)throw new i(`INVALID_ARGS`,`target-v1 "${t}" must be a string.`);return dn(Wt(e),t)}function ln(e,t){if(e===void 0)return;if(typeof e!=`string`)throw new i(`INVALID_ARGS`,`target-v1 "${t}" must be a string.`);let n=Ut(e);return n===void 0?void 0:dn(n,t)}function un(e,t){if(e===void 0)return;if(typeof e!=`string`)throw new i(`INVALID_ARGS`,`target-v1 "${t}" must be a string.`);let n=Gt(e);return n===void 0?void 0:dn(n,t)}function dn(e,t){if(E(e)>256)throw new i(`INVALID_ARGS`,`target-v1 "${t}" exceeds the 256-byte field cap.`);return e}function fn(e){if(e===void 0)return[];if(!Array.isArray(e))throw new i(`INVALID_ARGS`,`target-v1 "ancestry" must be an array.`);if(e.length>8)throw new i(`INVALID_ARGS`,`target-v1 "ancestry" exceeds the 8-entry cap.`);return e.map((e,t)=>pn(e,t))}function pn(e,t){if(typeof e!=`object`||!e||Array.isArray(e))throw new i(`INVALID_ARGS`,`target-v1 "ancestry[${t}]" must be an object.`);let n=e,r=cn(n.role,`ancestry[${t}].role`),a=un(n.label,`ancestry[${t}].label`);return{role:r,...a===void 0?{}:{label:a}}}function mn(e,t,n){if(e===void 0)return n;if(typeof e!=`number`||!Number.isSafeInteger(e)||e<0)throw new i(`INVALID_ARGS`,`target-v1 "${t}" must be a non-negative integer.`);return e}function hn(e){if(e===void 0)return;if(typeof e!=`object`||!e||Array.isArray(e))throw new i(`INVALID_ARGS`,`target-v1 "scrollRegion" must be an object.`);let t=e,n=cn(t.role,`scrollRegion.role`),r=ln(t.id,`id`),a=un(t.label,`scrollRegion.label`);return{role:n,...r===void 0?{}:{id:r},...a===void 0?{}:{label:a}}}function gn(e){if(e===void 0)return;if(typeof e!=`object`||!e||Array.isArray(e))throw new i(`INVALID_ARGS`,`target-v1 "rect" must be an object.`);let t=e;return{x:O(t.x,`rect.x`),y:O(t.y,`rect.y`),width:O(t.width,`rect.width`),height:O(t.height,`rect.height`)}}function O(e,t){if(typeof e!=`number`||!Number.isFinite(e))throw new i(`INVALID_ARGS`,`target-v1 "${t}" must be a finite number.`);return e}function _n(e){if(e===`verified`||e===`unverifiable`)return e;throw new i(`INVALID_ARGS`,`target-v1 "verification" must be "verified" or "unverifiable".`)}function k(e){let t=Wt(_(e.type??``)),n=Ut(e.identifier),r=Gt(e.label);return{...n===void 0?{}:{id:D(n,256)},role:D(t,256),...r===void 0?{}:{label:D(r,256)}}}function vn(e,t){return e.id===t.id&&e.role===t.role&&e.label===t.label}function yn(e,t){let n=0;for(let r of e)k(r).id===t&&(n+=1);return n}function bn(e,t){if(e.id===void 0||yn(t,e.id)<=1)return e;let{role:n,label:r}=e;return{role:n,...r===void 0?{}:{label:r}}}function xn(e,t){let n=k(t),r=e.filter(e=>vn(n,k(e)));return r.length===1?r[0]?.rect:void 0}function Sn(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 Cn(e,t){return{documentOrder:e.index,sibling:Sn(t,e)}}function wn(e,t){return e.documentOrder===t.documentOrder&&e.sibling===t.sibling}function Tn(e){return{...e.id===void 0?{}:{id:e.id},role:e.role,...e.label===void 0?{}:{label:e.label}}}function En(e,t){return t.id===void 0?e.role===t.role&&e.label===t.label:e.id===t.id}function Dn(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 On(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 kn(e){return e?`${e.role}${e.label?`/${e.label}`:``}`:`(missing)`}function An(e,t){return!t||t.role!==e.role||e.label!==void 0&&t.label!==e.label}function jn(e,t){for(let[n,r]of e.entries()){let e=t[n];if(An(r,e))return[`ancestry[${n}]: recorded=${kn(r)} observed=${kn(e)}`]}return[]}function Mn(e,t,n={}){let r=[],i=_(e.type??``),a=Pn(e,n.nodes),o=j(e.label),s=j(e.value),c=j(Re(e)),l=n.action===`fill`;a&&r.push(`id=${A(a)}`),i&&o&&r.push(l?`role=${A(i)} label=${A(o)} editable=true`:`role=${A(i)} label=${A(o)}`),o&&r.push(l?`label=${A(o)} editable=true`:`label=${A(o)}`),s&&r.push(l?`value=${A(s)} editable=true`:`value=${A(s)}`),c&&c!==o&&c!==s&&r.push(l?`text=${A(c)} editable=true`:`text=${A(c)}`),i&&l&&!r.some(e=>e.includes(`editable=true`))&&r.push(`role=${A(i)} editable=true`);let u=jt(r);return u.length===0&&i&&u.push(l?`role=${A(i)} editable=true`:`role=${A(i)}`),u.length===0&&y(e)&&u.push(`visible=true`),u}function Nn(e){let[t]=e;if(t===void 0)return;let n=C(t)?.selectors;return n?.length===1&&n[0]?.terms.length===1&&n[0].terms[0]?.key===`id`?t:e.join(` || `)}function Pn(e,t){let n=j(e.identifier);if(!n||!t)return n;let r=k(e).id;return r===void 0?n:yn(t,r)>1?null:n}function A(e){return JSON.stringify(e)}function j(e){return e&&e.trim()||null}const Fn=[`any`,`text`,`label`,`value`,`role`,`id`],In=[`text`,`label`,`value`,`role`,`id`];function Ln(e){let t=e?.toLowerCase();return t===`press`||t===`tap`?`click`:t}function Rn(e){return e===`exists`||e===`wait`||e===`get_text`||e===`get_attrs`||e===`list`}function zn(e,t,n,r={}){let i=N(n);if(!i)return{matches:[],score:0};let a=0,o=[];for(let n of e){if(r.requireRect&&!n.rect)continue;let e=Bn(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 Bn(e,t,n){switch(t){case`role`:return Vn(e,n);case`label`:return M(e.label,n);case`value`:return M(e.value,n);case`id`:return M(e.identifier,n);default:return Math.max(M(e.label,n),M(e.value,n),M(e.identifier,n))}}function M(e,t){let n=N(e??``);return n?n===t?2:+!!n.includes(t):0}function Vn(e,t){let n=Ze(e);return n.some(e=>N(e)===t)?2:+!!n.some(e=>Hn(e).includes(t))}function Hn(e){let t=e.lastIndexOf(`.`);return t===-1?e:e.slice(t+1)}function N(e){return e.trim().toLowerCase().replaceAll(/\s+/g,` `)}const Un=`find requires a value`,Wn=`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 Gn(e,t){if(e.length===0)return{ok:!1,code:`INVALID_ARGS`,message:`find requires a locator or text`};let n=Jn([...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:Un}}const Kn=[`exists`,`list`,`click`,`focus`];function qn(e){return Kn.includes(e)}function Jn(e){let t=`any`,n=0;In.includes(e[0])&&(t=e[0],n=1);let r=e[n]??``,a=e.slice(n+1);if(a.length===0)return{locator:t,query:r,action:`click`};let o=Ln(a[0]);if(qn(o))return{locator:t,query:r,action:o};if(o===`get`)return{locator:t,query:r,action:Yn(a[1])};if(o===`wait`){let e=Zn(a[1]);return{locator:t,query:r,action:`wait`,timeoutMs:e??void 0}}if(o===`fill`||o===`type`){let e=a.slice(1);return{locator:t,query:r,action:o,value:e.length===0?void 0:e.join(` `)}}throw new i(`INVALID_ARGS`,`Unsupported find action: ${a[0]}`,{hint:Wn})}function Yn(e){let t=e?.toLowerCase();if(t===`text`)return`get_text`;if(t===`attrs`)return`get_attrs`;throw new i(`INVALID_ARGS`,`find get only supports text or attrs`)}function Xn(e,t){return e!==`any`||!t.includes(`=`)&&!t.includes(`||`)?null:C(t)?t:null}function Zn(e){if(!e)return null;let t=Number(e);return Number.isFinite(t)?t:null}function Qn(e,t,n){return t.terms.every(t=>$n(e,t,n))}function $n(e,t,n){switch(t.key){case`id`:return P(e.identifier,String(t.value));case`role`:return er(e,String(t.value));case`label`:return P(e.label,String(t.value));case`value`:return P(e.value,String(t.value));case`text`:return P(Re(e),String(t.value));case`appname`:return P(e.appName,String(t.value));case`windowtitle`:return P(e.windowTitle,String(t.value));case`visible`:return y(e)===!!t.value;case`hidden`:return!y(e)==!!t.value;case`editable`:return b(e,n)===!!t.value;case`selected`:return e.selected===!0==!!t.value;case`checked`:return t.value===!0?e.checked===!0:e.checked===!1;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 P(e,t){return N(e??``)===N(t)}function er(e,t){let n=N(t);return Ze(e).some(e=>N(e)===n)}function tr(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=cr(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 nr(e,t,n){return tr(e,t,n).resolution}function rr(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:Qn(e,a,n.platform));if(t.length>0)return{selector:a,selectorIndex:i,matchedNodes:t}}return null}function ir(e,t,n){let r=n.requireRect??!1,i=[];for(let[a,o]of t.selectors.entries()){let t=fr(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 ar=`Snapshot refs expire when the UI changes. Run snapshot -i and retry with a fresh @ref.`;function or(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 sr(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 cr(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||Qn(l,t,n)&&(i+=1,a??=l,o.push(l),lr(s,l,c));return{count:i,firstNode:a,disambiguated:s.tie?null:s.best,tiebreak:s.tie?null:ur(o,s.best,c),candidates:o}}function lr(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=pr(t,e.best);i.result>0?(e.best=t,e.tie=!1):i.result===0&&(e.tie=!0)}function ur(e,t,n){if(!t)return null;let r=null;for(let i of e)i!==t&&(!r||dr(i,r,n).result>0)&&(r=i);return r?dr(t,r,n).criterion:null}function dr(e,t,n){let r=n(e);return r===n(t)?pr(e,t):{result:r?1:-1,criterion:`visible`}}function fr(e,t,n,r){let i=0;for(let a of e)r&&!a.rect||Qn(a,t,n)&&(i+=1);return i}function pr(e,t){let n=e.depth??0,r=t.depth??0;if(n!==r)return{result:n>r?1:-1,criterion:`deepest`};let i=mr(e),a=mr(t);return i===a?{result:0,criterion:null}:{result:i<a?1:-1,criterion:`smallest-area`}}function mr(e){return e.rect?e.rect.width*e.rect.height:1/0}const hr={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 gr(e){return e.ambiguity===`first-match`?{requireRect:e.requireRect,requireUnique:!1}:{requireRect:e.requireRect,requireUnique:!0,disambiguateAmbiguous:e.ambiguity===`disambiguate`}}function _r(e,t){let n=e===`is`?wt([...t]).split:T([...t]);return n?C(n.selectorExpression)?{kind:`expression`,expression:n.selectorExpression,rest:n.rest}:{kind:`invalid`}:{kind:`not-applicable`}}function vr(e){return{platform:e.platform,...gr({ambiguity:e.allowDisambiguation?`disambiguate`:`fail-closed`,requireRect:e.requireRect})}}function yr(e,t,n){let r=C(e);if(!r)return{kind:`unresolved`,reason:`parse-invalid`,matchedNodes:[]};let{resolution:i,matchedNodes:a}=tr(t,r,vr(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 br(e,t,n={}){return Mn(e,t,n)}function xr(e,t,n){let r=C(e);if(!r)return;let i=nr(t,r,vr(n));if(i)return{node:i.node,basis:Cr(i.selector)}}function Sr(e){if(!e)return;let t=C(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 Cr(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 wr(e,t){let n=C(e);if(!n)return e.includes(`=`)||e.includes(`||`)?null:e;let r=new Set(t.textKeys),i=t.textAliases??{};return n.selectors.length>1?Tr(n.selectors,r,i):Er(n.selectors[0],r,new Set(t.booleanKeys),i)}function Tr(e,t,n){let r=e.map(e=>{let r=e.terms.length===1?e.terms[0]:void 0;return r&&Dr(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 Er(e,t,n,r){if(!e)return null;let i={},a=0;for(let o of e.terms){if(Dr(o.key,t,r)&&typeof o.value==`string`)a+=1;else if(!Or(o,n,`boolean`))return null;i[r[o.key]??o.key]=o.value}return a<=1&&Object.keys(i).length>0?i:null}function Dr(e,t,n){return t.has(e)||n[e]!==void 0}function Or(e,t,n){return t.has(e.key)&&typeof e.value===n}function kr(e){let t=C(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 Ar(e,t){if(!t)return!1;let n=C(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 jr(e,t){return C(e)?.selectors.some(e=>e.terms.some(e=>e.key===t))??!1}function Mr(e){return S(e).selectors.map(e=>e.raw)}function Nr(e){return C(e)!==null}function Pr(e){S(e)}function Fr(e){return JSON.stringify({required:[...e.required].sort(),preferred:[...e.preferred].sort(),conditional:[...e.conditional??[]].sort()})}function Ir(){return e=>{let t=Lr(e.required,`required`),n=Lr(e.preferred??[],`preferred`),r=Lr(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 Lr(e,t){let n=[...e];if(new Set(n).size!==n.length)throw TypeError(`Runtime use contains duplicate ${t} operations`);return Object.freeze(n)}function Rr(e){if(typeof e!=`object`||!e)throw Gr();let t=e,n=Object.keys(t).sort();if(!(t.kind===`none`&&F(n,[`kind`]))&&!(t.kind===`host`&&F(n,[`kind`]))&&!(t.kind===`inventory`&&F(n,[`kind`,`use`])&&Br(t.use))&&!(t.kind===`device-runtime`&&F(n,[`kind`,`use`])&&Vr(t.use))&&!(t.kind===`device-runtime`&&(F(n,[`kind`,`uses`])||F(n,[`kind`,`selectUses`,`uses`])&&typeof t.selectUses==`function`)&&zr(t.uses)))throw Gr()}function zr(e){if(!Array.isArray(e)||e.length===0||!e.every(Vr))return!1;let t=e.map(Fr);return new Set(t).size===t.length}function Br(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.kind===`device-inventory`&&F(Object.keys(t).sort(),[`kind`])}function Vr(e){if(typeof e!=`object`||!e)return!1;let t=e,n=[Ur(t.required),Ur(t.preferred),Ur(t.conditional??[])];if(!Hr(n))return!1;let r=n.flat();return new Set(r).size===r.length&&F(Object.keys(t).sort(),t.conditional===void 0?[`preferred`,`required`]:[`conditional`,`preferred`,`required`])}function Hr(e){return e.every(e=>e!==null&&Wr(e))}function Ur(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)?e:null}function Wr(e){return new Set(e).size===e.length}function F(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function Gr(){return TypeError(`Command platform execution must declare exactly one of none, host, inventory, or device-runtime`)}function Kr(e){if(!a(e))throw TypeError(`Unknown local runtime family: ${String(e)}`);return Object.freeze({kind:`local-family`,family:e})}function qr(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,t){let n=e.trim();if(n.length===0)throw TypeError(`Provider runtime instance requires a non-empty provider`);let r=Object.create(null);r.provider=n;let i=new Set([`provider`]);for(let[e,n]of t){if(e.length===0||i.has(e))throw TypeError(`Provider runtime principal field '${e}' is empty or repeated`);if(/^\d+$/.test(e))throw TypeError(`Provider runtime principal field '${e}' must not be an integer`);i.add(e),n!==void 0&&(r[e]=n)}if(Object.keys(r).length===1)throw TypeError(`Provider runtime principal needs at least one fact with a value`);return`principal-${s(JSON.stringify(r),`agent-device:${n}-runtime-owner:v1`,32,{N:16384,r:8,p:1,maxmem:67108864}).toString(`hex`)}`}function Yr(e){switch(e.kind){case`local-family`:return`local:${e.family}`;case`provider-runtime`:return`provider:${JSON.stringify([e.provider,e.instance])}`}}function Xr(e,t){return Yr(e)===Yr(t)}const Zr=$r(`unsupported-platform-leaf`);function Qr(e,t){return!e.available||e.subjects===void 0?e:Object.hasOwn(e.subjects,t)?e.subjects[t]:e.unlisted??Zr}function $r(e,t){return Object.freeze(t===void 0?{available:!1,reason:e}:{available:!1,reason:e,hint:t})}function ei(e,t){return e.available?t():{}}function ti(e,t){let n={},r={};for(let i of t.required){let t=ni(e.facts.operations,i);if(n[i]=t,!t.available)throw si(i,t);r[i]=ai(e.operations,i)}for(let i of t.preferred){let t=ni(e.facts.operations,i);n[i]=t,t.available&&(r[i]=ai(e.operations,i))}for(let i of t.conditional??[]){let t=ni(e.facts.operations,i);n[i]=t,t.available&&(r[i]=ai(e.operations,i))}return Object.freeze({device:e.device,owner:e.owner,facts:Object.freeze(n),operations:Object.freeze(r)})}function ni(e,n){let r=e[n];if(!ri(r))throw t(`Runtime owner omitted the ${n} fact`);let i=ii(r);if(i)return i;throw t(`Runtime owner returned an invalid ${n} fact`)}function ri(e){return typeof e==`object`&&!!e&&`available`in e}function ii(e){if(e.available===!0)return Object.freeze({available:!0});if(e.available===!1&&oi(e.reason)&&(e.hint===void 0||typeof e.hint==`string`))return $r(e.reason,e.hint)}function ai(e,n){let r=e[n];if(typeof r!=`function`)throw t(`Runtime owner advertised ${n} without an implementation`);return r}function oi(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`||e===`network-capture-post-session`}function si(e,t){return new i(`UNSUPPORTED_OPERATION`,`Runtime operation ${e} is unavailable`,{reason:t.reason,hint:t.hint})}const I=Ir(),ci=I({required:[`bootTarget`]}),li=I({required:[`ensureReady`]}),ui=I({required:[`bootTargetHeadless`]}),di=I({required:[`ensureReady`,`listApps`]}),fi=I({required:[`captureSnapshot`]}),pi=I({required:[`setViewport`]}),mi=I({required:[`focusPoint`]}),hi=I({required:[`typeText`]}),gi=I({required:[`back`]}),_i=I({required:[`home`]}),vi=I({required:[`setOrientation`]}),yi=I({required:[`unlockOrientation`]}),bi=Object.freeze([vi,yi]),xi=I({required:[`setFoldPose`]}),Si=I({required:[`sendTelephonyEvent`]}),Ci=I({required:[`tvRemote`]}),wi=I({required:[`keyboardStatus`]}),Ti=I({required:[`keyboardDismiss`]}),Ei=I({required:[`keyboardEnter`]}),Di=I({required:[`appSwitcher`]}),Oi=I({required:[`actionButton`]}),ki=I({required:[`volumeUp`]}),Ai=I({required:[`volumeDown`]}),ji=I({required:[`power`]}),Mi=I({required:[`mute`]}),Ni=I({required:[`sleep`]}),Pi=I({required:[`wake`]}),Fi=I({required:[`mediaPlayPause`]}),Ii=I({required:[`mediaNext`]}),Li=I({required:[`mediaPrevious`]}),Ri=I({required:[`mediaRewind`]}),zi=I({required:[`mediaFastForward`]}),Bi=Object.freeze([ki,Ai,ji,Mi,Ni,Pi,Fi,Ii,Li,Ri,zi]),Vi=I({required:[`triggerAppEvent`]}),Hi=I({required:[`setSetting`]}),Ui=I({required:[`readSetting`]}),Wi=I({required:[`readAlert`]}),Gi=I({required:[`awaitAlert`]}),Ki=I({required:[`acceptAlert`]}),qi=I({required:[`dismissAlert`]}),Ji=I({required:[`readClipboard`]}),Yi=I({required:[`writeClipboard`]}),Xi=I({required:[`perfFrames`]}),Zi=I({required:[`perfMemorySample`]}),Qi=I({required:[`perfMemorySnapshot`]}),$i=I({required:[`perfNativeCaptureStart`]}),ea=I({required:[`perfNativeCaptureReattach`,`perfNativeCaptureCleanup`]}),ta=I({required:[`perfProfileReport`]}),na=Object.freeze([Xi,Zi,Qi,$i,ea,ta]),L=I({required:[`tapPoint`]}),ra=I({required:[`captureSnapshot`,`tapPoint`],preferred:[`tapRef`],conditional:[`tapElementSelector`,`querySelector`]}),ia=I({required:[`longPressPoint`]}),aa=I({required:[`captureSnapshot`,`longPressPoint`],conditional:[`querySelector`]}),oa=I({required:[`hoverPoint`]}),sa=I({required:[`captureSnapshot`,`hoverPoint`],preferred:[`hoverRef`],conditional:[`querySelector`]}),ca=I({required:[`fillPoint`]}),la=I({required:[`captureSnapshot`,`fillPoint`],preferred:[`fillRef`],conditional:[`querySelector`]}),ua=Object.freeze([L,ra]),da=ua,fa=Object.freeze([ia,aa]),pa=Object.freeze([oa,sa]),ma=Object.freeze([ca,la]);function ha(e,t){switch(e){case`click`:case`press`:return t?{kind:`captured-tap`,use:ra}:{kind:`tap-point`,use:L};case`fill`:return t?{kind:`captured-fill`,use:la}:{kind:`fill-point`,use:ca};case`longpress`:return t?{kind:`captured-long-press`,use:aa}:{kind:`long-press-point`,use:ia};case`hover`:return t?{kind:`captured-hover`,use:sa}:{kind:`hover-point`,use:oa}}}const ga=I({required:[`performGesturePlan`,`captureSnapshot`],preferred:[`gestureViewport`],conditional:[`querySelector`]}),_a=I({required:[`performDirectionalFlingPlan`,`captureSnapshot`],preferred:[`gestureViewport`],conditional:[`querySelector`]}),va=I({required:[`performMultiTouchGesturePlan`,`captureSnapshot`],preferred:[`gestureViewport`],conditional:[`querySelector`]}),ya=I({required:[`performTargetAuthoredDrag`,`captureSnapshot`],preferred:[`gestureViewport`],conditional:[`querySelector`]}),ba=I({required:[`gestureViewport`]}),xa=I({required:[`scrollDirection`],conditional:[`captureSnapshot`]}),Sa=I({required:[`scrollDirection`,`captureSnapshot`]}),Ca=Object.freeze({plan:ga,"directional-fling":_a,"multi-touch":va,"target-authored-drag":ya}),wa=Object.freeze([ga,_a,va,ya]),Ta=Object.freeze([ga]),Ea=Object.freeze([xa,Sa]);function Da(e){return e.intent===`pan`?(`pointerCount`in e?e.pointerCount:1)===2:e.intent===`pinch`||e.intent===`rotate`||e.intent===`transform`||e.intent===`tap`}function Oa(e){return e.intent===`drag`?`target-authored-drag`:Da(e)?`multi-touch`:e.intent===`fling`&&`direction`in e?`directional-fling`:`plan`}function ka(e){let t=Oa(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=Ca[e];return Object.freeze({tier:e,operation:t.required[0],use:t})}function Aa(e){return e.until===void 0?e.edge===void 0?Object.freeze({kind:`direction`,use:xa}):Object.freeze({kind:`edge`,edge:e.edge,use:Sa}):Object.freeze({kind:`until`,until:e.until,use:Sa})}const ja=I({required:[`captureSnapshot`,`captureSnapshotWithCustomActions`]}),Ma=I({required:[`captureSnapshot`,`captureSnapshotWithoutActiveApp`]}),Na=I({required:[`captureSnapshot`,`captureSnapshotWithCustomActions`,`captureSnapshotWithoutActiveApp`]}),Pa=I({required:[`captureSnapshot`]}),Fa=I({required:[`captureSnapshot`,`captureSnapshotWithoutActiveApp`]}),Ia=I({required:[`captureSnapshot`],preferred:[`readTextAtPoint`]}),La=I({required:[`captureSnapshot`,`captureSnapshotWithoutActiveApp`],preferred:[`readTextAtPoint`]}),Ra=I({required:[`captureSnapshot`],conditional:[`findText`]}),za=I({required:[`captureSnapshot`,`captureSnapshotWithoutActiveApp`],conditional:[`findText`]}),Ba=Object.freeze([Pa,Fa]),Va=Object.freeze([Ia,La]),Ha=I({required:[`captureSnapshot`,`focusPoint`]}),Ua=I({required:[`captureSnapshot`,`captureSnapshotWithoutActiveApp`,`focusPoint`]}),Wa=I({required:[`captureSnapshot`,`focusPoint`,`typeText`]}),Ga=I({required:[`captureSnapshot`,`captureSnapshotWithoutActiveApp`,`focusPoint`,`typeText`]}),Ka=Object.freeze([Ia,La,Pa,Fa,Ha,Ua,Wa,Ga]),qa=Object.freeze([Ra,za]),Ja=Object.freeze([fi,ja,Ma,Na]),z=Object.freeze({"capture-only":Ba,"element-text":Va,"wait-observation":qa,"find-focus":Object.freeze([Ha,Ua]),"find-type":Object.freeze([Wa,Ga])});function Ya(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 Za(e){return e.customActions?e.hasActiveApp?Object.freeze({kind:`custom-actions-active-app`,operation:`captureSnapshotWithCustomActions`,use:ja}):Object.freeze({kind:`custom-actions-without-active-app`,operation:`captureSnapshotWithCustomActions`,use:Na}):e.hasActiveApp?Object.freeze({kind:`active-app`,operation:`captureSnapshot`,use:fi}):Object.freeze({kind:`without-active-app`,operation:`captureSnapshotWithoutActiveApp`,use:Ma})}const Qa=I({required:[`captureScreenshot`]}),$a=I({required:[`captureScreenshot`,`captureSnapshot`]}),eo=Object.freeze([Qa,$a]);function to(e){return e.cropOn?Object.freeze({kind:`capture-with-crop-on`,use:$a}):e.overlayRefs?Object.freeze({kind:`capture-with-overlay-refs`,use:$a}):Object.freeze({kind:`capture`,use:Qa})}const no=Object.freeze([ci,ui]),ro=Object.freeze({kind:`boot-target`,operation:`bootTarget`,use:ci}),io=Object.freeze({kind:`boot-target-headless`,operation:`bootTargetHeadless`,use:ui});function ao(e){return e.headless?io:ro}const oo=I({required:[`ensureReady`,`appState`]}),so=Object.freeze([oo]),co=I({required:[`shutdownTarget`]}),lo=Object.freeze([Ji,Yi]),uo=Object.freeze([Hi,Ui]),fo=Object.keys({"text-size":!0}),po=Object.freeze({kind:`write`,use:Hi});function mo(e){let t=ho(e?.[0]);return e?.length!==1||t===void 0?po:fo.includes(t)?Object.freeze({kind:`read`,setting:t,use:Ui}):po}function ho(e){let t=e?.trim().toLowerCase();return fo.find(e=>e===t)}const go=Object.freeze([Wi,Gi,Ki,qi]),_o=Object.freeze([wi,Ti,Ei]),V={kind:`none`},vo={kind:`host`};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 Rr(t),t}const bo=e=>(e.positionals?.length??0)===0?{kind:`unconditional`}:void 0,xo=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},So=new Set([`status`,`get`]),Co=e=>No(e,So,`status`),wo=new Set([`get`,`wait`]),To=e=>No(e,wo,`get`),Eo=e=>Po(e,So,`status`),Do=e=>Po(e,wo,`get`),Oo=e=>{try{return Rn(Jn(e.positionals??[]).action)?`observes-app`:`mutates-app`}catch{return`mutates-app`}},ko=e=>Po(e,new Set([`read`]),``),Ao=e=>mo(e.positionals).kind===`read`,jo=e=>Ao(e)?`observes-app`:`mutates-app`,Mo=e=>Ao(e)?`preserve`:`may-invalidate`;function No(e,t,n){return t.has((e.positionals?.[0]??n).toLowerCase())?`preserve`:`may-invalidate`}function Po(e,t,n){return t.has((e.positionals?.[0]??n).toLowerCase())?`observes-app`:`mutates-app`}const Fo=3e4,Io=32e4,Lo=2147453647,Ro=24e4,zo=3e5,H={budget:{source:`none`},envelopeMs:9e4,onTimeout:`reset-daemon`},Bo={...H,daemonDeadlineMs:6e4},Vo={batch:Bo,replay:{...Bo,budget:{source:`flag`,envelope:`margin`}}},Ho={budget:{source:`none`},envelopeMs:255e3,onTimeout:`reset-daemon`};function Uo(e,t){if(e.envelopeMs===`unbounded`)return;let n=Go(e,t);if(n!==void 0)return n+Fo;let r={...e,envelopeMs:e.envelopeMs};return Ko(r,t.positionals??[])??qo(r,t.flags)??r.envelopeMs}function Wo(e,t){let n=Uo(e,t);return n===void 0?void 0:n-Fo}function Go(e,t){if(e.daemonDeadlineMs!==void 0)return e.budget.source===`flag`&&typeof t.flags?.timeoutMs==`number`?t.flags.timeoutMs:e.daemonDeadlineMs}function Ko(e,t){if(e.budget.source!==`positional-parser`)return;let n=e.budget.parser(t);return n===null?void 0:Xo(e,n)}function qo(e,t){if(e.budget.source===`flag`)return e.budget.envelope===`widen`?Yo(e,e.budget,t):e.budget.envelope===`margin`?Jo(e,t):typeof t?.timeoutMs==`number`?t.timeoutMs:e.envelopeMs}function Jo(e,t){let n=typeof t?.timeoutMs==`number`?Xo(e,t.timeoutMs):e.envelopeMs;return typeof t?.waitMs==`number`?Zo({...e,envelopeMs:n},t.waitMs):n}function Yo(e,t,n){if(n?.settle!==!0)return e.envelopeMs;let r=typeof n.timeoutMs==`number`?n.timeoutMs:t.defaultBudgetMs;return typeof r==`number`?Zo(e,r):e.envelopeMs}function Xo(e,t){return Math.max(e.envelopeMs,t+Fo)}function Zo(e,t){return Math.max(e.envelopeMs,e.envelopeMs+t+Fo)}const Qo={click:`settle-and-verify`,press:`settle-and-verify`,fill:`settle-and-verify`,longpress:`settle`,hover:`settle`,scroll:`settle`,back:`settle`};function $o(e){if(e!==void 0)return Qo[e]}const es={leaseAdmissionExempt:!0,sessionExecutionLockExempt:!0},U={leaseAdmissionExempt:!0,sessionExecutionLockExempt:!0,selectorValidationExempt:!0},ts=()=>!0,ns=e=>(e.positionals?.[0]??``).toLowerCase()===`start`,rs=e=>e.command===`test`&&(typeof e.flags?.shardAll==`number`||typeof e.flags?.shardSplit==`number`),W={recordsSessionAction:!0,recordingEffect:`mutates-app`,deviceClaimPolicy:`require-owner`,daemon:{route:`generic`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},timeoutPolicy:H,batchable:!0,compositeResource:`none`},G={targetIdentityVerification:`pre-dispatch`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,deviceClaimPolicy:`require-owner`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0}},is={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}}},as={fields:{delayMs:{defaultValue:0}}};function K(e){let t=$o(e);if(t===void 0)throw Error(`Missing post-action observation descriptor support for ${e}`);return t}function q(e){if(!e)return null;let t=Number(e);return Number.isFinite(t)?t:null}const J={...H,onTimeout:`preserve-daemon`},os={...H,envelopeMs:48e4},ss={...os,envelopeMs:6e5,daemonDeadlineMs:57e4},cs={...H,onTimeout:`preserve-daemon`},ls={...cs,envelopeMs:33e4},us={...H,budget:{source:`flag`,envelope:`widen`,defaultBudgetMs:1e4},onTimeout:`preserve-daemon`};function Y(e,t){return $o(e)===void 0?t:us}function ds(e){if((e[0]??`get`).toLowerCase()!==`wait`)return null;let t=q(e[1]);return t===null||t<=0||t>2147453647?null:t}const fs={...H,budget:{source:`positional-parser`,parser:ds}},ps=I({required:[`deployApp`],conditional:[`ensureReady`]}),ms=I({required:[`uninstallApp`]}),hs=I({required:[`ensureReady`,`materializeAppSource`,`deployMaterializedApp`]}),gs=I({required:[`ensureReady`,`sendPushNotification`]}),_s=I({required:[`resolveOpenTarget`,`prepareApplicationOpen`,`openApplication`]}),vs=I({required:[`resolveOpenTarget`,`prepareApplicationOpen`,`openApplication`,`applyRuntimeHints`]}),ys=I({required:[`resolveOpenTarget`,`prepareApplicationOpen`,`openApplication`,`clearRuntimeHints`]}),bs=I({required:[`resolveOpenTarget`,`prepareApplicationOpen`,`openApplication`,`applyRuntimeHints`,`clearRuntimeHints`]});function xs(e){return e.applyRuntimeHints&&e.clearRemovedRuntimeHints?Object.freeze({kind:`open-apply-and-clear-runtime-hints`,use:bs}):e.applyRuntimeHints?Object.freeze({kind:`open-apply-runtime-hints`,use:vs}):e.clearRemovedRuntimeHints?Object.freeze({kind:`open-clear-runtime-hints`,use:ys}):Object.freeze({kind:`open`,use:_s})}const Ss=Object.freeze([_s,vs,ys,bs]),Cs=I({required:[`closeApplication`,`finalizeApplicationClose`],conditional:[`shutdownTarget`]}),ws=I({required:[`closeApplication`,`finalizeApplicationClose`,`clearRuntimeHints`],conditional:[`shutdownTarget`]}),Ts=I({required:[`resolveOpenTarget`]}),Es=Object.freeze([Cs,ws,Ts]),Ds=I({required:[`finalizeApplicationClose`]}),Os=I({required:[`finalizeApplicationClose`,`clearRuntimeHints`]}),ks=I({required:[`prepareAppleRunner`]}),As=I({required:[`clearRuntimeHints`]}),js=I({required:[`configureProviderPortReverse`]}),Ms=Object.freeze([As,js]),X=I({required:[`appLogInspect`]}),Ns=I({required:[`appLogInspect`,`appLogDoctor`]}),Ps=I({required:[`appLogInspect`,`appLogStart`]}),Fs=I({required:[],preferred:[`appLogInspect`]}),Is=Object.freeze([X,Ns,Ps]);function Ls(e){let t=(e.action??`path`).toLowerCase();if(e.restart&&t!==`clear`)throw new i(`INVALID_ARGS`,`logs --restart is only supported with logs clear`);switch(t){case`path`:return Object.freeze({kind:`path`,requiresAppSession:!1,use:X});case`start`:return Object.freeze({kind:`start`,requiresAppSession:!0,use:Ps});case`stop`:return Object.freeze({kind:`stop`,requiresAppSession:!1,use:X});case`doctor`:return Object.freeze({kind:`doctor`,requiresAppSession:!1,use:Ns});case`mark`:return Object.freeze({kind:`mark`,marker:e.marker??``,requiresAppSession:!1,use:X});case`clear`:return e.restart?Object.freeze({kind:`clear-restart`,requiresAppSession:!0,use:Ps}):Object.freeze({kind:`clear`,requiresAppSession:!1,use:X});default:throw new i(`INVALID_ARGS`,`logs requires path, start, stop, doctor, mark, or clear`)}}const Rs=I({required:[`audioProbeStart`]}),zs=I({required:[`audioProbeReattach`,`audioProbeCleanup`]}),Bs=I({required:[`audioProbeQuery`]}),Vs=Object.freeze([Rs,zs,Bs]);function Hs(e){if(e.mode===`query`)return Object.freeze({kind:`query`,action:e.probeAction,use:Bs});switch(e.probeAction){case`start`:return Object.freeze({kind:`capture-start`,use:Rs});case`status`:return Object.freeze({kind:`capture-status`});case`stop`:return Object.freeze({kind:`capture-stop`})}}const Us=[`probe`],Ws=[`start`,`status`,`stop`];function Gs(e){let t=(e?.[0]??`probe`).toLowerCase();if(!Us.includes(t))throw new i(`INVALID_ARGS`,`audio requires probe`);let n=(e?.[1]??`status`).toLowerCase();if(!Ws.includes(n))throw new i(`INVALID_ARGS`,`audio probe requires ${Ws.join(`, `)}`);if(n!==`start`&&e&&e.length>2)throw new i(`INVALID_ARGS`,`audio probe duration and bucket are only supported with audio probe start`);return Object.freeze({probeAction:n,durationMs:Ks(e?.[2],{defaultValue:1e4,min:100,max:12e4,message:`audio probe duration must be an integer in range 100..120000 ms`}),bucketMs:Ks(e?.[3],{defaultValue:1e3,min:100,max:1e4,message:`audio probe bucket must be an integer in range 100..10000 ms`})})}function Ks(e,t){if(e===void 0)return t.defaultValue;let n=Number.parseInt(e,10);if(!Number.isInteger(n)||String(n)!==e||n<t.min||n>t.max)throw new i(`INVALID_ARGS`,t.message);return n}const qs=I({required:[`networkDump`]}),Js=I({required:[],preferred:[`networkDump`]}),Ys=[`dump`,`log`],Xs=[`summary`,`headers`,`body`,`all`];function Zs(e){let t=(e.action??`dump`).toLowerCase(),n=(e.include??`summary`).toLowerCase();if(!Qs(t))throw new i(`INVALID_ARGS`,`network requires dump or log`);if(!$s(n))throw new i(`INVALID_ARGS`,`network --include must be summary, headers, body, or all`);return Object.freeze({action:t,include:n,use:qs})}function Qs(e){return Ys.some(t=>t===e)}function $s(e){return Xs.some(t=>t===e)}const Z={deviceClaimPolicy:`transient-exclusive`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`},platformExecution:{kind:`device-runtime`,use:ps},timeoutPolicy:os,batchable:!0,compositeResource:`none`},ec=[{name:`perf`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`},timeoutPolicy:H,batchable:!0,compositeResource:`operation`,platformExecution:{kind:`device-runtime`,uses:na}},{name:`logs`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`},platformExecution:{kind:`device-runtime`,uses:Is},timeoutPolicy:H,batchable:!0,compositeResource:`operation`},{name:`events`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`,allowInvalidRecording:!0,...U},timeoutPolicy:H,batchable:!1,platformExecution:V},{name:`network`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`},platformExecution:{kind:`device-runtime`,use:qs},timeoutPolicy:H,batchable:!0,compositeResource:`none`},{name:`audio`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`},timeoutPolicy:H,batchable:!0,compositeResource:`operation`,platformExecution:{kind:`device-runtime`,uses:Vs}},{name:`replay`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`delegated`,sessionKind:`replay`,skipSessionlessProviderDevice:rs,saveScriptFlagOwner:!0},timeoutPolicy:Vo.replay,batchable:!1,platformExecution:V},{name:`test`,deviceClaimPolicy:`none`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`delegated`,sessionKind:`replay`,skipSessionlessProviderDevice:rs},timeoutPolicy:{...H,envelopeMs:`unbounded`},batchable:!0,compositeResource:`nested-test`,platformExecution:V},{name:`runtime`,compositeResource:`none`,deviceClaimPolicy:`require-owner`,catalog:{group:`internal`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`},timeoutPolicy:H,batchable:!1,platformExecution:{kind:`device-runtime`,uses:[...Ms,ba]}},{name:`clipboard`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:ko,daemon:{route:`session`,refFrameEffect:`preserve`},timeoutPolicy:H,batchable:!0,compositeResource:`none`,platformExecution:{kind:`device-runtime`,uses:lo}},{name:`keyboard`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:Eo,daemon:{route:`session`,refFrameEffect:Co,androidBlockingDialogGuard:!0},timeoutPolicy:H,batchable:!0,compositeResource:`none`,platformExecution:{kind:`device-runtime`,uses:_o}},{name:`install`,...Z,daemon:{...Z.daemon,androidAvdSelection:`include-stopped`}},{name:`reinstall`,...Z,daemon:{...Z.daemon,androidAvdSelection:`include-stopped`}},{name:`uninstall`,...Z,platformExecution:{kind:`device-runtime`,use:ms}},{name:`install_source`,compositeResource:`none`,deviceClaimPolicy:`transient-exclusive`,catalog:{group:`internal`,key:`installSource`,servesPublicCommand:`install-from-source`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`,androidAvdSelection:`include-stopped`},platformExecution:{kind:`device-runtime`,use:hs},timeoutPolicy:ss,batchable:!1},{name:`release_materialized_paths`,compositeResource:`none`,deviceClaimPolicy:`none`,catalog:{group:`internal`,key:`releaseMaterializedPaths`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,...U},timeoutPolicy:H,batchable:!1,platformExecution:V},{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:gs},timeoutPolicy:H,batchable:!0,compositeResource:`none`},{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:H,batchable:!0,compositeResource:`none`,platformExecution:{kind:`device-runtime`,uses:[Vi]}},{name:`open`,deviceClaimPolicy:`acquire-session`,catalog:{group:`public`},frameworkTier:`loop`,recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`,allowSessionlessDefaultDevice:ts,saveScriptFlagOwner:!0,appLease:`allowed`,androidAvdSelection:`include-stopped`},timeoutPolicy:{...H,budget:{source:`flag`,envelope:`margin`}},batchable:!0,compositeResource:`session-lifecycle`,platformExecution:{kind:`device-runtime`,uses:Ss}},{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:ks}},{name:`batch`,deviceClaimPolicy:`none`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`delegated`,appLease:`allowed`},timeoutPolicy:Vo.batch,batchable:!1,platformExecution:V},{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:bo,appLease:`allowed`},timeoutPolicy:H,batchable:!0,compositeResource:`session-lifecycle`,platformExecution:{kind:`device-runtime`,uses:Es}}],tc=new Set([`exists`,`present`,`appears`,`gone`,`disappears`]);function nc(e){let t=e[0];if(t===void 0)return null;let n=q(t);if(n!==null)return{kind:`sleep`,durationMs:n};let r=q(e.at(-1));return t===`text`?rc(e,r):t===`stable`?ic(e):t===`absent`?ac(e,r):t.startsWith(`@`)?{kind:`ref`,rawRef:t,timeoutMs:r}:sc(e,r)}function rc(e,t){return{kind:`text`,text:(t===null?e.slice(1).join(` `):e.slice(1,-1).join(` `)).trim(),timeoutMs:t}}function ic(e){let t=e.slice(1),n=t.length>1?q(t[1]):null;return{kind:`stable`,quietMs:t.length>0?q(t[0]):null,timeoutMs:n}}function ac(e,t){let n=t===null?e.slice(1):e.slice(1,-1),r=T(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:oc(n)}}function oc(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 sc(e,t){let n=t===null?e.slice():e.slice(0,-1),r=T(n);return r&&r.rest.length===0&&Nr(r.selectorExpression)?{kind:`selector`,selectorExpression:r.selectorExpression,timeoutMs:t}:cc(n,r)||{kind:`text`,text:(t===null?e.join(` `):e.slice(0,-1).join(` `)).trim(),timeoutMs:t}}function cc(e,t){for(let t of e){let n=it(t);if(n)return{kind:`invalid`,reason:`unknown-selector-key`,message:lc(n,e)}}return t&&t.rest.length>0?{kind:`invalid`,reason:`selector-shaped-text`,message:uc(t,e)}:e.some(e=>w(e))?{kind:`invalid`,reason:`selector-shaped-text`,message:dc(e)}:null}function lc(e,t){let n=t.join(` `),r=nt(e.key)?`role=${e.key} label="${e.value}"`:`label="${e.value}"`;return`Unknown selector key "${e.key}" in "${n}". Supported: ${et.join(`, `)}. Use wait '${r}' [timeoutMs] to wait for the selector, or wait text '${n}' [timeoutMs] to wait for the literal text "${n}".`}function uc(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 dc(e){let t=e.join(` `),n=e.filter(e=>!w(e)),r=e.filter(e=>w(e));if(n.length>0){let e=n[0],i=tc.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 (${et.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 fc(e){let t=nc(e);return t?t.kind===`sleep`?t.durationMs:t.kind===`invalid`?null:t.timeoutMs:null}const pc=I({required:[`screenRecordingStart`]}),mc=I({required:[`screenRecordingReattach`,`screenRecordingCleanup`]}),hc=I({required:[]}),gc=I({required:[],preferred:[`screenRecordingStart`]}),_c=Object.freeze([pc,mc]);function vc(e){switch((e.action??``).toLowerCase()){case`start`:if(!yc(e.scope??`app`))throw new i(`INVALID_ARGS`,`record scope must be app, device, or system`);return Object.freeze({kind:`start`,use:pc});case`stop`:return e.hasLiveHandle===!0?Object.freeze({kind:`stop-live`,use:hc}):Object.freeze({kind:`stop-recovery`,use:mc});default:throw new i(`INVALID_ARGS`,`record requires start or stop`)}}function yc(e){return e===`app`||e===`device`||e===`system`}const bc={captureAndSystem:[{name:`wait`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`loop`,recordsSessionAction:!0,recordingEffect:`observes-app`,targetIdentityVerification:`post-resolution`,daemon:{route:`snapshot`,refFrameEffect:`preserve`,appLease:`allowed`},timeoutPolicy:{...J,budget:{source:`positional-parser`,parser:fc}},batchable:!0,compositeResource:`none`,platformExecution:{kind:`device-runtime`,uses:qa}},{name:`alert`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`core`,recordsSessionAction:!0,recordingEffect:Do,daemon:{route:`snapshot`,refFrameEffect:To},timeoutPolicy:fs,batchable:!0,compositeResource:`none`,platformExecution:{kind:`device-runtime`,uses:go}},{name:`settings`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:jo,daemon:{route:`snapshot`,refFrameEffect:Mo},timeoutPolicy:H,batchable:!0,compositeResource:`none`,platformExecution:{kind:`device-runtime`,uses:uo}},{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:H,batchable:!0,compositeResource:`none`,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:ns},platformExecution:{kind:`device-runtime`,uses:_c},timeoutPolicy:J,batchable:!0,compositeResource:`operation`},{name:`trace`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`recordTrace`,refFrameEffect:`preserve`},timeoutPolicy:H,batchable:!0,compositeResource:`operation`,platformExecution:V}],interactionAndHardware:[{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:Y(`click`,J),postActionObservation:K(`click`),responseDataTransform:is,batchable:!0,compositeResource:`none`,platformExecution:{kind:`device-runtime`,uses:ua}},{name:`fill`,...G,daemon:{...G.daemon,appLease:`allowed`},frameworkTier:`loop`,timeoutPolicy:Y(`fill`,J),postActionObservation:K(`fill`),responseDataTransform:as,batchable:!0,compositeResource:`none`,platformExecution:{kind:`device-runtime`,uses:ma}},{name:`longpress`,...G,catalog:{group:`public`,key:`longPress`},frameworkTier:`extended`,timeoutPolicy:{...us,envelopeMs:32e4},postActionObservation:K(`longpress`),batchable:!0,compositeResource:`none`,platformExecution:{kind:`device-runtime`,uses:fa}},{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:Y(`hover`,J),postActionObservation:K(`hover`),batchable:!0,compositeResource:`none`,platformExecution:{kind:`device-runtime`,uses:pa}},{name:`press`,...G,daemon:{...G.daemon,appLease:`allowed`},frameworkTier:`loop`,timeoutPolicy:Y(`press`,J),postActionObservation:K(`press`),responseDataTransform:is,batchable:!0,compositeResource:`none`,platformExecution:{kind:`device-runtime`,uses:da}},{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:Y(`type`,J),batchable:!0,compositeResource:`none`,platformExecution:{kind:`device-runtime`,uses:[hi]}},{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:Y(`get`,J),batchable:!0,compositeResource:`none`,platformExecution:{kind:`device-runtime`,uses:Va}},{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:Y(`is`,J),batchable:!0,compositeResource:`none`,platformExecution:{kind:`device-runtime`,uses:Ba}},{name:`back`,catalog:{group:`public`},frameworkTier:`loop`,...W,timeoutPolicy:Y(`back`,H),postActionObservation:K(`back`),platformExecution:{kind:`device-runtime`,uses:[gi]}},{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:H,batchable:!0,compositeResource:`none`,platformExecution:{kind:`device-runtime`,uses:wa}},{name:`home`,catalog:{group:`public`},frameworkTier:`extended`,...W,platformExecution:{kind:`device-runtime`,uses:[_i]}},{name:`tv-remote`,catalog:{group:`public`,key:`tvRemote`},frameworkTier:`extended`,...W,platformExecution:{kind:`device-runtime`,uses:[Ci]}},{name:`orientation`,catalog:{group:`public`},frameworkTier:`extended`,...W,platformExecution:{kind:`device-runtime`,uses:bi}},{name:`fold`,catalog:{group:`public`},frameworkTier:`extended`,...W,timeoutPolicy:Ho,platformExecution:{kind:`device-runtime`,uses:[xi]}},{name:`telephony`,catalog:{group:`public`},frameworkTier:`extended`,...W,daemon:{...W.daemon,androidBlockingDialogGuard:!1},platformExecution:{kind:`device-runtime`,uses:[Si]}},{name:`scroll`,catalog:{group:`public`},frameworkTier:`loop`,...W,daemon:{...W.daemon,appLease:`allowed`},timeoutPolicy:Y(`scroll`,H),postActionObservation:K(`scroll`),platformExecution:{kind:`device-runtime`,uses:Ea}},{name:`swipe`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`core`,recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},timeoutPolicy:H,batchable:!0,compositeResource:`none`,platformExecution:{kind:`device-runtime`,uses:Ta}},{name:`focus`,catalog:{group:`public`},frameworkTier:`extended`,...W,daemon:{...W.daemon,appLease:`allowed`},platformExecution:{kind:`device-runtime`,uses:[mi]}},{name:`screenshot`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`core`,recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`generic`,refFrameEffect:`preserve`,appLease:`allowed`},timeoutPolicy:H,batchable:!0,compositeResource:`none`,platformExecution:{kind:`device-runtime`,uses:eo}},{name:`viewport`,compositeResource:`none`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`generic`,refFrameEffect:`may-invalidate`},timeoutPolicy:H,batchable:!1,platformExecution:{kind:`device-runtime`,uses:[pi]}},{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:H,batchable:!0,compositeResource:`none`,platformExecution:{kind:`device-runtime`,uses:[Di]}},{name:`action-button`,catalog:{group:`public`,key:`actionButton`},frameworkTier:`extended`,...W,platformExecution:{kind:`device-runtime`,uses:[Oi]}},{name:`hardware-button`,catalog:{group:`public`,key:`hardwareButton`},frameworkTier:`extended`,...W,platformExecution:{kind:`device-runtime`,uses:Bi}},{name:`install-from-source`,deviceClaimPolicy:`none`,catalog:{group:`public`,key:`installFromSource`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`mutates-app`,platformExecution:{kind:`device-runtime`,use:hs},timeoutPolicy:ss,batchable:!0,compositeResource:`none`}]};function xc(e){let t=new Map;for(let n of e){if(!a(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,Sc(n))}let n=o.filter(e=>!t.has(e));if(n.length>0)throw TypeError(`Missing platform family registrations: ${n.join(`, `)}`);let r=Object.freeze([...o]),i=Object.freeze(r.map(e=>Cc(t,e)));return Object.freeze({families:r,modules:i,get:e=>Cc(t,e)})}function Sc(e){return Object.freeze({...e})}function Cc(e,t){let n=e.get(t);if(!n)throw TypeError(`Missing platform family registration: ${t}`);return n}const wc=Object.freeze({kind:`device-inventory`}),Tc=[{name:`debug`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:H,batchable:!1,platformExecution:V},{name:`daemon`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:H,batchable:!1,mcpExposed:!1,platformExecution:vo},{name:`device`,deviceClaimPolicy:`observe`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:H,batchable:!1,mcpExposed:!1,platformExecution:V},{name:`metro`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:H,batchable:!1,platformExecution:V},{name:`session`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:H,batchable:!1,platformExecution:V},{name:`cdp`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:H,batchable:!1,mcpExposed:!1,platformExecution:V},{name:`auth`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:H,batchable:!1,mcpExposed:!1,platformExecution:V},{name:`plugins`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:H,batchable:!1,mcpExposed:!1,platformExecution:V},{name:`connect`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:H,batchable:!1,mcpExposed:!1,platformExecution:V},{name:`connection`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:H,batchable:!1,mcpExposed:!1,platformExecution:V},{name:`disconnect`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:H,batchable:!1,mcpExposed:!1,platformExecution:V},{name:`mcp`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:H,batchable:!1,mcpExposed:!1,platformExecution:V},{name:`proxy`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:H,batchable:!1,mcpExposed:!1,platformExecution:V},{name:`takeover`,deviceClaimPolicy:`observe`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:H,batchable:!1,mcpExposed:!1,platformExecution:{kind:`inventory`,use:wc}},{name:`react-devtools`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`,key:`reactDevtools`},recordsSessionAction:!1,timeoutPolicy:H,batchable:!1,mcpExposed:!1,platformExecution:V},{name:`web`,deviceClaimPolicy:`none`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:H,batchable:!1,mcpExposed:!1,platformExecution:vo}];function Ec(e){if(Rr(e),e.kind!==`device-runtime`||!(`uses`in e))throw Dc();let t=e.uses.map(Fr),n=_c.map(Fr),r=new Set(t),i=new Set(n);if(t.length!==n.length||r.size!==t.length||[...r].some(e=>!i.has(e)))throw Dc()}function Dc(){return TypeError(`Record runtime execution must declare exactly the uses selected by its two runtime-bearing plans`)}const Oc=e=>{let t=e.flags?.snapshotCustomActions===!0||e.input?.customActions===!0;return[!0,!1].map(e=>Za({customActions:t,hasActiveApp:e}).use)},kc=e=>{let t=e.positionals===void 0?void 0:Gn(e.positionals,e.flags),n=t?.ok?t.parsed.action:void 0;if(n===void 0||!(Rn(n)||n===`focus`||n===`type`))return Ka;let r=Ya(n);return[!0,!1].map(e=>Xa({hasActiveApp:e,intent:r}).use)},Ac=[{name:`human_control`,deviceClaimPolicy:`none`,catalog:{group:`internal`,key:`humanControl`},recordsSessionAction:!1,daemon:{route:`humanControl`,refFrameEffect:`preserve`,selectorValidationExempt:!0,skipSessionlessProviderDevice:ts},timeoutPolicy:H,batchable:!1,platformExecution:V},{name:`lease_allocate`,deviceClaimPolicy:`none`,catalog:{group:`internal`,key:`leaseAllocate`},recordsSessionAction:!1,daemon:{route:`lease`,refFrameEffect:`preserve`,...es},timeoutPolicy:ls,batchable:!1,platformExecution:V},{name:`lease_heartbeat`,deviceClaimPolicy:`none`,catalog:{group:`internal`,key:`leaseHeartbeat`},recordsSessionAction:!1,daemon:{route:`lease`,refFrameEffect:`preserve`,...es,appLease:`allowed`},timeoutPolicy:cs,batchable:!1,platformExecution:V},{name:`lease_release`,deviceClaimPolicy:`none`,catalog:{group:`internal`,key:`leaseRelease`},recordsSessionAction:!1,daemon:{route:`lease`,refFrameEffect:`preserve`,...es,appLease:`allowed`},timeoutPolicy:cs,batchable:!1,platformExecution:V},{name:`artifacts`,deviceClaimPolicy:`none`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`lease`,refFrameEffect:`preserve`,...es},timeoutPolicy:H,batchable:!1,platformExecution:V},{name:`session_list`,deviceClaimPolicy:`none`,catalog:{group:`internal`,key:`sessionList`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,...U},timeoutPolicy:H,batchable:!1,platformExecution:V},{name:`session_save_script`,deviceClaimPolicy:`none`,catalog:{group:`internal`,key:`sessionSaveScript`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`publication`},timeoutPolicy:H,batchable:!1,platformExecution:V},{name:`devices`,deviceClaimPolicy:`observe`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,lockPolicySelectorOverride:!0,...U},timeoutPolicy:H,batchable:!0,compositeResource:`none`,platformExecution:{kind:`inventory`,use:wc}},{name:`capabilities`,deviceClaimPolicy:`observe`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{androidAvdSelection:`include-stopped`,route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,lockPolicySelectorOverride:!0,preferExplicitDeviceOverExistingSession:!0,...U},timeoutPolicy:H,batchable:!0,compositeResource:`none`,platformExecution:V},{name:`doctor`,deviceClaimPolicy:`observe`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,lockPolicySelectorOverride:!0,allowSessionlessDefaultDevice:ts,...U},timeoutPolicy:H,batchable:!0,compositeResource:`none`,platformExecution:vo},{name:`apps`,deviceClaimPolicy:`observe`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{androidAvdSelection:`include-stopped`,route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,lockPolicySelectorOverride:!0,preferExplicitDeviceOverExistingSession:!0,sessionlessLeaseAdmissionExemption:xo},platformExecution:{kind:`device-runtime`,uses:[di]},timeoutPolicy:H,batchable:!0,compositeResource:`none`},{name:`boot`,deviceClaimPolicy:`transient-exclusive`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{androidAvdSelection:`include-stopped`,route:`session`,refFrameEffect:`may-invalidate`,sessionKind:`state`},platformExecution:{kind:`device-runtime`,uses:no},timeoutPolicy:{...H,budget:{source:`flag`,envelope:`margin`}},batchable:!0,compositeResource:`none`},{name:`shutdown`,deviceClaimPolicy:`transient-exclusive`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{androidAvdSelection:`include-stopped`,route:`session`,refFrameEffect:`may-invalidate`,sessionKind:`state`},platformExecution:{kind:`device-runtime`,use:co},timeoutPolicy:H,batchable:!0,compositeResource:`none`},{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:so},timeoutPolicy:H,batchable:!0,compositeResource:`none`},...ec,{name:`snapshot`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`loop`,recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`snapshot`,refFrameEffect:`preserve`,appLease:`allowed`},timeoutPolicy:{...J,budget:{source:`flag`}},batchable:!0,compositeResource:`none`,platformExecution:{kind:`device-runtime`,uses:Ja,selectUses:Oc}},{name:`diff`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`snapshot`,refFrameEffect:`preserve`},timeoutPolicy:H,batchable:!0,compositeResource:`none`,platformExecution:{kind:`device-runtime`,uses:Ja,selectUses:Oc}},{name:`audit`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`extended`,recordsSessionAction:!1,daemon:{route:`snapshot`,refFrameEffect:`preserve`,appLease:`allowed`},timeoutPolicy:J,batchable:!1,platformExecution:{kind:`device-runtime`,uses:Ja}},...bc.captureAndSystem,{name:`find`,deviceClaimPolicy:`require-owner`,catalog:{group:`public`},frameworkTier:`core`,recordsSessionAction:!0,recordingEffect:Oo,daemon:{route:`find`,refFrameEffect:`may-invalidate`,appLease:`allowed`},timeoutPolicy:J,batchable:!0,compositeResource:`none`,platformExecution:{kind:`device-runtime`,uses:Ka,selectUses:kc}},...bc.interactionAndHardware,...Tc],jc=new Set([`public`,`local-cli`]),Mc=new Set(Ac.filter(e=>jc.has(Uc(e))).map(e=>e.name));function Nc(e){let t=e.catalog.group===`internal`?e.catalog.servesPublicCommand:e.catalog.group===`public`?e.name:void 0;return t?{command:t,arguments:`original-required`,session:`same-session`}:void 0}const Q=Ac.map(e=>{let t=yo(e);return e.name===`record`&&Ec(t),{...e,mcpExposed:Vc(e),platformExecution:t,standaloneCommandProjection:Nc(e)}});function Pc(e){return Q.filter(t=>Uc(t)===e).map(e=>[Wc(e),e.name])}function Fc(){return Q.filter(e=>Hc(e)).map(e=>e.name).sort()}function Ic(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 Lc(){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 Rc(e){return $.get(e)?.compositeResource}function zc(e){return $.get(e)?.standaloneCommandProjection}function Bc(e){return Mc.has(e)}function Vc(e){return e.mcpExposed??Mc.has(e.name)}function Hc(e){return e.mcpExposed&&Bc(e.name)}function Uc(e){return e.catalog.group}function Wc(e){return e.catalog.key??e.name}const Gc=new Map(Array.from($.values(),e=>[e.name,e.timeoutPolicy])),Kc=new Map(Q.map(e=>[e.name,e.deviceClaimPolicy])),qc=new Map(Array.from($.values()).flatMap(e=>e.responseDataTransform?[[e.name,e.responseDataTransform]]:[]));function Jc(e){if(e!==void 0)return $.get(e)?.postActionObservation}function Yc(e){return Jc(e)!==void 0}function Xc(e){return Jc(e)===`settle-and-verify`}function Zc(e){return e===void 0?H:Gc.get(e)??H}function Qc(e){return e===void 0?`require-owner`:Kc.get(e)??`require-owner`}function $c(e){if(e!==void 0)return qc.get(e)}function el(e){return e===void 0?!1:$.get(e)?.recordsSessionAction??!1}function tl(e){if(e!==void 0)return $.get(e)?.frameworkTier}function nl(e){return $.get(e)?.targetIdentityVerification}function rl(e){let t=$.get(e.command);if(t?.recordsSessionAction)return typeof t.recordingEffect==`function`?t.recordingEffect(e):t.recordingEffect}function il(e){let t=rl(e);if(t!==void 0)return t===`observes-app`?`no`:`unknown`}function al(e){let t=$.get(e.command)?.daemon?.refFrameEffect;return(typeof t==`function`?t(e):t)===`delegated`}function ol(){return[...new Set(Array.from(qc.values()).flatMap(e=>Object.keys(e.fields)))].sort()}const sl={apps:{appsFilter:`user-installed`}};function cl(e,t){if(!e||!Bc(e))return!1;let n=sl[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 ll(e){let t=[];for(let n of e)n.daemon&&t.push({command:n.name,...n.daemon,replayScopedAction:n.recordsSessionAction});return t}function ul(e){return e.filter(e=>e.batchable).map(e=>e.name)}const dl=ul(Q),fl=new Set([`batch`,`replay`]),pl=[`command`,`positionals`,`input`,`flags`,`runtime`],ml=[`platform`,`target`,`device`,`udid`,`serial`,`verbose`,`out`,`testIme`],hl=`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.`,gl=new Set(dl);function _l(e){return gl.has(e)}function vl(e){let t=Rt(e);return _l(t)?t:void 0}function yl(e,t,n=hl){let r=vl(e);if(r!==void 0)return r;throw new i(`INVALID_ARGS`,`Batch step ${t} command is not available through command batch: ${String(e)}`,{hint:n})}function bl(e,t){if(fl.has(e))throw new i(`INVALID_ARGS`,`Batch step ${t} cannot run ${e}.`)}export{xs as $,or as $n,T as $r,Qi as $t,vc as A,Ce as Ai,Xr as An,D as Ar,I as At,Ls as B,p as Bi,br as Bn,Tt as Br,Ei as Bt,rl as C,h as Ci,Pi as Cn,wn as Cr,gi as Ct,Zc as D,Se as Di,qr as Dn,rn as Dr,ra as Dt,zc as E,ye as Ei,Jr as En,en as Er,aa as Et,Zs as F,ue as Fi,Mr as Fn,It as Fr,xi as Ft,Ds as G,f as Gi,hr as Gn,_t as Gr,Fi as Gt,Cs as H,ie as Hi,_r as Hn,Ot as Hr,ia as Ht,zs as I,le as Ii,kr as In,Mt as Ir,ba as It,bs as J,ee as Ji,ir as Jn,et as Jr,Mi as Jt,Os as K,d as Ki,gr as Kn,bt as Kr,Li as Kt,Gs as L,fe as Li,jr as Ln,Pt as Lr,_i as Lt,mc as M,he as Mi,ei as Mn,Lt as Mr,ca as Mt,nc as N,me as Ni,Nr as Nn,Rt as Nr,Ya as Nt,nl as O,be as Oi,Yr as On,on as Or,Ji as Ot,Js as P,de as Pi,wr as Pn,Ft as Pr,mi as Pt,Ts as Q,tr as Qn,S as Qr,Zi as Qt,Hs as R,oe as Ri,Ar as Rn,jt as Rr,oa as Rt,tl as S,Te as Si,ki as Sn,Sn as Sr,di as St,$c as T,g as Ti,ti as Tn,nn as Tr,sa as Tt,ws as U,te as Ui,yr as Un,Dt as Ur,zi as Ut,As as V,re as Vi,Sr as Vn,kt as Vr,wi as Vt,js as W,ae as Wi,xr as Wn,At as Wr,Ii as Wt,ys as X,c as Xi,rr as Xn,nt as Xr,yi as Xt,vs as Y,l as Yi,sr as Yn,it as Yr,vi as Yt,ks as Z,nr as Zn,w as Zr,Xi as Zt,Fc as _,_ as _i,Si as _n,Dn as _r,Wi as _t,bl as a,Be as ai,ka as an,Rn as ar,$o as at,Qc as b,we as bi,pi as bn,k as br,oo as bt,ll as c,Je as ci,Xa as cn,Xn as cr,zo as ct,Ic as d,Fe as di,ha as dn,Nn as dr,Wo as dt,C as ei,ea as en,Fn as er,ps as et,Yc as f,Re as fi,Ui as fn,Tn as fr,Go as ft,Pc as g,je as gi,L as gn,vn as gr,qi as gt,ol as h,Le as hi,Ni as hn,On as hr,Ki as ht,dl as i,Ye as ii,ao as in,zn as ir,q as it,gc as j,pe as ji,$r as jn,E as jr,li as jt,xc as k,ve as ki,Qr as kn,Xt as kr,Yi as kt,cl as l,Ve as li,mo as ln,Mn as lr,Lo as lt,al as m,Ie as mi,co as mn,jn as mr,Oi as mt,pl as n,y as ni,ta as nn,Wn as nr,gs as nt,yl as o,qe as oi,to as on,Ln as or,Vo as ot,Xc as p,Pe as pi,Hi as pn,bn as pr,Uo as pt,_s as q,u as qi,ar as qn,yt as qr,Ri as qt,ml as r,Xe as ri,ji as rn,Gn as rr,ms as rt,vl as s,Ke as si,Aa as sn,Jn as sr,Io as st,hl as t,b as ti,$i as tn,Un as tr,hs as tt,Q as u,Ue as ui,Za as un,j as ur,Ro as ut,Lc as v,Ae as vi,Ci as vn,En as vr,Gi as vt,el as w,Ee as wi,Kr as wn,Vt as wr,la as wt,il as x,xe as xi,Ai as xn,Cn as xr,Di as xt,Rc as y,Me as yi,hi as yn,xn as yr,Vi as yt,Fs as z,se as zi,Pr as zn,Et as zr,Ti as zt};