agent-device 0.19.2 → 0.19.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android-multitouch-helper/dist/{agent-device-android-multitouch-helper-0.19.2.apk → 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 +1 -0
- package/android-multitouch-helper/dist/{agent-device-android-multitouch-helper-0.19.2.manifest.json → agent-device-android-multitouch-helper-0.19.3.manifest.json} +4 -4
- package/android-snapshot-helper/dist/{agent-device-android-snapshot-helper-0.19.2.apk → 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 +1 -0
- package/android-snapshot-helper/dist/{agent-device-android-snapshot-helper-0.19.2.manifest.json → agent-device-android-snapshot-helper-0.19.3.manifest.json} +6 -6
- package/dist/apple-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedGesture.h +7 -0
- package/dist/apple-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSynthesizedGesture.m +99 -30
- package/dist/apple-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +9 -1
- package/dist/apple-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Interaction.swift +21 -8
- package/dist/apple-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +10 -0
- package/dist/apple-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SequenceExecution.swift +1 -0
- package/dist/src/agent-browser-tool.js +1 -1
- package/dist/src/android-adb.js +1 -1
- package/dist/src/android-input-ownership.js +1 -1
- package/dist/src/android.js +1 -1
- package/dist/src/app-lifecycle.js +1 -1
- package/dist/src/apple-runner-options.js +1 -1
- package/dist/src/apps.js +5 -5
- package/dist/src/audio-probe.js +1 -1
- package/dist/src/cli-help.js +14 -14
- package/dist/src/cli-runner.js +1 -1
- package/dist/src/cli.js +11 -11
- package/dist/src/client.js +2 -2
- package/dist/src/contracts.js +1 -1
- 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/find.js +1 -1
- package/dist/src/generic.js +1 -1
- package/dist/src/helper.js +1 -1
- package/dist/src/index.d.ts +11 -7
- package/dist/src/index.js +1 -1
- package/dist/src/input-actions.js +1 -1
- package/dist/src/input-actions2.js +1 -1
- package/dist/src/install-source2.js +1 -1
- package/dist/src/interaction-snapshot.js +1 -1
- package/dist/src/interaction.js +1 -1
- package/dist/src/interactor.js +2 -2
- package/dist/src/internal/bin.js +1 -1
- package/dist/src/internal/daemon.js +20 -16
- package/dist/src/internal/png-worker.js +1 -1
- package/dist/src/lease.js +1 -1
- package/dist/src/linux.js +1 -1
- package/dist/src/notifications.js +1 -1
- package/dist/src/png-worker-contract.js +1 -1
- package/dist/src/points.js +3 -3
- package/dist/src/providers.js +1 -1
- package/dist/src/react-native.js +1 -1
- package/dist/src/record-trace-recording.js +2 -2
- package/dist/src/record-trace.js +1 -1
- package/dist/src/registry.js +14 -14
- package/dist/src/reporting.js +3 -3
- package/dist/src/runner-client.js +1 -1
- package/dist/src/runner-sequence.js +1 -1
- package/dist/src/runtime-transport.js +1 -1
- package/dist/src/runtime.js +2 -2
- package/dist/src/sdk-android-adb.js +3 -3
- package/dist/src/sdk-app-inventory.js +1 -1
- package/dist/src/sdk-batch-runner.js +2 -2
- package/dist/src/sdk-batch.js +2 -2
- package/dist/src/sdk-contracts.js +2 -2
- package/dist/src/sdk-device.js +1 -0
- package/dist/src/sdk-finders.js +1 -1
- package/dist/src/sdk-io.js +1 -1
- 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/server.js +2 -2
- package/dist/src/session.js +10 -10
- package/dist/src/setting-state.js +1 -1
- package/dist/src/simctl.js +1 -1
- package/dist/src/simulator.js +1 -1
- package/dist/src/snapshot-diagnostics.js +1 -1
- package/dist/src/snapshot.js +1 -1
- package/dist/src/snapshot2.js +2 -2
- package/dist/src/tool-provider.js +2 -2
- package/dist/src/tool-provider2.js +1 -1
- package/dist/src/tv-remote.js +12 -12
- package/dist/src/web.js +1 -1
- package/package.json +11 -3
- package/server.json +2 -2
- package/android-multitouch-helper/dist/agent-device-android-multitouch-helper-0.19.2.apk.sha256 +0 -1
- package/android-snapshot-helper/dist/agent-device-android-snapshot-helper-0.19.2.apk.sha256 +0 -1
- package/dist/src/snapshot-helper.js +0 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{_ as e}from"./sdk-contracts.js";function t(e){return e.map(e=>({args:e.args.join(` `),exitCode:e.exitCode,stderr:e.stderr.slice(0,400)}))}const n=[`camera`,`microphone`,`photos`,`contacts`,`contacts-limited`,`notifications`,`calendar`,`location`,`location-always`,`media-library`,`motion`,`reminders`,`siri`];function r(t){let n=t.trim().toLowerCase();if(n===`grant`)return`grant`;if(n===`deny`)return`deny`;if(n===`reset`)return`reset`;throw new e(`INVALID_ARGS`,`Invalid permission action: ${t}. Use grant|deny|reset.`)}function i(t){let r=t?.trim().toLowerCase();if(r===`camera`||r===`microphone`||r===`photos`||r===`contacts`||r===`contacts-limited`||r===`notifications`||r===`calendar`||r===`location`||r===`location-always`||r===`media-library`||r===`motion`||r===`reminders`||r===`siri`)return r;throw new e(`INVALID_ARGS`,`permission setting requires a target: ${n.join(`|`)}`)}function a(t){let n=t.trim().toLowerCase();if(n===`light`)return`light`;if(n===`dark`)return`dark`;if(n===`toggle`)return`toggle`;throw new e(`INVALID_ARGS`,`Invalid appearance state: ${t}. Use light|dark|toggle.`)}function o(t){let n=t.toLowerCase();if(n===`on`||n===`true`||n===`1`)return!0;if(n===`off`||n===`false`||n===`0`)return!1;throw new e(`INVALID_ARGS`,`Invalid setting state: ${t}`)}export{t as a,i,a as n,r,o as t};
|
package/dist/src/simctl.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{s as e}from"./sdk-device.js";import{x as t}from"./android-input-ownership.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{
|
|
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{S as i,_ as a,g as o,w as s}from"./android-input-ownership.js";import{a as c,i as l}from"./tool-provider.js";import{n as u,t as d}from"./simctl.js";import{t as f}from"./ttl-memo.js";import{X as p,q as m}from"./internal/daemon.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=f({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 l(`open`,[...n,e],{allowFailure:!0,timeoutMs:1e4})).exitCode===0)return}async function E(e,l={}){if(e.kind!==`simulator`)return;if((x(e)?`Booted`:await O(e))===`Booted`){S(e),l.focusExisting&&await T({background:l.deviceHub,deviceHub:l.deviceHub});return}l.onColdBootStart?.(e);let d=i.fromTimeoutMs(m),f,p;try{await s(async({deadline:i})=>{if(i?.isExpired())throw new t(`COMMAND_FAILED`,`iOS simulator boot deadline exceeded`,{timeoutMs:m});let a=Math.max(1e3,i?.remainingMs()??18e4);f=await c(u(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));p=await c(u(e,[`bootstatus`,e.id,`-b`]),{allowFailure:!0,timeoutMs:a}),n(p,`simctl bootstatus failed`);let l=await O(e);if(l!==`Booted`)throw new t(`COMMAND_FAILED`,`Simulator is still booting`,{state:l})},{maxAttempts:3,baseDelayMs:500,maxDelayMs:2e3,jitter:.2,shouldRetry:e=>{let t=a({error:e,stdout:p?.stdout??f?.stdout,stderr:p?.stderr??f?.stderr,context:{platform:`ios`,phase:`boot`}});return t!==`IOS_BOOT_TIMEOUT`&&t!==`CI_RESOURCE_STARVATION_SUSPECTED`}},{deadline:d,phase:`boot`,classifyReason:e=>a({error:e,stdout:p?.stdout??f?.stdout,stderr:p?.stderr??f?.stderr,context:{platform:`ios`,phase:`boot`}})})}catch(n){let r=a({error:n,stdout:p?.stdout??f?.stdout,stderr:p?.stderr??f?.stderr,context:{platform:`ios`,phase:`boot`}});throw new t(`COMMAND_FAILED`,`iOS simulator failed to boot`,{platform:`ios`,deviceId:e.id,timeoutMs:m,elapsedMs:d.elapsedMs(),reason:r,hint:o(r),boot:f,bootstatus:p})}S(e),await T({deviceHub:l.deviceHub})}async function D(e){C(e);let t=await c(u(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 c(typeof e==`string`?d([`list`,`devices`,`-j`]):u(e,[`list`,`devices`,`-j`]),{allowFailure:!0,timeoutMs:p});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,3 @@
|
|
|
1
|
-
import{
|
|
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(`
|
|
2
2
|
`);for(;i!==-1;){let e=r.slice(0,i).trim();r=r.slice(i+1),e&&n.push(e),i=r.indexOf(`
|
|
3
3
|
`)}return{lines:n,buffer:r}}function z(e){return e.meta?.requestProgress===`replay-test`||e.meta?.requestProgress===`command`}function B(e){return!!e&&typeof e==`object`&&e.type===`progress`&&!!e.event}function V(e){return!!e&&typeof e==`object`&&e.type===`response`&&!!e.response}function oe(e){return`${JSON.stringify({type:`progress`,event:e})}\n`}function H(e){return`${JSON.stringify({type:`response`,response:e})}\n`}function U(e){return`${JSON.stringify({type:`response`,response:e})}\n`}function W(e,n={}){return{ok:!0,service:e,version:t(),rpcProtocolVersion:1,...n.upstream===void 0?{}:{upstream:n.upstream}}}function G(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 K(e){if(u(e))return G({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(le).flatMap(e=>{let t=q(e);return t?[t]:[]}):void 0})}function q(e){if(typeof e.ref!=`string`||e.ref.length===0)return;let t=se(e);if(t)return{ref:e.ref,...ce(e),...t}}function se(e){let t=l(e.rect);if(!t)return;let n=l(e.overlayRect);if(!n)return;let r=d(e.center);return r?{rect:t,overlayRect:n,center:r}:void 0}function ce(e){return typeof e.label==`string`&&e.label.length>0?{label:e.label}:{}}function le(e){return u(e)}const J=1500;function ue(e,t){e&&(e.snapshotDiagnostics??={samples:[]}).samples.push({...t,durationMs:Math.max(0,Math.round(t.durationMs))})}function de(e){let t=e?.snapshotDiagnostics?.samples;if(!(!t||t.length===0))return Y(t)}function Y(e){if(e.length===0)return;let t=X(e);return{stats:t,...t.p95Ms>=J?{warning:$(t)}:{}}}function fe(e){let t=e.flatMap(e=>ye(e?.stats));if(t.length===0)return;let n=X(t);return{stats:n,...n.p95Ms>=J?{warning:$(n)}:{}}}function pe(e){if(!u(e))return;let t=he(e.stats);if(!t)return;let n=typeof e.warning==`string`?e.warning:void 0;return{stats:t,...n?{warning:n}:{}}}function X(e){let t=e.map(e=>e.durationMs).sort((e,t)=>e-t);return{count:t.length,p50Ms:Z(t,50),p95Ms:Z(t,95),maxMs:t[t.length-1]??0,slowThresholdMs:J,...me(e),...Q(e)}}function Z(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 me(e){let t=e.map(e=>e.platform).filter(e=>!!e);return new Set(t).size===1?{platform:t[0]}:{}}function Q(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 he(e){if(!u(e))return;let t=ge(e);if(t)return{...t,...ve(e)}}function ge(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 _e(e){let t=Object.entries(e).filter(e=>typeof e[1]==`number`);return t.length>0?Object.fromEntries(t):void 0}function ve(e){let t=typeof e.platform==`string`?e.platform:void 0,n=u(e.backends)?_e(e.backends):void 0;return{...t?{platform:t}:{},...n?{backends:n}:{}}}function ye(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{_ as C,g as D,re as E,h as O,ie as S,ne as T,L as _,Y as a,T as b,W as c,oe as d,H as f,I as g,R as h,de as i,B as l,z as m,pe as n,G as o,U as p,ue as r,K as s,fe as t,V as u,M as v,te as w,w as x,P as y};
|
package/dist/src/snapshot.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./rolldown-runtime.js";import{
|
|
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<5;t++){let n=o.join(e,`src`,`platforms`,`linux`,u);if(a.existsSync(n))return d=n,n;if(t===0){let t=o.join(e,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,2 @@
|
|
|
1
|
-
import{
|
|
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 k.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,...m(`Alert visible`)}}async function Te(e,n){let r=await q(e,f);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 oe(e,i.x,i.y),Y(n,r.alert,i.label);if(n===`dismiss`)return await se(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 g(300)}return null}async function J(e){return L((await o(`snapshot_capture`,async()=>await re(e,{helperWaitForIdleTimeoutMs:0,includeHiddenContentHints:!1}),{backend:`android`,purpose:`alert`})).nodes)}function Ee(e){return{kind:`alertStatus`,platform:`android`,action:`get`,alert:e,...m(e?`Alert visible`:`No alert visible`)}}function Y(e,t,n){return{kind:`alertHandled`,platform:`android`,action:e,handled:!0,alert:t,button:n,...m(`Alert ${e}ed`)}}async function De(e){let{req:t,logPath:n,session:r,device:a}=e,o=Oe(t.positionals?.[0]),s=r?r.surface===`frontmost-app`?{surface:`frontmost-app`}:{bundleId:r.appBundleId,surface:r.surface}:{},l=S(`alert`,a);if(l)return l;if(a.platform===`android`)return Z(e,await Ce(a,o,{timeoutMs:c(t.positionals?.[1])??1e4}));if(i(a))return await X(e,o,async e=>await ee(e,s));let u=ce({req:t,logPath:n,traceLogPath:r?.trace?.outPath});return await X(e,o,async e=>await v(a,{command:`alert`,action:e,appBundleId:r?.appBundleId},u))}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=c(e.req.positionals?.[1])??1e4,r=Date.now();for(;Date.now()-r<n;){try{return Z(e,await t(`get`))}catch{}await g(300)}return y(`COMMAND_FAILED`,`alert wait timed out`)}async function Ae(e,t,n){let r=Date.now(),i;for(;Date.now()-r<f;){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 g(300)}throw je(i)}function Z(e,t){let n=t;return E(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])?y(`INVALID_ARGS`,l):{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:a,device:o,parsed:s}=e,{setting:c,state:l,appBundleId:d,permissionTarget:f,latitude:m,longitude:h}=s,g=S(`settings`,o);if(g)return g;if(i(o)&&!p(c))return y(`INVALID_ARGS`,u(c));let _=d??a?.appBundleId;if(c===`clear-app-state`&&!_)return y(`INVALID_ARGS`,`settings clear-app-state requires an app id when no app is bound to the session`);let v=await b(o,`settings`,c===`clear-app-state`?[c,l,_??``]:c===`permission`?[c,l,f??``,t.positionals?.[3]??``,_??``]:c===`location`&&l===`set`?[c,l,m??``,h??``,_??``]:[c,l,_??``],t.flags?.out,{...C(n,t.flags,_,a?.trace?.outPath)});return E(r,a,t,v??{setting:c,state:l}),{ok:!0,data:v??{setting:c,state:l}}}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 D.mkdtemp(O.join(fe.tmpdir(),`agent-device-android-snapshot-timeout-`)),n=O.join(e,`snapshot-timeout-overlay-refs.png`),r=Re(await b(t.device,`screenshot`,[n],void 0,{...C(t.logPath,{screenshotNoStabilize:!0},t.session?.appBundleId,t.session?.trace?.outPath),surface:t.session?.surface}),n);await D.access(r);let i=await Le(r,t.session);return s({level:`warn`,phase:`android_snapshot_timeout_screenshot_captured`,data:{path:r,overlayRefCount:`overlayRefCount`in i?i.overlayRefCount:void 0,overlayRefsAnnotated:`overlayRefsAnnotated`in i?i.overlayRefsAnnotated:void 0}}),i}catch(t){let n=e(t);return s({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 s({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 T(i,n,t.flags),s=S(e.command,o,{message:e.unsupportedMessage});if(s)return s;let c=ie(t.flags?.snapshotScope,a);return c.ok?qe(e.command,a,o)||await w(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!a(n)||t?.appBundleId?null:y(`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}),...de(`snapshot`),sessions:ae({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=le({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:te(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:i,device:a,snapshotScope:o}=e;return{platform:r(a),captureSnapshot:async(e,r)=>{let s=await x({device:a,session:i,flags:t.flags,outPath:r?.outPath??t.flags?.out,logPath:n,snapshotScope:o}),c=h(i);return{snapshot:s.snapshot,...d(s),...c?{snapshotDiagnostics:c}:{},appName:i?.appBundleId?i.appName??i.appBundleId:void 0,appBundleId:i?.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}):y(`INVALID_ARGS`,`diff currently supports only: diff snapshot`),wait:async({req:e,sessionName:t,logPath:n,sessionStore:r})=>await ue({req:e,sessionName:t,logPath:n,sessionStore:r}),alert:async({req:e,sessionName:t,logPath:n,sessionStore:r})=>{let{session:i,device:a}=await T(r,t,e.flags);return await w(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 T(r,t,e.flags);return await w(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,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,3 +1,3 @@
|
|
|
1
|
-
import{t as e}from"./rolldown-runtime.js";import{
|
|
1
|
+
import{t as e}from"./rolldown-runtime.js";import{_ as t}from"./sdk-contracts.js";import{f as n,h as r,v as i,w as a}from"./sdk-android-adb.js";import{t as o}from"./scoped-provider.js";import{promises as s}from"node:fs";import c from"node:os";import l from"node:path";function u(e,t){return t===`user-installed`?e.filter(e=>!e.bundleId.startsWith(`com.apple.`)):e}function d(e,n){return{openBundle:async(t,n)=>{await e(`open`,f(t,n))},openTarget:async t=>{await e(`open`,[t])},readClipboard:async()=>r(await e(`pbpaste`,[],{allowFailure:!0}),`Failed to read macOS clipboard`).stdout.replace(/\r\n/g,`
|
|
2
2
|
`).replace(/\n$/,``),writeClipboard:async t=>{r(await e(`pbcopy`,[],{allowFailure:!0,stdin:t}),`Failed to write macOS clipboard`)},readDarkMode:async()=>{let n=r(await e(`osascript`,[`-e`,`tell application "System Events" to tell appearance preferences to get dark mode`],{allowFailure:!0}),`Failed to read macOS appearance`),i=n.stdout.trim().toLowerCase();if(i===`true`)return!0;if(i===`false`)return!1;throw new t(`COMMAND_FAILED`,`Unable to determine current macOS appearance from osascript output: ${n.stdout.trim()}`)},setDarkMode:async t=>{r(await e(`osascript`,[`-e`,`tell application "System Events" to tell appearance preferences to set dark mode to ${t?`true`:`false`}`],{allowFailure:!0}),`Failed to set macOS appearance`)},listApps:async t=>await p(e,n,t)}}function f(e,t){let n=[`-b`,e];return t&&n.push(t),n}async function p(e,t,n){let r=[`/Applications`,`/System/Applications`,l.join(c.homedir(),`Applications`)],i=new Set;for(let t of r){if(!(await s.stat(t).catch(()=>null))?.isDirectory())continue;let n=await e(`find`,[t,`-maxdepth`,`4`,`-type`,`d`,`-name`,`*.app`],{allowFailure:!0});if(n.exitCode===0)for(let e of n.stdout.split(`
|
|
3
|
-
`)){let t=e.trim();t&&i.add(t)}}return u((await Promise.all(Array.from(i).map(async e=>{let n=await m(e,t).catch(()=>({})),r=n.bundleId;return r?{bundleId:r,name:n.appName??l.basename(e,`.app`)}:null}))).filter(e=>e!==null).sort((e,t)=>e.name.localeCompare(t.name)),n)}async function m(e,t){for(let n of[l.join(e,`Contents`,`Info.plist`),l.join(e,`Info.plist`)]){let e=await t(n),r=h(e,`CFBundleIdentifier`),i=h(e,`CFBundleDisplayName`),a=h(e,`CFBundleName`);if(r||i||a)return{bundleId:r,appName:i??a}}return{}}function h(e,t){let n=e?.[t];return typeof n==`string`&&n.trim()?n.trim():void 0}var g=e({createLocalAppleToolProvider:()=>y,hasScopedAppleToolProvider:()=>S,readApplePlistJson:()=>T,resolveAppleToolProvider:()=>b,runAppleToolCommand:()=>C,runXcrun:()=>w,withAppleToolProvider:()=>x});const _={runCommand:i,simctl:{run:async(e,t)=>await i(`xcrun`,[`simctl`,...e],t)},devicectl:{run:async(e,t)=>await i(`xcrun`,[`devicectl`,...e],t)},plist:{readJson:async e=>await k(i,e)},macosHost:d(i,async e=>await k(i,e)),whichCommand:a},v=o(_,E);function y(e={}){let t={..._,...e},n=e.plist??{readJson:async e=>await k(t.runCommand,e)};return{...t,simctl:e.simctl??{run:async(e,n)=>await t.runCommand(`xcrun`,[`simctl`,...e],n)},devicectl:e.devicectl??{run:async(e,n)=>await t.runCommand(`xcrun`,[`devicectl`,...e],n)},plist:n,macosHost:e.macosHost??d(t.runCommand,async e=>await n.readJson(e))}}function b(e){return v.resolve(e)}async function x(e,t){return await v.run(e,t)}function S(){return v.hasScope()}async function C(e,t,n){return await b().runCommand(e,t,n)}async function w(e,t){let n=b(),[r,...i]=e;return r===`simctl`?await(n.simctl?.run(i,t)??n.runCommand(`xcrun`,e,t)):r===`devicectl`?await(n.devicectl?.run(i,t)??n.runCommand(`xcrun`,e,t)):await C(`xcrun`,e,t)}async function T(e){return await b().plist?.readJson(e)??null}function E(e){return y(typeof e==`function`?{runCommand:D(e)}:{...e,runCommand:D(e.runCommand),...e.simctl?{simctl:{run:O(e.simctl.run)}}:{},...e.devicectl?{devicectl:{run:O(e.devicectl.run)}}:{},...e.macosHelper?{macosHelper:{run:O(e.macosHelper.run)}}:{}})}function D(e){return async(t,r,i)=>n(await e(t,r,i))}function O(e){return async(t,r)=>n(await e(t,r))}async function k(e,t){try{let n=await e(`plutil`,[`-convert`,`json`,`-o`,`-`,t],{allowFailure:!0});return n.exitCode!==0||!n.stdout.trim()?null:JSON.parse(n.stdout)}catch{return null}}export{
|
|
3
|
+
`)){let t=e.trim();t&&i.add(t)}}return u((await Promise.all(Array.from(i).map(async e=>{let n=await m(e,t).catch(()=>({})),r=n.bundleId;return r?{bundleId:r,name:n.appName??l.basename(e,`.app`)}:null}))).filter(e=>e!==null).sort((e,t)=>e.name.localeCompare(t.name)),n)}async function m(e,t){for(let n of[l.join(e,`Contents`,`Info.plist`),l.join(e,`Info.plist`)]){let e=await t(n),r=h(e,`CFBundleIdentifier`),i=h(e,`CFBundleDisplayName`),a=h(e,`CFBundleName`);if(r||i||a)return{bundleId:r,appName:i??a}}return{}}function h(e,t){let n=e?.[t];return typeof n==`string`&&n.trim()?n.trim():void 0}var g=e({createLocalAppleToolProvider:()=>y,hasScopedAppleToolProvider:()=>S,readApplePlistJson:()=>T,resolveAppleToolProvider:()=>b,runAppleToolCommand:()=>C,runXcrun:()=>w,withAppleToolProvider:()=>x});const _={runCommand:i,simctl:{run:async(e,t)=>await i(`xcrun`,[`simctl`,...e],t)},devicectl:{run:async(e,t)=>await i(`xcrun`,[`devicectl`,...e],t)},plist:{readJson:async e=>await k(i,e)},macosHost:d(i,async e=>await k(i,e)),whichCommand:a},v=o(_,E);function y(e={}){let t={..._,...e},n=e.plist??{readJson:async e=>await k(t.runCommand,e)};return{...t,simctl:e.simctl??{run:async(e,n)=>await t.runCommand(`xcrun`,[`simctl`,...e],n)},devicectl:e.devicectl??{run:async(e,n)=>await t.runCommand(`xcrun`,[`devicectl`,...e],n)},plist:n,macosHost:e.macosHost??d(t.runCommand,async e=>await n.readJson(e))}}function b(e){return v.resolve(e)}async function x(e,t){return await v.run(e,t)}function S(){return v.hasScope()}async function C(e,t,n){return await b().runCommand(e,t,n)}async function w(e,t){let n=b(),[r,...i]=e;return r===`simctl`?await(n.simctl?.run(i,t)??n.runCommand(`xcrun`,e,t)):r===`devicectl`?await(n.devicectl?.run(i,t)??n.runCommand(`xcrun`,e,t)):await C(`xcrun`,e,t)}async function T(e){return await b().plist?.readJson(e)??null}function E(e){return y(typeof e==`function`?{runCommand:D(e)}:{...e,runCommand:D(e.runCommand),...e.simctl?{simctl:{run:O(e.simctl.run)}}:{},...e.devicectl?{devicectl:{run:O(e.devicectl.run)}}:{},...e.macosHelper?{macosHelper:{run:O(e.macosHelper.run)}}:{}})}function D(e){return async(t,r,i)=>n(await e(t,r,i))}function O(e){return async(t,r)=>n(await e(t,r))}async function k(e,t){try{let n=await e(`plutil`,[`-convert`,`json`,`-o`,`-`,t],{allowFailure:!0});return n.exitCode!==0||!n.stdout.trim()?null:JSON.parse(n.stdout)}catch{return null}}export{w as a,C as i,T as n,g as o,b as r,u as s,S as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./rolldown-runtime.js";import{
|
|
1
|
+
import{t as e}from"./rolldown-runtime.js";import{_ as t}from"./sdk-contracts.js";import{j as n,v as r,w as i}from"./sdk-android-adb.js";import{t as a}from"./timeouts.js";import{t as o}from"./scoped-provider.js";var s=e({createLocalLinuxToolProvider:()=>u,resolveLinuxToolProvider:()=>d,runLinuxToolCommand:()=>p,withLinuxToolProvider:()=>f});const c={runCommand:r,whichCommand:i,desktop:m(r,i),clipboard:h(r,i),screenshot:g(r,i)},l=o(c,u);function u(e={}){let t={...c,...e};return{...t,desktop:e.desktop??m(t.runCommand,t.whichCommand),clipboard:e.clipboard??h(t.runCommand,t.whichCommand),screenshot:e.screenshot??g(t.runCommand,t.whichCommand)}}function d(e){return l.resolve(e)}async function f(e,t){return await l.run(e,t)}async function p(e,t,n){return await d().runCommand(e,t,n)}function m(e,t){return{async openTarget(r){if(r.includes(`://`)||r.startsWith(`/`)){await e(`xdg-open`,[r]);return}if(await t(r)){e(r,[],{allowFailure:!0}).catch(e=>{n({level:`warn`,phase:`linux_app_launch`,data:{app:r,error:String(e)}})}),await a(500);return}await e(`xdg-open`,[r],{allowFailure:!0})},async closeApp(n){if(await t(`wmctrl`)){await e(`wmctrl`,[`-c`,n],{allowFailure:!0});return}await e(`pkill`,[`-x`,n],{allowFailure:!0})}}}function h(e,t){return{async readText(){let n=await C(t,v),r=b[n];return(await e(r.cmd,r.args,r.options)).stdout},async writeText(n){let r=await C(t,v),i=x[r](n);await e(i.cmd,i.args,i.options)}}}function g(e,t){return{async capture(n){let r=await C(t,y),i=S[r](n);await e(i.cmd,i.args,i.options)}}}const _=5e3,v={wayland:[{tool:`wl-clipboard`,command:`wl-paste`}],x11:[{tool:`xclip`,command:`xclip`},{tool:`xsel`,command:`xsel`}],waylandError:`wl-paste (wl-clipboard) is required for clipboard access on Wayland. Install via your package manager.`,x11Error:`xclip or xsel is required for clipboard access on X11. Install via your package manager.`},y={wayland:[{tool:`grim`,command:`grim`},{tool:`gnome-screenshot`,command:`gnome-screenshot`}],x11:[{tool:`scrot`,command:`scrot`},{tool:`import`,command:`import`},{tool:`gnome-screenshot`,command:`gnome-screenshot`}],waylandError:`grim or gnome-screenshot is required for screenshots on Wayland. Install via your package manager.`,x11Error:`scrot, import (ImageMagick), or gnome-screenshot is required for screenshots on X11. Install via your package manager.`},b={"wl-clipboard":{cmd:`wl-paste`,args:[`--no-newline`],options:{allowFailure:!0,timeoutMs:_}},xclip:{cmd:`xclip`,args:[`-selection`,`clipboard`,`-o`],options:{allowFailure:!0,timeoutMs:_}},xsel:{cmd:`xsel`,args:[`--clipboard`,`--output`],options:{allowFailure:!0,timeoutMs:_}}},x={"wl-clipboard":e=>({cmd:`wl-copy`,args:[`--`,e],options:{allowFailure:!1,timeoutMs:_}}),xclip:e=>({cmd:`xclip`,args:[`-selection`,`clipboard`],options:{allowFailure:!1,timeoutMs:_,stdin:e}}),xsel:e=>({cmd:`xsel`,args:[`--clipboard`,`--input`],options:{allowFailure:!1,timeoutMs:_,stdin:e}})},S={grim:e=>({cmd:`grim`,args:[e]}),scrot:e=>({cmd:`scrot`,args:[e]}),import:e=>({cmd:`import`,args:[`-window`,`root`,e]}),"gnome-screenshot":e=>({cmd:`gnome-screenshot`,args:[`-f`,e]})};async function C(e,n){let r=w()?`wayland`:`x11`;for(let t of n[r])if(await e(t.command))return t.tool;throw new t(`TOOL_MISSING`,r===`wayland`?n.waylandError:n.x11Error)}function w(){return!!process.env.WAYLAND_DISPLAY||process.env.XDG_SESSION_TYPE===`wayland`}export{p as n,s as r,d as t};
|