sootsim 0.1.39 → 0.1.40

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 (138) hide show
  1. package/dist-cli/bin.js +16 -15
  2. package/dist-cli/chunks/{agent-HZP3LUGJ.js → agent-3F5PO4NL.js} +2 -2
  3. package/dist-cli/chunks/{agent-wrapper-CS6TV5UR.js → agent-wrapper-LVUUZRWL.js} +2 -2
  4. package/dist-cli/chunks/{assert-WVTX4CNR.js → assert-4WMVS3WU.js} +2 -2
  5. package/dist-cli/chunks/auto-bootstrap-Q4A3PTF5.js +2 -0
  6. package/dist-cli/chunks/beta-CLLKUB5X.js +2 -0
  7. package/dist-cli/chunks/{chunk-MIE6NMPJ.js → chunk-4IAKB3C4.js} +6 -6
  8. package/dist-cli/chunks/{chunk-ZBB7YS6C.js → chunk-4L45Q3YX.js} +2 -2
  9. package/dist-cli/chunks/{chunk-UWRBEBML.js → chunk-553OZX4H.js} +2 -2
  10. package/dist-cli/chunks/{chunk-CBPTHIJV.js → chunk-5GK4YX7O.js} +1 -1
  11. package/dist-cli/chunks/{runtime-YJPWA3XA.js → chunk-5IAIIX7B.js} +3 -3
  12. package/dist-cli/chunks/{chunk-223TXYOC.js → chunk-6X5NQJT7.js} +3 -3
  13. package/dist-cli/chunks/{chunk-JXKW62SL.js → chunk-6XI4VHIL.js} +2 -2
  14. package/dist-cli/chunks/{chunk-B2SCT4DL.js → chunk-BZED27B2.js} +2 -2
  15. package/dist-cli/chunks/{chunk-5L5SZXXG.js → chunk-CAJ247SC.js} +2 -2
  16. package/dist-cli/chunks/{chunk-YUKH7HF6.js → chunk-CCZHRBXJ.js} +1 -1
  17. package/dist-cli/chunks/{chunk-DSDLGFWH.js → chunk-D2ZMP7G4.js} +2 -2
  18. package/dist-cli/chunks/{chunk-WHQWINDB.js → chunk-D4Z7MWQY.js} +2 -2
  19. package/dist-cli/chunks/{chunk-WD54RD4K.js → chunk-DEBXVPIE.js} +1 -1
  20. package/dist-cli/chunks/{chunk-SLQ2GTYF.js → chunk-DHJIXXWG.js} +2 -2
  21. package/dist-cli/chunks/chunk-DPZDTJVQ.js +1 -0
  22. package/dist-cli/chunks/{chunk-NYZGZDHI.js → chunk-DSTHAISO.js} +1 -1
  23. package/dist-cli/chunks/{chunk-C6GUAXKO.js → chunk-EOWN4ZFJ.js} +1 -1
  24. package/dist-cli/chunks/chunk-FFR7EA4U.js +1 -0
  25. package/dist-cli/chunks/chunk-FNIL6BYS.js +108 -0
  26. package/dist-cli/chunks/chunk-I7KXFJDK.js +1 -0
  27. package/dist-cli/chunks/{chunk-OB3TB4AN.js → chunk-J6BPROH4.js} +1 -1
  28. package/dist-cli/chunks/{chunk-NJ4WXWKO.js → chunk-KGVH3YAG.js} +2 -2
  29. package/dist-cli/chunks/{chunk-RJQ73DLG.js → chunk-KVOMVYG6.js} +4 -4
  30. package/dist-cli/chunks/{chunk-FEMOLCB5.js → chunk-LCES5ZJI.js} +2 -2
  31. package/dist-cli/chunks/{chunk-NF65BNJR.js → chunk-LXR5EI74.js} +2 -2
  32. package/dist-cli/chunks/{chunk-YHYSOUIJ.js → chunk-MLCBIX7O.js} +2 -2
  33. package/dist-cli/chunks/{chunk-2ESCYOZW.js → chunk-OV5TY7M3.js} +2 -2
  34. package/dist-cli/chunks/chunk-PKB6IEGM.js +2 -0
  35. package/dist-cli/chunks/chunk-PNGBWMQH.js +17 -0
  36. package/dist-cli/chunks/{chunk-P6F636LU.js → chunk-QMBYRPRK.js} +1 -1
  37. package/dist-cli/chunks/{chunk-4YUHJ5FX.js → chunk-QUULF2II.js} +2 -2
  38. package/dist-cli/chunks/chunk-S4PJMUC7.js +2 -0
  39. package/dist-cli/chunks/{chunk-MGVTLDI3.js → chunk-TK2IPNHL.js} +2 -2
  40. package/dist-cli/chunks/chunk-U3JD6X75.js +4 -0
  41. package/dist-cli/chunks/{chunk-VLUFTHBB.js → chunk-W2XRHDQQ.js} +2 -2
  42. package/dist-cli/chunks/{chunk-XYTDYBXJ.js → chunk-WPS3TIOB.js} +1 -1
  43. package/dist-cli/chunks/{chunk-GUHXSXNO.js → chunk-WQXG4I5N.js} +2 -2
  44. package/dist-cli/chunks/{chunk-YGUQSPU6.js → chunk-WZE6T3GT.js} +1 -1
  45. package/dist-cli/chunks/chunk-XWXFUFB2.js +1 -0
  46. package/dist-cli/chunks/{chunk-7J4UIBA5.js → chunk-Y5CFIRLN.js} +2 -2
  47. package/dist-cli/chunks/{chunk-RLGCJT2D.js → chunk-Y66CDFAT.js} +1 -1
  48. package/dist-cli/chunks/chunk-YJMXGTP4.js +2 -0
  49. package/dist-cli/chunks/{chunk-ECDPQ6S7.js → chunk-YKEBL6GE.js} +1 -1
  50. package/dist-cli/chunks/{chunk-E5RYQUFB.js → chunk-Z3I2I4IO.js} +3 -3
  51. package/dist-cli/chunks/{compat-UMJ2IXUW.js → compat-NBFWHK5S.js} +2 -2
  52. package/dist-cli/chunks/{config-YMJK426V.js → config-JEDQ3NHA.js} +2 -2
  53. package/dist-cli/chunks/control-IMWZVYC3.js +2 -0
  54. package/dist-cli/chunks/{cpu-profile-67MCPAA2.js → cpu-profile-MQPUSRHG.js} +2 -2
  55. package/dist-cli/chunks/{daemon-LIVCJZR3.js → daemon-HOL7J3BI.js} +2 -2
  56. package/dist-cli/chunks/{debug-EV73WC7H.js → debug-LNVMIWD6.js} +20 -20
  57. package/dist-cli/chunks/demo-app-registry-4RFMJ4FM.js +2 -0
  58. package/dist-cli/chunks/{detox-NBT5BVX3.js → detox-EEZPH3DZ.js} +2 -2
  59. package/dist-cli/chunks/{device-MMROWQZ3.js → device-GVLYQI7X.js} +2 -2
  60. package/dist-cli/chunks/{diagnose-WXOKGBAJ.js → diagnose-JQ7DPTSL.js} +2 -2
  61. package/dist-cli/chunks/drivers-JUW6JBWH.js +2 -0
  62. package/dist-cli/chunks/{electron-F5DT7CFY.js → electron-UDV6K3IH.js} +3 -3
  63. package/dist-cli/chunks/flow-JOW23WNH.js +2 -0
  64. package/dist-cli/chunks/{hints-RODH4XE4.js → hints-46PJLATZ.js} +2 -2
  65. package/dist-cli/chunks/{home-paths-PCUMN33Z.js → home-paths-XD7AOYU7.js} +2 -2
  66. package/dist-cli/chunks/inspect-EDIKZ6O2.js +993 -0
  67. package/dist-cli/chunks/install-CCC3IF5S.js +2 -0
  68. package/dist-cli/chunks/{install-desktop-ASRNFHZU.js → install-desktop-CX6ATQTR.js} +3 -3
  69. package/dist-cli/chunks/{keys-DOOCGNTD.js → keys-CXQIYEVW.js} +2 -2
  70. package/dist-cli/chunks/{launch-DTVAQMZG.js → launch-DCFRKVD3.js} +3 -3
  71. package/dist-cli/chunks/{login-JA6VEDEP.js → login-HCIZL5GT.js} +4 -4
  72. package/dist-cli/chunks/{logout-H4WFWTPC.js → logout-7X2YHJY3.js} +2 -2
  73. package/dist-cli/chunks/{maestro-4TR7U6TS.js → maestro-TY622MIW.js} +2 -2
  74. package/dist-cli/chunks/{preview-GP7XXDW6.js → preview-DYI6ESOK.js} +2 -2
  75. package/dist-cli/chunks/{profile-3FESGAZD.js → profile-7SXJEJTG.js} +2 -2
  76. package/dist-cli/chunks/{react-SJD2DQQV.js → react-VGSDY766.js} +2 -2
  77. package/dist-cli/chunks/{record-PQUAMW5K.js → record-7JX2SMVP.js} +2 -2
  78. package/dist-cli/chunks/runtime-FTOQD7QK.js +2 -0
  79. package/dist-cli/chunks/runtime-delivery-PWLODFCY.js +2 -0
  80. package/dist-cli/chunks/{screenshot-45SAK7EW.js → screenshot-PTKY4UU4.js} +2 -2
  81. package/dist-cli/chunks/{screenshot-mode-TCY7FBGR.js → screenshot-mode-HSV7VY4G.js} +2 -2
  82. package/dist-cli/chunks/{screenshots-KZ364S2O.js → screenshots-VY7VAGSV.js} +2 -2
  83. package/dist-cli/chunks/server-EDB3EK4K.js +35 -0
  84. package/dist-cli/chunks/setup-repo-S2GFZR7F.js +2 -0
  85. package/dist-cli/chunks/{skills-SMXCCJCM.js → skills-KEPQLCMR.js} +2 -2
  86. package/dist-cli/chunks/start-5CJTBNRM.js +23 -0
  87. package/dist-cli/chunks/store-SCRULNVS.js +2 -0
  88. package/dist-cli/chunks/telemetry-RC3OT67I.js +2 -0
  89. package/dist-cli/chunks/{test-ZXTSA5GV.js → test-REKHGKFE.js} +3 -3
  90. package/dist-cli/chunks/{three-mode-4Q65J2ZA.js → three-mode-FZYHB4ZQ.js} +2 -2
  91. package/dist-cli/chunks/{timeline-ISEDS6XR.js → timeline-CWZAY52K.js} +2 -2
  92. package/dist-cli/chunks/upgrade-AIUJEF5F.js +4 -0
  93. package/dist-cli/chunks/upload-UDA5ITTE.js +2 -0
  94. package/dist-cli/chunks/what-happened-JSQQVQGE.js +15 -0
  95. package/dist-cli/chunks/{whoami-VKRQOG2U.js → whoami-5WUUPIRN.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 +1 -1
  106. package/dist-lib/home-paths.cjs +1 -1
  107. package/dist-lib/host/bridge-host.cjs +115 -82
  108. package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
  109. package/dist-lib/index.cjs +1 -1
  110. package/dist-lib/metro.cjs +1 -1
  111. package/dist-lib/profiles.cjs +1 -1
  112. package/dist-lib/render-mode.cjs +1 -1
  113. package/dist-lib/vite-base.cjs +140 -88
  114. package/dist-lib/vite.cjs +1 -1
  115. package/package.json +1 -1
  116. package/dist-cli/chunks/auto-bootstrap-3TUCG2BC.js +0 -2
  117. package/dist-cli/chunks/beta-3SCMB3IN.js +0 -2
  118. package/dist-cli/chunks/chunk-4LHQRDSN.js +0 -2
  119. package/dist-cli/chunks/chunk-4UI5OHEO.js +0 -1
  120. package/dist-cli/chunks/chunk-5RSSCKBF.js +0 -1
  121. package/dist-cli/chunks/chunk-6TSUQHSC.js +0 -4
  122. package/dist-cli/chunks/chunk-B3OEHV2C.js +0 -1
  123. package/dist-cli/chunks/chunk-HWRR23AJ.js +0 -17
  124. package/dist-cli/chunks/chunk-NFJDHJHK.js +0 -1
  125. package/dist-cli/chunks/chunk-W4QHQT64.js +0 -2
  126. package/dist-cli/chunks/control-DJR3DUAB.js +0 -2
  127. package/dist-cli/chunks/demo-app-registry-NZBZVJ52.js +0 -2
  128. package/dist-cli/chunks/drivers-NSPV5S6T.js +0 -2
  129. package/dist-cli/chunks/flow-T6DZQWHE.js +0 -2
  130. package/dist-cli/chunks/inspect-BIMFJFDR.js +0 -1101
  131. package/dist-cli/chunks/install-5YPVP466.js +0 -2
  132. package/dist-cli/chunks/server-S5CRYXXZ.js +0 -35
  133. package/dist-cli/chunks/setup-repo-TH3GXOP7.js +0 -2
  134. package/dist-cli/chunks/start-KLSAQM3C.js +0 -23
  135. package/dist-cli/chunks/store-E2N5NOUS.js +0 -2
  136. package/dist-cli/chunks/telemetry-RJXVYJSN.js +0 -2
  137. package/dist-cli/chunks/upload-KB7INQRC.js +0 -2
  138. package/dist-cli/chunks/what-happened-STY3AOCQ.js +0 -15
@@ -0,0 +1,993 @@
1
+ /*! sootsim v0.1.40 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
+ import{a as G}from"./chunk-MLCBIX7O.js";import{a as Ce,b as De}from"./chunk-WPS3TIOB.js";import{a as X,b as C,c as D,d as z,e as ce,f as ne,g as ot,h as st,i as xe}from"./chunk-KVOMVYG6.js";import{D as tt,a as Be,b as je,c as Le,d as Je,e as qe,f as be,g as we,h as We,i as He,j as Ke,k as Ue,l as ze,m as Ye,n as Ge,o as Xe,p as Ve,q as Qe,u as Ze,w as se,x as et}from"./chunk-FNIL6BYS.js";import{a as Re,e as le}from"./chunk-KGVH3YAG.js";import{b as nt,h as rt}from"./chunk-D4Z7MWQY.js";import"./chunk-CCZHRBXJ.js";import{a as Ee}from"./chunk-QMBYRPRK.js";import"./chunk-CAJ247SC.js";import"./chunk-WZE6T3GT.js";import"./chunk-TK2IPNHL.js";import"./chunk-I7KXFJDK.js";import"./chunk-EOWN4ZFJ.js";import{a as ge,c as ye,d as Ie}from"./chunk-4IAKB3C4.js";import{a as Ne}from"./chunk-S4PJMUC7.js";import{c as Fe,e as Ae,f as Pe,g as Oe,h as he}from"./chunk-PNGBWMQH.js";import{b as _e}from"./chunk-Y66CDFAT.js";import"./chunk-XWXFUFB2.js";import"./chunk-YKEBL6GE.js";import"./chunk-DEBXVPIE.js";import{existsSync as jt,mkdirSync as Lt,readFileSync as Jt,rmSync as it,writeFileSync as qt}from"fs";import{tmpdir as Wt}from"os";import{dirname as Ht,join as Kt,resolve as Ut}from"path";var re=1,zt="SOOTSIM_INSPECT_NOTICE_PATH",Yt=300*1e3,Gt=15e3;function at(){return Ut(process.env[zt]||Kt(Wt(),"sootsim-inspect-notice-state.json"))}function Xt(o,d){return Object.fromEntries(Object.entries(o).filter(([,a])=>typeof a?.signature=="string"&&Number.isFinite(a?.updatedAt)&&d-a.updatedAt<=Yt))}function Vt(o){let d=at();if(!jt(d))return{version:re,entries:{}};try{let a=JSON.parse(Jt(d,"utf8"));return a.version!==re||!a.entries||typeof a.entries!="object"?(it(d,{force:!0}),{version:re,entries:{}}):{version:re,entries:Xt(a.entries,o)}}catch{return it(d,{force:!0}),{version:re,entries:{}}}}function Qt(o){let d=at();Lt(Ht(d),{recursive:!0}),qt(d,JSON.stringify(o,null,2)+`
3
+ `)}function Zt(o,d){let a=d.trim()||"default";return`${o}:${a}`}function $e(o,d,a,l={}){let f=l.nowMs??Date.now(),i=l.cooldownMs??Gt,h=Vt(f),S=Zt(o,d),I=h.entries[S];return I&&I.signature===a&&f-I.updatedAt<i?!1:(h.entries[S]={signature:a,updatedAt:f},Qt(h),!0)}async function lt(o,d={args:[]}){let a=await Be(o);if(C(d.args)){D(a);return}console.log(` nodes: ${a.nodes}`)}function Se(o,d){let a=o.indexOf(d);return a>=0&&a+1<o.length?o[a+1]:null}async function ct(o){let{bridge:d,args:a,positional:l}=o,f=a.includes("--verbose")||a.includes("-v"),i=C(a),h=f&&!i,S=a.includes("--watch")||a.includes("-w"),I=1e3,T=a.includes("--compact"),x=a.includes("--no-xy"),v=Se(a,"--testid-like"),_=Se(a,"--only"),M=Se(a,"--subtree"),R=l[1],c=R?/[*?]/.test(R):!1,J=!c&&!_?R:void 0,U=_??(c?R:void 0),E=async()=>{await ce(d,{verbose:h});let Y=await Je(d,{describe:!0,verbose:f,filter:J||"",testIdLike:v||void 0,onlyGlob:U||void 0,subtreeRoot:M||void 0,compact:T,hideXy:x}),W=Y?.tree,w=Y?.shell,N=Y?.keyboard;if(i){D({shell:w,tree:W??"",keyboard:N});return}if(w&&typeof w=="object"){let F=[w.state?`state=${w.state}`:null,w.activeApp?`app=${w.activeApp}`:null,w.showSwitcher?"switcher":null,w.switcherPhase&&w.switcherPhase!=="idle"?`phase=${w.switcherPhase}`:null].filter(Boolean);F.length>0&&console.log(` shell: ${F.join(" ")}`)}if(typeof W=="string"&&W.startsWith("__SUBTREE_NOT_FOUND__:")){let F=W.slice(22);console.log(` subtree root not found: ${F}`),G("subtree-root-not-found",F);return}if(!W){let F=Y?.nodeCount??0;console.log(" no matching nodes found"),!(J||v||U||M)&&F<10&&G("app-still-loading",F);return}if(console.log(W),!(J||v||U||M)&&!S&&W.split(`
4
+ `).length>=80&&G("describe-use-filters"),N&&N.visible){let F=N.spec,V=[F?.keyboardType?`type=${F.keyboardType}`:null,F?.returnKeyType&&F.returnKeyType!=="default"?`return=${F.returnKeyType}`:null,N.mode!=="letters"?`mode=${N.mode}`:null,N.shifted?"shift":null,N.capsLock?"caps":null,F?.autoCapitalize&&F.autoCapitalize!=="sentences"?`autoCap=${F.autoCapitalize}`:null,N.accessoryBarId?`accessory=${N.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 E(),await X(I);else await E()}var eo=["SOOTSIM_AGENT","CLAUDECODE","CLAUDE_CODE_ENTRYPOINT","CLAUDE_CODE_SESSION_ID","CODEX_THREAD_ID","CURSOR_TRACE_ID","AIDER_MODEL"];function dt(){if(process.env.SOOTSIM_AGENT==="0")return!1;for(let o of eo){let d=process.env[o];if(d&&d.trim()&&d!=="0")return!0}return!1}async function ut(o){let{bridge:d,args:a,effectiveArgs:l,positional:f,inspectUsage:i}=o,h=w=>{let N=l.indexOf(w);return N>=0&&N+1<l.length?l[N+1]:null},S=w=>l.includes(w),I=h("--testid")||h("--test-id"),T=h("--role"),x=h("--type"),v=h("--text"),_=S("--pressable"),M=S("--visible"),R=S("--interactive-targets")||S("--actions"),c=!I&&!T&&!x&&!v&&!_&&!M&&!R?f[1]:null,J=v??c,U=await qe(d,{testId:I,role:T,type:x,text:J,pressable:_,visible:M,interactive:R});U||(console.error(i("find","<text> | --text <t> | --testid <id> | --role <r> | --type <t> | --pressable | --visible | --interactive-targets")),process.exit(1));let{mode:E,result:L}=U,Y=C(a),W=a.includes("--verbose")||a.includes("--dump");if(Y)E==="interactive-targets"&&Array.isArray(L)?D(be(L).map(w=>({...w,tap:we(w)}))):D(L??null);else if(Array.isArray(L))if(L.length===0){console.log(` no ${E} nodes found`);let w=await d.send({type:"evaluate",code:"(async () => (await window.__sootsimTest?.getNodeCount?.()) || 0)()"});typeof w=="number"&&w<10&&G("app-still-loading",w)}else if(E==="interactive-targets"){let w=be(L);console.log(` found ${w.length} interactive target${w.length===1?"":"s"} (sorted by score):`);for(let N of w.slice(0,20)){let Z=N.absolutePosition?`@(${Math.round(N.absolutePosition.x)},${Math.round(N.absolutePosition.y)})`:"",F=N.layout?`${Math.round(N.layout.width)}x${Math.round(N.layout.height)}`:"?x?",V=N.text?` "${N.text.slice(0,30)}"`:"",te=N.testID?` #${N.testID}`:"",e=N.accessibilityLabel?` \u24D8"${String(N.accessibilityLabel).slice(0,24)}"`:"",t=N.accessibilityRole?`[${N.accessibilityRole}]`:N.type,s=we(N);console.log(` ${t}${V}${e}${te} ${F} ${Z}`),console.log(` \u2192 ${s}`),W&&console.log(ve(JSON.stringify(N,null,2)," "))}w.length>20&&console.log(` ... and ${w.length-20} more`)}else{console.log(` found ${L.length} node${L.length===1?"":"s"} (${E}):`);for(let w of L.slice(0,20)){let N=w.absolutePosition?`@(${Math.round(w.absolutePosition.x)},${Math.round(w.absolutePosition.y)})`:"",Z=w.layout?`${Math.round(w.layout.width)}x${Math.round(w.layout.height)}`:"?x?",F=w.text?` "${w.text.slice(0,30)}"`:"",V=w.testID?` #${w.testID}`:"",te=w.pressable?" (tap)":"",e=w.accessibilityRole?`[${w.accessibilityRole}]`:w.type;console.log(` ${e}${F}${V} ${Z} ${N}${te}`),W&&console.log(ve(JSON.stringify(w,null,2)," "))}L.length>20&&console.log(` ... and ${L.length-20} more`)}else if(L==null)console.log(` not found: ${J||I||T||x||""||E}`),I&&G("wait-selector-for-missing-testid",I);else{let w=L;if(w.type&&w.absolutePosition){let N=`@(${Math.round(w.absolutePosition.x)},${Math.round(w.absolutePosition.y)})`,Z=w.layout?`${Math.round(w.layout.width)}x${Math.round(w.layout.height)}`:"?x?",F=w.text?` "${w.text.slice(0,40)}"`:"",V=w.testID?` #${w.testID}`:"",te=w.pressable?" (tap)":"",e=w.accessibilityRole?`[${w.accessibilityRole}]`:w.type;console.log(` ${e}${F}${V} ${Z} ${N}${te}`),W&&console.log(ve(JSON.stringify(w,null,2)," "))}else console.log(JSON.stringify(L,null,2))}}function ve(o,d){return o.split(`
7
+ `).map(a=>d+a).join(`
8
+ `)}async function mt(o,d={}){let a=await Ze(o);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:f,mode:i,shifted:h,capsLock:S,accessoryBarId:I}=a,T=[];T.push(`keyboard: ${l?"visible":"hidden"}`),f?(T.push(` type: ${f.keyboardType}`),T.push(` returnKey: ${f.returnKeyType}`),T.push(` autoCap: ${f.autoCapitalize}`),T.push(` autoCorrect: ${f.autoCorrect?"on":"off"}`),T.push(` appearance: ${f.keyboardAppearance}`),f.secureTextEntry&&T.push(" secureTextEntry: true"),f.enablesReturnKeyAutomatically&&T.push(` return: ${f.currentTextIsEmpty?"disabled (empty)":"enabled"}`)):T.push(" spec: <none> (shown via dev-tools with no TextInput)"),T.push(` mode: ${i}${h?" (shifted)":""}${S?" (caps)":""}`),I&&T.push(` accessoryBar: ${I}`),console.log(T.join(`
9
+ `))}async function pt(o){let d=await o.bridge.listSims();if(C(o.args)){D(d.map(a=>({...a,active:a.id===o.simId})));return}rt(d,o.simId)}function ee(o){return o<1024?`${o}B`:o<1024*1024?`${(o/1024).toFixed(1)}KB`:`${(o/1024/1024).toFixed(1)}MB`}function de(o,d){return d<=0?"?":`${(o/d*100).toFixed(0)}%`}async function ft(o,d={args:[]}){let a=await tt(o);if(C(d.args)){D(a);return}if(console.log(" memory:"),a.imageLoader){let l=a.imageLoader;console.log(" image-loader cache"),console.log(` entries: ${l.cacheEntries} / ${l.cacheMaxEntries} (${de(l.cacheEntries,l.cacheMaxEntries)})`),console.log(` pixel bytes: ${ee(l.cachePixelBytes)} / ${ee(l.cachePixelBudget)} (${de(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: ${ee(l.usedJSHeapSize)} / ${ee(l.jsHeapSizeLimit)} (${de(l.usedJSHeapSize,l.jsHeapSizeLimit)})`),console.log(` total: ${ee(l.totalJSHeapSize)}`)}if(a.hostHeap){let l=a.hostHeap;console.log(" host heap (chrome only)"),console.log(` used: ${ee(l.usedJSHeapSize)} / ${ee(l.jsHeapSizeLimit)} (${de(l.usedJSHeapSize,l.jsHeapSizeLimit)})`),console.log(` total: ${ee(l.totalJSHeapSize)}`)}}function ie(o){let d=o.indexOf("--testid");if(d>=0&&o[d+1])return{mode:"testid",value:o[d+1]};let a=o.indexOf("--test-id");if(a>=0&&o[a+1])return{mode:"testid",value:o[a+1]};let l=o.indexOf("--text");return l>=0&&o[l+1]?{mode:"text",value:o[l+1]}:null}async function ue(o,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 o.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 { x: cx, y: cy, testID: n.testID, text: n.text }
27
+ })()`})??null}async function gt(o,d={}){let{nav:a,keyboard:l,shell:f}=await et(o);if(d.json){console.log(JSON.stringify({shell:f??null,nav:a,keyboard:l},null,2));return}let i=[];if(f){let h=f.activeApp??f.state??"<none>",S=f.showSwitcher?" (app switcher open)":"",I=typeof f.launchProgress=="number"&&f.launchProgress<.98?` launching (${Math.round(f.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":" ",T=S.routeName?` ${S.routeName}`:"",x=S.headerHeight>0?` header=${S.headerHeight}`:"",v=S.largeTitleState&&S.largeTitleState!=="expanded"?` large-title=${S.largeTitleState}`:"";i.push(` ${I} #${S.id}${T}${x}${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(`
28
+ `))}async function oe({bridge:o,maxMs:d,pollMs:a=50,stablePolls:l=3,strict:f=!1}){let i=await o.send({type:"evaluate",code:`(async () => {
29
+ const start = Date.now()
30
+ const deadline = start + ${Math.max(0,Math.round(d))}
31
+ const pollMs = ${Math.max(1,Math.round(a))}
32
+ const requiredStablePolls = ${Math.max(1,Math.round(l))}
33
+ const strict = ${f?"true":"false"}
34
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
35
+ const readSnapshot = async () => {
36
+ let animating = false
37
+ try {
38
+ const stats = await window.__sootsimRenderHost?.queryStats?.()
39
+ if (stats) {
40
+ animating =
41
+ stats.hasActiveAnims === true ||
42
+ stats.hasActiveNativeAnimations === true ||
43
+ stats.hasPendingAnimationFrames === true
44
+ }
45
+ } catch {}
46
+ const root = window.__sootsimRoot
47
+ const nodes = []
48
+ if (root) {
49
+ const walk = (n) => {
50
+ if (n.layout && n.layout.width > 0) {
51
+ nodes.push(Math.round(n.layout.x) + ',' + Math.round(n.layout.y) + ',' + Math.round(n.layout.width))
52
+ }
53
+ for (const c of n.children || []) walk(c)
54
+ }
55
+ walk(root)
56
+ }
57
+ return { layout: nodes.join(';'), animating }
58
+ }
59
+
60
+ let lastLayout = ''
61
+ let stable = 0
62
+ while (Date.now() < deadline) {
63
+ const snapshot = await readSnapshot()
64
+ const strictOk = !strict || !snapshot.animating
65
+ if (strictOk && snapshot.layout === lastLayout) {
66
+ stable++
67
+ if (stable >= requiredStablePolls) {
68
+ return { settled: true, elapsed: Date.now() - start }
69
+ }
70
+ } else {
71
+ stable = 0
72
+ }
73
+ lastLayout = snapshot.layout
74
+ await sleep(pollMs)
75
+ }
76
+ return { settled: false, elapsed: Date.now() - start }
77
+ })()`}),{elapsed:h,settled:S}=i??{};return{elapsed:typeof h=="number"?h:d,settled:S===!0}}async function yt(o){let{bridge:d,args:a,positional:l}=o,f=l[1]?Number(l[1])*1e3:3e3,i=a.includes("--strict"),{elapsed:h,settled:S}=await oe({bridge:d,maxMs:f,strict:i});console.log(S?` settled in ${h}ms`:` timed out after ${h}ms (may still be animating)`)}async function ht(o){let d=o.positional[1]?Number(o.positional[1]):.5;(!Number.isFinite(d)||d<0)&&(console.error(o.inspectUsage("sleep","[seconds]")),process.exit(1)),await X(d*1e3),console.log(` slept ${d}s`)}async function bt(o){let{bridge:d,args:a,positional:l}=o,f=l[1]?Number(l[1]):5,{tree:i}=await je(d,f);if(C(a)){D({depth:f,tree:i??null});return}console.log(typeof i=="string"?i:JSON.stringify(i,null,2))}async function wt(o,d={args:[]}){let a=await Le(o);if(C(d.args)){D(a);return}console.log(a.url)}async function xt(o){let{wsPort:d,commandTimeoutMs:a,simId:l,positional:f}=o,i=f[1]?Number(f[1]):30,h=Math.max(1e3,(Number.isFinite(i)?i:30)*1e3),S=Math.max(1,Math.ceil(h/500));console.log(" waiting for sim reconnect...");let I=await ot(d,a,l,{attempts:S});I||(console.error(" timed out waiting for sim reconnect"),process.exit(1)),I.bridge.close(),le({source:"inspect wait",step:{wait:h},summary:`wait ${Math.round(h/1e3)}s`}),console.log(` ready: ${I.count} nodes`)}var $t=new Set(["app-launch","toast","keyboard","screen","route","alert","actionsheet","picker","notification","fetch","console","shell","scroll","gesture","text-input","react-commit","animation","reanimated"]);function me(o,d){let a=o.indexOf(d);if(a>=0&&a+1<o.length)return o[a+1]}function to(o,d){if(!d.filter&&!d.equals)return!0;let a=o.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 f=l.join(" ");return d.equals?l.some(i=>i===d.equals):d.filter?f.toLowerCase().includes(d.filter.toLowerCase()):!0}async function St(o){let{bridge:d,args:a,positional:l,inspectUsage:f}=o,i=l[1];i||(console.error(f("wait event","<kind> [--max-ms 5000] [--filter <substring>] [--equals <exact>] [--since now|cursor]")),process.exit(1)),$t.has(i)||console.error(` warning: '${i}' is not a known timeline kind \u2014 waiting anyway. known: ${[...$t].sort().join(", ")}`);let h=me(a,"--max-ms"),S=h&&Number.isFinite(Number(h))?Math.max(100,Number(h)):5e3,I=me(a,"--filter"),T=me(a,"--equals"),x=me(a,"--since")??"now",v=a.includes("--json"),_=Date.now(),M=_+S,R=200,c=_;for(;Date.now()<M;){let U={kinds:[i],since:x==="cursor"?void 0:c,limit:50},E=await d.send({type:"evaluate",code:`(async () => {
78
+ const t = window.SootSim?.bridges?.timeline
79
+ if (!t) return { ok: false, error: 'timeline bridge missing' }
80
+ return { ok: true, result: await t.recent(${JSON.stringify(U)}) }
81
+ })()`});(!E||!E.ok)&&(console.error(` could not query timeline: ${E&&"error"in E?E.error:"unknown"}`),process.exit(1));let L=E.result.events??[];for(let Y of L)if(to(Y,{filter:I,equals:T})){let W=Date.now()-_;console.log(v?JSON.stringify({found:!0,elapsedMs:W,event:Y}):` ${i} event after ${W}ms${I?` (filter: ${I})`:""}${T?` (equals: ${T})`:""}`);return}E.result.watermark&&E.result.watermark>c&&(c=E.result.watermark),await new Promise(Y=>setTimeout(Y,R))}let J=Date.now()-_;v?console.log(JSON.stringify({found:!1,elapsedMs:J,kind:i,filter:I,equals:T})):console.error(` \u26A0 wait event ${i} timed out after ${J}ms${I?` (filter: ${I})`:""}${T?` (equals: ${T})`:""}`),process.exit(1)}async function vt(o){let{bridge:d,args:a}=o,l=a.includes("--strict"),f=a.indexOf("--max-ms"),i=f>=0&&a[f+1]?Math.max(100,Number(a[f+1])):3e3,{elapsed:h,settled:S}=await oe({bridge:d,maxMs:i,strict:l});S?console.log(` idle in ${h}ms`):(console.error(` \u26A0 wait idle timed out after ${h}ms (may still be animating)`),process.exit(1))}async function kt(o){let{bridge:d,args:a}=o,l=2e4,f=a.indexOf("--max-ms");f>=0&&a[f+1]&&(l=Math.max(100,Number(a[f+1])));let{ready:i,elapsedMs:h,nodes:S}=await We(d,l);if(i){console.log(` ready in ${h}ms: ${S} nodes (flag)`);return}console.error(` \u26A0 wait ready timed out after ${h}ms \u2014 guest app did not emit sootsim:externalAppReady (nodes: ${S})`),process.exit(1)}async function Tt(o){let{bridge:d,args:a,positional:l,inspectUsage:f}=o,i=l[1];i||(console.error(f("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:T,elapsed:x}=await He(d,i,S);if(I&&T){let v=T.absolutePosition?`@(${Math.round(T.absolutePosition.x)},${Math.round(T.absolutePosition.y)})`:"",_=T.layout?`${Math.round(T.layout.width)}x${Math.round(T.layout.height)}`:"?x?";console.log(` found #${i} in ${x}ms ${_} ${v}`)}else console.error(` \u26A0 wait selector #${i} timed out after ${x??S}ms`),process.exit(1)}function At(o){return o==null?"\u2014":o<1024?`${o}B`:o<1024*1024?`${(o/1024).toFixed(1)}K`:`${(o/1024/1024).toFixed(1)}M`}function Pt(o){return o==null?" \u2026":o<1e3?`${o}ms`.padStart(5):`${(o/1e3).toFixed(2)}s`.padStart(5)}function so(o){return o.error?"err":o.status==null?" \u2026 ":String(o.status)}function Mt(o){let d=new Date(o.startTs).toLocaleTimeString(),a=so(o).padEnd(3),l=o.method.padEnd(5),f=At(o.size).padStart(6),i=Pt(o.durationMs);console.log(` [${d}] ${a} ${l} ${f} ${i} ${o.displayUrl}`),o.error&&console.log(` error: ${o.error}`)}function no(o){let d=[["id",o.id],["source",o.source],["kind",o.kind],["method",o.method],["status",o.error?`error: ${o.error}`:`${o.status??"\u2014"} ${o.statusText??""}`.trim()],["url",o.url],["started",new Date(o.startTs).toLocaleTimeString()],["duration",Pt(o.durationMs).trim()],["size",At(o.size)],["content-type",o.type??"\u2014"]];for(let[a,l]of d)console.log(` ${a.padEnd(13)} ${l}`)}var ro={error:"\x1B[31m",warn:"\x1B[33m",info:"\x1B[36m",debug:"\x1B[35m",log:"\x1B[37m"},Nt="\x1B[0m",io="\x1B[2m";function It(o,d){let a=new Date(o.ts).toLocaleTimeString(),l=o.level.toUpperCase().padEnd(5),f=o.args.join(" ");if(d){let i=ro[o.level];console.log(` ${io}[${a}]${Nt} ${i}${l}${Nt} ${f}`)}else console.log(` [${a}] ${l} ${f}`);if(o.stack&&o.level==="error"){let i=o.stack.split(`
82
+ `).slice(0,5);for(let h of i)console.log(` ${h.trim()}`)}}var Q="__sootsimCliPerf",ao=120;async function _t(o,d){let a=o.find((_,M)=>o[M-1]==="--id"),l=o.find((_,M)=>o[M-1]==="--text");if(a||l){let _=await d.send({type:"evaluate",code:Ce({id:a,text:l})});if(!_)throw new Error(a?`no node with id "${a}"`:`no node matching text "${l}"`);let{x:M,y:R,w:c,h:J}=_;return{x:M,y:R,w:c,h:J}}let f=o.find((_,M)=>o[M-1]==="--area");if(f){let _=f.split(",").map(U=>Number(U.trim()));if(_.length!==4||_.some(U=>!Number.isFinite(U)))throw new Error(`--area expects x,y,w,h (got "${f}")`);let[M,R,c,J]=_;return{x:M,y:R,w:c,h:J}}let i=_=>{let M=o.find((c,J)=>o[J-1]===_);if(M==null)return null;let R=Number(M);return Number.isFinite(R)?R:null},h=i("--x"),S=i("--y"),I=i("--w"),T=i("--h");if(h!=null||S!=null||I!=null||T!=null)return{x:h??0,y:S??0,w:I??1,h:T??1};let v=o.filter((_,M)=>M>0&&!_.startsWith("-")&&o[M-1]!=="--output"&&o[M-1]!=="--area"&&o[M-1]!=="--id"&&o[M-1]!=="--text"&&o[M-1]!=="--x"&&o[M-1]!=="--y"&&o[M-1]!=="--w"&&o[M-1]!=="--h").map(Number).filter(_=>Number.isFinite(_));if(v.length>=2){let[_,M,R=1,c=1]=v;return{x:_,y:M,w:R,h:c}}return null}function ke(o){let d={"<8":0,"8-12":0,"12-16":0,"16-20":0,"20-33":0,">33":0};for(let a of o)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 f="\u2588".repeat(Math.ceil(l/o.length*40));console.log(` ${a.padEnd(6)} ${f} ${l}`)}}async function pe(o,d,a){let l=Date.now()+d,f=await se(o,d);for(;;){if(a(f))return{settled:!0,state:f};if(Date.now()>=l)return{settled:!1,state:f};await X(16),f=await se(o)}}async function Me(o){return o.send({type:"evaluate",code:`(async () => {
83
+ const kb = window.__sootsimKeyboard
84
+ const test = window.__sootsimTest
85
+ if (!kb) return { error: 'keyboard bridge not available' }
86
+ const visible = kb.isVisible()
87
+ const mode = kb.getMode()
88
+ let focused = null
89
+ if (test && typeof test.getFocusedNode === 'function') {
90
+ try {
91
+ focused = await test.getFocusedNode()
92
+ } catch {}
93
+ }
94
+ let runtimeSnapshot = null
95
+ if (test && typeof test.getFocusKeyboardSnapshot === 'function') {
96
+ try {
97
+ runtimeSnapshot = await test.getFocusKeyboardSnapshot()
98
+ } catch {}
99
+ }
100
+ return {
101
+ visible,
102
+ mode,
103
+ focusedInput: focused ? {
104
+ nodeId: focused.nodeId ?? null,
105
+ testID: focused.testID || null,
106
+ id: focused.id || null,
107
+ placeholder: focused.placeholder || null,
108
+ text: focused.text || null,
109
+ } : null,
110
+ phase: runtimeSnapshot?.keyboard?.phase ?? null,
111
+ frame: runtimeSnapshot?.keyboard?.frame ?? null,
112
+ focusedRect: runtimeSnapshot?.focused?.rect ?? null,
113
+ }
114
+ })()`})}async function lo(o,d=600){let a=Date.now()+d;for(;Date.now()<=a;){let l=await Me(o);if(l.visible)return l;await X(30)}return Me(o)}async function fe(o,d){let a=await Me(o);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 Ft(o,d,a){return d==="appearance"?o.send({type:"evaluate",code:`(async () => {
115
+ const requested = ${JSON.stringify(a??"toggle")}
116
+ const rootBg = (document.documentElement?.style?.background || '').toLowerCase()
117
+ const inferredCurrent = rootBg.includes('33') ? 'dark' : 'light'
118
+ let next = requested
119
+ if (requested === 'toggle') {
120
+ next = inferredCurrent === 'dark' ? 'light' : 'dark'
121
+ }
122
+ // engine accepts 'auto' since the schema picker landed; pass through.
123
+ window.postMessage({ type: 'soot-action', action: 'set-appearance', value: next }, '*')
124
+ const applied = next === 'auto'
125
+ ? (window.matchMedia?.('(prefers-color-scheme: dark)')?.matches ? 'dark' : 'light')
126
+ : next
127
+ return { ok: true, requested, value: next, applied }
128
+ })()`}):o.send({type:"evaluate",code:`(async () => {
129
+ window.dispatchEvent(new CustomEvent(${JSON.stringify(d==="lock"?"sootsim:toggleLock":"sootsim:shake")}))
130
+ return { ok: true, action: ${JSON.stringify(d)} }
131
+ })()`})}function co(o){let d={Enter:"return",NumpadEnter:"return",Backspace:"delete",Delete:"delete",Space:"space",ShiftLeft:"shift",ShiftRight:"shift"};if(d[o])return d[o];let a=o.match(/^Digit([0-9])$/);if(a)return a[1];let l=o.match(/^Key([A-Z])$/);return l?l[1].toLowerCase():null}function uo(o){if(typeof o!="string")return null;let d=o.replace(/\s+/g," ").trim();return d?d.slice(0,80):null}function Ot(...o){for(let d of o){if(typeof d!="string")continue;let a=d.trim();if(a)return a}return null}async function j(o,d,a){le({source:o,step:d,summary:a})}function mo(o,d,a){if(!a||a.hit===!1)return null;let l=Ot(a.responderTestID,a.testID);if(l)return{step:{tapOn:{id:l}},summary:`tap #${l}`};let f=uo(a.text);return f?{step:{tapOn:f},summary:`tap "${f}"`}:{step:{tapAtCoords:{x:o,y:d}},summary:`tap @${Math.round(o)},${Math.round(d)}`}}function Te(o,d,a){let l=Ot(d?.testID,d?.id);return l?{step:{tapOn:{id:l}},summary:`tap #${l}`}:a==="id"?{step:{tapOn:{id:o}},summary:`tap #${o}`}:{step:{tapOn:o},summary:`tap "${o}"`}}async function Us(o,d){let a=o[0]==="get"||o[0]==="do"||o[0]==="debug"||o[0]==="wait"?o[0]:null,l=a?o.slice(1):o,f=Fe(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","--max-ms","--filter","--limit","--level","--threshold","--equals","--since"]}),i=f.positional,h=i[0],S=a==="get"||a==="do"||a==="debug"||a==="wait"?a:"inspect",I=typeof l[0]=="string"&&Ie.has(l[0]),T=I?l[0]:null,x=e=>I&&e===l[0]?`sootsim ${e}`:`sootsim ${S} ${e}`,v=(e,t)=>` usage: ${x(e)}${t?` ${t}`:""}`;if(!h||o.includes("--help")||o.includes("-h")){let e={bridgePort:7668,defaultShellUrl:Ne};if(S==="do"||S==="get"||S==="debug"||S==="wait"){let r=ge(S,e);r&&(console.log(`${r}
132
+ `),process.exit(0))}if(T==="shell"){let r=ye("shell",e);r&&(console.log(`${r}
133
+ `),process.exit(0))}let t=ye("inspect",e),s=["do","get","debug","wait"].map(r=>ge(r,e)).filter(r=>r!=null).join(`
134
+
135
+ `);console.log(`${t??""}
136
+
137
+ ${s}
138
+ `),process.exit(0)}let _=f.wsPort,M=f.simId,R=f.commandTimeoutMs;if(h==="list"&&l.some(e=>e==="--drivers"||e==="-D")){let{buildDriverListRows:e}=await import("./drivers-JUW6JBWH.js"),t=e();console.log(` available drivers (${t.length}):
139
+ `);let s=Math.max(...t.map(n=>n.id.length),6),r=Math.max(...t.map(n=>n.kind.length),4);for(let n of t){let u=n.available?"\u2713":"\u2717",m=n.id.padEnd(s),y=n.kind.padEnd(r);console.log(` ${u} ${m} ${y} ${n.description}`),n.available&&n.detail?console.log(` ${n.detail}`):!n.available&&n.reason&&console.log(` unavailable: ${n.reason}`)}return}let c=Ae(f),J=M||"default",U=new Set(["errors","warnings","requests","js","eval","reload","globals","perf","list","wait","sleep"]);function E(e){let t=e.displayUrl||e.url;return e.status!=null?`${e.method} ${t} -> ${e.status}${e.statusText?` ${e.statusText}`:""}`:e.error?`${e.method} ${t} -> ${e.error}`:`${e.method} ${t}`}async function L(e){let t=dt()?1200:350;try{let{settled:s,elapsed:r}=await oe({bridge:e,maxMs:t,pollMs:32,stablePolls:2});s||process.stderr.write(` \u26A0 auto-wait timed out after ${r??t}ms \u2014 next command may see mid-animation state. use \`sootsim do settle\` for a longer wait.
140
+ `)}catch{}}async function Y(){try{return await c.send({type:"evaluate",code:`(() => ({
141
+ console: window.__sootsimConsole?.count?.() || null,
142
+ requests: window.__sootsimTest?.getRequestCounts?.() || null,
143
+ }))()`})||{console:null,requests:null}}catch{return{console:null,requests:null}}}async function W(e={}){let t=e.counts!==void 0?e.counts:await z(c,"getRequestCounts");if(!t||typeof t!="object")return;let s=Math.max(0,Number(t.failed)||0);if(s===0||!e.includeTail&&!$e("requests",J,String(s))||(console.log(`
144
+ network: ${s} failed request${s===1?"":"s"}`),console.log(` inspect: ${x("requests")} 5`),!e.includeTail))return;let r=await z(c,"getFailedRequests",5);if(!(!Array.isArray(r)||r.length===0)){console.log(`
145
+ recent failed requests:
146
+ `);for(let n of r){let u=new Date(n.timestamp).toLocaleTimeString();console.log(` [${u}] ${E(n)}`),n.responseBody?console.log(` ${n.responseBody}`):n.error&&console.log(` ${n.error}`)}}}async function w(e={}){let t=e.counts!==void 0?e.counts:await c.send({type:"evaluate",code:"window.__sootsimConsole?.count?.() || { errors: 0, warnings: 0, total: 0 }"});if(!t||typeof t!="object")return;let s=t,r=Math.max(0,Number(s.errors)||0),n=Math.max(0,Number(s.warnings)||0);if(r===0&&n===0||!e.includeTail&&!$e("console",J,`${r}:${n}`))return;let u=[];if(r>0&&u.push(`${r} console error${r===1?"":"s"}`),n>0&&u.push(`${n} console warning${n===1?"":"s"}`),console.log(`
147
+ console: ${u.join(", ")}`),console.log(` inspect: ${x("errors")} 5`),n>0&&console.log(` inspect: ${x("warnings")} 5`),!e.includeTail||r===0)return;let m=await c.send({type:"evaluate",code:"window.__sootsimConsole?.getErrors?.(5) || []"});if(!(!Array.isArray(m)||m.length===0)){console.log(`
148
+ recent console errors:
149
+ `);for(let y of m){let g=new Date(y.timestamp).toLocaleTimeString(),$=Array.isArray(y.args)?y.args.map(A=>typeof A=="object"?JSON.stringify(A):String(A)).join(" "):String(y);console.log(` [${g}] ${$}`)}}}let N=["console","fetch","toast","alert","notification","screen","app-launch","keyboard","route","actionsheet","picker","shell","scroll","gesture","text-input","animation","reanimated"];async function Z(e){let t=_e(),s=null;try{s=await Oe(e,`(() => {
150
+ const tl = window.SootSim && window.SootSim.bridges && window.SootSim.bridges.timeline
151
+ if (!tl || typeof tl.summary !== 'function') return null
152
+ const cursorKey = ${JSON.stringify(t)}
153
+ const summary = tl.summary({ sinceCursor: cursorKey })
154
+ let consoleSplit = null
155
+ if (summary && summary.byKind && summary.byKind.console) {
156
+ const events = tl.recent({ sinceCursor: cursorKey, kinds: 'console', limit: 100000 }).events
157
+ consoleSplit = { error: 0, warn: 0 }
158
+ for (const ev of events) {
159
+ const lvl = ev && ev.data && ev.data.level
160
+ if (lvl === 'error') consoleSplit.error++
161
+ else if (lvl === 'warn') consoleSplit.warn++
162
+ }
163
+ }
164
+ return summary ? { summary, consoleSplit } : null
165
+ })()`)}catch{return}if(!s||!s.summary||!s.summary.total)return;let r=s.summary.byKind??{},n=[],u=new Set;for(let m of N){let y=r[m];if(y)if(u.add(m),m==="console"&&s.consoleSplit){let{error:g,warn:$}=s.consoleSplit;g>0&&n.push(`${g} error${g===1?"":"s"}`),$>0&&n.push(`${$} warning${$===1?"":"s"}`)}else n.push(`${y} ${m}${y===1?"":"s"}`)}for(let[m,y]of Object.entries(r))!u.has(m)&&y&&n.push(`${y} ${m}${y===1?"":"s"}`);if(n.length!==0&&(console.log(`
166
+ since last: ${n.join(" \xB7 ")} \u2014 sootsim what-happened`),s.summary.lastAt))try{await he(e,"SootSim.bridges.timeline.cursorAdvance",t,s.summary.lastAt)}catch{}}let F=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"]),V=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"]),te=(o.includes("--verbose")||o.includes("-v"))&&!o.includes("--json");S==="do"&&h==="shell"&&(console.error(" `sootsim do shell` was removed. use `sootsim shell ...` instead."),process.exit(1)),F.has(h)&&await Pe(c),V.has(h)&&await ce(c,{verbose:te});try{switch(h){case"list":{await pt({bridge:c,simId:M,args:l});break}case"tree":{await bt({bridge:c,args:l,positional:i});break}case"a11y":{let e=i[1]?Number(i[1]):5,t=await c.send({type:"evaluate",code:`(async () => {
167
+ const t = window.__sootsimTest
168
+ if (!t) return []
169
+ const all = await t.queryAll({ pruneHidden: true })
170
+ return all.filter(n => {
171
+ // skip zero-size nodes
172
+ if (!n.layout || n.layout.width <= 0 || n.layout.height <= 0) return false
173
+ // keep nodes with explicit accessibility roles or labels
174
+ if (n.accessibilityRole) return true
175
+ if (n.accessibilityHint) return true
176
+ if (n.isTextInput) return true
177
+ if (n.pressable) return true
178
+ // keep text leaf nodes
179
+ if (n.type === 'text' && n.text) return true
180
+ // keep views with intentional labels (not auto-derived)
181
+ if (n.accessibilityLabel && n.accessibilityLabel.length <= 30
182
+ && n.accessibilityLabel !== n.text) return true
183
+ // skip container views without role (just concatenated child text)
184
+ return false
185
+ }).map(n => ({
186
+ role: n.accessibilityRole || (n.pressable ? 'button' : n.isTextInput ? 'textfield' : n.type === 'text' ? 'statictext' : 'none'),
187
+ label: n.accessibilityLabel || n.text || null,
188
+ hint: n.accessibilityHint || null,
189
+ state: n.accessibilityState || null,
190
+ testID: n.testID || null,
191
+ position: n.absolutePosition ? { x: Math.round(n.absolutePosition.x), y: Math.round(n.absolutePosition.y) } : null,
192
+ size: n.layout ? { w: Math.round(n.layout.width), h: Math.round(n.layout.height) } : null,
193
+ }))
194
+ })()`});if(!Array.isArray(t)||t.length===0){console.log(" no accessible nodes found");break}if(o.includes("--json"))console.log(JSON.stringify(t,null,2));else{console.log(` accessibility tree (${t.length} nodes):
195
+ `);for(let s of t){let r=[];if(r.push(`[${s.role}]`),s.label){let n=s.label.length>50?s.label.slice(0,47)+"...":s.label;r.push(`"${n}"`)}if(s.hint&&r.push(`(hint: "${s.hint}")`),s.testID&&r.push(`#${s.testID}`),s.state){let n=[];s.state.disabled&&n.push("disabled"),s.state.selected&&n.push("selected"),s.state.checked===!0&&n.push("checked"),s.state.checked==="mixed"&&n.push("mixed"),s.state.busy&&n.push("busy"),s.state.expanded===!0&&n.push("expanded"),s.state.expanded===!1&&n.push("collapsed"),n.length&&r.push(`{${n.join(", ")}}`)}s.position&&r.push(`@(${s.position.x},${s.position.y})`),s.size&&r.push(`${s.size.w}x${s.size.h}`),console.log(" "+r.join(" "))}}break}case"find":{await ut({bridge:c,args:o,effectiveArgs:l,positional:i,inspectUsage:v});break}case"count":{await lt(c,{args:l});break}case"keyboard":{await mt(c,{json:o.includes("--json")});break}case"screens":{await gt(c,{json:o.includes("--json")});break}case"memory":{await ft(c,{args:l});break}case"wait":{await xt({wsPort:_,commandTimeoutMs:R,simId:M,positional:i});break}case"sleep":{await ht({positional:i,inspectUsage:v});break}case"settle":{await yt({bridge:c,args:o,positional:i});break}case"ready":{await kt({bridge:c,args:o});break}case"idle":{await vt({bridge:c,args:o,positional:i});break}case"selector":{await Tt({bridge:c,args:o,positional:i,inspectUsage:v});break}case"event":{await St({bridge:c,args:o,positional:i,inspectUsage:v});break}case"layout":{let e=i[1];e||(console.error(v("layout","<id>")),process.exit(1));let t=await c.send({type:"evaluate",code:`(async () => await window.__sootsimTest.getLayout(${JSON.stringify(e)}))()`});console.log(JSON.stringify(t,null,2));break}case"capture":case"screenshot":{let t=o.find((y,g)=>o[g-1]==="--output")||"/tmp/sootsim-inspect.png",s=await _t(o,c),r={type:"screenshot"};s&&(r.crop=s);let u=(await c.send(r)).replace(/^data:image\/png;base64,/,"");s&&console.log(` area: x=${s.x} y=${s.y} w=${s.w} h=${s.h}`),(await import("fs")).writeFileSync(t,Buffer.from(u,"base64")),console.log(` saved: ${t}`);break}case"sample-color":{let e=await _t(o,c);e||(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 t=await c.send({type:"evaluate",code:De(e)});if(o.includes("--json"))console.log(JSON.stringify(t,null,2));else{let{r:s,g:r,b:n,a:u,hex:m,samples:y}=t,g=e.w===1&&e.h===1?`@(${e.x},${e.y})`:`@(${e.x},${e.y}) ${e.w}x${e.h}`;console.log(` ${m} rgba(${s}, ${r}, ${n}, ${u}) ${g} ${y} samples`)}break}case"node":{let e=i[1];e||(console.error(v("node","<matcher>")),console.error(" resolves testID, id, then text \u2014 dumps full node info as JSON"),process.exit(1));let t=await c.send({type:"evaluate",code:`(async () => {
196
+ const t = window.__sootsimTest
197
+ const q = ${JSON.stringify(e)}
198
+ let node = null
199
+ let via = null
200
+ if (t.findByTestId) { node = await t.findByTestId(q); if (node) via = 'testID' }
201
+ if (!node && t.findById) { node = await t.findById(q); if (node) via = 'id' }
202
+ if (!node && t.findByText) { node = await t.findByText(q); if (node) via = 'text' }
203
+ if (!node) return { matcher: q, found: false }
204
+
205
+ // read the resolved transform (if any) off the style \u2014 useful
206
+ // because canvas nodes often animate via transform and describe
207
+ // output strips that.
208
+ const transform =
209
+ node.style && Array.isArray(node.style.transform)
210
+ ? node.style.transform
211
+ : node.style && node.style.transform
212
+ ? node.style.transform
213
+ : null
214
+
215
+ // parent chain \u2014 walk up from the node so the JSON dump is
216
+ // self-describing.
217
+ const parentChain = []
218
+ const root = window.__sootsimRoot
219
+ if (root && node.id != null) {
220
+ const findPath = (n, targetId, path) => {
221
+ if (!n) return null
222
+ if (n.id === targetId) return path
223
+ if (n.children) {
224
+ for (const child of n.children) {
225
+ const nextPath = [
226
+ ...path,
227
+ {
228
+ type: n.type || 'view',
229
+ testID: n.props?.testID || null,
230
+ text: n.text || null,
231
+ },
232
+ ]
233
+ const found = findPath(child, targetId, nextPath)
234
+ if (found) return found
235
+ }
236
+ }
237
+ return null
238
+ }
239
+ const chain = findPath(root, node.id, [])
240
+ if (chain) parentChain.push(...chain)
241
+ }
242
+
243
+ return {
244
+ matcher: q,
245
+ found: true,
246
+ resolvedVia: via,
247
+ node,
248
+ transform,
249
+ parentChain,
250
+ }
251
+ })()`});console.log(JSON.stringify(t,null,2));break}case"tap":{let e=Number(i[1]),t=Number(i[2]),s=ie(o);if(s){let u=await ue(c,s);u||(console.error(` not found: ${s.value}`),s.mode==="testid"&&G("wait-selector-for-missing-testid",s.value),process.exit(1)),e=u.x,t=u.y}(!Number.isFinite(e)||!Number.isFinite(t))&&(console.error(v("tap","<x> <y> | --testid <id> | --text <t>")),process.exit(1));let r=await c.send({type:"tap",x:e,y:t}),n=mo(e,t,r);n&&await j("inspect tap",n.step,n.summary),console.log(JSON.stringify(r,null,2));break}case"drag":case"swipe":{let e=Number(i[1]),t=Number(i[2]),s=Number(i[3]),r=Number(i[4]),n=h==="swipe"?10:12,u=h==="swipe"?8:16,m=i[5]?Number(i[5]):n,y=i[6]?Number(i[6]):u;(!Number.isFinite(e)||!Number.isFinite(t)||!Number.isFinite(s)||!Number.isFinite(r)||!Number.isFinite(m)||!Number.isFinite(y))&&(console.error(v(h,"<x1> <y1> <x2> <y2> [steps] [stepMs]")),process.exit(1));let g=await c.send({type:"evaluate",code:`(async () => {
252
+ const interact = window.__sootsimInteract
253
+ if (!interact?.drag) return { ok: false, reason: 'no interact.drag' }
254
+ const value = await interact.drag(${e}, ${t}, ${s}, ${r}, ${Math.max(1,Math.round(m))}, ${Math.max(0,Math.round(y))})
255
+ return { ok: !!value, value }
256
+ })()`});if(g?.ok){let $=Math.max(1,Math.round(Math.max(1,m)*Math.max(0,y)));await j(`inspect ${h}`,{swipe:{start:`${e}, ${t}`,end:`${s}, ${r}`,duration:$}},`${h} ${e},${t} -> ${s},${r}`)}console.log(JSON.stringify(g,null,2));break}case"pinch":{let e=Number(i[1]),t=Number(i[2]),s=Number(i[3]),r=Number(i[4]),n=Number(i[5]),u=Number(i[6]),m=Number(i[7]),y=Number(i[8]),g=i[9]?Number(i[9]):12,$=i[10]?Number(i[10]):16;(!Number.isFinite(e)||!Number.isFinite(t)||!Number.isFinite(s)||!Number.isFinite(r)||!Number.isFinite(n)||!Number.isFinite(u)||!Number.isFinite(m)||!Number.isFinite(y)||!Number.isFinite(g)||!Number.isFinite($))&&(console.error(v("pinch","<x1> <y1> <x2> <y2> <x1'> <y1'> <x2'> <y2'> [steps] [stepMs]")),process.exit(1));let A=await c.send({type:"evaluate",code:`(async () => {
257
+ const interact = window.__sootsimInteract
258
+ if (!interact?.pinch) return { ok: false, reason: 'no interact.pinch' }
259
+ const value = await interact.pinch(${e}, ${t}, ${s}, ${r}, ${n}, ${u}, ${m}, ${y}, ${Math.max(1,Math.round(g))}, ${Math.max(0,Math.round($))})
260
+ return { ok: !!value, value }
261
+ })()`});A?.ok&&await j("inspect pinch",{pinch:{from:[e,t,s,r],to:[n,u,m,y],steps:Math.max(1,Math.round(g)),stepMs:Math.max(0,Math.round($))}},`pinch (${e},${t}) (${s},${r}) -> (${n},${u}) (${m},${y})`),console.log(JSON.stringify(A,null,2));break}case"tap-text":{let e=i[1];e||(console.error(v("tap-text","<text>")),process.exit(1));let t=q=>{let P=o.indexOf(q);return P>=0&&P+1<o.length?o[P+1]:null},s=q=>o.includes(q),r=t("--nth")??t("--index"),n=r!==null?Number(r):null;n!==null&&!Number.isFinite(n)&&(console.error(` --nth/--index requires an integer, got: ${r}`),process.exit(1));let u=t("--within"),m=t("--role"),y=s("--exact"),g=s("--first"),$=t("--min-y"),A=t("--max-y"),B=t("--min-x"),H=t("--max-x");for(let[q,P]of[["--min-y",$],["--max-y",A],["--min-x",B],["--max-x",H]])P!==null&&!Number.isFinite(Number(P))&&(console.error(` ${q} requires a number, got: ${P}`),process.exit(1));let K=o.indexOf("--near"),k=null;if(K>=0){let q=Number(o[K+1]),P=Number(o[K+2]);(!Number.isFinite(q)||!Number.isFinite(P))&&(console.error(" --near requires two numbers: --near <x> <y>"),process.exit(1)),k={x:q,y:P}}let b=JSON.stringify({query:e,exact:y,role:m,within:u,minX:B!==null?Number(B):null,maxX:H!==null?Number(H):null,minY:$!==null?Number($):null,maxY:A!==null?Number(A):null,near:k,nth:n,first:g}),p=await c.send({type:"evaluate",code:`(async () => {
262
+ const t = window.__sootsimTest
263
+ if (!t) return { error: 'bridge-not-ready' }
264
+ const F = ${b}
265
+
266
+ const res = await t.queryTextCandidates({
267
+ query: F.query,
268
+ exact: !!F.exact,
269
+ ...(F.role ? { role: F.role } : {}),
270
+ })
271
+
272
+ let candidates = res.candidates || []
273
+
274
+ candidates = candidates.filter((c) => {
275
+ const ax = c.info.absolutePosition && c.info.absolutePosition.x
276
+ const ay = c.info.absolutePosition && c.info.absolutePosition.y
277
+ if (F.minX !== null && !(ax >= F.minX)) return false
278
+ if (F.maxX !== null && !(ax <= F.maxX)) return false
279
+ if (F.minY !== null && !(ay >= F.minY)) return false
280
+ if (F.maxY !== null && !(ay <= F.maxY)) return false
281
+ if (F.within && !c.ancestorTestIDs.includes(F.within)) return false
282
+ return true
283
+ })
284
+
285
+ if (F.near) {
286
+ candidates.sort((a, b) => {
287
+ const ax = (a.info.absolutePosition && a.info.absolutePosition.x) || 0
288
+ const ay = (a.info.absolutePosition && a.info.absolutePosition.y) || 0
289
+ const bx = (b.info.absolutePosition && b.info.absolutePosition.x) || 0
290
+ const by = (b.info.absolutePosition && b.info.absolutePosition.y) || 0
291
+ return (
292
+ Math.hypot(ax - F.near.x, ay - F.near.y) -
293
+ Math.hypot(bx - F.near.x, by - F.near.y)
294
+ )
295
+ })
296
+ } else {
297
+ candidates.sort((a, b) => {
298
+ const ay = (a.info.absolutePosition && a.info.absolutePosition.y) || 0
299
+ const by = (b.info.absolutePosition && b.info.absolutePosition.y) || 0
300
+ if (Math.abs(ay - by) > 2) return ay - by
301
+ const ax = (a.info.absolutePosition && a.info.absolutePosition.x) || 0
302
+ const bx = (b.info.absolutePosition && b.info.absolutePosition.x) || 0
303
+ return ax - bx
304
+ })
305
+ }
306
+
307
+ const total = candidates.length
308
+ if (total === 0) return { matched: 0, total: 0 }
309
+
310
+ let idx = 0
311
+ if (F.nth !== null) {
312
+ idx = F.nth < 0 ? total + F.nth : F.nth
313
+ if (idx < 0 || idx >= total) {
314
+ return { matched: 0, total, nthOutOfRange: true, nth: F.nth }
315
+ }
316
+ } else if (total > 1 && !F.first && !F.near) {
317
+ return {
318
+ ambiguous: true,
319
+ total,
320
+ candidates: candidates.slice(0, 10).map((c, i) => ({
321
+ idx: i,
322
+ nodeId: c.info.nodeId,
323
+ type: c.info.type,
324
+ testID: c.info.testID,
325
+ text: (c.info.text || '').slice(0, 60),
326
+ abs: c.info.absolutePosition,
327
+ layout: c.info.layout
328
+ ? {
329
+ width: Math.round(c.info.layout.width || 0),
330
+ height: Math.round(c.info.layout.height || 0),
331
+ }
332
+ : null,
333
+ ancestorTestIDs: (c.ancestorTestIDs || []).slice(0, 5),
334
+ })),
335
+ }
336
+ }
337
+
338
+ const picked = candidates[idx]
339
+ const n = picked.info
340
+ if (!n.absolutePosition || !n.layout) return { matched: 0, total }
341
+
342
+ const resolved =
343
+ typeof n.nodeId === 'number' &&
344
+ typeof t.resolveTapTarget === 'function'
345
+ ? await t.resolveTapTarget(n.nodeId)
346
+ : null
347
+ const target = (resolved && resolved.target) || n
348
+ const cx =
349
+ resolved && typeof resolved.cx === 'number'
350
+ ? resolved.cx
351
+ : n.absolutePosition.x + (n.layout.width || 0) / 2
352
+ const cy =
353
+ resolved && typeof resolved.cy === 'number'
354
+ ? resolved.cy
355
+ : n.absolutePosition.y + (n.layout.height || 0) / 2
356
+ return {
357
+ cx,
358
+ cy,
359
+ match: {
360
+ nodeId: n.nodeId ?? null,
361
+ id: n.id,
362
+ testID: n.testID,
363
+ type: n.type,
364
+ },
365
+ target: {
366
+ nodeId: target.nodeId ?? null,
367
+ id: target.id,
368
+ testID: target.testID,
369
+ type: target.type,
370
+ },
371
+ strategy: (resolved && resolved.strategy) || 'matched-node',
372
+ total,
373
+ idx,
374
+ }
375
+ })()`});if(p?.error==="bridge-not-ready"&&(console.error(" sootsim test bridge not ready"),process.exit(1)),p?.ambiguous){let q=p.candidates;console.error(` ambiguous: ${p.total} matches for "${e}"`);for(let P of q){let ae=P.abs?`@(${Math.round(P.abs.x)},${Math.round(P.abs.y)})`:"",Rt=P.layout?` ${P.layout.width}x${P.layout.height}`:"",Et=P.testID?` #${P.testID}`:"",Ct=P.text?` "${P.text}"`:"",Dt=P.ancestorTestIDs.length>0?` within ${P.ancestorTestIDs.slice(0,3).map(Bt=>`#${Bt}`).join(" > ")}`:"";console.error(` [${P.idx}] <${P.type}>${Ct}${Et} ${ae}${Rt}${Dt}`)}p.total>q.length&&console.error(` ... and ${p.total-q.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 "${e}"`),process.exit(1)),(!p||typeof p.cx!="number")&&(console.error(` not found: ${e}`),process.exit(1));let O=await c.send({type:"tap",x:p.cx,y:p.cy});if(O?.hit!==!1&&O?.ok!==!1){let q=Te(e,{id:p.target?.id??null,testID:p.target?.testID??null,type:p.target?.type??null,cx:p.cx,cy:p.cy},"text");await j("inspect tap-text",q.step,q.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||n!==null?{nth:{index:p.idx,total:p.total}}:{},result:O},null,2));break}case"tap-best":{let e=i[1];e||(console.error(v("tap-best","<query>")),process.exit(1));let t=JSON.stringify(e),s=await c.send({type:"evaluate",code:`(async () => {
376
+ const t = window.__sootsimTest
377
+ if (!t) return { error: 'bridge-not-ready' }
378
+ // try testID first \u2014 strongest signal of "this is the
379
+ // intended tap target".
380
+ const byTestId =
381
+ (await t.findByTestId(${t})) || (await t.findById(${t}))
382
+ if (byTestId && byTestId.absolutePosition && byTestId.layout) {
383
+ return {
384
+ strategy: 'testid',
385
+ node: {
386
+ nodeId: byTestId.nodeId ?? null,
387
+ id: byTestId.id,
388
+ testID: byTestId.testID,
389
+ type: byTestId.type,
390
+ text: byTestId.text,
391
+ absolutePosition: byTestId.absolutePosition,
392
+ layout: byTestId.layout,
393
+ },
394
+ }
395
+ }
396
+ // text fallback. findByText returns null when there are
397
+ // 0 or 2+ matches \u2014 to disambiguate we'd send the user
398
+ // back to tap-text with --nth, which is the right
399
+ // failure mode.
400
+ const byText = await t.findByText(${t})
401
+ if (byText && byText.absolutePosition && byText.layout) {
402
+ return {
403
+ strategy: 'text',
404
+ node: {
405
+ nodeId: byText.nodeId ?? null,
406
+ id: byText.id,
407
+ testID: byText.testID,
408
+ type: byText.type,
409
+ text: byText.text,
410
+ absolutePosition: byText.absolutePosition,
411
+ layout: byText.layout,
412
+ },
413
+ }
414
+ }
415
+ return { strategy: 'none' }
416
+ })()`});"error"in s&&(console.error(` ${s.error}`),process.exit(1)),s.strategy==="none"&&(console.error(` tap-best: no testID or visible text matched "${e}". try \`sootsim find --interactive-targets\` to list candidates.`),process.exit(1));let r=s.node,n=r.absolutePosition.x+r.layout.width/2,u=r.absolutePosition.y+r.layout.height/2,m=await c.send({type:"tap",x:n,y:u});if(m?.hit!==!1&&m?.ok!==!1){let y=Te(e,{id:r.id,testID:r.testID,type:r.type,cx:n,cy:u},s.strategy==="testid"?"id":"text");await j("inspect tap-best",y.step,y.summary)}console.log(JSON.stringify({matched:{strategy:s.strategy,nodeId:r.nodeId,id:r.id,testID:r.testID,type:r.type,text:r.text},tapped:{cx:n,cy:u},result:m},null,2));break}case"tap-id":{let e=i[1];e||(console.error(v("tap-id","<id>")),process.exit(1));let t=JSON.stringify(e),s=await c.send({type:"evaluate",code:`(async () => {
417
+ const t = window.__sootsimTest
418
+ if (!t) return null
419
+ const n = (await t.findByTestId(${t})) || (await t.findById(${t}))
420
+ if (!n || !n.absolutePosition || !n.layout) return { cx: null }
421
+ const resolved =
422
+ typeof n.nodeId === 'number' && typeof t.resolveTapTarget === 'function'
423
+ ? await t.resolveTapTarget(n.nodeId)
424
+ : null
425
+ const target = (resolved && resolved.target) || n
426
+ const cx =
427
+ resolved && typeof resolved.cx === 'number'
428
+ ? resolved.cx
429
+ : n.absolutePosition.x + (n.layout.width || 0) / 2
430
+ const cy =
431
+ resolved && typeof resolved.cy === 'number'
432
+ ? resolved.cy
433
+ : n.absolutePosition.y + (n.layout.height || 0) / 2
434
+ return {
435
+ cx,
436
+ cy,
437
+ match: {
438
+ nodeId: n.nodeId ?? null,
439
+ id: n.id,
440
+ testID: n.testID,
441
+ type: n.type,
442
+ },
443
+ target: {
444
+ nodeId: target.nodeId ?? null,
445
+ id: target.id,
446
+ testID: target.testID,
447
+ type: target.type,
448
+ },
449
+ strategy: (resolved && resolved.strategy) || 'matched-node',
450
+ }
451
+ })()`});(!s||typeof s.cx!="number")&&(console.error(` not found: ${e}`),process.exit(1));let r=await c.send({type:"tap",x:s.cx,y:s.cy});if(r?.hit!==!1&&r?.ok!==!1){let n=Te(e,{id:s.target?.id??null,testID:s.target?.testID??null,type:s.target?.type??null,cx:s.cx,cy:s.cy},"id");await j("inspect tap-id",n.step,n.summary)}console.log(JSON.stringify({matched:s.match,tapped:{nodeId:s.target?.nodeId??null,id:s.target?.id??null,testID:s.target?.testID??null,type:s.target?.type??null,cx:s.cx,cy:s.cy},...s.strategy&&s.strategy!=="matched-node"?{strategy:s.strategy}:{},result:r},null,2));break}case"type-into":{let e=i[1],t=i.slice(2).join(" ");(!e||!t)&&(console.error(v("type-into","<id> <text>")),process.exit(1));let s=JSON.stringify(e),r=await c.send({type:"evaluate",code:`(async () => {
452
+ const t = window.__sootsimTest
453
+ if (!t) return null
454
+ const n = await (t.findByTestId(${s}) || t.findById(${s}))
455
+ if (!n || !n.absolutePosition || !n.layout) return null
456
+ return {
457
+ cx: n.absolutePosition.x + (n.layout.width || 0) / 2,
458
+ cy: n.absolutePosition.y + (n.layout.height || 0) / 2,
459
+ testID: n.testID,
460
+ isTextInput: !!n.isTextInput,
461
+ placeholder: n.placeholder || null,
462
+ }
463
+ })()`});(!r||typeof r.cx!="number")&&(console.error(` not found: ${e}`),process.exit(1)),r.isTextInput||console.error(` warning: ${e} is not a text input (isTextInput: false)`);let n=await c.send({type:"tap",x:r.cx,y:r.cy}),u=await lo(c);u.visible||(console.error(` keyboard did not open after tapping ${e}`),process.exit(1));let m=u.focusedInput;m&&(m.testID===e||m.id===e||(console.error(` focus routing mismatch after tap: requested ${JSON.stringify(e)} 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:t}),await j("inspect type-into",{tapOn:{id:e},inputText:t},`type-into #${e} ${JSON.stringify(t)}`),console.log(JSON.stringify({target:e,isTextInput:r.isTextInput,keyboardOpened:u.visible??n?.keyboardOpened??!1,focusedInput:u.focusedInput??null,typed:t},null,2));break}case"type":{let e=i.slice(1).join(" ");e||(console.error(v("type","<text>")),process.exit(1)),await fe(c,"type"),await c.send({type:"keyboard",action:"type",text:e}),await j("inspect type",{inputText:e},`type ${JSON.stringify(e)}`),console.log(` typed: ${JSON.stringify(e)}`);break}case"key":{let e=i[1];e||(console.error(v("key","<name>")),process.exit(1)),await fe(c,"key"),await c.send({type:"keyboard",action:"press",text:e}),await j("inspect key",{pressKey:e},`key ${e}`),console.log(` pressed: ${e}`);break}case"key-sequence":{let e=i.slice(1);e.length===0&&(console.error(v("key-sequence","<key> [<key> ...]")),process.exit(1)),await fe(c,"key-sequence");for(let t of e)await c.send({type:"keyboard",action:"press",text:t});await j("inspect key-sequence",{pressKey:e.join(" ")},`key-sequence ${e.join(" ")}`),console.log(` pressed: ${e.join(", ")}`);break}case"keycode":{let e=i.slice(1);e.length===0&&(console.error(v("keycode","<code> [<code> ...]")),process.exit(1));let t=e.map(r=>({code:r,key:co(r)})),s=t.filter(r=>!r.key);s.length>0&&(console.error(` unsupported keycode(s): ${s.map(r=>r.code).join(", ")}`),process.exit(1)),await fe(c,"keycode");for(let r of t)await c.send({type:"keyboard",action:"press",text:r.key});await j("inspect keycode",{pressKey:t.map(r=>r.key).join(" ")},`keycode ${e.join(" ")}`),console.log(` pressed: ${e.join(", ")}`);break}case"dispatch":{let e=i[1];e||(console.error(v("dispatch","<char>")),process.exit(1)),await c.send({type:"keyboard",action:"dispatchKey",text:e}),await j("inspect dispatch",{dispatchKey:e},`dispatch ${JSON.stringify(e)}`),console.log(` dispatched: ${e}`);break}case"dismiss":{await c.send({type:"keyboard",action:"dismiss"}),await j("inspect dismiss",{hideKeyboard:!0},"dismiss keyboard"),console.log(" keyboard dismissed");break}case"double-tap":{let e=Number(i[1]),t=Number(i[2]),s=ie(o);if(s){let m=await ue(c,s);m||(console.error(` not found: ${s.value}`),s.mode==="testid"&&G("wait-selector-for-missing-testid",s.value),process.exit(1)),e=m.x,t=m.y}let r=i[3]?Number(i[3]):80;(!Number.isFinite(e)||!Number.isFinite(t)||!Number.isFinite(r))&&(console.error(v("double-tap","<x> <y> [gapMs] | --testid <id>")),process.exit(1));let n=Math.max(0,Math.round(r)),u=await c.send({type:"evaluate",code:`(async () => {
464
+ const interact = window.__sootsimInteract
465
+ if (interact?.doubleTap) {
466
+ return {
467
+ ok: !!(await interact.doubleTap(${e}, ${t}, ${n})),
468
+ gapMs: ${n},
469
+ }
470
+ }
471
+ if (!interact?.tap) {
472
+ return { ok: false, reason: 'no interact.tap', gapMs: ${n} }
473
+ }
474
+ const first = await interact.tap(${e}, ${t})
475
+ if (!first || first.hit === false) {
476
+ return { ok: false, reason: 'first tap missed', gapMs: ${n}, first }
477
+ }
478
+ await new Promise((resolve) => setTimeout(resolve, ${n}))
479
+ const second = await interact.tap(${e}, ${t})
480
+ return {
481
+ ok: !!second && second.hit !== false,
482
+ gapMs: ${n},
483
+ first,
484
+ second,
485
+ }
486
+ })()`});u?.ok&&await j("inspect double-tap",{doubleTapAtCoords:{x:e,y:t,gapMs:n}},`double-tap @${e},${t}`),console.log(JSON.stringify(u,null,2));break}case"long-press":{let e=Number(i[1]),t=Number(i[2]),s=ie(o);if(s){let u=await ue(c,s);u||(console.error(` not found: ${s.value}`),s.mode==="testid"&&G("wait-selector-for-missing-testid",s.value),process.exit(1)),e=u.x,t=u.y}let r=i[3]?Number(i[3]):600;(!Number.isFinite(e)||!Number.isFinite(t)||!Number.isFinite(r))&&(console.error(v("long-press","<x> <y> [durationMs] | --testid <id>")),process.exit(1));let n=await c.send({type:"evaluate",code:`(async () => {
487
+ const interact = window.__sootsimInteract
488
+ if (!interact?.longPress) return { ok: false, reason: 'no interact.longPress' }
489
+ const value = await interact.longPress(${e}, ${t}, ${Math.max(0,Math.round(r))})
490
+ return { ok: !!value, value }
491
+ })()`});n?.ok&&await j("inspect long-press",{tapAtCoords:{x:e,y:t}},`long-press @${e},${t}`),console.log(JSON.stringify(n,null,2));break}case"touch":{let e=i[1],t=Number(i[2]),s=Number(i[3]),r=i[4]?Number(i[4]):999,n=e==="down"?"touchDown":e==="move"?"touchMove":e==="up"?"touchUp":e==="cancel"?"touchCancel":null;n||(console.error(v("touch","<down|move|up|cancel> <x> <y> [pointerId]")),process.exit(1)),e!=="cancel"&&(!Number.isFinite(t)||!Number.isFinite(s))&&(console.error(v("touch","<down|move|up|cancel> <x> <y> [pointerId]")),process.exit(1));let u=e==="down"?"tap":e==="move"?"move":null,m=u&&Number.isFinite(t)&&Number.isFinite(s)?`window.dispatchEvent(new CustomEvent('sootsim:agentAction', { detail: { type: '${u}', x: ${t}, y: ${s} } }));`:"",y=await c.send({type:"evaluate",code:`(async () => {
492
+ ${m}
493
+ const interact = window.__sootsimInteract
494
+ if (!interact?.${n}) return { ok: false, reason: 'no interact.${n}' }
495
+ const value = ${e==="cancel"?`await interact.${n}(${Math.max(1,Math.round(r))})`:`await interact.${n}(${t}, ${s}, ${Math.max(1,Math.round(r))})`}
496
+ return { ok: !!value, value }
497
+ })()`});y?.ok&&e!=="cancel"&&await j("inspect touch",{tapAtCoords:{x:t,y:s}},`touch ${e} @${t},${s}`),console.log(JSON.stringify(y,null,2));break}case"gesture":{let e=i[1],t=i[2]?Number(i[2]):220;(!e||!Number.isFinite(t))&&(console.error(v("gesture","<preset> [durationMs]")),process.exit(1));let s=await c.send({type:"evaluate",code:`(async () => {
498
+ const spec = globalThis.__sootsimDeviceSpec || {}
499
+ return {
500
+ width: spec.width || window.innerWidth || 393,
501
+ height: spec.height || window.innerHeight || 852,
502
+ statusBarHeight: spec.statusBarHeight || 0,
503
+ homeIndicatorHeight: spec.homeIndicatorHeight || 0,
504
+ }
505
+ })()`}),r=Number(s?.width)||393,n=Number(s?.height)||852,u=Number(s?.statusBarHeight)||0,m=Number(s?.homeIndicatorHeight)||0,y=Math.round(r/2),g=Math.round(n/2),$=Math.max(24,u+18),A=Math.max(24,m+18),B=18,H=Math.min(220,Math.round(n*.24)),K=Math.min(180,Math.round(r*.32)),k=y,b=g,p=y,O=g;switch(e){case"scroll-up":b=g+Math.round(H/2),O=g-Math.round(H/2);break;case"scroll-down":b=g-Math.round(H/2),O=g+Math.round(H/2);break;case"scroll-left":k=y+Math.round(K/2),p=y-Math.round(K/2);break;case"scroll-right":k=y-Math.round(K/2),p=y+Math.round(K/2);break;case"swipe-from-left-edge":k=B,b=g,p=Math.min(r-B,B+K);break;case"swipe-from-right-edge":k=r-B,b=g,p=Math.max(B,r-B-K);break;case"swipe-from-top-edge":k=y,b=$,O=Math.min(n-A,$+H);break;case"swipe-from-bottom-edge":k=y,b=n-A,O=Math.max($,n-A-H);break;default:console.error(` unknown gesture preset: ${e}`),process.exit(1)}let q=Math.max(8,Math.round(t/16)),P=Math.max(1,Math.round(t/q)),ae=await c.send({type:"evaluate",code:`(async () => {
506
+ const interact = window.__sootsimInteract
507
+ if (!interact?.drag) return { ok: false, reason: 'no interact.drag' }
508
+ const value = await interact.drag(${k}, ${b}, ${p}, ${O}, ${q}, ${P})
509
+ return { ok: !!value, value }
510
+ })()`});ae?.ok&&await j("inspect gesture",{swipe:{start:`${k}, ${b}`,end:`${p}, ${O}`,duration:Math.max(1,Math.round(t))}},`gesture ${e}`),console.log(JSON.stringify({preset:e,from:{x:k,y:b},to:{x:p,y:O},result:ae},null,2));break}case"scroll":{let e=ie(o),t=e?.mode==="testid"?e.value:i[1],s=Number(i[e?1:2]),r=Number(i[e?2:3]);(!t||!Number.isFinite(s)||!Number.isFinite(r))&&(console.error(v("scroll","<id> <dx> <dy> | --testid <id> <dx> <dy>")),process.exit(1));let n=await c.send({type:"evaluate",code:`(async () => {
511
+ const t = window.__sootsimTest
512
+ if (!t) return null
513
+ const n = await t.findByTestId(${JSON.stringify(t)})
514
+ || await t.findById(${JSON.stringify(t)})
515
+ if (!n || !n.absolutePosition || !n.layout) return null
516
+ return {
517
+ cx: n.absolutePosition.x + (n.layout.width || 0) / 2,
518
+ cy: n.absolutePosition.y + (n.layout.height || 0) / 2,
519
+ }
520
+ })()`}),u=await z(c,"scrollTo",t,s,r,!1);u?.ok&&await j("inspect scroll",{scrollTo:{id:t,x:s,y:r}},`scroll ${t} -> ${s},${r}`),console.log(JSON.stringify({...u,...n?{at:{x:n.cx,y:n.cy}}:{}},null,2));break}case"state":{let e=i[1];if(a==="get"&&!e){let s=await z(c,"getRuntimeState"),r=await c.send({type:"evaluate",code:`({
521
+ errors: window.__sootsimConsole?.getErrors?.()?.length ?? 0,
522
+ warnings: window.__sootsimConsole?.getWarnings?.()?.length ?? 0,
523
+ })`});s&&typeof s=="object"&&s.diagnostics&&(s.diagnostics.errors=r?.errors??0,s.diagnostics.warnings=r?.warnings??0),console.log(JSON.stringify(s,null,2));break}if(!e||e==="--help"||e==="-h"){console.log(`
524
+ ${x("state")} \u2014 dump raw runtime state
525
+
526
+ subcommands:
527
+ shell dump shell transition/layout state
528
+ worker dump render-worker host/animation state
529
+ keyboard dump keyboard visibility, mode, and focused input
530
+ ownership dump surface ownership + pointerOnSurface delivery stats
531
+ node <id> dump raw node info by id or testID
532
+ scroll <id> dump scroll metrics and runtime state
533
+ scroll-hit <x> <y> dump the nearest scroll ancestor at coordinates
534
+ hit <x> <y> dump the hit-test ancestry at coordinates
535
+ gesture <x> <y> dump gesture routing/debug info at coordinates
536
+
537
+ examples:
538
+ ${x("state")} shell
539
+ ${x("state")} worker
540
+ ${x("state")} keyboard
541
+ ${x("state")} ownership
542
+ ${x("state")} node photos
543
+ ${x("state")} scroll feed
544
+ ${x("state")} scroll-hit 360 420
545
+ ${x("state")} hit 200 720
546
+ `);break}let t;switch(e){case"shell":t=await se(c,500);break;case"worker":t=await he(c,"__sootsimRenderHost.queryStats");break;case"ownership":t=await c.send({type:"evaluate",code:`(() => {
547
+ const h = window.__sootsimRenderHost
548
+ if (!h || typeof h.getOwnershipSnapshot !== 'function') {
549
+ return { error: 'getOwnershipSnapshot not available' }
550
+ }
551
+ return h.getOwnershipSnapshot()
552
+ })()`});break;case"keyboard":t=await c.send({type:"evaluate",code:`(async () => {
553
+ const kb = window.__sootsimKeyboard
554
+ const test = window.__sootsimTest
555
+ if (!kb) return { error: 'keyboard bridge not available' }
556
+ const layout = typeof kb.getLayout === 'function' ? kb.getLayout() : null
557
+ const visible = kb.isVisible()
558
+ const mode = kb.getMode()
559
+ let focused = null
560
+ if (test && typeof test.getFocusedNode === 'function') {
561
+ try {
562
+ focused = await test.getFocusedNode()
563
+ } catch {}
564
+ }
565
+ return {
566
+ visible,
567
+ mode,
568
+ layout,
569
+ focusedInput: focused ? {
570
+ nodeId: focused.nodeId ?? null,
571
+ testID: focused.testID || null,
572
+ id: focused.id || null,
573
+ placeholder: focused.placeholder || null,
574
+ text: focused.text || null,
575
+ } : null,
576
+ }
577
+ })()`});break;case"node":{let s=i[2];s||(console.error(` usage: ${x("state")} node <id>`),process.exit(1)),t=await z(c,"findByTestId",s)||await z(c,"findById",s);break}case"scroll":{let s=i[2];s||(console.error(` usage: ${x("state")} scroll <id>`),process.exit(1)),t=await z(c,"getScrollState",s);break}case"scroll-hit":{let s=Number(i[2]),r=Number(i[3]);(!Number.isFinite(s)||!Number.isFinite(r))&&(console.error(` usage: ${x("state")} scroll-hit <x> <y>`),process.exit(1)),t=await z(c,"getScrollStateAt",s,r);break}case"hit":{let s=Number(i[2]),r=Number(i[3]);(!Number.isFinite(s)||!Number.isFinite(r))&&(console.error(` usage: ${x("state")} hit <x> <y>`),process.exit(1)),t=await z(c,"debugHitAt",s,r);break}case"gesture":{let s=Number(i[2]),r=Number(i[3]);(!Number.isFinite(s)||!Number.isFinite(r))&&(console.error(` usage: ${x("state")} gesture <x> <y>`),process.exit(1)),t=await z(c,"debugGestureAt",s,r);break}default:console.error(` unknown state subcommand: ${e}`),process.exit(1)}console.log(JSON.stringify(t,null,2));break}case"shell":{let e=i[1];if(!e||e==="--help"||e==="-h"){console.log(`
578
+ ${x("shell")} \u2014 run built-in shell commands
579
+
580
+ subcommands:
581
+ launch <appId> [waitMs] [--clear-state]
582
+ launch app and wait for settled shell state
583
+ home [waitMs] go home and wait for settled shell state
584
+ switcher [waitMs] open switcher and wait for settled shell state
585
+ open-card <appId> [waitMs]
586
+ open a specific switcher card and wait for app settle
587
+ appearance <light|dark|auto|toggle>
588
+ update simulator appearance
589
+ lock toggle device lock state
590
+ shake trigger the simulator shake gesture
591
+
592
+ examples:
593
+ ${x("shell")} launch photos
594
+ ${x("shell")} launch rn --clear-state
595
+ ${x("shell")} launch photos 1500
596
+ ${x("shell")} home 500
597
+ ${x("shell")} switcher 800
598
+ ${x("shell")} open-card clock 800
599
+ ${x("shell")} appearance dark
600
+ ${x("shell")} lock
601
+ `);break}let t=e==="launch"||e==="open-card"||e==="home"||e==="switcher",s=e==="launch"||e==="open-card"?i[3]:i[2],r=s?Number(s):350;t&&(!Number.isFinite(r)||r<0)&&(console.error(v("shell",e==="launch"||e==="open-card"?"<launch|open-card> <appId> [settleMs]":"<home|switcher> [settleMs]")),process.exit(1));let n=!1,u=!1,m=null,y=o.includes("--clear-state");if(e==="launch"){let g=i[2];g||(console.error(v("shell","launch <appId> [settleMs] [--clear-state]")),process.exit(1)),y&&await c.send({type:"evaluate",code:Re}),n=!!await ne(c,"launchApp",r,g),{settled:u,state:m}=await pe(c,Math.round(r),$=>!!$&&$.state==="app"&&$.activeApp===g&&$.showSwitcher===!1&&$.switcherPhase==="idle"&&typeof $.launchProgress=="number"&&$.launchProgress>=.98),n&&await j("inspect shell launch",y?{launchApp:{clearState:!0}}:{launchApp:{}},y?"launch app (clear state)":"launch app")}else if(e==="home")n=!!await ne(c,"goHome",r),{settled:u,state:m}=await pe(c,Math.round(r),g=>!!g&&g.state==="home"&&g.activeApp==null&&g.showSwitcher===!1&&g.switcherPhase==="idle"&&typeof g.launchProgress=="number"&&g.launchProgress>=.98);else if(e==="switcher")n=!!await ne(c,"openSwitcher",r),{settled:u,state:m}=await pe(c,Math.round(r),g=>!!g&&g.state==="app"&&g.showSwitcher===!0&&g.switcherPhase==="idle"&&typeof g.zoomLevel=="number"&&Math.abs(g.zoomLevel)<=.02&&typeof g.horizontalZoom=="number"&&Math.abs(g.horizontalZoom)<=.02),u&&(await X(ao),m=await se(c));else if(e==="open-card"){let g=i[2];g||(console.error(v("shell","open-card <appId> [settleMs]")),process.exit(1)),n=!!await ne(c,"openSwitcherCard",r,g),{settled:u,state:m}=await pe(c,Math.round(r),$=>!!$&&$.state==="app"&&$.activeApp===g&&$.showSwitcher===!1&&$.switcherPhase==="idle"&&typeof $.zoomLevel=="number"&&$.zoomLevel>=.98&&typeof $.horizontalZoom=="number"&&$.horizontalZoom>=.98),n&&await j("inspect shell open-card",{openSwitcherCard:{appId:g}},`open switcher card ${g}`)}else if(e==="appearance"){let g=i[2];(!g||!["light","dark","auto","toggle"].includes(g))&&(console.error(v("shell","appearance <light|dark|auto|toggle>")),process.exit(1));let $=await Ft(c,"appearance",g);n=!!$?.ok,m={appearance:$}}else if(e==="lock"||e==="shake"){let g=await Ft(c,e);n=!!g?.ok,m={[e]:g}}else console.error(` unknown shell subcommand: ${e}`),process.exit(1);console.log(JSON.stringify({ok:n,settled:u,state:m},null,2));break}case"url":{await wt(c,{args:l});break}case"reload":{let s=!1,r=!1;try{await c.send({type:"evaluate",code:"window.__sootsimConsole?.clear()"});let m=await c.send({type:"evaluate",code:`;(() => {
602
+ const reloadExternalApp = window.SootSim?.bridges?.hotRemount?.reloadExternalApp
603
+ if (typeof reloadExternalApp === 'function') {
604
+ reloadExternalApp()
605
+ return { kind: 'external-app' }
606
+ }
607
+ window.location.reload()
608
+ return { kind: 'page' }
609
+ })()`});r=!!m&&m.kind==="external-app",s=!0}catch{}console.log(" reloading...");let n=c,u=null;if(r)u=await xe(c,{timeoutMs:1e4,errorGraceMs:3e3});else{s&&await X(300);let m=await st(_,R,M,{timeoutMs:1e4});m?(n=m,u=await xe(m,{timeoutMs:1e4,errorGraceMs:3e3})):(console.log(" \u26A0 reload: bridge never reconnected within 10000ms"),n=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(n)try{let m=await n.send({type:"evaluate",code:"window.__sootsimConsole?.getErrors(10) || []"});if(n!==c&&n.close(),Array.isArray(m)&&m.length>0){console.log(`
610
+ \u26A0 ${m.length} error(s) during mount:
611
+ `);for(let y of m){let g=y.args.map($=>typeof $=="object"?JSON.stringify($):$).join(" ");if(console.log(` ${g}`),y.stack){let $=y.stack.split(`
612
+ `).slice(0,2);for(let A of $)console.log(` ${A.trim()}`)}}}}catch{}u&&!u.ready&&(process.exitCode=1);break}case"eval":case"js":{let e=i.slice(1).join(" ");e||(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(` ${x("js")} SootSim.bridges.test.findByText("Sign in")`),console.error(` ${x("js")} SootSim.bridges.debug.snapshot("before")`),console.error(` ${x("js")} SootSim.bridges.keyboard.type("hello")`),console.error(` ${x("js")} SootSim.state.root.children.length`),process.exit(1));let t=e;t.startsWith("(async")||(t=`(async () => ${t})()`);let s=await c.send({type:"evaluate",code:t});console.log(JSON.stringify(s,null,2));let r=e.toLowerCase(),n=[];(r.includes("sootsim:gohome")||r.includes("gohome"))&&n.push("sootsim shell home"),(r.includes("sootsim:appswitcher")||r.includes("appswitcher"))&&n.push("sootsim shell switcher"),(r.includes("keyboard.isvisible")||r.includes("keyboard.getmode"))&&n.push("sootsim debug state keyboard"),r.includes("interact.tap")&&n.push("sootsim do tap <x> <y>"),r.includes("keyboard.type")&&n.push("sootsim do type <text>"),(r.includes("keyboard.press")||r.includes("keyboard.dispatchkey"))&&n.push("sootsim do key <name>"),r.includes("keyboard.dismiss")&&n.push("sootsim do dismiss"),r.includes("dumptree")&&n.push("sootsim get tree"),r.includes("dumpaccessibilitytree")&&n.push("sootsim get a11y"),r.includes("getnodecount")&&n.push("sootsim get count"),r.includes("findbytext")&&n.push("sootsim find <text>"),(r.includes("findbytestid")||r.includes("findbyid"))&&n.push("sootsim find --testid <id>"),r.includes("document.hidden")&&n.push("sootsim debug state keyboard (includes tab health)"),n.length>0&&G("prefer-cli-over-eval",n);break}case"globals":{let e=await c.send({type:"evaluate",code:`(async () => {
613
+ const globals = {}
614
+
615
+ // test bridge (proxy in worker mode)
616
+ const testMethods = [
617
+ 'findById', 'findByTestId', 'findByText', 'findByLabel', 'findByRole',
618
+ 'findAllByRole', 'findByA11yState', 'findAllByA11yState', 'findByHint',
619
+ 'findPressable', 'getStyle', 'getLayout', 'getAbsolutePosition', 'isVisible',
620
+ 'queryAll', 'dumpTree', 'dumpAccessibilityTree', 'getNodeCount', 'getShellState',
621
+ 'getScrollState', 'getScrollStateAt', 'scrollTo', 'waitForTree',
622
+ 'waitForScreenTransitions', 'debugByText', 'debugByTestId', 'debugHitAt',
623
+ 'debugGestureAt'
624
+ ]
625
+ globals['test (\u2192 __sootsimTest)'] = testMethods
626
+
627
+ // debug
628
+ if (window.__sootsimDebug) {
629
+ globals['debug (\u2192 __sootsimDebug)'] = Object.keys(window.__sootsimDebug)
630
+ }
631
+
632
+ // interact
633
+ if (window.__sootsimInteract) {
634
+ globals['interact (\u2192 __sootsimInteract)'] = Object.keys(window.__sootsimInteract)
635
+ }
636
+
637
+ // keyboard
638
+ if (window.__sootsimKeyboard) {
639
+ globals['keyboard (\u2192 __sootsimKeyboard)'] = Object.keys(window.__sootsimKeyboard)
640
+ }
641
+
642
+ // other globals
643
+ globals['other'] = [
644
+ 'root (\u2192 __sootsimRoot) - live node tree',
645
+ 'render() (\u2192 __sootsimForceRender) - force re-render'
646
+ ]
647
+
648
+ return globals
649
+ })()`});console.log(` sootsim JS API:
650
+ `);for(let[t,s]of Object.entries(e)){console.log(` ${t}:`);for(let r of s)console.log(` .${r}`);console.log("")}console.log(` use: ${x("js")} <expression>`),console.log(` example: ${x("js")} test.findByText("Sign in")`);break}case"describe":{await ct({bridge:c,args:o,positional:i});break}case"perf":{let e=i[1];if(!e||e==="--help"||e==="-h"){console.log(`
651
+ ${x("perf")} \u2014 performance profiling
652
+
653
+ subcommands:
654
+ stats one-shot stats (zero overhead query)
655
+ start begin recording frame times
656
+ stop stop recording and report results
657
+ frames [n] get last N frame times (default: 50)
658
+ transition <e> profile a shell transition (goHome, appSwitcher, lockScreen)
659
+
660
+ examples:
661
+ ${x("perf")} stats
662
+ ${x("perf")} start
663
+ # ... interact with the app ...
664
+ ${x("perf")} stop
665
+ ${x("perf")} transition goHome
666
+ `);break}switch(e){case"stats":{let t=await c.send({type:"evaluate",code:`(async () => {
667
+ // worker mode (host exposes these)
668
+ if (window.__sootsimPerfStats) {
669
+ return await window.__sootsimPerfStats()
670
+ }
671
+ // main-thread mode
672
+ const perf = window.__sootsimPerf
673
+ const a11y = window.__sootsimA11y
674
+ if (!perf && !a11y) return { error: 'no perf globals available' }
675
+
676
+ const frameStats = perf?.getFrameStats?.() || {}
677
+ const profile = a11y?.profile?.() || {}
678
+ const nodeCount = await window.__sootsimTest?.getNodeCount?.() || 0
679
+
680
+ return {
681
+ frames: frameStats.frames || profile.syncCount || 0,
682
+ avgMs: frameStats.totalMs && frameStats.frames
683
+ ? (frameStats.totalMs / frameStats.frames).toFixed(2)
684
+ : profile.avgSyncMs?.toFixed(2) || '?',
685
+ maxMs: frameStats.maxMs?.toFixed(2) || profile.maxSyncMs?.toFixed(2) || '?',
686
+ layoutMs: frameStats.layoutTotalMs?.toFixed(2) || '?',
687
+ nodeCount,
688
+ jankFrames: frameStats.recentFrames?.filter(f => f > 16.67).length || 0,
689
+ recentCount: frameStats.recentFrames?.length || 0,
690
+ }
691
+ })()`});t.error&&(console.error(` error: ${t.error}`),process.exit(1));let s=t.avgMs!=="?"?(1e3/parseFloat(t.avgMs)).toFixed(1):"?";console.log(" perf stats:"),console.log(` frames: ${t.frames}`),console.log(` avg: ${t.avgMs}ms (${s} fps)`),console.log(` max: ${t.maxMs}ms`),console.log(` layout: ${t.layoutMs}ms total`),console.log(` nodes: ${t.nodeCount}`),t.recentCount>0&&console.log(` jank: ${t.jankFrames}/${t.recentCount} frames >16.67ms`);break}case"start":{await c.send({type:"evaluate",code:`(async () => {
692
+ // worker mode
693
+ if (window.__sootsimPerfStart && window.__sootsimRenderHost) {
694
+ const result = window.__sootsimPerfStart()
695
+ window.${Q} = {
696
+ active: true,
697
+ mode: 'render-worker',
698
+ lastSamples: [],
699
+ startedAt: performance.now(),
700
+ }
701
+ return result
702
+ }
703
+ // main-thread mode
704
+ window.__sootsimPerf?.enableFrameStats?.(true)
705
+ window.__sootsimA11y?.resetProfile?.()
706
+ window.${Q} = {
707
+ active: true,
708
+ mode: 'main-thread',
709
+ lastSamples: [],
710
+ startedAt: performance.now(),
711
+ }
712
+ return { started: true }
713
+ })()`}),console.log(` profiling started \u2014 interact with the app, then run '${x("perf")} stop'`);break}case"stop":{let t=await c.send({type:"evaluate",code:`(async () => {
714
+ // worker mode
715
+ if (window.__sootsimRenderHost) {
716
+ const session = window.${Q} || {}
717
+ const priorSamples = session.active && Array.isArray(session.lastSamples)
718
+ ? session.lastSamples
719
+ : []
720
+ const flushedSamples = await window.__sootsimRenderHost.flushSamples()
721
+ const samples = priorSamples.concat(flushedSamples)
722
+ window.${Q} = {
723
+ ...session,
724
+ active: false,
725
+ mode: 'render-worker',
726
+ lastSamples: samples,
727
+ stoppedAt: performance.now(),
728
+ }
729
+
730
+ const frameTimes = samples.map(sample => sample[1])
731
+ const layoutTimes = samples.map(sample => sample[2])
732
+ const renderTimes = samples.map(sample => sample[3])
733
+ const copyTimes = samples.map(sample => sample[4])
734
+ const auxTimes = samples.map(sample => sample[5] || 0)
735
+ const otherTimes = samples.map(sample => sample[6] || 0)
736
+ const sorted = [...frameTimes].sort((a, b) => a - b)
737
+ const total = frameTimes.reduce((a, b) => a + b, 0)
738
+ const avg = frameTimes.length > 0 ? total / frameTimes.length : 0
739
+ const max = Math.max(...frameTimes, 0)
740
+ const layoutTotal = layoutTimes.reduce((a, b) => a + b, 0)
741
+ const renderTotal = renderTimes.reduce((a, b) => a + b, 0)
742
+ const copyTotal = copyTimes.reduce((a, b) => a + b, 0)
743
+ const auxTotal = auxTimes.reduce((a, b) => a + b, 0)
744
+ const otherTotal = otherTimes.reduce((a, b) => a + b, 0)
745
+
746
+ return {
747
+ mode: 'render-worker',
748
+ frames: frameTimes.length,
749
+ totalMs: total,
750
+ avgMs: avg,
751
+ maxMs: max,
752
+ layoutTotalMs: layoutTotal,
753
+ renderTotalMs: renderTotal,
754
+ copyTotalMs: copyTotal,
755
+ auxTotalMs: auxTotal,
756
+ otherTotalMs: otherTotal,
757
+ layoutAvgMs: frameTimes.length > 0 ? layoutTotal / frameTimes.length : 0,
758
+ renderAvgMs: frameTimes.length > 0 ? renderTotal / frameTimes.length : 0,
759
+ copyAvgMs: frameTimes.length > 0 ? copyTotal / frameTimes.length : 0,
760
+ auxAvgMs: frameTimes.length > 0 ? auxTotal / frameTimes.length : 0,
761
+ otherAvgMs: frameTimes.length > 0 ? otherTotal / frameTimes.length : 0,
762
+ p50: sorted[Math.floor(sorted.length * 0.5)] || 0,
763
+ p95: sorted[Math.floor(sorted.length * 0.95)] || 0,
764
+ p99: sorted[Math.floor(sorted.length * 0.99)] || 0,
765
+ jankFrames: frameTimes.filter((f) => f > 16.67).length,
766
+ sampleCount: frameTimes.length,
767
+ }
768
+ }
769
+ // main-thread mode
770
+ const perf = window.__sootsimPerf
771
+ const a11y = window.__sootsimA11y
772
+ if (!perf && !a11y) return { error: 'no perf globals' }
773
+
774
+ const frameStats = perf?.getFrameStats?.() || {}
775
+ const profile = a11y?.profile?.() || {}
776
+
777
+ // calculate distribution
778
+ const recent = frameStats.recentFrames || []
779
+ const sorted = [...recent].sort((a, b) => a - b)
780
+ const p50 = sorted[Math.floor(sorted.length * 0.5)] || 0
781
+ const p95 = sorted[Math.floor(sorted.length * 0.95)] || 0
782
+ const p99 = sorted[Math.floor(sorted.length * 0.99)] || 0
783
+
784
+ // disable collection
785
+ perf?.disableFrameStats?.()
786
+ window.${Q} = {
787
+ ...(window.${Q} || {}),
788
+ active: false,
789
+ mode: 'main-thread',
790
+ lastSamples: recent.map((ms, index) => [index, ms, 0, 0, 0, 0, 0]),
791
+ stoppedAt: performance.now(),
792
+ }
793
+
794
+ return {
795
+ mode: 'main-thread',
796
+ frames: frameStats.frames || profile.syncCount || 0,
797
+ totalMs: frameStats.totalMs || 0,
798
+ avgMs: frameStats.totalMs && frameStats.frames
799
+ ? frameStats.totalMs / frameStats.frames
800
+ : profile.avgSyncMs || 0,
801
+ maxMs: frameStats.maxMs || profile.maxSyncMs || 0,
802
+ layoutTotalMs: frameStats.layoutTotalMs || 0,
803
+ p50, p95, p99,
804
+ jankFrames: recent.filter(f => f > 16.67).length,
805
+ sampleCount: recent.length,
806
+ }
807
+ })()`});t.error&&(console.error(` error: ${t.error}`),process.exit(1));let s=t.avgMs>0?(1e3/t.avgMs).toFixed(1):"?",r=t.sampleCount>0?(t.jankFrames/t.sampleCount*100).toFixed(1):"0";console.log(` profiling stopped:
808
+ `),console.log(` frames: ${t.frames}`),console.log(` total: ${t.totalMs.toFixed(1)}ms`),console.log(` avg: ${t.avgMs.toFixed(2)}ms (${s} fps)`),console.log(` max: ${t.maxMs.toFixed(2)}ms`),console.log(""),t.layoutAvgMs!==void 0&&(console.log(" breakdown (avg per frame):"),console.log(` layout: ${t.layoutAvgMs.toFixed(2)}ms`),console.log(` render: ${t.renderAvgMs.toFixed(2)}ms`),console.log(` copy: ${t.copyAvgMs.toFixed(2)}ms`),t.auxAvgMs!==void 0&&console.log(` aux: ${t.auxAvgMs.toFixed(2)}ms`),t.otherAvgMs!==void 0&&console.log(` other: ${t.otherAvgMs.toFixed(2)}ms`),console.log("")),console.log(` distribution (${t.sampleCount} samples):`),console.log(` p50: ${t.p50.toFixed(2)}ms`),console.log(` p95: ${t.p95.toFixed(2)}ms`),console.log(` p99: ${t.p99.toFixed(2)}ms`),console.log(` jank: ${t.jankFrames} frames (${r}%) >16.67ms`);break}case"frames":{let t=i[2]?Number(i[2]):50;(!Number.isFinite(t)||t<=0)&&(console.error(` error: expected a positive frame count, got "${i[2]}"`),process.exit(1));let s=await c.send({type:"evaluate",code:`(async () => {
809
+ if (window.__sootsimRenderHost) {
810
+ const session = window.${Q} || {}
811
+ if (session.active) {
812
+ const priorSamples = Array.isArray(session.lastSamples) ? session.lastSamples : []
813
+ const flushedSamples = await window.__sootsimRenderHost.flushSamples()
814
+ const samples = priorSamples.concat(flushedSamples)
815
+ window.__sootsimRenderHost.startSampling()
816
+ window.${Q} = {
817
+ ...session,
818
+ active: true,
819
+ mode: 'render-worker',
820
+ lastSamples: samples,
821
+ lastFlushAt: performance.now(),
822
+ }
823
+ return {
824
+ mode: 'render-worker',
825
+ live: true,
826
+ samples: samples.slice(-${t}),
827
+ }
828
+ }
829
+ return {
830
+ mode: 'render-worker',
831
+ live: false,
832
+ samples: (session.lastSamples || []).slice(-${t}),
833
+ }
834
+ }
835
+ // main-thread mode
836
+ const perf = window.__sootsimPerf
837
+ if (!perf) return { error: 'no __sootsimPerf (try "perf start" first)' }
838
+ const stats = perf.getFrameStats?.() || {}
839
+ return {
840
+ mode: 'main-thread',
841
+ frames: (stats.recentFrames || []).slice(-${t}),
842
+ }
843
+ })()`});if(s.error&&(console.error(` error: ${s.error}`),process.exit(1)),s.mode==="render-worker"){let n=Array.isArray(s.samples)?s.samples:[];if(n.length===0){console.log(` no frame data \u2014 run '${x("perf")} start' first`);break}console.log(` last ${n.length} sampled frames (ms):`),console.log(" total layout render copy aux other t+");for(let[u,m,y,g,$,A,B]of n)console.log(` ${m.toFixed(2).padStart(7)} ${y.toFixed(2).padStart(7)} ${g.toFixed(2).padStart(7)} ${$.toFixed(2).padStart(7)} ${A.toFixed(2).padStart(6)} ${B.toFixed(2).padStart(7)} ${String(u).padStart(5)}`);console.log(""),ke(n.map(u=>u[1])),s.live&&console.log(" sampling continues");break}let r=Array.isArray(s.frames)?s.frames:Array.isArray(s)?s:[];if(r.length===0){console.log(` no frame data \u2014 run '${x("perf")} start' first`);break}console.log(` last ${r.length} frame times (ms):`),console.log(` ${r.map(n=>n.toFixed(2)).join(", ")}`),ke(r);break}case"worst":{let t=i[2]?Number(i[2]):20;(!Number.isFinite(t)||t<=0)&&(console.error(` error: expected a positive frame count, got "${i[2]}"`),process.exit(1));let s=await c.send({type:"evaluate",code:`(async () => {
844
+ if (window.__sootsimRenderHost) {
845
+ const session = window.${Q} || {}
846
+ if (session.active) {
847
+ const priorSamples = Array.isArray(session.lastSamples) ? session.lastSamples : []
848
+ const flushedSamples = await window.__sootsimRenderHost.flushSamples()
849
+ const samples = priorSamples.concat(flushedSamples)
850
+ window.__sootsimRenderHost.startSampling()
851
+ window.${Q} = {
852
+ ...session,
853
+ active: true,
854
+ mode: 'render-worker',
855
+ lastSamples: samples,
856
+ lastFlushAt: performance.now(),
857
+ }
858
+ return {
859
+ mode: 'render-worker',
860
+ live: true,
861
+ samples: samples
862
+ .slice()
863
+ .sort((a, b) => b[1] - a[1])
864
+ .slice(0, ${t}),
865
+ }
866
+ }
867
+ const samples = Array.isArray(session.lastSamples) ? session.lastSamples : []
868
+ return {
869
+ mode: 'render-worker',
870
+ live: false,
871
+ samples: samples
872
+ .slice()
873
+ .sort((a, b) => b[1] - a[1])
874
+ .slice(0, ${t}),
875
+ }
876
+ }
877
+ const perf = window.__sootsimPerf
878
+ if (!perf) return { error: 'no __sootsimPerf (try "perf start" first)' }
879
+ const stats = perf.getFrameStats?.() || {}
880
+ const recent = Array.isArray(stats.recentFrames) ? stats.recentFrames : []
881
+ return {
882
+ mode: 'main-thread',
883
+ frames: recent.slice().sort((a, b) => b - a).slice(0, ${t}),
884
+ }
885
+ })()`});if(s.error&&(console.error(` error: ${s.error}`),process.exit(1)),s.mode==="render-worker"){let n=Array.isArray(s.samples)?s.samples:[];if(n.length===0){console.log(` no frame data \u2014 run '${x("perf")} start' first`);break}console.log(` worst ${n.length} sampled frames (ms):`),console.log(" total layout render copy aux other t+");for(let[u,m,y,g,$,A,B]of n)console.log(` ${m.toFixed(2).padStart(7)} ${y.toFixed(2).padStart(7)} ${g.toFixed(2).padStart(7)} ${$.toFixed(2).padStart(7)} ${A.toFixed(2).padStart(6)} ${B.toFixed(2).padStart(7)} ${String(u).padStart(5)}`);s.live&&(console.log(""),console.log(" sampling continues"));break}let r=Array.isArray(s.frames)?s.frames:Array.isArray(s)?s:[];if(r.length===0){console.log(` no frame data \u2014 run '${x("perf")} start' first`);break}console.log(` worst ${r.length} frame times (ms):`),console.log(` ${r.map(n=>n.toFixed(2)).join(", ")}`);break}case"transition":{let t=i[2];if(!t||!["goHome","appSwitcher","lockScreen"].includes(t)){console.log(`
886
+ ${x("perf")} transition <event> \u2014 profile a shell transition
887
+
888
+ events:
889
+ goHome swipe-to-home animation
890
+ appSwitcher app switcher card animation
891
+ lockScreen lock screen transition
892
+
893
+ note: uses 600ms capture window \u2014 may need --timeout 10000 flag
894
+
895
+ examples:
896
+ ${x("perf")} transition goHome --timeout 10000
897
+ ${x("perf")} transition appSwitcher
898
+ `);break}let r=`sootsim:${t}`;console.log(` profiling ${t} transition...`),console.log(" (use --timeout 10000 if this times out)");let n=await c.send({type:"evaluate",code:`(async () => {
899
+ // only supported in render-worker mode
900
+ if (!window.__sootsimRenderHost) {
901
+ return { error: 'transition profiling requires render-worker mode' }
902
+ }
903
+
904
+ // start sampling
905
+ window.__sootsimRenderHost.startSampling()
906
+
907
+ // give a frame for sampling to start
908
+ await new Promise(r => requestAnimationFrame(() => r(undefined)))
909
+
910
+ // dispatch the shell event
911
+ window.dispatchEvent(new Event('${r}'))
912
+
913
+ // wait 600ms for transition to complete (shell animations are ~300-500ms)
914
+ // using fixed timing avoids complex animation-end detection
915
+ await new Promise(r => setTimeout(r, 600))
916
+
917
+ // flush samples and compute stats
918
+ const samples = await window.__sootsimRenderHost.flushSamples()
919
+ const frameTimes = samples.map(s => s[1])
920
+ const layoutTimes = samples.map(s => s[2])
921
+ const renderTimes = samples.map(s => s[3])
922
+ const copyTimes = samples.map(s => s[4])
923
+ const auxTimes = samples.map(s => s[5] || 0)
924
+ const otherTimes = samples.map(s => s[6] || 0)
925
+ const sorted = [...frameTimes].sort((a, b) => a - b)
926
+ const total = frameTimes.reduce((a, b) => a + b, 0)
927
+ const avg = frameTimes.length > 0 ? total / frameTimes.length : 0
928
+ const max = Math.max(...frameTimes, 0)
929
+ const layoutTotal = layoutTimes.reduce((a, b) => a + b, 0)
930
+ const renderTotal = renderTimes.reduce((a, b) => a + b, 0)
931
+ const copyTotal = copyTimes.reduce((a, b) => a + b, 0)
932
+ const auxTotal = auxTimes.reduce((a, b) => a + b, 0)
933
+ const otherTotal = otherTimes.reduce((a, b) => a + b, 0)
934
+
935
+ return {
936
+ event: '${t}',
937
+ frames: frameTimes.length,
938
+ totalMs: total,
939
+ avgMs: avg,
940
+ maxMs: max,
941
+ layoutTotalMs: layoutTotal,
942
+ renderTotalMs: renderTotal,
943
+ copyTotalMs: copyTotal,
944
+ auxTotalMs: auxTotal,
945
+ otherTotalMs: otherTotal,
946
+ layoutAvgMs: frameTimes.length > 0 ? layoutTotal / frameTimes.length : 0,
947
+ renderAvgMs: frameTimes.length > 0 ? renderTotal / frameTimes.length : 0,
948
+ copyAvgMs: frameTimes.length > 0 ? copyTotal / frameTimes.length : 0,
949
+ auxAvgMs: frameTimes.length > 0 ? auxTotal / frameTimes.length : 0,
950
+ otherAvgMs: frameTimes.length > 0 ? otherTotal / frameTimes.length : 0,
951
+ p50: sorted[Math.floor(sorted.length * 0.5)] || 0,
952
+ p95: sorted[Math.floor(sorted.length * 0.95)] || 0,
953
+ p99: sorted[Math.floor(sorted.length * 0.99)] || 0,
954
+ jankFrames: frameTimes.filter(f => f > 16.67).length,
955
+ samples,
956
+ }
957
+ })()`});if(n.error&&(console.error(` error: ${n.error}`),process.exit(1)),n.warning&&console.log(` warning: ${n.warning}`),n.frames===0){console.log(" no frames captured");break}let u=n.avgMs>0?(1e3/n.avgMs).toFixed(1):"?",m=n.frames>0?(n.jankFrames/n.frames*100).toFixed(1):"0";console.log(` ${t} transition profiled:
958
+
959
+ frames: ${n.frames}
960
+ total: ${n.totalMs.toFixed(1)}ms
961
+ avg: ${n.avgMs.toFixed(2)}ms (${u} fps)
962
+ max: ${n.maxMs.toFixed(2)}ms
963
+
964
+ breakdown (avg per frame):
965
+ layout: ${n.layoutAvgMs?.toFixed(2)||"?"}ms
966
+ render: ${n.renderAvgMs?.toFixed(2)||"?"}ms
967
+ copy: ${n.copyAvgMs?.toFixed(2)||"?"}ms
968
+ aux: ${n.auxAvgMs?.toFixed(2)||"?"}ms
969
+ other: ${n.otherAvgMs?.toFixed(2)||"?"}ms
970
+
971
+ distribution (${n.frames} samples):
972
+ p50: ${n.p50.toFixed(2)}ms
973
+ p95: ${n.p95.toFixed(2)}ms
974
+ p99: ${n.p99.toFixed(2)}ms
975
+ jank: ${n.jankFrames} frames (${m}%) >16.67ms`),Array.isArray(n.samples)&&n.samples.length>0&&(console.log(""),ke(n.samples.map(y=>y[1])));break}default:console.error(` unknown perf subcommand: ${e}`),process.exit(1)}break}case"errors":{let e=i[1];if(e==="clear"){await ze(c),C(l)?D({cleared:!0}):console.log(" error buffer cleared");break}let t=e?Number(e):20,s=await Ke(c,t);if(C(l)){D(s);break}if(s.length===0){console.log(" no errors captured");break}console.log(` ${s.length} error(s):
976
+ `);for(let r of s){let n=new Date(r.timestamp).toLocaleTimeString(),u=r.args.map(m=>typeof m=="object"?JSON.stringify(m):m).join(" ");if(console.log(` [${n}] ${u}`),r.stack){let m=r.stack.split(`
977
+ `).slice(0,3);for(let y of m)console.log(` ${y.trim()}`)}}break}case"warnings":{let e=i[1]?Number(i[1]):20,t=await Ue(c,e);if(C(l)){D(t);break}if(t.length===0){console.log(" no warnings captured");break}console.log(` ${t.length} warning(s):
978
+ `);for(let s of t){let r=new Date(s.timestamp).toLocaleTimeString(),n=s.args.map(u=>typeof u=="object"?JSON.stringify(u):u).join(" ");console.log(` [${r}] ${n}`)}break}case"animations":{let e=await z(c,"listAnimations")??[];if(o.includes("--json")){console.log(JSON.stringify(e,null,2));break}if(e.length===0){console.log(" no active animations");break}console.log(` ${e.length} active animation(s):
979
+ `);for(let t of e){let s=String(t.kind).padEnd(6),r=`${Number(t.from).toFixed(2)}\u2192${Number(t.to).toFixed(2)}`,n=Number(t.current??0).toFixed(2),u=`${Math.round((t.progress??0)*100)}%`,m=`${Math.round(t.elapsedMs??0)}ms`,y=t.loop?" loop":"",g=t.layoutBound?" layout":"";console.log(` #${t.id} ${s} ${r.padEnd(14)} cur=${n.padEnd(7)} ${u.padStart(4)} ${m}${y}${g}`)}break}case"animation":{let e=i[1];(!e||e==="--help"||e==="-h")&&(console.error(` usage: ${x("animation")} <id>`),process.exit(1));let t=Number(e);Number.isFinite(t)||(console.error(` invalid id: ${e}`),process.exit(1));let s=await z(c,"getAnimation",t);console.log(JSON.stringify(s,null,2));break}case"stop-animation":{let e=i[1];(!e||e==="--help"||e==="-h")&&(console.error(` usage: ${x("stop-animation")} <id|all>`),process.exit(1));let t=e==="all"?"all":Number(e);t!=="all"&&!Number.isFinite(t)&&(console.error(` invalid id: ${e}`),process.exit(1));let s=await z(c,"stopAnimation",t);console.log(` stopped ${s??0} animation(s)`);break}case"requests":{let e=i[1];if(e==="clear"){await Ge(c),C(l)?D({cleared:!0}):console.log(" request buffer cleared");break}let t=e==="all",s=t?i[2]:e,r=s?Number(s):20,n=await Ye(c,{failed:!t,limit:r});if(C(l)){D(n);break}if(n.length===0){console.log(t?" no requests captured":" no failed requests captured");break}console.log(` ${n.length} ${t?"request(s)":"failed request(s)"}:
980
+ `);for(let u of n){let m=new Date(u.timestamp).toLocaleTimeString();console.log(` [${m}] ${E(u)}`),u.responseBody?console.log(` ${u.responseBody}`):u.error&&console.log(` ${u.error}`)}break}case"network":{let e=i[1],t=null,s=null,r=!1,n=!1,u=1e3,m=!1,y=!1;for(let k=0;k<l.length;k++){let b=l[k];if(b==="--filter")t=l[k+1]??null,k++;else if(b==="--limit"){let p=Number(l[k+1]);Number.isFinite(p)&&(s=p),k++}else if(b==="--threshold"){let p=Number(l[k+1]);Number.isFinite(p)&&p>0&&(u=p),k++}else b==="--failed"?r=!0:b==="--slow"?n=!0:b==="--tail"||b==="-f"?m=!0:b==="--json"&&(y=!0)}if(e==="clear"){await c.send({type:"evaluate",code:'window.__sootsimObservability?.network.clear(); "cleared"'}),console.log(" network buffer cleared");break}if(e==="get"){let k=i[2];k||(console.error(" usage: sootsim network get <id>"),process.exit(1));let b=await c.send({type:"evaluate",code:`(() => {
981
+ const obs = window.__sootsimObservability;
982
+ if (!obs) return null;
983
+ return obs.network.getSnapshot().find(e => e.id === ${JSON.stringify(k)}) || null;
984
+ })()`});b||(console.error(` no entry with id ${k}`),process.exit(1)),y?console.log(JSON.stringify(b,null,2)):no(b);break}let g=s??(m?200:e?Number(e):20);Number.isFinite(g)||(console.error(` invalid limit: ${e}`),process.exit(1));let $=async()=>{let k=await c.send({type:"evaluate",code:`(() => {
985
+ const obs = window.__sootsimObservability;
986
+ if (!obs) return { ok: false };
987
+ return { ok: true, entries: obs.network.getSnapshot() };
988
+ })()`});if(!k||!k.ok)throw new Error("observability bridge not installed \u2014 is the engine running?");return k.entries??[]},A=k=>{let b=k;if(r&&(b=b.filter(p=>!!p.error||p.status!=null&&p.status>=400)),n&&(b=b.filter(p=>p.durationMs!=null&&p.durationMs>=u)),t){let p=t.toLowerCase();b=b.filter(O=>(O.displayUrl||O.url).toLowerCase().includes(p))}return n&&!m&&(b=[...b].sort((p,O)=>(O.durationMs??0)-(p.durationMs??0))),b};if(!m){let k=await $(),b=A(k).slice(-g);if(y){console.log(JSON.stringify(b,null,2));break}if(b.length===0){k.length===0?console.log(" no network requests captured"):console.log(n?` no requests slower than ${u}ms (${k.length} total \u2014 try --threshold <ms>)`:" no matching requests");break}console.log(n?` ${b.length} request(s) slower than ${u}ms (sorted by duration desc):
989
+ `:` ${b.length} request(s):
990
+ `);for(let p of b)Mt(p);break}console.log(` tailing network (ctrl-c to stop)...
991
+ `);let B=new Set,H=!0,K=()=>{H=!1};process.on("SIGINT",K);try{for(;H;){let k=await $(),b=A(k);for(let p of b)p.durationMs!=null&&(B.has(p.id)||(B.add(p.id),y?console.log(JSON.stringify(p)):Mt(p)));await X(250)}}finally{process.off("SIGINT",K)}break}case"logs":{let e=i[1],t=null,s=null,r=null,n=!1,u=!1,m=!1;for(let b=0;b<l.length;b++){let p=l[b];if(p==="--filter")t=l[b+1]??null,b++;else if(p==="--limit"){let O=Number(l[b+1]);Number.isFinite(O)&&(s=O),b++}else p==="--level"?(r=l[b+1]??null,b++):p==="--tail"||p==="-f"?n=!0:p==="--json"?u=!0:(p==="--internal"||p==="--all")&&(m=!0)}let y=r?new Set(r.split(",").map(b=>b.trim()).filter(b=>b==="log"||b==="info"||b==="warn"||b==="error"||b==="debug")):null;if(e==="clear"){await Ve(c),console.log(" log buffer cleared");break}let g=!u&&process.stdout.isTTY===!0,$=s??(n?500:e?Number(e):50);Number.isFinite($)||(console.error(` invalid limit: ${e}`),process.exit(1));let A=()=>Xe(c),B=b=>Qe(b,{level:y,filter:t,showInternal:m});if(!n){let b=await A(),p=B(b).slice(-$);if(u){console.log(JSON.stringify(p,null,2));break}if(p.length===0){console.log(b.length===0?" no logs captured":" no matching logs");break}console.log(` ${p.length} log(s):
992
+ `);for(let O of p)It(O,g);break}console.log(` tailing logs (ctrl-c to stop)...
993
+ `);let H=new Set,K=!0,k=()=>{K=!1};process.on("SIGINT",k);try{for(;K;){let b=await A(),p=B(b);for(let O of p)H.has(O.id)||(H.add(O.id),u?console.log(JSON.stringify(O)):It(O,g));await X(250)}}finally{process.off("SIGINT",k)}break}default:console.error(` unknown subcommand: ${h}`),process.exit(1)}if(F.has(h)&&!o.includes("--no-wait")&&process.env.SOOTSIM_NO_AUTO_WAIT!=="1"&&await L(c),!U.has(h)&&!C(l))try{await Z(c)}catch{}}catch(e){let t=e instanceof Error?e.message:String(e);if(console.error(` ${h??"inspect"} failed: ${t}`),/^no sim connected( with id .+)?$/.test(t))nt(_);else{try{await Ee(c)}catch{}try{await w({includeTail:!0})}catch{}try{await W({includeTail:!0})}catch{}}process.exit(1)}finally{c.close()}}export{Us as runInspect};