agent-device 0.21.7 → 0.21.8
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/ime-helper/dist/{agent-device-android-ime-helper-0.21.7.apk → agent-device-android-ime-helper-0.21.8.apk} +0 -0
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.8.apk.sha256 +1 -0
- package/android/ime-helper/dist/{agent-device-android-ime-helper-0.21.7.manifest.json → agent-device-android-ime-helper-0.21.8.manifest.json} +4 -4
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.21.7.apk → agent-device-android-snapshot-helper-0.21.8.apk} +0 -0
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.8.apk.sha256 +1 -0
- package/android/snapshot-helper/dist/{agent-device-android-snapshot-helper-0.21.7.manifest.json → agent-device-android-snapshot-helper-0.21.8.manifest.json} +6 -6
- package/apple/macos-helper/Package.swift +16 -1
- package/apple/macos-helper/Sources/AgentDeviceMacOSDeviceHub/DeviceHubPose.swift +47 -0
- package/apple/macos-helper/Sources/AgentDeviceMacOSHelper/DeviceHubPose.swift +320 -0
- package/apple/macos-helper/Sources/AgentDeviceMacOSHelper/main.swift +66 -13
- package/apple/macos-helper/Sources/AgentDeviceMacOSInput/MouseClickDelivery.swift +116 -0
- package/apple/macos-helper/Sources/AgentDeviceMacOSInput/MouseClickSchedule.swift +61 -0
- package/apple/macos-helper/Tests/AgentDeviceMacOSDeviceHubTests/DeviceHubPoseTests.swift +30 -0
- package/apple/macos-helper/Tests/AgentDeviceMacOSInputTests/MouseClickScheduleTests.swift +58 -0
- package/dist/src/absence-observation-errors.js +1 -1
- package/dist/src/adapter.js +1 -1
- package/dist/src/agent-browser-lifecycle.js +1 -1
- package/dist/src/agent-browser-process-record.js +1 -1
- package/dist/src/agent-device-client.js +2 -2
- package/dist/src/alert-runtime.js +1 -1
- package/dist/src/android-input-ownership.js +1 -1
- package/dist/src/android.js +1 -1
- package/dist/src/app-launch.js +1 -1
- package/dist/src/app-log-runtime2.js +3 -3
- package/dist/src/cli-help.js +9 -6
- package/dist/src/client-types.d.ts +33 -1
- package/dist/src/command-tools.js +3 -3
- package/dist/src/config.js +1 -1
- package/dist/src/device-claim-inspection.js +1 -1
- package/dist/src/device-claim-rule.js +2 -2
- package/dist/src/device-input-state.d.ts +1 -1
- package/dist/src/device-rotation.js +1 -1
- package/dist/src/device-session.js +1 -1
- package/dist/src/devicectl.js +1 -1
- package/dist/src/display-inventory.js +1 -1
- package/dist/src/durable-resource.js +1 -1
- package/dist/src/exec.js +1 -1
- package/dist/src/find.js +1 -1
- package/dist/src/finders.js +1 -1
- package/dist/src/gesture-runtime.js +1 -1
- package/dist/src/harmonyos.js +1 -1
- package/dist/src/helper.js +2 -2
- package/dist/src/host.js +1 -0
- package/dist/src/interaction-positionals.js +1 -1
- package/dist/src/interaction-ref-policy.js +1 -1
- package/dist/src/interactor-operation-binding.js +1 -0
- package/dist/src/interactor-operation-catalog.js +1 -1
- package/dist/src/interactor.js +4 -5
- package/dist/src/interactor2.js +1 -1
- package/dist/src/internal/bin.js +1 -1
- package/dist/src/internal/daemon.js +2 -2
- package/dist/src/internal/png-worker.d.ts +5 -0
- package/dist/src/internal/png-worker.js +1 -1
- package/dist/src/ios-snapshot-acquisition.js +1 -1
- package/dist/src/ios-snapshot-runtime.js +1 -1
- package/dist/src/lease.js +1 -1
- package/dist/src/linux.js +1 -1
- package/dist/src/local-interactor-operation-set.js +1 -1
- package/dist/src/location-coordinates.js +1 -1
- package/dist/src/macos-facade.js +1 -1
- package/dist/src/mechanics.js +16 -15
- package/dist/src/mobile-snapshot-semantics.js +1 -1
- package/dist/src/parameterized-recorded-fill.js +1 -1
- package/dist/src/perf-facade.js +1 -1
- package/dist/src/perf-runtime-plan.js +1 -1
- package/dist/src/physical-device-control.js +1 -1
- package/dist/src/platform-request-scope.js +1 -1
- package/dist/src/platform-runtime-managed-owner.js +1 -1
- package/dist/src/platform-runtime-unavailable.js +1 -1
- package/dist/src/platform-runtime.js +1 -1
- package/dist/src/platform-runtime2.js +1 -1
- package/dist/src/png-worker-client.js +1 -1
- package/dist/src/provider-webdriver.js +1 -1
- package/dist/src/quality-warnings.js +1 -1
- package/dist/src/registry.js +35 -35
- package/dist/src/replay.js +2 -2
- package/dist/src/request-admission.js +1 -1
- package/dist/src/request-runtime-binding.js +1 -1
- package/dist/src/runner-cache-metadata.js +2 -2
- package/dist/src/runner-client.js +1 -1
- package/dist/src/runner-contract.js +3 -0
- package/dist/src/runner-dev-tools-security.js +1 -0
- package/dist/src/runner-device-readiness.js +1 -0
- package/dist/src/runner-disposal.js +1 -1
- package/dist/src/runner-presentation.js +1 -1
- package/dist/src/runtime.js +2 -2
- package/dist/src/runtime2.js +4 -4
- package/dist/src/runtime4.js +4 -4
- package/dist/src/runtime6.js +1 -1
- package/dist/src/runtime7.js +1 -1
- package/dist/src/runtime8.js +1 -1
- package/dist/src/runtime9.js +1 -1
- package/dist/src/screen-recording-resource-recovery.js +1 -1
- package/dist/src/screenshot-image.js +1 -0
- package/dist/src/screenshot-runtime.js +1 -1
- package/dist/src/script.js +1 -1
- package/dist/src/scroll-gesture.js +1 -1
- package/dist/src/sdk-batch.js +1 -1
- package/dist/src/sdk-contracts.js +2 -2
- package/dist/src/sdk-finders.js +1 -1
- package/dist/src/sdk-selectors.d.ts +15 -6
- package/dist/src/sdk-selectors.js +1 -1
- package/dist/src/selection.js +0 -0
- package/dist/src/selector-runtime.js +1 -1
- package/dist/src/selectors.js +1 -1
- package/dist/src/semantic-index.js +1 -1
- package/dist/src/session-snapshot.js +1 -1
- package/dist/src/session-store.js +3 -3
- package/dist/src/session2.js +2 -2
- package/dist/src/simulator-facade.js +1 -1
- package/dist/src/simulator.js +1 -1
- package/dist/src/snapshot-runtime-binding.js +1 -1
- package/dist/src/snapshot-state.js +1 -1
- package/dist/src/snapshot4.js +1 -1
- package/dist/src/src.js +1 -1
- package/dist/src/src7.js +1 -1
- package/dist/src/src8.js +1 -1
- package/dist/src/text-entry-focus.js +1 -1
- package/dist/src/touch-runtime.js +1 -1
- package/dist/src/tree.js +1 -1
- package/dist/src/type-text-runtime.js +1 -1
- package/dist/src/video.js +1 -1
- package/dist/src/web2.js +1 -1
- package/package.json +3 -1
- package/server.json +2 -2
- package/android/ime-helper/dist/agent-device-android-ime-helper-0.21.7.apk.sha256 +0 -1
- package/android/snapshot-helper/dist/agent-device-android-snapshot-helper-0.21.7.apk.sha256 +0 -1
- package/dist/src/png-transcode.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Br as e,Nr as t,Ur as n,Vr as r,Wr as i,kr as a}from"./sdk-batch.js";import{n as o,t as s}from"./scroll-indicator.js";import{a as c,i as l,o as ee,r as u}from"./react-native-overlay.js";import{t as d}from"./rect-center.js";import{a as f,c as te,d as p,f as m,g as ne,h,i as g,l as re,m as _,n as v,o as y,p as b,r as x,s as S,t as C,u as ie}from"./tree.js";function ae(e,t){let n=g(t.sourceNodesByIndex.values());for(let r of e)oe(r,t.sourceNodesByIndex,n)&&b(t.replacements,r,{type:`Cell`})}function oe(e,n,r){return!(t(e.type??``)!==`other`||e.enabled===!1||!e.rect||!le(e.label)||!f(e,n,ce)||!se(e)||re(e.rect,r))}function se(e){return e.rect?e.rect.height>=44&&e.rect.height<=160&&e.rect.width>=120:!1}function ce(e){let n=t(e.type??``);return n===`scrollview`||n===`scrollarea`}function le(e){let t=e?.trim();return!(!t||/^(toolbar|window|application)$/i.test(t)||t.startsWith(`!,`)||/debugger|fast refresh/i.test(t))}function ue(e,t){let n=new Set;for(let r of e)de(t.replacements.get(r.index)??r)&&fe(r,t.sourceNodesByIndex,t,n);pe(e,t,n)}function de(e){let t=e.label?.trim();return!!(t&&o(t))}function fe(e,t,n,r){let i=!p(e.type)||n.isSuppressed(e),a=s(e.label?.trim()??``,e.value),o=a?y(e,t,{includeSelf:!0}):void 0;i&&n.suppressNode(e,o?[o]:[]),o&&a&&j(n,o,e,a)&&r.add(o.index)}function pe(e,t,n){let r=new Map;for(let i of e){let e=r.get(i.parentIndex??-1),a=e?.clip,o=t.replacements.get(i.index)??i,s=k(o.rect,a),c=me(o,a,s),l=w(e,c,o);T(t,i,o,a,s,c,l),r.set(i.index,E(i,o,a,s,l,n))}}function me(t,n,r){return!!(n&&e(t.rect)&&!e(r))}function w(e,t,n){return!!(e?.projectedOut||t&&O(n))}function T(e,t,n,r,i,a,o){o||a?e.suppressNode(t,[]):r&&i&&!A(n.rect,i)&&b(e.replacements,t,{rect:i})}function E(e,t,n,r,i,a){return{projectedOut:i,...D(e,t,n,r,a)?{clip:r}:n?{clip:n}:{}}}function D(t,n,r,i,a){return!!(e(i)&&(a.has(t.index)||r!==void 0&&p(n.type)))}function O(e){return e.type?.trim().toLowerCase()===`cell`||p(e.type)}function k(e,t){if(!e||!t)return e;let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y),i=Math.min(e.x+e.width,t.x+t.width),a=Math.min(e.y+e.height,t.y+t.height);return{x:n,y:r,width:Math.max(0,i-n),height:Math.max(0,a-r)}}function A(e,t){return!!(e&&e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height)}function j(e,t,n,r){let i=N((e.replacements.get(t.index)??t).rect,n.rect);return ne(e.replacements,t,e=>({rect:i??e.rect,hiddenContentAbove:M(e.hiddenContentAbove,r.above),hiddenContentBelow:M(e.hiddenContentBelow,r.below)})),!!i}function M(e,t){return e===!0||t?!0:void 0}function N(e,t){if(!(!e||!t)&&!(t.height<=0||t.height>=e.height)&&!(t.y<e.y||t.y>e.y+e.height))return{...e,y:t.y,height:Math.min(t.height,e.y+e.height-t.y)}}function P(e,n){for(let r=0;r<e.length;r+=1){let i=e[r],a=i?.label?.trim();i&&a&&t(i.type??``)===`other`&&n(i,a,r)}}function F(e,t){P(e,(n,r,i)=>{if(!c(r)||!n.rect)return;let a=x(e,i,e=>!!e.rect&&ee(e.label?.trim()??``));if(!a?.rect)return;let o=L(n.rect,a.rect);if(!o)return;let s=I(e,i,o);b(t,n,{rect:s}),S(e,i,e=>{c(e.label?.trim()??``)&&b(t,e,{rect:s})})})}function I(e,t,r){let a=r;return S(e,t,e=>{let t=e.label?.trim()??``;!e.rect||!c(t)||i(r,e.rect)&&n(e.rect)<n(a)&&(a=e.rect)}),a}function L(e,t){let n=e.x+e.width,r=t.x+t.width,i={x:t.x,y:e.y,width:n-t.x,height:e.height};if(t.x>e.x&&d(t,i))return{...e,width:t.x-e.x};let a={x:e.x,y:e.y,width:r-e.x,height:e.height};if(r<n&&d(t,a))return{...e,x:r,width:n-r}}function R(e,t){P(e,(n,r,i)=>{u(n)&&l(n,z(e,i))&&t.suppressNode(n,z(e,i))})}function z(e,t){let n=[];return S(e,t,e=>{n.push(e)}),n}function he(e,t){let n=g(e),r=n?n.y+n.height:null;if(r!==null)for(let n=0;n<e.length;n+=1){let i=e[n];!i||!ge(i,r)||(t.suppressNode(i,[]),_e(i,t,r),S(e,n,e=>{t.suppressNode(e,[])}))}}function ge(e,n){return!e.rect||t(e.type??``)!==`keyboard`?!1:e.rect.y>=n}function _e(e,t,n){let r=typeof e.parentIndex==`number`?t.sourceNodesByIndex.get(e.parentIndex):void 0;for(;r?.rect&&r.rect.y>=n;)t.suppressNode(r,[]),r=typeof r.parentIndex==`number`?t.sourceNodesByIndex.get(r.parentIndex):void 0}function ve(e,n){for(let r=0;r<e.length;r+=1){let i=e[r];if(!i)continue;if(ye(i)){B(e,r,i,n);continue}if(!be(i))continue;let a=x(e,r,e=>t(e.type??``)===`searchfield`&&e.label===`Search`);a&&(n.suppressNode(i,[a]),xe(i,a,n),B(e,r,a,n))}}function ye(e){return t(e.type??``)===`searchfield`&&e.label===`Search`}function be(e){let n=t(e.type??``);return e.label===`Toolbar`&&(n===`toolbar`||n===`searchfield`)}function B(e,t,n,r){S(e,t,e=>{e.index!==n.index&&Se(e)&&r.suppressNode(e,[n])})}function xe(e,t,n){let r=e;for(;typeof r.parentIndex==`number`;){let e=n.sourceNodesByIndex.get(r.parentIndex);if(!e||e.label!==`Toolbar`)return;n.suppressNode(e,[t]),r=e}}function Se(e){let n=t(e.type??``);return n===`button`?!1:n===`image`||e.label===`Search`}function Ce(e,t){for(let n=0;n<e.length;n+=1){let r=e[n],i=r?.label?.trim();!r||t.isSuppressed(r)||!i||we(e,n,r,i,t)}}function we(e,n,r,i,a){let o=t(r.type??``);if(o===`statictext`||o===`link`){V(e,n,i,r,a);return}if(o!==`other`)return;let s=Te(e,n,i);if(s){a.suppressNode(r,[s]);return}V(e,n,i,r,a)}function Te(e,n,r){return x(e,n,e=>{let n=t(e.type??``);return(n===`link`||n===`searchfield`||p(e.type))&&e.label?.trim()===r})}function V(e,t,n,r,i){S(e,t,e=>{!i.semanticRepresentativeIndexes.has(e.index)&&ie(e,n)&&i.suppressNode(e,[r])})}function Ee(e,t){P(e,(n,r,i)=>{let a=x(e,i,e=>m(e)&&e.label?.trim()===r&&(d(e.rect,n.rect)||De(n,e)));a&&t.suppressNode(n,[a])})}function De(e,n){if(n.label?.trim()!==e.label?.trim())return!1;let r=t(n.type??``);return Oe(e,r)||r===`textfield`||ke(e,r,n)}function Oe(e,t){let n=e.label?.trim();return t===`button`&&(n===`Dismiss`||n===`Back`)}function ke(e,t,n){return t!==`button`||!e.rect||!n.rect?!1:e.rect.x===0&&e.rect.y===0&&e.rect.width>=300&&e.rect.height>=600&&n.rect.width<e.rect.width}function Ae(e,n){let r=C(e);for(let i of e){if(t(i.type??``)!==`other`||i.hittable===!0||i.label?.trim()||i.value?.trim()||!i.identifier?.trim())continue;let e=je(i,r);(e.length!==0||i.hittable===!1)&&n.suppressNode(i,e)}}function je(e,t){let n=[],r=new Set([e.index]),i=[...t.get(e.index)??[]];for(;i.length>0;){let e=i.pop();if(!e||r.has(e.index))continue;r.add(e.index),n.push(e);let a=t.get(e.index);a&&i.push(...a)}return n}function Me(e,t){he(e,t),Ae(e,t),ue(e,t),ve(e,t),Ee(e,t),F(e,t.replacements),R(e,t),Ce(e,t)}function Ne(e,t){for(let n=0;n<e.length;n+=1){let r=e[n],i=r?Pe(e,n,r,t):void 0;!r?.rect||!i||Le(e,n,r,i,t)}}function Pe(e,n,r,i){let a=r.label?.trim();if(t(r.type??``)!==`cell`||a&&!Fe(a,r.identifier)&&!o(a))return a;let s=v(e,n).find(Ie),c=s?.label?.trim();return!s||!c?a:(b(i.replacements,r,{label:c}),i.suppressNode(s,[r]),c)}function Fe(e,t){return t?.trim()===e&&/^[A-Z_$][A-Za-z0-9_$]*Cell$/.test(e)}function Ie(e){if(!e.label?.trim())return!1;let n=t(e.type??``);return n===`statictext`||n===`text`||n===`textview`}function Le(e,n,r,i,a){let o=t(r.type??``);if(o===`button`){H(v(e,n),i,a,r);return}if(o!==`cell`)return;let s=v(e,n);Re(s,r,i,a)||ze(s,r,i,a)}function Re(e,t,n,r){let i=e.find(e=>Ve(e,t,n));if(!i)return!1;let a=e.find(e=>U(e,t,n)),o=i.identifier?void 0:a?.identifier??t.identifier;return o&&b(r.replacements,i,{identifier:o}),r.suppressNode(t,[i]),Be(e,t,n,i,r),!0}function ze(e,t,n,r){let i=e.find(e=>U(e,t,n));if(!i){e.some(te)&&H(e,n,r,t);return}!t.identifier&&i.identifier&&b(r.replacements,t,{identifier:i.identifier}),r.suppressNode(i,[t]),H(e.filter(e=>e.index!==i.index),n,r,t)}function Be(e,t,n,r,i){for(let a of e)a.index!==r.index&&(U(a,t,n)||W(a,t)||He(a,r)||h(a,n))&&i.suppressNode(a,[r])}function H(e,t,n,r){for(let i of e)(h(i,t)||r&&W(i,r))&&n.suppressNode(i,r?[r]:[])}function U(e,n,r){if(t(e.type??``)!==`button`)return!1;let i=n.identifier?.trim(),a=e.identifier?.trim();return i&&a&&i===a?!0:e.label?.trim()===r&&d(e.rect,n.rect)}function W(e,n){return t(e.type??``)===`button`&&!e.label?.trim()&&!e.value?.trim()&&d(e.rect,n.rect)}function Ve(e,n,r){if(t(e.type??``)!==`switch`)return!1;let i=n.identifier?.trim(),a=e.identifier?.trim();return i&&a&&i===a?!0:e.label?.trim()===r}function He(e,n){if(t(e.type??``)!==`switch`||e.index===n.index)return!1;let r=e.label?.trim();return r===n.value?.trim()||r===`0`||r===`1`}const G=1.15;function Ue(e,t,n){let i=new Map(e.map((e,t)=>[e.index,t]));for(let[a,o]of e.entries()){let s=We(e,i,t,o,n);if(!s)continue;q(e,a,n);let c=J(s.shelfRect,2);for(let t of s.intermediateSiblings){if($e(t)||!t.rect||!r(t.rect,c))continue;let a=i.get(t.index);a!==void 0&&q(e,a,n)}}}function We(e,t,n,r,i){let a=Ge(r,n,i.sourceNodesByIndex);if(!a)return;let o=Je(e,t,a.siblings,a.position,a.parent);if(!(o<0))return{shelfRect:a.rect,intermediateSiblings:a.siblings.slice(a.position+1,o)}}function Ge(e,t,n){let r=Ye(e,K(t,e.index));if(!r)return;let i=qe(e,n);if(!i||!i.rect)return;let a=K(t,i.index),o=a.findIndex(t=>t.index===e.index);if(Ke(a,o,e,r))return{rect:r.rect,parent:i,siblings:a,position:o}}function K(e,t){return e.get(t)??[]}function Ke(e,t,n,r){if(t<1)return!1;let i=Xe(e,t,n);return i?!r.childActionsPresented||!Ze(i,r.actionButtons):!1}function qe(e,t){return typeof e.parentIndex==`number`?t.get(e.parentIndex):void 0}function Je(e,t,n,r,i){return n.findIndex((n,a)=>a>r&&Qe(e,t.get(n.index),n,i))}function Ye(e,n){if(!p(e.type)||!e.rect)return;let r=e.rect,a=n.filter(e=>t(e.type??``)===`button`&&e.rect);if(a.length===0&&e.hiddenContentBelow===!0)return{rect:r,childActionsPresented:!1,actionButtons:a};if(a.length<3)return;let o=a.map(e=>e.rect.x+e.rect.width/2);if(o.every((e,t)=>t===0||e>o[t-1]))return{rect:r,childActionsPresented:a.some(e=>i(r,e.rect)),actionButtons:a}}function Xe(e,t,n){if(!(!n.rect||t<1))for(let r=t-1;r>=0;--r){let t=e[r];if(!(!t.rect||!m(t))&&t.rect.x+t.rect.width/2<n.rect.x&&et(t.rect,J(n.rect,2)))return t}}function Ze(e,t){if(!e.rect||t.length===0)return!1;let n=Math.max(...t.map(e=>e.rect?.width??0)),r=Math.max(...t.map(e=>e.rect?.height??0));return e.rect.width>n*G||e.rect.height>r*G}function Qe(e,n,r,i){return n!==void 0&&t(r.type??``)===`other`&&d(r.rect,i.rect)&&!!x(e,n,m)}function q(e,t,n){let r=e[t];if(r){n.suppressNode(r,[]);for(let r of v(e,t))n.suppressNode(r,[])}}function $e(e){let n=t(e.type??``);return n===`textfield`||n===`securetextfield`||n===`searchfield`||n===`textview`}function J(e,t){return{x:e.x-t,y:e.y-t,width:e.width+t*2,height:e.height+t*2}}function et(e,t){return Math.max(e.y,t.y)<=Math.min(e.y+e.height,t.y+t.height)}function tt(e,t){let n=C(e);Ue(e,n,t),nt(e,n,t)}function nt(e,n,r){for(let i of e){if(t(i.type??``)!==`navigationbar`||!i.rect)continue;let e=n.get(i.index)??[],a=e.flatMap(t=>rt(t,e,i.rect));if(a.length!==1)continue;let{field:o,title:s,image:c,label:l}=a[0];b(r.replacements,o,{type:`Button`,label:l,enabled:!0,hittable:void 0,rect:st([c.rect,o.rect,s.rect])}),r.semanticRepresentativeIndexes.add(o.index),r.suppressNode(s,[o]),r.suppressNode(c,[o])}}function rt(e,t,n){let r=a(e);if(!it(e,r))return[];let i=X(t,e=>at(e,r)),o=X(t,Y);return i?.rect&&o?.rect&&ot(o.rect,e.rect,i.rect,n)?[{field:e,title:i,image:o,label:r}]:[]}function it(e,n){return t(e.type??``)===`textfield`&&e.enabled===!1&&!!e.rect&&!!n&&e.value?.trim()===n}function at(e,n){return t(e.type??``)===`statictext`&&e.label?.trim()===n&&!!e.rect}function Y(e){return t(e.type??``)===`image`&&!!e.identifier?.trim()&&!!e.rect}function X(e,t){let n=e.filter(t);return n.length===1?n[0]:void 0}function ot(e,t,n,r){let a=t.x-(e.x+e.width),o=n.x-(t.x+t.width);return i(r,e)&&i(r,t)&&i(r,n)&&a>=0&&a<=12&&o>=0&&o<=12&&Z(e,t)&&Z(t,n)}function Z(e,t){return Math.max(e.y,t.y)<=Math.min(e.y+e.height,t.y+t.height)}function st(e){let t=Math.min(...e.map(e=>e.x)),n=Math.min(...e.map(e=>e.y)),r=Math.max(...e.map(e=>e.x+e.width)),i=Math.max(...e.map(e=>e.y+e.height));return{x:t,y:n,width:r-t,height:i-n}}function ct(e,n){let r=C(e);for(let i of e){if(t(i.type??``)===`element(58)`){b(n.replacements,i,{type:`WebView`});continue}let e=lt(i,n.sourceNodesByIndex,r);if(e?.kind===`suppress`){n.suppressNode(i,[]);continue}e&&(b(n.replacements,i,{type:e.type,...e.type===`Heading`?{value:void 0}:{}}),n.semanticRepresentativeIndexes.add(i.index))}}function lt(e,n,r){if(t(e.type??``)!==`other`)return null;let i=f(e,n,ft),a=e.label?.trim();return!i||!a?null:dt(e,i,a)?{kind:`suppress`}:ut(e,a,r)?{kind:`semantic`,type:Q(e.value)?`Heading`:`StaticText`}:null}function ut(e,n,r){let i=r.get(e.index);if(i?.length!==1)return!1;let a=i[0];return t(a.type??``)===`statictext`&&a.label?.trim()===n&&!r.has(a.index)}function dt(e,t,n){return e.parentIndex===t.index&&t.label?.trim()===n&&!Q(e.value)}function ft(e){let n=t(e.type??``);return n===`webview`||n===`element(58)`}function Q(e){return/^[1-6]$/.test(e?.trim()??``)}const pt=[ct,tt,ae,Ne,Me];function mt(e){if(e.length===0)return{nodes:e,presentedIndexesBySourceIndex:new Map};let t=new Map,n=new Map,r=new Set,i=new Map(e.map(e=>[e.index,e])),a=new Set,o={replacements:t,semanticRepresentativeIndexes:r,sourceNodesByIndex:i,isSuppressed:e=>a.has(e.index),suppressNode(e,t){if(a.add(e.index),t.length===0)return;let r=n.get(e.index)??new Set;for(let e of t)r.add(e.index);n.set(e.index,r)}};for(let t of pt)t(e,o);if(a.size===0&&t.size===0)return{nodes:e,presentedIndexesBySourceIndex:new Map(e.map(e=>[e.index,[e.index]]))};let s=e.filter(e=>!a.has(e.index)).map(e=>t.get(e.index)??e),c=_(s,a,e),l=new Map(s.map((e,t)=>[e.index,c[t].index]));return{nodes:c,presentedIndexesBySourceIndex:new Map(e.map(e=>[e.index,$(e.index,l,n)]))}}function $(e,t,n,r=new Set){let i=t.get(e);if(i!==void 0)return[i];if(r.has(e))return[];r.add(e);let a=new Set;for(let i of n.get(e)??[])for(let e of $(i,t,n,r))a.add(e);return[...a].sort((e,t)=>e-t)}export{mt as t};
|
|
1
|
+
import{Ar as e,Gr as t,Hr as n,Pr as r,Vr as i,Wr as a}from"./sdk-batch.js";import{n as o,t as s}from"./scroll-indicator.js";import{a as c,i as l,o as ee,r as u}from"./react-native-overlay.js";import{t as d}from"./rect-center.js";import{a as f,c as te,d as p,f as m,g as ne,h,i as g,l as re,m as _,n as v,o as y,p as b,r as x,s as S,t as C,u as ie}from"./tree.js";function ae(e,t){let n=g(t.sourceNodesByIndex.values());for(let r of e)oe(r,t.sourceNodesByIndex,n)&&b(t.replacements,r,{type:`Cell`})}function oe(e,t,n){return!(r(e.type??``)!==`other`||e.enabled===!1||!e.rect||!le(e.label)||!f(e,t,ce)||!se(e)||re(e.rect,n))}function se(e){return e.rect?e.rect.height>=44&&e.rect.height<=160&&e.rect.width>=120:!1}function ce(e){let t=r(e.type??``);return t===`scrollview`||t===`scrollarea`}function le(e){let t=e?.trim();return!(!t||/^(toolbar|window|application)$/i.test(t)||t.startsWith(`!,`)||/debugger|fast refresh/i.test(t))}function ue(e,t){let n=new Set;for(let r of e)de(t.replacements.get(r.index)??r)&&fe(r,t.sourceNodesByIndex,t,n);pe(e,t,n)}function de(e){let t=e.label?.trim();return!!(t&&o(t))}function fe(e,t,n,r){let i=!p(e.type)||n.isSuppressed(e),a=s(e.label?.trim()??``,e.value),o=a?y(e,t,{includeSelf:!0}):void 0;i&&n.suppressNode(e,o?[o]:[]),o&&a&&j(n,o,e,a)&&r.add(o.index)}function pe(e,t,n){let r=new Map;for(let i of e){let e=r.get(i.parentIndex??-1),a=e?.clip,o=t.replacements.get(i.index)??i,s=k(o.rect,a),c=me(o,a,s),l=w(e,c,o);T(t,i,o,a,s,c,l),r.set(i.index,E(i,o,a,s,l,n))}}function me(e,t,n){return!!(t&&i(e.rect)&&!i(n))}function w(e,t,n){return!!(e?.projectedOut||t&&O(n))}function T(e,t,n,r,i,a,o){o||a?e.suppressNode(t,[]):r&&i&&!A(n.rect,i)&&b(e.replacements,t,{rect:i})}function E(e,t,n,r,i,a){return{projectedOut:i,...D(e,t,n,r,a)?{clip:r}:n?{clip:n}:{}}}function D(e,t,n,r,a){return!!(i(r)&&(a.has(e.index)||n!==void 0&&p(t.type)))}function O(e){return e.type?.trim().toLowerCase()===`cell`||p(e.type)}function k(e,t){if(!e||!t)return e;let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y),i=Math.min(e.x+e.width,t.x+t.width),a=Math.min(e.y+e.height,t.y+t.height);return{x:n,y:r,width:Math.max(0,i-n),height:Math.max(0,a-r)}}function A(e,t){return!!(e&&e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height)}function j(e,t,n,r){let i=N((e.replacements.get(t.index)??t).rect,n.rect);return ne(e.replacements,t,e=>({rect:i??e.rect,hiddenContentAbove:M(e.hiddenContentAbove,r.above),hiddenContentBelow:M(e.hiddenContentBelow,r.below)})),!!i}function M(e,t){return e===!0||t?!0:void 0}function N(e,t){if(!(!e||!t)&&!(t.height<=0||t.height>=e.height)&&!(t.y<e.y||t.y>e.y+e.height))return{...e,y:t.y,height:Math.min(t.height,e.y+e.height-t.y)}}function P(e,t){for(let n=0;n<e.length;n+=1){let i=e[n],a=i?.label?.trim();i&&a&&r(i.type??``)===`other`&&t(i,a,n)}}function F(e,t){P(e,(n,r,i)=>{if(!c(r)||!n.rect)return;let a=x(e,i,e=>!!e.rect&&ee(e.label?.trim()??``));if(!a?.rect)return;let o=L(n.rect,a.rect);if(!o)return;let s=I(e,i,o);b(t,n,{rect:s}),S(e,i,e=>{c(e.label?.trim()??``)&&b(t,e,{rect:s})})})}function I(e,n,r){let i=r;return S(e,n,e=>{let n=e.label?.trim()??``;!e.rect||!c(n)||t(r,e.rect)&&a(e.rect)<a(i)&&(i=e.rect)}),i}function L(e,t){let n=e.x+e.width,r=t.x+t.width,i={x:t.x,y:e.y,width:n-t.x,height:e.height};if(t.x>e.x&&d(t,i))return{...e,width:t.x-e.x};let a={x:e.x,y:e.y,width:r-e.x,height:e.height};if(r<n&&d(t,a))return{...e,x:r,width:n-r}}function R(e,t){P(e,(n,r,i)=>{u(n)&&l(n,z(e,i))&&t.suppressNode(n,z(e,i))})}function z(e,t){let n=[];return S(e,t,e=>{n.push(e)}),n}function he(e,t){let n=g(e),r=n?n.y+n.height:null;if(r!==null)for(let n=0;n<e.length;n+=1){let i=e[n];!i||!ge(i,r)||(t.suppressNode(i,[]),_e(i,t,r),S(e,n,e=>{t.suppressNode(e,[])}))}}function ge(e,t){return!e.rect||r(e.type??``)!==`keyboard`?!1:e.rect.y>=t}function _e(e,t,n){let r=typeof e.parentIndex==`number`?t.sourceNodesByIndex.get(e.parentIndex):void 0;for(;r?.rect&&r.rect.y>=n;)t.suppressNode(r,[]),r=typeof r.parentIndex==`number`?t.sourceNodesByIndex.get(r.parentIndex):void 0}function ve(e,t){for(let n=0;n<e.length;n+=1){let i=e[n];if(!i)continue;if(ye(i)){B(e,n,i,t);continue}if(!be(i))continue;let a=x(e,n,e=>r(e.type??``)===`searchfield`&&e.label===`Search`);a&&(t.suppressNode(i,[a]),xe(i,a,t),B(e,n,a,t))}}function ye(e){return r(e.type??``)===`searchfield`&&e.label===`Search`}function be(e){let t=r(e.type??``);return e.label===`Toolbar`&&(t===`toolbar`||t===`searchfield`)}function B(e,t,n,r){S(e,t,e=>{e.index!==n.index&&Se(e)&&r.suppressNode(e,[n])})}function xe(e,t,n){let r=e;for(;typeof r.parentIndex==`number`;){let e=n.sourceNodesByIndex.get(r.parentIndex);if(!e||e.label!==`Toolbar`)return;n.suppressNode(e,[t]),r=e}}function Se(e){let t=r(e.type??``);return t===`button`?!1:t===`image`||e.label===`Search`}function Ce(e,t){for(let n=0;n<e.length;n+=1){let r=e[n],i=r?.label?.trim();!r||t.isSuppressed(r)||!i||we(e,n,r,i,t)}}function we(e,t,n,i,a){let o=r(n.type??``);if(o===`statictext`||o===`link`){V(e,t,i,n,a);return}if(o!==`other`)return;let s=Te(e,t,i);if(s){a.suppressNode(n,[s]);return}V(e,t,i,n,a)}function Te(e,t,n){return x(e,t,e=>{let t=r(e.type??``);return(t===`link`||t===`searchfield`||p(e.type))&&e.label?.trim()===n})}function V(e,t,n,r,i){S(e,t,e=>{!i.semanticRepresentativeIndexes.has(e.index)&&ie(e,n)&&i.suppressNode(e,[r])})}function Ee(e,t){P(e,(n,r,i)=>{let a=x(e,i,e=>m(e)&&e.label?.trim()===r&&(d(e.rect,n.rect)||De(n,e)));a&&t.suppressNode(n,[a])})}function De(e,t){if(t.label?.trim()!==e.label?.trim())return!1;let n=r(t.type??``);return Oe(e,n)||n===`textfield`||ke(e,n,t)}function Oe(e,t){let n=e.label?.trim();return t===`button`&&(n===`Dismiss`||n===`Back`)}function ke(e,t,n){return t!==`button`||!e.rect||!n.rect?!1:e.rect.x===0&&e.rect.y===0&&e.rect.width>=300&&e.rect.height>=600&&n.rect.width<e.rect.width}function Ae(e,t){let n=C(e);for(let i of e){if(r(i.type??``)!==`other`||i.hittable===!0||i.label?.trim()||i.value?.trim()||!i.identifier?.trim())continue;let e=je(i,n);(e.length!==0||i.hittable===!1)&&t.suppressNode(i,e)}}function je(e,t){let n=[],r=new Set([e.index]),i=[...t.get(e.index)??[]];for(;i.length>0;){let e=i.pop();if(!e||r.has(e.index))continue;r.add(e.index),n.push(e);let a=t.get(e.index);a&&i.push(...a)}return n}function Me(e,t){he(e,t),Ae(e,t),ue(e,t),ve(e,t),Ee(e,t),F(e,t.replacements),R(e,t),Ce(e,t)}function Ne(e,t){for(let n=0;n<e.length;n+=1){let r=e[n],i=r?Pe(e,n,r,t):void 0;!r?.rect||!i||Le(e,n,r,i,t)}}function Pe(e,t,n,i){let a=n.label?.trim();if(r(n.type??``)!==`cell`||a&&!Fe(a,n.identifier)&&!o(a))return a;let s=v(e,t).find(Ie),c=s?.label?.trim();return!s||!c?a:(b(i.replacements,n,{label:c}),i.suppressNode(s,[n]),c)}function Fe(e,t){return t?.trim()===e&&/^[A-Z_$][A-Za-z0-9_$]*Cell$/.test(e)}function Ie(e){if(!e.label?.trim())return!1;let t=r(e.type??``);return t===`statictext`||t===`text`||t===`textview`}function Le(e,t,n,i,a){let o=r(n.type??``);if(o===`button`){H(v(e,t),i,a,n);return}if(o!==`cell`)return;let s=v(e,t);Re(s,n,i,a)||ze(s,n,i,a)}function Re(e,t,n,r){let i=e.find(e=>Ve(e,t,n));if(!i)return!1;let a=e.find(e=>U(e,t,n)),o=i.identifier?void 0:a?.identifier??t.identifier;return o&&b(r.replacements,i,{identifier:o}),r.suppressNode(t,[i]),Be(e,t,n,i,r),!0}function ze(e,t,n,r){let i=e.find(e=>U(e,t,n));if(!i){e.some(te)&&H(e,n,r,t);return}!t.identifier&&i.identifier&&b(r.replacements,t,{identifier:i.identifier}),r.suppressNode(i,[t]),H(e.filter(e=>e.index!==i.index),n,r,t)}function Be(e,t,n,r,i){for(let a of e)a.index!==r.index&&(U(a,t,n)||W(a,t)||He(a,r)||h(a,n))&&i.suppressNode(a,[r])}function H(e,t,n,r){for(let i of e)(h(i,t)||r&&W(i,r))&&n.suppressNode(i,r?[r]:[])}function U(e,t,n){if(r(e.type??``)!==`button`)return!1;let i=t.identifier?.trim(),a=e.identifier?.trim();return i&&a&&i===a?!0:e.label?.trim()===n&&d(e.rect,t.rect)}function W(e,t){return r(e.type??``)===`button`&&!e.label?.trim()&&!e.value?.trim()&&d(e.rect,t.rect)}function Ve(e,t,n){if(r(e.type??``)!==`switch`)return!1;let i=t.identifier?.trim(),a=e.identifier?.trim();return i&&a&&i===a?!0:e.label?.trim()===n}function He(e,t){if(r(e.type??``)!==`switch`||e.index===t.index)return!1;let n=e.label?.trim();return n===t.value?.trim()||n===`0`||n===`1`}const G=1.15;function Ue(e,t,r){let i=new Map(e.map((e,t)=>[e.index,t]));for(let[a,o]of e.entries()){let s=We(e,i,t,o,r);if(!s)continue;q(e,a,r);let c=J(s.shelfRect,2);for(let t of s.intermediateSiblings){if($e(t)||!t.rect||!n(t.rect,c))continue;let a=i.get(t.index);a!==void 0&&q(e,a,r)}}}function We(e,t,n,r,i){let a=Ge(r,n,i.sourceNodesByIndex);if(!a)return;let o=Je(e,t,a.siblings,a.position,a.parent);if(!(o<0))return{shelfRect:a.rect,intermediateSiblings:a.siblings.slice(a.position+1,o)}}function Ge(e,t,n){let r=Ye(e,K(t,e.index));if(!r)return;let i=qe(e,n);if(!i||!i.rect)return;let a=K(t,i.index),o=a.findIndex(t=>t.index===e.index);if(Ke(a,o,e,r))return{rect:r.rect,parent:i,siblings:a,position:o}}function K(e,t){return e.get(t)??[]}function Ke(e,t,n,r){if(t<1)return!1;let i=Xe(e,t,n);return i?!r.childActionsPresented||!Ze(i,r.actionButtons):!1}function qe(e,t){return typeof e.parentIndex==`number`?t.get(e.parentIndex):void 0}function Je(e,t,n,r,i){return n.findIndex((n,a)=>a>r&&Qe(e,t.get(n.index),n,i))}function Ye(e,n){if(!p(e.type)||!e.rect)return;let i=e.rect,a=n.filter(e=>r(e.type??``)===`button`&&e.rect);if(a.length===0&&e.hiddenContentBelow===!0)return{rect:i,childActionsPresented:!1,actionButtons:a};if(a.length<3)return;let o=a.map(e=>e.rect.x+e.rect.width/2);if(o.every((e,t)=>t===0||e>o[t-1]))return{rect:i,childActionsPresented:a.some(e=>t(i,e.rect)),actionButtons:a}}function Xe(e,t,n){if(!(!n.rect||t<1))for(let r=t-1;r>=0;--r){let t=e[r];if(!(!t.rect||!m(t))&&t.rect.x+t.rect.width/2<n.rect.x&&et(t.rect,J(n.rect,2)))return t}}function Ze(e,t){if(!e.rect||t.length===0)return!1;let n=Math.max(...t.map(e=>e.rect?.width??0)),r=Math.max(...t.map(e=>e.rect?.height??0));return e.rect.width>n*G||e.rect.height>r*G}function Qe(e,t,n,i){return t!==void 0&&r(n.type??``)===`other`&&d(n.rect,i.rect)&&!!x(e,t,m)}function q(e,t,n){let r=e[t];if(r){n.suppressNode(r,[]);for(let r of v(e,t))n.suppressNode(r,[])}}function $e(e){let t=r(e.type??``);return t===`textfield`||t===`securetextfield`||t===`searchfield`||t===`textview`}function J(e,t){return{x:e.x-t,y:e.y-t,width:e.width+t*2,height:e.height+t*2}}function et(e,t){return Math.max(e.y,t.y)<=Math.min(e.y+e.height,t.y+t.height)}function tt(e,t){let n=C(e);Ue(e,n,t),nt(e,n,t)}function nt(e,t,n){for(let i of e){if(r(i.type??``)!==`navigationbar`||!i.rect)continue;let e=t.get(i.index)??[],a=e.flatMap(t=>rt(t,e,i.rect));if(a.length!==1)continue;let{field:o,title:s,image:c,label:l}=a[0];b(n.replacements,o,{type:`Button`,label:l,enabled:!0,hittable:void 0,rect:st([c.rect,o.rect,s.rect])}),n.semanticRepresentativeIndexes.add(o.index),n.suppressNode(s,[o]),n.suppressNode(c,[o])}}function rt(t,n,r){let i=e(t);if(!it(t,i))return[];let a=X(n,e=>at(e,i)),o=X(n,Y);return a?.rect&&o?.rect&&ot(o.rect,t.rect,a.rect,r)?[{field:t,title:a,image:o,label:i}]:[]}function it(e,t){return r(e.type??``)===`textfield`&&e.enabled===!1&&!!e.rect&&!!t&&e.value?.trim()===t}function at(e,t){return r(e.type??``)===`statictext`&&e.label?.trim()===t&&!!e.rect}function Y(e){return r(e.type??``)===`image`&&!!e.identifier?.trim()&&!!e.rect}function X(e,t){let n=e.filter(t);return n.length===1?n[0]:void 0}function ot(e,n,r,i){let a=n.x-(e.x+e.width),o=r.x-(n.x+n.width);return t(i,e)&&t(i,n)&&t(i,r)&&a>=0&&a<=12&&o>=0&&o<=12&&Z(e,n)&&Z(n,r)}function Z(e,t){return Math.max(e.y,t.y)<=Math.min(e.y+e.height,t.y+t.height)}function st(e){let t=Math.min(...e.map(e=>e.x)),n=Math.min(...e.map(e=>e.y)),r=Math.max(...e.map(e=>e.x+e.width)),i=Math.max(...e.map(e=>e.y+e.height));return{x:t,y:n,width:r-t,height:i-n}}function ct(e,t){let n=C(e);for(let i of e){if(r(i.type??``)===`element(58)`){b(t.replacements,i,{type:`WebView`});continue}let e=lt(i,t.sourceNodesByIndex,n);if(e?.kind===`suppress`){t.suppressNode(i,[]);continue}e&&(b(t.replacements,i,{type:e.type,...e.type===`Heading`?{value:void 0}:{}}),t.semanticRepresentativeIndexes.add(i.index))}}function lt(e,t,n){if(r(e.type??``)!==`other`)return null;let i=f(e,t,ft),a=e.label?.trim();return!i||!a?null:dt(e,i,a)?{kind:`suppress`}:ut(e,a,n)?{kind:`semantic`,type:Q(e.value)?`Heading`:`StaticText`}:null}function ut(e,t,n){let i=n.get(e.index);if(i?.length!==1)return!1;let a=i[0];return r(a.type??``)===`statictext`&&a.label?.trim()===t&&!n.has(a.index)}function dt(e,t,n){return e.parentIndex===t.index&&t.label?.trim()===n&&!Q(e.value)}function ft(e){let t=r(e.type??``);return t===`webview`||t===`element(58)`}function Q(e){return/^[1-6]$/.test(e?.trim()??``)}const pt=[ct,tt,ae,Ne,Me];function mt(e){if(e.length===0)return{nodes:e,presentedIndexesBySourceIndex:new Map};let t=new Map,n=new Map,r=new Set,i=new Map(e.map(e=>[e.index,e])),a=new Set,o={replacements:t,semanticRepresentativeIndexes:r,sourceNodesByIndex:i,isSuppressed:e=>a.has(e.index),suppressNode(e,t){if(a.add(e.index),t.length===0)return;let r=n.get(e.index)??new Set;for(let e of t)r.add(e.index);n.set(e.index,r)}};for(let t of pt)t(e,o);if(a.size===0&&t.size===0)return{nodes:e,presentedIndexesBySourceIndex:new Map(e.map(e=>[e.index,[e.index]]))};let s=e.filter(e=>!a.has(e.index)).map(e=>t.get(e.index)??e),c=_(s,a,e),l=new Map(s.map((e,t)=>[e.index,c[t].index]));return{nodes:c,presentedIndexesBySourceIndex:new Map(e.map(e=>[e.index,$(e.index,l,n)]))}}function $(e,t,n,r=new Set){let i=t.get(e);if(i!==void 0)return[i];if(r.has(e))return[];r.add(e);let a=new Set;for(let i of n.get(e)??[])for(let e of $(i,t,n,r))a.add(e);return[...a].sort((e,t)=>e-t)}export{mt as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{D as e,S as t,_ as n,b as r,f as i,o as a}from"./sdk-contracts.js";import{l as o}from"./capture.js";import{r as s}from"./snapshot-capture-annotations.js";import{r as c}from"./snapshot-diagnostics.js";import{f as l}from"./android-input-ownership.js";import{f as u,l as d,y as f}from"./sdk-device.js";import{$n as p,Dr as ee,Jn as te,Kn as ne,Rn as re,Rt as ie,Un as ae,Vt as oe,Wn as se,bt as ce,ct as le,dt as ue,ht as de,lt as fe,tr as m,ut as pe,wt as me}from"./sdk-batch.js";import{A as he,F as ge,N as _e,P as ve,T as ye,a as be,g as xe,o as Se,t as Ce,x as we}from"./runtime.js";import{r as h}from"./success-text.js";import{i as g}from"./click-button.js";import{a as Te,r as _}from"./diagnostics.js";import{t as v}from"./timeouts.js";import"./diagnostics2.js";import"./retry.js";import{i as Ee}from"./rect-center.js";import{t as De}from"./snapshot-state.js";import{n as Oe}from"./request-runtime-binding.js";import{i as ke}from"./lease-context.js";import{o as Ae}from"./tree.js";import{t as je}from"./interactor-types.js";import{randomInt as Me}from"node:crypto";function Ne(e){return e.matchedRefs.length===0?{path:2,outcome:`unverifiable`,reason:`selector-miss`}:e.identitySetRefs.length===0?{path:3,outcome:`unverifiable`,reason:`identity-set-empty`}:e.identitySetRefs.length===1?e.identitySetRefs[0]===e.winnerRef?{path:4,outcome:`verified`}:{path:5,outcome:`unverifiable`,reason:`unique-but-wrong`}:e.siblingMatchRefs.length===1?e.siblingMatchRefs[0]===e.winnerRef?{path:6,outcome:`verified`}:{path:6,outcome:`unverifiable`,reason:`signal-isolated-wrong`}:e.regionMemberRefs!==void 0&&e.regionMemberRefs.length>0&&e.viewportCandidateRef!==void 0?e.viewportCandidateRef===e.winnerRef?{path:6,outcome:`verified`}:{path:6,outcome:`unverifiable`,reason:`signal-isolated-wrong`}:{path:6,outcome:`unverifiable`,reason:`no-signal-isolation`}}let Pe={resolve:async()=>{throw new e(`COMMAND_FAILED`,`Interactor resolution is not composed for this process.`,{reason:`interactor-resolution-missing`})}};function Fe(e){Pe=e}function Ie(){return Pe}var y=class e{#e;constructor(e){this.#e=e}get state(){return this.#e.state}get scope(){return this.#e.scope}get tree(){return this.#e.tree}get generation(){return this.#e.generation}static expire(t){return t.#e.state===`expired`?t:new e({...t.#e,state:`expired`})}};const Le=new y({state:`active`,scope:`all`,tree:void 0,generation:void 0});function Re(e){return new y({state:`active`,...e})}function ze(e){return y.expire(e)}const Be=new WeakMap;function b(e){return e.refFrame??Le}function x(e){return b(e).generation??e.snapshotGeneration}function Ve(e){return b(e).tree}function He(e){Ue(e),e.refFrame=ze(b(e)),e.snapshotScopeSource=void 0}function Ue(e){let t=We(e)+1;return Be.set(e,t),t}function We(e){return Be.get(e)??0}function Ge(e){qe(e,`all`)}function Ke(e,t){qe(e,t)}function qe(e,t){e.refFrame=Re({scope:t,tree:e.snapshot,generation:e.snapshotGeneration})}function Je(e){return b(e).state}function Ye(e){return b(e).scope}function Xe(e){let t=e.ref.startsWith(`@`)?e.ref.slice(1):e.ref;return{admission:Ze({session:e.session,refBody:t,mintedGeneration:e.mintedGeneration}),scope:Ye(e.session),currentGeneration:x(e.session)}}function Ze(e){let{session:t,refBody:n,mintedGeneration:r}=e;if(Je(t)===`expired`)return{admitted:!1,reason:`ref_frame_expired`};if(r!==void 0&&r!==x(t))return{admitted:!1,reason:`ref_generation_mismatch`};let i=Ye(t);if(i!==`all`){if(r===void 0)return{admitted:!1,reason:`plain_ref_requires_complete_frame`};if(!i.has(n))return{admitted:!1,reason:`ref_not_issued`}}return{admitted:!0}}const Qe=[250,400,600];function $e(e){return e===`press`||e===`click`||e===`back`||e===`open`}function S(e){return e.map(e=>[e.depth??0,e.type??``,e.label??``,e.value??``,e.identifier??``,e.enabled===!1?`disabled`:`enabled`,e.hittable===!0?`hittable`:`not-hittable`].join(`|`))}function et(e,t){return e<12?!1:t<=Math.floor(e*.2)}function tt(e,t,n){return n.interactiveOnly&&e.snapshot.nodes.length===0&&e.rawNodeCount!==void 0&&e.rawNodeCount>=12?`empty-interactive`:n.mode===`ref-refresh`?null:et(t.baselineCount,e.snapshot.nodes.length)?nt(e.snapshot)?null:`sharp-drop`:t.routeComparable&&$e(t.action)&&rt(t.baselineSignatures,e.snapshot.nodes)?`stuck-route`:null}function nt(e){return e.nodes.some(e=>e.hittable===!0||!!e.label?.trim()||!!e.value?.trim()||!!e.identifier?.trim())}function rt(e,t){if(!e||e.length===0)return!1;let n=Math.max(e.length,t.length);if(n<12)return!1;let r=S(t),i=Math.min(e.length,r.length),a=0;for(let t=0;t<i;t+=1)e[t]===r[t]&&(a+=1);let o=Math.max(0,r.length-e.length),s=Math.max(0,e.length-r.length),c=Math.max(3,Math.floor(n*.15));return a>=Math.floor(n*.9)&&o<=c&&s<=c}async function it(e){let t=e.window.markedAt+e.retry.retryBudgetMs,n=await e.capture(),r=e.classify(n),i=0;for(let a of e.retry.delaysMs){if(!r)break;let o=t-Date.now();if(o<=0)break;await v(Math.min(a,o)),n=await e.capture(),i+=1,r=e.classify(n)}r||e.onTrustworthyCapture?.();let a=i>0||r?{action:e.window.action,retryCount:i,staleAfterRetries:!!r,reason:r??void 0}:void 0;return{...n,annotations:{...n.annotations,...s({freshness:a})}}}function at(e,t,n=e.snapshot){if(e.device.platform!==`android`)return;let r=ot(e,n),i=r?.comparisonSafe===!0;e.androidSnapshotFreshness={action:t,markedAt:Date.now(),baselineCount:(r??n)?.nodes.length??0,baselineSignatures:i?S(r?.nodes??[]):void 0,routeComparable:i}}function ot(e,t){if(t?.comparisonSafe===!0)return t;let n=e.lastComparisonSafeSnapshot;return!n||n.comparisonSafe!==!0?t:Date.now()-n.createdAt<=5e3?n:t}function C(e){if(!e||e.device.platform!==`android`)return;let t=e.androidSnapshotFreshness;if(t){if(Date.now()-t.markedAt>2500){delete e.androidSnapshotFreshness;return}return t}}function w(e){!e||e.device.platform!==`android`||delete e.androidSnapshotFreshness}async function st(e,t){return it({capture:e.capture,classify:n=>tt({snapshot:n.snapshot,rawNodeCount:n.annotations.analysis?.rawNodeCount},t,{interactiveOnly:e.interactiveOnly,mode:e.androidFreshnessMode}),window:t,retry:{retryBudgetMs:1500,delaysMs:Qe},onTrustworthyCapture:()=>w(e.session)})}function ct(e,t){return`${[e,...t].join(` `).trim()} produced no visible change: the tree still matches its pre-gesture state. Either the container is already at its edge, or it ignores synthesized scrolls — a raw drag moves such lists: swipe x1 y1 x2 y2 (start inside the list).`}function lt(e,t){return t?{...e,warnings:[...e.warnings??[],ct(t.action,t.positionals)]}:e}const ut=`activity.launchConsole.launchArgs.clearAppState.verbose.iosXctestrunFile.iosXctestDerivedDataPath.iosXctestEnvDir.snapshotInteractiveOnly.snapshotPreferredBackend.snapshotDepth.snapshotScope.snapshotRaw.snapshotCustomActions.snapshotIncludeHiddenContentHints.count.intervalMs.delayMs.durationMs.holdMs.jitterPx.pixels.until.doubleTap.backMode.pauseMs.pattern`.split(`.`);function dt(e){return Object.fromEntries(ut.map(t=>[t,e?.[t]]))}function T(e,t,n,r,i,a){return{requestId:i??Te().requestId,appBundleId:n,runnerLeaseContext:ke({meta:a}),logPath:e,traceLogPath:r,...dt(t),screenshotCaptureBackend:t?.maestro?.screenshotCaptureBackend,...o(t),clickButton:g(t)}}function ft(e){return e?.interactionOutcome?.retryOnNoChange===!0}function pt(e){let{session:t,command:n,positionals:r,flags:i,preSnapshot:a}=e;if(!ft(i)||!F(t))return;let o=xt(n);if(!o||!Et(r))return;let s=A(a?.nodes??[]);s.length!==0&&(t.pendingInteractionOutcome={action:n,command:o,positionals:r,flags:k(i),markedAt:Date.now(),attemptsRemaining:2,preSignature:s})}function mt(e){let t=e?.pendingInteractionOutcome;if(!(!e||!t)){if(!F(e)){E(e);return}if(Date.now()-t.markedAt>3e4){E(e);return}return t}}function E(e){e?.pendingInteractionOutcome&&(e.pendingInteractionOutcome=void 0)}async function D(e){let{pending:t,snapshot:n}=e,r=j(t.preSignature,A(n.nodes));if(r!==`unchanged`||t.attemptsRemaining<=0)return{retried:!1,change:r};let i=e.retryTap,a=i?I(t.positionals):void 0;if(!i||!a)return O(t,i?`unreadable-retry-point`:`device-runtime-unavailable`),{retried:!1,change:r};let o=Date.now();return--t.attemptsRemaining,await ht(i,e)?(_({level:`info`,phase:`interaction_no_change_retry`,data:{action:t.action,attemptsRemaining:t.attemptsRemaining,durationMs:Date.now()-o}}),{retried:!0,change:r}):(O(t,`retry-tap-unavailable`),{retried:!1,change:r})}async function ht(e,t){let{session:n,pending:r}=t,i=I(r.positionals);if(!i)return!1;try{return await e({device:n.device,point:i,context:{...T(t.logPath,r.flags,n.appBundleId,n.trace?.outPath),surface:n.surface}})}catch{return!1}}function O(e,t){_({level:`info`,phase:`interaction_no_change_retry_skipped`,data:{action:e.action,attemptsRemaining:e.attemptsRemaining,reason:t}})}function gt(e){_({level:e.attempts>0?`info`:`debug`,phase:`interaction_settled`,data:{action:e.pending.action,change:e.change,attempts:e.attempts,durationMs:Date.now()-e.startedAt}})}function _t(e){_({level:`warn`,phase:`interaction_settle_timeout`,data:{action:e.pending.action,attempts:e.attempts,durationMs:Date.now()-e.startedAt}})}function k(e){if(!e?.interactionOutcome&&!e?.postGestureStabilization)return e;let{interactionOutcome:t,postGestureStabilization:n,...r}=e;return r}function A(e){let t=new Map,n=[],r=he(e);for(let i of e){let e=St(i,t,r);e&&n.push(e)}return n}function j(e,t){return e.length===0||t.length===0?`ambiguous`:N(e,t)?`unchanged`:`changed`}function M(e,t){return Math.abs(e.x-t.x)<=1&&Math.abs(e.y-t.y)<=1&&Math.abs(e.width-t.width)<=1&&Math.abs(e.height-t.height)<=1}function N(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1){let r=e[n],i=t[n];if(!r||!i||r.key!==i.key||!M(r,i))return!1}return!0}function vt(e,t){let n=P(e),r=P(t);if(n.size===0||r.size===0)return`ambiguous`;let i=0,a=!1;for(let[e,t]of n){let n=r.get(e);if(!n){a=!0;continue}if(i+=1,!M(t,n))return`changed`}if(i===0)return`ambiguous`;let o=r.size>i;return a&&o?`changed`:`unchanged`}function P(e){let t=new Map;for(let n of e)!n.identity||!n.discriminating||t.has(n.identity)||t.set(n.identity,n);return t}function yt(e,t){let n=e.filter(e=>e.discriminating),r=t.filter(e=>e.discriminating);if(n.length===0||n.length!==r.length)return!1;let i=new Map(r.map(e=>[e.key,e]));for(let e of n){let t=i.get(e.key);if(!t||!M(e,t))return!1}return!0}function bt(e,t){let n=new Map(t.filter(e=>e.discriminating).map(e=>[e.key,e])),r=0,i=0,a=0;for(let t of e){if(!t.discriminating)continue;let e=n.get(t.key);if(!e){r+=1;continue}n.delete(t.key),a+=1,M(t,e)||(i+=1)}return{onlyInBaseline:r,onlyInCurrent:n.size,rectMismatched:i,shared:a}}function F(e){return u(e.device)}function I(e){let t=Number(e[0]),n=Number(e[1]);return Number.isFinite(t)&&Number.isFinite(n)?{x:t,y:n}:void 0}function xt(e){if(e===`click`||e===`press`)return`press`}function St(e,t,n){if(!e.rect||!Dt(e.rect)||Ot(e))return;let r=Tt(e);if(!r)return;let i=t.get(r)??0;t.set(r,i+1);let a=Ct(e);return{key:`${r}|#${i}`,...a?{identity:a}:{},x:Math.round(e.rect.x),y:Math.round(e.rect.y),width:Math.round(e.rect.width),height:Math.round(e.rect.height),discriminating:!wt(e,n)}}function Ct(e){let t=[e.identifier,e.label,e.value].map(e=>typeof e==`string`?e.trim():``).join(`|`);if(t.replaceAll(`|`,``))return`${t}|${e.type??``}`}function wt(e,t){return ee(e)||e.ref!==void 0&&t.has(e.ref)}function Tt(e){let t=[e.identifier,e.label,e.value,e.type,e.role,e.enabled===!1?`disabled`:`enabled`,e.selected===!0?`selected`:`unselected`,e.hittable===!0?`hittable`:`not-hittable`].map(e=>typeof e==`string`?e.trim():``).join(`|`);return t.replaceAll(`|`,``)?t:void 0}function Et(e){return e.length===2&&e.every(e=>Number.isFinite(Number(e)))}function Dt(e){return[e.x,e.y,e.width,e.height].every(e=>Number.isFinite(e))&&e.width>0&&e.height>0}function Ot(e){return`${e.label??``} ${e.identifier??``}`.toLowerCase().includes(`scroll bar`)}const L=3500;function kt(e){let{needsBaselineDistrust:t,baselineSignature:n,quietSignature:r,elapsedMs:i,distrustCapMs:a}=e;return!t||!n?.length||e.classifyBaselineEvidence(n,r)!==`unchanged`?`trust`:i<a?`distrust`:`accept-stale`}async function At(e){let{pending:t,needsBaselineDistrust:n,hooks:r}=e,i=Date.now(),a=1,o=await R(r,e.initial),s=t.baselineSignature,c=t.baselineBackend,l=!1,u=1500;for(;a<2||Date.now()-i<u;){await v(200),a+=1;let e=await R(r);if(r.signaturesStable(o.signature,e.signature)){let d=Date.now()-i;if(s&&c!==e.backend){_({level:`debug`,phase:`post_gesture_snapshot_baseline_rebased`,data:{action:t.action,from:c,to:e.backend,attempts:a}}),s=e.signature,c=e.backend,l=!0,o=e;continue}let f=kt({needsBaselineDistrust:n,baselineSignature:s,quietSignature:e.signature,elapsedMs:d,distrustCapMs:L,classifyBaselineEvidence:r.classifyBaselineEvidence});if(f===`distrust`){u=L,o=e;continue}return jt(f,t.action,a,d),Mt(f,t,e,r,l)}o=e}return _({level:`warn`,phase:`post_gesture_snapshot_stabilization_timeout`,data:{action:t.action,attempts:a,durationMs:Date.now()-i}}),{value:o.value}}async function R(e,t){let n=t??await e.capture();return{value:n,...e.readSurface(n)}}function jt(e,t,n,r){if(e===`accept-stale`){_({level:`warn`,phase:`post_gesture_snapshot_stale_accept`,data:{action:t,attempts:n,durationMs:r,matchedPreGestureBaseline:!0}});return}_({level:n>2?`info`:`debug`,phase:`post_gesture_snapshot_stabilized`,data:{action:t,attempts:n,durationMs:r}})}function Mt(e,t,n,r,i){if(e!==`accept-stale`)return{value:n.value};let a=t.baselineSignature;return a!==void 0&&r.surfacesIdentical(a,n.signature)?{value:n.value,gestureNoEffect:{action:t.action,positionals:t.positionals}}:(_({level:`info`,phase:`post_gesture_no_effect_vetoed`,data:{action:t.action,backend:n.backend,...i?{reason:`baseline_rebased`}:{reason:`surface_divergence`,...a===void 0?{}:r.summarizeDivergence(a,n.signature)}}}),{value:n.value})}function Nt(e){let{session:t,command:n,action:r=n,positionals:i,flags:a,scheduleOutcomeRetry:o=!1,androidFreshnessBaseline:s}=e;o&&pt({session:t,command:n,positionals:i,flags:a,preSnapshot:t.snapshot}),$e(r)&&at(t,r,s??t.snapshot),Pt(t,r,i,a)}function Pt(e,t,n=[],r){if(!W(e.device)||!zt(t,n,r))return;let i=G(e.device)?A(e.snapshot?.nodes??[]):void 0;e.postGestureStabilization={action:t,positionals:n,markedAt:Date.now(),...i?.length?{baselineSignature:i,baselineBackend:U(e.snapshot)}:{}}}function Ft(e){e?.postGestureStabilization&&(e.postGestureStabilization=void 0)}function z(e){return!!e?.postGestureStabilization}async function It(e){let t=mt(e.session);if(t&&e.session)return await Lt({...e,session:e.session},t);if(u(e.device)&&e.session&&z(e.session))return await Rt({...e,session:e.session});let n=C(e.session);if(n&&e.device.platform===`android`){let t=await st(e,n);return{snapshot:t.snapshot,...t.annotations}}}async function Lt(e,t){let n=e.session,r=Date.now(),i=0,a=await B(e,t,await V(e)),o=await D({session:n,pending:t,logPath:e.logPath,snapshot:a.snapshot,retryTap:e.retryTap});for(;o.retried;)i+=1,a=await B(e,t,await V(e)),o=await D({session:n,pending:t,logPath:e.logPath,snapshot:a.snapshot,retryTap:e.retryTap});E(n);let s=await H({session:n,initial:a,capture:async()=>await V(e),readSnapshot:e=>e.snapshot});return a=s.value,o.change!==`ambiguous`&&a.annotations.freshness?.staleAfterRetries!==!0&&w(n),o.change===`unchanged`?_t({pending:t,attempts:i,startedAt:r}):gt({pending:t,change:o.change,attempts:i,startedAt:r}),{snapshot:a.snapshot,...lt(a.annotations,s.gestureNoEffect)}}async function B(e,t,n){let r=n;return j(t.preSignature,A(r.snapshot.nodes))===`unchanged`?(await v(500),r=await V(e),r):r}async function Rt(e){let t=await H({session:e.session,capture:async()=>await V(e),readSnapshot:e=>e.snapshot}),n=t.value;return{snapshot:n.snapshot,...lt(n.annotations,t.gestureNoEffect)}}async function V(e){let t=C(e.session);return t&&e.device.platform===`android`?await st(e,t):await e.capture()}async function H(e){let{session:t,capture:n,readSnapshot:r}=e,i=t?.postGestureStabilization;if(!t||!W(t.device)||!i)return{value:e.initial??await n()};let a=await At({pending:{action:i.action,positionals:i.positionals??[],baselineSignature:i.baselineSignature,baselineBackend:i.baselineBackend},needsBaselineDistrust:G(t.device),initial:e.initial,hooks:{capture:n,readSurface:e=>{let t=r(e);return{signature:A(t.nodes),backend:U(t)}},signaturesStable:N,classifyBaselineEvidence:vt,surfacesIdentical:yt,summarizeDivergence:bt}});return Ft(t),a}function U(e){return e?.comparisonKey??e?.snapshotQuality?.backend}function zt(e,t,n){return n?.postGestureStabilization===!1?!1:n?.postGestureStabilization===!0||e===`swipe`||e===`scroll`||e===`gesture`&&t[0]===`swipe`}function W(e){return u(e)}function G(e){return d(e.platform)}function Bt(e,t={}){let n=t.mode??`action`,{node:r,preActionNodes:i}=e;if(typeof r.index!=`number`)return;let a=ve(i),o=re(K(r),i);if(n===`landmark`&&o.id===void 0&&o.label===void 0)return;let s=_e(r,a,8),c=s.chain,l=q(i,r),u=J(r,a),d=Gt(r),f=+(c.length>0),p=e=>{let t=c.slice(0,e),n=Kt({nodes:i,byIndex:a,node:r,identity:o,ancestry:t,sibling:l,scrollRegion:u});return{candidate:{...o,ancestry:t,sibling:l,viewportOrder:n.viewportOrder,...u?{scrollRegion:u}:{},...d?{rect:d}:{},verification:`verified`},domain:n}};for(let e=c.length;e>=f;--e){let{candidate:t,domain:i}=p(e);if(Ht(t))return t.verification=Vt({node:r,domain:i,mode:n,brokenWalk:s.broken}),t;if(e===f)return Ut(t)}}function Vt(e){return e.brokenWalk?`unverifiable`:e.mode===`landmark`?`verified`:Jt({node:e.node,domain:e.domain})}function Ht(e){return m(p({...e,verification:`unverifiable`}))<=te}function Ut(e){return e.verification=`unverifiable`,m(p(e))>4096&&delete e.rect,e}const K=se;function q(e,t){return ne(e,t)}function J(e,t){let n=Ae(e,t);if(!n)return;let r=K(n);return{role:r.role,...r.id===void 0?r.label===void 0?{}:{label:r.label}:{id:r.id}}}function Wt(e,t){return!e&&!t?!0:!e||!t?!1:ae(e,t)}function Gt(e){let t=e.rect;if(t)return{x:t.x,y:t.y,width:t.width,height:t.height}}function Kt(e){let{nodes:t,byIndex:n,node:r,identity:i,ancestry:a,sibling:o,scrollRegion:s}=e,c=ge(t,n,i,a),l=c.filter(e=>q(t,e)===o),u=c.length>0?c.filter(e=>Wt(J(e,n),s)):void 0,d=u?qt(u):[];return{identitySet:c,siblingMatches:l,regionMembers:u,orderedRegion:d,viewportOrder:Math.max(d.findIndex(e=>e.index===r.index),0)}}function qt(e){return e.map((e,t)=>({node:e,documentOrder:t,center:Ee(e.rect)})).sort((e,t)=>!e.center&&!t.center?e.documentOrder-t.documentOrder:e.center?t.center?e.center.y===t.center.y?e.center.x===t.center.x?e.documentOrder-t.documentOrder:e.center.x-t.center.x:e.center.y-t.center.y:-1:1).map(e=>e.node)}function Jt(e){let{node:t,domain:n}=e,r=t.ref,i=n.identitySet.map(e=>e.ref);return Ne({winnerRef:r,matchedRefs:i,identitySetRefs:i,siblingMatchRefs:n.siblingMatches.map(e=>e.ref),regionMemberRefs:n.regionMembers?.map(e=>e.ref),viewportCandidateRef:n.orderedRegion[n.viewportOrder]?.ref}).outcome}let Y;async function Yt(){if(Y)return Y;let{createAppleSessionObservation:e}=await import(`./session-observation.js`),{listLocalDeviceInventory:t,shouldPropagateDeviceInventoryProbeError:n}=await import(`./device-inventory-context.js`).then(e=>e.t);return Y??=e({listLocalDevices:t,shouldPropagateProbeError:n}),Y}const Xt=Object.freeze({async observeRunnerSession(e){return(await Yt()).observeRunnerSession(e)},async resolveSoleForegroundApp(e){return(await Yt()).resolveSoleForegroundApp(e)}});async function Zt(e,t,n,r){let{queryAppleRunnerSelector:i}=await import(`./runner-operations-facade.js`);return await i(e,t,n,r)}async function X(e){let t=await en(e.inspectFacts)(e.device);for(let n of e.required){let r=t.operations[n];if(!r.available)return{type:`response`,response:e.unavailableResponse?e.unavailableResponse(r):a(`UNSUPPORTED_OPERATION`,`${e.command} is not supported on this device`,void 0,r.hint?{hint:r.hint}:void 0)}}return{type:`admitted`,bind:tn(e.bindDevice)}}async function Qt(e){let t=await X({...e,required:e.use.required});if(t.type===`response`)return t;let n=await t.bind(e.device,e.use);return e.readiness!==void 0&&await Oe(n,e.readiness),{type:`runtime`,runtime:n}}async function $t(e,t){let n=await Qt(e);if(n.type===`response`)return{ok:!1,response:n.response};let r=n.runtime;return{ok:!0,execute:async({dispatchContext:e})=>await t(r,e)}}function en(t){if(t)return t;throw new e(`COMMAND_FAILED`,`Device runtime facts inspection is unavailable.`,{reason:`runtime-gateway-missing`})}function tn(t){if(t)return t;throw new e(`COMMAND_FAILED`,`Device runtime binding is unavailable.`,{reason:`runtime-gateway-missing`})}function nn(e){let{flags:n,logPath:r,meta:a,session:o,snapshotScope:s}=e,{appBundleId:c,trace:l,surface:u}=o??{},d=e.context??T(r??``,n,c,l?.outPath,a?.requestId,a);return{options:{appBundleId:c,...t(n,i),scope:s,includeRects:e.includeRects,surface:u},execution:Z(d),...e.signal===void 0?{}:{signal:e.signal}}}function Z(e){return{requestId:e.requestId,verbose:e.verbose,logPath:e.logPath,traceLogPath:e.traceLogPath,iosXctestrunFile:e.iosXctestrunFile,iosXctestDerivedDataPath:e.iosXctestDerivedDataPath,iosXctestEnvDir:e.iosXctestEnvDir,runnerLeaseContext:e.runnerLeaseContext}}function rn(e){let t=xe(e);return{...t,capture:Ce(t),selectors:Se(t),interactions:be(t)}}async function an(e){let t=await(await Ie().resolve(e.device,e.runnerContext)).snapshot(e.options);if(!(`stage`in t))return t;let{presentIosSnapshotAcquisition:n}=await import(`./ios-snapshot-runtime.js`);return await n(t,e.options)}function on(e){let t=e?e.textEntryReadiness:void 0,n=dn(t)?{textEntryReadiness:t}:{},r=sn(e);return r?{...n,...r}:n}function sn(e){if(!cn(e))return null;let t=ln(e.target);return t?{verification:`unconfirmed`,requested:e.requested,before:e.before,after:e.after,target:t}:null}function cn(e){return!!(e&&e.verification===`unconfirmed`&&typeof e.requested==`string`&&Q(e.before)&&Q(e.after))}function ln(e){if(!pn(e)||!un(e))return null;let t=fn(e.rect);return t?{resourceId:e.resourceId,className:e.className,packageName:e.packageName,rect:t}:null}function un(e){return Q(e.resourceId)&&Q(e.className)&&Q(e.packageName)}function dn(e){return typeof e==`string`&&je.includes(e)}function Q(e){return e===null||typeof e==`string`}function fn(e){return!pn(e)||![e.x,e.y,e.width,e.height].every(e=>typeof e==`number`)?null:e}function pn(e){return!!e&&typeof e==`object`}async function mn(e){let t={device:e.device,inspectFacts:e.inspectFacts,bindDevice:e.bindDevice},n=ie(e.command,e.requiresCapture),r=await X({command:e.command,required:n.use.required,...e.unavailableResponse?{unavailableResponse:e.unavailableResponse}:{},...t});if(r.type===`response`)return{ok:!1,response:r.response};let i=r.bind;switch(n.kind){case`tap-point`:return{ok:!0,runtime:{kind:`tap`,captured:!1,runtime:await i(e.device,oe)}};case`captured-tap`:return{ok:!0,runtime:{kind:`tap`,captured:!0,runtime:await i(e.device,ue)}};case`long-press-point`:return{ok:!0,runtime:{kind:`long-press`,captured:!1,runtime:await i(e.device,me)}};case`captured-long-press`:return{ok:!0,runtime:{kind:`long-press`,captured:!0,runtime:await i(e.device,pe)}};case`hover-point`:return{ok:!0,runtime:{kind:`hover`,captured:!1,runtime:await i(e.device,ce)}};case`captured-hover`:return{ok:!0,runtime:{kind:`hover`,captured:!0,runtime:await i(e.device,fe)}};case`fill-point`:return{ok:!0,runtime:{kind:`fill`,captured:!1,runtime:await i(e.device,de)}};case`captured-fill`:return{ok:!0,runtime:{kind:`fill`,captured:!0,runtime:await i(e.device,le)}}}}function hn(e,t){let n={execution:Z(t),appBundleId:t.appBundleId},r=e.captured?xn(e.runtime):void 0;switch(e.kind){case`tap`:return gn(e,t,n,r);case`long-press`:return _n(e,n,r);case`hover`:return vn(e,n,r);case`fill`:return yn(e,t,n,r)}}function gn(e,t,n,r){let i=e.captured?e.runtime.operations.tapRef:void 0,a=e.captured?e.runtime.operations.tapElementSelector:void 0;return Object.freeze({captureSnapshot:r,tapPoint:async(r,i={})=>{let a=Sn(i,t),o=await e.runtime.operations.tapPoint({point:r,options:a,...n});return{x:r.x,y:r.y,count:a.count,intervalMs:a.intervalMs,holdMs:a.holdMs,jitterPx:a.jitterPx,doubleTap:a.doubleTap,...a.button===`primary`?{}:{button:a.button},...o??{},...h(Tn(r,a.button))}},tapRef:i?async e=>await i({ref:e,...n}):void 0,tapElementSelector:e.captured&&a?async t=>{let r=await e.runtime.operations.tapElementSelector?.({selector:t,...n}),i=r?.maestroNonHittableCoordinateFallbackUsed===!0;return{selector:t.raw,...r??{},...h(i?`tapped via non-hittable coordinate fallback`:`Tapped ${t.raw}`)}}:void 0})}function _n(e,t,n){return Object.freeze({captureSnapshot:n,longPressPoint:async(n,r)=>{let i=await e.runtime.operations.longPressPoint({point:n,durationMs:r,...t});return{x:n.x,y:n.y,durationMs:r,...i??{},...h(`Long pressed (${n.x}, ${n.y})`)}}})}function vn(e,t,n){let r=e.captured?e.runtime.operations.hoverRef:void 0;return Object.freeze({captureSnapshot:n,hoverPoint:async n=>{let r=await e.runtime.operations.hoverPoint({point:n,...t});return{x:n.x,y:n.y,...r??{},...h(`Hovered (${n.x}, ${n.y})`)}},hoverRef:r?async e=>await r({ref:e,...t}):void 0})}function yn(e,t,n,r){let i=e.captured?e.runtime.operations.fillRef:void 0,a=e=>we(e??t.delayMs??0,`delay-ms`,0,1e4);return Object.freeze({captureSnapshot:r,fillPoint:async(t,r,i={})=>{let o=a(i.delayMs),s=await e.runtime.operations.fillPoint({point:t,text:r,delayMs:o,allowNonHittableCoordinateFallback:i.allowNonHittableCoordinateFallback===!0,...n});return{x:t.x,y:t.y,text:r,delayMs:o,...bn(s)?{maestroNonHittableCoordinateFallbackUsed:!0}:{},...on(s),...h(`Filled ${Array.from(r).length} chars`)}},fillRef:i?async(e,t,r={})=>await i({ref:e,text:t,delayMs:a(r.delayMs),...n}):void 0})}function bn(e){return typeof e==`object`&&!!e&&`maestroNonHittableCoordinateFallbackUsed`in e&&e.maestroNonHittableCoordinateFallbackUsed===!0}function xn(e){return async t=>await e.operations.captureSnapshot(t)}function Sn(e,t){let n=Cn(e,t);return wn(n),{button:e.button??g(t),...n,surface:e.surface??t.surface}}function Cn(e,t){return{count:$(e.count,t.count,1,`count`,1,200),intervalMs:$(e.intervalMs,t.intervalMs,0,`interval-ms`,0,1e4),holdMs:$(e.holdMs,t.holdMs,0,`hold-ms`,0,1e4),jitterPx:$(e.jitterPx,t.jitterPx,0,`jitter-px`,0,100),doubleTap:e.doubleTap??t.doubleTap??!1}}function $(e,t,n,r,i,a){return we(e??t??n,r,i,a)}function wn(t){if(t.doubleTap&&t.holdMs>0)throw new e(`INVALID_ARGS`,`double-tap cannot be combined with hold-ms`);if(t.doubleTap&&t.jitterPx>0)throw new e(`INVALID_ARGS`,`double-tap cannot be combined with jitter-px`)}function Tn(e,t){return t===`primary`?`Pressed (${e.x}, ${e.y})`:`${t===`secondary`?`Right`:`Middle`} clicked (${e.x}, ${e.y})`}function En(e){let{inspectFacts:t,bindDevice:n}=e;if(!t||!n)return;let r=new Map;return async({device:e,point:i,context:a})=>{let o=r.get(e.id);o||(o=mn({device:e,command:`press`,requiresCapture:!1,inspectFacts:t,bindDevice:n}),r.set(e.id,o));let s=await o;if(!s.ok)return!1;let c=hn(s.runtime,a);return c.tapPoint?(await c.tapPoint(i),!0):!1}}async function Dn(e){let t=await It({session:e.session,device:e.device,logPath:e.logPath,interactiveOnly:e.flags?.snapshotInteractiveOnly===!0,androidFreshnessMode:e.androidFreshnessMode,capture:()=>kn(e),retryTap:En(e)});if(t)return t;let n=await kn(e);return w(e.session),{snapshot:n.snapshot,...n.annotations}}async function On(e){if(e.captureData)return await e.captureData();let{device:n,session:r,logPath:a}=e,o=T(a,An(e),r?.appBundleId,r?.trace?.outPath);return await an({device:n,runnerContext:{requestId:o.requestId,signal:e.signal,appBundleId:o.appBundleId,verbose:o.verbose,logPath:o.logPath,traceLogPath:o.traceLogPath,iosXctestrunFile:o.iosXctestrunFile,iosXctestDerivedDataPath:o.iosXctestDerivedDataPath,iosXctestEnvDir:o.iosXctestEnvDir,runnerLeaseContext:o.runnerLeaseContext},options:{appBundleId:o.appBundleId,signal:e.signal,...t(o,i),includeRects:e.includeRects,surface:r?.surface}})}async function kn(e){let t=Date.now(),n=await On(e);c(e.session,{durationMs:Date.now()-t,backend:n.backend,platform:f(e.device)});let r=s(n),i=l(n,De(n,An(e)));return r.androidSnapshot?.systemSurfaceOnly===!0&&(i.systemSurfaceOnly=!0),{data:n,snapshot:i,annotations:r}}function An(e){return e.snapshotScope===void 0?e.flags:{...e.flags,snapshotScope:e.snapshotScope}}function jn(e,t){if(!e||!e.trim().startsWith(`@`))return{ok:!0,scope:e};if(!t?.snapshot)return a(`INVALID_ARGS`,`Ref scope requires an existing snapshot in session.`);let i=r(e.trim());if(!i)return a(`INVALID_ARGS`,`Invalid ref scope: ${e}`);let o=[t.snapshot,...t.snapshotScopeSource?[t.snapshotScopeSource]:[]],s;for(let e of o){let t=n(e.nodes,i);if(s=t?ye(t,e.nodes):void 0,s)break}return s?{ok:!0,scope:s}:a(`COMMAND_FAILED`,`Ref ${e} not found or has no label`)}function Mn(e,t,n={}){if(!e)return;let r=Ve(e);return{name:t,appBundleId:e.appBundleId,appName:e.appName,...n.includeSnapshot===!0?{snapshot:e.snapshot,...r&&n.omitRefFrameSnapshot!==!0?{refFrameSnapshot:r}:{}}:{},metadata:{surface:e.surface,...n.metadata??{}}}}function Nn(e){return{get:t=>t===e.sessionName?Mn(e.getSession(),e.sessionName,e.recordOptions):void 0,set:t=>{if(t.name!==e.sessionName){_({level:`warn`,phase:`runtime_session_write_skipped`,data:{expected:e.sessionName,received:t.name}});return}e.setRecord(t)}}}function Pn(e,t){e.snapshot!==t&&(e.snapshotGeneration=In(e.snapshotGeneration)),e.snapshot=t,e.snapshotScopeSource=void 0,t.comparisonSafe===!0&&(e.lastComparisonSafeSnapshot=t)}function Fn(e,t){e.snapshotScopeSource=t.scopeSource,e.snapshotGeneration=t.keptCurrentSnapshot?t.previousGeneration:In(t.previousGeneration)}function In(e){return e===void 0?Me(1e5,1e6):e+1}function Ln(e){let t=e.startsWith(`@`)?e.slice(1):e,n=t.indexOf(`~`);return n===-1?t:t.slice(0,n)}function Rn(e,t){let n=new Set;for(let e of t){let t=Ln(e);t.length>0&&n.add(t)}n.size!==0&&Ke(e,n)}function zn(e,t){if(t?.diff)return Rn(e,Bn(t)),e.snapshotGeneration}function Bn(e){let t=[];for(let n of e.diff?.lines??[])n.ref&&t.push(n.ref);for(let n of e.refs??[])t.push(n.ref);for(let n of e.tail??[])t.push(n.ref);return t}function Vn(e){return`Ref @${e.ref.startsWith(`@`)?e.ref.slice(1):e.ref} was minted from snapshot s${e.mintedGeneration} but the session's ref frame is now s${e.currentFrameEpoch} — re-run snapshot -i.`}function Hn(e){let{session:t,ref:n,mintedGeneration:r}=e;if(t&&Je(t)===`expired`)return`The UI may have changed since these refs were issued, so they no longer represent current device state. Take a new snapshot before relying on or interacting with them.`;if(r!==void 0){let e=t?x(t)??0:0;if(r!==e)return Vn({ref:n,mintedGeneration:r,currentFrameEpoch:e})}}export{C as A,Bt as C,Nt as D,z as E,b as F,Fe as I,Ne as L,He as M,Xe as N,k as O,We as P,q as S,Wt as T,$t as _,Fn as a,K as b,On as c,mn as d,rn as f,Qt as g,X as h,Pn as i,Ge as j,T as k,jn as l,Z as m,Rn as n,Nn as o,nn as p,Hn as r,Dn as s,zn as t,hn as u,Xt as v,qt as w,J as x,Zt as y};
|
|
1
|
+
import{D as e,S as t,_ as n,b as r,f as i,o as a}from"./sdk-contracts.js";import{l as o}from"./capture.js";import{r as s}from"./snapshot-capture-annotations.js";import{r as c}from"./snapshot-diagnostics.js";import{f as l}from"./android-input-ownership.js";import{f as u,l as d,y as f}from"./sdk-device.js";import{Gn as p,Ht as ee,Or as te,Tt as ne,Wn as re,Yn as ie,ct as ae,dt as oe,er as se,ht as ce,lt as le,nr as ue,qn as de,ut as fe,xt as pe,zn as me,zt as he}from"./sdk-batch.js";import{A as ge,F as _e,N as ve,P as ye,T as be,a as xe,g as Se,o as Ce,t as we,x as m}from"./runtime.js";import{r as h}from"./success-text.js";import{i as g}from"./click-button.js";import{a as Te,r as _}from"./diagnostics.js";import{t as v}from"./timeouts.js";import"./diagnostics2.js";import"./retry.js";import{i as Ee}from"./rect-center.js";import{t as De}from"./snapshot-state.js";import{n as Oe}from"./request-runtime-binding.js";import{i as ke}from"./lease-context.js";import{o as Ae}from"./tree.js";import{t as je}from"./interactor-types.js";import{randomInt as Me}from"node:crypto";function y(e){return e.matchedRefs.length===0?{path:2,outcome:`unverifiable`,reason:`selector-miss`}:e.identitySetRefs.length===0?{path:3,outcome:`unverifiable`,reason:`identity-set-empty`}:e.identitySetRefs.length===1?e.identitySetRefs[0]===e.winnerRef?{path:4,outcome:`verified`}:{path:5,outcome:`unverifiable`,reason:`unique-but-wrong`}:e.siblingMatchRefs.length===1?e.siblingMatchRefs[0]===e.winnerRef?{path:6,outcome:`verified`}:{path:6,outcome:`unverifiable`,reason:`signal-isolated-wrong`}:e.regionMemberRefs!==void 0&&e.regionMemberRefs.length>0&&e.viewportCandidateRef!==void 0?e.viewportCandidateRef===e.winnerRef?{path:6,outcome:`verified`}:{path:6,outcome:`unverifiable`,reason:`signal-isolated-wrong`}:{path:6,outcome:`unverifiable`,reason:`no-signal-isolation`}}let Ne={resolve:async()=>{throw new e(`COMMAND_FAILED`,`Interactor resolution is not composed for this process.`,{reason:`interactor-resolution-missing`})}};function Pe(e){Ne=e}function Fe(){return Ne}var b=class e{#e;constructor(e){this.#e=e}get state(){return this.#e.state}get scope(){return this.#e.scope}get tree(){return this.#e.tree}get generation(){return this.#e.generation}static expire(t){return t.#e.state===`expired`?t:new e({...t.#e,state:`expired`})}};const Ie=new b({state:`active`,scope:`all`,tree:void 0,generation:void 0});function Le(e){return new b({state:`active`,...e})}function Re(e){return b.expire(e)}const ze=new WeakMap;function x(e){return e.refFrame??Ie}function S(e){return x(e).generation??e.snapshotGeneration}function Be(e){return x(e).tree}function Ve(e){He(e),e.refFrame=Re(x(e)),e.snapshotScopeSource=void 0}function He(e){let t=C(e)+1;return ze.set(e,t),t}function C(e){return ze.get(e)??0}function Ue(e){w(e,`all`)}function We(e,t){w(e,t)}function w(e,t){e.refFrame=Le({scope:t,tree:e.snapshot,generation:e.snapshotGeneration})}function Ge(e){return x(e).state}function Ke(e){return x(e).scope}function qe(e){let t=e.ref.startsWith(`@`)?e.ref.slice(1):e.ref;return{admission:Je({session:e.session,refBody:t,mintedGeneration:e.mintedGeneration}),scope:Ke(e.session),currentGeneration:S(e.session)}}function Je(e){let{session:t,refBody:n,mintedGeneration:r}=e;if(Ge(t)===`expired`)return{admitted:!1,reason:`ref_frame_expired`};if(r!==void 0&&r!==S(t))return{admitted:!1,reason:`ref_generation_mismatch`};let i=Ke(t);if(i!==`all`){if(r===void 0)return{admitted:!1,reason:`plain_ref_requires_complete_frame`};if(!i.has(n))return{admitted:!1,reason:`ref_not_issued`}}return{admitted:!0}}const Ye=[250,400,600];function Xe(e){return e===`press`||e===`click`||e===`back`||e===`open`}function Ze(e){return e.map(e=>[e.depth??0,e.type??``,e.label??``,e.value??``,e.identifier??``,e.enabled===!1?`disabled`:`enabled`,e.hittable===!0?`hittable`:`not-hittable`].join(`|`))}function Qe(e,t){return e<12?!1:t<=Math.floor(e*.2)}function $e(e,t,n){return n.interactiveOnly&&e.snapshot.nodes.length===0&&e.rawNodeCount!==void 0&&e.rawNodeCount>=12?`empty-interactive`:n.mode===`ref-refresh`?null:Qe(t.baselineCount,e.snapshot.nodes.length)?et(e.snapshot)?null:`sharp-drop`:t.routeComparable&&Xe(t.action)&&tt(t.baselineSignatures,e.snapshot.nodes)?`stuck-route`:null}function et(e){return e.nodes.some(e=>e.hittable===!0||!!e.label?.trim()||!!e.value?.trim()||!!e.identifier?.trim())}function tt(e,t){if(!e||e.length===0)return!1;let n=Math.max(e.length,t.length);if(n<12)return!1;let r=Ze(t),i=Math.min(e.length,r.length),a=0;for(let t=0;t<i;t+=1)e[t]===r[t]&&(a+=1);let o=Math.max(0,r.length-e.length),s=Math.max(0,e.length-r.length),c=Math.max(3,Math.floor(n*.15));return a>=Math.floor(n*.9)&&o<=c&&s<=c}async function nt(e){let t=e.window.markedAt+e.retry.retryBudgetMs,n=await e.capture(),r=e.classify(n),i=0;for(let a of e.retry.delaysMs){if(!r)break;let o=t-Date.now();if(o<=0)break;await v(Math.min(a,o)),n=await e.capture(),i+=1,r=e.classify(n)}r||e.onTrustworthyCapture?.();let a=i>0||r?{action:e.window.action,retryCount:i,staleAfterRetries:!!r,reason:r??void 0}:void 0;return{...n,annotations:{...n.annotations,...s({freshness:a})}}}function rt(e,t,n=e.snapshot){if(e.device.platform!==`android`)return;let r=it(e,n),i=r?.comparisonSafe===!0;e.androidSnapshotFreshness={action:t,markedAt:Date.now(),baselineCount:(r??n)?.nodes.length??0,baselineSignatures:i?Ze(r?.nodes??[]):void 0,routeComparable:i}}function it(e,t){if(t?.comparisonSafe===!0)return t;let n=e.lastComparisonSafeSnapshot;return!n||n.comparisonSafe!==!0?t:Date.now()-n.createdAt<=5e3?n:t}function T(e){if(!e||e.device.platform!==`android`)return;let t=e.androidSnapshotFreshness;if(t){if(Date.now()-t.markedAt>2500){delete e.androidSnapshotFreshness;return}return t}}function E(e){!e||e.device.platform!==`android`||delete e.androidSnapshotFreshness}async function at(e,t){return nt({capture:e.capture,classify:n=>$e({snapshot:n.snapshot,rawNodeCount:n.annotations.analysis?.rawNodeCount},t,{interactiveOnly:e.interactiveOnly,mode:e.androidFreshnessMode}),window:t,retry:{retryBudgetMs:1500,delaysMs:Ye},onTrustworthyCapture:()=>E(e.session)})}function ot(e,t){return`${[e,...t].join(` `).trim()} produced no visible change: the tree still matches its pre-gesture state. Either the container is already at its edge, or it ignores synthesized scrolls — a raw drag moves such lists: swipe x1 y1 x2 y2 (start inside the list).`}function st(e,t){return t?{...e,warnings:[...e.warnings??[],ot(t.action,t.positionals)]}:e}const ct=`activity.launchConsole.launchArgs.clearAppState.verbose.iosXctestrunFile.iosXctestDerivedDataPath.iosXctestEnvDir.snapshotInteractiveOnly.snapshotPreferredBackend.snapshotDepth.snapshotScope.snapshotRaw.snapshotCustomActions.snapshotIncludeHiddenContentHints.count.intervalMs.delayMs.durationMs.holdMs.jitterPx.pixels.until.doubleTap.backMode.pauseMs.pattern`.split(`.`);function lt(e){return Object.fromEntries(ct.map(t=>[t,e?.[t]]))}function D(e,t,n,r,i,a){return{requestId:i??Te().requestId,appBundleId:n,runnerLeaseContext:ke({meta:a}),logPath:e,traceLogPath:r,...lt(t),screenshotCaptureBackend:t?.maestro?.screenshotCaptureBackend,...o(t),clickButton:g(t)}}function ut(e){return e?.interactionOutcome?.retryOnNoChange===!0}function dt(e){let{session:t,command:n,positionals:r,flags:i,preSnapshot:a}=e;if(!ut(i)||!L(t))return;let o=yt(n);if(!o||!wt(r))return;let s=M(a?.nodes??[]);s.length!==0&&(t.pendingInteractionOutcome={action:n,command:o,positionals:r,flags:j(i),markedAt:Date.now(),attemptsRemaining:2,preSignature:s})}function ft(e){let t=e?.pendingInteractionOutcome;if(!(!e||!t)){if(!L(e)){O(e);return}if(Date.now()-t.markedAt>3e4){O(e);return}return t}}function O(e){e?.pendingInteractionOutcome&&(e.pendingInteractionOutcome=void 0)}async function k(e){let{pending:t,snapshot:n}=e,r=N(t.preSignature,M(n.nodes));if(r!==`unchanged`||t.attemptsRemaining<=0)return{retried:!1,change:r};let i=e.retryTap,a=i?R(t.positionals):void 0;if(!i||!a)return A(t,i?`unreadable-retry-point`:`device-runtime-unavailable`),{retried:!1,change:r};let o=Date.now();return--t.attemptsRemaining,await pt(i,e)?(_({level:`info`,phase:`interaction_no_change_retry`,data:{action:t.action,attemptsRemaining:t.attemptsRemaining,durationMs:Date.now()-o}}),{retried:!0,change:r}):(A(t,`retry-tap-unavailable`),{retried:!1,change:r})}async function pt(e,t){let{session:n,pending:r}=t,i=R(r.positionals);if(!i)return!1;try{return await e({device:n.device,point:i,context:{...D(t.logPath,r.flags,n.appBundleId,n.trace?.outPath),surface:n.surface}})}catch{return!1}}function A(e,t){_({level:`info`,phase:`interaction_no_change_retry_skipped`,data:{action:e.action,attemptsRemaining:e.attemptsRemaining,reason:t}})}function mt(e){_({level:e.attempts>0?`info`:`debug`,phase:`interaction_settled`,data:{action:e.pending.action,change:e.change,attempts:e.attempts,durationMs:Date.now()-e.startedAt}})}function ht(e){_({level:`warn`,phase:`interaction_settle_timeout`,data:{action:e.pending.action,attempts:e.attempts,durationMs:Date.now()-e.startedAt}})}function j(e){if(!e?.interactionOutcome&&!e?.postGestureStabilization)return e;let{interactionOutcome:t,postGestureStabilization:n,...r}=e;return r}function M(e){let t=new Map,n=[],r=ge(e);for(let i of e){let e=bt(i,t,r);e&&n.push(e)}return n}function N(e,t){return e.length===0||t.length===0?`ambiguous`:F(e,t)?`unchanged`:`changed`}function P(e,t){return Math.abs(e.x-t.x)<=1&&Math.abs(e.y-t.y)<=1&&Math.abs(e.width-t.width)<=1&&Math.abs(e.height-t.height)<=1}function F(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1){let r=e[n],i=t[n];if(!r||!i||r.key!==i.key||!P(r,i))return!1}return!0}function gt(e,t){let n=I(e),r=I(t);if(n.size===0||r.size===0)return`ambiguous`;let i=0,a=!1;for(let[e,t]of n){let n=r.get(e);if(!n){a=!0;continue}if(i+=1,!P(t,n))return`changed`}if(i===0)return`ambiguous`;let o=r.size>i;return a&&o?`changed`:`unchanged`}function I(e){let t=new Map;for(let n of e)!n.identity||!n.discriminating||t.has(n.identity)||t.set(n.identity,n);return t}function _t(e,t){let n=e.filter(e=>e.discriminating),r=t.filter(e=>e.discriminating);if(n.length===0||n.length!==r.length)return!1;let i=new Map(r.map(e=>[e.key,e]));for(let e of n){let t=i.get(e.key);if(!t||!P(e,t))return!1}return!0}function vt(e,t){let n=new Map(t.filter(e=>e.discriminating).map(e=>[e.key,e])),r=0,i=0,a=0;for(let t of e){if(!t.discriminating)continue;let e=n.get(t.key);if(!e){r+=1;continue}n.delete(t.key),a+=1,P(t,e)||(i+=1)}return{onlyInBaseline:r,onlyInCurrent:n.size,rectMismatched:i,shared:a}}function L(e){return u(e.device)}function R(e){let t=Number(e[0]),n=Number(e[1]);return Number.isFinite(t)&&Number.isFinite(n)?{x:t,y:n}:void 0}function yt(e){if(e===`click`||e===`press`)return`press`}function bt(e,t,n){if(!e.rect||!Tt(e.rect)||Et(e))return;let r=Ct(e);if(!r)return;let i=t.get(r)??0;t.set(r,i+1);let a=xt(e);return{key:`${r}|#${i}`,...a?{identity:a}:{},x:Math.round(e.rect.x),y:Math.round(e.rect.y),width:Math.round(e.rect.width),height:Math.round(e.rect.height),discriminating:!St(e,n)}}function xt(e){let t=[e.identifier,e.label,e.value].map(e=>typeof e==`string`?e.trim():``).join(`|`);if(t.replaceAll(`|`,``))return`${t}|${e.type??``}`}function St(e,t){return te(e)||e.ref!==void 0&&t.has(e.ref)}function Ct(e){let t=[e.identifier,e.label,e.value,e.type,e.role,e.enabled===!1?`disabled`:`enabled`,e.selected===!0?`selected`:`unselected`,e.hittable===!0?`hittable`:`not-hittable`].map(e=>typeof e==`string`?e.trim():``).join(`|`);return t.replaceAll(`|`,``)?t:void 0}function wt(e){return e.length===2&&e.every(e=>Number.isFinite(Number(e)))}function Tt(e){return[e.x,e.y,e.width,e.height].every(e=>Number.isFinite(e))&&e.width>0&&e.height>0}function Et(e){return`${e.label??``} ${e.identifier??``}`.toLowerCase().includes(`scroll bar`)}const z=3500;function Dt(e){let{needsBaselineDistrust:t,baselineSignature:n,quietSignature:r,elapsedMs:i,distrustCapMs:a}=e;return!t||!n?.length||e.classifyBaselineEvidence(n,r)!==`unchanged`?`trust`:i<a?`distrust`:`accept-stale`}async function Ot(e){let{pending:t,needsBaselineDistrust:n,hooks:r}=e,i=Date.now(),a=1,o=await B(r,e.initial),s=t.baselineSignature,c=t.baselineBackend,l=!1,u=1500;for(;a<2||Date.now()-i<u;){await v(200),a+=1;let e=await B(r);if(r.signaturesStable(o.signature,e.signature)){let d=Date.now()-i;if(s&&c!==e.backend){_({level:`debug`,phase:`post_gesture_snapshot_baseline_rebased`,data:{action:t.action,from:c,to:e.backend,attempts:a}}),s=e.signature,c=e.backend,l=!0,o=e;continue}let f=Dt({needsBaselineDistrust:n,baselineSignature:s,quietSignature:e.signature,elapsedMs:d,distrustCapMs:z,classifyBaselineEvidence:r.classifyBaselineEvidence});if(f===`distrust`){u=z,o=e;continue}return kt(f,t.action,a,d),At(f,t,e,r,l)}o=e}return _({level:`warn`,phase:`post_gesture_snapshot_stabilization_timeout`,data:{action:t.action,attempts:a,durationMs:Date.now()-i}}),{value:o.value}}async function B(e,t){let n=t??await e.capture();return{value:n,...e.readSurface(n)}}function kt(e,t,n,r){if(e===`accept-stale`){_({level:`warn`,phase:`post_gesture_snapshot_stale_accept`,data:{action:t,attempts:n,durationMs:r,matchedPreGestureBaseline:!0}});return}_({level:n>2?`info`:`debug`,phase:`post_gesture_snapshot_stabilized`,data:{action:t,attempts:n,durationMs:r}})}function At(e,t,n,r,i){if(e!==`accept-stale`)return{value:n.value};let a=t.baselineSignature;return a!==void 0&&r.surfacesIdentical(a,n.signature)?{value:n.value,gestureNoEffect:{action:t.action,positionals:t.positionals}}:(_({level:`info`,phase:`post_gesture_no_effect_vetoed`,data:{action:t.action,backend:n.backend,...i?{reason:`baseline_rebased`}:{reason:`surface_divergence`,...a===void 0?{}:r.summarizeDivergence(a,n.signature)}}}),{value:n.value})}function jt(e){let{session:t,command:n,action:r=n,positionals:i,flags:a,scheduleOutcomeRetry:o=!1,androidFreshnessBaseline:s}=e;o&&dt({session:t,command:n,positionals:i,flags:a,preSnapshot:t.snapshot}),Xe(r)&&rt(t,r,s??t.snapshot),Mt(t,r,i,a)}function Mt(e,t,n=[],r){if(!Rt(e.device)||!Lt(t,n,r))return;let i=zt(e.device)?M(e.snapshot?.nodes??[]):void 0;e.postGestureStabilization={action:t,positionals:n,markedAt:Date.now(),...i?.length?{baselineSignature:i,baselineBackend:G(e.snapshot)}:{}}}function Nt(e){e?.postGestureStabilization&&(e.postGestureStabilization=void 0)}function V(e){return!!e?.postGestureStabilization}async function Pt(e){let t=ft(e.session);if(t&&e.session)return await Ft({...e,session:e.session},t);if(u(e.device)&&e.session&&V(e.session))return await It({...e,session:e.session});let n=T(e.session);if(n&&e.device.platform===`android`){let t=await at(e,n);return{snapshot:t.snapshot,...t.annotations}}}async function Ft(e,t){let n=e.session,r=Date.now(),i=0,a=await H(e,t,await U(e)),o=await k({session:n,pending:t,logPath:e.logPath,snapshot:a.snapshot,retryTap:e.retryTap});for(;o.retried;)i+=1,a=await H(e,t,await U(e)),o=await k({session:n,pending:t,logPath:e.logPath,snapshot:a.snapshot,retryTap:e.retryTap});O(n);let s=await W({session:n,initial:a,capture:async()=>await U(e),readSnapshot:e=>e.snapshot});return a=s.value,o.change!==`ambiguous`&&a.annotations.freshness?.staleAfterRetries!==!0&&E(n),o.change===`unchanged`?ht({pending:t,attempts:i,startedAt:r}):mt({pending:t,change:o.change,attempts:i,startedAt:r}),{snapshot:a.snapshot,...st(a.annotations,s.gestureNoEffect)}}async function H(e,t,n){let r=n;return N(t.preSignature,M(r.snapshot.nodes))===`unchanged`?(await v(500),r=await U(e),r):r}async function It(e){let t=await W({session:e.session,capture:async()=>await U(e),readSnapshot:e=>e.snapshot}),n=t.value;return{snapshot:n.snapshot,...st(n.annotations,t.gestureNoEffect)}}async function U(e){let t=T(e.session);return t&&e.device.platform===`android`?await at(e,t):await e.capture()}async function W(e){let{session:t,capture:n,readSnapshot:r}=e,i=t?.postGestureStabilization;if(!t||!Rt(t.device)||!i)return{value:e.initial??await n()};let a=await Ot({pending:{action:i.action,positionals:i.positionals??[],baselineSignature:i.baselineSignature,baselineBackend:i.baselineBackend},needsBaselineDistrust:zt(t.device),initial:e.initial,hooks:{capture:n,readSurface:e=>{let t=r(e);return{signature:M(t.nodes),backend:G(t)}},signaturesStable:F,classifyBaselineEvidence:gt,surfacesIdentical:_t,summarizeDivergence:vt}});return Nt(t),a}function G(e){return e?.comparisonKey??e?.snapshotQuality?.backend}function Lt(e,t,n){return n?.postGestureStabilization===!1?!1:n?.postGestureStabilization===!0||e===`swipe`||e===`scroll`||e===`gesture`&&t[0]===`swipe`}function Rt(e){return u(e)}function zt(e){return d(e.platform)}function Bt(e,t={}){let n=t.mode??`action`,{node:r,preActionNodes:i}=e;if(typeof r.index!=`number`)return;let a=ye(i),o=me(K(r),i);if(n===`landmark`&&o.id===void 0&&o.label===void 0)return;let s=ve(r,a,8),c=s.chain,l=q(i,r),u=J(r,a),d=Gt(r),f=+(c.length>0),p=e=>{let t=c.slice(0,e),n=Kt({nodes:i,byIndex:a,node:r,identity:o,ancestry:t,sibling:l,scrollRegion:u});return{candidate:{...o,ancestry:t,sibling:l,viewportOrder:n.viewportOrder,...u?{scrollRegion:u}:{},...d?{rect:d}:{},verification:`verified`},domain:n}};for(let e=c.length;e>=f;--e){let{candidate:t,domain:i}=p(e);if(Ht(t))return t.verification=Vt({node:r,domain:i,mode:n,brokenWalk:s.broken}),t;if(e===f)return Ut(t)}}function Vt(e){return e.brokenWalk?`unverifiable`:e.mode===`landmark`?`verified`:Jt({node:e.node,domain:e.domain})}function Ht(e){return ue(se({...e,verification:`unverifiable`}))<=ie}function Ut(e){return e.verification=`unverifiable`,ue(se(e))>4096&&delete e.rect,e}const K=p;function q(e,t){return de(e,t)}function J(e,t){let n=Ae(e,t);if(!n)return;let r=K(n);return{role:r.role,...r.id===void 0?r.label===void 0?{}:{label:r.label}:{id:r.id}}}function Wt(e,t){return!e&&!t?!0:!e||!t?!1:re(e,t)}function Gt(e){let t=e.rect;if(t)return{x:t.x,y:t.y,width:t.width,height:t.height}}function Kt(e){let{nodes:t,byIndex:n,node:r,identity:i,ancestry:a,sibling:o,scrollRegion:s}=e,c=_e(t,n,i,a),l=c.filter(e=>q(t,e)===o),u=c.length>0?c.filter(e=>Wt(J(e,n),s)):void 0,d=u?qt(u):[];return{identitySet:c,siblingMatches:l,regionMembers:u,orderedRegion:d,viewportOrder:Math.max(d.findIndex(e=>e.index===r.index),0)}}function qt(e){return e.map((e,t)=>({node:e,documentOrder:t,center:Ee(e.rect)})).sort((e,t)=>!e.center&&!t.center?e.documentOrder-t.documentOrder:e.center?t.center?e.center.y===t.center.y?e.center.x===t.center.x?e.documentOrder-t.documentOrder:e.center.x-t.center.x:e.center.y-t.center.y:-1:1).map(e=>e.node)}function Jt(e){let{node:t,domain:n}=e,r=t.ref,i=n.identitySet.map(e=>e.ref);return y({winnerRef:r,matchedRefs:i,identitySetRefs:i,siblingMatchRefs:n.siblingMatches.map(e=>e.ref),regionMemberRefs:n.regionMembers?.map(e=>e.ref),viewportCandidateRef:n.orderedRegion[n.viewportOrder]?.ref}).outcome}let Y;async function Yt(){if(Y)return Y;let{createAppleSessionObservation:e}=await import(`./session-observation.js`),{listLocalDeviceInventory:t,shouldPropagateDeviceInventoryProbeError:n}=await import(`./device-inventory-context.js`).then(e=>e.t);return Y??=e({listLocalDevices:t,shouldPropagateProbeError:n}),Y}const Xt=Object.freeze({async observeRunnerSession(e){return(await Yt()).observeRunnerSession(e)},async resolveSoleForegroundApp(e){return(await Yt()).resolveSoleForegroundApp(e)}});async function Zt(e,t,n,r){let{queryAppleRunnerSelector:i}=await import(`./runner-operations-facade.js`);return await i(e,t,n,r)}async function X(e){let t=await en(e.inspectFacts)(e.device);for(let n of e.required){let r=t.operations[n];if(!r.available)return{type:`response`,response:e.unavailableResponse?e.unavailableResponse(r):a(`UNSUPPORTED_OPERATION`,`${e.command} is not supported on this device`,void 0,r.hint?{hint:r.hint}:void 0)}}return{type:`admitted`,bind:tn(e.bindDevice)}}async function Qt(e){let t=await X({...e,required:e.use.required});if(t.type===`response`)return t;let n=await t.bind(e.device,e.use);return e.readiness!==void 0&&await Oe(n,e.readiness),{type:`runtime`,runtime:n}}async function $t(e,t){let n=await Qt(e);if(n.type===`response`)return{ok:!1,response:n.response};let r=n.runtime;return{ok:!0,execute:async({dispatchContext:e})=>await t(r,e)}}function en(t){if(t)return t;throw new e(`COMMAND_FAILED`,`Device runtime facts inspection is unavailable.`,{reason:`runtime-gateway-missing`})}function tn(t){if(t)return t;throw new e(`COMMAND_FAILED`,`Device runtime binding is unavailable.`,{reason:`runtime-gateway-missing`})}function nn(e){let{flags:n,logPath:r,meta:a,session:o,snapshotScope:s}=e,{appBundleId:c,trace:l,surface:u}=o??{},d=e.context??D(r??``,n,c,l?.outPath,a?.requestId,a);return{options:{appBundleId:c,...t(n,i),scope:s,includeRects:e.includeRects,surface:u},execution:Z(d),...e.signal===void 0?{}:{signal:e.signal}}}function Z(e){return{requestId:e.requestId,verbose:e.verbose,logPath:e.logPath,traceLogPath:e.traceLogPath,iosXctestrunFile:e.iosXctestrunFile,iosXctestDerivedDataPath:e.iosXctestDerivedDataPath,iosXctestEnvDir:e.iosXctestEnvDir,runnerLeaseContext:e.runnerLeaseContext}}function rn(e){let t=Se(e);return{...t,capture:we(t),selectors:Ce(t),interactions:xe(t)}}async function an(e){let t=await(await Fe().resolve(e.device,e.runnerContext)).snapshot(e.options);if(!(`stage`in t))return t;let{presentIosSnapshotAcquisition:n}=await import(`./ios-snapshot-runtime.js`);return await n(t,e.options)}function on(e){let t=e?e.textEntryReadiness:void 0,n=dn(t)?{textEntryReadiness:t}:{},r=sn(e);return r?{...n,...r}:n}function sn(e){if(!cn(e))return null;let t=ln(e.target);return t?{verification:`unconfirmed`,requested:e.requested,before:e.before,after:e.after,target:t}:null}function cn(e){return!!(e&&e.verification===`unconfirmed`&&typeof e.requested==`string`&&Q(e.before)&&Q(e.after))}function ln(e){if(!pn(e)||!un(e))return null;let t=fn(e.rect);return t?{resourceId:e.resourceId,className:e.className,packageName:e.packageName,rect:t}:null}function un(e){return Q(e.resourceId)&&Q(e.className)&&Q(e.packageName)}function dn(e){return typeof e==`string`&&je.includes(e)}function Q(e){return e===null||typeof e==`string`}function fn(e){return!pn(e)||![e.x,e.y,e.width,e.height].every(e=>typeof e==`number`)?null:e}function pn(e){return!!e&&typeof e==`object`}async function mn(e){let t={device:e.device,inspectFacts:e.inspectFacts,bindDevice:e.bindDevice},n=he(e.command,e.requiresCapture),r=await X({command:e.command,required:n.use.required,...e.unavailableResponse?{unavailableResponse:e.unavailableResponse}:{},...t});if(r.type===`response`)return{ok:!1,response:r.response};let i=r.bind;switch(n.kind){case`tap-point`:return{ok:!0,runtime:{kind:`tap`,captured:!1,runtime:await i(e.device,ee)}};case`captured-tap`:return{ok:!0,runtime:{kind:`tap`,captured:!0,runtime:await i(e.device,oe)}};case`long-press-point`:return{ok:!0,runtime:{kind:`long-press`,captured:!1,runtime:await i(e.device,ne)}};case`captured-long-press`:return{ok:!0,runtime:{kind:`long-press`,captured:!0,runtime:await i(e.device,fe)}};case`hover-point`:return{ok:!0,runtime:{kind:`hover`,captured:!1,runtime:await i(e.device,pe)}};case`captured-hover`:return{ok:!0,runtime:{kind:`hover`,captured:!0,runtime:await i(e.device,le)}};case`fill-point`:return{ok:!0,runtime:{kind:`fill`,captured:!1,runtime:await i(e.device,ce)}};case`captured-fill`:return{ok:!0,runtime:{kind:`fill`,captured:!0,runtime:await i(e.device,ae)}}}}function hn(e,t){let n={execution:Z(t),appBundleId:t.appBundleId},r=e.captured?xn(e.runtime):void 0;switch(e.kind){case`tap`:return gn(e,t,n,r);case`long-press`:return _n(e,n,r);case`hover`:return vn(e,n,r);case`fill`:return yn(e,t,n,r)}}function gn(e,t,n,r){let i=e.captured?e.runtime.operations.tapRef:void 0,a=e.captured?e.runtime.operations.tapElementSelector:void 0;return Object.freeze({captureSnapshot:r,tapPoint:async(r,i={})=>{let a=Sn(i,t),o=await e.runtime.operations.tapPoint({point:r,options:a,...n});return{x:r.x,y:r.y,count:a.count,intervalMs:a.intervalMs,holdMs:a.holdMs,jitterPx:a.jitterPx,doubleTap:a.doubleTap,...a.button===`primary`?{}:{button:a.button},...o??{},...h(Tn(r,a.button))}},tapRef:i?async e=>await i({ref:e,...n}):void 0,tapElementSelector:e.captured&&a?async t=>{let r=await e.runtime.operations.tapElementSelector?.({selector:t,...n}),i=r?.maestroNonHittableCoordinateFallbackUsed===!0;return{selector:t.raw,...r??{},...h(i?`tapped via non-hittable coordinate fallback`:`Tapped ${t.raw}`)}}:void 0})}function _n(e,t,n){return Object.freeze({captureSnapshot:n,longPressPoint:async(n,r)=>{let i=await e.runtime.operations.longPressPoint({point:n,durationMs:r,...t});return{x:n.x,y:n.y,durationMs:r,...i??{},...h(`Long pressed (${n.x}, ${n.y})`)}}})}function vn(e,t,n){let r=e.captured?e.runtime.operations.hoverRef:void 0;return Object.freeze({captureSnapshot:n,hoverPoint:async n=>{let r=await e.runtime.operations.hoverPoint({point:n,...t});return{x:n.x,y:n.y,...r??{},...h(`Hovered (${n.x}, ${n.y})`)}},hoverRef:r?async e=>await r({ref:e,...t}):void 0})}function yn(e,t,n,r){let i=e.captured?e.runtime.operations.fillRef:void 0,a=e=>m(e??t.delayMs??0,`delay-ms`,0,1e4);return Object.freeze({captureSnapshot:r,fillPoint:async(t,r,i={})=>{let o=a(i.delayMs),s=await e.runtime.operations.fillPoint({point:t,text:r,delayMs:o,allowNonHittableCoordinateFallback:i.allowNonHittableCoordinateFallback===!0,...n});return{x:t.x,y:t.y,text:r,delayMs:o,...bn(s)?{maestroNonHittableCoordinateFallbackUsed:!0}:{},...on(s),...h(`Filled ${Array.from(r).length} chars`)}},fillRef:i?async(e,t,r={})=>await i({ref:e,text:t,delayMs:a(r.delayMs),...n}):void 0})}function bn(e){return typeof e==`object`&&!!e&&`maestroNonHittableCoordinateFallbackUsed`in e&&e.maestroNonHittableCoordinateFallbackUsed===!0}function xn(e){return async t=>await e.operations.captureSnapshot(t)}function Sn(e,t){let n=Cn(e,t);return wn(n),{button:e.button??g(t),...n,surface:e.surface??t.surface}}function Cn(e,t){return{count:$(e.count,t.count,1,`count`,1,200),intervalMs:$(e.intervalMs,t.intervalMs,0,`interval-ms`,0,1e4),holdMs:$(e.holdMs,t.holdMs,0,`hold-ms`,0,1e4),jitterPx:$(e.jitterPx,t.jitterPx,0,`jitter-px`,0,100),doubleTap:e.doubleTap??t.doubleTap??!1}}function $(e,t,n,r,i,a){return m(e??t??n,r,i,a)}function wn(t){if(t.doubleTap&&t.holdMs>0)throw new e(`INVALID_ARGS`,`double-tap cannot be combined with hold-ms`);if(t.doubleTap&&t.jitterPx>0)throw new e(`INVALID_ARGS`,`double-tap cannot be combined with jitter-px`)}function Tn(e,t){return t===`primary`?`Pressed (${e.x}, ${e.y})`:`${t===`secondary`?`Right`:`Middle`} clicked (${e.x}, ${e.y})`}function En(e){let{inspectFacts:t,bindDevice:n}=e;if(!t||!n)return;let r=new Map;return async({device:e,point:i,context:a})=>{let o=r.get(e.id);o||(o=mn({device:e,command:`press`,requiresCapture:!1,inspectFacts:t,bindDevice:n}),r.set(e.id,o));let s=await o;if(!s.ok)return!1;let c=hn(s.runtime,a);return c.tapPoint?(await c.tapPoint(i),!0):!1}}async function Dn(e){let t=await Pt({session:e.session,device:e.device,logPath:e.logPath,interactiveOnly:e.flags?.snapshotInteractiveOnly===!0,androidFreshnessMode:e.androidFreshnessMode,capture:()=>kn(e),retryTap:En(e)});if(t)return t;let n=await kn(e);return E(e.session),{snapshot:n.snapshot,...n.annotations}}async function On(e){if(e.captureData)return await e.captureData();let{device:n,session:r,logPath:a}=e,o=D(a,An(e),r?.appBundleId,r?.trace?.outPath);return await an({device:n,runnerContext:{requestId:o.requestId,signal:e.signal,appBundleId:o.appBundleId,verbose:o.verbose,logPath:o.logPath,traceLogPath:o.traceLogPath,iosXctestrunFile:o.iosXctestrunFile,iosXctestDerivedDataPath:o.iosXctestDerivedDataPath,iosXctestEnvDir:o.iosXctestEnvDir,runnerLeaseContext:o.runnerLeaseContext},options:{appBundleId:o.appBundleId,signal:e.signal,...t(o,i),includeRects:e.includeRects,surface:r?.surface}})}async function kn(e){let t=Date.now(),n=await On(e);c(e.session,{durationMs:Date.now()-t,backend:n.backend,platform:f(e.device)});let r=s(n),i=l(n,De(n,An(e)));return r.androidSnapshot?.systemSurfaceOnly===!0&&(i.systemSurfaceOnly=!0),{data:n,snapshot:i,annotations:r}}function An(e){return e.snapshotScope===void 0?e.flags:{...e.flags,snapshotScope:e.snapshotScope}}function jn(e,t){if(!e||!e.trim().startsWith(`@`))return{ok:!0,scope:e};if(!t?.snapshot)return a(`INVALID_ARGS`,`Ref scope requires an existing snapshot in session.`);let i=r(e.trim());if(!i)return a(`INVALID_ARGS`,`Invalid ref scope: ${e}`);let o=[t.snapshot,...t.snapshotScopeSource?[t.snapshotScopeSource]:[]],s;for(let e of o){let t=n(e.nodes,i);if(s=t?be(t,e.nodes):void 0,s)break}return s?{ok:!0,scope:s}:a(`COMMAND_FAILED`,`Ref ${e} not found or has no label`)}function Mn(e,t,n={}){if(!e)return;let r=Be(e);return{name:t,appBundleId:e.appBundleId,appName:e.appName,...n.includeSnapshot===!0?{snapshot:e.snapshot,...r&&n.omitRefFrameSnapshot!==!0?{refFrameSnapshot:r}:{}}:{},metadata:{surface:e.surface,...n.metadata??{}}}}function Nn(e){return{get:t=>t===e.sessionName?Mn(e.getSession(),e.sessionName,e.recordOptions):void 0,set:t=>{if(t.name!==e.sessionName){_({level:`warn`,phase:`runtime_session_write_skipped`,data:{expected:e.sessionName,received:t.name}});return}e.setRecord(t)}}}function Pn(e,t){e.snapshot!==t&&(e.snapshotGeneration=In(e.snapshotGeneration)),e.snapshot=t,e.snapshotScopeSource=void 0,t.comparisonSafe===!0&&(e.lastComparisonSafeSnapshot=t)}function Fn(e,t){e.snapshotScopeSource=t.scopeSource,e.snapshotGeneration=t.keptCurrentSnapshot?t.previousGeneration:In(t.previousGeneration)}function In(e){return e===void 0?Me(1e5,1e6):e+1}function Ln(e){let t=e.startsWith(`@`)?e.slice(1):e,n=t.indexOf(`~`);return n===-1?t:t.slice(0,n)}function Rn(e,t){let n=new Set;for(let e of t){let t=Ln(e);t.length>0&&n.add(t)}n.size!==0&&We(e,n)}function zn(e,t){if(t?.diff)return Rn(e,Bn(t)),e.snapshotGeneration}function Bn(e){let t=[];for(let n of e.diff?.lines??[])n.ref&&t.push(n.ref);for(let n of e.refs??[])t.push(n.ref);for(let n of e.tail??[])t.push(n.ref);return t}function Vn(e){return`Ref @${e.ref.startsWith(`@`)?e.ref.slice(1):e.ref} was minted from snapshot s${e.mintedGeneration} but the session's ref frame is now s${e.currentFrameEpoch} — re-run snapshot -i.`}function Hn(e){let{session:t,ref:n,mintedGeneration:r}=e;if(t&&Ge(t)===`expired`)return`The UI may have changed since these refs were issued, so they no longer represent current device state. Take a new snapshot before relying on or interacting with them.`;if(r!==void 0){let e=t?S(t)??0:0;if(r!==e)return Vn({ref:n,mintedGeneration:r,currentFrameEpoch:e})}}export{T as A,Bt as C,jt as D,V as E,x as F,Pe as I,y as L,Ve as M,qe as N,j as O,C as P,q as S,Wt as T,$t as _,Fn as a,K as b,On as c,mn as d,rn as f,Qt as g,X as h,Pn as i,Ue as j,D as k,jn as l,Z as m,Rn as n,Nn as o,nn as p,Hn as r,Dn as s,zn as t,hn as u,Xt as v,qt as w,J as x,Zt as y};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{D as e,W as t}from"./sdk-contracts.js";import{g as n}from"./sdk-batch-runner.js";import{i as r,r as i,t as a,y as o}from"./sdk-device.js";import{Xn as s,Yn as c,an as l,p as ee,rn as te,x as ne}from"./sdk-batch.js";import{o as re,s as ie,t as u}from"./back-mode.js";import{a as ae}from"./scroll-gesture.js";import{_ as d,c as oe,d as se,g as ce,h as le,i as ue,l as de,m as fe,o as pe,p as f,s as me,u as p,y as he}from"./script.js";import{A as ge,C as _e,D as ve,E as ye,M as be,N as xe,S as Se,T as Ce,_ as we,a as Te,b as Ee,g as m,i as De,k as Oe,l as ke,n as Ae,r as je,s as Me,t as Ne,v as Pe,w as Fe,x as Ie,y as Le}from"./parameterized-recorded-fill.js";import{n as h,t as g}from"./catalog.js";import{t as Re}from"./session.js";import{r as ze}from"./success-text.js";import{t as Be}from"./click-button.js";import"./device.js";import{t as _}from"./device-rotation.js";import{a as v,r as y}from"./diagnostics.js";import{D as Ve}from"./owner-identity.js";import"./file.js";import{t as He}from"./tv-remote.js";import"./diagnostics2.js";import{n as Ue,r as We}from"./session-repair-tombstone.js";import{n as Ge,r as b,t as x}from"./session-paths.js";import{t as Ke}from"./keyboard-actions.js";import S from"node:path";import C from"node:fs";import{createHash as qe}from"node:crypto";import{StringDecoder as Je}from"node:string_decoder";function Ye(e,t={}){let n=[e.command];return e.command===`snapshot`?se(n,e):e.command===`open`?ue(n,e):e.command===`runtime`?oe(n,e,{includeAllPositionals:t.runtimeIncludeAllPositionals}):e.command===`record`?me(n,e):e.command===`screenshot`?de(n,e):pe(n,e),n.join(` `)}function Xe(e){return e.targetEvidences?[c(e.targetEvidences)]:e.targetEvidence?[s(e.targetEvidence)]:[]}function w(e){return e?.scriptPublication??m}function Ze(e,t){let n=w(e),r=typeof t.saveScript==`string`?x(t.saveScript):n.kind===`repair`?void 0:t.healedSiblingPath;e.scriptPublication=Pe(n,{requested:{path:r,force:t.force===!0},boundary:t.firstArm?e.actions.length:0,sourcePath:t.sourcePath})}function Qe(e){e.scriptPublication=Ee(w(e))}function $e(e){e.scriptPublication=Fe(w(e))}function et(e,t){e.scriptPublication=Ce(w(e),t)}function tt(e){e.scriptPublication=we(w(e))}function nt(e,t){let n=w(e);return n.kind===`repair`&&n.closeReceipt===t}function rt(e){return w(e).kind===`repair`}function it(e){return _e(w(e))}function T(e){return ye(w(e))}function at(e){return ve(w(e))}function ot(e,t){if(t.flags?.noRecord||gt(e,t))return;t.flags&&Me(e,t.flags);let n=ct(t),r=dt(e,lt(t,n));n&&ut(e,n);let i={ts:Date.now(),command:r.command,positionals:r.positionals,runtime:r.runtime,flags:vt(r.flags),result:r.result,...r.targetEvidence?{targetEvidence:r.targetEvidence}:{},...r.targetEvidences?{targetEvidences:r.targetEvidences}:{}};return e.actions.push(i),y({level:`debug`,phase:`record_action`,data:{command:t.command,session:e.name}}),i}function st(e,t,n,r,i,a){t&&e.recordAction(t,{command:r,positionals:a?.positionals??n.positionals??[],flags:a?.flags??n.flags??{},result:i??{}})}function ct(e){if(e.command!==`fill`||typeof e.flags.recordAs!=`string`)return;let t=xe(e.flags.recordAs),n=be(t);return{literal:ge({ts:0,command:e.command,positionals:e.positionals,flags:e.flags}),placeholder:n}}function lt(e,t){if(!t)return e;let{literal:n,placeholder:r}=t;return{...e,positionals:pt(e.positionals,r),result:Ne(e.result,n,r),targetEvidence:Ae(e.targetEvidence,n,r)}}function ut(e,t){t.literal.trim()&&(e.recordedFillLiterals??=new Map,!e.recordedFillLiterals.has(t.literal)&&e.recordedFillLiterals.set(t.literal,t.placeholder))}function dt(e,t){let n=e.recordedFillLiterals;if(!n||n.size===0)return t;let r=je(t.result,n),i=(t.targetEvidenceMode??`action`)===`landmark`?ft(t.targetEvidence,n):E(t.targetEvidence,n),a=t.targetEvidences?{source:E(t.targetEvidences.source,n),destination:E(t.targetEvidences.destination,n)}:t.targetEvidences;return{...t,result:r,targetEvidence:i,targetEvidences:a}}function ft(e,t){return e&&(Te(e,t)?void 0:e)}function E(e,t){return!e||!Te(e,t)?e:{...De(e,t),verification:`unverifiable`}}function pt(e,t){let n=e[0];return n?.startsWith(`@`)?e.length>=3?[n,e[1],t]:[n,t]:e.length>=3&&Number.isFinite(Number(e[0]))&&Number.isFinite(Number(e[1]))?[e[0],e[1],t]:n===void 0?[t]:[n,t]}const mt=new Set([`snapshot`,`get`,`is`,`find`]);function ht(e){return e.internal?.replayPlanStep!==!0&&mt.has(e.command)}function gt(e,t){return!t.interactiveObservation||T(e)===void 0?!1:t.flags?.record!==!0}const _t=re();function vt(e){if(!e)return{};let t={};for(let n of _t){let r=e[n];r!==void 0&&(t[n]=r)}return t}function yt(t){let n=t.flatMap((e,t)=>e.command===`open`?[t]:[]);if(n.length!==1||n[0]!==0)throw new e(`COMMAND_FAILED`,`Cannot publish this session: an open-to-destination script requires exactly one initial recorded open.`,{retriable:!1,hint:`Close this session and start a fresh one with open <app> --save-script[=<path>].`});if(t.some(e=>e.command===`close`))throw new e(`COMMAND_FAILED`,`Cannot publish an active-session script containing close.`,{retriable:!1,hint:`Close this session and record the journey again from a fresh open --save-script session.`});let r=-1;for(let[e,n]of t.entries())ne({command:n.command,positionals:n.positionals,flags:n.flags})===`mutates-app`&&(r=e);if(!t.slice(r+1).some(Tt))throw new e(`COMMAND_FAILED`,`Cannot publish this session without a portable destination guard after the final mutating action.`,{retriable:!0,hint:`Record a selector-targeted wait on a labeled or id-bearing landmark, for example wait 'role="heading" label="Screen X"', so its recorded identity is captured, then retry session save-script.`})}function bt(t){for(let n of t){if(xt(n)){St(n);continue}let t=Et(n),r=t??(n.command===`wait`?n.positionals[0]:void 0);if(r?.startsWith(`@`))throw new e(`COMMAND_FAILED`,`Cannot publish recorded step "${n.command} ${r}": the session-local ref was not converted to a portable selector.`,{retriable:!1,hint:`Close this session and record the journey again using selectors or resolvable refs.`});if(n.command===`find`&&ne(n)===`mutates-app`)throw new e(`COMMAND_FAILED`,`Cannot publish a recorded mutating find step because its target identity is not replay-verifiable.`,{retriable:!1,hint:`Close this session and record the journey again with an explicit selector-targeted click, press, fill, or focus action.`});let i=t;if(!(!i||!l(i)||n.targetEvidence))throw new e(`COMMAND_FAILED`,`Cannot publish recorded step "${n.command} ${i}": recording-time target identity evidence is missing.`,{retriable:!1,hint:`Close this session and record the journey again from open --save-script so target-v1 evidence is captured before each interaction.`})}}function xt(e){return Ct(e)!==void 0}function St(t){let n=Ct(t);if(!n)return;let r=[n.source,n.destination];for(let n of r){if(n?.startsWith(`@`))throw new e(`COMMAND_FAILED`,`Cannot publish recorded drag endpoint "${n}": the session-local ref was not converted to a portable selector.`,{retriable:!1});if(!(!n||!l(n))&&!t.targetEvidences)throw new e(`COMMAND_FAILED`,`Cannot publish recorded drag endpoint "${n}": recording-time target identity evidence is missing.`,{retriable:!1,hint:`Close this session and record the journey again so targets-v1 evidence is captured for both drag endpoints.`})}}function Ct(e){return e.command===`gesture`?he(e.positionals):void 0}function wt(t,n){if(t instanceof e){if(t.details?.reason===`script_target_exists`)return new e(t.code,`A file already exists at ${String(t.details.path)}.`,{...t.details,retriable:!0,hint:`Retry session save-script with another path, or pass --force to replace the existing file. The session remains armed.`});let n=t.details?.retriable===!0;return new e(t.code,t.message,{...t.details,retriable:n,hint:t.details?.hint??(n?`Fix the recorded journey or target, then retry session save-script. The session remains armed.`:`Close this session and start a fresh one with open <app> --save-script[=<path>].`)})}let r=t instanceof Error?t.message:String(t);return new e(`COMMAND_FAILED`,`Failed to publish the active session script${n?` to ${n}`:``}: ${r}`,{retriable:!0,hint:`Check the target path and permissions, then retry session save-script. The session remains armed.`})}function Tt(e){if(e.command!==`wait`)return!1;let t=te(e.positionals);return t?.kind!==`selector`||!l(t.selectorExpression)?!1:e.targetEvidence?.verification===`verified`}function Et(e){if(e.command===`get`)return e.positionals[1];if(ce(e.command)||e.command===`fill`){let[t,n]=e.positionals;return t!==void 0&&n!==void 0&&Dt(t)&&Dt(n)?void 0:t}}function Dt(e){return e.trim().length>0&&Number.isFinite(Number(e))}function Ot(e){let t=e.scriptPublication??m;return t.kind===`repair`?t.status===`committed`||!Se(t):!1}function kt(e){return!Ie(e.scriptPublication??m)||Ot(e)}var At=class{sessionsDir;constructor(e){this.sessionsDir=e}write(e,t){let n=rt(e),r=t?.publication===`active`,i;try{if(kt(e))return{written:!1};let a=jt(e,{appendCompleteSentinel:n,activePublication:r});i=this.resolveScriptPath(e);let o=S.dirname(i);return C.existsSync(o)||C.mkdirSync(o,{recursive:!0}),Pt({scriptPath:i,script:a.script,force:t?.force}),n&&(e.scriptPublication=Le(e.scriptPublication??m)),{written:!0,path:i,actionCount:a.actionCount}}catch(t){return Mt({session:e,error:t,scriptPath:i,repairArmed:n,activePublication:r})}}resolveScriptPath(e){let t=Oe(e.scriptPublication??m);if(t)return x(t);let n=b(e.name),r=new Date(e.createdAt).toISOString().replaceAll(/[:.]/g,`-`);return S.join(this.sessionsDir,`${n}-${r}.ad`)}};function jt(e,t){let n=Ft(e,{strictPortableRefs:t.activePublication});return t.activePublication&&yt(n),{script:Gt(e,n,t.appendCompleteSentinel),actionCount:n.length}}function Mt(t){let{session:n,error:r,scriptPath:i,repairArmed:a,activePublication:o}=t;if(y({level:`warn`,phase:`session_script_write_failed`,data:{session:n.name,path:i,error:r instanceof Error?r.message:String(r)}}),a)return{written:!1,error:Nt(r,i)};if(o)return{written:!1,error:wt(r,i)};if(r instanceof e)throw r;return{written:!1}}function Nt(t,n){if(t instanceof e)return t;let r=t instanceof Error?t.message:String(t);return new e(`COMMAND_FAILED`,`Failed to write the healed script${n?` to ${n}`:``}: ${r}`,{hint:`The repair transaction completed but the healed .ad could not be published; check the target path and permissions, then retry close --save-script.`})}function Pt(t){let{scriptPath:n,script:r,force:i}=t;try{Ve({destination:n,contents:r,publish:i?`replace`:`link-exclusive`})}catch(t){throw t.code===`EEXIST`?new e(`COMMAND_FAILED`,`A file already exists at ${n}; remove it, pass replay --save-script=<other-path>, or pass --force/--overwrite to replace it.`,{reason:`script_target_exists`,path:n}):t}}function Ft(e,t={}){let n=T(e),r=n!==void 0,i=e.actions.slice(n??0),a=[];for(let n of i){if(n.command===`snapshot`)continue;let i=Rt(n);if(i){a.push(i);continue}(r||t.strictPortableRefs)&&It(n);let o=Wt(e,n);o&&a.push(o),a.push(n)}return t.strictPortableRefs&&bt(a),a}function It(t){let n=t.command===`gesture`?he(t.positionals??[]):void 0;if(n){Lt(n);return}if(!D(t.command))return;let r=t.command===`get`?t.positionals?.[1]:t.positionals?.[0];if(r?.startsWith(`@`))throw new e(`COMMAND_FAILED`,`Cannot write recorded step "${t.command} ${r}" to a script: it never resolved to a selector, so the ref would not resolve in a fresh replay session.`)}function Lt(t){let n=[t.source,t.destination].find(e=>e.startsWith(`@`));if(n)throw new e(`COMMAND_FAILED`,`Cannot write recorded drag endpoint "${n}" to a script: it never resolved to a selector, so the ref would not resolve in a fresh replay session.`)}function Rt(e){let t=zt(e);if(!(!t||!D(e.command)))return le(e.command)||e.command===`hover`?{...e,positionals:[t]}:e.command===`longpress`?Vt(e,t):e.command===`fill`?Bt(e,t):Ht(e,t)}function zt(e){let t=Array.isArray(e.result?.selectorChain)&&e.result.selectorChain.every(e=>typeof e==`string`)?e.result.selectorChain:[];return t.length>0?t.join(` || `):void 0}function D(e){return ce(e)||e===`fill`||e===`get`}function Bt(e,t){let n=ge(e);return n.length>0?{...e,positionals:[t,n]}:void 0}function Vt(e,t){let n=typeof e.result?.durationMs==`number`?String(e.result.durationMs):Ut(e.positionals??[]);return{...e,positionals:n?[t,n]:[t]}}function Ht(e,t){let n=e.positionals?.[0];return n===`text`||n===`attrs`?{...e,positionals:[n,t]}:void 0}function Ut(e){let t=e.at(-1);if(!(e.length<=1||t===void 0||t.trim()===``))return Number.isFinite(Number(t))?t:void 0}function Wt(e,t){if(!D(t.command))return;let n=t.result?.refLabel;if(typeof n!=`string`||n.trim().length===0)return;let r=n.trim();return{ts:t.ts,command:`snapshot`,positionals:[],flags:{platform:e.device.platform,snapshotInteractiveOnly:!0,snapshotScope:r},result:{scope:r}}}function Gt(e,t,n){let r=[],i=e.device.kind?` kind=${e.device.kind}`:``;r.push(`context platform=${o(e.device)} device=${fe(e.device.name)}${i} theme=unknown`);for(let e of t)e.flags?.noRecord||(r.push(...Xe(e)),r.push(Kt(e)));return n&&r.push(`# agent-device:heal-complete`),`${r.join(`
|
|
2
|
-
`)}\n`}function Kt(e){return qt([e.command],e)||Ye(e)}function qt(e,t){if(le(t.command))return Jt(e,t);if(t.command===`fill`)return Yt(e,t);if(t.command===`get`)return Xt(e,t)}function Jt(e,t){let n=t.positionals?.[0];if(n){if(n.startsWith(`@`))return e.push(f(d(n))),O(e,t),p(e,t),e.join(` `);if(t.positionals.length===1)return e.push(f(n)),p(e,t),e.join(` `)}}function Yt(e,t){let n=t.positionals?.[0];if(!n?.startsWith(`@`))return;e.push(f(d(n))),O(e,t);let r=t.positionals.slice(1).join(` `);return t.positionals.length>1&&e.push(f(r)),p(e,t),e.join(` `)}function Xt(e,t){let n=t.positionals?.[0],r=t.positionals?.[1];if(!(!n||!r))return e.push(f(n)),e.push(f(d(r))),r.startsWith(`@`)&&O(e,t),e.join(` `)}function O(e,t){let n=t.result?.refLabel;typeof n==`string`&&n.trim().length>0&&e.push(f(n))}const Zt=[`id`,`deviceId`,`device_id`,`serial`,`udid`,`device_udid`,`identifier`],Qt={ios:`iOS`,ipados:`iPadOS`,tvos:`tvOS`,watchos:`watchOS`,visionos:`visionOS`,macos:`macOS`,apple:`Apple`,android:`Android`,linux:`Linux`,web:`Web`};function $t(e,t){let n=t??{};switch(e.command){case h.devices:return en(n.devices);case h.apps:return tn(n.apps,e.flags?.appsFilter);case h.boot:return nn(`Booted`,n,!0);case h.shutdown:return nn(`Shut down`,n,!1);case h.install:return k(`Installed`,n);case h.reinstall:return k(`Reinstalled`,n);case h.screenshot:return rn(e,n);default:return{}}}function en(e){if(!Array.isArray(e))return{};let t=e.flatMap(e=>{let t=on(e);return t?[t]:[]}),n=t.slice(0,5),r=Math.max(0,t.length-n.length),i=t.slice(0,3);return{summary:hn(`Found ${t.length} ${gn(`device`,t.length)}`,i.map(e=>pn(e,!0)),Math.max(0,t.length-i.length)),details:{deviceCount:t.length,devices:n,...r>0?{omittedDeviceCount:r}:{}}}}function tn(e,t){if(!Array.isArray(e))return{};let n=e.flatMap(e=>{let t=M(e);return t?[t]:[]}),r=n.slice(0,5),i=Math.max(0,n.length-r.length),a=n.slice(0,3);return{summary:hn(`Found ${n.length} ${gn(`app`,n.length)}`,a,Math.max(0,n.length-a.length)),details:{appCount:n.length,apps:r,...i>0?{omittedAppCount:i}:{},...t===`all`||t===`user-installed`?{filter:t}:{}}}}function nn(e,t,n){let r=sn(t);if(!r)return{};let i={device:r,...fn(t),booted:n};return{summary:`${e} ${pn(i,!1)}`,details:i}}function k(e,t){let n=M(t.appName),r=M(t.bundleId),i=A(t,[`packageName`,`package`]),a=M(t.platform),o=M(t.launchTarget),s=A(t,[`bundleId`,`packageName`,`package`,`appId`,`launchTarget`]),c=mn(n,s);if(!c)return{};let l={};return j(l,`appName`,n),j(l,`bundleId`,r),j(l,`packageName`,i),j(l,`platform`,a),o!==s&&j(l,`launchTarget`,o),{summary:`${e} ${c}`,details:l}}function rn(e,t){let n=an(e,t);return n?{details:{requestedFileName:n}}:{}}function an(e,t){let n=R(e.meta?.clientArtifactPaths?.path)??R(t.path);if(n)return L(n)}function on(e){if(!n(e))return;let t=sn(e);if(t)return{name:t,...fn(e)}}function sn(e){let t=A(e,[`name`,`deviceName`,`device`]);return!t||!cn(e,t)?t:un(e)}function cn(e,t){let n=ln(t);return Zt.some(t=>{let r=M(e[t]);return r!==void 0&&ln(r)===n})}function ln(e){return e.toLowerCase()}function un(e){let t=M(e.appleOs),n=M(e.platform),r=M(e.kind),i=dn(t,n);return i&&(r===`simulator`||r===`emulator`)?`${i} ${r}`:i?`${i} device`:r===`simulator`?`Simulator`:r===`emulator`?`Emulator`:`Unnamed device`}function dn(e,t){let n=e??t;if(!(!n||!Object.hasOwn(Qt,n)))return Qt[n]}function fn(e){let t=M(e.platform),n=M(e.appleOs),r=M(e.kind),i=M(e.target);return{...t?{platform:t}:{},...n?{appleOs:n}:{},...r?{kind:r}:{},...i?{target:i}:{},...typeof e.booted==`boolean`?{booted:e.booted}:{}}}function pn(e,t){let n=M(e.name)??M(e.device)??`device`,r=M(e.platform),i=M(e.appleOs),a=[r,i===r?void 0:i,M(e.kind),M(e.target),t&&typeof e.booted==`boolean`?e.booted?`booted`:`stopped`:void 0].filter(e=>!!e);return a.length>0?`${n} (${a.join(`, `)})`:n}function mn(e,t){return e&&t&&e!==t?`${e} (${t})`:e??t}function A(e,t){for(let n of t){let t=M(e[n]);if(t)return t}}function j(e,t,n){n&&(e[t]=n)}function hn(e,t,n){let r=[...t,...n>0?[`+${n} more`]:[]];return r.length>0?`${e}: ${r.join(`, `)}`:e}function gn(e,t){return t===1?e:`${e}s`}function M(e){let t=R(e);if(!t)return;let n=t.trim(),r=Array.from(n);return r.length<=120?n:`${r.slice(0,119).join(``)}…`}function N(e){return M(e)}function P(e){return typeof e==`boolean`?e:void 0}function F(e,t){let n=N(e);return n&&t.includes(n)?n:void 0}function I(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0))}function L(e){let t=R(e);return t?M(t.split(/[\\/]/).at(-1)):void 0}function R(e){if(typeof e==`string`)return e.trim().length>0?e:void 0}function z(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}const _n=[`up`,`down`,`left`,`right`],vn=[`top`,`bottom`];function yn(e){return`${e.command===h.reinstall?`Reinstalled`:`Installed`} ${Cn(e.result??{})??`app`}`}function bn(e){let t=e.result??{};switch(e.command){case h.scroll:return Tn(t);case h.screenshot:return On(t);case h.home:return`Went home`;case h.back:return An(t);case h.appSwitcher:return`Opened app switcher`;case h.actionButton:return`Pressed Action Button`;case h.orientation:return jn(t);case h.viewport:return Mn(t);case h.clipboard:return Nn(t);case h.keyboard:return Pn(t);case h.tvRemote:return Ln(t);case h.gesture:return Rn(t);case h.swipe:return zn(t);case h.trace:return Vn(`trace`,e);case h.record:return Vn(`recording`,e);default:return}}function xn(e){let t=e.result??{};switch(e.command){case h.scroll:return I({direction:F(t.direction,_n),edge:F(t.edge,vn),passes:z(t.passes),amount:z(t.amount),pixels:z(t.pixels),durationMs:z(t.durationMs),x1:z(t.x1),y1:z(t.y1),x2:z(t.x2),y2:z(t.y2)});case h.screenshot:return I({requestedFileName:kn(t)});case h.back:return I({mode:F(t.mode,u)});case h.orientation:return I({orientation:F(t.orientation,_)});case h.viewport:return I({width:z(t.width),height:z(t.height)});case h.clipboard:return I({action:F(t.action,[`read`,`write`])});case h.keyboard:return In(t);case h.tvRemote:return I({button:F(t.button,He),durationMs:z(t.durationMs)});case h.gesture:case h.swipe:return Bn(t);case h.trace:case h.record:return I({action:F(t.action,[`start`,`stop`]),fileName:Un(e),showTouches:P(t.showTouches)});default:return{}}}function Sn(e,t){if(e.command!==h.screenshot)return t;let n=an(e,t);return n?{...t,requestedFileName:n}:t}function Cn(e){let t=N(e.appName),n=Wn(e,[`bundleId`,`packageName`,`appBundleId`,`launchTarget`]);return t&&n&&t!==n?`${t} (${n})`:t??n??wn(e)}function wn(e){let t=N(e.app);return t&&!t.includes(`/`)&&!t.includes(`\\`)?t:void 0}function Tn(e){let t=F(e.direction,_n),n=F(e.edge,vn),r=z(e.passes);return n?En(n,r):t?Dn(t,e):`Scrolled`}function En(e,t){return t===0?`Already at ${e}`:t===void 0?`Scrolled to ${e}`:`Scrolled to ${e} in ${t} ${t===1?`pass`:`passes`}`}function Dn(e,t){let n=z(t.pixels);if(n!==void 0)return`Scrolled ${e} by ${n}px`;let r=z(t.amount);return r===void 0?`Scrolled ${e}`:`Scrolled ${e} by ${r}`}function On(e){let t=kn(e);return t?`Captured screenshot ${t}`:`Captured screenshot`}function kn(e){return L(e.requestedFileName)??L(e.path)}function An(e){return F(e.mode,u)===`system`?`Went back using system navigation`:`Went back`}function jn(e){let t=F(e.orientation,_);return t?P(e.confirmed)===!1?`Requested ${t} (unconfirmed)`:`Rotated to ${t}`:`Changed orientation`}function Mn(e){let t=z(e.width),n=z(e.height);return t!==void 0&&n!==void 0?`Set viewport to ${t}×${n}`:`Changed viewport`}function Nn(e){let t=F(e.action,[`read`,`write`]);return t===`read`?`Read clipboard`:t===`write`?`Updated clipboard`:`Used clipboard`}function Pn(e){let t=R(e.action);if(!t||!Ke(t))return`Used keyboard`;if(t===`dismiss`)return Fn(e);if(t===`enter`||t===`return`)return`Pressed keyboard return`;let n=P(e.visible);return n===void 0?`Inspected keyboard`:n?`Keyboard is visible`:`Keyboard is hidden`}function Fn(e){return P(e.dismissed)===!1?`Keyboard was already hidden`:`Dismissed keyboard`}function In(e){let t=R(e.action);return I({action:t&&Ke(t)?t:void 0,platform:F(e.platform,[`ios`,`android`]),visible:P(e.visible),wasVisible:P(e.wasVisible),dismissed:P(e.dismissed),attempts:z(e.attempts),mechanism:F(e.mechanism,[`dismissKey`])})}function Ln(e){let t=F(e.button,He);return t?`Pressed TV remote ${t}`:`Used TV remote`}function Rn(e){let t=F(e.kind,[`fling`,`pan`,`pinch`,`rotate`,`transform`]);return t?`Ran ${t} gesture`:`Ran gesture`}function zn(e){let t=z(e.count);return t!==void 0&&t>1?`Swiped ${t} times`:`Swiped`}function Bn(e){return I({kind:F(e.kind,[`fling`,`pan`,`pinch`,`rotate`,`transform`]),durationMs:z(e.durationMs),pointerCount:z(e.pointerCount),x1:z(e.x1),y1:z(e.y1),x2:z(e.x2),y2:z(e.y2),count:z(e.count),pauseMs:z(e.pauseMs),pattern:F(e.pattern,[`one-way`,`ping-pong`]),scale:z(e.scale)})}function Vn(e,t){let n=Hn(e,F(t.result?.action,[`start`,`stop`])),r=Un(t);return r?`${n} ${r}`:n}function Hn(e,t){return t===`start`?e===`trace`?`Started trace`:`Started recording`:t===`stop`?e===`trace`?`Stopped trace`:`Stopped recording`:e===`trace`?`Updated trace`:`Updated recording`}function Un(e){let t=e.result??{};return L(t.requestedFileName)??L(t.outPath)??L(t.path)??L(e.positionals[1])}function Wn(e,t){for(let n of t){let t=N(e[n]);if(t)return t}}function Gn(e){switch(e.command){case h.open:return`Opened ${B(e)??`session`}`;case h.close:return`Closed ${N(e.result?.session)??`session`}`;case h.click:case h.press:return`Tapped ${B(e)??`target`}`;case h.longPress:return`Long pressed ${B(e)??`target`}`;case h.hover:return`Hovered ${B(e)??`target`}`;case h.fill:return`Filled ${B(e)??`target`}`;case h.type:return`Typed text`;case h.install:case h.reinstall:case g.installSource:return yn(e);default:return bn(e)??`Ran ${e.command}`}}function Kn(e){return I({command:e.command,positionals:tr(e),flags:pr(e),...qn(e),...Jn(e),...Yn(e),...xn(e)})}function qn(e){if(!Xn(e.command))return{};let t=e.result??{};return I({ref:G(t),targetLabel:B(e),selectorChainLength:lr(t.selectorChain)?.length,x:z(t.x),y:z(t.y),x2:z(t.x2),y2:z(t.y2),durationMs:z(t.durationMs)})}function Jn(e){if(!Zn(e.command))return{};let t=e.result??{};return I({platform:F(t.platform,r),target:F(t.target,a),appName:N(t.appName),appBundleId:N(t.appBundleId),bundleId:N(t.bundleId),packageName:N(t.packageName),launchTarget:N(t.launchTarget)})}function Yn(e){let t=e.result??{};return e.command===h.snapshot?Array.isArray(t.nodes)?{nodeCount:t.nodes.length}:{}:e.command!==h.wait&&e.command!==h.find&&e.command!==h.get&&e.command!==h.is?{}:I({waitedMs:z(t.waitedMs),found:P(t.found)})}function Xn(e){return e===h.click||e===h.press||e===h.longPress||e===h.hover||e===h.focus||e===h.fill}function Zn(e){return e===h.open||e===h.install||e===h.reinstall||e===g.installSource}function B(e){let t=e.result??{};return Qn(t)??$n(t)??er(t)??sr(e.positionals[0])}function Qn(e){let t=G(e);if(t)return t.startsWith(`@`)?t:`@${t}`}function $n(e){let t=z(e.x),n=z(e.y);if(t!==void 0&&n!==void 0)return`(${t}, ${n})`}function er(e){return N(e.appName)??N(e.appBundleId)??N(e.bundleId)??N(e.packageName)}function tr(e){if(e.positionals.length!==0)return e.command===h.type?[H(`text`)]:e.command===h.fill?nr(e):e.command===h.find?rr(e):e.command===h.clipboard?ir(e):e.command===h.push?ar(e,`app`,`payload`):e.command===h.triggerAppEvent?ar(e,`event`,`payload`):e.positionals.map(V)}function nr(e){let t=H(`text`),n=e.result??{},r=G(n);if(r)return[`@${r}`,t];if(N(n.selector))return[H(`target`),t];let i=z(n.x),a=z(n.y);return i!==void 0&&a!==void 0?[String(i),String(a),t]:[t]}function rr(e){let t=+!!cr(e.positionals[0]);if(e.positionals[t]===void 0)return;let n=t+1,r=[...t===1?[String(e.positionals[0])]:[],H(`query`)],i=e.positionals[n];return i?i===`fill`||i===`type`?[...r,i,H(`text`)]:[...r,...e.positionals.slice(n).map(or)]:r}function ir(e){let t=e.positionals[0]?.toLowerCase();return t===`read`?[`read`]:t===`write`?[`write`,H(`text`)]:e.positionals.map(V)}function ar(e,t,n){let[r,i,...a]=e.positionals;return[...r?[H(t)]:[],...i?[H(n)]:[],...a.map(V)]}function or(e){return e===`click`||e===`focus`||e===`exists`||e===`get`||e===`text`||e===`attrs`||e===`wait`?e:V(e)}function V(e){return sr(e)??H(`arg`)}function sr(e){if(!e)return;let t=e.trim();if(/^@[a-zA-Z0-9:_-]+$/.test(t))return t}function H(e){return`<${e}>`}function cr(e){return e===`text`||e===`label`||e===`value`||e===`role`||e===`id`}function lr(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)?e:void 0}const ur={enums:[{source:`platform`,values:i},{source:`target`,values:a}]},dr={booleans:[{source:`settle`}],numbers:[{source:`settleQuietMs`}]},fr={[h.open]:{booleans:[{source:`relaunch`},{source:`testIme`}],enums:[{source:`surface`,values:Re}]},[h.click]:U(),[h.press]:U(),[h.longPress]:U(),[h.hover]:U(),[h.fill]:hr(),[h.type]:hr(),[h.scroll]:{numbers:[{source:`pixels`},{source:`durationMs`}]},[h.gesture]:gr(),[h.swipe]:gr(),[h.screenshot]:{booleans:[{source:`overlayRefs`},{source:`screenshotFullscreen`,output:`fullscreen`},{source:`screenshotNoStabilize`,output:`noStabilize`},{source:`screenshotNormalizeStatusBar`,output:`normalizeStatusBar`}],numbers:[{source:`screenshotPixelDensity`,output:`pixelDensity`},{source:`screenshotScale`,output:`scale`}]},[h.snapshot]:{booleans:[{source:`snapshotInteractiveOnly`,output:`interactiveOnly`},{source:`snapshotDiff`,output:`diff`},{source:`snapshotRaw`,output:`raw`},{source:`snapshotCustomActions`,output:`actions`},{source:`snapshotForceFull`,output:`forceFull`}],numbers:[{source:`snapshotDepth`,output:`depth`}]},[h.back]:{enums:[{source:`backMode`,output:`mode`,values:u}]},[h.record]:{booleans:[{source:`hideTouches`}],numbers:[{source:`fps`}],enums:[{source:`recordingScope`,output:`scope`,values:ie}]},[h.apps]:{enums:[{source:`appsFilter`,output:`filter`,values:[`user-installed`,`all`]}]},[h.boot]:{booleans:[{source:`headless`}]},[h.close]:{booleans:[{source:`shutdown`}]}};function pr(e){let t=e.flags??{},n={},r=Object.hasOwn(fr,e.command)?fr[e.command]:void 0;return W(n,t,ur),W(n,t,r),W(n,t,mr(e.command)),Object.keys(n).length>0?n:void 0}function mr(e){return ee(e)?dr:void 0}function U(){return{booleans:[{source:`doubleTap`}],numbers:[{source:`count`},{source:`intervalMs`},{source:`holdMs`},{source:`jitterPx`}],enums:[{source:`clickButton`,values:Be}]}}function hr(){return{numbers:[{source:`delayMs`}]}}function gr(){return{numbers:[{source:`pointerCount`},{source:`count`},{source:`pauseMs`}],enums:[{source:`pattern`,values:ae}]}}function W(e,t,n){n&&(_r(e,t,n.booleans??[]),vr(e,t,n.numbers??[]),yr(e,t,n.enums??[]))}function _r(e,t,n){for(let r of n)br(e,r.output??r.source,t[r.source])}function vr(e,t,n){for(let r of n)xr(e,r.output??r.source,t[r.source])}function yr(e,t,n){for(let r of n)Sr(e,r.output??r.source,t[r.source],r.values)}function G(e){let t=N(e.ref);if(!t)return;let n=t.startsWith(`@`)?t.slice(1):t;return/^[a-zA-Z0-9:_-]+$/.test(n)?n:void 0}function br(e,t,n){typeof n==`boolean`&&(e[t]=n)}function xr(e,t,n){let r=z(n);r!==void 0&&(e[t]=r)}function Sr(e,t,n,r){let i=F(n,r);i!==void 0&&(e[t]=i)}const Cr=65536;function wr(e){return qe(`sha256`).update(e,`utf8`).digest(`hex`).slice(0,32)}function K(e,t){let n=Or(e);if(n===void 0)return!1;try{let e=Er(t),r=Buffer.allocUnsafe(Cr),i=0;do if(i=C.readSync(n,r,0,r.length,null),!e.push(r.subarray(0,i)))return!0;while(i>0);return e.end(),!0}finally{C.closeSync(n)}}async function Tr(e){let t=await kr(e);if(t===void 0)return{lineCount:0,firstLineDigest:void 0};let n={lineCount:0,firstLineDigest:void 0};try{let e=Er(e=>{n.lineCount===0&&(n.firstLineDigest=wr(e)),n.lineCount+=1}),r=Buffer.allocUnsafe(Cr);for(;;){let{bytesRead:n}=await t.read(r,0,r.length,null);if(e.push(r.subarray(0,n)),n===0)break}return e.end(),n}finally{await t.close()}}function q(e){let t;return K(e,e=>(t=wr(e),!1)),t}function Er(e){let t=new Je(`utf8`),n=``,r=!1;return{push(i){if(r)return!1;let a=`${n}${t.write(i)}`,o=0;for(let t=a.indexOf(`
|
|
1
|
+
import{D as e,W as t}from"./sdk-contracts.js";import{g as n}from"./sdk-batch-runner.js";import{i as r,r as i,t as a,y as o}from"./sdk-device.js";import{Xn as s,Zn as c,in as l,on as u,p as ee,x as te}from"./sdk-batch.js";import{o as ne,s as re,t as d}from"./back-mode.js";import{a as ie}from"./scroll-gesture.js";import{_ as f,c as ae,d as oe,g as se,h as ce,i as le,l as ue,m as de,o as fe,p,s as pe,u as m,y as me}from"./script.js";import{A as he,C as ge,D as _e,E as ve,M as ye,N as be,S as xe,T as Se,_ as Ce,a as we,b as Te,g as h,i as Ee,k as De,l as Oe,n as ke,r as Ae,s as je,t as Me,v as Ne,w as Pe,x as Fe,y as Ie}from"./parameterized-recorded-fill.js";import{n as g,t as Le}from"./catalog.js";import{t as Re}from"./session.js";import{r as ze}from"./success-text.js";import{t as Be}from"./click-button.js";import"./device.js";import{r as _,t as Ve}from"./device-rotation.js";import{a as v,r as y}from"./diagnostics.js";import{D as He}from"./owner-identity.js";import"./file.js";import{t as Ue}from"./tv-remote.js";import"./diagnostics2.js";import{n as We,r as Ge}from"./session-repair-tombstone.js";import{n as Ke,r as b,t as x}from"./session-paths.js";import{t as qe}from"./keyboard-actions.js";import S from"node:path";import C from"node:fs";import{createHash as Je}from"node:crypto";import{StringDecoder as Ye}from"node:string_decoder";function Xe(e,t={}){let n=[e.command];return e.command===`snapshot`?oe(n,e):e.command===`open`?le(n,e):e.command===`runtime`?ae(n,e,{includeAllPositionals:t.runtimeIncludeAllPositionals}):e.command===`record`?pe(n,e):e.command===`screenshot`?ue(n,e):fe(n,e),n.join(` `)}function Ze(e){return e.targetEvidences?[s(e.targetEvidences)]:e.targetEvidence?[c(e.targetEvidence)]:[]}function w(e){return e?.scriptPublication??h}function Qe(e,t){let n=w(e),r=typeof t.saveScript==`string`?x(t.saveScript):n.kind===`repair`?void 0:t.healedSiblingPath;e.scriptPublication=Ne(n,{requested:{path:r,force:t.force===!0},boundary:t.firstArm?e.actions.length:0,sourcePath:t.sourcePath})}function $e(e){e.scriptPublication=Te(w(e))}function et(e){e.scriptPublication=Pe(w(e))}function tt(e,t){e.scriptPublication=Se(w(e),t)}function nt(e){e.scriptPublication=Ce(w(e))}function rt(e,t){let n=w(e);return n.kind===`repair`&&n.closeReceipt===t}function it(e){return w(e).kind===`repair`}function at(e){return ge(w(e))}function T(e){return ve(w(e))}function ot(e){return _e(w(e))}function st(e,t){if(t.flags?.noRecord||_t(e,t))return;t.flags&&je(e,t.flags);let n=lt(t),r=ft(e,ut(t,n));n&&dt(e,n);let i={ts:Date.now(),command:r.command,positionals:r.positionals,runtime:r.runtime,flags:yt(r.flags),result:r.result,...r.targetEvidence?{targetEvidence:r.targetEvidence}:{},...r.targetEvidences?{targetEvidences:r.targetEvidences}:{}};return e.actions.push(i),y({level:`debug`,phase:`record_action`,data:{command:t.command,session:e.name}}),i}function ct(e,t,n,r,i,a){t&&e.recordAction(t,{command:r,positionals:a?.positionals??n.positionals??[],flags:a?.flags??n.flags??{},result:i??{}})}function lt(e){if(e.command!==`fill`||typeof e.flags.recordAs!=`string`)return;let t=be(e.flags.recordAs),n=ye(t);return{literal:he({ts:0,command:e.command,positionals:e.positionals,flags:e.flags}),placeholder:n}}function ut(e,t){if(!t)return e;let{literal:n,placeholder:r}=t;return{...e,positionals:mt(e.positionals,r),result:Me(e.result,n,r),targetEvidence:ke(e.targetEvidence,n,r)}}function dt(e,t){t.literal.trim()&&(e.recordedFillLiterals??=new Map,!e.recordedFillLiterals.has(t.literal)&&e.recordedFillLiterals.set(t.literal,t.placeholder))}function ft(e,t){let n=e.recordedFillLiterals;if(!n||n.size===0)return t;let r=Ae(t.result,n),i=(t.targetEvidenceMode??`action`)===`landmark`?pt(t.targetEvidence,n):E(t.targetEvidence,n),a=t.targetEvidences?{source:E(t.targetEvidences.source,n),destination:E(t.targetEvidences.destination,n)}:t.targetEvidences;return{...t,result:r,targetEvidence:i,targetEvidences:a}}function pt(e,t){return e&&(we(e,t)?void 0:e)}function E(e,t){return!e||!we(e,t)?e:{...Ee(e,t),verification:`unverifiable`}}function mt(e,t){let n=e[0];return n?.startsWith(`@`)?e.length>=3?[n,e[1],t]:[n,t]:e.length>=3&&Number.isFinite(Number(e[0]))&&Number.isFinite(Number(e[1]))?[e[0],e[1],t]:n===void 0?[t]:[n,t]}const ht=new Set([`snapshot`,`get`,`is`,`find`]);function gt(e){return e.internal?.replayPlanStep!==!0&&ht.has(e.command)}function _t(e,t){return!t.interactiveObservation||T(e)===void 0?!1:t.flags?.record!==!0}const vt=ne();function yt(e){if(!e)return{};let t={};for(let n of vt){let r=e[n];r!==void 0&&(t[n]=r)}return t}function bt(t){let n=t.flatMap((e,t)=>e.command===`open`?[t]:[]);if(n.length!==1||n[0]!==0)throw new e(`COMMAND_FAILED`,`Cannot publish this session: an open-to-destination script requires exactly one initial recorded open.`,{retriable:!1,hint:`Close this session and start a fresh one with open <app> --save-script[=<path>].`});if(t.some(e=>e.command===`close`))throw new e(`COMMAND_FAILED`,`Cannot publish an active-session script containing close.`,{retriable:!1,hint:`Close this session and record the journey again from a fresh open --save-script session.`});let r=-1;for(let[e,n]of t.entries())te({command:n.command,positionals:n.positionals,flags:n.flags})===`mutates-app`&&(r=e);if(!t.slice(r+1).some(Et))throw new e(`COMMAND_FAILED`,`Cannot publish this session without a portable destination guard after the final mutating action.`,{retriable:!0,hint:`Record a selector-targeted wait on a labeled or id-bearing landmark, for example wait 'role="heading" label="Screen X"', so its recorded identity is captured, then retry session save-script.`})}function xt(t){for(let n of t){if(St(n)){Ct(n);continue}let t=Dt(n),r=t??(n.command===`wait`?n.positionals[0]:void 0);if(r?.startsWith(`@`))throw new e(`COMMAND_FAILED`,`Cannot publish recorded step "${n.command} ${r}": the session-local ref was not converted to a portable selector.`,{retriable:!1,hint:`Close this session and record the journey again using selectors or resolvable refs.`});if(n.command===`find`&&te(n)===`mutates-app`)throw new e(`COMMAND_FAILED`,`Cannot publish a recorded mutating find step because its target identity is not replay-verifiable.`,{retriable:!1,hint:`Close this session and record the journey again with an explicit selector-targeted click, press, fill, or focus action.`});let i=t;if(!(!i||!u(i)||n.targetEvidence))throw new e(`COMMAND_FAILED`,`Cannot publish recorded step "${n.command} ${i}": recording-time target identity evidence is missing.`,{retriable:!1,hint:`Close this session and record the journey again from open --save-script so target-v1 evidence is captured before each interaction.`})}}function St(e){return wt(e)!==void 0}function Ct(t){let n=wt(t);if(!n)return;let r=[n.source,n.destination];for(let n of r){if(n?.startsWith(`@`))throw new e(`COMMAND_FAILED`,`Cannot publish recorded drag endpoint "${n}": the session-local ref was not converted to a portable selector.`,{retriable:!1});if(!(!n||!u(n))&&!t.targetEvidences)throw new e(`COMMAND_FAILED`,`Cannot publish recorded drag endpoint "${n}": recording-time target identity evidence is missing.`,{retriable:!1,hint:`Close this session and record the journey again so targets-v1 evidence is captured for both drag endpoints.`})}}function wt(e){return e.command===`gesture`?me(e.positionals):void 0}function Tt(t,n){if(t instanceof e){if(t.details?.reason===`script_target_exists`)return new e(t.code,`A file already exists at ${String(t.details.path)}.`,{...t.details,retriable:!0,hint:`Retry session save-script with another path, or pass --force to replace the existing file. The session remains armed.`});let n=t.details?.retriable===!0;return new e(t.code,t.message,{...t.details,retriable:n,hint:t.details?.hint??(n?`Fix the recorded journey or target, then retry session save-script. The session remains armed.`:`Close this session and start a fresh one with open <app> --save-script[=<path>].`)})}let r=t instanceof Error?t.message:String(t);return new e(`COMMAND_FAILED`,`Failed to publish the active session script${n?` to ${n}`:``}: ${r}`,{retriable:!0,hint:`Check the target path and permissions, then retry session save-script. The session remains armed.`})}function Et(e){if(e.command!==`wait`)return!1;let t=l(e.positionals);return t?.kind!==`selector`||!u(t.selectorExpression)?!1:e.targetEvidence?.verification===`verified`}function Dt(e){if(e.command===`get`)return e.positionals[1];if(se(e.command)||e.command===`fill`){let[t,n]=e.positionals;return t!==void 0&&n!==void 0&&Ot(t)&&Ot(n)?void 0:t}}function Ot(e){return e.trim().length>0&&Number.isFinite(Number(e))}function kt(e){let t=e.scriptPublication??h;return t.kind===`repair`?t.status===`committed`||!xe(t):!1}function At(e){return!Fe(e.scriptPublication??h)||kt(e)}var jt=class{sessionsDir;constructor(e){this.sessionsDir=e}write(e,t){let n=it(e),r=t?.publication===`active`,i;try{if(At(e))return{written:!1};let a=Mt(e,{appendCompleteSentinel:n,activePublication:r});i=this.resolveScriptPath(e);let o=S.dirname(i);return C.existsSync(o)||C.mkdirSync(o,{recursive:!0}),Ft({scriptPath:i,script:a.script,force:t?.force}),n&&(e.scriptPublication=Ie(e.scriptPublication??h)),{written:!0,path:i,actionCount:a.actionCount}}catch(t){return Nt({session:e,error:t,scriptPath:i,repairArmed:n,activePublication:r})}}resolveScriptPath(e){let t=De(e.scriptPublication??h);if(t)return x(t);let n=b(e.name),r=new Date(e.createdAt).toISOString().replaceAll(/[:.]/g,`-`);return S.join(this.sessionsDir,`${n}-${r}.ad`)}};function Mt(e,t){let n=It(e,{strictPortableRefs:t.activePublication});return t.activePublication&&bt(n),{script:Kt(e,n,t.appendCompleteSentinel),actionCount:n.length}}function Nt(t){let{session:n,error:r,scriptPath:i,repairArmed:a,activePublication:o}=t;if(y({level:`warn`,phase:`session_script_write_failed`,data:{session:n.name,path:i,error:r instanceof Error?r.message:String(r)}}),a)return{written:!1,error:Pt(r,i)};if(o)return{written:!1,error:Tt(r,i)};if(r instanceof e)throw r;return{written:!1}}function Pt(t,n){if(t instanceof e)return t;let r=t instanceof Error?t.message:String(t);return new e(`COMMAND_FAILED`,`Failed to write the healed script${n?` to ${n}`:``}: ${r}`,{hint:`The repair transaction completed but the healed .ad could not be published; check the target path and permissions, then retry close --save-script.`})}function Ft(t){let{scriptPath:n,script:r,force:i}=t;try{He({destination:n,contents:r,publish:i?`replace`:`link-exclusive`})}catch(t){throw t.code===`EEXIST`?new e(`COMMAND_FAILED`,`A file already exists at ${n}; remove it, pass replay --save-script=<other-path>, or pass --force/--overwrite to replace it.`,{reason:`script_target_exists`,path:n}):t}}function It(e,t={}){let n=T(e),r=n!==void 0,i=e.actions.slice(n??0),a=[];for(let n of i){if(n.command===`snapshot`)continue;let i=zt(n);if(i){a.push(i);continue}(r||t.strictPortableRefs)&&Lt(n);let o=Gt(e,n);o&&a.push(o),a.push(n)}return t.strictPortableRefs&&xt(a),a}function Lt(t){let n=t.command===`gesture`?me(t.positionals??[]):void 0;if(n){Rt(n);return}if(!D(t.command))return;let r=t.command===`get`?t.positionals?.[1]:t.positionals?.[0];if(r?.startsWith(`@`))throw new e(`COMMAND_FAILED`,`Cannot write recorded step "${t.command} ${r}" to a script: it never resolved to a selector, so the ref would not resolve in a fresh replay session.`)}function Rt(t){let n=[t.source,t.destination].find(e=>e.startsWith(`@`));if(n)throw new e(`COMMAND_FAILED`,`Cannot write recorded drag endpoint "${n}" to a script: it never resolved to a selector, so the ref would not resolve in a fresh replay session.`)}function zt(e){let t=Bt(e);if(!(!t||!D(e.command)))return ce(e.command)||e.command===`hover`?{...e,positionals:[t]}:e.command===`longpress`?Ht(e,t):e.command===`fill`?Vt(e,t):Ut(e,t)}function Bt(e){let t=Array.isArray(e.result?.selectorChain)&&e.result.selectorChain.every(e=>typeof e==`string`)?e.result.selectorChain:[];return t.length>0?t.join(` || `):void 0}function D(e){return se(e)||e===`fill`||e===`get`}function Vt(e,t){let n=he(e);return n.length>0?{...e,positionals:[t,n]}:void 0}function Ht(e,t){let n=typeof e.result?.durationMs==`number`?String(e.result.durationMs):Wt(e.positionals??[]);return{...e,positionals:n?[t,n]:[t]}}function Ut(e,t){let n=e.positionals?.[0];return n===`text`||n===`attrs`?{...e,positionals:[n,t]}:void 0}function Wt(e){let t=e.at(-1);if(!(e.length<=1||t===void 0||t.trim()===``))return Number.isFinite(Number(t))?t:void 0}function Gt(e,t){if(!D(t.command))return;let n=t.result?.refLabel;if(typeof n!=`string`||n.trim().length===0)return;let r=n.trim();return{ts:t.ts,command:`snapshot`,positionals:[],flags:{platform:e.device.platform,snapshotInteractiveOnly:!0,snapshotScope:r},result:{scope:r}}}function Kt(e,t,n){let r=[],i=e.device.kind?` kind=${e.device.kind}`:``;r.push(`context platform=${o(e.device)} device=${de(e.device.name)}${i} theme=unknown`);for(let e of t)e.flags?.noRecord||(r.push(...Ze(e)),r.push(qt(e)));return n&&r.push(`# agent-device:heal-complete`),`${r.join(`
|
|
2
|
+
`)}\n`}function qt(e){return Jt([e.command],e)||Xe(e)}function Jt(e,t){if(ce(t.command))return Yt(e,t);if(t.command===`fill`)return Xt(e,t);if(t.command===`get`)return Zt(e,t)}function Yt(e,t){let n=t.positionals?.[0];if(n){if(n.startsWith(`@`))return e.push(p(f(n))),O(e,t),m(e,t),e.join(` `);if(t.positionals.length===1)return e.push(p(n)),m(e,t),e.join(` `)}}function Xt(e,t){let n=t.positionals?.[0];if(!n?.startsWith(`@`))return;e.push(p(f(n))),O(e,t);let r=t.positionals.slice(1).join(` `);return t.positionals.length>1&&e.push(p(r)),m(e,t),e.join(` `)}function Zt(e,t){let n=t.positionals?.[0],r=t.positionals?.[1];if(!(!n||!r))return e.push(p(n)),e.push(p(f(r))),r.startsWith(`@`)&&O(e,t),e.join(` `)}function O(e,t){let n=t.result?.refLabel;typeof n==`string`&&n.trim().length>0&&e.push(p(n))}const Qt=[`id`,`deviceId`,`device_id`,`serial`,`udid`,`device_udid`,`identifier`],$t={ios:`iOS`,ipados:`iPadOS`,tvos:`tvOS`,watchos:`watchOS`,visionos:`visionOS`,macos:`macOS`,apple:`Apple`,android:`Android`,linux:`Linux`,web:`Web`};function en(e,t){let n=t??{};switch(e.command){case g.devices:return tn(n.devices);case g.apps:return nn(n.apps,e.flags?.appsFilter);case g.boot:return k(`Booted`,n,!0);case g.shutdown:return k(`Shut down`,n,!1);case g.install:return rn(`Installed`,n);case g.reinstall:return rn(`Reinstalled`,n);case g.screenshot:return an(e,n);default:return{}}}function tn(e){if(!Array.isArray(e))return{};let t=e.flatMap(e=>{let t=sn(e);return t?[t]:[]}),n=t.slice(0,5),r=Math.max(0,t.length-n.length),i=t.slice(0,3);return{summary:gn(`Found ${t.length} ${_n(`device`,t.length)}`,i.map(e=>mn(e,!0)),Math.max(0,t.length-i.length)),details:{deviceCount:t.length,devices:n,...r>0?{omittedDeviceCount:r}:{}}}}function nn(e,t){if(!Array.isArray(e))return{};let n=e.flatMap(e=>{let t=M(e);return t?[t]:[]}),r=n.slice(0,5),i=Math.max(0,n.length-r.length),a=n.slice(0,3);return{summary:gn(`Found ${n.length} ${_n(`app`,n.length)}`,a,Math.max(0,n.length-a.length)),details:{appCount:n.length,apps:r,...i>0?{omittedAppCount:i}:{},...t===`all`||t===`user-installed`?{filter:t}:{}}}}function k(e,t,n){let r=cn(t);if(!r)return{};let i={device:r,...pn(t),booted:n};return{summary:`${e} ${mn(i,!1)}`,details:i}}function rn(e,t){let n=M(t.appName),r=M(t.bundleId),i=A(t,[`packageName`,`package`]),a=M(t.platform),o=M(t.launchTarget),s=A(t,[`bundleId`,`packageName`,`package`,`appId`,`launchTarget`]),c=hn(n,s);if(!c)return{};let l={};return j(l,`appName`,n),j(l,`bundleId`,r),j(l,`packageName`,i),j(l,`platform`,a),o!==s&&j(l,`launchTarget`,o),{summary:`${e} ${c}`,details:l}}function an(e,t){let n=on(e,t);return n?{details:{requestedFileName:n}}:{}}function on(e,t){let n=R(e.meta?.clientArtifactPaths?.path)??R(t.path);if(n)return L(n)}function sn(e){if(!n(e))return;let t=cn(e);if(t)return{name:t,...pn(e)}}function cn(e){let t=A(e,[`name`,`deviceName`,`device`]);return!t||!ln(e,t)?t:dn(e)}function ln(e,t){let n=un(t);return Qt.some(t=>{let r=M(e[t]);return r!==void 0&&un(r)===n})}function un(e){return e.toLowerCase()}function dn(e){let t=M(e.appleOs),n=M(e.platform),r=M(e.kind),i=fn(t,n);return i&&(r===`simulator`||r===`emulator`)?`${i} ${r}`:i?`${i} device`:r===`simulator`?`Simulator`:r===`emulator`?`Emulator`:`Unnamed device`}function fn(e,t){let n=e??t;if(!(!n||!Object.hasOwn($t,n)))return $t[n]}function pn(e){let t=M(e.platform),n=M(e.appleOs),r=M(e.kind),i=M(e.target);return{...t?{platform:t}:{},...n?{appleOs:n}:{},...r?{kind:r}:{},...i?{target:i}:{},...typeof e.booted==`boolean`?{booted:e.booted}:{}}}function mn(e,t){let n=M(e.name)??M(e.device)??`device`,r=M(e.platform),i=M(e.appleOs),a=[r,i===r?void 0:i,M(e.kind),M(e.target),t&&typeof e.booted==`boolean`?e.booted?`booted`:`stopped`:void 0].filter(e=>!!e);return a.length>0?`${n} (${a.join(`, `)})`:n}function hn(e,t){return e&&t&&e!==t?`${e} (${t})`:e??t}function A(e,t){for(let n of t){let t=M(e[n]);if(t)return t}}function j(e,t,n){n&&(e[t]=n)}function gn(e,t,n){let r=[...t,...n>0?[`+${n} more`]:[]];return r.length>0?`${e}: ${r.join(`, `)}`:e}function _n(e,t){return t===1?e:`${e}s`}function M(e){let t=R(e);if(!t)return;let n=t.trim(),r=Array.from(n);return r.length<=120?n:`${r.slice(0,119).join(``)}…`}function N(e){return M(e)}function P(e){return typeof e==`boolean`?e:void 0}function F(e,t){let n=N(e);return n&&t.includes(n)?n:void 0}function I(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0))}function L(e){let t=R(e);return t?M(t.split(/[\\/]/).at(-1)):void 0}function R(e){if(typeof e==`string`)return e.trim().length>0?e:void 0}function z(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}const vn=[`up`,`down`,`left`,`right`],yn=[`top`,`bottom`];function bn(e){return`${e.command===g.reinstall?`Reinstalled`:`Installed`} ${wn(e.result??{})??`app`}`}function xn(e){let t=e.result??{};switch(e.command){case g.scroll:return En(t);case g.screenshot:return kn(t);case g.home:return`Went home`;case g.back:return jn(t);case g.appSwitcher:return`Opened app switcher`;case g.actionButton:return`Pressed Action Button`;case g.orientation:return Nn(t);case g.fold:return Mn(t);case g.viewport:return Pn(t);case g.clipboard:return Fn(t);case g.keyboard:return In(t);case g.tvRemote:return zn(t);case g.gesture:return Bn(t);case g.swipe:return Vn(t);case g.trace:return Un(`trace`,e);case g.record:return Un(`recording`,e);default:return}}function Sn(e){let t=e.result??{};switch(e.command){case g.scroll:return I({direction:F(t.direction,vn),edge:F(t.edge,yn),passes:z(t.passes),amount:z(t.amount),pixels:z(t.pixels),durationMs:z(t.durationMs),x1:z(t.x1),y1:z(t.y1),x2:z(t.x2),y2:z(t.y2)});case g.screenshot:return I({requestedFileName:An(t)});case g.back:return I({mode:F(t.mode,d)});case g.orientation:return I({orientation:F(t.orientation,Ve)});case g.fold:return I({pose:F(t.pose,_)});case g.viewport:return I({width:z(t.width),height:z(t.height)});case g.clipboard:return I({action:F(t.action,[`read`,`write`])});case g.keyboard:return Rn(t);case g.tvRemote:return I({button:F(t.button,Ue),durationMs:z(t.durationMs)});case g.gesture:case g.swipe:return Hn(t);case g.trace:case g.record:return I({action:F(t.action,[`start`,`stop`]),fileName:Gn(e),showTouches:P(t.showTouches)});default:return{}}}function Cn(e,t){if(e.command!==g.screenshot)return t;let n=on(e,t);return n?{...t,requestedFileName:n}:t}function wn(e){let t=N(e.appName),n=Kn(e,[`bundleId`,`packageName`,`appBundleId`,`launchTarget`]);return t&&n&&t!==n?`${t} (${n})`:t??n??Tn(e)}function Tn(e){let t=N(e.app);return t&&!t.includes(`/`)&&!t.includes(`\\`)?t:void 0}function En(e){let t=F(e.direction,vn),n=F(e.edge,yn),r=z(e.passes);return n?Dn(n,r):t?On(t,e):`Scrolled`}function Dn(e,t){return t===0?`Already at ${e}`:t===void 0?`Scrolled to ${e}`:`Scrolled to ${e} in ${t} ${t===1?`pass`:`passes`}`}function On(e,t){let n=z(t.pixels);if(n!==void 0)return`Scrolled ${e} by ${n}px`;let r=z(t.amount);return r===void 0?`Scrolled ${e}`:`Scrolled ${e} by ${r}`}function kn(e){let t=An(e);return t?`Captured screenshot ${t}`:`Captured screenshot`}function An(e){return L(e.requestedFileName)??L(e.path)}function jn(e){return F(e.mode,d)===`system`?`Went back using system navigation`:`Went back`}function Mn(e){let t=F(e.pose,_);return t?`Folded to ${t}`:`Changed fold pose`}function Nn(e){let t=F(e.orientation,Ve);return t?P(e.confirmed)===!1?`Requested ${t} (unconfirmed)`:`Rotated to ${t}`:`Changed orientation`}function Pn(e){let t=z(e.width),n=z(e.height);return t!==void 0&&n!==void 0?`Set viewport to ${t}×${n}`:`Changed viewport`}function Fn(e){let t=F(e.action,[`read`,`write`]);return t===`read`?`Read clipboard`:t===`write`?`Updated clipboard`:`Used clipboard`}function In(e){let t=R(e.action);if(!t||!qe(t))return`Used keyboard`;if(t===`dismiss`)return Ln(e);if(t===`enter`||t===`return`)return`Pressed keyboard return`;let n=P(e.visible);return n===void 0?`Inspected keyboard`:n?`Keyboard is visible`:`Keyboard is hidden`}function Ln(e){return P(e.dismissed)===!1?`Keyboard was already hidden`:`Dismissed keyboard`}function Rn(e){let t=R(e.action);return I({action:t&&qe(t)?t:void 0,platform:F(e.platform,[`ios`,`android`]),visible:P(e.visible),wasVisible:P(e.wasVisible),dismissed:P(e.dismissed),attempts:z(e.attempts),mechanism:F(e.mechanism,[`dismissKey`])})}function zn(e){let t=F(e.button,Ue);return t?`Pressed TV remote ${t}`:`Used TV remote`}function Bn(e){let t=F(e.kind,[`fling`,`pan`,`pinch`,`rotate`,`transform`]);return t?`Ran ${t} gesture`:`Ran gesture`}function Vn(e){let t=z(e.count);return t!==void 0&&t>1?`Swiped ${t} times`:`Swiped`}function Hn(e){return I({kind:F(e.kind,[`fling`,`pan`,`pinch`,`rotate`,`transform`]),durationMs:z(e.durationMs),pointerCount:z(e.pointerCount),x1:z(e.x1),y1:z(e.y1),x2:z(e.x2),y2:z(e.y2),count:z(e.count),pauseMs:z(e.pauseMs),pattern:F(e.pattern,[`one-way`,`ping-pong`]),scale:z(e.scale)})}function Un(e,t){let n=Wn(e,F(t.result?.action,[`start`,`stop`])),r=Gn(t);return r?`${n} ${r}`:n}function Wn(e,t){return t===`start`?e===`trace`?`Started trace`:`Started recording`:t===`stop`?e===`trace`?`Stopped trace`:`Stopped recording`:e===`trace`?`Updated trace`:`Updated recording`}function Gn(e){let t=e.result??{};return L(t.requestedFileName)??L(t.outPath)??L(t.path)??L(e.positionals[1])}function Kn(e,t){for(let n of t){let t=N(e[n]);if(t)return t}}function qn(e){switch(e.command){case g.open:return`Opened ${B(e)??`session`}`;case g.close:return`Closed ${N(e.result?.session)??`session`}`;case g.click:case g.press:return`Tapped ${B(e)??`target`}`;case g.longPress:return`Long pressed ${B(e)??`target`}`;case g.hover:return`Hovered ${B(e)??`target`}`;case g.fill:return`Filled ${B(e)??`target`}`;case g.type:return`Typed text`;case g.install:case g.reinstall:case Le.installSource:return bn(e);default:return xn(e)??`Ran ${e.command}`}}function Jn(e){return I({command:e.command,positionals:rr(e),flags:hr(e),...Yn(e),...Xn(e),...Zn(e),...Sn(e)})}function Yn(e){if(!Qn(e.command))return{};let t=e.result??{};return I({ref:G(t),targetLabel:B(e),selectorChainLength:dr(t.selectorChain)?.length,x:z(t.x),y:z(t.y),x2:z(t.x2),y2:z(t.y2),durationMs:z(t.durationMs)})}function Xn(e){if(!$n(e.command))return{};let t=e.result??{};return I({platform:F(t.platform,r),target:F(t.target,a),appName:N(t.appName),appBundleId:N(t.appBundleId),bundleId:N(t.bundleId),packageName:N(t.packageName),launchTarget:N(t.launchTarget)})}function Zn(e){let t=e.result??{};return e.command===g.snapshot?Array.isArray(t.nodes)?{nodeCount:t.nodes.length}:{}:e.command!==g.wait&&e.command!==g.find&&e.command!==g.get&&e.command!==g.is?{}:I({waitedMs:z(t.waitedMs),found:P(t.found)})}function Qn(e){return e===g.click||e===g.press||e===g.longPress||e===g.hover||e===g.focus||e===g.fill}function $n(e){return e===g.open||e===g.install||e===g.reinstall||e===Le.installSource}function B(e){let t=e.result??{};return er(t)??tr(t)??nr(t)??lr(e.positionals[0])}function er(e){let t=G(e);if(t)return t.startsWith(`@`)?t:`@${t}`}function tr(e){let t=z(e.x),n=z(e.y);if(t!==void 0&&n!==void 0)return`(${t}, ${n})`}function nr(e){return N(e.appName)??N(e.appBundleId)??N(e.bundleId)??N(e.packageName)}function rr(e){if(e.positionals.length!==0)return e.command===g.type?[H(`text`)]:e.command===g.fill?ir(e):e.command===g.find?ar(e):e.command===g.clipboard?or(e):e.command===g.push?sr(e,`app`,`payload`):e.command===g.triggerAppEvent?sr(e,`event`,`payload`):e.positionals.map(V)}function ir(e){let t=H(`text`),n=e.result??{},r=G(n);if(r)return[`@${r}`,t];if(N(n.selector))return[H(`target`),t];let i=z(n.x),a=z(n.y);return i!==void 0&&a!==void 0?[String(i),String(a),t]:[t]}function ar(e){let t=+!!ur(e.positionals[0]);if(e.positionals[t]===void 0)return;let n=t+1,r=[...t===1?[String(e.positionals[0])]:[],H(`query`)],i=e.positionals[n];return i?i===`fill`||i===`type`?[...r,i,H(`text`)]:[...r,...e.positionals.slice(n).map(cr)]:r}function or(e){let t=e.positionals[0]?.toLowerCase();return t===`read`?[`read`]:t===`write`?[`write`,H(`text`)]:e.positionals.map(V)}function sr(e,t,n){let[r,i,...a]=e.positionals;return[...r?[H(t)]:[],...i?[H(n)]:[],...a.map(V)]}function cr(e){return e===`click`||e===`focus`||e===`exists`||e===`get`||e===`text`||e===`attrs`||e===`wait`?e:V(e)}function V(e){return lr(e)??H(`arg`)}function lr(e){if(!e)return;let t=e.trim();if(/^@[a-zA-Z0-9:_-]+$/.test(t))return t}function H(e){return`<${e}>`}function ur(e){return e===`text`||e===`label`||e===`value`||e===`role`||e===`id`}function dr(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)?e:void 0}const fr={enums:[{source:`platform`,values:i},{source:`target`,values:a}]},pr={booleans:[{source:`settle`}],numbers:[{source:`settleQuietMs`}]},mr={[g.open]:{booleans:[{source:`relaunch`},{source:`testIme`}],enums:[{source:`surface`,values:Re}]},[g.click]:U(),[g.press]:U(),[g.longPress]:U(),[g.hover]:U(),[g.fill]:_r(),[g.type]:_r(),[g.scroll]:{numbers:[{source:`pixels`},{source:`durationMs`}]},[g.gesture]:vr(),[g.swipe]:vr(),[g.screenshot]:{booleans:[{source:`overlayRefs`},{source:`screenshotFullscreen`,output:`fullscreen`},{source:`screenshotNoStabilize`,output:`noStabilize`},{source:`screenshotNormalizeStatusBar`,output:`normalizeStatusBar`}],numbers:[{source:`screenshotPixelDensity`,output:`pixelDensity`},{source:`screenshotScale`,output:`scale`}]},[g.snapshot]:{booleans:[{source:`snapshotInteractiveOnly`,output:`interactiveOnly`},{source:`snapshotDiff`,output:`diff`},{source:`snapshotRaw`,output:`raw`},{source:`snapshotCustomActions`,output:`actions`},{source:`snapshotForceFull`,output:`forceFull`}],numbers:[{source:`snapshotDepth`,output:`depth`}]},[g.back]:{enums:[{source:`backMode`,output:`mode`,values:d}]},[g.record]:{booleans:[{source:`hideTouches`}],numbers:[{source:`fps`}],enums:[{source:`recordingScope`,output:`scope`,values:re}]},[g.apps]:{enums:[{source:`appsFilter`,output:`filter`,values:[`user-installed`,`all`]}]},[g.boot]:{booleans:[{source:`headless`}]},[g.close]:{booleans:[{source:`shutdown`}]}};function hr(e){let t=e.flags??{},n={},r=Object.hasOwn(mr,e.command)?mr[e.command]:void 0;return W(n,t,fr),W(n,t,r),W(n,t,gr(e.command)),Object.keys(n).length>0?n:void 0}function gr(e){return ee(e)?pr:void 0}function U(){return{booleans:[{source:`doubleTap`}],numbers:[{source:`count`},{source:`intervalMs`},{source:`holdMs`},{source:`jitterPx`}],enums:[{source:`clickButton`,values:Be}]}}function _r(){return{numbers:[{source:`delayMs`}]}}function vr(){return{numbers:[{source:`pointerCount`},{source:`count`},{source:`pauseMs`}],enums:[{source:`pattern`,values:ie}]}}function W(e,t,n){n&&(yr(e,t,n.booleans??[]),br(e,t,n.numbers??[]),xr(e,t,n.enums??[]))}function yr(e,t,n){for(let r of n)Sr(e,r.output??r.source,t[r.source])}function br(e,t,n){for(let r of n)Cr(e,r.output??r.source,t[r.source])}function xr(e,t,n){for(let r of n)wr(e,r.output??r.source,t[r.source],r.values)}function G(e){let t=N(e.ref);if(!t)return;let n=t.startsWith(`@`)?t.slice(1):t;return/^[a-zA-Z0-9:_-]+$/.test(n)?n:void 0}function Sr(e,t,n){typeof n==`boolean`&&(e[t]=n)}function Cr(e,t,n){let r=z(n);r!==void 0&&(e[t]=r)}function wr(e,t,n,r){let i=F(n,r);i!==void 0&&(e[t]=i)}const Tr=65536;function Er(e){return Je(`sha256`).update(e,`utf8`).digest(`hex`).slice(0,32)}function K(e,t){let n=Ar(e);if(n===void 0)return!1;try{let e=Or(t),r=Buffer.allocUnsafe(Tr),i=0;do if(i=C.readSync(n,r,0,r.length,null),!e.push(r.subarray(0,i)))return!0;while(i>0);return e.end(),!0}finally{C.closeSync(n)}}async function Dr(e){let t=await jr(e);if(t===void 0)return{lineCount:0,firstLineDigest:void 0};let n={lineCount:0,firstLineDigest:void 0};try{let e=Or(e=>{n.lineCount===0&&(n.firstLineDigest=Er(e)),n.lineCount+=1}),r=Buffer.allocUnsafe(Tr);for(;;){let{bytesRead:n}=await t.read(r,0,r.length,null);if(e.push(r.subarray(0,n)),n===0)break}return e.end(),n}finally{await t.close()}}function q(e){let t;return K(e,e=>(t=Er(e),!1)),t}function Or(e){let t=new Ye(`utf8`),n=``,r=!1;return{push(i){if(r)return!1;let a=`${n}${t.write(i)}`,o=0;for(let t=a.indexOf(`
|
|
3
3
|
`);t!==-1;t=a.indexOf(`
|
|
4
|
-
`,o)){if(Dr(a.slice(o,t),e)===!1)return r=!0,!1;o=t+1}return n=a.slice(o),!0},end(){r||Dr(`${n}${t.end()}`,e)}}}function Dr(e,t){let n=e.endsWith(`\r`)?e.slice(0,-1):e;if(n.trim().length!==0)return t(n)}function Or(e){try{return C.openSync(e,`r`)}catch(e){if(e.code===`ENOENT`)return;throw e}}async function kr(e){try{return await C.promises.open(e,`r`)}catch(e){if(e.code===`ENOENT`)return;throw e}}const Ar=5242880;function jr(e=process.env){let t=e.AGENT_DEVICE_EVENT_LOG_MAX_BYTES?.trim();if(t===void 0||!/^\d+$/.test(t))return Ar;let n=Number(t);return Number.isSafeInteger(n)&&n>0?n:Ar}function J(e){return`${e}.1`}function Y(e){return`${e}.window.json`}function Mr(e){let t;for(let n=0;n<3;n+=1){let n=Z(e);try{let t=Nr(e);if(Z(e)===n)return t}catch(r){if(t=r,Z(e)===n)throw r}}throw t??X(e,`the window did not settle while reading`)}function Nr(e){let t=J(e),n=Br(e);if(n===`unverifiable`)throw X(e,`window file is invalid`);if(n===void 0)return Pr(e,t);let r=n.at(-1);if(!r)throw X(e,`window file records no generation`);let i=Ur(e),a=Fr(e,r),o=[],s=Ir({eventLogPath:e,rotatedPath:t,sidecar:n,activeStart:a,activeExists:i});return s!==void 0&&o.push({path:t,firstLineIndex:s}),i&&o.push({path:e,firstLineIndex:a}),{files:o,earliestCursor:o[0]?.firstLineIndex??a}}function Pr(e,t){if(q(t)!==void 0)throw X(e,`a rotated event log exists with no window record`);return{files:Ur(e)?[{path:e,firstLineIndex:0}]:[],earliestCursor:0}}function Fr(e,t){let n=q(e);return n!==void 0&&n===t.firstLineDigest?t.firstLineIndex:t.firstLineIndex+t.lineCount}function Ir(e){let{eventLogPath:t,rotatedPath:n,sidecar:r,activeStart:i,activeExists:a}=e,o=q(n);if(o===void 0)return;let s=r.find(e=>e.firstLineDigest===o);if(!s)throw X(t,`the rotated event log matches no window record`);let c=zr(n);if(c!==s.lineCount)throw X(t,`the rotated event log holds ${c} lines, the window recorded ${s.lineCount}`);if(a&&s.firstLineIndex+s.lineCount!==i)throw X(t,`retained event log generations are not contiguous`);return s.firstLineIndex}async function Lr(e,t){let n=Wr(e);if(!n||n.size<t)return!1;let r=Br(e);if(r===`unverifiable`)return await C.promises.rename(e,J(e)),!0;let i=await Tr(e);if(i.firstLineDigest!==void 0){let t=r??[],n=t.at(-1),a=n&&n.firstLineDigest===i.firstLineDigest?n:{firstLineIndex:n?n.firstLineIndex+n.lineCount:0,lineCount:i.lineCount,firstLineDigest:i.firstLineDigest};await Hr(e,(a===n?t:[...t,a]).slice(-2))}return await C.promises.rename(e,J(e)),!0}function Rr(t,n){if(!(t>=n))throw new e(`COMMAND_FAILED`,`events cursor ${t} precedes the retained event log window; events before cursor ${n} were rotated out.`,{reason:`EVENT_LOG_CURSOR_EXPIRED`,cursor:t,earliestCursor:n,hint:`Resume with cursor ${n}, the oldest retained event; earlier events are no longer available.`})}function X(t,n){return new e(`COMMAND_FAILED`,`Session event log window cannot be verified: ${n}.`,{reason:`EVENT_LOG_WINDOW_UNVERIFIED`,path:t,hint:`Cursor positions for this session cannot be resolved. Delete ${t}, ${J(t)}, and ${Y(t)} to restart the timeline, or read the files directly.`})}function zr(e){let t=0;return K(e,()=>{t+=1}),t}function Z(e){return[Q(Y(e)),Q(e),Q(J(e))].join(`|`)}function Q(e){try{let t=C.lstatSync(e);return`${t.ino}:${t.size}:${t.mtimeMs}`}catch{return`absent`}}function Br(e){let t;try{t=C.readFileSync(Y(e),`utf8`)}catch(e){return e.code===`ENOENT`?void 0:`unverifiable`}try{let e=JSON.parse(t);if(!n(e)||e.version!==2)return`unverifiable`;let{generations:r}=e;if(!Array.isArray(r)||r.length===0)return`unverifiable`;let i=r.map(Vr);return i.every(e=>e!==void 0)?i:`unverifiable`}catch{return`unverifiable`}}function Vr(e){if(!n(e))return;let{firstLineIndex:t,lineCount:r,firstLineDigest:i}=e;if(!(!Number.isSafeInteger(t)||t<0)&&!(!Number.isSafeInteger(r)||r<0)&&typeof i==`string`&&i.length!==0)return{firstLineIndex:t,lineCount:r,firstLineDigest:i}}async function Hr(e,t){let n=Y(e),r=`${n}.${process.pid}.tmp`;await C.promises.writeFile(r,JSON.stringify({version:2,generations:t}),`utf8`),await C.promises.rename(r,n)}function Ur(e){return Wr(e)!==void 0}function Wr(t){try{let n=C.lstatSync(t);if(n.isSymbolicLink())throw new e(`COMMAND_FAILED`,`Session event log must not be a symbolic link: ${t}`);return n}catch(e){if(e.code===`ENOENT`)return;throw e}}const $=new Map,Gr=new Set;function Kr(e){return S.join(e,`events.ndjson`)}function qr(e){return e.command!==h.events}function Jr(e,n,r){let i=t({version:1,ts:r.ts??new Date().toISOString(),session:n,...r});Xr(e,`${JSON.stringify(i)}\n`)}async function Yr(e){await(e?$.get(e):Promise.all($.values()))}function Xr(e,t){let n=($.get(e)??Promise.resolve()).catch(()=>void 0).then(async()=>{await Zr(e),await Lr(e,jr()),await C.promises.appendFile(e,t,`utf8`)}).catch(t=>{y({level:`warn`,phase:`session_event_log_write_failed`,data:{path:e,error:t instanceof Error?t.message:String(t)}})}).finally(()=>{$.get(e)===n&&$.delete(e)});$.set(e,n)}async function Zr(e){let t=S.dirname(e);if(!Gr.has(t))try{await C.promises.mkdir(t,{recursive:!0}),Gr.add(t)}catch(t){throw y({level:`warn`,phase:`session_event_log_dir_failed`,data:{path:e,error:t instanceof Error?t.message:String(t)}}),t}}function Qr(e,t,n){Jr(e,t,{kind:`action.recorded`,requestId:v().requestId,command:n.command,summary:Gn(n),details:Kn(n)})}function $r(e){let{req:t}=e;return{kind:`request.started`,requestId:t.meta?.requestId??v().requestId,command:t.command,summary:`Started ${t.command}`}}function ei(e){let{req:t,response:n,durationMs:r}=e;if(n.ok){let e=$t(t,n.data);return{kind:`request.finished`,requestId:t.meta?.requestId??v().requestId,command:t.command,status:`ok`,summary:e.summary??`Finished ${t.command}`,details:{durationMs:r,...e.details}}}return{kind:`request.finished`,requestId:t.meta?.requestId??v().requestId,command:t.command,status:`error`,summary:`Failed ${t.command}: ${n.error.code}`,details:{durationMs:r,code:n.error.code,diagnosticId:n.error.diagnosticId}}}function ti(e,t={}){let n=ri(t.cursor),r=ii(t.limit),i=Mr(e);Rr(n,i.earliestCursor);let a=ni(i.files,n,r),o=a.lines.flatMap(e=>{let t=ai(e);return t?[t]:[]});return{path:e,cursor:String(n),limit:r,events:o,...a.nextCursor===void 0?{}:{nextCursor:String(a.nextCursor)}}}function ni(e,t,n){let r=[],i;for(let a of e){let e=a.firstLineIndex;if(K(a.path,a=>{if(e>=t+n)return i=t+n,!1;e>=t&&r.push(a),e+=1}),i!==void 0)break}return{lines:r,...i===void 0?{}:{nextCursor:i}}}function ri(t){if(t===void 0||t.trim()===``)return 0;let n=Number(t);if(Number.isInteger(n)&&n>=0)return n;throw new e(`INVALID_ARGS`,`events cursor must be a non-negative integer string.`)}function ii(t){if(t===void 0||typeof t==`string`&&t.trim()===``)return 100;let n=typeof t==`string`?Number(t):t;if(Number.isInteger(n)&&n>=1&&n<=500)return n;throw new e(`INVALID_ARGS`,`events limit must be between 1 and 500.`)}function ai(e){try{let t=oi(JSON.parse(e));return t?si(t):void 0}catch{return}}function oi(e){if(n(e)&&e.version===1&&typeof e.ts==`string`&&typeof e.session==`string`&&ci(e.kind))return e}function si(e){let t=n(e.details)?e.details:void 0;return{version:1,ts:e.ts,session:e.session,kind:e.kind,...typeof e.requestId==`string`?{requestId:e.requestId}:{},...typeof e.command==`string`?{command:e.command}:{},...li(e.status)?{status:e.status}:{},...typeof e.summary==`string`?{summary:e.summary}:{},...t?{details:t}:{}}}function ci(e){return e===`request.started`||e===`request.finished`||e===`action.recorded`}function li(e){return e===`ok`||e===`error`}const ui=36e5;var di=class{sessions=new Map;runtimeHints=new Map;sessionsDir;scriptWriter;constructor(e){this.sessionsDir=e,this.scriptWriter=new At(e)}get(e){return this.sessions.get(e)}set(e,t){this.sessions.set(e,t)}delete(e){return this.runtimeHints.delete(e),this.sessions.delete(e)}values(){return this.sessions.values()}toArray(){return Array.from(this.sessions.values())}lookup(e){let t=this.sessions.get(e);return t?{address:e,session:t}:void 0}findByDevice(e){for(let[t,n]of this.sessions)if(n.device.id===e)return{address:t,session:n}}listRefs(){return Array.from(this.sessions,([e,t])=>({address:e,session:t}))}getRuntimeHints(e){return this.runtimeHints.get(e)}setRuntimeHints(e,t){this.runtimeHints.set(e,t)}clearRuntimeHints(e){return this.runtimeHints.delete(e)}recordAction(e,t){let n=ot(e,t);if(n){let t=this.resolveStoredSessionName(e);Qr(this.resolveEventLogPath(t),t,n)}}recordEvent(e,t){Jr(this.resolveEventLogPath(e),e,t)}readEvents(e,t={}){return ti(this.resolveEventLogPath(e),t)}async flushEvents(e){await Yr(e?this.resolveEventLogPath(e):void 0)}writeSessionLog(e,t){let n=this.scriptWriter.write(e,t);return n.written&&y({level:`info`,phase:`session_script_written`,data:{session:e.name,path:n.path}}),n}finalizeRepairTeardown(e){this.recordRepairFinalizeCloseIfCommitting(e);let t=this.writeSessionLog(e,{force:ke(e,void 0)});it(e)&&(!t.written&&t.error?this.writeRepairTombstone(e,ui,{code:String(t.error.code),message:t.error.message}):this.writeRepairTombstone(e))}recordRepairFinalizeCloseIfCommitting(e){let t=e.scriptPublication??m;Se(t)&&this.recordAction(e,{command:`close`,positionals:[],flags:{},result:{session:e.name,...ze(`Closed: ${e.name}`)}})}writeRepairTombstone(e,t=ui,n){try{let r=this.resolveSessionDir(e.name);C.mkdirSync(r,{recursive:!0});let i={owner:e.name,reapedAt:Date.now(),expiresAt:Date.now()+t,...at(e)?{sourcePath:at(e)}:{},...n?{commitFailure:n}:{}};C.writeFileSync(this.repairTombstonePath(e.name),`${JSON.stringify(i)}\n`)}catch(t){y({level:`warn`,phase:`repair_tombstone_write_failed`,data:{session:e.name,error:t instanceof Error?t.message:String(t)}})}}readRepairTombstone(e){return Ue(this.repairTombstonePath(e))}clearRepairTombstone(e){try{C.rmSync(this.repairTombstonePath(e),{force:!0})}catch{}}repairTombstonePath(e){return We(this.resolveSessionDir(e))}defaultTracePath(e){let t=b(e.name),n=new Date().toISOString().replaceAll(/[:.]/g,`-`);return S.join(this.sessionsDir,`${t}-${n}.trace.log`)}resolveSessionDir(t){if(!Ge(t))throw new e(`INVALID_ARGS`,`Invalid session name ${JSON.stringify(t)}: a session name cannot be empty, ".", or "..".`);return S.join(this.sessionsDir,b(t))}resolveDaemonStateDir(){return S.dirname(this.sessionsDir)}ensureSessionDir(e){let t=this.resolveSessionDir(e);return C.mkdirSync(t,{recursive:!0}),t}resolveAppLogPath(e){return S.join(this.resolveSessionDir(e),`app.log`)}resolveAppLogPidPath(e){return S.join(this.resolveSessionDir(e),`app-log.pid`)}resolveEventLogPath(e){return Kr(this.resolveSessionDir(e))}static expandHome(e,t){return x(e,t)}resolveStoredSessionName(e){for(let[t,n]of this.sessions)if(n===e)return t;return e.name}};export{Qe as _,tr as a,st as c,nt as d,rt as f,T as g,et as h,qr as i,tt as l,$e as m,ei as n,Sn as o,it as p,$r as r,ht as s,di as t,Ze as u};
|
|
4
|
+
`,o)){if(kr(a.slice(o,t),e)===!1)return r=!0,!1;o=t+1}return n=a.slice(o),!0},end(){r||kr(`${n}${t.end()}`,e)}}}function kr(e,t){let n=e.endsWith(`\r`)?e.slice(0,-1):e;if(n.trim().length!==0)return t(n)}function Ar(e){try{return C.openSync(e,`r`)}catch(e){if(e.code===`ENOENT`)return;throw e}}async function jr(e){try{return await C.promises.open(e,`r`)}catch(e){if(e.code===`ENOENT`)return;throw e}}const Mr=5242880;function Nr(e=process.env){let t=e.AGENT_DEVICE_EVENT_LOG_MAX_BYTES?.trim();if(t===void 0||!/^\d+$/.test(t))return Mr;let n=Number(t);return Number.isSafeInteger(n)&&n>0?n:Mr}function J(e){return`${e}.1`}function Y(e){return`${e}.window.json`}function Pr(e){let t;for(let n=0;n<3;n+=1){let n=Z(e);try{let t=Fr(e);if(Z(e)===n)return t}catch(r){if(t=r,Z(e)===n)throw r}}throw t??X(e,`the window did not settle while reading`)}function Fr(e){let t=J(e),n=Hr(e);if(n===`unverifiable`)throw X(e,`window file is invalid`);if(n===void 0)return Ir(e,t);let r=n.at(-1);if(!r)throw X(e,`window file records no generation`);let i=Gr(e),a=Lr(e,r),o=[],s=Rr({eventLogPath:e,rotatedPath:t,sidecar:n,activeStart:a,activeExists:i});return s!==void 0&&o.push({path:t,firstLineIndex:s}),i&&o.push({path:e,firstLineIndex:a}),{files:o,earliestCursor:o[0]?.firstLineIndex??a}}function Ir(e,t){if(q(t)!==void 0)throw X(e,`a rotated event log exists with no window record`);return{files:Gr(e)?[{path:e,firstLineIndex:0}]:[],earliestCursor:0}}function Lr(e,t){let n=q(e);return n!==void 0&&n===t.firstLineDigest?t.firstLineIndex:t.firstLineIndex+t.lineCount}function Rr(e){let{eventLogPath:t,rotatedPath:n,sidecar:r,activeStart:i,activeExists:a}=e,o=q(n);if(o===void 0)return;let s=r.find(e=>e.firstLineDigest===o);if(!s)throw X(t,`the rotated event log matches no window record`);let c=Vr(n);if(c!==s.lineCount)throw X(t,`the rotated event log holds ${c} lines, the window recorded ${s.lineCount}`);if(a&&s.firstLineIndex+s.lineCount!==i)throw X(t,`retained event log generations are not contiguous`);return s.firstLineIndex}async function zr(e,t){let n=Kr(e);if(!n||n.size<t)return!1;let r=Hr(e);if(r===`unverifiable`)return await C.promises.rename(e,J(e)),!0;let i=await Dr(e);if(i.firstLineDigest!==void 0){let t=r??[],n=t.at(-1),a=n&&n.firstLineDigest===i.firstLineDigest?n:{firstLineIndex:n?n.firstLineIndex+n.lineCount:0,lineCount:i.lineCount,firstLineDigest:i.firstLineDigest};await Wr(e,(a===n?t:[...t,a]).slice(-2))}return await C.promises.rename(e,J(e)),!0}function Br(t,n){if(!(t>=n))throw new e(`COMMAND_FAILED`,`events cursor ${t} precedes the retained event log window; events before cursor ${n} were rotated out.`,{reason:`EVENT_LOG_CURSOR_EXPIRED`,cursor:t,earliestCursor:n,hint:`Resume with cursor ${n}, the oldest retained event; earlier events are no longer available.`})}function X(t,n){return new e(`COMMAND_FAILED`,`Session event log window cannot be verified: ${n}.`,{reason:`EVENT_LOG_WINDOW_UNVERIFIED`,path:t,hint:`Cursor positions for this session cannot be resolved. Delete ${t}, ${J(t)}, and ${Y(t)} to restart the timeline, or read the files directly.`})}function Vr(e){let t=0;return K(e,()=>{t+=1}),t}function Z(e){return[Q(Y(e)),Q(e),Q(J(e))].join(`|`)}function Q(e){try{let t=C.lstatSync(e);return`${t.ino}:${t.size}:${t.mtimeMs}`}catch{return`absent`}}function Hr(e){let t;try{t=C.readFileSync(Y(e),`utf8`)}catch(e){return e.code===`ENOENT`?void 0:`unverifiable`}try{let e=JSON.parse(t);if(!n(e)||e.version!==2)return`unverifiable`;let{generations:r}=e;if(!Array.isArray(r)||r.length===0)return`unverifiable`;let i=r.map(Ur);return i.every(e=>e!==void 0)?i:`unverifiable`}catch{return`unverifiable`}}function Ur(e){if(!n(e))return;let{firstLineIndex:t,lineCount:r,firstLineDigest:i}=e;if(!(!Number.isSafeInteger(t)||t<0)&&!(!Number.isSafeInteger(r)||r<0)&&typeof i==`string`&&i.length!==0)return{firstLineIndex:t,lineCount:r,firstLineDigest:i}}async function Wr(e,t){let n=Y(e),r=`${n}.${process.pid}.tmp`;await C.promises.writeFile(r,JSON.stringify({version:2,generations:t}),`utf8`),await C.promises.rename(r,n)}function Gr(e){return Kr(e)!==void 0}function Kr(t){try{let n=C.lstatSync(t);if(n.isSymbolicLink())throw new e(`COMMAND_FAILED`,`Session event log must not be a symbolic link: ${t}`);return n}catch(e){if(e.code===`ENOENT`)return;throw e}}const $=new Map,qr=new Set;function Jr(e){return S.join(e,`events.ndjson`)}function Yr(e){return e.command!==g.events}function Xr(e,n,r){let i=t({version:1,ts:r.ts??new Date().toISOString(),session:n,...r});Qr(e,`${JSON.stringify(i)}\n`)}async function Zr(e){await(e?$.get(e):Promise.all($.values()))}function Qr(e,t){let n=($.get(e)??Promise.resolve()).catch(()=>void 0).then(async()=>{await $r(e),await zr(e,Nr()),await C.promises.appendFile(e,t,`utf8`)}).catch(t=>{y({level:`warn`,phase:`session_event_log_write_failed`,data:{path:e,error:t instanceof Error?t.message:String(t)}})}).finally(()=>{$.get(e)===n&&$.delete(e)});$.set(e,n)}async function $r(e){let t=S.dirname(e);if(!qr.has(t))try{await C.promises.mkdir(t,{recursive:!0}),qr.add(t)}catch(t){throw y({level:`warn`,phase:`session_event_log_dir_failed`,data:{path:e,error:t instanceof Error?t.message:String(t)}}),t}}function ei(e,t,n){Xr(e,t,{kind:`action.recorded`,requestId:v().requestId,command:n.command,summary:qn(n),details:Jn(n)})}function ti(e){let{req:t}=e;return{kind:`request.started`,requestId:t.meta?.requestId??v().requestId,command:t.command,summary:`Started ${t.command}`}}function ni(e){let{req:t,response:n,durationMs:r}=e;if(n.ok){let e=en(t,n.data);return{kind:`request.finished`,requestId:t.meta?.requestId??v().requestId,command:t.command,status:`ok`,summary:e.summary??`Finished ${t.command}`,details:{durationMs:r,...e.details}}}return{kind:`request.finished`,requestId:t.meta?.requestId??v().requestId,command:t.command,status:`error`,summary:`Failed ${t.command}: ${n.error.code}`,details:{durationMs:r,code:n.error.code,diagnosticId:n.error.diagnosticId}}}function ri(e,t={}){let n=ai(t.cursor),r=oi(t.limit),i=Pr(e);Br(n,i.earliestCursor);let a=ii(i.files,n,r),o=a.lines.flatMap(e=>{let t=si(e);return t?[t]:[]});return{path:e,cursor:String(n),limit:r,events:o,...a.nextCursor===void 0?{}:{nextCursor:String(a.nextCursor)}}}function ii(e,t,n){let r=[],i;for(let a of e){let e=a.firstLineIndex;if(K(a.path,a=>{if(e>=t+n)return i=t+n,!1;e>=t&&r.push(a),e+=1}),i!==void 0)break}return{lines:r,...i===void 0?{}:{nextCursor:i}}}function ai(t){if(t===void 0||t.trim()===``)return 0;let n=Number(t);if(Number.isInteger(n)&&n>=0)return n;throw new e(`INVALID_ARGS`,`events cursor must be a non-negative integer string.`)}function oi(t){if(t===void 0||typeof t==`string`&&t.trim()===``)return 100;let n=typeof t==`string`?Number(t):t;if(Number.isInteger(n)&&n>=1&&n<=500)return n;throw new e(`INVALID_ARGS`,`events limit must be between 1 and 500.`)}function si(e){try{let t=ci(JSON.parse(e));return t?li(t):void 0}catch{return}}function ci(e){if(n(e)&&e.version===1&&typeof e.ts==`string`&&typeof e.session==`string`&&ui(e.kind))return e}function li(e){let t=n(e.details)?e.details:void 0;return{version:1,ts:e.ts,session:e.session,kind:e.kind,...typeof e.requestId==`string`?{requestId:e.requestId}:{},...typeof e.command==`string`?{command:e.command}:{},...di(e.status)?{status:e.status}:{},...typeof e.summary==`string`?{summary:e.summary}:{},...t?{details:t}:{}}}function ui(e){return e===`request.started`||e===`request.finished`||e===`action.recorded`}function di(e){return e===`ok`||e===`error`}const fi=36e5;var pi=class{sessions=new Map;runtimeHints=new Map;sessionsDir;scriptWriter;constructor(e){this.sessionsDir=e,this.scriptWriter=new jt(e)}get(e){return this.sessions.get(e)}set(e,t){this.sessions.set(e,t)}delete(e){return this.runtimeHints.delete(e),this.sessions.delete(e)}values(){return this.sessions.values()}toArray(){return Array.from(this.sessions.values())}lookup(e){let t=this.sessions.get(e);return t?{address:e,session:t}:void 0}findByDevice(e){for(let[t,n]of this.sessions)if(n.device.id===e)return{address:t,session:n}}listRefs(){return Array.from(this.sessions,([e,t])=>({address:e,session:t}))}getRuntimeHints(e){return this.runtimeHints.get(e)}setRuntimeHints(e,t){this.runtimeHints.set(e,t)}clearRuntimeHints(e){return this.runtimeHints.delete(e)}recordAction(e,t){let n=st(e,t);if(n){let t=this.resolveStoredSessionName(e);ei(this.resolveEventLogPath(t),t,n)}}recordEvent(e,t){Xr(this.resolveEventLogPath(e),e,t)}readEvents(e,t={}){return ri(this.resolveEventLogPath(e),t)}async flushEvents(e){await Zr(e?this.resolveEventLogPath(e):void 0)}writeSessionLog(e,t){let n=this.scriptWriter.write(e,t);return n.written&&y({level:`info`,phase:`session_script_written`,data:{session:e.name,path:n.path}}),n}finalizeRepairTeardown(e){this.recordRepairFinalizeCloseIfCommitting(e);let t=this.writeSessionLog(e,{force:Oe(e,void 0)});at(e)&&(!t.written&&t.error?this.writeRepairTombstone(e,fi,{code:String(t.error.code),message:t.error.message}):this.writeRepairTombstone(e))}recordRepairFinalizeCloseIfCommitting(e){let t=e.scriptPublication??h;xe(t)&&this.recordAction(e,{command:`close`,positionals:[],flags:{},result:{session:e.name,...ze(`Closed: ${e.name}`)}})}writeRepairTombstone(e,t=fi,n){try{let r=this.resolveSessionDir(e.name);C.mkdirSync(r,{recursive:!0});let i={owner:e.name,reapedAt:Date.now(),expiresAt:Date.now()+t,...ot(e)?{sourcePath:ot(e)}:{},...n?{commitFailure:n}:{}};C.writeFileSync(this.repairTombstonePath(e.name),`${JSON.stringify(i)}\n`)}catch(t){y({level:`warn`,phase:`repair_tombstone_write_failed`,data:{session:e.name,error:t instanceof Error?t.message:String(t)}})}}readRepairTombstone(e){return We(this.repairTombstonePath(e))}clearRepairTombstone(e){try{C.rmSync(this.repairTombstonePath(e),{force:!0})}catch{}}repairTombstonePath(e){return Ge(this.resolveSessionDir(e))}defaultTracePath(e){let t=b(e.name),n=new Date().toISOString().replaceAll(/[:.]/g,`-`);return S.join(this.sessionsDir,`${t}-${n}.trace.log`)}resolveSessionDir(t){if(!Ke(t))throw new e(`INVALID_ARGS`,`Invalid session name ${JSON.stringify(t)}: a session name cannot be empty, ".", or "..".`);return S.join(this.sessionsDir,b(t))}resolveDaemonStateDir(){return S.dirname(this.sessionsDir)}ensureSessionDir(e){let t=this.resolveSessionDir(e);return C.mkdirSync(t,{recursive:!0}),t}resolveAppLogPath(e){return S.join(this.resolveSessionDir(e),`app.log`)}resolveAppLogPidPath(e){return S.join(this.resolveSessionDir(e),`app-log.pid`)}resolveEventLogPath(e){return Jr(this.resolveSessionDir(e))}static expandHome(e,t){return x(e,t)}resolveStoredSessionName(e){for(let[t,n]of this.sessions)if(n===e)return t;return e.name}};export{$e as _,rr as a,ct as c,rt as d,it as f,T as g,tt as h,Yr as i,nt as l,et as m,ni as n,Cn as o,at as p,ti as r,gt as s,pi as t,Qe as u};
|