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.
- package/README.md +62 -70
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.20.1.apk +0 -0
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.20.1.apk.sha256 +1 -0
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.20.1.manifest.json +10 -0
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.1.apk +0 -0
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.20.1.apk.sha256 +1 -0
- 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
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerAXSnapshotBridge.h +2 -0
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerAXSnapshotBridge.m +5 -0
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedGesture.h +5 -10
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedGesture.m +74 -174
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Alert.swift +113 -19
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+BlockingSystemModalResolution.swift +82 -0
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +325 -123
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandJournal.swift +2 -2
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift +149 -105
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Lifecycle.swift +56 -2
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+LifecycleCacheTests.swift +73 -0
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +51 -26
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScrollGesture.swift +2 -2
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SequenceExecution.swift +2 -107
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Snapshot.swift +130 -13
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotCapturePlan.swift +51 -8
- package/dist/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotTraversalIdentityTests.swift +24 -0
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedGesturePolicy.swift +1 -1
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SystemModal.swift +43 -35
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TextEntry.swift +1 -1
- package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift +16 -1
- package/dist/src/agent-browser-tool.js +1 -1
- package/dist/src/agent-device-client.js +3 -0
- package/dist/src/android-adb.d.ts +1 -1
- package/dist/src/android-adb.js +1 -1
- package/dist/src/android-input-method-overlays.js +1 -0
- package/dist/src/android-input-ownership.js +1 -6
- package/dist/src/android-system-chrome.js +1 -0
- package/dist/src/android.js +1 -1
- package/dist/src/app-lifecycle.js +5 -5
- package/dist/src/app-log-request-scope.js +1 -0
- package/dist/src/app-resolution.js +1 -0
- package/dist/src/apple-multitouch-support.js +1 -0
- package/dist/src/apps.js +5 -5
- package/dist/src/boot-diagnostics.js +2 -0
- package/dist/src/cli-config.js +1 -0
- package/dist/src/cli-help.js +131 -40
- package/dist/src/cli-runner.js +1 -1
- package/dist/src/cli.js +15 -11
- package/dist/src/command-metadata.js +1 -1
- package/dist/src/command-schema.js +3 -3
- package/dist/src/compatibility-policy.js +1 -0
- package/dist/src/context.js +1 -0
- package/dist/src/contracts.d.ts +2 -2
- package/dist/src/debug-symbols.js +1 -1
- package/dist/src/device-input-state.js +1 -1
- package/dist/src/devices2.js +1 -1
- package/dist/src/devices4.js +1 -0
- package/dist/src/find.js +1 -1
- package/dist/src/finders.js +1 -1
- package/dist/src/generic.js +1 -1
- package/dist/src/helper.js +1 -1
- package/dist/src/index.d.ts +533 -279
- package/dist/src/index.js +1 -1
- package/dist/src/input-actions.js +4 -3
- package/dist/src/install-artifact.js +1 -0
- package/dist/src/install-source.d.ts +5 -1
- package/dist/src/install-source.js +1 -1
- package/dist/src/install-source2.js +1 -1
- package/dist/src/interaction-snapshot.js +1 -1
- package/dist/src/interaction.d.ts +230 -0
- package/dist/src/interaction.js +1 -1
- package/dist/src/interactor.js +2 -2
- package/dist/src/interactor2.js +1 -0
- package/dist/src/internal/bin.js +1 -1
- package/dist/src/internal/daemon.js +42 -20
- package/dist/src/internal/png-worker.d.ts +22 -0
- package/dist/src/internal/png-worker.js +1 -1
- package/dist/src/launch-console.js +1 -0
- package/dist/src/lease-context.js +1 -0
- package/dist/src/lease.js +1 -1
- package/dist/src/linux.js +1 -1
- package/dist/src/logcat.js +5 -0
- package/dist/src/method-scope.js +1 -0
- package/dist/src/metro-types.d.ts +52 -0
- package/dist/src/metro.d.ts +3 -3
- package/dist/src/notifications.js +1 -1
- package/dist/src/png-worker-contract.js +1 -1
- package/dist/src/process-lock.js +1 -0
- package/dist/src/react-native.js +1 -1
- package/dist/src/record-trace.js +1 -1
- package/dist/src/recording-export-quality.js +15 -0
- package/dist/src/register-builtins.js +1 -0
- package/dist/src/registry.js +24 -24
- package/dist/src/remote-config.d.ts +1 -1
- package/dist/src/reporting.js +8 -7
- package/dist/src/runner-client.js +1 -1
- package/dist/src/runner-disposal.js +2 -0
- package/dist/src/runner-lease.js +1 -0
- package/dist/src/runner-provider.js +1 -1
- package/dist/src/runner-sequence.js +1 -1
- package/dist/src/runtime.js +3 -3
- package/dist/src/runtime2.js +1 -0
- package/dist/src/sdk-android-adb.d.ts +97 -33
- package/dist/src/sdk-android-adb.js +4 -4
- package/dist/src/sdk-batch-runner.d.ts +2 -1
- package/dist/src/sdk-batch-runner.js +3 -2
- package/dist/src/sdk-contracts.d.ts +70 -149
- package/dist/src/sdk-contracts.js +1 -1
- package/dist/src/sdk-device.js +1 -1
- package/dist/src/sdk-finders.d.ts +5 -4
- package/dist/src/sdk-finders.js +1 -1
- package/dist/src/sdk-io.d.ts +1 -1
- package/dist/src/sdk-remote-config.d.ts +19 -96
- package/dist/src/sdk-remote-config.js +1 -1
- package/dist/src/sdk-selectors.js +1 -1
- package/dist/src/selector-runtime.js +1 -1
- package/dist/src/selector-vocabulary.js +1 -0
- package/dist/src/selectors.d.ts +12 -3
- package/dist/src/selectors.js +1 -1
- package/dist/src/server.js +3 -3
- package/dist/src/session-target-evidence.js +1 -0
- package/dist/src/session.js +8 -10
- package/dist/src/simctl.js +1 -1
- package/dist/src/simulator.js +1 -1
- package/dist/src/snapshot-diagnostics.js +5 -2
- package/dist/src/snapshot-quality.js +1 -1
- package/dist/src/snapshot.js +1 -1
- package/dist/src/snapshot2.js +1 -2
- package/dist/src/tool-provider3.js +1 -0
- package/dist/src/unsupported-interactor.js +1 -0
- package/dist/src/url.js +1 -1
- package/dist/src/web.js +1 -1
- package/package.json +34 -27
- package/server.json +2 -2
- package/skills/agent-device/SKILL.md +5 -3
- package/android-multitouch-helper/dist/agent-device-android-multitouch-helper-0.19.3.apk +0 -0
- package/android-multitouch-helper/dist/agent-device-android-multitouch-helper-0.19.3.apk.sha256 +0 -1
- package/android-multitouch-helper/dist/agent-device-android-multitouch-helper-0.19.3.manifest.json +0 -10
- package/android-snapshot-helper/dist/agent-device-android-snapshot-helper-0.19.3.apk +0 -0
- package/android-snapshot-helper/dist/agent-device-android-snapshot-helper-0.19.3.apk.sha256 +0 -1
- package/dist/src/apple-runner-options.js +0 -1
- package/dist/src/cli-output.js +0 -1
- package/dist/src/client.js +0 -3
- package/dist/src/handler-utils.js +0 -1
- package/dist/src/output-path.js +0 -1
- package/dist/src/points.js +0 -4
- package/dist/src/provider.js +0 -1
- package/dist/src/providers.js +0 -1
- package/dist/src/record-trace-recording.js +0 -23
- package/dist/src/recording-provider.js +0 -1
- package/dist/src/sdk-batch.js +0 -2
- package/dist/src/selectors2.js +0 -1
- package/dist/src/ttl-memo.js +0 -1
- package/dist/src/tv-remote.js +0 -14
- package/dist/src/xml.js +0 -2
- /package/{macos-helper → apple/macos-helper}/Package.swift +0 -0
- /package/{macos-helper → apple/macos-helper}/Sources/AgentDeviceMacOSHelper/AudioProbe.swift +0 -0
- /package/{macos-helper → apple/macos-helper}/Sources/AgentDeviceMacOSHelper/SnapshotTraversal.swift +0 -0
- /package/{macos-helper → apple/macos-helper}/Sources/AgentDeviceMacOSHelper/main.swift +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerApp.m +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunner.xcodeproj/project.pbxproj +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunner.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunner.xcodeproj/xcshareddata/xcschemes/AgentDeviceRunner.xcscheme +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/AgentDeviceRunnerUITests-Bridging-Header.h +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/AgentDeviceRunnerUITests.entitlements +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerObjCExceptionCatcher.h +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerObjCExceptionCatcher.m +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTapPointPolicy.swift +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+AXSnapshotFallback.swift +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Environment.swift +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Exceptions.swift +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+FlatSnapshotFiltering.swift +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Navigation.swift +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+ScreenRecorder.swift +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Transport.swift +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+TvRemote.swift +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/AgentDeviceRunnerUITests.xctestplan +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/RecordingScripts/recording-overlay.swift +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/RecordingScripts/recording-resize.swift +0 -0
- /package/dist/{apple-runner → apple/runner}/AgentDeviceRunner/RecordingScripts/recording-trim.swift +0 -0
- /package/{src/platforms/linux → linux}/atspi-dump.py +0 -0
package/dist/src/simctl.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{s as e}from"./sdk-device.js";import{
|
|
1
|
+
import{s as e}from"./sdk-device.js";import{o as t}from"./boot-diagnostics.js";import{a as n}from"./tool-provider.js";function r(e,n={}){let r=t(n.simulatorSetPath);return r?[`simctl`,`--set`,r,...e]:[`simctl`,...e]}function i(t,n){return!e(t)||t.kind!==`simulator`?[`simctl`,...n]:r(n,{simulatorSetPath:t.simulatorSetPath})}function a(e,t,r){return n(i(e,t),r)}export{i as n,a as r,r as t};
|
package/dist/src/simulator.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./rolldown-runtime.js";import{_ as t}from"./sdk-contracts.js";import{h as n,p as r}from"./sdk-android-adb.js";import{
|
|
1
|
+
import{t as e}from"./rolldown-runtime.js";import{_ as t}from"./sdk-contracts.js";import{h as n,p as r}from"./sdk-android-adb.js";import{l as i,n as a,s as o,t as s}from"./boot-diagnostics.js";import{F as c,N as l,q as u}from"./runner-disposal.js";import{a as d,i as f}from"./tool-provider.js";import{n as p,t as m}from"./simctl.js";var h=e({SIMULATOR_BOOTED_MEMO_TTL_MS:()=>v,ensureBootedSimulator:()=>E,getSimulatorState:()=>O,markSimulatorBooted:()=>S,openIosSimulatorApp:()=>T,requireSimulatorDevice:()=>w,shutdownSimulator:()=>D});const g=[`Simulator`],_=[`Device Hub`,`Simulator`],v=5e3,y=u({ttlMs:v});function b(e){return`${e.id}|${e.simulatorSetPath??``}`}function x(e){return y.get(b(e))===!0}function S(e){y.set(b(e),!0)}function C(e){y.delete(b(e))}function w(e,n){if(e.kind!==`simulator`)throw new t(`UNSUPPORTED_OPERATION`,`${n} is only supported on iOS simulators`)}async function T(e={}){let t=e.deviceHub?_:g,n=e.background?[`-g`,`-a`]:[`-a`];for(let e of t)if((await f(`open`,[...n,e],{allowFailure:!0,timeoutMs:1e4})).exitCode===0)return}async function E(e,c={}){if(e.kind!==`simulator`)return;if((x(e)?`Booted`:await O(e))===`Booted`){S(e),c.focusExisting&&await T({background:c.deviceHub,deviceHub:c.deviceHub});return}c.onColdBootStart?.(e);let u=o.fromTimeoutMs(l),f,m;try{await i(async({deadline:i})=>{if(i?.isExpired())throw new t(`COMMAND_FAILED`,`iOS simulator boot deadline exceeded`,{timeoutMs:l});let a=Math.max(1e3,i?.remainingMs()??18e4);f=await d(p(e,[`boot`,e.id]),{allowFailure:!0,timeoutMs:a});let o=`${f.stdout}\n${f.stderr}`.toLowerCase(),s=o.includes(`already booted`)||o.includes(`current state: booted`);if(f.exitCode!==0&&!s)throw new t(`COMMAND_FAILED`,`simctl boot failed`,r(f));m=await d(p(e,[`bootstatus`,e.id,`-b`]),{allowFailure:!0,timeoutMs:a}),n(m,`simctl bootstatus failed`);let c=await O(e);if(c!==`Booted`)throw new t(`COMMAND_FAILED`,`Simulator is still booting`,{state:c})},{maxAttempts:3,baseDelayMs:500,maxDelayMs:2e3,jitter:.2,shouldRetry:e=>{let t=a({error:e,stdout:m?.stdout??f?.stdout,stderr:m?.stderr??f?.stderr,context:{platform:`ios`,phase:`boot`}});return t!==`IOS_BOOT_TIMEOUT`&&t!==`CI_RESOURCE_STARVATION_SUSPECTED`}},{deadline:u,phase:`boot`,classifyReason:e=>a({error:e,stdout:m?.stdout??f?.stdout,stderr:m?.stderr??f?.stderr,context:{platform:`ios`,phase:`boot`}})})}catch(n){let r=a({error:n,stdout:m?.stdout??f?.stdout,stderr:m?.stderr??f?.stderr,context:{platform:`ios`,phase:`boot`}});throw new t(`COMMAND_FAILED`,`iOS simulator failed to boot`,{platform:`ios`,deviceId:e.id,timeoutMs:l,elapsedMs:u.elapsedMs(),reason:r,hint:s(r),boot:f,bootstatus:m})}S(e),await T({deviceHub:c.deviceHub})}async function D(e){C(e);let t=await d(p(e,[`shutdown`,e.id]),{allowFailure:!0,timeoutMs:15e3});return{success:t.exitCode===0,exitCode:t.exitCode,stdout:t.stdout,stderr:t.stderr}}async function O(e){let t=typeof e==`string`?e:e.id,n=await d(typeof e==`string`?m([`list`,`devices`,`-j`]):p(e,[`list`,`devices`,`-j`]),{allowFailure:!0,timeoutMs:c});if(n.exitCode!==0)return null;try{let e=JSON.parse(n.stdout);for(let n of Object.values(e.devices??{})){let e=n.find(e=>e.udid===t);if(e)return e.state}return null}catch{return null}}export{D as a,w as i,O as n,h as o,S as r,E as t};
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import{_ as e}from"./sdk-contracts.js";import{n as t,t as n}from"./version.js";import{n as r,t as i}from"./path-resolution.js";import{a,n as o,o as s,u as c}from"./host-process.js";import{d as l,l as u,u as d}from"./sdk-batch-runner.js";import f from"node:crypto";import p from"node:fs";import m from"node:path";function h(e){return new Promise((t,n)=>{let r=``;e.setEncoding(`utf8`),e.on(`data`,e=>{r+=e}),e.on(`end`,()=>t(r)),e.on(`error`,n)})}async function g(t,n,r){let i=[],a=0;for await(let o of t){let t=Buffer.isBuffer(o)?o:Buffer.from(o);if(a+=t.length,a>n)throw new e(`INVALID_ARGS`,r);i.push(t)}return Buffer.concat(i)}function _(e,t={}){let n=v(e,t);return{baseDir:n,infoPath:m.join(n,`daemon.json`),lockPath:m.join(n,`daemon.lock`),logPath:m.join(n,`daemon.log`),sessionsDir:m.join(n,`sessions`)}}function v(e,t){let n=(e??``).trim();return n?r(n,{env:t.env}):y(t)}function y(e={}){let t=m.join(i(`~`,{env:e.env}),`.agent-device`),r=e.projectRoot??n();return b(r)?m.join(t,`dev`,x(r)):t}function b(e){return p.existsSync(m.join(e,`package.json`))&&p.existsSync(m.join(e,`src`,`daemon.ts`))}function x(e){let t=ee(e),n=m.basename(t).replaceAll(/[^a-zA-Z0-9._-]+/g,`-`),r=f.createHash(`sha1`).update(t).digest(`hex`).slice(0,12);return`${n||`agent-device`}-${r}`}function ee(e){try{return p.realpathSync.native(e)}catch{return m.resolve(e)}}function te(e){let t=(e??``).trim().toLowerCase();return t===`http`?`http`:t===`dual`?`dual`:`socket`}function ne(e){let t=(e??``).trim().toLowerCase();return t===`auto`?`auto`:t===`socket`?`socket`:t===`http`?`http`:`auto`}function re(e){return(e??``).trim().toLowerCase()===`tenant`?`tenant`:`none`}function ie(e){if(!e)return;let t=e.trim();if(t&&/^[a-zA-Z0-9._-]{1,128}$/.test(t))return t}const ae=/(?:^|[^\w$.])(?:import|export)\s+(?:type\s+)?(?:[^'"`]*?\s+from\s+)?['"]([^'"]+)['"]/gm,S=/import\(\s*['"]([^'"]+)['"]\s*\)/gm,C=[`.ts`,`.tsx`,`.js`,`.jsx`,`.mjs`,`.cjs`];function w(){let e=process.argv[1];return e?T(e):`unknown`}function T(e,t=n()){try{let n=m.resolve(t),r=[m.resolve(e)],i=new Set,a=[];for(;r.length>0;){let e=r.pop();if(!e||i.has(e))continue;i.add(e);let t=p.statSync(e);if(!t.isFile())continue;let o=m.relative(n,e)||e;a.push(`${o}:${t.size}:${Math.trunc(t.mtimeMs)}`);let s=p.readFileSync(e,`utf8`);for(let t of E(s)){let n=O(e,t);n&&r.push(n)}}let o=a.sort().join(`|`),s=f.createHash(`sha1`).update(o).digest(`hex`);return`graph:${a.length}:${s}`}catch{return`unknown`}}function E(e){let t=new Set;return D(e,ae,t),D(e,S,t),[...t]}function D(e,t,n){t.lastIndex=0;let r=null;for(;(r=t.exec(e))!==null;){let e=r[1]?.trim();e?.startsWith(`.`)&&n.add(e)}}function O(e,t){let n=m.resolve(m.dirname(e),t),r=k(n);if(r)return r;for(let e of C){let t=k(`${n}${e}`);if(t)return t}for(let e of C){let t=k(m.join(n,`index${e}`));if(t)return t}return null}function k(e){try{return p.statSync(e).isFile()?e:null}catch{return null}}const A=[/(^|[/\s"'=])dist\/src\/daemon\.js($|[\s"'])/,/(^|[/\s"'=])dist\/src\/internal\/daemon\.js($|[\s"'])/,/(^|[/\s"'=])src\/daemon\.ts($|[\s"'])/];function j(e){let t=e.toLowerCase().replaceAll(`\\`,`/`);return t.includes(`agent-device`)?A.some(e=>e.test(t)):!1}function M(e,t){if(!o(e))return!1;if(t){let n=s(e);if(!n||n!==t)return!1}let n=a(e);return n?j(n):!1}function N(e,t){try{return process.kill(e,t),!0}catch(e){let t=e.code;if(t===`ESRCH`||t===`EPERM`)return!1;throw e}}async function P(e,t){M(e,t.expectedStartTime)&&N(e,`SIGTERM`)&&(await c(e,t.termTimeoutMs)||N(e,`SIGKILL`)&&await c(e,t.killTimeoutMs))}const F=/^[A-Za-z0-9_@%+=:,./-]+$/;function I(e){return`'${e.replaceAll(`'`,`'\\''`)}'`}function L(e){return F.test(e)?e:I(e)}function R(e,t){let n=[],r=e+t.toString(),i=r.indexOf(`
|
|
1
|
+
import{T as e,_ as t,h as n}from"./sdk-contracts.js";import{N as r,j as i}from"./sdk-android-adb.js";import{M as a,R as o,et as s,g as c,h as l,m as u}from"./sdk-batch-runner.js";import{Dn as ee,Gn as te,Jn as ne,Pn as re,Qn as ie,Xn as d,bn as ae,cr as f,er as oe,kn as se,rr as ce,sr as le}from"./recording-export-quality.js";import{n as ue,t as de}from"./version.js";import{n as fe,t as pe}from"./path-resolution.js";import{h as me,n as he,r as ge,t as _e}from"./sdk-device.js";import{mt as ve}from"./sdk-selectors.js";import{a as ye,n as be,o as xe,u as p}from"./host-process.js";import Se from"node:crypto";import m from"node:fs";import h from"node:path";import{StringDecoder as Ce}from"node:string_decoder";const we=`/agent-device`,Te=`x-agent-device-tenant`;function Ee(e){return De(e,we)}function De(e,t){let n=e.endsWith(`/`)?e:`${e}/`;return new URL(t.replace(/^\/+/,``),n).toString()}function Oe(e){let t=e?.trim();return t?{authorization:`Bearer ${t}`,"x-agent-device-token":t}:{}}function ke(e){let t=e?.trim();return t?{[Te]:t}:{}}const Ae=`.webm`;function je(e){return e===`web`?Ae:`.mp4`}function Me(e,t){return h.extname(e)?e:`${e}${t}`}function Ne(e){return`./recording-${Date.now()}${je(e)}`}function Pe(e){return new Promise((t,n)=>{let r=``;e.setEncoding(`utf8`),e.on(`data`,e=>{r+=e}),e.on(`end`,()=>t(r)),e.on(`error`,n)})}async function Fe(e,n,r){let i=[],a=0;for await(let o of e){let e=Buffer.isBuffer(o)?o:Buffer.from(o);if(a+=e.length,a>n)throw new t(`INVALID_ARGS`,r);i.push(e)}return Buffer.concat(i)}function g(e){return e.replace(/[^a-zA-Z0-9._-]/g,`_`)}function _(e,t){return fe(e,{cwd:t})}function v(e){let t=e.result?.text;if(typeof t==`string`)return t;let n=e.positionals??[];return n.length===0?``:n[0]?.startsWith(`@`)?n.length>=3?n.slice(2).join(` `):n.slice(1).join(` `):n.length>=3&&!Number.isNaN(Number(n[0]))&&!Number.isNaN(Number(n[1]))?n.slice(2).join(` `):n.slice(1).join(` `)}const y=/^[A-Z_][A-Z0-9_]*$/,Ie=/(\\\$\{)|\$\{([A-Za-z_][A-Za-z0-9_.]*)(?::-((?:[^}\\]|\\.)*))?\}/g;function b(e){return e.startsWith(`AD_`)}function Le(e){return new t(`INVALID_ARGS`,`The AD_* namespace is reserved for built-in variables. Rename ${e} to avoid the AD_ prefix.`)}function Re(e){let t={};if(e.builtins)for(let[n,r]of Object.entries(e.builtins))t[n]=r;let n=[e.fileEnv,e.shellEnv,e.cliEnv];for(let e of n)if(e)for(let[n,r]of Object.entries(e)){if(b(n))throw Le(n);t[n]=r}return{values:t,expandedBuiltinNames:new Set}}function ze(e){let t={};for(let[n,r]of Object.entries(e)){if(typeof r!=`string`||!n.startsWith(`AD_VAR_`))continue;let e=n.slice(7);e.length!==0&&y.test(e)&&(b(e)||(t[e]=r))}return t}function Be(e){let n={};for(let r of e){let e=r.indexOf(`=`);if(e<=0)throw new t(`INVALID_ARGS`,`Invalid -e entry "${r}": expected KEY=VALUE.`);let i=r.slice(0,e);if(!y.test(i))throw new t(`INVALID_ARGS`,`Invalid -e key "${i}": keys must be uppercase letters, digits, and underscores (e.g. APP_ID).`);if(b(i))throw Le(i);n[i]=r.slice(e+1)}return n}function Ve(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function He(e){if(e&&typeof e==`object`&&!Array.isArray(e)){let t={};for(let[n,r]of Object.entries(e))typeof r==`string`&&(t[n]=r);return t}return process.env}function Ue(e,n,r){return e.replace(Ie,(e,i,a,o)=>{if(i)return"${";if(!a)return e;if(Object.prototype.hasOwnProperty.call(n.values,a))return b(a)&&(n.expandedBuiltinNames??=new Set).add(a),String(n.values[a]);if(o!==void 0)return o.replace(/\\(.)/g,`$1`);throw new t(`INVALID_ARGS`,`Unresolved variable \${${a}} at ${r.file}:${r.line}.`)})}function We(e,t,n){return{...e,positionals:(e.positionals??[]).map(e=>Ue(e,t,n)),flags:Ge(e.flags,t,n)??{},runtime:Ge(e.runtime,t,n)}}function Ge(e,t,n){return e&&x(e,t,n)}function x(e,t,n){return typeof e==`string`?Ue(e,t,n):Array.isArray(e)?e.map(e=>x(e,t,n)):e&&typeof e==`object`?Object.fromEntries(Object.entries(e).map(([e,r])=>[e,x(r,t,n)])):e}function Ke(e){return Object.entries(e.values).filter(([t,n])=>n.length>0&&(!b(t)||e.expandedBuiltinNames?.has(t))).map(([e,t])=>({name:e,value:t})).sort((e,t)=>t.value.length-e.value.length)}const qe=/^\$\{([A-Z_][A-Z0-9_]*)\}$/;function Je(e){if(e!==e.trim()||!y.test(e))throw new t(`INVALID_ARGS`,`Invalid --record-as variable "${e}": use uppercase letters, digits, and underscores (for example PASSWORD).`);if(e.startsWith(`AD_`))throw new t(`INVALID_ARGS`,`Invalid --record-as variable "${e}": the AD_* namespace is reserved for built-in replay variables.`);return e}function Ye(e){return`\${${e}}`}function Xe(e){let t=qe.exec(e);if(!(!t?.[1]||t[1].startsWith(`AD_`)))return t[1]}const Ze=new Set([`text`,`label`,`value`]),Qe=new Set(`action.backend.cost.delayMs.evidence.gesture.hint.kind.maestroFallbackReason.maestroNonHittableCoordinateFallbackAllowed.maestroNonHittableCoordinateFallbackUsed.message.platform.ref.referenceHeight.referenceWidth.refLabel.resolution.selector.selectorChain.settle.targetHittable.targetKind.text.warning.x.y`.split(`.`)),$e=new Set([`action`,`backend`,`gesture`,`kind`,`platform`,`ref`,`selector`,`targetKind`]),et=new Set([`cost`,`evidence`,`resolution`,`settle`]),tt=new Map([[`cost`,new Set([`nodeCount`,`runnerRoundTrips`,`wallClockMs`])],[`evidence`,new Set([`changedFromBefore`,`digest`,`foregroundApp`,`interactiveNodeCount`,`nodeCount`])],[`resolution`,new Set([`alternatives`,`kind`,`matchCount`,`phase`,`source`,`tiebreak`,`winnerDiagnostic`])],[`resolution.alternatives`,new Set([`diagnosticRef`,`label`,`role`])],[`resolution.winnerDiagnostic`,new Set([`diagnosticRef`,`label`,`role`])],[`settle`,new Set([`captures`,`diff`,`hint`,`quietMs`,`refs`,`refsGeneration`,`settled`,`tail`,`tailTruncated`,`timeoutMs`,`waitedMs`])],[`settle.diff`,new Set([`lines`,`summary`,`truncated`])],[`settle.diff.lines`,new Set([`kind`,`ref`,`text`])],[`settle.diff.summary`,new Set([`additions`,`removals`,`unchanged`])],[`settle.refs`,new Set([`ref`])],[`settle.tail`,new Set([`label`,`ref`,`role`])]]),nt=new Set([`evidence.digest`,`evidence.foregroundApp`,`resolution.alternatives.diagnosticRef`,`resolution.alternatives.role`,`resolution.kind`,`resolution.phase`,`resolution.source`,`resolution.tiebreak`,`resolution.winnerDiagnostic.diagnosticRef`,`resolution.winnerDiagnostic.role`,`settle.diff.lines.kind`,`settle.diff.lines.ref`,`settle.refs.ref`,`settle.tail.ref`,`settle.tail.role`]);function rt(e,t,n){if(!e)return e;let r=ut(e.selectorChain);return{...ot(e,t,n),...typeof e.text==`string`?{text:n}:{},...r?{selectorChain:r.filter(e=>!at(e,t))}:{}}}function it(e,t,n){return e&&{...e,...e.label===t?{label:n}:{},ancestry:e.ancestry.map(e=>({...e,...e.label===t?{label:n}:{}})),...e.scrollRegion?{scrollRegion:{...e.scrollRegion,...e.scrollRegion.label===t?{label:n}:{}}}:{}}}function at(e,t){return s(e)?.selectors.some(e=>e.terms.some(e=>Ze.has(e.key)&&typeof e.value==`string`&&C(e.value,t,``)!==e.value))??!1}function ot(e,t,n){return Object.fromEntries(Object.entries(e).map(([e,r])=>[Qe.has(e)?e:C(e,t,n),st(r,e,t,n)]))}function st(e,t,n,r){return typeof e==`string`&&$e.has(t)?e:t===`selectorChain`&<(e)?ct(e,n):S(e,n,r,et.has(t)?t:void 0)}function S(e,t,n,r){if(typeof e==`string`)return r&&nt.has(r)?e:C(e,t,n);if(Array.isArray(e))return e.map(e=>S(e,t,n,r));if(!e||typeof e!=`object`)return e;let i=r?tt.get(r):void 0;return Object.fromEntries(Object.entries(e).map(([e,a])=>{let o=i?.has(e)===!0;return[o?e:C(e,t,n),S(a,t,n,o?`${r}.${e}`:void 0)]}))}function ct(e,t){return e.filter(e=>!at(e,t))}function C(e,t,n){if(!t)return e===t?n:e;let r=n?e.split(n):[e];return r.every(e=>!e.includes(t))?e:t.trim()?r.map(e=>e.replaceAll(t,n)).join(n):n}function lt(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)}function ut(e){return lt(e)?e:void 0}function dt(e,t,n){e.saveScriptPath!==void 0&&e.saveScriptPath!==t&&!n&&(e.saveScriptForce=void 0),e.saveScriptPath=t}function ft(e,t){if(t.flags?.noRecord||_t(e,t))return;t.flags?.saveScript&&(e.recordSession=!0,typeof t.flags.saveScript==`string`&&(dt(e,_(t.flags.saveScript),t.flags.force),e.saveScriptDefaultedHealedPath=!1),t.flags.force&&(e.saveScriptForce=!0));let n=pt(t),r={ts:Date.now(),command:n.command,positionals:n.positionals,runtime:n.runtime,flags:yt(n.flags),result:n.result,...n.targetEvidence?{targetEvidence:n.targetEvidence}:{}};return e.actions.push(r),i({level:`debug`,phase:`record_action`,data:{command:t.command,session:e.name}}),r}function pt(e){if(e.command!==`fill`||typeof e.flags.recordAs!=`string`)return e;let t=Ye(Je(e.flags.recordAs)),n=v({ts:0,command:e.command,positionals:e.positionals,flags:e.flags});return{...e,positionals:mt(e.positionals,t),result:rt(e.result,n,t),targetEvidence:it(e.targetEvidence,n,t)}}function mt(e,t){let n=e[0];return n?.startsWith(`@`)?e.length>=3?[n,e[1],t]:[n,t]:e.length>=3&&Number.isFinite(Number(e[0]))&&Number.isFinite(Number(e[1]))?[e[0],e[1],t]:n===void 0?[t]:[n,t]}const ht=new Set([`snapshot`,`get`,`is`,`find`]);function gt(e){return e.internal?.replayPlanStep===!0?!1:ht.has(e.command)}function _t(e,t){return!t.interactiveObservation||e.saveScriptBoundary===void 0?!1:t.flags?.record!==!0}const vt=[`platform`,`device`,`udid`,`serial`,`out`,`verbose`,`metroHost`,`metroPort`,`bundleUrl`,`launchUrl`,`snapshotInteractiveOnly`,`snapshotDepth`,`snapshotScope`,`snapshotRaw`,...oe,`relaunch`,`saveScript`,`force`,`noRecord`,`record`,`fps`,`quality`,`hideTouches`,`count`,`pointerCount`,`intervalMs`,`delayMs`,`holdMs`,`jitterPx`,`doubleTap`,`clickButton`,`pauseMs`,`pattern`];function yt(e){if(!e)return{};let t={};for(let n of vt)e[n]!==void 0&&(t[n]=e[n]);return t}function w(e){return e.startsWith(`@`)?n(e)?.base??e:e}const T=/^-?\d+(\.\d+)?$/,bt=/^[^\s"\\]+$/,xt=new Map([[`--count`,`count`],[`--interval-ms`,`intervalMs`],[`--hold-ms`,`holdMs`],[`--jitter-px`,`jitterPx`]]),St=new Map([[`--count`,`count`],[`--pause-ms`,`pauseMs`]]),Ct=new Map([[`--pointer-count`,`pointerCount`]]),wt=new Map([[`--delay-ms`,`delayMs`]]);function E(e){return e===`click`||e===`press`}function D(e){return E(e)||e===`longpress`}function Tt(e){return e===`type`||e===`fill`}function O(e){return Dt(e,Ot)}function Et(e){return JSON.stringify(e)}function k(e){return Dt(e,kt)}function Dt(e,t){return t(e)?e:Et(e)}function Ot(e){return kt(e)&&e.startsWith(`@`)||T.test(e)}function kt(e){return bt.test(e)}const At=new Set([`fill`,`type`]);function jt(e){if(!At.has(e.command)){let t=(e.positionals??[]).map(e=>O(e));return[e.command,...t].join(` `)}let t=Mt(e).map(e=>O(e)).join(` `);return[e.command,t,`<text>`].filter(e=>e.length>0).join(` `)}function Mt(e){if(e.command===`type`)return[];let t=e.positionals??[],n=t[0];return n===void 0?[]:n.startsWith(`@`)?[n]:t.length>=3&&T.test(n)&&T.test(t[1]??``)?[n,t[1]]:[n]}function A(e,t){let n=t.flags??{};if(E(t.command)){typeof n.count==`number`&&e.push(`--count`,String(n.count)),typeof n.intervalMs==`number`&&e.push(`--interval-ms`,String(n.intervalMs)),typeof n.holdMs==`number`&&e.push(`--hold-ms`,String(n.holdMs)),typeof n.jitterPx==`number`&&e.push(`--jitter-px`,String(n.jitterPx)),n.doubleTap===!0&&e.push(`--double-tap`);let t=n.clickButton;t&&t!==`primary`&&e.push(`--button`,t);return}if(t.command===`swipe`){typeof n.count==`number`&&e.push(`--count`,String(n.count)),typeof n.pauseMs==`number`&&e.push(`--pause-ms`,String(n.pauseMs)),(n.pattern===`one-way`||n.pattern===`ping-pong`)&&e.push(`--pattern`,n.pattern);return}if(t.command===`gesture`){typeof n.pointerCount==`number`&&e.push(`--pointer-count`,String(n.pointerCount));return}Tt(t.command)&&typeof n.delayMs==`number`&&e.push(`--delay-ms`,String(n.delayMs))}function Nt(e,t){t&&((t.platform===`ios`||t.platform===`android`)&&e.push(`--platform`,t.platform),typeof t.metroHost==`string`&&t.metroHost.length>0&&e.push(`--metro-host`,k(t.metroHost)),typeof t.metroPort==`number`&&e.push(`--metro-port`,String(t.metroPort)),typeof t.bundleUrl==`string`&&t.bundleUrl.length>0&&e.push(`--bundle-url`,k(t.bundleUrl)),typeof t.launchUrl==`string`&&t.launchUrl.length>0&&e.push(`--launch-url`,k(t.launchUrl)))}function Pt(e,t){let[n,...r]=t.positionals??[];n&&e.push(k(n));for(let t of r)e.push(O(t));typeof t.flags?.fps==`number`&&e.push(`--fps`,String(t.flags.fps)),typeof t.flags?.screenshotMaxSize==`number`&&e.push(`--max-size`,String(t.flags.screenshotMaxSize)),(typeof t.flags?.quality==`number`||typeof t.flags?.quality==`string`)&&e.push(`--quality`,String(t.flags.quality)),t.flags?.hideTouches&&e.push(`--hide-touches`)}function Ft(e,t){t.flags?.snapshotInteractiveOnly&&e.push(`-i`),typeof t.flags?.snapshotDepth==`number`&&e.push(`-d`,String(t.flags.snapshotDepth)),t.flags?.snapshotScope&&e.push(`-s`,O(t.flags.snapshotScope)),t.flags?.snapshotRaw&&e.push(`--raw`)}function It(e,t){for(let n of t.positionals??[])e.push(O(n));ce(e,t.flags)}function Lt(e,t,n={}){let r=t.positionals??[],i=n.includeAllPositionals?r:r.slice(0,1);for(let t of i)e.push(k(t));Nt(e,t.flags)}function Rt(e,t){for(let n of t.positionals??[])e.push(O(t.command===`wait`?w(n):n));A(e,t)}function zt(e,t){let n=[],r={},i=E(e)?xt:e===`swipe`?St:e===`gesture`?Ct:Tt(e)?wt:void 0;for(let a=0;a<t.length;a+=1){let o=t[a];if(E(e)&&o===`--double-tap`){r.doubleTap=!0;continue}let s=t[a+1];if(E(e)&&o===`--button`&&s!==void 0){let e=s;(e===`primary`||e===`secondary`||e===`middle`)&&(r.clickButton=e),a+=1;continue}let c=i?.get(o);if(c&&s!==void 0){let e=Vt(s);if(e!==null){r[c]=e,a+=1;continue}}if(e===`swipe`&&o===`--pattern`&&s!==void 0){let e=s;(e===`one-way`||e===`ping-pong`)&&(r.pattern=e),a+=1;continue}n.push(o)}return{positionals:n,flags:r}}function Bt(e){let t=[],n={};for(let r=0;r<e.length;r+=1){let i=e[r],a=e[r+1];if(i===`--platform`&&a!==void 0){let e=a;(e===`ios`||e===`android`)&&(n.platform=e),r+=1;continue}if(i===`--metro-host`&&a!==void 0){n.metroHost=a,r+=1;continue}if(i===`--metro-port`&&a!==void 0){let e=Vt(a);e!==null&&(n.metroPort=e),r+=1;continue}if(i===`--bundle-url`&&a!==void 0){n.bundleUrl=a,r+=1;continue}if(i===`--launch-url`&&a!==void 0){n.launchUrl=a,r+=1;continue}t.push(i)}return{positionals:t,flags:n}}function Vt(e){if(!e)return null;let t=Number(e);return!Number.isFinite(t)||t<0?null:Math.floor(t)}function Ht(e,t){for(let n of t.positionals??[])e.push(O(n));t.flags?.relaunch&&e.push(`--relaunch`),Nt(e,t.runtime)}function Ut(e){let t=[],n={};for(let r of e){if(r===`--relaunch`){n.relaunch=!0;continue}t.push(r)}let r=Bt(t);return{positionals:r.positionals,flags:n,runtime:Wt(r.flags)?r.flags:void 0}}function Wt(e){return!!(e.platform||e.metroHost||e.metroPort!==void 0||e.bundleUrl||e.launchUrl)}function Gt(e,t={}){let n=[e.command];return e.command===`snapshot`?Ft(n,e):e.command===`open`?Ht(n,e):e.command===`runtime`?Lt(n,e,{includeAllPositionals:t.runtimeIncludeAllPositionals}):e.command===`record`?Pt(n,e):e.command===`screenshot`?It(n,e):Rt(n,e),n.join(` `)}function Kt(e){return e.targetEvidence?[ve(e.targetEvidence)]:[]}function qt(e){let n=e.flatMap((e,t)=>e.command===`open`?[t]:[]);if(n.length!==1||n[0]!==0)throw new t(`COMMAND_FAILED`,`Cannot publish this session: an open-to-destination script requires exactly one initial recorded open.`,{retriable:!1,hint:`Close this session and start a fresh one with open <app> --save-script[=<path>].`});if(e.some(e=>e.command===`close`))throw new t(`COMMAND_FAILED`,`Cannot publish an active-session script containing close.`,{retriable:!1,hint:`Close this session and record the journey again from a fresh open --save-script session.`});let r=-1;for(let[t,n]of e.entries())a({command:n.command,positionals:n.positionals,flags:n.flags})===`mutates-app`&&(r=t);if(!e.slice(r+1).some(Xt))throw new t(`COMMAND_FAILED`,`Cannot publish this session without a portable destination guard after the final mutating action.`,{retriable:!0,hint:`Record a selector-targeted wait on a labeled or id-bearing landmark, for example wait 'role="heading" label="Screen X"', so its recorded identity is captured, then retry session save-script.`})}function Jt(e){for(let n of e){let e=Zt(n),r=e??(n.command===`wait`?n.positionals[0]:void 0);if(r?.startsWith(`@`))throw new t(`COMMAND_FAILED`,`Cannot publish recorded step "${n.command} ${r}": the session-local ref was not converted to a portable selector.`,{retriable:!1,hint:`Close this session and record the journey again using selectors or resolvable refs.`});if(n.command===`find`&&a(n)===`mutates-app`)throw new t(`COMMAND_FAILED`,`Cannot publish a recorded mutating find step because its target identity is not replay-verifiable.`,{retriable:!1,hint:`Close this session and record the journey again with an explicit selector-targeted click, press, fill, or focus action.`});let i=e;if(!(!i||!s(i)||n.targetEvidence))throw new t(`COMMAND_FAILED`,`Cannot publish recorded step "${n.command} ${i}": recording-time target identity evidence is missing.`,{retriable:!1,hint:`Close this session and record the journey again from open --save-script so target-v1 evidence is captured before each interaction.`})}}function Yt(e,n){if(e instanceof t){if(e.details?.reason===`script_target_exists`)return new t(e.code,`A file already exists at ${String(e.details.path)}.`,{...e.details,retriable:!0,hint:`Retry session save-script with another path, or pass --force to replace the existing file. The session remains armed.`});let n=e.details?.retriable===!0;return new t(e.code,e.message,{...e.details,retriable:n,hint:e.details?.hint??(n?`Fix the recorded journey or target, then retry session save-script. The session remains armed.`:`Close this session and start a fresh one with open <app> --save-script[=<path>].`)})}let r=e instanceof Error?e.message:String(e);return new t(`COMMAND_FAILED`,`Failed to publish the active session script${n?` to ${n}`:``}: ${r}`,{retriable:!0,hint:`Check the target path and permissions, then retry session save-script. The session remains armed.`})}function Xt(e){if(e.command!==`wait`)return!1;let t=o(e.positionals);return t?.kind!==`selector`||s(t.selectorExpression)===null?!1:e.targetEvidence?.verification===`verified`}function Zt(e){if(e.command===`get`)return e.positionals[1];if(D(e.command)||e.command===`fill`){let[t,n]=e.positionals;return t!==void 0&&n!==void 0&&Qt(t)&&Qt(n)?void 0:t}}function Qt(e){return e.trim().length>0&&Number.isFinite(Number(e))}function $t(e){return e.saveScriptBoundary===void 0?!1:e.saveScriptCommitted?!0:!e.saveScriptComplete}var en=class{sessionsDir;constructor(e){this.sessionsDir=e}write(e,t){let n=e.saveScriptBoundary!==void 0,r=t?.publication===`active`,i;try{if(!e.recordSession||$t(e))return{written:!1};let a=tn(e,{appendCompleteSentinel:n,activePublication:r});i=this.resolveScriptPath(e);let o=h.dirname(i);return m.existsSync(o)||m.mkdirSync(o,{recursive:!0}),an({scriptPath:i,script:a.script,force:t?.force}),n&&(e.saveScriptCommitted=!0),{written:!0,path:i,actionCount:a.actionCount}}catch(t){return nn({session:e,error:t,scriptPath:i,repairArmed:n,activePublication:r})}}resolveScriptPath(e){if(e.saveScriptPath)return _(e.saveScriptPath);let t=g(e.name),n=new Date(e.createdAt).toISOString().replace(/[:.]/g,`-`);return h.join(this.sessionsDir,`${t}-${n}.ad`)}};function tn(e,t){let n=on(e,{strictPortableRefs:t.activePublication});return t.activePublication&&qt(n),{script:hn(e,n,t.appendCompleteSentinel),actionCount:n.length}}function nn(e){let{session:n,error:r,scriptPath:a,repairArmed:o,activePublication:s}=e;if(i({level:`warn`,phase:`session_script_write_failed`,data:{session:n.name,path:a,error:r instanceof Error?r.message:String(r)}}),o)return{written:!1,error:rn(r,a)};if(s)return{written:!1,error:Yt(r,a)};if(r instanceof t)throw r;return{written:!1}}function rn(e,n){if(e instanceof t)return e;let r=e instanceof Error?e.message:String(e);return new t(`COMMAND_FAILED`,`Failed to write the healed script${n?` to ${n}`:``}: ${r}`,{hint:`The repair transaction completed but the healed .ad could not be published; check the target path and permissions, then retry close --save-script.`})}function an(e){let{scriptPath:n,script:r,force:i}=e,a=h.dirname(n),o=h.join(a,`.${h.basename(n)}.${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}.tmp`);m.writeFileSync(o,r);try{if(i){m.renameSync(o,n);return}m.linkSync(o,n)}catch(e){throw e.code===`EEXIST`?new t(`COMMAND_FAILED`,`A file already exists at ${n}; remove it, pass replay --save-script=<other-path>, or pass --force/--overwrite to replace it.`,{reason:`script_target_exists`,path:n}):e}finally{m.rmSync(o,{force:!0})}}function on(e,t={}){let n=e.saveScriptBoundary!==void 0,r=e.actions.slice(e.saveScriptBoundary??0),i=[];for(let a of r){if(a.command===`snapshot`)continue;let r=cn(a);if(r){i.push(r);continue}(n||t.strictPortableRefs)&&sn(a);let o=mn(e,a);o&&i.push(o),i.push(a)}return t.strictPortableRefs&&Jt(i),i}function sn(e){if(!j(e.command))return;let n=e.command===`get`?e.positionals?.[1]:e.positionals?.[0];if(n?.startsWith(`@`))throw new t(`COMMAND_FAILED`,`Cannot write recorded step "${e.command} ${n}" to a script: it never resolved to a selector, so the ref would not resolve in a fresh replay session.`)}function cn(e){let t=ln(e);if(!(!t||!j(e.command)))return E(e.command)?{...e,positionals:[t]}:e.command===`longpress`?dn(e,t):e.command===`fill`?un(e,t):fn(e,t)}function ln(e){let t=Array.isArray(e.result?.selectorChain)&&e.result.selectorChain.every(e=>typeof e==`string`)?e.result.selectorChain:[];return t.length>0?t.join(` || `):void 0}function j(e){return D(e)||e===`fill`||e===`get`}function un(e,t){let n=v(e);return n.length>0?{...e,positionals:[t,n]}:void 0}function dn(e,t){let n=typeof e.result?.durationMs==`number`?String(e.result.durationMs):pn(e.positionals??[]);return{...e,positionals:n?[t,n]:[t]}}function fn(e,t){let n=e.positionals?.[0];return n===`text`||n===`attrs`?{...e,positionals:[n,t]}:void 0}function pn(e){let t=e.at(-1);if(!(e.length<=1||t===void 0||t.trim()===``))return Number.isFinite(Number(t))?t:void 0}function mn(e,t){if(!j(t.command))return;let n=t.result?.refLabel;if(typeof n!=`string`||n.trim().length===0)return;let r=n.trim();return{ts:t.ts,command:`snapshot`,positionals:[],flags:{platform:e.device.platform,snapshotInteractiveOnly:!0,snapshotScope:r},result:{scope:r}}}function hn(e,t,n){let r=[],i=e.device.kind?` kind=${e.device.kind}`:``;r.push(`context platform=${me(e.device)} device=${Et(e.device.name)}${i} theme=unknown`);for(let e of t)e.flags?.noRecord||(r.push(...Kt(e)),r.push(gn(e)));return n&&r.push(`# agent-device:heal-complete`),`${r.join(`
|
|
2
|
+
`)}\n`}function gn(e){return _n([e.command],e)||Gt(e)}function _n(e,t){if(E(t.command))return vn(e,t);if(t.command===`fill`)return yn(e,t);if(t.command===`get`)return bn(e,t)}function vn(e,t){let n=t.positionals?.[0];if(n){if(n.startsWith(`@`))return e.push(O(w(n))),M(e,t),A(e,t),e.join(` `);if(t.positionals.length===1)return e.push(O(n)),A(e,t),e.join(` `)}}function yn(e,t){let n=t.positionals?.[0];if(!n?.startsWith(`@`))return;e.push(O(w(n))),M(e,t);let r=t.positionals.slice(1).join(` `);return t.positionals.length>1&&e.push(O(r)),A(e,t),e.join(` `)}function bn(e,t){let n=t.positionals?.[0],r=t.positionals?.[1];if(!(!n||!r))return e.push(O(n)),e.push(O(w(r))),r.startsWith(`@`)&&M(e,t),e.join(` `)}function M(e,t){let n=t.result?.refLabel;typeof n==`string`&&n.trim().length>0&&e.push(O(n))}const xn=[`status`,`get`,`dismiss`,`enter`,`return`];function N(e){return xn.includes(e)}const Sn=[`id`,`deviceId`,`device_id`,`serial`,`udid`,`device_udid`,`identifier`],Cn={ios:`iOS`,ipados:`iPadOS`,tvos:`tvOS`,watchos:`watchOS`,visionos:`visionOS`,macos:`macOS`,apple:`Apple`,android:`Android`,linux:`Linux`,web:`Web`};function wn(e,t){let n=t??{};switch(e.command){case f.devices:return Tn(n.devices);case f.apps:return En(n.apps,e.flags?.appsFilter);case f.boot:return Dn(`Booted`,n,!0);case f.shutdown:return Dn(`Shut down`,n,!1);case f.install:return On(`Installed`,n);case f.reinstall:return On(`Reinstalled`,n);case f.screenshot:return kn(e,n);default:return{}}}function Tn(e){if(!Array.isArray(e))return{};let t=e.flatMap(e=>{let t=jn(e);return t?[t]:[]}),n=t.slice(0,5),r=Math.max(0,t.length-n.length),i=t.slice(0,3);return{summary:Bn(`Found ${t.length} ${Vn(`device`,t.length)}`,i.map(e=>Rn(e,!0)),Math.max(0,t.length-i.length)),details:{deviceCount:t.length,devices:n,...r>0?{omittedDeviceCount:r}:{}}}}function En(e,t){if(!Array.isArray(e))return{};let n=e.flatMap(e=>{let t=I(e);return t?[t]:[]}),r=n.slice(0,5),i=Math.max(0,n.length-r.length),a=n.slice(0,3);return{summary:Bn(`Found ${n.length} ${Vn(`app`,n.length)}`,a,Math.max(0,n.length-a.length)),details:{appCount:n.length,apps:r,...i>0?{omittedAppCount:i}:{},...t===`all`||t===`user-installed`?{filter:t}:{}}}}function Dn(e,t,n){let r=Mn(t);if(!r)return{};let i={device:r,...Ln(t),booted:n};return{summary:`${e} ${Rn(i,!1)}`,details:i}}function On(e,t){let n=I(t.appName),r=I(t.bundleId),i=P(t,[`packageName`,`package`]),a=I(t.platform),o=I(t.launchTarget),s=P(t,[`bundleId`,`packageName`,`package`,`appId`,`launchTarget`]),c=zn(n,s);if(!c)return{};let l={};return F(l,`appName`,n),F(l,`bundleId`,r),F(l,`packageName`,i),F(l,`platform`,a),o!==s&&F(l,`launchTarget`,o),{summary:`${e} ${c}`,details:l}}function kn(e,t){let n=An(e,t);return n?{details:{requestedFileName:n}}:{}}function An(e,t){let n=H(e.meta?.clientArtifactPaths?.path)??H(t.path);if(n)return V(n)}function jn(e){if(!u(e))return;let t=Mn(e);if(t)return{name:t,...Ln(e)}}function Mn(e){let t=P(e,[`name`,`deviceName`,`device`]);return!t||!Nn(e,t)?t:Fn(e)}function Nn(e,t){let n=Pn(t);return Sn.some(t=>{let r=I(e[t]);return r!==void 0&&Pn(r)===n})}function Pn(e){return e.toLowerCase()}function Fn(e){let t=I(e.appleOs),n=I(e.platform),r=I(e.kind),i=In(t,n);return i&&(r===`simulator`||r===`emulator`)?`${i} ${r}`:i?`${i} device`:r===`simulator`?`Simulator`:r===`emulator`?`Emulator`:`Unnamed device`}function In(e,t){let n=e??t;if(!(!n||!Object.hasOwn(Cn,n)))return Cn[n]}function Ln(e){let t=I(e.platform),n=I(e.appleOs),r=I(e.kind),i=I(e.target);return{...t?{platform:t}:{},...n?{appleOs:n}:{},...r?{kind:r}:{},...i?{target:i}:{},...typeof e.booted==`boolean`?{booted:e.booted}:{}}}function Rn(e,t){let n=I(e.name)??I(e.device)??`device`,r=I(e.platform),i=I(e.appleOs),a=[r,i===r?void 0:i,I(e.kind),I(e.target),t&&typeof e.booted==`boolean`?e.booted?`booted`:`stopped`:void 0].filter(e=>!!e);return a.length>0?`${n} (${a.join(`, `)})`:n}function zn(e,t){return e&&t&&e!==t?`${e} (${t})`:e??t}function P(e,t){for(let n of t){let t=I(e[n]);if(t)return t}}function F(e,t,n){n&&(e[t]=n)}function Bn(e,t,n){let r=[...t,...n>0?[`+${n} more`]:[]];return r.length>0?`${e}: ${r.join(`, `)}`:e}function Vn(e,t){return t===1?e:`${e}s`}function I(e){let t=H(e);if(!t)return;let n=t.trim(),r=Array.from(n);return r.length<=120?n:`${r.slice(0,119).join(``)}…`}function L(e){return I(e)}function R(e){return typeof e==`boolean`?e:void 0}function z(e,t){let n=L(e);return n&&t.includes(n)?n:void 0}function B(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0))}function V(e){let t=H(e);return t?I(t.split(/[\\/]/).at(-1)):void 0}function H(e){if(typeof e==`string`)return e.trim().length>0?e:void 0}function U(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}const Hn=[`up`,`down`,`left`,`right`],Un=[`top`,`bottom`];function Wn(e){return`${e.command===f.reinstall?`Reinstalled`:`Installed`} ${Jn(e.result??{})??`app`}`}function Gn(e){let t=e.result??{};switch(e.command){case f.scroll:return Xn(t);case f.screenshot:return $n(t);case f.home:return`Went home`;case f.back:return tr(t);case f.appSwitcher:return`Opened app switcher`;case f.orientation:return nr(t);case f.viewport:return rr(t);case f.clipboard:return ir(t);case f.keyboard:return ar(t);case f.tvRemote:return sr(t);case f.gesture:return cr(t);case f.swipe:return lr(t);case f.trace:return dr(`trace`,e);case f.record:return dr(`recording`,e);default:return}}function Kn(e){let t=e.result??{};switch(e.command){case f.scroll:return B({direction:z(t.direction,Hn),edge:z(t.edge,Un),passes:U(t.passes),amount:U(t.amount),pixels:U(t.pixels),durationMs:U(t.durationMs),x1:U(t.x1),y1:U(t.y1),x2:U(t.x2),y2:U(t.y2)});case f.screenshot:return B({requestedFileName:er(t)});case f.back:return B({mode:z(t.mode,d)});case f.orientation:return B({orientation:z(t.orientation,ee)});case f.viewport:return B({width:U(t.width),height:U(t.height)});case f.clipboard:return B({action:z(t.action,[`read`,`write`])});case f.keyboard:return or(t);case f.tvRemote:return B({button:z(t.button,ae),durationMs:U(t.durationMs)});case f.gesture:case f.swipe:return ur(t);case f.trace:case f.record:return B({action:z(t.action,[`start`,`stop`]),fileName:pr(e),showTouches:R(t.showTouches)});default:return{}}}function qn(e,t){if(e.command!==f.screenshot)return t;let n=An(e,t);return n?{...t,requestedFileName:n}:t}function Jn(e){let t=L(e.appName),n=mr(e,[`bundleId`,`packageName`,`appBundleId`,`launchTarget`]);return t&&n&&t!==n?`${t} (${n})`:t??n??Yn(e)}function Yn(e){let t=L(e.app);return t&&!t.includes(`/`)&&!t.includes(`\\`)?t:void 0}function Xn(e){let t=z(e.direction,Hn),n=z(e.edge,Un),r=U(e.passes);return n?Zn(n,r):t?Qn(t,e):`Scrolled`}function Zn(e,t){return t===0?`Already at ${e}`:t===void 0?`Scrolled to ${e}`:`Scrolled to ${e} in ${t} ${t===1?`pass`:`passes`}`}function Qn(e,t){let n=U(t.pixels);if(n!==void 0)return`Scrolled ${e} by ${n}px`;let r=U(t.amount);return r===void 0?`Scrolled ${e}`:`Scrolled ${e} by ${r}`}function $n(e){let t=er(e);return t?`Captured screenshot ${t}`:`Captured screenshot`}function er(e){return V(e.requestedFileName)??V(e.path)}function tr(e){return z(e.mode,d)===`system`?`Went back using system navigation`:`Went back`}function nr(e){let t=z(e.orientation,ee);return t?`Rotated to ${t}`:`Changed orientation`}function rr(e){let t=U(e.width),n=U(e.height);return t!==void 0&&n!==void 0?`Set viewport to ${t}×${n}`:`Changed viewport`}function ir(e){let t=z(e.action,[`read`,`write`]);return t===`read`?`Read clipboard`:t===`write`?`Updated clipboard`:`Used clipboard`}function ar(e){let t=H(e.action);if(!t||!N(t))return`Used keyboard`;if(t===`dismiss`)return R(e.dismissed)===!1?`Keyboard was already hidden`:`Dismissed keyboard`;if(t===`enter`||t===`return`)return`Pressed keyboard return`;let n=R(e.visible);return n===void 0?`Inspected keyboard`:n?`Keyboard is visible`:`Keyboard is hidden`}function or(e){let t=H(e.action);return B({action:t&&N(t)?t:void 0,platform:z(e.platform,[`ios`,`android`]),visible:R(e.visible),wasVisible:R(e.wasVisible),dismissed:R(e.dismissed),attempts:U(e.attempts)})}function sr(e){let t=z(e.button,ae);return t?`Pressed TV remote ${t}`:`Used TV remote`}function cr(e){let t=z(e.kind,[`fling`,`pan`,`pinch`,`rotate`,`transform`]);return t?`Ran ${t} gesture`:`Ran gesture`}function lr(e){let t=U(e.count);return t!==void 0&&t>1?`Swiped ${t} times`:`Swiped`}function ur(e){return B({kind:z(e.kind,[`fling`,`pan`,`pinch`,`rotate`,`transform`]),durationMs:U(e.durationMs),pointerCount:U(e.pointerCount),x1:U(e.x1),y1:U(e.y1),x2:U(e.x2),y2:U(e.y2),count:U(e.count),pauseMs:U(e.pauseMs),pattern:z(e.pattern,[`one-way`,`ping-pong`]),scale:U(e.scale)})}function dr(e,t){let n=fr(e,z(t.result?.action,[`start`,`stop`])),r=pr(t);return r?`${n} ${r}`:n}function fr(e,t){return t===`start`?e===`trace`?`Started trace`:`Started recording`:t===`stop`?e===`trace`?`Stopped trace`:`Stopped recording`:e===`trace`?`Updated trace`:`Updated recording`}function pr(e){let t=e.result??{};return V(t.requestedFileName)??V(t.outPath)??V(t.path)??V(e.positionals[1])}function mr(e,t){for(let n of t){let t=L(e[n]);if(t)return t}}function hr(e){switch(e.command){case f.open:return`Opened ${W(e)??`session`}`;case f.close:return`Closed ${L(e.result?.session)??`session`}`;case f.click:case f.press:return`Tapped ${W(e)??`target`}`;case f.longPress:return`Long pressed ${W(e)??`target`}`;case f.fill:return`Filled ${W(e)??`target`}`;case f.type:return`Typed text`;case f.install:case f.reinstall:case le.installSource:return Wn(e);default:return Gn(e)??`Ran ${e.command}`}}function gr(e){return B({command:e.command,positionals:Tr(e),flags:Ir(e),..._r(e),...vr(e),...yr(e),...Kn(e)})}function _r(e){if(!br(e.command))return{};let t=e.result??{};return B({ref:J(t),targetLabel:W(e),selectorChainLength:Nr(t.selectorChain)?.length,x:U(t.x),y:U(t.y),x2:U(t.x2),y2:U(t.y2),durationMs:U(t.durationMs)})}function vr(e){if(!xr(e.command))return{};let t=e.result??{};return B({platform:z(t.platform,ge),target:z(t.target,_e),appName:L(t.appName),appBundleId:L(t.appBundleId),bundleId:L(t.bundleId),packageName:L(t.packageName),launchTarget:L(t.launchTarget)})}function yr(e){let t=e.result??{};return e.command===f.snapshot?{...Array.isArray(t.nodes)?{nodeCount:t.nodes.length}:{}}:e.command!==f.wait&&e.command!==f.find&&e.command!==f.get&&e.command!==f.is?{}:B({waitedMs:U(t.waitedMs),found:R(t.found)})}function br(e){return e===f.click||e===f.press||e===f.longPress||e===f.focus||e===f.fill}function xr(e){return e===f.open||e===f.install||e===f.reinstall||e===le.installSource}function W(e){let t=e.result??{};return Sr(t)??Cr(t)??wr(t)??jr(e.positionals[0])}function Sr(e){let t=J(e);if(t)return t.startsWith(`@`)?t:`@${t}`}function Cr(e){let t=U(e.x),n=U(e.y);if(t!==void 0&&n!==void 0)return`(${t}, ${n})`}function wr(e){return L(e.appName)??L(e.appBundleId)??L(e.bundleId)??L(e.packageName)}function Tr(e){if(e.positionals.length!==0)return e.command===f.type?[K(`text`)]:e.command===f.fill?Er(e):e.command===f.find?Dr(e):e.command===f.clipboard?Or(e):e.command===f.push?kr(e,`app`,`payload`):e.command===f.triggerAppEvent?kr(e,`event`,`payload`):e.positionals.map(G)}function Er(e){let t=K(`text`),n=e.result??{},r=J(n);if(r)return[`@${r}`,t];if(L(n.selector))return[K(`target`),t];let i=U(n.x),a=U(n.y);return i!==void 0&&a!==void 0?[String(i),String(a),t]:[t]}function Dr(e){let t=+!!Mr(e.positionals[0]);if(e.positionals[t]===void 0)return;let n=t+1,r=[...t===1?[String(e.positionals[0])]:[],K(`query`)],i=e.positionals[n];return i?i===`fill`||i===`type`?[...r,i,K(`text`)]:[...r,...e.positionals.slice(n).map(Ar)]:r}function Or(e){let t=e.positionals[0]?.toLowerCase();return t===`read`?[`read`]:t===`write`?[`write`,K(`text`)]:e.positionals.map(G)}function kr(e,t,n){let[r,i,...a]=e.positionals;return[...r?[K(t)]:[],...i?[K(n)]:[],...a.map(G)]}function Ar(e){return e===`click`||e===`focus`||e===`exists`||e===`get`||e===`text`||e===`attrs`||e===`wait`?e:G(e)}function G(e){return jr(e)??K(`arg`)}function jr(e){if(!e)return;let t=e.trim();if(/^@[a-zA-Z0-9:_-]+$/.test(t))return t}function K(e){return`<${e}>`}function Mr(e){return e===`text`||e===`label`||e===`value`||e===`role`||e===`id`}function Nr(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)?e:void 0}const Pr={enums:[{source:`platform`,values:he},{source:`target`,values:_e}]},Fr={[f.open]:{booleans:[{source:`relaunch`},{source:`testIme`}],enums:[{source:`surface`,values:te}]},[f.click]:q(),[f.press]:q(),[f.longPress]:q(),[f.fill]:Lr(),[f.type]:Lr(),[f.scroll]:{numbers:[{source:`pixels`},{source:`durationMs`}]},[f.gesture]:Rr(),[f.swipe]:Rr(),[f.screenshot]:{booleans:[{source:`overlayRefs`},{source:`screenshotFullscreen`,output:`fullscreen`},{source:`screenshotNoStabilize`,output:`noStabilize`},{source:`screenshotNormalizeStatusBar`,output:`normalizeStatusBar`}],numbers:[{source:`screenshotPixelDensity`,output:`pixelDensity`},{source:`screenshotMaxSize`,output:`maxSize`}]},[f.snapshot]:{booleans:[{source:`snapshotInteractiveOnly`,output:`interactiveOnly`},{source:`snapshotDiff`,output:`diff`},{source:`snapshotRaw`,output:`raw`},{source:`snapshotForceFull`,output:`forceFull`}],numbers:[{source:`snapshotDepth`,output:`depth`}]},[f.back]:{enums:[{source:`backMode`,output:`mode`,values:d}]},[f.record]:{booleans:[{source:`hideTouches`}],numbers:[{source:`fps`},{source:`screenshotMaxSize`,output:`maxSize`}],enums:[{source:`recordingScope`,output:`scope`,values:ne}]},[f.apps]:{enums:[{source:`appsFilter`,output:`filter`,values:[`user-installed`,`all`]}]},[f.boot]:{booleans:[{source:`headless`}]},[f.close]:{booleans:[{source:`shutdown`}]}};function Ir(e){let t=e.flags??{},n={},r=Object.hasOwn(Fr,e.command)?Fr[e.command]:void 0;return zr(n,t,Pr),zr(n,t,r),Object.keys(n).length>0?n:void 0}function q(){return{booleans:[{source:`doubleTap`},{source:`settle`}],numbers:[{source:`count`},{source:`intervalMs`},{source:`holdMs`},{source:`jitterPx`},{source:`settleQuietMs`}],enums:[{source:`clickButton`,values:se}]}}function Lr(){return{booleans:[{source:`settle`}],numbers:[{source:`delayMs`},{source:`settleQuietMs`}]}}function Rr(){return{numbers:[{source:`pointerCount`},{source:`count`},{source:`pauseMs`}],enums:[{source:`pattern`,values:re}]}}function zr(e,t,n){n&&(Br(e,t,n.booleans??[]),Vr(e,t,n.numbers??[]),Hr(e,t,n.enums??[]))}function Br(e,t,n){for(let r of n)Ur(e,r.output??r.source,t[r.source])}function Vr(e,t,n){for(let r of n)Wr(e,r.output??r.source,t[r.source])}function Hr(e,t,n){for(let r of n)Gr(e,r.output??r.source,t[r.source],r.values)}function J(e){let t=L(e.ref);if(!t)return;let n=t.startsWith(`@`)?t.slice(1):t;return/^[a-zA-Z0-9:_-]+$/.test(n)?n:void 0}function Ur(e,t,n){typeof n==`boolean`&&(e[t]=n)}function Wr(e,t,n){let r=U(n);r!==void 0&&(e[t]=r)}function Gr(e,t,n,r){let i=z(n,r);i!==void 0&&(e[t]=i)}const Y=new Map,Kr=new Set;function qr(e){return h.join(e,`events.ndjson`)}function Jr(e){return e.command!==f.events}function Yr(t,n,r){let i=e({version:1,ts:r.ts??new Date().toISOString(),session:n,...r});Zr(t,`${JSON.stringify(i)}\n`)}async function Xr(e){await(e?Y.get(e):Promise.all(Y.values()))}function Zr(e,t){let n=(Y.get(e)??Promise.resolve()).catch(()=>void 0).then(async()=>{await Qr(e),await m.promises.appendFile(e,t,`utf8`)}).catch(t=>{i({level:`warn`,phase:`session_event_log_write_failed`,data:{path:e,error:t instanceof Error?t.message:String(t)}})}).finally(()=>{Y.get(e)===n&&Y.delete(e)});Y.set(e,n)}async function Qr(e){let t=h.dirname(e);if(!Kr.has(t))try{await m.promises.mkdir(t,{recursive:!0}),Kr.add(t)}catch(t){throw i({level:`warn`,phase:`session_event_log_dir_failed`,data:{path:e,error:t instanceof Error?t.message:String(t)}}),t}}function $r(e,t,n){Yr(e,t,{kind:`action.recorded`,requestId:r().requestId,command:n.command,summary:hr(n),details:gr(n)})}function ei(e){let{req:t}=e;return{kind:`request.started`,requestId:t.meta?.requestId??r().requestId,command:t.command,summary:`Started ${t.command}`}}function ti(e){let{req:t,response:n,durationMs:i}=e;if(n.ok){let e=wn(t,n.data);return{kind:`request.finished`,requestId:t.meta?.requestId??r().requestId,command:t.command,status:`ok`,summary:e.summary??`Finished ${t.command}`,details:{durationMs:i,...e.details}}}return{kind:`request.finished`,requestId:t.meta?.requestId??r().requestId,command:t.command,status:`error`,summary:`Failed ${t.command}: ${n.error.code}`,details:{durationMs:i,code:n.error.code,diagnosticId:n.error.diagnosticId}}}function ni(e,t={}){let n=si(t.cursor),r=ci(t.limit);if(!m.existsSync(e))return{path:e,cursor:String(n),limit:r,events:[]};let i=ri(e,n,r),a=i.lines.flatMap(e=>{let t=li(e);return t?[t]:[]});return{path:e,cursor:String(n),limit:r,events:a,...i.nextCursor===void 0?{}:{nextCursor:String(i.nextCursor)}}}function ri(e,t,n){let r=m.openSync(e,`r`);try{let e=new Ce(`utf8`),i=Buffer.allocUnsafe(65536),a=ii(t,n),o=``,s=0;do{s=m.readSync(r,i,0,i.length,null);let t=e.write(i.subarray(0,s));o=ai(`${o}${t}`,a)}while(s>0&&a.nextCursor===void 0);let c=`${o}${e.end()}`;return a.nextCursor===void 0&&c.length>0&&oi(c,a),{lines:a.lines,nextCursor:a.nextCursor}}finally{m.closeSync(r)}}function ii(e,t){return{cursor:e,limit:t,lineIndex:0,lines:[]}}function ai(e,t){let n=0;for(let r=e.indexOf(`
|
|
3
|
+
`);r!==-1;r=e.indexOf(`
|
|
4
|
+
`,n))if(oi(e.slice(n,r),t),n=r+1,t.nextCursor!==void 0)return``;return e.slice(n)}function oi(e,t){let n=e.endsWith(`\r`)?e.slice(0,-1):e;if(n.trim().length!==0){if(t.lineIndex>=t.cursor+t.limit){t.nextCursor=t.cursor+t.limit;return}t.lineIndex>=t.cursor&&t.lines.push(n),t.lineIndex+=1}}function si(e){if(e===void 0||e.trim()===``)return 0;let n=Number(e);if(Number.isInteger(n)&&n>=0)return n;throw new t(`INVALID_ARGS`,`events cursor must be a non-negative integer string.`)}function ci(e){if(e===void 0||typeof e==`string`&&e.trim()===``)return 100;let n=typeof e==`string`?Number(e):e;if(Number.isInteger(n)&&n>=1&&n<=500)return n;throw new t(`INVALID_ARGS`,`events limit must be between 1 and 500.`)}function li(e){try{let t=ui(JSON.parse(e));return t?di(t):void 0}catch{return}}function ui(e){if(u(e)&&e.version===1&&!(typeof e.ts!=`string`||typeof e.session!=`string`)&&fi(e.kind))return e}function di(e){let t=u(e.details)?e.details:void 0;return{version:1,ts:e.ts,session:e.session,kind:e.kind,...typeof e.requestId==`string`?{requestId:e.requestId}:{},...typeof e.command==`string`?{command:e.command}:{},...pi(e.status)?{status:e.status}:{},...typeof e.summary==`string`?{summary:e.summary}:{},...t?{details:t}:{}}}function fi(e){return e===`request.started`||e===`request.finished`||e===`action.recorded`}function pi(e){return e===`ok`||e===`error`}const mi=60*6e4;var hi=class{sessions=new Map;runtimeHints=new Map;sessionsDir;scriptWriter;constructor(e){this.sessionsDir=e,this.scriptWriter=new en(e)}get(e){return this.sessions.get(e)}set(e,t){this.sessions.set(e,t)}delete(e){return this.runtimeHints.delete(e),this.sessions.delete(e)}values(){return this.sessions.values()}toArray(){return Array.from(this.sessions.values())}getRuntimeHints(e){return this.runtimeHints.get(e)}setRuntimeHints(e,t){this.runtimeHints.set(e,t)}clearRuntimeHints(e){return this.runtimeHints.delete(e)}recordAction(e,t){let n=ft(e,t);if(n){let t=this.resolveStoredSessionName(e);$r(this.resolveEventLogPath(t),t,n)}}recordEvent(e,t){Yr(this.resolveEventLogPath(e),e,t)}readEvents(e,t={}){return ni(this.resolveEventLogPath(e),t)}async flushEvents(e){await Xr(e?this.resolveEventLogPath(e):void 0)}writeSessionLog(e,t){let n=this.scriptWriter.write(e,t);return n.written&&i({level:`info`,phase:`session_script_written`,data:{session:e.name,path:n.path}}),n}finalizeRepairTeardown(e){this.recordRepairFinalizeCloseIfCommitting(e);let t=this.writeSessionLog(e,{force:e.saveScriptForce});e.saveScriptBoundary!==void 0&&e.saveScriptCommitted!==!0&&(!t.written&&t.error?this.writeRepairTombstone(e,mi,{code:String(t.error.code),message:t.error.message}):this.writeRepairTombstone(e))}recordRepairFinalizeCloseIfCommitting(e){e.saveScriptBoundary!==void 0&&e.saveScriptComplete===!0&&e.saveScriptCommitted!==!0&&this.recordAction(e,{command:`close`,positionals:[],flags:{},result:{session:e.name,...ie(`Closed: ${e.name}`)}})}writeRepairTombstone(e,t=mi,n){try{let r=this.resolveSessionDir(e.name);m.mkdirSync(r,{recursive:!0});let i={owner:e.name,reapedAt:Date.now(),expiresAt:Date.now()+t,...e.repairSourcePath?{sourcePath:e.repairSourcePath}:{},...n?{commitFailure:n}:{}};m.writeFileSync(this.repairTombstonePath(e.name),`${JSON.stringify(i)}\n`)}catch(t){i({level:`warn`,phase:`repair_tombstone_write_failed`,data:{session:e.name,error:t instanceof Error?t.message:String(t)}})}}readRepairTombstone(e){return gi(this.repairTombstonePath(e))}clearRepairTombstone(e){try{m.rmSync(this.repairTombstonePath(e),{force:!0})}catch{}}repairTombstonePath(e){return h.join(this.resolveSessionDir(e),`repair-tombstone.json`)}defaultTracePath(e){let t=g(e.name),n=new Date().toISOString().replace(/[:.]/g,`-`);return h.join(this.sessionsDir,`${t}-${n}.trace.log`)}resolveSessionDir(e){return h.join(this.sessionsDir,g(e))}resolveDaemonStateDir(){return h.dirname(this.sessionsDir)}ensureSessionDir(e){let t=this.resolveSessionDir(e);return m.mkdirSync(t,{recursive:!0}),t}resolveAppLogPath(e){return h.join(this.resolveSessionDir(e),`app.log`)}resolveAppLogPidPath(e){return h.join(this.resolveSessionDir(e),`app-log.pid`)}resolveEventLogPath(e){return qr(this.resolveSessionDir(e))}static expandHome(e,t){return _(e,t)}resolveStoredSessionName(e){for(let[t,n]of this.sessions)if(n===e)return t;return e.name}};function gi(e){let t;try{t=m.readFileSync(e,`utf8`)}catch{return}let n;try{n=JSON.parse(t)}catch{return}if(!(typeof n?.expiresAt!=`number`||n.expiresAt<=Date.now()))return n}function _i(e){let t;try{t=m.readdirSync(e,{withFileTypes:!0})}catch{return}for(let n of t){if(!n.isDirectory())continue;let t=gi(h.join(e,n.name,`repair-tombstone.json`));if(t?.commitFailure)return{sessionName:n.name,tombstone:{...t,commitFailure:t.commitFailure}}}}function vi(e){return h.join(e,`runner.log`)}function yi(e,t){let n=g(t&&t.length>0?t:`unknown`);return h.join(e,`requests`,`${n}.ndjson`)}function bi(e,t={}){let n=xi(e,t);return{baseDir:n,infoPath:h.join(n,`daemon.json`),lockPath:h.join(n,`daemon.lock`),logPath:h.join(n,`daemon.log`),sessionsDir:h.join(n,`sessions`)}}function xi(e,t){let n=(e??``).trim();return n?fe(n,{env:t.env}):Si(t)}function Si(e={}){let t=h.join(pe(`~`,{env:e.env}),`.agent-device`),n=e.projectRoot??de();return Ci(n)?h.join(t,`dev`,wi(n)):t}function Ci(e){return m.existsSync(h.join(e,`package.json`))&&m.existsSync(h.join(e,`src`,`daemon.ts`))}function wi(e){let t=Ti(e),n=h.basename(t).replaceAll(/[^a-zA-Z0-9._-]+/g,`-`),r=Se.createHash(`sha1`).update(t).digest(`hex`).slice(0,12);return`${n||`agent-device`}-${r}`}function Ti(e){try{return m.realpathSync.native(e)}catch{return h.resolve(e)}}function Ei(e){let t=(e??``).trim().toLowerCase();return t===`http`?`http`:t===`dual`?`dual`:`socket`}function Di(e){let t=(e??``).trim().toLowerCase();return t===`auto`?`auto`:t===`socket`?`socket`:t===`http`?`http`:`auto`}function Oi(e){return(e??``).trim().toLowerCase()===`tenant`?`tenant`:`none`}function ki(e){if(!e)return;let t=e.trim();if(t&&/^[a-zA-Z0-9._-]{1,128}$/.test(t))return t}const Ai=/(?:^|[^\w$.])(?:import|export)\s+(?:type\s+)?(?:[^'"`]*?\s+from\s+)?['"]([^'"]+)['"]/gm,ji=/import\(\s*['"]([^'"]+)['"]\s*\)/gm,Mi=[`.ts`,`.tsx`,`.js`,`.jsx`,`.mjs`,`.cjs`];function Ni(){let e=process.argv[1];return e?Pi(e):`unknown`}function Pi(e,t=de()){try{let n=h.resolve(t),r=[h.resolve(e)],i=new Set,a=[];for(;r.length>0;){let e=r.pop();if(!e||i.has(e))continue;i.add(e);let t=m.statSync(e);if(!t.isFile())continue;let o=h.relative(n,e)||e;a.push(`${o}:${t.size}:${Math.trunc(t.mtimeMs)}`);let s=m.readFileSync(e,`utf8`);for(let t of Fi(s)){let n=Li(e,t);n&&r.push(n)}}let o=a.sort().join(`|`),s=Se.createHash(`sha1`).update(o).digest(`hex`);return`graph:${a.length}:${s}`}catch{return`unknown`}}function Fi(e){let t=new Set;return Ii(e,Ai,t),Ii(e,ji,t),[...t]}function Ii(e,t,n){t.lastIndex=0;let r=null;for(;(r=t.exec(e))!==null;){let e=r[1]?.trim();e?.startsWith(`.`)&&n.add(e)}}function Li(e,t){let n=h.resolve(h.dirname(e),t),r=X(n);if(r)return r;for(let e of Mi){let t=X(`${n}${e}`);if(t)return t}for(let e of Mi){let t=X(h.join(n,`index${e}`));if(t)return t}return null}function X(e){try{return m.statSync(e).isFile()?e:null}catch{return null}}const Ri=/^[A-Za-z0-9_@%+=:,./-]+$/;function zi(e){return`'${e.replaceAll(`'`,`'\\''`)}'`}function Bi(e){return Ri.test(e)?e:zi(e)}const Vi=[/(^|[/\s"'=])dist\/src\/daemon\.js($|[\s"'])/,/(^|[/\s"'=])dist\/src\/internal\/daemon\.js($|[\s"'])/,/(^|[/\s"'=])src\/daemon\.ts($|[\s"'])/];function Hi(e){let t=e.toLowerCase().replaceAll(`\\`,`/`);return t.includes(`agent-device`)?Vi.some(e=>e.test(t)):!1}function Ui(e,t){if(!be(e))return!1;if(t){let n=xe(e);if(!n||n!==t)return!1}let n=ye(e);return n?Hi(n):!1}function Z(e,t){try{return process.kill(e,t),!0}catch(e){let t=e.code;if(t===`ESRCH`||t===`EPERM`)return!1;throw e}}async function Wi(e,t){Ui(e,t.expectedStartTime)&&Z(e,`SIGTERM`)&&(await p(e,t.termTimeoutMs)||Z(e,`SIGKILL`)&&await p(e,t.killTimeoutMs))}function Gi(e,t){let n=[],r=e+t.toString(),i=r.indexOf(`
|
|
2
5
|
`);for(;i!==-1;){let e=r.slice(0,i).trim();r=r.slice(i+1),e&&n.push(e),i=r.indexOf(`
|
|
3
|
-
`)}return{lines:n,buffer:r}}function
|
|
6
|
+
`)}return{lines:n,buffer:r}}function Ki(e){return e.meta?.requestProgress===`replay-test`||e.meta?.requestProgress===`command`}function qi(e){return!!e&&typeof e==`object`&&e.type===`progress`&&!!e.event}function Ji(e){return!!e&&typeof e==`object`&&e.type===`response`&&!!e.response}function Yi(e){return`${JSON.stringify({type:`progress`,event:e})}\n`}function Xi(e){return`${JSON.stringify({type:`response`,response:e})}\n`}function Zi(e){return`${JSON.stringify({type:`response`,response:e})}\n`}function Qi(e,t={}){return{ok:!0,service:e,version:ue(),rpcProtocolVersion:2,...t.upstream===void 0?{}:{upstream:t.upstream}}}function $i(e){return{...typeof e.path==`string`?{path:e.path}:{},...typeof e.width==`number`?{width:e.width}:{},...typeof e.height==`number`?{height:e.height}:{},...typeof e.logicalWidth==`number`?{logicalWidth:e.logicalWidth}:{},...typeof e.logicalHeight==`number`?{logicalHeight:e.logicalHeight}:{},...typeof e.pixelDensity==`number`?{pixelDensity:e.pixelDensity}:{},...e.overlayRefs?{overlayRefs:e.overlayRefs}:{}}}function ea(e){if(u(e))return $i({path:typeof e.path==`string`?e.path:void 0,width:typeof e.width==`number`?e.width:void 0,height:typeof e.height==`number`?e.height:void 0,logicalWidth:typeof e.logicalWidth==`number`?e.logicalWidth:void 0,logicalHeight:typeof e.logicalHeight==`number`?e.logicalHeight:void 0,pixelDensity:typeof e.pixelDensity==`number`?e.pixelDensity:void 0,overlayRefs:Array.isArray(e.overlayRefs)?e.overlayRefs.filter(ia).flatMap(e=>{let t=ta(e);return t?[t]:[]}):void 0})}function ta(e){if(typeof e.ref!=`string`||e.ref.length===0)return;let t=na(e);if(t)return{ref:e.ref,...ra(e),...t}}function na(e){let t=c(e.rect);if(!t)return;let n=c(e.overlayRect);if(!n)return;let r=l(e.center);return r?{rect:t,overlayRect:n,center:r}:void 0}function ra(e){return typeof e.label==`string`&&e.label.length>0?{label:e.label}:{}}function ia(e){return u(e)}const Q=1500;function aa(e,t){e&&(e.snapshotDiagnostics??={samples:[]}).samples.push({...t,durationMs:Math.max(0,Math.round(t.durationMs))})}function oa(e){let t=e?.snapshotDiagnostics?.samples;if(!(!t||t.length===0))return sa(t)}function sa(e){if(e.length===0)return;let t=ua(e);return{stats:t,...t.p95Ms>=Q?{warning:$(t)}:{}}}function ca(e){let t=e.flatMap(e=>va(e?.stats));if(t.length===0)return;let n=ua(t);return{stats:n,...n.p95Ms>=Q?{warning:$(n)}:{}}}function la(e){if(!u(e))return;let t=ma(e.stats);if(!t)return;let n=typeof e.warning==`string`?e.warning:void 0;return{stats:t,...n?{warning:n}:{}}}function ua(e){let t=e.map(e=>e.durationMs).sort((e,t)=>e-t);return{count:t.length,p50Ms:da(t,50),p95Ms:da(t,95),maxMs:t[t.length-1]??0,slowThresholdMs:Q,...fa(e),...pa(e)}}function da(e,t){if(e.length===0)return 0;let n=Math.max(0,Math.ceil(t/100*e.length)-1);return e[Math.min(n,e.length-1)]??0}function fa(e){let t=e.map(e=>e.platform).filter(e=>!!e);return new Set(t).size===1?{platform:t[0]}:{}}function pa(e){let t={};for(let n of e)n.backend&&(t[n.backend]=(t[n.backend]??0)+1);return Object.keys(t).length>0?{backends:t}:{}}function $(e){return`Warning: ${e.platform?`${e.platform} `:``}snapshots are slow in this run: p95 ${e.p95Ms}ms over ${e.count} captures. Possible causes: device load, app or dev server stuck, helper fallback, or stale daemon.`}function ma(e){if(!u(e))return;let t=ha(e);if(t)return{...t,..._a(e)}}function ha(e){let t={count:e.count,p50Ms:e.p50Ms,p95Ms:e.p95Ms,maxMs:e.maxMs,slowThresholdMs:e.slowThresholdMs};if(!Object.values(t).some(e=>typeof e!=`number`))return t}function ga(e){let t=Object.entries(e).filter(e=>typeof e[1]==`number`);return t.length>0?Object.fromEntries(t):void 0}function _a(e){let t=typeof e.platform==`string`?e.platform:void 0,n=u(e.backends)?ga(e.backends):void 0;return{...t?{platform:t}:{},...n?{backends:n}:{}}}function va(e){if(!e||e.count<=0)return[];let t=e.platform;return e.count===1?[{durationMs:e.maxMs,platform:t}]:e.count===2?[{durationMs:e.p50Ms,platform:t},{durationMs:e.maxMs,platform:t}]:[...Array.from({length:e.count-3},()=>({durationMs:e.p50Ms,platform:t})),{durationMs:e.p50Ms,platform:t},{durationMs:e.p95Ms,platform:t},{durationMs:e.maxMs,platform:t}]}export{Re as $,yi as A,O as B,ki as C,Oi as D,Di as E,Tr as F,w as G,D as H,qn as I,rt as J,dt as K,N as L,ti as M,ei as N,hi as O,Jr as P,y as Q,Ut as R,Ni as S,Ei as T,Bt as U,E as V,zt as W,Ye as X,Xe as Y,Je as Z,Wi as _,Oe as _t,sa as a,We as at,Bi as b,De as bt,Qi as c,g as ct,Yi as d,Ae as dt,Ke as et,Xi as f,Me as ft,Ui as g,Te as gt,Gi as h,we as ht,oa as i,He as it,vi as j,_i as k,qi as l,Fe as lt,Ki as m,je as mt,la as n,Be as nt,$i as o,v as ot,Zi as p,Ne as pt,gt as q,aa as r,Ve as rt,ea as s,_ as st,ca as t,ze as tt,Ji as u,Pe as ut,Z as v,Ee as vt,bi as w,Pi as x,zi as y,ke as yt,jt as z};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=new Set([`healthy`,`recovered`,`sparse`]),t=new Set([`tree`,`queries`,`private-ax`]),n=new Set([`ax-rejected`,`sparse-tree`,`budget`,`no-nodes`,`capture-failed`]);function r(r){if(!r||typeof r!=`object`)return;let i=r;if(!(typeof i.state!=`string`||!e.has(i.state))&&!(typeof i.backend!=`string`||!t.has(i.backend)))return{state:i.state,backend:i.backend,reason:typeof i.reason==`string`?i.reason:void 0,reasonCode:typeof i.reasonCode==`string`&&n.has(i.reasonCode)?i.reasonCode:void 0,effectiveDepth:typeof i.effectiveDepth==`number`?i.effectiveDepth:void 0,collapsedLeafIndexes:Array.isArray(i.collapsedLeafIndexes)?i.collapsedLeafIndexes.filter(e=>typeof e==`number`):void 0}}function i(e){return e?.state===`sparse`}function a(e,t){return[...o(e),...s(e),...c(e,t)]}function o(e){return e.state===`recovered`?[`Detected an overly complex or slow accessibility tree. Fell back to the ${e.backend} snapshot backend. It is OK to continue; use --json to inspect snapshotQuality.reason if you need recovery details.`]:e.state===`sparse`?[`No snapshot backend could read this screen`+(e.reason?` (${e.reason})`:``)+`. Use screenshot as visual truth and coordinate taps; retry snapshot after navigating.`]:[]}function s(e){return e.effectiveDepth===void 0?[]:[`Some deeper accessibility nodes were omitted; this tree is capped at depth ${e.effectiveDepth}. Re-run with --depth ${e.effectiveDepth} --scope <container> only if you need deeper content.`]}function c(e,t){let n=[];for(let r of e.collapsedLeafIndexes??[]){let e=t.find(e=>e.index===r);if(!e)continue;let i=e.identifier?` (${e.identifier})`:``;n.push(`@${e.ref} [${e.type??`element`}]${i} merges many labels into a single accessibility element. The app likely marks a container as accessible, which hides every descendant from assistive tech and automation — the children cannot be addressed individually. Fix the app's accessibility (mark the rows, not the container); until then use screenshot as visual truth and coordinate taps.`)}return n}export{
|
|
1
|
+
const e=new Set([`healthy`,`recovered`,`sparse`]),t=new Set([`tree`,`queries`,`private-ax`]),n=new Set([`ax-rejected`,`sparse-tree`,`budget`,`no-nodes`,`capture-failed`]);function r(r){if(!r||typeof r!=`object`)return;let i=r;if(!(typeof i.state!=`string`||!e.has(i.state))&&!(typeof i.backend!=`string`||!t.has(i.backend)))return{state:i.state,backend:i.backend,reason:typeof i.reason==`string`?i.reason:void 0,reasonCode:typeof i.reasonCode==`string`&&n.has(i.reasonCode)?i.reasonCode:void 0,effectiveDepth:typeof i.effectiveDepth==`number`?i.effectiveDepth:void 0,collapsedLeafIndexes:Array.isArray(i.collapsedLeafIndexes)?i.collapsedLeafIndexes.filter(e=>typeof e==`number`):void 0}}function i(e){return e?.state===`sparse`}function a(e,t){return[...o(e),...s(e),...c(e,t)]}function o(e){return e.state===`recovered`?[`Detected an overly complex or slow accessibility tree. Fell back to the ${e.backend} snapshot backend. It is OK to continue; use --json to inspect snapshotQuality.reason if you need recovery details.`]:e.state===`sparse`?[`No snapshot backend could read this screen`+(e.reason?` (${e.reason})`:``)+`. Use screenshot as visual truth and coordinate taps; retry snapshot after navigating.`]:[]}function s(e){return e.effectiveDepth===void 0?[]:[`Some deeper accessibility nodes were omitted; this tree is capped at depth ${e.effectiveDepth}. Re-run with --depth ${e.effectiveDepth} --scope <container> only if you need deeper content.`]}function c(e,t){let n=[];for(let r of e.collapsedLeafIndexes??[]){let e=t.find(e=>e.index===r);if(!e)continue;let i=e.identifier?` (${e.identifier})`:``;n.push(`@${e.ref} [${e.type??`element`}]${i} merges many labels into a single accessibility element. The app likely marks a container as accessible, which hides every descendant from assistive tech and automation — the children cannot be addressed individually. Fix the app's accessibility (mark the rows, not the container); until then use screenshot as visual truth and coordinate taps.`)}return n}const l=new Set([`empty-helper-output`,`system-window-only`,`content-poor-app-window`]);function u(e){if(!e||typeof e!=`object`)return!1;let t=e.details?.androidSnapshotHelperFailureReason;return typeof t==`string`&&l.has(t)}export{a as i,u as n,r,i as t};
|
package/dist/src/snapshot.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./rolldown-runtime.js";import{_ as t}from"./sdk-contracts.js";import{j as n}from"./sdk-android-adb.js";import{n as r,t as i}from"./tool-provider2.js";import a from"node:fs";import o from"node:path";import{fileURLToPath as s}from"node:url";const c={"push button":`Button`,"toggle button":`Button`,"push button menu":`Button`,label:`StaticText`,static:`StaticText`,caption:`StaticText`,text:`TextField`,entry:`TextField`,"password text":`TextField`,"spin button":`TextField`,terminal:`TextArea`,"document text":`TextArea`,paragraph:`TextArea`,frame:`Window`,window:`Window`,dialog:`Dialog`,alert:`Alert`,"file chooser":`Dialog`,"color chooser":`Dialog`,"font chooser":`Dialog`,panel:`Group`,filler:`Group`,section:`Group`,form:`Group`,grouping:`Group`,"layered pane":`Group`,"glass pane":`Group`,"root pane":`Group`,"option pane":`Group`,"internal frame":`Group`,"desktop frame":`Group`,"block quote":`Group`,article:`Group`,comment:`Group`,landmark:`Group`,log:`Group`,marquee:`Group`,math:`Group`,notification:`Group`,"content deletion":`Group`,"content insertion":`Group`,mark:`Group`,suggestion:`Group`,"scroll pane":`ScrollArea`,"scroll bar":`ScrollBar`,"menu bar":`MenuBar`,menu:`Menu`,"popup menu":`Menu`,"menu item":`MenuItem`,"check menu item":`MenuItem`,"radio menu item":`MenuItem`,"tearoff menu item":`MenuItem`,"check box":`CheckBox`,"radio button":`RadioButton`,switch:`Switch`,"combo box":`ComboBox`,"page tab":`Tab`,"page tab list":`TabList`,table:`Table`,"tree table":`Table`,"table cell":`Cell`,"table row":`Row`,"table column header":`Cell`,"table row header":`Cell`,"column header":`Cell`,"row header":`Cell`,list:`List`,"list item":`ListItem`,"list box":`List`,tree:`Tree`,"tree item":`TreeItem`,"description list":`List`,"description term":`ListItem`,"description value":`ListItem`,"tool bar":`Toolbar`,"status bar":`StatusBar`,"info bar":`StatusBar`,slider:`Slider`,"progress bar":`ProgressBar`,"level bar":`ProgressBar`,image:`Image`,icon:`Image`,animation:`Image`,canvas:`Image`,"drawing area":`Image`,video:`Video`,audio:`Audio`,link:`Link`,hyperlink:`Link`,separator:`Separator`,application:`Application`,"tool tip":`Tooltip`,timer:`Timer`,heading:`Heading`,footnote:`Footnote`,"title bar":`TitleBar`,"date editor":`DateEditor`,rating:`Slider`};function l(e){let t=e.toLowerCase().trim();return c[t]||t.split(/[\s_-]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)}const u=`atspi-dump.py`;let d=null;function f(){if(d)return d;let e=o.dirname(s(import.meta.url));for(let t=0;t<
|
|
1
|
+
import{t as e}from"./rolldown-runtime.js";import{_ as t}from"./sdk-contracts.js";import{j as n}from"./sdk-android-adb.js";import{n as r,t as i}from"./tool-provider2.js";import a from"node:fs";import o from"node:path";import{fileURLToPath as s}from"node:url";const c={"push button":`Button`,"toggle button":`Button`,"push button menu":`Button`,label:`StaticText`,static:`StaticText`,caption:`StaticText`,text:`TextField`,entry:`TextField`,"password text":`TextField`,"spin button":`TextField`,terminal:`TextArea`,"document text":`TextArea`,paragraph:`TextArea`,frame:`Window`,window:`Window`,dialog:`Dialog`,alert:`Alert`,"file chooser":`Dialog`,"color chooser":`Dialog`,"font chooser":`Dialog`,panel:`Group`,filler:`Group`,section:`Group`,form:`Group`,grouping:`Group`,"layered pane":`Group`,"glass pane":`Group`,"root pane":`Group`,"option pane":`Group`,"internal frame":`Group`,"desktop frame":`Group`,"block quote":`Group`,article:`Group`,comment:`Group`,landmark:`Group`,log:`Group`,marquee:`Group`,math:`Group`,notification:`Group`,"content deletion":`Group`,"content insertion":`Group`,mark:`Group`,suggestion:`Group`,"scroll pane":`ScrollArea`,"scroll bar":`ScrollBar`,"menu bar":`MenuBar`,menu:`Menu`,"popup menu":`Menu`,"menu item":`MenuItem`,"check menu item":`MenuItem`,"radio menu item":`MenuItem`,"tearoff menu item":`MenuItem`,"check box":`CheckBox`,"radio button":`RadioButton`,switch:`Switch`,"combo box":`ComboBox`,"page tab":`Tab`,"page tab list":`TabList`,table:`Table`,"tree table":`Table`,"table cell":`Cell`,"table row":`Row`,"table column header":`Cell`,"table row header":`Cell`,"column header":`Cell`,"row header":`Cell`,list:`List`,"list item":`ListItem`,"list box":`List`,tree:`Tree`,"tree item":`TreeItem`,"description list":`List`,"description term":`ListItem`,"description value":`ListItem`,"tool bar":`Toolbar`,"status bar":`StatusBar`,"info bar":`StatusBar`,slider:`Slider`,"progress bar":`ProgressBar`,"level bar":`ProgressBar`,image:`Image`,icon:`Image`,animation:`Image`,canvas:`Image`,"drawing area":`Image`,video:`Video`,audio:`Audio`,link:`Link`,hyperlink:`Link`,separator:`Separator`,application:`Application`,"tool tip":`Tooltip`,timer:`Timer`,heading:`Heading`,footnote:`Footnote`,"title bar":`TitleBar`,"date editor":`DateEditor`,rating:`Slider`};function l(e){let t=e.toLowerCase().trim();return c[t]||t.split(/[\s_-]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)}const u=`atspi-dump.py`;let d=null;function f(){if(d)return d;let e=o.dirname(s(import.meta.url));for(let t=0;t<6;t++){let t=o.join(e,`linux`,u);if(a.existsSync(t))return d=t,t;e=o.dirname(e)}throw new t(`TOOL_MISSING`,`Cannot find ${u}. Ensure the agent-device package is installed correctly.`)}async function p(e,n={}){let a=i().accessibility;if(a)return await a.captureTree(e,n);if(process.platform!==`linux`)throw new t(`UNSUPPORTED_PLATFORM`,`AT-SPI2 bridge is only available on Linux`);if(!await i().whichCommand(`python3`))throw new t(`TOOL_MISSING`,`python3 is required for AT-SPI2 accessibility snapshots on Linux.`);let o=n.maxNodes??1500,s=n.maxDepth??12,c=n.maxApps??24,u=await r(`python3`,[f(),`--surface`,e,`--max-nodes`,String(o),`--max-depth`,String(s),`--max-apps`,String(c)],{allowFailure:!0,timeoutMs:3e4});if(u.exitCode!==0){let e=u.stderr.trim();throw e.includes(`No module named`)||e.includes(`gi.require_version`)?new t(`TOOL_MISSING`,`AT-SPI2 Python bindings not found. Install python3-gi and gir1.2-atspi-2.0.`,{cause:e}):new t(`COMMAND_FAILED`,`AT-SPI2 snapshot failed (exit ${u.exitCode}): ${e||u.stdout}`)}let d;try{d=JSON.parse(u.stdout)}catch{throw new t(`COMMAND_FAILED`,`AT-SPI2 snapshot returned invalid JSON: ${u.stdout.slice(0,200)}`)}if(d.error)throw new t(`COMMAND_FAILED`,`AT-SPI2: ${d.error}`);return{nodes:(d.nodes??[]).map(e=>({index:e.index,type:l(e.role),role:e.role,label:e.label??void 0,value:e.value??void 0,rect:e.rect??void 0,enabled:e.enabled??void 0,selected:e.selected??void 0,hittable:e.hittable??void 0,depth:e.depth,parentIndex:e.parentIndex??void 0,pid:e.pid??void 0,appName:e.appName??void 0,windowTitle:e.windowTitle??void 0})),truncated:d.truncated,surface:e}}var m=e({readLinuxTextAtPoint:()=>_,snapshotLinux:()=>g});function h(e){return e===`desktop`?`desktop`:e===`frontmost-app`||e===`app`?`frontmost-app`:(e===`menubar`&&n({level:`warn`,phase:`linux_snapshot`,data:{message:`menubar surface is not supported on Linux, falling back to desktop`}}),`desktop`)}async function g(e){let t=await p(h(e));return{nodes:t.nodes,truncated:t.truncated}}async function _(e,t,n){let{nodes:r}=await g(n),i=r.filter(n=>{let r=n.rect;return r?e>=r.x&&t>=r.y&&e<=r.x+r.width&&t<=r.y+r.height:!1}).sort((e,t)=>{let n=e.depth??0,r=t.depth??0;return n===r?v(e.rect)-v(t.rect):r-n});for(let e of i){let t=y(e);if(t.trim())return t}return``}function v(e){return(e?.width??0)*(e?.height??0)}function y(e){for(let t of[e.value,e.label,e.identifier])if(typeof t==`string`&&t.length>0)return t;return``}export{m as n,g as t};
|
package/dist/src/snapshot2.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
import{S as e,_ as t,u as n}from"./sdk-contracts.js";import{F as r,j as i}from"./sdk-android-adb.js";import{E as a}from"./sdk-batch.js";import{Dt as o,Et as s,Sn as c,kt as l,pn as u,wt as d}from"./tv-remote.js";import{i as f}from"./snapshot-diagnostics.js";import{t as p}from"./timeouts.js";import{c as m,m as h,s as g}from"./sdk-device.js";import{t as _}from"./runtime.js";import{i as v}from"./runner-client.js";import{i as ee}from"./helper.js";import{Bt as te,Ct as ne,Dt as y,Ft as re,Nt as ie,Wt as b,Xt as x,in as S,on as C,zt as w}from"./internal/daemon.js";import{l as ae,n as oe}from"./input-actions.js";import{t as se}from"./apple-runner-options.js";import{C as T,S as E,b as ce,i as le,o as ue,x as D}from"./selector-runtime.js";import{promises as O}from"node:fs";import de from"node:os";import k from"node:path";const fe=new Set([`com.android.permissioncontroller`,`com.google.android.permissioncontroller`,`com.google.android.packageinstaller`,`com.android.packageinstaller`]),A=new Set([`android`,`com.android.systemui`]),j=/^android:id\/(?:alertTitle|message|button[123]|parentPanel|buttonPanel|contentPanel)$/i,M=/^android:id\/button[123]$/i,N=/(?:^|:)id\/permission_/i,P=/\b(?:is(?:n't| not) responding|keeps stopping|has stopped|close app|app info)\b/i,F=/^(?:ok|allow|allow all|while using the app|only this time|yes|continue|save|confirm|turn on|open settings)$/i,I=/^(?:cancel|deny|don.t allow|don’t allow|not now|no|dismiss|close|close app|later|skip)$/i;function L(e){let t=z(e),n=t.nodes;if(n.length===0)return null;let r=he(n),i=n.filter(e=>K(e)&&!G(e)),a=ve(i),o=ye(i,a),s=Se(n);return{alert:{...a?{title:a}:{},...o?{message:o}:{},buttons:r.map(e=>e.label),platform:`android`,source:t.source,...s?{packageName:s}:{}},buttons:r}}function R(e,t){let n=t===`accept`?`accept`:`dismiss`;return e.find(e=>e.role===n)||(t===`dismiss`?e.find(e=>e.role===`neutral`)??null:e.length===1?e[0]??null:null)}function z(e){let t=e.filter(e=>be(e));if(t.length)return{nodes:t,source:`permission`};let n=me(e);return n.length?{nodes:n,source:`system-dialog`}:{nodes:B(e),source:`native-dialog`}}function B(e){let t=e.filter(e=>V(e.type??``)),n=e.filter(e=>j.test(e.identifier??``)),r=t.length?[...t,...n]:pe(n);if(r.length===0)return[];let i=H(e,r);return i===void 0?r:W(e,i)}function V(e){return/(?:^|[.$])[^.]*Dialog$/i.test(e)}function pe(e){let t=e.some(e=>M.test(e.identifier??``)),n=e.some(e=>!M.test(e.identifier??``));return t&&n?e:[]}function me(e){let t=e.filter(e=>xe(e));if(t.length===0)return[];let n=H(e,t);return n===void 0?t:W(e,n).filter(e=>e.bundleId&&A.has(e.bundleId))}function he(e){let t=new Set,r=[];for(let i of e){let e=K(i);if(!e||!i.rect||!G(i))continue;let a=e.trim().toLowerCase();if(!a||t.has(a))continue;t.add(a);let o=n(i.rect);r.push({label:e,x:o.x,y:o.y,role:ge(i,e)})}return r}function ge(e,t){return _e(e.identifier??``)||(F.test(t.trim())?`accept`:I.test(t.trim())?`dismiss`:`neutral`)}function _e(e){return/(?:^|:)id\/button1$/i.test(e)?`accept`:/(?:^|:)id\/button2$/i.test(e)?`dismiss`:/(?:^|:)id\/button3$/i.test(e)?`neutral`:/(?:^|:)id\/permission_allow/i.test(e)?`accept`:/(?:^|:)id\/permission_deny/i.test(e)?`dismiss`:null}function ve(e){return K(e.find(e=>/(?:^|:)id\/(?:alertTitle|permission_message)$/i.test(e.identifier??``)))||K(e[0])}function ye(e,t){let n=e.map(e=>K(e)).filter(e=>e&&e!==t);return n.length?[...new Set(n)].join(`
|
|
2
|
-
`):void 0}function H(e,t){let n=t[0];if(!n)return;let r=U(e,n.index);for(let n of t.slice(1)){let t=new Set(U(e,n.index));for(let e=r.length-1;e>=0;--e)t.has(r[e])||r.splice(e,1)}return r[r.length-1]}function U(e,t){let n=new Map(e.map(e=>[e.index,e])),r=[],i=n.get(t);for(;i;)r.push(i.index),i=i.parentIndex===void 0?void 0:n.get(i.parentIndex);return r.reverse()}function W(e,t){let n=new Map;for(let t of e){if(t.parentIndex===void 0)continue;let e=n.get(t.parentIndex)??[];e.push(t),n.set(t.parentIndex,e)}let r=new Set([t]),i=[t];for(let e of i)for(let t of n.get(e)??[])r.has(t.index)||(r.add(t.index),i.push(t.index));return e.filter(e=>r.has(e.index))}function be(e){let t=e.bundleId??``;return fe.has(t)||N.test(e.identifier??``)}function xe(e){let t=e.bundleId??``;return A.has(t)&&P.test(K(e))}function G(e){let t=e.type??``,n=e.identifier??``;return!!(e.hittable||/\bbutton\b/i.test(t)||M.test(n)||/(?:^|:)id\/permission_(?:allow|deny)/i.test(n))}function K(e){return e?[e.label,e.value].filter(e=>typeof e==`string`&&e.trim().length>0)[0]?.trim()??``:``}function Se(e){return e.find(e=>e.bundleId)?.bundleId}async function Ce(e,t,n={}){return t===`wait`?await we(e,n.timeoutMs??1e4):t===`get`?Ee((await J(e))?.alert??null):await Te(e,t)}async function we(e,n){let r=Date.now(),i=await q(e,n);if(!i)throw new t(`COMMAND_FAILED`,`alert wait timed out`);return{kind:`alertWait`,platform:`android`,action:`wait`,alert:i.alert,waitedMs:Date.now()-r,...c(`Alert visible`)}}async function Te(e,n){let r=await q(e,l);if(!r)throw new t(`COMMAND_FAILED`,`alert not found`,{hint:`If a sheet is visible in snapshot but alert reports no alert, it is likely app-owned UI. Use snapshot -i and press the visible label/ref.`});let i=R(r.buttons,n);if(i)return await ae(e,i.x,i.y),Y(n,r.alert,i.label);if(n===`dismiss`)return await oe(e),Y(n,r.alert,`Back`);throw new t(`COMMAND_FAILED`,`alert accept found an alert but no accept button`,{alert:r.alert,hint:`Inspect alert get --json for visible buttons, then use press by visible label/ref if needed.`})}async function q(e,t){let n=Date.now();for(;Date.now()-n<t;){let t=await J(e);if(t)return t;await p(300)}return null}async function J(e){return L((await r(`snapshot_capture`,async()=>await y(e,{helperWaitForIdleTimeoutMs:0,includeHiddenContentHints:!1}),{backend:`android`,purpose:`alert`})).nodes)}function Ee(e){return{kind:`alertStatus`,platform:`android`,action:`get`,alert:e,...c(e?`Alert visible`:`No alert visible`)}}function Y(e,t,n){return{kind:`alertHandled`,platform:`android`,action:e,handled:!0,alert:t,button:n,...c(`Alert ${e}ed`)}}async function De(e){let{req:t,logPath:n,session:r,device:i}=e,o=Oe(t.positionals?.[0]),s=r?r.surface===`frontmost-app`?{surface:`frontmost-app`}:{bundleId:r.appBundleId,surface:r.surface}:{},c=C(`alert`,i);if(c)return c;if(i.platform===`android`)return Z(e,await Ce(i,o,{timeoutMs:a(t.positionals?.[1])??1e4}));if(m(i))return await X(e,o,async e=>await ee(e,s));let l=se({req:t,logPath:n,traceLogPath:r?.trace?.outPath});return await X(e,o,async e=>await v(i,{command:`alert`,action:e,appBundleId:r?.appBundleId},l))}async function X(e,t,n){if(t===`wait`)return await ke(e,n);let r=t===`accept`||t===`dismiss`?t:`get`;return r===`accept`||r===`dismiss`?await Ae(e,r,n):Z(e,await n(`get`))}function Oe(e){return e===`accept`||e===`dismiss`||e===`wait`?e:`get`}async function ke(e,t){let n=a(e.req.positionals?.[1])??1e4,r=Date.now();for(;Date.now()-r<n;){try{return Z(e,await t(`get`))}catch{}await p(300)}return S(`COMMAND_FAILED`,`alert wait timed out`)}async function Ae(e,t,n){let r=Date.now(),i;for(;Date.now()-r<l;){try{return Z(e,await n(t))}catch(e){i=e;let t=String(e?.message??``).toLowerCase();if(!t.includes(`alert not found`)&&!t.includes(`no alert`))break}await p(300)}throw je(i)}function Z(e,t){let n=t;return D(e.sessionStore,e.session,e.req,n),{ok:!0,data:n}}function je(e){return!(e instanceof t)||!Me(e)?e:new t(e.code,e.message,{...e.details??{},hint:`If the permission sheet is visible in snapshot or screenshot but alert reports no alert, take a scoped snapshot around the visible button label and use press @ref.`})}function Me(e){let t=String(e?.message??``).toLowerCase();return t.includes(`alert not found`)||t.includes(`no alert`)}function Ne(e){let t=e.positionals?.[0]?.toLowerCase(),n=e.positionals?.[1]?.toLowerCase(),r=e.positionals?.[2]?.toLowerCase();return t===`clear-app-state`?{ok:!0,parsed:{setting:t,state:`clear`,appBundleId:n===`clear`?e.positionals?.[2]:e.positionals?.[1]}}:!t||!n||t===`permission`&&!r||t===`location`&&n===`set`&&(!e.positionals?.[2]||!e.positionals?.[3])?S(`INVALID_ARGS`,d):{ok:!0,parsed:{setting:t,state:n,permissionTarget:r,latitude:e.positionals?.[2],longitude:e.positionals?.[3]}}}async function Pe(e){let{req:t,logPath:n,sessionStore:r,session:i,device:a,parsed:c}=e,{setting:l,state:u,appBundleId:d,permissionTarget:f,latitude:p,longitude:h}=c,g=C(`settings`,a);if(g)return g;if(m(a)&&!o(l))return S(`INVALID_ARGS`,s(l));let _=d??i?.appBundleId;if(l===`clear-app-state`&&!_)return S(`INVALID_ARGS`,`settings clear-app-state requires an app id when no app is bound to the session`);let v=await x(a,`settings`,l===`clear-app-state`?[l,u,_??``]:l===`permission`?[l,u,f??``,t.positionals?.[3]??``,_??``]:l===`location`&&u===`set`?[l,u,p??``,h??``,_??``]:[l,u,_??``],t.flags?.out,{...b(n,t.flags,_,i?.trace?.outPath)});return D(r,i,t,v??{setting:l,state:u}),{ok:!0,data:v??{setting:l,state:u}}}async function Fe(t){if(t.command!==`snapshot`||t.device.platform!==`android`)return;let n=e(t.error);if(Be(n))return{ok:!1,error:{...n,details:{...n.details??{},androidSnapshotTimeoutScreenshot:await Ie(t)}}}}async function Ie(t){try{let e=await O.mkdtemp(k.join(de.tmpdir(),`agent-device-android-snapshot-timeout-`)),n=k.join(e,`snapshot-timeout-overlay-refs.png`),r=Re(await x(t.device,`screenshot`,[n],void 0,{...b(t.logPath,{screenshotNoStabilize:!0},t.session?.appBundleId,t.session?.trace?.outPath),surface:t.session?.surface}),n);await O.access(r);let a=await Le(r,t.session);return i({level:`warn`,phase:`android_snapshot_timeout_screenshot_captured`,data:{path:r,overlayRefCount:`overlayRefCount`in a?a.overlayRefCount:void 0,overlayRefsAnnotated:`overlayRefsAnnotated`in a?a.overlayRefsAnnotated:void 0}}),a}catch(t){let n=e(t);return i({level:`warn`,phase:`android_snapshot_timeout_screenshot_failed`,data:{error:n.message}}),{captureFailed:!0,error:n.message}}}async function Le(t,n){if(!n?.snapshot)return{path:t,overlayRefsRequested:!0,overlayRefsAnnotated:!1,overlayRefSource:`unavailable`,overlayRefCount:0};try{let e=await ne({screenshotPath:t,snapshot:n.snapshot});return{path:t,overlayRefsRequested:!0,overlayRefsAnnotated:e.length>0,overlayRefCount:e.length,overlayRefSource:`session-snapshot`,overlayRefs:e}}catch(n){let r=e(n);return i({level:`warn`,phase:`android_snapshot_timeout_screenshot_overlay_failed`,data:{path:t,error:r.message}}),{path:t,overlayRefsRequested:!0,overlayRefsAnnotated:!1,overlayRefSource:`session-snapshot`,overlayRefCount:0,overlayAnnotationError:r.message}}}function Re(e,t){return ze(e)?e.path:t}function ze(e){return typeof e==`object`&&!!e&&`path`in e&&typeof e.path==`string`}function Be(e){return e.code===`COMMAND_FAILED`?Ve(e)||He(e.details?.helper)||Ue(e.details):!1}function Ve(e){let t=`${e.message}\n${e.hint??``}`;return/Android UI hierarchy dump timed out/i.test(t)||/Stock UIAutomator fallback was skipped/i.test(t)?!0:/Android accessibility snapshots can be blocked/i.test(t)}function He(e){if(!e||typeof e!=`object`)return!1;let t=e,n=String(t.errorType??``),r=String(t.message??``);return/TimeoutException/i.test(n)||/timed out/i.test(r)}function Ue(e){if(!e)return!1;let t=e?.timeoutMs,n=e?.cmd,r=We(e?.args);return typeof t==`number`&&n===`adb`&&r.includes(`uiautomator`)&&r.includes(`dump`)}function We(e){return Array.isArray(e)?e.map(String):typeof e==`string`?e.split(/\s+/):[]}async function Ge(e){return await Q({...e,command:`snapshot`,unsupportedMessage:`snapshot is not supported on this device`,execute:async({runtime:t,sessionName:n,req:r,snapshotScope:i})=>{let a=await t.capture.snapshot({session:n,interactiveOnly:r.flags?.snapshotInteractiveOnly,depth:r.flags?.snapshotDepth,scope:i,raw:r.flags?.snapshotRaw,forceFull:r.flags?.snapshotForceFull}),o=e.sessionStore.get(n)?.snapshotGeneration;return{data:o===void 0?a:{...a,refsGeneration:o},record:{kind:`snapshot`,nodes:a.nodes.length,truncated:a.truncated}}}})}async function Ke(e){return await Q({...e,command:`diff`,unsupportedMessage:`diff is not supported on this device`,execute:async({runtime:e,sessionName:t,req:n,snapshotScope:r})=>{let i=await e.capture.diffSnapshot({session:t,interactiveOnly:n.flags?.snapshotInteractiveOnly,depth:n.flags?.snapshotDepth,scope:r,raw:n.flags?.snapshotRaw});return{data:i,record:{kind:`diff`,mode:`snapshot`,baselineInitialized:i.baselineInitialized,summary:i.summary}}}})}async function Q(e){let{req:t,sessionName:n,logPath:r,sessionStore:i}=e,{session:a,device:o}=await E(i,n,t.flags),s=C(e.command,o,{message:e.unsupportedMessage});if(s)return s;let c=te(t.flags?.snapshotScope,a);return c.ok?qe(e.command,a,o)||await T(a,o,async()=>{let s=Je({req:t,sessionName:n,logPath:r,sessionStore:i,session:a,device:o,snapshotScope:c.scope}),l;try{l=await e.execute({runtime:s,sessionName:n,req:t,snapshotScope:c.scope})}catch(t){let n=await Fe({error:t,command:e.command,logPath:r,session:a,device:o});if(!n)throw t;return n}return $e({req:t,sessionName:n,sessionStore:i,result:l.record}),{ok:!0,data:l.data}}):c}function qe(e,t,n){return!g(n)||t?.appBundleId?null:S(`SESSION_NOT_FOUND`,`iOS ${e} requires an active app session on the target device. Run open first (for example: open --session ${t?.name??`sim`} --platform ios --device "<name>" <app>).`)}function Je(e){let{req:t,sessionName:n,logPath:r,sessionStore:i,session:a,device:o,snapshotScope:s}=e;return _({backend:Qe({req:t,logPath:r,session:a,device:o,snapshotScope:s}),...ue(`snapshot`),sessions:ie({sessionName:n,getSession:()=>i.get(n),recordOptions:{includeSnapshot:!0},setRecord:e=>{let r=et(e),a=i.get(n);i.set(n,$({current:a,sessionName:n,device:o,record:r,refScopedSnapshot:Ye(t),issuesRefsToClient:t.command===`snapshot`}))}})})}function $(e){let{current:t,sessionName:n,device:r,record:i,refScopedSnapshot:a}=e,o=Xe(t,i,a),s=ce({session:t,sessionName:n,device:r,snapshot:o?t.snapshot:i.snapshot,appBundleId:i.appBundleId});return s.snapshotScopeSource=Ze({current:t,keepCurrentSnapshot:o,refScopedSnapshot:a}),s.snapshotRefsStale=o?t?.snapshotRefsStale:!e.issuesRefsToClient,s.snapshotGeneration=o?t?.snapshotGeneration:re(t?.snapshotGeneration),i.appName&&(s.appName=i.appName),s}function Ye(e){return e.flags?.snapshotScope?.trim().startsWith(`@`)===!0}function Xe(e,t,n){return n&&t.snapshot?.nodes.length===0&&e?.snapshot!==void 0}function Ze(e){let{current:t,keepCurrentSnapshot:n,refScopedSnapshot:r}=e;if(r)return n?t?.snapshotScopeSource:t?.snapshotScopeSource??t?.snapshot}function Qe(e){let{req:t,logPath:n,session:r,device:i,snapshotScope:a}=e;return{platform:h(i),captureSnapshot:async(e,o)=>{let s=await w({device:i,session:r,flags:t.flags,outPath:o?.outPath??t.flags?.out,logPath:n,snapshotScope:a}),c=f(r);return{snapshot:s.snapshot,...u(s),...c?{snapshotDiagnostics:c}:{},appName:r?.appBundleId?r.appName??r.appBundleId:void 0,appBundleId:r?.appBundleId}}}}function $e(e){let t=e.sessionStore.get(e.sessionName);t&&e.sessionStore.recordAction(t,{command:e.req.command,positionals:e.req.positionals??[],flags:e.req.flags??{},result:tt(e.result)})}function et(e){if(!e.snapshot)throw new t(`UNKNOWN`,`snapshot runtime did not produce session state`);return e}function tt(e){return e.kind===`snapshot`?{nodes:e.nodes,truncated:e.truncated}:{mode:e.mode,baselineInitialized:e.baselineInitialized,summary:e.summary}}const nt={snapshot:async({req:e,sessionName:t,logPath:n,sessionStore:r})=>await Ge({req:e,sessionName:t,logPath:n,sessionStore:r}),diff:async({req:e,sessionName:t,logPath:n,sessionStore:r})=>e.positionals?.[0]===`snapshot`?await Ke({req:e,sessionName:t,logPath:n,sessionStore:r}):S(`INVALID_ARGS`,`diff currently supports only: diff snapshot`),wait:async({req:e,sessionName:t,logPath:n,sessionStore:r})=>await le({req:e,sessionName:t,logPath:n,sessionStore:r}),alert:async({req:e,sessionName:t,logPath:n,sessionStore:r})=>{let{session:i,device:a}=await E(r,t,e.flags);return await T(i,a,async()=>await De({req:e,logPath:n,sessionStore:r,session:i,device:a}))},settings:async({req:e,sessionName:t,logPath:n,sessionStore:r})=>{let i=Ne(e);if(!i.ok)return i;let{session:a,device:o}=await E(r,t,e.flags);return await T(a,o,async()=>await Pe({req:e,logPath:n,sessionStore:r,session:a,device:o,parsed:i.parsed}))}};async function rt(e){let t=e.req.command,n=nt[t];return n?await n(e):null}export{rt as handleSnapshotCommands};
|
|
1
|
+
import{S as e,_ as t}from"./sdk-contracts.js";import{I as n,j as r}from"./sdk-android-adb.js";import{z as i}from"./sdk-batch-runner.js";import{At as a,Dt as o,Et as s,Qn as c,kt as l,wt as u,xt as d}from"./recording-export-quality.js";import{i as f,q as p}from"./snapshot-diagnostics.js";import{c as m,h,s as g}from"./sdk-device.js";import{t as _}from"./timeouts.js";import{i as v}from"./android-system-chrome.js";import{t as y}from"./runtime.js";import{l as b,n as x,s as S,t as C}from"./context.js";import{i as ee}from"./helper.js";import{a as w}from"./runner-client.js";import{Lt as T,Nt as E,Rt as D,Sn as O,Xt as k,en as A,on as te,rn as j,sn as ne,tn as re,u as ie,zt as ae}from"./internal/daemon.js";import{l as oe,n as M}from"./input-actions.js";import{C as N,S as P,b as F,i as I,o as L,x as R}from"./selector-runtime.js";import{promises as z}from"node:fs";import B from"node:os";import V from"node:path";async function H(e,t,n={}){return t===`wait`?await U(e,n.timeoutMs??1e4):t===`get`?q((await K(e))?.alert??null):await W(e,t)}async function U(e,n){let r=Date.now(),i=await G(e,n);if(!i)throw new t(`COMMAND_FAILED`,`alert wait timed out`);return{kind:`alertWait`,platform:`android`,action:`wait`,alert:i.alert,waitedMs:Date.now()-r,...c(`Alert visible`)}}async function W(e,n){let r=await G(e,l);if(!r)throw new t(`COMMAND_FAILED`,`alert not found`,{hint:`If a sheet is visible in snapshot but alert reports no alert, it is likely app-owned UI. Use snapshot -i and press the visible label/ref.`});let i=D(r.buttons,n);if(i)return await oe(e,i.x,i.y),J(n,r.alert,i.label);if(n===`dismiss`)return await M(e),J(n,r.alert,`Back`);throw new t(`COMMAND_FAILED`,`alert accept found an alert but no accept button`,{alert:r.alert,hint:`Inspect alert get --json for visible buttons, then use press by visible label/ref if needed.`})}async function G(e,t){let n=Date.now();for(;Date.now()-n<t;){let t=await K(e);if(t)return t;await _(300)}return null}async function K(e){return ae((await n(`snapshot_capture`,async()=>await T(e,{helperWaitForIdleTimeoutMs:0,includeHiddenContentHints:!1}),{backend:`android`,purpose:`alert`})).nodes)}function q(e){return{kind:`alertStatus`,platform:`android`,action:`get`,alert:e,...c(e?`Alert visible`:`No alert visible`)}}function J(e,t,n){return{kind:`alertHandled`,platform:`android`,action:e,handled:!0,alert:t,button:n,...c(`Alert ${e}ed`)}}async function se(e){let{req:t,logPath:n,session:r,device:a}=e,o=ce(t.positionals?.[0]),s=r?r.surface===`frontmost-app`?{surface:`frontmost-app`}:{bundleId:r.appBundleId,surface:r.surface}:{},c=b(`alert`,a);if(c)return c;if(r&&O(t)===`may-invalidate`&&j(r),a.platform===`android`)return Z(e,await H(a,o,{timeoutMs:i(t.positionals?.[1])??1e4}));if(m(a))return await Y(e,o,async e=>await ee(e,s));let l=ie({req:t,logPath:n,traceLogPath:r?.trace?.outPath});return await Y(e,o,async(e,t)=>await w(a,{command:`alert`,action:e,appBundleId:r?.appBundleId,timeoutMs:t},l))}async function Y(e,t,n){if(t===`wait`)return await le(e,n);let r=t===`accept`||t===`dismiss`?t:`get`;return r===`accept`||r===`dismiss`?await ue(e,r,n):Z(e,await n(`get`,a))}function ce(e){return e===`accept`||e===`dismiss`||e===`wait`?e:`get`}async function le(e,t){let n=i(e.req.positionals?.[1])??1e4,r=Date.now(),a=!0;for(;Date.now()-r<n;){try{let i=a?n:X(r,n);return a=!1,Z(e,await t(`get`,i))}catch{}await _(300)}return S(`COMMAND_FAILED`,`alert wait timed out`)}async function ue(e,t,n){let r=g(e.device)?a:l,i=Date.now(),o,s=!0;for(;Date.now()-i<l;){try{let a=s?r:X(i,l);return s=!1,Z(e,await n(t,a))}catch(e){o=e;let t=String(e?.message??``).toLowerCase();if(!t.includes(`alert not found`)&&!t.includes(`no alert`))break}await _(300)}throw de(o)}function X(e,t){return Math.max(1,t-(Date.now()-e))}function Z(e,t){let n=t;return R(e.sessionStore,e.session,e.req,n),{ok:!0,data:n}}function de(e){return!(e instanceof t)||!fe(e)?e:new t(e.code,e.message,{...e.details??{},hint:`If the permission sheet is visible in snapshot or screenshot but alert reports no alert, take a scoped snapshot around the visible button label and use press @ref.`})}function fe(e){let t=String(e?.message??``).toLowerCase();return t.includes(`alert not found`)||t.includes(`no alert`)}function pe(e){let t=e.positionals?.[0]?.toLowerCase(),n=e.positionals?.[1]?.toLowerCase(),r=e.positionals?.[2]?.toLowerCase();return t===`clear-app-state`?{ok:!0,parsed:{setting:t,state:`clear`,appBundleId:n===`clear`?e.positionals?.[2]:e.positionals?.[1]}}:!t||!n||t===`permission`&&!r||t===`location`&&n===`set`&&(!e.positionals?.[2]||!e.positionals?.[3])?S(`INVALID_ARGS`,u):{ok:!0,parsed:{setting:t,state:n,permissionTarget:r,latitude:e.positionals?.[2],longitude:e.positionals?.[3]}}}async function me(e){let{req:t,logPath:n,sessionStore:r,session:i,device:a,parsed:c}=e,{setting:l,state:u,appBundleId:d,permissionTarget:f,latitude:p,longitude:h}=c,g=b(`settings`,a);if(g)return g;if(m(a)&&!o(l))return S(`INVALID_ARGS`,s(l));let _=d??i?.appBundleId;if(l===`clear-app-state`&&!_)return S(`INVALID_ARGS`,`settings clear-app-state requires an app id when no app is bound to the session`);let v=l===`clear-app-state`?[l,u,_??``]:l===`permission`?[l,u,f??``,t.positionals?.[3]??``,_??``]:l===`location`&&u===`set`?[l,u,p??``,h??``,_??``]:[l,u,_??``];i&&j(i);let y=await x(a,`settings`,v,t.flags?.out,{...C(n,t.flags,_,i?.trace?.outPath)});return R(r,i,t,y??{setting:l,state:u}),{ok:!0,data:y??{setting:l,state:u}}}async function he(t){if(t.command!==`snapshot`||t.device.platform!==`android`)return;let n=e(t.error);if(be(n))return{ok:!1,error:{...n,details:{...n.details??{},androidSnapshotTimeoutScreenshot:await ge(t)}}}}async function ge(t){try{let e=await z.mkdtemp(V.join(B.tmpdir(),`agent-device-android-snapshot-timeout-`)),n=V.join(e,`snapshot-timeout-overlay-refs.png`),i=ve(await x(t.device,`screenshot`,[n],void 0,{...C(t.logPath,{screenshotNoStabilize:!0},t.session?.appBundleId,t.session?.trace?.outPath),surface:t.session?.surface}),n);await z.access(i);let a=await _e(i,t.session);return r({level:`warn`,phase:`android_snapshot_timeout_screenshot_captured`,data:{path:i,overlayRefCount:`overlayRefCount`in a?a.overlayRefCount:void 0,overlayRefsAnnotated:`overlayRefsAnnotated`in a?a.overlayRefsAnnotated:void 0}}),a}catch(t){let n=e(t);return r({level:`warn`,phase:`android_snapshot_timeout_screenshot_failed`,data:{error:n.message}}),{captureFailed:!0,error:n.message}}}async function _e(t,n){if(!n?.snapshot)return{path:t,overlayRefsRequested:!0,overlayRefsAnnotated:!1,overlayRefSource:`unavailable`,overlayRefCount:0};try{let e=await E({screenshotPath:t,snapshot:n.snapshot});return{path:t,overlayRefsRequested:!0,overlayRefsAnnotated:e.length>0,overlayRefCount:e.length,overlayRefSource:`session-snapshot`,overlayRefs:e}}catch(n){let i=e(n);return r({level:`warn`,phase:`android_snapshot_timeout_screenshot_overlay_failed`,data:{path:t,error:i.message}}),{path:t,overlayRefsRequested:!0,overlayRefsAnnotated:!1,overlayRefSource:`session-snapshot`,overlayRefCount:0,overlayAnnotationError:i.message}}}function ve(e,t){return ye(e)?e.path:t}function ye(e){return typeof e==`object`&&!!e&&`path`in e&&typeof e.path==`string`}function be(e){return e.code===`COMMAND_FAILED`?xe(e)||Se(e.details?.helper):!1}function xe(e){let t=`${e.message}\n${e.hint??``}`;return/Android accessibility snapshots can be blocked/i.test(t)}function Se(e){if(!e||typeof e!=`object`)return!1;let t=e,n=String(t.errorType??``),r=String(t.message??``);return/TimeoutException/i.test(n)||/timed out/i.test(r)}async function Ce(e){return await Q({...e,command:`snapshot`,unsupportedMessage:`snapshot is not supported on this device`,execute:async({runtime:t,sessionName:n,req:r,snapshotScope:i})=>{let a=await t.capture.snapshot({session:n,interactiveOnly:r.flags?.snapshotInteractiveOnly,depth:r.flags?.snapshotDepth,scope:i,raw:r.flags?.snapshotRaw,forceFull:r.flags?.snapshotForceFull}),o=e.sessionStore.get(n)?.snapshotGeneration,s=v(a.nodes),c=s===a.nodes?a:{...a,nodes:s};return{data:o===void 0?c:{...c,refsGeneration:o},record:{kind:`snapshot`,nodes:a.nodes.length,truncated:a.truncated}}}})}async function we(e){return await Q({...e,command:`diff`,unsupportedMessage:`diff is not supported on this device`,execute:async({runtime:e,sessionName:t,req:n,snapshotScope:r})=>{let i=await e.capture.diffSnapshot({session:t,interactiveOnly:n.flags?.snapshotInteractiveOnly,depth:n.flags?.snapshotDepth,scope:r,raw:n.flags?.snapshotRaw});return{data:i,record:{kind:`diff`,mode:`snapshot`,baselineInitialized:i.baselineInitialized,summary:i.summary}}}})}async function Q(e){let{req:t,sessionName:n,logPath:r,sessionStore:i}=e,{session:a,device:o}=await P(i,n,t.flags),s=b(e.command,o,{message:e.unsupportedMessage});if(s)return s;let c=ne(t.flags?.snapshotScope,a);return c.ok?Te(e.command,a,o)||await N(a,o,async()=>{let s=Ee({req:t,sessionName:n,logPath:r,sessionStore:i,session:a,device:o,snapshotScope:c.scope}),l;try{l=await e.execute({runtime:s,sessionName:n,req:t,snapshotScope:c.scope})}catch(t){let n=await he({error:t,command:e.command,logPath:r,session:a,device:o});if(!n)throw t;return n}return Me({req:t,sessionName:n,sessionStore:i,result:l.record}),{ok:!0,data:l.data}}):c}function Te(e,t,n){return!g(n)||t?.appBundleId?null:S(`SESSION_NOT_FOUND`,`iOS ${e} requires an active app session on the target device. Run open first (for example: open --session ${t?.name??`sim`} --platform ios --device "<name>" <app>).`)}function Ee(e){let{req:t,sessionName:n,logPath:r,sessionStore:i,session:a,device:o,snapshotScope:s}=e;return y({backend:je({req:t,logPath:r,session:a,device:o,snapshotScope:s}),...L(`snapshot`),sessions:k({sessionName:n,getSession:()=>i.get(n),recordOptions:{includeSnapshot:!0},setRecord:e=>{let r=Ne(e),a=i.get(n);i.set(n,De({current:a,sessionName:n,device:o,record:r,refScopedSnapshot:Oe(t),issuesRefsToClient:t.command===`snapshot`}))}})})}function De(e){let{current:t,sessionName:n,device:r,record:i,refScopedSnapshot:a}=e,o=ke(t,i,a),s=F({session:t,sessionName:n,device:r,snapshot:o?t.snapshot:i.snapshot,appBundleId:i.appBundleId});return A(s,{scopeSource:$({current:t,keepCurrentSnapshot:o,refScopedSnapshot:a}),keptCurrentSnapshot:o,previousGeneration:t?.snapshotGeneration}),Ae(s,o,e.issuesRefsToClient),i.appName&&(s.appName=i.appName),s}function Oe(e){return e.flags?.snapshotScope?.trim().startsWith(`@`)===!0}function ke(e,t,n){return n&&t.snapshot?.nodes.length===0&&e?.snapshot!==void 0}function Ae(e,t,n){!t&&n&&re(e)}function $(e){let{current:t,keepCurrentSnapshot:n,refScopedSnapshot:r}=e;if(r)return n?t?.snapshotScopeSource:t?.snapshotScopeSource??t?.snapshot}function je(e){let{req:t,logPath:n,session:r,device:i,snapshotScope:a}=e;return{platform:h(i),captureSnapshot:async(e,o)=>{let s=await te({device:i,session:r,flags:t.flags,outPath:o?.outPath??t.flags?.out,logPath:n,snapshotScope:a}),c=f(r);return{snapshot:s.snapshot,...d(s),...c?{snapshotDiagnostics:c}:{},appName:r?.appBundleId?r.appName??r.appBundleId:void 0,appBundleId:r?.appBundleId}}}}function Me(e){let t=e.sessionStore.get(e.sessionName);t&&e.sessionStore.recordAction(t,{command:e.req.command,positionals:e.req.positionals??[],flags:e.req.flags??{},result:Pe(e.result),interactiveObservation:p(e.req)})}function Ne(e){if(!e.snapshot)throw new t(`UNKNOWN`,`snapshot runtime did not produce session state`);return e}function Pe(e){return e.kind===`snapshot`?{nodes:e.nodes,truncated:e.truncated}:{mode:e.mode,baselineInitialized:e.baselineInitialized,summary:e.summary}}const Fe={snapshot:async({req:e,sessionName:t,logPath:n,sessionStore:r})=>await Ce({req:e,sessionName:t,logPath:n,sessionStore:r}),diff:async({req:e,sessionName:t,logPath:n,sessionStore:r})=>e.positionals?.[0]===`snapshot`?await we({req:e,sessionName:t,logPath:n,sessionStore:r}):S(`INVALID_ARGS`,`diff currently supports only: diff snapshot`),wait:async({req:e,sessionName:t,logPath:n,sessionStore:r})=>await I({req:e,sessionName:t,logPath:n,sessionStore:r}),alert:async({req:e,sessionName:t,logPath:n,sessionStore:r})=>{let{session:i,device:a}=await P(r,t,e.flags);return await N(i,a,async()=>await se({req:e,logPath:n,sessionStore:r,session:i,device:a}))},settings:async({req:e,sessionName:t,logPath:n,sessionStore:r})=>{let i=pe(e);if(!i.ok)return i;let{session:a,device:o}=await P(r,t,e.flags);return await N(a,o,async()=>await me({req:e,logPath:n,sessionStore:r,session:a,device:o,parsed:i.parsed}))}};async function Ie(e){let t=e.req.command,n=Fe[t];return n?await n(e):null}export{Ie as handleSnapshotCommands};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./rolldown-runtime.js";import{v as t,w as n}from"./sdk-android-adb.js";import{t as r}from"./scoped-provider.js";import{constants as i}from"node:fs";import a from"node:os";import o from"node:path";import{access as s}from"node:fs/promises";var c=e({createLocalVegaToolProvider:()=>d,resolveVegaToolProvider:()=>f,withVegaToolProvider:()=>p});const l={run:async(e,n)=>await t(await h()??`vega`,e,n),isAvailable:async()=>!!await h()},u=r(d());function d(e=l){return{isAvailable:async()=>await e.isAvailable(),version:async t=>await e.run([`--version`],t),listDevices:async t=>await e.run([`device`,`list`],t),checkConnected:async(t,n)=>await e.run([`device`,`is-connected`,`--device`,t],n),launchApp:async(t,n,r)=>await e.run([`device`,`launch-app`,`--device`,t,`--appName`,n],r),terminateApp:async(t,n,r)=>await e.run([`device`,`terminate-app`,`--device`,t,`--appName`,n],r),pressRemote:async(t,n,r,i)=>await e.run([`device`,`run-cmd`,`--device`,t,`--command`,[`inputd-cli`,`button_press`,n,...r===void 0?[]:[`--holdDuration`,String(r)]].join(` `)],i)}}function f(e){return u.resolve(e)}async function p(e,t){return await u.run(e,t)}let m;async function h(){if(m)return m;if(await n(`vega`))return m=`vega`,m;let e=o.join(a.homedir(),`vega`,`bin`,`vega`);try{await s(e,i.X_OK),m=e}catch{return}return m}export{c as n,f as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{_ as e}from"./sdk-contracts.js";function t(t){let n=async n=>{throw new e(`UNSUPPORTED_OPERATION`,`${n} is not supported on ${t}`)};return{open:()=>n(`open`),openDevice:()=>n(`openDevice`),close:()=>n(`close`),tap:()=>n(`tap`),doubleTap:()=>n(`doubleTap`),longPress:()=>n(`longPress`),focus:()=>n(`focus`),type:()=>n(`type`),fill:()=>n(`fill`),scroll:()=>n(`scroll`),screenshot:()=>n(`screenshot`),snapshot:()=>n(`snapshot`),back:()=>n(`back`),home:()=>n(`home`),setOrientation:()=>n(`setOrientation`),appSwitcher:()=>n(`appSwitcher`),tvRemote:()=>n(`tvRemote`),readClipboard:()=>n(`readClipboard`),writeClipboard:()=>n(`writeClipboard`),setSetting:()=>n(`setSetting`)}}export{t};
|
package/dist/src/url.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=`--agent-device-run-metro-companion`,t=`--agent-device-run-react-devtools-companion`,n=1e3,r=`AGENT_DEVICE_COMPANION_TUNNEL_SERVER_BASE_URL`,i=`AGENT_DEVICE_COMPANION_TUNNEL_BEARER_TOKEN`,a=`AGENT_DEVICE_COMPANION_TUNNEL_LOCAL_BASE_URL`,o=`AGENT_DEVICE_COMPANION_TUNNEL_LAUNCH_URL`,s=`AGENT_DEVICE_COMPANION_TUNNEL_STATE_PATH`,c=`AGENT_DEVICE_COMPANION_TUNNEL_SCOPE_TENANT_ID`,l=`AGENT_DEVICE_COMPANION_TUNNEL_SCOPE_RUN_ID`,u=`AGENT_DEVICE_COMPANION_TUNNEL_SCOPE_LEASE_ID`,d=`AGENT_DEVICE_COMPANION_TUNNEL_REGISTER_PATH`,f=`AGENT_DEVICE_COMPANION_TUNNEL_UNREGISTER_PATH`,p=`AGENT_DEVICE_COMPANION_TUNNEL_DEVICE_PORT`,m=`AGENT_DEVICE_COMPANION_TUNNEL_SESSION`;var h=class extends Error{name=`MissingCompanionEnvError`};function g(e){let t=e.length;for(;t>0&&e.charCodeAt(t-1)===47;)--t;return t===e.length?e:e.slice(0,t)}function _(e,t){let
|
|
1
|
+
const e=`--agent-device-run-metro-companion`,t=`--agent-device-run-react-devtools-companion`,n=1e3,r=`AGENT_DEVICE_COMPANION_TUNNEL_SERVER_BASE_URL`,i=`AGENT_DEVICE_COMPANION_TUNNEL_BEARER_TOKEN`,a=`AGENT_DEVICE_COMPANION_TUNNEL_LOCAL_BASE_URL`,o=`AGENT_DEVICE_COMPANION_TUNNEL_LAUNCH_URL`,s=`AGENT_DEVICE_COMPANION_TUNNEL_STATE_PATH`,c=`AGENT_DEVICE_COMPANION_TUNNEL_SCOPE_TENANT_ID`,l=`AGENT_DEVICE_COMPANION_TUNNEL_SCOPE_RUN_ID`,u=`AGENT_DEVICE_COMPANION_TUNNEL_SCOPE_LEASE_ID`,d=`AGENT_DEVICE_COMPANION_TUNNEL_REGISTER_PATH`,f=`AGENT_DEVICE_COMPANION_TUNNEL_UNREGISTER_PATH`,p=`AGENT_DEVICE_COMPANION_TUNNEL_DEVICE_PORT`,m=`AGENT_DEVICE_COMPANION_TUNNEL_SESSION`;var h=class extends Error{name=`MissingCompanionEnvError`};function g(e){let t=e.length;for(;t>0&&e.charCodeAt(t-1)===47;)--t;return t===e.length?e:e.slice(0,t)}function _(e,t,n=`index.bundle`){let r=new URL(`${g(e)}/${n}`);return r.searchParams.set(`platform`,t),r.searchParams.set(`dev`,`true`),r.searchParams.set(`minify`,`false`),r.toString()}export{h as _,p as a,d as c,c as d,r as f,e as g,f as h,i,u as l,s as m,g as n,o,m as p,n as r,a as s,_ as t,l as u,t as v};
|
package/dist/src/web.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{_ as e}from"./sdk-contracts.js";import{
|
|
1
|
+
import{_ as e}from"./sdk-contracts.js";import{I as t}from"./sdk-android-adb.js";import{m as n}from"./internal/daemon.js";import{t as r}from"./unsupported-interactor.js";function i(){let i=()=>n();return{...r(`web`),open:(e,t)=>i().open(t?.url??e,{url:t?.url}),openDevice:()=>i().open(`about:blank`),close:e=>i().close(e),tap:(e,t)=>i().click(e,t),focus:(e,t)=>i().click(e,t),type:(e,t)=>i().typeText(e,{delayMs:t}),fill:(e,t,n,r)=>i().fill(e,t,n,{delayMs:r}),scroll:(e,t)=>i().scroll(e,t),screenshot:(e,t)=>i().screenshot(e,t),setViewport:(e,t)=>i().setViewport(e,t),snapshot:async e=>{let n=await t(`snapshot_capture`,async()=>await i().snapshot(e),{backend:`web`});return{nodes:n.nodes,truncated:n.truncated??!1,backend:`web`}},setOrientation:async()=>{throw new e(`UNSUPPORTED_OPERATION`,`orientation is not supported on web`)}}}export{i as createWebInteractor};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-device",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.1",
|
|
4
4
|
"description": "Agent-native CLI for AI app automation across iOS, Android, tvOS, Android TV, macOS, Linux, and web.",
|
|
5
5
|
"mcpName": "io.github.callstackincubator/agent-device",
|
|
6
6
|
"license": "MIT",
|
|
@@ -90,24 +90,27 @@
|
|
|
90
90
|
"build:xcuitest:visionos:clean": "pnpm clean:xcuitest:visionos && pnpm build:xcuitest:visionos",
|
|
91
91
|
"build:android-snapshot-helper": "sh ./scripts/build-android-snapshot-helper.sh $(node -p \"require('./package.json').version\") .tmp/android-snapshot-helper",
|
|
92
92
|
"package:android-snapshot-helper": "sh ./scripts/package-android-snapshot-helper.sh $(node -p \"require('./package.json').version\") v$(node -p \"require('./package.json').version\") .tmp/android-snapshot-helper",
|
|
93
|
-
"package:android-snapshot-helper:npm": "rm -rf android
|
|
93
|
+
"package:android-snapshot-helper:npm": "rm -rf android/snapshot-helper/dist && sh ./scripts/package-android-snapshot-helper.sh $(node -p \"require('./package.json').version\") v$(node -p \"require('./package.json').version\") android/snapshot-helper/dist",
|
|
94
94
|
"package:apple-runner:npm": "node scripts/package-apple-runner-source.mjs",
|
|
95
|
-
"build:android
|
|
96
|
-
"
|
|
97
|
-
"package:android-
|
|
98
|
-
"
|
|
99
|
-
"build:macos-helper": "swift build -c release --package-path macos-helper",
|
|
95
|
+
"build:android": "pnpm package:android-snapshot-helper:npm && pnpm package:android-ime-helper:npm",
|
|
96
|
+
"build:android-ime-helper": "sh ./scripts/build-android-ime-helper.sh $(node -p \"require('./package.json').version\") .tmp/android-ime-helper",
|
|
97
|
+
"package:android-ime-helper": "sh ./scripts/package-android-ime-helper.sh $(node -p \"require('./package.json').version\") .tmp/android-ime-helper",
|
|
98
|
+
"package:android-ime-helper:npm": "rm -rf android/ime-helper/dist && sh ./scripts/package-android-ime-helper.sh $(node -p \"require('./package.json').version\") android/ime-helper/dist",
|
|
99
|
+
"build:macos-helper": "swift build -c release --package-path apple/macos-helper",
|
|
100
100
|
"build:all": "pnpm build:node && pnpm build:xcuitest",
|
|
101
101
|
"ad": "node bin/agent-device.mjs",
|
|
102
102
|
"bench:help-conformance": "node scripts/help-conformance-bench.mjs",
|
|
103
|
+
"maestro:conformance": "node --experimental-strip-types --test scripts/maestro-conformance/verify.test.ts scripts/maestro-conformance/differential/run.test.ts scripts/maestro-conformance/differential/invariants.test.ts",
|
|
104
|
+
"maestro:conformance:regenerate": "node scripts/maestro-conformance/regenerate.mjs",
|
|
105
|
+
"maestro:conformance:differential": "node --experimental-strip-types scripts/maestro-conformance/differential/run.ts",
|
|
103
106
|
"size": "node scripts/size-report.mjs",
|
|
104
107
|
"size:markdown": "node scripts/size-report.mjs --json .tmp/size-report.json --markdown .tmp/size-report.md",
|
|
105
108
|
"perf": "node --experimental-strip-types scripts/perf/run.ts",
|
|
106
109
|
"perf:ios": "node --experimental-strip-types scripts/perf/run.ts --platform ios",
|
|
107
110
|
"perf:android": "node --experimental-strip-types scripts/perf/run.ts --platform android",
|
|
108
111
|
"lint": "oxlint . --deny-warnings",
|
|
109
|
-
"format": "node ./node_modules/oxfmt/bin/oxfmt --write src test skills package.json tsconfig.json tsconfig.lib.json tsdown.config.ts vitest.config.ts .github/actions/setup-node-pnpm/action.yml .oxlintrc.json .oxfmtrc.json '!test/skillgym/.skillgym-results/**'",
|
|
110
|
-
"format:check": "node ./node_modules/oxfmt/bin/oxfmt --check src test skills package.json tsconfig.json tsconfig.lib.json tsdown.config.ts vitest.config.ts .github/actions/setup-node-pnpm/action.yml .oxlintrc.json .oxfmtrc.json '!test/skillgym/.skillgym-results/**'",
|
|
112
|
+
"format": "node ./node_modules/oxfmt/bin/oxfmt --write src test skills scripts/help-conformance-bench.mjs scripts/help-conformance-case-checks.mjs scripts/help-conformance-command-validator.ts scripts/help-conformance-expectations.mjs scripts/help-conformance-plan-validator.mjs scripts/help-conformance-runner-output.mjs scripts/help-conformance-summary.mjs scripts/help-conformance-cases.mjs scripts/help-conformance-sample-outputs.mjs scripts/__tests__/help-conformance-bench.test.ts scripts/__tests__/help-conformance-sample-outputs.test.ts scripts/__tests__/help-conformance-topic-coverage.test.ts package.json tsconfig.json tsconfig.lib.json tsdown.config.ts vitest.config.ts .github/actions/setup-node-pnpm/action.yml .oxlintrc.json .oxfmtrc.json '!test/skillgym/.skillgym-results/**'",
|
|
113
|
+
"format:check": "node ./node_modules/oxfmt/bin/oxfmt --check src test skills scripts/help-conformance-bench.mjs scripts/help-conformance-case-checks.mjs scripts/help-conformance-command-validator.ts scripts/help-conformance-expectations.mjs scripts/help-conformance-plan-validator.mjs scripts/help-conformance-runner-output.mjs scripts/help-conformance-summary.mjs scripts/help-conformance-cases.mjs scripts/help-conformance-sample-outputs.mjs scripts/__tests__/help-conformance-bench.test.ts scripts/__tests__/help-conformance-sample-outputs.test.ts scripts/__tests__/help-conformance-topic-coverage.test.ts package.json tsconfig.json tsconfig.lib.json tsdown.config.ts vitest.config.ts .github/actions/setup-node-pnpm/action.yml .oxlintrc.json .oxfmtrc.json '!test/skillgym/.skillgym-results/**'",
|
|
111
114
|
"fallow": "fallow audit --base origin/main",
|
|
112
115
|
"fallow:all": "fallow --summary",
|
|
113
116
|
"fallow:baseline": "(fallow dead-code --save-baseline fallow-baselines/dead-code.json --summary || true) && (fallow health --save-baseline fallow-baselines/health.json --summary || true)",
|
|
@@ -115,19 +118,21 @@
|
|
|
115
118
|
"check:affected": "node --experimental-strip-types scripts/check-affected/run.ts",
|
|
116
119
|
"check:affected:test": "node --experimental-strip-types --test scripts/check-affected/model.test.ts scripts/check-affected/run.test.ts",
|
|
117
120
|
"check:layering": "node --experimental-strip-types --test scripts/layering/model.test.ts && node --experimental-strip-types scripts/layering/check.ts",
|
|
118
|
-
"
|
|
119
|
-
"
|
|
120
|
-
"check:production-exports
|
|
121
|
+
"depgraph": "node --experimental-strip-types scripts/depgraph/build.ts",
|
|
122
|
+
"depgraph:test": "node --experimental-strip-types --test scripts/depgraph/model.test.ts",
|
|
123
|
+
"check:production-exports": "fallow dead-code --config fallow-production-exports.json --production --unused-exports --fail-on-issues",
|
|
124
|
+
"check:bundle-owner-files": "node --experimental-strip-types scripts/check-bundle-owner-files.ts",
|
|
125
|
+
"check:freerange": "fr",
|
|
121
126
|
"check:quick": "pnpm lint && pnpm typecheck",
|
|
122
127
|
"sync:mcp-metadata": "node scripts/sync-mcp-metadata.mjs",
|
|
123
128
|
"check:mcp-metadata": "node scripts/sync-mcp-metadata.mjs --check",
|
|
124
129
|
"version": "node scripts/sync-mcp-metadata.mjs && git add server.json",
|
|
125
|
-
"check:tooling": "pnpm lint && pnpm typecheck && pnpm check:layering && pnpm check:production-exports && pnpm check:mcp-metadata && pnpm build",
|
|
130
|
+
"check:tooling": "pnpm lint && pnpm typecheck && pnpm check:layering && pnpm depgraph:test && pnpm check:production-exports && pnpm check:mcp-metadata && pnpm build && pnpm check:bundle-owner-files",
|
|
126
131
|
"check:unit": "pnpm test:unit && pnpm test:smoke",
|
|
127
132
|
"check": "pnpm check:tooling && pnpm check:fallow && pnpm check:unit",
|
|
128
|
-
"prepack": "pnpm check:mcp-metadata && pnpm build:all && pnpm package:apple-runner:npm && pnpm package:android-snapshot-helper:npm && pnpm package:android-
|
|
133
|
+
"prepack": "pnpm check:mcp-metadata && pnpm build:all && pnpm package:apple-runner:npm && pnpm package:android-snapshot-helper:npm && pnpm package:android-ime-helper:npm",
|
|
129
134
|
"typecheck": "tsc -p tsconfig.json",
|
|
130
|
-
"test-app:install": "pnpm install --dir examples/test-app
|
|
135
|
+
"test-app:install": "pnpm install --dir examples/test-app",
|
|
131
136
|
"test-app:start": "pnpm --dir examples/test-app start",
|
|
132
137
|
"test-app:ios": "pnpm --dir examples/test-app ios",
|
|
133
138
|
"test-app:android": "pnpm --dir examples/test-app android",
|
|
@@ -137,8 +142,8 @@
|
|
|
137
142
|
"test-app:maestro": "node scripts/run-test-app-maestro-suite.mjs",
|
|
138
143
|
"test-app:maestro:ios": "node scripts/run-test-app-maestro-suite.mjs --platform ios",
|
|
139
144
|
"test-app:maestro:android": "node scripts/run-test-app-maestro-suite.mjs --platform android",
|
|
140
|
-
"test": "vitest run --project unit-core --project
|
|
141
|
-
"test:unit": "vitest run --project unit-core --project
|
|
145
|
+
"test": "vitest run --project unit-core --project subprocess-stub",
|
|
146
|
+
"test:unit": "vitest run --project unit-core --project subprocess-stub",
|
|
142
147
|
"test:coverage": "vitest run --coverage",
|
|
143
148
|
"test:integration:provider": "vitest run --project provider-integration",
|
|
144
149
|
"test:integration:progress": "node --experimental-strip-types scripts/integration-progress.ts",
|
|
@@ -159,15 +164,15 @@
|
|
|
159
164
|
"files": [
|
|
160
165
|
"bin",
|
|
161
166
|
"dist",
|
|
162
|
-
"macos-helper",
|
|
163
|
-
"!macos-helper/**/.build",
|
|
164
|
-
"android
|
|
165
|
-
"!android
|
|
166
|
-
"!android
|
|
167
|
-
"android-
|
|
168
|
-
"!android-
|
|
169
|
-
"!android-
|
|
170
|
-
"
|
|
167
|
+
"apple/macos-helper",
|
|
168
|
+
"!apple/macos-helper/**/.build",
|
|
169
|
+
"android/snapshot-helper/dist",
|
|
170
|
+
"!android/snapshot-helper/dist/*.idsig",
|
|
171
|
+
"!android/snapshot-helper/README.md",
|
|
172
|
+
"android/ime-helper/dist",
|
|
173
|
+
"!android/ime-helper/dist/*.idsig",
|
|
174
|
+
"!android/ime-helper/README.md",
|
|
175
|
+
"linux/atspi-dump.py",
|
|
171
176
|
"skills",
|
|
172
177
|
"server.json",
|
|
173
178
|
"smithery.yaml",
|
|
@@ -218,11 +223,12 @@
|
|
|
218
223
|
"detox"
|
|
219
224
|
],
|
|
220
225
|
"dependencies": {
|
|
226
|
+
"@limrun/api": "^0.24.5",
|
|
221
227
|
"yaml": "^2.9.0"
|
|
222
228
|
},
|
|
223
229
|
"devDependencies": {
|
|
230
|
+
"@chenglou/freerange": "^0.0.1",
|
|
224
231
|
"@types/node": "^22.19.21",
|
|
225
|
-
"typescript": "^7.0.2",
|
|
226
232
|
"@vitest/coverage-v8": "4.1.8",
|
|
227
233
|
"fallow": "^2.95.0",
|
|
228
234
|
"oxc-parser": "^0.138.0",
|
|
@@ -230,6 +236,7 @@
|
|
|
230
236
|
"oxlint": "^1.69.0",
|
|
231
237
|
"skillgym": "^0.9.1",
|
|
232
238
|
"tsdown": "^0.22.4",
|
|
239
|
+
"typescript": "^7.0.2",
|
|
233
240
|
"vite": "^8.0.16",
|
|
234
241
|
"vitest": "^4.1.8"
|
|
235
242
|
}
|
package/server.json
CHANGED
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
"url": "https://github.com/callstack/agent-device",
|
|
8
8
|
"source": "github"
|
|
9
9
|
},
|
|
10
|
-
"version": "0.
|
|
10
|
+
"version": "0.20.1",
|
|
11
11
|
"packages": [
|
|
12
12
|
{
|
|
13
13
|
"registryType": "npm",
|
|
14
14
|
"identifier": "agent-device",
|
|
15
|
-
"version": "0.
|
|
15
|
+
"version": "0.20.1",
|
|
16
16
|
"transport": {
|
|
17
17
|
"type": "stdio"
|
|
18
18
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: agent-device
|
|
3
|
-
description: Automates Apple-platform apps (iOS, tvOS, macOS) and
|
|
3
|
+
description: Automates Apple-platform apps (iOS, tvOS, macOS), Android devices, and Amazon Vega OS TV apps in Vega Virtual Devices. Use when navigating apps, taking snapshots/screenshots where supported, driving TV remotes, tapping, typing, scrolling, extracting UI info, collecting evidence, or planning agent-device CLI commands.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# agent-device
|
|
@@ -13,7 +13,7 @@ agent-device --version
|
|
|
13
13
|
|
|
14
14
|
If that fails but the user may have installed `agent-device` globally, check the user's configured login/interactive shell and environment before using `npx`. Resolve the command the same way the user would from a normal terminal session, then run the absolute binary path if found. This may require inspecting shell startup behavior or package-manager/global bin locations; do not assume the Codex process `PATH` is the user's `PATH`.
|
|
15
15
|
|
|
16
|
-
Require `agent-device >= 0.
|
|
16
|
+
Require `agent-device >= 0.20.0`; older CLIs lack the current help topics and Vega OS routing. If older, stop and tell the user to upgrade the trusted install or approve an exact-version npm command. Do not run `npm install -g agent-device@latest` or `npx -y agent-device@latest` autonomously, and do not include version/upgrade commands in final plans.
|
|
17
17
|
|
|
18
18
|
Before your first agent-device command or plan, read the smallest version-matched CLI guide that fits the task:
|
|
19
19
|
|
|
@@ -34,9 +34,11 @@ agent-device help cdp
|
|
|
34
34
|
agent-device help remote
|
|
35
35
|
agent-device help macos
|
|
36
36
|
agent-device help dogfood
|
|
37
|
+
agent-device help tv
|
|
38
|
+
agent-device help ios-system-ui # iOS SpringBoard, widgets, and system-UI surfaces
|
|
37
39
|
```
|
|
38
40
|
|
|
39
|
-
Default loop: `open -> snapshot/-i -> get/is/find or press/fill/scroll/wait -> verify -> close`.
|
|
41
|
+
Default loop: `open -> snapshot/-i -> get/is/find or press/fill/scroll/wait -> verify -> close`. When target-specific help says capture or selectors are unsupported, use its control-only loop and the device display as visual truth.
|
|
40
42
|
|
|
41
43
|
Use this skill only to route into version-matched CLI help. Let the selected help topic provide exact command shapes, platform limits, and current workflow guidance; use `help workflow` as the full reference when a task-specific topic is too narrow.
|
|
42
44
|
|
|
Binary file
|
package/android-multitouch-helper/dist/agent-device-android-multitouch-helper-0.19.3.apk.sha256
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
38e24a9ed16d41ac68b810c664e7bfc5c21d7a59be83d9789ea759e46c81eb7e agent-device-android-multitouch-helper-0.19.3.apk
|
package/android-multitouch-helper/dist/agent-device-android-multitouch-helper-0.19.3.manifest.json
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "android-multitouch-helper",
|
|
3
|
-
"version": "0.19.3",
|
|
4
|
-
"assetName": "agent-device-android-multitouch-helper-0.19.3.apk",
|
|
5
|
-
"sha256": "38e24a9ed16d41ac68b810c664e7bfc5c21d7a59be83d9789ea759e46c81eb7e",
|
|
6
|
-
"packageName": "com.callstack.agentdevice.multitouchhelper",
|
|
7
|
-
"versionCode": 19003,
|
|
8
|
-
"instrumentationRunner": "com.callstack.agentdevice.multitouchhelper/.MultiTouchInstrumentation",
|
|
9
|
-
"statusProtocol": "android-multitouch-helper-v1"
|
|
10
|
-
}
|
|
Binary file
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
a03f6bc81224ce0a16a141ef88b969f988ad7da52e0f4f1dfda34abaa81ac868 agent-device-android-snapshot-helper-0.19.3.apk
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{_ as e}from"./sdk-contracts.js";import{p as t}from"./sdk-android-adb.js";import{s as n}from"./sdk-device.js";import{D as r}from"./android-input-ownership.js";import{n as i}from"./runner-client.js";import{a}from"./tool-provider.js";import{t as o}from"./ttl-memo.js";import{H as s,W as c,Wt as l,xn as u}from"./internal/daemon.js";import{promises as d}from"node:fs";import f from"node:os";import p from"node:path";const m=o({ttlMs:5e3});async function h(e,t={}){if(u(e))return;let r=_(e);if(m.get(r)===!0){if(!t.focusExisting)return;m.delete(r)}if(n(e)){if(e.kind===`simulator`){let{ensureBootedSimulator:n}=await import(`./simulator.js`).then(e=>e.o);await n(e,{deviceHub:t.deviceHub,focusExisting:t.focusExisting,onColdBootStart:t.onIosSimulatorColdBootStart}),g(r);return}if(e.kind===`device`){await v(e.id),g(r);return}}if(e.platform===`android`){let{waitForAndroidBoot:t}=await import(`./android-input-ownership.js`).then(e=>e.m);await t(e.id),g(r)}}function g(e){m.set(e,!0)}function _(e){let t=e.kind===`simulator`?e.simulatorSetPath??``:``;return JSON.stringify([e.platform,e.kind,e.id,e.target??``,t])}async function v(n){let r=p.join(f.tmpdir(),`agent-device-ready-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2)}.json`);try{let i=await a([`devicectl`,`device`,`info`,`details`,`--device`,n,`--json-output`,r,`--timeout`,`15`],{allowFailure:!0,timeoutMs:18e3}),{stdout:o,stderr:s}=i,c=await b(r);if(i.exitCode===0){if(!c.parsed)throw new e(`COMMAND_FAILED`,`iOS device readiness probe failed`,{kind:`probe_inconclusive`,deviceId:n,stdout:o,stderr:s,hint:`CoreDevice returned success but readiness JSON output was missing or invalid. Retry; if it persists restart Xcode and the iOS device.`});let t=c?.tunnelState?.toLowerCase();if(t===`connecting`)throw new e(`COMMAND_FAILED`,`iOS device is not ready for automation`,{kind:`not_ready`,deviceId:n,tunnelState:t,hint:`Device tunnel is still connecting. Keep the device unlocked and connected by cable until it is fully available in Xcode Devices, then retry.`});return}throw new e(`COMMAND_FAILED`,`iOS device is not ready for automation`,t(i,{kind:`not_ready`,deviceId:n,tunnelState:c?.tunnelState,hint:x(o,s)}))}catch(t){if(t instanceof e&&t.code===`COMMAND_FAILED`){if((typeof t.details?.kind==`string`?t.details.kind:``)===`not_ready`)throw t;let r=t.details??{},i=String(r.stdout??``),a=String(r.stderr??``),o=Number(r.timeoutMs??15e3),s=`CoreDevice did not respond within ${o}ms. Keep the device unlocked and trusted, then retry; if it persists restart Xcode and the iOS device.`;throw new e(`COMMAND_FAILED`,`iOS device readiness probe failed`,{deviceId:n,cause:t.message,timeoutMs:o,stdout:i,stderr:a,hint:i||a?x(i,a):s},t)}throw new e(`COMMAND_FAILED`,`iOS device readiness probe failed`,{deviceId:n,hint:`Reconnect the device, keep it unlocked, and retry.`},t instanceof Error?t:void 0)}finally{await d.rm(r,{force:!0}).catch(()=>{})}}function y(e){let t=e?.result;if(!t||typeof t!=`object`)return{};let n=t.connectionProperties?.tunnelState,r=t.device?.connectionProperties?.tunnelState,i=typeof n==`string`?n:typeof r==`string`?r:void 0;return i?{tunnelState:i}:{}}async function b(e){try{let t=await d.readFile(e,`utf8`);return{parsed:!0,tunnelState:y(JSON.parse(t)).tunnelState}}catch{return{parsed:!1}}}function x(e,t){return c(e,t)||(`${e}\n${t}`.toLowerCase().includes(`timed out waiting for all destinations`)?`Xcode destination did not become available in time. Keep device unlocked and retry.`:s)}function S(e){let{req:t,logPath:n,traceLogPath:r}=e;return{verbose:t.flags?.verbose,logPath:n,traceLogPath:r,requestId:t.meta?.requestId,iosXctestrunFile:t.flags?.iosXctestrunFile,iosXctestDerivedDataPath:t.flags?.iosXctestDerivedDataPath,iosXctestEnvDir:t.flags?.iosXctestEnvDir}}function C(e){let{req:t,logPath:n,appBundleId:r,traceLogPath:i}=e;return{...S({req:t,logPath:n,traceLogPath:i}),runnerLeaseContext:l(n,t.flags,r,i,t.meta?.requestId,t.meta).runnerLeaseContext}}function w(e){let{req:t,logPath:r,device:a,traceLogPath:o,enabled:s}=e;if(!(!s||!n(a)||a.kind!==`simulator`))return e=>i(e,S({req:t,logPath:r,traceLogPath:o}))}function T(e){let{req:t,logPath:n,device:i,surface:a,openTarget:o,traceLogPath:s}=e;return w({req:t,logPath:n,device:i,traceLogPath:s,enabled:a===`app`&&!!o&&!r(o??``)})}export{h as a,w as i,C as n,T as r,S as t};
|
package/dist/src/cli-output.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./registry.js";const t=e();function n(e){return t[e.name]?.({input:e.input??{},result:e.result})}export{n as t};
|