sootsim 0.1.65 → 0.1.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/dist-cli/bin.js +3 -3
  2. package/dist-cli/chunks/{agent-44BHCTZA.js → agent-Z45KTLTP.js} +2 -2
  3. package/dist-cli/chunks/{agent-wrapper-BEP5WHZR.js → agent-wrapper-EEKVEJOC.js} +2 -2
  4. package/dist-cli/chunks/{assert-SKDEGGRD.js → assert-MDYZKXZ6.js} +2 -2
  5. package/dist-cli/chunks/auto-bootstrap-YZ6C6VYO.js +2 -0
  6. package/dist-cli/chunks/beta-WXH75XUE.js +2 -0
  7. package/dist-cli/chunks/chunk-2HKCZLY7.js +372 -0
  8. package/dist-cli/chunks/{chunk-46OKLW3Z.js → chunk-2I535GZU.js} +1 -1
  9. package/dist-cli/chunks/{chunk-L2SDB6G5.js → chunk-3KVVIZ6M.js} +2 -2
  10. package/dist-cli/chunks/chunk-42NMKOVE.js +3 -0
  11. package/dist-cli/chunks/{chunk-S46M5JZP.js → chunk-4H6LBA4A.js} +1 -1
  12. package/dist-cli/chunks/{chunk-M4HI2THN.js → chunk-4QSGVTBE.js} +2 -2
  13. package/dist-cli/chunks/{chunk-MLPLYQGK.js → chunk-52RZ6TSZ.js} +3 -3
  14. package/dist-cli/chunks/{chunk-ELZHT3LB.js → chunk-5WRBVYML.js} +2 -2
  15. package/dist-cli/chunks/{chunk-NJ2ACA36.js → chunk-67566AJS.js} +2 -2
  16. package/dist-cli/chunks/chunk-6O64VUC6.js +2 -0
  17. package/dist-cli/chunks/chunk-7PQHQOCI.js +186 -0
  18. package/dist-cli/chunks/{chunk-5ZB5ZN5Z.js → chunk-AQ7YR4MO.js} +14 -14
  19. package/dist-cli/chunks/{chunk-FRANP4PR.js → chunk-ATRGAFJD.js} +1 -1
  20. package/dist-cli/chunks/{chunk-OTWUZRFZ.js → chunk-BCVVANS5.js} +2 -2
  21. package/dist-cli/chunks/chunk-CUNQTNH4.js +35 -0
  22. package/dist-cli/chunks/{chunk-JC5L5ZJX.js → chunk-DOWYG3HG.js} +2 -2
  23. package/dist-cli/chunks/{chunk-MSBMGQJE.js → chunk-EJTXYZEF.js} +128 -36
  24. package/dist-cli/chunks/{chunk-P2C3JX3D.js → chunk-F23Y4HMT.js} +1 -1
  25. package/dist-cli/chunks/{chunk-GHFA4O5B.js → chunk-F4RC4AOY.js} +1 -1
  26. package/dist-cli/chunks/chunk-GFVC6EEB.js +1 -0
  27. package/dist-cli/chunks/{chunk-TWKWXGN5.js → chunk-HW5YHSIE.js} +1 -1
  28. package/dist-cli/chunks/{chunk-VGQXIMEX.js → chunk-IB4BRND4.js} +1 -1
  29. package/dist-cli/chunks/{chunk-X75XFMI4.js → chunk-IBWN764Q.js} +2 -2
  30. package/dist-cli/chunks/chunk-JE4JBSNJ.js +119 -0
  31. package/dist-cli/chunks/{chunk-O56DABNK.js → chunk-K4PKR2EO.js} +2 -2
  32. package/dist-cli/chunks/chunk-KBJ2WHII.js +73 -0
  33. package/dist-cli/chunks/chunk-KR36VJSN.js +1 -0
  34. package/dist-cli/chunks/{chunk-UHYZO26V.js → chunk-LQ5BA5JU.js} +2 -2
  35. package/dist-cli/chunks/chunk-MIAAZSSE.js +12 -0
  36. package/dist-cli/chunks/{chunk-PTUCXL7Y.js → chunk-N4JRDJMN.js} +3 -3
  37. package/dist-cli/chunks/{chunk-U5EQ5RWL.js → chunk-NYR3Z44O.js} +2 -2
  38. package/dist-cli/chunks/{chunk-2EBGZC4A.js → chunk-O624O5MO.js} +2 -2
  39. package/dist-cli/chunks/{chunk-HNXQ2JP6.js → chunk-SH6HMUCY.js} +2 -2
  40. package/dist-cli/chunks/chunk-SVFSMAZN.js +2 -0
  41. package/dist-cli/chunks/chunk-TEMZK6Q2.js +1 -0
  42. package/dist-cli/chunks/{chunk-KKOOZPQP.js → chunk-TLTS533S.js} +1 -1
  43. package/dist-cli/chunks/chunk-U47AHSGE.js +23 -0
  44. package/dist-cli/chunks/{chunk-6GZS5TCL.js → chunk-XCRUPKWB.js} +2 -2
  45. package/dist-cli/chunks/{chunk-5MMRIGC3.js → chunk-YGQV3CUV.js} +2 -2
  46. package/dist-cli/chunks/{chunk-GZCZ4GCS.js → chunk-ZJJKYJMH.js} +2 -2
  47. package/dist-cli/chunks/{chunk-FU33BTPL.js → chunk-ZO7SGE65.js} +1 -1
  48. package/dist-cli/chunks/{chunk-UH4H5HXN.js → chunk-ZP2HMCKS.js} +1 -1
  49. package/dist-cli/chunks/cli-version-5LGQQE5P.js +2 -0
  50. package/dist-cli/chunks/{compat-MDZTV64M.js → compat-5MMZ4R3Q.js} +3 -3
  51. package/dist-cli/chunks/{config-DRGNQOYL.js → config-YWN44WJQ.js} +2 -2
  52. package/dist-cli/chunks/control-LUCFDAZI.js +2 -0
  53. package/dist-cli/chunks/{cpu-profile-JQAGHLDS.js → cpu-profile-VFGUVXU5.js} +2 -2
  54. package/dist-cli/chunks/{daemon-3RT7EABW.js → daemon-ONX5ZBXF.js} +2 -2
  55. package/dist-cli/chunks/{debug-CYINYNWV.js → debug-CPOG32OT.js} +5 -5
  56. package/dist-cli/chunks/demo-app-registry-LWT6JLU6.js +2 -0
  57. package/dist-cli/chunks/{detox-DUABQYC6.js → detox-J6NGSZR5.js} +2 -2
  58. package/dist-cli/chunks/{device-KSSSQOQC.js → device-QYOQXI2P.js} +2 -2
  59. package/dist-cli/chunks/{diagnose-NUDACXIR.js → diagnose-MMW4LJLA.js} +2 -2
  60. package/dist-cli/chunks/drivers-NRWUJJCD.js +2 -0
  61. package/dist-cli/chunks/{electron-LC3Y74FA.js → electron-IK3HIZY4.js} +3 -3
  62. package/dist-cli/chunks/flow-2MB7HINM.js +2 -0
  63. package/dist-cli/chunks/{hints-EOARRVNB.js → hints-KZOD56U5.js} +2 -2
  64. package/dist-cli/chunks/{home-paths-HOBR3K3B.js → home-paths-R2YZZTUM.js} +2 -2
  65. package/dist-cli/chunks/inspect-ZARO3HQ4.js +970 -0
  66. package/dist-cli/chunks/install-O67RTYCX.js +2 -0
  67. package/dist-cli/chunks/{install-desktop-W2OOILJG.js → install-desktop-4GH5I7SC.js} +3 -3
  68. package/dist-cli/chunks/{keys-RR43E2O3.js → keys-AXEFZUUI.js} +2 -2
  69. package/dist-cli/chunks/{launch-GAPSA5HQ.js → launch-QLE56ON7.js} +3 -3
  70. package/dist-cli/chunks/{login-IADXSJEW.js → login-J45NQQM6.js} +4 -4
  71. package/dist-cli/chunks/{logout-AT33MGA7.js → logout-ZE5OUBB7.js} +2 -2
  72. package/dist-cli/chunks/{maestro-G36ATKHQ.js → maestro-FS6CAKDD.js} +2 -2
  73. package/dist-cli/chunks/{preview-BJUMMDBL.js → preview-TSU5IXVR.js} +2 -2
  74. package/dist-cli/chunks/{profile-CEQNS53P.js → profile-ZBJ4TYWA.js} +2 -2
  75. package/dist-cli/chunks/{react-BPEDK3TN.js → react-TGZLTTYN.js} +2 -2
  76. package/dist-cli/chunks/record-JSBFUNOD.js +54 -0
  77. package/dist-cli/chunks/runtime-DGDQ7NVY.js +2 -0
  78. package/dist-cli/chunks/{runtime-delivery-IYK2HNPG.js → runtime-delivery-36UMAXOV.js} +2 -2
  79. package/dist-cli/chunks/screenshot-3CHMALUJ.js +33 -0
  80. package/dist-cli/chunks/{screenshot-mode-VUBCO7T2.js → screenshot-mode-C547UT5H.js} +2 -2
  81. package/dist-cli/chunks/{screenshots-JENURQSV.js → screenshots-XCNGSNYG.js} +2 -2
  82. package/dist-cli/chunks/{server-PVAO3OA2.js → server-W37X3IW7.js} +6 -6
  83. package/dist-cli/chunks/setup-repo-DETS5ZJT.js +2 -0
  84. package/dist-cli/chunks/{skills-4JI327YS.js → skills-OXZLDNDW.js} +2 -2
  85. package/dist-cli/chunks/{start-7YB4I5V5.js → start-N6ZQYUBP.js} +4 -4
  86. package/dist-cli/chunks/store-QOXJKJUZ.js +2 -0
  87. package/dist-cli/chunks/telemetry-74LX7WG4.js +2 -0
  88. package/dist-cli/chunks/{test-5C6NYF62.js → test-DWZ7PRSW.js} +3 -3
  89. package/dist-cli/chunks/{three-mode-C6TE63VR.js → three-mode-P2R7KA62.js} +2 -2
  90. package/dist-cli/chunks/{timeline-NFYS6IPO.js → timeline-VPES3YCN.js} +3 -3
  91. package/dist-cli/chunks/{upgrade-KROEHYG2.js → upgrade-NYQLA4UJ.js} +2 -2
  92. package/dist-cli/chunks/upload-YOMMYESV.js +2 -0
  93. package/dist-cli/chunks/{web-UTOZ7MRF.js → web-OTALJKK5.js} +2 -2
  94. package/dist-cli/chunks/what-happened-GZ73H6KF.js +22 -0
  95. package/dist-cli/chunks/{whoami-O6XVOJBF.js → whoami-UDLQK7IY.js} +2 -2
  96. package/dist-lib/agent-daemon-client.cjs +1 -1
  97. package/dist-lib/agent-events.cjs +1 -1
  98. package/dist-lib/agent-sessions.cjs +1 -1
  99. package/dist-lib/attached-projects.cjs +1 -1
  100. package/dist-lib/auth/shared-session.cjs +1 -1
  101. package/dist-lib/backend-origin.cjs +1 -1
  102. package/dist-lib/bridge-constants.cjs +1 -1
  103. package/dist-lib/cli-constants.cjs +1 -1
  104. package/dist-lib/config.cjs +1 -1
  105. package/dist-lib/dev-bundle-resolution.cjs +9 -2
  106. package/dist-lib/home-paths.cjs +1 -1
  107. package/dist-lib/host/bridge-host.cjs +23 -7
  108. package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
  109. package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
  110. package/dist-lib/index.cjs +1 -1
  111. package/dist-lib/metro.cjs +1 -1
  112. package/dist-lib/profiles.cjs +1 -1
  113. package/dist-lib/render-mode.cjs +1 -1
  114. package/dist-lib/vite-base.cjs +23 -7
  115. package/dist-lib/vite.cjs +1 -1
  116. package/package.json +1 -1
  117. package/dist-cli/chunks/auto-bootstrap-SMQMN7WS.js +0 -2
  118. package/dist-cli/chunks/beta-DEQZ2J7G.js +0 -2
  119. package/dist-cli/chunks/chunk-3HC3F7CO.js +0 -3
  120. package/dist-cli/chunks/chunk-5MRRLWSD.js +0 -1
  121. package/dist-cli/chunks/chunk-B32KMMQV.js +0 -2
  122. package/dist-cli/chunks/chunk-CBRKFAOD.js +0 -1
  123. package/dist-cli/chunks/chunk-DLSOZVYM.js +0 -1
  124. package/dist-cli/chunks/chunk-E6CRWOWO.js +0 -2
  125. package/dist-cli/chunks/chunk-FPOQPEGK.js +0 -11
  126. package/dist-cli/chunks/chunk-GHTXP5R7.js +0 -348
  127. package/dist-cli/chunks/chunk-NTEZEQSB.js +0 -100
  128. package/dist-cli/chunks/chunk-R2QEABGZ.js +0 -119
  129. package/dist-cli/chunks/chunk-TRHZBTPF.js +0 -34
  130. package/dist-cli/chunks/chunk-UXFF7AEE.js +0 -73
  131. package/dist-cli/chunks/chunk-X2IIAIAP.js +0 -3
  132. package/dist-cli/chunks/chunk-ZW3HKMLQ.js +0 -17
  133. package/dist-cli/chunks/cli-version-HH7DAYBK.js +0 -2
  134. package/dist-cli/chunks/control-NCUWAXPH.js +0 -2
  135. package/dist-cli/chunks/demo-app-registry-JGIZ7NN7.js +0 -2
  136. package/dist-cli/chunks/drivers-CKGMOVM4.js +0 -2
  137. package/dist-cli/chunks/flow-3AHNNHF7.js +0 -2
  138. package/dist-cli/chunks/inspect-QCZVODE6.js +0 -1025
  139. package/dist-cli/chunks/install-747G2O4S.js +0 -2
  140. package/dist-cli/chunks/record-73CGQ3EP.js +0 -50
  141. package/dist-cli/chunks/runtime-QR5IHGKJ.js +0 -2
  142. package/dist-cli/chunks/screenshot-GUM2U2PN.js +0 -28
  143. package/dist-cli/chunks/setup-repo-ECVECJZQ.js +0 -2
  144. package/dist-cli/chunks/store-2MXXL4QE.js +0 -2
  145. package/dist-cli/chunks/telemetry-GIA7FIKW.js +0 -2
  146. package/dist-cli/chunks/upload-OS3J5ZOS.js +0 -2
  147. package/dist-cli/chunks/what-happened-FCP2U43H.js +0 -15
