agent-device 0.16.1 → 0.16.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android-multitouch-helper/dist/{agent-device-android-multitouch-helper-0.16.1.apk → agent-device-android-multitouch-helper-0.16.4.apk} +0 -0
- package/android-multitouch-helper/dist/agent-device-android-multitouch-helper-0.16.4.apk.sha256 +1 -0
- package/android-multitouch-helper/dist/{agent-device-android-multitouch-helper-0.16.1.manifest.json → agent-device-android-multitouch-helper-0.16.4.manifest.json} +4 -4
- package/android-snapshot-helper/dist/agent-device-android-snapshot-helper-0.16.4.apk +0 -0
- package/android-snapshot-helper/dist/agent-device-android-snapshot-helper-0.16.4.apk.sha256 +1 -0
- package/android-snapshot-helper/dist/{agent-device-android-snapshot-helper-0.16.1.manifest.json → agent-device-android-snapshot-helper-0.16.4.manifest.json} +6 -6
- package/dist/src/1393.js +1 -0
- package/dist/src/1769.js +7 -7
- package/dist/src/221.js +6 -4
- package/dist/src/6277.js +4 -0
- package/dist/src/7519.js +1 -1
- package/dist/src/7599.js +3 -0
- package/dist/src/89.js +1 -1
- package/dist/src/9542.js +3 -2
- package/dist/src/android-adb.js +1 -1
- package/dist/src/android-snapshot-helper.d.ts +10 -1
- package/dist/src/android-snapshot-helper.js +1 -1
- package/dist/src/batch.d.ts +1 -0
- package/dist/src/cli.js +15 -13
- package/dist/src/contracts.d.ts +1 -0
- package/dist/src/contracts.js +1 -1
- package/dist/src/index.d.ts +3 -0
- package/dist/src/internal/daemon.js +52 -52
- package/dist/src/server.js +1 -1
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunner/Assets.xcassets/AppIcon.appiconset/logo.jpg +0 -0
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunner/Assets.xcassets/Logo.imageset/logo.jpg +0 -0
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunner.xcodeproj/project.pbxproj +0 -4
- package/package.json +1 -4
- package/server.json +2 -2
- package/android-multitouch-helper/dist/agent-device-android-multitouch-helper-0.16.1.apk.sha256 +0 -1
- package/android-snapshot-helper/dist/agent-device-android-snapshot-helper-0.16.1.apk +0 -0
- package/android-snapshot-helper/dist/agent-device-android-snapshot-helper-0.16.1.apk.sha256 +0 -1
- package/dist/src/2099.js +0 -1
- package/dist/src/3622.js +0 -3
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/Assets.xcassets/AppIcon.appiconset/Contents.json +0 -14
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/Assets.xcassets/AppIcon.appiconset/logo-tinted.jpg +0 -0
- package/ios-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/Assets.xcassets/Contents.json +0 -6
|
Binary file
|
package/android-multitouch-helper/dist/agent-device-android-multitouch-helper-0.16.4.apk.sha256
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
f390055d51600b183b9b9cb07cbee02dd2966c03682ee389f10823622e9ff714 agent-device-android-multitouch-helper-0.16.4.apk
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "android-multitouch-helper",
|
|
3
|
-
"version": "0.16.
|
|
4
|
-
"assetName": "agent-device-android-multitouch-helper-0.16.
|
|
5
|
-
"sha256": "
|
|
3
|
+
"version": "0.16.4",
|
|
4
|
+
"assetName": "agent-device-android-multitouch-helper-0.16.4.apk",
|
|
5
|
+
"sha256": "f390055d51600b183b9b9cb07cbee02dd2966c03682ee389f10823622e9ff714",
|
|
6
6
|
"packageName": "com.callstack.agentdevice.multitouchhelper",
|
|
7
|
-
"versionCode":
|
|
7
|
+
"versionCode": 16004,
|
|
8
8
|
"instrumentationRunner": "com.callstack.agentdevice.multitouchhelper/.MultiTouchInstrumentation",
|
|
9
9
|
"statusProtocol": "android-multitouch-helper-v1"
|
|
10
10
|
}
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
94f014115f4797937f21786b542dcbf9d310be1e8d90520a33ec6dbe4b88ff0b agent-device-android-snapshot-helper-0.16.4.apk
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "android-snapshot-helper",
|
|
3
|
-
"version": "0.16.
|
|
4
|
-
"releaseTag": "v0.16.
|
|
5
|
-
"assetName": "agent-device-android-snapshot-helper-0.16.
|
|
3
|
+
"version": "0.16.4",
|
|
4
|
+
"releaseTag": "v0.16.4",
|
|
5
|
+
"assetName": "agent-device-android-snapshot-helper-0.16.4.apk",
|
|
6
6
|
"apkUrl": null,
|
|
7
|
-
"sha256": "
|
|
8
|
-
"checksumName": "agent-device-android-snapshot-helper-0.16.
|
|
7
|
+
"sha256": "94f014115f4797937f21786b542dcbf9d310be1e8d90520a33ec6dbe4b88ff0b",
|
|
8
|
+
"checksumName": "agent-device-android-snapshot-helper-0.16.4.apk.sha256",
|
|
9
9
|
"packageName": "com.callstack.agentdevice.snapshothelper",
|
|
10
|
-
"versionCode":
|
|
10
|
+
"versionCode": 16004,
|
|
11
11
|
"instrumentationRunner": "com.callstack.agentdevice.snapshothelper/.SnapshotInstrumentation",
|
|
12
12
|
"minSdk": 23,
|
|
13
13
|
"targetSdk": 36,
|
package/dist/src/1393.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{AppError as e}from"./9152.js";let r="user-installed";function t(e){return e??r}function o(r){if(void 0===r)throw new e("INVALID_ARGS","appsFilter must be resolved before executing the apps command");return r}export{r as DEFAULT_APPS_FILTER,o as assertResolvedAppsFilter,t as resolveAppsFilter};
|
package/dist/src/1769.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{promises as e}from"node:fs";import t from"node:os";import a from"node:path";import{asAppError as n,AppError as i}from"./9152.js";import{emitDiagnostic as r}from"./
|
|
2
|
-
${e.stderr}`}function q(e,t){return["-s",e,...t]}function Z(e){return e.startsWith("emulator-")}function J(e){return e.toLowerCase().replace(/_/g," ").replace(/\s+/g," ").trim()}async function X(e,t=1e4){return o("adb",q(e,["shell","getprop","sys.boot_completed"]),{allowFailure:!0,timeoutMs:t})}async function Q(e,t){let a=t.replace(/_/g," ").trim();if(!Z(e))return a||e;let n=await ee(e);return n?n.replace(/_/g," "):a||e}async function Y(e,t,a){try{return await a("adb",q(e,t),{allowFailure:!0,timeoutMs:1e4})}catch(e){var i;if("COMMAND_FAILED"===(i=n(e)).code&&"number"==typeof i.details?.timeoutMs)return;throw e}}async function ee(e,t=o){for(let a of["ro.boot.qemu.avd_name","persist.sys.avd_name"]){let n=await Y(e,["shell","getprop",a],t);if(!n)continue;let i=n.stdout.trim();if(0===n.exitCode&&i.length>0)return i}let a=await Y(e,["emu","avd","name"],t);if(!a)return;let n=function(e){let t=e.split("\n").map(e=>e.trim()).filter(e=>e.length>0);if(0!==t.length)return"OK"===t.at(-1)&&t.pop(),t.join("\n").trim()||void 0}(a.stdout);if(0===a.exitCode&&n)return n}async function et(e,t){let a=z(await o("adb",q(e,["shell","cmd","package","has-feature",t]),{allowFailure:!0,timeoutMs:1e4})).toLowerCase();return!!a.includes("true")||!a.includes("false")&&null}async function ea(e){return(await H(K,2,async t=>await et(e,t))).some(e=>!0===e)}async function en(e){var t;let a;return"tv"===((a=z(await o("adb",q(e,["shell","getprop","ro.build.characteristics"]),{allowFailure:!0,timeoutMs:1e4})).toLowerCase()).includes("tv")||a.includes("leanback")?"tv":null)||await ea(e)?"tv":(t=z(await o("adb",q(e,["shell","pm","list","features"]),{allowFailure:!0,timeoutMs:1e4})),/feature:android\.(software\.leanback(_only)?|hardware\.type\.television)\b/i.test(t))?"tv":"mobile"}async function ei(e={}){if(await u(),!await l("adb"))throw new i("TOOL_MISSING","adb not found in PATH");let t=e.serialAllowlist??$(void 0),a=(await er()).filter(e=>!t||t.has(e.serial));return await H(a,3,async({serial:e,rawModel:t})=>{let[a,n,i]=await Promise.all([Q(e,t),ed(e),en(e)]);return{platform:"android",id:e,name:a,kind:Z(e)?"emulator":"device",target:i,booted:n}})}async function er(){return(await o("adb",["devices","-l"],{timeoutMs:1e4})).stdout.split("\n").map(e=>e.trim()).filter(e=>e.length>0&&!e.startsWith("List of devices")).map(e=>e.split(/\s+/)).flatMap(e=>{let t=e[0];return void 0===t||"device"!==e[1]?[]:[{serial:t,rawModel:(e.find(e=>e.startsWith("model:"))??"").replace("model:","")}]})}async function eo(){let e=await o("emulator",["-list-avds"],{allowFailure:!0,timeoutMs:1e4});if(0!==e.exitCode)throw new i("COMMAND_FAILED","Failed to list Android emulator AVDs",{stdout:e.stdout,stderr:e.stderr,exitCode:e.exitCode,hint:"Verify Android emulator tooling is installed and available in PATH."});return e.stdout.split("\n").map(e=>e.trim()).filter(e=>e.length>0)}async function es(e){let t=Date.now();for(;Date.now()-t<e.timeoutMs;){try{let t=await el(e.avdName,e.serial);if(t)return{platform:"android",id:t,name:e.avdName,kind:"emulator",target:"mobile",booted:!1}}catch{}await p(1e3)}throw new i("COMMAND_FAILED","Android emulator did not appear in time",{avdName:e.avdName,serial:e.serial,timeoutMs:e.timeoutMs,hint:"Check emulator logs and verify the AVD can start from command line."})}async function el(e,t){let a=J(e);for(let e of(await er()).filter(e=>(!t||e.serial===t)&&Z(e.serial)))if(J(e.rawModel)===a||J(await Q(e.serial,e.rawModel))===a)return e.serial}async function ed(e){try{let t=await X(e);return"1"===t.stdout.trim()}catch{return!1}}async function eu(e){var t,a;let n;await u();let r=e.avdName.trim();if(!r)throw new i("INVALID_ARGS","Android emulator boot requires a non-empty AVD name.");let o=e.timeoutMs??12e4;if(!await l("adb"))throw new i("TOOL_MISSING","adb not found in PATH");if(!await l("emulator"))throw new i("TOOL_MISSING","emulator not found in PATH");let s=await eo(),c=function(e,t){let a=e.find(e=>e===t);if(a)return a;let n=J(t);return e.find(e=>J(e)===n)}(s,r);if(!c)throw new i("DEVICE_NOT_FOUND",`No Android emulator AVD named ${e.avdName}`,{requestedAvdName:r,availableAvds:s,hint:"Run `emulator -list-avds` and pass an existing AVD name to --device."});let p=Date.now(),f=(t=await ei(),a=e.serial,n=J(c),t.find(e=>"android"===e.platform&&"emulator"===e.kind&&(!a||e.id===a)&&J(e.name)===n));if(!f){let t=["-avd",c];e.headless&&t.push("-no-window","-no-audio"),d("emulator",t)}let m=f??await es({avdName:c,serial:e.serial,timeoutMs:o}),w=Math.max(1e3,o-(Date.now()-p));await ec(m.id,w);let h=(await ei()).find(e=>e.id===m.id);return h?{...h,name:c,booted:!0}:{...m,name:c,booted:!0}}async function ec(e,t=6e4){let a,r=x.fromTimeoutMs(t),o=Math.max(1,Math.ceil(t/1e3)),s=!1;try{await S(async({deadline:n})=>{if(n?.isExpired())throw s=!0,new i("COMMAND_FAILED","Android boot deadline exceeded",{serial:e,timeoutMs:t,elapsedMs:r.elapsedMs(),message:"timeout"});let o=Math.max(1e3,n?.remainingMs()??t),l=await X(e,Math.min(o,1e4));if(a=l,"1"!==l.stdout.trim())throw new i("COMMAND_FAILED","Android device is still booting",{serial:e,stdout:l.stdout,stderr:l.stderr,exitCode:l.exitCode})},{maxAttempts:o,baseDelayMs:1e3,maxDelayMs:1e3,jitter:0,shouldRetry:e=>{let t=G({error:e,stdout:a?.stdout,stderr:a?.stderr,context:{platform:"android",phase:"boot"}});return"ADB_TRANSPORT_UNAVAILABLE"!==t&&"ANDROID_BOOT_TIMEOUT"!==t}},{deadline:r,phase:"boot",classifyReason:e=>G({error:e,stdout:a?.stdout,stderr:a?.stderr,context:{platform:"android",phase:"boot"}})})}catch(f){let o=n(f),l=a?.stdout,d=a?.stderr,u=a?.exitCode,c=G({error:f,stdout:l,stderr:d,context:{platform:"android",phase:"boot"}});"BOOT_COMMAND_FAILED"===c&&"Android device is still booting"===o.message&&(c="ANDROID_BOOT_TIMEOUT");let p={serial:e,timeoutMs:t,elapsedMs:r.elapsedMs(),reason:c,hint:j(c),stdout:l,stderr:d,exitCode:u};if(s||"ANDROID_BOOT_TIMEOUT"===c)throw new i("COMMAND_FAILED","Android device did not finish booting in time",p);if("TOOL_MISSING"===o.code)throw new i("TOOL_MISSING",o.message,{...p,...o.details??{}});if("ADB_TRANSPORT_UNAVAILABLE"===c)throw new i("COMMAND_FAILED",o.message,{...p,...o.details??{}});throw new i(o.code,o.message,{...p,...o.details??{}},o.cause)}}async function ep(e,t,a){return await h(e)(t,a)}function ef(e){return{platform:"android",id:e,name:e,kind:e.startsWith("emulator-")?"emulator":"device",booted:!0}}async function em(){if(await u(),!await l("adb"))throw new i("TOOL_MISSING","adb not found in PATH")}let ew=/\.(?:apk|aab)$/i,eh=/^[A-Za-z_][\w]*(\.[A-Za-z_][\w]*)+$/;function eA(e){var t,a;let n=e.trim();return 0===n.length?"other":ew.test(n)?n.includes("/")||n.includes("\\")||n.startsWith(".")||n.startsWith("~")||(t=n,!eh.test(t))?"binary":"package":(a=n,eh.test(a))?"package":"other"}function ey(e){return`Android runtime hints require an installed package name, not "${e}". Install or reinstall the app first, then relaunch by package.`}async function eg(e,t){let n="url"===e.kind&&y(e.url),i=await A({source:e,isInstallablePath:(e,t)=>{var n;let i;return t.isFile()&&(n=e,".apk"===(i=a.extname(n).toLowerCase())||".aab"===i)},installableLabel:"Android installable (.apk or .aab)",allowArchiveExtraction:"url"!==e.kind||n,signal:t?.signal});try{let e=t?.resolveIdentity===!1?{}:await ev(i.installablePath);return{archivePath:i.archivePath,installablePath:i.installablePath,packageName:e.packageName,cleanup:i.cleanup}}catch(e){throw await i.cleanup(),e}}async function ev(e){let t=a.extname(e).toLowerCase();return".apk"!==t&&".aab"!==t?{}:{packageName:await c(e)}}let eb={settings:{type:"intent",value:"android.settings.SETTINGS"}},eM="android.intent.category.LAUNCHER",e_="android.intent.category.LEANBACK_LAUNCHER",eI="android.intent.category.DEFAULT",eO="Run agent-device apps --platform android to discover the installed package name, then retry open with that exact package.",eN=new Set(["localhost","127.0.0.1","::1","[::1]"]),eC=T();function eD(e){return{platform:"android",deviceId:e.id,variant:e.target??""}}async function ek(e,t){let a=t.trim();if("package"===eA(a))return{type:"package",value:a};let n=eb[a.toLowerCase()];if(n)return n;let r=eD(e),o=eC.get(r,a);if(o)return o;let s=(await ep(e,["shell","pm","list","packages"])).stdout.split("\n").map(e=>e.replace("package:","").trim()).filter(Boolean).filter(e=>e.toLowerCase().includes(a.toLowerCase())),l=s[0];if(void 0!==l&&1===s.length)return eC.set(r,a,{type:"package",value:l});if(s.length>1)throw new i("INVALID_ARGS",`Multiple packages matched "${t}"`,{matches:s,hint:"Run agent-device apps --platform android to see the exact installed package names before retrying open."});throw new i("APP_NOT_INSTALLED",`No package found matching "${t}"`,{hint:eO})}async function eT(e,t){let a=await eE(e);return("user-installed"===t?(await ex(e)).filter(e=>a.has(e)):Array.from(a)).sort((e,t)=>e.localeCompare(t)).map(e=>({package:e,name:eS(e)}))}async function eE(e){let t=new Set;for(let a of eL(e,{includeFallbackWhenUnknown:!0})){let n=await ep(e,["shell","cmd","package","query-activities","--brief","-a","android.intent.action.MAIN","-c",a],{allowFailure:!0});if(0===n.exitCode&&0!==n.stdout.trim().length)for(let e of _(n.stdout))t.add(e)}return t}function eL(e,t={}){return"tv"===e.target?[e_]:"mobile"===e.target?[eM]:t.includeFallbackWhenUnknown?[eM,e_]:[eM]}async function ex(e){return I((await ep(e,["shell","pm","list","packages","-3"])).stdout)}function eS(e){let t=new Set(["com","android","google","app","apps","service","services","mobile","client"]),a=e.split(".").flatMap(e=>e.split(/[_-]+/)).map(e=>e.trim().toLowerCase()).filter(e=>e.length>0),n=a[a.length-1]??e;for(let e=a.length-1;e>=0;e-=1){let i=a[e];if(i&&!t.has(i)){n=i;break}}return n.split(/[^a-z0-9]+/i).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" ")}async function eR(e){let t=await eU(e,[["shell","dumpsys","window","windows"],["shell","dumpsys","window"]]);if(t)return t;let a=await eU(e,[["shell","dumpsys","activity","activities"],["shell","dumpsys","activity"]]);return a||{}}async function eP(e){return await eF(e,[["shell","dumpsys","window","windows"],["shell","dumpsys","window"]])}async function eU(e,t){for(let a of t){let t=O((await ep(e,a,{allowFailure:!0})).stdout??"");if(t)return t}return null}async function eF(e,t){for(let a of t){let t=N((await ep(e,a,{allowFailure:!0})).stdout??"",(e,t)=>(function(e,t){let a=e.split("}")[0]?.trim()??e.trim(),n=v.exec(a);if(n){let e=n[1];return{package:e,focusedWindow:`Application Not Responding: ${e}`,raw:t}}let i=b.exec(a);if(!i)return null;let r=i[1];if(void 0===r)return null;let o=r.trim().replace(/\s+/g," "),s=M.exec(o)?.[1];return{...s?{package:s}:{},focusedWindow:o,raw:t}})(e,t));if(t)return t}return null}async function eB(e,t){let a=function(e){let t;try{t=new URL(e)}catch{return null}let a=t.hostname.toLowerCase();if(!eN.has(a)||!t.port)return null;let n=Number(t.port);return Number.isInteger(n)?`tcp:${n}`:null}(t);if(!a)return;let n=f(m(e));try{await n.ensure({local:a,remote:a})}catch(t){let e={localPort:a.replace("tcp:",""),operation:`adb reverse ${a} ${a}`};throw t instanceof i&&Object.assign(e,{hint:t.details?.hint,diagnosticId:t.details?.diagnosticId,logPath:t.details?.logPath}),new i("COMMAND_FAILED",`Failed to ensure Android port reverse ${a} before opening localhost URL`,e,t)}}async function e$(e,t,a){var n;e.booted||await ec(e.id);let i="string"==typeof(n=a)?{activity:n}:n??{},r=i.activity,o=t.trim();if(D(o))return void await eW(e,o,i);if(void 0!==i.url)return void await eV(e,t,i);let s=await ek(e,t),l=eL(e)[0]??eM;"intent"===s.type?await eG(e,s.value,r):r?await ej(e,s.value,r,l):await eK(e,s.value,l)}async function eW(e,t,a){var n;let r;if(a.activity)throw new i("INVALID_ARGS","Activity override is not supported when opening a deep link URL");await eB(e,t),await ep(e,["shell","am","start","-W","-a","android.intent.action.VIEW","-d",t,...(n=a.appBundleId,(r=n?.trim())?["-p",r]:[])])}async function eV(e,t,a){if(a.activity)throw new i("INVALID_ARGS","Activity override is not supported when opening an app-bound deep link URL");let n=a.url?.trim()??"";if(!D(n))throw new i("INVALID_ARGS","Android app-bound open requires a valid URL target");let r=await ez(e,t,"app-bound open");await ep(e,["shell","am","start","-W","-a","android.intent.action.VIEW","-d",n,"-p",r])}async function eG(e,t,a){if(a)throw new i("INVALID_ARGS","Activity override requires a package name, not an intent");await ep(e,["shell","am","start","-W","-a",t])}async function ej(e,t,a,n){let i=a.includes("/")?a:`${t}/${a.startsWith(".")?a:`.${a}`}`;try{await ep(e,eH(i,n))}catch(a){throw await eJ(e,t,a),a}}async function eK(e,t,a){let n=await ep(e,["shell","am","start","-W","-a","android.intent.action.MAIN","-c",eI,"-c",a,"-p",t],{allowFailure:!0});if(0===n.exitCode&&!eY(n.stdout,n.stderr))return;let r=await eQ(e,t);if(!r){if(!await eZ(e,t))throw eq(t);throw new i("COMMAND_FAILED",`Failed to launch ${t}`,{stdout:n.stdout,stderr:n.stderr})}await ep(e,eH(r,a))}function eH(e,t){return["shell","am","start","-W","-a","android.intent.action.MAIN","-c",eI,"-c",t,"-n",e]}async function ez(e,t,a){let n=await ek(e,t);if("intent"===n.type)throw new i("INVALID_ARGS",`Android ${a} requires a package name, not an intent`);return n.value}function eq(e){return new i("APP_NOT_INSTALLED",`No package found matching "${e}"`,{package:e,hint:eO})}async function eZ(e,t){let a=await ep(e,["shell","pm","path",t],{allowFailure:!0}),n=`${a.stdout}
|
|
3
|
-
${a.stderr}`;return!!(0===a.exitCode&&/\bpackage:/i.test(n))||(
|
|
4
|
-
${String(a.details?.stderr??"")}`:"")||!await
|
|
5
|
-
${t}`;return/Error:.*(?:Activity not started|unable to resolve Intent)/i.test(a)}function
|
|
6
|
-
${n.stderr}`.toLowerCase();if(!e.includes("unknown package")&&!e.includes("not installed"))throw new i("COMMAND_FAILED",`adb uninstall failed for ${a.value}`,{stdout:n.stdout,stderr:n.stderr,exitCode:n.exitCode})}return{package:a.value}}let
|
|
7
|
-
${r}`.toLowerCase()).includes("no shell command implementation")||o.includes("unknown command"))throw new i("UNSUPPORTED_OPERATION",`Android shell clipboard ${a} is not supported on this device.`);if(0!==s.exitCode)throw new i("COMMAND_FAILED",`Failed to ${a} Android clipboard text`,{stdout:s.stdout,stderr:s.stderr,exitCode:s.exitCode});return s.stdout}export{x as Deadline,
|
|
1
|
+
import{promises as e}from"node:fs";import t from"node:os";import a from"node:path";import{asAppError as n,AppError as i}from"./9152.js";import{emitDiagnostic as r}from"./7599.js";import{runCmd as o,resolveFileOverridePath as s,whichCmd as l,runCmdDetached as d}from"./9818.js";import{ensureAndroidSdkPathConfigured as u,resolveAndroidArchivePackageName as c}from"./7651.js";import{sleep as p}from"./4829.js";import{createAndroidPortReverseManager as f,resolveAndroidAdbProvider as m,installAndroidAdbPackage as w,resolveAndroidAdbExecutor as h}from"./9639.js";import{materializeInstallablePath as A,isTrustedInstallSourceUrl as y}from"./989.js";let g=["mCurrentFocus=Window{","mFocusedApp=AppWindowToken{","mResumedActivity:","ResumedActivity:"],b=/\bApplication Not Responding:\s*([A-Za-z0-9_.]+)/i,v=/([^{}]*\bis(?:n't| not)\s+responding[^{}]*)/i,M=/\b([A-Za-z][A-Za-z0-9_]*(?:\.[A-Za-z0-9_]+)+)\b/;function _(e){let t=new Set;for(let a of e.split("\n")){let e=a.trim();if(!e)continue;let n=e.split(/\s+/)[0]??"";if(!n.includes("/"))continue;let i=n.split("/")[0]??"";i.includes(".")&&i&&t.add(i)}return Array.from(t)}function I(e){return e.split("\n").map(e=>{let t=e.trim();return t.startsWith("package:")?t.slice(8):t}).filter(Boolean)}function O(e){return N(e,e=>(function(e){for(let t of e.trim().split(/\s+/)){let e=t.indexOf("/");if(e<=0)continue;let a=C(t.slice(0,e),!1),n=C(t.slice(e+1),!0);if(a&&n&&a.length===e)return{package:a,activity:n}}return null})(e))}function N(e,t){let a=e.split("\n");for(let e of g)for(let n of a){let a=n.indexOf(e);if(-1===a)continue;let i=n.trim(),r=t(n.slice(a+e.length),i);if(r)return r}return null}function C(e,t){let a=0;for(;a<e.length&&function(e,t){if(!e)return!1;let a=e.charCodeAt(0);return a>=48&&a<=57||a>=65&&a<=90||a>=97&&a<=122||"_"===e||"."===e||t&&"$"===e}(e[a],t);)a+=1;return e.slice(0,a)}function D(e){let t=e.trim();if(!t||/\s/.test(t))return!1;let a=/^([A-Za-z][A-Za-z0-9+.-]*):(.+)$/.exec(t);if(!a)return!1;let n=a[1]?.toLowerCase(),i=a[2]??"";return"http"!==n&&"https"!==n&&"ws"!==n&&"wss"!==n&&"ftp"!==n&&"ftps"!==n||i.startsWith("//")}function k(e){let t=e.trim().split(":")[0]?.toLowerCase();return"http"===t||"https"===t}function T(e,t){let a=e?.trim();return a||(k(t)?"com.apple.mobilesafari":void 0)}function E(e={}){let t=e.ttlMs??3e4,a=e.nowMs??Date.now,n=new Map,i=e=>{var t;let a=[(t=e).platform,t.deviceId,""].join("\0");for(let e of n.keys())e.startsWith(a)&&n.delete(e)};return{get(e,t){let i=S(e,t),r=n.get(i);if(r)return r.expiresAtMs<=a()?void n.delete(i):r.value},set:(e,i,r)=>(n.set(S(e,i),{value:r,expiresAtMs:a()+t}),r),clear(e){i(e)},async invalidateWhile(e,t){i(e);try{return await t()}finally{i(e)}}}}function S(e,t){return[e.platform,e.deviceId,e.variant??"",t.trim().toLowerCase()].join("\0")}function L(e){return["1","true","yes","on"].includes((e??"").trim().toLowerCase())}class x{startedAtMs;expiresAtMs;constructor(e,t){this.startedAtMs=e,this.expiresAtMs=e+Math.max(0,t)}static fromTimeoutMs(e,t=Date.now()){return new x(t,e)}remainingMs(e=Date.now()){return Math.max(0,this.expiresAtMs-e)}elapsedMs(e=Date.now()){return Math.max(0,e-this.startedAtMs)}isExpired(e=Date.now()){return 0>=this.remainingMs(e)}}async function R(e,t={},a={}){let n,r={maxAttempts:t.maxAttempts??3,baseDelayMs:t.baseDelayMs??200,maxDelayMs:t.maxDelayMs??2e3,jitter:t.jitter??.2,shouldRetry:t.shouldRetry};for(let t=1;t<=r.maxAttempts;t+=1){if(a.signal?.aborted)throw new i("COMMAND_FAILED","request canceled",{reason:"request_canceled"});if(a.deadline?.isExpired()&&t>1)break;try{let n=await e({attempt:t,maxAttempts:r.maxAttempts,deadline:a.deadline});return a.onEvent?.({phase:a.phase,event:"succeeded",attempt:t,maxAttempts:r.maxAttempts,elapsedMs:a.deadline?.elapsedMs(),remainingMs:a.deadline?.remainingMs()}),U({phase:a.phase,event:"succeeded",attempt:t,maxAttempts:r.maxAttempts,elapsedMs:a.deadline?.elapsedMs(),remainingMs:a.deadline?.remainingMs()}),n}catch(d){n=d;let e=a.classifyReason?.(d),i={phase:a.phase,event:"attempt_failed",attempt:t,maxAttempts:r.maxAttempts,elapsedMs:a.deadline?.elapsedMs(),remainingMs:a.deadline?.remainingMs(),reason:e};if(a.onEvent?.(i),U(i),t>=r.maxAttempts||r.shouldRetry&&!r.shouldRetry(d,t))break;let o=function(e,t,a,n){let i=Math.min(t,e*2**(n-1));return Math.max(0,i+i*a*(2*Math.random()-1))}(r.baseDelayMs,r.maxDelayMs,r.jitter,t),s=a.deadline?Math.min(o,a.deadline.remainingMs()):o;if(s<=0)break;let l={phase:a.phase,event:"retry_scheduled",attempt:t,maxAttempts:r.maxAttempts,delayMs:s,elapsedMs:a.deadline?.elapsedMs(),remainingMs:a.deadline?.remainingMs(),reason:e};a.onEvent?.(l),U(l),await function(e,t){return new Promise(a=>{if(t?.aborted)return void a();let n=!1,i=()=>{n||(n=!0,t&&t.removeEventListener("abort",o),a())},r=setTimeout(i,e);function o(){clearTimeout(r),i()}t&&t.addEventListener("abort",o,{once:!0})})}(s,a.signal)}}let o={phase:a.phase,event:"exhausted",attempt:r.maxAttempts,maxAttempts:r.maxAttempts,elapsedMs:a.deadline?.elapsedMs(),remainingMs:a.deadline?.remainingMs(),reason:a.classifyReason?.(n)};if(a.onEvent?.(o),U(o),n)throw n;throw new i("COMMAND_FAILED","retry failed")}async function P(e,t={}){return R(()=>e(),{maxAttempts:t.attempts,baseDelayMs:t.baseDelayMs,maxDelayMs:t.maxDelayMs,jitter:t.jitter,shouldRetry:t.shouldRetry})}function U(e){r({level:"attempt_failed"===e.event||"exhausted"===e.event?"warn":"debug",phase:"retry",data:{...e}})}function F(e){return e?.trim()||void 0}function B(e){return F(e)}function V(e){return new Set(e.split(/[\s,]+/).map(e=>e.trim()).filter(Boolean))}function W(e,t=process.env){let a=F(e)??F(t.AGENT_DEVICE_ANDROID_DEVICE_ALLOWLIST);if(a)return V(a)}let $=new Set(["IOS_BOOT_TIMEOUT","IOS_RUNNER_CONNECT_TIMEOUT","IOS_TOOL_MISSING","ANDROID_BOOT_TIMEOUT","ADB_TRANSPORT_UNAVAILABLE","CI_RESOURCE_STARVATION_SUSPECTED"]);function G(e){return $.has(e.toUpperCase())}function j(e){let t=e.error?n(e.error):null,a=e.context?.platform,i=e.context?.phase;if(t?.code==="TOOL_MISSING")return"android"===a?"ADB_TRANSPORT_UNAVAILABLE":"IOS_TOOL_MISSING";let r=t?.details??{},o="string"==typeof r.message?r.message:void 0,s="string"==typeof r.stdout?r.stdout:void 0,l="string"==typeof r.stderr?r.stderr:void 0,d=r.boot&&"object"==typeof r.boot?r.boot:null,u=r.bootstatus&&"object"==typeof r.bootstatus?r.bootstatus:null,c=[e.message,t?.message,e.stdout,e.stderr,o,s,l,"string"==typeof d?.stdout?d.stdout:void 0,"string"==typeof d?.stderr?d.stderr:void 0,"string"==typeof u?.stdout?u.stdout:void 0,"string"==typeof u?.stderr?u.stderr:void 0].filter(Boolean).join("\n").toLowerCase();return"ios"===a&&(c.includes("runner did not accept connection")||"connect"===i&&(c.includes("timed out")||c.includes("timeout")||c.includes("econnrefused")||c.includes("connection refused")||c.includes("fetch failed")||c.includes("socket hang up")))?"IOS_RUNNER_CONNECT_TIMEOUT":"ios"===a&&"boot"===i&&(c.includes("timed out")||c.includes("timeout"))?"IOS_BOOT_TIMEOUT":"android"===a&&"boot"===i&&(c.includes("timed out")||c.includes("timeout"))?"ANDROID_BOOT_TIMEOUT":c.includes("resource temporarily unavailable")||c.includes("killed: 9")||c.includes("cannot allocate memory")||c.includes("system is low on memory")?"CI_RESOURCE_STARVATION_SUSPECTED":"android"===a&&(c.includes("device not found")||c.includes("no devices")||c.includes("device offline")||c.includes("offline")||c.includes("unauthorized")||c.includes("not authorized")||c.includes("unable to locate device")||c.includes("invalid device"))?"ADB_TRANSPORT_UNAVAILABLE":t?.code==="COMMAND_FAILED"||c.length>0?"BOOT_COMMAND_FAILED":"UNKNOWN"}function K(e){switch(e){case"IOS_BOOT_TIMEOUT":return"Retry simulator boot and inspect simctl bootstatus logs; in CI reduce parallel jobs or use a larger runner.";case"IOS_RUNNER_CONNECT_TIMEOUT":return"Retry runner startup, inspect xcodebuild logs, and verify simulator responsiveness before command execution.";case"ANDROID_BOOT_TIMEOUT":return"Retry emulator startup and verify sys.boot_completed reaches 1; consider increasing startup budget in CI.";case"ADB_TRANSPORT_UNAVAILABLE":return"Check adb server/device transport (adb devices -l), restart adb, and ensure the target device is online and authorized.";case"CI_RESOURCE_STARVATION_SUSPECTED":return"CI machine may be resource constrained; reduce parallel jobs or use a larger runner.";case"IOS_TOOL_MISSING":return"Xcode command-line tools are missing or not in PATH; run xcode-select --install and verify xcrun works.";case"BOOT_COMMAND_FAILED":return"Inspect command stderr/stdout for the failing boot phase and retry after environment validation.";default:return"Retry once and inspect verbose logs for the failing phase."}}let H=["android.software.leanback","android.software.leanback_only","android.hardware.type.television"];async function z(e,t,a){let n=Array(e.length),i=0,r=Math.min(t,e.length);return await Promise.all(Array.from({length:r},async()=>{for(;i<e.length;){let t=i;i+=1,n[t]=await a(e[t])}})),n}function q(e){return`${e.stdout}
|
|
2
|
+
${e.stderr}`}function Z(e,t){return["-s",e,...t]}function J(e){return e.startsWith("emulator-")}function X(e){return e.toLowerCase().replace(/_/g," ").replace(/\s+/g," ").trim()}async function Q(e,t=1e4){return o("adb",Z(e,["shell","getprop","sys.boot_completed"]),{allowFailure:!0,timeoutMs:t})}async function Y(e,t){let a=t.replace(/_/g," ").trim();if(!J(e))return a||e;let n=await et(e);return n?n.replace(/_/g," "):a||e}async function ee(e,t,a){try{return await a("adb",Z(e,t),{allowFailure:!0,timeoutMs:1e4})}catch(e){var i;if("COMMAND_FAILED"===(i=n(e)).code&&"number"==typeof i.details?.timeoutMs)return;throw e}}async function et(e,t=o){for(let a of["ro.boot.qemu.avd_name","persist.sys.avd_name"]){let n=await ee(e,["shell","getprop",a],t);if(!n)continue;let i=n.stdout.trim();if(0===n.exitCode&&i.length>0)return i}let a=await ee(e,["emu","avd","name"],t);if(!a)return;let n=function(e){let t=e.split("\n").map(e=>e.trim()).filter(e=>e.length>0);if(0!==t.length)return"OK"===t.at(-1)&&t.pop(),t.join("\n").trim()||void 0}(a.stdout);if(0===a.exitCode&&n)return n}async function ea(e,t){let a=q(await o("adb",Z(e,["shell","cmd","package","has-feature",t]),{allowFailure:!0,timeoutMs:1e4})).toLowerCase();return!!a.includes("true")||!a.includes("false")&&null}async function en(e){return(await z(H,2,async t=>await ea(e,t))).some(e=>!0===e)}async function ei(e){var t;let a;return"tv"===((a=q(await o("adb",Z(e,["shell","getprop","ro.build.characteristics"]),{allowFailure:!0,timeoutMs:1e4})).toLowerCase()).includes("tv")||a.includes("leanback")?"tv":null)||await en(e)?"tv":(t=q(await o("adb",Z(e,["shell","pm","list","features"]),{allowFailure:!0,timeoutMs:1e4})),/feature:android\.(software\.leanback(_only)?|hardware\.type\.television)\b/i.test(t))?"tv":"mobile"}async function er(e={}){if(await u(),!await l("adb"))throw new i("TOOL_MISSING","adb not found in PATH");let t=e.serialAllowlist??W(void 0),a=(await eo()).filter(e=>!t||t.has(e.serial));return await z(a,3,async({serial:e,rawModel:t})=>{let[a,n,i]=await Promise.all([Y(e,t),eu(e),ei(e)]);return{platform:"android",id:e,name:a,kind:J(e)?"emulator":"device",target:i,booted:n}})}async function eo(){return(await o("adb",["devices","-l"],{timeoutMs:1e4})).stdout.split("\n").map(e=>e.trim()).filter(e=>e.length>0&&!e.startsWith("List of devices")).map(e=>e.split(/\s+/)).flatMap(e=>{let t=e[0];return void 0===t||"device"!==e[1]?[]:[{serial:t,rawModel:(e.find(e=>e.startsWith("model:"))??"").replace("model:","")}]})}async function es(){let e=await o("emulator",["-list-avds"],{allowFailure:!0,timeoutMs:1e4});if(0!==e.exitCode)throw new i("COMMAND_FAILED","Failed to list Android emulator AVDs",{stdout:e.stdout,stderr:e.stderr,exitCode:e.exitCode,hint:"Verify Android emulator tooling is installed and available in PATH."});return e.stdout.split("\n").map(e=>e.trim()).filter(e=>e.length>0)}async function el(e){let t=Date.now();for(;Date.now()-t<e.timeoutMs;){try{let t=await ed(e.avdName,e.serial);if(t)return{platform:"android",id:t,name:e.avdName,kind:"emulator",target:"mobile",booted:!1}}catch{}await p(1e3)}throw new i("COMMAND_FAILED","Android emulator did not appear in time",{avdName:e.avdName,serial:e.serial,timeoutMs:e.timeoutMs,hint:"Check emulator logs and verify the AVD can start from command line."})}async function ed(e,t){let a=X(e);for(let e of(await eo()).filter(e=>(!t||e.serial===t)&&J(e.serial)))if(X(e.rawModel)===a||X(await Y(e.serial,e.rawModel))===a)return e.serial}async function eu(e){try{let t=await Q(e);return"1"===t.stdout.trim()}catch{return!1}}async function ec(e){var t,a;let n;await u();let r=e.avdName.trim();if(!r)throw new i("INVALID_ARGS","Android emulator boot requires a non-empty AVD name.");let o=e.timeoutMs??12e4;if(!await l("adb"))throw new i("TOOL_MISSING","adb not found in PATH");if(!await l("emulator"))throw new i("TOOL_MISSING","emulator not found in PATH");let s=await es(),c=function(e,t){let a=e.find(e=>e===t);if(a)return a;let n=X(t);return e.find(e=>X(e)===n)}(s,r);if(!c)throw new i("DEVICE_NOT_FOUND",`No Android emulator AVD named ${e.avdName}`,{requestedAvdName:r,availableAvds:s,hint:"Run `emulator -list-avds` and pass an existing AVD name to --device."});let p=Date.now(),f=(t=await er(),a=e.serial,n=X(c),t.find(e=>"android"===e.platform&&"emulator"===e.kind&&(!a||e.id===a)&&X(e.name)===n));if(!f){let t=["-avd",c];e.headless&&t.push("-no-window","-no-audio"),d("emulator",t)}let m=f??await el({avdName:c,serial:e.serial,timeoutMs:o}),w=Math.max(1e3,o-(Date.now()-p));await ep(m.id,w);let h=(await er()).find(e=>e.id===m.id);return h?{...h,name:c,booted:!0}:{...m,name:c,booted:!0}}async function ep(e,t=6e4){let a,r=x.fromTimeoutMs(t),o=Math.max(1,Math.ceil(t/1e3)),s=!1;try{await R(async({deadline:n})=>{if(n?.isExpired())throw s=!0,new i("COMMAND_FAILED","Android boot deadline exceeded",{serial:e,timeoutMs:t,elapsedMs:r.elapsedMs(),message:"timeout"});let o=Math.max(1e3,n?.remainingMs()??t),l=await Q(e,Math.min(o,1e4));if(a=l,"1"!==l.stdout.trim())throw new i("COMMAND_FAILED","Android device is still booting",{serial:e,stdout:l.stdout,stderr:l.stderr,exitCode:l.exitCode})},{maxAttempts:o,baseDelayMs:1e3,maxDelayMs:1e3,jitter:0,shouldRetry:e=>{let t=j({error:e,stdout:a?.stdout,stderr:a?.stderr,context:{platform:"android",phase:"boot"}});return"ADB_TRANSPORT_UNAVAILABLE"!==t&&"ANDROID_BOOT_TIMEOUT"!==t}},{deadline:r,phase:"boot",classifyReason:e=>j({error:e,stdout:a?.stdout,stderr:a?.stderr,context:{platform:"android",phase:"boot"}})})}catch(f){let o=n(f),l=a?.stdout,d=a?.stderr,u=a?.exitCode,c=j({error:f,stdout:l,stderr:d,context:{platform:"android",phase:"boot"}});"BOOT_COMMAND_FAILED"===c&&"Android device is still booting"===o.message&&(c="ANDROID_BOOT_TIMEOUT");let p={serial:e,timeoutMs:t,elapsedMs:r.elapsedMs(),reason:c,hint:K(c),stdout:l,stderr:d,exitCode:u};if(s||"ANDROID_BOOT_TIMEOUT"===c)throw new i("COMMAND_FAILED","Android device did not finish booting in time",p);if("TOOL_MISSING"===o.code)throw new i("TOOL_MISSING",o.message,{...p,...o.details??{}});if("ADB_TRANSPORT_UNAVAILABLE"===c)throw new i("COMMAND_FAILED",o.message,{...p,...o.details??{}});throw new i(o.code,o.message,{...p,...o.details??{}},o.cause)}}async function ef(e,t,a){return await h(e)(t,a)}function em(e){return{platform:"android",id:e,name:e,kind:e.startsWith("emulator-")?"emulator":"device",booted:!0}}async function ew(){if(await u(),!await l("adb"))throw new i("TOOL_MISSING","adb not found in PATH")}let eh=/\.(?:apk|aab)$/i,eA=/^[A-Za-z_][\w]*(\.[A-Za-z_][\w]*)+$/;function ey(e){var t,a;let n=e.trim();return 0===n.length?"other":eh.test(n)?n.includes("/")||n.includes("\\")||n.startsWith(".")||n.startsWith("~")||(t=n,!eA.test(t))?"binary":"package":(a=n,eA.test(a))?"package":"other"}function eg(e){return`Android runtime hints require an installed package name, not "${e}". Install or reinstall the app first, then relaunch by package.`}async function eb(e,t){let n="url"===e.kind&&y(e.url),i=await A({source:e,isInstallablePath:(e,t)=>{var n;let i;return t.isFile()&&(n=e,".apk"===(i=a.extname(n).toLowerCase())||".aab"===i)},installableLabel:"Android installable (.apk or .aab)",allowArchiveExtraction:"url"!==e.kind||n,signal:t?.signal});try{let e=t?.resolveIdentity===!1?{}:await ev(i.installablePath);return{archivePath:i.archivePath,installablePath:i.installablePath,packageName:e.packageName,cleanup:i.cleanup}}catch(e){throw await i.cleanup(),e}}async function ev(e){let t=a.extname(e).toLowerCase();return".apk"!==t&&".aab"!==t?{}:{packageName:await c(e)}}let eM={settings:{type:"intent",value:"android.settings.SETTINGS"}},e_="android.intent.category.LAUNCHER",eI="android.intent.category.LEANBACK_LAUNCHER",eO="android.intent.category.DEFAULT",eN="Run agent-device apps --platform android to discover the installed package name, then retry open with that exact package.",eC=new Set(["localhost","127.0.0.1","::1","[::1]"]),eD=E();function ek(e){return{platform:"android",deviceId:e.id,variant:e.target??""}}async function eT(e,t){let a=t.trim();if("package"===ey(a))return{type:"package",value:a};let n=eM[a.toLowerCase()];if(n)return n;let r=ek(e),o=eD.get(r,a);if(o)return o;let s=(await ef(e,["shell","pm","list","packages"])).stdout.split("\n").map(e=>e.replace("package:","").trim()).filter(Boolean).filter(e=>e.toLowerCase().includes(a.toLowerCase())),l=s[0];if(void 0!==l&&1===s.length)return eD.set(r,a,{type:"package",value:l});if(s.length>1)throw new i("INVALID_ARGS",`Multiple packages matched "${t}"`,{matches:s,hint:"Run agent-device apps --platform android to see the exact installed package names before retrying open."});throw new i("APP_NOT_INSTALLED",`No package found matching "${t}"`,{hint:eN})}async function eE(e,t){let a=await eS(e);return("user-installed"===t?(await ex(e)).filter(e=>a.has(e)):Array.from(a)).sort((e,t)=>e.localeCompare(t)).map(e=>({package:e,name:eR(e)}))}async function eS(e){let t=new Set;for(let a of eL(e,{includeFallbackWhenUnknown:!0})){let n=await ef(e,["shell","cmd","package","query-activities","--brief","-a","android.intent.action.MAIN","-c",a],{allowFailure:!0});if(0===n.exitCode&&0!==n.stdout.trim().length)for(let e of _(n.stdout))t.add(e)}return t}function eL(e,t={}){return"tv"===e.target?[eI]:"mobile"===e.target?[e_]:t.includeFallbackWhenUnknown?[e_,eI]:[e_]}async function ex(e){return I((await ef(e,["shell","pm","list","packages","-3"])).stdout)}function eR(e){let t=new Set(["com","android","google","app","apps","service","services","mobile","client"]),a=e.split(".").flatMap(e=>e.split(/[_-]+/)).map(e=>e.trim().toLowerCase()).filter(e=>e.length>0),n=a[a.length-1]??e;for(let e=a.length-1;e>=0;e-=1){let i=a[e];if(i&&!t.has(i)){n=i;break}}return n.split(/[^a-z0-9]+/i).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" ")}async function eP(e){let t=await eF(e,[["shell","dumpsys","window","windows"],["shell","dumpsys","window"]]);if(t)return t;let a=await eF(e,[["shell","dumpsys","activity","activities"],["shell","dumpsys","activity"]]);return a||{}}async function eU(e){return await eB(e,[["shell","dumpsys","window","windows"],["shell","dumpsys","window"]])}async function eF(e,t){for(let a of t){let t=O((await ef(e,a,{allowFailure:!0})).stdout??"");if(t)return t}return null}async function eB(e,t){for(let a of t){let t=N((await ef(e,a,{allowFailure:!0})).stdout??"",(e,t)=>(function(e,t){let a=e.split("}")[0]?.trim()??e.trim(),n=b.exec(a);if(n){let e=n[1];return{package:e,focusedWindow:`Application Not Responding: ${e}`,raw:t}}let i=v.exec(a);if(!i)return null;let r=i[1];if(void 0===r)return null;let o=r.trim().replace(/\s+/g," "),s=M.exec(o)?.[1];return{...s?{package:s}:{},focusedWindow:o,raw:t}})(e,t));if(t)return t}return null}async function eV(e,t){let a=function(e){let t;try{t=new URL(e)}catch{return null}let a=t.hostname.toLowerCase();if(!eC.has(a)||!t.port)return null;let n=Number(t.port);return Number.isInteger(n)?`tcp:${n}`:null}(t);if(!a)return;let n=f(m(e));try{await n.ensure({local:a,remote:a})}catch(t){let e={localPort:a.replace("tcp:",""),operation:`adb reverse ${a} ${a}`};throw t instanceof i&&Object.assign(e,{hint:t.details?.hint,diagnosticId:t.details?.diagnosticId,logPath:t.details?.logPath}),new i("COMMAND_FAILED",`Failed to ensure Android port reverse ${a} before opening localhost URL`,e,t)}}async function eW(e,t,a){var n;e.booted||await ep(e.id);let i="string"==typeof(n=a)?{activity:n}:n??{},r=i.activity,o=t.trim();if(D(o))return void await e$(e,o,i);if(void 0!==i.url)return void await eG(e,t,i);let s=await eT(e,t),l=eL(e)[0]??e_;"intent"===s.type?await ej(e,s.value,r):r?await eK(e,s.value,r,l):await eH(e,s.value,l)}async function e$(e,t,a){var n;let r;if(a.activity)throw new i("INVALID_ARGS","Activity override is not supported when opening a deep link URL");await eV(e,t),await ef(e,["shell","am","start","-W","-a","android.intent.action.VIEW","-d",t,...(n=a.appBundleId,(r=n?.trim())?["-p",r]:[])])}async function eG(e,t,a){if(a.activity)throw new i("INVALID_ARGS","Activity override is not supported when opening an app-bound deep link URL");let n=a.url?.trim()??"";if(!D(n))throw new i("INVALID_ARGS","Android app-bound open requires a valid URL target");let r=await eq(e,t,"app-bound open");await ef(e,["shell","am","start","-W","-a","android.intent.action.VIEW","-d",n,"-p",r])}async function ej(e,t,a){if(a)throw new i("INVALID_ARGS","Activity override requires a package name, not an intent");await ef(e,["shell","am","start","-W","-a",t])}async function eK(e,t,a,n){let i=a.includes("/")?a:`${t}/${a.startsWith(".")?a:`.${a}`}`;try{await ef(e,ez(i,n))}catch(a){throw await eX(e,t,a),a}}async function eH(e,t,a){let n=await ef(e,["shell","am","start","-W","-a","android.intent.action.MAIN","-c",eO,"-c",a,"-p",t],{allowFailure:!0});if(0===n.exitCode&&!e0(n.stdout,n.stderr))return;let r=await eY(e,t);if(!r){if(!await eJ(e,t))throw eZ(t);throw new i("COMMAND_FAILED",`Failed to launch ${t}`,{stdout:n.stdout,stderr:n.stderr})}await ef(e,ez(r,a))}function ez(e,t){return["shell","am","start","-W","-a","android.intent.action.MAIN","-c",eO,"-c",t,"-n",e]}async function eq(e,t,a){let n=await eT(e,t);if("intent"===n.type)throw new i("INVALID_ARGS",`Android ${a} requires a package name, not an intent`);return n.value}function eZ(e){return new i("APP_NOT_INSTALLED",`No package found matching "${e}"`,{package:e,hint:eN})}async function eJ(e,t){let a=await ef(e,["shell","pm","path",t],{allowFailure:!0}),n=`${a.stdout}
|
|
3
|
+
${a.stderr}`;return!!(0===a.exitCode&&/\bpackage:/i.test(n))||(eQ(n),!1)}async function eX(e,t,a){if(eQ(a instanceof i?`${String(a.details?.stdout??"")}
|
|
4
|
+
${String(a.details?.stderr??"")}`:"")||!await eJ(e,t))throw eZ(t)}function eQ(e){return/\bunknown package\b/i.test(e)||/\bpackage .* (?:was|is) not found\b/i.test(e)||/\bpackage .* does not exist\b/i.test(e)||/\bcould not find package\b/i.test(e)}async function eY(e,t){for(let a of Array.from(new Set(eL(e,{includeFallbackWhenUnknown:!0})))){let n=await ef(e,["shell","cmd","package","resolve-activity","--brief","-a","android.intent.action.MAIN","-c",a,t],{allowFailure:!0});if(0!==n.exitCode)continue;let i=e1(n.stdout);if(i)return i}return null}function e0(e,t){let a=`${e}
|
|
5
|
+
${t}`;return/Error:.*(?:Activity not started|unable to resolve Intent)/i.test(a)}function e1(e){let t=e.split("\n").map(e=>e.trim()).filter(Boolean);for(let e=t.length-1;e>=0;e-=1){let a=t[e];if(void 0===a||!a.includes("/"))continue;let n=a.split(/\s+/)[0];if(void 0!==n)return n}return null}async function e2(e){e.booted||await ep(e.id)}async function e9(e,t){if("settings"===t.trim().toLowerCase())return void await ef(e,["shell","am","force-stop","com.android.settings"]);let a=await eT(e,t);if("intent"===a.type)throw new i("INVALID_ARGS","Close requires a package name, not an intent");await ef(e,["shell","am","force-stop",a.value])}async function e4(e,t){let a=await eT(e,t);if("intent"===a.type)throw new i("INVALID_ARGS","App uninstall requires a package name, not an intent");let n=await ef(e,["uninstall",a.value],{allowFailure:!0});if(0!==n.exitCode){let e=`${n.stdout}
|
|
6
|
+
${n.stderr}`.toLowerCase();if(!e.includes("unknown package")&&!e.includes("not installed"))throw new i("COMMAND_FAILED",`adb uninstall failed for ${a.value}`,{stdout:n.stdout,stderr:n.stderr,exitCode:n.exitCode})}return{package:a.value}}let e3=null;async function e8(){let e=`${process.env.PATH??""}::${process.env.AGENT_DEVICE_BUNDLETOOL_JAR??""}`;if(e3?.key===e)return e3.invocation;if(await l("bundletool")){let t={cmd:"bundletool",prefixArgs:[]};return e3={key:e,invocation:t},t}let t=await s(process.env.AGENT_DEVICE_BUNDLETOOL_JAR,"AGENT_DEVICE_BUNDLETOOL_JAR");if(!t)throw new i("TOOL_MISSING","bundletool not found in PATH. Install bundletool or set AGENT_DEVICE_BUNDLETOOL_JAR to a bundletool-all.jar path.");let a={cmd:"java",prefixArgs:["-jar",t]};return e3={key:e,invocation:a},a}async function e5(e){let t=await e8();await o(t.cmd,[...t.prefixArgs,...e])}async function e6(n,i){let r=m(n),o="universal";if(r.installBundle)return void await r.installBundle(i,{mode:o});let s=await e.mkdtemp(a.join(t.tmpdir(),"agent-device-aab-")),l=a.join(s,"bundle.apks");try{await e5(["build-apks","--bundle",i,"--output",l,"--mode",o]),await e5(["install-apks","--apks",l,"--device-id",n.id])}finally{await e.rm(s,{recursive:!0,force:!0})}}async function e7(e,t){".aab"===a.extname(t).toLowerCase()?await e6(e,t):await w(t,{device:e,replace:!0})}async function te(e){return new Set((await ef(e,["shell","pm","list","packages"])).stdout.split("\n").map(e=>e.replace("package:","").trim()).filter(Boolean))}async function tt(e,t){let a=Array.from(await te(e)).filter(e=>!t.has(e));if(1===a.length)return a[0]}async function ta(e,t){await eD.invalidateWhile(ek(e),async()=>{e.booted||await ep(e.id),await e7(e,t)})}async function tn(e,t,a){let n=a?void 0:await te(e);return await ta(e,t),a??(n?await tt(e,n):void 0)}async function ti(e,t){e.booted||await ep(e.id);let a=await eb({kind:"path",path:t});try{let t=await tn(e,a.installablePath,a.packageName),n=t?eR(t):void 0;return{archivePath:a.archivePath,installablePath:a.installablePath,packageName:t,appName:n,launchTarget:t}}finally{await a.cleanup()}}async function tr(e,t,a){return await eD.invalidateWhile(ek(e),async()=>{e.booted||await ep(e.id);let{package:n}=await e4(e,t),i=await eb({kind:"path",path:a},{resolveIdentity:!1});try{await ta(e,i.installablePath)}finally{await i.cleanup()}return{package:n}})}async function to(e,t={}){let a=["logcat","-d","-v","time"];void 0!==t.lines&&a.push("-t",String(Math.max(1,Math.floor(t.lines))));let n=await e(a,{allowFailure:!0,timeoutMs:t.timeoutMs,signal:t.signal});if(0!==n.exitCode)throw new i("COMMAND_FAILED","Failed to capture Android logcat",{stdout:n.stdout,stderr:n.stderr,exitCode:n.exitCode});return n.stdout}function ts(e,t={}){if(!e.spawn)throw new i("UNSUPPORTED_OPERATION","Android ADB provider does not support streams",{capability:"adb.spawn"});let a=["logcat","-v","time"];t.pid&&a.push("--pid",t.pid);let n=e.spawn(a,{stdio:["ignore","pipe","pipe"],signal:t.signal});return t.output&&n.stdout&&n.stdout.pipe(t.output,{end:!1}),n}let tl=new Set(["com.google.android.inputmethod.latin","com.samsung.android.honeyboard","com.touchtype.swiftkey","com.microsoft.swiftkey"]);function td(e){let t=tc(e.packageName),a=(e.resourceId??"").toLowerCase(),n=tc(e.activeInputMethodPackage);if(t&&n&&t===n)return{inputMethodOwned:!0,source:"active-input-method"};if(n&&a.startsWith(`${n}:id/`))return{inputMethodOwned:!0,source:"active-input-method-resource"};if(t&&tl.has(t))return{inputMethodOwned:!0,source:"known-ime-package"};for(let e of tl)if(a.startsWith(`${e}:id/`))return{inputMethodOwned:!0,source:"known-ime-resource"};return{inputMethodOwned:!1,source:"app"}}function tu(e){return td(e).inputMethodOwned}function tc(e){return(e??"").trim().toLowerCase()||void 0}let tp=["mInputShown","mIsInputViewShown","isInputViewShown","mDecorViewVisible","mWindowVisible","mInShowWindow"],tf=new Map([[2,"number"],[3,"phone"],[4,"datetime"]]),tm=new Set([32,208]),tw=new Set([128,224,144]);async function th(e){return await tA(h(e))}async function tA(e){var t,a,n;let o,s,l,d,u,c,p,f,m=await e(["shell","dumpsys","input_method"],{allowFailure:!0});if(0!==m.exitCode)throw new i("COMMAND_FAILED","Failed to query Android keyboard state",{stdout:m.stdout,stderr:m.stderr,exitCode:m.exitCode});return s=function(e){var t=function(e,t){let a=new Map,n=RegExp(`\\b(${t.join("|")})=([a-zA-Z]+)\\b`,"g");for(let t of e.matchAll(n)){let e=t[1],n=t[2]?.toLowerCase();e&&("true"===n||"false"===n)&&a.set(e,"true"===n)}return a}(e,tp);if(0===t.size)return null;let a=tv(t,["mWindowVisible","mDecorViewVisible","mInShowWindow"]);if(void 0!==a)return a;let n=t.get("mInputShown");return void 0!==n?n:tv(t,["mIsInputViewShown","isInputViewShown"])??null}(t=m.stdout)??function(e){let t=e.match(/\bmImeWindowVis=0x([0-9a-fA-F]+)\b/),a=t?.[1];if(!a)return null;let n=Number.parseInt(a,16);return Number.isNaN(n)?null:(1&n)!=0}(t),l=(o=tb(t,/\binputType=0x([0-9a-fA-F]+)\b/gi))?`0x${o.toLowerCase()}`:void 0,d=tb(t,/\bpackageName=([A-Za-z0-9_.]+)\b/g),u=tb(t,/\b(?:resourceId|resource-id)=([^\s,}]+)/g),p=function(e,t,a){return e||t?td({packageName:e,resourceId:t,activeInputMethodPackage:a}).inputMethodOwned?"ime":"app":"unknown"}(d,u,c=function(e){for(let t of[/\bmCurMethodId=([^\s]+)/i,/\bmCurId=([^\s]+)/i,/\bmCurrentInputMethodId=([^\s]+)/i,/\bcurMethodId=([^\s]+)/i]){let a=e.match(t),n=function(e){let t=(e??"").trim();if(!t)return;let a=(t.split("/")[0]??"").match(/[a-zA-Z0-9_.]+/);return tc(a?.[0])}(a?.[1]);if(n)return n}}(t)),a=d,n=u,!c&&((f=tc(a))&&tl.has(f)||function(e){let t=(e??"").toLowerCase();for(let e of tl)if(t.startsWith(`${e}:id/`))return!0;return!1}(n))&&r({level:"warn",phase:"android_input_ownership_fallback",data:{focusedPackage:a,focusedResourceId:n}}),{visible:s??!1,inputType:l,type:l?function(e){let t=Number.parseInt(e.replace(/^0x/i,""),16);if(Number.isNaN(t))return"unknown";let a=15&t,n=tf.get(a);if(n)return n;if(1!==a)return"unknown";let i=4080&t;return tm.has(i)?"email":tw.has(i)?"password":"text"}(l):void 0,inputMethodPackage:c,focusedPackage:d,focusedResourceId:u,inputOwner:p}}async function ty(e){return await tg(h(e))}async function tg(e){let t=await tA(e),a=t,n=0;for(;a.visible&&n<2;)await e(["shell","input","keyevent","111"]),n+=1,await p(120),a=await tA(e);if(t.visible&&a.visible)throw new i("UNSUPPORTED_OPERATION","Android keyboard dismiss is unavailable for the current IME without back navigation.",{attempts:n,inputType:a.inputType,type:a.type,inputMethodPackage:a.inputMethodPackage,focusedPackage:a.focusedPackage,focusedResourceId:a.focusedResourceId,inputOwner:a.inputOwner});return{attempts:n,wasVisible:t.visible,dismissed:t.visible&&!a.visible,visible:a.visible,inputType:a.inputType,type:a.type,inputMethodPackage:a.inputMethodPackage,focusedPackage:a.focusedPackage,focusedResourceId:a.focusedResourceId,inputOwner:a.inputOwner}}function tb(e,t){let a;for(let n of e.matchAll(t))a=n[1];return a}function tv(e,t){for(let a of t){let t=e.get(a);if(void 0!==t)return t}}async function tM(e){return await t_(h(e))}async function t_(e){let t,a;return(a=(t=(await tN(e,["shell","cmd","clipboard","get","text"],"read")).replace(/\r\n/g,"\n").replace(/\n$/,"")).match(/^clipboard text:\s*(.*)$/i))?a[1]??"":"null"===t.trim().toLowerCase()?"":t}async function tI(e,t){await tO(h(e),t)}async function tO(e,t){await tN(e,["shell","cmd","clipboard","set","text",t],"write")}async function tN(e,t,a){var n,r;let o,s=await e(t,{allowFailure:!0});if(n=s.stdout,r=s.stderr,(o=`${n}
|
|
7
|
+
${r}`.toLowerCase()).includes("no shell command implementation")||o.includes("unknown command"))throw new i("UNSUPPORTED_OPERATION",`Android shell clipboard ${a} is not supported on this device.`);if(0!==s.exitCode)throw new i("COMMAND_FAILED",`Failed to ${a} Android clipboard text`,{stdout:s.stdout,stderr:s.stderr,exitCode:s.exitCode});return s.stdout}export{x as Deadline,em as androidDeviceForSerial,K as bootFailureHint,to as captureAndroidLogcatWithAdb,ey as classifyAndroidAppTarget,j as classifyBootFailure,e9 as closeAndroidApp,E as createAppResolutionCache,ty as dismissAndroidKeyboard,tg as dismissAndroidKeyboardWithAdb,ew as ensureAdb,ec as ensureAndroidEmulatorBooted,eg as formatAndroidInstalledPackageRequiredMessage,eP as getAndroidAppState,eU as getAndroidBlockingDialogFocus,th as getAndroidKeyboardState,tA as getAndroidKeyboardStatusWithAdb,eR as inferAndroidAppName,ti as installAndroidApp,tn as installAndroidInstallablePathAndResolvePackageName,e0 as isAmStartError,tu as isAndroidInputMethodOwnedNode,D as isDeepLinkTarget,L as isEnvTruthy,G as isInfrastructureBootFailureReason,k as isWebUrl,eE as listAndroidApps,er as listAndroidDevices,eW as openAndroidApp,e2 as openAndroidDevice,O as parseAndroidForegroundApp,e1 as parseAndroidLaunchComponent,_ as parseAndroidLaunchablePackages,I as parseAndroidUserInstalledPackages,V as parseSerialAllowlist,eb as prepareAndroidInstallArtifact,tM as readAndroidClipboardText,t_ as readAndroidClipboardWithAdb,tr as reinstallAndroidApp,eT as resolveAndroidApp,W as resolveAndroidSerialAllowlist,T as resolveIosDeviceDeepLinkBundleId,B as resolveIosSimulatorDeviceSetPath,R as retryWithPolicy,ef as runAndroidAdb,ts as streamAndroidLogcatWithAdb,ep as waitForAndroidBoot,P as withRetry,tI as writeAndroidClipboardText,tO as writeAndroidClipboardWithAdb};
|
package/dist/src/221.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import e from"node:crypto";import t from"node:fs";import n from"node:fs/promises";import r from"node:os";import i from"node:path";import{AppError as a}from"./9152.js";import{isScrollableType as o}from"./2842.js";import{installAndroidAdbPackage as s}from"./9639.js";let u="android-snapshot-helper",l="com.callstack.agentdevice.snapshothelper",d="com.callstack.agentdevice.snapshothelper/.SnapshotInstrumentation",c="android-snapshot-helper-v1",h="uiautomator-xml",f={"-r":"replace","-t":"allowTestPackages","-d":"allowDowngrade","-g":"grantPermissions"};async function p(e){let t=await M(e.apkPath);if(t!==e.manifest.sha256)throw new a("COMMAND_FAILED","Android snapshot helper APK checksum mismatch",{apkPath:e.apkPath,expectedSha256:e.manifest.sha256,actualSha256:t})}async function m(e){let t=e.fetch??fetch,o=await t(e.manifestUrl);if(!o.ok)throw new a("COMMAND_FAILED","Failed to download Android snapshot helper manifest",{manifestUrl:e.manifestUrl,status:o.status,statusText:o.statusText});let s=w(JSON.parse((await A(o,65536,"Android snapshot helper manifest")).toString("utf8")));if(!s.apkUrl)throw new a("COMMAND_FAILED","Android snapshot helper manifest does not include apkUrl",{manifestUrl:e.manifestUrl});let u=e.cacheDir??i.join(r.tmpdir(),`agent-device-android-snapshot-helper-${s.version}`),l=!e.cacheDir;await n.mkdir(u,{recursive:!0});let d=s.assetName??`agent-device-android-snapshot-helper-${s.version}.apk`,c=i.join(u,d),h=await t(s.apkUrl);if(!h.ok)throw new a("COMMAND_FAILED","Failed to download Android snapshot helper APK",{apkUrl:s.apkUrl,status:h.status,statusText:h.statusText});await n.writeFile(c,await A(h,0x1400000,"Android snapshot helper APK"));let f={apkPath:c,manifest:s};return await p(f),{...f,cleanup:async()=>{await n.rm(l?u:c,{recursive:l,force:!0})}}}function w(e){var t,n;if(!e||"object"!=typeof e||Array.isArray(e))throw new a("INVALID_ARGS","Android snapshot helper manifest must be an object.");return{name:v(e.name,"name",u),version:N(e.version,"version"),releaseTag:I(e.releaseTag),assetName:I(e.assetName),apkUrl:(t=e.apkUrl,n="apkUrl",null===t?null:N(t,n)),sha256:function(e){let t=N(e,"sha256").trim().toLowerCase();if(64!==t.length||!function(e){for(let t of e){let e=t.charCodeAt(0),n=e>=48&&e<=57,r=e>=97&&e<=102;if(!n&&!r)return!1}return!0}(t))throw new a("INVALID_ARGS","Android snapshot helper manifest sha256 must be a 64-character hex string.");return t}(e.sha256),checksumName:I(e.checksumName),packageName:N(e.packageName,"packageName"),versionCode:x(e.versionCode,"versionCode"),instrumentationRunner:N(e.instrumentationRunner,"instrumentationRunner"),minSdk:x(e.minSdk,"minSdk"),targetSdk:void 0===e.targetSdk?void 0:x(e.targetSdk,"targetSdk"),outputFormat:v(e.outputFormat,"outputFormat",h),statusProtocol:v(e.statusProtocol,"statusProtocol",c),installArgs:g(e.installArgs)}}async function A(e,t,n){let r=e.headers.get("content-length");if(null!==r){let e=Number(r);if(Number.isFinite(e)&&e>t)throw new a("COMMAND_FAILED",`${n} download exceeds size limit`,{contentLength:e,maxBytes:t})}if(!e.body){let r=Buffer.from(await e.arrayBuffer());if(r.length>t)throw new a("COMMAND_FAILED",`${n} download exceeds size limit`,{contentLength:r.length,maxBytes:t});return r}let i=e.body.getReader(),o=[],s=0;try{for(;;){let{done:e,value:r}=await i.read();if(e)break;if((s+=r.byteLength)>t)throw new a("COMMAND_FAILED",`${n} download exceeds size limit`,{contentLength:s,maxBytes:t});o.push(Buffer.from(r))}}finally{i.releaseLock()}return Buffer.concat(o,s)}function g(e){let t=function(e,t){if(!Array.isArray(e)||!e.every(e=>"string"==typeof e))throw new a("INVALID_ARGS",`Android snapshot helper manifest ${t} must be a string array.`);return e}(e,"installArgs");if("install"!==t[0])throw new a("INVALID_ARGS",'Android snapshot helper manifest installArgs must start with "install".');if(t.some(e=>e.includes("\0")))throw new a("INVALID_ARGS","Android snapshot helper manifest installArgs must not contain null bytes.");let n=t.slice(1).find(e=>void 0===D(e));if(n)throw new a("INVALID_ARGS",`Android snapshot helper manifest installArgs contains unsupported install flag "${n}".`);return t}async function M(n){return await new Promise((r,i)=>{let a=e.createHash("sha256"),o=t.createReadStream(n);o.on("error",i),o.on("data",e=>a.update(e)),o.on("end",()=>r(a.digest("hex")))})}function N(e,t){if("string"!=typeof e||0===e.trim().length)throw new a("INVALID_ARGS",`Android snapshot helper manifest ${t} is required.`);return e}function I(e){return"string"==typeof e&&e.trim().length>0?e:void 0}function x(e,t){if("number"!=typeof e||!Number.isInteger(e))throw new a("INVALID_ARGS",`Android snapshot helper manifest ${t} must be an integer.`);return e}function v(e,t,n){if(e!==n)throw new a("INVALID_ARGS",`Android snapshot helper manifest ${t} must be "${n}".`);return n}function D(e){if(Object.hasOwn(f,e))return f[e]}function*b(e){let t=/<node\b[^>]*>/g,n=t.exec(e);for(;n;)yield C(n[0]),n=t.exec(e)}function C(e){let t,n,r=(t=function(e){let t=new Map,n=e.indexOf(" "),r=e.lastIndexOf(">");if(n<0||r<=n)return t;let i=n;for(;i<r&&!((i=_(e,i,r))>=r);){var a;let n=e[i];if("/"===n||">"===n)break;let o=i;for(;i<r&&!("="===(a=e[i]??"")||"/"===a||">"===a||y(a));)i+=1;let s=e.slice(o,i);if(i=_(e,i,r),!s||"="!==e[i])break;i=_(e,i+1,r);let u=e[i];if('"'!==u&&"'"!==u)break;let l=i+=1;for(;i<r&&e[i]!==u;)i+=1;if(i>=r)break;t.set(s,function(e){let t="",n=0;for(;n<e.length;){let r=e.indexOf("&",n);if(r<0){t+=e.slice(n);break}t+=e.slice(n,r);let i=e.indexOf(";",r+1);if(i<0){t+=e.slice(r);break}t+=function(e){switch(e){case"amp":return"&";case"lt":return"<";case"gt":return">";case"quot":return'"';case"apos":return"'";default:return function(e){if(!e.startsWith("#"))return;let t=e[1]?.toLowerCase()==="x"?16:10,n=16===t?e.slice(2):e.slice(1);if(!n||!function(e,t){for(let n of e){let e=n.charCodeAt(0),r=e>=48&&e<=57;if(10===t){if(!r)return!1;continue}let i=e>=65&&e<=70,a=e>=97&&e<=102;if(!r&&!i&&!a)return!1}return!0}(n,t))return;let r=Number.parseInt(n,t);if(Number.isFinite(r))try{return String.fromCodePoint(r)}catch{return}}(e)}}(e.slice(r+1,i))??e.slice(r,i+1),n=i+1}return t}(e.slice(l,i))),i+=1}return t}(e),n=e=>{let n=L(t,e);if(null!==n)return"true"===n},{text:L(t,"text"),desc:L(t,"content-desc"),resourceId:L(t,"resource-id"),packageName:L(t,"package"),className:L(t,"class"),bounds:L(t,"bounds"),clickable:n("clickable"),enabled:n("enabled"),focusable:n("focusable"),focused:n("focused"),password:n("password")}),i=function(e){if(!e)return;let t=/\[(\d+),(\d+)\]\[(\d+),(\d+)\]/.exec(e);if(!t)return;let n=Number(t[1]),r=Number(t[2]);return{x:n,y:r,width:Math.max(0,Number(t[3])-n),height:Math.max(0,Number(t[4])-r)}}(r.bounds);return{...r,...i?{rect:i}:{}}}function S(e,t,n){let{sourceNodes:r,...i}=k(F(e),t,n);return i}function k(e,t,n){let r={nodes:[],sourceNodes:[],maxNodes:t,maxDepth:n.depth??1/0,options:n,analysis:function(e){let t=0,n=0,r=[...e.children];for(;r.length>0;){let e=r.pop();t+=1,n=Math.max(n,e.depth),r.push(...e.children)}return{rawNodeCount:t,maxDepth:n}}(e),interactiveDescendantMemo:new Map,truncated:!1},i=n.scope?function(e,t){let n=t.toLowerCase(),r=[...e.children],i=0;for(;i<r.length;){let e=r[i++],t=e.label?.toLowerCase()??"",a=e.value?.toLowerCase()??"",o=e.identifier?.toLowerCase()??"";if(t.includes(n)||a.includes(n)||o.includes(n))return e;r.push(...e.children)}return null}(e,n.scope):null;for(let t of i?[i]:e.children)if(function e(t,n,r,i,a=!1,s=!1){if(t.nodes.length>=t.maxNodes){t.truncated=!0;return}if(r>t.maxDepth)return;let u=t.options.raw||function(e,t,n,r,i){var a,s,u;let l=function(e){let t=T(e.type),n=!!(e.label&&e.label.trim().length>0),r=!!(e.identifier&&e.identifier.trim().length>0);return{type:t,hasMeaningfulText:n&&!O(e.label??""),hasMeaningfulId:r&&!O(e.identifier??""),isStructural:function(e){let t=e.split(".").pop()??e;return t.includes("layout")||"viewgroup"===t||"view"===t}(t),isVisual:"imageview"===t||"imagebutton"===t}}(e);return t.interactiveOnly?function(e,t,n,r,i){var a,s,u,l;return!!(e.hittable||o(t.type)&&r)||(a=t,s=n,u=r,l=i,(!!a.hasMeaningfulText||!!a.hasMeaningfulId)&&!a.isVisual&&(!a.isStructural||!!l)&&(s||u||l))}(e,l,n,r,i):t.compact?l.hasMeaningfulText||l.hasMeaningfulId||!!e.hittable:!l.isStructural&&!l.isVisual||(a=e,s=l,u=r,!!a.hittable||!!s.hasMeaningfulText||!!s.hasMeaningfulId&&!!u||u)}(n,t.options,a,function e(t,n){let r=t.interactiveDescendantMemo.get(n);if(void 0!==r)return r;for(let r of n.children)if(r.hittable||e(t,r))return t.interactiveDescendantMemo.set(n,!0),!0;return t.interactiveDescendantMemo.set(n,!1),!1}(t,n),s)?function(e,t,n,r){let i=e.nodes.length;return e.sourceNodes.push(t),e.nodes.push({index:i,type:t.type??void 0,label:t.label??void 0,value:t.value??void 0,identifier:t.identifier??void 0,bundleId:t.packageName??void 0,rect:t.rect,enabled:t.enabled,hittable:t.hittable,depth:n,parentIndex:r,...t.hiddenContentAbove?{hiddenContentAbove:!0}:{},...t.hiddenContentBelow?{hiddenContentBelow:!0}:{}}),i}(t,n,r,i):i,l=a||!!n.hittable,d=s||function(e){if(!e)return!1;let t=T(e);return t.includes("recyclerview")||t.includes("listview")||t.includes("gridview")}(n.type);for(let i of n.children)if(e(t,i,r+1,u,l,d),t.truncated)return}(r,t,0),r.truncated)break;let a={nodes:r.nodes,sourceNodes:r.sourceNodes,analysis:r.analysis};return r.truncated?{...a,truncated:!0}:a}function _(e,t,n){for(;t<n&&y(e[t]??"");)t+=1;return t}function y(e){return" "===e||"\n"===e||"\r"===e||" "===e}function L(e,t){return e.get(t)??null}function F(e){let t={type:null,label:null,value:null,identifier:null,packageName:null,depth:-1,children:[]},n=[t],r=/<node\b[^>]*>|<\/node>/g,i=r.exec(e);for(;i;){let t=i[0];if(t.startsWith("</node")){n.length>1&&n.pop(),i=r.exec(e);continue}let a=C(t),o=n[n.length-1],s={type:a.className,label:a.text||a.desc,value:a.text,identifier:a.resourceId,packageName:a.packageName,rect:a.rect,enabled:a.enabled,hittable:a.clickable??a.focusable,depth:o.depth+1,parentIndex:void 0,children:[]};o.children.push(s),t.endsWith("/>")||n.push(s),i=r.exec(e)}return t}function T(e){return e?e.toLowerCase():""}function O(e){let t=e.trim();return!!t&&/^[\w.]+:id\/[\w.-]+$/i.test(t)}async function P(e){var t,n;let r,i,o=(r=E((t=e).timeoutMs,8e3),i=E(t.packageName,l),{waitForIdleTimeoutMs:E(t.waitForIdleTimeoutMs,500),waitForIdleQuietMs:E(t.waitForIdleQuietMs,100),timeoutMs:r,commandTimeoutMs:E(t.commandTimeoutMs,r+5e3),maxDepth:E(t.maxDepth,128),maxNodes:E(t.maxNodes,5e3),packageName:i,runner:E(t.instrumentationRunner,`${i}/.SnapshotInstrumentation`),...t.outputPath?{outputPath:t.outputPath}:{}}),s=await e.adb(["shell","am","instrument","-w","-e","waitForIdleTimeoutMs",String((n=o).waitForIdleTimeoutMs),"-e","waitForIdleQuietMs",String(n.waitForIdleQuietMs),"-e","timeoutMs",String(n.timeoutMs),"-e","maxDepth",String(n.maxDepth),"-e","maxNodes",String(n.maxNodes),...n.outputPath?["-e","outputPath",n.outputPath]:[],n.runner],{allowFailure:!0,timeoutMs:o.commandTimeoutMs}),u=await R(e,o,s);if(o.outputPath&&await H(e.adb,o.outputPath),0!==s.exitCode)throw new a("COMMAND_FAILED","Android snapshot helper failed",{stdout:s.stdout,stderr:s.stderr,exitCode:s.exitCode,helper:u.metadata});return u}function E(e,t){return void 0===e?t:e}async function R(e,t,n){try{return V(`${n.stdout}
|
|
2
|
-
${
|
|
3
|
-
${r.stderr}
|
|
4
|
-
|
|
1
|
+
import e from"node:crypto";import t from"node:fs";import r from"node:fs/promises";import n from"node:os";import o from"node:path";import i from"node:net";import{AppError as a}from"./9152.js";import{isScrollableType as s}from"./2842.js";import{emitDiagnostic as u}from"./7599.js";import{installAndroidAdbPackage as l}from"./9639.js";let d="android-snapshot-helper",c="com.callstack.agentdevice.snapshothelper",h="com.callstack.agentdevice.snapshothelper/.SnapshotInstrumentation",p="android-snapshot-helper-v1",f="uiautomator-xml",m={"-r":"replace","-t":"allowTestPackages","-d":"allowDowngrade","-g":"grantPermissions"};async function w(e){let t=await v(e.apkPath);if(t!==e.manifest.sha256)throw new a("COMMAND_FAILED","Android snapshot helper APK checksum mismatch",{apkPath:e.apkPath,expectedSha256:e.manifest.sha256,actualSha256:t})}async function A(e){let t=e.fetch??fetch,i=await t(e.manifestUrl);if(!i.ok)throw new a("COMMAND_FAILED","Failed to download Android snapshot helper manifest",{manifestUrl:e.manifestUrl,status:i.status,statusText:i.statusText});let s=M(JSON.parse((await g(i,65536,"Android snapshot helper manifest")).toString("utf8")));if(!s.apkUrl)throw new a("COMMAND_FAILED","Android snapshot helper manifest does not include apkUrl",{manifestUrl:e.manifestUrl});let u=e.cacheDir??o.join(n.tmpdir(),`agent-device-android-snapshot-helper-${s.version}`),l=!e.cacheDir;await r.mkdir(u,{recursive:!0});let d=s.assetName??`agent-device-android-snapshot-helper-${s.version}.apk`,c=o.join(u,d),h=await t(s.apkUrl);if(!h.ok)throw new a("COMMAND_FAILED","Failed to download Android snapshot helper APK",{apkUrl:s.apkUrl,status:h.status,statusText:h.statusText});await r.writeFile(c,await g(h,0x1400000,"Android snapshot helper APK"));let p={apkPath:c,manifest:s};return await w(p),{...p,cleanup:async()=>{await r.rm(l?u:c,{recursive:l,force:!0})}}}function M(e){var t,r;if(!e||"object"!=typeof e||Array.isArray(e))throw new a("INVALID_ARGS","Android snapshot helper manifest must be an object.");return{name:C(e.name,"name",d),version:I(e.version,"version"),releaseTag:D(e.releaseTag),assetName:D(e.assetName),apkUrl:(t=e.apkUrl,r="apkUrl",null===t?null:I(t,r)),sha256:function(e){let t=I(e,"sha256").trim().toLowerCase();if(64!==t.length||!function(e){for(let t of e){let e=t.charCodeAt(0),r=e>=48&&e<=57,n=e>=97&&e<=102;if(!r&&!n)return!1}return!0}(t))throw new a("INVALID_ARGS","Android snapshot helper manifest sha256 must be a 64-character hex string.");return t}(e.sha256),checksumName:D(e.checksumName),packageName:I(e.packageName,"packageName"),versionCode:x(e.versionCode,"versionCode"),instrumentationRunner:I(e.instrumentationRunner,"instrumentationRunner"),minSdk:x(e.minSdk,"minSdk"),targetSdk:void 0===e.targetSdk?void 0:x(e.targetSdk,"targetSdk"),outputFormat:C(e.outputFormat,"outputFormat",f),statusProtocol:C(e.statusProtocol,"statusProtocol",p),installArgs:N(e.installArgs)}}async function g(e,t,r){let n=e.headers.get("content-length");if(null!==n){let e=Number(n);if(Number.isFinite(e)&&e>t)throw new a("COMMAND_FAILED",`${r} download exceeds size limit`,{contentLength:e,maxBytes:t})}if(!e.body){let n=Buffer.from(await e.arrayBuffer());if(n.length>t)throw new a("COMMAND_FAILED",`${r} download exceeds size limit`,{contentLength:n.length,maxBytes:t});return n}let o=e.body.getReader(),i=[],s=0;try{for(;;){let{done:e,value:n}=await o.read();if(e)break;if((s+=n.byteLength)>t)throw new a("COMMAND_FAILED",`${r} download exceeds size limit`,{contentLength:s,maxBytes:t});i.push(Buffer.from(n))}}finally{o.releaseLock()}return Buffer.concat(i,s)}function N(e){let t=function(e,t){if(!Array.isArray(e)||!e.every(e=>"string"==typeof e))throw new a("INVALID_ARGS",`Android snapshot helper manifest ${t} must be a string array.`);return e}(e,"installArgs");if("install"!==t[0])throw new a("INVALID_ARGS",'Android snapshot helper manifest installArgs must start with "install".');if(t.some(e=>e.includes("\0")))throw new a("INVALID_ARGS","Android snapshot helper manifest installArgs must not contain null bytes.");let r=t.slice(1).find(e=>void 0===y(e));if(r)throw new a("INVALID_ARGS",`Android snapshot helper manifest installArgs contains unsupported install flag "${r}".`);return t}async function v(r){return await new Promise((n,o)=>{let i=e.createHash("sha256"),a=t.createReadStream(r);a.on("error",o),a.on("data",e=>i.update(e)),a.on("end",()=>n(i.digest("hex")))})}function I(e,t){if("string"!=typeof e||0===e.trim().length)throw new a("INVALID_ARGS",`Android snapshot helper manifest ${t} is required.`);return e}function D(e){return"string"==typeof e&&e.trim().length>0?e:void 0}function x(e,t){if("number"!=typeof e||!Number.isInteger(e))throw new a("INVALID_ARGS",`Android snapshot helper manifest ${t} must be an integer.`);return e}function C(e,t,r){if(e!==r)throw new a("INVALID_ARGS",`Android snapshot helper manifest ${t} must be "${r}".`);return r}function y(e){if(Object.hasOwn(m,e))return m[e]}function*S(e){let t=/<node\b[^>]*>/g,r=t.exec(e);for(;r;)yield _(r[0]),r=t.exec(e)}function _(e){let t,r,n,o=(t=function(e){let t=new Map,r=e.indexOf(" "),n=e.lastIndexOf(">");if(r<0||n<=r)return t;let o=r;for(;o<n&&!((o=F(e,o,n))>=n);){var i;let r=e[o];if("/"===r||">"===r)break;let a=o;for(;o<n&&!("="===(i=e[o]??"")||"/"===i||">"===i||L(i));)o+=1;let s=e.slice(a,o);if(o=F(e,o,n),!s||"="!==e[o])break;o=F(e,o+1,n);let u=e[o];if('"'!==u&&"'"!==u)break;let l=o+=1;for(;o<n&&e[o]!==u;)o+=1;if(o>=n)break;t.set(s,function(e){let t="",r=0;for(;r<e.length;){let n=e.indexOf("&",r);if(n<0){t+=e.slice(r);break}t+=e.slice(r,n);let o=e.indexOf(";",n+1);if(o<0){t+=e.slice(n);break}t+=function(e){switch(e){case"amp":return"&";case"lt":return"<";case"gt":return">";case"quot":return'"';case"apos":return"'";default:return function(e){if(!e.startsWith("#"))return;let t=e[1]?.toLowerCase()==="x"?16:10,r=16===t?e.slice(2):e.slice(1);if(!r||!function(e,t){for(let r of e){let e=r.charCodeAt(0),n=e>=48&&e<=57;if(10===t){if(!n)return!1;continue}let o=e>=65&&e<=70,i=e>=97&&e<=102;if(!n&&!o&&!i)return!1}return!0}(r,t))return;let n=Number.parseInt(r,t);if(Number.isFinite(n))try{return String.fromCodePoint(n)}catch{return}}(e)}}(e.slice(n+1,o))??e.slice(n,o+1),r=o+1}return t}(e.slice(l,o))),o+=1}return t}(e),r=e=>{let r=T(t,e);if(null!==r)return"true"===r},n=(e,t)=>{let n=r(t);return void 0===n?{}:{[e]:n}},{text:T(t,"text"),desc:T(t,"content-desc"),resourceId:T(t,"resource-id"),packageName:T(t,"package"),className:T(t,"class"),bounds:T(t,"bounds"),clickable:r("clickable"),enabled:r("enabled"),focusable:r("focusable"),focused:r("focused"),password:r("password"),...n("scrollable","scrollable"),...n("canScrollForward","can-scroll-forward"),...n("canScrollBackward","can-scroll-backward")}),i=function(e){if(!e)return;let t=/\[(\d+),(\d+)\]\[(\d+),(\d+)\]/.exec(e);if(!t)return;let r=Number(t[1]),n=Number(t[2]);return{x:r,y:n,width:Math.max(0,Number(t[3])-r),height:Math.max(0,Number(t[4])-n)}}(o.bounds);return{...o,...i?{rect:i}:{}}}function b(e,t,r){let{sourceNodes:n,...o}=k(E(e),t,r);return o}function k(e,t,r){let n={nodes:[],sourceNodes:[],maxNodes:t,maxDepth:r.depth??1/0,options:r,analysis:function(e){let t=0,r=0,n=[...e.children];for(;n.length>0;){let e=n.pop();t+=1,r=Math.max(r,e.depth),n.push(...e.children)}return{rawNodeCount:t,maxDepth:r}}(e),interactiveDescendantMemo:new Map,truncated:!1},o=r.scope?function(e,t){let r=t.toLowerCase(),n=[...e.children],o=0;for(;o<n.length;){let e=n[o++],t=e.label?.toLowerCase()??"",i=e.value?.toLowerCase()??"",a=e.identifier?.toLowerCase()??"";if(t.includes(r)||i.includes(r)||a.includes(r))return e;n.push(...e.children)}return null}(e,r.scope):null;for(let t of o?[o]:e.children)if(function e(t,r,n,o,i=!1,a=!1){if(t.nodes.length>=t.maxNodes){t.truncated=!0;return}if(n>t.maxDepth)return;let u=t.options.raw||function(e,t,r,n,o){var i,a,u;let l=function(e){let t=O(e.type),r=!!(e.label&&e.label.trim().length>0),n=!!(e.identifier&&e.identifier.trim().length>0);return{type:t,hasMeaningfulText:r&&!P(e.label??""),hasMeaningfulId:n&&!P(e.identifier??""),isStructural:function(e){let t=e.split(".").pop()??e;return t.includes("layout")||"viewgroup"===t||"view"===t}(t),isVisual:"imageview"===t||"imagebutton"===t}}(e);return t.interactiveOnly?function(e,t,r,n,o){var i,a,u,l,d;return!((i=e).rect&&(i.rect.width<=0||i.rect.height<=0))&&(!!(e.hittable||s(t.type)&&n)||(a=t,u=r,l=n,d=o,(!!a.hasMeaningfulText||!!a.hasMeaningfulId)&&!a.isVisual&&(!a.isStructural||!!d)&&(u||l||d)))}(e,l,r,n,o):t.compact?l.hasMeaningfulText||l.hasMeaningfulId||!!e.hittable:!l.isStructural&&!l.isVisual||(i=e,a=l,u=n,!!i.hittable||!!a.hasMeaningfulText||!!a.hasMeaningfulId&&!!u||u)}(r,t.options,i,function e(t,r){let n=t.interactiveDescendantMemo.get(r);if(void 0!==n)return n;for(let n of r.children)if(n.hittable||e(t,n))return t.interactiveDescendantMemo.set(r,!0),!0;return t.interactiveDescendantMemo.set(r,!1),!1}(t,r),a)?function(e,t,r,n){let o=e.nodes.length;return e.sourceNodes.push(t),e.nodes.push({index:o,type:t.type??void 0,label:t.label??void 0,value:t.value??void 0,identifier:t.identifier??void 0,bundleId:t.packageName??void 0,rect:t.rect,enabled:t.enabled,hittable:t.hittable,depth:r,parentIndex:n,...t.hiddenContentAbove?{hiddenContentAbove:!0}:{},...t.hiddenContentBelow?{hiddenContentBelow:!0}:{}}),o}(t,r,n,o):o,l=i||!!r.hittable,d=a||function(e){if(!e)return!1;let t=O(e);return t.includes("recyclerview")||t.includes("listview")||t.includes("gridview")}(r.type);for(let o of r.children)if(e(t,o,n+1,u,l,d),t.truncated)return}(n,t,0),n.truncated)break;let i={nodes:n.nodes,sourceNodes:n.sourceNodes,analysis:n.analysis};return n.truncated?{...i,truncated:!0}:i}function F(e,t,r){for(;t<r&&L(e[t]??"");)t+=1;return t}function L(e){return" "===e||"\n"===e||"\r"===e||" "===e}function T(e,t){return e.get(t)??null}function E(e){let t={type:null,label:null,value:null,identifier:null,packageName:null,depth:-1,children:[]},r=[t],n=/<node\b[^>]*>|<\/node>/g,o=n.exec(e);for(;o;){let t=o[0];if(t.startsWith("</node")){r.length>1&&r.pop(),o=n.exec(e);continue}let i=_(t),a=r[r.length-1],s={type:i.className,label:i.text||i.desc,value:i.text,identifier:i.resourceId,packageName:i.packageName,rect:i.rect,enabled:i.enabled,hittable:i.clickable??i.focusable,scrollable:i.scrollable,canScrollForward:i.canScrollForward,canScrollBackward:i.canScrollBackward,depth:a.depth+1,parentIndex:void 0,children:[]};a.children.push(s),t.endsWith("/>")||r.push(s),o=n.exec(e)}return function(e){let t=[...e.children];for(;t.length>0;){let e=t.pop();t.push(...e.children),function(e){if(!e.scrollable||!s(e.type)||`${e.type??""}`.toLowerCase().includes("horizontalscrollview"))return!1;let t=function(e){if(!e.rect||0===e.children.length)return null;let t=e.children.map(e=>e.rect).filter(e=>void 0!==e);if(0===t.length)return null;let r=Math.min(...t.map(e=>e.x)),n=Math.max(...t.map(e=>e.x+e.width)),o=Math.min(...t.map(e=>e.y)),i=Math.max(...t.map(e=>e.y+e.height));return{horizontal:Math.max(0,n-r-e.rect.width),vertical:Math.max(0,i-o-e.rect.height)}}(e);return!t||!(t.horizontal>t.vertical)||!(t.horizontal>16)}(e)&&(e.canScrollBackward&&(e.hiddenContentAbove=!0),e.canScrollForward&&(e.hiddenContentBelow=!0))}}(t),t}function O(e){return e?e.toLowerCase():""}function P(e){let t=e.trim();return!!t&&/^[\w.]+:id\/[\w.-]+$/i.test(t)}async function R(e){let t=$(e),r=await e.adb(H(t),{allowFailure:!0,timeoutMs:t.commandTimeoutMs}),{output:n,cleanupDone:o}=await V(e,t,r);if(t.outputPath&&!o&&await Q(e.adb,t.outputPath),0!==r.exitCode)throw new a("COMMAND_FAILED","Android snapshot helper failed",{stdout:r.stdout,stderr:r.stderr,exitCode:r.exitCode,helper:n.metadata});return n}function $(e){let t=U(e.timeoutMs,8e3),r=U(e.packageName,c);return{waitForIdleTimeoutMs:U(e.waitForIdleTimeoutMs,25),waitForIdleQuietMs:U(e.waitForIdleQuietMs,25),timeoutMs:t,commandTimeoutMs:U(e.commandTimeoutMs,t+5e3),maxDepth:U(e.maxDepth,128),maxNodes:U(e.maxNodes,5e3),packageName:r,runner:U(e.instrumentationRunner,`${r}/.SnapshotInstrumentation`),...e.outputPath?{outputPath:e.outputPath}:{},...void 0!==e.emitChunks?{emitChunks:e.emitChunks}:{}}}function U(e,t){return void 0===e?t:e}function H(e){return["shell","am","instrument","-w","-e","waitForIdleTimeoutMs",String(e.waitForIdleTimeoutMs),"-e","waitForIdleQuietMs",String(e.waitForIdleQuietMs),"-e","timeoutMs",String(e.timeoutMs),"-e","maxDepth",String(e.maxDepth),"-e","maxNodes",String(e.maxNodes),...e.outputPath?["-e","outputPath",e.outputPath]:[],...void 0!==e.emitChunks?["-e","emitChunks",String(e.emitChunks)]:[],e.runner]}async function V(e,t,r){try{return{output:W(`${r.stdout}
|
|
2
|
+
${r.stderr}`),cleanupDone:!1}}catch(n){return await B(e,t,r,n)}}async function B(e,t,r,n){if(n instanceof a&&0!==r.exitCode&&n.details?.helper)throw n;let o=await K(e,t,r);if(o)return{output:o,cleanupDone:!0};throw new a("COMMAND_FAILED",0===r.exitCode?"Android snapshot helper output could not be parsed":"Android snapshot helper failed before returning parseable output",{stdout:r.stdout,stderr:r.stderr,exitCode:r.exitCode},n)}async function K(e,t,r){if(0===r.exitCode&&t.outputPath){var n;return await G(e.adb,t.outputPath,function(e){try{let t=q(e);return j(z(t.results))}catch{return null}}(`${r.stdout}
|
|
3
|
+
${r.stderr}`)??{outputFormat:f,waitForIdleTimeoutMs:(n=t).waitForIdleTimeoutMs,waitForIdleQuietMs:n.waitForIdleQuietMs,timeoutMs:n.timeoutMs,maxDepth:n.maxDepth,maxNodes:n.maxNodes,transport:"instrumentation"})}}async function G(e,t,r){let n;try{var o;n=await e((o=t,["shell","sh","-c",'cat "$1"; status=$?; rm -f "$1"; exit "$status"',"agent-device-snapshot-helper-output",o]),{allowFailure:!0,timeoutMs:5e3})}catch{return}if(0!==n.exitCode)return;let i=n.stdout.trim();if(i.includes("<hierarchy")&&i.includes("</hierarchy>"))return{xml:i,metadata:r}}async function Q(e,t){try{await e(["shell","rm","-f",t],{allowFailure:!0,timeoutMs:5e3})}catch{}}function W(e){let t=q(e),r=z(t.results);return{xml:function(e,t){if(0===e.length)throw new a("COMMAND_FAILED","Android snapshot helper did not return XML chunks",{helper:t});let r=function(e){let t=e[0]?.count??e.length;if(t<1||e.length!==t||e.some(e=>e.count!==t))throw new a("COMMAND_FAILED","Android snapshot helper returned incomplete XML chunks",{expectedChunks:t,actualChunks:e.length});return t}(e),n=Buffer.concat(function(e,t){let r=[];for(let n=0;n<t;n+=1){let o=e.get(n);if(void 0===o)throw new a("COMMAND_FAILED","Android snapshot helper returned incomplete XML chunks",{missingChunkIndex:n,expectedChunks:t});r.push(Buffer.from(o,"base64"))}return r}(function(e,t){let r=new Map;for(let n of e){if(void 0===n.index||n.index<0||n.index>=t)throw new a("COMMAND_FAILED","Android snapshot helper returned invalid chunk index",{chunkIndex:n.index,expectedChunks:t});if(r.has(n.index))throw new a("COMMAND_FAILED","Android snapshot helper returned duplicate XML chunks",{chunkIndex:n.index});r.set(n.index,n.payloadBase64)}return r}(e,r),r)).toString("utf8");if(!n.includes("<hierarchy")||!n.includes("</hierarchy>"))throw new a("COMMAND_FAILED","Android snapshot helper output did not contain XML",{xml:n});return n}(function(e){let t=[];for(let r of e){if(r.agentDeviceProtocol!==p||r.outputFormat!==f)continue;let{payloadBase64:e}=r;void 0!==e&&t.push({index:er(r.chunkIndex),count:er(r.chunkCount),payloadBase64:e})}return t}(t.status),r),metadata:{...j(r),transport:"instrumentation"}}}function X(e,t={outputFormat:f},r={},n=800){return{...b(e,n,r),metadata:t}}function z(e){let t=e.find(e=>e.agentDeviceProtocol===p);if(!t)throw new a("COMMAND_FAILED","Android snapshot helper did not return a final result");if("true"!==t.ok){var r;throw new a("COMMAND_FAILED",(r=t).message&&"null"!==r.message?r.message:r.errorType||"Android snapshot helper returned an error",{errorType:t.errorType,helper:t})}return t}function j(e){var t;return{helperApiVersion:e.helperApiVersion,outputFormat:f,waitForIdleTimeoutMs:er(e.waitForIdleTimeoutMs),waitForIdleQuietMs:er(e.waitForIdleQuietMs),timeoutMs:er(e.timeoutMs),maxDepth:er(e.maxDepth),maxNodes:er(e.maxNodes),rootPresent:en(e.rootPresent),captureMode:"interactive-windows"===(t=e.captureMode)||"active-window"===t?t:void 0,windowCount:er(e.windowCount),nodeCount:er(e.nodeCount),truncated:en(e.truncated),elapsedMs:er(e.elapsedMs)}}function q(e){var t;let r={status:[],results:[],currentStatus:null,currentResult:null};for(let t of e.split(/\r?\n/))!function(e,t){if(e.startsWith("INSTRUMENTATION_STATUS: ")){t.currentStatus??={},Z(e.slice(24),t.currentStatus);return}if(e.startsWith("INSTRUMENTATION_STATUS_CODE: "))return J(t);if(e.startsWith("INSTRUMENTATION_RESULT: ")){t.currentResult??={},Z(e.slice(24),t.currentResult);return}e.startsWith("INSTRUMENTATION_CODE: ")&&Y(t)}(t,r);return J(t=r),Y(t),{status:r.status,results:r.results}}function J(e){e.currentStatus&&(e.status.push(e.currentStatus),e.currentStatus=null)}function Y(e){e.currentResult&&(e.results.push(e.currentResult),e.currentResult=null)}function Z(e,t){let r=e.indexOf("=");r<0||(t[e.slice(0,r)]=e.slice(r+1))}function ee(e){if(void 0===e)return;let t=Number(e);return Number.isFinite(t)?t:void 0}function et(e){return"true"===e||"false"!==e&&void 0}let er=ee,en=et,eo=new Map;async function ei(e){var t,r,n;let o;if(!(void 0===(o=process.env.AGENT_DEVICE_ANDROID_SNAPSHOT_HELPER_SESSION)||!/^(0|false|no|off)$/i.test(o))||!e.adbProvider?.spawn)return;let i=$(e),a=e.deviceKey??"android:default",s=(t=a,r=i,n=e,JSON.stringify({deviceKey:t,packageName:r.packageName,runner:r.runner,helperVersion:n.helperVersion,helperVersionCode:n.helperVersionCode,waitForIdleTimeoutMs:r.waitForIdleTimeoutMs,waitForIdleQuietMs:r.waitForIdleQuietMs,timeoutMs:r.timeoutMs,maxDepth:r.maxDepth,maxNodes:r.maxNodes})),u=eo.get(a);u&&u.identity!==s&&(await ea(a),u=void 0),u||(u=await es({deviceKey:a,identity:s,options:e,resolved:i}));try{let e=u.capturedCount>0,t=await eu(u,i);return u.capturedCount+=1,{xml:t.xml,metadata:{...t.metadata,transport:"persistent-session",sessionReused:e}}}catch(e){throw await ea(a),e}}async function ea(e){let t=eo.get(e);if(t){eo.delete(e);try{await el(t,`quit ${Date.now()}`,1e3)}catch{}try{await t.process.kill("SIGTERM")}catch{}try{await ed(t)}catch{}u({phase:"android_snapshot_helper_session_stop",data:{deviceKey:e,port:t.port,capturedCount:t.capturedCount,lifetimeMs:Date.now()-t.startedAtMs}})}}async function es(e){let t=await new Promise((e,t)=>{let r=i.createServer();r.unref(),r.on("error",t),r.listen(0,"127.0.0.1",()=>{let n=r.address();if(!n||"string"==typeof n)return void r.close(()=>t(Error("Failed to allocate a local TCP port")));let o=n.port;r.close(()=>e(o))})});await e.options.adb(["forward",`tcp:${t}`,`tcp:${t}`],{allowFailure:!1,timeoutMs:5e3});let r=H({...e.resolved,outputPath:void 0,emitChunks:!1}),n=r[r.length-1];if(!n)throw new a("INVALID_ARGS","Android snapshot helper runner was not resolved");let o=[...r.slice(0,-1),"-e","sessionPort",String(t),n],s=e.options.adbProvider.spawn(o,{allowFailure:!0,captureOutput:!1}),l={identity:e.identity,deviceKey:e.deviceKey,port:t,adb:e.options.adb,process:s,startedAtMs:Date.now(),capturedCount:0};try{var d;return await (d=s,new Promise((e,t)=>{let r="",n=setTimeout(()=>{t(new a("COMMAND_FAILED","Android snapshot helper session did not become ready",{output:r,timeoutMs:1e4}))},1e4),o=t=>{(r+=t.toString()).includes(`agentDeviceProtocol=${p}`)&&r.includes("sessionReady=true")&&(clearTimeout(n),e())};d.stdout?.on("data",o),d.stderr?.on("data",o),d.once("exit",(e,o)=>{clearTimeout(n),t(new a("COMMAND_FAILED","Android snapshot helper session exited before ready",{output:r,exitCode:e,signal:o}))}),d.on("error",e=>{clearTimeout(n),t(e)})})),eo.set(e.deviceKey,l),u({phase:"android_snapshot_helper_session_ready",data:{deviceKey:e.deviceKey,port:t,packageName:e.resolved.packageName,runner:e.resolved.runner}}),l}catch(e){await ed(l);try{s.kill("SIGTERM")}catch{}throw e}}async function eu(e,t){let r=`snapshot-${Date.now()}-${Math.random().toString(16).slice(2)}`,n=Math.max(t.timeoutMs+2e3,3e3);return function(e,t){var r;let{headers:n,xml:o}=function(e){let t=e.indexOf("\n\n");if(t<0)throw new a("COMMAND_FAILED","Android snapshot helper session returned malformed output",{response:e});return{headers:function(e){let t={};for(let r of e.split(/\r?\n/)){let e=r.indexOf("=");e<0||(t[r.slice(0,e)]=r.slice(e+1))}return t}(e.slice(0,t)),xml:e.slice(t+2)}}(e);return function(e,t){if(e.agentDeviceProtocol!==p)throw new a("COMMAND_FAILED","Android snapshot helper session returned wrong protocol",{headers:e});if(e.outputFormat!==f)throw new a("COMMAND_FAILED","Android snapshot helper session returned wrong output format",{headers:e});if(e.requestId!==t)throw new a("COMMAND_FAILED","Android snapshot helper session returned stale output",{headers:e,requestId:t});if("true"!==e.ok)throw new a("COMMAND_FAILED",e.message||e.errorType||"Android snapshot helper session returned an error",{helper:e})}(n,t),function(e,t){let r=ee(e.byteLength);if(void 0!==r&&Buffer.byteLength(t,"utf8")!==r)throw new a("COMMAND_FAILED","Android snapshot helper session returned truncated XML",{headers:e,actualByteLength:Buffer.byteLength(t,"utf8")});if(!t.includes("<hierarchy")||!t.includes("</hierarchy>"))throw new a("COMMAND_FAILED","Android snapshot helper session did not return XML",{headers:e,xml:t})}(n,o),{xml:o,metadata:{helperApiVersion:(r=n).helperApiVersion,outputFormat:f,waitForIdleTimeoutMs:ee(r.waitForIdleTimeoutMs),waitForIdleQuietMs:ee(r.waitForIdleQuietMs),timeoutMs:ee(r.timeoutMs),maxDepth:ee(r.maxDepth),maxNodes:ee(r.maxNodes),rootPresent:et(r.rootPresent),captureMode:"interactive-windows"===r.captureMode||"active-window"===r.captureMode?r.captureMode:void 0,windowCount:ee(r.windowCount),nodeCount:ee(r.nodeCount),truncated:et(r.truncated),elapsedMs:ee(r.elapsedMs)}}}(await el(e,`snapshot ${r}`,n),r)}function el(e,t,r){return new Promise((n,o)=>{let s=i.connect({host:"127.0.0.1",port:e.port}),u=[],l=setTimeout(()=>{s.destroy(),o(new a("COMMAND_FAILED","Android snapshot helper session request timed out",{command:t,timeoutMs:r,port:e.port}))},r);s.on("connect",()=>{s.write(`${t}
|
|
4
|
+
`)}),s.on("data",e=>{u.push(Buffer.from(e))}),s.on("error",e=>{clearTimeout(l),o(e)}),s.on("close",()=>{clearTimeout(l),n(Buffer.concat(u).toString("utf8"))})})}async function ed(e){await e.process.stdin?.end(),await e.process.stdout?.destroy(),await e.process.stderr?.destroy(),await ec(e)}async function ec(e){await e.adb(["forward","--remove",`tcp:${e.port}`],{allowFailure:!0,timeoutMs:5e3})}let eh=new Map;function ep(e){em(ef(e.deviceKey,e.packageName,e.versionCode))}function ef(e,t,r){return e?`${e}\0${t}\0${r}`:void 0}function em(e){e&&eh.delete(e)}async function ew(e){var t,r,n;let{adb:o,artifact:i}=e,s=e.installPolicy??"missing-or-outdated",u=i.manifest.packageName,l=i.manifest.versionCode;if("never"===s)return{packageName:u,versionCode:l,installed:!1,reason:"skipped"};let d=ef(e.deviceKey,u,l),c=d?eh.get(d):void 0;if(d&&"always"!==s&&void 0!==c)return{packageName:u,versionCode:l,installedVersionCode:c,installed:!1,reason:"current"};let h=await eA(o,u,e.timeoutMs),p=(t=s,r=h,n=l,"never"===t?"skipped":"always"===t?"forced":void 0===r?"missing":r<n?"outdated":"current");if("current"===p){if(void 0===h)throw Error("Expected installed versionCode for current Android snapshot helper");return d&&eh.set(d,h),{packageName:u,versionCode:l,installedVersionCode:h,installed:!1,reason:p}}await w(i);let f=await eM(o,e.adbProvider??o,i.apkPath,function(e){let t={};for(let r of e.slice(1)){let e=y(r);if(!e)throw new a("INVALID_ARGS",`Android snapshot helper manifest installArgs contains unsupported install flag "${r}".`);t[e]=!0}return t}(N(i.manifest.installArgs)),{packageName:u,timeoutMs:e.timeoutMs});if(0!==f.exitCode)throw em(d),new a("COMMAND_FAILED","Failed to install Android snapshot helper",{packageName:u,versionCode:l,stdout:f.stdout,stderr:f.stderr,exitCode:f.exitCode});return d&&eh.set(d,l),{packageName:u,versionCode:l,installedVersionCode:h,installed:!0,reason:p}}async function eA(e,t,r){let n=await e(["shell","cmd","package","list","packages","--show-versioncode",t],{allowFailure:!0,timeoutMs:r});if(0===n.exitCode){var o=`${n.stdout}
|
|
5
|
+
${n.stderr}`,i=t;let e=`package:${i}`;for(let t of o.split(/\r?\n/)){if(!t.startsWith(e)||t.length>e.length&&!/\s/.test(t[e.length]??""))continue;let r=/(?:^|\s)versionCode:(\d+)(?:\s|$)/.exec(t);if(r)return Number(r[1])}return}}async function eM(e,t,r,n,o){var i;let a=async()=>await l(r,{allowFailure:!0,provider:t,...n,timeoutMs:o.timeoutMs}),s=await a();if(0===s.exitCode||(i=s,!`${i.stdout}
|
|
6
|
+
${i.stderr}`.includes("INSTALL_FAILED_UPDATE_INCOMPATIBLE")))return s;let u=await e(["uninstall",o.packageName],{allowFailure:!0,timeoutMs:o.timeoutMs}),d=await a();return 0===d.exitCode?d:{...d,stderr:[d.stderr,u.stderr?`Previous uninstall stderr after INSTALL_FAILED_UPDATE_INCOMPATIBLE: ${u.stderr}`:""].filter(Boolean).join("\n")}}export{d as ANDROID_SNAPSHOT_HELPER_NAME,f as ANDROID_SNAPSHOT_HELPER_OUTPUT_FORMAT,c as ANDROID_SNAPSHOT_HELPER_PACKAGE,p as ANDROID_SNAPSHOT_HELPER_PROTOCOL,h as ANDROID_SNAPSHOT_HELPER_RUNNER,S as androidUiNodes,k as buildUiHierarchySnapshot,R as captureAndroidSnapshotWithHelper,ei as captureAndroidSnapshotWithHelperSession,ew as ensureAndroidSnapshotHelper,ep as forgetAndroidSnapshotHelperInstall,M as parseAndroidSnapshotHelperManifest,W as parseAndroidSnapshotHelperOutput,X as parseAndroidSnapshotHelperXml,b as parseUiHierarchy,E as parseUiHierarchyTree,A as prepareAndroidSnapshotHelperArtifactFromManifestUrl,ea as stopAndroidSnapshotHelperSession,w as verifyAndroidSnapshotHelperArtifact};
|
package/dist/src/6277.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import e from"node:fs";import t from"node:path";import{fileURLToPath as r}from"node:url";import n from"node:crypto";import{resolveUserPath as i,expandUserHomePath as o}from"./3267.js";import{AppError as a}from"./9152.js";import{splitSelectorFromArgs as s,tryParseSelectorChain as l}from"./940.js";import{assertResolvedAppsFilter as u}from"./1393.js";function c(e,t){let r=[],n=e+t.toString(),i=n.indexOf("\n");for(;-1!==i;){let e=n.slice(0,i).trim();n=n.slice(i+1),e&&r.push(e),i=n.indexOf("\n")}return{lines:r,buffer:n}}function d(){try{let r=p();return JSON.parse(e.readFileSync(t.join(r,"package.json"),"utf8")).version??"0.0.0"}catch{return"0.0.0"}}function p(){let n=t.dirname(r(import.meta.url)),i=n;for(let r=0;r<6;r+=1){let r=t.join(i,"package.json");if(e.existsSync(r))return i;i=t.dirname(i)}return n}function f(e){let r,n=(r=(e??"").trim())?i(r):t.join(o("~"),".agent-device");return{baseDir:n,infoPath:t.join(n,"daemon.json"),lockPath:t.join(n,"daemon.lock"),logPath:t.join(n,"daemon.log"),sessionsDir:t.join(n,"sessions")}}function m(e){let t=(e??"").trim().toLowerCase();return"http"===t?"http":"dual"===t?"dual":"socket"}function h(e){let t=(e??"").trim().toLowerCase();return"auto"===t?"auto":"socket"===t?"socket":"http"===t?"http":"auto"}function g(e){return"tenant"===(e??"").trim().toLowerCase()?"tenant":"none"}function v(e){if(!e)return;let t=e.trim();if(t&&/^[a-zA-Z0-9._-]{1,128}$/.test(t))return t}let y=/(?:^|[^\w$.])(?:import|export)\s+(?:type\s+)?(?:[^'"`]*?\s+from\s+)?['"]([^'"]+)['"]/gm,b=/import\(\s*['"]([^'"]+)['"]\s*\)/gm,w=[".ts",".tsx",".js",".jsx",".mjs",".cjs"];function S(){let e=process.argv[1];return e?I(e):"unknown"}function I(r,i=p()){try{let o=t.resolve(i),a=[t.resolve(r)],s=new Set,l=[];for(;a.length>0;){let r=a.pop();if(!r||s.has(r))continue;s.add(r);let n=e.statSync(r);if(!n.isFile())continue;let i=t.relative(o,r)||r;l.push(`${i}:${n.size}:${Math.trunc(n.mtimeMs)}`);let u=e.readFileSync(r,"utf8");for(let e of function(e){let t=new Set;return A(e,y,t),A(e,b,t),[...t]}(u)){let n=function(e,r){let n=t.resolve(t.dirname(e),r),i=x(n);if(i)return i;for(let e of w){let t=x(`${n}${e}`);if(t)return t}for(let e of w){let r=x(t.join(n,`index${e}`));if(r)return r}return null}(r,e);n&&a.push(n)}}let u=l.sort().join("|"),c=n.createHash("sha1").update(u).digest("hex");return`graph:${l.length}:${c}`}catch{return"unknown"}}function A(e,t,r){t.lastIndex=0;let n=null;for(;null!==(n=t.exec(e));){let e=n[1]?.trim();e?.startsWith(".")&&r.add(e)}}function x(t){try{return e.statSync(t).isFile()?t:null}catch{return null}}let N={alert:"alert",appState:"appstate",appSwitcher:"app-switcher",apps:"apps",back:"back",batch:"batch",boot:"boot",click:"click",close:"close",clipboard:"clipboard",devices:"devices",diff:"diff",fill:"fill",find:"find",focus:"focus",gesture:"gesture",get:"get",home:"home",install:"install",installFromSource:"install-from-source",is:"is",keyboard:"keyboard",logs:"logs",longPress:"longpress",network:"network",open:"open",perf:"perf",press:"press",push:"push",record:"record",reactNative:"react-native",reinstall:"reinstall",replay:"replay",rotate:"rotate",scroll:"scroll",screenshot:"screenshot",settings:"settings",snapshot:"snapshot",swipe:"swipe",test:"test",trace:"trace",triggerAppEvent:"trigger-app-event",type:"type",wait:"wait"},k={installSource:"install_source",leaseAllocate:"lease_allocate",leaseHeartbeat:"lease_heartbeat",leaseRelease:"lease_release",releaseMaterializedPaths:"release_materialized_paths",sessionList:"session_list"},D={auth:"auth",connect:"connect",connection:"connection",disconnect:"disconnect",mcp:"mcp",metro:"metro",reactDevtools:"react-devtools",session:"session"},R="gesture requires one of: pan, fling, pinch, rotate, transform",M=E(D.auth,D.connect,D.connection,D.disconnect,D.mcp,D.reactDevtools);E(D.auth,D.connect,D.connection,D.disconnect,D.mcp,D.metro,D.reactDevtools,D.session,N.appState,N.batch,N.devices,N.gesture,N.replay,N.test,N.trace);let _={inventory:E(k.sessionList,N.devices,N.apps),state:E(N.boot,N.appState),observability:E(N.perf,N.logs,N.network),replay:E(N.replay,N.test),snapshot:E(N.snapshot,N.diff,N.wait,N.alert,N.settings),replayScopedAction:E(N.alert,N.back,N.click,N.clipboard,N.diff,N.fill,N.find,N.gesture,N.get,N.home,N.is,N.keyboard,N.longPress,"pinch",N.press,N.record,N.reactNative,N.rotate,N.screenshot,N.scroll,N.settings,N.snapshot,N.swipe,N.type,N.wait),androidBlockingDialogGuardedAction:E(N.back,N.click,N.fill,N.focus,N.gesture,N.home,N.keyboard,N.longPress,"fling","pan","pinch",N.press,N.rotate,"rotate-gesture",N.scroll,N.swipe,"transform-gesture",N.type),selectorValidationExempt:E(k.sessionList,N.devices,k.releaseMaterializedPaths),leaseAdmissionExempt:E(k.sessionList,N.devices,k.releaseMaterializedPaths,k.leaseAllocate,k.leaseHeartbeat,k.leaseRelease)};function E(...e){return new Set(e)}function L(){return[...Object.values(N),...Object.values(D)].sort()}function j(){return L().filter(e=>!M.has(e))}function P(e){return e.meta?.requestProgress==="replay-test"}function $(e){return!!e&&"object"==typeof e&&"progress"===e.type&&!!e.event}function F(e){return!!e&&"object"==typeof e&&"response"===e.type&&!!e.response}function z(e){return`${JSON.stringify({type:"progress",event:e})}
|
|
2
|
+
`}function O(e){return`${JSON.stringify({type:"response",response:e})}
|
|
3
|
+
`}function q(e){return`${JSON.stringify({type:"response",response:e})}
|
|
4
|
+
`}function G(e){var t;if("replay-test"!==e.type)return;let r=[e.status,`${e.index}/${e.total}`,e.file];void 0!==e.attempt&&void 0!==e.maxAttempts&&r.push(`attempt=${e.attempt}/${e.maxAttempts}`),e.retrying&&r.push("retry=true"),void 0!==e.durationMs&&r.push(`duration=${(t=e.durationMs,`${(Math.max(0,t)/1e3).toFixed(2)}s`)}`),e.artifactsDir&&"fail"===e.status&&r.push(`artifacts=${e.artifactsDir}`);let n=e.message?.replace(/\s+/g," ").trim();return n&&r.push(n),r.join(" ")}let T=["out","overlayRefs","screenshotFullscreen","screenshotMaxSize","screenshotNoStabilize"],V=["screenshotFullscreen","screenshotMaxSize","screenshotNoStabilize"],C=[{key:"screenshotFullscreen",names:["--fullscreen"],type:"boolean",usageLabel:"--fullscreen",usageDescription:"Screenshot: capture the full screen instead of the app window"},{key:"screenshotMaxSize",names:["--max-size"],type:"int",min:1,usageLabel:"--max-size <px>",usageDescription:"Screenshot: downscale so the longest edge is at most <px>"},{key:"screenshotNoStabilize",names:["--no-stabilize"],type:"boolean",usageLabel:"--no-stabilize",usageDescription:"Screenshot: skip Android demo-mode/status-bar stabilization and settle delay for low-latency capture loops"}];function U(e){return K({overlayRefs:e?.overlayRefs,fullscreen:e?.screenshotFullscreen,maxSize:e?.screenshotMaxSize,stabilize:!e?.screenshotNoStabilize&&void 0})}function B(e={}){return K({overlayRefs:e.overlayRefs,screenshotFullscreen:e.screenshotFullscreen??e.fullscreen,screenshotMaxSize:e.screenshotMaxSize??e.maxSize,screenshotNoStabilize:e.screenshotNoStabilize??(!1===e.stabilize||void 0)})}function H(e,t){t?.screenshotFullscreen&&e.push("--fullscreen"),"number"==typeof t?.screenshotMaxSize&&e.push("--max-size",String(t.screenshotMaxSize)),t?.screenshotNoStabilize&&e.push("--no-stabilize")}function J(e){let{args:t,flags:r,index:n}=e,i=t[n];if("--fullscreen"===i)return r.screenshotFullscreen=!0,{handled:!0,nextIndex:n};if("--no-stabilize"===i)return r.screenshotNoStabilize=!0,{handled:!0,nextIndex:n};if("--max-size"===i){let e=t[n+1],i=void 0===e?NaN:Number(e);if(!Number.isInteger(i)||i<1)throw new a("INVALID_ARGS","screenshot --max-size requires a positive integer");return r.screenshotMaxSize=i,{handled:!0,nextIndex:n+1}}return{handled:!1}}function K(e){return Object.fromEntries(Object.entries(e).filter(e=>void 0!==e[1]))}function W(e){return e?{message:e}:{}}function Y(e,t){return t?{...e,message:t}:e}function Z(e){return"string"==typeof e?.message&&e.message.length>0?e.message:null}function Q(e){let t=e.appId??e.bundleId??e.packageName;return{session:e.session,appId:t,appBundleId:e.bundleId,package:e.packageName}}function X(e,t,r){return{deviceId:t,deviceName:r,..."android"===e?{serial:t}:"ios"===e?{udid:t}:{}}}function ee(e,t={}){let r=t.includeAndroidSerial??!0;return{platform:e.platform,target:e.target,device:e.name,id:e.id,..."ios"===e.platform?{device_udid:e.ios?.udid??e.id,ios_simulator_device_set:e.ios?.simulatorSetPath??null}:{},..."android"===e.platform&&r?{serial:e.android?.serial??e.id}:{}}}function et(e){return{name:e.name,...ee(e.device,{includeAndroidSerial:!1}),createdAt:e.createdAt}}function er(e){return{platform:e.platform,id:e.id,name:e.name,kind:e.kind,target:e.target,..."boolean"==typeof e.booted?{booted:e.booted}:{}}}function en(e){return e.bundleId??e.package??e.app}function ei(e){return Y({app:e.app,appPath:e.appPath,platform:e.platform,...e.appId?{appId:e.appId}:{},...e.bundleId?{bundleId:e.bundleId}:{},...e.package?{package:e.package}:{}},`Installed: ${en(e)}`)}function eo(e){return e.appName??e.bundleId??e.packageName??e.launchTarget}function ea(e){return Y({launchTarget:e.launchTarget,...e.appName?{appName:e.appName}:{},...e.appId?{appId:e.appId}:{},...e.bundleId?{bundleId:e.bundleId}:{},...e.packageName?{package:e.packageName}:{},...e.installablePath?{installablePath:e.installablePath}:{},...e.archivePath?{archivePath:e.archivePath}:{},...e.materializationId?{materializationId:e.materializationId}:{},...e.materializationExpiresAt?{materializationExpiresAt:e.materializationExpiresAt}:{}},`Installed: ${eo(e)}`)}function es(e){let t=e.appName??e.appBundleId??e.session;return Y({session:e.session,...e.appName?{appName:e.appName}:{},...e.appBundleId?{appBundleId:e.appBundleId}:{},...e.startup?{startup:e.startup}:{},...e.runtime?{runtime:e.runtime}:{},...e.device?ee(e.device):{}},t?`Opened: ${t}`:"Opened")}function el(e){return{session:e.session,...e.shutdown?{shutdown:e.shutdown}:{},...W(e.session?`Closed: ${e.session}`:"Closed")}}function eu(e){return{nodes:e.nodes,truncated:e.truncated,...e.appName?{appName:e.appName}:{},...e.appBundleId?{appBundleId:e.appBundleId}:{},...e.visibility?{visibility:e.visibility}:{},...e.androidSnapshot?{androidSnapshot:e.androidSnapshot}:{},...e.warnings&&e.warnings.length>0?{warnings:e.warnings}:{},...e.unchanged?{unchanged:e.unchanged}:{}}}function ec(e,t,r,n){let i=r(e[t]);if(void 0===i)throw new a("COMMAND_FAILED",n,{response:e});return i}function ed(e,t){return ec(e,t,ey,`Daemon response is missing "${t}".`)}function ep(e,t){return ey(e[t])}function ef(e,t){var r;let n;return r=ey,null===(n=e[t])?null:r(n)}function em(e,t){return ec(e,t,ew,`Daemon response has invalid "${t}".`)}function eh(e,t){return function(e){return"tv"===e||"mobile"===e||"desktop"===e?e:void 0}(e[t])??"mobile"}function eg(e,t){let r=e[t];if(!eI(r))return;let n=ev(r,"x"),i=ev(r,"y"),o=ev(r,"width"),a=ev(r,"height");if(void 0!==n&&void 0!==i&&void 0!==o&&void 0!==a)return{x:n,y:i,width:o,height:a}}function ev(e,t){let r=e[t];return"number"==typeof r?r:void 0}function ey(e){return"string"==typeof e&&e.length>0?e:void 0}function eb(e){return"number"==typeof e&&Number.isFinite(e)?e:void 0}function ew(e){return"ios"===e||"macos"===e||"android"===e||"linux"===e?e:void 0}function eS(e){return"simulator"===e||"emulator"===e||"device"===e?e:void 0}function eI(e){return"object"==typeof e&&null!==e}function eA(e){let t={};for(let[r,n]of Object.entries(e))void 0!==n&&(t[r]=n);return t}function ex(e){return e.split("\n").map(e=>e.trim()).filter(e=>e.length>0)}function eN(e,t){let r=ep(e,"bundleId"),n=ep(e,"package");return{app:ed(e,"app"),appPath:ed(e,"appPath"),platform:em(e,"platform"),appId:r??n,bundleId:r,package:n,identifiers:Q({session:t,bundleId:r,packageName:n})}}function ek(e,t){let r=ep(e,"bundleId"),n=ep(e,"packageName"),i=r??n??ep(e,"appId"),o=ep(e,"launchTarget")??n??r??i;if(!o)throw new a("COMMAND_FAILED",'Daemon response is missing "launchTarget".',{response:e});return{appName:ep(e,"appName"),appId:i,bundleId:r,packageName:n,launchTarget:o,installablePath:ep(e,"installablePath"),archivePath:ep(e,"archivePath"),materializationId:ep(e,"materializationId"),materializationExpiresAt:ep(e,"materializationExpiresAt"),identifiers:Q({session:t,bundleId:r,packageName:n,appId:i})}}function eD(e){return{released:!0===e.released,materializationId:ed(e,"materializationId"),identifiers:{}}}function eR(e){let{record:t,platform:r,id:n,name:i,target:o}=e_(e,"name");return{platform:r,target:o,kind:ec(t,"kind",eS,'Daemon response has invalid "kind".'),id:n,name:i,booted:"boolean"==typeof t.booted?t.booted:void 0,identifiers:X(r,n,i),...eE(r,n)}}function eM(e){let{record:t,platform:r,id:n,name:i,target:o}=e_(e,"name"),a=ed(t,"device"),s={session:i,...X(r,n,a)};return{name:i,createdAt:ec(t,"createdAt",eb,'Daemon response is missing numeric "createdAt".'),device:{platform:r,target:o,id:n,name:a,identifiers:s,...eE(r,n,ef(t,"ios_simulator_device_set"))},identifiers:s}}function e_(e,t){let r=function(e){if(!eI(e))throw new a("COMMAND_FAILED","Daemon returned an unexpected response shape.",{value:e});return e}(e);return{record:r,platform:em(r,"platform"),id:ed(r,"id"),name:ed(r,t),target:eh(r,"target")}}function eE(e,t,r){return{ios:"ios"===e?{udid:t,...void 0!==r?{simulatorSetPath:r}:{}}:void 0,android:"android"===e?{serial:t}:void 0}}function eL(e){if(!eI(e))return;let t=e.platform,r=ep(e,"metroHost"),n="number"==typeof e.metroPort?e.metroPort:void 0;return{platform:"ios"===t||"android"===t?t:void 0,metroHost:r,metroPort:n,bundleUrl:ep(e,"bundleUrl"),launchUrl:ep(e,"launchUrl")}}function ej(e){let t=e.platform,r=ep(e,"id"),n=ep(e,"device");if("ios"!==t&&"macos"!==t&&"android"!==t&&"linux"!==t||!r||!n)return;let i=eh(e,"target"),o=X(t,r,n);return{platform:t,target:i,id:r,name:n,identifiers:o,ios:"ios"===t?{udid:ep(e,"device_udid")??r,simulatorSetPath:ef(e,"ios_simulator_device_set")}:void 0,android:"android"===t?{serial:ep(e,"serial")??r}:void 0}}function eP(e){if(eI(e)&&"number"==typeof e.durationMs&&"string"==typeof e.measuredAt&&"string"==typeof e.method)return{durationMs:e.durationMs,measuredAt:e.measuredAt,method:e.method,appTarget:ep(e,"appTarget"),appBundleId:ep(e,"appBundleId")}}function e$(e){return Array.isArray(e)?e:[]}function eF(e){let t=e.overlayRefs;if(!Array.isArray(t))return;let r=[];for(let e of t){if(!eI(e))continue;let t=ep(e,"ref"),n=eg(e,"rect"),i=eg(e,"overlayRect"),o=function(e,t){let r=e[t];if(!eI(r))return;let n=ev(r,"x"),i=ev(r,"y");if(void 0!==n&&void 0!==i)return{x:n,y:i}}(e,"center");t&&n&&i&&o&&r.push({ref:t,label:ep(e,"label"),rect:n,overlayRect:i,center:o})}return r}function ez(e){return eA({stateDir:e.stateDir,daemonBaseUrl:e.daemonBaseUrl,daemonAuthToken:e.daemonAuthToken,daemonTransport:e.daemonTransport,daemonServerMode:e.daemonServerMode,tenant:e.tenant,sessionIsolation:e.sessionIsolation,runId:e.runId,leaseId:e.leaseId,leaseBackend:e.leaseBackend,platform:e.platform,target:e.target,device:e.device,udid:e.udid,serial:e.serial,iosSimulatorDeviceSet:e.iosSimulatorDeviceSet,androidDeviceAllowlist:e.androidDeviceAllowlist,surface:e.surface,activity:e.activity,launchConsole:e.launchConsole,relaunch:e.relaunch,shutdown:e.shutdown,saveScript:e.saveScript,noRecord:e.noRecord,backMode:e.backMode,metroHost:e.metroHost,metroPort:e.metroPort,bundleUrl:e.bundleUrl,launchUrl:e.launchUrl,snapshotInteractiveOnly:e.interactiveOnly,snapshotCompact:e.compact,snapshotDepth:e.depth,snapshotScope:e.scope,snapshotRaw:e.raw,snapshotForceFull:e.forceFull,...B(e),appsFilter:e.appsFilter,out:e.out,count:e.count,fps:e.fps,quality:e.quality,hideTouches:e.hideTouches,intervalMs:e.intervalMs,delayMs:e.delayMs,holdMs:e.holdMs,jitterPx:e.jitterPx,pixels:e.pixels,doubleTap:e.doubleTap,clickButton:e.clickButton,pauseMs:e.pauseMs,pattern:e.pattern,headless:e.headless,restart:e.restart,replayUpdate:e.replayUpdate,replayBackend:e.replayBackend,replayEnv:e.replayEnv,replayShellEnv:e.replayShellEnv,failFast:e.failFast,timeoutMs:e.timeoutMs,retries:e.retries,artifactsDir:e.artifactsDir,reportJunit:e.reportJunit,findFirst:e.findFirst,findLast:e.findLast,networkInclude:e.networkInclude,batchOnError:e.batchOnError,batchMaxSteps:e.batchMaxSteps,batchSteps:e.batchSteps,verbose:e.debug})}function eO(e){return eA({requestId:e.requestId,cwd:e.cwd,debug:e.debug,lockPolicy:e.lockPolicy,lockPlatform:e.lockPlatform,tenantId:e.tenant,runId:e.runId,leaseId:e.leaseId,leaseBackend:e.leaseBackend,leaseTtlMs:e.leaseTtlMs,sessionIsolation:e.sessionIsolation,installSource:e.installSource,retainMaterializedPaths:e.retainMaterializedPaths,materializedPathRetentionMs:e.materializedPathRetentionMs,materializationId:e.materializationId})}function eq(e){return e??"default"}function eG(e,t){if(!e||"object"!=typeof e||Array.isArray(e))throw new a("INVALID_ARGS",`${t} installSource must be an object.`);if("github-actions-artifact"!==eC(e.type,`${t} installSource.type`))throw new a("INVALID_ARGS",`${t} installSource.type must be "github-actions-artifact".`);let{owner:r,repo:n}=eV(eC(e.repo,`${t} installSource.repo`),`${t} installSource.repo`);return eT(r,n,e.artifact,`${t} installSource.artifact`)}function eT(e,t,r,n){var i;return"number"==typeof r||"string"==typeof(i=r)&&/^\d+$/.test(i.trim())?{kind:"github-actions-artifact",owner:e,repo:t,artifactId:function(e,t){let r="number"==typeof e?e:"string"==typeof e?Number(e):NaN;if(!Number.isInteger(r))throw new a("INVALID_ARGS",`${t} must be an integer.`);return r}(r,n)}:{kind:"github-actions-artifact",owner:e,repo:t,artifactName:eC(r,n)}}function eV(e,t){let r=e.indexOf("/");if(r<=0||r===e.length-1||-1!==e.indexOf("/",r+1))throw new a("INVALID_ARGS",`${t} must use owner/repo.`);let n={owner:e.slice(0,r).trim(),repo:e.slice(r+1).trim()};if(!n.owner||!n.repo)throw new a("INVALID_ARGS",`${t} must use owner/repo.`);return n}function eC(e,t){let r="string"==typeof e&&e.trim().length>0?e.trim():void 0;if(!r)throw new a("INVALID_ARGS",`${t} must be a non-empty string.`);return r}let eU=["ios","android","macos","linux","apple"],eB=["mobile","tv","desktop"],eH=["ref","selector","point"];function eJ(e){return{type:"string",...e?{description:e}:{}}}function eK(e){return{type:"integer",...e?{description:e}:{}}}function eW(e){return{type:"boolean",...e?{description:e}:{}}}function eY(e){return{type:"object",additionalProperties:!0,...e?{description:e}:{}}}function eZ(e){return{...e,required:!0}}function eQ(e){return tI(eJ(e),tl)}function eX(e){return tI({type:"number",...e?{description:e}:{}},tc)}function e0(e,t={}){var r,n;return tI((r=e,n=t,{...eK(r),...void 0===n.min?{}:{minimum:n.min},...void 0===n.max?{}:{maximum:n.max}}),(e,r)=>td(e,r,t))}function e1(e){return tI(eW(e),tp)}function e2(e,t){return tI({type:"string",enum:e,...t?{description:t}:{}},(t,r)=>tm(t,r,e))}function e3(e){return tI(eY(e),tA)}function e8(e){return tI({type:"array",items:{type:"string"},...e?{description:e}:{}},tx)}function e4(e){return tI(e,(e,t)=>e[t])}function e9(e,t){return tI(e,t)}function e6(){return tI({oneOf:[...tN(),{type:"object",properties:{kind:{type:"string",const:"point"},x:{type:"number"},y:{type:"number"}},required:["kind","x","y"],additionalProperties:!1}],description:"UI target. This is separate from deviceTarget, which selects the device form."},(e,t)=>void 0===e[t]?void 0:function(e,t){let r=tk(e,t),n=tf(r,"kind",eH);switch(n){case"ref":return{kind:n,ref:ts(r,"ref"),label:tl(r,"label")};case"selector":return{kind:n,selector:ts(r,"selector")};case"point":return{kind:n,x:tu(r,"x"),y:tu(r,"y")}}}(e,t))}function e5(){return tI({oneOf:tN(),description:"UI element target by snapshot ref or selector expression."},(e,t)=>{let r,n;return void 0===e[t]?void 0:"ref"===(n=tf(r=tk(e,t),"kind",["ref","selector"]))?{kind:n,ref:ts(r,"ref"),label:tl(r,"label")}:{kind:n,selector:ts(r,"selector")}})}function e7(e){return tI({type:"object",description:e,properties:{x:{type:"number"},y:{type:"number"}},required:["x","y"],additionalProperties:!1},(e,t)=>void 0===e[t]?void 0:ta(e,t))}function te(){return{depth:e0("Snapshot traversal depth.",{min:0}),scope:eQ("Snapshot scope selector used before resolution."),raw:e1("Use raw snapshot data during selector resolution.")}}function tt(){return{count:e0("Number of press/click repetitions.",{min:1}),intervalMs:e0("Delay between repeated press/click actions.",{min:0}),holdMs:e0("Hold duration for each action.",{min:0}),jitterPx:e0("Randomization radius in pixels.",{min:0}),doubleTap:e1("Request a double-tap action.")}}function tr(e){return function(e,t=[]){return{type:"object",properties:{session:{type:"string",description:"Agent-device session name."},platform:{type:"string",enum:eU,description:"Platform selector used to resolve a device."},deviceTarget:{type:"string",enum:eB,description:"Device target form. Maps to the CLI --target flag."},target:{type:"string",enum:eB,description:"Alias for deviceTarget on commands without a UI target field. Interaction commands reserve target for the UI element."},device:{type:"string",description:"Device name selector."},udid:{type:"string",description:"iOS device UDID selector."},serial:{type:"string",description:"Android serial selector."},iosSimulatorDeviceSet:{type:"string",description:"iOS simulator device-set path used for device resolution."},androidDeviceAllowlist:{type:"string",description:"Android serial allowlist used for device resolution."},daemonBaseUrl:{type:"string",description:"Remote daemon base URL."},daemonAuthToken:{type:"string",description:"Remote daemon auth token."},tenant:{type:"string",description:"Remote tenant identifier."},runId:{type:"string",description:"Lease run identifier."},leaseId:{type:"string",description:"Existing lease identifier."},cwd:{type:"string",description:"Working directory for command execution."},debug:{type:"boolean",description:"Enable debug diagnostics."},...e},...t.length>0?{required:t}:{},additionalProperties:!1}}(Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.schema])),Object.entries(e).flatMap(([e,t])=>t.required?[e]:[]))}function tn(e,t){let r=ti(e),n=Object.fromEntries(Object.entries(t).flatMap(([e,t])=>{let n=t.read(r,e);if(t.required&&void 0===n)throw Error(`Expected ${e} to be set.`);return void 0===n?[]:[[e,n]]})),i=to(r,{readTargetAlias:!Object.hasOwn(t,"target")});return tS({...i,...th(i),...n})}function ti(e){if(null==e)return{};if(!e||"object"!=typeof e||Array.isArray(e))throw Error("Expected object arguments.");return e}function to(e,t={}){return{session:tl(e,"session"),platform:tm(e,"platform",eU),deviceTarget:function(e,t){let r=tm(e,"deviceTarget",eB);if(!1===t.readTargetAlias||void 0===e.target)return r;let n=tm(e,"target",eB);if(void 0!==r&&n!==r)throw Error("Expected target alias to match deviceTarget when both are set.");return r??n}(e,t),device:tl(e,"device"),udid:tl(e,"udid"),serial:tl(e,"serial"),iosSimulatorDeviceSet:tl(e,"iosSimulatorDeviceSet"),androidDeviceAllowlist:tl(e,"androidDeviceAllowlist"),daemonBaseUrl:tl(e,"daemonBaseUrl"),daemonAuthToken:tl(e,"daemonAuthToken"),tenant:tl(e,"tenant"),runId:tl(e,"runId"),leaseId:tl(e,"leaseId"),cwd:tl(e,"cwd"),debug:tp(e,"debug")}}function ta(e,t){let r=tk(e,t);return{x:tu(r,"x"),y:tu(r,"y")}}function ts(e,t){let r=e[t];if("string"!=typeof r||0===r.length)throw Error(`Expected ${t} to be a non-empty string.`);return r}function tl(e,t){let r=e[t];if(void 0!==r){if("string"!=typeof r||0===r.length)throw Error(`Expected ${t} to be a non-empty string.`);return r}}function tu(e,t){let r=e[t];if("number"!=typeof r||!Number.isFinite(r))throw Error(`Expected ${t} to be a finite number.`);return r}function tc(e,t){let r=e[t];if(void 0!==r){if("number"!=typeof r||!Number.isFinite(r))throw Error(`Expected ${t} to be a finite number.`);return r}}function td(e,t,r={}){let n=e[t];if(void 0!==n){if(!Number.isInteger(n))throw Error(`Expected ${t} to be an integer.`);if(void 0!==r.min&&n<r.min)throw Error(`Expected ${t} to be at least ${r.min}.`);if(void 0!==r.max&&n>r.max)throw Error(`Expected ${t} to be at most ${r.max}.`);return n}}function tp(e,t){let r=e[t];if(void 0!==r){if("boolean"!=typeof r)throw Error(`Expected ${t} to be a boolean.`);return r}}function tf(e,t,r){let n=e[t];if("string"!=typeof n||!r.includes(n))throw Error(`Expected ${t} to be one of: ${r.join(", ")}.`);return n}function tm(e,t,r){let n=e[t];if(void 0!==n){if("string"!=typeof n||!r.includes(n))throw Error(`Expected ${t} to be one of: ${r.join(", ")}.`);return n}}function th(e){return{session:e.session,platform:e.platform,target:e.deviceTarget,device:e.device,udid:e.udid,serial:e.serial,iosSimulatorDeviceSet:e.iosSimulatorDeviceSet,androidDeviceAllowlist:e.androidDeviceAllowlist,daemonBaseUrl:e.daemonBaseUrl,daemonAuthToken:e.daemonAuthToken,tenant:e.tenant,runId:e.runId,leaseId:e.leaseId,cwd:e.cwd,debug:e.debug}}function tg(e){switch(e.kind){case"ref":return{ref:e.ref,label:e.label};case"selector":return{selector:e.selector};case"point":return{x:e.x,y:e.y}}}function tv(e){switch(e.kind){case"ref":return{ref:e.ref,label:e.label};case"selector":return{selector:e.selector}}}function ty(e){return{count:e.count,intervalMs:e.intervalMs,holdMs:e.holdMs,jitterPx:e.jitterPx,doubleTap:e.doubleTap}}function tb(e){return{depth:e.depth,scope:e.scope,raw:e.raw}}function tw(e,t,r){let n=new Set(t),i=Object.keys(e).filter(e=>!n.has(e));if(i.length>0)throw Error(`${r} has unknown field(s): ${i.join(", ")}.`)}function tS(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>void 0!==e))}function tI(e,t){return{schema:e,required:!1,read:t}}function tA(e,t){let r=e[t];if(void 0!==r){if(!r||"object"!=typeof r||Array.isArray(r))throw Error(`Expected ${t} to be an object.`);return r}}function tx(e,t){let r=e[t];if(void 0!==r){if(!Array.isArray(r)||r.some(e=>"string"!=typeof e))throw Error(`Expected ${t} to be an array of strings.`);return r}}function tN(){return[{type:"object",properties:{kind:{type:"string",const:"ref"},ref:{type:"string",description:"Snapshot element ref such as @e12."},label:{type:"string",description:"Optional human label for the ref."}},required:["kind","ref"],additionalProperties:!1},{type:"object",properties:{kind:{type:"string",const:"selector"},selector:{type:"string",description:"Agent-device selector expression."}},required:["kind","selector"],additionalProperties:!1}]}function tk(e,t){let r=e[t];if(!r||"object"!=typeof r||Array.isArray(r))throw Error(`Expected ${t} to be an object.`);return r}function tD(e,t){return r=>tR(e,t?t(r):[],r)}function tR(e,t,r){return{command:e,positionals:t,options:function(e){var t;let r="mobile"===(t=e.deviceTarget??e.target)||"tv"===t||"desktop"===t?t:void 0;if(void 0===r&&void 0===e.target)return e;let{target:n,...i}=e;return void 0===r?i:{...i,target:r}}(r)}}function tM(e){return tS({session:e.session,platform:e.platform,deviceTarget:e.target,device:e.device,udid:e.udid,serial:e.serial,iosSimulatorDeviceSet:e.iosSimulatorDeviceSet,androidDeviceAllowlist:e.androidDeviceAllowlist})}function t_(e){return{platform:e.platform,target:e.target,device:e.device,udid:e.udid,serial:e.serial,iosSimulatorDeviceSet:e.iosSimulatorDeviceSet,androidDeviceAllowlist:e.androidDeviceAllowlist}}function tE(e){return tS({depth:e.snapshotDepth,scope:e.snapshotScope,raw:e.snapshotRaw})}function tL(e){return{depth:e.snapshotDepth,scope:e.snapshotScope,raw:e.snapshotRaw}}function tj(e){return tS({count:e.count,intervalMs:e.intervalMs,holdMs:e.holdMs,jitterPx:e.jitterPx,doubleTap:e.doubleTap})}function tP(e){return"ref"in e&&void 0!==e.ref?tS({kind:"ref",ref:e.ref,label:e.label}):"selector"in e&&void 0!==e.selector?{kind:"selector",selector:e.selector}:{kind:"point",x:e.x,y:e.y}}function t$(e){let t=tF(e);if("string"==typeof t.ref)return[t.ref,...tO(t.label)];if("string"==typeof t.selector)return[t.selector];if("point"===t.kind||void 0!==t.x||void 0!==t.y)return[String(tz(t.x,"x")),String(tz(t.y,"y"))];throw new a("INVALID_ARGS","interaction requires @ref, selector, or point target")}function tF(e){if(!e||"object"!=typeof e||Array.isArray(e))throw new a("INVALID_ARGS","Expected target object.");let t=e.target;return t&&"object"==typeof t&&!Array.isArray(t)?t:e}function tz(e,t){if("number"!=typeof e||!Number.isFinite(e))throw new a("INVALID_ARGS",`point target requires numeric ${t}.`);return e}function tO(e){return"string"==typeof e&&e.length>0?[e]:[]}function tq(e){return e.join(" ").trim()||void 0}function tG(...e){return new Set(e)}function tT(e,t){return void 0!==e&&t.has(e)}function tV(e){return void 0!==e&&""!==e.trim()&&Number.isFinite(Number(e))}function tC(e){return void 0===e?void 0:Number(e)}function tU(e){return void 0===e?[]:[e]}function tB(e){return void 0===e?[]:[String(e)]}function tH(e,t){if(void 0===e||""===e)throw new a("INVALID_ARGS",t);return e}function tJ(e,t){if("string"!=typeof e||0===e.length)throw new a("INVALID_ARGS",t);return e}let tK={devices:(e,t)=>tM(t),apps:(e,t)=>({...tM(t),appsFilter:u(t.appsFilter)}),session:(e,t)=>({...tM(t),action:function(e){let t=e??"list";if("list"===t)return t;throw new a("INVALID_ARGS","session only supports list")}(e[0])}),boot:(e,t)=>({...tM(t),headless:t.headless}),open:(e,t)=>({...tM(t),app:e[0],url:e[1],surface:t.surface,activity:t.activity,launchConsole:t.launchConsole,relaunch:t.relaunch,saveScript:t.saveScript,noRecord:t.noRecord}),close:(e,t)=>({...tM(t),app:e[0],shutdown:t.shutdown,saveScript:t.saveScript}),install:tY,reinstall:tY,"install-from-source":(e,t)=>({...tM(t),source:function(e,t){let r=e[0]?.trim();if(e.length>1)throw new a("INVALID_ARGS","install-from-source accepts either one <url> positional or --github-actions-artifact");let n=t.githubActionsArtifact?function(e,t="--github-actions-artifact"){let r=e.indexOf(":");if(r<=0||r===e.length-1)throw new a("INVALID_ARGS",`${t} must use owner/repo:artifact, for example thymikee/RNCLI83:6635342232`);let{owner:n,repo:i}=eV(e.slice(0,r),t);return eT(n,i,e.slice(r+1),`${t} artifact`)}(t.githubActionsArtifact):void 0,i=t.installSource;if(1!=+!!r+ +!!n+ +!!i)throw new a("INVALID_ARGS","install-from-source requires exactly one source: <url>, --github-actions-artifact, or config installSource");if(!r&&t.header&&t.header.length>0)throw new a("INVALID_ARGS","install-from-source --header is only supported for URL sources");return n||i||{kind:"url",url:r,headers:function(e){if(!e||0===e.length)return;let t={};for(let r of e){let e=r.indexOf(":");if(e<=0)throw new a("INVALID_ARGS",`Invalid --header value "${r}". Expected "name:value".`);let n=r.slice(0,e).trim(),i=r.slice(e+1).trim();if(!n)throw new a("INVALID_ARGS",`Invalid --header value "${r}". Header name cannot be empty.`);t[n]=i}return t}(t.header)}}(e,t),retainPaths:t.retainPaths,retentionMs:t.retentionMs}),push:(e,t)=>({...tM(t),app:tH(e[0],"push requires bundleOrPackage"),payload:tH(e[1],"push requires payloadOrJson")}),"trigger-app-event":(e,t)=>({...tM(t),event:tH(e[0],"trigger-app-event requires event"),payload:e[1]?function(e,t){try{let t=JSON.parse(e);if(t&&"object"==typeof t&&!Array.isArray(t))return t}catch{}throw new a("INVALID_ARGS",`${t} must be a JSON object`)}(e[1],"trigger-app-event payload"):void 0})},tW={devices:tD(N.devices),boot:tD(N.boot),apps:tD(N.apps),open:tD(N.open,function(e){return e.app?e.url?[e.app,e.url]:[e.app]:[]}),close:tD(N.close,e=>tU(e.app)),install:tD(N.install,e=>tZ(e.app,e.appPath)),reinstall:tD(N.reinstall,e=>tZ(e.app,e.appPath)),"install-from-source":e=>tR(k.installSource,[],{...e,installSource:e.source,retainMaterializedPaths:e.retainPaths,materializedPathRetentionMs:e.retentionMs}),push:tD(N.push,e=>{var t;return[(t=e).app,"string"==typeof t.payload?t.payload:JSON.stringify(t.payload)]}),"trigger-app-event":tD(N.triggerAppEvent,e=>{var t;return[(t=e).event,...t.payload?[JSON.stringify(t.payload)]:[]]})};function tY(e,t,r="install"){return{...tM(t),app:tH(e[0],`${r} requires app`),appPath:tH(e[1],`${r} requires path`)}}function tZ(e,t){return[tJ(e,"missing first positional"),tJ(t,"missing second positional")]}function tQ(e){if(!e)return null;let t=Number(e);return Number.isFinite(t)?t:null}function tX(e,t){if(void 0===e||""===e.trim())throw new a("INVALID_ARGS",`settings location set requires ${t}`);return t1(Number(e),t)}function t0(e){return{latitude:t1(e?.latitude,"latitude"),longitude:t1(e?.longitude,"longitude")}}function t1(e,t){let r="latitude"===t?-90:-180,n="latitude"===t?90:180;if("number"!=typeof e||!Number.isFinite(e)||e<r||e>n)throw new a("INVALID_ARGS",`${t} must be a number from ${r} to ${n}`);return e}let t2={snapshot:(e,t)=>({...tM(t),interactiveOnly:t.snapshotInteractiveOnly,compact:t.snapshotCompact,depth:t.snapshotDepth,scope:t.snapshotScope,raw:t.snapshotRaw,forceFull:t.snapshotForceFull}),screenshot:(e,t)=>({...tM(t),path:e[0]??t.out,...U(t)}),diff:(e,t)=>{if("snapshot"!==e[0])throw new a("INVALID_ARGS","Only diff snapshot is available through this parser.");return{...tM(t),kind:"snapshot",out:t.out,interactiveOnly:t.snapshotInteractiveOnly,compact:t.snapshotCompact,depth:t.snapshotDepth,scope:t.snapshotScope,raw:t.snapshotRaw}},wait:(e,t)=>(function(e,t){let r=t8(e);if(!r)throw new a("INVALID_ARGS","wait requires <ms>, text <text>, @ref, or <selector> [timeoutMs].");let n={...t_(t),...tL(t)};if("sleep"===r.kind)return{...n,durationMs:r.durationMs};if("text"===r.kind){if(!r.text)throw new a("INVALID_ARGS","wait requires text.");return{...n,text:r.text,...t4(r.timeoutMs)}}return"ref"===r.kind?{...n,ref:r.rawRef,...t4(r.timeoutMs)}:{...n,selector:r.selectorExpression,...t4(r.timeoutMs)}})(e,t),alert:(e,t)=>({...tM(t),...function(e){if(e.length>2)throw new a("INVALID_ARGS","alert accepts at most action and timeout arguments.");return tS({action:function(e){let t=e?.toLowerCase();if(void 0===t||"get"===t||"accept"===t||"dismiss"===t||"wait"===t)return t;throw new a("INVALID_ARGS","alert action must be get, accept, dismiss, or wait.")}(e[0]),timeoutMs:function(e,t){if(void 0===e)return;let r=Number(e);if(Number.isFinite(r))return r;throw new a("INVALID_ARGS",`${t} must be a finite number.`)}(e[1],"alert timeout")})}(e)}),settings:(e,t)=>(function(e,t){let r=t_(t),n=e[0],i=e[1];if(tT(n,t9)&&tT(i,t6))return{...r,setting:n,state:i};if("location"===n&&"set"===i)return{...r,setting:n,state:i,latitude:tX(e[2],"latitude"),longitude:tX(e[3],"longitude")};if("appearance"===n&&tT(i,t5)||tT(n,t7)&&tT(i,re)||"fingerprint"===n&&tT(i,rt))return{...r,setting:n,state:i};if("permission"===n&&tT(i,rr))return{...r,setting:n,state:i,permission:function(e){if(tT(e,rn))return e;throw new a("INVALID_ARGS","settings permission requires a permission target.")}(e[2]),mode:function(e){if(void 0===e||"full"===e||"limited"===e)return e;throw new a("INVALID_ARGS","settings permission mode must be full or limited.")}(e[3])};throw new a("INVALID_ARGS","Invalid settings arguments.")})(e,t)},t3={snapshot:tD(N.snapshot),screenshot:e=>tR(N.screenshot,tU(e.path),{...e,...B(e)}),diff:tD(N.diff,e=>[tJ(e.kind,"diff requires kind")]),wait:tD(N.wait,e=>(function(e){if(1!==[void 0!==e.durationMs?"durationMs":void 0,void 0!==e.text?"text":void 0,void 0!==e.ref?"ref":void 0,void 0!==e.selector?"selector":void 0].filter(Boolean).length)throw new a("INVALID_ARGS","wait command requires exactly one of durationMs, text, ref, or selector.");if(void 0!==e.durationMs)return[String(e.durationMs)];let t=tB(e.timeoutMs);if(void 0!==e.text)return["text",e.text,...t];if(void 0!==e.ref)return[e.ref,...t];let r=e.selector;if(!l(r))throw new a("INVALID_ARGS",`Invalid wait selector: ${r}`);return[r,...t]})(e)),alert:tD(N.alert,e=>{var t;return[(t=e).action??"get",...tB(t.timeoutMs)]}),settings:tD(N.settings,e=>{var t;return"location"===(t=e).setting&&"set"===t.state?[t.setting,t.state,String(t.latitude),String(t.longitude)]:"permission"===t.setting?[t.setting,t.state,t.permission,...tU(t.mode)]:[t.setting,t.state]})};function t8(e){let t=e[0];if(void 0===t)return null;let r=tQ(t);if(null!==r)return{kind:"sleep",durationMs:r};let n=tQ(e[e.length-1]);if("text"===t)return{kind:"text",text:(null!==n?e.slice(1,-1).join(" "):e.slice(1).join(" ")).trim(),timeoutMs:n};if(t.startsWith("@"))return{kind:"ref",rawRef:t,timeoutMs:n};let i=s(null!==n?e.slice(0,-1):e.slice());return i&&0===i.rest.length&&l(i.selectorExpression)?{kind:"selector",selectorExpression:i.selectorExpression,timeoutMs:n}:{kind:"text",text:(null!==n?e.slice(0,-1).join(" "):e.join(" ")).trim(),timeoutMs:n}}function t4(e){return null===e?{}:{timeoutMs:e}}let t9=tG("wifi","airplane","location","animations"),t6=tG("on","off"),t5=tG("light","dark","toggle"),t7=tG("faceid","touchid"),re=tG("match","nonmatch","enroll","unenroll"),rt=tG("match","nonmatch"),rr=tG("grant","deny","reset"),rn=tG("camera","microphone","photos","contacts","contacts-limited","notifications","calendar","location","location-always","media-library","motion","reminders","siri","accessibility","screen-recording","input-monitoring"),ri={gesture:function(e,t){let r=e[0],n=e.slice(1),i=tM(t);switch(r){case"pan":return{...i,kind:r,origin:{x:Number(n[0]),y:Number(n[1])},delta:{x:Number(n[2]),y:Number(n[3])},durationMs:tC(n[4])};case"fling":return{...i,kind:r,direction:n[0],origin:{x:Number(n[1]),y:Number(n[2])},distance:tC(n[3]),durationMs:tC(n[4])};case"pinch":return{...i,kind:r,scale:Number(n[0]),origin:void 0===n[1]||void 0===n[2]?void 0:{x:Number(n[1]),y:Number(n[2])}};case"rotate":return{...i,kind:r,degrees:Number(n[0]),origin:void 0===n[1]||void 0===n[2]?void 0:{x:Number(n[1]),y:Number(n[2])},velocity:tC(n[3])};case"transform":return{...i,kind:r,origin:{x:Number(n[0]),y:Number(n[1])},delta:{x:Number(n[2]),y:Number(n[3])},scale:Number(n[4]),degrees:Number(n[5]),durationMs:tC(n[6])};default:throw new a("INVALID_ARGS","gesture requires pan, fling, pinch, rotate, or transform")}}},ro={gesture:tD(N.gesture,function(e){switch(e.kind){case"pan":return["pan",String(e.origin?.x),String(e.origin?.y),String(e.delta?.x),String(e.delta?.y),...tB(e.durationMs)];case"fling":return["fling",tJ(e.direction,"gesture fling requires direction"),String(e.origin?.x),String(e.origin?.y),...tB(e.distance),...tB(e.durationMs)];case"pinch":return["pinch",String(e.scale),...tB(e.origin?.x),...tB(e.origin?.y)];case"rotate":return["rotate",String(e.degrees),...tB(e.origin?.x),...tB(e.origin?.y),...tB(e.velocity)];case"transform":return["transform",String(e.origin?.x),String(e.origin?.y),String(e.delta?.x),String(e.delta?.y),String(e.scale),String(e.degrees),...tB(e.durationMs)];default:throw new a("INVALID_ARGS","gesture requires pan, fling, pinch, rotate, or transform")}}),"gesture-pan":tD(N.gesture,function(e){return["pan",String(e.x),String(e.y),String(e.dx),String(e.dy),...tB(e.durationMs)]}),"gesture-fling":tD(N.gesture,e=>{var t;let r;return r=void 0!==(t=e).durationMs?t.distance??180:t.distance,["fling",t.direction,String(t.x),String(t.y),...tB(r),...tB(t.durationMs)]}),"gesture-pinch":tD(N.gesture,function(e){return["pinch",String(e.scale),...tB(e.x),...tB(e.y)]}),"gesture-rotate":tD(N.gesture,e=>(function(e){var t=e;if(void 0===t.x&&void 0!==t.y||void 0!==t.x&&void 0===t.y)throw new a("INVALID_ARGS","gesture rotate center requires both x and y");let r=void 0===e.x||void 0===e.y?[]:[String(e.x),String(e.y)];return["rotate",String(e.degrees),...r,...tB(e.velocity)]})(e)),"gesture-transform":tD(N.gesture,function(e){return["transform",String(e.x),String(e.y),String(e.dx),String(e.dy),String(e.scale),String(e.degrees),...tB(e.durationMs)]})},ra={click:(e,t)=>({...tM(t),...tE(t),...tj(t),target:tP(rl(e)),button:t.clickButton}),press:(e,t)=>({...tM(t),...tE(t),...tj(t),target:tP(rl(e))}),longpress:(e,t)=>{let r,n={...rl((r=function(e){if(tV(e[0])&&tV(e[1]))return{target:e.slice(0,2),...void 0!==e[2]?{durationMs:Number(e[2])}:{}};let t=e.at(-1);return e.length>1&&tV(t)?{target:e.slice(0,-1),durationMs:Number(t)}:{target:e}}(e)).target),...void 0!==r.durationMs?{durationMs:r.durationMs}:{}};return{...tM(t),...tE(t),target:tP(n),durationMs:n.durationMs}},swipe:(e,t)=>({...tM(t),from:{x:Number(e[0]),y:Number(e[1])},to:{x:Number(e[2]),y:Number(e[3])},durationMs:tC(e[4]),count:t.count,pauseMs:t.pauseMs,pattern:t.pattern}),focus:(e,t)=>({...tM(t),x:Number(e[0]),y:Number(e[1])}),type:(e,t)=>({...tM(t),text:e.join(" "),delayMs:t.delayMs}),fill:(e,t)=>{let r=ru(e);return{...tM(t),...tE(t),target:tP(r.target),text:r.text,delayMs:t.delayMs}},scroll:(e,t)=>({...tM(t),direction:function(e){if("up"===e||"down"===e||"left"===e||"right"===e||"top"===e||"bottom"===e)return e;throw new a("INVALID_ARGS",`Unknown direction: ${String(e)}`)}(e[0]),amount:tC(e[1]),pixels:t.pixels}),get:(e,t)=>({...tM(t),...tE(t),format:function(e){if("text"===e||"attrs"===e)return e;throw new a("INVALID_ARGS","get only supports text or attrs")}(e[0]),target:tP(function(e){if(e[0]?.startsWith("@"))return{ref:e[0],label:tq(e.slice(1))};let t=e.join(" ").trim();if(!t)throw new a("INVALID_ARGS","get requires @ref or selector expression");return{selector:t}}(e.slice(1)))})},rs={click:e=>tR(N.click,t$(e),{...e,clickButton:e.button}),press:tD(N.press,e=>t$(e)),longpress:tD(N.longPress,e=>{var t;return[...t$(t=e),...tB(t.durationMs)]}),swipe:tD(N.swipe,function(e){return[String(e.from?.x),String(e.from?.y),String(e.to?.x),String(e.to?.y),...tB(e.durationMs)]}),focus:tD(N.focus,e=>[String(e.x),String(e.y)]),type:tD(N.type,e=>[e.text]),fill:tD(N.fill,e=>{var t;return[...t$(t=e),t.text]}),scroll:tD(N.scroll,e=>[tJ(e.direction,"scroll requires direction"),...tB(e.amount)]),get:tD(N.get,e=>[tJ(e.format,"get requires format"),...function(e){let t=tF(e);if("string"==typeof t.ref)return[t.ref,...tO(t.label)];if("string"==typeof t.selector)return[t.selector];throw new a("INVALID_ARGS","element command requires @ref or selector target")}(e)])};function rl(e){if(e[0]?.startsWith("@")){let t=tq(e.slice(1));return{ref:e[0],...void 0===t?{}:{label:t}}}let t=s(e);return t?{selector:t.selectorExpression}:{x:Number(e[0]),y:Number(e[1])}}function ru(e){let t=e[0];if(t?.startsWith("@")){let r=e.length>=3?e.slice(2).join(" "):e.slice(1).join(" ");return{kind:"ref",target:{ref:t,label:e.length>=3?tq(e.slice(1,2)):void 0},text:r}}let r=s(e,{preferTrailingValue:!0});return r?{kind:"selector",target:{selector:r.selectorExpression},text:r.rest.join(" ")}:{kind:"point",target:{x:Number(e[0]),y:Number(e[1])},text:e.slice(2).join(" ")}}let rc={perf:(e,t)=>tM(t),logs:(e,t)=>({...tM(t),action:function(e){if(void 0!==e){if("path"===e||"start"===e||"stop"===e||"doctor"===e||"mark"===e||"clear"===e)return e;throw new a("INVALID_ARGS","logs requires path, start, stop, doctor, mark, or clear")}}(e[0]),message:e.slice(1).join(" ")||void 0,restart:t.restart}),network:(e,t)=>({...tM(t),action:function(e){if(void 0!==e){if("dump"===e||"log"===e)return e;throw new a("INVALID_ARGS","network requires dump or log")}}(e[0]),limit:tC(e[1]),include:t.networkInclude??function(e){if(void 0!==e){if("summary"===e||"headers"===e||"body"===e||"all"===e)return e;throw new a("INVALID_ARGS","network include mode must be summary, headers, body, or all")}}(e[2])}),record:(e,t)=>({...tM(t),action:rf(e[0],"record"),path:e[1],fps:t.fps,quality:t.quality,hideTouches:t.hideTouches}),trace:(e,t)=>({...tM(t),action:rf(e[0],"trace"),path:e[1]})},rd={perf:tD(N.perf),logs:tD(N.logs,e=>{var t;return[(t=e).action??"path",...tU(t.message)]}),network:e=>{var t;return tR(N.network,[...(t=e).action?[t.action]:[],...tB(t.limit)],{...e,networkInclude:e.include})},record:tD(N.record,e=>rp(e)),trace:tD(N.trace,e=>rp(e))};function rp(e){return[e.action,...tU(e.path)]}function rf(e,t){if("start"===e||"stop"===e)return e;throw new a("INVALID_ARGS",`${t} requires start|stop`)}let rm={replay:(e,t)=>({...tM(t),path:tH(e[0],"replay requires path"),update:t.replayUpdate,backend:t.replayMaestro?"maestro":void 0,env:t.replayEnv}),test:(e,t)=>({...tM(t),paths:e,update:t.replayUpdate,backend:t.replayMaestro?"maestro":void 0,env:t.replayEnv,failFast:t.failFast,timeoutMs:t.timeoutMs,retries:t.retries,artifactsDir:t.artifactsDir,reportJunit:t.reportJunit})};function rh(e){return e.backend??(!0===e.maestro?"maestro":void 0)}function rg(e){let t={};for(let[r,n]of Object.entries(e))"string"==typeof n&&r.startsWith("AD_VAR_")&&(t[r]=n);return t}let rv={find:(e,t)=>(function(e,t){var r;let n={...{depth:(r=t).snapshotDepth,raw:r.snapshotRaw},...t_(t),first:t.findFirst,last:t.findLast},i=function(e){if("text"===e||"label"===e||"value"===e||"role"===e||"id"===e)return e}(e[0]),o=void 0!==i,s=o?e[1]:e[0],l=o?2:1,u=e[l];if(void 0===u)return{...n,locator:i,query:rb(s)};if("get"===u){let t=e[l+1];if("text"===t)return{...n,locator:i,query:rb(s),action:"getText"};if("attrs"===t)return{...n,locator:i,query:rb(s),action:"getAttrs"};throw new a("INVALID_ARGS","find get only supports text or attrs")}if("wait"===u)return{...n,locator:i,query:rb(s),action:"wait",timeoutMs:tC(e[l+1])};if("fill"===u||"type"===u)return{...n,locator:i,query:rb(s),action:u,value:e.slice(l+1).join(" ")};if("click"===u||"focus"===u||"exists"===u)return{...n,locator:i,query:rb(s),action:u};throw new a("INVALID_ARGS",`Unsupported find action: ${u}`)})(e,t),is:(e,t)=>(function(e,t){let r={...tL(t),...t_(t)},n=e[0],i=function(e,t={}){let r=s(e,t);if(!r)throw new a("INVALID_ARGS","is requires a selector expression");return r}(e.slice(1),{preferTrailingValue:"text"===n});if("text"===n)return{...r,predicate:n,selector:i.selectorExpression,value:i.rest.join(" ")};if("visible"===n||"hidden"===n||"exists"===n||"editable"===n||"selected"===n)return{...r,predicate:n,selector:i.selectorExpression};throw new a("INVALID_ARGS","is requires predicate: visible|hidden|exists|editable|selected|text")})(e,t)},ry={is:tD(N.is,e=>{var t;return[(t=e).predicate,t.selector,..."text"===t.predicate?[t.value]:[]]}),find:e=>tR(N.find,function(e){let t=e.locator&&"any"!==e.locator?[e.locator,e.query]:[e.query];switch(e.action){case void 0:case"click":case"focus":case"exists":return e.action?[...t,e.action]:t;case"getText":return[...t,"get","text"];case"getAttrs":return[...t,"get","attrs"];case"wait":return[...t,"wait",...tB(e.timeoutMs)];case"fill":case"type":return[...t,e.action,e.value]}}(e),{...e,findFirst:e.first,findLast:e.last})};function rb(e){if(void 0===e||""===e)throw new a("INVALID_ARGS","find requires query");return e}function rw(e){if(void 0===e)throw new a("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 a("INVALID_ARGS",`Invalid rotation: ${e}. Use portrait|portrait-upside-down|landscape-left|landscape-right.`)}}let rS={appstate:(e,t)=>tM(t),home:(e,t)=>tM(t),"app-switcher":(e,t)=>tM(t),back:(e,t)=>({...tM(t),mode:t.backMode}),rotate:(e,t)=>({...tM(t),orientation:rw(e[0])}),keyboard:(e,t)=>({...tM(t),...function(e){if(e.length>1)throw new a("INVALID_ARGS","keyboard accepts at most one action argument.");return tS({action:function(e){let t=e?.toLowerCase();if("get"===t)return"status";if(void 0===t||"status"===t||"dismiss"===t||"enter"===t||"return"===t)return t;throw new a("INVALID_ARGS","keyboard action must be status, get, dismiss, enter, or return.")}(e[0])})}(e)}),clipboard:(e,t)=>({...tM(t),...function(e){let t=e[0]?.toLowerCase();if("read"!==t&&"write"!==t)throw new a("INVALID_ARGS","clipboard requires a subcommand: read or write.");if("read"===t){if(1!==e.length)throw new a("INVALID_ARGS","clipboard read does not accept additional arguments.");return{action:t}}if(e.length<2)throw new a("INVALID_ARGS","clipboard write requires text.");return{action:t,text:e.slice(1).join(" ")}}(e)}),"react-native":(e,t)=>({...tM(t),action:function(e){if("dismiss-overlay"===e)return e;throw new a("INVALID_ARGS","react-native supports only: dismiss-overlay")}(e[0])})},rI={appstate:tD(N.appState),back:e=>{var t;return tR(N.back,[],{...e,backMode:"in-app"===(t=e.mode)||"system"===t?t:void 0})},home:tD(N.home),rotate:tD(N.rotate,e=>[tJ(e.orientation,"rotate requires orientation")]),"app-switcher":tD(N.appSwitcher),keyboard:tD(N.keyboard,e=>tU(e.action)),clipboard:tD(N.clipboard,e=>{var t;return"read"===(t=e).action?["read"]:["write",t.text]}),"react-native":tD(N.reactNative,e=>[tJ(e.action,"react-native requires action")])},rA={...tW,...t3,...rs,...ro,...ry,...rd,replay:e=>tR(N.replay,[tJ(e.path,"replay requires path")],{...e,replayUpdate:e.update,replayBackend:rh(e),replayEnv:e.env,replayShellEnv:rg(process.env)}),test:e=>tR(N.test,e.paths??[],{...e,replayUpdate:e.update,replayBackend:rh(e),replayEnv:e.env,replayShellEnv:rg(process.env)}),...rI,batch:e=>tR(N.batch,[],{...e,batchSteps:function(e){if(!Array.isArray(e)||0===e.length)throw new a("INVALID_ARGS","batch requires a non-empty steps array.");return e.map((e,t)=>{var r;let n,i,o,s,l,u;return o=function(e,t){let r="string"==typeof e.command?e.command.trim().toLowerCase():"";if(rk.has(r))return r;throw new a("INVALID_ARGS",`Batch step ${t} command is not available through command batch: ${String(e.command)}`)}(i=function(e,t){if(!e||"object"!=typeof e||Array.isArray(e))throw new a("INVALID_ARGS",`Invalid batch step ${t}.`);return e}(e,r=t+1),r),s=function(e,t){let r=e.input;if(!r||"object"!=typeof r||Array.isArray(r))throw new a("INVALID_ARGS",`Batch step ${t} input must be an object.`);return r}(i,r),l=function(e,t){let r=e.runtime;if(void 0!==r&&(!r||"object"!=typeof r||Array.isArray(r)))throw new a("INVALID_ARGS",`Batch step ${t} runtime must be an object.`);return r}(i,r),{...u={command:(n=rD(o,s)).command,positionals:n.positionals,flags:ez(n.options),runtime:n.options.runtime},runtime:l??u.runtime}})}(e.steps),batchOnError:e.onError,batchMaxSteps:e.maxSteps})},rx=new Set(["replay","batch","gesture-pan","gesture-fling","gesture-pinch","gesture-rotate","gesture-transform"]),rN=Object.keys(rA).filter(e=>!rx.has(e)),rk=new Set(rN);function rD(e,t){return rA[e](t)}export{_ as DAEMON_COMMAND_GROUPS,R as GESTURE_SUBCOMMAND_ERROR,k as INTERNAL_COMMANDS,N as PUBLIC_COMMANDS,V as SCREENSHOT_ACTION_FLAG_KEYS,T as SCREENSHOT_COMMAND_FLAG_KEYS,C as SCREENSHOT_SPECIFIC_FLAG_DEFINITIONS,tK as appCliReaders,H as appendScreenshotScriptFlags,tw as assertAllowedKeys,rN as batchCommandNames,e1 as booleanField,eW as booleanSchema,ez as buildFlags,eO as buildMeta,t2 as captureCliReaders,ta as command_input_readPoint,tM as commonInputFromFlags,th as commonToClientOptions,I as computeDaemonCodeSignature,c as consumeTextLines,e9 as customField,e5 as elementTargetField,e2 as enumField,tr as fieldsInputSchema,p as findProjectRoot,G as formatRequestProgressEvent,ri as gestureCliReaders,e0 as integerField,eK as integerSchema,ra as interactionCliReaders,e6 as interactionTargetField,$ as isDaemonProgressEnvelope,F as isDaemonResponseEnvelope,e4 as jsonSchemaField,L as listCliCommandNames,j as listMcpExposedCommandNames,e3 as looseObjectField,eY as looseObjectSchema,eN as normalizeDeployResult,eR as normalizeDevice,ek as normalizeInstallFromSourceResult,eD as normalizeMaterializationReleaseResult,ej as normalizeOpenDevice,eL as normalizeRuntimeHints,eM as normalizeSession,eP as normalizeStartupSample,v as normalizeTenantId,eX as numberField,rc as observabilityCliReaders,tm as optionalEnum,td as optionalInteger,rw as parseDeviceRotation,eG as parseInstallSourceConfig,tQ as parseTimeout,t8 as parseWaitPositionals,e7 as pointField,rD as prepareDaemonCommandRequest,Z as readCommandMessage,to as readCommonInput,tn as readFieldInput,ru as readFillTargetFromPositionals,ti as readInputRecord,rl as readInteractionTargetFromPositionals,tX as readLocationCoordinate,ep as readOptionalString,ed as readRequiredString,eF as readScreenshotOverlayRefs,J as readScreenshotScriptFlag,e$ as readSnapshotNodes,d as readVersion,tt as repeatedFields,rm as replayCliReaders,t0 as requireLocationCoordinates,tf as requiredEnum,eZ as requiredField,tu as requiredNumber,S as resolveDaemonCodeSignature,f as resolveDaemonPaths,m as resolveDaemonServerMode,h as resolveDaemonTransportPreference,en as resolveDeployResultTarget,eo as resolveInstallFromSourceResultTarget,g as resolveSessionIsolationMode,eq as resolveSessionName,B as screenshotFlagsFromOptions,U as screenshotOptionsFromFlags,rv as selectorCliReaders,te as selectorSnapshotFields,el as serializeCloseResult,z as serializeDaemonProgressEnvelope,O as serializeDaemonResponseEnvelope,q as serializeDaemonRpcResponseEnvelope,ei as serializeDeployResult,er as serializeDevice,ea as serializeInstallFromSourceResult,es as serializeOpenResult,et as serializeSessionListEntry,eu as serializeSnapshotResult,P as shouldStreamRequestProgress,ex as splitNonEmptyTrimmedLines,e8 as stringArrayField,eQ as stringField,eJ as stringSchema,W as successText,rS as systemCliReaders,tv as toClientElementTarget,tg as toClientInteractionTarget,ty as toRepeatedOptions,tb as toSelectorSnapshotOptions,Y as withSuccessText};
|