agent-device 0.19.3 → 0.20.1

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.
Files changed (179) hide show
  1. package/README.md +62 -70
  2. package/android/ime-helper/dist/agent-device-android-ime-helper-0.20.1.apk +0 -0
  3. package/android/ime-helper/dist/agent-device-android-ime-helper-0.20.1.apk.sha256 +1 -0
  4. package/android/ime-helper/dist/agent-device-android-ime-helper-0.20.1.manifest.json +10 -0
  5. package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.1.apk +0 -0
  6. package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.1.apk.sha256 +1 -0
  7. package/{android-snapshot-helper/dist/agent-device-android-snapshot-helper-0.19.3.manifest.json → android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.1.manifest.json} +6 -6
  8. package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerAXSnapshotBridge.h +2 -0
  9. package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerAXSnapshotBridge.m +5 -0
  10. package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedGesture.h +5 -10
  11. package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedGesture.m +74 -174
  12. package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Alert.swift +113 -19
  13. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+BlockingSystemModalResolution.swift +82 -0
  14. package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +325 -123
  15. package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandJournal.swift +2 -2
  16. package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift +149 -105
  17. package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Lifecycle.swift +56 -2
  18. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+LifecycleCacheTests.swift +73 -0
  19. package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +51 -26
  20. package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScrollGesture.swift +2 -2
  21. package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SequenceExecution.swift +2 -107
  22. package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Snapshot.swift +130 -13
  23. package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotCapturePlan.swift +51 -8
  24. package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotTraversalIdentityTests.swift +24 -0
  25. package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedGesturePolicy.swift +1 -1
  26. package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SystemModal.swift +43 -35
  27. package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntry.swift +1 -1
  28. package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift +16 -1
  29. package/dist/src/agent-browser-tool.js +1 -1
  30. package/dist/src/agent-device-client.js +3 -0
  31. package/dist/src/android-adb.d.ts +1 -1
  32. package/dist/src/android-adb.js +1 -1
  33. package/dist/src/android-input-method-overlays.js +1 -0
  34. package/dist/src/android-input-ownership.js +1 -6
  35. package/dist/src/android-system-chrome.js +1 -0
  36. package/dist/src/android.js +1 -1
  37. package/dist/src/app-lifecycle.js +5 -5
  38. package/dist/src/app-log-request-scope.js +1 -0
  39. package/dist/src/app-resolution.js +1 -0
  40. package/dist/src/apple-multitouch-support.js +1 -0
  41. package/dist/src/apps.js +5 -5
  42. package/dist/src/boot-diagnostics.js +2 -0
  43. package/dist/src/cli-config.js +1 -0
  44. package/dist/src/cli-help.js +131 -40
  45. package/dist/src/cli-runner.js +1 -1
  46. package/dist/src/cli.js +15 -11
  47. package/dist/src/command-metadata.js +1 -1
  48. package/dist/src/command-schema.js +3 -3
  49. package/dist/src/compatibility-policy.js +1 -0
  50. package/dist/src/context.js +1 -0
  51. package/dist/src/contracts.d.ts +2 -2
  52. package/dist/src/debug-symbols.js +1 -1
  53. package/dist/src/device-input-state.js +1 -1
  54. package/dist/src/devices2.js +1 -1
  55. package/dist/src/devices4.js +1 -0
  56. package/dist/src/find.js +1 -1
  57. package/dist/src/finders.js +1 -1
  58. package/dist/src/generic.js +1 -1
  59. package/dist/src/helper.js +1 -1
  60. package/dist/src/index.d.ts +533 -279
  61. package/dist/src/index.js +1 -1
  62. package/dist/src/input-actions.js +4 -3
  63. package/dist/src/install-artifact.js +1 -0
  64. package/dist/src/install-source.d.ts +5 -1
  65. package/dist/src/install-source.js +1 -1
  66. package/dist/src/install-source2.js +1 -1
  67. package/dist/src/interaction-snapshot.js +1 -1
  68. package/dist/src/interaction.d.ts +230 -0
  69. package/dist/src/interaction.js +1 -1
  70. package/dist/src/interactor.js +2 -2
  71. package/dist/src/interactor2.js +1 -0
  72. package/dist/src/internal/bin.js +1 -1
  73. package/dist/src/internal/daemon.js +42 -20
  74. package/dist/src/internal/png-worker.d.ts +22 -0
  75. package/dist/src/internal/png-worker.js +1 -1
  76. package/dist/src/launch-console.js +1 -0
  77. package/dist/src/lease-context.js +1 -0
  78. package/dist/src/lease.js +1 -1
  79. package/dist/src/linux.js +1 -1
  80. package/dist/src/logcat.js +5 -0
  81. package/dist/src/method-scope.js +1 -0
  82. package/dist/src/metro-types.d.ts +52 -0
  83. package/dist/src/metro.d.ts +3 -3
  84. package/dist/src/notifications.js +1 -1
  85. package/dist/src/png-worker-contract.js +1 -1
  86. package/dist/src/process-lock.js +1 -0
  87. package/dist/src/react-native.js +1 -1
  88. package/dist/src/record-trace.js +1 -1
  89. package/dist/src/recording-export-quality.js +15 -0
  90. package/dist/src/register-builtins.js +1 -0
  91. package/dist/src/registry.js +24 -24
  92. package/dist/src/remote-config.d.ts +1 -1
  93. package/dist/src/reporting.js +8 -7
  94. package/dist/src/runner-client.js +1 -1
  95. package/dist/src/runner-disposal.js +2 -0
  96. package/dist/src/runner-lease.js +1 -0
  97. package/dist/src/runner-provider.js +1 -1
  98. package/dist/src/runner-sequence.js +1 -1
  99. package/dist/src/runtime.js +3 -3
  100. package/dist/src/runtime2.js +1 -0
  101. package/dist/src/sdk-android-adb.d.ts +97 -33
  102. package/dist/src/sdk-android-adb.js +4 -4
  103. package/dist/src/sdk-batch-runner.d.ts +2 -1
  104. package/dist/src/sdk-batch-runner.js +3 -2
  105. package/dist/src/sdk-contracts.d.ts +70 -149
  106. package/dist/src/sdk-contracts.js +1 -1
  107. package/dist/src/sdk-device.js +1 -1
  108. package/dist/src/sdk-finders.d.ts +5 -4
  109. package/dist/src/sdk-finders.js +1 -1
  110. package/dist/src/sdk-io.d.ts +1 -1
  111. package/dist/src/sdk-remote-config.d.ts +19 -96
  112. package/dist/src/sdk-remote-config.js +1 -1
  113. package/dist/src/sdk-selectors.js +1 -1
  114. package/dist/src/selector-runtime.js +1 -1
  115. package/dist/src/selector-vocabulary.js +1 -0
  116. package/dist/src/selectors.d.ts +12 -3
  117. package/dist/src/selectors.js +1 -1
  118. package/dist/src/server.js +3 -3
  119. package/dist/src/session-target-evidence.js +1 -0
  120. package/dist/src/session.js +8 -10
  121. package/dist/src/simctl.js +1 -1
  122. package/dist/src/simulator.js +1 -1
  123. package/dist/src/snapshot-diagnostics.js +5 -2
  124. package/dist/src/snapshot-quality.js +1 -1
  125. package/dist/src/snapshot.js +1 -1
  126. package/dist/src/snapshot2.js +1 -2
  127. package/dist/src/tool-provider3.js +1 -0
  128. package/dist/src/unsupported-interactor.js +1 -0
  129. package/dist/src/url.js +1 -1
  130. package/dist/src/web.js +1 -1
  131. package/package.json +34 -27
  132. package/server.json +2 -2
  133. package/skills/agent-device/SKILL.md +5 -3
  134. package/android-multitouch-helper/dist/agent-device-android-multitouch-helper-0.19.3.apk +0 -0
  135. package/android-multitouch-helper/dist/agent-device-android-multitouch-helper-0.19.3.apk.sha256 +0 -1
  136. package/android-multitouch-helper/dist/agent-device-android-multitouch-helper-0.19.3.manifest.json +0 -10
  137. package/android-snapshot-helper/dist/agent-device-android-snapshot-helper-0.19.3.apk +0 -0
  138. package/android-snapshot-helper/dist/agent-device-android-snapshot-helper-0.19.3.apk.sha256 +0 -1
  139. package/dist/src/apple-runner-options.js +0 -1
  140. package/dist/src/cli-output.js +0 -1
  141. package/dist/src/client.js +0 -3
  142. package/dist/src/handler-utils.js +0 -1
  143. package/dist/src/output-path.js +0 -1
  144. package/dist/src/points.js +0 -4
  145. package/dist/src/provider.js +0 -1
  146. package/dist/src/providers.js +0 -1
  147. package/dist/src/record-trace-recording.js +0 -23
  148. package/dist/src/recording-provider.js +0 -1
  149. package/dist/src/sdk-batch.js +0 -2
  150. package/dist/src/selectors2.js +0 -1
  151. package/dist/src/ttl-memo.js +0 -1
  152. package/dist/src/tv-remote.js +0 -14
  153. package/dist/src/xml.js +0 -2
  154. /package/{macos-helper → apple/macos-helper}/Package.swift +0 -0
  155. /package/{macos-helper → apple/macos-helper}/Sources/AgentDeviceMacOSHelper/AudioProbe.swift +0 -0
  156. /package/{macos-helper → apple/macos-helper}/Sources/AgentDeviceMacOSHelper/SnapshotTraversal.swift +0 -0
  157. /package/{macos-helper → apple/macos-helper}/Sources/AgentDeviceMacOSHelper/main.swift +0 -0
  158. /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerApp.m +0 -0
  159. /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunner.xcodeproj/project.pbxproj +0 -0
  160. /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunner.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -0
  161. /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunner.xcodeproj/xcshareddata/xcschemes/AgentDeviceRunner.xcscheme +0 -0
  162. /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/AgentDeviceRunnerUITests-Bridging-Header.h +0 -0
  163. /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/AgentDeviceRunnerUITests.entitlements +0 -0
  164. /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerObjCExceptionCatcher.h +0 -0
  165. /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerObjCExceptionCatcher.m +0 -0
  166. /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTapPointPolicy.swift +0 -0
  167. /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AXSnapshotFallback.swift +0 -0
  168. /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Environment.swift +0 -0
  169. /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Exceptions.swift +0 -0
  170. /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+FlatSnapshotFiltering.swift +0 -0
  171. /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Navigation.swift +0 -0
  172. /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScreenRecorder.swift +0 -0
  173. /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Transport.swift +0 -0
  174. /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TvRemote.swift +0 -0
  175. /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests.xctestplan +0 -0
  176. /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/RecordingScripts/recording-overlay.swift +0 -0
  177. /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/RecordingScripts/recording-resize.swift +0 -0
  178. /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/RecordingScripts/recording-trim.swift +0 -0
  179. /package/{src/platforms/linux → linux}/atspi-dump.py +0 -0