@@ -1,1025 +0,0 @@
1
- /*! sootsim v0.1.65 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
- import{a as G}from"./chunk-X2IIAIAP.js";import{a as Je,b as We}from"./chunk-S46M5JZP.js";import{a as X,b as C,c as B,d as z,e as ue,f as re,g as lt,h as ct,i as Te}from"./chunk-3HC3F7CO.js";import{a as je,h as ce}from"./chunk-MSBMGQJE.js";import{b as dt,c as ut,i as mt}from"./chunk-FPOQPEGK.js";import"./chunk-O56DABNK.js";import{a as Le}from"./chunk-TRHZBTPF.js";import{A as rt,C as se,D as it,J as at,a as de,b as qe,c as He,d as Ue,e as Ke,f as ze,g as Ye,h as ve,i as ke,n as Ge,o as Xe,p as Ve,q as Qe,r as Ze,s as et,t as tt,u as ot,v as st,w as nt}from"./chunk-5ZB5ZN5Z.js";import"./chunk-6GZS5TCL.js";import"./chunk-NTEZEQSB.js";import"./chunk-FU33BTPL.js";import"./chunk-CBRKFAOD.js";import"./chunk-ELZHT3LB.js";import"./chunk-UH4H5HXN.js";import{a as xe,c as $e,d as Pe}from"./chunk-R2QEABGZ.js";import{a as Oe}from"./chunk-B32KMMQV.js";import{c as Ee,e as De,f as Ce,g as Be,h as Se}from"./chunk-ZW3HKMLQ.js";import{b as Re}from"./chunk-VGQXIMEX.js";import"./chunk-E6CRWOWO.js";import"./chunk-TWKWXGN5.js";import"./chunk-KKOOZPQP.js";import{existsSync as Ut,mkdirSync as Kt,readFileSync as zt,rmSync as pt,writeFileSync as Yt}from"fs";import{tmpdir as Gt}from"os";import{dirname as Xt,join as Vt,resolve as Qt}from"path";var ie=1,Zt="SOOTSIM_INSPECT_NOTICE_PATH",eo=300*1e3,to=15e3;function ft(){return Qt(process.env[Zt]||Vt(Gt(),"sootsim-inspect-notice-state.json"))}function oo(s,d){return Object.fromEntries(Object.entries(s).filter(([,a])=>typeof a?.signature=="string"&&Number.isFinite(a?.updatedAt)&&d-a.updatedAt<=eo))}function so(s){let d=ft();if(!Ut(d))return{version:ie,entries:{}};try{let a=JSON.parse(zt(d,"utf8"));return a.version!==ie||!a.entries||typeof a.entries!="object"?(pt(d,{force:!0}),{version:ie,entries:{}}):{version:ie,entries:oo(a.entries,s)}}catch{return pt(d,{force:!0}),{version:ie,entries:{}}}}function no(s){let d=ft();Kt(Xt(d),{recursive:!0}),Yt(d,JSON.stringify(s,null,2)+`
3
- `)}function ro(s,d){let a=d.trim()||"default";return`${s}:${a}`}function Me(s,d,a,l={}){let g=l.nowMs??Date.now(),i=l.cooldownMs??to,h=so(g),S=ro(s,d),I=h.entries[S];return I&&I.signature===a&&g-I.updatedAt<i?!1:(h.entries[S]={signature:a,updatedAt:g},no(h),!0)}async function gt(s,d={args:[]}){let a=await qe(s);if(C(d.args)){B(a);return}console.log(` nodes: ${a.nodes}`)}function Ie(s,d){let a=s.indexOf(d);return a>=0&&a+1<s.length?s[a+1]:null}async function yt(s){let{bridge:d,args:a,positional:l}=s,g=a.includes("--verbose")||a.includes("-v"),i=C(a),h=g&&!i,S=a.includes("--watch")||a.includes("-w"),I=1e3,k=a.includes("--compact"),b=a.includes("--no-xy"),v=Ie(a,"--testid-like"),N=Ie(a,"--only"),T=Ie(a,"--subtree"),E=l[1],J=E?/[*?]/.test(E):!1,c=!J&&!N?E:void 0,K=N??(J?E:void 0),j=async()=>{await ue(d,{verbose:h});let Y=await Ke(d,{describe:!0,verbose:g,filter:c||"",testIdLike:v||void 0,onlyGlob:K||void 0,subtreeRoot:T||void 0,compact:k,hideXy:b}),W=Y?.tree,x=Y?.shell,F=Y?.keyboard;if(i){B({shell:x,tree:W??"",keyboard:F});return}if(x&&typeof x=="object"){let O=[x.state?`state=${x.state}`:null,x.activeApp?`app=${x.activeApp}`:null,x.showSwitcher?"switcher":null,x.switcherPhase&&x.switcherPhase!=="idle"?`phase=${x.switcherPhase}`:null].filter(Boolean);O.length>0&&console.log(` shell: ${O.join(" ")}`)}if(typeof W=="string"&&W.startsWith("__SUBTREE_NOT_FOUND__:")){let O=W.slice(22);console.log(` subtree root not found: ${O}`),G("subtree-root-not-found",O);return}if(!W){let O=Y?.nodeCount??0;console.log(" no matching nodes found"),!(c||v||K||T)&&O<10&&G("app-still-loading",O);return}if(console.log(W),!(c||v||K||T)&&!S&&W.split(`
4
- `).length>=80&&G("describe-use-filters"),F&&F.visible){let O=F.spec,V=[O?.keyboardType?`type=${O.keyboardType}`:null,O?.returnKeyType&&O.returnKeyType!=="default"?`return=${O.returnKeyType}`:null,F.mode!=="letters"?`mode=${F.mode}`:null,F.shifted?"shift":null,F.capsLock?"caps":null,O?.autoCapitalize&&O.autoCapitalize!=="sentences"?`autoCap=${O.autoCapitalize}`:null,F.accessoryBarId?`accessory=${F.accessoryBarId}`:null].filter(Boolean);console.log(`
5
- keyboard: ${V.join(" ")||"visible"}`)}};if(S)for(console.log(` watching... (Ctrl+C to stop)
6
- `);;)console.clear(),await j(),await X(I);else await j()}var io=["SOOTSIM_AGENT","CLAUDECODE","CLAUDE_CODE_ENTRYPOINT","CLAUDE_CODE_SESSION_ID","CODEX_THREAD_ID","CURSOR_TRACE_ID","AIDER_MODEL"];function ht(){if(process.env.SOOTSIM_AGENT==="0")return!1;for(let s of io){let d=process.env[s];if(d&&d.trim()&&d!=="0")return!0}return!1}async function bt(s){let{bridge:d,args:a,effectiveArgs:l,positional:g,inspectUsage:i}=s,h=x=>{let F=l.indexOf(x);return F>=0&&F+1<l.length?l[F+1]:null},S=x=>l.includes(x),I=h("--testid")||h("--test-id"),k=h("--role"),b=h("--type"),v=h("--text"),N=S("--pressable"),T=S("--visible"),E=S("--interactive-targets")||S("--actions"),J=!I&&!k&&!b&&!v&&!N&&!T&&!E?g[1]:null,c=v??J,K=await Ye(d,{testId:I,role:k,type:b,text:c,pressable:N,visible:T,interactive:E});K||(console.error(i("find","<text> | --text <t> | --testid <id> | --role <r> | --type <t> | --pressable | --visible | --interactive-targets")),process.exit(1));let{mode:j,result:D}=K,Y=C(a),W=a.includes("--verbose")||a.includes("--dump");if(Y)j==="interactive-targets"&&Array.isArray(D)?B(ve(D).map(x=>({...x,tap:ke(x)}))):B(D??null);else if(Array.isArray(D))if(D.length===0){console.log(` no ${j} nodes found`);let x=await d.send({type:"evaluate",code:"(async () => (await window.__sootsimTest?.getNodeCount?.()) || 0)()"});typeof x=="number"&&x<10&&G("app-still-loading",x)}else if(j==="interactive-targets"){let x=ve(D);console.log(` found ${x.length} interactive target${x.length===1?"":"s"} (sorted by score):`);for(let F of x.slice(0,20)){let Z=F.absolutePosition?`@(${Math.round(F.absolutePosition.x)},${Math.round(F.absolutePosition.y)})`:"",O=F.layout?`${Math.round(F.layout.width)}x${Math.round(F.layout.height)}`:"?x?",V=F.text?` "${F.text.slice(0,30)}"`:"",oe=F.testID?` #${F.testID}`:"",ee=F.accessibilityLabel?` \u24D8"${String(F.accessibilityLabel).slice(0,24)}"`:"",he=F.accessibilityRole?`[${F.accessibilityRole}]`:F.type,be=ke(F);console.log(` ${he}${V}${ee}${oe} ${O} ${Z}`),console.log(` \u2192 ${be}`),W&&console.log(Ne(JSON.stringify(F,null,2)," "))}x.length>20&&console.log(` ... and ${x.length-20} more`)}else{console.log(` found ${D.length} node${D.length===1?"":"s"} (${j}):`);for(let x of D.slice(0,20)){let F=x.absolutePosition?`@(${Math.round(x.absolutePosition.x)},${Math.round(x.absolutePosition.y)})`:"",Z=x.layout?`${Math.round(x.layout.width)}x${Math.round(x.layout.height)}`:"?x?",O=x.text?` "${x.text.slice(0,30)}"`:"",V=x.testID?` #${x.testID}`:"",oe=x.pressable?" (tap)":"",ee=x.accessibilityRole?`[${x.accessibilityRole}]`:x.type;console.log(` ${ee}${O}${V} ${Z} ${F}${oe}`),W&&console.log(Ne(JSON.stringify(x,null,2)," "))}D.length>20&&console.log(` ... and ${D.length-20} more`)}else if(D==null)console.log(` not found: ${c||I||k||b||""||j}`),I&&G("wait-selector-for-missing-testid",I);else{let x=D;if(x.type&&x.absolutePosition){let F=`@(${Math.round(x.absolutePosition.x)},${Math.round(x.absolutePosition.y)})`,Z=x.layout?`${Math.round(x.layout.width)}x${Math.round(x.layout.height)}`:"?x?",O=x.text?` "${x.text.slice(0,40)}"`:"",V=x.testID?` #${x.testID}`:"",oe=x.pressable?" (tap)":"",ee=x.accessibilityRole?`[${x.accessibilityRole}]`:x.type;console.log(` ${ee}${O}${V} ${Z} ${F}${oe}`),W&&console.log(Ne(JSON.stringify(x,null,2)," "))}else console.log(JSON.stringify(D,null,2))}}function Ne(s,d){return s.split(`
7
- `).map(a=>d+a).join(`
8
- `)}async function wt(s,d={}){let a=await rt(s);if("error"in a&&(console.error(a.error),process.exit(1)),d.json){console.log(JSON.stringify(a,null,2));return}let{visible:l,spec:g,mode:i,shifted:h,capsLock:S,accessoryBarId:I}=a,k=[];k.push(`keyboard: ${l?"visible":"hidden"}`),g?(k.push(` type: ${g.keyboardType}`),k.push(` returnKey: ${g.returnKeyType}`),k.push(` autoCap: ${g.autoCapitalize}`),k.push(` autoCorrect: ${g.autoCorrect?"on":"off"}`),k.push(` appearance: ${g.keyboardAppearance}`),g.secureTextEntry&&k.push(" secureTextEntry: true"),g.enablesReturnKeyAutomatically&&k.push(` return: ${g.currentTextIsEmpty?"disabled (empty)":"enabled"}`)):k.push(" spec: <none> (shown via dev-tools with no TextInput)"),k.push(` mode: ${i}${h?" (shifted)":""}${S?" (caps)":""}`),I&&k.push(` accessoryBar: ${I}`),console.log(k.join(`
9
- `))}async function xt(s){let d=await s.bridge.listSims();if(C(s.args)){B(d.map(a=>({...a,active:a.id===s.simId})));return}mt(d,s.simId)}function te(s){return s<1024?`${s}B`:s<1024*1024?`${(s/1024).toFixed(1)}KB`:`${(s/1024/1024).toFixed(1)}MB`}function me(s,d){return d<=0?"?":`${(s/d*100).toFixed(0)}%`}async function $t(s,d={args:[]}){let a=await at(s);if(C(d.args)){B(a);return}if(console.log(" memory:"),a.imageLoader){let l=a.imageLoader;console.log(" image-loader cache"),console.log(` entries: ${l.cacheEntries} / ${l.cacheMaxEntries} (${me(l.cacheEntries,l.cacheMaxEntries)})`),console.log(` pixel bytes: ${te(l.cachePixelBytes)} / ${te(l.cachePixelBudget)} (${me(l.cachePixelBytes,l.cachePixelBudget)})`),console.log(` pending: ${l.pendingFetches} fetches, ${l.pendingBytes} bytes`),console.log(` failed uris: ${l.failedUris}`),console.log(` snapshots: ${l.snapshots}`),console.log(` camera frames: ${l.cameraFrames}`)}else console.log(" image-loader cache: not available (engine pre-rebuild?)");if(a.workerHeap){let l=a.workerHeap;console.log(" worker heap (chrome only)"),console.log(` used: ${te(l.usedJSHeapSize)} / ${te(l.jsHeapSizeLimit)} (${me(l.usedJSHeapSize,l.jsHeapSizeLimit)})`),console.log(` total: ${te(l.totalJSHeapSize)}`)}if(a.hostHeap){let l=a.hostHeap;console.log(" host heap (chrome only)"),console.log(` used: ${te(l.usedJSHeapSize)} / ${te(l.jsHeapSizeLimit)} (${me(l.usedJSHeapSize,l.jsHeapSizeLimit)})`),console.log(` total: ${te(l.totalJSHeapSize)}`)}}function ae(s){let d=s.indexOf("--testid");if(d>=0&&s[d+1])return{mode:"testid",value:s[d+1]};let a=s.indexOf("--test-id");if(a>=0&&s[a+1])return{mode:"testid",value:s[a+1]};let l=s.indexOf("--text");return l>=0&&s[l+1]?{mode:"text",value:s[l+1]}:null}async function pe(s,d){let a=JSON.stringify(d.value),l=d.mode==="testid"?`(await t.findByTestId(${a})) || (await t.findById(${a}))`:`await t.findByText(${a})`;return await s.send({type:"evaluate",code:`(async () => {
10
- const t = window.__sootsimTest
11
- if (!t) return null
12
- const n = ${l}
13
- if (!n || !n.absolutePosition || !n.layout) return null
14
- const resolved =
15
- typeof n.nodeId === 'number' && typeof t.resolveTapTarget === 'function'
16
- ? await t.resolveTapTarget(n.nodeId)
17
- : null
18
- const cx =
19
- typeof resolved?.cx === 'number'
20
- ? resolved.cx
21
- : n.absolutePosition.x + (n.layout.width || 0) / 2
22
- const cy =
23
- typeof resolved?.cy === 'number'
24
- ? resolved.cy
25
- : n.absolutePosition.y + (n.layout.height || 0) / 2
26
- return {
27
- x: cx,
28
- y: cy,
29
- id: n.id ?? null,
30
- testID: n.testID ?? null,
31
- text: ${JSON.stringify(d.mode==="text")} ? ${a} : (n.text ?? n.accessibilityLabel ?? null),
32
- type: n.type ?? null,
33
- }
34
- })()`})??null}async function St(s,d={}){let{nav:a,keyboard:l,shell:g}=await it(s);if(d.json){console.log(JSON.stringify({shell:g??null,nav:a,keyboard:l},null,2));return}let i=[];if(g){let h=g.activeApp??g.state??"<none>",S=g.showSwitcher?" (app switcher open)":"",I=typeof g.launchProgress=="number"&&g.launchProgress<.98?` launching (${Math.round(g.launchProgress*100)}%)`:"";i.push(`shell: ${h}${S}${I}`)}else i.push("shell: <unavailable>");if(a){let h=a.transitionPhase!=="idle"?` (${a.transitionPhase}, ${a.activeTransitionCount} active)`:"";if(i.push(`nav: phase=${a.transitionPhase}${h}`),a.screens.length===0)i.push(" <no registered screens \u2014 app may not use react-native-screens>");else for(let S of a.screens){let I=S.isActive?"\u25B6":" ",k=S.routeName?` ${S.routeName}`:"",b=S.headerHeight>0?` header=${S.headerHeight}`:"",v=S.largeTitleState&&S.largeTitleState!=="expanded"?` large-title=${S.largeTitleState}`:"";i.push(` ${I} #${S.id}${k}${b}${v}`)}}else i.push("nav: <runtime not available>");if(l&&l.visible){let h=l.spec?.keyboardType??"default",S=l.spec?.returnKeyType??"default";i.push(`keyboard: visible (${h}, return=${S}, mode=${l.mode??"?"})`)}else i.push("keyboard: hidden");console.log(i.join(`
35
- `))}async function ne({bridge:s,maxMs:d,pollMs:a=50,stablePolls:l=3,strict:g=!1}){let i=await s.send({type:"evaluate",code:`(async () => {
36
- const start = Date.now()
37
- const deadline = start + ${Math.max(0,Math.round(d))}
38
- const pollMs = ${Math.max(1,Math.round(a))}
39
- const requiredStablePolls = ${Math.max(1,Math.round(l))}
40
- const strict = ${g?"true":"false"}
41
- const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
42
-
43
- // route-aware settle: a tap that pushes/pops a screen is async \u2014 the
44
- // old screen still renders for a moment, then the new one mounts and
45
- // its content loads. a pure layout-hash check reports "idle" on the
46
- // outgoing screen or on the incoming skeleton, so a driver re-taps
47
- // and stacks duplicate navigations. drain any in-flight screen
48
- // transition FIRST, bounded by the overall budget. when no
49
- // transition is happening this returns in ~80ms (startWindowMs), so
50
- // a plain button tap barely pays for it.
51
- try {
52
- const wfst = window.__sootsimTest?.waitForScreenTransitions
53
- if (typeof wfst === 'function') {
54
- const remaining = deadline - Date.now()
55
- if (remaining > 120) {
56
- await wfst({
57
- timeoutMs: Math.min(remaining - 80, 4000),
58
- settleMs: 64,
59
- startWindowMs: 80,
60
- })
61
- }
62
- }
63
- } catch {}
64
-
65
- const readSnapshot = async () => {
66
- let animating = false
67
- let pendingFetches = 0
68
- try {
69
- const stats = await window.__sootsimRenderHost?.queryStats?.()
70
- if (stats) {
71
- animating =
72
- stats.hasActiveAnims === true ||
73
- stats.hasActiveNativeAnimations === true ||
74
- stats.hasPendingAnimationFrames === true
75
- // a freshly-pushed screen showing a skeleton is layout-stable
76
- // but not actually settled \u2014 its data/images are still in
77
- // flight. treat bounded image-loader fetches as not-idle so
78
- // settle waits for real content, capped by the budget.
79
- const pf = stats.memory && stats.memory.imageLoader
80
- ? stats.memory.imageLoader.pendingFetches
81
- : 0
82
- pendingFetches = typeof pf === 'number' ? pf : 0
83
- }
84
- } catch {}
85
- const root = window.__sootsimRoot
86
- const nodes = []
87
- if (root) {
88
- const walk = (n) => {
89
- if (n.layout && n.layout.width > 0) {
90
- nodes.push(Math.round(n.layout.x) + ',' + Math.round(n.layout.y) + ',' + Math.round(n.layout.width))
91
- }
92
- for (const c of n.children || []) walk(c)
93
- }
94
- walk(root)
95
- }
96
- return { layout: nodes.join(';'), animating, pendingFetches }
97
- }
98
-
99
- let lastLayout = ''
100
- let stable = 0
101
- while (Date.now() < deadline) {
102
- const snapshot = await readSnapshot()
103
- const strictOk = !strict || !snapshot.animating
104
- const contentReady = snapshot.pendingFetches === 0
105
- if (strictOk && contentReady && snapshot.layout === lastLayout) {
106
- stable++
107
- if (stable >= requiredStablePolls) {
108
- return { settled: true, elapsed: Date.now() - start }
109
- }
110
- } else {
111
- stable = 0
112
- }
113
- lastLayout = snapshot.layout
114
- await sleep(pollMs)
115
- }
116
- return { settled: false, elapsed: Date.now() - start }
117
- })()`}),{elapsed:h,settled:S}=i??{};return{elapsed:typeof h=="number"?h:d,settled:S===!0}}async function vt(s){let{bridge:d,args:a,positional:l}=s,g=l[1]?Number(l[1])*1e3:3e3,i=a.includes("--strict"),{elapsed:h,settled:S}=await ne({bridge:d,maxMs:g,strict:i});console.log(S?` settled in ${h}ms`:` timed out after ${h}ms (may still be animating)`)}async function kt(s){let d=s.positional[1]?Number(s.positional[1]):.5;(!Number.isFinite(d)||d<0)&&(console.error(s.inspectUsage("sleep","[seconds]")),process.exit(1)),await X(d*1e3),console.log(` slept ${d}s`)}async function Tt(s){let{bridge:d,args:a,positional:l}=s,g=l[1]?Number(l[1]):5,{tree:i}=await He(d,g);if(C(a)){B({depth:g,tree:i??null});return}console.log(typeof i=="string"?i:JSON.stringify(i,null,2))}async function Mt(s,d={args:[]}){let a=await Ue(s);if(C(d.args)){B(a);return}console.log(a.url)}async function It(s){let{wsPort:d,commandTimeoutMs:a,simId:l,simIdSource:g,positional:i}=s,h=i[1]?Number(i[1]):30,S=Math.max(1e3,(Number.isFinite(h)?h:30)*1e3),I=Math.max(1,Math.ceil(S/500));console.log(" waiting for sim reconnect...");let k=await lt(d,a,l,{attempts:I,simIdSource:g});k||(console.error(" timed out waiting for sim reconnect"),process.exit(1)),k.bridge.close(),ce({source:"inspect wait",step:{wait:S},summary:`wait ${Math.round(S/1e3)}s`}),console.log(` ready: ${k.count} nodes`)}var Nt=new Set(["app-launch","toast","keyboard","screen","route","alert","actionsheet","picker","notification","fetch","console","shell","scroll","gesture","text-input","react-commit","animation","reanimated"]);function fe(s,d){let a=s.indexOf(d);if(a>=0&&a+1<s.length)return s[a+1]}function ao(s,d){if(!d.filter&&!d.equals)return!0;let a=s.data,l=[];if(a&&typeof a=="object")for(let i of["url","displayUrl","message","name","activeName","path","pathname","title","phase","event","type","kind"]){let h=a[i];typeof h=="string"&&h.length>0&&l.push(h)}let g=l.join(" ");return d.equals?l.some(i=>i===d.equals):d.filter?g.toLowerCase().includes(d.filter.toLowerCase()):!0}async function Ft(s){let{bridge:d,args:a,positional:l,inspectUsage:g}=s,i=l[1];i||(console.error(g("wait event","<kind> [--max-ms 5000] [--filter <substring>] [--equals <exact>] [--since now|cursor]")),process.exit(1)),Nt.has(i)||console.error(` warning: '${i}' is not a known timeline kind \u2014 waiting anyway. known: ${[...Nt].sort().join(", ")}`);let h=fe(a,"--max-ms"),S=h&&Number.isFinite(Number(h))?Math.max(100,Number(h)):5e3,I=fe(a,"--filter"),k=fe(a,"--equals"),b=fe(a,"--since")??"now",v=a.includes("--json"),N=Date.now(),T=N+S,E=200,J=N;for(;Date.now()<T;){let K={kinds:[i],since:b==="cursor"?void 0:J,limit:50},j=await d.send({type:"evaluate",code:`(async () => {
118
- const t = window.SootSim?.bridges?.timeline
119
- if (!t) return { ok: false, error: 'timeline bridge missing' }
120
- return { ok: true, result: await t.recent(${JSON.stringify(K)}) }
121
- })()`});(!j||!j.ok)&&(console.error(` could not query timeline: ${j&&"error"in j?j.error:"unknown"}`),process.exit(1));let D=j.result.events??[];for(let Y of D)if(ao(Y,{filter:I,equals:k})){let W=Date.now()-N;console.log(v?JSON.stringify({found:!0,elapsedMs:W,event:Y}):` ${i} event after ${W}ms${I?` (filter: ${I})`:""}${k?` (equals: ${k})`:""}`);return}j.result.watermark&&j.result.watermark>J&&(J=j.result.watermark),await new Promise(Y=>setTimeout(Y,E))}let c=Date.now()-N;v?console.log(JSON.stringify({found:!1,elapsedMs:c,kind:i,filter:I,equals:k})):console.error(` \u26A0 wait event ${i} timed out after ${c}ms${I?` (filter: ${I})`:""}${k?` (equals: ${k})`:""}`),process.exit(1)}async function _t(s){let{bridge:d,args:a}=s,l=a.includes("--strict"),g=de(a,3e3),{elapsed:i,settled:h}=await ne({bridge:d,maxMs:g,strict:l});h?console.log(` idle in ${i}ms`):(console.error(` \u26A0 wait idle timed out after ${i}ms (may still be animating)`),process.exit(1))}async function At(s){let{bridge:d,args:a}=s,l=de(a,2e4),{ready:g,elapsedMs:i,nodes:h,targets:S,flag:I,loadingText:k,externalReady:b,externalError:v,errors:N}=await Ge(d,l);if(g){console.log(` ready in ${i}ms: ${h} nodes, ${S} targets`);return}let T=v?`guest app errored: ${v}`:k?`still showing "${k}"`:b===!1?"guest app is still loading":I!==!0?"guest app has not emitted sootsim:externalAppReady":S<=0?"ready flag emitted but no visible app content is inspectable yet":"node tree is still changing";console.error(` \u26A0 wait ready timed out after ${i}ms \u2014 ${T} (nodes: ${h}, targets: ${S}, errors: ${N})`),process.exit(1)}async function Ot(s){let{bridge:d,args:a,positional:l,inspectUsage:g}=s,i=l[1];i||(console.error(g("wait selector","<testid> [--max-ms 5000]")),process.exit(1));let h=a.indexOf("--max-ms"),S=h>=0&&a[h+1]?Math.max(100,Number(a[h+1])):5e3,{found:I,node:k,elapsed:b}=await Xe(d,i,S);if(I&&k){let v=k.absolutePosition?`@(${Math.round(k.absolutePosition.x)},${Math.round(k.absolutePosition.y)})`:"",N=k.layout?`${Math.round(k.layout.width)}x${Math.round(k.layout.height)}`:"?x?";console.log(` found #${i} in ${b}ms ${N} ${v}`)}else console.error(` \u26A0 wait selector #${i} timed out after ${b??S}ms`),process.exit(1)}function Bt(s){return s==null?"\u2014":s<1024?`${s}B`:s<1024*1024?`${(s/1024).toFixed(1)}K`:`${(s/1024/1024).toFixed(1)}M`}function jt(s){return s==null?" \u2026":s<1e3?`${s}ms`.padStart(5):`${(s/1e3).toFixed(2)}s`.padStart(5)}function co(s){return s.error?"err":s.status==null?" \u2026 ":String(s.status)}function Pt(s){let d=new Date(s.startTs).toLocaleTimeString(),a=co(s).padEnd(3),l=s.method.padEnd(5),g=Bt(s.size).padStart(6),i=jt(s.durationMs);console.log(` [${d}] ${a} ${l} ${g} ${i} ${s.displayUrl}`),s.error&&console.log(` error: ${s.error}`)}function uo(s){let d=[["id",s.id],["source",s.source],["kind",s.kind],["method",s.method],["status",s.error?`error: ${s.error}`:`${s.status??"\u2014"} ${s.statusText??""}`.trim()],["url",s.url],["started",new Date(s.startTs).toLocaleTimeString()],["duration",jt(s.durationMs).trim()],["size",Bt(s.size)],["content-type",s.type??"\u2014"]];for(let[a,l]of d)console.log(` ${a.padEnd(13)} ${l}`)}var mo={error:"\x1B[31m",warn:"\x1B[33m",info:"\x1B[36m",debug:"\x1B[35m",log:"\x1B[37m"},Rt="\x1B[0m",po="\x1B[2m";function Et(s,d){let a=new Date(s.ts).toLocaleTimeString(),l=s.level.toUpperCase().padEnd(5),g=s.args.join(" ");if(d){let i=mo[s.level];console.log(` ${po}[${a}]${Rt} ${i}${l}${Rt} ${g}`)}else console.log(` [${a}] ${l} ${g}`);if(s.stack&&s.level==="error"){let i=s.stack.split(`
122
- `).slice(0,5);for(let h of i)console.log(` ${h.trim()}`)}}var Q="__sootsimCliPerf",fo=120;async function Dt(s,d){let a=s.find((N,T)=>s[T-1]==="--id"),l=s.find((N,T)=>s[T-1]==="--text");if(a||l){let N=await d.send({type:"evaluate",code:Je({id:a,text:l})});if(!N)throw new Error(a?`no node with id "${a}"`:`no node matching text "${l}"`);let{x:T,y:E,w:J,h:c}=N;return{x:T,y:E,w:J,h:c}}let g=s.find((N,T)=>s[T-1]==="--area");if(g){let N=g.split(",").map(K=>Number(K.trim()));if(N.length!==4||N.some(K=>!Number.isFinite(K)))throw new Error(`--area expects x,y,w,h (got "${g}")`);let[T,E,J,c]=N;return{x:T,y:E,w:J,h:c}}let i=N=>{let T=s.find((J,c)=>s[c-1]===N);if(T==null)return null;let E=Number(T);return Number.isFinite(E)?E:null},h=i("--x"),S=i("--y"),I=i("--w"),k=i("--h");if(h!=null||S!=null||I!=null||k!=null)return{x:h??0,y:S??0,w:I??1,h:k??1};let v=s.filter((N,T)=>T>0&&!N.startsWith("-")&&s[T-1]!=="--output"&&s[T-1]!=="--area"&&s[T-1]!=="--id"&&s[T-1]!=="--text"&&s[T-1]!=="--x"&&s[T-1]!=="--y"&&s[T-1]!=="--w"&&s[T-1]!=="--h").map(Number).filter(N=>Number.isFinite(N));if(v.length>=2){let[N,T,E=1,J=1]=v;return{x:N,y:T,w:E,h:J}}return null}function Fe(s){let d={"<8":0,"8-12":0,"12-16":0,"16-20":0,"20-33":0,">33":0};for(let a of s)a<8?d["<8"]++:a<12?d["8-12"]++:a<16?d["12-16"]++:a<20?d["16-20"]++:a<33?d["20-33"]++:d[">33"]++;console.log(" histogram:");for(let[a,l]of Object.entries(d)){let g="\u2588".repeat(Math.ceil(l/s.length*40));console.log(` ${a.padEnd(6)} ${g} ${l}`)}}async function ge(s,d,a){let l=Date.now()+d,g=await se(s,d);for(;;){if(a(g))return{settled:!0,state:g};if(Date.now()>=l)return{settled:!1,state:g};await X(16),g=await se(s)}}async function Ae(s){return s.send({type:"evaluate",code:`(async () => {
123
- const kb = window.__sootsimKeyboard
124
- const test = window.__sootsimTest
125
- if (!kb) return { error: 'keyboard bridge not available' }
126
- const visible = kb.isVisible()
127
- const mode = kb.getMode()
128
- let focused = null
129
- if (test && typeof test.getFocusedNode === 'function') {
130
- try {
131
- focused = await test.getFocusedNode()
132
- } catch {}
133
- }
134
- let runtimeSnapshot = null
135
- if (test && typeof test.getFocusKeyboardSnapshot === 'function') {
136
- try {
137
- runtimeSnapshot = await test.getFocusKeyboardSnapshot()
138
- } catch {}
139
- }
140
- return {
141
- visible,
142
- mode,
143
- focusedInput: focused ? {
144
- nodeId: focused.nodeId ?? null,
145
- testID: focused.testID || null,
146
- id: focused.id || null,
147
- placeholder: focused.placeholder || null,
148
- text: focused.text || null,
149
- } : null,
150
- phase: runtimeSnapshot?.keyboard?.phase ?? null,
151
- frame: runtimeSnapshot?.keyboard?.frame ?? null,
152
- focusedRect: runtimeSnapshot?.focused?.rect ?? null,
153
- }
154
- })()`})}async function go(s,d=600){let a=Date.now()+d;for(;Date.now()<=a;){let l=await Ae(s);if(l.visible)return l;await X(30)}return Ae(s)}async function ye(s,d){let a=await Ae(s);if(a.visible)return a;console.error(` ${d} requires the iOS keyboard to be visible. focus an input first with sootsim do tap-id/tap-text or sootsim do type-into.`),process.exit(1)}async function Ct(s,d,a){return d==="appearance"?s.send({type:"evaluate",code:`(async () => {
155
- const requested = ${JSON.stringify(a??"toggle")}
156
- const rootBg = (document.documentElement?.style?.background || '').toLowerCase()
157
- const inferredCurrent = rootBg.includes('33') ? 'dark' : 'light'
158
- let next = requested
159
- if (requested === 'toggle') {
160
- next = inferredCurrent === 'dark' ? 'light' : 'dark'
161
- }
162
- // engine accepts 'auto' since the schema picker landed; pass through.
163
- window.postMessage({ type: 'soot-action', action: 'set-appearance', value: next }, '*')
164
- const applied = next === 'auto'
165
- ? (window.matchMedia?.('(prefers-color-scheme: dark)')?.matches ? 'dark' : 'light')
166
- : next
167
- return { ok: true, requested, value: next, applied }
168
- })()`}):s.send({type:"evaluate",code:`(async () => {
169
- window.dispatchEvent(new CustomEvent(${JSON.stringify(d==="lock"?"sootsim:toggleLock":"sootsim:shake")}))
170
- return { ok: true, action: ${JSON.stringify(d)} }
171
- })()`})}function yo(s){let d={Enter:"return",NumpadEnter:"return",Backspace:"delete",Delete:"delete",Space:"space",ShiftLeft:"shift",ShiftRight:"shift"};if(d[s])return d[s];let a=s.match(/^Digit([0-9])$/);if(a)return a[1];let l=s.match(/^Key([A-Z])$/);return l?l[1].toLowerCase():null}function ho(s){if(typeof s!="string")return null;let d=s.replace(/\s+/g," ").trim();return d?d.slice(0,80):null}function Lt(...s){for(let d of s){if(typeof d!="string")continue;let a=d.trim();if(a)return a}return null}function bo(s){let d=s.indexOf("--node-id");if(d<0)return null;let a=s[d+1];if(!a)return null;let l=Number(a);return Number.isInteger(l)&&l>0?l:null}async function L(s,d,a){let l=ce({source:s,step:d,summary:a});l.active&&(l.replaced?console.error(` draft: replaced unkept action "${l.replaced.summary}" \u2014 \`flow keep\` commits one action at a time`):console.error(" draft: action pending \u2014 `sootsim flow keep` to commit"))}function wo(s,d,a){if(!a||a.hit===!1)return null;let l=Lt(a.responderTestID,a.testID);if(l)return{step:{tapOn:{id:l}},summary:`tap #${l}`};let g=ho(a.text);return g?{step:{tapOn:g},summary:`tap "${g}"`}:{step:{tapAtCoords:{x:s,y:d}},summary:`tap @${Math.round(s)},${Math.round(d)}`}}function _e(s,d,a){let l=Lt(d?.testID,d?.id);return l?{step:{tapOn:{id:l}},summary:`tap #${l}`}:a==="id"?{step:{tapOn:{id:s}},summary:`tap #${s}`}:{step:{tapOn:s},summary:`tap "${s}"`}}async function en(s,d){let a=s[0]==="get"||s[0]==="do"||s[0]==="debug"||s[0]==="wait"?s[0]:null,l=a?s.slice(1):s,g=Ee(l,{port:d.port,commandTimeoutMs:d.timeoutMs,stripBooleanFlags:["--verbose","-v","--help","-h","--clear-state","--json","--all","--watch","-w","--strict","--no-wait","--dump","--failed","--slow","--tail","-f","--interactive-targets","--actions","--internal"],stripValueFlags:["--output","--nth","--index","--testid","--test-id","--text","--node-id","--max-ms","--filter","--limit","--level","--threshold","--equals","--since"]}),i=g.positional,h=i[0],S=a==="get"||a==="do"||a==="debug"||a==="wait"?a:"inspect",I=typeof l[0]=="string"&&Pe.has(l[0]),k=I?l[0]:null,b=t=>I&&t===l[0]?`sootsim ${t}`:`sootsim ${S} ${t}`,v=(t,e)=>` usage: ${b(t)}${e?` ${e}`:""}`;if(!h||s.includes("--help")||s.includes("-h")){let t={bridgePort:7668,defaultShellUrl:Oe};if(S==="do"||S==="get"||S==="debug"||S==="wait"){let n=xe(S,t);n&&(console.log(`${n}
172
- `),process.exit(0))}if(k==="shell"){let n=$e("shell",t);n&&(console.log(`${n}
173
- `),process.exit(0))}let e=$e("inspect",t),o=["do","get","debug","wait"].map(n=>xe(n,t)).filter(n=>n!=null).join(`
174
-
175
- `);console.log(`${e??""}
176
-
177
- ${o}
178
- `),process.exit(0)}let N=g.wsPort,T=g.simId,E=g.simIdSource,J=g.commandTimeoutMs;if(h==="list"&&l.some(t=>t==="--drivers"||t==="-D")){let{buildDriverListRows:t}=await import("./drivers-CKGMOVM4.js"),e=t();console.log(` available drivers (${e.length}):
179
- `);let o=Math.max(...e.map(r=>r.id.length),6),n=Math.max(...e.map(r=>r.kind.length),4);for(let r of e){let u=r.available?"\u2713":"\u2717",m=r.id.padEnd(o),w=r.kind.padEnd(n);console.log(` ${u} ${m} ${w} ${r.description}`),r.available&&r.detail?console.log(` ${r.detail}`):!r.available&&r.reason&&console.log(` unavailable: ${r.reason}`)}return}let c=De(g),K=T||"default",j=new Set(["errors","warnings","requests","js","eval","reload","globals","perf","list","wait","sleep"]),D=200;function Y(t){let e=t.replace(/\s+/g," ").trim();if(!e)return"";if(/^<(!doctype html|html|\?xml)|<body[\s>]/i.test(e)){let n=/<title[^>]*>([^<]+)<\/title>/i.exec(t)?.[1]?.trim(),r=/<body[^>]*>([\s\S]*?)<\//i.exec(t)?.[1]?.replace(/<[^>]+>/g," ").replace(/\s+/g," ").trim().slice(0,80),u=n||r||"html error page";return`<html ${t.length}B> "${u}" (body elided \u2014 add --json for the full payload)`}return e.length<=D?e:`${e.slice(0,D)}\u2026 (+${e.length-D} more bytes)`}function W(t){let e=t.displayUrl||t.url;return t.status!=null?`${t.method} ${e} -> ${t.status}${t.statusText?` ${t.statusText}`:""}`:t.error?`${t.method} ${e} -> ${t.error}`:`${t.method} ${e}`}async function x(t){let e=ht()?5e3:1500;try{let{settled:o,elapsed:n}=await ne({bridge:t,maxMs:e,pollMs:32,stablePolls:2});o||process.stderr.write(` \u26A0 auto-wait timed out after ${n??e}ms \u2014 next command may see mid-animation state. use \`sootsim do settle\` for a longer wait.
180
- `)}catch{}}async function F(){try{return await c.send({type:"evaluate",code:`(() => ({
181
- console: window.__sootsimConsole?.count?.() || null,
182
- requests: window.__sootsimTest?.getRequestCounts?.() || null,
183
- }))()`})||{console:null,requests:null}}catch{return{console:null,requests:null}}}async function Z(t={}){let e=t.counts!==void 0?t.counts:await z(c,"getRequestCounts");if(!e||typeof e!="object")return;let o=Math.max(0,Number(e.failed)||0);if(o===0||!t.includeTail&&!Me("requests",K,String(o))||(console.log(`
184
- network: ${o} failed request${o===1?"":"s"}`),console.log(` inspect: ${b("requests")} 5`),!t.includeTail))return;let n=await z(c,"getFailedRequests",5);if(!(!Array.isArray(n)||n.length===0)){console.log(`
185
- recent failed requests:
186
- `);for(let r of n){let u=new Date(r.timestamp).toLocaleTimeString();console.log(` [${u}] ${W(r)}`),r.responseBody?console.log(` ${Y(r.responseBody)}`):r.error&&console.log(` ${r.error}`)}}}async function O(t={}){let e=t.counts!==void 0?t.counts:await c.send({type:"evaluate",code:"window.__sootsimConsole?.count?.() || { errors: 0, warnings: 0, total: 0 }"});if(!e||typeof e!="object")return;let o=e,n=Math.max(0,Number(o.errors)||0),r=Math.max(0,Number(o.warnings)||0);if(n===0&&r===0||!t.includeTail&&!Me("console",K,`${n}:${r}`))return;let u=[];if(n>0&&u.push(`${n} console error${n===1?"":"s"}`),r>0&&u.push(`${r} console warning${r===1?"":"s"}`),console.log(`
187
- console: ${u.join(", ")}`),console.log(` inspect: ${b("errors")} 5`),r>0&&console.log(` inspect: ${b("warnings")} 5`),!t.includeTail||n===0)return;let m=await c.send({type:"evaluate",code:"window.__sootsimConsole?.getErrors?.(5) || []"});if(!(!Array.isArray(m)||m.length===0)){console.log(`
188
- recent console errors:
189
- `);for(let w of m){let f=new Date(w.timestamp).toLocaleTimeString(),$=Array.isArray(w.args)?w.args.map(_=>typeof _=="object"?JSON.stringify(_):String(_)).join(" "):String(w);console.log(` [${f}] ${$}`)}}}let V=["console","fetch","toast","alert","notification","screen","app-launch","keyboard","route","actionsheet","picker","shell","scroll","gesture","text-input","animation","reanimated"];async function oe(t){let e=Re(),o=null;try{o=await Be(t,`(() => {
190
- const tl = window.SootSim && window.SootSim.bridges && window.SootSim.bridges.timeline
191
- if (!tl || typeof tl.summary !== 'function') return null
192
- const cursorKey = ${JSON.stringify(e)}
193
- const summary = tl.summary({ sinceCursor: cursorKey })
194
- let consoleSplit = null
195
- if (summary && summary.byKind && summary.byKind.console) {
196
- const events = tl.recent({ sinceCursor: cursorKey, kinds: 'console', limit: 100000 }).events
197
- consoleSplit = { error: 0, warn: 0 }
198
- for (const ev of events) {
199
- const lvl = ev && ev.data && ev.data.level
200
- if (lvl === 'error') consoleSplit.error++
201
- else if (lvl === 'warn') consoleSplit.warn++
202
- }
203
- }
204
- return summary ? { summary, consoleSplit } : null
205
- })()`)}catch{return}if(!o||!o.summary||!o.summary.total)return;let n=o.summary.byKind??{},r=[],u=new Set;for(let m of V){let w=n[m];if(w)if(u.add(m),m==="console"&&o.consoleSplit){let{error:f,warn:$}=o.consoleSplit;f>0&&r.push(`${f} error${f===1?"":"s"}`),$>0&&r.push(`${$} warning${$===1?"":"s"}`)}else r.push(`${w} ${m}${w===1?"":"s"}`)}for(let[m,w]of Object.entries(n))!u.has(m)&&w&&r.push(`${w} ${m}${w===1?"":"s"}`);if(r.length!==0&&(console.log(`
206
- since last: ${r.join(" \xB7 ")} \u2014 sootsim what-happened`),o.summary.lastAt))try{await Se(t,"SootSim.bridges.timeline.cursorAdvance",e,o.summary.lastAt)}catch{}}let ee=new Set(["tap","double-tap","tap-text","tap-id","type","type-into","key","key-sequence","keycode","drag","swipe","long-press","touch","gesture","pinch","scroll","shell"]),he=new Set(["a11y","capture","count","double-tap","drag","find","gesture","layout","long-press","node","pinch","sample-color","scroll","screenshot","swipe","tap","tap-id","tap-text","touch","tree","type-into"]),be=(s.includes("--verbose")||s.includes("-v"))&&!s.includes("--json");S==="do"&&h==="shell"&&(console.error(" `sootsim do shell` was removed. use `sootsim shell ...` instead."),process.exit(1)),ee.has(h)&&await Ce(c),he.has(h)&&await ue(c,{verbose:be});try{switch(h){case"list":{await xt({bridge:c,simId:T,args:l});break}case"tree":{await Tt({bridge:c,args:l,positional:i});break}case"a11y":{let t=await ze(c);if(!Array.isArray(t)||t.length===0){console.log(" no accessible nodes found");break}if(s.includes("--json"))console.log(JSON.stringify(t,null,2));else{console.log(` accessibility tree (${t.length} nodes):
207
- `);for(let e of t){let o=[];if(o.push(`[${e.role}]`),e.label){let n=e.label.length>50?e.label.slice(0,47)+"...":e.label;o.push(`"${n}"`)}if(e.hint&&o.push(`(hint: "${e.hint}")`),e.testID&&o.push(`#${e.testID}`),e.state){let n=[];e.state.disabled&&n.push("disabled"),e.state.selected&&n.push("selected"),e.state.checked===!0&&n.push("checked"),e.state.checked==="mixed"&&n.push("mixed"),e.state.busy&&n.push("busy"),e.state.expanded===!0&&n.push("expanded"),e.state.expanded===!1&&n.push("collapsed"),n.length&&o.push(`{${n.join(", ")}}`)}e.position&&o.push(`@(${e.position.x},${e.position.y})`),e.size&&o.push(`${e.size.w}x${e.size.h}`),console.log(" "+o.join(" "))}}break}case"find":{await bt({bridge:c,args:s,effectiveArgs:l,positional:i,inspectUsage:v});break}case"count":{await gt(c,{args:l});break}case"keyboard":{await wt(c,{json:s.includes("--json")});break}case"screens":{await St(c,{json:s.includes("--json")});break}case"memory":{await $t(c,{args:l});break}case"wait":{await It({wsPort:N,commandTimeoutMs:J,simId:T,simIdSource:E,positional:i});break}case"sleep":{await kt({positional:i,inspectUsage:v});break}case"settle":{await vt({bridge:c,args:s,positional:i});break}case"ready":{await At({bridge:c,args:s});break}case"idle":{await _t({bridge:c,args:s,positional:i});break}case"selector":{await Ot({bridge:c,args:s,positional:i,inspectUsage:v});break}case"event":{await Ft({bridge:c,args:s,positional:i,inspectUsage:v});break}case"layout":{let t=i[1];t||(console.error(v("layout","<id>")),process.exit(1));let e=await c.send({type:"evaluate",code:`(async () => await window.__sootsimTest.getLayout(${JSON.stringify(t)}))()`});console.log(JSON.stringify(e,null,2));break}case"capture":case"screenshot":{let e=s.find((w,f)=>s[f-1]==="--output")||"/tmp/sootsim-inspect.png",o=await Dt(s,c),n={type:"screenshot"};o&&(n.crop=o);let u=(await c.send(n)).replace(/^data:image\/png;base64,/,"");o&&console.log(` area: x=${o.x} y=${o.y} w=${o.w} h=${o.h}`),(await import("fs")).writeFileSync(e,Buffer.from(u,"base64")),console.log(` saved: ${e}`);break}case"sample-color":{let t=await Dt(s,c);t||(console.error(v("sample-color","<x> <y> [w] [h] | --id <testID> | --text <text>")),console.error(" samples an averaged color from the canvas. coords are logical sootsim units."),process.exit(1));let e=await c.send({type:"evaluate",code:We(t)});if(s.includes("--json"))console.log(JSON.stringify(e,null,2));else{let{r:o,g:n,b:r,a:u,hex:m,samples:w}=e,f=t.w===1&&t.h===1?`@(${t.x},${t.y})`:`@(${t.x},${t.y}) ${t.w}x${t.h}`;console.log(` ${m} rgba(${o}, ${n}, ${r}, ${u}) ${f} ${w} samples`)}break}case"node":{let t=i[1];t||(console.error(v("node","<matcher>")),console.error(" resolves testID, id, then text \u2014 dumps full node info as JSON"),process.exit(1));let e=await c.send({type:"evaluate",code:`(async () => {
208
- const t = window.__sootsimTest
209
- const q = ${JSON.stringify(t)}
210
- let node = null
211
- let via = null
212
- if (t.findByTestId) { node = await t.findByTestId(q); if (node) via = 'testID' }
213
- if (!node && t.findById) { node = await t.findById(q); if (node) via = 'id' }
214
- if (!node && t.findByText) { node = await t.findByText(q); if (node) via = 'text' }
215
- if (!node) return { matcher: q, found: false }
216
-
217
- // read the resolved transform (if any) off the style \u2014 useful
218
- // because canvas nodes often animate via transform and describe
219
- // output strips that.
220
- const transform =
221
- node.style && Array.isArray(node.style.transform)
222
- ? node.style.transform
223
- : node.style && node.style.transform
224
- ? node.style.transform
225
- : null
226
-
227
- // parent chain \u2014 walk up from the node so the JSON dump is
228
- // self-describing.
229
- const parentChain = []
230
- const root = window.__sootsimRoot
231
- if (root && node.id != null) {
232
- const findPath = (n, targetId, path) => {
233
- if (!n) return null
234
- if (n.id === targetId) return path
235
- if (n.children) {
236
- for (const child of n.children) {
237
- const nextPath = [
238
- ...path,
239
- {
240
- type: n.type || 'view',
241
- testID: n.props?.testID || null,
242
- text: n.text || null,
243
- },
244
- ]
245
- const found = findPath(child, targetId, nextPath)
246
- if (found) return found
247
- }
248
- }
249
- return null
250
- }
251
- const chain = findPath(root, node.id, [])
252
- if (chain) parentChain.push(...chain)
253
- }
254
-
255
- return {
256
- matcher: q,
257
- found: true,
258
- resolvedVia: via,
259
- node,
260
- transform,
261
- parentChain,
262
- }
263
- })()`});console.log(JSON.stringify(e,null,2));break}case"tap":{let t=Number(i[1]),e=Number(i[2]),o=ae(s),n=null;if(o){let m=await pe(c,o);m||(console.error(` not found: ${o.value}`),o.mode==="testid"&&G("wait-selector-for-missing-testid",o.value),process.exit(1)),t=m.x,e=m.y,n=m}(!Number.isFinite(t)||!Number.isFinite(e))&&(console.error(v("tap","<x> <y> | --testid <id> | --text <t>")),process.exit(1));let r=await c.send({type:"tap",x:t,y:e,...o?{target:{id:n?.id??(o.mode==="testid"?o.value:null),testID:n?.testID??(o.mode==="testid"?o.value:null),text:n?.text??(o.mode==="text"?o.value:null),type:n?.type??null}}:{}}),u=wo(t,e,r);u&&await L("inspect tap",u.step,u.summary),console.log(JSON.stringify(r,null,2));break}case"drag":case"swipe":{let t=Number(i[1]),e=Number(i[2]),o=Number(i[3]),n=Number(i[4]),r=h==="swipe"?10:12,u=h==="swipe"?8:16,m=i[5]?Number(i[5]):r,w=i[6]?Number(i[6]):u;(!Number.isFinite(t)||!Number.isFinite(e)||!Number.isFinite(o)||!Number.isFinite(n)||!Number.isFinite(m)||!Number.isFinite(w))&&(console.error(v(h,"<x1> <y1> <x2> <y2> [steps] [stepMs]")),process.exit(1));let f=await c.send({type:"evaluate",code:`(async () => {
264
- const interact = window.__sootsimInteract
265
- if (!interact?.drag) return { ok: false, reason: 'no interact.drag' }
266
- const value = await interact.drag(${t}, ${e}, ${o}, ${n}, ${Math.max(1,Math.round(m))}, ${Math.max(0,Math.round(w))})
267
- return { ok: !!value, value }
268
- })()`});if(f?.ok){let $=Math.max(1,Math.round(Math.max(1,m)*Math.max(0,w)));await L(`inspect ${h}`,{swipe:{start:`${t}, ${e}`,end:`${o}, ${n}`,duration:$}},`${h} ${t},${e} -> ${o},${n}`)}console.log(JSON.stringify(f,null,2));break}case"pinch":{let t=Number(i[1]),e=Number(i[2]),o=Number(i[3]),n=Number(i[4]),r=Number(i[5]),u=Number(i[6]),m=Number(i[7]),w=Number(i[8]),f=i[9]?Number(i[9]):12,$=i[10]?Number(i[10]):16;(!Number.isFinite(t)||!Number.isFinite(e)||!Number.isFinite(o)||!Number.isFinite(n)||!Number.isFinite(r)||!Number.isFinite(u)||!Number.isFinite(m)||!Number.isFinite(w)||!Number.isFinite(f)||!Number.isFinite($))&&(console.error(v("pinch","<x1> <y1> <x2> <y2> <x1'> <y1'> <x2'> <y2'> [steps] [stepMs]")),process.exit(1));let _=await c.send({type:"evaluate",code:`(async () => {
269
- const interact = window.__sootsimInteract
270
- if (!interact?.pinch) return { ok: false, reason: 'no interact.pinch' }
271
- const value = await interact.pinch(${t}, ${e}, ${o}, ${n}, ${r}, ${u}, ${m}, ${w}, ${Math.max(1,Math.round(f))}, ${Math.max(0,Math.round($))})
272
- return { ok: !!value, value }
273
- })()`});_?.ok&&await L("inspect pinch",{pinch:{from:[t,e,o,n],to:[r,u,m,w],steps:Math.max(1,Math.round(f)),stepMs:Math.max(0,Math.round($))}},`pinch (${t},${e}) (${o},${n}) -> (${r},${u}) (${m},${w})`),console.log(JSON.stringify(_,null,2));break}case"tap-text":{let t=i[1];t||(console.error(v("tap-text","<text>")),process.exit(1));let e=R=>{let A=s.indexOf(R);return A>=0&&A+1<s.length?s[A+1]:null},o=R=>s.includes(R),n=e("--nth")??e("--index"),r=n!==null?Number(n):null;r!==null&&!Number.isFinite(r)&&(console.error(` --nth/--index requires an integer, got: ${n}`),process.exit(1));let u=e("--within"),m=e("--role"),w=o("--exact"),f=o("--first"),$=e("--min-y"),_=e("--max-y"),q=e("--min-x"),H=e("--max-x");for(let[R,A]of[["--min-y",$],["--max-y",_],["--min-x",q],["--max-x",H]])A!==null&&!Number.isFinite(Number(A))&&(console.error(` ${R} requires a number, got: ${A}`),process.exit(1));let U=s.indexOf("--near"),M=null;if(U>=0){let R=Number(s[U+1]),A=Number(s[U+2]);(!Number.isFinite(R)||!Number.isFinite(A))&&(console.error(" --near requires two numbers: --near <x> <y>"),process.exit(1)),M={x:R,y:A}}let y=JSON.stringify({query:t,exact:w,role:m,within:u,minX:q!==null?Number(q):null,maxX:H!==null?Number(H):null,minY:$!==null?Number($):null,maxY:_!==null?Number(_):null,near:M,nth:r,first:f}),p=await c.send({type:"evaluate",code:`(async () => {
274
- const t = window.__sootsimTest
275
- if (!t) return { error: 'bridge-not-ready' }
276
- const F = ${y}
277
-
278
- const res = await t.queryTextCandidates({
279
- query: F.query,
280
- exact: !!F.exact,
281
- ...(F.role ? { role: F.role } : {}),
282
- })
283
-
284
- let candidates = res.candidates || []
285
-
286
- candidates = candidates.filter((c) => {
287
- const ax = c.info.absolutePosition && c.info.absolutePosition.x
288
- const ay = c.info.absolutePosition && c.info.absolutePosition.y
289
- if (F.minX !== null && !(ax >= F.minX)) return false
290
- if (F.maxX !== null && !(ax <= F.maxX)) return false
291
- if (F.minY !== null && !(ay >= F.minY)) return false
292
- if (F.maxY !== null && !(ay <= F.maxY)) return false
293
- if (F.within && !c.ancestorTestIDs.includes(F.within)) return false
294
- return true
295
- })
296
-
297
- if (F.near) {
298
- candidates.sort((a, b) => {
299
- const ax = (a.info.absolutePosition && a.info.absolutePosition.x) || 0
300
- const ay = (a.info.absolutePosition && a.info.absolutePosition.y) || 0
301
- const bx = (b.info.absolutePosition && b.info.absolutePosition.x) || 0
302
- const by = (b.info.absolutePosition && b.info.absolutePosition.y) || 0
303
- return (
304
- Math.hypot(ax - F.near.x, ay - F.near.y) -
305
- Math.hypot(bx - F.near.x, by - F.near.y)
306
- )
307
- })
308
- } else {
309
- candidates.sort((a, b) => {
310
- const ay = (a.info.absolutePosition && a.info.absolutePosition.y) || 0
311
- const by = (b.info.absolutePosition && b.info.absolutePosition.y) || 0
312
- if (Math.abs(ay - by) > 2) return ay - by
313
- const ax = (a.info.absolutePosition && a.info.absolutePosition.x) || 0
314
- const bx = (b.info.absolutePosition && b.info.absolutePosition.x) || 0
315
- return ax - bx
316
- })
317
- }
318
-
319
- const total = candidates.length
320
- if (total === 0) return { matched: 0, total: 0 }
321
-
322
- let idx = 0
323
- if (F.nth !== null) {
324
- idx = F.nth < 0 ? total + F.nth : F.nth
325
- if (idx < 0 || idx >= total) {
326
- return { matched: 0, total, nthOutOfRange: true, nth: F.nth }
327
- }
328
- } else if (total > 1 && !F.first && !F.near) {
329
- return {
330
- ambiguous: true,
331
- total,
332
- candidates: candidates.slice(0, 10).map((c, i) => ({
333
- idx: i,
334
- nodeId: c.info.nodeId,
335
- type: c.info.type,
336
- testID: c.info.testID,
337
- text: (c.info.text || '').slice(0, 60),
338
- abs: c.info.absolutePosition,
339
- layout: c.info.layout
340
- ? {
341
- width: Math.round(c.info.layout.width || 0),
342
- height: Math.round(c.info.layout.height || 0),
343
- }
344
- : null,
345
- ancestorTestIDs: (c.ancestorTestIDs || []).slice(0, 5),
346
- })),
347
- }
348
- }
349
-
350
- const picked = candidates[idx]
351
- const n = picked.info
352
- if (!n.absolutePosition || !n.layout) return { matched: 0, total }
353
-
354
- const resolved =
355
- typeof n.nodeId === 'number' &&
356
- typeof t.resolveTapTarget === 'function'
357
- ? await t.resolveTapTarget(n.nodeId)
358
- : null
359
- const target = (resolved && resolved.target) || n
360
- const cx =
361
- resolved && typeof resolved.cx === 'number'
362
- ? resolved.cx
363
- : n.absolutePosition.x + (n.layout.width || 0) / 2
364
- const cy =
365
- resolved && typeof resolved.cy === 'number'
366
- ? resolved.cy
367
- : n.absolutePosition.y + (n.layout.height || 0) / 2
368
- return {
369
- cx,
370
- cy,
371
- match: {
372
- nodeId: n.nodeId ?? null,
373
- id: n.id,
374
- testID: n.testID,
375
- type: n.type,
376
- },
377
- target: {
378
- nodeId: target.nodeId ?? null,
379
- id: target.id,
380
- testID: target.testID,
381
- text:
382
- target.text ??
383
- target.accessibilityLabel ??
384
- n.text ??
385
- n.accessibilityLabel ??
386
- null,
387
- type: target.type,
388
- },
389
- strategy: (resolved && resolved.strategy) || 'matched-node',
390
- total,
391
- idx,
392
- }
393
- })()`});if(p?.error==="bridge-not-ready"&&(console.error(" sootsim test bridge not ready"),process.exit(1)),p?.ambiguous){let R=p.candidates;console.error(` ambiguous: ${p.total} matches for "${t}"`);for(let A of R){let we=A.abs?`@(${Math.round(A.abs.x)},${Math.round(A.abs.y)})`:"",le=A.layout?` ${A.layout.width}x${A.layout.height}`:"",Jt=A.testID?` #${A.testID}`:"",Wt=A.text?` "${A.text}"`:"",qt=A.ancestorTestIDs.length>0?` within ${A.ancestorTestIDs.slice(0,3).map(Ht=>`#${Ht}`).join(" > ")}`:"";console.error(` [${A.idx}] <${A.type}>${Wt}${Jt} ${we}${le}${qt}`)}p.total>R.length&&console.error(` ... and ${p.total-R.length} more`),console.error(" pick one:"),console.error(" --nth <index> pick the nth match (top-to-bottom, left-to-right; negatives from end)"),console.error(" --within <testID> narrow to descendants of a node"),console.error(" --min-y / --max-y geometric filter (pixels, absolute)"),console.error(" --min-x / --max-x geometric filter (pixels, absolute)"),console.error(" --near <x> <y> pick the closest match to a point"),console.error(" --exact exact text match (default is substring)"),console.error(" --role <role> narrow to accessibilityRole"),console.error(" --first keep the old pick-first-silently behavior"),process.exit(2)}p?.nthOutOfRange&&(console.error(` not found: nth ${p.nth} of ${p.total} match${p.total===1?"":"es"} for "${t}"`),process.exit(1)),(!p||typeof p.cx!="number")&&(console.error(` not found: ${t}`),process.exit(1));let P=await c.send({type:"tap",x:p.cx,y:p.cy,target:{id:p.target?.id??null,testID:p.target?.testID??null,text:t,type:p.target?.type??null}});if(P?.hit!==!1&&P?.ok!==!1){let R=_e(t,{id:p.target?.id??null,testID:p.target?.testID??null,type:p.target?.type??null,cx:p.cx,cy:p.cy},"text");await L("inspect tap-text",R.step,R.summary)}console.log(JSON.stringify({matched:p.match,tapped:{nodeId:p.target?.nodeId??null,id:p.target?.id??null,testID:p.target?.testID??null,type:p.target?.type??null,cx:p.cx,cy:p.cy},...p.strategy&&p.strategy!=="matched-node"?{strategy:p.strategy}:{},...p.total>1||r!==null?{nth:{index:p.idx,total:p.total}}:{},result:P},null,2));break}case"tap-best":{let t=i[1];t||(console.error(v("tap-best","<query>")),process.exit(1));let e=JSON.stringify(t),o=await c.send({type:"evaluate",code:`(async () => {
394
- const t = window.__sootsimTest
395
- if (!t) return { error: 'bridge-not-ready' }
396
- // try testID first \u2014 strongest signal of "this is the
397
- // intended tap target".
398
- const byTestId =
399
- (await t.findByTestId(${e})) || (await t.findById(${e}))
400
- if (byTestId && byTestId.absolutePosition && byTestId.layout) {
401
- return {
402
- strategy: 'testid',
403
- node: {
404
- nodeId: byTestId.nodeId ?? null,
405
- id: byTestId.id,
406
- testID: byTestId.testID,
407
- type: byTestId.type,
408
- text: byTestId.text,
409
- absolutePosition: byTestId.absolutePosition,
410
- layout: byTestId.layout,
411
- },
412
- }
413
- }
414
- // text fallback. findByText returns null when there are
415
- // 0 or 2+ matches \u2014 to disambiguate we'd send the user
416
- // back to tap-text with --nth, which is the right
417
- // failure mode.
418
- const byText = await t.findByText(${e})
419
- if (byText && byText.absolutePosition && byText.layout) {
420
- return {
421
- strategy: 'text',
422
- node: {
423
- nodeId: byText.nodeId ?? null,
424
- id: byText.id,
425
- testID: byText.testID,
426
- type: byText.type,
427
- text: byText.text,
428
- absolutePosition: byText.absolutePosition,
429
- layout: byText.layout,
430
- },
431
- }
432
- }
433
- return { strategy: 'none' }
434
- })()`});"error"in o&&(console.error(` ${o.error}`),process.exit(1)),o.strategy==="none"&&(console.error(` tap-best: no testID or visible text matched "${t}". try \`sootsim find --interactive-targets\` to list candidates.`),process.exit(1));let n=o.node,r=n.absolutePosition.x+n.layout.width/2,u=n.absolutePosition.y+n.layout.height/2,m=await c.send({type:"tap",x:r,y:u,target:{id:n.id,testID:n.testID,text:o.strategy==="text"?t:null,type:n.type}});if(m?.hit!==!1&&m?.ok!==!1){let w=_e(t,{id:n.id,testID:n.testID,type:n.type,cx:r,cy:u},o.strategy==="testid"?"id":"text");await L("inspect tap-best",w.step,w.summary)}console.log(JSON.stringify({matched:{strategy:o.strategy,nodeId:n.nodeId,id:n.id,testID:n.testID,type:n.type,text:n.text},tapped:{cx:r,cy:u},result:m},null,2));break}case"tap-id":{let t=i[1];t||(console.error(v("tap-id","<id>")),process.exit(1));let e=JSON.stringify(t),o=await c.send({type:"evaluate",code:`(async () => {
435
- const t = window.__sootsimTest
436
- if (!t) return null
437
- const n = (await t.findByTestId(${e})) || (await t.findById(${e}))
438
- if (!n || !n.absolutePosition || !n.layout) return { cx: null }
439
- const resolved =
440
- typeof n.nodeId === 'number' && typeof t.resolveTapTarget === 'function'
441
- ? await t.resolveTapTarget(n.nodeId)
442
- : null
443
- const target = (resolved && resolved.target) || n
444
- const cx =
445
- resolved && typeof resolved.cx === 'number'
446
- ? resolved.cx
447
- : n.absolutePosition.x + (n.layout.width || 0) / 2
448
- const cy =
449
- resolved && typeof resolved.cy === 'number'
450
- ? resolved.cy
451
- : n.absolutePosition.y + (n.layout.height || 0) / 2
452
- return {
453
- cx,
454
- cy,
455
- match: {
456
- nodeId: n.nodeId ?? null,
457
- id: n.id,
458
- testID: n.testID,
459
- text: n.text ?? n.accessibilityLabel ?? null,
460
- type: n.type,
461
- },
462
- target: {
463
- nodeId: target.nodeId ?? null,
464
- id: target.id,
465
- testID: target.testID,
466
- text:
467
- target.text ??
468
- target.accessibilityLabel ??
469
- n.text ??
470
- n.accessibilityLabel ??
471
- null,
472
- type: target.type,
473
- },
474
- strategy: (resolved && resolved.strategy) || 'matched-node',
475
- }
476
- })()`});(!o||typeof o.cx!="number")&&(console.error(` not found: ${t}`),process.exit(1));let n=await c.send({type:"tap",x:o.cx,y:o.cy,target:{id:o.target?.id??o.match?.id??null,testID:o.target?.testID??o.match?.testID??null,text:o.target?.text??o.target?.accessibilityLabel??o.match?.text??o.match?.accessibilityLabel??null,type:o.target?.type??o.match?.type??null}});if(n?.hit!==!1&&n?.ok!==!1){let r=_e(t,{id:o.target?.id??null,testID:o.target?.testID??null,type:o.target?.type??null,cx:o.cx,cy:o.cy},"id");await L("inspect tap-id",r.step,r.summary)}console.log(JSON.stringify({matched:o.match,tapped:{nodeId:o.target?.nodeId??null,id:o.target?.id??null,testID:o.target?.testID??null,type:o.target?.type??null,cx:o.cx,cy:o.cy},...o.strategy&&o.strategy!=="matched-node"?{strategy:o.strategy}:{},result:n},null,2));break}case"type-into":{let t=i[1],e=i.slice(2).join(" ");(!t||!e)&&(console.error(v("type-into","<id> <text>")),process.exit(1));let o=JSON.stringify(t),n=await c.send({type:"evaluate",code:`(async () => {
477
- const t = window.__sootsimTest
478
- if (!t) return null
479
- const n = await (t.findByTestId(${o}) || t.findById(${o}))
480
- if (!n || !n.absolutePosition || !n.layout) return null
481
- return {
482
- cx: n.absolutePosition.x + (n.layout.width || 0) / 2,
483
- cy: n.absolutePosition.y + (n.layout.height || 0) / 2,
484
- id: n.id,
485
- testID: n.testID,
486
- type: n.type,
487
- isTextInput: !!n.isTextInput,
488
- placeholder: n.placeholder || null,
489
- }
490
- })()`});(!n||typeof n.cx!="number")&&(console.error(` not found: ${t}`),process.exit(1)),n.isTextInput||console.error(` warning: ${t} is not a text input (isTextInput: false)`);let r=await c.send({type:"tap",x:n.cx,y:n.cy,target:{id:n.id??t,testID:n.testID??t,text:null,type:n.type??null}}),u=await go(c);u.visible||(console.error(` keyboard did not open after tapping ${t}`),process.exit(1));let m=u.focusedInput;m&&(m.testID===t||m.id===t||(console.error(` focus routing mismatch after tap: requested ${JSON.stringify(t)} but focus is on ${JSON.stringify(m.testID??m.id??null)}. did the tap land on an outer Pressable wrapper?`),process.exit(1))),await c.send({type:"keyboard",action:"type",text:e}),await L("inspect type-into",{tapOn:{id:t},inputText:e},`type-into #${t} ${JSON.stringify(e)}`),console.log(JSON.stringify({target:t,isTextInput:n.isTextInput,keyboardOpened:u.visible??r?.keyboardOpened??!1,focusedInput:u.focusedInput??null,typed:e},null,2));break}case"type":{let t=i.slice(1).join(" ");t||(console.error(v("type","<text>")),process.exit(1)),await ye(c,"type"),await c.send({type:"keyboard",action:"type",text:t}),await L("inspect type",{inputText:t},`type ${JSON.stringify(t)}`),console.log(` typed: ${JSON.stringify(t)}`);break}case"key":{let t=i[1];t||(console.error(v("key","<name>")),process.exit(1)),await ye(c,"key"),await c.send({type:"keyboard",action:"press",text:t}),await L("inspect key",{pressKey:t},`key ${t}`),console.log(` pressed: ${t}`);break}case"key-sequence":{let t=i.slice(1);t.length===0&&(console.error(v("key-sequence","<key> [<key> ...]")),process.exit(1)),await ye(c,"key-sequence");for(let e of t)await c.send({type:"keyboard",action:"press",text:e});await L("inspect key-sequence",{pressKey:t.join(" ")},`key-sequence ${t.join(" ")}`),console.log(` pressed: ${t.join(", ")}`);break}case"keycode":{let t=i.slice(1);t.length===0&&(console.error(v("keycode","<code> [<code> ...]")),process.exit(1));let e=t.map(n=>({code:n,key:yo(n)})),o=e.filter(n=>!n.key);o.length>0&&(console.error(` unsupported keycode(s): ${o.map(n=>n.code).join(", ")}`),process.exit(1)),await ye(c,"keycode");for(let n of e)await c.send({type:"keyboard",action:"press",text:n.key});await L("inspect keycode",{pressKey:e.map(n=>n.key).join(" ")},`keycode ${t.join(" ")}`),console.log(` pressed: ${t.join(", ")}`);break}case"dispatch":{let t=i[1];t||(console.error(v("dispatch","<char>")),process.exit(1)),await c.send({type:"keyboard",action:"dispatchKey",text:t}),await L("inspect dispatch",{dispatchKey:t},`dispatch ${JSON.stringify(t)}`),console.log(` dispatched: ${t}`);break}case"dismiss":{await c.send({type:"keyboard",action:"dismiss"}),await L("inspect dismiss",{hideKeyboard:!0},"dismiss keyboard"),console.log(" keyboard dismissed");break}case"double-tap":{let t=Number(i[1]),e=Number(i[2]),o=ae(s);if(o){let m=await pe(c,o);m||(console.error(` not found: ${o.value}`),o.mode==="testid"&&G("wait-selector-for-missing-testid",o.value),process.exit(1)),t=m.x,e=m.y}let n=i[3]?Number(i[3]):80;(!Number.isFinite(t)||!Number.isFinite(e)||!Number.isFinite(n))&&(console.error(v("double-tap","<x> <y> [gapMs] | --testid <id>")),process.exit(1));let r=Math.max(0,Math.round(n)),u=await c.send({type:"evaluate",code:`(async () => {
491
- const interact = window.__sootsimInteract
492
- if (interact?.doubleTap) {
493
- return {
494
- ok: !!(await interact.doubleTap(${t}, ${e}, ${r})),
495
- gapMs: ${r},
496
- }
497
- }
498
- if (!interact?.tap) {
499
- return { ok: false, reason: 'no interact.tap', gapMs: ${r} }
500
- }
501
- const first = await interact.tap(${t}, ${e})
502
- if (!first || first.hit === false) {
503
- return { ok: false, reason: 'first tap missed', gapMs: ${r}, first }
504
- }
505
- await new Promise((resolve) => setTimeout(resolve, ${r}))
506
- const second = await interact.tap(${t}, ${e})
507
- return {
508
- ok: !!second && second.hit !== false,
509
- gapMs: ${r},
510
- first,
511
- second,
512
- }
513
- })()`});u?.ok&&await L("inspect double-tap",{doubleTapAtCoords:{x:t,y:e,gapMs:r}},`double-tap @${t},${e}`),console.log(JSON.stringify(u,null,2));break}case"long-press":{let t=Number(i[1]),e=Number(i[2]),o=ae(s);if(o){let u=await pe(c,o);u||(console.error(` not found: ${o.value}`),o.mode==="testid"&&G("wait-selector-for-missing-testid",o.value),process.exit(1)),t=u.x,e=u.y}let n=i[3]?Number(i[3]):600;(!Number.isFinite(t)||!Number.isFinite(e)||!Number.isFinite(n))&&(console.error(v("long-press","<x> <y> [durationMs] | --testid <id>")),process.exit(1));let r=await c.send({type:"evaluate",code:`(async () => {
514
- const interact = window.__sootsimInteract
515
- if (!interact?.longPress) return { ok: false, reason: 'no interact.longPress' }
516
- const value = await interact.longPress(${t}, ${e}, ${Math.max(0,Math.round(n))})
517
- return { ok: !!value, value }
518
- })()`});r?.ok&&await L("inspect long-press",{tapAtCoords:{x:t,y:e}},`long-press @${t},${e}`),console.log(JSON.stringify(r,null,2));break}case"touch":{let t=i[1],e=Number(i[2]),o=Number(i[3]),n=i[4]?Number(i[4]):999,r=t==="down"?"touchDown":t==="move"?"touchMove":t==="up"?"touchUp":t==="cancel"?"touchCancel":null;r||(console.error(v("touch","<down|move|up|cancel> <x> <y> [pointerId]")),process.exit(1)),t!=="cancel"&&(!Number.isFinite(e)||!Number.isFinite(o))&&(console.error(v("touch","<down|move|up|cancel> <x> <y> [pointerId]")),process.exit(1));let u=t==="down"?"tap":t==="move"?"move":null,m=u&&Number.isFinite(e)&&Number.isFinite(o)?`window.dispatchEvent(new CustomEvent('sootsim:agentAction', { detail: { type: '${u}', x: ${e}, y: ${o} } }));`:"",w=await c.send({type:"evaluate",code:`(async () => {
519
- ${m}
520
- const interact = window.__sootsimInteract
521
- if (!interact?.${r}) return { ok: false, reason: 'no interact.${r}' }
522
- const value = ${t==="cancel"?`await interact.${r}(${Math.max(1,Math.round(n))})`:`await interact.${r}(${e}, ${o}, ${Math.max(1,Math.round(n))})`}
523
- return { ok: !!value, value }
524
- })()`});w?.ok&&t!=="cancel"&&await L("inspect touch",{tapAtCoords:{x:e,y:o}},`touch ${t} @${e},${o}`),console.log(JSON.stringify(w,null,2));break}case"gesture":{let t=["scroll-up","scroll-down","scroll-left","scroll-right","swipe-from-left-edge","swipe-from-right-edge","swipe-from-top-edge","swipe-from-bottom-edge"],e=i[1],o=i[2]?Number(i[2]):220;(!e||!Number.isFinite(o))&&(console.error(v("gesture","<preset> [durationMs]")),console.error(` presets: ${t.join(", ")}`),process.exit(1)),t.includes(e)||(console.error(` unknown gesture preset: ${e}`),console.error(` presets: ${t.join(", ")}`),process.exit(1));let n=await c.send({type:"evaluate",code:`(async () => {
525
- const spec = globalThis.__sootsimDeviceSpec || {}
526
- return {
527
- width: spec.width || window.innerWidth || 393,
528
- height: spec.height || window.innerHeight || 852,
529
- statusBarHeight: spec.statusBarHeight || 0,
530
- homeIndicatorHeight: spec.homeIndicatorHeight || 0,
531
- }
532
- })()`}),r=Number(n?.width)||393,u=Number(n?.height)||852,m=Number(n?.statusBarHeight)||0,w=Number(n?.homeIndicatorHeight)||0,f=Math.round(r/2),$=Math.round(u/2),_=Math.max(24,m+18),q=Math.max(24,w+18),H=18,U=Math.min(220,Math.round(u*.24)),M=Math.min(180,Math.round(r*.32)),y=f,p=$,P=f,R=$;switch(e){case"scroll-up":p=$+Math.round(U/2),R=$-Math.round(U/2);break;case"scroll-down":p=$-Math.round(U/2),R=$+Math.round(U/2);break;case"scroll-left":y=f+Math.round(M/2),P=f-Math.round(M/2);break;case"scroll-right":y=f-Math.round(M/2),P=f+Math.round(M/2);break;case"swipe-from-left-edge":y=H,p=$,P=Math.min(r-H,H+M);break;case"swipe-from-right-edge":y=r-H,p=$,P=Math.max(H,r-H-M);break;case"swipe-from-top-edge":y=f,p=_,R=Math.min(u-q,_+U);break;case"swipe-from-bottom-edge":y=f,p=u-q,R=Math.max(_,u-q-U);break}let A=Math.max(8,Math.round(o/16)),we=Math.max(1,Math.round(o/A)),le=await c.send({type:"evaluate",code:`(async () => {
533
- const interact = window.__sootsimInteract
534
- if (!interact?.drag) return { ok: false, reason: 'no interact.drag' }
535
- const value = await interact.drag(${y}, ${p}, ${P}, ${R}, ${A}, ${we})
536
- return { ok: !!value, value }
537
- })()`});le?.ok&&await L("inspect gesture",{swipe:{start:`${y}, ${p}`,end:`${P}, ${R}`,duration:Math.max(1,Math.round(o))}},`gesture ${e}`),console.log(JSON.stringify({preset:e,from:{x:y,y:p},to:{x:P,y:R},result:le},null,2));break}case"scroll":{let t=ae(s),e=bo(s),o=t?.mode==="testid"?t.value:e==null?i[1]:null,n=t||e!=null?1:2,r=Number(i[n]),u=Number(i[n+1]);(!o&&e==null||!Number.isFinite(r)||!Number.isFinite(u))&&(console.error(v("scroll","<id> <x> <y> | --testid <id> <x> <y> | --node-id <nodeId> <x> <y>")),process.exit(1));let m=await c.send({type:"evaluate",code:`(async () => {
538
- const t = window.__sootsimTest
539
- if (!t) return null
540
- const n = ${e!=null?`await t.inspectByNodeId(${JSON.stringify(e)})`:`await t.findByTestId(${JSON.stringify(o)})
541
- || await t.findById(${JSON.stringify(o)})`}
542
- if (!n || !n.absolutePosition || !n.layout) return null
543
- return {
544
- cx: n.absolutePosition.x + (n.layout.width || 0) / 2,
545
- cy: n.absolutePosition.y + (n.layout.height || 0) / 2,
546
- }
547
- })()`}),w=await z(c,"scrollTo",e!=null?{nodeId:e}:o,r,u,!1);if(w?.ok){let f=e!=null?`node ${e}`:`#${o}`;await L("inspect scroll",{scrollTo:{...e!=null?{nodeId:e}:{id:o},x:r,y:u}},`scroll ${f} -> ${r},${u}`)}console.log(JSON.stringify({...w,...m?{at:{x:m.cx,y:m.cy}}:{}},null,2));break}case"state":{let t=i[1];if(a==="get"&&!t){let o=await z(c,"getRuntimeState"),n=await c.send({type:"evaluate",code:`({
548
- errors: window.__sootsimConsole?.getErrors?.()?.length ?? 0,
549
- warnings: window.__sootsimConsole?.getWarnings?.()?.length ?? 0,
550
- })`});if(o&&typeof o=="object"&&o.diagnostics&&(o.diagnostics.errors=n?.errors??0,o.diagnostics.warnings=n?.warnings??0),o&&typeof o=="object"&&o.shell==null)try{let r=await se(c);r&&(o.shell=r)}catch{}console.log(JSON.stringify(o,null,2));break}if(!t||t==="--help"||t==="-h"){console.log(`
551
- ${b("state")} \u2014 dump raw runtime state
552
-
553
- subcommands:
554
- shell dump shell transition/layout state
555
- worker dump render-worker host/animation state
556
- keyboard dump keyboard visibility, mode, and focused input
557
- ownership dump surface ownership + pointerOnSurface delivery stats
558
- node <id> dump raw node info by id or testID
559
- scroll <id> dump scroll metrics and runtime state
560
- scroll-hit <x> <y> dump the nearest scroll ancestor at coordinates
561
- hit <x> <y> dump the hit-test ancestry at coordinates
562
- gesture <x> <y> dump gesture routing/debug info at coordinates
563
-
564
- examples:
565
- ${b("state")} shell
566
- ${b("state")} worker
567
- ${b("state")} keyboard
568
- ${b("state")} ownership
569
- ${b("state")} node photos
570
- ${b("state")} scroll feed
571
- ${b("state")} scroll-hit 360 420
572
- ${b("state")} hit 200 720
573
- `);break}let e;switch(t){case"shell":e=await se(c,500);break;case"worker":e=await Se(c,"__sootsimRenderHost.queryStats");break;case"ownership":e=await c.send({type:"evaluate",code:`(() => {
574
- const h = window.__sootsimRenderHost
575
- if (!h || typeof h.getOwnershipSnapshot !== 'function') {
576
- return { error: 'getOwnershipSnapshot not available' }
577
- }
578
- return h.getOwnershipSnapshot()
579
- })()`});break;case"keyboard":e=await c.send({type:"evaluate",code:`(async () => {
580
- const kb = window.__sootsimKeyboard
581
- const test = window.__sootsimTest
582
- if (!kb) return { error: 'keyboard bridge not available' }
583
- const layout = typeof kb.getLayout === 'function' ? kb.getLayout() : null
584
- const visible = kb.isVisible()
585
- const mode = kb.getMode()
586
- let focused = null
587
- if (test && typeof test.getFocusedNode === 'function') {
588
- try {
589
- focused = await test.getFocusedNode()
590
- } catch {}
591
- }
592
- return {
593
- visible,
594
- mode,
595
- layout,
596
- focusedInput: focused ? {
597
- nodeId: focused.nodeId ?? null,
598
- testID: focused.testID || null,
599
- id: focused.id || null,
600
- placeholder: focused.placeholder || null,
601
- text: focused.text || null,
602
- } : null,
603
- }
604
- })()`});break;case"node":{let o=i[2];o||(console.error(` usage: ${b("state")} node <id>`),process.exit(1)),e=await z(c,"findByTestId",o)||await z(c,"findById",o);break}case"scroll":{let o=i[2];o||(console.error(` usage: ${b("state")} scroll <id>`),process.exit(1)),e=await z(c,"getScrollState",o);break}case"scroll-hit":{let o=Number(i[2]),n=Number(i[3]);(!Number.isFinite(o)||!Number.isFinite(n))&&(console.error(` usage: ${b("state")} scroll-hit <x> <y>`),process.exit(1)),e=await z(c,"getScrollStateAt",o,n);break}case"hit":{let o=Number(i[2]),n=Number(i[3]);(!Number.isFinite(o)||!Number.isFinite(n))&&(console.error(` usage: ${b("state")} hit <x> <y>`),process.exit(1)),e=await z(c,"debugHitAt",o,n);break}case"gesture":{let o=Number(i[2]),n=Number(i[3]);(!Number.isFinite(o)||!Number.isFinite(n))&&(console.error(` usage: ${b("state")} gesture <x> <y>`),process.exit(1)),e=await z(c,"debugGestureAt",o,n);break}default:console.error(` unknown state subcommand: ${t}`),process.exit(1)}console.log(JSON.stringify(e,null,2));break}case"shell":{let t=i[1];if(!t||t==="--help"||t==="-h"){console.log(`
605
- ${b("shell")} \u2014 run built-in shell commands
606
-
607
- subcommands:
608
- launch <appId> [waitMs] [--clear-state]
609
- launch app and wait for settled shell state
610
- home [waitMs] go home and wait for settled shell state
611
- switcher [waitMs] open switcher and wait for settled shell state
612
- open-card <appId> [waitMs]
613
- open a specific switcher card and wait for app settle
614
- appearance <light|dark|auto|toggle>
615
- update simulator appearance
616
- lock toggle device lock state
617
- shake trigger the simulator shake gesture
618
-
619
- examples:
620
- ${b("shell")} launch photos
621
- ${b("shell")} launch rn --clear-state
622
- ${b("shell")} launch photos 1500
623
- ${b("shell")} home 500
624
- ${b("shell")} switcher 800
625
- ${b("shell")} open-card clock 800
626
- ${b("shell")} appearance dark
627
- ${b("shell")} lock
628
- `);break}let e=t==="launch"||t==="open-card"||t==="home"||t==="switcher",o=t==="launch"||t==="open-card"?i[3]:i[2],n=o?Number(o):350;e&&(!Number.isFinite(n)||n<0)&&(console.error(v("shell",t==="launch"||t==="open-card"?"<launch|open-card> <appId> [settleMs]":"<home|switcher> [settleMs]")),process.exit(1));let r=!1,u=!1,m=null,w=s.includes("--clear-state");if(t==="launch"){let f=i[2];f||(console.error(v("shell","launch <appId> [settleMs] [--clear-state]")),process.exit(1)),w&&await c.send({type:"evaluate",code:je}),r=!!await re(c,"launchApp",n,f),{settled:u,state:m}=await ge(c,Math.round(n),$=>!!$&&$.state==="app"&&$.activeApp===f&&$.showSwitcher===!1&&$.switcherPhase==="idle"&&typeof $.launchProgress=="number"&&$.launchProgress>=.98),r&&await L("inspect shell launch",w?{launchApp:{clearState:!0}}:{launchApp:{}},w?"launch app (clear state)":"launch app")}else if(t==="home")r=!!await re(c,"goHome",n),{settled:u,state:m}=await ge(c,Math.round(n),f=>!!f&&f.state==="home"&&f.activeApp==null&&f.showSwitcher===!1&&f.switcherPhase==="idle"&&typeof f.launchProgress=="number"&&f.launchProgress>=.98);else if(t==="switcher")r=!!await re(c,"openSwitcher",n),{settled:u,state:m}=await ge(c,Math.round(n),f=>!!f&&f.state==="app"&&f.showSwitcher===!0&&f.switcherPhase==="idle"&&typeof f.zoomLevel=="number"&&Math.abs(f.zoomLevel)<=.02&&typeof f.horizontalZoom=="number"&&Math.abs(f.horizontalZoom)<=.02),u&&(await X(fo),m=await se(c));else if(t==="open-card"){let f=i[2];f||(console.error(v("shell","open-card <appId> [settleMs]")),process.exit(1)),r=!!await re(c,"openSwitcherCard",n,f),{settled:u,state:m}=await ge(c,Math.round(n),$=>!!$&&$.state==="app"&&$.activeApp===f&&$.showSwitcher===!1&&$.switcherPhase==="idle"&&typeof $.zoomLevel=="number"&&$.zoomLevel>=.98&&typeof $.horizontalZoom=="number"&&$.horizontalZoom>=.98),r&&await L("inspect shell open-card",{openSwitcherCard:{appId:f}},`open switcher card ${f}`)}else if(t==="appearance"){let f=i[2];(!f||!["light","dark","auto","toggle"].includes(f))&&(console.error(v("shell","appearance <light|dark|auto|toggle>")),process.exit(1));let $=await Ct(c,"appearance",f);if(r=!!$?.ok,m={appearance:$},r){let _=$?.applied??f;console.log(` appearance: ${_}`)}}else if(t==="lock"||t==="shake"){let f=await Ct(c,t);r=!!f?.ok,m={[t]:f}}else console.error(` unknown shell subcommand: ${t}`),process.exit(1);console.log(JSON.stringify({ok:r,settled:u,state:m},null,2));break}case"url":{await Mt(c,{args:l});break}case"reload":{let o=!1,n=!1;try{await c.send({type:"evaluate",code:"window.__sootsimConsole?.clear()"});let m=await c.send({type:"evaluate",code:`;(() => {
629
- const reloadExternalApp = window.SootSim?.bridges?.hotRemount?.reloadExternalApp
630
- if (typeof reloadExternalApp === 'function') {
631
- reloadExternalApp()
632
- return { kind: 'external-app' }
633
- }
634
- window.location.reload()
635
- return { kind: 'page' }
636
- })()`});n=!!m&&m.kind==="external-app",o=!0}catch{}console.log(" reloading...");let r=c,u=null;if(n)u=await Te(c,{timeoutMs:1e4,errorGraceMs:3e3});else{o&&await X(300);let m=await ct(N,J,T,{timeoutMs:1e4,simIdSource:E});m?(r=m,u=await Te(m,{timeoutMs:1e4,errorGraceMs:3e3})):(console.log(" \u26A0 reload: bridge never reconnected within 10000ms"),r=null)}if(u)if(u.ready){let m=u.source==="nodes-fallback"?" (no ready signal, node-count fallback)":"";console.log(` ready in ${u.elapsedMs}ms: ${u.nodes} nodes${m}`)}else u.source==="error-bail"?console.log(` \u26A0 reload bailed after ${u.elapsedMs}ms: ${u.errors} console error(s), ready signal never fired`):console.log(` \u26A0 reload timed out after ${u.elapsedMs}ms (${u.nodes} nodes, ${u.errors} errors)`);if(r)try{let m=await r.send({type:"evaluate",code:"window.__sootsimConsole?.getErrors(10) || []"});if(r!==c&&r.close(),Array.isArray(m)&&m.length>0){console.log(`
637
- \u26A0 ${m.length} error(s) during mount:
638
- `);for(let w of m){let f=w.args.map($=>typeof $=="object"?JSON.stringify($):$).join(" ");if(console.log(` ${f}`),w.stack){let $=w.stack.split(`
639
- `).slice(0,2);for(let _ of $)console.log(` ${_.trim()}`)}}}}catch{}u&&!u.ready&&(process.exitCode=1);break}case"eval":case"js":{let t=i.slice(1).join(" ");t||(console.error(v("js","<javascript>")),console.error(""),console.error(" runs the snippet in the engine realm. SootSim is the"),console.error(" canonical state surface \u2014 reach into it directly."),console.error(""),console.error(" examples:"),console.error(` ${b("js")} SootSim.bridges.test.findByText("Sign in")`),console.error(` ${b("js")} SootSim.bridges.debug.snapshot("before")`),console.error(` ${b("js")} SootSim.bridges.keyboard.type("hello")`),console.error(` ${b("js")} SootSim.state.root.children.length`),process.exit(1));let e=t;e.startsWith("(async")||(e=`(async () => ${e})()`);let o=await c.send({type:"evaluate",code:e});console.log(JSON.stringify(o,null,2));let n=t.toLowerCase(),r=[];(n.includes("sootsim:gohome")||n.includes("gohome"))&&r.push("sootsim shell home"),(n.includes("sootsim:appswitcher")||n.includes("appswitcher"))&&r.push("sootsim shell switcher"),(n.includes("keyboard.isvisible")||n.includes("keyboard.getmode"))&&r.push("sootsim debug state keyboard"),n.includes("interact.tap")&&r.push("sootsim do tap <x> <y>"),n.includes("keyboard.type")&&r.push("sootsim do type <text>"),(n.includes("keyboard.press")||n.includes("keyboard.dispatchkey"))&&r.push("sootsim do key <name>"),n.includes("keyboard.dismiss")&&r.push("sootsim do dismiss"),n.includes("dumptree")&&r.push("sootsim get tree"),n.includes("dumpaccessibilitytree")&&r.push("sootsim get a11y"),n.includes("getnodecount")&&r.push("sootsim get count"),n.includes("findbytext")&&r.push("sootsim find <text>"),(n.includes("findbytestid")||n.includes("findbyid"))&&r.push("sootsim find --testid <id>"),n.includes("document.hidden")&&r.push("sootsim debug state keyboard (includes tab health)"),r.length>0&&G("prefer-cli-over-eval",r);break}case"globals":{let t=await c.send({type:"evaluate",code:`(async () => {
640
- const globals = {}
641
-
642
- // test bridge (proxy in worker mode)
643
- const testMethods = [
644
- 'findById', 'findByTestId', 'findByText', 'findByLabel', 'findByRole',
645
- 'findAllByRole', 'findByA11yState', 'findAllByA11yState', 'findByHint',
646
- 'findPressable', 'getStyle', 'getLayout', 'getAbsolutePosition', 'isVisible',
647
- 'queryAll', 'dumpTree', 'dumpAccessibilityTree', 'getNodeCount', 'getShellState',
648
- 'getScrollState', 'getScrollStateAt', 'scrollTo', 'waitForTree',
649
- 'waitForScreenTransitions', 'debugByText', 'debugByTestId', 'debugHitAt',
650
- 'debugGestureAt'
651
- ]
652
- globals['test (\u2192 __sootsimTest)'] = testMethods
653
-
654
- // debug
655
- if (window.__sootsimDebug) {
656
- globals['debug (\u2192 __sootsimDebug)'] = Object.keys(window.__sootsimDebug)
657
- }
658
-
659
- // interact
660
- if (window.__sootsimInteract) {
661
- globals['interact (\u2192 __sootsimInteract)'] = Object.keys(window.__sootsimInteract)
662
- }
663
-
664
- // keyboard
665
- if (window.__sootsimKeyboard) {
666
- globals['keyboard (\u2192 __sootsimKeyboard)'] = Object.keys(window.__sootsimKeyboard)
667
- }
668
-
669
- // other globals
670
- globals['other'] = [
671
- 'root (\u2192 __sootsimRoot) - live node tree',
672
- 'render() (\u2192 __sootsimForceRender) - force re-render'
673
- ]
674
-
675
- return globals
676
- })()`});console.log(` sootsim JS API:
677
- `);for(let[e,o]of Object.entries(t)){console.log(` ${e}:`);for(let n of o)console.log(` .${n}`);console.log("")}console.log(` use: ${b("js")} <expression>`),console.log(` example: ${b("js")} test.findByText("Sign in")`);break}case"describe":{await yt({bridge:c,args:s,positional:i});break}case"perf":{let t=i[1];if(!t||t==="--help"||t==="-h"){console.log(`
678
- ${b("perf")} \u2014 performance profiling
679
-
680
- subcommands:
681
- stats one-shot stats (zero overhead query)
682
- start begin recording frame times
683
- stop stop recording and report results
684
- frames [n] get last N frame times (default: 50)
685
- transition <e> profile a shell transition (goHome, appSwitcher, lockScreen)
686
-
687
- examples:
688
- ${b("perf")} stats
689
- ${b("perf")} start
690
- # ... interact with the app ...
691
- ${b("perf")} stop
692
- ${b("perf")} transition goHome
693
- `);break}switch(t){case"stats":{let e=await c.send({type:"evaluate",code:`(async () => {
694
- // worker mode (host exposes these)
695
- if (window.__sootsimPerfStats) {
696
- return await window.__sootsimPerfStats()
697
- }
698
- // main-thread mode
699
- const perf = window.__sootsimPerf
700
- const a11y = window.__sootsimA11y
701
- if (!perf && !a11y) return { error: 'no perf globals available' }
702
-
703
- const frameStats = perf?.getFrameStats?.() || {}
704
- const profile = a11y?.profile?.() || {}
705
- const nodeCount = await window.__sootsimTest?.getNodeCount?.() || 0
706
-
707
- return {
708
- frames: frameStats.frames || profile.syncCount || 0,
709
- avgMs: frameStats.totalMs && frameStats.frames
710
- ? (frameStats.totalMs / frameStats.frames).toFixed(2)
711
- : profile.avgSyncMs?.toFixed(2) || '?',
712
- maxMs: frameStats.maxMs?.toFixed(2) || profile.maxSyncMs?.toFixed(2) || '?',
713
- layoutMs: frameStats.layoutTotalMs?.toFixed(2) || '?',
714
- nodeCount,
715
- jankFrames: frameStats.recentFrames?.filter(f => f > 16.67).length || 0,
716
- recentCount: frameStats.recentFrames?.length || 0,
717
- }
718
- })()`});e.error&&(console.error(` error: ${e.error}`),process.exit(1));let o=e.avgMs!=="?"?(1e3/parseFloat(e.avgMs)).toFixed(1):"?";console.log(" perf stats:"),console.log(` frames: ${e.frames}`),console.log(` avg: ${e.avgMs}ms (${o} fps)`),console.log(` max: ${e.maxMs}ms`),console.log(` layout: ${e.layoutMs}ms total`),console.log(` nodes: ${e.nodeCount}`),e.recentCount>0&&console.log(` jank: ${e.jankFrames}/${e.recentCount} frames >16.67ms`);break}case"start":{await c.send({type:"evaluate",code:`(async () => {
719
- // worker mode
720
- if (window.__sootsimPerfStart && window.__sootsimRenderHost) {
721
- const result = window.__sootsimPerfStart()
722
- window.${Q} = {
723
- active: true,
724
- mode: 'render-worker',
725
- lastSamples: [],
726
- startedAt: performance.now(),
727
- }
728
- return result
729
- }
730
- // main-thread mode
731
- window.__sootsimPerf?.enableFrameStats?.(true)
732
- window.__sootsimA11y?.resetProfile?.()
733
- window.${Q} = {
734
- active: true,
735
- mode: 'main-thread',
736
- lastSamples: [],
737
- startedAt: performance.now(),
738
- }
739
- return { started: true }
740
- })()`}),console.log(` profiling started \u2014 interact with the app, then run '${b("perf")} stop'`);break}case"stop":{let e=await c.send({type:"evaluate",code:`(async () => {
741
- // worker mode
742
- if (window.__sootsimRenderHost) {
743
- const session = window.${Q} || {}
744
- const priorSamples = session.active && Array.isArray(session.lastSamples)
745
- ? session.lastSamples
746
- : []
747
- const flushedSamples = await window.__sootsimRenderHost.flushSamples()
748
- const samples = priorSamples.concat(flushedSamples)
749
- window.${Q} = {
750
- ...session,
751
- active: false,
752
- mode: 'render-worker',
753
- lastSamples: samples,
754
- stoppedAt: performance.now(),
755
- }
756
-
757
- const frameTimes = samples.map(sample => sample[1])
758
- const layoutTimes = samples.map(sample => sample[2])
759
- const renderTimes = samples.map(sample => sample[3])
760
- const copyTimes = samples.map(sample => sample[4])
761
- const auxTimes = samples.map(sample => sample[5] || 0)
762
- const otherTimes = samples.map(sample => sample[6] || 0)
763
- const sorted = [...frameTimes].sort((a, b) => a - b)
764
- const total = frameTimes.reduce((a, b) => a + b, 0)
765
- const avg = frameTimes.length > 0 ? total / frameTimes.length : 0
766
- const max = Math.max(...frameTimes, 0)
767
- const layoutTotal = layoutTimes.reduce((a, b) => a + b, 0)
768
- const renderTotal = renderTimes.reduce((a, b) => a + b, 0)
769
- const copyTotal = copyTimes.reduce((a, b) => a + b, 0)
770
- const auxTotal = auxTimes.reduce((a, b) => a + b, 0)
771
- const otherTotal = otherTimes.reduce((a, b) => a + b, 0)
772
-
773
- return {
774
- mode: 'render-worker',
775
- frames: frameTimes.length,
776
- totalMs: total,
777
- avgMs: avg,
778
- maxMs: max,
779
- layoutTotalMs: layoutTotal,
780
- renderTotalMs: renderTotal,
781
- copyTotalMs: copyTotal,
782
- auxTotalMs: auxTotal,
783
- otherTotalMs: otherTotal,
784
- layoutAvgMs: frameTimes.length > 0 ? layoutTotal / frameTimes.length : 0,
785
- renderAvgMs: frameTimes.length > 0 ? renderTotal / frameTimes.length : 0,
786
- copyAvgMs: frameTimes.length > 0 ? copyTotal / frameTimes.length : 0,
787
- auxAvgMs: frameTimes.length > 0 ? auxTotal / frameTimes.length : 0,
788
- otherAvgMs: frameTimes.length > 0 ? otherTotal / frameTimes.length : 0,
789
- p50: sorted[Math.floor(sorted.length * 0.5)] || 0,
790
- p95: sorted[Math.floor(sorted.length * 0.95)] || 0,
791
- p99: sorted[Math.floor(sorted.length * 0.99)] || 0,
792
- jankFrames: frameTimes.filter((f) => f > 16.67).length,
793
- sampleCount: frameTimes.length,
794
- }
795
- }
796
- // main-thread mode
797
- const perf = window.__sootsimPerf
798
- const a11y = window.__sootsimA11y
799
- if (!perf && !a11y) return { error: 'no perf globals' }
800
-
801
- const frameStats = perf?.getFrameStats?.() || {}
802
- const profile = a11y?.profile?.() || {}
803
-
804
- // calculate distribution
805
- const recent = frameStats.recentFrames || []
806
- const sorted = [...recent].sort((a, b) => a - b)
807
- const p50 = sorted[Math.floor(sorted.length * 0.5)] || 0
808
- const p95 = sorted[Math.floor(sorted.length * 0.95)] || 0
809
- const p99 = sorted[Math.floor(sorted.length * 0.99)] || 0
810
-
811
- // disable collection
812
- perf?.disableFrameStats?.()
813
- window.${Q} = {
814
- ...(window.${Q} || {}),
815
- active: false,
816
- mode: 'main-thread',
817
- lastSamples: recent.map((ms, index) => [index, ms, 0, 0, 0, 0, 0]),
818
- stoppedAt: performance.now(),
819
- }
820
-
821
- return {
822
- mode: 'main-thread',
823
- frames: frameStats.frames || profile.syncCount || 0,
824
- totalMs: frameStats.totalMs || 0,
825
- avgMs: frameStats.totalMs && frameStats.frames
826
- ? frameStats.totalMs / frameStats.frames
827
- : profile.avgSyncMs || 0,
828
- maxMs: frameStats.maxMs || profile.maxSyncMs || 0,
829
- layoutTotalMs: frameStats.layoutTotalMs || 0,
830
- p50, p95, p99,
831
- jankFrames: recent.filter(f => f > 16.67).length,
832
- sampleCount: recent.length,
833
- }
834
- })()`});e.error&&(console.error(` error: ${e.error}`),process.exit(1));let o=e.avgMs>0?(1e3/e.avgMs).toFixed(1):"?",n=e.sampleCount>0?(e.jankFrames/e.sampleCount*100).toFixed(1):"0";console.log(` profiling stopped:
835
- `),console.log(` frames: ${e.frames}`),console.log(` total: ${e.totalMs.toFixed(1)}ms`),console.log(` avg: ${e.avgMs.toFixed(2)}ms (${o} fps)`),console.log(` max: ${e.maxMs.toFixed(2)}ms`),console.log(""),e.layoutAvgMs!==void 0&&(console.log(" breakdown (avg per frame):"),console.log(` layout: ${e.layoutAvgMs.toFixed(2)}ms`),console.log(` render: ${e.renderAvgMs.toFixed(2)}ms`),console.log(` copy: ${e.copyAvgMs.toFixed(2)}ms`),e.auxAvgMs!==void 0&&console.log(` aux: ${e.auxAvgMs.toFixed(2)}ms`),e.otherAvgMs!==void 0&&console.log(` other: ${e.otherAvgMs.toFixed(2)}ms`),console.log("")),console.log(` distribution (${e.sampleCount} samples):`),console.log(` p50: ${e.p50.toFixed(2)}ms`),console.log(` p95: ${e.p95.toFixed(2)}ms`),console.log(` p99: ${e.p99.toFixed(2)}ms`),console.log(` jank: ${e.jankFrames} frames (${n}%) >16.67ms`);break}case"frames":{let e=i[2]?Number(i[2]):50;(!Number.isFinite(e)||e<=0)&&(console.error(` error: expected a positive frame count, got "${i[2]}"`),process.exit(1));let o=await c.send({type:"evaluate",code:`(async () => {
836
- if (window.__sootsimRenderHost) {
837
- const session = window.${Q} || {}
838
- if (session.active) {
839
- const priorSamples = Array.isArray(session.lastSamples) ? session.lastSamples : []
840
- const flushedSamples = await window.__sootsimRenderHost.flushSamples()
841
- const samples = priorSamples.concat(flushedSamples)
842
- window.__sootsimRenderHost.startSampling()
843
- window.${Q} = {
844
- ...session,
845
- active: true,
846
- mode: 'render-worker',
847
- lastSamples: samples,
848
- lastFlushAt: performance.now(),
849
- }
850
- return {
851
- mode: 'render-worker',
852
- live: true,
853
- samples: samples.slice(-${e}),
854
- }
855
- }
856
- return {
857
- mode: 'render-worker',
858
- live: false,
859
- samples: (session.lastSamples || []).slice(-${e}),
860
- }
861
- }
862
- // main-thread mode
863
- const perf = window.__sootsimPerf
864
- if (!perf) return { error: 'no __sootsimPerf (try "perf start" first)' }
865
- const stats = perf.getFrameStats?.() || {}
866
- return {
867
- mode: 'main-thread',
868
- frames: (stats.recentFrames || []).slice(-${e}),
869
- }
870
- })()`});if(o.error&&(console.error(` error: ${o.error}`),process.exit(1)),o.mode==="render-worker"){let r=Array.isArray(o.samples)?o.samples:[];if(r.length===0){console.log(` no frame data \u2014 run '${b("perf")} start' first`);break}console.log(` last ${r.length} sampled frames (ms):`),console.log(" total layout render copy aux other t+");for(let[u,m,w,f,$,_,q]of r)console.log(` ${m.toFixed(2).padStart(7)} ${w.toFixed(2).padStart(7)} ${f.toFixed(2).padStart(7)} ${$.toFixed(2).padStart(7)} ${_.toFixed(2).padStart(6)} ${q.toFixed(2).padStart(7)} ${String(u).padStart(5)}`);console.log(""),Fe(r.map(u=>u[1])),o.live&&console.log(" sampling continues");break}let n=Array.isArray(o.frames)?o.frames:Array.isArray(o)?o:[];if(n.length===0){console.log(` no frame data \u2014 run '${b("perf")} start' first`);break}console.log(` last ${n.length} frame times (ms):`),console.log(` ${n.map(r=>r.toFixed(2)).join(", ")}`),Fe(n);break}case"worst":{let e=i[2]?Number(i[2]):20;(!Number.isFinite(e)||e<=0)&&(console.error(` error: expected a positive frame count, got "${i[2]}"`),process.exit(1));let o=await c.send({type:"evaluate",code:`(async () => {
871
- if (window.__sootsimRenderHost) {
872
- const session = window.${Q} || {}
873
- if (session.active) {
874
- const priorSamples = Array.isArray(session.lastSamples) ? session.lastSamples : []
875
- const flushedSamples = await window.__sootsimRenderHost.flushSamples()
876
- const samples = priorSamples.concat(flushedSamples)
877
- window.__sootsimRenderHost.startSampling()
878
- window.${Q} = {
879
- ...session,
880
- active: true,
881
- mode: 'render-worker',
882
- lastSamples: samples,
883
- lastFlushAt: performance.now(),
884
- }
885
- return {
886
- mode: 'render-worker',
887
- live: true,
888
- samples: samples
889
- .slice()
890
- .sort((a, b) => b[1] - a[1])
891
- .slice(0, ${e}),
892
- }
893
- }
894
- const samples = Array.isArray(session.lastSamples) ? session.lastSamples : []
895
- return {
896
- mode: 'render-worker',
897
- live: false,
898
- samples: samples
899
- .slice()
900
- .sort((a, b) => b[1] - a[1])
901
- .slice(0, ${e}),
902
- }
903
- }
904
- const perf = window.__sootsimPerf
905
- if (!perf) return { error: 'no __sootsimPerf (try "perf start" first)' }
906
- const stats = perf.getFrameStats?.() || {}
907
- const recent = Array.isArray(stats.recentFrames) ? stats.recentFrames : []
908
- return {
909
- mode: 'main-thread',
910
- frames: recent.slice().sort((a, b) => b - a).slice(0, ${e}),
911
- }
912
- })()`});if(o.error&&(console.error(` error: ${o.error}`),process.exit(1)),o.mode==="render-worker"){let r=Array.isArray(o.samples)?o.samples:[];if(r.length===0){console.log(` no frame data \u2014 run '${b("perf")} start' first`);break}console.log(` worst ${r.length} sampled frames (ms):`),console.log(" total layout render copy aux other t+");for(let[u,m,w,f,$,_,q]of r)console.log(` ${m.toFixed(2).padStart(7)} ${w.toFixed(2).padStart(7)} ${f.toFixed(2).padStart(7)} ${$.toFixed(2).padStart(7)} ${_.toFixed(2).padStart(6)} ${q.toFixed(2).padStart(7)} ${String(u).padStart(5)}`);o.live&&(console.log(""),console.log(" sampling continues"));break}let n=Array.isArray(o.frames)?o.frames:Array.isArray(o)?o:[];if(n.length===0){console.log(` no frame data \u2014 run '${b("perf")} start' first`);break}console.log(` worst ${n.length} frame times (ms):`),console.log(` ${n.map(r=>r.toFixed(2)).join(", ")}`);break}case"transition":{let e=i[2];if(!e||!["goHome","appSwitcher","lockScreen"].includes(e)){console.log(`
913
- ${b("perf")} transition <event> \u2014 profile a shell transition
914
-
915
- events:
916
- goHome swipe-to-home animation
917
- appSwitcher app switcher card animation
918
- lockScreen lock screen transition
919
-
920
- note: uses 600ms capture window \u2014 may need --timeout 10000 flag
921
-
922
- examples:
923
- ${b("perf")} transition goHome --timeout 10000
924
- ${b("perf")} transition appSwitcher
925
- `);break}let n=`sootsim:${e}`;console.log(` profiling ${e} transition...`),console.log(" (use --timeout 10000 if this times out)");let r=await c.send({type:"evaluate",code:`(async () => {
926
- // only supported in render-worker mode
927
- if (!window.__sootsimRenderHost) {
928
- return { error: 'transition profiling requires render-worker mode' }
929
- }
930
-
931
- // start sampling
932
- window.__sootsimRenderHost.startSampling()
933
-
934
- // give a frame for sampling to start
935
- await new Promise(r => requestAnimationFrame(() => r(undefined)))
936
-
937
- // dispatch the shell event
938
- window.dispatchEvent(new Event('${n}'))
939
-
940
- // wait 600ms for transition to complete (shell animations are ~300-500ms)
941
- // using fixed timing avoids complex animation-end detection
942
- await new Promise(r => setTimeout(r, 600))
943
-
944
- // flush samples and compute stats
945
- const samples = await window.__sootsimRenderHost.flushSamples()
946
- const frameTimes = samples.map(s => s[1])
947
- const layoutTimes = samples.map(s => s[2])
948
- const renderTimes = samples.map(s => s[3])
949
- const copyTimes = samples.map(s => s[4])
950
- const auxTimes = samples.map(s => s[5] || 0)
951
- const otherTimes = samples.map(s => s[6] || 0)
952
- const sorted = [...frameTimes].sort((a, b) => a - b)
953
- const total = frameTimes.reduce((a, b) => a + b, 0)
954
- const avg = frameTimes.length > 0 ? total / frameTimes.length : 0
955
- const max = Math.max(...frameTimes, 0)
956
- const layoutTotal = layoutTimes.reduce((a, b) => a + b, 0)
957
- const renderTotal = renderTimes.reduce((a, b) => a + b, 0)
958
- const copyTotal = copyTimes.reduce((a, b) => a + b, 0)
959
- const auxTotal = auxTimes.reduce((a, b) => a + b, 0)
960
- const otherTotal = otherTimes.reduce((a, b) => a + b, 0)
961
-
962
- return {
963
- event: '${e}',
964
- frames: frameTimes.length,
965
- totalMs: total,
966
- avgMs: avg,
967
- maxMs: max,
968
- layoutTotalMs: layoutTotal,
969
- renderTotalMs: renderTotal,
970
- copyTotalMs: copyTotal,
971
- auxTotalMs: auxTotal,
972
- otherTotalMs: otherTotal,
973
- layoutAvgMs: frameTimes.length > 0 ? layoutTotal / frameTimes.length : 0,
974
- renderAvgMs: frameTimes.length > 0 ? renderTotal / frameTimes.length : 0,
975
- copyAvgMs: frameTimes.length > 0 ? copyTotal / frameTimes.length : 0,
976
- auxAvgMs: frameTimes.length > 0 ? auxTotal / frameTimes.length : 0,
977
- otherAvgMs: frameTimes.length > 0 ? otherTotal / frameTimes.length : 0,
978
- p50: sorted[Math.floor(sorted.length * 0.5)] || 0,
979
- p95: sorted[Math.floor(sorted.length * 0.95)] || 0,
980
- p99: sorted[Math.floor(sorted.length * 0.99)] || 0,
981
- jankFrames: frameTimes.filter(f => f > 16.67).length,
982
- samples,
983
- }
984
- })()`});if(r.error&&(console.error(` error: ${r.error}`),process.exit(1)),r.warning&&console.log(` warning: ${r.warning}`),r.frames===0){console.log(" no frames captured");break}let u=r.avgMs>0?(1e3/r.avgMs).toFixed(1):"?",m=r.frames>0?(r.jankFrames/r.frames*100).toFixed(1):"0";console.log(` ${e} transition profiled:
985
-
986
- frames: ${r.frames}
987
- total: ${r.totalMs.toFixed(1)}ms
988
- avg: ${r.avgMs.toFixed(2)}ms (${u} fps)
989
- max: ${r.maxMs.toFixed(2)}ms
990
-
991
- breakdown (avg per frame):
992
- layout: ${r.layoutAvgMs?.toFixed(2)||"?"}ms
993
- render: ${r.renderAvgMs?.toFixed(2)||"?"}ms
994
- copy: ${r.copyAvgMs?.toFixed(2)||"?"}ms
995
- aux: ${r.auxAvgMs?.toFixed(2)||"?"}ms
996
- other: ${r.otherAvgMs?.toFixed(2)||"?"}ms
997
-
998
- distribution (${r.frames} samples):
999
- p50: ${r.p50.toFixed(2)}ms
1000
- p95: ${r.p95.toFixed(2)}ms
1001
- p99: ${r.p99.toFixed(2)}ms
1002
- jank: ${r.jankFrames} frames (${m}%) >16.67ms`),Array.isArray(r.samples)&&r.samples.length>0&&(console.log(""),Fe(r.samples.map(w=>w[1])));break}default:console.error(` unknown perf subcommand: ${t}`),process.exit(1)}break}case"errors":{let t=i[1];if(t==="clear"){await Ze(c),C(l)?B({cleared:!0}):console.log(" error buffer cleared");break}let e=t?Number(t):20,o=await Ve(c,e);if(C(l)){B(o);break}if(o.length===0){console.log(" no errors captured");break}console.log(` ${o.length} error(s):
1003
- `);for(let n of o){let r=new Date(n.timestamp).toLocaleTimeString(),u=n.args.map(m=>typeof m=="object"?JSON.stringify(m):m).join(" ");if(console.log(` [${r}] ${u}`),n.stack){let m=n.stack.split(`
1004
- `).slice(0,3);for(let w of m)console.log(` ${w.trim()}`)}}break}case"warnings":{let t=i[1]?Number(i[1]):20,e=await Qe(c,t);if(C(l)){B(e);break}if(e.length===0){console.log(" no warnings captured");break}console.log(` ${e.length} warning(s):
1005
- `);for(let o of e){let n=new Date(o.timestamp).toLocaleTimeString(),r=o.args.map(u=>typeof u=="object"?JSON.stringify(u):u).join(" ");console.log(` [${n}] ${r}`)}break}case"animations":{let t=await z(c,"listAnimations")??[];if(s.includes("--json")){console.log(JSON.stringify(t,null,2));break}if(t.length===0){console.log(" no active animations");break}console.log(` ${t.length} active animation(s):
1006
- `);for(let e of t){let o=String(e.kind).padEnd(6),n=`${Number(e.from).toFixed(2)}\u2192${Number(e.to).toFixed(2)}`,r=Number(e.current??0).toFixed(2),u=`${Math.round((e.progress??0)*100)}%`,m=`${Math.round(e.elapsedMs??0)}ms`,w=e.loop?" loop":"",f=e.layoutBound?" layout":"";console.log(` #${e.id} ${o} ${n.padEnd(14)} cur=${r.padEnd(7)} ${u.padStart(4)} ${m}${w}${f}`)}break}case"animation":{let t=i[1];(!t||t==="--help"||t==="-h")&&(console.error(` usage: ${b("animation")} <id>`),process.exit(1));let e=Number(t);Number.isFinite(e)||(console.error(` invalid id: ${t}`),process.exit(1));let o=await z(c,"getAnimation",e);console.log(JSON.stringify(o,null,2));break}case"stop-animation":{let t=i[1];(!t||t==="--help"||t==="-h")&&(console.error(` usage: ${b("stop-animation")} <id|all>`),process.exit(1));let e=t==="all"?"all":Number(t);e!=="all"&&!Number.isFinite(e)&&(console.error(` invalid id: ${t}`),process.exit(1));let o=await z(c,"stopAnimation",e);console.log(` stopped ${o??0} animation(s)`);break}case"requests":{let t=i[1];if(t==="clear"){await tt(c),C(l)?B({cleared:!0}):console.log(" request buffer cleared");break}let e=t==="all",o=e?i[2]:t,n=o?Number(o):20,r=await et(c,{failed:!e,limit:n});if(C(l)){B(r);break}if(r.length===0){console.log(e?" no requests captured":" no failed requests captured");break}console.log(` ${r.length} ${e?"request(s)":"failed request(s)"}:
1007
- `);for(let u of r){let m=new Date(u.timestamp).toLocaleTimeString();console.log(` [${m}] ${W(u)}`),u.responseBody?console.log(` ${u.responseBody}`):u.error&&console.log(` ${u.error}`)}break}case"network":{let t=i[1],e=null,o=null,n=!1,r=!1,u=1e3,m=!1,w=!1;for(let M=0;M<l.length;M++){let y=l[M];if(y==="--filter")e=l[M+1]??null,M++;else if(y==="--limit"){let p=Number(l[M+1]);Number.isFinite(p)&&(o=p),M++}else if(y==="--threshold"){let p=Number(l[M+1]);Number.isFinite(p)&&p>0&&(u=p),M++}else y==="--failed"?n=!0:y==="--slow"?r=!0:y==="--tail"||y==="-f"?m=!0:y==="--json"&&(w=!0)}if(t==="clear"){await c.send({type:"evaluate",code:'window.__sootsimObservability?.network.clear(); "cleared"'}),console.log(" network buffer cleared");break}if(t==="get"){let M=i[2];M||(console.error(" usage: sootsim network get <id>"),process.exit(1));let y=await c.send({type:"evaluate",code:`(() => {
1008
- const obs = window.__sootsimObservability;
1009
- if (!obs) return null;
1010
- return obs.network.getSnapshot().find(e => e.id === ${JSON.stringify(M)}) || null;
1011
- })()`});y||(console.error(` no entry with id ${M}`),process.exit(1)),w?console.log(JSON.stringify(y,null,2)):uo(y);break}let f=o??(m?200:t?Number(t):20);Number.isFinite(f)||(console.error(` invalid limit: ${t} \u2014 \`network\` takes a numeric count (e.g. ${b("network")} 100).
1012
- to target a specific sim, use \`--sim ${t}\` instead.`),process.exit(1));let $=async()=>{let M=await c.send({type:"evaluate",code:`(() => {
1013
- const obs = window.__sootsimObservability;
1014
- if (!obs) return { ok: false };
1015
- return { ok: true, entries: obs.network.getSnapshot() };
1016
- })()`});if(!M||!M.ok)throw new Error("observability bridge not installed \u2014 is the engine running?");return M.entries??[]},_=M=>{let y=M;if(n&&(y=y.filter(p=>!!p.error||p.status!=null&&p.status>=400)),r&&(y=y.filter(p=>p.durationMs!=null&&p.durationMs>=u)),e){let p=e.toLowerCase();y=y.filter(P=>(P.displayUrl||P.url).toLowerCase().includes(p))}return r&&!m&&(y=[...y].sort((p,P)=>(P.durationMs??0)-(p.durationMs??0))),y};if(!m){let M=await $(),y=_(M).slice(-f);if(w){console.log(JSON.stringify(y,null,2));break}if(y.length===0){M.length===0?console.log(" no network requests captured"):console.log(r?` no requests slower than ${u}ms (${M.length} total \u2014 try --threshold <ms>)`:" no matching requests");break}console.log(r?` ${y.length} request(s) slower than ${u}ms (sorted by duration desc):
1017
- `:` ${y.length} request(s):
1018
- `);for(let p of y)Pt(p);break}console.log(` tailing network (ctrl-c to stop)...
1019
- `);let q=new Set,H=!0,U=()=>{H=!1};process.on("SIGINT",U);try{for(;H;){let M=await $(),y=_(M);for(let p of y)p.durationMs!=null&&(q.has(p.id)||(q.add(p.id),w?console.log(JSON.stringify(p)):Pt(p)));await X(250)}}finally{process.off("SIGINT",U)}break}case"logs":{let t=i[1],e=null,o=null,n=null,r=!1,u=!1,m=!1;for(let y=0;y<l.length;y++){let p=l[y];if(p==="--filter")e=l[y+1]??null,y++;else if(p==="--limit"){let P=Number(l[y+1]);Number.isFinite(P)&&(o=P),y++}else p==="--level"?(n=l[y+1]??null,y++):p==="--tail"||p==="-f"?r=!0:p==="--json"?u=!0:(p==="--internal"||p==="--all")&&(m=!0)}let w=n?new Set(n.split(",").map(y=>y.trim()).filter(y=>y==="log"||y==="info"||y==="warn"||y==="error"||y==="debug")):null;if(t==="clear"){await st(c),console.log(" log buffer cleared");break}let f=!u&&process.stdout.isTTY===!0,$=o??(r?500:t?Number(t):50);Number.isFinite($)||(console.error(` invalid limit: ${t} \u2014 \`logs\` takes a numeric count (e.g. ${b("logs")} 100).
1020
- to target a specific sim, use \`--sim ${t}\` instead.`),process.exit(1));let _=()=>ot(c),q=y=>nt(y,{level:w,filter:e,showInternal:m});if(!r){let y=await _(),p=q(y).slice(-$);if(u){console.log(JSON.stringify(p,null,2));break}if(p.length===0){console.log(y.length===0?" no logs captured":" no matching logs");break}console.log(` ${p.length} log(s):
1021
- `);for(let P of p)Et(P,f);break}console.log(` tailing logs (ctrl-c to stop)...
1022
- `);let H=new Set,U=!0,M=()=>{U=!1};process.on("SIGINT",M);try{for(;U;){let y=await _(),p=q(y);for(let P of p)H.has(P.id)||(H.add(P.id),u?console.log(JSON.stringify(P)):Et(P,f));await X(250)}}finally{process.off("SIGINT",M)}break}default:console.error(` unknown subcommand: ${h}`),process.exit(1)}if(ee.has(h)&&!s.includes("--no-wait")&&process.env.SOOTSIM_NO_AUTO_WAIT!=="1"&&await x(c),!j.has(h)&&!C(l))try{await oe(c)}catch{}}catch(t){let e=t instanceof Error?t.message:String(t);console.error(` ${h??"inspect"} failed: ${e}`);let o=/^no sim connected with id (.+)$/.exec(e),n=/^command timed out after \d+s$/.test(e)||e.startsWith("sim disconnected:")||e.startsWith("bridge never reconnected")||e.startsWith("could not connect to ws://");if(o)await ut(c,N,o[1]);else if(/^no sim connected$/.test(e))dt(N);else if(n)process.stderr.write(` the sim is not responding. recover it with:
1023
- sootsim close --sim <id> # force-close the wedged sim
1024
- sootsim list # confirm it's gone
1025
- `);else{try{await Le(c)}catch{}try{await O({includeTail:!0})}catch{}try{await Z({includeTail:!0})}catch{}}process.exit(1)}finally{c.close()}}export{en as runInspect};