agent-device 0.18.1 → 0.18.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/android-multitouch-helper/dist/{agent-device-android-multitouch-helper-0.18.1.apk → agent-device-android-multitouch-helper-0.18.2.apk} +0 -0
  2. package/android-multitouch-helper/dist/agent-device-android-multitouch-helper-0.18.2.apk.sha256 +1 -0
  3. package/android-multitouch-helper/dist/{agent-device-android-multitouch-helper-0.18.1.manifest.json → agent-device-android-multitouch-helper-0.18.2.manifest.json} +4 -4
  4. package/android-snapshot-helper/dist/{agent-device-android-snapshot-helper-0.18.1.apk → agent-device-android-snapshot-helper-0.18.2.apk} +0 -0
  5. package/android-snapshot-helper/dist/agent-device-android-snapshot-helper-0.18.2.apk.sha256 +1 -0
  6. package/android-snapshot-helper/dist/{agent-device-android-snapshot-helper-0.18.1.manifest.json → agent-device-android-snapshot-helper-0.18.2.manifest.json} +6 -6
  7. package/apple-runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift +2 -1
  8. package/dist/src/1986.js +1 -1
  9. package/dist/src/2948.js +16 -16
  10. package/dist/src/3340.js +8 -8
  11. package/dist/src/4428.js +3 -3
  12. package/dist/src/495.js +5 -5
  13. package/dist/src/6849.js +1 -1
  14. package/dist/src/7871.js +1 -1
  15. package/dist/src/8184.js +1 -1
  16. package/dist/src/8414.js +2 -2
  17. package/dist/src/8875.js +4 -1
  18. package/dist/src/9624.js +1 -1
  19. package/dist/src/9722.js +36 -36
  20. package/dist/src/android.js +1 -1
  21. package/dist/src/apps.js +9 -9
  22. package/dist/src/audio-probe.js +1 -1
  23. package/dist/src/batch.d.ts +1 -1
  24. package/dist/src/cli-help.js +9 -7
  25. package/dist/src/cli.js +23 -23
  26. package/dist/src/contracts.d.ts +1 -1
  27. package/dist/src/devices.js +1 -1
  28. package/dist/src/devices~1.js +1 -1
  29. package/dist/src/index.d.ts +42 -15
  30. package/dist/src/input-actions.js +1 -1
  31. package/dist/src/interaction.js +1 -1
  32. package/dist/src/interactor.js +1 -1
  33. package/dist/src/internal/bin.js +1 -1
  34. package/dist/src/linux.js +1 -1
  35. package/dist/src/record-trace-recording.js +3 -3
  36. package/dist/src/remote-config.d.ts +1 -1
  37. package/dist/src/selector-runtime.js +1 -1
  38. package/dist/src/selectors.d.ts +8 -4
  39. package/dist/src/session.js +11 -11
  40. package/dist/src/simulator.js +2 -2
  41. package/dist/src/snapshot.js +2 -2
  42. package/dist/src/web.js +1 -1
  43. package/package.json +1 -1
  44. package/server.json +2 -2
  45. package/android-multitouch-helper/dist/agent-device-android-multitouch-helper-0.18.1.apk.sha256 +0 -1
  46. package/android-snapshot-helper/dist/agent-device-android-snapshot-helper-0.18.1.apk.sha256 +0 -1
  47. package/dist/src/432.js +0 -4