@@ -1,4 +1,4 @@
1
- import{t as e}from"./rolldown-runtime.js";import{T as t,_ as n}from"./sdk-contracts.js";import{AsyncLocalStorage as r}from"node:async_hooks";import i from"node:crypto";import a,{constants as o}from"node:fs";import s from"node:os";import c from"node:path";import{pipeline as l}from"node:stream/promises";import{Readable as u}from"node:stream";import{access as d,stat as f}from"node:fs/promises";import{spawn as p,spawnSync as m}from"node:child_process";const h=new r;function g(){return i.randomBytes(8).toString(`hex`)}function ee(){return`${Date.now().toString(36)}-${i.randomBytes(4).toString(`hex`)}`}async function te(e,t){let n={...e,diagnosticId:ee(),events:[],liveWrittenEventCount:0,phaseCounts:new Map};return await h.run(n,t)}function ne(e){let t=h.getStore();t&&Object.assign(t,e)}function re(){let e=h.getStore();return e?{diagnosticId:e.diagnosticId,requestId:e.requestId,session:e.session,command:e.command,debug:e.debug,flushOnSuccess:e.flushOnSuccess}:{}}function ie(e){let t=h.getStore();if(!t)return 0;let n=0;for(let r of e)n+=t.phaseCounts.get(r)??0;return n}function _(e){let n=h.getStore();if(!n)return;let r={ts:new Date().toISOString(),level:e.level??`info`,phase:e.phase,session:n.session,requestId:n.requestId,command:n.command,durationMs:e.durationMs,data:e.data?t(e.data):void 0};if(n.events.push(r),n.phaseCounts.set(e.phase,(n.phaseCounts.get(e.phase)??0)+1),!n.debug)return;let i=`${JSON.stringify(r)}\n`;try{n.logPath&&(v(n.logPath,i),n.liveWrittenEventCount=n.events.length),n.traceLogPath&&v(n.traceLogPath,i),!n.logPath&&!n.traceLogPath&&process.stderr.write(`[agent-device][diag] ${i}`)}catch{}}async function ae(e,t,n){let r=Date.now();try{let i=await t();return _({level:`info`,phase:e,durationMs:Date.now()-r,data:n}),i}catch(t){throw _({level:`error`,phase:e,durationMs:Date.now()-r,data:{...n??{},error:t instanceof Error?t.message:String(t)}}),t}}function oe(e={}){let n=h.getStore();if(!n||!e.force&&!n.debug&&!n.flushOnSuccess||n.events.length===0)return null;try{if(n.logPath){let e=n.events.slice(n.liveWrittenEventCount);if(e.length>0){let r=e.map(e=>JSON.stringify(t(e)));v(n.logPath,`${r.join(`
2
- `)}\n`)}let r=n.logPath;return n.events=[],n.liveWrittenEventCount=0,r}let e=se(n.session??`default`),r=new Date().toISOString().slice(0,10),i=c.join(s.homedir(),`.agent-device`,`logs`,e,r);a.mkdirSync(i,{recursive:!0});let o=new Date().toISOString().replace(/[:.]/g,`-`),l=c.join(i,`${o}-${n.diagnosticId}.ndjson`),u=n.events.map(e=>JSON.stringify(t(e)));return a.writeFileSync(l,`${u.join(`
3
- `)}\n`),n.events=[],l}catch{return null}}function se(e){return e.replace(/[^a-zA-Z0-9._-]/g,`_`)}function v(e,t){a.mkdirSync(c.dirname(e),{recursive:!0}),a.appendFileSync(e,t,`utf8`)}const ce=new Set([`1`,`true`,`yes`,`on`]),le=new Set([`0`,`false`,`no`,`off`]);function ue(e){return`AGENT_DEVICE_${e.replace(/([A-Z])/g,`_$1`).replace(/[^A-Za-z0-9_]/g,`_`).toUpperCase()}`}function de(e,t,r,i){if(e.multiple)return(Array.isArray(t)?t:[t]).map(t=>de({...e,multiple:!1},t,r,i));if(e.type===`boolean`)return fe(t,r,i);if(e.type===`booleanOrString`){if(typeof t==`boolean`)return t;if(typeof t==`string`&&y(t)!==void 0)return y(t);if(typeof t==`string`&&t.trim().length>0)return t;throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected boolean or non-empty string.`)}if(e.type===`string`){if(typeof t==`string`&&t.trim().length>0)return t;throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected non-empty string.`)}if(e.type===`enum`){if(e.setValue!==void 0)return pe(e,t,r,i);if(typeof t!=`string`||!e.enumValues?.includes(t))throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected one of: ${e.enumValues?.join(`, `)}.`);return t}let a=typeof t==`number`?t:typeof t==`string`?Number(t):NaN;if(!Number.isFinite(a)||!Number.isInteger(a))throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected integer.`);if(typeof e.min==`number`&&a<e.min)throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Must be >= ${e.min}.`);if(typeof e.max==`number`&&a>e.max)throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Must be <= ${e.max}.`);return a}function fe(e,t,r){if(typeof e==`boolean`)return e;if(typeof e==`string`){let t=y(e);if(t!==void 0)return t}throw new n(`INVALID_ARGS`,`Invalid value for "${r}" in ${t}. Expected boolean.`)}function y(e){let t=e.trim().toLowerCase();if(ce.has(t))return!0;if(le.has(t))return!1}function pe(e,t,r,i){let a=e.setValue;if(t===a)return a;if(typeof t==`string`){let e=t.trim();if(e===``||e===`true`||e===`1`)return a;if(e===`false`||e===`0`)return}if(t===!0)return a;if(t!==!1)throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected boolean-like value for enum flag.`)}const me=/^[A-Za-z0-9][A-Za-z0-9._+-]*$/,he=[`.com`,`.exe`,`.bat`,`.cmd`],b=new r;async function ge(e,t){return e?await b.run(e,t):await t()}async function x(e){return await b.run(void 0,e)}async function _e(e,t,n={}){let r=b.getStore()?.(e,t,n);return r?S(await r):await C(e,t,n)}async function ve(e,t,n={}){let r=b.getStore()?.(e,t,n);return r?S(await r):await C(e,t,n)}function S(e){let t=typeof e.stdout==`string`?e.stdout:String(e.stdout??``),n=typeof e.stderr==`string`?e.stderr:String(e.stderr??``),r=typeof e.exitCode==`number`?e.exitCode:1;return t===e.stdout&&n===e.stderr&&r===e.exitCode?e:{...e,stdout:t,stderr:n,exitCode:r}}function C(e,t,n={}){let r=O(e),i=E();return new Promise((a,o)=>{let s=p(r,t,{cwd:n.cwd,env:n.env,stdio:[`pipe`,`pipe`,`pipe`],detached:n.detached,windowsHide:!0,shell:!1});n.onSpawn?.(s);let c=``,l=n.binaryStdout?[]:void 0,u=``,d=!1,f=B(n.timeoutMs),m=f?setTimeout(()=>{d=!0,H(s,n.detached)},f):null,h=V(s,n);n.binaryStdout||s.stdout.setEncoding(`utf8`),s.stderr.setEncoding(`utf8`),je(s,n.stdin).catch(i=>{h.didAbort||d||Me(i)||(o(Ee(r,e,t,i)),H(s,n.detached))}),s.stdout.on(`data`,e=>{if(n.binaryStdout){l?.push(Buffer.isBuffer(e)?e:Buffer.from(e));return}let t=String(e);c+=t,n.onStdoutChunk?.(t)}),s.stderr.on(`data`,e=>{let t=String(e);u+=t,n.onStderrChunk?.(t)}),s.on(`error`,n=>{m&&clearTimeout(m),h.dispose(),i.emitForegroundCompletion(e,t),o(P(h,r,e,t,n))}),s.on(`close`,s=>{m&&clearTimeout(m),h.dispose(),i.emitForegroundCompletion(e,t);let p=s??1;if(!h.didAbort&&d&&f){o(De(r,e,t,f,p,c,u));return}let g=F(h,r,e,t,p,n.allowFailure,c,u);if(g){o(g);return}a({stdout:c,stderr:u,exitCode:p,stdoutBuffer:l?Buffer.concat(l):void 0})})})}async function ye(e){let t=L(e);if(!t)return!1;if(c.isAbsolute(t))return R(t);let n=process.env.PATH;if(!n)return!1;let r=ke();for(let e of n.split(c.delimiter)){let n=e.trim();if(n){for(let e of Ae(t,r))if(await R(c.join(n,e)))return!0}}return!1}async function be(e,t){let r=I(e,t,`executable`);if(r){if(!await R(r))throw new n(`TOOL_MISSING`,`${t} points to a missing or non-executable file: ${r}`,{envName:t,path:r});return r}}async function xe(e,t){let r=I(e,t,`file`);if(r){if(!await z(r))throw new n(`TOOL_MISSING`,`${t} points to a missing or non-file path: ${r}`,{envName:t,path:r});return r}}function Se(e,t,r={}){let i=O(e),a=m(i,t,{cwd:r.cwd,env:r.env,stdio:[`pipe`,`pipe`,`pipe`],encoding:r.binaryStdout?void 0:`utf8`,input:r.stdin,timeout:B(r.timeoutMs),windowsHide:!0,shell:!1,...r.maxBuffer===void 0?{}:{maxBuffer:r.maxBuffer}});if(a.error){let o=a.error.code;throw o===`ETIMEDOUT`?new n(`COMMAND_FAILED`,`${i} timed out after ${B(r.timeoutMs)}ms`,{cmd:e,args:t,timeoutMs:B(r.timeoutMs)},a.error):o===`ENOENT`?k(i,e,a.error):A(i,e,t,a.error)}let o=r.binaryStdout?Buffer.isBuffer(a.stdout)?a.stdout:Buffer.from(a.stdout??``):void 0,s=r.binaryStdout?``:typeof a.stdout==`string`?a.stdout:(a.stdout??``).toString(),c=typeof a.stderr==`string`?a.stderr:(a.stderr??``).toString(),l=a.status??1;if(l!==0&&!r.allowFailure)throw M(i,e,t,l,s,c);return{stdout:s,stderr:c,exitCode:l,stdoutBuffer:o}}function Ce(e,t,n={}){return w(e,t,n).pid}function w(e,t,n={}){let r=p(O(e),t,{cwd:n.cwd,env:n.env,stdio:n.stdio??`ignore`,detached:!0,windowsHide:!0,shell:!1}),i=r.pid??0,a=new Promise(e=>{r.once(`error`,t=>{e({pid:i,error:t.message})}),r.once(`exit`,(t,n)=>{e({pid:i,...typeof t==`number`?{exitCode:t}:{},...n?{signal:n}:{}})})});return r.unref(),{pid:i,exited:a}}function T(e,t,n={}){let r=O(e),i=E(),a=p(r,t,{cwd:n.cwd,env:n.env,stdio:n.stdio??[`ignore`,`pipe`,`pipe`],detached:n.detached,windowsHide:!0,shell:!1});i.emitBackgroundSpawn(e,t);let o=``,s=``,c=n.captureOutput??!0,l=V(a,n);return c&&(a.stdout?.setEncoding(`utf8`),a.stderr?.setEncoding(`utf8`),a.stdout?.on(`data`,e=>{o+=e}),a.stderr?.on(`data`,e=>{s+=e})),{child:a,wait:new Promise((c,u)=>{a.on(`error`,n=>{l.dispose(),i.emitBackgroundCompletion(e,t,`error`),u(P(l,r,e,t,n))}),a.on(`close`,a=>{l.dispose(),i.emitBackgroundCompletion(e,t,`exit`);let d=a??1,f=F(l,r,e,t,d,n.allowFailure,o,s);if(f){u(f);return}c({stdout:o,stderr:s,exitCode:d})})})}}function E(){let e=re(),t=e.debug===!0,n=y(process.env.AGENT_DEVICE_EXEC_TRACE??``)===!0;if(!t&&!n)return we();n&&e.flushOnSuccess!==!0&&ne({flushOnSuccess:!0});let r=Date.now(),i=!1;return{emitForegroundCompletion:(e,t)=>{i||(i=!0,D({cmd:e,args:t,startedAtMs:r}))},emitBackgroundSpawn:(e,t)=>{D({cmd:e,args:t,data:{event:`spawn`}})},emitBackgroundCompletion:(e,t,n)=>{i||(i=!0,D({cmd:e,args:t,startedAtMs:r,data:{event:n}}))}}}function we(){return{emitForegroundCompletion:()=>{},emitBackgroundSpawn:()=>{},emitBackgroundCompletion:()=>{}}}function D(e){let t=e.args.slice(0,6);_({level:`debug`,phase:`exec_command`,durationMs:e.startedAtMs===void 0?void 0:Math.max(0,Date.now()-e.startedAtMs),data:{command:e.cmd,argsPrefix:t,...e.args.length>t.length?{omittedArgCount:e.args.length-t.length}:{},...e.data??{}}})}function O(e){let t=L(e);if(!t)throw new n(`INVALID_ARGS`,`Invalid executable command: ${JSON.stringify(e)}`,{cmd:e,hint:`Use a bare command name from PATH or an absolute executable path.`});return t}function Te(e,t,n,r){return r.code===`ENOENT`?k(e,t,r):A(e,t,n,r)}function k(e,t,r){return new n(`TOOL_MISSING`,`${e} not found in PATH`,{cmd:t},r)}function A(e,t,r,i){return new n(`COMMAND_FAILED`,`Failed to run ${e}`,{cmd:t,args:r},i)}function Ee(e,t,r,i){return new n(`COMMAND_FAILED`,`Failed to write stdin for ${e}`,{cmd:t,args:r},i instanceof Error?i:void 0)}function j(e,t,r){return new n(`COMMAND_FAILED`,`request canceled`,{cmd:t,args:r,executable:e,reason:`request_canceled`})}function De(e,t,r,i,a,o,s){return new n(`COMMAND_FAILED`,`${e} timed out after ${i}ms`,{cmd:t,args:r,stdout:o,stderr:s,exitCode:a,timeoutMs:i})}function M(e,t,r,i,a,o){return new n(`COMMAND_FAILED`,`${e} exited with code ${i}`,N({stdout:a,stderr:o,exitCode:i},{cmd:t,args:r}))}function Oe(e,t,r){if(e.exitCode===0)return e;throw new n(`COMMAND_FAILED`,t,N(e,typeof r==`function`?r(e):r))}function N(e,t){return{stdout:e.stdout,stderr:e.stderr,exitCode:e.exitCode,processExitError:!0,...t}}function P(e,t,n,r,i){return e.didAbort?j(t,n,r):Te(t,n,r,i)}function F(e,t,n,r,i,a,o,s){return e.didAbort?j(t,n,r):i!==0&&!a?M(t,n,r,i,o,s):null}function I(e,t,r){let i=e?.trim();if(i){if(!c.isAbsolute(i)||i.includes(`\0`))throw new n(`INVALID_ARGS`,`${t} must be an absolute ${r} path, not ${JSON.stringify(e)}`,{envName:t,path:e});return i}}function L(e){let t=e.trim();return!t||t.includes(`\0`)?null:c.isAbsolute(t)?t:t.includes(`/`)||t.includes(`\\`)?null:me.test(t)?t:null}function ke(){if(process.platform!==`win32`)return[``];let e=process.env.PATHEXT;if(!e)return he;let t=e.split(`;`).map(e=>e.trim().toLowerCase()).filter(e=>e.length>0);return t.length>0?t:he}function Ae(e,t){if(process.platform!==`win32`)return[e];let n=e.toLowerCase();return t.some(e=>n.endsWith(e))?[e]:t.map(t=>`${e}${t}`)}async function R(e){try{return await z(e)?(await d(e,process.platform===`win32`?o.F_OK:o.X_OK),!0):!1}catch{return!1}}async function z(e){try{return(await f(e)).isFile()}catch{return!1}}function B(e){if(!Number.isFinite(e))return;let t=Math.floor(e);if(!(t<=0))return t}function V(e,t){let n=!1,r=()=>{n=!0,H(e,t.detached)};return t.signal?.aborted?r():t.signal?.addEventListener(`abort`,r,{once:!0}),{get didAbort(){return n},dispose:()=>{t.signal?.removeEventListener(`abort`,r)}}}function H(e,t){if(t&&e.pid&&process.platform!==`win32`)try{process.kill(-e.pid,`SIGKILL`);return}catch{}e.kill(`SIGKILL`)}async function je(e,t){if(e.stdin){if(t===void 0){e.stdin?.end();return}await l(u.from([t]),e.stdin)}}function Me(e){return e instanceof Error&&`code`in e&&e.code===`EPIPE`}var Ne=e({androidAdbResultError:()=>K,attachAdbFailureHint:()=>G,classifyAdbFailure:()=>W,createAndroidPortReverseManager:()=>We,createDeviceAdbExecutor:()=>Y,createLocalAndroidAdbProvider:()=>Ve,installAndroidAdbPackage:()=>Ke,pullAndroidAdbFile:()=>Ge,resolveAndroidAdbExecutor:()=>He,resolveAndroidAdbProvider:()=>X,resolveAndroidTextInjector:()=>Ue,resolveAndroidTouchInjector:()=>Z,withAndroidAdbProvider:()=>Je});const U=new r,Pe=[{reason:`device_unauthorized`,pattern:/device unauthorized|device still authorizing/,hint:`USB debugging is not authorized — accept the authorization prompt on the device screen (re-plug the cable if none appears), then retry.`},{reason:`device_offline`,pattern:/device offline/,hint:`The device is connected but offline — wait for it to finish booting or run adb reconnect, then retry.`,retriable:!0},{reason:`multiple_devices`,pattern:/more than one (?:device\/emulator|device and emulator)/,hint:`Multiple Android devices are connected — pass --serial <serial> (see adb devices) to select one.`},{reason:`no_devices`,pattern:/no devices\/emulators found|no devices found/,hint:`No Android devices detected — boot an emulator or connect a device and verify it appears in adb devices.`},{reason:`device_not_found`,pattern:/device (?:'[^']*' )?not found/,hint:`The device disconnected or is restarting — verify it is listed in adb devices, then retry.`,retriable:!0},{reason:`server_version_mismatch`,pattern:/adb server version \(\d+\) doesn't match this client/,hint:`Multiple adb installs conflict — adb restarts its server automatically, so retry; align PATH to a single adb to stop recurrences.`,retriable:!0},{reason:`connection_dropped`,pattern:/transport error|connection reset|broken pipe|protocol fault/,hint:`The adb connection dropped — retry; if it persists, run adb kill-server and reconnect the device.`,retriable:!0},{reason:`install_insufficient_storage`,pattern:/install_failed_insufficient_storage/,hint:`The device is out of storage — free up space or uninstall unused apps, then retry the install.`,matchStdout:!0},{reason:`install_update_incompatible`,pattern:/install_failed_update_incompatible/,hint:`The installed app has an incompatible signature — uninstall the existing app first, then retry the install.`,matchStdout:!0},{reason:`install_version_downgrade`,pattern:/install_failed_version_downgrade/,hint:`The APK is older than the installed app — uninstall the app first (or install with downgrade allowed), then retry.`,matchStdout:!0},{reason:`install_failed`,pattern:/install_failed_\w+|install_parse_failed_\w+/,hint:`The Android package installer rejected the APK — see the INSTALL_FAILED code in the error output for the exact cause.`,matchStdout:!0}],Fe={reason:`timeout`,hint:`adb timed out — the adb server may be wedged. Run adb kill-server && adb start-server, check adb devices, then retry.`};function W(e,t=``){let n=e.toLowerCase(),r=t.toLowerCase();for(let{pattern:e,matchStdout:t,...i}of Pe)if(e.test(n)||t&&e.test(r))return i}function G(e){if(!(e instanceof n)||e.code!==`COMMAND_FAILED`)return e;let t=Ie(e);return t&&(e.details={...e.details,adbFailure:t.reason,...typeof e.details?.hint==`string`?{}:{hint:t.hint},...t.retriable!==void 0&&e.details?.retriable===void 0?{retriable:t.retriable}:{}}),e}function Ie(e){return typeof e.details?.timeoutMs==`number`?Fe:W(typeof e.details?.stderr==`string`?e.details.stderr:``,typeof e.details?.stdout==`string`?e.details.stdout:``)}function K(e,t,r){return G(new n(`COMMAND_FAILED`,e,t.exitCode===0?{stdout:t.stdout,stderr:t.stderr,exitCode:t.exitCode,...r}:N(t,r)))}function q(e){return async(...t)=>{try{return await e(...t)}catch(e){throw G(e)}}}const Le=new WeakSet;function Re(e){if(Le.has(e))return e;let t={...e,exec:q(J(e.exec)),...e.pull?{pull:q(J(e.pull))}:{},...e.install?{install:q(J(e.install))}:{},...e.installBundle?{installBundle:q(e.installBundle)}:{}};return Le.add(t),t}function J(e){return async(...t)=>S(await e(...t))}function Y(e){return ze(e.id)}function ze(e){return q(async(t,n)=>await x(async()=>await _e(`adb`,[`-s`,e,...t],{...n,detached:process.platform!==`win32`})))}function Be(e){return(t,n)=>{let r=T(`adb`,[`-s`,e,...t],{...n,allowFailure:!0,captureOutput:!1});return r.wait.catch(()=>{}),r.child}}function Ve(e){let t=Y(e);return{exec:t,spawn:Be(e.id),reverse:Ze(t),pull:async(e,n,r)=>await t([`pull`,e,n],r),install:async(e,n)=>{let{installArgs:r,execOptions:i}=$(n);return await t([`install`,...r,e],i)}}}function He(e,t){let n=U.getStore();return t||(n?.serial===e.id?n.provider.exec:Y(e))}function X(e,t){if(t)return Q(t);let n=U.getStore();return n?.serial===e.id?Q(n.provider):Ve(e)}function Ue(e){let t=U.getStore();return t?.serial===e.id?t.provider.text:void 0}function Z(e){let t=U.getStore();return t?.serial===e.id?t.provider.touch:void 0}function We(e){let t=Q(e),r=t.reverse??Ze(t.exec),i=new Map;return{async ensure(e,t){let a=i.get(e.local);if(a&&a.ownerId!==e.ownerId)throw new n(`COMMAND_FAILED`,`Android port reverse ${e.local} is already owned by ${a.ownerId??`another session`}`,{current:a,requested:e});a?.remote!==e.remote&&(await r.ensure(e,t),i.set(e.local,{...e}))},async remove(e,t){if(!i.has(e)){await r.remove(e,t);return}await r.remove(e,t),i.delete(e)},async removeAllOwned(e,t){let n=[...i.values()].filter(t=>t.ownerId===e).map(e=>e.local);if(n.length===0){await r.removeAllOwned(e,t);return}for(let e of n)await r.remove(e,t),i.delete(e)},async list(e){return r.list?await r.list(e):[...i.values()]}}}function Q(e){return Re(typeof e==`function`?{exec:e}:e)}async function Ge(e,t,r){let{device:i,provider:a,...o}=r??{},s=qe(i,a),c=s?.pull;if(c)return await x(async()=>await c(e,t,o));let l=s?.exec;if(!l)throw new n(`COMMAND_FAILED`,`Android adb pull requires an adb provider`);return await x(async()=>await l([`pull`,e,t],o))}async function Ke(e,t){let{device:r,provider:i,...a}=t??{},o=qe(r,i),s=o?.install;if(s)return await x(async()=>await s(e,a));let c=o?.exec;if(!c)throw new n(`COMMAND_FAILED`,`Android adb install requires an adb provider`);let{installArgs:l,execOptions:u}=$(a);return await x(async()=>await c([`install`,...l,e],u))}function qe(e,t){if(t)return Q(t);if(e)return X(e);let n=U.getStore();if(n)return Q(n.provider)}async function Je(e,t,n){if(!e)return await n();let r={provider:Q(e),serial:t.serial},i=Ye(r);return await U.run(r,async()=>await ge(i,n))}function Ye(e){return(t,n,r)=>{if(t!==`adb`)return;let i=Xe(n,e.serial);if(i)return x(async()=>await e.provider.exec(i,r))}}function Xe(e,t){if(!(e[0]!==`-s`||!e[1])&&e[1]===t)return e.slice(2)}function Ze(e){let t=new Map;return{async ensure(n,r){if(await e([`reverse`,n.local,n.remote],{allowFailure:!1,signal:r?.signal,timeoutMs:r?.timeoutMs}),n.ownerId){let e=t.get(n.ownerId)??new Set;e.add(n.local),t.set(n.ownerId,e)}},async remove(n,r){let i=await e([`reverse`,`--remove`,n],{allowFailure:!0,signal:r?.signal,timeoutMs:r?.timeoutMs});if(i.exitCode!==0&&!$e(i.stdout,i.stderr))throw K(`Failed to remove Android port reverse ${n}`,i,{local:n});for(let e of t.values())e.delete(n)},async removeAllOwned(e,n){let r=[...t.get(e)??[]];for(let e of r)await this.remove(e,n);t.delete(e)},async list(n){let r=await e([`reverse`,`--list`],{allowFailure:!0,signal:n?.signal,timeoutMs:n?.timeoutMs});return r.exitCode===0?Qe(r.stdout,t):[]}}}function Qe(e,t){let n=new Map;for(let[e,r]of t)for(let t of r)n.set(t,e);return e.split(`
4
- `).map(e=>e.trim().split(/\s+/)).filter(e=>e.length>=3).map(([,e,t])=>{let r=e;return{local:r,remote:t,ownerId:n.get(r)}})}function $e(e,t){let n=`${e}\n${t}`.toLowerCase();return n.includes(`listener`)&&n.includes(`not found`)}function $(e){let{replace:t,allowTestPackages:n,allowDowngrade:r,grantPermissions:i,...a}=e??{},o=[];return t&&o.push(`-r`),n&&o.push(`-t`),r&&o.push(`-d`),i&&o.push(`-g`),{installArgs:o,execOptions:a}}export{g as A,Se as C,y as D,ue as E,ae as F,te as I,oe as M,re as N,de as O,ne as P,ve as S,x as T,xe as _,We as a,Ce as b,He as c,Z as d,S as f,be as g,Oe as h,W as i,_ as j,ie as k,X as l,R as m,K as n,Ke as o,N as p,G as r,Ge as s,Ne as t,Ue as u,_e as v,ye as w,w as x,T as y};
1
+ import{t as e}from"./rolldown-runtime.js";import{T as t,_ as n}from"./sdk-contracts.js";import{AsyncLocalStorage as r}from"node:async_hooks";import i from"node:crypto";import a,{constants as o}from"node:fs";import s from"node:os";import c from"node:path";import{pipeline as l}from"node:stream/promises";import{Readable as u}from"node:stream";import{access as d,stat as f}from"node:fs/promises";import{spawn as p,spawnSync as m}from"node:child_process";const h=new r;function g(){return i.randomBytes(8).toString(`hex`)}function ee(){return`${Date.now().toString(36)}-${i.randomBytes(4).toString(`hex`)}`}async function te(e,t){let n={...e,diagnosticId:ee(),events:[],liveWrittenEventCount:0,phaseCounts:new Map,sensitiveValues:new Set};return await h.run(n,t)}function _(e){let t=h.getStore();t&&Object.assign(t,e)}function ne(){let e=h.getStore();return e?{diagnosticId:e.diagnosticId,requestId:e.requestId,session:e.session,command:e.command,debug:e.debug,flushOnSuccess:e.flushOnSuccess}:{}}function re(e){e&&h.getStore()?.sensitiveValues.add(e)}function ie(e){let t=h.getStore();if(!t)return 0;let n=0;for(let r of e)n+=t.phaseCounts.get(r)??0;return n}function v(e){let t=h.getStore();if(!t)return;let n={ts:new Date().toISOString(),level:e.level??`info`,phase:e.phase,session:t.session,requestId:t.requestId,command:t.command,durationMs:e.durationMs,data:e.data?y(t,e.data):void 0};if(t.events.push(n),t.phaseCounts.set(e.phase,(t.phaseCounts.get(e.phase)??0)+1),!t.debug&&!t.traceLogPath)return;let r=`${JSON.stringify(n)}\n`;try{t.debug&&t.logPath&&(x(t.logPath,r),t.liveWrittenEventCount=t.events.length),t.traceLogPath&&x(t.traceLogPath,r),t.debug&&!t.logPath&&!t.traceLogPath&&process.stderr.write(`[agent-device][diag] ${r}`)}catch{}}async function ae(e,t,n){let r=Date.now();try{let i=await t();return v({level:`info`,phase:e,durationMs:Date.now()-r,data:n}),i}catch(t){throw v({level:`error`,phase:e,durationMs:Date.now()-r,data:{...n??{},error:t instanceof Error?t.message:String(t)}}),t}}function oe(e={}){let t=h.getStore();if(!t||!e.force&&!t.debug&&!t.flushOnSuccess||t.events.length===0)return null;try{if(t.logPath){let e=t.events.slice(t.liveWrittenEventCount);if(e.length>0){let n=e.map(e=>JSON.stringify(y(t,e)));x(t.logPath,`${n.join(`
2
+ `)}\n`)}let n=t.logPath;return t.events=[],t.liveWrittenEventCount=0,n}let e=se(t.session??`default`),n=new Date().toISOString().slice(0,10),r=c.join(s.homedir(),`.agent-device`,`logs`,e,n);a.mkdirSync(r,{recursive:!0});let i=new Date().toISOString().replace(/[:.]/g,`-`),o=c.join(r,`${i}-${t.diagnosticId}.ndjson`),l=t.events.map(e=>JSON.stringify(y(t,e)));return a.writeFileSync(o,`${l.join(`
3
+ `)}\n`),t.events=[],o}catch{return null}}function y(e,n){return b(t(n),[...e.sensitiveValues].sort((e,t)=>t.length-e.length))}function b(e,t){return typeof e==`string`?t.reduce((e,t)=>e.replaceAll(t,`[REDACTED]`),e):Array.isArray(e)?e.map(e=>b(e,t)):!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).map(([e,n])=>[e,b(n,t)]))}function se(e){return e.replace(/[^a-zA-Z0-9._-]/g,`_`)}function x(e,t){a.mkdirSync(c.dirname(e),{recursive:!0}),a.appendFileSync(e,t,`utf8`)}const ce=new Set([`1`,`true`,`yes`,`on`]),le=new Set([`0`,`false`,`no`,`off`]);function ue(e){return`AGENT_DEVICE_${e.replace(/([A-Z])/g,`_$1`).replace(/[^A-Za-z0-9_]/g,`_`).toUpperCase()}`}function de(e,t,r,i){if(e.multiple)return(Array.isArray(t)?t:[t]).map(t=>de({...e,multiple:!1},t,r,i));if(e.type===`boolean`)return fe(t,r,i);if(e.type===`booleanOrString`){if(typeof t==`boolean`)return t;if(typeof t==`string`&&S(t)!==void 0)return S(t);if(typeof t==`string`&&t.trim().length>0)return t;throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected boolean or non-empty string.`)}if(e.type===`string`){if(typeof t==`string`&&t.trim().length>0)return t;throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected non-empty string.`)}if(e.type===`enum`){if(e.setValue!==void 0)return pe(e,t,r,i);if(typeof t!=`string`||!e.enumValues?.includes(t))throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected one of: ${e.enumValues?.join(`, `)}.`);return t}let a=typeof t==`number`?t:typeof t==`string`?Number(t):NaN;if(!Number.isFinite(a)||!Number.isInteger(a))throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected integer.`);if(typeof e.min==`number`&&a<e.min)throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Must be >= ${e.min}.`);if(typeof e.max==`number`&&a>e.max)throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Must be <= ${e.max}.`);return a}function fe(e,t,r){if(typeof e==`boolean`)return e;if(typeof e==`string`){let t=S(e);if(t!==void 0)return t}throw new n(`INVALID_ARGS`,`Invalid value for "${r}" in ${t}. Expected boolean.`)}function S(e){let t=e.trim().toLowerCase();if(ce.has(t))return!0;if(le.has(t))return!1}function pe(e,t,r,i){let a=e.setValue;if(t===a)return a;if(typeof t==`string`){let e=t.trim();if(e===``||e===`true`||e===`1`)return a;if(e===`false`||e===`0`)return}if(t===!0)return a;if(t!==!1)throw new n(`INVALID_ARGS`,`Invalid value for "${i}" in ${r}. Expected boolean-like value for enum flag.`)}const me=/^[A-Za-z0-9][A-Za-z0-9._+-]*$/,he=[`.com`,`.exe`,`.bat`,`.cmd`],C=new r;async function ge(e,t){return e?await C.run(e,t):await t()}async function w(e){return await C.run(void 0,e)}async function T(e,t,n={}){let r=C.getStore()?.(e,t,n);return r?E(await r):await D(e,t,n)}async function _e(e,t,n={}){let r=C.getStore()?.(e,t,n);return r?E(await r):await D(e,t,n)}function E(e){let t=typeof e.stdout==`string`?e.stdout:String(e.stdout??``),n=typeof e.stderr==`string`?e.stderr:String(e.stderr??``),r=typeof e.exitCode==`number`?e.exitCode:1;return t===e.stdout&&n===e.stderr&&r===e.exitCode?e:{...e,stdout:t,stderr:n,exitCode:r}}function D(e,t,n={}){let r=M(e),i=A();return new Promise((a,o)=>{let s=p(r,t,{cwd:n.cwd,env:n.env,stdio:[`pipe`,`pipe`,`pipe`],detached:n.detached,windowsHide:!0,shell:!1});n.onSpawn?.(s);let c=``,l=n.binaryStdout?[]:void 0,u=``,d=!1,f=H(n.timeoutMs),m=f?setTimeout(()=>{d=!0,U(s,n.detached)},f):null,h=Me(s,n);n.binaryStdout||s.stdout.setEncoding(`utf8`),s.stderr.setEncoding(`utf8`),Ne(s,n.stdin).catch(i=>{h.didAbort||d||Pe(i)||(o(Te(r,e,t,i)),U(s,n.detached))}),s.stdout.on(`data`,e=>{if(n.binaryStdout){l?.push(Buffer.isBuffer(e)?e:Buffer.from(e));return}let t=String(e);c+=t,n.onStdoutChunk?.(t)}),s.stderr.on(`data`,e=>{let t=String(e);u+=t,n.onStderrChunk?.(t)}),s.on(`error`,n=>{m&&clearTimeout(m),h.dispose(),i.emitForegroundCompletion(e,t),o(R(h,r,e,t,n))}),s.on(`close`,s=>{m&&clearTimeout(m),h.dispose(),i.emitForegroundCompletion(e,t);let p=s??1;if(!h.didAbort&&d&&f){o(Ee(r,e,t,f,p,c,u));return}let g=z(h,r,e,t,p,n.allowFailure,c,u);if(g){o(g);return}a({stdout:c,stderr:u,exitCode:p,stdoutBuffer:l?Buffer.concat(l):void 0})})})}async function ve(e){let t=Oe(e);if(!t)return!1;if(c.isAbsolute(t))return V(t);let n=process.env.PATH;if(!n)return!1;let r=ke();for(let e of n.split(c.delimiter)){let n=e.trim();if(n){for(let e of Ae(t,r))if(await V(c.join(n,e)))return!0}}return!1}async function ye(e,t){let r=B(e,t,`executable`);if(r){if(!await V(r))throw new n(`TOOL_MISSING`,`${t} points to a missing or non-executable file: ${r}`,{envName:t,path:r});return r}}async function be(e,t){let r=B(e,t,`file`);if(r){if(!await je(r))throw new n(`TOOL_MISSING`,`${t} points to a missing or non-file path: ${r}`,{envName:t,path:r});return r}}function xe(e,t,r={}){let i=M(e),a=m(i,t,{cwd:r.cwd,env:r.env,stdio:[`pipe`,`pipe`,`pipe`],encoding:r.binaryStdout?void 0:`utf8`,input:r.stdin,timeout:H(r.timeoutMs),windowsHide:!0,shell:!1,...r.maxBuffer===void 0?{}:{maxBuffer:r.maxBuffer}});if(a.error){let o=a.error.code;throw o===`ETIMEDOUT`?new n(`COMMAND_FAILED`,`${i} timed out after ${H(r.timeoutMs)}ms`,{cmd:e,args:t,timeoutMs:H(r.timeoutMs)},a.error):o===`ENOENT`?N(i,e,a.error):P(i,e,t,a.error)}let o=r.binaryStdout?Buffer.isBuffer(a.stdout)?a.stdout:Buffer.from(a.stdout??``):void 0,s=r.binaryStdout?``:typeof a.stdout==`string`?a.stdout:(a.stdout??``).toString(),c=typeof a.stderr==`string`?a.stderr:(a.stderr??``).toString(),l=a.status??1;if(l!==0&&!r.allowFailure)throw I(i,e,t,l,s,c);return{stdout:s,stderr:c,exitCode:l,stdoutBuffer:o}}function Se(e,t,n={}){return O(e,t,n).pid}function O(e,t,n={}){let r=p(M(e),t,{cwd:n.cwd,env:n.env,stdio:n.stdio??`ignore`,detached:!0,windowsHide:!0,shell:!1}),i=r.pid??0,a=new Promise(e=>{r.once(`error`,t=>{e({pid:i,error:t.message})}),r.once(`exit`,(t,n)=>{e({pid:i,...typeof t==`number`?{exitCode:t}:{},...n?{signal:n}:{}})})});return r.unref(),{pid:i,exited:a}}function k(e,t,n={}){let r=M(e),i=A(),a=p(r,t,{cwd:n.cwd,env:n.env,stdio:n.stdio??[`ignore`,`pipe`,`pipe`],detached:n.detached,windowsHide:!0,shell:!1});i.emitBackgroundSpawn(e,t);let o=``,s=``,c=n.captureOutput??!0,l=Me(a,n);return c&&(a.stdout?.setEncoding(`utf8`),a.stderr?.setEncoding(`utf8`),a.stdout?.on(`data`,e=>{o+=e}),a.stderr?.on(`data`,e=>{s+=e})),{child:a,wait:new Promise((c,u)=>{a.on(`error`,n=>{l.dispose(),i.emitBackgroundCompletion(e,t,`error`),u(R(l,r,e,t,n))}),a.on(`close`,a=>{l.dispose(),i.emitBackgroundCompletion(e,t,`exit`);let d=a??1,f=z(l,r,e,t,d,n.allowFailure,o,s);if(f){u(f);return}c({stdout:o,stderr:s,exitCode:d})})})}}function A(){let e=ne(),t=e.debug===!0,n=S(process.env.AGENT_DEVICE_EXEC_TRACE??``)===!0;if(!t&&!n)return Ce();n&&e.flushOnSuccess!==!0&&_({flushOnSuccess:!0});let r=Date.now(),i=!1;return{emitForegroundCompletion:(e,t)=>{i||(i=!0,j({cmd:e,args:t,startedAtMs:r}))},emitBackgroundSpawn:(e,t)=>{j({cmd:e,args:t,data:{event:`spawn`}})},emitBackgroundCompletion:(e,t,n)=>{i||(i=!0,j({cmd:e,args:t,startedAtMs:r,data:{event:n}}))}}}function Ce(){return{emitForegroundCompletion:()=>{},emitBackgroundSpawn:()=>{},emitBackgroundCompletion:()=>{}}}function j(e){let t=e.args.slice(0,6);v({level:`debug`,phase:`exec_command`,durationMs:e.startedAtMs===void 0?void 0:Math.max(0,Date.now()-e.startedAtMs),data:{command:e.cmd,argsPrefix:t,...e.args.length>t.length?{omittedArgCount:e.args.length-t.length}:{},...e.data??{}}})}function M(e){let t=Oe(e);if(!t)throw new n(`INVALID_ARGS`,`Invalid executable command: ${JSON.stringify(e)}`,{cmd:e,hint:`Use a bare command name from PATH or an absolute executable path.`});return t}function we(e,t,n,r){return r.code===`ENOENT`?N(e,t,r):P(e,t,n,r)}function N(e,t,r){return new n(`TOOL_MISSING`,`${e} not found in PATH`,{cmd:t},r)}function P(e,t,r,i){return new n(`COMMAND_FAILED`,`Failed to run ${e}`,{cmd:t,args:r},i)}function Te(e,t,r,i){return new n(`COMMAND_FAILED`,`Failed to write stdin for ${e}`,{cmd:t,args:r},i instanceof Error?i:void 0)}function F(e,t,r){return new n(`COMMAND_FAILED`,`request canceled`,{cmd:t,args:r,executable:e,reason:`request_canceled`})}function Ee(e,t,r,i,a,o,s){return new n(`COMMAND_FAILED`,`${e} timed out after ${i}ms`,{cmd:t,args:r,stdout:o,stderr:s,exitCode:a,timeoutMs:i})}function I(e,t,r,i,a,o){return new n(`COMMAND_FAILED`,`${e} exited with code ${i}`,L({stdout:a,stderr:o,exitCode:i},{cmd:t,args:r}))}function De(e,t,r){if(e.exitCode===0)return e;throw new n(`COMMAND_FAILED`,t,L(e,typeof r==`function`?r(e):r))}function L(e,t){return{stdout:e.stdout,stderr:e.stderr,exitCode:e.exitCode,processExitError:!0,...t}}function R(e,t,n,r,i){return e.didAbort?F(t,n,r):we(t,n,r,i)}function z(e,t,n,r,i,a,o,s){return e.didAbort?F(t,n,r):i!==0&&!a?I(t,n,r,i,o,s):null}function B(e,t,r){let i=e?.trim();if(i){if(!c.isAbsolute(i)||i.includes(`\0`))throw new n(`INVALID_ARGS`,`${t} must be an absolute ${r} path, not ${JSON.stringify(e)}`,{envName:t,path:e});return i}}function Oe(e){let t=e.trim();return!t||t.includes(`\0`)?null:c.isAbsolute(t)?t:t.includes(`/`)||t.includes(`\\`)?null:me.test(t)?t:null}function ke(){if(process.platform!==`win32`)return[``];let e=process.env.PATHEXT;if(!e)return he;let t=e.split(`;`).map(e=>e.trim().toLowerCase()).filter(e=>e.length>0);return t.length>0?t:he}function Ae(e,t){if(process.platform!==`win32`)return[e];let n=e.toLowerCase();return t.some(e=>n.endsWith(e))?[e]:t.map(t=>`${e}${t}`)}async function V(e){try{return await je(e)?(await d(e,process.platform===`win32`?o.F_OK:o.X_OK),!0):!1}catch{return!1}}async function je(e){try{return(await f(e)).isFile()}catch{return!1}}function H(e){if(!Number.isFinite(e))return;let t=Math.floor(e);if(!(t<=0))return t}function Me(e,t){let n=!1,r=()=>{n=!0,U(e,t.detached)};return t.signal?.aborted?r():t.signal?.addEventListener(`abort`,r,{once:!0}),{get didAbort(){return n},dispose:()=>{t.signal?.removeEventListener(`abort`,r)}}}function U(e,t){if(t&&e.pid&&process.platform!==`win32`)try{process.kill(-e.pid,`SIGKILL`);return}catch{}e.kill(`SIGKILL`)}async function Ne(e,t){if(e.stdin){if(t===void 0){e.stdin?.end();return}await l(u.from([t]),e.stdin)}}function Pe(e){return e instanceof Error&&`code`in e&&e.code===`EPIPE`}var Fe=e({androidAdbResultError:()=>K,attachAdbFailureHint:()=>G,classifyAdbFailure:()=>Re,createAndroidPortReverseManager:()=>qe,createDeviceAdbExecutor:()=>Y,createLocalAndroidAdbProvider:()=>We,installAndroidAdbPackage:()=>Ye,pullAndroidAdbFile:()=>Je,resolveAndroidAdbExecutor:()=>Ge,resolveAndroidAdbProvider:()=>X,resolveAndroidTextInjector:()=>Ke,resolveAndroidTouchProvider:()=>Z,withAndroidAdbProvider:()=>Ze});const W=new r,Ie=[{reason:`device_unauthorized`,pattern:/device unauthorized|device still authorizing/,hint:`USB debugging is not authorized — accept the authorization prompt on the device screen (re-plug the cable if none appears), then retry.`},{reason:`device_offline`,pattern:/device offline/,hint:`The device is connected but offline — wait for it to finish booting or run adb reconnect, then retry.`,retriable:!0},{reason:`multiple_devices`,pattern:/more than one (?:device\/emulator|device and emulator)/,hint:`Multiple Android devices are connected — pass --serial <serial> (see adb devices) to select one.`},{reason:`no_devices`,pattern:/no devices\/emulators found|no devices found/,hint:`No Android devices detected — boot an emulator or connect a device and verify it appears in adb devices.`},{reason:`device_not_found`,pattern:/device (?:'[^']*' )?not found/,hint:`The device disconnected or is restarting — verify it is listed in adb devices, then retry.`,retriable:!0},{reason:`server_version_mismatch`,pattern:/adb server version \(\d+\) doesn't match this client/,hint:`Multiple adb installs conflict — adb restarts its server automatically, so retry; align PATH to a single adb to stop recurrences.`,retriable:!0},{reason:`connection_dropped`,pattern:/transport error|connection reset|broken pipe|protocol fault/,hint:`The adb connection dropped — retry; if it persists, run adb kill-server and reconnect the device.`,retriable:!0},{reason:`install_insufficient_storage`,pattern:/install_failed_insufficient_storage/,hint:`The device is out of storage — free up space or uninstall unused apps, then retry the install.`,matchStdout:!0},{reason:`install_update_incompatible`,pattern:/install_failed_update_incompatible/,hint:`The installed app has an incompatible signature — uninstall the existing app first, then retry the install.`,matchStdout:!0},{reason:`install_version_downgrade`,pattern:/install_failed_version_downgrade/,hint:`The APK is older than the installed app — uninstall the app first (or install with downgrade allowed), then retry.`,matchStdout:!0},{reason:`install_failed`,pattern:/install_failed_\w+|install_parse_failed_\w+/,hint:`The Android package installer rejected the APK — see the INSTALL_FAILED code in the error output for the exact cause.`,matchStdout:!0}],Le={reason:`timeout`,hint:`adb timed out — the adb server may be wedged. Run adb kill-server && adb start-server, check adb devices, then retry.`};function Re(e,t=``){let n=e.toLowerCase(),r=t.toLowerCase();for(let{pattern:e,matchStdout:t,...i}of Ie)if(e.test(n)||t&&e.test(r))return i}function G(e){if(!(e instanceof n)||e.code!==`COMMAND_FAILED`)return e;let t=ze(e);return t&&(e.details={...e.details,adbFailure:t.reason,...typeof e.details?.hint==`string`?{}:{hint:t.hint},...t.retriable!==void 0&&e.details?.retriable===void 0?{retriable:t.retriable}:{}}),e}function ze(e){return typeof e.details?.timeoutMs==`number`?Le:Re(typeof e.details?.stderr==`string`?e.details.stderr:``,typeof e.details?.stdout==`string`?e.details.stdout:``)}function K(e,t,r){return G(new n(`COMMAND_FAILED`,e,t.exitCode===0?{stdout:t.stdout,stderr:t.stderr,exitCode:t.exitCode,...r}:L(t,r)))}function q(e){return async(...t)=>{try{return await e(...t)}catch(e){throw G(e)}}}const Be=new WeakSet;function Ve(e){if(Be.has(e))return e;let t={...e,exec:q(J(e.exec)),...e.pull?{pull:q(J(e.pull))}:{},...e.install?{install:q(J(e.install))}:{},...e.installBundle?{installBundle:q(e.installBundle)}:{}};return Be.add(t),t}function J(e){return async(...t)=>E(await e(...t))}function Y(e){return He(e.id)}function He(e){return q(async(t,n)=>await w(async()=>await T(`adb`,[`-s`,e,...t],{...n,detached:process.platform!==`win32`})))}function Ue(e){return(t,n)=>{let r=k(`adb`,[`-s`,e,...t],{...n,allowFailure:!0,captureOutput:!1});return r.wait.catch(()=>{}),r.child}}function We(e){let t=Y(e);return{exec:t,spawn:Ue(e.id),reverse:tt(t),pull:async(e,n,r)=>await t([`pull`,e,n],r),install:async(e,n)=>{let{installArgs:r,execOptions:i}=$(n);return await t([`install`,...r,e],i)}}}function Ge(e,t){let n=W.getStore();return t||(n?.serial===e.id?n.provider.exec:Y(e))}function X(e,t){if(t)return Q(t);let n=W.getStore();return n?.serial===e.id?Q(n.provider):We(e)}function Ke(e){let t=W.getStore();return t?.serial===e.id?t.provider.text:void 0}function Z(e){let t=W.getStore();return t?.serial===e.id&&t.provider.touch?t.provider:void 0}function qe(e){let t=Q(e);if(t.reverse&&et.has(t.reverse))return t.reverse;let r=t.reverse??tt(t.exec),i=new Map,a={async ensure(e,t){let a=i.get(e.local);if(a&&a.ownerId!==e.ownerId)throw new n(`COMMAND_FAILED`,`Android port reverse ${e.local} is already owned by ${a.ownerId??`another session`}`,{current:a,requested:e});a?.remote!==e.remote&&(await r.ensure(e,t),i.set(e.local,{...e}))},async remove(e,t){if(!i.has(e)){await r.remove(e,t);return}await r.remove(e,t),i.delete(e)},async removeAllOwned(e,t){let n=[...i.values()].filter(t=>t.ownerId===e).map(e=>e.local);if(n.length===0){await r.removeAllOwned(e,t);return}for(let e of n)await r.remove(e,t),i.delete(e)},async list(e){return r.list?await r.list(e):[...i.values()]}};return et.add(a),a}function Q(e){return Ve(typeof e==`function`?{exec:e}:e)}async function Je(e,t,r){let{device:i,provider:a,...o}=r??{},s=Xe(i,a),c=s?.pull;if(c)return await w(async()=>await c(e,t,o));let l=s?.exec;if(!l)throw new n(`COMMAND_FAILED`,`Android adb pull requires an adb provider`);return await w(async()=>await l([`pull`,e,t],o))}async function Ye(e,t){let{device:r,provider:i,...a}=t??{},o=Xe(r,i),s=o?.install;if(s)return await w(async()=>await s(e,a));let c=o?.exec;if(!c)throw new n(`COMMAND_FAILED`,`Android adb install requires an adb provider`);let{installArgs:l,execOptions:u}=$(a);return await w(async()=>await c([`install`,...l,e],u))}function Xe(e,t){if(t)return Q(t);if(e)return X(e);let n=W.getStore();if(n)return Q(n.provider)}async function Ze(e,t,n){if(!e)return await n();let r={provider:Q(e),serial:t.serial},i=Qe(r);return await W.run(r,async()=>await ge(i,n))}function Qe(e){return(t,n,r)=>{if(t!==`adb`)return;let i=$e(n,e.serial);if(i)return w(async()=>await e.provider.exec(i,r))}}function $e(e,t){if(!(e[0]!==`-s`||!e[1])&&e[1]===t)return e.slice(2)}const et=new WeakSet;function tt(e){let t=new Map;return{async ensure(n,r){if(await e([`reverse`,n.local,n.remote],{allowFailure:!1,signal:r?.signal,timeoutMs:r?.timeoutMs}),n.ownerId){let e=t.get(n.ownerId)??new Set;e.add(n.local),t.set(n.ownerId,e)}},async remove(n,r){let i=await e([`reverse`,`--remove`,n],{allowFailure:!0,signal:r?.signal,timeoutMs:r?.timeoutMs});if(i.exitCode!==0&&!rt(i.stdout,i.stderr))throw K(`Failed to remove Android port reverse ${n}`,i,{local:n});for(let e of t.values())e.delete(n)},async removeAllOwned(e,n){let r=[...t.get(e)??[]];for(let e of r)await this.remove(e,n);t.delete(e)},async list(n){let r=await e([`reverse`,`--list`],{allowFailure:!0,signal:n?.signal,timeoutMs:n?.timeoutMs});return r.exitCode===0?nt(r.stdout,t):[]}}}function nt(e,t){let n=new Map;for(let[e,r]of t)for(let t of r)n.set(t,e);return e.split(`
4
+ `).map(e=>e.trim().split(/\s+/)).filter(e=>e.length>=3).map(([,e,t])=>{let r=e;return{local:r,remote:t,ownerId:n.get(r)}})}function rt(e,t){let n=`${e}\n${t}`.toLowerCase();return n.includes(`listener`)&&n.includes(`not found`)}function $(e){let{replace:t,allowTestPackages:n,allowDowngrade:r,grantPermissions:i,...a}=e??{},o=[];return t&&o.push(`-r`),n&&o.push(`-t`),r&&o.push(`-d`),i&&o.push(`-g`),{installArgs:o,execOptions:a}}export{g as A,xe as C,S as D,ue as E,_ as F,ae as I,te as L,oe as M,ne as N,de as O,re as P,_e as S,w as T,be as _,Ye as a,Se as b,X as c,Ze as d,E as f,ye as g,De as h,qe as i,v as j,ie as k,Ke as l,V as m,K as n,Je as o,L as p,G as r,Ge as s,Fe as t,Z as u,T as v,ve as w,O as x,k as y};
@@ -1,8 +1,9 @@
1
- import { a as DaemonRequest, o as DaemonResponse } from "./sdk-contracts.js";
1
+ import { o as DaemonRequest, s as DaemonResponse } from "./sdk-contracts.js";
2
2
  //#region src/core/batch.d.ts
3
3
  type DaemonBatchStep = {
4
4
  command: string;
5
5
  positionals?: string[];
6
+ input?: Record<string, unknown>;
6
7
  flags?: Record<string, unknown>;
7
8
  runtime?: DaemonRequest['runtime'];
8
9
  };
@@ -1,2 +1,3 @@
1
- import{_ as e,a as t,i as n,v as r}from"./sdk-contracts.js";import{a as i,i as a,n as o,t as s}from"./sdk-batch.js";function c(t,n,r,i){let a=r(t[n]);if(a===void 0)throw new e(`COMMAND_FAILED`,i,{response:t});return a}function l(e,t,n){return n(e[t])}function u(e,t,n){let r=e[t];return r===null?null:n(r)}function d(e,t){return c(e,t,x,`Daemon response is missing "${t}".`)}function f(e,t){return l(e,t,x)}function p(e,t){return u(e,t,x)}function m(e,t){return c(e,t,S,`Daemon response is missing numeric "${t}".`)}function h(e,t){return c(e,t,C,`Daemon response has invalid "${t}".`)}function g(e,t){return c(e,t,w,`Daemon response has invalid "${t}".`)}function _(e,t){return l(e,t,T)??`mobile`}function v(e){if(!D(e))return;let t=b(e,`x`),n=b(e,`y`),r=b(e,`width`),i=b(e,`height`);if(!(t===void 0||n===void 0||r===void 0||i===void 0))return{x:t,y:n,width:r,height:i}}function y(e){if(!D(e))return;let t=b(e,`x`),n=b(e,`y`);if(!(t===void 0||n===void 0))return{x:t,y:n}}function b(e,t){let n=e[t];return typeof n==`number`?n:void 0}function x(e){return typeof e==`string`&&e.length>0?e:void 0}function S(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function C(e){return e===`apple`?`ios`:e===`ios`||e===`macos`||e===`android`||e===`linux`||e===`web`?e:void 0}function w(e){return e===`simulator`||e===`emulator`||e===`device`?e:void 0}function T(e){return e===`tv`||e===`mobile`||e===`desktop`?e:void 0}function E(t){if(!D(t))throw new e(`COMMAND_FAILED`,`Daemon returned an unexpected response shape.`,{value:t});return t}function D(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function O(e){let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t}function k(e){return e.split(`
2
- `).map(e=>e.trim()).filter(e=>e.length>0)}function A(e){return Number.isInteger(e)&&e>=1&&e<=1e3}function j(t,n){if(t>n)throw new e(`INVALID_ARGS`,`batch has ${t} steps; max allowed is ${n}.`)}function M(t,n){if(!D(t))throw new e(`INVALID_ARGS`,`Invalid batch step ${n}.`);return t}function N(t,n){let r=t.input;if(!D(r))throw new e(`INVALID_ARGS`,`Batch step ${n} input must be an object.`);return r}function P(t,r){if(t!==void 0)try{return n.parse(t)}catch(t){throw new e(`INVALID_ARGS`,`Batch step ${r} runtime is invalid: ${t instanceof Error?t.message:String(t)}`)}}const F=new Set(s);async function I(e,t,n){let i=U(e.flags),a=i?.batchOnError??`stop`;if(a!==`stop`)return W(`INVALID_ARGS`,`Unsupported batch on-error mode: ${a}.`);let o=i?.batchMaxSteps??100;if(!A(o))return W(`INVALID_ARGS`,`Invalid batch max-steps: ${String(i?.batchMaxSteps)}`);try{let r=L(i?.batchSteps,o),a=Date.now(),s=[];for(let[i,a]of r.entries()){let o=await H(e,t,a,n,i+1,i===r.length-1);if(!o.ok)return{ok:!1,error:{code:o.error.code,message:`Batch failed at step ${o.step} (${a.command}): ${o.error.message}`,hint:o.error.hint,diagnosticId:o.error.diagnosticId,logPath:o.error.logPath,details:{...o.error.details??{},step:o.step,command:a.command,positionals:a.positionals,executed:i,total:r.length,partialResults:s}}};s.push(o.result)}return{ok:!0,data:{total:r.length,executed:r.length,totalDurationMs:Date.now()-a,results:s}}}catch(e){let t=r(e);return W(t.code,t.message,t.details)}}function L(t,n){if(!Array.isArray(t)||t.length===0)throw new e(`INVALID_ARGS`,`batch requires a non-empty batchSteps array.`);j(t.length,n);let r=[];for(let n=0;n<t.length;n+=1){let o=t[n];if(!D(o))throw new e(`INVALID_ARGS`,`Invalid batch step at index ${n}.`);let s=Object.keys(o).filter(e=>!F.has(e));if(s.length>0){let t=s.map(e=>`"${e}"`).join(`, `);throw new e(`INVALID_ARGS`,`Batch step ${n+1} has unknown field(s): ${t}. Allowed fields: command, positionals, flags, runtime.`)}let c=i(o.command);if(!c)throw new e(`INVALID_ARGS`,`Batch step ${n+1} requires command.`);if(a(c,n+1),o.positionals!==void 0&&!Array.isArray(o.positionals))throw new e(`INVALID_ARGS`,`Batch step ${n+1} positionals must be an array.`);let l=o.positionals??[];if(l.some(e=>typeof e!=`string`))throw new e(`INVALID_ARGS`,`Batch step ${n+1} positionals must contain only strings.`);if(o.flags!==void 0&&!D(o.flags))throw new e(`INVALID_ARGS`,`Batch step ${n+1} flags must be an object.`);r.push({command:c,positionals:l,flags:o.flags??{},runtime:P(o.runtime,n+1)})}return r}function R(e,t){let{batchSteps:n,batchOnError:r,batchMaxSteps:i,...a}=t??{};return z(U(e),a)}function z(e,t){let n=U(e)??{},r=t;for(let e of o)r[e]===void 0&&n[e]!==void 0&&(r[e]=n[e]);return t}function B(e,n){return t(e)?n?e:`digest`:e}function V(e,t){let n=e?.responseLevel,r=B(n,t);return r===n?e:{...e,responseLevel:r}}async function H(e,t,n,r,i,a){let o=Date.now(),s=R(e.flags,n.flags);s.session===void 0&&(s.session=t);let c=await r({token:e.token,session:t,command:n.command,positionals:n.positionals,flags:s,runtime:n.runtime===void 0?e.runtime:n.runtime,meta:V(e.meta,a)}),l=Date.now()-o;return c.ok?{ok:!0,step:i,result:{step:i,command:n.command,ok:!0,data:c.data??{},durationMs:l}}:{ok:!1,step:i,error:c.error}}function U(e){return e}function W(e,t,n){return{ok:!1,error:{code:e,message:t,...n?{details:n}:{}}}}export{h as _,P as a,O as b,E as c,v as d,_ as f,m as g,g as h,A as i,D as l,f as m,I as n,N as o,p,j as r,M as s,z as t,y as u,d as v,k as y};
1
+ import{_ as e,a as t,i as n,v as r}from"./sdk-contracts.js";const i=new Set([`id`,`role`,`text`,`label`,`value`,`appname`,`windowtitle`]),a=new Set([`visible`,`hidden`,`editable`,`selected`,`focused`,`enabled`,`hittable`]),o=new Set([...i,...a]),s=[...o],c=new Set(`button.imagebutton.link.cell.statictext.checkedtextview.textfield.textbox.edittext.textarea.switch.slider.image.imageview.webview.framelayout.linearlayout.relativelayout.constraintlayout.viewgroup.view.listview.recyclerview.collectionview.list.searchfield.segmentedcontrol.group.window.checkbox.radio.menuitem.toolbar.scrollarea.scrollview.nestedscrollview.table.application.navigationbar.tabbar.tab.alert.dialog.header`.split(`.`));function ee(e){return c.has(e.trim().toLowerCase())}const te=new Map([[`"`,`"`],[`'`,`'`],[`\\`,`\\`],[`/`,`/`],[`b`,`\b`],[`f`,`\f`],[`n`,`
2
+ `],[`r`,`\r`],[`t`,` `]]);function ne(t){let n=t.trim();if(!n)throw new e(`INVALID_ARGS`,`Selector expression cannot be empty`);let r=oe(n);if(r.length===0)throw new e(`INVALID_ARGS`,`Selector expression cannot be empty`);return{raw:n,selectors:r.map(e=>ie(e))}}function l(e){try{return ne(e)}catch{return null}}function u(e){let t=e.trim();if(!t)return!1;if(t===`||`)return!0;let n=t.indexOf(`=`);if(n!==-1){let e=t.slice(0,n).trim().toLowerCase();return o.has(e)}return o.has(t.toLowerCase())}function re(e){let t=e.trim(),n=t.indexOf(`=`);if(n===-1)return null;let r=t.slice(0,n).trim().toLowerCase();if(!r||o.has(r))return null;let i=t.slice(n+1).trim();if(!i)return null;let a=p(i).trim();return a?{key:r,value:a}:null}function d(e,t={}){if(e.length===0)return null;let n=t.preferTrailingValue??!1,r=0,i=[];for(;r<e.length;){let t=e[r];if(t===void 0||!u(t))break;r+=1;let n=e.slice(0,r).join(` `).trim();n&&l(n)&&i.push(r)}if(i.length===0)return null;let a=i.at(-1);if(a===void 0)return null;let o=a;if(n)for(let t=i.length-1;t>=0;--t){let n=i[t];if(n!==void 0&&n<e.length){o=n;break}}let s=e.slice(0,o).join(` `).trim();return s?{selectorExpression:s,rest:e.slice(o)}:null}function ie(t){let n=t.trim();if(!n)throw new e(`INVALID_ARGS`,`Selector segment cannot be empty`);let r=se(n);if(r.length===0)throw new e(`INVALID_ARGS`,`Invalid selector segment: ${t}`);return{raw:n,terms:r.map(ae)}}function ae(t){let n=t.trim();if(!n)throw new e(`INVALID_ARGS`,`Empty selector term`);let r=n.indexOf(`=`);if(r===-1){let r=n.toLowerCase();if(!a.has(r))throw new e(`INVALID_ARGS`,`Invalid selector term "${t}", expected key=value`);return{key:r,value:!0}}let i=n.slice(0,r).trim().toLowerCase(),s=n.slice(r+1).trim();if(!o.has(i))throw new e(`INVALID_ARGS`,`Unknown selector key: ${i}`);if(!s)throw new e(`INVALID_ARGS`,`Missing selector value for key: ${i}`);if(a.has(i)){let t=ue(s);if(t===null)throw new e(`INVALID_ARGS`,`Invalid boolean value for ${i}: ${s}`);return{key:i,value:t}}return{key:i,value:p(s)}}function oe(t){let n=[],r=``,i=null;for(let a=0;a<t.length;a+=1){let o=t[a];if((o===`"`||o===`'`)&&!m(t,a)){i=f(i,o),r+=o;continue}if(!i&&o===`|`&&t[a+1]===`|`){let i=r.trim();if(!i)throw new e(`INVALID_ARGS`,`Invalid selector fallback expression: ${t}`);n.push(i),r=``,a+=1;continue}r+=o}let a=r.trim();if(!a)throw new e(`INVALID_ARGS`,`Invalid selector fallback expression: ${t}`);return n.push(a),n}function se(t){let n=[],r=``,i=null;for(let e=0;e<t.length;e+=1){let a=t.charAt(e);if((a===`"`||a===`'`)&&!m(t,e)){i=f(i,a),r+=a;continue}if(!i&&/\s/.test(a)){r.trim()&&n.push(r.trim()),r=``;continue}r+=a}if(i)throw new e(`INVALID_ARGS`,`Unclosed quote in selector: ${t}`);return r.trim()&&n.push(r.trim()),n}function f(e,t){return e?e===t?null:e:t}function p(e){let t=e.trim();return t.startsWith(`"`)&&t.endsWith(`"`)||t.startsWith(`'`)&&t.endsWith(`'`)?ce(t.slice(1,-1)):t}function ce(e){let t=``,n=0;for(;n<e.length;){let r=e.charAt(n);if(r!==`\\`){t+=r,n+=1;continue}let i=e.charAt(n+1);if(!i){t+=r,n+=1;continue}let a=le(i);if(a!==null){t+=a,n+=2;continue}if(i===`u`){let r=e.slice(n+2,n+6);if(/^[0-9a-fA-F]{4}$/.test(r)){t+=String.fromCharCode(Number.parseInt(r,16)),n+=6;continue}}t+=r,n+=1}return t}function le(e){return te.get(e)??null}function ue(e){let t=p(e).toLowerCase();return t===`true`?!0:t===`false`?!1:null}function m(e,t){let n=0;for(let r=t-1;r>=0&&e[r]===`\\`;--r)n+=1;return n%2==1}const de=[`any`,`text`,`label`,`value`,`role`,`id`],fe=[`text`,`label`,`value`,`role`,`id`];function pe(e){return e===`exists`||e===`wait`||e===`get_text`||e===`get_attrs`}function me(e,t,n,r={}){let i=g(n);if(!i)return{matches:[],score:0};let a=0,o=[];for(let n of e){if(r.requireRect&&!n.rect)continue;let e=he(n,t,i);if(!(e<=0)){if(e>a){a=e,o.length=0,o.push(n);continue}e===a&&o.push(n)}}return{matches:o,score:a}}function he(e,t,n){switch(t){case`role`:return ge(e.type,n);case`label`:return h(e.label,n);case`value`:return h(e.value,n);case`id`:return h(e.identifier,n);default:return Math.max(h(e.label,n),h(e.value,n),h(e.identifier,n))}}function h(e,t){let n=g(e??``);return n?n===t?2:+!!n.includes(t):0}function ge(e,t){let n=_e(e??``);return n?n===t?2:+!!n.includes(t):0}function g(e){return e.trim().toLowerCase().replace(/\s+/g,` `)}function _e(e){let t=e.trim();return t?(t=(t.split(`.`).pop()??t).replace(/XCUIElementType/gi,``).toLowerCase(),t):``}const ve=`find requires a value`;function ye(e,t){if(e.length===0)return{ok:!1,code:`INVALID_ARGS`,message:`find requires a locator or text`};let n=_([...e]);return n.query?t?.findFirst&&t?.findLast?{ok:!1,code:`INVALID_ARGS`,message:`find accepts only one of --first or --last`}:{ok:!0,parsed:n}:{ok:!1,code:`INVALID_ARGS`,message:ve}}function _(t){let n=`any`,r=0;fe.includes(t[0])&&(n=t[0],r=1);let i=t[r]??``,a=t.slice(r+1);if(a.length===0)return{locator:n,query:i,action:`click`};let o=a[0]?.toLowerCase();if(o===`get`){let t=a[1]?.toLowerCase();if(t===`text`)return{locator:n,query:i,action:`get_text`};if(t===`attrs`)return{locator:n,query:i,action:`get_attrs`};throw new e(`INVALID_ARGS`,`find get only supports text or attrs`)}if(o===`wait`){let e=xe(a[1]);return{locator:n,query:i,action:`wait`,timeoutMs:e??void 0}}if(o===`exists`)return{locator:n,query:i,action:`exists`};if(o===`click`)return{locator:n,query:i,action:`click`};if(o===`focus`)return{locator:n,query:i,action:`focus`};if(o===`fill`){let e=a.slice(1).join(` `);return{locator:n,query:i,action:`fill`,value:e}}if(o===`type`){let e=a.slice(1).join(` `);return{locator:n,query:i,action:`type`,value:e}}throw new e(`INVALID_ARGS`,`Unsupported find action: ${a[0]}`)}function be(e,t){return e!==`any`||!t.includes(`=`)&&!t.includes(`||`)?null:l(t)}function xe(e){if(!e)return null;let t=Number(e);return Number.isFinite(t)?t:null}function v(e){if(!e)return null;let t=Number(e);return Number.isFinite(t)?t:null}function y(e){let t=e[0];if(t===void 0)return null;let n=v(t);if(n!==null)return{kind:`sleep`,durationMs:n};let r=v(e[e.length-1]);if(t===`text`)return{kind:`text`,text:(r===null?e.slice(1).join(` `):e.slice(1,-1).join(` `)).trim(),timeoutMs:r};if(t===`stable`){let t=e.slice(1),n=t.length>1?v(t[1]):null;return{kind:`stable`,quietMs:t.length>0?v(t[0]):null,timeoutMs:n}}if(t.startsWith(`@`))return{kind:`ref`,rawRef:t,timeoutMs:r};let i=d(r===null?e.slice():e.slice(0,-1));return i&&i.rest.length===0&&l(i.selectorExpression)?{kind:`selector`,selectorExpression:i.selectorExpression,timeoutMs:r}:{kind:`text`,text:(r===null?e.join(` `):e.slice(0,-1).join(` `)).trim(),timeoutMs:r}}function Se(e){let t=y(e);return t?t.kind===`sleep`?t.durationMs:t.timeoutMs:null}const b=24e4,x={budget:{source:`none`},envelopeMs:9e4,onTimeout:`reset-daemon`},Ce={click:`settle-and-verify`,press:`settle-and-verify`,fill:`settle-and-verify`,longpress:`settle`};function S(e){if(e!==void 0)return Ce[e]}const C={leaseAdmissionExempt:!0,sessionExecutionLockExempt:!0},w={leaseAdmissionExempt:!0,sessionExecutionLockExempt:!0,selectorValidationExempt:!0},T=()=>!0,we=e=>(e.positionals?.[0]??``).toLowerCase()===`start`,E=e=>e.command===`test`&&(typeof e.flags?.shardAll==`number`||typeof e.flags?.shardSplit==`number`),D=new Set([`status`,`get`]),Te=e=>k(e,D,`status`),O=new Set([`get`,`wait`]),Ee=e=>k(e,O,`get`),De=e=>A(e,D,`status`),Oe=e=>A(e,O,`get`),ke=e=>{try{return pe(_(e.positionals??[]).action)?`observes-app`:`mutates-app`}catch{return`mutates-app`}};function k(e,t,n){return t.has((e.positionals?.[0]??n).toLowerCase())?`preserve`:`may-invalidate`}function A(e,t,n){return t.has((e.positionals?.[0]??n).toLowerCase())?`observes-app`:`mutates-app`}const j={simulator:!0,device:!0},M={emulator:!0,device:!0,unknown:!0},N={emulator:!0},P={device:!0},F={},I={apple:j,android:M,linux:P},L={...I,vega:N},Ae={apple:j,android:M,linux:F},R={apple:j,android:M,linux:F},z={recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`generic`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},dispatch:{},capability:{apple:j,android:M,linux:P},timeoutPolicy:x,batchable:!0},B={...x,onTimeout:`preserve-daemon`},V={...x,envelopeMs:18e4},H={...x,budget:{source:`flag`,envelope:`widen`,defaultBudgetMs:1e4},onTimeout:`preserve-daemon`},je={fields:{count:{defaultValue:1,omitDefault:!0},intervalMs:{defaultValue:0,omitDefault:!0},holdMs:{defaultValue:0,omitDefault:!0},jitterPx:{defaultValue:0,omitDefault:!0},doubleTap:{defaultValue:!1,omitDefault:!0}}},Me={fields:{delayMs:{defaultValue:0}}};function U(e){return S(e)===void 0?B:H}function W(e){let t=S(e);if(t===void 0)throw Error(`Missing post-action observation descriptor support for ${e}`);return t}const Ne=[{name:`lease_allocate`,catalog:{group:`internal`,key:`leaseAllocate`},recordsSessionAction:!1,daemon:{route:`lease`,refFrameEffect:`preserve`,...C},timeoutPolicy:x,batchable:!1},{name:`lease_heartbeat`,catalog:{group:`internal`,key:`leaseHeartbeat`},recordsSessionAction:!1,daemon:{route:`lease`,refFrameEffect:`preserve`,...C},timeoutPolicy:x,batchable:!1},{name:`lease_release`,catalog:{group:`internal`,key:`leaseRelease`},recordsSessionAction:!1,daemon:{route:`lease`,refFrameEffect:`preserve`,...C},timeoutPolicy:x,batchable:!1},{name:`artifacts`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`lease`,refFrameEffect:`preserve`,...C},timeoutPolicy:x,batchable:!1},{name:`session_list`,catalog:{group:`internal`,key:`sessionList`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,...w},timeoutPolicy:x,batchable:!1},{name:`session_save_script`,catalog:{group:`internal`,key:`sessionSaveScript`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`publication`},timeoutPolicy:x,batchable:!1},{name:`devices`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,lockPolicySelectorOverride:!0,...w},timeoutPolicy:x,batchable:!0},{name:`capabilities`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,lockPolicySelectorOverride:!0,preferExplicitDeviceOverExistingSession:!0,...w},timeoutPolicy:x,batchable:!0},{name:`doctor`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,lockPolicySelectorOverride:!0,allowSessionlessDefaultDevice:T,...w},timeoutPolicy:x,batchable:!0},{name:`apps`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`inventory`,lockPolicySelectorOverride:!0,preferExplicitDeviceOverExistingSession:!0},capability:Ae,timeoutPolicy:x,batchable:!0},{name:`boot`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`may-invalidate`,sessionKind:`state`},capability:{apple:j,android:M,linux:F},timeoutPolicy:x,batchable:!0},{name:`shutdown`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`may-invalidate`,sessionKind:`state`},capability:{apple:{simulator:!0},android:{emulator:!0},linux:F},timeoutPolicy:x,batchable:!0},{name:`appstate`,catalog:{group:`public`,key:`appState`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`state`},timeoutPolicy:x,batchable:!0},{name:`perf`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`},capability:{apple:j,android:M,linux:F},timeoutPolicy:x,batchable:!0},{name:`logs`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`},capability:{apple:j,android:M,linux:F},timeoutPolicy:x,batchable:!0},{name:`events`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`,allowInvalidRecording:!0,...w},timeoutPolicy:x,batchable:!1},{name:`network`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`},capability:{apple:j,android:M,linux:F},timeoutPolicy:x,batchable:!0},{name:`audio`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,sessionKind:`observability`},capability:{apple:j,android:{emulator:!0},linux:F},timeoutPolicy:x,batchable:!0},{name:`replay`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`delegated`,sessionKind:`replay`,skipSessionlessProviderDevice:E},timeoutPolicy:{...x,budget:{source:`flag`}},batchable:!1},{name:`test`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`delegated`,sessionKind:`replay`,skipSessionlessProviderDevice:E},timeoutPolicy:{...x,envelopeMs:`unbounded`},batchable:!0},{name:`runtime`,catalog:{group:`internal`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`},timeoutPolicy:x,batchable:!1},{name:`clipboard`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`session`,refFrameEffect:`preserve`},dispatch:{},capability:{apple:j,android:M,linux:P},timeoutPolicy:x,batchable:!0},{name:`keyboard`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:De,daemon:{route:`session`,refFrameEffect:Te,androidBlockingDialogGuard:!0},dispatch:{},capability:{apple:j,android:M,linux:F},timeoutPolicy:x,batchable:!0},{name:`install`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`},capability:R,timeoutPolicy:V,batchable:!0},{name:`reinstall`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`},capability:R,timeoutPolicy:V,batchable:!0},{name:`install_source`,catalog:{group:`internal`,key:`installSource`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`},timeoutPolicy:V,batchable:!1},{name:`release_materialized_paths`,catalog:{group:`internal`,key:`releaseMaterializedPaths`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`,...w},timeoutPolicy:x,batchable:!1},{name:`push`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`},dispatch:{},capability:{apple:{simulator:!0},android:M,linux:F},timeoutPolicy:x,batchable:!0},{name:`trigger-app-event`,catalog:{group:`public`,key:`triggerAppEvent`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`},dispatch:{},capability:{apple:j,android:M,linux:F},timeoutPolicy:x,batchable:!0},{name:`open`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`,allowSessionlessDefaultDevice:T},dispatch:{},capability:L,timeoutPolicy:x,batchable:!0},{name:`prepare`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`preserve`},timeoutPolicy:{budget:{source:`flag`},envelopeMs:b,onTimeout:`reset-daemon`},batchable:!1,mcpExposed:!1},{name:`batch`,catalog:{group:`public`},recordsSessionAction:!1,daemon:{route:`session`,refFrameEffect:`delegated`},timeoutPolicy:x,batchable:!1},{name:`close`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`session`,refFrameEffect:`may-invalidate`,allowInvalidRecording:!0},dispatch:{},capability:L,timeoutPolicy:x,batchable:!0},{name:`snapshot`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`snapshot`,refFrameEffect:`preserve`},dispatch:{},capability:I,timeoutPolicy:{...B,budget:{source:`flag`}},batchable:!0},{name:`diff`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`snapshot`,refFrameEffect:`preserve`},capability:I,timeoutPolicy:x,batchable:!0},{name:`wait`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,targetIdentityVerification:`post-resolution`,daemon:{route:`snapshot`,refFrameEffect:`preserve`},capability:I,timeoutPolicy:{...B,budget:{source:`positional-parser`,parser:Se}},batchable:!0},{name:`alert`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:Oe,daemon:{route:`snapshot`,refFrameEffect:Ee},capability:{apple:j,android:M,linux:F},timeoutPolicy:x,batchable:!0},{name:`settings`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`snapshot`,refFrameEffect:`may-invalidate`},dispatch:{},capability:{apple:j,android:M,linux:F},timeoutPolicy:x,batchable:!0},{name:`react-native`,catalog:{group:`public`,key:`reactNative`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`reactNative`,refFrameEffect:`may-invalidate`},capability:{apple:j,android:M,linux:F},timeoutPolicy:x,batchable:!0},{name:`record`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`recordTrace`,refFrameEffect:`preserve`,allowInvalidRecording:!0,allowSessionlessDefaultDevice:we},capability:{apple:j,android:M,linux:F},timeoutPolicy:x,batchable:!0},{name:`trace`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`recordTrace`,refFrameEffect:`preserve`},timeoutPolicy:x,batchable:!0},{name:`find`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:ke,daemon:{route:`find`,refFrameEffect:`may-invalidate`},capability:I,timeoutPolicy:B,batchable:!0},{name:`click`,targetIdentityVerification:`pre-dispatch`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},capability:{apple:j,android:M,linux:P},timeoutPolicy:U(`click`),postActionObservation:W(`click`),responseDataTransform:je,batchable:!0},{name:`fill`,targetIdentityVerification:`pre-dispatch`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},dispatch:{},capability:{apple:j,android:M,linux:P},timeoutPolicy:U(`fill`),postActionObservation:W(`fill`),responseDataTransform:Me,batchable:!0},{name:`longpress`,targetIdentityVerification:`pre-dispatch`,catalog:{group:`public`,key:`longPress`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},dispatch:{},capability:{apple:j,android:M,linux:P},timeoutPolicy:{...H,envelopeMs:21e4},postActionObservation:W(`longpress`),batchable:!0},{name:`press`,targetIdentityVerification:`pre-dispatch`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},dispatch:{},capability:{apple:j,android:M,linux:P},timeoutPolicy:U(`press`),postActionObservation:W(`press`),responseDataTransform:je,batchable:!0},{name:`type`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},dispatch:{},capability:I,timeoutPolicy:U(`type`),batchable:!0},{name:`get`,targetIdentityVerification:`pre-dispatch`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`interaction`,refFrameEffect:`preserve`},capability:I,timeoutPolicy:U(`get`),batchable:!0},{name:`read`,catalog:{group:`dispatch-alias`},recordsSessionAction:!1,dispatch:{},timeoutPolicy:x,batchable:!1},{name:`is`,targetIdentityVerification:`pre-dispatch`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`interaction`,refFrameEffect:`preserve`},capability:I,timeoutPolicy:U(`is`),batchable:!0},{name:`back`,catalog:{group:`public`},...z,capability:{...z.capability,vega:N}},{name:`gesture`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},capability:I,timeoutPolicy:x,batchable:!0},{name:`home`,catalog:{group:`public`},...z,capability:{...z.capability,vega:N}},{name:`tv-remote`,catalog:{group:`public`,key:`tvRemote`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`generic`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},dispatch:{},capability:{apple:j,android:M,vega:N,linux:F},timeoutPolicy:x,batchable:!0},{name:`orientation`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`generic`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},dispatch:{},capability:{apple:j,android:M,linux:F},timeoutPolicy:x,batchable:!0},{name:`scroll`,catalog:{group:`public`},...z},{name:`swipe`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`interaction`,refFrameEffect:`may-invalidate`,androidBlockingDialogGuard:!0},capability:{apple:j,android:M,linux:P},timeoutPolicy:x,batchable:!0},{name:`focus`,catalog:{group:`public`},...z},{name:`screenshot`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`observes-app`,daemon:{route:`generic`,refFrameEffect:`preserve`},dispatch:{},capability:I,timeoutPolicy:x,batchable:!0},{name:`viewport`,catalog:{group:`public`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`generic`,refFrameEffect:`may-invalidate`},dispatch:{},capability:{apple:j,android:M,linux:F},timeoutPolicy:x,batchable:!1},{name:`app-switcher`,catalog:{group:`public`,key:`appSwitcher`},recordsSessionAction:!0,recordingEffect:`mutates-app`,daemon:{route:`generic`,refFrameEffect:`may-invalidate`},dispatch:{},capability:{apple:j,android:M,linux:F},timeoutPolicy:x,batchable:!0},{name:`install-from-source`,catalog:{group:`public`,key:`installFromSource`},recordsSessionAction:!0,recordingEffect:`mutates-app`,capability:R,timeoutPolicy:x,batchable:!0},{name:`debug`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:x,batchable:!1},{name:`daemon`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:x,batchable:!1,mcpExposed:!1},{name:`device`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:x,batchable:!1,mcpExposed:!1},{name:`metro`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:x,batchable:!1},{name:`session`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:x,batchable:!1},{name:`cdp`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:x,batchable:!1,mcpExposed:!1},{name:`auth`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:x,batchable:!1,mcpExposed:!1},{name:`connect`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:x,batchable:!1,mcpExposed:!1},{name:`connection`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:x,batchable:!1,mcpExposed:!1},{name:`disconnect`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:x,batchable:!1,mcpExposed:!1},{name:`mcp`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:x,batchable:!1,mcpExposed:!1},{name:`proxy`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:x,batchable:!1,mcpExposed:!1},{name:`react-devtools`,catalog:{group:`local-cli`,key:`reactDevtools`},recordsSessionAction:!1,timeoutPolicy:x,batchable:!1,mcpExposed:!1},{name:`web`,catalog:{group:`local-cli`},recordsSessionAction:!1,timeoutPolicy:x,batchable:!1,mcpExposed:!1}],Pe=new Set([`public`,`local-cli`]),G=new Set(Ne.filter(e=>Pe.has(Be(e))).map(e=>e.name)),K=Ne.map(e=>({...e,mcpExposed:Re(e)}));function Fe(e){return K.filter(t=>Be(t)===e).map(e=>[Ve(e),e.name])}function Ie(){return K.filter(e=>ze(e)).map(e=>e.name).sort()}const q=new Map(K.map(e=>[e.name,e]));function Le(e){return G.has(e)}function Re(e){return e.mcpExposed??G.has(e.name)}function ze(e){return e.mcpExposed&&Le(e.name)}function Be(e){return e.catalog.group}function Ve(e){return e.catalog.key??e.name}const He=new Map(K.map(e=>[e.name,e.timeoutPolicy])),Ue=new Map(Array.from(q.values()).flatMap(e=>e.responseDataTransform?[[e.name,e.responseDataTransform]]:[]));function We(e){if(e!==void 0)return q.get(e)?.postActionObservation}function Ge(e){return We(e)!==void 0}function Ke(e){return We(e)===`settle-and-verify`}function qe(e){return e===void 0?x:He.get(e)??x}function Je(e){if(e!==void 0)return Ue.get(e)}function Ye(e){return e===void 0?!1:q.get(e)?.recordsSessionAction??!1}function Xe(e){return q.get(e)?.targetIdentityVerification}function Ze(e){let t=q.get(e.command);if(t?.recordsSessionAction)return typeof t.recordingEffect==`function`?t.recordingEffect(e):t.recordingEffect}function Qe(){return[...new Set(Array.from(Ue.values()).flatMap(e=>Object.keys(e.fields)))].sort()}function J(t,n,r,i){let a=r(t[n]);if(a===void 0)throw new e(`COMMAND_FAILED`,i,{response:t});return a}function $e(e,t,n){return n(e[t])}function et(e,t,n){let r=e[t];return r===null?null:n(r)}function tt(e,t){return J(e,t,X,`Daemon response is missing "${t}".`)}function nt(e,t){return $e(e,t,X)}function rt(e,t){return et(e,t,X)}function it(e,t){return J(e,t,ut,`Daemon response is missing numeric "${t}".`)}function at(e,t){return J(e,t,dt,`Daemon response has invalid "${t}".`)}function ot(e,t){return J(e,t,ft,`Daemon response has invalid "${t}".`)}function st(e,t){return $e(e,t,pt)??`mobile`}function ct(e){if(!Z(e))return;let t=Y(e,`x`),n=Y(e,`y`),r=Y(e,`width`),i=Y(e,`height`);if(!(t===void 0||n===void 0||r===void 0||i===void 0))return{x:t,y:n,width:r,height:i}}function lt(e){if(!Z(e))return;let t=Y(e,`x`),n=Y(e,`y`);if(!(t===void 0||n===void 0))return{x:t,y:n}}function Y(e,t){let n=e[t];return typeof n==`number`?n:void 0}function X(e){return typeof e==`string`&&e.length>0?e:void 0}function ut(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function dt(e){return e===`apple`?`ios`:e===`ios`||e===`macos`||e===`android`||e===`vega`||e===`linux`||e===`web`?e:void 0}function ft(e){return e===`simulator`||e===`emulator`||e===`device`?e:void 0}function pt(e){return e===`tv`||e===`mobile`||e===`desktop`?e:void 0}function mt(t){if(!Z(t))throw new e(`COMMAND_FAILED`,`Daemon returned an unexpected response shape.`,{value:t});return t}function Z(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function ht(e){return Z(e)?e:void 0}function gt(e){let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(t[n]=r);return t}function _t(e){return e.split(`
3
+ `).map(e=>e.trim()).filter(e=>e.length>0)}function vt(e){return Number.isInteger(e)&&e>=1&&e<=1e3}function yt(t,n){if(t>n)throw new e(`INVALID_ARGS`,`batch has ${t} steps; max allowed is ${n}.`)}function bt(t,n){if(!Z(t))throw new e(`INVALID_ARGS`,`Invalid batch step ${n}.`);return t}function xt(t,n){let r=t.input;if(!Z(r))throw new e(`INVALID_ARGS`,`Batch step ${n} input must be an object.`);return r}function St(t,r){if(t!==void 0)try{return n.parse(t)}catch(t){throw new e(`INVALID_ARGS`,`Batch step ${r} runtime is invalid: ${t instanceof Error?t.message:String(t)}`)}}function Ct(e){let t=[];for(let n of e)n.daemon&&t.push({command:n.name,...n.daemon,replayScopedAction:n.recordsSessionAction});return t}function wt(e){let t={};for(let n of e)n.capability&&(t[n.name]=n.capability);return t}function Tt(e){return e.filter(e=>e.batchable).map(e=>e.name)}const Et=Tt(K),Dt=new Set([`batch`,`replay`]),Ot=[`command`,`positionals`,`input`,`flags`,`runtime`],kt=[`platform`,`target`,`device`,`udid`,`serial`,`verbose`,`out`],At=new Set(Et);function jt(e){return At.has(e)}function Mt(e){return typeof e==`string`?e.trim().toLowerCase():``}function Nt(t,n){let r=Mt(t);if(jt(r))return r;throw new e(`INVALID_ARGS`,`Batch step ${n} command is not available through command batch: ${String(t)}`)}function Pt(t,n){if(Dt.has(t))throw new e(`INVALID_ARGS`,`Batch step ${n} cannot run ${t}.`)}const Ft=new Set(Ot);async function It(e,t,n){let i=Q(e.flags),a=i?.batchOnError??`stop`;if(a!==`stop`)return $(`INVALID_ARGS`,`Unsupported batch on-error mode: ${a}.`);let o=i?.batchMaxSteps??100;if(!vt(o))return $(`INVALID_ARGS`,`Invalid batch max-steps: ${String(i?.batchMaxSteps)}`);try{let r=Lt(i?.batchSteps,o),a=Date.now(),s=[];for(let[i,a]of r.entries()){let o=await Ht(e,t,a,n,i+1,i===r.length-1);if(!o.ok)return{ok:!1,error:{code:o.error.code,message:`Batch failed at step ${o.step} (${a.command}): ${o.error.message}`,hint:o.error.hint,diagnosticId:o.error.diagnosticId,logPath:o.error.logPath,details:{...o.error.details??{},step:o.step,command:a.command,positionals:a.positionals,executed:i,total:r.length,partialResults:s}}};s.push(o.result)}return{ok:!0,data:{total:r.length,executed:r.length,totalDurationMs:Date.now()-a,results:s}}}catch(e){let t=r(e);return $(t.code,t.message,t.details)}}function Lt(t,n){if(!Array.isArray(t)||t.length===0)throw new e(`INVALID_ARGS`,`batch requires a non-empty batchSteps array.`);yt(t.length,n);let r=[];for(let n=0;n<t.length;n+=1){let i=t[n];if(!Z(i))throw new e(`INVALID_ARGS`,`Invalid batch step at index ${n}.`);let a=Object.keys(i).filter(e=>!Ft.has(e));if(a.length>0){let t=a.map(e=>`"${e}"`).join(`, `);throw new e(`INVALID_ARGS`,`Batch step ${n+1} has unknown field(s): ${t}. Allowed fields: command, positionals, input, flags, runtime.`)}let o=Mt(i.command);if(!o)throw new e(`INVALID_ARGS`,`Batch step ${n+1} requires command.`);if(Pt(o,n+1),i.positionals!==void 0&&!Array.isArray(i.positionals))throw new e(`INVALID_ARGS`,`Batch step ${n+1} positionals must be an array.`);let s=i.positionals??[];if(s.some(e=>typeof e!=`string`))throw new e(`INVALID_ARGS`,`Batch step ${n+1} positionals must contain only strings.`);if(i.flags!==void 0&&!Z(i.flags))throw new e(`INVALID_ARGS`,`Batch step ${n+1} flags must be an object.`);if(i.input!==void 0&&!Z(i.input))throw new e(`INVALID_ARGS`,`Batch step ${n+1} input must be an object.`);r.push({command:o,positionals:s,input:i.input,flags:i.flags??{},runtime:St(i.runtime,n+1)})}return r}function Rt(e,t){let{batchSteps:n,batchOnError:r,batchMaxSteps:i,...a}=t??{};return zt(Q(e),a)}function zt(e,t){let n=Q(e)??{},r=t;for(let e of kt)r[e]===void 0&&n[e]!==void 0&&(r[e]=n[e]);return t}function Bt(e,n){return t(e)?n?e:`digest`:e}function Vt(e,t){let n=e?.responseLevel,r=Bt(n,t);return r===n?e:{...e,responseLevel:r}}async function Ht(e,t,n,r,i,a){let o=Date.now(),s=Rt(e.flags,n.flags);s.session===void 0&&(s.session=t);let c=await r({token:e.token,session:t,command:n.command,positionals:n.positionals,input:n.input,flags:s,runtime:n.runtime===void 0?e.runtime:n.runtime,meta:Vt(e.meta,a)}),ee=Date.now()-o;return c.ok?{ok:!0,step:i,result:{step:i,command:n.command,ok:!0,data:c.data??{},durationMs:ee}}:{ok:!1,step:i,error:c.error}}function Q(e){return e}function $(e,t,n){return{ok:!1,error:{code:e,message:t,...n?{details:n}:{}}}}export{d as $,Fe as A,de as B,tt as C,Ge as D,K as E,qe as F,g as G,ye as H,Xe as I,s as J,_ as K,b as L,Ze as M,Ye as N,Ke as O,Je as P,ne as Q,y as R,at as S,gt as T,me as U,ve as V,pe as W,ee as X,re as Y,u as Z,st as _,wt as a,ot as b,vt as c,bt as d,l as et,ht as f,ct as g,lt as h,Nt as i,Ie as j,Qe as k,St as l,Z as m,It as n,Ct as o,mt as p,be as q,Et as r,yt as s,zt as t,xt as u,rt as v,_t as w,it as x,nt as y,v as z};
@@ -1,125 +1,17 @@
1
1
  //#region src/kernel/device.d.ts
2
2
  declare const APPLE_OS_VALUES: readonly ['ios', 'ipados', 'tvos', 'watchos', 'visionos', 'macos'];
3
3
  type AppleOS = (typeof APPLE_OS_VALUES)[number];
4
- declare const PLATFORMS: readonly ['apple', 'android', 'linux', 'web'];
4
+ declare const PLATFORMS: readonly ['apple', 'android', 'vega', 'linux', 'web'];
5
5
  type Platform = (typeof PLATFORMS)[number];
6
- declare const PUBLIC_PLATFORMS: readonly ['ios', 'macos', 'android', 'linux', 'web'];
6
+ declare const PUBLIC_PLATFORMS: readonly ['ios', 'macos', 'android', 'vega', 'linux', 'web'];
7
7
  type PublicPlatform = (typeof PUBLIC_PLATFORMS)[number];
8
- declare const PLATFORM_SELECTORS: readonly ["apple", "android", "linux", "web", "ios", "macos"];
8
+ declare const PLATFORM_SELECTORS: readonly ["apple", "android", "vega", "linux", "web", "ios", "macos"];
9
9
  type PlatformSelector = (typeof PLATFORM_SELECTORS)[number];
10
10
  declare const DEVICE_KINDS: readonly ['simulator', 'emulator', 'device'];
11
11
  type DeviceKind = (typeof DEVICE_KINDS)[number];
12
12
  declare const DEVICE_TARGETS: readonly ['mobile', 'tv', 'desktop'];
13
13
  type DeviceTarget = (typeof DEVICE_TARGETS)[number];
14
14
  //#endregion
15
- //#region src/kernel/errors.d.ts
16
- type KnownAppErrorCode = 'INVALID_ARGS' | 'DEVICE_NOT_FOUND' | 'DEVICE_IN_USE' | 'TOOL_MISSING' | 'APP_NOT_INSTALLED' | 'UNSUPPORTED_PLATFORM' | 'UNSUPPORTED_OPERATION' | 'NOT_IMPLEMENTED' | 'COMMAND_FAILED' | 'SESSION_NOT_FOUND' | 'UNAUTHORIZED' | 'AMBIGUOUS_MATCH' | 'UNKNOWN';
17
- type AppErrorCode = KnownAppErrorCode | (string & {});
18
- /**
19
- * Details bag for AppError. Free-form context is allowed, but these keys carry
20
- * meaning at normalize/render time and must keep their types:
21
- * - `hint` — overrides `defaultHintForCode`; re-wraps preserve an existing hint.
22
- * - `diagnosticId` / `logPath` — lifted onto the normalized error, stripped from details.
23
- * - `processExitError` + `stdout`/`stderr`/`exitCode` — marks a wrap of a real
24
- * process exit so normalizeError can surface the first meaningful stderr line;
25
- * build these via `execFailureDetails`/`requireExecSuccess` in src/utils/exec.ts
26
- * rather than by hand.
27
- * - `retriable` — typed retry signal hoisted to the wire error shape.
28
- * - `reason` — machine-dispatchable sub-classification within a code.
29
- */
30
- type AppErrorDetails = Record<string, unknown> & {
31
- hint?: string;
32
- diagnosticId?: string;
33
- logPath?: string;
34
- retriable?: boolean;
35
- supportedOn?: string;
36
- processExitError?: boolean;
37
- stdout?: string;
38
- stderr?: string;
39
- exitCode?: number | null;
40
- reason?: string;
41
- };
42
- type NormalizedError = {
43
- code: string;
44
- message: string;
45
- hint?: string;
46
- diagnosticId?: string;
47
- logPath?: string;
48
- /**
49
- * Lifted from `details.retriable` when a throw site classified the failure as
50
- * clearly transient (or clearly not). Included only when set, so the default
51
- * error wire shape is unchanged.
52
- */
53
- retriable?: boolean;
54
- supportedOn?: string;
55
- details?: Record<string, unknown>;
56
- };
57
- declare class AppError extends Error {
58
- code: AppErrorCode;
59
- details?: AppErrorDetails;
60
- cause?: unknown;
61
- constructor(code: AppErrorCode, message: string, details?: AppErrorDetails, cause?: unknown);
62
- }
63
- declare function isAgentDeviceError(err: unknown): err is AppError;
64
- declare function normalizeAgentDeviceError(err: unknown, context?: {
65
- diagnosticId?: string;
66
- logPath?: string;
67
- }): NormalizedError;
68
- declare function normalizeError(err: unknown, context?: {
69
- diagnosticId?: string;
70
- logPath?: string;
71
- }): NormalizedError;
72
- declare function defaultHintForCode(code: string): string | undefined;
73
- //#endregion
74
- //#region src/contracts/debug-symbols.d.ts
75
- type DebugSymbolsOptions = {
76
- action?: 'symbols';
77
- artifact: string;
78
- dsym?: string;
79
- searchPath?: string;
80
- out?: string;
81
- cwd?: string;
82
- };
83
- type DebugSymbolsImage = {
84
- name: string;
85
- uuid: string;
86
- arch?: string;
87
- dsymPath: string;
88
- binaryPath: string;
89
- };
90
- type DebugSymbolsCrashFrame = {
91
- index: number;
92
- image: string;
93
- address: string;
94
- symbol?: string;
95
- };
96
- type DebugSymbolsCrashSummary = {
97
- format: 'ips' | 'text';
98
- appName?: string;
99
- bundleId?: string;
100
- version?: string;
101
- incident?: string;
102
- timestamp?: string;
103
- exceptionType?: string;
104
- exceptionCodes?: string;
105
- terminationReason?: string;
106
- crashedThread?: number;
107
- topFrames: DebugSymbolsCrashFrame[];
108
- findings: string[];
109
- };
110
- type DebugSymbolsResult = {
111
- kind: 'debugSymbols';
112
- platform: 'apple';
113
- artifactPath: string;
114
- outPath: string;
115
- crash: DebugSymbolsCrashSummary;
116
- matchedImages: DebugSymbolsImage[];
117
- symbolicatedFrames: number;
118
- skippedImages: number;
119
- warnings?: string[];
120
- message: string;
121
- };
122
- //#endregion
123
15
  //#region src/kernel/snapshot.d.ts
124
16
  /**
125
17
  * Structured quality verdict computed once by the iOS runner's snapshot capture plan.
@@ -193,6 +85,12 @@ type SnapshotState = {
193
85
  snapshotQuality?: SnapshotQualityVerdict;
194
86
  comparisonSafe?: boolean;
195
87
  presentationKey?: string;
88
+ /**
89
+ * Android: the capture is an occluding system surface (notification shade, quick settings)
90
+ * rather than app content. Consumers that surface this tree to the agent must disclose the
91
+ * occlusion (see snapshot/system-surface-disclosure.ts).
92
+ */
93
+ systemSurfaceOnly?: boolean;
196
94
  };
197
95
  type SnapshotUnchanged = {
198
96
  ageMs: number;
@@ -216,6 +114,65 @@ type ScreenshotOverlayRef = {
216
114
  };
217
115
  declare function centerOfRect(rect: Rect): Point;
218
116
  //#endregion
117
+ //#region src/kernel/errors.d.ts
118
+ type KnownAppErrorCode = 'INVALID_ARGS' | 'DEVICE_NOT_FOUND' | 'DEVICE_IN_USE' | 'TOOL_MISSING' | 'APP_NOT_INSTALLED' | 'UNSUPPORTED_PLATFORM' | 'UNSUPPORTED_OPERATION' | 'NOT_IMPLEMENTED' | 'COMMAND_FAILED' | 'SESSION_NOT_FOUND' | 'UNAUTHORIZED' | 'AMBIGUOUS_MATCH' | 'REPLAY_DIVERGENCE' | 'REPAIR_SESSION_EXPIRED' | 'REPAIR_COMMIT_FAILED' | 'UNKNOWN';
119
+ type AppErrorCode = KnownAppErrorCode | (string & {});
120
+ /**
121
+ * Details bag for AppError. Free-form context is allowed, but these keys carry
122
+ * meaning at normalize/render time and must keep their types:
123
+ * - `hint` — overrides `defaultHintForCode`; re-wraps preserve an existing hint.
124
+ * - `diagnosticId` / `logPath` — lifted onto the normalized error, stripped from details.
125
+ * - `processExitError` + `stdout`/`stderr`/`exitCode` — marks a wrap of a real
126
+ * process exit so normalizeError can surface the first meaningful stderr line;
127
+ * build these via `execFailureDetails`/`requireExecSuccess` in src/utils/exec.ts
128
+ * rather than by hand.
129
+ * - `retriable` — typed retry signal hoisted to the wire error shape.
130
+ * - `reason` — machine-dispatchable sub-classification within a code.
131
+ */
132
+ type AppErrorDetails = Record<string, unknown> & {
133
+ hint?: string;
134
+ diagnosticId?: string;
135
+ logPath?: string;
136
+ retriable?: boolean;
137
+ supportedOn?: string;
138
+ processExitError?: boolean;
139
+ stdout?: string;
140
+ stderr?: string;
141
+ exitCode?: number | null;
142
+ reason?: string;
143
+ };
144
+ type NormalizedError = {
145
+ code: string;
146
+ message: string;
147
+ hint?: string;
148
+ diagnosticId?: string;
149
+ logPath?: string;
150
+ /**
151
+ * Lifted from `details.retriable` when a throw site classified the failure as
152
+ * clearly transient (or clearly not). Included only when set, so the default
153
+ * error wire shape is unchanged.
154
+ */
155
+ retriable?: boolean;
156
+ supportedOn?: string;
157
+ details?: Record<string, unknown>;
158
+ };
159
+ declare class AppError extends Error {
160
+ code: AppErrorCode;
161
+ details?: AppErrorDetails;
162
+ cause?: unknown;
163
+ constructor(code: AppErrorCode, message: string, details?: AppErrorDetails, cause?: unknown);
164
+ }
165
+ declare function isAgentDeviceError(err: unknown): err is AppError;
166
+ declare function normalizeAgentDeviceError(err: unknown, context?: {
167
+ diagnosticId?: string;
168
+ logPath?: string;
169
+ }): NormalizedError;
170
+ declare function normalizeError(err: unknown, context?: {
171
+ diagnosticId?: string;
172
+ logPath?: string;
173
+ }): NormalizedError;
174
+ declare function defaultHintForCode(code: string): string | undefined;
175
+ //#endregion
219
176
  //#region src/kernel/contracts.d.ts
220
177
  type SessionRuntimeHints = {
221
178
  platform?: 'ios' | 'android';
@@ -288,6 +245,7 @@ type DaemonRequest = {
288
245
  session?: string;
289
246
  command: string;
290
247
  positionals: string[];
248
+ input?: Record<string, unknown>;
291
249
  flags?: Record<string, unknown>;
292
250
  runtime?: SessionRuntimeHints;
293
251
  meta?: DaemonRequestMeta;
@@ -338,43 +296,6 @@ type DaemonResponse = {
338
296
  ok: false;
339
297
  error: DaemonError;
340
298
  };
341
- type LeaseAllocatePayload = {
342
- token?: string;
343
- session?: string;
344
- tenantId?: string;
345
- tenant?: string;
346
- runId?: string;
347
- ttlMs?: number;
348
- backend?: LeaseBackend;
349
- leaseProvider?: string;
350
- deviceKey?: string;
351
- clientId?: string;
352
- };
353
- type LeaseHeartbeatPayload = {
354
- token?: string;
355
- session?: string;
356
- tenantId?: string;
357
- tenant?: string;
358
- runId?: string;
359
- leaseId?: string;
360
- ttlMs?: number;
361
- backend?: LeaseBackend;
362
- leaseProvider?: string;
363
- deviceKey?: string;
364
- clientId?: string;
365
- };
366
- type LeaseReleasePayload = {
367
- token?: string;
368
- session?: string;
369
- tenantId?: string;
370
- tenant?: string;
371
- runId?: string;
372
- leaseId?: string;
373
- backend?: LeaseBackend;
374
- leaseProvider?: string;
375
- deviceKey?: string;
376
- clientId?: string;
377
- };
378
299
  type JsonRpcId = string | number | null;
379
300
  type JsonRpcRequestEnvelope<TParams = unknown> = {
380
301
  jsonrpc?: string;
@@ -383,4 +304,4 @@ type JsonRpcRequestEnvelope<TParams = unknown> = {
383
304
  params?: TParams;
384
305
  };
385
306
  //#endregion
386
- export { AppError as A, PlatformSelector as B, SnapshotQualityVerdict as C, centerOfRect as D, SnapshotVisibility as E, normalizeError as F, AppleOS as I, DeviceKind as L, defaultHintForCode as M, isAgentDeviceError as N, DebugSymbolsOptions as O, normalizeAgentDeviceError as P, DeviceTarget as R, SnapshotNode as S, SnapshotUnchanged as T, PublicPlatform as V, ResponseLevel as _, DaemonRequest as a, Point as b, DaemonServerMode as c, JsonRpcRequestEnvelope as d, LeaseAllocatePayload as f, NetworkIncludeMode as g, LeaseReleasePayload as h, DaemonLockPolicy as i, NormalizedError as j, DebugSymbolsResult as k, DaemonTransportPreference as l, LeaseHeartbeatPayload as m, DaemonError as n, DaemonResponse as o, LeaseBackend as p, DaemonInstallSource as r, DaemonResponseData as s, DaemonArtifactType as t, JsonRpcId as u, SessionIsolationMode as v, SnapshotState as w, ScreenshotOverlayRef as x, SessionRuntimeHints as y, Platform as z };
307
+ export { SnapshotState as A, normalizeAgentDeviceError as C, ScreenshotOverlayRef as D, Rect as E, DeviceKind as F, DeviceTarget as I, Platform as L, SnapshotVisibility as M, centerOfRect as N, SnapshotNode as O, AppleOS as P, PlatformSelector as R, isAgentDeviceError as S, Point as T, SessionIsolationMode as _, DaemonLockPolicy as a, NormalizedError as b, DaemonResponseData as c, JsonRpcId as d, JsonRpcRequestEnvelope as f, ResponseLevel as g, ResponseCost as h, DaemonInstallSource as i, SnapshotUnchanged as j, SnapshotQualityVerdict as k, DaemonServerMode as l, NetworkIncludeMode as m, DaemonArtifactType as n, DaemonRequest as o, LeaseBackend as p, DaemonError as r, DaemonResponse as s, DaemonArtifact as t, DaemonTransportPreference as u, SessionRuntimeHints as v, normalizeError as w, defaultHintForCode as x, AppError as y, PublicPlatform as z };
@@ -1,2 +1,2 @@
1
1
  const e=/(token|secret|password|authorization|cookie|api[_-]?key|access[_-]?key|private[_-]?key|user[_-]?code|device[_-]?code|refresh[_-]?credential)/i,t=/\b(?:bearer\s+[a-z0-9._-]+|adc_(?:agent|live|refresh|cli)_[a-z0-9._-]+)\b/gi,n=/\b([a-z0-9_-]*(?:api[_-]?key|token|secret|password|user[_-]?code|device[_-]?code|refresh[_-]?credential)[a-z0-9_-]*)(\s*[=:]\s*)("[^"]*"|'[^']*'|\S+)/gi,r=/https?:\/\/[^\s"'<>]+/gi;function i(e){return a(e,new WeakSet)}function a(t,n,r){if(t==null)return t;if(typeof t==`string`)return o(t,r);if(typeof t!=`object`)return t;if(n.has(t))return`[Circular]`;if(n.add(t),Array.isArray(t))return t.map(e=>a(e,n));let i={};for(let[r,o]of Object.entries(t)){if(e.test(r)){i[r]=`[REDACTED]`;continue}i[r]=a(o,n,r)}return i}function o(r,i){let a=r.trim();if(!a)return r;if(i&&e.test(i))return`[REDACTED]`;let o=s(a);return o=o.replace(t,`[REDACTED]`),o=o.replace(n,(e,t,n,r,i,a)=>l({key:t,separator:n,rawValue:r,offset:i,input:a})||c(r)?e:`${t}${n}[REDACTED]`),o===a?a.length>400?`${a.slice(0,200)}...<truncated>`:a:o}function s(e){return e.replace(r,e=>u(e)??e)}function c(e){return/^adc_(?:agent|live|refresh|cli)_\.\.\.$/i.test(e)}function l(e){if(e.key.toLowerCase()!==`token`||!e.separator.includes(`:`))return!1;try{return new URL(e.rawValue).pathname.replace(/\/+$/,``)===`/api-keys`?/(?:^|\b)(?:service\/)?api\s+$/i.test(e.input.slice(0,e.offset)):!1}catch{return!1}}function u(e){try{let t=new URL(e);return t.search&&=`?REDACTED`,(t.username||t.password)&&(t.username=`REDACTED`,t.password=`REDACTED`),t.toString()}catch{return null}}function d(e,t=`COMMAND_FAILED`){return typeof e==`string`&&e.length>0?e:t}var f=class extends Error{code;details;cause;constructor(e,t,n,r){super(t),this.code=e,this.details=n,this.cause=r}};function p(e,t=`UNKNOWN`){return e instanceof f?e:e instanceof Error?new f(t,e.message,void 0,e):new f(t,`Unknown error`,{err:e})}function m(e){return e instanceof f}function h(e,t={}){return g(e,t)}function g(e,t={}){let n=p(e),r=n.details?i(n.details):void 0,a=S(r,`diagnosticId`)??t.diagnosticId,o=S(r,`logPath`)??t.logPath,s=S(r,`hint`)??E(n.code),c=C(r,`retriable`)??T(n.code),l=S(r,`supportedOn`),u=w(r),d=v(n.code,n.message,r);return{code:n.code,message:d,hint:s,diagnosticId:a,logPath:o,...c===void 0?{}:{retriable:c},...l===void 0?{}:{supportedOn:l},details:u}}const _=/^\S+ exited with code -?\d+$/;function v(e,t,n){if(e!==`COMMAND_FAILED`||n?.processExitError!==!0)return t;let r=x(typeof n?.stderr==`string`?n.stderr:``);return r?_.test(t)?r:t.includes(r)?t:`${t}: ${r}`:t}const y=[/^an error was encountered processing the command/i,/^underlying error\b/i,/^simulator device failed to complete the requested operation/i],b=/^(?:(?:adb|xcrun|simctl):\s*)?(?:error:\s*)?/i;function x(e){for(let t of e.split(`
