agent-device 0.14.8 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -6
- package/android-snapshot-helper/README.md +4 -2
- package/android-snapshot-helper/dist/{agent-device-android-snapshot-helper-0.14.8.apk → agent-device-android-snapshot-helper-0.15.0.apk} +0 -0
- package/android-snapshot-helper/dist/agent-device-android-snapshot-helper-0.15.0.apk.sha256 +1 -0
- package/android-snapshot-helper/dist/{agent-device-android-snapshot-helper-0.14.8.manifest.json → agent-device-android-snapshot-helper-0.15.0.manifest.json} +6 -6
- package/dist/src/1769.js +7 -0
- package/dist/src/2151.js +429 -0
- package/dist/src/221.js +4 -4
- package/dist/src/2842.js +1 -0
- package/dist/src/3572.js +1 -0
- package/dist/src/4057.js +1 -1
- package/dist/src/840.js +2 -0
- package/dist/src/9542.js +2 -2
- package/dist/src/9639.js +2 -2
- package/dist/src/9818.js +1 -1
- package/dist/src/android-adb.d.ts +49 -11
- package/dist/src/android-adb.js +1 -1
- package/dist/src/android-snapshot-helper.d.ts +35 -2
- package/dist/src/cli.js +60 -57
- package/dist/src/contracts.d.ts +2 -0
- package/dist/src/finders.d.ts +2 -0
- package/dist/src/index.d.ts +25 -22
- package/dist/src/internal/companion-tunnel.js +1 -1
- package/dist/src/internal/daemon.js +51 -23
- package/dist/src/remote-config.d.ts +17 -14
- package/dist/src/selectors.d.ts +3 -0
- package/dist/src/server.js +2 -20
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunner.xcodeproj/xcshareddata/xcschemes/AgentDeviceRunner.xcscheme +7 -1
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +210 -56
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift +890 -99
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Lifecycle.swift +94 -7
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +8 -0
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Snapshot.swift +24 -0
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SystemModal.swift +2 -0
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TvRemote.swift +185 -0
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift +1 -2
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests.xctestplan +26 -0
- package/package.json +25 -11
- package/server.json +3 -3
- package/skills/agent-device/SKILL.md +6 -1
- package/skills/dogfood/SKILL.md +3 -1
- package/android-snapshot-helper/dist/agent-device-android-snapshot-helper-0.14.8.apk.sha256 +0 -1
- package/dist/src/180.js +0 -1
- package/dist/src/6108.js +0 -26
- package/dist/src/6642.js +0 -1
- package/dist/src/7462.js +0 -1
- package/dist/src/8809.js +0 -8
- package/dist/src/command-schema.js +0 -381
- package/skills/react-devtools/SKILL.md +0 -48
package/dist/src/2151.js
ADDED
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
let e,t,a,n,r,i,s,o;import{promises as l}from"node:fs";import{PNG as c}from"pngjs";import d from"node:path";import{normalizeRef as p,centerOfRect as u,buildSnapshotPresentationKey as h,findNodeByRef as m}from"./4057.js";import{isScrollableNodeLike as f}from"./2842.js";import{asAppError as g,AppError as b}from"./9152.js";import{SCREENSHOT_SPECIFIC_FLAG_DEFINITIONS as w,SCREENSHOT_COMMAND_FLAG_KEYS as y,PUBLIC_COMMANDS as v,ALL_DEVICE_COMMAND_CAPABILITY as k,defineCommand as x,INTERACTION_COMMAND_SCHEMAS as A,successText as D,commandCapabilityMap as I,commandSchemaMap as R}from"./3572.js";import{resolveAppsFilter as S,DEFAULT_APPS_FILTER as M,assertResolvedAppsFilter as N}from"./840.js";import{whichCmd as O,runCmd as L}from"./9818.js";import{trimText as P,extractNodeText as E,parseSelectorChain as C,isNodeVisible as U,isNodeEditable as T,buildTextPreview as _,findNearestHittableAncestor as $,buildSelectorChainForNode as F,findSelectorChainMatch as B,resolveSelectorChain as q,findNodeByLabel as G,resolveRefLabel as j,describeTextSurface as V,extractReadableText as X,formatSelectorFailure as Y,normalizeType as K,isFillableType as z}from"./940.js";import{findBestMatchesByLocator as H}from"./7556.js";import"./7847.js";function J(e,t,a){return t>=e.x&&t<=e.x+e.width&&a>=e.y&&a<=e.y+e.height}function W(e){let t=null,a=-1;for(let n of e){let e=n.width*n.height;e>a&&(t=n,a=e)}return t}function Q(e,t,a,n){return Math.max(e,a)<=Math.min(t,n)}function Z(e){let t=new Map;for(let[a,n]of e.entries())t.set(n.index,a);let a=[],n=[];for(let[r,i]of e.entries()){let e=Math.max(0,i.depth??0);for(;n.length>0&&e<=n[n.length-1].depth;)n.pop();let s="number"==typeof i.parentIndex?t.get(i.parentIndex):void 0,o="number"==typeof s&&s<r?s:n[n.length-1]?.index;a.push({...i,index:r,depth:e,parentIndex:o}),n.push({depth:e,index:r})}return a}function ee(e){return new Map(e.map(e=>[e.index,e]))}function et(e){return e.label?.trim()||e.value?.trim()||e.identifier?.trim()||""}function ea(e){if(0===e.length)return{nodes:e,hiddenCount:0,summaryLines:[]};let{byIndex:t,visibleNodeIndexes:a,offscreenNodes:n,hintedContainers:r}=er(e),i=0===a.size?e:e.filter(e=>a.has(e.index));return{nodes:i.map(e=>(function(e,t){let a=t.get(e.index);if(!a||0===a.size)return e;let n=!!(!0===e.hiddenContentAbove||a.has("above"))||void 0,r=!!(!0===e.hiddenContentBelow||a.has("below"))||void 0;return{...e,hiddenContentAbove:n,hiddenContentBelow:r}})(e,r.directionsByContainer)),hiddenCount:0===a.size?0:e.length-i.length,summaryLines:function(e,t,a){let n=new Map;for(let r of e){let e=function(e,t,a){if(!e.rect)return null;let n=es(e,t,a);return n?eo(e.rect,n):null}(r,t,a);if(!e)continue;let i=n.get(e)??[];i.push(r),n.set(e,i)}return["above","below"].flatMap(e=>{let t=n.get(e);if(!t||0===t.length)return[];let a=(function(e){let t=new Set,a=[];for(let n of e){let e=et(n);!e||t.has(e)||(t.add(e),a.push(e))}return a})(t).slice(0,3).map(e=>`"${e}"`),r=1===t.length?"interactive item":"interactive items",i=a.length>0?`: ${a.join(", ")}`:"";return[`[off-screen ${e}] ${t.length} ${r}${i}`]})}(n.filter(e=>!r.coveredNodeIndexes.has(e.index)&&function(e){if(!0===e.hittable)return!0;let t=(e.type??"").toLowerCase();return t.includes("button")||t.includes("link")||t.includes("textfield")||t.includes("edittext")||t.includes("searchfield")||t.includes("checkbox")||t.includes("radio")||t.includes("switch")||t.includes("menuitem")||!!et(e)}(e)),e,t)}}function en(e){if(0===e.length)return new Map;let{hintedContainers:t}=er(e);var a=t.directionsByContainer;let n=new Map;for(let[e,t]of a){let a={};t.has("above")&&(a.hiddenContentAbove=!0),t.has("below")&&(a.hiddenContentBelow=!0),(a.hiddenContentAbove||a.hiddenContentBelow)&&n.set(e,a)}return n}function er(e){let t=ee(e),a=new Set,n=[];for(let r of e){if(ei(r,e,t)){!function(e,t,a){let n=e,r=new Set;for(;n&&!r.has(n.index);)r.add(n.index),t.add(n.index),n="number"==typeof n.parentIndex?a.get(n.parentIndex):void 0}(r,a,t);continue}n.push(r)}let r=function(e,t,a,n){let r=new Map,i=new Set;for(let e of t){if(!e.rect)continue;let t=el(e,a,n);if(!t?.rect)continue;let s=eo(e.rect,t.rect);if(!s)continue;let o=r.get(t.index)??new Set;o.add(s),r.set(t.index,o),i.add(e.index)}return function(e,t,a,n){for(let r of e){let e=function(e){let t=function(e,t){if(!(e?.trim().toLowerCase()??"").includes("vertical scroll bar"))return null;let a=function(e){if(!e)return null;let t=/^(\d{1,3})%$/.exec(e.trim());if(!t)return null;let a=Number(t[1]);return Number.isFinite(a)?Math.max(0,Math.min(100,a)):null}(t);return null===a?null:a<=1?{above:!1,below:!0}:a>=99?{above:!0,below:!1}:{above:!0,below:!0}}(e.label,e.value);if(!t)return null;let a=new Set;return t.above&&a.add("above"),t.below&&a.add("below"),a.size>0?a:null}(r);if(!e||0===e.size)continue;let i=el(r,t,a);if(!i)continue;let s=n.get(i.index)??new Set;for(let t of e)s.add(t);n.set(i.index,s)}}(e,a,n,r),{directionsByContainer:r,coveredNodeIndexes:i}}(e,n,a,t);return{byIndex:t,visibleNodeIndexes:a,offscreenNodes:n,hintedContainers:r}}function ei(e,t,a=ee(t)){var n;if(!e.rect)return!0;let r=es(e,t,a);return!r||(n=e.rect,Q(n.x,n.x+n.width,r.x,r.x+r.width)&&Q(n.y,n.y+n.height,r.y,r.y+r.height))}function es(e,t,a=ee(t)){let n=function(e,t){let a="number"==typeof e.parentIndex?t.get(e.parentIndex):void 0,n=new Set;for(;a&&!n.has(a.index);){if(n.add(a.index),a.rect&&f(a))return a.rect;a="number"==typeof a.parentIndex?t.get(a.parentIndex):void 0}return null}(e,a);return n||function(e,t){let a=u(t),n=e.filter(e=>{var t;return!!(t=e.rect)&&Number.isFinite(t.x)&&Number.isFinite(t.y)&&Number.isFinite(t.width)&&Number.isFinite(t.height)}),r=n.filter(e=>{let t=(e.type??"").toLowerCase();return t.includes("application")||t.includes("window")}),i=W(r.map(e=>e.rect).filter(e=>J(e,a.x,a.y)));if(i)return i;let s=W(r.map(e=>e.rect));if(s)return s;let o=W(n.map(e=>e.rect).filter(e=>J(e,a.x,a.y)));return o||null}(t,e.rect??{x:0,y:0,width:0,height:0})}function eo(e,t){return e.y+e.height<=t.y?"above":e.y>=t.y+t.height?"below":null}function el(e,t,a){let n="number"==typeof e.parentIndex?a.get(e.parentIndex):void 0,r=new Set;for(;n&&!r.has(n.index);){if(r.add(n.index),t.has(n.index)&&f(n))return n;n="number"==typeof n.parentIndex?a.get(n.parentIndex):void 0}return null}let ec="<wifi|airplane|location> <on|off>",ed="location set <lat> <lon>",ep="animations <on|off>",eu="appearance <light|dark|toggle>",eh="faceid <match|nonmatch|enroll|unenroll>",em="touchid <match|nonmatch|enroll|unenroll>",ef="fingerprint <match|nonmatch>",eg="permission <grant|deny|reset> <camera|microphone|photos|contacts|contacts-limited|notifications|calendar|location|location-always|media-library|motion|reminders|siri> [full|limited]",eb="permission <grant|reset> <accessibility|screen-recording|input-monitoring>",ew=`macOS supports only settings ${eu} and settings ${eb}. wifi|airplane|location|animations remain unsupported on macOS.`,ey=`settings ${ec} | settings ${ed} | settings ${ep} | settings ${eu} | settings ${eh} | settings ${em} | settings ${ef} | settings ${eg} | settings ${eb}`,ev=`settings requires ${ec}, ${ed}, ${ep}, ${eu}, ${eh}, ${em}, ${ef}, ${eg}, or ${eb}`;function ek(e){let t=e.trim().toLowerCase();return"appearance"===t||"permission"===t}function ex(e){return`Unsupported macOS setting: ${e}. ${ew}`}function eA(e){let t=e?.trim().split(/\s+/,1)[0];if(!t||!t.startsWith("@")||t.length<3)return null;let a=t.slice(1);return/^[A-Za-z_-]*\d[\w-]*$/i.test(a)||/^(?:ref|node|element|el)[\w-]*$/i.test(a)?t:null}function eD(e,t,a,n){if(!Number.isFinite(e)||!Number.isInteger(e)||e<a||e>n)throw new b("INVALID_ARGS",`${t} must be an integer between ${a} and ${n}`);return e}function eI(e){if(void 0===e)throw new b("INVALID_ARGS","rotate requires an orientation argument. Use portrait|portrait-upside-down|landscape-left|landscape-right.");switch(e?.trim().toLowerCase()){case"portrait":return"portrait";case"portrait-upside-down":case"upside-down":return"portrait-upside-down";case"landscape-left":case"left":return"landscape-left";case"landscape-right":case"right":return"landscape-right";default:throw new b("INVALID_ARGS",`Invalid rotation: ${e}. Use portrait|portrait-upside-down|landscape-left|landscape-right.`)}}let eR=["snapshotInteractiveOnly","snapshotCompact","snapshotDepth","snapshotScope","snapshotRaw"],eS=[x({name:v.snapshot,schema:{usageOverride:"snapshot [--diff] [-i] [-c] [-d <depth>] [-s <scope>] [--raw] [--force-full]",helpDescription:"Capture accessibility tree or diff against the previous session baseline",positionalArgs:[],allowedFlags:["snapshotDiff",...eR,"snapshotForceFull"]},capability:k}),x({name:v.diff,schema:{usageOverride:"diff snapshot | diff screenshot --baseline <path> [current.png] [--out <diff.png>] [--threshold <0-1>] [--overlay-refs]",helpDescription:"Diff accessibility snapshot or compare screenshots pixel-by-pixel",summary:"Diff snapshot or screenshot",positionalArgs:["kind","current?"],allowedFlags:[...eR,"baseline","threshold","out","overlayRefs"]},capability:k}),x({name:v.screenshot,schema:{helpDescription:"Capture screenshot (macOS app sessions default to the app window; use --fullscreen for full desktop, --max-size to downscale, --overlay-refs to annotate current refs, or --no-stabilize for low-latency Android capture loops)",positionalArgs:["path?"],allowedFlags:y},capability:k})],eM=R(eS),eN=I(eS),eO=["snapshotDepth","snapshotScope","snapshotRaw"],eL=[x({name:v.wait,schema:{usageOverride:"wait <ms>|text <text>|@ref|<selector> [timeoutMs]",helpDescription:"Wait for duration, text, ref, or selector to appear",summary:"Wait for time, text, ref, or selector",positionalArgs:["durationOrSelector","timeoutMs?"],allowsExtraPositionals:!0,allowedFlags:[...eO]},capability:k}),x({name:v.get,schema:{usageOverride:"get text|attrs <@ref|selector>",helpDescription:"Return exposed element text/attributes by ref or selector; use snapshot -s @ref for truncated previews",summary:"Get exposed text or attrs by ref or selector",positionalArgs:["subcommand","target"],allowedFlags:[...eO]},capability:k}),x({name:v.find,schema:{usageOverride:"find <locator|text> <action> [value] [--first|--last]",helpDescription:"Find by text/label/value/role/id and run action",summary:"Find an element and act",positionalArgs:["query","action","value?"],allowsExtraPositionals:!0,allowedFlags:["snapshotDepth","snapshotRaw","findFirst","findLast"]},capability:k}),x({name:v.is,schema:{helpDescription:"Assert UI state (visible|hidden|exists|editable|selected|text)",summary:"Assert UI state",positionalArgs:["predicate","selector","value?"],allowsExtraPositionals:!0,allowedFlags:[...eO]},capability:k})],eP=R(eL),eE=I(eL),eC={apple:{simulator:!0,device:!0},android:{emulator:!0,device:!0,unknown:!0},linux:{device:!0}},eU={apple:{simulator:!0,device:!0},android:{emulator:!0,device:!0,unknown:!0},linux:{},supports:e=>"macos"!==e.platform},eT=[x({name:v.open,schema:{helpDescription:"Boot device/simulator; optionally launch app or deep link URL (macOS also supports --surface app|frontmost-app|desktop|menubar)",summary:"Open an app, deep link or URL, save replays",positionalArgs:["appOrUrl?","url?"],allowedFlags:["activity","saveScript","relaunch","surface"]},capability:eC}),x({name:v.close,schema:{helpDescription:"Close app or just end session",summary:"Close app or end session",positionalArgs:["app?"],allowedFlags:["saveScript","shutdown"]},capability:eC}),x({name:v.reinstall,schema:{helpDescription:"Uninstall + install app from binary path",summary:"Reinstall app from binary path",positionalArgs:["app","path"],allowedFlags:[]},capability:eU}),x({name:v.install,schema:{helpDescription:"Install app from binary path without uninstalling first",summary:"Install app from binary path",positionalArgs:["app","path"],allowedFlags:[]},capability:eU}),x({name:v.installFromSource,schema:{usageOverride:"install-from-source <url> | install-from-source --github-actions-artifact <owner/repo:artifact>",listUsageOverride:"install-from-source <url> | install-from-source --github-actions-artifact",helpDescription:"Install app from a URL or remote-resolved source",summary:"Install app from a source",positionalArgs:["url?"],allowedFlags:["header","githubActionsArtifact","installSource","retainPaths","retentionMs"]},capability:eU}),x({name:v.apps,schema:{helpDescription:"List user-installed apps; use --all to include system/OEM apps",summary:"List installed apps",positionalArgs:[],allowedFlags:["appsFilter"],defaults:{appsFilter:M}},capability:{apple:{simulator:!0,device:!0},android:{emulator:!0,device:!0,unknown:!0},linux:{}}})],e_=R(eT),e$=I(eT);function eF(e,t){try{return c.sync.read(e)}catch(e){throw new b("COMMAND_FAILED",`Failed to decode ${t} as PNG`,{label:t,reason:e instanceof Error?e.message:String(e)})}}async function eB(e,t){if(!Number.isInteger(t)||t<1)throw new b("INVALID_ARGS","Screenshot max size must be a positive integer");let a=eF(await l.readFile(e),"screenshot"),n=Math.max(a.width,a.height);if(n<=t)return;let r=t/n,i=Math.max(1,Math.round(a.width*r)),s=Math.max(1,Math.round(a.height*r)),o=function(e,t,a){let n=new c({width:t,height:a});for(let r=0;r<a;r+=1){let i=r*e.height/a,s=(r+1)*e.height/a;for(let a=0;a<t;a+=1){let o=a*e.width/t,l=(a+1)*e.width/t,c=0,d=0,p=0,u=0,h=0;for(let t=Math.floor(i);t<Math.ceil(s);t+=1){let a=Math.min(t+1,s)-Math.max(t,i);for(let n=Math.floor(o);n<Math.ceil(l);n+=1){let r=a*(Math.min(n+1,l)-Math.max(n,o)),i=(t*e.width+n)*4;c+=(e.data[i]??0)*r,d+=(e.data[i+1]??0)*r,p+=(e.data[i+2]??0)*r,u+=(e.data[i+3]??0)*r,h+=r}}let m=(r*n.width+a)*4;n.data[m]=Math.round(c/h),n.data[m+1]=Math.round(d/h),n.data[m+2]=Math.round(p/h),n.data[m+3]=Math.round(u/h)}}return n}(a,i,s);await l.writeFile(e,c.sync.write(o))}async function eq(e,t,a){if("path"===t.kind&&!e.policy.allowLocalInputPaths)throw new b("INVALID_ARGS",`Local ${a.field??"input"} paths are not allowed by command policy`);try{return await e.artifacts.resolveInput(t,a)}catch(e){throw g(e)}}async function eG(e,t,a){if(t?.kind==="path"&&!e.policy.allowLocalOutputPaths)throw new b("INVALID_ARGS","Local output paths are not allowed by command policy");try{return await e.artifacts.reserveOutput(t,{...a,visibility:a.visibility??"client-visible",requestedClientPath:t?.kind==="downloadableArtifact"?t.clientPath??a.requestedClientPath:a.requestedClientPath})}catch(e){throw g(e)}}async function ej(e,t){try{return await e.artifacts.createTempFile(t)}catch(e){throw g(e)}}let eV=async(e,t)=>{let a;if(!e.backend.captureScreenshot)throw new b("UNSUPPORTED_OPERATION","screenshot is not supported by this backend");let n=await eG(e,t.out,{field:"path",ext:".png"});try{await e.backend.captureScreenshot({session:t.session,requestId:t.requestId,appId:t.appId,appBundleId:t.appBundleId,signal:t.signal??e.signal,metadata:t.metadata},n.path,{fullscreen:t.fullscreen,overlayRefs:t.overlayRefs,stabilize:t.stabilize,surface:t.surface}),void 0!==t.maxSize&&await eB(n.path,t.maxSize),a=await n.publish()}catch(e){throw await n.cleanup?.(),e}return{path:n.path,...a?{artifacts:[a]}:{},...D(`Saved screenshot: ${n.path}`)}},eX=[0,187,255,255];function eY(e,t,a,n){if(t<0||t>=e.width||a<0||a>=e.height)return;let r=(a*e.width+t)*4;e.data[r]=n[0],e.data[r+1]=n[1],e.data[r+2]=n[2],e.data[r+3]=n[3]}function eK(e,t,a){return Math.min(Math.max(e,t),a)}let ez={icon:90,toggle:90,chevron:75,separator:45,visual:35,background:10},eH={leading:20,trailing:20,separator:10,unknown:0,background:-30};function eJ(e){return"background"!==e.likelyKind}function eW(e,t){return e.width>=.25*t.width||e.height>=.06*t.height}function eQ(e,t){let a,n=0;for(let r of t){let t=e5(e,r.rect);t<=n||(n=t,a=r)}return a}function eZ(e){let t=[];for(let a of[...e].sort((e,t)=>e.rect.y-t.rect.y)){let e=t.find(e=>{var t,n;return t=e.rect,e5(t,n=a.rect)>0||Math.abs(e3(t).y-e3(n).y)<=.5*Math.max(t.height,n.height)});if(!e){t.push({rect:a.rect,blocks:[a]});continue}e.blocks.push(a),e.blocks.sort((e,t)=>e.rect.x-t.rect.x),e.rect=function(e){let t=1/0,a=1/0,n=-1/0,r=-1/0;for(let i of e)t=Math.min(t,i.x),a=Math.min(a,i.y),n=Math.max(n,i.x+i.width),r=Math.max(r,i.y+i.height);return{x:t,y:a,width:n-t,height:r-a}}([e.rect,a.rect])}return t}function e0(e,t){let a,n=e3(e);for(let e of t){var r,i;let t=Math.sqrt((r=n,i=e3(e.rect),(r.x-i.x)**2+(r.y-i.y)**2));a&&t>=a.distance||(a={block:e,distance:t})}return a}function e1(e){let t=e2(e);return e.differentPixels>=24&&t.width>=3&&t.height>=3}function e2(e){return{x:e.minX,y:e.minY,width:e.maxX-e.minX+1,height:e.maxY-e.minY+1}}function e5(e,t){return Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y))}function e3(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function e4(e,t,a){return Math.min(Math.max(e,t),a)}async function e8(e){if(await O("tesseract"))try{let[t,a]=await Promise.all([e7(e.baselinePath),e7(e.currentPath)]);if(0!==t.exitCode||0!==a.exitCode)return;let n=e6(t.stdout,e.width,e.height),r=e6(a.stdout,e.width,e.height),i=function(e,t){let a=new Set,n=[];for(let i of e){var r;let e=ti(i.text),s=function(e,t,a,n){let r=null,i=1/0;for(let l=0;l<a.length;l+=1){var s,o;if(n.has(l))continue;let c=a[l];if(ti(c.text)!==t)continue;let d=(s=ta(e.normalizedRect),o=ta(c.normalizedRect),(s.x-o.x)**2+(s.y-o.y)**2);d>=i||(r=l,i=d)}return r}(i,e,t,a);if(null===s)continue;a.add(s);let o=function(e,t){let a={x:t.rect.x-e.rect.x,y:t.rect.y-e.rect.y,width:t.rect.width-e.rect.width,height:t.rect.height-e.rect.height},n=tl(t.rect.width/e.rect.width),r=tl(t.rect.height/e.rect.height),i=Math.abs(n-1)>=.08||Math.abs(r-1)>=.12;return{text:e.text,baselineRect:e.rect,currentRect:t.rect,delta:a,confidence:Math.round(100*Math.min(e.confidence,t.confidence))/100,possibleTextMetricMismatch:i}}(i,t[s]);r=o,(Math.abs(r.delta.x)>=2||Math.abs(r.delta.y)>=2||Math.abs(r.delta.width)>=2||Math.abs(r.delta.height)>=2||r.possibleTextMetricMismatch)&&n.push(o)}return n.sort((e,t)=>e9(t)-e9(e)).slice(0,12)}(n,r),s=function(e){let t=[];for(let a of[...e].sort((e,t)=>e.currentRect.y-t.currentRect.y)){let e=t.find(e=>32>=Math.abs(a.delta.x-ts(e.map(e=>e.delta.x))));e?e.push(a):t.push([a])}return t.filter(e=>e.length>=2).map(te).filter(e=>e.yRange.max-e.yRange.min<=60).sort((e,t)=>tt(t)-tt(e)).slice(0,4)}(i);if(0===n.length&&0===r.length)return;return{provider:"tesseract",baselineBlocks:n.length,currentBlocks:r.length,baselineBlocksRaw:n,currentBlocksRaw:r,matches:i,...s.length>0?{movementClusters:s}:{}}}catch{return}}function e6(e,t,a){let[n,...r]=e.split(/\r?\n/);if(!n)return[];let i=new Map(n.split(" ").map((e,t)=>[e,t])),s=[];for(let e of r){var o;if(!e.trim())continue;let t=e.split(" "),a=tr(t,i,"level"),n=tn(t,i,"text").trim(),r=tr(t,i,"conf");if(5!==a||(o=n,!/[\p{L}\p{N}]/u.test(o))||r<0)continue;let l=tr(t,i,"left"),c=tr(t,i,"top"),d=tr(t,i,"width"),p=tr(t,i,"height");d<=0||p<=0||s.push({key:[tn(t,i,"page_num"),tn(t,i,"block_num"),tn(t,i,"par_num"),tn(t,i,"line_num")].join(":"),text:n,confidence:r,rect:{x:l,y:c,width:d,height:p}})}let l=new Map;for(let e of s){let t=l.get(e.key);t?t.push(e):l.set(e.key,[e])}return Array.from(l.values()).flatMap(e=>(function(e){let t=[...e].sort((e,t)=>e.rect.x-t.rect.x),a=[],n=[];for(let e of t){let t=n.at(-1);if(!t){n.push(e);continue}if(e.rect.x-(t.rect.x+t.rect.width)>Math.max(48,2.5*Math.max(t.rect.height,e.rect.height))){a.push(n),n=[e];continue}n.push(e)}return n.length>0&&a.push(n),a})(e)).map(e=>(function(e,t,a){if(0===e.length)return null;let n=[...e].sort((e,t)=>e.rect.x-t.rect.x),r=function(e){let t=1/0,a=1/0,n=-1/0,r=-1/0;for(let i of e)t=Math.min(t,i.x),a=Math.min(a,i.y),n=Math.max(n,i.x+i.width),r=Math.max(r,i.y+i.height);return{x:t,y:a,width:n-t,height:r-a}}(n.map(e=>e.rect)),i=Math.round(100*ts(n.map(e=>e.confidence)))/100;return{text:n.map(e=>e.text).join(" "),confidence:i,rect:r,normalizedRect:{x:to(r.x/t),y:to(r.y/a),width:to(r.width/t),height:to(r.height/a)}}})(e,t,a)).filter(e=>null!==e)}function e7(e){return L("tesseract",[e,"stdout","-l","eng","tsv"],{allowFailure:!0,timeoutMs:1e4})}function e9(e){return Math.abs(e.delta.x)+Math.abs(e.delta.y)+Math.abs(e.delta.width)+Math.abs(e.delta.height)+25*!!e.possibleTextMetricMismatch}function te(e){let t=e.map(e=>e.delta.x),a=e.map(e=>e.delta.y);return{texts:e.map(e=>e.text),xRange:{min:Math.min(...t),max:Math.max(...t)},yRange:{min:Math.min(...a),max:Math.max(...a)}}}function tt(e){return 2*Math.abs((e.xRange.min+e.xRange.max)/2)+Math.abs((e.yRange.min+e.yRange.max)/2)}function ta(e){return{x:e.x+e.width/2,y:e.y+e.height/2}}function tn(e,t,a){let n=t.get(a);return void 0===n?"":e[n]??""}function tr(e,t,a){let n=Number(tn(e,t,a));return Number.isFinite(n)?n:0}function ti(e){return e.trim().replace(/\s+/g," ").toLowerCase()}function ts(e){return e.reduce((e,t)=>e+t,0)/e.length}function to(e){return Math.round(100*e*100)/100}function tl(e){return Math.round(1e3*e)/1e3}function tc(e,t,a,n){return{r:Math.round(e/n),g:Math.round(t/n),b:Math.round(a/n)}}function td(e){return .2126*e.r+.7152*e.g+.0722*e.b}function tp(e){return`#${tu(e.r)}${tu(e.g)}${tu(e.b)}`}function tu(e){return e.toString(16).padStart(2,"0")}function th(e){return Math.round(100*e*100)/100}let tm=255*Math.sqrt(3);async function tf(e,t,a={}){let n,r,i,s;await tg(e,"Baseline image not found"),await tg(t,"Current screenshot not found");let o=a.outputPath,[p,u]=await Promise.all([l.readFile(e),l.readFile(t)]),h=eF(p,"baseline screenshot"),m=eF(u,"current screenshot");tb(h.width,h.height,"baseline screenshot",a.maxPixels),tb(m.width,m.height,"current screenshot",a.maxPixels);let f=a.threshold??.1;if(h.width!==m.width||h.height!==m.height){let e=h.width*h.height;return await tw(a.outputPath),{match:!1,mismatchPercentage:100,totalPixels:e,differentPixels:e,dimensionMismatch:{expected:{width:h.width,height:h.height},actual:{width:m.width,height:m.height}}}}let g=h.width*h.height,b=f*tm,w=new c({width:h.width,height:h.height}),y=new Uint8Array(g),v=0;for(let e=0,t=0;e<h.data.length;e+=4,t+=1){if(Math.sqrt((h.data[e]-m.data[e])**2+(h.data[e+1]-m.data[e+1])**2+(h.data[e+2]-m.data[e+2])**2)>b){v+=1,y[t]=1;let a=ty(m,e);w.data[e]=tv(a,220,.78),w.data[e+1]=tv(a,0,.78),w.data[e+2]=tv(a,0,.78),w.data[e+3]=255;continue}let a=ty(m,e);w.data[e]=a,w.data[e+1]=a,w.data[e+2]=a,w.data[e+3]=255}let k=v>0?(A=(n=function(e){let{diffMask:t,baseline:a,current:n}=e,{width:r,height:i}=a,s=new Uint8Array(t.length),o=new Int32Array(t.length),l=[];for(let e=0;e<t.length;e+=1){if(1!==t[e]||1===s[e])continue;let c=0,d=0;o[0]=e,d+=1,s[e]=1;let p=e%r,u=Math.floor(e/r),h={minX:p,minY:u,maxX:p,maxY:u,differentPixels:0,baselineRed:0,baselineGreen:0,baselineBlue:0,currentRed:0,currentGreen:0,currentBlue:0};for(;c<d;){let e=o[c];c+=1,function(e,t,a,n,r){let i=t%a,s=Math.floor(t/a),o=4*t;e.minX=Math.min(e.minX,i),e.minY=Math.min(e.minY,s),e.maxX=Math.max(e.maxX,i),e.maxY=Math.max(e.maxY,s),e.differentPixels+=1,e.baselineRed+=n.data[o],e.baselineGreen+=n.data[o+1],e.baselineBlue+=n.data[o+2],e.currentRed+=r.data[o],e.currentGreen+=r.data[o+1],e.currentBlue+=r.data[o+2]}(h,e,r,a,n);let l=e%r,p=Math.floor(e/r);for(let e=-1;e<=1;e+=1){let a=p+e;if(!(a<0)&&!(a>=i))for(let n=-1;n<=1;n+=1){if(0===n&&0===e)continue;let i=l+n;if(i<0||i>=r)continue;let c=a*r+i;1===t[c]&&1!==s[c]&&(s[c]=1,o[d]=c,d+=1)}}}l.push(h)}return l}(x={diffMask:y,baseline:h,current:m,totalPixels:g,differentPixels:v,maxRegions:a.maxRegions})).length<=2e3?function(e){let t=[];for(let r of e.sort((e,t)=>{let a=e.minY-t.minY;return 0!==a?a:e.minX-t.minX})){var a,n;let e=t.find(e=>{var t,a,n;return t=e,a=r,n=12,t.minX-n<=a.maxX&&a.minX-n<=t.maxX&&t.minY-n<=a.maxY&&a.minY-n<=t.maxY});if(!e){t.push({...r});continue}a=e,n=r,a.minX=Math.min(a.minX,n.minX),a.minY=Math.min(a.minY,n.minY),a.maxX=Math.max(a.maxX,n.maxX),a.maxY=Math.max(a.maxY,n.maxY),a.differentPixels+=n.differentPixels,a.baselineRed+=n.baselineRed,a.baselineGreen+=n.baselineGreen,a.baselineBlue+=n.baselineBlue,a.currentRed+=n.currentRed,a.currentGreen+=n.currentGreen,a.currentBlue+=n.currentBlue}return t}(n):n,A.flatMap(e=>{var t,a,n;let r;return(t=e,a=x.baseline.width,n=x.baseline.height,r=t.maxX-t.minX+1,t.maxY-t.minY+1>=Math.max(48,Math.round(.07*n))&&r>=.35*a)?function(e,t,a){var n;let r=function(e,t){let a=[],n=null;for(let r=0;r<e.length;r+=1){if(e[r]<=t){n??=r;continue}null!==n&&(r-n>=6&&a.push([n,r-1]),n=null)}return null!==n&&e.length-n>=6&&a.push([n,e.length-1]),a}((n=function(e,t,a){let n=[];for(let r=e.minY;r<=e.maxY;r+=1){let i=0;for(let n=e.minX;n<=e.maxX;n+=1)1===t[r*a+n]&&(i+=1);n.push(i)}return n}(e,t.diffMask,t.baseline.width)).map((e,t)=>{let a=0,r=0,i=Math.max(0,t-3),s=Math.min(n.length-1,t+3);for(let e=i;e<=s;e+=1)a+=n[e],r+=1;return Math.round(a/r)}),Math.max(1,Math.round((e.maxX-e.minX+1)*.08))),i=function(e,t,a){let n=[],r=e.minY;for(let[i,s]of t){let t=e.minY+Math.round((i+s)/2);t-r+1<a||e.maxY-t<a||(n.push([r,t]),r=t+1)}return n.push([r,e.maxY]),n}(e,r,a);if(i.length<=1)return[e];let s=i.map(([a,n])=>(function(e,t,a,n){let r=null;for(let o=t;o<=a;o+=1)for(let t=e.minX;t<=e.maxX;t+=1){var i,s;let e=o*n.baseline.width+t;1===n.diffMask[e]&&function(e,t,a,n,r,i){let s=4*t;e.minX=Math.min(e.minX,a),e.minY=Math.min(e.minY,n),e.maxX=Math.max(e.maxX,a),e.maxY=Math.max(e.maxY,n),e.differentPixels+=1,e.baselineRed+=r.data[s],e.baselineGreen+=r.data[s+1],e.baselineBlue+=r.data[s+2],e.currentRed+=i.data[s],e.currentGreen+=i.data[s+1],e.currentBlue+=i.data[s+2]}(r??={minX:i=t,minY:s=o,maxX:i,maxY:s,differentPixels:0,baselineRed:0,baselineGreen:0,baselineBlue:0,currentRed:0,currentGreen:0,currentBlue:0},e,t,o,n.baseline,n.current)}return r})(e,a,n,t)).filter(e=>null!==e);return s.length>1?s:[e]}(e,x,Math.max(24,Math.round(.03*x.baseline.height))):[e]})).sort((e,t)=>{let a=t.differentPixels-e.differentPixels;if(0!==a)return a;let n=e.minY-t.minY;return 0!==n?n:e.minX-t.minX}).slice(0,Math.max(0,x.maxRegions??8)).map((e,t)=>{var a,n,r,i,s,o,l,c,d,p,u;let h,m,f,g,b,w,y,v,k,A,D,I,R,S,M,N,O;return a=e,n=t+1,r={width:x.baseline.width,height:x.baseline.height,totalPixels:x.totalPixels,differentPixels:x.differentPixels},w={x:a.minX,y:a.minY,width:a.maxX-a.minX+1,height:a.maxY-a.minY+1},y={x:Math.round(a.minX+w.width/2),y:Math.round(a.minY+w.height/2)},v=tc(a.baselineRed,a.baselineGreen,a.baselineBlue,a.differentPixels),k=tc(a.currentRed,a.currentGreen,a.currentBlue,a.differentPixels),A=w.width*w.height,D=th(a.differentPixels/A),I=Math.round(td(v)),R=Math.round(td(k)),S=(i=w,s=r.width,o=r.height,i.width>=.55*s&&i.height>=.12*o?"large-area":i.width>=2.5*i.height?"horizontal-band":i.height>=2.5*i.width?"vertical-band":"compact"),M=(h=A/r.totalPixels)>=.04?"large":h>=.01?"medium":"small",N=(l=v,c=k,m=td(l),Math.abs(f=td(c)-m)>=12?f>0?"brighter":"darker":Math.max(Math.abs(c.r-l.r),Math.abs(c.g-l.g),Math.abs(c.b-l.b))>=12?"color-shift":"mixed"),O=(d=y,p=r.width,u=r.height,g=d.x<p/3?"left":d.x>2*p/3?"right":"center",b=d.y<u/3?"top":d.y>2*u/3?"bottom":"middle","center"===g&&"middle"===b?"center":`${b}-${g}`),{index:n,rect:w,normalizedRect:{x:th(w.x/r.width),y:th(w.y/r.height),width:th(w.width/r.width),height:th(w.height/r.height)},differentPixels:a.differentPixels,shareOfDiffPercentage:th(a.differentPixels/r.differentPixels),densityPercentage:D,shape:S,size:M,location:O,averageBaselineColorHex:tp(v),averageCurrentColorHex:tp(k),baselineLuminance:I,currentLuminance:R,dominantChange:N}}):[];if(v>0&&o){var x,A,D;for(let e of k)e.rect.width<4||e.rect.height<4||function(e,t){let a=eK(t.x,0,e.width-1),n=eK(t.y,0,e.height-1),r=eK(t.x+t.width-1,0,e.width-1),i=eK(t.y+t.height-1,0,e.height-1);for(let t=0;t<2;t+=1){for(let s=a;s<=r;s+=1)eY(e,s,n+t,eX),eY(e,s,i-t,eX);for(let s=n;s<=i;s+=1)eY(e,a+t,s,eX),eY(e,r-t,s,eX)}}(w,e.rect);await l.mkdir(d.dirname(o),{recursive:!0}),await l.writeFile(o,c.sync.write(w))}else await tw(a.outputPath);let I=v>0?await e8({baselinePath:e,currentPath:t,width:h.width,height:h.height}):void 0,R=I&&(I.matches.length>0||(I.movementClusters?.length??0)>0)?{provider:I.provider,baselineBlocks:I.baselineBlocks,currentBlocks:I.currentBlocks,matches:I.matches,...I.movementClusters?{movementClusters:I.movementClusters}:{}}:void 0,S=v>0&&I?(r=function(e){let t=[];for(let a of e.sort((e,t)=>e.minY-t.minY||e.minX-t.minX)){let e=t.find(e=>{var t,n,r;return t=e,n=a,r=10,t.minX-r<=n.maxX&&n.minX-r<=t.maxX&&t.minY-r<=n.maxY&&n.minY-r<=t.maxY});if(!e){t.push({...a});continue}e.minX=Math.min(e.minX,a.minX),e.minY=Math.min(e.minY,a.minY),e.maxX=Math.max(e.maxX,a.maxX),e.maxY=Math.max(e.maxY,a.maxY),e.differentPixels+=a.differentPixels}return t}(function(e,t,a){let n=new Uint8Array(e.length),r=new Int32Array(e.length),i=[];for(let s=0;s<e.length;s+=1){if(1!==e[s]||1===n[s])continue;let o=0,l=0;r[0]=s,l+=1,n[s]=1;let c=s%t,d=Math.floor(s/t),p={minX:c,minY:d,maxX:c,maxY:d,differentPixels:0};for(;o<l;){let i=r[o];o+=1;let s=i%t,c=Math.floor(i/t);p.minX=Math.min(p.minX,s),p.minY=Math.min(p.minY,c),p.maxX=Math.max(p.maxX,s),p.maxY=Math.max(p.maxY,c),p.differentPixels+=1;for(let i=-1;i<=1;i+=1){let o=c+i;if(!(o<0)&&!(o>=a))for(let a=-1;a<=1;a+=1){if(0===a&&0===i)continue;let c=s+a;if(c<0||c>=t)continue;let d=o*t+c;1===e[d]&&1!==n[d]&&(n[d]=1,r[l]=d,l+=1)}}}i.push(p)}return i}(function(e,t,a,n){let r=new Uint8Array(e);if(!n)return r;for(let e of[...n.baselineBlocksRaw,...n.currentBlocksRaw]){var i;!function(e,t,a,n){let r=e4(Math.floor(n.x),0,t-1),i=e4(Math.floor(n.y),0,a-1),s=e4(Math.ceil(n.x+n.width),0,t),o=e4(Math.ceil(n.y+n.height),0,a);for(let a=i;a<o;a+=1)for(let n=r;n<s;n+=1)e[a*t+n]=0}(r,t,a,{x:(i=e.rect).x-8,y:i.y-8,width:i.width+16,height:i.height+16})}return r}((D={diffMask:y,width:h.width,height:h.height,regions:k,ocr:I}).diffMask,D.width,D.height,D.ocr),D.width,D.height)),i=eZ(D.ocr?.currentBlocksRaw??[]),s=eZ(D.ocr?.baselineBlocksRaw??[]),r.filter(e1).map(e=>{var t,a,n,r,o,l,c,d,p,u,h;let m,f,g,b,w,y,v,k,x,A;return t=e,a=D,n=i,r=s,b=function(e,t){let a,n=0;for(let r of t){let t=function(e,t){let a=Math.max(e.x,t.x),n=Math.max(e.y,t.y),r=Math.min(e.x+e.width,t.x+t.width),i=Math.min(e.y+e.height,t.y+t.height);return r<=a||i<=n?0:(r-a)*(i-n)}(e,r.rect);t<=n||(n=t,a=r)}return a?.index}(g=e2(t),a.regions),w=function(e,t,a){let n=eQ(e,t);if(n)return e0(e,n.blocks);let r=eQ(e,a);return r?e0(e,r.blocks):void 0}(g,n,r),y=function(e,t,a){if(e.height<=3&&e.width>=.12*a)return"separator";if(!t)return e.width>=.4*a?"background":"unknown";if(e.width>=.4*a)return"background";let n=e.x+e.width/2,r=t.x+t.width/2;return n<r-t.width/2?"leading":n>r+t.width/2?"trailing":e.width>=.35*a?"background":"unknown"}(g,w?.block.rect,a.width),v=(o=g,l=y,c=t.differentPixels,d=a,m=o.width/o.height,f=c/(o.width*o.height),"separator"===l?"separator":"background"===l?"background":"trailing"===l&&m>=1.5&&m<=3.8&&f>=.35?"toggle":"trailing"===l&&o.width<=.06*d.width&&o.height<=.04*d.height?"chevron":"leading"===l&&m>=.55&&m<=1.8?"icon":eW(o,d)?"background":"visual"),k={...b?{regionIndex:b}:{},slot:y,likelyKind:v,rect:g},{...b?{regionIndex:b}:{},slot:y,likelyKind:v,rect:g,...w?{nearestText:w.block.text.trim().replace(/^[^\p{L}\p{N}]+/u,"").replace(/^\p{L}\s+/u,"")}:{},score:(p=k,u=t.differentPixels,h=a,x=eW(p.rect,h)?-35:0,A=20*!!p.regionIndex,ez[p.likelyKind]+eH[p.slot]+A+x+Math.min(20,u/200))}}).filter(e=>e.rect.y>=.08*D.height).filter(eJ).sort((e,t)=>t.score-e.score).slice(0,Math.max(0,D.maxDeltas??12)).map((e,t)=>{var a;return a=e,{index:t+1,...a.regionIndex?{regionIndex:a.regionIndex}:{},slot:a.slot,likelyKind:a.likelyKind,rect:a.rect,...a.nearestText?{nearestText:a.nearestText}:{}}})):[],M=g>0?Math.round(v/g*1e4)/100:0;return{...v>0&&o?{diffPath:o}:{},...k.length>0?{regions:k}:{},...R?{ocr:R}:{},...S.length>0?{nonTextDeltas:S}:{},totalPixels:g,differentPixels:v,mismatchPercentage:M,match:0===v}}async function tg(e,t){try{await l.access(e)}catch{throw new b("INVALID_ARGS",`${t}: ${e}`)}}function tb(e,t,a,n){if(null==n||n<=0)return;let r=e*t;if(!(r<=n))throw new b("INVALID_ARGS",`${a} is ${r} pixels, which exceeds the configured maxImagePixels limit of ${n}`)}async function tw(e){if(e)try{await l.unlink(e)}catch(e){var t;if(!("object"==typeof(t=e)&&null!==t&&"code"in t&&"ENOENT"===t.code))throw e}}function ty(e,t){return tv(Math.round(.299*e.data[t]+.587*e.data[t+1]+.114*e.data[t+2]),255,.72)}function tv(e,t,a){return Math.round(e*(1-a)+t*a)}function tk(e){return e.width*e.height}function tx(e){return Math.round(100*e*100)/100}let tA=async(e,t)=>{let a,n,r;if(!t.baseline)throw new b("INVALID_ARGS","diff screenshot requires a baseline image");let i=function(e){if(null==e||""===e)return .1;let t=Number(e);if(Number.isNaN(t)||t<0||t>1)throw new b("INVALID_ARGS","--threshold must be a number between 0 and 1");return t}(t.threshold),s=t.current??{kind:"live"};if(t.overlayRefs&&!tO(s))throw new b("INVALID_ARGS","diff screenshot <current.png> cannot use --overlay-refs because saved-image comparisons have no live accessibility refs");let o=await eq(e,t.baseline,{usage:"diff screenshot baseline",field:"baseline"}),l=[];try{let c;c=tO(s)?(n=await tD(e,t)).path:(a=await eq(e,s,{usage:"diff screenshot current",field:"current"})).path,r=t.out?await eG(e,t.out,{field:"diffPath",ext:".png"}):void 0;let d=await tf(o.path,c,{threshold:i,outputPath:r?.path,maxPixels:e.policy.maxImagePixels});tO(s)&&(d=await tI(e,t,r?.path,d,l));let p=d.diffPath?await r?.publish():void 0;return p&&l.push(p),d.diffPath||await r?.cleanup?.(),{...d,...l.length>0?{artifacts:l}:{}}}catch(e){throw await r?.cleanup?.(),e}finally{await o.cleanup?.(),await a?.cleanup?.(),await n?.cleanup?.()}};async function tD(e,t){let a=await ej(e,{prefix:"agent-device-diff-current",ext:".png"});try{await tR(e,t,a.path,tS(t))}catch(e){throw await a.cleanup(),e}return a}async function tI(e,t,a,n,r){var i,s,o,l;if(!t.overlayRefs)return n;if(n.match||n.dimensionMismatch)return a&&await tN(a),n;let c=(i=t,s=a,i.currentOverlayOut?i.currentOverlayOut:i.out?.kind==="path"?{kind:"path",path:tM(s??i.out.path)}:i.out?.kind==="downloadableArtifact"?{kind:"downloadableArtifact",...i.out.clientPath?{clientPath:tM(i.out.clientPath)}:{},...i.out.fileName?{fileName:tM(i.out.fileName)}:{}}:void 0),d=await eG(e,c,{field:"currentOverlayPath",ext:".png"});try{let a=await tR(e,t,d.path,{overlayRefs:!0,...tS(t)}),i=await d.publish();return i&&r.push(i),{...n,currentOverlayPath:a.path??d.path,...a.overlayRefs?{currentOverlayRefCount:a.overlayRefs.length}:{},...n.regions&&a.overlayRefs?{regions:(o=n.regions,l=a.overlayRefs,o.map(e=>{var t,a;let n,r=(t=e,a=l,n=tk(t.rect),a.map(e=>{var a,r;let i,s,o,l,c=e.overlayRect,d=(a=t.rect,r=c,i=Math.max(a.x,r.x),s=Math.max(a.y,r.y),o=Math.min(a.x+a.width,r.x+r.width),l=Math.min(a.y+a.height,r.y+r.height),o<=i||l<=s?0:(o-i)*(l-s));return d<=0?null:{ref:e.ref,...e.label?{label:e.label}:{},rect:c,overlayCoveragePercentage:tx(d/tk(c)),regionCoveragePercentage:tx(d/n)}}).filter(e=>null!==e).sort((e,t)=>{let a=t.regionCoveragePercentage-e.regionCoveragePercentage;return 0!==a?a:t.overlayCoveragePercentage-e.overlayCoveragePercentage}).slice(0,3).map(e=>({ref:e.ref,...e.label?{label:e.label}:{},rect:e.rect,regionCoveragePercentage:e.regionCoveragePercentage})));return r.length>0?{...e,currentOverlayMatches:r}:e}))}:{}}}catch(e){throw await d.cleanup?.(),e}}async function tR(e,t,a,n={}){if(!e.backend.captureScreenshot)throw new b("UNSUPPORTED_OPERATION","screenshot is not supported by this backend");return await e.backend.captureScreenshot({session:t.session,requestId:t.requestId,signal:t.signal??e.signal,metadata:t.metadata},a,n)??{}}function tS(e){return e.surface?{surface:e.surface}:{}}function tM(e){let t=d.extname(e),a=t?e.slice(0,-t.length):e;return`${a}.current-overlay${t||".png"}`}async function tN(e){try{await l.unlink(tM(e))}catch(e){var t;if(!("object"==typeof(t=e)&&null!==t&&"code"in t&&"ENOENT"===t.code))throw e}}function tO(e){return"live"===e.kind}let tL={application:"application",navigationbar:"navigation-bar",tabbar:"tab-bar",button:"button",imagebutton:"button",link:"link",cell:"cell",statictext:"text",checkedtextview:"text",textfield:"text-field",edittext:"text-field",textarea:"text-view",switch:"switch",slider:"slider",image:"image",imageview:"image",webview:"webview",framelayout:"group",linearlayout:"group",relativelayout:"group",constraintlayout:"group",viewgroup:"group",view:"group",listview:"list",recyclerview:"list",collectionview:"collection",searchfield:"search",segmentedcontrol:"segmented-control",group:"group",window:"window",checkbox:"checkbox",radio:"radio",menuitem:"menu-item",toolbar:"toolbar",scrollarea:"scroll-area",scrollview:"scroll-area",nestedscrollview:"scroll-area",table:"table"};function tP(e,t={}){let a=[],n=[];for(let r of e){let e=r.depth??0,i=r.label?.trim()||r.value?.trim()||r.identifier?.trim()||"",s=tU(r.type??"Element");if("group"===s&&!i)continue;for(;a.length>0&&e<=a[a.length-1];)a.pop();let o=a.length;a.push(e),n.push({node:r,depth:o,type:s,text:tE(r,o,!1,s,t)})}return n}function tE(e,t,a,n,r={}){var i,s,o,l,c,d,p,u;let h,m=n??tU(e.type??"Element"),f=V(e,m),g=(i=e,s=m,o=r,l=f,o.summarizeTextSurfaces&&l.shouldSummarize&&function(e,t,a){let n=P(e.label);if(n&&n!==a)return n;let r=P(e.identifier);if(r&&!t_(r)&&r!==a)return r;switch(t){case"text":case"text-view":return"Text view";case"text-field":return"Text field";case"search":return"Search field";default:return""}}(i,s,l.text)||tC(i,s)),b=" ".repeat(t),w=e.ref?`@${e.ref}`:"",y=(c=e,d=m,p=r,u=f,h=[],(!1===c.enabled&&h.push("disabled"),p.summarizeTextSurfaces)?(!0===c.selected&&h.push("selected"),!0===c.focused&&h.push("focused"),tT(d)&&h.push("editable"),function(e,t){if("scroll-area"===t)return!0;let a=(e.type??"").toLowerCase(),n=`${e.role??""} ${e.subrole??""}`.toLowerCase();return a.includes("scroll")||n.includes("scroll")}(c,d)&&h.push("scrollable"),h.push(...c.presentationHints??[]),u.shouldSummarize&&(h.push(`preview:"${_(u.text).replace(/\\/g,"\\\\").replace(/"/g,'\\"')}"`),h.push("truncated")),t$(h)):h).map(e=>` [${e}]`).join(""),v=g?` "${g}"`:"";return a?`${b}${w} [${m}]${y}`.trimEnd():`${b}${w} [${m}]${v}${y}`.trimEnd()}function tC(e,t){var a,n;let r,i=e.label?.trim();if(i&&(a=t,n=i,("scroll-area"===a||"list"===a||"collection"===a||"table"===a)&&(r=n.trim().toLowerCase())&&/^(vertical|horizontal)\s+scroll\s+bar(?:,?\s*\d+\s+pages?)?$/.test(r)))return"";let s=e.value?.trim();if(tT(t)){if(s)return s;if(i)return i}else if(i)return i;if(s)return s;let o=e.identifier?.trim();return!o||t_(o)&&("group"===t||"image"===t||"list"===t||"collection"===t)?"":o}function tU(e){var t;let a=e.replace(/XCUIElementType/gi,"").toLowerCase(),n=e.includes(".")&&(e.startsWith("android.")||e.startsWith("androidx.")||e.startsWith("com."));return(a.includes(".")&&(a=a.replace(/^android\.widget\./,"").replace(/^android\.view\./,"").replace(/^android\.webkit\./,"").replace(/^androidx\./,"").replace(/^com\.google\.android\./,"").replace(/^com\.android\./,""),n&&a.includes(".")&&(a=a.slice(a.lastIndexOf(".")+1))),"textview"===a)?n?"text":"text-view":(t=a,(Object.prototype.hasOwnProperty.call(tL,t)?tL[t]:void 0)||a||"element")}function tT(e){return"text-field"===e||"text-view"===e||"search"===e}function t_(e){return/^[\w.]+:id\/[\w.-]+$/i.test(e)}function t$(e){return[...new Set(e)]}function tF(e,t){let a=tU(e.type??"Element"),n=tC(e,a),r=!1===e.enabled?"disabled":"enabled",i=!0===e.selected?"selected":"unselected",s=!0===e.hittable?"hittable":"not-hittable";return[String(t??e.depth??0),a,n,r,i,s].join("|")}function tB(e,t){return t.flatten?e.map(e=>({text:tE(e,0,!1),comparable:tF(e,0)})):tP(e).map(e=>({text:e.text,comparable:tF(e.node,e.depth)}))}function tq(e,t){return e.get(t)??0}function tG(e){return e.map(e=>({index:e.index,depth:e.depth,parentIndex:e.parentIndex,type:e.type,role:e.role,subrole:e.subrole,label:e.label,value:e.value,identifier:e.identifier,enabled:e.enabled,selected:e.selected,focused:e.focused,hittable:e.hittable,rect:e.rect,bundleId:e.bundleId,appName:e.appName,windowTitle:e.windowTitle,surface:e.surface,hiddenContentAbove:e.hiddenContentAbove,hiddenContentBelow:e.hiddenContentBelow}))}function tj(e){return"text"===e||"label"===e||"any"===e}function tV(e,t){return{session:t.session,requestId:t.requestId,signal:t.signal??e.signal,metadata:t.metadata}}function tX(e){return e.clock?.now()??Date.now()}async function tY(e,t){e.clock?await e.clock.sleep(t):await new Promise(e=>setTimeout(e,t))}let tK=async(e,t)=>{var a;let n,r,i=await tH(e,t),s=function(e){var t,a,n,r,i;let{previous:s,current:o,options:l,identity:c}=e;if(!0===l.forceFull||!0===l.raw||!s||!1===s.comparisonSafe||!1===o.comparisonSafe||(t=s,a=o,n=c,t.backend&&a.backend&&t.backend!==a.backend||n?.previousAppBundleId&&n.currentAppBundleId&&n.previousAppBundleId!==n.currentAppBundleId)||!s.presentationKey||s.presentationKey!==o.presentationKey||(r=s,i=o,r.truncated!==i.truncated||JSON.stringify(tG(r.nodes))!==JSON.stringify(tG(i.nodes))))return;let d=l.scope?.trim();return{ageMs:Math.max(0,o.createdAt-s.createdAt),nodeCount:o.nodes.length,...!0===l.interactiveOnly?{interactiveOnly:!0}:{},...d?{scope:d}:{}}}({previous:i.session?.snapshot,current:i.snapshot,options:t,identity:{previousAppBundleId:i.session?.appBundleId,currentAppBundleId:i.result.appBundleId??i.session?.appBundleId}});return await e.sessions.set(tJ(t.session,i)),{nodes:i.snapshot.nodes,truncated:i.snapshot.truncated??!1,visibility:function(e){var t;let{nodes:a,backend:n,snapshotRaw:r}=e;if(r||"macos-helper"===(t=n)||"linux-atspi"===t)return{partial:!1,visibleNodeCount:a.length,totalNodeCount:a.length,reasons:[]};let i=ea(a),s=new Set;return i.hiddenCount>0&&s.add("offscreen-nodes"),i.nodes.some(e=>e.hiddenContentAbove)&&s.add("scroll-hidden-above"),i.nodes.some(e=>e.hiddenContentBelow)&&s.add("scroll-hidden-below"),{partial:s.size>0,visibleNodeCount:i.nodes.length,totalNodeCount:a.length,reasons:[...s]}}({nodes:i.snapshot.nodes,backend:i.snapshot.backend,snapshotRaw:t.raw}),...i.result.androidSnapshot?{androidSnapshot:i.result.androidSnapshot}:{},...i.warnings.length>0?{warnings:i.warnings}:{},...s?{unchanged:s}:{},...(n=(a=i).result.appName??a.session?.appName,r=a.result.appBundleId??a.session?.appBundleId,{...n||r?{appName:n??r}:{},...r?{appBundleId:r}:{}})}},tz=async(e,t)=>{let a=await tH(e,t),n=!0===t.interactiveOnly,r=a.session?.snapshot,i=tJ(t.session,a);if(!r){let t=function(e,t={}){return tB(e,t).length}(a.snapshot.nodes,{flatten:n});return await e.sessions.set(i),{mode:"snapshot",baselineInitialized:!0,summary:{additions:0,removals:0,unchanged:t},lines:[],...a.warnings.length>0?{warnings:a.warnings}:{}}}let s=function(e,t,a={}){let n=function(e,t){let a=e.length,n=t.length,r=a+n,i=new Map,s=[];i.set(1,0);for(let o=0;o<=r;o+=1){s.push(new Map(i));for(let r=-o;r<=o;r+=2){let l=r===-o||r!==o&&tq(i,r-1)<tq(i,r+1)?tq(i,r+1):tq(i,r-1)+1,c=l-r;for(;l<a&&c<n&&e[l].comparable===t[c].comparable;)l+=1,c+=1;if(i.set(r,l),l>=a&&c>=n)return function(e,t,a,n,r){let i=[],s=n,o=r;for(let n=e.length-1;n>=0;n-=1){let r=e[n],l=s-o,c=l===-n||l!==n&&tq(r,l-1)<tq(r,l+1)?l+1:l-1,d=tq(r,c),p=d-c;for(;s>d&&o>p;)i.push({kind:"unchanged",text:a[o-1].text}),s-=1,o-=1;if(0===n)break;s===d?(i.push({kind:"added",text:a[p].text}),o=p):(i.push({kind:"removed",text:t[d].text}),s=d)}return i.reverse(),i}(s,e,t,a,n)}}return[]}(tB(e,a),tB(t,a)),r={additions:0,removals:0,unchanged:0};for(let e of n)"added"===e.kind&&(r.additions+=1),"removed"===e.kind&&(r.removals+=1),"unchanged"===e.kind&&(r.unchanged+=1);return{summary:r,lines:n}}(r.nodes,a.snapshot.nodes,{flatten:n});return await e.sessions.set(i),{mode:"snapshot",baselineInitialized:!1,summary:s.summary,lines:s.lines,...a.warnings.length>0?{warnings:a.warnings}:{}}};async function tH(e,t){var a,n,r,i,s,o;let l,c,d,p;if(!e.backend.captureSnapshot)throw new b("UNSUPPORTED_OPERATION","snapshot is not supported by this backend");let u=t.session??"default",m=await e.sessions.get(u),f=await e.backend.captureSnapshot({session:u,requestId:t.requestId,appId:m?.appId,appBundleId:m?.appBundleId,signal:t.signal??e.signal,metadata:t.metadata},{interactiveOnly:t.interactiveOnly,compact:t.compact,depth:t.depth,scope:t.scope,raw:t.raw}),g=(n=f,r=e,a=n.snapshot?n.snapshot:{nodes:n.nodes??[],truncated:n.truncated,backend:n.backend,createdAt:tX(r)},a.presentationKey?a:{...a,presentationKey:h(t)}),w=tX(e);return{snapshot:g,result:f,session:m,warnings:((l=[...(i={result:f,snapshot:g,options:t,session:m,capturedAt:g.createdAt??w,runtimeNow:w}).result.warnings??[]]).push(...function(e){let t=e.result.analysis;if("android"!==e.snapshot.backend||!0!==e.options.interactiveOnly||e.snapshot.nodes.length>0||!t||(t.rawNodeCount??0)<12)return[];let a=[`Interactive snapshot is empty after filtering ${t.rawNodeCount} raw Android nodes. Likely causes: the app content is not accessibility-visible yet, a transient route change, or depth/filter options hid the target.`];return"number"==typeof e.options.depth&&"number"==typeof t.maxDepth&&t.maxDepth>=e.options.depth+2&&a.push(`Interactive output is empty at depth ${e.options.depth}; retry without -d.`),a}(i)),(c=function(e){if(e?.backend!=="uiautomator-dump")return;let t=e.fallbackReason?` Reason: ${e.fallbackReason}`:"";return`Android snapshot helper unavailable; using stock UIAutomator dump, which can time out on busy React Native UIs.${t}`}(i.result.androidSnapshot))&&l.push(c),(d=function(e){var t,a,n,r;let i,s,o,l,c,d,p,u=(i=(t=e).map(e=>[e.label,e.value,e.identifier,e.type,e.role].filter(Boolean).join(" ")).join("\n").toLowerCase(),s=t1(t,tQ),o=t1(t,tZ),l=t1(t,t0),c=(a=i,/\b[\w.$<>/-]+\.(?:tsx?|jsx?):\d+(?::\d+)?\b/.test(a)||/\b[\w.$<>/-]+\.(?:tsx?|jsx?)\s+\(\d+:\d+\)/.test(a)),d=s.length>0||o.length>0,p=/\b(redbox|runtime error|reload js|copy stack|component stack|call stack)\b/.test(i)||c&&d,{detected:(n=i,/\b(logbox|redbox|reload js|copy stack|component stack|call stack|runtime error|open debugger to view warnings)\b/.test(n)||l.length>0||c&&d),redBox:p,dismissRefs:s,minimizeRefs:o,collapsedRefs:l});if(u.detected){return u.redBox?(r=u.minimizeRefs).length>0?`Possible React Native warning/error overlay detected. React Native RedBox stack overlay detected. Minimize before continuing: press ${t2(r)}, then snapshot -i and report the error in the final summary. Prefer Minimize over Dismiss when the error may re-render immediately.`:"Possible React Native warning/error overlay detected. React Native RedBox stack overlay detected. Do not press Dismiss if the error may re-render immediately; use screenshot --overlay-refs if visual evidence is required and report the error in the final summary.":u.dismissRefs.length>0?`Possible React Native warning/error overlay detected. Dismiss before continuing: press ${t2(u.dismissRefs)}, then snapshot -i and report the warning/error in the final summary. Use screenshot --overlay-refs only if visual evidence is required.`:u.collapsedRefs.length>0?`Possible React Native warning/error overlay detected. Warning banner detected. Press ${t2(u.collapsedRefs)} to expand or clear it; if Dismiss/Close appears, press it, then snapshot -i and report the warning/error in the final summary.`:"Possible React Native warning/error overlay detected. Dismiss visible Dismiss/Close before continuing, then snapshot -i and report the warning/error in the final summary. Use screenshot --overlay-refs only if visual evidence is required."}}(i.snapshot.nodes))&&l.push(d),(p=function(e){var t,a;let n=e.session?.snapshot,r=!!n&&[e.capturedAt,e.runtimeNow].some(e=>{let t=e-n.createdAt;return t>=0&&t<=2e3});if(!e.result.freshness&&n&&r&&(t=n.nodes.length,a=e.snapshot.nodes.length,!(t<12)&&a<=Math.floor(.2*t)))return tW}(i))&&l.push(p),l.push(...(s=i.result.freshness,o=i.snapshot.backend,s?.staleAfterRetries&&"android"===o?"stuck-route"===s.reason?[`Recent ${s.action} was followed by a nearly identical snapshot after ${s.retryCount} automatic retr${1===s.retryCount?"y":"ies"}. If you expected navigation or submit, the tree may still be stale. Use screenshot as visual truth, wait briefly, then re-snapshot once.`]:"sharp-drop"===s.reason?[tW]:[]:[])),Array.from(new Set(l)))}}function tJ(e,t){let a=t.session?.name??e??"default";return{...t.session??{name:a},name:a,snapshot:t.snapshot,appName:t.result.appName??t.session?.appName,appBundleId:t.result.appBundleId??t.session?.appBundleId}}let tW="Recent snapshots dropped sharply in node count, which suggests stale or mid-transition UI. Use screenshot as visual truth, wait briefly, then re-snapshot once.";function tQ(e){return"dismiss"===e||"close"===e}function tZ(e){return/^minimi[sz]e$/.test(e)}function t0(e){return e.includes("open debugger to view warnings")||/^!,\s+/.test(e)||/^(warn|warning|error):\s+/.test(e)||/\b(?:possible\s+)?unhandled (?:promise )?rejection\b/.test(e)||e.includes("getsnapshot should be cached to avoid an infinite loop")||e.includes('unique "key" prop')||e.includes("unique 'key' prop")||e.includes("virtualizedlists should never be nested")||e.includes("failed prop type")}function t1(e,t){let a=[];for(let n of e)n.ref&&t((n.label??"").trim().toLowerCase())&&a.push(n.ref);return a}function t2(e){return e.slice(0,3).map(e=>`@${e}`).join(", ")}function t5(e){return["visible","hidden","exists","editable","selected","text"].includes(e)}function t3(e){let{predicate:t,node:a,nodes:n,expectedText:r,platform:i}=e,s=E(a),o=T(a,i),l=!0===a.selected,c="text"===t?U(a):function(e,t){if(!0===e.hittable)return!0;if(t4(e.rect))return function(e,t){return ei(e,t)}(e,t);if(e.rect)return!1;let a=function(e,t){let a=new Map(t.map(e=>[e.index,e])),n=e,r=new Set;for(;"number"==typeof n.parentIndex&&!r.has(n.index);){r.add(n.index);let e=a.get(n.parentIndex);if(!e)break;if(function(e){let t=K(e.type??"");return!(t.includes("application")||t.includes("window")||t.includes("scrollview")||t.includes("tableview")||t.includes("collectionview"))&&"table"!==t&&"list"!==t&&"listview"!==t&&(!0===e.hittable||t4(e.rect))}(e))return e;n=e}return null}(e,t);return!!a&&(!0===a.hittable||!!t4(a.rect)&&function(e,t){return ei(e,t)}(a,t))}(a,n),d=!1;switch(t){case"visible":d=c;break;case"hidden":d=!c;break;case"editable":d=o;break;case"selected":d=l;break;case"text":d=s===(r??"")}let p="text"===t?`expected="${r??""}" actual="${s}"`:`actual=${JSON.stringify({visible:c,editable:o,selected:l})}`;return{pass:d,actualText:s,details:p}}function t4(e){return!!(e&&Number.isFinite(e.x)&&Number.isFinite(e.y)&&Number.isFinite(e.width)&&Number.isFinite(e.height)&&e.width>0&&e.height>0)}async function t8(e,t){let a=t??"default",n=await e.sessions.get(a);if(!n)throw new b("SESSION_NOT_FOUND","No active session. Run open first.");if(!n.snapshot)throw new b("INVALID_ARGS","No snapshot in session. Run snapshot first.");return{sessionName:a,session:n,snapshot:n.snapshot}}async function t6(e,t,a={updateSession:!0}){if(!e.backend.captureSnapshot)throw new b("UNSUPPORTED_OPERATION","snapshot is not supported by this backend");let n=t.session??"default",r=await e.sessions.get(n),i=await e.backend.captureSnapshot(tV(e,t),{interactiveOnly:!1,compact:!1,depth:t.depth,scope:a.scope??t.scope,raw:t.raw}),s=i.snapshot??{nodes:i.nodes??[],truncated:i.truncated,backend:i.backend,createdAt:tX(e)};return a.updateSession&&r&&await e.sessions.set({...r,snapshot:s}),{sessionName:n,session:r,snapshot:s}}async function t7(e,t,a){if(e.backend.readText){let n=await e.backend.readText(tV(e,{session:t.sessionName}),a);if(n.text.trim())return n.text}return X(a)}let t9=async(e,t)=>{let a=t.locator??"any";if(!t.query)throw new b("INVALID_ARGS","find requires a value");if("wait"===t.action)return await al(e,t,a);let n=await t6(e,t,{updateSession:!0,scope:tj(a)?t.query:void 0}),r=H(n.snapshot.nodes,a,t.query,{requireRect:!1}).matches[0];if(!r)throw new b("COMMAND_FAILED","find did not match any element");if("exists"===t.action)return{kind:"found",found:!0};let i=`@${r.ref}`;return"get_attrs"===t.action?{kind:"attrs",ref:i,node:r}:{kind:"text",ref:i,text:await t7(e,n,r),node:r}},ae=async(e,t)=>{if("ref"===t.target.kind){let a=await t8(e,t.session),n=function(e,t,a){let n=p(t);if(!n)throw new b("INVALID_ARGS",a.invalidRefMessage);let r=m(e,n)??(a.fallbackLabel.length>0?G(e,a.fallbackLabel):null);if(!r)throw new b("COMMAND_FAILED",a.notFoundMessage);return{ref:n,node:r}}(a.snapshot.nodes,t.target.ref,{fallbackLabel:t.target.fallbackLabel??"",invalidRefMessage:"get text requires a ref like @e2",notFoundMessage:`Ref ${t.target.ref} not found`}),r=F(n.node,e.backend.platform,{action:"get"}),i={kind:"ref",ref:`@${n.ref}`};return"attrs"===t.property?{kind:"attrs",target:i,node:n.node,selectorChain:r}:{kind:"text",target:i,text:await t7(e,a,n.node),node:n.node,selectorChain:r}}let a=await au(e,t,t.session??"default",{selector:t.target.selector,disambiguateAmbiguous:"text"===t.property}),n=F(a.node,e.backend.platform,{action:"get"});if("attrs"===t.property)return{kind:"attrs",target:{kind:"selector",selector:a.selector},node:a.node,selectorChain:n};let r=await t7(e,a.capture,a.node);return{kind:"text",target:{kind:"selector",selector:a.selector},text:r,node:a.node,selectorChain:n}},at=async(e,t)=>{let a=await ae(e,{...t,property:"text",target:t.target});if("text"!==a.kind)throw new b("COMMAND_FAILED","getText returned non-text result");return a},aa=async(e,t)=>{let a=await ae(e,{...t,property:"attrs",target:t.target});if("attrs"!==a.kind)throw new b("COMMAND_FAILED","getAttrs returned non-attrs result");return a},an=async(e,t)=>{if(!t5(t.predicate))throw new b("INVALID_ARGS","is requires predicate: visible|hidden|exists|editable|selected|text");if("text"===t.predicate&&!t.expectedText)throw new b("INVALID_ARGS","is text requires expected text value");let a=await t6(e,t,{updateSession:!0}),n=C(t.selector);if("exists"===t.predicate){let r=B(a.snapshot.nodes,n,{platform:e.backend.platform});if(!r)throw new b("COMMAND_FAILED",Y(n,[],{unique:!1}));return{predicate:t.predicate,pass:!0,selector:r.selector.raw,matches:r.matches,selectorChain:n.selectors.map(e=>e.raw)}}let r=q(a.snapshot.nodes,n,{platform:e.backend.platform,requireRect:!1,requireUnique:!0,disambiguateAmbiguous:!1});if(!r)throw new b("COMMAND_FAILED",Y(n,[],{unique:!0}));let i=t3({predicate:t.predicate,node:r.node,nodes:a.snapshot.nodes,expectedText:t.expectedText,platform:e.backend.platform});if(!i.pass)throw new b("COMMAND_FAILED",`is ${t.predicate} failed for selector ${r.selector.raw}: ${i.details}`);return{predicate:t.predicate,pass:!0,selector:r.selector.raw,..."text"===t.predicate?{text:i.actualText}:{},selectorChain:n.selectors.map(e=>e.raw)}},ar=async(e,t)=>await an(e,{...t,predicate:"visible",selector:t.target.selector}),ai=async(e,t)=>await an(e,{...t,predicate:"hidden",selector:t.target.selector}),as=async(e,t)=>{if("sleep"===t.target.kind)return await tY(e,t.target.durationMs),{kind:"sleep",waitedMs:t.target.durationMs};if("ref"===t.target.kind){let a=await t8(e,t.session),n=p(t.target.ref);if(!n)throw new b("INVALID_ARGS",`Invalid ref: ${t.target.ref}`);let r=m(a.snapshot.nodes,n),i=r?j(r,a.snapshot.nodes):void 0;if(!i)throw new b("COMMAND_FAILED",`Ref ${t.target.ref} not found or has no label`);return await ad(e,t,i,t.target.timeoutMs)}if("selector"===t.target.kind)return await ac(e,t,t.target.selector,t.target.timeoutMs);if(!t.target.text)throw new b("INVALID_ARGS","wait requires text");return await ad(e,t,t.target.text,t.target.timeoutMs)},ao=async(e,t)=>{let a=await as(e,{...t,target:{kind:"text",text:t.text,timeoutMs:t.timeoutMs}});if("text"!==a.kind)throw new b("COMMAND_FAILED","waitForText returned non-text result");return a};async function al(e,t,a){let n=t.timeoutMs??1e4,r=tX(e);for(;tX(e)-r<n;){if(H((await t6(e,t,{updateSession:!0,scope:tj(a)?t.query:void 0})).snapshot.nodes,a,t.query,{requireRect:!1}).matches[0])return{kind:"found",found:!0,waitedMs:tX(e)-r};await tY(e,300)}throw new b("COMMAND_FAILED","find wait timed out")}async function ac(e,t,a,n){let r=n??1e4,i=tX(e),s=C(a);for(;tX(e)-i<r;){let a=B((await t6(e,t,{updateSession:!0})).snapshot.nodes,s,{platform:e.backend.platform});if(a)return{kind:"selector",selector:a.selector.raw,waitedMs:tX(e)-i};await tY(e,300)}throw new b("COMMAND_FAILED",`wait timed out for selector: ${a}`)}async function ad(e,t,a,n){let r=n??1e4,i=tX(e);for(;tX(e)-i<r;){if(e.backend.findText?(await e.backend.findText(tV(e,t),a)).found:await ap(e,t,a))return{kind:"text",text:a,waitedMs:tX(e)-i};await tY(e,300)}throw new b("COMMAND_FAILED",`wait timed out for text: ${a}`)}async function ap(e,t,a){return!!G((await t6(e,t,{updateSession:!0})).snapshot.nodes,a)}async function au(e,t,a,n){let r=await t6(e,{...t,session:a},{updateSession:!0}),i=C(n.selector),s=q(r.snapshot.nodes,i,{platform:e.backend.platform,requireRect:!1,requireUnique:!0,disambiguateAmbiguous:n.disambiguateAmbiguous});if(!s)throw new b("COMMAND_FAILED",Y(i,[],{unique:!0}));return{capture:r,node:s.node,selector:s.selector.raw,ref:`@${s.node.ref}`}}function ah(e){let t=am(e);if(!t)return null;let a=u(t);return Number.isFinite(a.x)&&Number.isFinite(a.y)?a:null}function am(e){if(!e)return null;let t=Number(e.x),a=Number(e.y),n=Number(e.width),r=Number(e.height);return Number.isFinite(t)&&Number.isFinite(a)&&Number.isFinite(n)&&Number.isFinite(r)&&!(n<0)&&!(r<0)?{x:t,y:a,width:n,height:r}:null}let af=["button","link","menuitem","tabitem","textfield","searchfield","securetextfield","checkbox","radio","switch","cell"];function ag(e,t){var a;let n=function(e,t){let a=am(t.rect);if(!a)return null;let n=t,r=new Set;for(;!r.has(n.ref);){r.add(n.ref);let t=e.filter(e=>{if(e.parentIndex!==n.index||!e.hittable)return!1;let t=am(e.rect);return!!t&&aw(t,a)});if(1!==t.length)break;n=t[0]}return n===t?null:n}(e,t);if(n?.rect&&ah(n.rect))return{node:n,reason:"same-rect-descendant"};if([(a=t).type,a.role,a.subrole].map(e=>K(e??"")).some(ab)&&t.rect&&ah(t.rect))return{node:t,reason:"semantic-target"};let r=$(e,t);return r?.rect&&ah(r.rect)?!function(e,t,a){var n,r,i,s;let o,l,c,d=am(e.rect),p=am(t.rect);if(!d||!p)return!1;let h=function(e,t){let a=u(t),n=e.filter(e=>{let t=(e.type??"").toLowerCase();return t.includes("application")||t.includes("window")}).map(e=>am(e.rect)).filter(e=>null!==e);if(0===n.length)return null;let r=n.filter(e=>J(e,a.x,a.y));return W(r.length>0?r:n)}(a,d);return!!h&&(n=p,r=h,o=(i=n,s=r,Math.max(0,Math.min(i.x+i.width,s.x+s.width)-Math.max(i.x,s.x))*Math.max(0,Math.min(i.y+i.height,s.y+s.height)-Math.max(i.y,s.y))),l=n.width*n.height,c=r.width*r.height,!(o<=0)&&!(l<=0)&&!(c<=0)&&!!(o/c>=.9)&&!!(o/l>=.8))&&!aw(d,p)}(t,r,e)?{node:r,reason:"hittable-ancestor"}:{node:t,reason:"overly-broad-ancestor"}:{node:t,reason:"original"}}function ab(e){return"tab"===e||af.some(t=>e.includes(t))}function aw(e,t){return .5>=Math.abs(e.x-t.x)&&.5>=Math.abs(e.y-t.y)&&.5>=Math.abs(e.width-t.width)&&.5>=Math.abs(e.height-t.height)}async function ay(e,t,a){if(await ak(e,t,a.action),"point"===t.target.kind)return{kind:"point",point:{x:t.target.x,y:t.target.y}};if("ref"===t.target.kind){let n=await aA(e,t,t.target),r=n.resolved,i=a.promoteToHittableAncestor?ag(n.snapshot.nodes,r.node).node:r.node;return function(e,t,a,n){let r=e.rect?es(e,t):null;if(!(!e.rect||!r||ei(e,t)))throw new b("COMMAND_FAILED",`Ref ${a} is off-screen and not safe to ${n}`,{reason:"offscreen_ref",ref:p(a),rect:e.rect,viewport:r,hint:`Use scroll with the direction from the off-screen summary, take a fresh snapshot, then retry ${n} with the new ref or a selector.`})}(i,n.snapshot.nodes,t.target.ref,a.action),{kind:"ref",point:aI(i,`Ref ${t.target.ref} not found or has invalid bounds`),target:{kind:"ref",ref:`@${r.ref}`},node:i,selectorChain:F(i,e.backend.platform,{action:"fill"===a.action?"fill":"click"}),refLabel:j(i,n.snapshot.nodes)}}let n=await av(e,t,a.requireInteractive),r=C(t.target.selector),i=q(n.snapshot.nodes,r,{platform:e.backend.platform,requireRect:!0,requireUnique:!0,disambiguateAmbiguous:!0});if(!i||!i.node.rect)throw new b("COMMAND_FAILED",Y(r,i?.diagnostics??[],{unique:!0}));let s=a.promoteToHittableAncestor?ag(n.snapshot.nodes,i.node).node:i.node;return{kind:"selector",point:aI(s,`Selector ${i.selector.raw} resolved to invalid bounds`),target:{kind:"selector",selector:i.selector.raw},node:s,selectorChain:F(s,e.backend.platform,{action:"fill"===a.action?"fill":"click"}),refLabel:j(s,n.snapshot.nodes)}}async function av(e,t,a){if(!e.backend.captureSnapshot)throw new b("UNSUPPORTED_OPERATION","snapshot is not supported by this backend");let n=t.session??"default",r=await e.sessions.get(n);if(!r)throw new b("SESSION_NOT_FOUND","No active session. Run open first.");let i=await e.backend.captureSnapshot(tV(e,t),{interactiveOnly:a,compact:a}),s=i.snapshot??{nodes:i.nodes??[],truncated:i.truncated,backend:i.backend,createdAt:tX(e)};return await e.sessions.set({...r,snapshot:s}),{snapshot:s}}async function ak(e,t,a){if("macos"!==e.backend.platform)return;let n=await ax(e,t);if(("desktop"===n||"menubar"===n)&&("menubar"!==n||"click"!==a&&"press"!==a))throw new b("UNSUPPORTED_OPERATION",`${a} is not supported on macOS ${n} sessions yet. Open an app session to act, or use the ${n} surface to inspect.`)}async function ax(e,t){let a=await e.sessions.get(t.session??"default");return a?.metadata?.surface}async function aA(e,t,a){let n=t.session??"default",r=await e.sessions.get(n);if(!r)throw new b("SESSION_NOT_FOUND","No active session. Run open first.");if(!r.snapshot)throw new b("INVALID_ARGS","No snapshot in session. Run snapshot first.");let i=a.fallbackLabel??"",s=aD(r.snapshot.nodes,a.ref,{fallbackLabel:i,requireRect:!0});if(s)return{snapshot:r.snapshot,resolved:s};let o=await av(e,t,!0),l=aD(o.snapshot.nodes,a.ref,{fallbackLabel:i,requireRect:!0});if(!l)throw new b("COMMAND_FAILED",`Ref ${a.ref} not found or has no bounds`);return{...o,resolved:l}}function aD(e,t,a){let n=p(t);if(!n)throw new b("INVALID_ARGS",`Invalid ref: ${t}`);let r=m(e,n);if(aR(r,a.requireRect))return{ref:n,node:r};let i=a.fallbackLabel.length>0?G(e,a.fallbackLabel):null;return aR(i,a.requireRect)?{ref:n,node:i}:null}function aI(e,t){if(!e.rect)throw new b("COMMAND_FAILED",t);let a=u(e.rect);if(!Number.isFinite(a.x)||!Number.isFinite(a.y))throw new b("COMMAND_FAILED",t);return a}function aR(e,t){if(!e)return!1;if(!t)return!0;if(!e.rect)return!1;let{x:a,y:n,width:r,height:i}=e.rect;if(!Number.isFinite(Number(a))||!Number.isFinite(Number(n))||!Number.isFinite(Number(r))||!Number.isFinite(Number(i))||0>Number(r)||0>Number(i))return!1;let s=u(e.rect);return Number.isFinite(s.x)&&Number.isFinite(s.y)}async function aS(e,t){let a=t.target??{kind:"viewport"};return"viewport"===a.kind?(await ak(e,t,"scroll"),{kind:"viewport"}):await ay(e,{...t,target:a},{action:"scroll",requireInteractive:!1,promoteToHittableAncestor:!1})}async function aM(e,t){if(t.from){var a;if("x"in(a=t.from)&&"y"in a)return await ak(e,t,"swipe"),{point:aO(t.from,"from")};let n=await ay(e,{...t,target:t.from},{action:"swipe",requireInteractive:!1,promoteToHittableAncestor:!1});return{point:n.point,target:n}}if(!t.direction)throw new b("INVALID_ARGS","swipe requires from+to or a direction");return await ak(e,t,"swipe"),{point:u(function(e){let t=e.filter(t=>ei(t,e)).map(e=>e.rect).filter(aP),a=t.length>0?t:e.map(e=>e.rect).filter(aP);if(0===a.length)throw new b("COMMAND_FAILED","Cannot infer viewport for directional swipe");let n=Math.min(...a.map(e=>e.x)),r=Math.min(...a.map(e=>e.y));return{x:n,y:r,width:Math.max(...a.map(e=>e.x+e.width))-n,height:Math.max(...a.map(e=>e.y+e.height))-r}}((await av(e,t,!1)).snapshot.nodes)),target:{kind:"viewport"}}}function aN(e,t){switch(e){case"up":case"down":case"left":case"right":return e;default:throw new b("INVALID_ARGS",`${t} must be up, down, left, or right`)}}function aO(e,t){let a=Number(e.x),n=Number(e.y);if(!Number.isFinite(a)||!Number.isFinite(n))throw new b("INVALID_ARGS",`${t} point requires finite x and y`);return{x:a,y:n}}function aL(e,t){if(!Number.isFinite(e)||e<=0)throw new b("INVALID_ARGS",`${t} must be a positive number`);return e}function aP(e){return!!(e&&e.width>0&&e.height>0)}function aE(e){return e&&"object"==typeof e?e:void 0}async function aC(e,t,a){let n=await ay(e,t,{action:a,requireInteractive:!0,promoteToHittableAncestor:!0});if(!e.backend.tap)throw new b("UNSUPPORTED_OPERATION","tap is not supported by this backend");let r=aU(await e.backend.tap(tV(e,t),n.point,{button:t.button,count:t.count,intervalMs:t.intervalMs,holdMs:t.holdMs,jitterPx:t.jitterPx,doubleTap:t.doubleTap}));return{...n,...r?{backendResult:r}:{}}}function aU(e){return e&&"object"==typeof e?e:void 0}function aT(e,t){if(void 0!==e)return a_(e,t)}function a_(e,t){let a=e?.trim();if(!a)throw new b("INVALID_ARGS",`${t} must be a non-empty string`);return a}function a$(e){return!!(e&&"object"==typeof e)}function aF(e){return e&&"object"==typeof e?e:void 0}let aB=/^[A-Za-z0-9_.:-]{1,64}$/;async function aq(e,t){if(!t||"object"!=typeof t)throw new b("INVALID_ARGS","apps.push requires an input");if("json"===t.kind)return aG(t.payload,"apps.push JSON payload",8192),{backendInput:{kind:"json",payload:t.payload},inputKind:"json"};let a=await eq(e,t,{usage:"apps.push",field:"input"});return{backendInput:{kind:"file",path:a.path},inputKind:"file",...a.cleanup?{cleanup:a.cleanup}:{}}}function aG(e,t,a){if(function(e,t){if(!e||"object"!=typeof e||Array.isArray(e))throw new b("INVALID_ARGS",`${t} must be a JSON object`)}(e,t),Buffer.byteLength(function(e,t){try{let a=JSON.stringify(e);if("string"!=typeof a)throw new b("INVALID_ARGS",`${t} must be JSON-serializable`);return a}catch{throw new b("INVALID_ARGS",`${t} must be JSON-serializable`)}}(e,t),"utf8")>a)throw new b("INVALID_ARGS",`${t} exceeds ${a} bytes`)}function aj(e,t){return{session:t.session,requestId:t.requestId,signal:t.signal??e.signal,metadata:t.metadata}}function aV(e){return e&&"object"==typeof e?e:void 0}async function aX(e,t,a){let n="reinstall"===a?"reinstallApp":"installApp",r=e.backend[n];if(!r)throw new b("UNSUPPORTED_OPERATION",`admin.${a} is not supported by this backend`);let i="app"in t&&void 0!==t.app?a_(t.app,"app"):void 0;if("installFromSource"!==a&&!i)throw new b("INVALID_ARGS",`admin.${a} requires app`);let s=tV(e,t),o=await aY(e,s,t.source);try{var l,c,d,p,u;let t,n,h,m,f,g,b,w,y=await r.call(e.backend,s,{...i?{app:i}:{},source:o.source});return l=a,c=i,d=o.source,p=y,t=aJ(p),n=aH(p,"appName"),h=aH(p,"appId"),m=aH(p,"bundleId"),f=aH(p,"packageName"),g=aH(p,"launchTarget"),b=aH(p,"installablePath"),w=aH(p,"archivePath"),{kind:"reinstall"===l?"appReinstalled":"installFromSource"===l?"appInstalledFromSource":"appInstalled",...c?{app:c}:{},source:d,...h?{appId:h}:{},...n?{appName:n}:{},...m?{bundleId:m}:{},...f?{packageName:f}:{},...g?{launchTarget:g}:{},...b?{installablePath:b}:{},...w?{archivePath:w}:{},...t?{backendResult:t}:{},...D(`${"reinstall"===l?"Reinstalled":"Installed"}: ${n??g??c??(u=d,"path"===u.kind?u.path:"uploadedArtifact"===u.kind?u.id:u.url)}`)}}finally{await o.cleanup?.()}}async function aY(e,t,a){let n=az(a),r=await aK(e,n);try{let a=e.backend.resolveInstallSource?await e.backend.resolveInstallSource(t,r.source):r.source;return{source:az(a),...r.cleanup?{cleanup:r.cleanup}:{}}}catch(e){if(r.cleanup)try{await r.cleanup()}catch{}throw e}}async function aK(e,t){if("url"===t.kind)return{source:t};let a=await eq(e,t,{usage:"admin.install",field:"source"});return{source:{kind:"path",path:a.path},...a.cleanup?{cleanup:a.cleanup}:{}}}function az(e){if(!e||"object"!=typeof e)throw new b("INVALID_ARGS","install source is required");if("path"===e.kind)return{kind:"path",path:a_(e.path,"source.path")};if("uploadedArtifact"===e.kind)return{kind:"uploadedArtifact",id:a_(e.id,"source.id")};if("url"===e.kind){let t=a_(e.url,"source.url");return function(e){let t;try{t=new URL(e)}catch{throw new b("INVALID_ARGS",`Invalid install source URL: ${e}`)}if("http:"!==t.protocol&&"https:"!==t.protocol)throw new b("INVALID_ARGS","Install source URL must use http or https")}(t),{kind:"url",url:t}}throw new b("INVALID_ARGS","install source kind must be path, uploadedArtifact, or url")}function aH(e,t){let a=e[t];return"string"==typeof a&&a.length>0?a:void 0}function aJ(e){return e&&"object"==typeof e?e:void 0}function aW(e,t){if("start"===e||"stop"===e)return e;throw new b("INVALID_ARGS",`${t} action must be start or stop`)}function aQ(e,t,a,n){return{kind:"start"===e?n.startKind:n.stopKind,action:e,...a?{artifact:a}:{},backendResult:t,...D("start"===e?n.startMessage:n.stopMessage)}}let aZ=/(?:authorization|cookie|token|secret|password|passwd|api[-_]?key)/i,a0=/\b[A-Za-z0-9_-]{16,}\.[A-Za-z0-9_-]{16,}\.[A-Za-z0-9_-]{16,}\b/g;function a1(e){var t,a;let n=!1,r=e;return{value:(t=r=(r=(r=(r=(r=r.replaceAll(/(authorization|token|secret|password|passwd|api[-_]?key)=([^&\s]+)/gi,(e,t)=>(n=!0,`${String(t)}=[REDACTED]`))).replaceAll(/("(?:authorization|cookie|token|secret|password|passwd|api[-_]?key)"\s*:\s*")([^"]*)(")/gi,(e,t,a,r)=>(n=!0,`${String(t)}[REDACTED]${String(r)}`))).replaceAll(/\b(Bearer\s+)([^\s",;]+)/gi,(e,t)=>(n=!0,`${String(t)}[REDACTED]`))).replaceAll(/((?:authorization|cookie|token|secret|password|passwd|api[-_]?key)\s*[:=]\s*)([^\s,;&]+)/gi,(e,t)=>(n=!0,`${String(t)}[REDACTED]`))).replaceAll(a0,()=>(n=!0,"[REDACTED]")),a=()=>{n=!0},r=/(https?:\/\/|token|secret|password|authorization|cookie|api[-_]?key)/i.test(t)?t.replaceAll(/https?:\/\/[^\s"'<>)]+/gi,e=>{let t=a2(e);return t?(t.redacted&&a(),t.value):e}):t),redacted:n}}function a2(e){try{let t=new URL(e),a=function(e){let t=!1;for(let a of Array.from(e.searchParams.keys()))aZ.test(a)&&(e.searchParams.set(a,"[REDACTED]"),t=!0);return t}(t);return(t.username||t.password)&&(t.username="REDACTED",t.password="REDACTED",a=!0),{value:t.toString(),redacted:a}}catch{return}}let a5=/(?:authorization|cookie|token|secret|password|passwd|api[-_]?key)/i;function a3(e){if(!e)return{redacted:!1};let t=!1,a={};for(let[n,r]of Object.entries(e))if(a5.test(n))a[n]="[REDACTED]",t=!0;else{let e=a7(r,2048);a[n]=e.value??"",t||=e.redacted}return{value:a,redacted:t}}function a4(e){return void 0===e?{redacted:!1}:function(e){try{let t=JSON.parse(e),a=a6(t,a1);return a9(JSON.stringify(a.value),2048,a.redacted)}catch{return}}(e)??a7(e,2048)}function a8(e){return a6(e,e=>a7(e,2048))}function a6(e,t){if(void 0===e)return{redacted:!1};if("string"==typeof e)return t(e);if(!e||"object"!=typeof e)return{value:e,redacted:!1};if(Array.isArray(e)){let a=!1;return{value:e.map(e=>{let n=a6(e,t);return a||=n.redacted,n.value}),redacted:a}}let a=!1,n={};for(let[r,i]of Object.entries(e)){if(a5.test(r)){n[r]="[REDACTED]",a=!0;continue}let e=a6(i,t);n[r]=e.value,a||=e.redacted}return{value:n,redacted:a}}function a7(e,t){if(void 0===e)return{redacted:!1};let a=a1(e);return a9(a.value,t,a.redacted)}function a9(e,t,a){if(void 0===e)return{redacted:a};let n=e;return n.length>t&&(n=`${n.slice(0,t)}...[truncated]`,a=!0),{value:n,redacted:a}}async function ne(e,t){let a=tV(e,t),n=t.session?await e.sessions.get(t.session):void 0;return{...a,...t.appId??n?.appId?{appId:t.appId??n?.appId}:{},...t.appBundleId??n?.appBundleId?{appBundleId:t.appBundleId??n?.appBundleId}:{}}}function nt(e,t,a,n){return{...na(e),...void 0!==e.cursor?{cursor:a_(e.cursor,"cursor")}:{},limit:void 0===e.limit?t:eD(e.limit,n,1,a)}}function na(e){return{...void 0!==e.since?{since:a_(e.since,"since")}:{},...void 0!==e.until?{until:a_(e.until,"until")}:{}}}function nn(e,t,a=50){if(!Array.isArray(e))throw new b("INVALID_ARGS",`${t} must be an array of strings`);if(e.length>a)throw new b("INVALID_ARGS",`${t} must contain at most ${a} entries`);return e.map((e,a)=>a_(e,`${t}[${a}]`))}let nr=eV,ni=tA,ns=tK,no=tz,nl=t9,nc=ae,nd=at,np=aa,nu=an,nh=ar,nm=ai,nf=as,ng=ao,nb=async(e,t)=>await aC(e,t,"click"),nw=async(e,t)=>await aC(e,t,"press"),ny=async(e,t)=>{var a;if(!t.text)throw new b("INVALID_ARGS","fill requires text");let n=await ay(e,t,{action:"fill",requireInteractive:!0,promoteToHittableAncestor:!1});if(!e.backend.fill)throw new b("UNSUPPORTED_OPERATION","fill is not supported by this backend");let r=aU(await e.backend.fill(tV(e,t),n.point,t.text,{delayMs:t.delayMs})),i="node"in n?n.node.type??"":"",s=i&&!z(i,e.backend.platform)?`fill target ${a=n,a.target?.kind==="ref"?a.target.ref:a.target?.kind==="selector"?a.target.selector:"point"} resolved to "${i}", attempting fill anyway.`:void 0;return{...n,text:t.text,...s?{warning:s}:{},...r?{backendResult:r}:{}}},nv=async(e,t)=>{let a=t.text;if(!a)throw new b("INVALID_ARGS","type requires text");let n=eA(a);if(n)throw new b("INVALID_ARGS",`type does not accept a target ref like "${n}"`,{hint:`Use fill ${n} "text" to target that field, or press ${n} then type "text" to append.`});if(!e.backend.typeText)throw new b("UNSUPPORTED_OPERATION","type is not supported by this backend");let r=eD(t.delayMs??0,"delay-ms",0,1e4),i=aU(await e.backend.typeText(tV(e,t),a,{delayMs:r}));return{kind:"text",text:a,delayMs:r,...i?{backendResult:i}:{},...D(`Typed ${Array.from(a).length} chars`)}},nk=async(e,t)=>{let a=await ay(e,t,{action:"focus",requireInteractive:!0,promoteToHittableAncestor:!1});if(!e.backend.focus)throw new b("UNSUPPORTED_OPERATION","focus is not supported by this backend");let n=aE(await e.backend.focus(tV(e,t),a.point));return{...a,...n?{backendResult:n}:{},...D(`Focused (${a.point.x}, ${a.point.y})`)}},nx=async(e,t)=>{let a=await ay(e,t,{action:"longPress",requireInteractive:!0,promoteToHittableAncestor:!0});if(!e.backend.longPress)throw new b("UNSUPPORTED_OPERATION","longPress is not supported by this backend");let n=void 0===t.durationMs?void 0:eD(t.durationMs,"durationMs",0,12e4),r=aE(await e.backend.longPress(tV(e,t),a.point,{durationMs:n}));return{...a,...void 0!==n?{durationMs:n}:{},...r?{backendResult:r}:{},...D(`Long pressed (${a.point.x}, ${a.point.y})`)}},nA=async(e,t)=>{if(!e.backend.swipe)throw new b("UNSUPPORTED_OPERATION","swipe is not supported by this backend");let a=await aM(e,t),n=function(e,t){if(t.to)return{point:aO(t.to,"to")};let a=aN(t.direction,"swipe direction"),n=aL(t.distance??200,"swipe distance");switch(a){case"up":return{point:{x:e.x,y:e.y-n},direction:a,distance:n};case"down":return{point:{x:e.x,y:e.y+n},direction:a,distance:n};case"left":return{point:{x:e.x-n,y:e.y},direction:a,distance:n};case"right":return{point:{x:e.x+n,y:e.y},direction:a,distance:n}}}(a.point,t),r=void 0===t.durationMs?void 0:eD(t.durationMs,"durationMs",16,1e4),i=aE(await e.backend.swipe(tV(e,t),a.point,n.point,{durationMs:r}));return{kind:"swipe",from:a.point,to:n.point,...n.direction?{direction:n.direction}:{},...void 0!==n.distance?{distance:n.distance}:{},...void 0!==r?{durationMs:r}:{},...a.target?{fromTarget:a.target}:{},...i?{backendResult:i}:{},...D("Swiped")}},nD=async(e,t)=>{var a,n;if(!e.backend.scroll)throw new b("UNSUPPORTED_OPERATION","scroll is not supported by this backend");let r=aN(t.direction,"scroll direction"),i=(a=t.amount,n="scroll amount",void 0===a?void 0:aL(a,n)),s=function(e,t){if(void 0!==e){if(!Number.isFinite(e)||!Number.isInteger(e)||e<=0)throw new b("INVALID_ARGS",`${t} must be a positive integer`);return e}}(t.pixels,"scroll pixels");if(void 0!==i&&void 0!==s)throw new b("INVALID_ARGS","scroll accepts either amount or pixels, not both");let o=await aS(e,t),l="viewport"===o.kind?{kind:"viewport"}:{kind:"point",point:o.point},c=aE(await e.backend.scroll(tV(e,t),l,{direction:r,...void 0!==i?{amount:i}:{},...void 0!==s?{pixels:s}:{}}));return{...o,direction:r,...void 0!==i?{amount:i}:{},...void 0!==s?{pixels:s}:{},...c?{backendResult:c}:{},...D(void 0!==s?`Scrolled ${r} by ${s}px`:void 0!==i?`Scrolled ${r} by ${i}`:`Scrolled ${r}`)}},nI=async(e,t)=>{if(!e.backend.pinch)throw new b("UNSUPPORTED_OPERATION","pinch is not supported by this backend");await ak(e,t,"pinch");let a=aL(t.scale,"pinch scale"),n=t.center?await ay(e,{...t,target:t.center},{action:"pinch",requireInteractive:!1,promoteToHittableAncestor:!1}):void 0,r=aE(await e.backend.pinch(tV(e,t),{scale:a,...n?{center:n.point}:{}}));return{kind:"pinch",scale:a,...n?{center:n.point,centerTarget:n}:{},...r?{backendResult:r}:{},...D(`Pinched to scale ${a}`)}},nR=async(e,t={})=>{if(!e.backend.pressBack)throw new b("UNSUPPORTED_OPERATION","system.back is not supported by this backend");let a=t.mode??"in-app";if("in-app"!==a&&"system"!==a)throw new b("INVALID_ARGS","system.back mode must be in-app or system");let n=aF(await e.backend.pressBack(tV(e,t),{mode:a}));return{kind:"systemBack",mode:a,...n?{backendResult:n}:{},...D("Back")}},nS=async(e,t={})=>{if(!e.backend.pressHome)throw new b("UNSUPPORTED_OPERATION","system.home is not supported by this backend");let a=aF(await e.backend.pressHome(tV(e,t)));return{kind:"systemHome",...a?{backendResult:a}:{},...D("Home")}},nM=async(e,t)=>{if(!e.backend.rotate)throw new b("UNSUPPORTED_OPERATION","system.rotate is not supported by this backend");let a=function(e){switch(e){case"portrait":case"portrait-upside-down":case"landscape-left":case"landscape-right":return e;default:throw new b("INVALID_ARGS","system.rotate orientation must be portrait, portrait-upside-down, landscape-left, or landscape-right")}}(t.orientation),n=aF(await e.backend.rotate(tV(e,t),a));return{kind:"systemRotated",orientation:a,...n?{backendResult:n}:{},...D(`Rotated to ${a}`)}},nN=async(e,t={})=>{if(!e.backend.setKeyboard)throw new b("UNSUPPORTED_OPERATION","system.keyboard is not supported by this backend");let a=t.action??"status";if("status"!==a&&"get"!==a&&"dismiss"!==a)throw new b("INVALID_ARGS","system.keyboard action must be status, get, or dismiss");let n=await e.backend.setKeyboard(tV(e,t),{action:a}),r=aF(n);if("dismiss"===a){let e=a$(n)?n.dismissed:void 0;return{kind:"keyboardDismissed",action:a,state:a$(n)?n:{},...r?{backendResult:r}:{},...D(!1===e?"Keyboard already hidden":"Keyboard dismissed")}}return{kind:"keyboardState",action:a,state:a$(n)?n:{},...r?{backendResult:r}:{}}},nO=async(e,t)=>{if("read"===t.action){if(!e.backend.getClipboard)throw new b("UNSUPPORTED_OPERATION","system.clipboard read is not supported by this backend");let a=await e.backend.getClipboard(tV(e,t));return{kind:"clipboardText",action:"read",text:"string"==typeof a?a:a.text}}if("write"!==t.action)throw new b("INVALID_ARGS","system.clipboard action must be read or write");if(!e.backend.setClipboard)throw new b("UNSUPPORTED_OPERATION","system.clipboard write is not supported by this backend");if("string"!=typeof t.text)throw new b("INVALID_ARGS","system.clipboard write requires text");let a=aF(await e.backend.setClipboard(tV(e,t),t.text));return{kind:"clipboardUpdated",action:"write",textLength:Array.from(t.text).length,...a?{backendResult:a}:{},...D("Clipboard updated")}},nL=async(e,t={})=>{if(!e.backend.openSettings)throw new b("UNSUPPORTED_OPERATION","system.settings is not supported by this backend");let a=aT(t.target,"target"),n=aF(await e.backend.openSettings(tV(e,t),a));return{kind:"settingsOpened",...a?{target:a}:{},...n?{backendResult:n}:{},...D(a?`Opened settings: ${a}`:"Opened settings")}},nP=async(e,t={})=>{if(!e.backend.handleAlert)throw new b("UNSUPPORTED_OPERATION","system.alert is not supported by this backend");let a=t.action??"get";if("get"!==a&&"accept"!==a&&"dismiss"!==a&&"wait"!==a)throw new b("INVALID_ARGS","system.alert action must be get, accept, dismiss, or wait");let n=void 0===t.timeoutMs?void 0:eD(t.timeoutMs,"timeoutMs",0,12e4),r=await e.backend.handleAlert(tV(e,t),a,{timeoutMs:n});var i=a,s=r;if("get"===i){if("alertStatus"!==s.kind)throw new b("COMMAND_FAILED","system.alert get returned an invalid backend result");return{kind:"alertStatus",action:i,alert:s.alert}}if("wait"===i){if("alertWait"!==s.kind)throw new b("COMMAND_FAILED","system.alert wait returned an invalid backend result");return{kind:"alertWait",action:i,alert:s.alert,...void 0!==s.waitedMs?{waitedMs:s.waitedMs}:{},...void 0!==s.timedOut?{timedOut:s.timedOut}:{},...D(s.alert?"Alert visible":"Alert wait timed out")}}if("alertHandled"!==s.kind)throw new b("COMMAND_FAILED",`system.alert ${i} returned an invalid backend result`);return{kind:"alertHandled",action:i,handled:s.handled,...s.alert?{alert:s.alert}:{},...s.button?{button:s.button}:{},...D(s.handled?`Alert ${i}ed`:"No alert handled")}},nE=async(e,t={})=>{if(!e.backend.openAppSwitcher)throw new b("UNSUPPORTED_OPERATION","system.appSwitcher is not supported by this backend");let a=aF(await e.backend.openAppSwitcher(tV(e,t)));return{kind:"appSwitcherOpened",...a?{backendResult:a}:{},...D("Opened app switcher")}},nC=async(e,t)=>{var a;if(!e.backend.openApp)throw new b("UNSUPPORTED_OPERATION","apps.open is not supported by this backend");let n=function(e){var t;let a=aT(e.app,"app"),n=aT(e.appId,"appId"),r=aT(e.bundleId,"bundleId"),i=aT(e.packageName,"packageName"),s=aT(e.url,"url"),o=aT(e.activity,"activity"),l={...a?{app:a}:{},...n?{appId:n}:{},...r?{bundleId:r}:{},...i?{packageName:i}:{},...s?{url:s}:{},...o?{activity:o}:{}};if(!((t=l).app??t.appId??t.bundleId??t.packageName??t.url??t.activity))throw new b("INVALID_ARGS","apps.open requires app, appId, bundleId, packageName, url, or activity");return l}(t),r=aV(await e.backend.openApp(aj(e,t),n,{relaunch:t.relaunch}));return{kind:"appOpened",target:n,relaunch:!0===t.relaunch,...r?{backendResult:r}:{},...D(`Opened: ${(a=n).app??a.appId??a.bundleId??a.packageName??a.url??a.activity??"app"}`)}},nU=async(e,t={})=>{if(!e.backend.closeApp)throw new b("UNSUPPORTED_OPERATION","apps.close is not supported by this backend");let a=aT(t.app,"app"),n=aV(await e.backend.closeApp(aj(e,t),a));return{kind:"appClosed",...a?{app:a}:{},...n?{backendResult:n}:{},...D(a?`Closed: ${a}`:"Closed app")}},nT=async(e,t={})=>{if(!e.backend.listApps)throw new b("UNSUPPORTED_OPERATION","apps.list is not supported by this backend");return{kind:"appsList",apps:await e.backend.listApps(aj(e,t),N(t.filter))}},n_=async(e,t)=>{if(!e.backend.getAppState)throw new b("UNSUPPORTED_OPERATION","apps.state is not supported by this backend");let a=a_(t.app,"app"),n=await e.backend.getAppState(aj(e,t),a);return{kind:"appState",app:a,state:n}},n$=async(e,t)=>{if(!e.backend.pushFile)throw new b("UNSUPPORTED_OPERATION","apps.push is not supported by this backend");let a=a_(t.app,"app"),n=await aq(e,t.input);try{let r=await e.backend.pushFile(aj(e,t),n.backendInput,a),i=aV(r);return{kind:"appPushed",app:a,inputKind:n.inputKind,...i?{backendResult:i}:{},...D(`Pushed to ${a}`)}}finally{await n.cleanup?.()}},nF=async(e,t)=>{var a,n;if(!e.backend.triggerAppEvent)throw new b("UNSUPPORTED_OPERATION","apps.triggerEvent is not supported by this backend");let r=function(e){let t=a_(e,"name");if(!aB.test(t))throw new b("INVALID_ARGS",`Invalid apps.triggerEvent name: ${t}`,{hint:"Use 1-64 chars: letters, numbers, underscore, dot, colon, or dash."});return t}(t.name);a=t.payload,n=`apps.triggerEvent payload for "${r}"`,void 0!==a&&aG(a,n,8192);let i=aV(await e.backend.triggerAppEvent(aj(e,t),{name:r,...t.payload?{payload:t.payload}:{}}));return{kind:"appEventTriggered",name:r,...t.payload?{payload:t.payload}:{},...i?{backendResult:i}:{},...D(`Triggered app event: ${r}`)}},nB=async(e,t={})=>{if(!e.backend.listDevices)throw new b("UNSUPPORTED_OPERATION","admin.devices is not supported by this backend");return{kind:"adminDevices",devices:await e.backend.listDevices(tV(e,t),t.filter)}},nq=async(e,t={})=>{if(!e.backend.bootDevice)throw new b("UNSUPPORTED_OPERATION","admin.boot is not supported by this backend");let a=function(e){if(!e)return;let t=aT(e.id,"target.id"),a=aT(e.name,"target.name"),n={...t?{id:t}:{},...a?{name:a}:{},...e.platform?{platform:e.platform}:{},...e.target?{target:e.target}:{},...void 0!==e.headless?{headless:e.headless}:{}};return Object.keys(n).length>0?n:void 0}(t.target),n=aJ(await e.backend.bootDevice(tV(e,t),a));return{kind:"deviceBooted",...a?{target:a}:{},...n?{backendResult:n}:{},...D("Booted device")}},nG=async(e,t)=>await aX(e,t,"install"),nj=async(e,t)=>await aX(e,t,"reinstall"),nV=async(e,t)=>await aX(e,t,"installFromSource"),nX=async(e,t)=>{let a=aW(t.action,"record"),n="start"===a?e.backend.startRecording:e.backend.stopRecording;if(!n)throw new b("UNSUPPORTED_OPERATION",`record ${a} is not supported by this backend`);let r=t.out?await eG(e,t.out,{field:"path",ext:".mp4"}):void 0;try{var i,s,o,l,c;let d,p,u=(i=t,s=r?.path,d=void 0===i.fps?void 0:eD(i.fps,"fps",1,60),p=void 0===i.quality?void 0:eD(i.quality,"quality",5,10),{...s?{outPath:s}:{},...void 0!==d?{fps:d}:{},...void 0!==p?{quality:p}:{},...void 0!==i.hideTouches?{showTouches:!0!==i.hideTouches}:{}}),h=await n.call(e.backend,tV(e,t),u),m=await r?.publish();return o=a,l=h,c=m,{..."string"==typeof l.path?{path:l.path}:{},..."string"==typeof l.telemetryPath?{telemetryPath:l.telemetryPath}:{},..."string"==typeof l.warning?{warning:l.warning}:{},...aQ(o,l,c,{startKind:"recordingStarted",stopKind:"recordingStopped",startMessage:"Recording started",stopMessage:"Recording stopped"})}}catch(e){throw await r?.cleanup?.(),e}},nY=async(e,t)=>{let a=aW(t.action,"trace"),n="start"===a?e.backend.startTrace:e.backend.stopTrace;if(!n)throw new b("UNSUPPORTED_OPERATION",`trace ${a} is not supported by this backend`);let r=t.out?await eG(e,t.out,{field:"outPath",ext:".trace"}):void 0;try{var i,s,o;let l={...r?.path?{outPath:r.path}:{}},c=await n.call(e.backend,tV(e,t),l),d=await r?.publish();return i=a,s=c,o=d,{..."string"==typeof s.outPath?{outPath:s.outPath}:{},...aQ(i,s,o,{startKind:"traceStarted",stopKind:"traceStopped",startMessage:"Trace started",stopMessage:"Trace stopped"})}}catch(e){throw await r?.cleanup?.(),e}},nK=async(e,t={})=>{var a,n;let r;if(!e.backend.readLogs)throw new b("UNSUPPORTED_OPERATION","diagnostics.logs is not supported by this backend");return r=!0===(a=await e.backend.readLogs(await ne(e,t),{...nt(n=t,100,500,"logs limit"),...void 0!==n.levels?{levels:nn(n.levels,"levels")}:{},...void 0!==n.search?{search:a_(n.search,"search")}:{},...void 0!==n.source?{source:a_(n.source,"source")}:{}})).redacted,{kind:"diagnosticsLogs",entries:a.entries.map(e=>{let t=a7(e.message,4096),a=a8(e.metadata);return r||=t.redacted||a.redacted,{...e.timestamp?{timestamp:e.timestamp}:{},...e.level?{level:e.level}:{},message:t.value??"",...e.source?{source:e.source}:{},...a.value?{metadata:a.value}:{}}}),...a.nextCursor?{nextCursor:a.nextCursor}:{},...a.timeWindow?{timeWindow:a.timeWindow}:{},...a.backend?{backend:a.backend}:{},redacted:r,...a.notes?{notes:a.notes}:{}}},nz=async(e,t={})=>{var a,n,r;let i;if(!e.backend.dumpNetwork)throw new b("UNSUPPORTED_OPERATION","diagnostics.network is not supported by this backend");let s={...nt(r=t,25,200,"network limit"),include:function(e){if(void 0===e)return"summary";if("summary"===e||"headers"===e||"body"===e||"all"===e)return e;throw new b("INVALID_ARGS","network include must be summary, headers, body, or all")}(r.include)};return a=await e.backend.dumpNetwork(await ne(e,t),s),n=s.include??"summary",i=!0===a.redacted,{kind:"diagnosticsNetwork",entries:a.entries.map(e=>{var t;let a=e.url?a2(t=e.url)??a7(t,2048):void 0,r="headers"===n||"all"===n?a3(e.requestHeaders):void 0,s="headers"===n||"all"===n?a3(e.responseHeaders):void 0,o="body"===n||"all"===n?a4(e.requestBody):void 0,l="body"===n||"all"===n?a4(e.responseBody):void 0,c=a8(e.metadata);return i||=(a?.redacted??!1)||(r?.redacted??!1)||(s?.redacted??!1)||(o?.redacted??!1)||(l?.redacted??!1)||c.redacted,{...e.timestamp?{timestamp:e.timestamp}:{},...e.method?{method:e.method}:{},...a?{url:a.value}:{},...void 0!==e.status?{status:e.status}:{},...void 0!==e.durationMs?{durationMs:e.durationMs}:{},...r?.value?{requestHeaders:r.value}:{},...s?.value?{responseHeaders:s.value}:{},...o?.value!==void 0?{requestBody:o.value}:{},...l?.value!==void 0?{responseBody:l.value}:{},...c.value?{metadata:c.value}:{}}}),...a.nextCursor?{nextCursor:a.nextCursor}:{},...a.timeWindow?{timeWindow:a.timeWindow}:{},...a.backend?{backend:a.backend}:{},redacted:i,...a.notes?{notes:a.notes}:{}}},nH=async(e,t={})=>{var a,n;let r;if(!e.backend.measurePerf)throw new b("UNSUPPORTED_OPERATION","diagnostics.perf is not supported by this backend");return r=!0===(a=await e.backend.measurePerf(await ne(e,t),{...na(n=t),...void 0!==n.sampleMs?{sampleMs:eD(n.sampleMs,"sampleMs",100,6e4)}:{},...void 0!==n.metrics?{metrics:nn(n.metrics,"metrics",20)}:{}})).redacted,{kind:"diagnosticsPerf",metrics:a.metrics.map(e=>{let t=a7(e.message,4096),a=a8(e.metadata);return r||=t.redacted||a.redacted,{name:e.name,...void 0!==e.value?{value:e.value}:{},...e.unit?{unit:e.unit}:{},...e.status?{status:e.status}:{},...void 0!==t.value?{message:t.value}:{},...a.value?{metadata:a.value}:{}}}),...a.startedAt?{startedAt:a.startedAt}:{},...a.endedAt?{endedAt:a.endedAt}:{},...a.backend?{backend:a.backend}:{},redacted:r,...a.notes?{notes:a.notes}:{}}};function nJ(e){let t={backend:e.backend,artifacts:e.artifacts,sessions:e.sessions??function(e=[]){let t=new Map(e.map(e=>[e.name,nW(e)]));return{get:e=>nW(t.get(e)),set:e=>{t.set(e.name,nW(e))},delete:e=>{t.delete(e)},list:()=>Array.from(t.values(),e=>nW(e))}}(),policy:e.policy??function(e={}){return{allowLocalInputPaths:!1,allowLocalOutputPaths:!1,maxImagePixels:2e7,allowNamedBackendCapabilities:[],...e}}(),diagnostics:e.diagnostics,clock:e.clock,signal:e.signal};return{...t,capture:{screenshot:e=>nr(t,e),diffScreenshot:e=>ni(t,e),snapshot:e=>ns(t,e),diffSnapshot:e=>no(t,e)},selectors:{find:e=>nl(t,e),get:e=>nc(t,e),getText:(e,a={})=>nd(t,{...a,target:e}),getAttrs:(e,a={})=>np(t,{...a,target:e}),is:e=>nu(t,e),isVisible:(e,a={})=>nh(t,{...a,target:e}),isHidden:(e,a={})=>nm(t,{...a,target:e}),wait:e=>nf(t,e),waitForText:(e,a={})=>ng(t,{...a,text:e})},interactions:{click:(e,a={})=>nb(t,{...a,target:e}),press:(e,a={})=>nw(t,{...a,target:e}),fill:(e,a,n={})=>ny(t,{...n,target:e,text:a}),typeText:(e,a={})=>nv(t,{...a,text:e}),focus:(e,a={})=>nk(t,{...a,target:e}),longPress:(e,a={})=>nx(t,{...a,target:e}),swipe:e=>nA(t,e),scroll:e=>nD(t,e),pinch:e=>nI(t,e)},system:{back:e=>nR(t,e),home:e=>nS(t,e),rotate:e=>nM(t,e),keyboard:e=>nN(t,e),clipboard:e=>nO(t,e),settings:e=>nL(t,e),alert:e=>nP(t,e),appSwitcher:e=>nE(t,e)},apps:{open:e=>nC(t,e),close:e=>nU(t,e),list:(e={})=>nT(t,{...e,filter:S(e.filter)}),state:e=>n_(t,e),push:e=>n$(t,e),triggerEvent:e=>nF(t,e)},admin:{devices:e=>nB(t,e),boot:e=>nq(t,e),install:e=>nG(t,e),reinstall:e=>nj(t,e),installFromSource:e=>nV(t,e)},recording:{record:e=>nX(t,e),trace:e=>nY(t,e)},observability:{logs:e=>nK(t,e),network:e=>nz(t,e),perf:e=>nH(t,e)}}}function nW(e){if(e)return{...e,...e.snapshot?{snapshot:structuredClone(e.snapshot)}:{},...e.metadata?{metadata:function(e){try{return structuredClone(e)}catch{return{...e}}}(e.metadata)}:{}}}function nQ(e={}){return{allowLocalInputPaths:!0,allowLocalOutputPaths:!0,maxImagePixels:2e7,allowNamedBackendCapabilities:[],...e}}let nZ=["app","frontmost-app","desktop","menubar"];function n0(e){let t=e?.trim().toLowerCase();if("app"===t||"frontmost-app"===t||"desktop"===t||"menubar"===t)return t;throw new b("INVALID_ARGS",`Invalid surface: ${e}. Use ${nZ.join("|")}.`)}let n1={workflow:{summary:"Normal agent-device bootstrap, exploration, and validation loop",body:`agent-device help workflow
|
|
2
|
+
|
|
3
|
+
Version-matched operating guide for normal agent-device work.
|
|
4
|
+
|
|
5
|
+
Core loop:
|
|
6
|
+
devices/apps -> open -> snapshot or snapshot -i -> get/is/find/wait or press/fill/scroll/back -> verify -> close
|
|
7
|
+
|
|
8
|
+
Command shape:
|
|
9
|
+
Plans should use agent-device commands, not raw platform tools, pseudo commands, package-manager aliases, or helper prose.
|
|
10
|
+
Put subcommand first, then positionals, then flags:
|
|
11
|
+
agent-device open com.example.app --session checkout --platform android --relaunch
|
|
12
|
+
agent-device record start ./checkout.mp4 --session checkout
|
|
13
|
+
Snapshot refs look like @e12. After snapshot -i, use the exact @eN ref from that output.
|
|
14
|
+
If the exact ref is not known yet, first output snapshot -i, then use a concrete example shape like press @e12 in the next command; do not write @<ref>, @ref, @Label_Name, or @eN placeholders.
|
|
15
|
+
Close means agent-device close. App-owned back means back; system back means back --system.
|
|
16
|
+
Taps are press or click. Gestures are direct commands: swipe, longpress, pinch.
|
|
17
|
+
|
|
18
|
+
Bootstrap:
|
|
19
|
+
agent-device devices --platform ios
|
|
20
|
+
agent-device apps --platform android
|
|
21
|
+
agent-device open MyApp --platform ios --device "iPhone 17 Pro"
|
|
22
|
+
agent-device open <discovered-app-id> --session checkout --platform android
|
|
23
|
+
agent-device install com.example.app ./dist/app.apk --platform android
|
|
24
|
+
agent-device reinstall com.example.app ./build/MyApp.app --platform ios
|
|
25
|
+
agent-device install-from-source --github-actions-artifact org/repo:app-debug --platform android
|
|
26
|
+
agent-device open com.example.app --platform android --relaunch
|
|
27
|
+
If app id is unknown, plan devices, apps, then open <discovered-app-id>. Discovery is not enough when the task asks to open/start the app.
|
|
28
|
+
Install arguments are app/package id then artifact path. If the task says install, use install; use reinstall only when explicitly requested. Fresh runtime state is open --relaunch after install.
|
|
29
|
+
Do not open artifact paths or invent package ids. If apps lookup misses the target and no URL/artifact is provided, ask or stop.
|
|
30
|
+
|
|
31
|
+
Snapshots and refs:
|
|
32
|
+
snapshot reads visible state. snapshot -i gets current interactive refs.
|
|
33
|
+
Default snapshot text is an agent-facing, token-efficient view for planning and targeting actions; use --raw or --json only when you need the full provider tree.
|
|
34
|
+
Snapshot legend:
|
|
35
|
+
@e12 [button] label="Add to cart" id="add-cart" enabled hittable -> press @e12 or press 'id="add-cart"'.
|
|
36
|
+
@e13 [textinput] label="Notes" preview="Leave at side..." truncated -> snapshot -s @e13 before reading.
|
|
37
|
+
@e14 [cell] label="Profiles" focused -> tvOS focus is currently on this row.
|
|
38
|
+
[off-screen below] 4 items: "Privacy", "About" -> scroll down, then snapshot -i; those are hints, not refs.
|
|
39
|
+
Re-snapshot after navigation, submit, modal/list/reload/dynamic changes.
|
|
40
|
+
Anti-pattern: snapshot -i followed by snapshot -i | grep ...
|
|
41
|
+
Refs from the first snapshot remain valid until you press, fill, scroll, go back, wait for async UI, or otherwise change app state.
|
|
42
|
+
For a targeted query, use find/get/is. If you truly need the full tree again, pass --force-full.
|
|
43
|
+
Off-screen summaries are scroll hints; use scroll, not swipe, then snapshot -i.
|
|
44
|
+
Missing target in a long list: use a short manual scroll + snapshot loop with a max attempt count; do not rely on unbounded scrollintoview.
|
|
45
|
+
Truncated text/input previews: do not use get text first; expand with snapshot -s @ref (for example snapshot -s @e7), then read the scoped output.
|
|
46
|
+
Rare iOS accessibility gaps: if a row ref is shown disabled/hittable:false and press @ref reports success but no UI change, or a horizontal tab/filter bar is collapsed into one composite/seekbar with no child refs, run agent-device snapshot -i -c --json to read rects, compute the target center, press x y, then diff snapshot -i. Coordinates are fallback-only; document why you used them.
|
|
47
|
+
|
|
48
|
+
Selectors:
|
|
49
|
+
Use selectors as positional targets: id="field-email" or label="Allow".
|
|
50
|
+
Do not use CSS selectors, pseudo refs, --selector, --text, or raw x/y when refs/selectors exist.
|
|
51
|
+
agent-device fill 'id="catalog-search"' "tart" --delay-ms 80
|
|
52
|
+
agent-device press 'id="submit-order"'
|
|
53
|
+
agent-device is visible 'label="Online"'
|
|
54
|
+
agent-device get text 'id="quantity-value"'
|
|
55
|
+
|
|
56
|
+
Text entry:
|
|
57
|
+
fill replaces; type appends to focused field.
|
|
58
|
+
agent-device fill @e5 "qa@example.com"
|
|
59
|
+
agent-device fill 'id="field-email"' "qa@example.com"
|
|
60
|
+
agent-device press 'id="product-note"'
|
|
61
|
+
agent-device type "Handle with care" --delay-ms 80
|
|
62
|
+
Empty replacement is not a supported clear-field command: do not plan fill <target> "" or fill <target> ''. Prefer a visible clear/reset control; if the app exposes none, report the tool gap instead of inventing a clear command.
|
|
63
|
+
Debounced field with no result selector: agent-device wait 1000. Keyboard read-only: keyboard status/get. Blocked control: try keyboard dismiss when supported.
|
|
64
|
+
On iOS, prefer keyboard dismiss before manually pressing visible Done; the runner can use safe native keyboard controls and still reports unsupported layouts explicitly. If it returns UNSUPPORTED_OPERATION, prefer a visible app dismiss control, or use back --system only when system navigation is an acceptable side effect.
|
|
65
|
+
Search-as-you-type fields on iOS can drop characters when driven too fast; use --delay-ms on fill/type before trying clipboard paste.
|
|
66
|
+
iOS Allow Paste prompt cannot be exercised under XCUITest. To test paste-driven app behavior, prefill first with agent-device clipboard write "some text"; test the system prompt manually.
|
|
67
|
+
Android Gboard handwriting/stylus UI can capture text in an IME-owned input instead of the app field. If fill reports that input was captured by the keyboard/IME, use the diagnostic targetInput/actualInput details, inspect keyboard status/get if needed, and switch or disable handwriting outside the command plan before retrying. Do not keep retrying fill/type against the same field while the IME owns focus.
|
|
68
|
+
Android text entry is owned by agent-device: provider-native text injection when available, then chunk-safe ASCII shell input. Do not switch to raw adb, clipboard, or paste as an agent fallback. If non-ASCII is unsupported in the current backend, report the tool/device gap.
|
|
69
|
+
|
|
70
|
+
Session ordering:
|
|
71
|
+
Stateful commands against one --session must run serially. Do not run open/press/fill/type/scroll/back/alert/replay/batch/close commands in parallel against the same session.
|
|
72
|
+
It is fine to parallelize independent read-only collection or commands that use different sessions/devices.
|
|
73
|
+
|
|
74
|
+
Read-only and waits:
|
|
75
|
+
Read-only visible/state question: use snapshot/get/is/find.
|
|
76
|
+
agent-device snapshot
|
|
77
|
+
agent-device get text 'id="product-title"'
|
|
78
|
+
agent-device get attrs @e4
|
|
79
|
+
agent-device is visible 'label="Online"'
|
|
80
|
+
agent-device wait text "Refreshing metrics..." 3000
|
|
81
|
+
agent-device wait 'label="Ready"' 3000
|
|
82
|
+
agent-device find "Increment" press --json
|
|
83
|
+
For async/list text presence, prefer wait text over is visible when no interaction is needed.
|
|
84
|
+
Use snapshot -i only when refs are needed for an action or targeted query.
|
|
85
|
+
Ambiguous find: add --first or --last. If info is not visible/exposed, report that gap instead of typing/searching/navigating to reveal it.
|
|
86
|
+
|
|
87
|
+
Navigation and gestures:
|
|
88
|
+
Use scroll for lists; swipe for coordinate gestures/carousels.
|
|
89
|
+
If app-owned back is ambiguous or has just misrouted, prefer a visible nav/back button ref, tab-bar ref, or deep link over repeated back/system back.
|
|
90
|
+
App-owned action sheets, menus, and camera/scan screens are normal UI. After opening one, run snapshot -i or wait for the option, press by label/ref, handle visible permission sheets through UI or platform-supported native alerts, then wait for a concrete result before returning to chat/form state.
|
|
91
|
+
Keep count/pause/pattern on one swipe; flags are --count, --pause-ms, --pattern ping-pong.
|
|
92
|
+
longpress duration and pinch scale/center are positional:
|
|
93
|
+
agent-device longpress 300 500 800
|
|
94
|
+
agent-device swipe 320 500 40 500 --count 8 --pause-ms 30 --pattern ping-pong
|
|
95
|
+
agent-device pinch 0.5 200 400
|
|
96
|
+
|
|
97
|
+
Validation and evidence:
|
|
98
|
+
Nearby mutation diff: agent-device diff snapshot -i.
|
|
99
|
+
Expected text/selector verification must include the exact text or selector via wait, is, get, or find; bare screenshots/snapshots are insufficient for named expectations.
|
|
100
|
+
Prefer provided testIDs/ids/selectors for verification; use visible text when no durable selector is provided.
|
|
101
|
+
If task says snapshot, use snapshot. If it asks visual evidence, use screenshot.
|
|
102
|
+
Icon/tappable visual proof: screenshot --overlay-refs. Flag is --overlay-refs.
|
|
103
|
+
Startup/frame health/CPU/memory: perf --json or metrics. Replay maintenance: replay -u ./flow.ad.
|
|
104
|
+
Recording: record start/stop. Tracing: trace start ./trace.log, trace stop ./trace.log. Paths are positional.
|
|
105
|
+
Stable known flow: batch ./steps.json, not workflow batch.
|
|
106
|
+
Inline batch JSON example:
|
|
107
|
+
agent-device batch --steps '[{"command":"open","positionals":["settings"],"flags":{}},{"command":"wait","positionals":["100"],"flags":{}}]'
|
|
108
|
+
Batch step keys are command, positionals, flags, and optional runtime. Never use args, step, text, or target as batch step fields.
|
|
109
|
+
Android animations: settings animations off/on, not animations disable/restore.
|
|
110
|
+
Debug logs: logs clear --restart, logs mark, reproduce, then logs path; do not split clear/restart into separate stop/start commands.
|
|
111
|
+
Network headers: network dump --include headers; do not write network log headers.
|
|
112
|
+
Remote/cloud: connect to discover a cloud profile, or connect --remote-config ./remote-config.json for a local profile; then open, snapshot, disconnect.
|
|
113
|
+
macOS menu bar: open ... --platform macos --surface menubar; snapshot -i --platform macos --surface menubar.
|
|
114
|
+
|
|
115
|
+
React Native dev loop:
|
|
116
|
+
JS-only change with Metro connected:
|
|
117
|
+
agent-device metro reload
|
|
118
|
+
agent-device find "Home"
|
|
119
|
+
Do not use agent-device reload. Use open --relaunch for native startup reset.
|
|
120
|
+
React Native apps: use help react-native for Metro/Fast Refresh, LogBox/RedBox overlays, DevTools routing, and RN-specific blockers.
|
|
121
|
+
Android RN/Expo Metro: run adb reverse tcp:<port> tcp:<port> before opening the app or URL; it is harmless even if already configured.
|
|
122
|
+
Expo Go is a host shell. Use a provided project URL instead of inventing a bundle id; if no URL is provided but a target/app name is provided, open that target and do not inspect project files to find one. On iOS, prefer host + URL when the host shell is known because direct URL open can report success while leaving the runner/shell focused; verify with snapshot -i after opening:
|
|
123
|
+
agent-device open "Expo Go" exp://127.0.0.1:8081 --platform ios
|
|
124
|
+
agent-device snapshot -i --platform ios
|
|
125
|
+
There is no open-url command; use open with the URL target or host + URL form.
|
|
126
|
+
Direct iOS URL open remains valid when no host shell is known, but verify that the app UI loaded:
|
|
127
|
+
agent-device open exp://127.0.0.1:8081 --platform ios
|
|
128
|
+
Android uses the URL target directly; do not write open <app> <url> there:
|
|
129
|
+
agent-device open exp://127.0.0.1:8081 --platform android
|
|
130
|
+
Android URL/deep-link opens infer the foreground package after launch when possible, so logs/perf can remain package-bound. If perf still says no package is associated, open the host package/app id first, then open the URL in the same session.
|
|
131
|
+
If apps lookup misses the project but shows Expo Go/dev-client and a project URL is available, open the URL/host shell; if no URL is available, ask instead of inventing an app id.
|
|
132
|
+
Expo Dev Client/development builds: open the installed dev-client app id/name; if a dev-client URL is provided, open that URL next. For Metro setup use metro prepare --kind expo.
|
|
133
|
+
|
|
134
|
+
Escalate:
|
|
135
|
+
help debugging logs, network, alerts, traces, flaky runtime failures
|
|
136
|
+
help react-devtools React Native performance, profiling, props/state/hooks, slow renders, rerenders
|
|
137
|
+
help react-native React Native app automation hazards, overlays, Metro, and routing
|
|
138
|
+
help remote remote/cloud config, tenant, lease, local service tunnels
|
|
139
|
+
help macos desktop, frontmost-app, menu bar surfaces
|
|
140
|
+
help dogfood exploratory QA report workflow`},debugging:{summary:"Targeted failure evidence without dumping stale context",body:`agent-device help debugging
|
|
141
|
+
|
|
142
|
+
Use this when behavior fails, hangs, times out, throws alerts, or needs runtime evidence.
|
|
143
|
+
|
|
144
|
+
Logs:
|
|
145
|
+
Keep log windows small. Prefer clear, mark, reproduce, then path.
|
|
146
|
+
agent-device logs clear --restart
|
|
147
|
+
agent-device logs mark "before diagnostics retry"
|
|
148
|
+
agent-device press 'id="load-diagnostics"'
|
|
149
|
+
agent-device logs path
|
|
150
|
+
Do not cat a full stale log into agent context. Open or grep only the relevant window when needed.
|
|
151
|
+
logs clear --restart is the compact command to clear old logs and start a fresh capture; do not split it into logs stop, logs clear, logs start.
|
|
152
|
+
|
|
153
|
+
Network:
|
|
154
|
+
Use network dump for recent session HTTP traffic parsed from app logs.
|
|
155
|
+
agent-device network dump --include headers
|
|
156
|
+
agent-device network dump 20 --include all
|
|
157
|
+
Use this instead of logs path when the question is request/response metadata.
|
|
158
|
+
network log is a supported alias, but network dump --include headers is the clearest plan form. Do not write network log headers.
|
|
159
|
+
|
|
160
|
+
Alerts:
|
|
161
|
+
Native alerts:
|
|
162
|
+
agent-device alert wait 3000
|
|
163
|
+
agent-device alert accept
|
|
164
|
+
agent-device alert dismiss
|
|
165
|
+
If alert accept says no alert but a permission sheet is visibly on screen, treat it as normal UI:
|
|
166
|
+
agent-device snapshot -i
|
|
167
|
+
agent-device press 'label="Allow"'
|
|
168
|
+
Android runtime permission prompts are visible UI. Do not use alert wait for them, and do not use settings permission to answer a dialog already on screen. Reserve settings permission for setup/resetting permission state before a flow.
|
|
169
|
+
|
|
170
|
+
Diagnostics and traces:
|
|
171
|
+
Use --debug for CLI/daemon diagnostic ids and log paths.
|
|
172
|
+
Use trace for low-level session diagnostics around one repro:
|
|
173
|
+
agent-device trace start ./traces/diagnostics.trace
|
|
174
|
+
agent-device press 'id="load-diagnostics"'
|
|
175
|
+
agent-device trace stop ./traces/diagnostics.trace
|
|
176
|
+
The trace path is positional. Do not use --path for trace start or trace stop.
|
|
177
|
+
|
|
178
|
+
Stabilizers:
|
|
179
|
+
Android animation-sensitive flows:
|
|
180
|
+
agent-device settings animations off
|
|
181
|
+
agent-device snapshot
|
|
182
|
+
agent-device settings animations on
|
|
183
|
+
Re-enable settings you changed before finishing.
|
|
184
|
+
|
|
185
|
+
React Native internals:
|
|
186
|
+
If the question is about React Native performance, profiling, props, state, hooks, render causes, slow components, or rerenders, use help react-devtools instead of inferring from screenshots or logs.`},"react-devtools":{summary:"React Native performance, profiling, and component internals",body:`agent-device help react-devtools
|
|
187
|
+
|
|
188
|
+
Use this for React Native performance/profiling and internals that the accessibility tree cannot expose: components, props, state, hooks, ownership, slow renders, and rerenders.
|
|
189
|
+
|
|
190
|
+
Core commands:
|
|
191
|
+
agent-device react-devtools start
|
|
192
|
+
agent-device react-devtools stop
|
|
193
|
+
agent-device react-devtools status
|
|
194
|
+
agent-device react-devtools wait --connected
|
|
195
|
+
agent-device react-devtools wait --component <ComponentName>
|
|
196
|
+
agent-device react-devtools count
|
|
197
|
+
agent-device react-devtools get tree --depth 3
|
|
198
|
+
agent-device react-devtools find <ComponentName>
|
|
199
|
+
agent-device react-devtools find <ComponentName> --exact
|
|
200
|
+
agent-device react-devtools get component @c5
|
|
201
|
+
agent-device react-devtools errors
|
|
202
|
+
agent-device react-devtools profile start
|
|
203
|
+
agent-device react-devtools profile stop
|
|
204
|
+
agent-device react-devtools profile slow --limit 5
|
|
205
|
+
agent-device react-devtools profile rerenders --limit 5
|
|
206
|
+
agent-device react-devtools profile report @c5
|
|
207
|
+
agent-device react-devtools profile timeline --limit 20
|
|
208
|
+
agent-device react-devtools profile export profile.json
|
|
209
|
+
agent-device react-devtools profile diff before.json after.json --limit 10
|
|
210
|
+
|
|
211
|
+
Profiling loop:
|
|
212
|
+
1. Verify the app is connected: react-devtools status, then wait --connected if needed.
|
|
213
|
+
2. If correlating with logs or network, run logs clear --restart before the first logs mark.
|
|
214
|
+
3. Start profiling immediately before the interaction.
|
|
215
|
+
4. Drive the interaction with normal agent-device commands and mark before/after the repro when timing matters.
|
|
216
|
+
5. Stop profiling.
|
|
217
|
+
6. Make one bounded first-pass survey: profile stop for the summary, profile slow --limit 5 once, profile rerenders --limit 5 once, and profile timeline --limit 20 only when commit timing matters.
|
|
218
|
+
7. Use profile report @cN for targeted render causes and changed props/state/hooks; use get component @cN for current props/state/hooks.
|
|
219
|
+
|
|
220
|
+
Rules:
|
|
221
|
+
Every React DevTools command is an agent-device subcommand: agent-device react-devtools ...
|
|
222
|
+
Do not write agent-devtools, agent-react-devtools, or bare react-devtools commands in final command plans.
|
|
223
|
+
Start with get tree --depth 3 or find <name>; use find --exact when fuzzy results are noisy.
|
|
224
|
+
@c refs reset after reload/remount. After reload, wait --connected and inspect again.
|
|
225
|
+
Keep the profile window narrow; unrelated navigation makes render data noisy.
|
|
226
|
+
Do not repeatedly raise broad profile slow limits such as --limit 50, --limit 200, or --limit 500. Drill into a specific @c ref with profile report unless you have a specific target that needs more rows.
|
|
227
|
+
For network evidence, use agent-device network dump --include headers; headers is not a positional argument.
|
|
228
|
+
For cross-platform validation with explicit device selectors, prefer isolated --state-dir and restart react-devtools between platforms.
|
|
229
|
+
Remote Android and iOS bridge runs normally through agent-device react-devtools; the CLI keeps the needed local service tunnel alive until agent-device react-devtools stop or disconnect. Expo support depends on the SDK's bundled React Native runtime.
|
|
230
|
+
Remote iOS apps attempt the legacy React DevTools websocket during JavaScript startup. If the app was already open before react-devtools start, run open <bundle-id> --platform ios --relaunch, then wait --connected.
|
|
231
|
+
|
|
232
|
+
Example:
|
|
233
|
+
agent-device react-devtools status
|
|
234
|
+
agent-device react-devtools wait --connected
|
|
235
|
+
agent-device logs clear --restart
|
|
236
|
+
agent-device logs mark "before catalog search"
|
|
237
|
+
agent-device react-devtools profile start
|
|
238
|
+
agent-device fill 'id="catalog-search"' "tart" --delay-ms 80
|
|
239
|
+
agent-device logs mark "after catalog search"
|
|
240
|
+
agent-device react-devtools profile stop
|
|
241
|
+
agent-device react-devtools profile slow --limit 5
|
|
242
|
+
agent-device react-devtools profile rerenders --limit 5
|
|
243
|
+
agent-device react-devtools profile timeline --limit 20
|
|
244
|
+
agent-device react-devtools profile report @c5
|
|
245
|
+
agent-device network dump --include headers
|
|
246
|
+
|
|
247
|
+
Use snapshot, screenshot, logs, network, and perf for device/app runtime evidence. Use react-devtools only when component internals or React rendering behavior matters.`},"react-native":{summary:"React Native app automation hazards and routing",body:`agent-device help react-native
|
|
248
|
+
|
|
249
|
+
Use this when the target app is React Native, Expo, or a React Native dev client.
|
|
250
|
+
This topic covers React Native-specific automation hazards and routes deeper
|
|
251
|
+
questions to the owning help topic.
|
|
252
|
+
|
|
253
|
+
Choose the next help topic:
|
|
254
|
+
Generic navigation, selectors, refs, verification, serial commands: help workflow.
|
|
255
|
+
Logs, network, diagnostics, traces, permission dialogs, or runtime failures: help debugging.
|
|
256
|
+
Component tree, props/state/hooks, slow renders, rerenders, or render causes: help react-devtools.
|
|
257
|
+
Remote/cloud config, leases, and local service tunnels: help remote.
|
|
258
|
+
|
|
259
|
+
React Native dev loop:
|
|
260
|
+
For "start from screen X" flows, prefer open --relaunch before the first snapshot so the app does not reuse a prior in-progress navigation state.
|
|
261
|
+
JS-only change with Metro connected:
|
|
262
|
+
agent-device metro reload
|
|
263
|
+
agent-device find "Home"
|
|
264
|
+
Do not use agent-device reload. Use open --relaunch for native startup reset.
|
|
265
|
+
Android RN/Expo Metro: run adb reverse tcp:<port> tcp:<port> before opening the app or URL; it is harmless even if already configured.
|
|
266
|
+
Expo Go/dev clients are host shells. Use provided project URLs, verify with snapshot -i after opening, and ask instead of inventing app ids or URLs. Help workflow owns the full Expo URL command shapes.
|
|
267
|
+
|
|
268
|
+
Overlays and busy RN UIs:
|
|
269
|
+
React Native warning/error overlays belong to the app run. Treat them as blockers before normal app work: press visible Dismiss/Close immediately when unrelated, or press the collapsed warning banner first if only a warning chip is visible; then re-snapshot and report the overlay in the final summary. Use screenshot --overlay-refs only if visual evidence is required.
|
|
270
|
+
Full-screen RedBox stack traces are app errors, not failed navigation. If Minimize is visible, prefer Minimize over Dismiss; Dismiss can re-trigger infinite-loop render errors such as getSnapshot/useOnyx stack paths.
|
|
271
|
+
If snapshot times out because the UI never becomes idle, Android accessibility may be blocked by busy or continuously changing app UI. After that timeout, use screenshot as visual truth instead of repeatedly retrying snapshots.
|
|
272
|
+
Android runtime permission dialogs are visible UI: inspect snapshot -i and press Allow/Deny by visible label/ref. Use alert wait/accept/dismiss only where the platform supports native alerts.
|
|
273
|
+
|
|
274
|
+
React DevTools routing:
|
|
275
|
+
Keep the agent-device react-devtools prefix on every React DevTools command.
|
|
276
|
+
Use help react-devtools for status/wait, component trees, props/state/hooks, profile windows, slow renders, rerenders, and remote bridge rules.
|
|
277
|
+
If React DevTools cannot connect, report status and continue with logs, network, perf, screenshot, and trace evidence instead of blocking the whole flow.
|
|
278
|
+
|
|
279
|
+
Slow-flow investigation:
|
|
280
|
+
Keep one named session, start with session list, open, and snapshot -i.
|
|
281
|
+
Use help react-devtools for the narrow React profile window.
|
|
282
|
+
Use help debugging for logs clear --restart, logs mark, network dump --include headers, perf --json, traces, and runtime failure evidence.
|
|
283
|
+
For 15-20s async work, use wait with the exact expected text or selector instead of repeated snapshots.
|
|
284
|
+
Report React render offenders separately from network/backend waits and device frame/CPU/memory findings.`},remote:{summary:"Remote config, tenant, lease, and remote host flow",body:`agent-device help remote
|
|
285
|
+
|
|
286
|
+
Use remote config or the cloud connection profile when a profile owns daemon URL, auth, tenant, run, lease, device scope, and Metro hints. Do not restate those as individual flags unless overriding intentionally.
|
|
287
|
+
|
|
288
|
+
Cloud profile flow:
|
|
289
|
+
agent-device connect
|
|
290
|
+
agent-device open com.example.app
|
|
291
|
+
agent-device snapshot
|
|
292
|
+
agent-device disconnect
|
|
293
|
+
|
|
294
|
+
Local profile flow:
|
|
295
|
+
agent-device connect --remote-config ./remote-config.json
|
|
296
|
+
agent-device open com.example.app
|
|
297
|
+
agent-device snapshot
|
|
298
|
+
agent-device disconnect
|
|
299
|
+
|
|
300
|
+
Script flow, per-command config:
|
|
301
|
+
agent-device open com.example.app --remote-config ./remote-config.json
|
|
302
|
+
agent-device snapshot --remote-config ./remote-config.json
|
|
303
|
+
agent-device disconnect --remote-config ./remote-config.json
|
|
304
|
+
|
|
305
|
+
Rules:
|
|
306
|
+
connect and disconnect are top-level commands. Do not write agent-device remote connect or agent-device remote disconnect.
|
|
307
|
+
Use connect without --remote-config when the cloud control plane owns the connection profile.
|
|
308
|
+
Prefer --remote-config over --daemon-base-url, --tenant, --run-id, and --lease-id when using a local profile.
|
|
309
|
+
For self-contained scripts, pass the same --remote-config to every operational command, including disconnect; a preceding connect is optional but not required.
|
|
310
|
+
For remote artifact installs, use install-from-source <url> or install-from-source --github-actions-artifact org/repo:artifact; do not download CI artifacts locally first.
|
|
311
|
+
After connect, let the active remote connection supply runtime hints.
|
|
312
|
+
For remote Android and iOS bridge React DevTools, run agent-device react-devtools normally. The CLI opens the needed local service tunnel for the DevTools daemon and keeps it alive until agent-device react-devtools stop or disconnect.
|
|
313
|
+
Use --debug when remote connection or transport errors need diagnostic ids and remote log hints.`},macos:{summary:"macOS desktop, frontmost-app, and menu bar surfaces",body:`agent-device help macos
|
|
314
|
+
|
|
315
|
+
Use macOS only when the task targets desktop apps, desktop surfaces, or menu bar extras.
|
|
316
|
+
|
|
317
|
+
Open and inspect:
|
|
318
|
+
agent-device open TextEdit --platform macos
|
|
319
|
+
agent-device snapshot -i --platform macos
|
|
320
|
+
|
|
321
|
+
Surfaces:
|
|
322
|
+
--surface app normal app session
|
|
323
|
+
--surface frontmost-app inspect whichever app is frontmost
|
|
324
|
+
--surface desktop desktop-wide surface
|
|
325
|
+
--surface menubar menu bar extras and menu bar-only apps
|
|
326
|
+
|
|
327
|
+
Menu bar app example:
|
|
328
|
+
agent-device open "Agent Device Tester Menu" --platform macos --surface menubar
|
|
329
|
+
agent-device snapshot -i --platform macos --surface menubar
|
|
330
|
+
|
|
331
|
+
Context menu example:
|
|
332
|
+
agent-device click @e66 --button secondary --platform macos
|
|
333
|
+
agent-device snapshot -i --platform macos
|
|
334
|
+
|
|
335
|
+
Rules:
|
|
336
|
+
Use open and snapshot -i for menu bar inspection. Do not output inspect as a command.
|
|
337
|
+
Context menus are not ambient UI: secondary-click a visible target, then re-snapshot and use the new menu-item refs.
|
|
338
|
+
Do not let iOS simulator-set scoping hide macOS desktop targets.
|
|
339
|
+
Prefer refs/selectors over raw coordinates.
|
|
340
|
+
macOS snapshot rects are window-space; use current refs or overlay refs instead of guessing coordinates.`},dogfood:{summary:"Exploratory QA workflow with reproducible evidence",body:`agent-device help dogfood
|
|
341
|
+
|
|
342
|
+
Use this when asked to dogfood, exploratory test, bug hunt, QA, or find issues in an app.
|
|
343
|
+
|
|
344
|
+
Goal:
|
|
345
|
+
Find user-visible issues from runtime behavior. Do not read app source or invent findings from code.
|
|
346
|
+
Produce a concise report with severity, repro commands, expected/actual behavior, and evidence paths.
|
|
347
|
+
|
|
348
|
+
Loop:
|
|
349
|
+
1. Identify target app/platform; ask only if missing.
|
|
350
|
+
2. Create output dirs and open a named session. If auth or OTP is required, sign in or ask the user for the code.
|
|
351
|
+
3. Capture baseline snapshot -i and screenshot.
|
|
352
|
+
4. Map top-level navigation, then exercise primary flows and edge states.
|
|
353
|
+
5. For each issue, capture evidence and write the finding immediately, then continue.
|
|
354
|
+
6. Close the session and reconcile the report summary.
|
|
355
|
+
Keep stateful commands serial within the same session. Parallel runs can pollute text fields, focus, alerts, and navigation state.
|
|
356
|
+
|
|
357
|
+
Coverage:
|
|
358
|
+
Navigation, forms, empty/error/loading states, offline or retry behavior, permissions, settings, accessibility labels, orientation/keyboard, and obvious performance stalls.
|
|
359
|
+
React Native warning/error overlays can be real findings or test blockers. Capture them, dismiss if unrelated, re-snapshot, and report them.
|
|
360
|
+
Expo Go/dev-client shells: use the provided exp:// or dev-client URL and record whether the shell, project load, or app UI is being tested. On iOS dogfood, prefer agent-device open "Expo Go" <url> when Expo Go is the known shell, then snapshot -i to confirm the project UI rather than the runner splash.
|
|
361
|
+
Android RN/Expo Metro: run adb reverse tcp:<port> tcp:<port> before opening the app or URL; it is harmless even if already configured.
|
|
362
|
+
Categories: visual, functional, UX, content, performance, diagnostics, permissions, accessibility.
|
|
363
|
+
Severity: critical blocks a core flow/data/crashes; high breaks a major feature; medium has friction or workaround; low is polish.
|
|
364
|
+
|
|
365
|
+
Evidence commands:
|
|
366
|
+
mkdir -p ./dogfood-output/screenshots ./dogfood-output/videos ./dogfood-output/traces
|
|
367
|
+
agent-device --session qa open <app> --platform ios
|
|
368
|
+
agent-device --session qa snapshot -i
|
|
369
|
+
agent-device --session qa screenshot ./dogfood-output/screenshots/initial.png
|
|
370
|
+
agent-device --session qa screenshot ./dogfood-output/screenshots/issue-001.png --overlay-refs
|
|
371
|
+
agent-device --session qa logs clear --restart
|
|
372
|
+
agent-device --session qa logs mark "issue-001 repro"
|
|
373
|
+
agent-device --session qa logs path
|
|
374
|
+
agent-device --session qa record start ./dogfood-output/videos/issue-001.mp4
|
|
375
|
+
agent-device --session qa record stop
|
|
376
|
+
agent-device --session qa close
|
|
377
|
+
|
|
378
|
+
Evidence rules:
|
|
379
|
+
Interactive/behavioral issues need step screenshots and usually a repro video.
|
|
380
|
+
Static/on-load issues can use one screenshot; set repro video to N/A.
|
|
381
|
+
Use screenshot --overlay-refs when showing the tappable target or broken state helps repro.
|
|
382
|
+
|
|
383
|
+
Report shape:
|
|
384
|
+
./dogfood-output/report.md
|
|
385
|
+
Include date, platform, target app, session, scope, severity counts, and issues.
|
|
386
|
+
For each finding: ID, severity, category, title, affected flow/screen, repro commands, expected, actual, evidence files, notes.
|
|
387
|
+
Target 5-10 well-evidenced issues when available. If no issues are found, report coverage completed and residual risk instead of claiming the app is bug-free.
|
|
388
|
+
|
|
389
|
+
Rules:
|
|
390
|
+
Findings must come from observed runtime behavior, not source reads.
|
|
391
|
+
Re-snapshot after each mutation.
|
|
392
|
+
Keep commands in the report reproducible; use selectors or refs from fresh snapshots, not guessed coordinates.
|
|
393
|
+
Prefer refs for exploration and selectors for deterministic replay.
|
|
394
|
+
Use logs, network, screenshot --overlay-refs, trace, perf, or react-devtools only when they add evidence to a specific issue.
|
|
395
|
+
Never delete screenshots, videos, traces, or report artifacts during a session.
|
|
396
|
+
Escalate to help debugging or help react-devtools when runtime symptoms require those tools.`}},n2=[{key:"config",names:["--config"],type:"string",usageLabel:"--config <path>",usageDescription:"Load CLI defaults from a specific config file"},{key:"remoteConfig",names:["--remote-config"],type:"string",usageLabel:"--remote-config <path>",usageDescription:"Load remote host + Metro workflow settings from a specific profile file"},{key:"stateDir",names:["--state-dir"],type:"string",usageLabel:"--state-dir <path>",usageDescription:"Daemon state directory (defaults to ~/.agent-device)"},{key:"daemonBaseUrl",names:["--daemon-base-url"],type:"string",usageLabel:"--daemon-base-url <url>",usageDescription:"Explicit remote HTTP daemon base URL (skip local daemon discovery/startup)"},{key:"daemonAuthToken",names:["--daemon-auth-token"],type:"string",usageLabel:"--daemon-auth-token <token>",usageDescription:"Remote HTTP daemon auth token (sent as request token and bearer header)"},{key:"daemonTransport",names:["--daemon-transport"],type:"enum",enumValues:["auto","socket","http"],usageLabel:"--daemon-transport auto|socket|http",usageDescription:"Daemon client transport preference"},{key:"daemonServerMode",names:["--daemon-server-mode"],type:"enum",enumValues:["socket","http","dual"],usageLabel:"--daemon-server-mode socket|http|dual",usageDescription:"Daemon server mode used when spawning daemon"},{key:"tenant",names:["--tenant"],type:"string",usageLabel:"--tenant <id>",usageDescription:"Tenant scope identifier for isolated daemon sessions"},{key:"sessionIsolation",names:["--session-isolation"],type:"enum",enumValues:["none","tenant"],usageLabel:"--session-isolation none|tenant",usageDescription:"Session isolation strategy (tenant prefixes session namespace)"},{key:"runId",names:["--run-id"],type:"string",usageLabel:"--run-id <id>",usageDescription:"Run identifier used for tenant lease admission checks"},{key:"leaseId",names:["--lease-id"],type:"string",usageLabel:"--lease-id <id>",usageDescription:"Lease identifier bound to tenant/run admission scope"},{key:"leaseBackend",names:["--lease-backend"],type:"enum",enumValues:["ios-simulator","ios-instance","android-instance"],usageLabel:"--lease-backend ios-simulator|ios-instance|android-instance",usageDescription:"Lease backend for remote tenant connection admission"},{key:"force",names:["--force"],type:"boolean",usageLabel:"--force",usageDescription:"Force connection state replacement when reconnecting"},{key:"noLogin",names:["--no-login"],type:"boolean",usageLabel:"--no-login",usageDescription:"Connect: fail instead of starting implicit cloud login"},{key:"sessionLock",names:["--session-lock"],type:"enum",enumValues:["reject","strip"],usageLabel:"--session-lock reject|strip",usageDescription:"Lock bound-session device routing for this CLI invocation and nested batch steps"},{key:"sessionLocked",names:["--session-locked"],type:"boolean",usageLabel:"--session-locked",usageDescription:"Deprecated alias for --session-lock reject"},{key:"sessionLockConflicts",names:["--session-lock-conflicts"],type:"enum",enumValues:["reject","strip"],usageLabel:"--session-lock-conflicts reject|strip",usageDescription:"Deprecated alias for --session-lock"},{key:"platform",names:["--platform"],type:"enum",enumValues:["ios","macos","android","linux","apple"],usageLabel:"--platform ios|macos|android|linux|apple",usageDescription:"Platform to target (`apple` aliases the Apple automation backend)"},{key:"target",names:["--target"],type:"enum",enumValues:["mobile","tv","desktop"],usageLabel:"--target mobile|tv|desktop",usageDescription:"Device target class to match"},{key:"device",names:["--device"],type:"string",usageLabel:"--device <name>",usageDescription:"Device name to target"},{key:"udid",names:["--udid"],type:"string",usageLabel:"--udid <udid>",usageDescription:"iOS device UDID"},{key:"serial",names:["--serial"],type:"string",usageLabel:"--serial <serial>",usageDescription:"Android device serial"},{key:"surface",names:["--surface"],type:"enum",enumValues:nZ,usageLabel:"--surface app|frontmost-app|desktop|menubar",usageDescription:"macOS session surface for open (defaults to app)"},{key:"headless",names:["--headless"],type:"boolean",usageLabel:"--headless",usageDescription:"Boot: launch Android emulator without a GUI window"},{key:"metroHost",names:["--metro-host"],type:"string",usageLabel:"--metro-host <host>",usageDescription:"Session-scoped Metro/debug host hint"},{key:"metroPort",names:["--metro-port"],type:"int",min:1,max:65535,usageLabel:"--metro-port <port>",usageDescription:"Session-scoped Metro/debug port hint"},{key:"metroProjectRoot",names:["--project-root"],type:"string",usageLabel:"--project-root <path>",usageDescription:"metro prepare: React Native project root (default: cwd)"},{key:"metroKind",names:["--kind"],type:"enum",enumValues:["auto","react-native","expo"],usageLabel:"--kind auto|react-native|expo",usageDescription:"metro prepare: detect or force the Metro launcher kind"},{key:"metroPublicBaseUrl",names:["--public-base-url"],type:"string",usageLabel:"--public-base-url <url>",usageDescription:"metro prepare: public base URL used for direct bundle hints"},{key:"metroProxyBaseUrl",names:["--proxy-base-url"],type:"string",usageLabel:"--proxy-base-url <url>",usageDescription:"metro prepare: optional bridge origin for remote Metro access"},{key:"metroBearerToken",names:["--bearer-token"],type:"string",usageLabel:"--bearer-token <token>",usageDescription:"metro prepare: host bridge bearer token (prefer AGENT_DEVICE_PROXY_TOKEN or AGENT_DEVICE_METRO_BEARER_TOKEN)"},{key:"metroPreparePort",names:["--port"],type:"int",min:1,max:65535,usageLabel:"--port <port>",usageDescription:"metro prepare: local Metro port (default: 8081)"},{key:"metroListenHost",names:["--listen-host"],type:"string",usageLabel:"--listen-host <host>",usageDescription:"metro prepare: host Metro listens on (default: 0.0.0.0)"},{key:"metroStatusHost",names:["--status-host"],type:"string",usageLabel:"--status-host <host>",usageDescription:"metro prepare: host used for local /status polling (default: 127.0.0.1)"},{key:"metroStartupTimeoutMs",names:["--startup-timeout-ms"],type:"int",min:1,usageLabel:"--startup-timeout-ms <ms>",usageDescription:"metro prepare: timeout while waiting for Metro to become ready"},{key:"metroProbeTimeoutMs",names:["--probe-timeout-ms"],type:"int",min:1,usageLabel:"--probe-timeout-ms <ms>",usageDescription:"metro prepare: timeout for /status and proxy bridge calls"},{key:"metroRuntimeFile",names:["--runtime-file"],type:"string",usageLabel:"--runtime-file <path>",usageDescription:"metro prepare: optional file path to persist the JSON result"},{key:"metroNoReuseExisting",names:["--no-reuse-existing"],type:"boolean",usageLabel:"--no-reuse-existing",usageDescription:"metro prepare: always start a fresh Metro process"},{key:"metroNoInstallDeps",names:["--no-install-deps"],type:"boolean",usageLabel:"--no-install-deps",usageDescription:"metro prepare: skip package-manager install when node_modules is missing"},{key:"bundleUrl",names:["--bundle-url"],type:"string",usageLabel:"--bundle-url <url>",usageDescription:"Session-scoped bundle URL hint"},{key:"launchUrl",names:["--launch-url"],type:"string",usageLabel:"--launch-url <url>",usageDescription:"Session-scoped deep link / launch URL hint"},{key:"iosSimulatorDeviceSet",names:["--ios-simulator-device-set"],type:"string",usageLabel:"--ios-simulator-device-set <path>",usageDescription:"Scope iOS simulator discovery/commands to this simulator device set"},{key:"androidDeviceAllowlist",names:["--android-device-allowlist"],type:"string",usageLabel:"--android-device-allowlist <serials>",usageDescription:"Comma/space separated Android serial allowlist for discovery/selection"},{key:"activity",names:["--activity"],type:"string",usageLabel:"--activity <component>",usageDescription:"Android app launch activity (package/Activity); not for URL opens"},{key:"header",names:["--header"],type:"string",multiple:!0,usageLabel:"--header <name:value>",usageDescription:"install-from-source: repeatable HTTP header for URL downloads"},{key:"githubActionsArtifact",names:["--github-actions-artifact"],type:"string",usageLabel:"--github-actions-artifact <owner/repo:artifact>",usageDescription:"install-from-source: GitHub Actions artifact resolved by a remote daemon"},{key:"installSource",names:[],type:"string"},{key:"session",names:["--session"],type:"string",usageLabel:"--session <name>",usageDescription:"Named session"},{key:"count",names:["--count"],type:"int",min:1,max:200,usageLabel:"--count <n>",usageDescription:"Repeat count for press/swipe series"},{key:"fps",names:["--fps"],type:"int",min:1,max:120,usageLabel:"--fps <n>",usageDescription:"Record: target frames per second (iOS physical device runner)"},{key:"quality",names:["--quality"],type:"int",min:5,max:10,usageLabel:"--quality <5-10>",usageDescription:"Record: scale recording resolution from 5 (50%) through 10 (native resolution)"},{key:"hideTouches",names:["--hide-touches"],type:"boolean",usageLabel:"--hide-touches",usageDescription:"Record: disable touch overlays in the final video"},{key:"intervalMs",names:["--interval-ms"],type:"int",min:0,max:1e4,usageLabel:"--interval-ms <ms>",usageDescription:"Delay between press iterations"},{key:"delayMs",names:["--delay-ms"],type:"int",min:0,max:1e4,usageLabel:"--delay-ms <ms>",usageDescription:"Delay between typed characters"},{key:"holdMs",names:["--hold-ms"],type:"int",min:0,max:1e4,usageLabel:"--hold-ms <ms>",usageDescription:"Press hold duration for each iteration"},{key:"jitterPx",names:["--jitter-px"],type:"int",min:0,max:100,usageLabel:"--jitter-px <n>",usageDescription:"Deterministic coordinate jitter radius for press"},{key:"pixels",names:["--pixels"],type:"int",min:1,max:1e5,usageLabel:"--pixels <n>",usageDescription:"Scroll: explicit gesture distance in pixels"},{key:"doubleTap",names:["--double-tap"],type:"boolean",usageLabel:"--double-tap",usageDescription:"Use double-tap gesture per press iteration"},{key:"clickButton",names:["--button"],type:"enum",enumValues:["primary","secondary","middle"],usageLabel:"--button primary|secondary|middle",usageDescription:"Click: choose mouse button (middle reserved for future macOS support)"},{key:"backMode",names:["--in-app"],type:"enum",enumValues:["in-app","system"],setValue:"in-app",usageLabel:"--in-app",usageDescription:"Back: use app-provided back UI when available"},{key:"backMode",names:["--system"],type:"enum",enumValues:["in-app","system"],setValue:"system",usageLabel:"--system",usageDescription:"Back: use system back input or gesture when available"},{key:"pauseMs",names:["--pause-ms"],type:"int",min:0,max:1e4,usageLabel:"--pause-ms <ms>",usageDescription:"Delay between swipe iterations"},{key:"pattern",names:["--pattern"],type:"enum",enumValues:["one-way","ping-pong"],usageLabel:"--pattern one-way|ping-pong",usageDescription:"Swipe repeat pattern"},{key:"verbose",names:["--debug","--verbose","-v"],type:"boolean",usageLabel:"--debug, --verbose, -v",usageDescription:"Enable debug diagnostics and stream daemon/runner logs"},{key:"json",names:["--json"],type:"boolean",usageLabel:"--json",usageDescription:"JSON output"},{key:"help",names:["--help","-h"],type:"boolean",usageLabel:"--help, -h",usageDescription:"Print help and exit"},{key:"version",names:["--version","-V"],type:"boolean",usageLabel:"--version, -V",usageDescription:"Print version and exit"},{key:"snapshotDiff",names:["--diff"],type:"boolean",usageLabel:"--diff",usageDescription:"Snapshot: show structural diff against the previous session baseline"},{key:"saveScript",names:["--save-script"],type:"booleanOrString",usageLabel:"--save-script [path]",usageDescription:"Save session script (.ad) on close; optional custom output path"},{key:"networkInclude",names:["--include"],type:"enum",enumValues:["summary","headers","body","all"],usageLabel:"--include summary|headers|body|all",usageDescription:"Network: include headers, bodies, or both in output"},{key:"shutdown",names:["--shutdown"],type:"boolean",usageLabel:"--shutdown",usageDescription:"close: shutdown associated simulator/emulator after ending session"},{key:"relaunch",names:["--relaunch"],type:"boolean",usageLabel:"--relaunch",usageDescription:"open: terminate app process before launching it"},{key:"restart",names:["--restart"],type:"boolean",usageLabel:"--restart",usageDescription:"logs clear: stop active stream, clear logs, then start streaming again"},{key:"retainPaths",names:["--retain-paths"],type:"boolean",usageLabel:"--retain-paths",usageDescription:"install-from-source: keep materialized artifact paths after install"},{key:"retentionMs",names:["--retention-ms"],type:"int",min:1,usageLabel:"--retention-ms <ms>",usageDescription:"install-from-source: retention TTL for materialized artifact paths"},{key:"noRecord",names:["--no-record"],type:"boolean",usageLabel:"--no-record",usageDescription:"Do not record this action"},{key:"replayUpdate",names:["--update","-u"],type:"boolean",usageLabel:"--update, -u",usageDescription:"Replay: update selectors and rewrite replay file in place"},{key:"replayMaestro",names:["--maestro"],type:"boolean",usageLabel:"--maestro",usageDescription:"Replay: treat input as a prototype Maestro YAML flow and execute the supported subset through replay"},{key:"replayEnv",names:["-e","--env"],type:"string",multiple:!0,usageLabel:"-e KEY=VALUE, --env KEY=VALUE",usageDescription:"Replay/Test: inject or override a ${KEY} variable for the script (repeatable)"},{key:"failFast",names:["--fail-fast"],type:"boolean",usageLabel:"--fail-fast",usageDescription:"Test: stop the suite after the first failing script"},{key:"timeoutMs",names:["--timeout"],type:"int",min:1,usageLabel:"--timeout <ms>",usageDescription:"Test: maximum wall-clock time per script attempt"},{key:"retries",names:["--retries"],type:"int",min:0,max:3,usageLabel:"--retries <n>",usageDescription:"Test: retry each failed script up to n additional times"},{key:"artifactsDir",names:["--artifacts-dir"],type:"string",usageLabel:"--artifacts-dir <path>",usageDescription:"Test: root directory for suite artifacts"},{key:"reportJunit",names:["--report-junit"],type:"string",usageLabel:"--report-junit <path>",usageDescription:"Test: write a JUnit XML report for the replay suite"},{key:"steps",names:["--steps"],type:"string",usageLabel:"--steps <json>",usageDescription:"Batch: JSON array of steps"},{key:"stepsFile",names:["--steps-file"],type:"string",usageLabel:"--steps-file <path>",usageDescription:"Batch: read steps JSON from file"},{key:"batchOnError",names:["--on-error"],type:"enum",enumValues:["stop"],usageLabel:"--on-error stop",usageDescription:"Batch: stop when a step fails"},{key:"batchMaxSteps",names:["--max-steps"],type:"int",min:1,max:1e3,usageLabel:"--max-steps <n>",usageDescription:"Batch: maximum number of allowed steps"},{key:"appsFilter",names:["--all"],type:"enum",enumValues:["user-installed","all"],setValue:"all",usageLabel:"--all",usageDescription:"Apps: include system/OEM apps"},{key:"snapshotInteractiveOnly",names:["-i"],type:"boolean",usageLabel:"-i",usageDescription:"Snapshot: interactive elements only"},{key:"snapshotCompact",names:["-c"],type:"boolean",usageLabel:"-c",usageDescription:"Snapshot: compact output (drop empty structure)"},{key:"snapshotDepth",names:["--depth","-d"],type:"int",min:0,usageLabel:"--depth, -d <depth>",usageDescription:"Snapshot: limit snapshot depth"},{key:"snapshotScope",names:["--scope","-s"],type:"string",usageLabel:"--scope, -s <scope>",usageDescription:"Snapshot: scope snapshot to label/identifier"},{key:"snapshotRaw",names:["--raw"],type:"boolean",usageLabel:"--raw",usageDescription:"Snapshot: raw node output"},{key:"snapshotForceFull",names:["--force-full"],type:"boolean",usageLabel:"--force-full",usageDescription:"Snapshot: re-emit the full tree even when unchanged"},{key:"findFirst",names:["--first"],type:"boolean",usageLabel:"--first",usageDescription:"Find: pick the first match when ambiguous"},{key:"findLast",names:["--last"],type:"boolean",usageLabel:"--last",usageDescription:"Find: pick the last match when ambiguous"},{key:"out",names:["--out"],type:"string",usageLabel:"--out <path>",usageDescription:"Output path"},{key:"overlayRefs",names:["--overlay-refs"],type:"boolean",usageLabel:"--overlay-refs",usageDescription:"Screenshot: draw current snapshot refs and target rectangles onto the saved PNG; diff screenshot: also write a separate current-screen overlay guide"},...w,{key:"baseline",names:["--baseline","-b"],type:"string",usageLabel:"--baseline, -b <path>",usageDescription:"Diff screenshot: path to baseline image file"},{key:"threshold",names:["--threshold"],type:"string",usageLabel:"--threshold <0-1>",usageDescription:"Diff screenshot: color distance threshold (default 0.1)"}],n5=new Set(["json","config","remoteConfig","stateDir","daemonBaseUrl","daemonAuthToken","daemonTransport","daemonServerMode","tenant","sessionIsolation","runId","leaseId","leaseBackend","sessionLock","sessionLocked","sessionLockConflicts","help","version","verbose","platform","target","device","udid","serial","iosSimulatorDeviceSet","androidDeviceAllowlist","session","noRecord"]),n3={boot:{helpDescription:"Ensure target device/simulator is booted and ready",summary:"Boot target device/simulator",positionalArgs:[],allowedFlags:["headless"]},...e_,connect:{usageOverride:"connect [--remote-config <path>] [--tenant <id>] [--run-id <id>] [--lease-backend <backend>] [--force] [--no-login]",helpDescription:"Connect to a remote daemon, authenticate when needed, and save remote session state. AGENT_DEVICE_CLOUD_BASE_URL is the bridge/control-plane API origin; use AGENT_DEVICE_DAEMON_AUTH_TOKEN=adc_live_... for CI/service-token automation.",summary:"Connect to remote daemon",positionalArgs:[],allowedFlags:["force","noLogin","metroProjectRoot","metroKind","metroPublicBaseUrl","metroProxyBaseUrl","metroBearerToken","metroPreparePort","metroListenHost","metroStatusHost","metroStartupTimeoutMs","metroProbeTimeoutMs","metroRuntimeFile","metroNoReuseExisting","metroNoInstallDeps","launchUrl"],skipCapabilityCheck:!0},mcp:{helpDescription:"Start the official stdio MCP discovery router. It exposes only a status tool with CLI install, verify, and starting-help guidance; device automation still runs through terminal CLI commands.",summary:"Start MCP discovery router",positionalArgs:[],allowedFlags:[],skipCapabilityCheck:!0},disconnect:{helpDescription:"Disconnect remote daemon state, stop owned Metro companion, and release lease",summary:"Disconnect remote daemon",positionalArgs:[],allowedFlags:["shutdown"],skipCapabilityCheck:!0},connection:{usageOverride:"connection status",listUsageOverride:"connection status",helpDescription:"Inspect active remote connection state",summary:"Inspect remote connection",positionalArgs:["status"],allowedFlags:[],skipCapabilityCheck:!0},auth:{usageOverride:"auth status|login|logout",listUsageOverride:"auth status|login|logout",helpDescription:"Manage cloud CLI authentication",summary:"Manage cloud authentication",positionalArgs:["status|login|logout"],allowedFlags:[],skipCapabilityCheck:!0},push:{helpDescription:"Simulate push notification payload delivery",summary:"Deliver push payload",positionalArgs:["bundleOrPackage","payloadOrJson"],allowedFlags:[]},...eM,devices:{helpDescription:"List available devices",positionalArgs:[],allowedFlags:[],skipCapabilityCheck:!0},appstate:{helpDescription:"Show foreground app/activity",positionalArgs:[],allowedFlags:[],skipCapabilityCheck:!0},metro:{usageOverride:"metro prepare (--public-base-url <url> | --proxy-base-url <url>) [--project-root <path>] [--port <port>] [--kind auto|react-native|expo]\n agent-device metro reload [--metro-host <host>] [--metro-port <port>] [--bundle-url <url>]",listUsageOverride:"metro prepare --public-base-url <url> | --proxy-base-url <url>; metro reload",helpDescription:"Prepare a local Metro runtime or ask Metro to reload connected React Native apps",summary:"Prepare Metro or reload apps",positionalArgs:["prepare|reload"],allowedFlags:["metroHost","metroPort","metroProjectRoot","metroKind","metroPublicBaseUrl","metroProxyBaseUrl","metroBearerToken","metroPreparePort","metroListenHost","metroStatusHost","metroStartupTimeoutMs","metroProbeTimeoutMs","metroRuntimeFile","metroNoReuseExisting","metroNoInstallDeps","bundleUrl"],skipCapabilityCheck:!0},clipboard:{usageOverride:"clipboard read | clipboard write <text>",listUsageOverride:"clipboard read | clipboard write <text>",helpDescription:"Read or write device clipboard text",positionalArgs:["read|write","text?"],allowsExtraPositionals:!0,allowedFlags:[]},keyboard:{usageOverride:"keyboard [status|get|dismiss]",helpDescription:"Inspect Android keyboard visibility/type or dismiss the device keyboard",summary:"Inspect or dismiss the device keyboard",positionalArgs:["action?"],allowedFlags:[]},perf:{helpDescription:"Show session performance metrics, including frame health on Android and iOS devices",summary:"Show performance metrics",positionalArgs:[],allowedFlags:[]},"react-devtools":{usageOverride:"react-devtools [...args]",listUsageOverride:"react-devtools [...args]",helpDescription:"Run pinned agent-react-devtools commands for React Native performance profiling, component trees, props/state/hooks, and render analysis",summary:"Profile React Native performance and component renders",positionalArgs:["args?"],allowsExtraPositionals:!0,allowedFlags:[],skipCapabilityCheck:!0},back:{usageOverride:"back [--in-app|--system]",helpDescription:"Navigate back with explicit app or system semantics",summary:"Go back",positionalArgs:[],allowedFlags:["backMode"]},home:{helpDescription:"Go to home screen (where supported)",summary:"Go home",positionalArgs:[],allowedFlags:[]},rotate:{usageOverride:"rotate <portrait|portrait-upside-down|landscape-left|landscape-right>",helpDescription:"Rotate device orientation on iOS and Android",summary:"Rotate device orientation",positionalArgs:["orientation"],allowedFlags:[]},"app-switcher":{helpDescription:"Open app switcher (where supported)",summary:"Open app switcher",positionalArgs:[],allowedFlags:[]},...eP,alert:{usageOverride:"alert [get|accept|dismiss|wait] [timeout]",helpDescription:"Inspect or handle alert (iOS simulator and macOS desktop)",summary:"Inspect or handle iOS/macOS alerts",positionalArgs:["action?","timeout?"],allowedFlags:[]},click:{usageOverride:"click <x y|@ref|selector>",helpDescription:"Tap/click by coordinates, snapshot ref, or selector",summary:"Tap by coordinates, ref, or selector",positionalArgs:["target"],allowsExtraPositionals:!0,allowedFlags:["count","intervalMs","holdMs","jitterPx","doubleTap","clickButton",...eO]},replay:{helpDescription:"Replay a recorded session",positionalArgs:["path"],allowedFlags:["replayUpdate","replayMaestro","replayEnv"],skipCapabilityCheck:!0},test:{usageOverride:"test <path-or-glob>...",listUsageOverride:"test <path-or-glob>...",helpDescription:"Run one or more .ad scripts as a serial test suite",summary:"Run .ad test suites",positionalArgs:["pathOrGlob"],allowsExtraPositionals:!0,allowedFlags:["replayUpdate","replayEnv","failFast","timeoutMs","retries","artifactsDir","reportJunit"],skipCapabilityCheck:!0},batch:{usageOverride:"batch [--steps <json> | --steps-file <path>]",listUsageOverride:"batch --steps <json> | --steps-file <path>",helpDescription:"Execute multiple commands in one daemon request",summary:"Run multiple commands",positionalArgs:[],allowedFlags:["steps","stepsFile","batchOnError","batchMaxSteps","out"],skipCapabilityCheck:!0},press:{usageOverride:"press <x y|@ref|selector>",helpDescription:"Tap/press by coordinates, snapshot ref, or selector (supports repeated series)",summary:"Press by coordinates, ref, or selector",positionalArgs:["targetOrX","y?"],allowsExtraPositionals:!0,allowedFlags:["count","intervalMs","holdMs","jitterPx","doubleTap",...eO]},longpress:{helpDescription:"Long press by coordinates (iOS and Android)",summary:"Long press by coordinates",positionalArgs:["x","y","durationMs?"],allowedFlags:[]},swipe:{helpDescription:"Swipe coordinates with optional repeat pattern",summary:"Swipe coordinates",positionalArgs:["x1","y1","x2","y2","durationMs?"],allowedFlags:["count","pauseMs","pattern"]},focus:{helpDescription:"Focus input at coordinates",positionalArgs:["x","y"],allowedFlags:[]},...A,fill:{usageOverride:"fill <x> <y> <text> | fill <@ref|selector> <text>",helpDescription:"Tap then type",positionalArgs:["targetOrX","yOrText","text?"],allowsExtraPositionals:!0,allowedFlags:[...eO,"delayMs"]},scroll:{usageOverride:"scroll <direction> [amount] [--pixels <n>]",helpDescription:"Scroll in direction (relative amount or explicit pixels)",summary:"Scroll in a direction",positionalArgs:["direction","amount?"],allowedFlags:["pixels"]},pinch:{helpDescription:"Pinch/zoom gesture (Apple simulator or macOS app session)",positionalArgs:["scale","x?","y?"],allowedFlags:[]},"trigger-app-event":{usageOverride:"trigger-app-event <event> [payloadJson]",helpDescription:"Trigger app-defined event hook via deep link template",summary:"Trigger app event hook",positionalArgs:["event","payloadJson?"],allowedFlags:[]},record:{usageOverride:"record start [path] [--fps <n>] [--quality <5-10>] [--hide-touches] | record stop",listUsageOverride:"record start [path] | record stop",helpDescription:"Start/stop screen recording",summary:"Start or stop screen recording",positionalArgs:["start|stop","path?"],allowedFlags:["fps","quality","hideTouches"]},trace:{usageOverride:"trace start <path> | trace stop <path>",listUsageOverride:"trace start <path> | trace stop <path>",helpDescription:"Start/stop trace log capture; when an artifact path is requested, pass the same positional path to start and stop",summary:"Start or stop trace capture",positionalArgs:["start|stop","path?"],allowedFlags:[],skipCapabilityCheck:!0},logs:{usageOverride:"logs path | logs start | logs stop | logs clear [--restart] | logs doctor | logs mark [message...]",helpDescription:"Session app log info, start/stop streaming, diagnostics, and markers",summary:"Manage session app logs",positionalArgs:["path|start|stop|clear|doctor|mark","message?"],allowsExtraPositionals:!0,allowedFlags:["restart"]},network:{usageOverride:"network dump [limit] [summary|headers|body|all] [--include summary|headers|body|all] | network log [limit] [summary|headers|body|all] [--include summary|headers|body|all]",helpDescription:"Dump recent HTTP(s) traffic parsed from the session app log",summary:"Show recent HTTP traffic",positionalArgs:["dump|log","limit?","include?"],allowedFlags:["networkInclude"]},settings:{usageOverride:ey,listUsageOverride:"settings [area] [options]",helpDescription:"Toggle OS settings, animation scales, appearance, and app permissions (macOS supports only settings appearance <light|dark|toggle> and settings permission <grant|reset> <accessibility|screen-recording|input-monitoring>; wifi|airplane|location|animations remain unsupported on macOS; mobile permission actions use the active session app)",summary:"Change OS settings and app permissions",positionalArgs:["setting","state","target?","mode?"],allowedFlags:[]},session:{usageOverride:"session list",helpDescription:"List active sessions",positionalArgs:["list?"],allowedFlags:[],skipCapabilityCheck:!0}},n4=new Map,n8=new Map;for(let e of n2){for(let t of e.names)n4.set(t,e);let t=n8.get(e.key);t?t.push(e):n8.set(e.key,[e])}function n6(e){return n4.get(e)}function n7(){return n2}function n9(e){if(e)return n3[e]}function re(e,t){let a=n9(e);if(!a?.defaults)return!1;let n=!1;for(let[e,r]of Object.entries(a.defaults))void 0===t[e]&&(t[e]=r,n=!0);return n}function rt(){return Object.keys(n3)}function ra(e){if(!e)return!1;let t=e.trim().toLowerCase();return"1"===t||"true"===t||"yes"===t||"on"===t}function rn(e){let t=e.endsWith("?"),a=t?e.slice(0,-1):e;return t?`[${a}]`:`<${a}>`}let rr=(e=`agent-device <command> [args] [--json]
|
|
397
|
+
|
|
398
|
+
CLI to control iOS and Android devices for AI agents.
|
|
399
|
+
`,t=rl("Commands:",rt().map(e=>{let t=n3[e];if(!t)throw Error(`Missing command schema for ${e}`);return{name:e,schema:t,usage:function(e,t){if(t.listUsageOverride)return t.listUsageOverride;let a=t.positionalArgs.map(a=>{var n,r,i;let s,o,l,c;return n=e,r=t,o=(s=(i=a).endsWith("?"))?i.slice(0,-1):i,c=(l=/^[a-z-]+(?:\|[a-z-]+)+$/i.test(o))||void 0!==r.usageOverride&&r.usageOverride.startsWith(`${n} ${o}`),s?l?`[${o}]`:c?o:`[${o}]`:c?o:`<${o}>`});return[e,...a].join(" ")}(e,t)}}).map(e=>({label:e.usage,description:e.schema.summary??e.schema.helpDescription}))),a=ro("Flags:",rs(n5)),n=rc("Agent Quickstart:",["Default loop: devices/apps -> open -> snapshot -i -> press/fill/get/is/wait/find -> verify -> close.",'Use selectors or refs as positional targets: id="submit", label="Allow", or @e12 from snapshot -i.',"Plain snapshot reads state; snapshot -i is required to refresh interactive refs.","Default snapshot text is an agent-facing, token-efficient view for planning and targeting actions.","Read-only visible/state question: use snapshot/get/is/find; use snapshot -i only when refs are needed.","Anti-pattern: snapshot -i followed by snapshot -i | grep ...; prior refs stay valid until app state changes, and --force-full is the explicit full re-read.","Truncated text/input preview: expand first with snapshot -s @e12, not get text.","React Native apps: read help react-native for Metro, LogBox/RedBox overlays, DevTools routing, and RN-specific blockers.","Android RN/Expo Metro: adb reverse tcp:<port> tcp:<port> is harmless and helps the device reach any local Metro port.",'Expo Go/dev clients: use the provided URL when given; on iOS prefer open "Expo Go" <url>; Android URL opens infer the foreground package for logs/perf when possible.',"Install flows: install/install-from-source first, then open the installed id with --relaunch.",'Text: fill \'id="field-email"\' "qa@example.com" replaces; type appends after press.','Clearing text: do not use fill <target> ""; use a visible clear/reset control or report that clearing is unsupported.',"Android IME capture: if fill says input was captured by the keyboard/IME, inspect keyboard state and switch/disable handwriting before retrying; do not loop fill/type.","Run mutating commands serially against one session; parallelize only read-only commands or separate sessions.","Before taking over a shared device, run session list and reuse the active session name when one already owns the device.","Clipboard limits: iOS Allow Paste cannot be automated through XCUITest; prefill with clipboard write. Android non-ASCII should use fill/type, not raw adb input.","After mutation: diff snapshot -i. Off-screen hints: scroll, then snapshot -i.","Raw coordinates are fallback-only: use snapshot -i -c --json rects when iOS refs no-op or child refs are missing.",'Batch JSON steps use "command", "positionals", "flags"; never "args" or "step".',"Navigation: app-owned back uses back; system back uses back --system.","Verification commands must name the expected text/selector; bare screenshots/snapshots are not enough.","Debug evidence: logs clear --restart/mark/path; trace start ./path; trace stop ./path; network dump --include headers.","Use agent-device commands in final plans; raw platform tools, pseudo commands, and helper prose are wrong.","Full operating guide: agent-device help workflow. Exploratory QA: agent-device help dogfood."]),r=rl("Agent Workflows:",[{label:"help workflow",description:"Normal bootstrap, exploration, and validation loop"},{label:"help debugging",description:"Logs, network, alerts, diagnostics, and traces"},{label:"help react-native",description:"React Native app automation hazards, overlays, Metro, and routing"},{label:"help react-devtools",description:"React Native performance, profiling, component tree, and renders"},{label:"help remote",description:"Remote/cloud config, tenants, leases, and local service tunnels"},{label:"help macos",description:"Desktop, frontmost-app, and menu bar surfaces"},{label:"help dogfood",description:"Exploratory QA report workflow"}]),i=rc("Configuration:",["Default config files: ~/.agent-device/config.json, ./agent-device.json","Use --config <path> or AGENT_DEVICE_CONFIG to load one explicit config file."]),s=rl("Environment:",[{label:"AGENT_DEVICE_SESSION",description:"Default session name"},{label:"AGENT_DEVICE_PLATFORM",description:"Default platform binding"},{label:"AGENT_DEVICE_SESSION_LOCK",description:"Bound-session conflict mode"},{label:"AGENT_DEVICE_DAEMON_BASE_URL",description:"Connect to remote daemon"},{label:"AGENT_DEVICE_DAEMON_AUTH_TOKEN",description:"Remote daemon service/API token"},{label:"AGENT_DEVICE_CLOUD_BASE_URL",description:"Bridge/control-plane API origin for cloud auth and /api-keys"}]),o=rc("Examples:",["agent-device open Settings --platform ios","agent-device open TextEdit --platform macos","agent-device snapshot -i","agent-device react-devtools get tree --depth 3",'agent-device fill @e3 "test@example.com"',"agent-device replay ./session.ad","agent-device test ./suite --platform android"]),`${e}
|
|
400
|
+
${t}
|
|
401
|
+
|
|
402
|
+
${a}
|
|
403
|
+
|
|
404
|
+
${n}
|
|
405
|
+
|
|
406
|
+
${r}
|
|
407
|
+
|
|
408
|
+
${i}
|
|
409
|
+
|
|
410
|
+
${s}
|
|
411
|
+
|
|
412
|
+
${o}
|
|
413
|
+
`);function ri(){return rr}function rs(e){return n2.filter(t=>e.has(t.key)&&void 0!==t.usageLabel&&void 0!==t.usageDescription)}function ro(e,t){return rl(e,t.map(e=>({label:e.usageLabel??"",description:e.usageDescription??""})))}function rl(e,t){if(0===t.length)return`${e}
|
|
414
|
+
(none)`;let a=Math.max(...t.map(e=>e.label.length))+2,n=[e];for(let e of t)n.push(` ${e.label.padEnd(a)}${e.description}`);return n.join("\n")}function rc(e,t){return 0===t.length?`${e}
|
|
415
|
+
(none)`:[e,...t.map(e=>` ${e}`)].join("\n")}function rd(e){var t,a;let n,r=(n=n1[e])?`${n.body}
|
|
416
|
+
|
|
417
|
+
Related:
|
|
418
|
+
agent-device help command list and global flags
|
|
419
|
+
agent-device help <command> command-specific flags
|
|
420
|
+
agent-device help workflow normal app automation loop
|
|
421
|
+
`:null;if(r)return r;let i=n9(e);if(!i)return null;let s=(t=e,(a=i).usageOverride?a.usageOverride:[t,...a.positionalArgs.map(rn),...a.allowedFlags.flatMap(e=>(n8.get(e)??[]).map(e=>e.usageLabel??e.names[0])).map(e=>`[${e}]`)].join(" ")),o=rs(new Set(i.allowedFlags)),l=rs(n5),c=[];return o.length>0&&c.push(ro("Command flags:",o)),c.push(ro("Global flags:",l)),`agent-device ${s}
|
|
422
|
+
|
|
423
|
+
${i.helpDescription}
|
|
424
|
+
|
|
425
|
+
Usage:
|
|
426
|
+
agent-device ${s}
|
|
427
|
+
|
|
428
|
+
${c.join("\n\n")}
|
|
429
|
+
`}export{eN as CAPTURE_COMMAND_CAPABILITIES,n5 as GLOBAL_FLAG_KEYS,eE as SELECTOR_COMMAND_CAPABILITIES,e$ as SESSION_LIFECYCLE_COMMAND_CAPABILITIES,ev as SETTINGS_INVALID_ARGS_MESSAGE,re as applyCommandDefaults,rd as buildCommandUsageText,ea as buildMobileSnapshotPresentation,tP as buildSnapshotDisplayLines,ri as buildUsageText,nJ as createAgentDevice,eF as decodePng,en as deriveMobileSnapshotHiddenContentHints,et as displayNodeLabel,t3 as evaluateIsPredicate,eA as findMistargetedTypeRefToken,tE as formatSnapshotLine,rt as getCliCommandNames,n9 as getCommandSchema,n6 as getFlagDefinition,n7 as getFlagDefinitions,ex as getUnsupportedMacOsSettingMessage,ek as isMacOsSettingSupported,ra as isStrictFlagModeEnabled,t5 as isSupportedPredicate,nQ as localCommandPolicy,Z as normalizeSnapshotTree,eI as parseDeviceRotation,n0 as parseSessionSurface,eD as requireIntInRange,ah as resolveRectCenter};
|