@@ -1,2 +1,2 @@
1
- import{AppError as t}from"./485.js";import{classifyBootFailure as e,retryWithPolicy as o,bootFailureHint as i,Deadline as r}from"./3340.js";import{runXcrun as s,buildSimctlArgs as d,buildSimctlArgsForDevice as a,runAppleToolCommand as u}from"./9722.js";let l=["Simulator"],n=["Device Hub","Simulator"];function c(e,o){if("simulator"!==e.kind)throw new t("UNSUPPORTED_OPERATION",`${o} is only supported on iOS simulators`)}async function m(t={}){let e=t.deviceHub?n:l,o=t.background?["-g","-a"]:["-a"];for(let t of e)if(0===(await u("open",[...o,t],{allowFailure:!0,timeoutMs:1e4})).exitCode)return}async function f(d,u={}){let l,n;if("simulator"!==d.kind)return;if("Booted"===await C(d)){u.focusExisting&&await m({background:u.deviceHub,deviceHub:u.deviceHub});return}u.onColdBootStart?.(d);let c=r.fromTimeoutMs(18e4);try{await o(async({deadline:e})=>{if(e?.isExpired())throw new t("COMMAND_FAILED","iOS simulator boot deadline exceeded",{timeoutMs:18e4});let o=Math.max(1e3,e?.remainingMs()??18e4),i=await s(a(d,["boot",d.id]),{allowFailure:!0,timeoutMs:o});l={stdout:String(i.stdout??""),stderr:String(i.stderr??""),exitCode:i.exitCode};let r=`${l.stdout}
2
- ${l.stderr}`.toLowerCase(),u=r.includes("already booted")||r.includes("current state: booted");if(0!==l.exitCode&&!u)throw new t("COMMAND_FAILED","simctl boot failed",{stdout:l.stdout,stderr:l.stderr,exitCode:l.exitCode});let c=await s(a(d,["bootstatus",d.id,"-b"]),{allowFailure:!0,timeoutMs:o});if(n={stdout:String(c.stdout??""),stderr:String(c.stderr??""),exitCode:c.exitCode},0!==n.exitCode)throw new t("COMMAND_FAILED","simctl bootstatus failed",{stdout:n.stdout,stderr:n.stderr,exitCode:n.exitCode});let m=await C(d);if("Booted"!==m)throw new t("COMMAND_FAILED","Simulator is still booting",{state:m})},{maxAttempts:3,baseDelayMs:500,maxDelayMs:2e3,jitter:.2,shouldRetry:t=>{let o=e({error:t,stdout:n?.stdout??l?.stdout,stderr:n?.stderr??l?.stderr,context:{platform:"ios",phase:"boot"}});return"IOS_BOOT_TIMEOUT"!==o&&"CI_RESOURCE_STARVATION_SUSPECTED"!==o}},{deadline:c,phase:"boot",classifyReason:t=>e({error:t,stdout:n?.stdout??l?.stdout,stderr:n?.stderr??l?.stderr,context:{platform:"ios",phase:"boot"}})})}catch(r){let o=e({error:r,stdout:n?.stdout??l?.stdout,stderr:n?.stderr??l?.stderr,context:{platform:"ios",phase:"boot"}});throw new t("COMMAND_FAILED","iOS simulator failed to boot",{platform:"ios",deviceId:d.id,timeoutMs:18e4,elapsedMs:c.elapsedMs(),reason:o,hint:i(o),boot:l,bootstatus:n})}await m({deviceHub:u.deviceHub})}async function S(t){let e=a(t,["shutdown",t.id]),o=await s(e,{allowFailure:!0,timeoutMs:15e3});return{success:0===o.exitCode,exitCode:o.exitCode,stdout:String(o.stdout??""),stderr:String(o.stderr??"")}}async function C(t){let e="string"==typeof t?t:t.id,o="string"==typeof t?d(["list","devices","-j"]):a(t,["list","devices","-j"]),i=await s(o,{allowFailure:!0,timeoutMs:6e4});if(0!==i.exitCode)return null;try{let t=JSON.parse(String(i.stdout??""));for(let o of Object.values(t.devices??{})){let t=o.find(t=>t.udid===e);if(t)return t.state}return null}catch{return null}}export{f as ensureBootedSimulator,C as getSimulatorState,c as requireSimulatorDevice,S as shutdownSimulator};
1
+ import{AppError as t}from"./485.js";import{classifyBootFailure as e,retryWithPolicy as o,bootFailureHint as i,Deadline as r}from"./3340.js";import{runXcrun as s,buildSimctlArgs as d,buildSimctlArgsForDevice as a,runAppleToolCommand as u}from"./9722.js";let l=["Simulator"],n=["Device Hub","Simulator"],c=new Map;function m(t){return`${t.id}|${t.simulatorSetPath??""}`}function f(t){c.set(m(t),Date.now())}function S(e,o){if("simulator"!==e.kind)throw new t("UNSUPPORTED_OPERATION",`${o} is only supported on iOS simulators`)}async function w(t={}){let e=t.deviceHub?n:l,o=t.background?["-g","-a"]:["-a"];for(let t of e)if(0===(await u("open",[...o,t],{allowFailure:!0,timeoutMs:1e4})).exitCode)return}async function C(d,u={}){let l,n,S,M;if("simulator"!==d.kind)return;if("Booted"===((S=m(d),void 0!==(M=c.get(S))&&(!(Date.now()-M>5e3)||(c.delete(S),0)))?"Booted":await b(d))){f(d),u.focusExisting&&await w({background:u.deviceHub,deviceHub:u.deviceHub});return}u.onColdBootStart?.(d);let _=r.fromTimeoutMs(18e4);try{await o(async({deadline:e})=>{if(e?.isExpired())throw new t("COMMAND_FAILED","iOS simulator boot deadline exceeded",{timeoutMs:18e4});let o=Math.max(1e3,e?.remainingMs()??18e4),i=await s(a(d,["boot",d.id]),{allowFailure:!0,timeoutMs:o});l={stdout:String(i.stdout??""),stderr:String(i.stderr??""),exitCode:i.exitCode};let r=`${l.stdout}
2
+ ${l.stderr}`.toLowerCase(),u=r.includes("already booted")||r.includes("current state: booted");if(0!==l.exitCode&&!u)throw new t("COMMAND_FAILED","simctl boot failed",{stdout:l.stdout,stderr:l.stderr,exitCode:l.exitCode});let c=await s(a(d,["bootstatus",d.id,"-b"]),{allowFailure:!0,timeoutMs:o});if(n={stdout:String(c.stdout??""),stderr:String(c.stderr??""),exitCode:c.exitCode},0!==n.exitCode)throw new t("COMMAND_FAILED","simctl bootstatus failed",{stdout:n.stdout,stderr:n.stderr,exitCode:n.exitCode});let m=await b(d);if("Booted"!==m)throw new t("COMMAND_FAILED","Simulator is still booting",{state:m})},{maxAttempts:3,baseDelayMs:500,maxDelayMs:2e3,jitter:.2,shouldRetry:t=>{let o=e({error:t,stdout:n?.stdout??l?.stdout,stderr:n?.stderr??l?.stderr,context:{platform:"ios",phase:"boot"}});return"IOS_BOOT_TIMEOUT"!==o&&"CI_RESOURCE_STARVATION_SUSPECTED"!==o}},{deadline:_,phase:"boot",classifyReason:t=>e({error:t,stdout:n?.stdout??l?.stdout,stderr:n?.stderr??l?.stderr,context:{platform:"ios",phase:"boot"}})})}catch(r){let o=e({error:r,stdout:n?.stdout??l?.stdout,stderr:n?.stderr??l?.stderr,context:{platform:"ios",phase:"boot"}});throw new t("COMMAND_FAILED","iOS simulator failed to boot",{platform:"ios",deviceId:d.id,timeoutMs:18e4,elapsedMs:_.elapsedMs(),reason:o,hint:i(o),boot:l,bootstatus:n})}f(d),await w({deviceHub:u.deviceHub})}async function M(t){c.delete(m(t));let e=a(t,["shutdown",t.id]),o=await s(e,{allowFailure:!0,timeoutMs:15e3});return{success:0===o.exitCode,exitCode:o.exitCode,stdout:String(o.stdout??""),stderr:String(o.stderr??"")}}async function b(t){let e="string"==typeof t?t:t.id,o="string"==typeof t?d(["list","devices","-j"]):a(t,["list","devices","-j"]),i=await s(o,{allowFailure:!0,timeoutMs:6e4});if(0!==i.exitCode)return null;try{let t=JSON.parse(String(i.stdout??""));for(let o of Object.values(t.devices??{})){let t=o.find(t=>t.udid===e);if(t)return t.state}return null}catch{return null}}export{C as ensureBootedSimulator,b as getSimulatorState,f as markSimulatorBooted,S as requireSimulatorDevice,M as shutdownSimulator};
@@ -1,2 +1,2 @@
1
- import{__webpack_require__ as e}from"./rslib-runtime.js";import{promises as t}from"node:fs";import a from"node:os";import n from"node:path";import{centerOfRect as s}from"./6849.js";import{normalizeError as o,AppError as r}from"./485.js";import{withDiagnosticTimer as i,emitDiagnostic as l}from"./432.js";import{pressAndroid as d,backAndroid as p}from"./input-actions.js";import{runAppleRunnerCommand as u,createDaemonRuntimeSessionStore as c,captureSnapshot as f,dispatchCommand as m,requireCommandSupported as h,runMacOsAlertAction as w,errorResponse as g,annotateScreenshotWithRefs as y,resolveSnapshotScope as _,snapshotAndroid as v,context_contextFromFlags as S}from"./9722.js";import{SETTINGS_INVALID_ARGS_MESSAGE as b,parseTimeout as I,getUnsupportedMacOsSettingMessage as A,successText as C,isMacOsSettingSupported as R,snapshotCaptureAnnotationsFrom as N}from"./2948.js";import{sleep as M}from"./5560.js";import{buildAppleRunnerRequestOptions as k}from"./8414.js";import{buildSnapshotSession as D,dispatchWaitViaRuntime as K,createDaemonRuntimePolicy as x,recordIfSession as P,resolveSessionDevice as E,withSessionlessRunnerCleanup as U}from"./selector-runtime.js";import{createAgentDevice as L}from"./7871.js";import{summarizeSnapshotDiagnostics as O}from"./5913.js";var B={};e.r(B),e.d(B,{handleSnapshotCommands:()=>eg});let H=new Set(["com.android.permissioncontroller","com.google.android.permissioncontroller","com.google.android.packageinstaller","com.android.packageinstaller"]),$=new Set(["android","com.android.systemui"]),q=/^android:id\/(?:alertTitle|message|button[123]|parentPanel|buttonPanel|contentPanel)$/i,F=/^android:id\/button[123]$/i,j=/(?:^|:)id\/permission_/i,T=/\b(?:is(?:n't| not) responding|keeps stopping|has stopped|close app|app info)\b/i,z=/^(?:ok|allow|allow all|while using the app|only this time|yes|continue|save|confirm|turn on|open settings)$/i,G=/^(?:cancel|deny|don.t allow|don’t allow|not now|no|dismiss|close|close app|later|skip)$/i;function V(e,t){let a=t[0];if(!a)return;let n=W(e,a.index);for(let a of t.slice(1)){let t=new Set(W(e,a.index));for(let e=n.length-1;e>=0;e-=1)t.has(n[e])||n.splice(e,1)}return n[n.length-1]}function W(e,t){let a=new Map(e.map(e=>[e.index,e])),n=[],s=a.get(t);for(;s;)n.push(s.index),s=void 0===s.parentIndex?void 0:a.get(s.parentIndex);return n.reverse()}function J(e,t){let a=new Map;for(let t of e){if(void 0===t.parentIndex)continue;let e=a.get(t.parentIndex)??[];e.push(t),a.set(t.parentIndex,e)}let n=new Set([t]),s=[t];for(let e of s)for(let t of a.get(e)??[])n.has(t.index)||(n.add(t.index),s.push(t.index));return e.filter(e=>n.has(e.index))}function Q(e){let t=e.type??"",a=e.identifier??"";return!!(e.hittable||/\bbutton\b/i.test(t)||F.test(a)||/(?:^|:)id\/permission_(?:allow|deny)/i.test(a))}function X(e){if(!e)return"";let t=[e.label,e.value].filter(e=>"string"==typeof e&&e.trim().length>0);return t[0]?.trim()??""}async function Y(e,t,a={}){if("wait"===t)return await Z(e,a.timeoutMs??1e4);if("get"===t){var n;let t=await ea(e);return{kind:"alertStatus",platform:"android",action:"get",alert:n=t?.alert??null,...n?C("Alert visible"):C("No alert visible")}}return await ee(e,t)}async function Z(e,t){let a=Date.now(),n=await et(e,t);if(!n)throw new r("COMMAND_FAILED","alert wait timed out");return{kind:"alertWait",platform:"android",action:"wait",alert:n.alert,waitedMs:Date.now()-a,...C("Alert visible")}}async function ee(e,t){var a;let n,s,o=await et(e,2e3);if(!o)throw new r("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=(a=o.buttons,n="accept"===t?"accept":"dismiss",(s=a.find(e=>e.role===n))||("dismiss"===t?a.find(e=>"neutral"===e.role)??null:1===a.length?a[0]??null:null));if(i)return await d(e,i.x,i.y),en(t,o.alert,i.label);if("dismiss"===t)return await p(e),en(t,o.alert,"Back");throw new r("COMMAND_FAILED","alert accept found an alert but no accept button",{alert:o.alert,hint:"Inspect alert get --json for visible buttons, then use press by visible label/ref if needed."})}async function et(e,t){let a=Date.now();for(;Date.now()-a<t;){let t=await ea(e);if(t)return t;await M(300)}return null}async function ea(e){return function(e){var t,a,n,o;let r,i=function(e){let t=e.filter(e=>{var t;let a;return a=(t=e).bundleId??"",H.has(a)||j.test(t.identifier??"")});if(t.length)return{nodes:t,source:"permission"};let a=function(e){let t=e.filter(e=>{var t;let a;return a=(t=e).bundleId??"",$.has(a)&&T.test(X(t))});if(0===t.length)return[];let a=V(e,t);return void 0===a?t:J(e,a).filter(e=>e.bundleId&&$.has(e.bundleId))}(e);return a.length?{nodes:a,source:"system-dialog"}:{nodes:function(e){var t;let a,n,s=e.filter(e=>{var t;return t=e.type??"",/(?:^|[.$])[^.]*Dialog$/i.test(t)}),o=e.filter(e=>q.test(e.identifier??"")),r=s.length?[...s,...o]:(a=(t=o).some(e=>F.test(e.identifier??"")),n=t.some(e=>!F.test(e.identifier??"")),a&&n?t:[]);if(0===r.length)return[];let i=V(e,r);return void 0===i?r:J(e,i)}(e),source:"native-dialog"}}(e),l=i.nodes;if(0===l.length)return null;let d=function(e){let t=new Set,a=[];for(let n of e){let e=X(n);if(!e||!n.rect||!Q(n))continue;let o=e.trim().toLowerCase();if(!o||t.has(o))continue;t.add(o);let r=s(n.rect);a.push({label:e,x:r.x,y:r.y,role:function(e,t){var a;let n=(a=e.identifier??"",/(?:^|:)id\/button1$/i.test(a)?"accept":/(?:^|:)id\/button2$/i.test(a)?"dismiss":/(?:^|:)id\/button3$/i.test(a)?"neutral":/(?:^|:)id\/permission_allow/i.test(a)?"accept":/(?:^|:)id\/permission_deny/i.test(a)?"dismiss":null);return n||(z.test(t.trim())?"accept":G.test(t.trim())?"dismiss":"neutral")}(n,e)})}return a}(l),p=l.filter(e=>X(e)&&!Q(e)),u=X((t=p).find(e=>/(?:^|:)id\/(?:alertTitle|permission_message)$/i.test(e.identifier??"")))||X(t[0]),c=(a=p,n=u,(r=a.map(e=>X(e)).filter(e=>e&&e!==n)).length?[...new Set(r)].join("\n"):void 0),f=(o=l,o.find(e=>e.bundleId)?.bundleId);return{alert:{...u?{title:u}:{},...c?{message:c}:{},buttons:d.map(e=>e.label),platform:"android",source:i.source,...f?{packageName:f}:{}},buttons:d}}((await i("snapshot_capture",async()=>await v(e,{helperWaitForIdleTimeoutMs:0,includeHiddenContentHints:!1}),{backend:"android",purpose:"alert"})).nodes)}function en(e,t,a){return{kind:"alertHandled",platform:"android",action:e,handled:!0,alert:t,button:a,...C(`Alert ${e}ed`)}}async function es(e){var t;let{req:a,logPath:n,session:s,device:o}=e,r="accept"===(t=a.positionals?.[0])||"dismiss"===t||"wait"===t?t:"get",i=s?"frontmost-app"===s.surface?{surface:"frontmost-app"}:{bundleId:s.appBundleId,surface:s.surface}:{},l=h("alert",o);if(l)return l;if("android"===o.platform){let t=I(a.positionals?.[1])??1e4;return el(e,await Y(o,r,{timeoutMs:t}))}if("macos"===o.platform){let t=async e=>await w(e,i);return await eo(e,r,t)}let d=k({req:a,logPath:n,traceLogPath:s?.trace?.outPath}),p=async e=>await u(o,{command:"alert",action:e,appBundleId:s?.appBundleId},d);return await eo(e,r,p)}async function eo(e,t,a){if("wait"===t)return await er(e,a);let n="accept"===t||"dismiss"===t?t:"get";return"accept"===n||"dismiss"===n?await ei(e,n,a):el(e,await a("get"))}async function er(e,t){let a=I(e.req.positionals?.[1])??1e4,n=Date.now();for(;Date.now()-n<a;){try{return el(e,await t("get"))}catch{}await M(300)}return g("COMMAND_FAILED","alert wait timed out")}async function ei(e,t,a){var n,s;let o,i,l=Date.now();for(;Date.now()-l<2e3;){try{return el(e,await a(t))}catch(t){i=t;let e=String(t?.message??"").toLowerCase();if(!e.includes("alert not found")&&!e.includes("no alert"))break}await M(300)}throw(n=i)instanceof r&&(s=n,(o=String(s?.message??"").toLowerCase()).includes("alert not found")||o.includes("no alert"))?new r(n.code,n.message,{...n.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."}):n}function el(e,t){return P(e.sessionStore,e.session,e.req,t),{ok:!0,data:t}}async function ed(e){let{req:t,logPath:a,sessionStore:n,session:s,device:o,parsed:r}=e,{setting:i,state:l,appBundleId:d,permissionTarget:p,latitude:u,longitude:c}=r,f=h("settings",o);if(f)return f;if("macos"===o.platform&&!R(i))return g("INVALID_ARGS",A(i));let w=d??s?.appBundleId;if("clear-app-state"===i&&!w)return g("INVALID_ARGS","settings clear-app-state requires an app id when no app is bound to the session");let y="clear-app-state"===i?[i,l,w??""]:"permission"===i?[i,l,p??"",t.positionals?.[3]??"",w??""]:"location"===i&&"set"===l?[i,l,u??"",c??"",w??""]:[i,l,w??""],_=await m(o,"settings",y,t.flags?.out,{...S(a,t.flags,w,s?.trace?.outPath)});return P(n,s,t,_??{setting:i,state:l}),{ok:!0,data:_??{setting:i,state:l}}}async function ep(e){var t,a;let n;if("snapshot"!==e.command||"android"!==e.device.platform)return;let s=o(e.error);if("COMMAND_FAILED"===(t=s).code&&(a=t,n=`${a.message}
2
- ${a.hint??""}`,/Android UI hierarchy dump timed out/i.test(n)||/Stock UIAutomator fallback was skipped/i.test(n)||/Android accessibility snapshots can be blocked/i.test(n)||function(e){if(!e||"object"!=typeof e)return!1;let t=String(e.errorType??""),a=String(e.message??"");return/TimeoutException/i.test(t)||/timed out/i.test(a)}(t.details?.helper)||function(e){var t;if(!e)return!1;let a=e?.timeoutMs,n=e?.cmd,s=Array.isArray(t=e?.args)?t.map(String):"string"==typeof t?t.split(/\s+/):[];return"number"==typeof a&&"adb"===n&&s.includes("uiautomator")&&s.includes("dump")}(t.details)))return{ok:!1,error:{...s,details:{...s.details??{},androidSnapshotTimeoutScreenshot:await eu(e)}}}}async function eu(e){try{var s,r,i;let o=await t.mkdtemp(n.join(a.tmpdir(),"agent-device-android-snapshot-timeout-")),d=n.join(o,"snapshot-timeout-overlay-refs.png"),p=(s=await m(e.device,"screenshot",[d],void 0,{...S(e.logPath,{screenshotNoStabilize:!0},e.session?.appBundleId,e.session?.trace?.outPath),surface:e.session?.surface}),r=d,(i=s,"object"==typeof i&&null!==i&&"path"in i&&"string"==typeof i.path)?s.path:r);await t.access(p);let u=await ec(p,e.session);return l({level:"warn",phase:"android_snapshot_timeout_screenshot_captured",data:{path:p,overlayRefCount:"overlayRefCount"in u?u.overlayRefCount:void 0,overlayRefsAnnotated:"overlayRefsAnnotated"in u?u.overlayRefsAnnotated:void 0}}),u}catch(t){let e=o(t);return l({level:"warn",phase:"android_snapshot_timeout_screenshot_failed",data:{error:e.message}}),{captureFailed:!0,error:e.message}}}async function ec(e,t){if(!t?.snapshot)return{path:e,overlayRefsRequested:!0,overlayRefsAnnotated:!1,overlayRefSource:"unavailable",overlayRefCount:0};try{let a=await y({screenshotPath:e,snapshot:t.snapshot});return{path:e,overlayRefsRequested:!0,overlayRefsAnnotated:a.length>0,overlayRefCount:a.length,overlayRefSource:"session-snapshot",overlayRefs:a}}catch(a){let t=o(a);return l({level:"warn",phase:"android_snapshot_timeout_screenshot_overlay_failed",data:{path:e,error:t.message}}),{path:e,overlayRefsRequested:!0,overlayRefsAnnotated:!1,overlayRefSource:"session-snapshot",overlayRefCount:0,overlayAnnotationError:t.message}}}async function ef(e){return await eh({...e,command:"snapshot",unsupportedMessage:"snapshot is not supported on this device",execute:async({runtime:e,sessionName:t,req:a,snapshotScope:n})=>{let s=await e.capture.snapshot({session:t,interactiveOnly:a.flags?.snapshotInteractiveOnly,depth:a.flags?.snapshotDepth,scope:n,raw:a.flags?.snapshotRaw,forceFull:a.flags?.snapshotForceFull});return{data:s,record:{kind:"snapshot",nodes:s.nodes.length,truncated:s.truncated}}}})}async function em(e){return await eh({...e,command:"diff",unsupportedMessage:"diff is not supported on this device",execute:async({runtime:e,sessionName:t,req:a,snapshotScope:n})=>{let s=await e.capture.diffSnapshot({session:t,interactiveOnly:a.flags?.snapshotInteractiveOnly,depth:a.flags?.snapshotDepth,scope:n,raw:a.flags?.snapshotRaw});return{data:s,record:{kind:"diff",mode:"snapshot",baselineInitialized:s.baselineInitialized,summary:s.summary}}}})}async function eh(e){var t,a;let{req:n,sessionName:s,logPath:o,sessionStore:i}=e,{session:l,device:d}=await E(i,s,n.flags),p=h(e.command,d,{message:e.unsupportedMessage});if(p)return p;let u=_(n.flags?.snapshotScope,l);if(!u.ok)return u;let m=(t=e.command,a=l,"ios"!==d.platform||a?.appBundleId?null:g("SESSION_NOT_FOUND",`iOS ${t} requires an active app session on the target device. Run open first (for example: open --session ${a?.name??"sim"} --platform ios --device "<name>" <app>).`));return m||await U(l,d,async()=>{var t,a;let p,m,h=function(e){let{req:t,sessionName:a,logPath:n,sessionStore:s,session:o,device:i,snapshotScope:l}=e;return L({backend:function(e){let{req:t,logPath:a,session:n,device:s,snapshotScope:o}=e;return{platform:s.platform,captureSnapshot:async(e,r)=>{let i=await f({device:s,session:n,flags:t.flags,outPath:r?.outPath??t.flags?.out,logPath:a,snapshotScope:o}),l=O(n);return{snapshot:i.snapshot,...N(i),...l?{snapshotDiagnostics:l}:{},appName:n?.appBundleId?n.appName??n.appBundleId:void 0,appBundleId:n?.appBundleId}}}}({req:t,logPath:n,session:o,device:i,snapshotScope:l}),...x("snapshot"),sessions:c({sessionName:a,getSession:()=>s.get(a),recordOptions:{includeSnapshot:!0},setRecord:e=>{var n;let o=function(e){if(!e.snapshot)throw new r("UNKNOWN","snapshot runtime did not produce session state");return e}(e),l=s.get(a);s.set(a,function(e){var t,a;let{current:n,sessionName:s,device:o,record:r,refScopedSnapshot:i}=e,l=(t=n,a=r,i&&a.snapshot?.nodes.length===0&&t?.snapshot!==void 0),d=l?n.snapshot:r.snapshot,p=D({session:n,sessionName:s,device:o,snapshot:d,appBundleId:r.appBundleId});return p.snapshotScopeSource=function(e){let{current:t,keepCurrentSnapshot:a,refScopedSnapshot:n}=e;if(n)return a?t?.snapshotScopeSource:t?.snapshotScopeSource??t?.snapshot}({current:n,keepCurrentSnapshot:l,refScopedSnapshot:i}),r.appName&&(p.appName=r.appName),p}({current:l,sessionName:a,device:i,record:o,refScopedSnapshot:(n=t,n.flags?.snapshotScope?.trim().startsWith("@")===!0)}))}})})}({req:n,sessionName:s,logPath:o,sessionStore:i,session:l,device:d,snapshotScope:u.scope});try{m=await e.execute({runtime:h,sessionName:s,req:n,snapshotScope:u.scope})}catch(a){let t=await ep({error:a,command:e.command,logPath:o,session:l,device:d});if(!t)throw a;return t}return(p=(t={req:n,sessionName:s,sessionStore:i,result:m.record}).sessionStore.get(t.sessionName))&&t.sessionStore.recordAction(p,{command:t.req.command,positionals:t.req.positionals??[],flags:t.req.flags??{},result:"snapshot"===(a=t.result).kind?{nodes:a.nodes,truncated:a.truncated}:{mode:a.mode,baselineInitialized:a.baselineInitialized,summary:a.summary}}),{ok:!0,data:m.data}})}let ew={snapshot:async({req:e,sessionName:t,logPath:a,sessionStore:n})=>await ef({req:e,sessionName:t,logPath:a,sessionStore:n}),diff:async({req:e,sessionName:t,logPath:a,sessionStore:n})=>e.positionals?.[0]!=="snapshot"?g("INVALID_ARGS","diff currently supports only: diff snapshot"):await em({req:e,sessionName:t,logPath:a,sessionStore:n}),wait:async({req:e,sessionName:t,logPath:a,sessionStore:n})=>await K({req:e,sessionName:t,logPath:a,sessionStore:n}),alert:async({req:e,sessionName:t,logPath:a,sessionStore:n})=>{let{session:s,device:o}=await E(n,t,e.flags);return await U(s,o,async()=>await es({req:e,logPath:a,sessionStore:n,session:s,device:o}))},settings:async({req:e,sessionName:t,logPath:a,sessionStore:n})=>{let s,o,r,i=(s=e.positionals?.[0]?.toLowerCase(),o=e.positionals?.[1]?.toLowerCase(),r=e.positionals?.[2]?.toLowerCase(),"clear-app-state"===s?{ok:!0,parsed:{setting:s,state:"clear",appBundleId:"clear"===o?e.positionals?.[2]:e.positionals?.[1]}}:s&&o&&("permission"!==s||r)&&("location"!==s||"set"!==o||e.positionals?.[2]&&e.positionals?.[3])?{ok:!0,parsed:{setting:s,state:o,permissionTarget:r,latitude:e.positionals?.[2],longitude:e.positionals?.[3]}}:g("INVALID_ARGS",b));if(!i.ok)return i;let{session:l,device:d}=await E(n,t,e.flags);return await U(l,d,async()=>await ed({req:e,logPath:a,sessionStore:n,session:l,device:d,parsed:i.parsed}))}};async function eg(e){let t=ew[e.req.command];return t?await t(e):null}export{B as snapshot_namespaceObject};
1
+ import{__webpack_require__ as e}from"./rslib-runtime.js";import{promises as t}from"node:fs";import a from"node:os";import n from"node:path";import{isMacOs as s,centerOfRect as o,isIosFamily as r,publicPlatformString as i}from"./6849.js";import{normalizeError as l,AppError as d}from"./485.js";import{withDiagnosticTimer as p,emitDiagnostic as u}from"./8875.js";import{pressAndroid as c,backAndroid as f}from"./input-actions.js";import{runAppleRunnerCommand as m,createDaemonRuntimeSessionStore as h,captureSnapshot as w,dispatchCommand as g,requireCommandSupported as y,runMacOsAlertAction as _,errorResponse as v,annotateScreenshotWithRefs as S,resolveSnapshotScope as b,snapshotAndroid as I,context_contextFromFlags as A}from"./9722.js";import{SETTINGS_INVALID_ARGS_MESSAGE as C,parseTimeout as R,getUnsupportedMacOsSettingMessage as N,successText as M,isMacOsSettingSupported as k,snapshotCaptureAnnotationsFrom as D}from"./2948.js";import{sleep as K}from"./5560.js";import{buildAppleRunnerRequestOptions as x}from"./8414.js";import{buildSnapshotSession as P,dispatchWaitViaRuntime as E,createDaemonRuntimePolicy as U,recordIfSession as L,resolveSessionDevice as O,withSessionlessRunnerCleanup as B}from"./selector-runtime.js";import{createAgentDevice as H}from"./7871.js";import{summarizeSnapshotDiagnostics as $}from"./5913.js";var q={};e.r(q),e.d(q,{handleSnapshotCommands:()=>ev});let F=new Set(["com.android.permissioncontroller","com.google.android.permissioncontroller","com.google.android.packageinstaller","com.android.packageinstaller"]),j=new Set(["android","com.android.systemui"]),T=/^android:id\/(?:alertTitle|message|button[123]|parentPanel|buttonPanel|contentPanel)$/i,z=/^android:id\/button[123]$/i,G=/(?:^|:)id\/permission_/i,V=/\b(?:is(?:n't| not) responding|keeps stopping|has stopped|close app|app info)\b/i,W=/^(?:ok|allow|allow all|while using the app|only this time|yes|continue|save|confirm|turn on|open settings)$/i,J=/^(?:cancel|deny|don.t allow|don’t allow|not now|no|dismiss|close|close app|later|skip)$/i;function Q(e,t){let a=t[0];if(!a)return;let n=X(e,a.index);for(let a of t.slice(1)){let t=new Set(X(e,a.index));for(let e=n.length-1;e>=0;e-=1)t.has(n[e])||n.splice(e,1)}return n[n.length-1]}function X(e,t){let a=new Map(e.map(e=>[e.index,e])),n=[],s=a.get(t);for(;s;)n.push(s.index),s=void 0===s.parentIndex?void 0:a.get(s.parentIndex);return n.reverse()}function Y(e,t){let a=new Map;for(let t of e){if(void 0===t.parentIndex)continue;let e=a.get(t.parentIndex)??[];e.push(t),a.set(t.parentIndex,e)}let n=new Set([t]),s=[t];for(let e of s)for(let t of a.get(e)??[])n.has(t.index)||(n.add(t.index),s.push(t.index));return e.filter(e=>n.has(e.index))}function Z(e){let t=e.type??"",a=e.identifier??"";return!!(e.hittable||/\bbutton\b/i.test(t)||z.test(a)||/(?:^|:)id\/permission_(?:allow|deny)/i.test(a))}function ee(e){if(!e)return"";let t=[e.label,e.value].filter(e=>"string"==typeof e&&e.trim().length>0);return t[0]?.trim()??""}async function et(e,t,a={}){if("wait"===t)return await ea(e,a.timeoutMs??1e4);if("get"===t){var n;let t=await eo(e);return{kind:"alertStatus",platform:"android",action:"get",alert:n=t?.alert??null,...n?M("Alert visible"):M("No alert visible")}}return await en(e,t)}async function ea(e,t){let a=Date.now(),n=await es(e,t);if(!n)throw new d("COMMAND_FAILED","alert wait timed out");return{kind:"alertWait",platform:"android",action:"wait",alert:n.alert,waitedMs:Date.now()-a,...M("Alert visible")}}async function en(e,t){var a;let n,s,o=await es(e,2e3);if(!o)throw new d("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 r=(a=o.buttons,n="accept"===t?"accept":"dismiss",(s=a.find(e=>e.role===n))||("dismiss"===t?a.find(e=>"neutral"===e.role)??null:1===a.length?a[0]??null:null));if(r)return await c(e,r.x,r.y),er(t,o.alert,r.label);if("dismiss"===t)return await f(e),er(t,o.alert,"Back");throw new d("COMMAND_FAILED","alert accept found an alert but no accept button",{alert:o.alert,hint:"Inspect alert get --json for visible buttons, then use press by visible label/ref if needed."})}async function es(e,t){let a=Date.now();for(;Date.now()-a<t;){let t=await eo(e);if(t)return t;await K(300)}return null}async function eo(e){return function(e){var t,a,n,s;let r,i=function(e){let t=e.filter(e=>{var t;let a;return a=(t=e).bundleId??"",F.has(a)||G.test(t.identifier??"")});if(t.length)return{nodes:t,source:"permission"};let a=function(e){let t=e.filter(e=>{var t;let a;return a=(t=e).bundleId??"",j.has(a)&&V.test(ee(t))});if(0===t.length)return[];let a=Q(e,t);return void 0===a?t:Y(e,a).filter(e=>e.bundleId&&j.has(e.bundleId))}(e);return a.length?{nodes:a,source:"system-dialog"}:{nodes:function(e){var t;let a,n,s=e.filter(e=>{var t;return t=e.type??"",/(?:^|[.$])[^.]*Dialog$/i.test(t)}),o=e.filter(e=>T.test(e.identifier??"")),r=s.length?[...s,...o]:(a=(t=o).some(e=>z.test(e.identifier??"")),n=t.some(e=>!z.test(e.identifier??"")),a&&n?t:[]);if(0===r.length)return[];let i=Q(e,r);return void 0===i?r:Y(e,i)}(e),source:"native-dialog"}}(e),l=i.nodes;if(0===l.length)return null;let d=function(e){let t=new Set,a=[];for(let n of e){let e=ee(n);if(!e||!n.rect||!Z(n))continue;let s=e.trim().toLowerCase();if(!s||t.has(s))continue;t.add(s);let r=o(n.rect);a.push({label:e,x:r.x,y:r.y,role:function(e,t){var a;let n=(a=e.identifier??"",/(?:^|:)id\/button1$/i.test(a)?"accept":/(?:^|:)id\/button2$/i.test(a)?"dismiss":/(?:^|:)id\/button3$/i.test(a)?"neutral":/(?:^|:)id\/permission_allow/i.test(a)?"accept":/(?:^|:)id\/permission_deny/i.test(a)?"dismiss":null);return n||(W.test(t.trim())?"accept":J.test(t.trim())?"dismiss":"neutral")}(n,e)})}return a}(l),p=l.filter(e=>ee(e)&&!Z(e)),u=ee((t=p).find(e=>/(?:^|:)id\/(?:alertTitle|permission_message)$/i.test(e.identifier??"")))||ee(t[0]),c=(a=p,n=u,(r=a.map(e=>ee(e)).filter(e=>e&&e!==n)).length?[...new Set(r)].join("\n"):void 0),f=(s=l,s.find(e=>e.bundleId)?.bundleId);return{alert:{...u?{title:u}:{},...c?{message:c}:{},buttons:d.map(e=>e.label),platform:"android",source:i.source,...f?{packageName:f}:{}},buttons:d}}((await p("snapshot_capture",async()=>await I(e,{helperWaitForIdleTimeoutMs:0,includeHiddenContentHints:!1}),{backend:"android",purpose:"alert"})).nodes)}function er(e,t,a){return{kind:"alertHandled",platform:"android",action:e,handled:!0,alert:t,button:a,...M(`Alert ${e}ed`)}}async function ei(e){var t;let{req:a,logPath:n,session:o,device:r}=e,i="accept"===(t=a.positionals?.[0])||"dismiss"===t||"wait"===t?t:"get",l=o?"frontmost-app"===o.surface?{surface:"frontmost-app"}:{bundleId:o.appBundleId,surface:o.surface}:{},d=y("alert",r);if(d)return d;if("android"===r.platform){let t=R(a.positionals?.[1])??1e4;return eu(e,await et(r,i,{timeoutMs:t}))}if(s(r)){let t=async e=>await _(e,l);return await el(e,i,t)}let p=x({req:a,logPath:n,traceLogPath:o?.trace?.outPath}),u=async e=>await m(r,{command:"alert",action:e,appBundleId:o?.appBundleId},p);return await el(e,i,u)}async function el(e,t,a){if("wait"===t)return await ed(e,a);let n="accept"===t||"dismiss"===t?t:"get";return"accept"===n||"dismiss"===n?await ep(e,n,a):eu(e,await a("get"))}async function ed(e,t){let a=R(e.req.positionals?.[1])??1e4,n=Date.now();for(;Date.now()-n<a;){try{return eu(e,await t("get"))}catch{}await K(300)}return v("COMMAND_FAILED","alert wait timed out")}async function ep(e,t,a){var n,s;let o,r,i=Date.now();for(;Date.now()-i<2e3;){try{return eu(e,await a(t))}catch(t){r=t;let e=String(t?.message??"").toLowerCase();if(!e.includes("alert not found")&&!e.includes("no alert"))break}await K(300)}throw(n=r)instanceof d&&(s=n,(o=String(s?.message??"").toLowerCase()).includes("alert not found")||o.includes("no alert"))?new d(n.code,n.message,{...n.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."}):n}function eu(e,t){return L(e.sessionStore,e.session,e.req,t),{ok:!0,data:t}}async function ec(e){let{req:t,logPath:a,sessionStore:n,session:o,device:r,parsed:i}=e,{setting:l,state:d,appBundleId:p,permissionTarget:u,latitude:c,longitude:f}=i,m=y("settings",r);if(m)return m;if(s(r)&&!k(l))return v("INVALID_ARGS",N(l));let h=p??o?.appBundleId;if("clear-app-state"===l&&!h)return v("INVALID_ARGS","settings clear-app-state requires an app id when no app is bound to the session");let w="clear-app-state"===l?[l,d,h??""]:"permission"===l?[l,d,u??"",t.positionals?.[3]??"",h??""]:"location"===l&&"set"===d?[l,d,c??"",f??"",h??""]:[l,d,h??""],_=await g(r,"settings",w,t.flags?.out,{...A(a,t.flags,h,o?.trace?.outPath)});return L(n,o,t,_??{setting:l,state:d}),{ok:!0,data:_??{setting:l,state:d}}}async function ef(e){var t,a;let n;if("snapshot"!==e.command||"android"!==e.device.platform)return;let s=l(e.error);if("COMMAND_FAILED"===(t=s).code&&(a=t,n=`${a.message}
2
+ ${a.hint??""}`,/Android UI hierarchy dump timed out/i.test(n)||/Stock UIAutomator fallback was skipped/i.test(n)||/Android accessibility snapshots can be blocked/i.test(n)||function(e){if(!e||"object"!=typeof e)return!1;let t=String(e.errorType??""),a=String(e.message??"");return/TimeoutException/i.test(t)||/timed out/i.test(a)}(t.details?.helper)||function(e){var t;if(!e)return!1;let a=e?.timeoutMs,n=e?.cmd,s=Array.isArray(t=e?.args)?t.map(String):"string"==typeof t?t.split(/\s+/):[];return"number"==typeof a&&"adb"===n&&s.includes("uiautomator")&&s.includes("dump")}(t.details)))return{ok:!1,error:{...s,details:{...s.details??{},androidSnapshotTimeoutScreenshot:await em(e)}}}}async function em(e){try{var s,o,r;let i=await t.mkdtemp(n.join(a.tmpdir(),"agent-device-android-snapshot-timeout-")),l=n.join(i,"snapshot-timeout-overlay-refs.png"),d=(s=await g(e.device,"screenshot",[l],void 0,{...A(e.logPath,{screenshotNoStabilize:!0},e.session?.appBundleId,e.session?.trace?.outPath),surface:e.session?.surface}),o=l,(r=s,"object"==typeof r&&null!==r&&"path"in r&&"string"==typeof r.path)?s.path:o);await t.access(d);let p=await eh(d,e.session);return u({level:"warn",phase:"android_snapshot_timeout_screenshot_captured",data:{path:d,overlayRefCount:"overlayRefCount"in p?p.overlayRefCount:void 0,overlayRefsAnnotated:"overlayRefsAnnotated"in p?p.overlayRefsAnnotated:void 0}}),p}catch(t){let e=l(t);return u({level:"warn",phase:"android_snapshot_timeout_screenshot_failed",data:{error:e.message}}),{captureFailed:!0,error:e.message}}}async function eh(e,t){if(!t?.snapshot)return{path:e,overlayRefsRequested:!0,overlayRefsAnnotated:!1,overlayRefSource:"unavailable",overlayRefCount:0};try{let a=await S({screenshotPath:e,snapshot:t.snapshot});return{path:e,overlayRefsRequested:!0,overlayRefsAnnotated:a.length>0,overlayRefCount:a.length,overlayRefSource:"session-snapshot",overlayRefs:a}}catch(a){let t=l(a);return u({level:"warn",phase:"android_snapshot_timeout_screenshot_overlay_failed",data:{path:e,error:t.message}}),{path:e,overlayRefsRequested:!0,overlayRefsAnnotated:!1,overlayRefSource:"session-snapshot",overlayRefCount:0,overlayAnnotationError:t.message}}}async function ew(e){return await ey({...e,command:"snapshot",unsupportedMessage:"snapshot is not supported on this device",execute:async({runtime:e,sessionName:t,req:a,snapshotScope:n})=>{let s=await e.capture.snapshot({session:t,interactiveOnly:a.flags?.snapshotInteractiveOnly,depth:a.flags?.snapshotDepth,scope:n,raw:a.flags?.snapshotRaw,forceFull:a.flags?.snapshotForceFull});return{data:s,record:{kind:"snapshot",nodes:s.nodes.length,truncated:s.truncated}}}})}async function eg(e){return await ey({...e,command:"diff",unsupportedMessage:"diff is not supported on this device",execute:async({runtime:e,sessionName:t,req:a,snapshotScope:n})=>{let s=await e.capture.diffSnapshot({session:t,interactiveOnly:a.flags?.snapshotInteractiveOnly,depth:a.flags?.snapshotDepth,scope:n,raw:a.flags?.snapshotRaw});return{data:s,record:{kind:"diff",mode:"snapshot",baselineInitialized:s.baselineInitialized,summary:s.summary}}}})}async function ey(e){var t,a;let{req:n,sessionName:s,logPath:o,sessionStore:l}=e,{session:p,device:u}=await O(l,s,n.flags),c=y(e.command,u,{message:e.unsupportedMessage});if(c)return c;let f=b(n.flags?.snapshotScope,p);if(!f.ok)return f;let m=(t=e.command,a=p,!r(u)||a?.appBundleId?null:v("SESSION_NOT_FOUND",`iOS ${t} requires an active app session on the target device. Run open first (for example: open --session ${a?.name??"sim"} --platform ios --device "<name>" <app>).`));return m||await B(p,u,async()=>{var t,a;let r,c,m=function(e){let{req:t,sessionName:a,logPath:n,sessionStore:s,session:o,device:r,snapshotScope:l}=e;return H({backend:function(e){let{req:t,logPath:a,session:n,device:s,snapshotScope:o}=e;return{platform:i(s),captureSnapshot:async(e,r)=>{let i=await w({device:s,session:n,flags:t.flags,outPath:r?.outPath??t.flags?.out,logPath:a,snapshotScope:o}),l=$(n);return{snapshot:i.snapshot,...D(i),...l?{snapshotDiagnostics:l}:{},appName:n?.appBundleId?n.appName??n.appBundleId:void 0,appBundleId:n?.appBundleId}}}}({req:t,logPath:n,session:o,device:r,snapshotScope:l}),...U("snapshot"),sessions:h({sessionName:a,getSession:()=>s.get(a),recordOptions:{includeSnapshot:!0},setRecord:e=>{var n;let o=function(e){if(!e.snapshot)throw new d("UNKNOWN","snapshot runtime did not produce session state");return e}(e),i=s.get(a);s.set(a,function(e){var t,a;let{current:n,sessionName:s,device:o,record:r,refScopedSnapshot:i}=e,l=(t=n,a=r,i&&a.snapshot?.nodes.length===0&&t?.snapshot!==void 0),d=l?n.snapshot:r.snapshot,p=P({session:n,sessionName:s,device:o,snapshot:d,appBundleId:r.appBundleId});return p.snapshotScopeSource=function(e){let{current:t,keepCurrentSnapshot:a,refScopedSnapshot:n}=e;if(n)return a?t?.snapshotScopeSource:t?.snapshotScopeSource??t?.snapshot}({current:n,keepCurrentSnapshot:l,refScopedSnapshot:i}),r.appName&&(p.appName=r.appName),p}({current:i,sessionName:a,device:r,record:o,refScopedSnapshot:(n=t,n.flags?.snapshotScope?.trim().startsWith("@")===!0)}))}})})}({req:n,sessionName:s,logPath:o,sessionStore:l,session:p,device:u,snapshotScope:f.scope});try{c=await e.execute({runtime:m,sessionName:s,req:n,snapshotScope:f.scope})}catch(a){let t=await ef({error:a,command:e.command,logPath:o,session:p,device:u});if(!t)throw a;return t}return(r=(t={req:n,sessionName:s,sessionStore:l,result:c.record}).sessionStore.get(t.sessionName))&&t.sessionStore.recordAction(r,{command:t.req.command,positionals:t.req.positionals??[],flags:t.req.flags??{},result:"snapshot"===(a=t.result).kind?{nodes:a.nodes,truncated:a.truncated}:{mode:a.mode,baselineInitialized:a.baselineInitialized,summary:a.summary}}),{ok:!0,data:c.data}})}let e_={snapshot:async({req:e,sessionName:t,logPath:a,sessionStore:n})=>await ew({req:e,sessionName:t,logPath:a,sessionStore:n}),diff:async({req:e,sessionName:t,logPath:a,sessionStore:n})=>e.positionals?.[0]!=="snapshot"?v("INVALID_ARGS","diff currently supports only: diff snapshot"):await eg({req:e,sessionName:t,logPath:a,sessionStore:n}),wait:async({req:e,sessionName:t,logPath:a,sessionStore:n})=>await E({req:e,sessionName:t,logPath:a,sessionStore:n}),alert:async({req:e,sessionName:t,logPath:a,sessionStore:n})=>{let{session:s,device:o}=await O(n,t,e.flags);return await B(s,o,async()=>await ei({req:e,logPath:a,sessionStore:n,session:s,device:o}))},settings:async({req:e,sessionName:t,logPath:a,sessionStore:n})=>{let s,o,r,i=(s=e.positionals?.[0]?.toLowerCase(),o=e.positionals?.[1]?.toLowerCase(),r=e.positionals?.[2]?.toLowerCase(),"clear-app-state"===s?{ok:!0,parsed:{setting:s,state:"clear",appBundleId:"clear"===o?e.positionals?.[2]:e.positionals?.[1]}}:s&&o&&("permission"!==s||r)&&("location"!==s||"set"!==o||e.positionals?.[2]&&e.positionals?.[3])?{ok:!0,parsed:{setting:s,state:o,permissionTarget:r,latitude:e.positionals?.[2],longitude:e.positionals?.[3]}}:v("INVALID_ARGS",C));if(!i.ok)return i;let{session:l,device:d}=await O(n,t,e.flags);return await B(l,d,async()=>await ec({req:e,logPath:a,sessionStore:n,session:l,device:d,parsed:i.parsed}))}};async function ev(e){let t=e_[e.req.command];return t?await t(e):null}export{q as snapshot_namespaceObject};
package/dist/src/web.js CHANGED
@@ -1 +1 @@
1
- import{AppError as e}from"./485.js";import{withDiagnosticTimer as t}from"./432.js";import{resolveWebProvider as r}from"./provider.js";function o(){return{open:(e,t)=>r().open(t?.url??e,{url:t?.url}),openDevice:()=>r().open("about:blank"),close:e=>r().close(e),tap:(e,t)=>r().click(e,t),doubleTap:()=>n("doubleTap"),swipe:()=>n("swipe"),pan:()=>n("pan"),fling:()=>n("fling"),longPress:()=>n("longPress"),focus:(e,t)=>r().click(e,t),type:(e,t)=>r().typeText(e,{delayMs:t}),fill:(e,t,o,n)=>r().fill(e,t,o,{delayMs:n}),scroll:(e,t)=>r().scroll(e,t),pinch:()=>n("pinch"),screenshot:(e,t)=>r().screenshot(e,t),setViewport:(e,t)=>r().setViewport(e,t),snapshot:async e=>{let o=await t("snapshot_capture",async()=>await r().snapshot(e),{backend:"web"});return{nodes:o.nodes,truncated:o.truncated??!1,backend:"web"}},back:()=>n("back"),home:()=>n("home"),rotate:()=>n("rotate"),rotateGesture:()=>n("rotateGesture"),transformGesture:()=>n("transformGesture"),appSwitcher:()=>n("appSwitcher"),readClipboard:()=>n("readClipboard"),writeClipboard:()=>n("writeClipboard"),setSetting:()=>n("setSetting")}}async function n(t){throw new e("UNSUPPORTED_OPERATION",`${t} is not supported on web`)}export{o as createWebInteractor};
1
+ import{AppError as e}from"./485.js";import{withDiagnosticTimer as t}from"./8875.js";import{resolveWebProvider as r}from"./provider.js";function o(){return{open:(e,t)=>r().open(t?.url??e,{url:t?.url}),openDevice:()=>r().open("about:blank"),close:e=>r().close(e),tap:(e,t)=>r().click(e,t),doubleTap:()=>n("doubleTap"),swipe:()=>n("swipe"),pan:()=>n("pan"),fling:()=>n("fling"),longPress:()=>n("longPress"),focus:(e,t)=>r().click(e,t),type:(e,t)=>r().typeText(e,{delayMs:t}),fill:(e,t,o,n)=>r().fill(e,t,o,{delayMs:n}),scroll:(e,t)=>r().scroll(e,t),pinch:()=>n("pinch"),screenshot:(e,t)=>r().screenshot(e,t),setViewport:(e,t)=>r().setViewport(e,t),snapshot:async e=>{let o=await t("snapshot_capture",async()=>await r().snapshot(e),{backend:"web"});return{nodes:o.nodes,truncated:o.truncated??!1,backend:"web"}},back:()=>n("back"),home:()=>n("home"),rotate:()=>n("rotate"),rotateGesture:()=>n("rotateGesture"),transformGesture:()=>n("transformGesture"),appSwitcher:()=>n("appSwitcher"),readClipboard:()=>n("readClipboard"),writeClipboard:()=>n("writeClipboard"),setSetting:()=>n("setSetting")}}async function n(t){throw new e("UNSUPPORTED_OPERATION",`${t} is not supported on web`)}export{o as createWebInteractor};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-device",
3
- "version": "0.18.1",
3
+ "version": "0.18.2",
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",
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.18.1",
10
+ "version": "0.18.2",
11
11
  "packages": [
12
12
  {
13
13
  "registryType": "npm",
14
14
  "identifier": "agent-device",
15
- "version": "0.18.1",
15
+ "version": "0.18.2",
16
16
  "transport": {
17
17
  "type": "stdio"
18
18
  }
@@ -1 +0,0 @@
1
- a0d4d7dec1141d8e84a68fdf00471957e52fcf5dbd8bfdd4824c967a59b2ecde agent-device-android-multitouch-helper-0.18.1.apk
@@ -1 +0,0 @@
1
- 50b67b8553bedee0d1d3b54094ef0f2ef94337e9e0fa0166e285fd8b91efd551 agent-device-android-snapshot-helper-0.18.1.apk
package/dist/src/432.js DELETED
@@ -1,4 +0,0 @@
1
- import{AsyncLocalStorage as e}from"node:async_hooks";import t from"node:crypto";import n from"node:fs";import o from"node:os";import r from"node:path";import{redactDiagnosticData as i}from"./485.js";let s=new e;function a(){return t.randomBytes(8).toString("hex")}async function c(e,n){let o={...e,diagnosticId:`${Date.now().toString(36)}-${t.randomBytes(4).toString("hex")}`,events:[],liveWrittenEventCount:0,phaseCounts:new Map};return await s.run(o,n)}function g(e){let t=s.getStore();t&&Object.assign(t,e)}function l(){let e=s.getStore();return e?{diagnosticId:e.diagnosticId,requestId:e.requestId,session:e.session,command:e.command,debug:e.debug}:{}}function u(e){let t=s.getStore();if(!t)return 0;let n=0;for(let o of e)n+=t.phaseCounts.get(o)??0;return n}function d(e){let t=s.getStore();if(!t)return;let n={ts:new Date().toISOString(),level:e.level??"info",phase:e.phase,session:t.session,requestId:t.requestId,command:t.command,durationMs:e.durationMs,data:e.data?i(e.data):void 0};if(t.events.push(n),t.phaseCounts.set(e.phase,(t.phaseCounts.get(e.phase)??0)+1),!t.debug)return;let o=`${JSON.stringify(n)}
2
- `;try{t.logPath&&(m(t.logPath,o),t.liveWrittenEventCount=t.events.length),t.traceLogPath&&m(t.traceLogPath,o),t.logPath||t.traceLogPath||process.stderr.write(`[agent-device][diag] ${o}`)}catch{}}async function f(e,t,n){let o=Date.now();try{let r=await t();return d({level:"info",phase:e,durationMs:Date.now()-o,data:n}),r}catch(t){throw d({level:"error",phase:e,durationMs:Date.now()-o,data:{...n??{},error:t instanceof Error?t.message:String(t)}}),t}}function h(e={}){let t=s.getStore();if(!t||!e.force&&!t.debug||0===t.events.length)return null;try{if(t.logPath){let e=t.events.slice(t.liveWrittenEventCount);if(e.length>0){let n=e.map(e=>JSON.stringify(i(e)));m(t.logPath,`${n.join("\n")}
3
- `)}let n=t.logPath;return t.events=[],t.liveWrittenEventCount=0,n}let e=(t.session??"default").replace(/[^a-zA-Z0-9._-]/g,"_"),s=new Date().toISOString().slice(0,10),a=r.join(o.homedir(),".agent-device","logs",e,s);n.mkdirSync(a,{recursive:!0});let c=new Date().toISOString().replace(/[:.]/g,"-"),g=r.join(a,`${c}-${t.diagnosticId}.ndjson`),l=t.events.map(e=>JSON.stringify(i(e)));return n.writeFileSync(g,`${l.join("\n")}
4
- `),t.events=[],g}catch{return null}}function m(e,t){n.mkdirSync(r.dirname(e),{recursive:!0}),n.appendFileSync(e,t,"utf8")}export{u as countDiagnosticEventsByPhase,a as createRequestId,d as emitDiagnostic,h as flushDiagnosticsToSessionFile,l as getDiagnosticsMeta,g as updateDiagnosticsScope,f as withDiagnosticTimer,c as withDiagnosticsScope};