2
- `)){let e=t.trim();if(!e||y.some(t=>t.test(e)))continue;let n=e.replace(b,``).trim();if(n)return n.length>200?`${n.slice(0,200)}...`:n}return null}function S(e,t){let n=e?.[t];return typeof n==`string`?n:void 0}function C(e,t){let n=e?.[t];return typeof n==`boolean`?n:void 0}function w(e){if(!e)return;let t={...e};return delete t.hint,delete t.diagnosticId,delete t.logPath,delete t.retriable,delete t.supportedOn,Object.keys(t).length>0?t:void 0}function T(e){switch(e){case`DEVICE_IN_USE`:return!0;default:return}}function E(e){switch(e){case`INVALID_ARGS`:return`Check command arguments and run --help for usage examples.`;case`SESSION_NOT_FOUND`:return`Run open first or pass an explicit device selector.`;case`TOOL_MISSING`:return`Install required platform tooling and ensure it is available in PATH.`;case`DEVICE_NOT_FOUND`:return`Verify the target device is booted/connected and selectors match.`;case`APP_NOT_INSTALLED`:return`Run apps to discover the exact installed package or bundle id, or install the app before open.`;case`UNSUPPORTED_OPERATION`:return`This command is not available for the selected platform/device.`;case`UNSUPPORTED_PLATFORM`:return`This platform is not supported for the requested operation; run devices to inspect available targets.`;case`AMBIGUOUS_MATCH`:return`Multiple candidates matched. Narrow the query or pass an exact identifier.`;case`DEVICE_IN_USE`:return`The device is busy with another agent-device request; retry once it frees up.`;case`NOT_IMPLEMENTED`:return`This command is part of the planned API but is not implemented yet.`;case`COMMAND_FAILED`:return`Retry with --debug and inspect diagnostics log for details.`;case`UNAUTHORIZED`:return`Refresh daemon metadata and retry the command.`;case`UNKNOWN`:return`Unexpected internal error. Retry with --debug and report the diagnostics log if it persists.`;default:return`Retry with --debug and inspect diagnostics log for details.`}}function D(e){return e===`xctest`||e===`android`||e===`macos-helper`||e===`linux-atspi`||e===`web`}function O(e){return e===void 0||e===`xctest`||e===`android`}function k(e){return e.map((e,t)=>({...e,ref:`e${t+1}`}))}const A=/^~s(\d+)$/,j=`Refs look like @e12, optionally pinned to the snapshot generation that minted them: @e12~s3 (the ref, then "~s" and the refsGeneration reported by the issuing snapshot/find response).`;function M(e){let t=e.trim(),n=t.indexOf(`~`);if(n===-1)return{base:t};let r=A.exec(t.slice(n));return!r||n===0?null:{base:t.slice(0,n),generation:Number(r[1])}}function N(e){let t=M(e);if(!t)return null;let n=t.base;return n.startsWith(`@`)?n.slice(1)||null:n.startsWith(`e`)?n:null}function P(e,t){return e.find(e=>e.ref===t)??null}function F(e){return JSON.stringify({interactiveOnly:e?.interactiveOnly===!0,depth:typeof e?.depth==`number`?e.depth:null,scope:e?.scope?.trim()||null,raw:e?.raw===!0})}function I(e){if(e)return{depth:e.snapshotDepth,interactiveOnly:e.snapshotInteractiveOnly,raw:e.snapshotRaw,scope:e.snapshotScope}}function L(e){return{x:Math.round(e.x+e.width/2),y:Math.round(e.y+e.height/2)}}const R=[`summary`,`headers`,`body`,`all`],z=[`digest`,`default`,`full`];function B(e){return e!==void 0&&e!=="default"}function V(e){return{parse(t){return e(t,`$`)}}}function H(e,t){throw Error(`${e}: ${t}`)}function U(e,t){return(!e||typeof e!=`object`||Array.isArray(e))&&H(t,`Expected an object`),e}function W(e,t){return typeof e!=`string`&&H(t,`Expected a string`),e}function G(e,t){return Number.isInteger(e)||H(t,`Expected an integer`),e}function K(e,t){return Array.isArray(e)||H(t,`Expected an array`),e}function q(e,t,n){let r=e[t];return r===void 0?void 0:W(r,`${n}.${t}`)}function J(e,t,n){let r=e[t];if(r!==void 0)return K(r,`${n}.${t}`).map((e,r)=>W(e,`${n}.${t}[${String(r)}]`))}function Y(e,t,n){let r=e[t];return r===void 0?void 0:G(r,`${n}.${t}`)}function X(e,t,n){let r=e[t];return r===void 0?void 0:U(r,`${n}.${t}`)}function Z(e,t,n,r){let i=e[t];if(i!==void 0)return(typeof i!=`string`||!n.includes(i))&&H(`${r}.${t}`,`Expected one of: ${n.join(`, `)}`),i}const Q=V((e,t)=>{let n=U(e,t);return{platform:Z(n,`platform`,[`ios`,`android`],t),metroHost:q(n,`metroHost`,t),metroPort:Y(n,`metroPort`,t),bundleUrl:q(n,`bundleUrl`,t),launchUrl:q(n,`launchUrl`,t)}});function $(e,t){let n=e.id;return n==null||typeof n!=`string`&&typeof n!=`number`&&H(`${t}.id`,`Expected a string, number, or null`),n}const ee=V((e,t)=>{let n=U(e,t);return{jsonrpc:q(n,`jsonrpc`,t),id:$(n,t),method:q(n,`method`,t),params:n.params}}),te=V((e,t)=>{let n=U(e,t);return{token:q(n,`token`,t),session:q(n,`session`,t),command:q(n,`command`,t),positionals:J(n,`positionals`,t),flags:X(n,`flags`,t),runtime:X(n,`runtime`,t),meta:X(n,`meta`,t)}});export{T as C,g as S,i as T,f as _,B as a,m as b,k as c,P as d,D as f,O as g,M as h,Q as i,F as l,I as m,z as n,ee as o,N as p,te as r,j as s,R as t,L as u,p as v,d as w,h as x,E as y};
2
+ `)){let e=t.trim();if(!e||y.some(t=>t.test(e)))continue;let n=e.replace(b,``).trim();if(n)return n.length>200?`${n.slice(0,200)}...`:n}return null}function S(e,t){let n=e?.[t];return typeof n==`string`?n:void 0}function C(e,t){let n=e?.[t];return typeof n==`boolean`?n:void 0}function w(e){if(!e)return;let t={...e};return delete t.hint,delete t.diagnosticId,delete t.logPath,delete t.retriable,delete t.supportedOn,Object.keys(t).length>0?t:void 0}function T(e){switch(e){case`DEVICE_IN_USE`:return!0;default:return}}function E(e){switch(e){case`INVALID_ARGS`:return`Check command arguments and run --help for usage examples.`;case`SESSION_NOT_FOUND`:return`Run open first or pass an explicit device selector.`;case`TOOL_MISSING`:return`Install required platform tooling and ensure it is available in PATH.`;case`DEVICE_NOT_FOUND`:return`Verify the target device is booted/connected and selectors match.`;case`APP_NOT_INSTALLED`:return`Run apps to discover the exact installed package or bundle id, or install the app before open.`;case`UNSUPPORTED_OPERATION`:return`This command is not available for the selected platform/device.`;case`UNSUPPORTED_PLATFORM`:return`This platform is not supported for the requested operation; run devices to inspect available targets.`;case`AMBIGUOUS_MATCH`:return`Multiple candidates matched. Narrow the query or pass an exact identifier.`;case`DEVICE_IN_USE`:return`The device is busy with another agent-device request; retry once it frees up.`;case`REPLAY_DIVERGENCE`:return`Read details.divergence (screen/suggestions) for repair context, or rerun with --json for the full report.`;case`REPAIR_SESSION_EXPIRED`:return`The --save-script repair session was reaped before it was finalized; re-run replay <script> --save-script from the start.`;case`REPAIR_COMMIT_FAILED`:return`The repair transaction completed, but committing its healed script failed at teardown (no-clobber refusal or a filesystem error); inspect the target path/permissions, then re-run replay <script> --save-script to retry.`;case`NOT_IMPLEMENTED`:return`This command is part of the planned API but is not implemented yet.`;case`COMMAND_FAILED`:return`Retry with --debug and inspect diagnostics log for details.`;case`UNAUTHORIZED`:return`Refresh daemon metadata and retry the command.`;case`UNKNOWN`:return`Unexpected internal error. Retry with --debug and report the diagnostics log if it persists.`;default:return`Retry with --debug and inspect diagnostics log for details.`}}function D(e){return e===`xctest`||e===`android`||e===`macos-helper`||e===`linux-atspi`||e===`web`}function O(e){return e===void 0||e===`xctest`||e===`android`}function k(e){return e.map((e,t)=>({...e,ref:`e${t+1}`}))}const A=/^~s(\d+)$/,j=`Refs look like @e12, optionally pinned to the snapshot generation that minted them: @e12~s3 (the ref, then "~s" and the refsGeneration reported by the issuing snapshot/find response).`;function M(e){let t=e.trim(),n=t.indexOf(`~`);if(n===-1)return{base:t};let r=A.exec(t.slice(n));return!r||n===0?null:{base:t.slice(0,n),generation:Number(r[1])}}function N(e){let t=M(e);if(!t)return null;let n=t.base;return n.startsWith(`@`)?n.slice(1)||null:n.startsWith(`e`)?n:null}function P(e,t){return e.find(e=>e.ref===t)??null}function F(e){return JSON.stringify({interactiveOnly:e?.interactiveOnly===!0,depth:typeof e?.depth==`number`?e.depth:null,scope:e?.scope?.trim()||null,raw:e?.raw===!0})}function I(e){if(e)return{depth:e.snapshotDepth,interactiveOnly:e.snapshotInteractiveOnly,raw:e.snapshotRaw,scope:e.snapshotScope}}function L(e){return{x:Math.round(e.x+e.width/2),y:Math.round(e.y+e.height/2)}}const R=[`summary`,`headers`,`body`,`all`],z=[`digest`,`default`,`full`];function B(e){return e!==void 0&&e!=="default"}function V(e){return{parse(t){return e(t,`$`)}}}function H(e,t){throw Error(`${e}: ${t}`)}function U(e,t){return(!e||typeof e!=`object`||Array.isArray(e))&&H(t,`Expected an object`),e}function W(e,t){return typeof e!=`string`&&H(t,`Expected a string`),e}function G(e,t){return Number.isInteger(e)||H(t,`Expected an integer`),e}function K(e,t){return Array.isArray(e)||H(t,`Expected an array`),e}function q(e,t,n){let r=e[t];return r===void 0?void 0:W(r,`${n}.${t}`)}function J(e,t,n){let r=e[t];if(r!==void 0)return K(r,`${n}.${t}`).map((e,r)=>W(e,`${n}.${t}[${String(r)}]`))}function Y(e,t,n){let r=e[t];return r===void 0?void 0:G(r,`${n}.${t}`)}function X(e,t,n){let r=e[t];return r===void 0?void 0:U(r,`${n}.${t}`)}function Z(e,t,n,r){let i=e[t];if(i!==void 0)return(typeof i!=`string`||!n.includes(i))&&H(`${r}.${t}`,`Expected one of: ${n.join(`, `)}`),i}const Q=V((e,t)=>{let n=U(e,t);return{platform:Z(n,`platform`,[`ios`,`android`],t),metroHost:q(n,`metroHost`,t),metroPort:Y(n,`metroPort`,t),bundleUrl:q(n,`bundleUrl`,t),launchUrl:q(n,`launchUrl`,t)}});function $(e,t){let n=e.id;return n==null||typeof n!=`string`&&typeof n!=`number`&&H(`${t}.id`,`Expected a string, number, or null`),n}const ee=V((e,t)=>{let n=U(e,t);return{jsonrpc:q(n,`jsonrpc`,t),id:$(n,t),method:q(n,`method`,t),params:n.params}}),te=V((e,t)=>{let n=U(e,t);return{token:q(n,`token`,t),session:q(n,`session`,t),command:q(n,`command`,t),positionals:J(n,`positionals`,t),input:X(n,`input`,t),flags:X(n,`flags`,t),runtime:X(n,`runtime`,t),meta:X(n,`meta`,t)}});export{T as C,g as S,i as T,f as _,B as a,m as b,k as c,P as d,D as f,O as g,M as h,Q as i,F as l,I as m,z as n,ee as o,N as p,te as r,j as s,R as t,L as u,p as v,d as w,h as x,E as y};
@@ -1 +1 @@
1
- import{_ as e}from"./sdk-contracts.js";const t=[`ios`,`ipados`,`tvos`,`watchos`,`visionos`,`macos`],n=[`apple`,`android`,`linux`,`web`],r=[`ios`,`macos`,`android`,`linux`,`web`],i=[...n,`ios`,`macos`],a=[`mobile`,`tv`,`desktop`];function o(e){return e===`apple`||e===`ios`||e===`macos`}function s(e){return e.appleOs===`macos`||e.platform===`macos`}function c(e){return o(e.platform)&&!s(e)}function l(e){return e.platform===`android`||o(e.platform)&&!s(e)}function u(e){return o(e.platform)?s(e)?`macos`:`ios`:e.platform}function d(e){return e===`macos`?{platform:`apple`,appleOs:`macos`}:e===`ios`?{platform:`apple`}:{platform:e}}function f(e){return o(e.platform)&&e.target===`tv`}function p(e){return r.includes(e)}function m(e){return t.includes(e)}function h(e,t){return t?t===`apple`?o(e.platform):t===`ios`?o(e.platform)&&!s(e):t===`macos`?o(e.platform)&&s(e):e.platform===t:!0}function g(e,t){return t?_(t):e===`macos`||e===`desktop`?`macOS`:e===`tv`?`tvOS`:`iOS`}function _(e){switch(e){case`tvos`:return`tvOS`;case`macos`:return`macOS`;case`visionos`:return`visionOS`;default:return`iOS`}}function v(e){let{simulatorSetPath:t,platform:n,target:r}=e;if(t&&!(n===`macos`||r===`desktop`))return t}function y(e){return e.map((e,t)=>({device:e,index:t})).sort((e,t)=>D(e,t)).map(({device:e})=>e)}function b(e){return!e||e===`apple`||e===`ios`}async function x(t,n,r={}){let i=t.filter(e=>C(e,n));if(n.udid){let t=i.find(e=>e.id===n.udid&&o(e.platform));if(!t)throw new e(`DEVICE_NOT_FOUND`,`No Apple device with UDID ${n.udid}`);return t}if(n.serial){let t=i.find(e=>e.id===n.serial&&e.platform===`android`);if(!t)throw new e(`DEVICE_NOT_FOUND`,`No Android device with serial ${n.serial}`);return t}if(r.allowStoppedAndroidAvdPlaceholders!==!0&&(i=i.filter(e=>!S(e))),n.deviceName){let t=E(n.deviceName),r=i.find(e=>E(e.name)===t);if(!r)throw new e(`DEVICE_NOT_FOUND`,`No device named ${n.deviceName}`);return r}A(i)&&(i=y(i));let a=i[0];if(a!==void 0&&i.length===1)return a;i.length===0&&T(n,r);let s=i.filter(e=>e.kind!==`device`),c=s.length>0?s:i,l=c.filter(e=>e.booted),u=l[0];if(u&&l.length===1&&!A(c))return u;let d=A(c)?c[0]:l[0]??c[0];return d||T(n,r),d}function S(e){return e.platform===`android`&&e.kind===`emulator`&&e.booted===!1&&!/^emulator-\d+$/.test(e.id)}function C(e,t,n={}){return h(e,t.platform)&&(!t.target||(e.target??`mobile`)===t.target)&&(!n.includeExplicitSelectors||w(e,t))}function w(e,t){return!(t.udid&&!(e.id===t.udid&&o(e.platform))||t.serial&&!(e.id===t.serial&&e.platform===`android`)||t.deviceName&&E(e.name)!==E(t.deviceName))}function T(t,n){let r=n.simulatorSetPath;throw r&&b(t.platform)?new e(`DEVICE_NOT_FOUND`,`No devices found in the scoped simulator set`,{simulatorSetPath:r,hint:`The simulator set at "${r}" appears to be empty. Create a compatible simulator first with xcrun simctl --set "${r}" create, or remove the scoped simulator set.`,selector:t}):new e(`DEVICE_NOT_FOUND`,`No devices found`,{selector:t})}function E(e){return e.toLowerCase().replace(/_/g,` `).replace(/\s+/g,` `).trim()}function D(e,t){return O(e.device)-O(t.device)||Number(t.device.booted===!0)-Number(e.device.booted===!0)||e.device.name.localeCompare(t.device.name)||e.index-t.index}function O(e){return e.kind===`simulator`?k(e,0,1,2,3):e.kind===`device`&&o(e.platform)&&!s(e)?k(e,10,11,12,13):14}function k(e,t,n,r,i){return{mobile:j(e.name)?n:t,tv:r,desktop:i}[e.target??`mobile`]}function A(e){return e.length>0&&e.every(e=>o(e.platform))}function j(e){return/\bipad\b/i.test(e)}export{x as _,m as a,s as c,f as d,C as f,v as g,g as h,d as i,l,u as m,n,o,h as p,i as r,c as s,a as t,p as u,y as v};
1
+ import{_ as e}from"./sdk-contracts.js";const t=[`ios`,`ipados`,`tvos`,`watchos`,`visionos`,`macos`],n=[`apple`,`android`,`vega`,`linux`,`web`],r=[`ios`,`macos`,`android`,`vega`,`linux`,`web`],i=[...n,`ios`,`macos`],a=[`mobile`,`tv`,`desktop`];function o(e){return e===`apple`||e===`ios`||e===`macos`}function s(e){return e.appleOs===`macos`||e.platform===`macos`}function c(e){return o(e.platform)&&!s(e)}function l(e){return e.platform===`android`||o(e.platform)&&!s(e)}function u(e){return o(e.platform)?s(e)?`macos`:`ios`:e.platform}function d(e){return e===`macos`?{platform:`apple`,appleOs:`macos`}:e===`ios`?{platform:`apple`}:{platform:e}}function f(e){return o(e.platform)&&e.target===`tv`}function p(e){return e.appleOs?e.appleOs:e.platform===`macos`?`macos`:f(e)?`tvos`:`ios`}function m(e){return r.includes(e)}function h(e){return t.includes(e)}function g(e,t){return t?t===`apple`?o(e.platform):t===`ios`?o(e.platform)&&!s(e):t===`macos`?o(e.platform)&&s(e):e.platform===t:!0}function _(e,t){return t?v(t):e===`macos`||e===`desktop`?`macOS`:e===`tv`?`tvOS`:`iOS`}function v(e){switch(e){case`tvos`:return`tvOS`;case`macos`:return`macOS`;case`visionos`:return`visionOS`;default:return`iOS`}}function y(e){let{simulatorSetPath:t,platform:n,target:r}=e;if(t&&!(n===`macos`||r===`desktop`))return t}function b(e){return e.map((e,t)=>({device:e,index:t})).sort((e,t)=>A(e,t)).map(({device:e})=>e)}function x(e){return!e||e===`apple`||e===`ios`}async function S(t,n,r={}){let i=t.filter(e=>w(e,n));if(n.udid){let t=i.find(e=>e.id===n.udid&&o(e.platform));if(!t)throw new e(`DEVICE_NOT_FOUND`,`No Apple device with UDID ${n.udid}`);return t}if(n.serial){let t=i.find(e=>e.id===n.serial&&E(e.platform));if(!t)throw new e(`DEVICE_NOT_FOUND`,D(n));return t}if(r.allowStoppedAndroidAvdPlaceholders!==!0&&(i=i.filter(e=>!C(e))),n.deviceName){let t=k(n.deviceName),r=i.find(e=>k(e.name)===t);if(!r)throw new e(`DEVICE_NOT_FOUND`,`No device named ${n.deviceName}`);return r}N(i)&&(i=b(i));let a=i[0];if(a!==void 0&&i.length===1)return a;i.length===0&&O(n,r);let s=i.filter(e=>e.kind!==`device`),c=s.length>0?s:i,l=c.filter(e=>e.booted),u=l[0];if(u&&l.length===1&&!N(c))return u;let d=N(c)?c[0]:l[0]??c[0];return d||O(n,r),d}function C(e){return e.platform===`android`&&e.kind===`emulator`&&e.booted===!1&&!/^emulator-\d+$/.test(e.id)}function w(e,t,n={}){return g(e,t.platform)&&(!t.target||(e.target??`mobile`)===t.target)&&(!n.includeExplicitSelectors||T(e,t))}function T(e,t){return!(t.udid&&!(e.id===t.udid&&o(e.platform))||t.serial&&!(e.id===t.serial&&E(e.platform))||t.deviceName&&k(e.name)!==k(t.deviceName))}function E(e){return e===`android`||e===`vega`}function D(e){return e.platform===`android`?`No Android device with serial ${e.serial}`:e.platform===`vega`?`No Vega VVD with serial ${e.serial}`:`No Android device or Vega VVD with serial ${e.serial}`}function O(t,n){let r=n.simulatorSetPath;throw r&&x(t.platform)?new e(`DEVICE_NOT_FOUND`,`No devices found in the scoped simulator set`,{simulatorSetPath:r,hint:`The simulator set at "${r}" appears to be empty. Create a compatible simulator first with xcrun simctl --set "${r}" create, or remove the scoped simulator set.`,selector:t}):new e(`DEVICE_NOT_FOUND`,`No devices found`,{selector:t})}function k(e){return e.toLowerCase().replace(/_/g,` `).replace(/\s+/g,` `).trim()}function A(e,t){return j(e.device)-j(t.device)||Number(t.device.booted===!0)-Number(e.device.booted===!0)||e.device.name.localeCompare(t.device.name)||e.index-t.index}function j(e){return e.kind===`simulator`?M(e,0,1,2,3):e.kind===`device`&&o(e.platform)&&!s(e)?M(e,10,11,12,13):14}function M(e,t,n,r,i){return{mobile:P(e.name)?n:t,tv:r,desktop:i}[e.target??`mobile`]}function N(e){return e.length>0&&e.every(e=>o(e.platform))}function P(e){return/\bipad\b/i.test(e)}export{y as _,h as a,b,s as c,E as d,f,_ as g,u as h,d as i,l,g as m,i as n,o,w as p,r,c as s,a as t,m as u,S as v,p as y};
@@ -1,5 +1,5 @@
1
- import { S as SnapshotNode } from "./sdk-contracts.js";
2
- //#region src/utils/selectors-parse.d.ts
1
+ import { O as SnapshotNode } from "./sdk-contracts.js";
2
+ //#region src/selectors/parse.d.ts
3
3
  type SelectorKey = 'id' | 'role' | 'text' | 'label' | 'value' | 'appname' | 'windowtitle' | 'visible' | 'hidden' | 'editable' | 'selected' | 'focused' | 'enabled' | 'hittable';
4
4
  type SelectorTerm = {
5
5
  key: SelectorKey;
@@ -17,7 +17,7 @@ declare function parseSelectorChain(expression: string): SelectorChain;
17
17
  declare function tryParseSelectorChain(expression: string): SelectorChain | null;
18
18
  declare function isSelectorToken(token: string): boolean;
19
19
  //#endregion
20
- //#region src/utils/finders.d.ts
20
+ //#region src/selectors/find.d.ts
21
21
  declare const FIND_LOCATORS: readonly ['any', 'text', 'label', 'value', 'role', 'id'];
22
22
  type FindLocator = (typeof FIND_LOCATORS)[number];
23
23
  type FindAction = {
@@ -40,13 +40,14 @@ type FindAction = {
40
40
  kind: 'wait';
41
41
  timeoutMs?: number;
42
42
  };
43
- declare function parseFindArgs(args: string[]): {
43
+ type ParsedFindArgs = {
44
44
  locator: FindLocator;
45
45
  query: string;
46
46
  action: FindAction['kind'];
47
47
  value?: string;
48
48
  timeoutMs?: number;
49
49
  };
50
+ declare function parseFindArgs(args: string[]): ParsedFindArgs;
50
51
  //#endregion
51
52
  //#region src/finders.d.ts
52
53
  type FindMatchOptions = {
@@ -1 +1 @@
1
- import{_ as e}from"./sdk-contracts.js";import{T as t}from"./sdk-batch.js";const n=[`any`,`text`,`label`,`value`,`role`,`id`],r=[`text`,`label`,`value`,`role`,`id`];function i(e,t,n,r={}){let i=c(n);if(!i)return{matches:[],score:0};let o=0,s=[];for(let n of e){if(r.requireRect&&!n.rect)continue;let e=a(n,t,i);if(!(e<=0)){if(e>o){o=e,s.length=0,s.push(n);continue}e===o&&s.push(n)}}return{matches:s,score:o}}function a(e,t,n){switch(t){case`role`:return s(e.type,n);case`label`:return o(e.label,n);case`value`:return o(e.value,n);case`id`:return o(e.identifier,n);default:return Math.max(o(e.label,n),o(e.value,n),o(e.identifier,n))}}function o(e,t){let n=c(e??``);return n?n===t?2:+!!n.includes(t):0}function s(e,t){let n=l(e??``);return n?n===t?2:+!!n.includes(t):0}function c(e){return e.trim().toLowerCase().replace(/\s+/g,` `)}function l(e){let t=e.trim();return t?(t=(t.split(`.`).pop()??t).replace(/XCUIElementType/gi,``).toLowerCase(),t):``}function u(t){let n=`any`,i=0;r.includes(t[0])&&(n=t[0],i=1);let a=t[i]??``,o=t.slice(i+1);if(o.length===0)return{locator:n,query:a,action:`click`};let s=o[0]?.toLowerCase();if(s===`get`){let t=o[1]?.toLowerCase();if(t===`text`)return{locator:n,query:a,action:`get_text`};if(t===`attrs`)return{locator:n,query:a,action:`get_attrs`};throw new e(`INVALID_ARGS`,`find get only supports text or attrs`)}if(s===`wait`){let e=f(o[1]);return{locator:n,query:a,action:`wait`,timeoutMs:e??void 0}}if(s===`exists`)return{locator:n,query:a,action:`exists`};if(s===`click`)return{locator:n,query:a,action:`click`};if(s===`focus`)return{locator:n,query:a,action:`focus`};if(s===`fill`){let e=o.slice(1).join(` `);return{locator:n,query:a,action:`fill`,value:e}}if(s===`type`){let e=o.slice(1).join(` `);return{locator:n,query:a,action:`type`,value:e}}throw new e(`INVALID_ARGS`,`Unsupported find action: ${o[0]}`)}function d(e,n){return e!==`any`||!n.includes(`=`)&&!n.includes(`||`)?null:t(n)}function f(e){if(!e)return null;let t=Number(e);return Number.isFinite(t)?t:null}function p(e,t,n,r){return i(e,t,n,typeof r==`boolean`?{requireRect:r}:r)}export{u as a,c as i,n,d as o,i as r,p as t};
1
+ import{U as e}from"./sdk-batch-runner.js";function t(t,n,r,i){return e(t,n,r,typeof i==`boolean`?{requireRect:i}:i)}export{t};
@@ -1,4 +1,4 @@
1
- import { t as DaemonArtifactType } from "./sdk-contracts.js";
1
+ import { n as DaemonArtifactType } from "./sdk-contracts.js";
2
2
  //#region src/io.d.ts
3
3
  type FileInputRef = {
4
4
  kind: 'path';