sootsim 0.1.36 → 0.1.37

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 (161) hide show
  1. package/README.md +20 -5
  2. package/dist-cli/bin.js +15 -20
  3. package/dist-cli/chunks/{agent-YZB6D3DR.js → agent-EQRQGSBL.js} +2 -2
  4. package/dist-cli/chunks/{agent-wrapper-VHCVS22I.js → agent-wrapper-AWKZ67GN.js} +10 -10
  5. package/dist-cli/chunks/{assert-AIVCKKLG.js → assert-ZVGELUZB.js} +2 -2
  6. package/dist-cli/chunks/auto-bootstrap-UEOLNAWJ.js +2 -0
  7. package/dist-cli/chunks/beta-4MD7WSI4.js +2 -0
  8. package/dist-cli/chunks/chunk-2ZPJHSIJ.js +11 -0
  9. package/dist-cli/chunks/{chunk-A5BRCXYE.js → chunk-4IO3D5XG.js} +1 -1
  10. package/dist-cli/chunks/chunk-4OHVCGMF.js +2 -0
  11. package/dist-cli/chunks/chunk-56BIMCDH.js +2 -0
  12. package/dist-cli/chunks/chunk-5FLDI6CV.js +66 -0
  13. package/dist-cli/chunks/{chunk-LHDWH7VS.js → chunk-B3RAGRK6.js} +1 -1
  14. package/dist-cli/chunks/{chunk-27P763IZ.js → chunk-BGAPLYMS.js} +2 -2
  15. package/dist-cli/chunks/chunk-CX3ZIPD3.js +3 -0
  16. package/dist-cli/chunks/{chunk-HWCKZXNJ.js → chunk-DSTV2VJT.js} +2 -2
  17. package/dist-cli/chunks/chunk-EDBFYOQB.js +2 -0
  18. package/dist-cli/chunks/chunk-ERLA3F77.js +1 -0
  19. package/dist-cli/chunks/chunk-FCQLQ7NA.js +117 -0
  20. package/dist-cli/chunks/chunk-H2HSOHXN.js +7 -0
  21. package/dist-cli/chunks/chunk-HYYMBXIX.js +2 -0
  22. package/dist-cli/chunks/chunk-JMGDVXAV.js +3 -0
  23. package/dist-cli/chunks/chunk-JMU5IGIU.js +1 -0
  24. package/dist-cli/chunks/chunk-KA5JJCWL.js +1 -0
  25. package/dist-cli/chunks/chunk-L4F4JRKJ.js +348 -0
  26. package/dist-cli/chunks/{chunk-G7XQD4KC.js → chunk-LDWXH43L.js} +2 -2
  27. package/dist-cli/chunks/chunk-PERKPZ7T.js +4 -0
  28. package/dist-cli/chunks/chunk-PN6FWLD4.js +5 -0
  29. package/dist-cli/chunks/chunk-QD7YIVPS.js +64 -0
  30. package/dist-cli/chunks/chunk-QWKO62QM.js +2 -0
  31. package/dist-cli/chunks/{chunk-VFDRZNPN.js → chunk-QXMZNJV5.js} +1 -1
  32. package/dist-cli/chunks/chunk-R77F5J3X.js +4 -0
  33. package/dist-cli/chunks/chunk-RLNIKWFO.js +27 -0
  34. package/dist-cli/chunks/chunk-RX6RHGSI.js +2 -0
  35. package/dist-cli/chunks/{chunk-IJMYFYDZ.js → chunk-S74RCIVB.js} +2 -2
  36. package/dist-cli/chunks/chunk-SK4SOISL.js +1 -0
  37. package/dist-cli/chunks/{chunk-YIO6S3R5.js → chunk-T5L73GJB.js} +1 -1
  38. package/dist-cli/chunks/{chunk-KAXZHEKM.js → chunk-UIQ3536J.js} +1 -1
  39. package/dist-cli/chunks/chunk-URSEYCC5.js +16 -0
  40. package/dist-cli/chunks/chunk-WFXYY3DU.js +3 -0
  41. package/dist-cli/chunks/{chunk-EWSQSALM.js → chunk-WHLHA5R5.js} +4 -4
  42. package/dist-cli/chunks/chunk-WLIVBPPY.js +3 -0
  43. package/dist-cli/chunks/{chunk-CYCXOAVZ.js → chunk-X6BP5JFC.js} +4 -4
  44. package/dist-cli/chunks/chunk-YFXTO4QX.js +5 -0
  45. package/dist-cli/chunks/{chunk-RMW5BO3S.js → chunk-Z5SVSAZO.js} +2 -2
  46. package/dist-cli/chunks/{chunk-OXN2PEB7.js → chunk-Z5X3PITK.js} +3 -3
  47. package/dist-cli/chunks/chunk-ZBOIGEGO.js +5 -0
  48. package/dist-cli/chunks/chunk-ZERYEI3L.js +17 -0
  49. package/dist-cli/chunks/{compat-Y2O2U7FL.js → compat-QQ3OJDBI.js} +2 -2
  50. package/dist-cli/chunks/{config-SRBOFUCI.js → config-LT27SC25.js} +2 -2
  51. package/dist-cli/chunks/control-3BO54QMO.js +2 -0
  52. package/dist-cli/chunks/cpu-profile-XEO3JCVB.js +22 -0
  53. package/dist-cli/chunks/daemon-3J2SAVQZ.js +83 -0
  54. package/dist-cli/chunks/{debug-BIDMW2PE.js → debug-OGQLIH4U.js} +4 -4
  55. package/dist-cli/chunks/demo-app-registry-5RZCXLWB.js +2 -0
  56. package/dist-cli/chunks/detox-Z2OSCIQU.js +49 -0
  57. package/dist-cli/chunks/device-RPTVD25S.js +16 -0
  58. package/dist-cli/chunks/diagnose-LAEXBNOQ.js +41 -0
  59. package/dist-cli/chunks/drivers-PSQUUAYC.js +2 -0
  60. package/dist-cli/chunks/electron-S2463O3P.js +18 -0
  61. package/dist-cli/chunks/flow-34YCVQDB.js +2 -0
  62. package/dist-cli/chunks/hints-E5PXPWFT.js +2 -0
  63. package/dist-cli/chunks/home-paths-F5SGBTRZ.js +2 -0
  64. package/dist-cli/chunks/inspect-EVGMEZ3G.js +1101 -0
  65. package/dist-cli/chunks/install-AM5PTJT3.js +2 -0
  66. package/dist-cli/chunks/{install-desktop-2MYEI4FM.js → install-desktop-ZNWYKTWQ.js} +3 -3
  67. package/dist-cli/chunks/{keys-7PNASIQR.js → keys-5ETF6DYO.js} +2 -2
  68. package/dist-cli/chunks/{launch-JNS47LAQ.js → launch-DHUCNFX6.js} +3 -3
  69. package/dist-cli/chunks/{login-YWZWUHBS.js → login-KDR34JIP.js} +4 -4
  70. package/dist-cli/chunks/{logout-O6SXMSBP.js → logout-R6WIJYCW.js} +2 -2
  71. package/dist-cli/chunks/maestro-ZOOJ2YVH.js +80 -0
  72. package/dist-cli/chunks/{preview-WGKJO5FS.js → preview-YFADHNBD.js} +2 -2
  73. package/dist-cli/chunks/profile-CQSC32HB.js +22 -0
  74. package/dist-cli/chunks/react-QSQD6CJE.js +30 -0
  75. package/dist-cli/chunks/{record-QPWLYH5R.js → record-IWLEYATN.js} +5 -5
  76. package/dist-cli/chunks/{runtime-KEMO2MSB.js → runtime-WKMNKYTN.js} +3 -3
  77. package/dist-cli/chunks/screenshot-VJXHV57I.js +28 -0
  78. package/dist-cli/chunks/screenshot-mode-FA4VQ76K.js +17 -0
  79. package/dist-cli/chunks/screenshots-U4FQXHVK.js +70 -0
  80. package/dist-cli/chunks/server-7WZLM5NQ.js +35 -0
  81. package/dist-cli/chunks/setup-repo-3BXLAX5E.js +2 -0
  82. package/dist-cli/chunks/{skills-MO7BFNVM.js → skills-KO7RCY24.js} +2 -2
  83. package/dist-cli/chunks/start-EBD7T2GW.js +23 -0
  84. package/dist-cli/chunks/store-ONX3EBS4.js +2 -0
  85. package/dist-cli/chunks/telemetry-MFR7TUW7.js +2 -0
  86. package/dist-cli/chunks/{test-XUI3KNNQ.js → test-OSVUG54G.js} +3 -3
  87. package/dist-cli/chunks/three-mode-MDBXZQG4.js +39 -0
  88. package/dist-cli/chunks/timeline-UJOKZKQR.js +22 -0
  89. package/dist-cli/chunks/upload-H2SMWP6T.js +2 -0
  90. package/dist-cli/chunks/what-happened-LFWH74FR.js +15 -0
  91. package/dist-cli/chunks/whoami-CUF56TLP.js +2 -0
  92. package/dist-lib/agent-daemon-client.cjs +4 -1
  93. package/dist-lib/agent-events.cjs +1 -1
  94. package/dist-lib/agent-sessions.cjs +41 -39
  95. package/dist-lib/attached-projects.cjs +30 -28
  96. package/dist-lib/auth/shared-session.cjs +35 -27
  97. package/dist-lib/backend-origin.cjs +1 -1
  98. package/dist-lib/bridge-constants.cjs +1 -1
  99. package/dist-lib/cli-constants.cjs +1 -1
  100. package/dist-lib/config.cjs +6 -2
  101. package/dist-lib/dev-bundle-resolution.cjs +5 -21
  102. package/dist-lib/home-paths.cjs +94 -38
  103. package/dist-lib/host/bridge-host.cjs +2131 -1333
  104. package/dist-lib/host/fetch-proxy-handler.cjs +248 -0
  105. package/dist-lib/index.cjs +21 -21
  106. package/dist-lib/metro.cjs +21 -21
  107. package/dist-lib/profiles.cjs +246 -0
  108. package/dist-lib/render-mode.cjs +1 -1
  109. package/dist-lib/vite-base.cjs +3402 -1640
  110. package/dist-lib/vite.cjs +1 -1
  111. package/package.json +7 -1
  112. package/dist-cli/chunks/auto-bootstrap-MLNTX23H.js +0 -2
  113. package/dist-cli/chunks/chunk-3UIWOHC2.js +0 -62
  114. package/dist-cli/chunks/chunk-5KGFHWVR.js +0 -1
  115. package/dist-cli/chunks/chunk-5QIUJNT3.js +0 -5
  116. package/dist-cli/chunks/chunk-6GGMKFWJ.js +0 -4
  117. package/dist-cli/chunks/chunk-6Z275LCY.js +0 -2
  118. package/dist-cli/chunks/chunk-75LBYBKW.js +0 -11
  119. package/dist-cli/chunks/chunk-DFN3GGH7.js +0 -5
  120. package/dist-cli/chunks/chunk-EBEHZJRG.js +0 -117
  121. package/dist-cli/chunks/chunk-EJLNUMMP.js +0 -3
  122. package/dist-cli/chunks/chunk-FE7UI3MT.js +0 -4
  123. package/dist-cli/chunks/chunk-G663654J.js +0 -1
  124. package/dist-cli/chunks/chunk-GW7XY5KC.js +0 -2
  125. package/dist-cli/chunks/chunk-H2QO4TDV.js +0 -22
  126. package/dist-cli/chunks/chunk-HWFHBMAQ.js +0 -27
  127. package/dist-cli/chunks/chunk-J7CTD37P.js +0 -1
  128. package/dist-cli/chunks/chunk-N32NCVL2.js +0 -3
  129. package/dist-cli/chunks/chunk-NIZBR7EK.js +0 -2
  130. package/dist-cli/chunks/chunk-NYY36OKU.js +0 -308
  131. package/dist-cli/chunks/chunk-PJL25JQV.js +0 -5
  132. package/dist-cli/chunks/chunk-SHO54NET.js +0 -2
  133. package/dist-cli/chunks/chunk-SMVJOWSV.js +0 -16
  134. package/dist-cli/chunks/chunk-TC6V7YFC.js +0 -3
  135. package/dist-cli/chunks/chunk-YLIIVTTQ.js +0 -3
  136. package/dist-cli/chunks/chunk-YR7BGGYE.js +0 -2
  137. package/dist-cli/chunks/chunk-ZEW3RF5Q.js +0 -1
  138. package/dist-cli/chunks/control-PL2V2O6S.js +0 -2
  139. package/dist-cli/chunks/daemon-IZC32PZW.js +0 -50
  140. package/dist-cli/chunks/demo-app-registry-5JFOUU3D.js +0 -2
  141. package/dist-cli/chunks/detox-B3FDOIS3.js +0 -49
  142. package/dist-cli/chunks/device-ZZSI363W.js +0 -16
  143. package/dist-cli/chunks/drivers-S4NGK4DB.js +0 -2
  144. package/dist-cli/chunks/electron-5YFHXEOI.js +0 -15
  145. package/dist-cli/chunks/flow-JJBO6TFY.js +0 -2
  146. package/dist-cli/chunks/hints-G5HBBV2O.js +0 -2
  147. package/dist-cli/chunks/home-paths-VWC3FWA3.js +0 -2
  148. package/dist-cli/chunks/inspect-POOPWUQI.js +0 -1034
  149. package/dist-cli/chunks/install-MP6FHXNZ.js +0 -2
  150. package/dist-cli/chunks/install-dev-desktop-SKH3KEHY.js +0 -100
  151. package/dist-cli/chunks/maestro-CW6XVUKV.js +0 -75
  152. package/dist-cli/chunks/profile-SUOBRPIC.js +0 -22
  153. package/dist-cli/chunks/screenshot-JTY46V7G.js +0 -26
  154. package/dist-cli/chunks/screenshot-mode-7OYBBX6D.js +0 -17
  155. package/dist-cli/chunks/screenshots-QISKC4GD.js +0 -70
  156. package/dist-cli/chunks/server-YSFJAKAV.js +0 -34
  157. package/dist-cli/chunks/setup-repo-LFB3HBEO.js +0 -2
  158. package/dist-cli/chunks/store-6MFL53I4.js +0 -2
  159. package/dist-cli/chunks/telemetry-CN42GMVC.js +0 -2
  160. package/dist-cli/chunks/upload-6FUT7AX5.js +0 -2
  161. package/dist-cli/chunks/whoami-TQFHY42N.js +0 -2
@@ -1,1034 +0,0 @@
1
- /*! sootsim v0.1.36 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
- import{a as U}from"./chunk-N32NCVL2.js";import{a as Ne,b as _e}from"./chunk-YIO6S3R5.js";import{a as Y,b as E,c as C,d as z,e as ie,f as V,g as te,h as Ie,i as Fe,j as fe}from"./chunk-CYCXOAVZ.js";import{a as Te,e as ae}from"./chunk-HWCKZXNJ.js";import{a as me,c as pe,d as xe}from"./chunk-EBEHZJRG.js";import{b as Ae,h as Pe}from"./chunk-75LBYBKW.js";import"./chunk-GW7XY5KC.js";import{a as Me}from"./chunk-OXN2PEB7.js";import"./chunk-YR7BGGYE.js";import"./chunk-PJL25JQV.js";import"./chunk-G663654J.js";import"./chunk-A5BRCXYE.js";import{a as we}from"./chunk-SHO54NET.js";import{c as $e,e as Se,f as ve,h as ke}from"./chunk-SMVJOWSV.js";import"./chunk-6GGMKFWJ.js";import"./chunk-ZEW3RF5Q.js";import"./chunk-5QIUJNT3.js";import"./chunk-LHDWH7VS.js";import{existsSync as mt,mkdirSync as pt,readFileSync as ft,rmSync as Oe,writeFileSync as gt}from"fs";import{tmpdir as yt}from"os";import{dirname as ht,join as bt,resolve as wt}from"path";var oe=1,xt="SOOTSIM_INSPECT_NOTICE_PATH",$t=300*1e3,St=15e3;function Ee(){return wt(process.env[xt]||bt(yt(),"sootsim-inspect-notice-state.json"))}function vt(o,c){return Object.fromEntries(Object.entries(o).filter(([,i])=>typeof i?.signature=="string"&&Number.isFinite(i?.updatedAt)&&c-i.updatedAt<=$t))}function kt(o){let c=Ee();if(!mt(c))return{version:oe,entries:{}};try{let i=JSON.parse(ft(c,"utf8"));return i.version!==oe||!i.entries||typeof i.entries!="object"?(Oe(c,{force:!0}),{version:oe,entries:{}}):{version:oe,entries:vt(i.entries,o)}}catch{return Oe(c,{force:!0}),{version:oe,entries:{}}}}function Tt(o){let c=Ee();pt(ht(c),{recursive:!0}),gt(c,JSON.stringify(o,null,2)+`
3
- `)}function Mt(o,c){let i=c.trim()||"default";return`${o}:${i}`}function ge(o,c,i,d={}){let u=d.nowMs??Date.now(),a=d.cooldownMs??St,h=kt(u),v=Mt(o,c),$=h.entries[v];return $&&$.signature===i&&u-$.updatedAt<a?!1:(h.entries[v]={signature:i,updatedAt:u},Tt(h),!0)}async function Re(o,c={args:[]}){let i=await o.send({type:"evaluate",code:"(async () => await window.__sootsimTest.getNodeCount())()"}),d=typeof i=="number"?i:0;if(E(c.args)){C({nodes:d});return}console.log(` nodes: ${d}`)}function ye(o,c){let i=o.indexOf(c);return i>=0&&i+1<o.length?o[i+1]:null}async function Ce(o){let{bridge:c,args:i,positional:d}=o,u=i.includes("--verbose")||i.includes("-v"),a=E(i),h=u&&!a,v=i.includes("--watch")||i.includes("-w"),$=1e3,I=i.includes("--compact"),y=i.includes("--no-xy"),S=ye(i,"--testid-like"),A=ye(i,"--only"),k=ye(i,"--subtree"),j=d[1],l=j?/[*?]/.test(j):!1,R=!l&&!A?j:void 0,D=A??(l?j:void 0),q=async()=>{await ie(c,{verbose:h});let Z=`(async () => {
4
- const t = window.__sootsimTest
5
- const mainShell = window.SootSim?.bridges?.mainShell
6
- const kb = window.__sootsimKeyboard
7
- if (!t) return { error: 'no test bridge' }
8
-
9
- let shell = null
10
- try {
11
- shell = typeof mainShell?.getState === 'function' ? await mainShell.getState() : null
12
- } catch {}
13
-
14
- const tree = await t.dumpTree(12, ${JSON.stringify({describe:!0,verbose:u,filter:R||"",testIdLike:S||void 0,onlyGlob:D||void 0,subtreeRoot:k||void 0,compact:I,hideXy:y})})
15
- const nodeCount = (await t.getNodeCount?.()) || 0
16
- const keyboard = kb && typeof kb.getLayout === 'function' ? kb.getLayout() : null
17
- return { tree, shell, nodeCount, keyboard }
18
- })()`,x=await c.send({type:"evaluate",code:Z}),J=x?.tree,H=x?.shell,K=x?.keyboard;if(a){C({shell:H,tree:J??"",keyboard:K});return}if(H&&typeof H=="object"){let e=[H.state?`state=${H.state}`:null,H.activeApp?`app=${H.activeApp}`:null,H.showSwitcher?"switcher":null,H.switcherPhase&&H.switcherPhase!=="idle"?`phase=${H.switcherPhase}`:null].filter(Boolean);e.length>0&&console.log(` shell: ${e.join(" ")}`)}if(typeof J=="string"&&J.startsWith("__SUBTREE_NOT_FOUND__:")){let e=J.slice(22);console.log(` subtree root not found: ${e}`),U("subtree-root-not-found",e);return}if(!J){let e=x?.nodeCount??0;console.log(" no matching nodes found"),!(R||S||D||k)&&e<10&&U("app-still-loading",e);return}if(console.log(J),!(R||S||D||k)&&!v&&J.split(`
19
- `).length>=80&&U("describe-use-filters"),K&&K.visible){let e=K.spec,t=[e?.keyboardType?`type=${e.keyboardType}`:null,e?.returnKeyType&&e.returnKeyType!=="default"?`return=${e.returnKeyType}`:null,K.mode!=="letters"?`mode=${K.mode}`:null,K.shifted?"shift":null,K.capsLock?"caps":null,e?.autoCapitalize&&e.autoCapitalize!=="sentences"?`autoCap=${e.autoCapitalize}`:null,K.accessoryBarId?`accessory=${K.accessoryBarId}`:null].filter(Boolean);console.log(`
20
- keyboard: ${t.join(" ")||"visible"}`)}};if(v)for(console.log(` watching... (Ctrl+C to stop)
21
- `);;)console.clear(),await q(),await Y($);else await q()}var Nt=["SOOTSIM_AGENT","CLAUDECODE","CLAUDE_CODE_ENTRYPOINT","CLAUDE_CODE_SESSION_ID","CODEX_THREAD_ID","CURSOR_TRACE_ID","AIDER_MODEL"];function De(){if(process.env.SOOTSIM_AGENT==="0")return!1;for(let o of Nt){let c=process.env[o];if(c&&c.trim()&&c!=="0")return!0}return!1}async function Le(o){let{bridge:c,args:i,effectiveArgs:d,positional:u,inspectUsage:a}=o,h=x=>{let J=d.indexOf(x);return J>=0&&J+1<d.length?d[J+1]:null},v=x=>d.includes(x),$=h("--testid")||h("--test-id"),I=h("--role"),y=h("--type"),S=h("--text"),A=v("--pressable"),k=v("--visible"),j=!$&&!I&&!y&&!S&&!A&&!k?u[1]:null,l=S??j,R,D;$?(D="testid",R=`(async () => {
22
- const t = window.__sootsimTest
23
- return (await t.findByTestId(${JSON.stringify($)})) || (await t.findById(${JSON.stringify($)}))
24
- })()`):I?(D="role",R=`(async () => await window.__sootsimTest.queryAll({ hasRole: ${JSON.stringify(I)}, pruneHidden: true }))()`):y?(D="type",R=`(async () => await window.__sootsimTest.queryAll({ type: ${JSON.stringify(y)}, pruneHidden: true }))()`):A?(D="pressable",R=`(async () => {
25
- const t = window.__sootsimTest
26
- const all = await t.queryAll({ pruneHidden: true })
27
- return all.filter(n => n.pressable)
28
- })()`):k?(D="visible",R=`(async () => {
29
- const all = await window.__sootsimTest.queryAll({ pruneHidden: true })
30
- return all.filter(n => n.layout && n.layout.width > 0 && n.layout.height > 0)
31
- })()`):l?(D="text",R=`(async () => await window.__sootsimTest.findByText(${JSON.stringify(l)}))()`):(console.error(a("find","<text> | --text <t> | --testid <id> | --role <r> | --type <t> | --pressable | --visible")),process.exit(1));let q=await c.send({type:"evaluate",code:R}),ne=E(i),Z=i.includes("--verbose")||i.includes("--dump");if(ne)C(q??null);else if(Array.isArray(q))if(q.length===0){console.log(` no ${D} nodes found`);let x=await c.send({type:"evaluate",code:"(async () => (await window.__sootsimTest?.getNodeCount?.()) || 0)()"});typeof x=="number"&&x<10&&U("app-still-loading",x)}else{console.log(` found ${q.length} node${q.length===1?"":"s"} (${D}):`);for(let x of q.slice(0,20)){let J=x.absolutePosition?`@(${Math.round(x.absolutePosition.x)},${Math.round(x.absolutePosition.y)})`:"",H=x.layout?`${Math.round(x.layout.width)}x${Math.round(x.layout.height)}`:"?x?",K=x.text?` "${x.text.slice(0,30)}"`:"",Q=x.testID?` #${x.testID}`:"",e=x.pressable?" (tap)":"",t=x.accessibilityRole?`[${x.accessibilityRole}]`:x.type;console.log(` ${t}${K}${Q} ${H} ${J}${e}`),Z&&console.log(Be(JSON.stringify(x,null,2)," "))}q.length>20&&console.log(` ... and ${q.length-20} more`)}else if(q==null)console.log(` not found: ${l||$||I||y||""||D}`),$&&U("wait-selector-for-missing-testid",$);else{let x=q;if(x.type&&x.absolutePosition){let J=`@(${Math.round(x.absolutePosition.x)},${Math.round(x.absolutePosition.y)})`,H=x.layout?`${Math.round(x.layout.width)}x${Math.round(x.layout.height)}`:"?x?",K=x.text?` "${x.text.slice(0,40)}"`:"",Q=x.testID?` #${x.testID}`:"",e=x.pressable?" (tap)":"",t=x.accessibilityRole?`[${x.accessibilityRole}]`:x.type;console.log(` ${t}${K}${Q} ${H} ${J}${e}`),Z&&console.log(Be(JSON.stringify(x,null,2)," "))}else console.log(JSON.stringify(q,null,2))}}function Be(o,c){return o.split(`
32
- `).map(i=>c+i).join(`
33
- `)}async function je(o,c={}){let i=await o.send({type:"evaluate",code:`(() => {
34
- const kb = window.__sootsimKeyboard
35
- if (!kb || typeof kb.getLayout !== 'function') {
36
- return { error: 'keyboard bridge getLayout() not available' }
37
- }
38
- return kb.getLayout()
39
- })()`});if("error"in i&&(console.error(i.error),process.exit(1)),c.json){console.log(JSON.stringify(i,null,2));return}let{visible:d,spec:u,mode:a,shifted:h,capsLock:v,accessoryBarId:$}=i,I=[];I.push(`keyboard: ${d?"visible":"hidden"}`),u?(I.push(` type: ${u.keyboardType}`),I.push(` returnKey: ${u.returnKeyType}`),I.push(` autoCap: ${u.autoCapitalize}`),I.push(` autoCorrect: ${u.autoCorrect?"on":"off"}`),I.push(` appearance: ${u.keyboardAppearance}`),u.secureTextEntry&&I.push(" secureTextEntry: true"),u.enablesReturnKeyAutomatically&&I.push(` return: ${u.currentTextIsEmpty?"disabled (empty)":"enabled"}`)):I.push(" spec: <none> (shown via dev-tools with no TextInput)"),I.push(` mode: ${a}${h?" (shifted)":""}${v?" (caps)":""}`),$&&I.push(` accessoryBar: ${$}`),console.log(I.join(`
40
- `))}async function Je(o){let c=await o.bridge.listBrowsers();if(E(o.args)){C(c.map(i=>({...i,active:i.id===o.browserId})));return}Pe(c,o.browserId)}function X(o){return o<1024?`${o}B`:o<1024*1024?`${(o/1024).toFixed(1)}KB`:`${(o/1024/1024).toFixed(1)}MB`}function le(o,c){return c<=0?"?":`${(o/c*100).toFixed(0)}%`}async function He(o,c={args:[]}){let d=await o.send({type:"evaluate",code:`(async () => {
41
- const host = window.__sootsimRenderHost
42
- const stats = host?.queryStats ? await host.queryStats() : null
43
- const hostMem = performance.memory
44
- ? {
45
- usedJSHeapSize: performance.memory.usedJSHeapSize,
46
- totalJSHeapSize: performance.memory.totalJSHeapSize,
47
- jsHeapSizeLimit: performance.memory.jsHeapSizeLimit,
48
- }
49
- : null
50
- return {
51
- imageLoader: stats?.memory?.imageLoader ?? null,
52
- workerHeap: stats?.memory?.workerHeap ?? null,
53
- hostHeap: hostMem,
54
- }
55
- })()`})??{};if(E(c.args)){C(d);return}if(console.log(" memory:"),d.imageLoader){let u=d.imageLoader;console.log(" image-loader cache"),console.log(` entries: ${u.cacheEntries} / ${u.cacheMaxEntries} (${le(u.cacheEntries,u.cacheMaxEntries)})`),console.log(` pixel bytes: ${X(u.cachePixelBytes)} / ${X(u.cachePixelBudget)} (${le(u.cachePixelBytes,u.cachePixelBudget)})`),console.log(` pending: ${u.pendingFetches} fetches, ${u.pendingBytes} bytes`),console.log(` failed uris: ${u.failedUris}`),console.log(` snapshots: ${u.snapshots}`),console.log(` camera frames: ${u.cameraFrames}`)}else console.log(" image-loader cache: not available (engine pre-rebuild?)");if(d.workerHeap){let u=d.workerHeap;console.log(" worker heap (chrome only)"),console.log(` used: ${X(u.usedJSHeapSize)} / ${X(u.jsHeapSizeLimit)} (${le(u.usedJSHeapSize,u.jsHeapSizeLimit)})`),console.log(` total: ${X(u.totalJSHeapSize)}`)}if(d.hostHeap){let u=d.hostHeap;console.log(" host heap (chrome only)"),console.log(` used: ${X(u.usedJSHeapSize)} / ${X(u.jsHeapSizeLimit)} (${le(u.usedJSHeapSize,u.jsHeapSizeLimit)})`),console.log(` total: ${X(u.totalJSHeapSize)}`)}}function se(o){let c=o.indexOf("--testid");if(c>=0&&o[c+1])return{mode:"testid",value:o[c+1]};let i=o.indexOf("--test-id");if(i>=0&&o[i+1])return{mode:"testid",value:o[i+1]};let d=o.indexOf("--text");return d>=0&&o[d+1]?{mode:"text",value:o[d+1]}:null}async function ce(o,c){let i=JSON.stringify(c.value),d=c.mode==="testid"?`(await t.findByTestId(${i})) || (await t.findById(${i}))`:`await t.findByText(${i})`;return await o.send({type:"evaluate",code:`(async () => {
56
- const t = window.__sootsimTest
57
- if (!t) return null
58
- const n = ${d}
59
- if (!n || !n.absolutePosition || !n.layout) return null
60
- const resolved =
61
- typeof n.nodeId === 'number' && typeof t.resolveTapTarget === 'function'
62
- ? await t.resolveTapTarget(n.nodeId)
63
- : null
64
- const cx =
65
- typeof resolved?.cx === 'number'
66
- ? resolved.cx
67
- : n.absolutePosition.x + (n.layout.width || 0) / 2
68
- const cy =
69
- typeof resolved?.cy === 'number'
70
- ? resolved.cy
71
- : n.absolutePosition.y + (n.layout.height || 0) / 2
72
- return { x: cx, y: cy, testID: n.testID, text: n.text }
73
- })()`})??null}async function qe(o,c={}){let i=await o.send({type:"evaluate",code:`(async () => {
74
- const test = window.__sootsimTest
75
- const kb = window.__sootsimKeyboard
76
- // host-side __sootsimTest is a Proxy that forwards every call to the
77
- // tenant worker \u2014 every method returns a Promise, so we must await.
78
- const navSnap =
79
- test && typeof test.getNavigationSnapshot === 'function'
80
- ? await test.getNavigationSnapshot()
81
- : null
82
- const keyboard =
83
- kb && typeof kb.getLayout === 'function'
84
- ? (() => {
85
- const layout = kb.getLayout()
86
- return layout ? {
87
- visible: layout.visible,
88
- mode: layout.mode,
89
- spec: layout.spec
90
- ? {
91
- keyboardType: layout.spec.keyboardType,
92
- returnKeyType: layout.spec.returnKeyType,
93
- }
94
- : null,
95
- } : null
96
- })()
97
- : null
98
- return { nav: navSnap, keyboard }
99
- })()`}),d=i?.nav??null,u=i?.keyboard??null,a=await V(o,500).catch(()=>null);if(c.json){console.log(JSON.stringify({shell:a??null,nav:d,keyboard:u},null,2));return}let h=[];if(a){let v=a.activeApp??a.state??"<none>",$=a.showSwitcher?" (app switcher open)":"",I=typeof a.launchProgress=="number"&&a.launchProgress<.98?` launching (${Math.round(a.launchProgress*100)}%)`:"";h.push(`shell: ${v}${$}${I}`)}else h.push("shell: <unavailable>");if(d){let v=d.transitionPhase!=="idle"?` (${d.transitionPhase}, ${d.activeTransitionCount} active)`:"";if(h.push(`nav: phase=${d.transitionPhase}${v}`),d.screens.length===0)h.push(" <no registered screens \u2014 app may not use react-native-screens>");else for(let $ of d.screens){let I=$.isActive?"\u25B6":" ",y=$.routeName?` ${$.routeName}`:"",S=$.headerHeight>0?` header=${$.headerHeight}`:"",A=$.largeTitleState&&$.largeTitleState!=="expanded"?` large-title=${$.largeTitleState}`:"";h.push(` ${I} #${$.id}${y}${S}${A}`)}}else h.push("nav: <runtime not available>");if(u&&u.visible){let v=u.spec?.keyboardType??"default",$=u.spec?.returnKeyType??"default";h.push(`keyboard: visible (${v}, return=${$}, mode=${u.mode??"?"})`)}else h.push("keyboard: hidden");console.log(h.join(`
100
- `))}async function ee({bridge:o,maxMs:c,pollMs:i=50,stablePolls:d=3,strict:u=!1}){let a=await o.send({type:"evaluate",code:`(async () => {
101
- const start = Date.now()
102
- const deadline = start + ${Math.max(0,Math.round(c))}
103
- const pollMs = ${Math.max(1,Math.round(i))}
104
- const requiredStablePolls = ${Math.max(1,Math.round(d))}
105
- const strict = ${u?"true":"false"}
106
- const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
107
- const readSnapshot = async () => {
108
- let animating = false
109
- try {
110
- const stats = await window.__sootsimRenderHost?.queryStats?.()
111
- if (stats) {
112
- animating =
113
- stats.hasActiveAnims === true ||
114
- stats.hasActiveNativeAnimations === true ||
115
- stats.hasPendingAnimationFrames === true
116
- }
117
- } catch {}
118
- const root = window.__sootsimRoot
119
- const nodes = []
120
- if (root) {
121
- const walk = (n) => {
122
- if (n.layout && n.layout.width > 0) {
123
- nodes.push(Math.round(n.layout.x) + ',' + Math.round(n.layout.y) + ',' + Math.round(n.layout.width))
124
- }
125
- for (const c of n.children || []) walk(c)
126
- }
127
- walk(root)
128
- }
129
- return { layout: nodes.join(';'), animating }
130
- }
131
-
132
- let lastLayout = ''
133
- let stable = 0
134
- while (Date.now() < deadline) {
135
- const snapshot = await readSnapshot()
136
- const strictOk = !strict || !snapshot.animating
137
- if (strictOk && snapshot.layout === lastLayout) {
138
- stable++
139
- if (stable >= requiredStablePolls) {
140
- return { settled: true, elapsed: Date.now() - start }
141
- }
142
- } else {
143
- stable = 0
144
- }
145
- lastLayout = snapshot.layout
146
- await sleep(pollMs)
147
- }
148
- return { settled: false, elapsed: Date.now() - start }
149
- })()`}),{elapsed:h,settled:v}=a??{};return{elapsed:typeof h=="number"?h:c,settled:v===!0}}async function We(o){let{bridge:c,args:i,positional:d}=o,u=d[1]?Number(d[1])*1e3:3e3,a=i.includes("--strict"),{elapsed:h,settled:v}=await ee({bridge:c,maxMs:u,strict:a});console.log(v?` settled in ${h}ms`:` timed out after ${h}ms (may still be animating)`)}async function ze(o){let c=o.positional[1]?Number(o.positional[1]):.5;(!Number.isFinite(c)||c<0)&&(console.error(o.inspectUsage("sleep","[seconds]")),process.exit(1)),await Y(c*1e3),console.log(` slept ${c}s`)}async function Ke(o){let{bridge:c,args:i,positional:d}=o,u=d[1]?Number(d[1]):5,a=await c.send({type:"evaluate",code:`(async () => await window.__sootsimTest.dumpTree(${u}))()`});if(E(i)){C({depth:u,tree:a??null});return}console.log(typeof a=="string"?a:JSON.stringify(a,null,2))}async function Ue(o,c={args:[]}){let i=await o.send({type:"evaluate",code:"window.location.href"}),d=typeof i=="string"?i:"";if(E(c.args)){C({url:d});return}console.log(d)}async function Ye(o){let{wsPort:c,commandTimeoutMs:i,browserId:d,positional:u}=o,a=u[1]?Number(u[1]):30,h=Math.max(1e3,(Number.isFinite(a)?a:30)*1e3),v=Math.max(1,Math.ceil(h/500));console.log(" waiting for browser reconnect...");let $=await Ie(c,i,d,{attempts:v});$||(console.error(" timed out waiting for browser reconnect"),process.exit(1)),$.bridge.close(),ae({source:"inspect wait",step:{wait:h},summary:`wait ${Math.round(h/1e3)}s`}),console.log(` ready: ${$.count} nodes`)}async function Ge(o){let{bridge:c,args:i}=o,d=i.includes("--strict"),u=i.indexOf("--max-ms"),a=u>=0&&i[u+1]?Math.max(100,Number(i[u+1])):3e3,{elapsed:h,settled:v}=await ee({bridge:c,maxMs:a,strict:d});v?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 Xe(o){let{bridge:c,args:i}=o,d=2e4,u=i.indexOf("--max-ms");u>=0&&i[u+1]&&(d=Math.max(100,Number(i[u+1])));let a=Date.now(),h=a+d,v=`(async () => {
150
- const t = window.__sootsimTest
151
- let nodes = 0
152
- try { nodes = (await t?.getNodeCount?.()) || 0 } catch {}
153
- return {
154
- flag: (window).__sootsimExternalAppReady,
155
- at: (window).__sootsimExternalAppReadyAt || 0,
156
- nodes,
157
- }
158
- })()`,$={flag:void 0,at:0,nodes:0};for(;Date.now()<h;){try{$=await c.send({type:"evaluate",code:v})??$}catch{}if($.flag===!0){console.log(` ready in ${Date.now()-a}ms: ${$.nodes} nodes (flag)`);return}await new Promise(I=>setTimeout(I,150))}console.error(` \u26A0 wait ready timed out after ${Date.now()-a}ms \u2014 guest app did not emit sootsim:externalAppReady (nodes: ${$.nodes})`),process.exit(1)}async function Ve(o){let{bridge:c,args:i,positional:d,inspectUsage:u}=o,a=d[1];a||(console.error(u("wait selector","<testid> [--max-ms 5000]")),process.exit(1));let h=i.indexOf("--max-ms"),v=h>=0&&i[h+1]?Math.max(100,Number(i[h+1])):5e3,$=await c.send({type:"evaluate",code:`(async () => {
159
- const start = Date.now()
160
- const deadline = start + ${v}
161
- const t = window.__sootsimTest
162
- const find = async () => {
163
- try {
164
- return (await t?.findByTestId?.(${JSON.stringify(a)})) ||
165
- (await t?.findById?.(${JSON.stringify(a)})) || null
166
- } catch {}
167
- return null
168
- }
169
- while (Date.now() < deadline) {
170
- const node = await find()
171
- if (node && node.layout && node.layout.width > 0 && node.layout.height > 0) {
172
- return { found: true, node, elapsed: Date.now() - start }
173
- }
174
- await new Promise((r) => setTimeout(r, 80))
175
- }
176
- return { found: false, elapsed: Date.now() - start }
177
- })()`}),{found:I,node:y,elapsed:S}=$??{};if(I&&y){let A=y.absolutePosition?`@(${Math.round(y.absolutePosition.x)},${Math.round(y.absolutePosition.y)})`:"",k=y.layout?`${Math.round(y.layout.width)}x${Math.round(y.layout.height)}`:"?x?";console.log(` found #${a} in ${S}ms ${k} ${A}`)}else console.error(` \u26A0 wait selector #${a} timed out after ${S??v}ms`),process.exit(1)}function nt(o){return o==null?"\u2014":o<1024?`${o}B`:o<1024*1024?`${(o/1024).toFixed(1)}K`:`${(o/1024/1024).toFixed(1)}M`}function rt(o){return o==null?" \u2026":o<1e3?`${o}ms`.padStart(5):`${(o/1e3).toFixed(2)}s`.padStart(5)}function It(o){return o.error?"err":o.status==null?" \u2026 ":String(o.status)}function Ze(o){let c=new Date(o.startTs).toLocaleTimeString(),i=It(o).padEnd(3),d=o.method.padEnd(5),u=nt(o.size).padStart(6),a=rt(o.durationMs);console.log(` [${c}] ${i} ${d} ${u} ${a} ${o.displayUrl}`),o.error&&console.log(` error: ${o.error}`)}function Ft(o){let c=[["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",rt(o.durationMs).trim()],["size",nt(o.size)],["content-type",o.type??"\u2014"]];for(let[i,d]of c)console.log(` ${i.padEnd(13)} ${d}`)}var At={error:"\x1B[31m",warn:"\x1B[33m",info:"\x1B[36m",debug:"\x1B[35m",log:"\x1B[37m"},Qe="\x1B[0m",Pt="\x1B[2m";function et(o,c){let i=new Date(o.ts).toLocaleTimeString(),d=o.level.toUpperCase().padEnd(5),u=o.args.join(" ");if(c){let a=At[o.level];console.log(` ${Pt}[${i}]${Qe} ${a}${d}${Qe} ${u}`)}else console.log(` [${i}] ${d} ${u}`);if(o.stack&&o.level==="error"){let a=o.stack.split(`
178
- `).slice(0,5);for(let h of a)console.log(` ${h.trim()}`)}}var G="__sootsimCliPerf",Ot=120;async function tt(o,c){let i=o.find((A,k)=>o[k-1]==="--id"),d=o.find((A,k)=>o[k-1]==="--text");if(i||d){let A=await c.send({type:"evaluate",code:Ne({id:i,text:d})});if(!A)throw new Error(i?`no node with id "${i}"`:`no node matching text "${d}"`);let{x:k,y:j,w:l,h:R}=A;return{x:k,y:j,w:l,h:R}}let u=o.find((A,k)=>o[k-1]==="--area");if(u){let A=u.split(",").map(D=>Number(D.trim()));if(A.length!==4||A.some(D=>!Number.isFinite(D)))throw new Error(`--area expects x,y,w,h (got "${u}")`);let[k,j,l,R]=A;return{x:k,y:j,w:l,h:R}}let a=A=>{let k=o.find((l,R)=>o[R-1]===A);if(k==null)return null;let j=Number(k);return Number.isFinite(j)?j:null},h=a("--x"),v=a("--y"),$=a("--w"),I=a("--h");if(h!=null||v!=null||$!=null||I!=null)return{x:h??0,y:v??0,w:$??1,h:I??1};let S=o.filter((A,k)=>k>0&&!A.startsWith("-")&&o[k-1]!=="--output"&&o[k-1]!=="--area"&&o[k-1]!=="--id"&&o[k-1]!=="--text"&&o[k-1]!=="--x"&&o[k-1]!=="--y"&&o[k-1]!=="--w"&&o[k-1]!=="--h").map(Number).filter(A=>Number.isFinite(A));if(S.length>=2){let[A,k,j=1,l=1]=S;return{x:A,y:k,w:j,h:l}}return null}function he(o){let c={"<8":0,"8-12":0,"12-16":0,"16-20":0,"20-33":0,">33":0};for(let i of o)i<8?c["<8"]++:i<12?c["8-12"]++:i<16?c["12-16"]++:i<20?c["16-20"]++:i<33?c["20-33"]++:c[">33"]++;console.log(" histogram:");for(let[i,d]of Object.entries(c)){let u="\u2588".repeat(Math.ceil(d/o.length*40));console.log(` ${i.padEnd(6)} ${u} ${d}`)}}async function de(o,c,i){let d=Date.now()+c,u=await V(o,c);for(;;){if(i(u))return{settled:!0,state:u};if(Date.now()>=d)return{settled:!1,state:u};await Y(16),u=await V(o)}}async function be(o){return o.send({type:"evaluate",code:`(async () => {
179
- const kb = window.__sootsimKeyboard
180
- const test = window.__sootsimTest
181
- if (!kb) return { error: 'keyboard bridge not available' }
182
- const visible = kb.isVisible()
183
- const mode = kb.getMode()
184
- let focused = null
185
- if (test && typeof test.getFocusedNode === 'function') {
186
- try {
187
- focused = await test.getFocusedNode()
188
- } catch {}
189
- }
190
- let runtimeSnapshot = null
191
- if (test && typeof test.getFocusKeyboardSnapshot === 'function') {
192
- try {
193
- runtimeSnapshot = await test.getFocusKeyboardSnapshot()
194
- } catch {}
195
- }
196
- return {
197
- visible,
198
- mode,
199
- focusedInput: focused ? {
200
- nodeId: focused.nodeId ?? null,
201
- testID: focused.testID || null,
202
- id: focused.id || null,
203
- placeholder: focused.placeholder || null,
204
- text: focused.text || null,
205
- } : null,
206
- phase: runtimeSnapshot?.keyboard?.phase ?? null,
207
- frame: runtimeSnapshot?.keyboard?.frame ?? null,
208
- focusedRect: runtimeSnapshot?.focused?.rect ?? null,
209
- }
210
- })()`})}async function Et(o,c=600){let i=Date.now()+c;for(;Date.now()<=i;){let d=await be(o);if(d.visible)return d;await Y(30)}return be(o)}async function ue(o,c){let i=await be(o);if(i.visible)return i;console.error(` ${c} 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 ot(o,c,i){return c==="appearance"?o.send({type:"evaluate",code:`(async () => {
211
- const requested = ${JSON.stringify(i??"toggle")}
212
- const rootBg = (document.documentElement?.style?.background || '').toLowerCase()
213
- const inferredCurrent = rootBg.includes('33') ? 'dark' : 'light'
214
- let next = requested
215
- if (requested === 'toggle') {
216
- next = inferredCurrent === 'dark' ? 'light' : 'dark'
217
- }
218
- // engine accepts 'auto' since the schema picker landed; pass through.
219
- window.postMessage({ type: 'soot-action', action: 'set-appearance', value: next }, '*')
220
- const applied = next === 'auto'
221
- ? (window.matchMedia?.('(prefers-color-scheme: dark)')?.matches ? 'dark' : 'light')
222
- : next
223
- return { ok: true, requested, value: next, applied }
224
- })()`}):o.send({type:"evaluate",code:`(async () => {
225
- window.dispatchEvent(new CustomEvent(${JSON.stringify(c==="lock"?"sootsim:toggleLock":"sootsim:shake")}))
226
- return { ok: true, action: ${JSON.stringify(c)} }
227
- })()`})}function Rt(o){let c={Enter:"return",NumpadEnter:"return",Backspace:"delete",Delete:"delete",Space:"space",ShiftLeft:"shift",ShiftRight:"shift"};if(c[o])return c[o];let i=o.match(/^Digit([0-9])$/);if(i)return i[1];let d=o.match(/^Key([A-Z])$/);return d?d[1].toLowerCase():null}function Ct(o){if(typeof o!="string")return null;let c=o.replace(/\s+/g," ").trim();return c?c.slice(0,80):null}function at(...o){for(let c of o){if(typeof c!="string")continue;let i=c.trim();if(i)return i}return null}async function L(o,c,i){ae({source:o,step:c,summary:i})}function Dt(o,c,i){if(!i||i.hit===!1)return null;let d=at(i.responderTestID,i.testID);if(d)return{step:{tapOn:{id:d}},summary:`tap #${d}`};let u=Ct(i.text);return u?{step:{tapOn:u},summary:`tap "${u}"`}:{step:{tapAtCoords:{x:o,y:c}},summary:`tap @${Math.round(o)},${Math.round(c)}`}}function st(o,c,i){let d=at(c?.testID,c?.id);return d?{step:{tapOn:{id:d}},summary:`tap #${d}`}:i==="id"?{step:{tapOn:{id:o}},summary:`tap #${o}`}:{step:{tapOn:o},summary:`tap "${o}"`}}async function rs(o,c){let i=o[0]==="get"||o[0]==="do"||o[0]==="debug"||o[0]==="wait"?o[0]:null,d=i?o.slice(1):o,u=$e(d,{port:c.port,commandTimeoutMs:c.timeoutMs,stripBooleanFlags:["--verbose","-v","--help","-h","--clear-state","--json","--all","--watch","-w","--strict","--no-wait","--dump","--failed","--tail","-f","--internal"],stripValueFlags:["--output","--nth","--index","--testid","--test-id","--text","--max-ms","--filter","--limit","--level"]}),a=u.positional,h=a[0],v=i==="get"||i==="do"||i==="debug"||i==="wait"?i:"inspect",$=typeof d[0]=="string"&&xe.has(d[0]),I=$?d[0]:null,y=e=>$&&e===d[0]?`sootsim ${e}`:`sootsim ${v} ${e}`,S=(e,t)=>` usage: ${y(e)}${t?` ${t}`:""}`;if(!h||o.includes("--help")||o.includes("-h")){let e={bridgePort:7668,defaultShellUrl:we};if(v==="do"||v==="get"||v==="debug"||v==="wait"){let r=me(v,e);r&&(console.log(`${r}
228
- `),process.exit(0))}if(I==="shell"){let r=pe("shell",e);r&&(console.log(`${r}
229
- `),process.exit(0))}let t=pe("inspect",e),s=["do","get","debug","wait"].map(r=>me(r,e)).filter(r=>r!=null).join(`
230
-
231
- `);console.log(`${t??""}
232
-
233
- ${s}
234
- `),process.exit(0)}let A=u.wsPort,k=u.browserId,j=u.commandTimeoutMs;if(h==="list"&&d.some(e=>e==="--drivers"||e==="-D")){let{buildDriverListRows:e}=await import("./drivers-S4NGK4DB.js"),t=e();console.log(` available drivers (${t.length}):
235
- `);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 m=n.available?"\u2713":"\u2717",p=n.id.padEnd(s),b=n.kind.padEnd(r);console.log(` ${m} ${p} ${b} ${n.description}`),n.available&&n.detail?console.log(` ${n.detail}`):!n.available&&n.reason&&console.log(` unavailable: ${n.reason}`)}return}let l=Se(u),R=k||"default",D=new Set(["errors","warnings","requests","js","eval","reload","globals","perf","list","wait","sleep"]);function q(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 ne(e){let t=De()?1200:350;try{let{settled:s,elapsed:r}=await ee({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.
236
- `)}catch{}}async function Z(){try{return await l.send({type:"evaluate",code:`(() => ({
237
- console: window.__sootsimConsole?.count?.() || null,
238
- requests: window.__sootsimTest?.getRequestCounts?.() || null,
239
- }))()`})||{console:null,requests:null}}catch{return{console:null,requests:null}}}async function x(e={}){let t=e.counts!==void 0?e.counts:await z(l,"getRequestCounts");if(!t||typeof t!="object")return;let s=Math.max(0,Number(t.failed)||0);if(s===0||!e.includeTail&&!ge("requests",R,String(s))||(console.log(`
240
- network: ${s} failed request${s===1?"":"s"}`),console.log(` inspect: ${y("requests")} 5`),!e.includeTail))return;let r=await z(l,"getFailedRequests",5);if(!(!Array.isArray(r)||r.length===0)){console.log(`
241
- recent failed requests:
242
- `);for(let n of r){let m=new Date(n.timestamp).toLocaleTimeString();console.log(` [${m}] ${q(n)}`),n.responseBody?console.log(` ${n.responseBody}`):n.error&&console.log(` ${n.error}`)}}}async function J(e={}){let t=e.counts!==void 0?e.counts:await l.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&&!ge("console",R,`${r}:${n}`))return;let m=[];if(r>0&&m.push(`${r} console error${r===1?"":"s"}`),n>0&&m.push(`${n} console warning${n===1?"":"s"}`),console.log(`
243
- console: ${m.join(", ")}`),console.log(` inspect: ${y("errors")} 5`),n>0&&console.log(` inspect: ${y("warnings")} 5`),!e.includeTail||r===0)return;let p=await l.send({type:"evaluate",code:"window.__sootsimConsole?.getErrors?.(5) || []"});if(!(!Array.isArray(p)||p.length===0)){console.log(`
244
- recent console errors:
245
- `);for(let b of p){let f=new Date(b.timestamp).toLocaleTimeString(),w=Array.isArray(b.args)?b.args.map(O=>typeof O=="object"?JSON.stringify(O):String(O)).join(" "):String(b);console.log(` [${f}] ${w}`)}}}let H=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"]),K=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"]),Q=(o.includes("--verbose")||o.includes("-v"))&&!o.includes("--json");v==="do"&&h==="shell"&&(console.error(" `sootsim do shell` was removed. use `sootsim shell ...` instead."),process.exit(1)),H.has(h)&&await ve(l),K.has(h)&&await ie(l,{verbose:Q});try{switch(h){case"list":{await Je({bridge:l,browserId:k,args:d});break}case"tree":{await Ke({bridge:l,args:d,positional:a});break}case"a11y":{let e=a[1]?Number(a[1]):5,t=await l.send({type:"evaluate",code:`(async () => {
246
- const t = window.__sootsimTest
247
- if (!t) return []
248
- const all = await t.queryAll({ pruneHidden: true })
249
- return all.filter(n => {
250
- // skip zero-size nodes
251
- if (!n.layout || n.layout.width <= 0 || n.layout.height <= 0) return false
252
- // keep nodes with explicit accessibility roles or labels
253
- if (n.accessibilityRole) return true
254
- if (n.accessibilityHint) return true
255
- if (n.isTextInput) return true
256
- if (n.pressable) return true
257
- // keep text leaf nodes
258
- if (n.type === 'text' && n.text) return true
259
- // keep views with intentional labels (not auto-derived)
260
- if (n.accessibilityLabel && n.accessibilityLabel.length <= 30
261
- && n.accessibilityLabel !== n.text) return true
262
- // skip container views without role (just concatenated child text)
263
- return false
264
- }).map(n => ({
265
- role: n.accessibilityRole || (n.pressable ? 'button' : n.isTextInput ? 'textfield' : n.type === 'text' ? 'statictext' : 'none'),
266
- label: n.accessibilityLabel || n.text || null,
267
- hint: n.accessibilityHint || null,
268
- state: n.accessibilityState || null,
269
- testID: n.testID || null,
270
- position: n.absolutePosition ? { x: Math.round(n.absolutePosition.x), y: Math.round(n.absolutePosition.y) } : null,
271
- size: n.layout ? { w: Math.round(n.layout.width), h: Math.round(n.layout.height) } : null,
272
- }))
273
- })()`});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):
274
- `);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 Le({bridge:l,args:o,effectiveArgs:d,positional:a,inspectUsage:S});break}case"count":{await Re(l,{args:d});break}case"keyboard":{await je(l,{json:o.includes("--json")});break}case"screens":{await qe(l,{json:o.includes("--json")});break}case"memory":{await He(l,{args:d});break}case"wait":{await Ye({wsPort:A,commandTimeoutMs:j,browserId:k,positional:a});break}case"sleep":{await ze({positional:a,inspectUsage:S});break}case"settle":{await We({bridge:l,args:o,positional:a});break}case"ready":{await Xe({bridge:l,args:o});break}case"idle":{await Ge({bridge:l,args:o,positional:a});break}case"selector":{await Ve({bridge:l,args:o,positional:a,inspectUsage:S});break}case"layout":{let e=a[1];e||(console.error(S("layout","<id>")),process.exit(1));let t=await l.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((b,f)=>o[f-1]==="--output")||"/tmp/sootsim-inspect.png",s=await tt(o,l),r={type:"screenshot"};s&&(r.crop=s);let m=(await l.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(m,"base64")),console.log(` saved: ${t}`);break}case"sample-color":{let e=await tt(o,l);e||(console.error(S("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 l.send({type:"evaluate",code:_e(e)});if(o.includes("--json"))console.log(JSON.stringify(t,null,2));else{let{r:s,g:r,b:n,a:m,hex:p,samples:b}=t,f=e.w===1&&e.h===1?`@(${e.x},${e.y})`:`@(${e.x},${e.y}) ${e.w}x${e.h}`;console.log(` ${p} rgba(${s}, ${r}, ${n}, ${m}) ${f} ${b} samples`)}break}case"node":{let e=a[1];e||(console.error(S("node","<matcher>")),console.error(" resolves testID, id, then text \u2014 dumps full node info as JSON"),process.exit(1));let t=await l.send({type:"evaluate",code:`(async () => {
275
- const t = window.__sootsimTest
276
- const q = ${JSON.stringify(e)}
277
- let node = null
278
- let via = null
279
- if (t.findByTestId) { node = await t.findByTestId(q); if (node) via = 'testID' }
280
- if (!node && t.findById) { node = await t.findById(q); if (node) via = 'id' }
281
- if (!node && t.findByText) { node = await t.findByText(q); if (node) via = 'text' }
282
- if (!node) return { matcher: q, found: false }
283
-
284
- // read the resolved transform (if any) off the style \u2014 useful
285
- // because canvas nodes often animate via transform and describe
286
- // output strips that.
287
- const transform =
288
- node.style && Array.isArray(node.style.transform)
289
- ? node.style.transform
290
- : node.style && node.style.transform
291
- ? node.style.transform
292
- : null
293
-
294
- // parent chain \u2014 walk up from the node so the JSON dump is
295
- // self-describing.
296
- const parentChain = []
297
- const root = window.__sootsimRoot
298
- if (root && node.id != null) {
299
- const findPath = (n, targetId, path) => {
300
- if (!n) return null
301
- if (n.id === targetId) return path
302
- if (n.children) {
303
- for (const child of n.children) {
304
- const nextPath = [
305
- ...path,
306
- {
307
- type: n.type || 'view',
308
- testID: n.props?.testID || null,
309
- text: n.text || null,
310
- },
311
- ]
312
- const found = findPath(child, targetId, nextPath)
313
- if (found) return found
314
- }
315
- }
316
- return null
317
- }
318
- const chain = findPath(root, node.id, [])
319
- if (chain) parentChain.push(...chain)
320
- }
321
-
322
- return {
323
- matcher: q,
324
- found: true,
325
- resolvedVia: via,
326
- node,
327
- transform,
328
- parentChain,
329
- }
330
- })()`});console.log(JSON.stringify(t,null,2));break}case"tap":{let e=Number(a[1]),t=Number(a[2]),s=se(o);if(s){let m=await ce(l,s);m||(console.error(` not found: ${s.value}`),s.mode==="testid"&&U("wait-selector-for-missing-testid",s.value),process.exit(1)),e=m.x,t=m.y}(!Number.isFinite(e)||!Number.isFinite(t))&&(console.error(S("tap","<x> <y> | --testid <id> | --text <t>")),process.exit(1));let r=await l.send({type:"tap",x:e,y:t}),n=Dt(e,t,r);n&&await L("inspect tap",n.step,n.summary),console.log(JSON.stringify(r,null,2));break}case"drag":case"swipe":{let e=Number(a[1]),t=Number(a[2]),s=Number(a[3]),r=Number(a[4]),n=h==="swipe"?10:12,m=h==="swipe"?8:16,p=a[5]?Number(a[5]):n,b=a[6]?Number(a[6]):m;(!Number.isFinite(e)||!Number.isFinite(t)||!Number.isFinite(s)||!Number.isFinite(r)||!Number.isFinite(p)||!Number.isFinite(b))&&(console.error(S(h,"<x1> <y1> <x2> <y2> [steps] [stepMs]")),process.exit(1));let f=await l.send({type:"evaluate",code:`(async () => {
331
- const interact = window.__sootsimInteract
332
- if (!interact?.drag) return { ok: false, reason: 'no interact.drag' }
333
- const value = await interact.drag(${e}, ${t}, ${s}, ${r}, ${Math.max(1,Math.round(p))}, ${Math.max(0,Math.round(b))})
334
- return { ok: !!value, value }
335
- })()`});if(f?.ok){let w=Math.max(1,Math.round(Math.max(1,p)*Math.max(0,b)));await L(`inspect ${h}`,{swipe:{start:`${e}, ${t}`,end:`${s}, ${r}`,duration:w}},`${h} ${e},${t} -> ${s},${r}`)}console.log(JSON.stringify(f,null,2));break}case"pinch":{let e=Number(a[1]),t=Number(a[2]),s=Number(a[3]),r=Number(a[4]),n=Number(a[5]),m=Number(a[6]),p=Number(a[7]),b=Number(a[8]),f=a[9]?Number(a[9]):12,w=a[10]?Number(a[10]):16;(!Number.isFinite(e)||!Number.isFinite(t)||!Number.isFinite(s)||!Number.isFinite(r)||!Number.isFinite(n)||!Number.isFinite(m)||!Number.isFinite(p)||!Number.isFinite(b)||!Number.isFinite(f)||!Number.isFinite(w))&&(console.error(S("pinch","<x1> <y1> <x2> <y2> <x1'> <y1'> <x2'> <y2'> [steps] [stepMs]")),process.exit(1));let O=await l.send({type:"evaluate",code:`(async () => {
336
- const interact = window.__sootsimInteract
337
- if (!interact?.pinch) return { ok: false, reason: 'no interact.pinch' }
338
- const value = await interact.pinch(${e}, ${t}, ${s}, ${r}, ${n}, ${m}, ${p}, ${b}, ${Math.max(1,Math.round(f))}, ${Math.max(0,Math.round(w))})
339
- return { ok: !!value, value }
340
- })()`});O?.ok&&await L("inspect pinch",{pinch:{from:[e,t,s,r],to:[n,m,p,b],steps:Math.max(1,Math.round(f)),stepMs:Math.max(0,Math.round(w))}},`pinch (${e},${t}) (${s},${r}) -> (${n},${m}) (${p},${b})`),console.log(JSON.stringify(O,null,2));break}case"tap-text":{let e=a[1];e||(console.error(S("tap-text","<text>")),process.exit(1));let t=_=>{let P=o.indexOf(_);return P>=0&&P+1<o.length?o[P+1]:null},s=_=>o.includes(_),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 m=t("--within"),p=t("--role"),b=s("--exact"),f=s("--first"),w=t("--min-y"),O=t("--max-y"),B=t("--min-x"),N=t("--max-x");for(let[_,P]of[["--min-y",w],["--max-y",O],["--min-x",B],["--max-x",N]])P!==null&&!Number.isFinite(Number(P))&&(console.error(` ${_} requires a number, got: ${P}`),process.exit(1));let M=o.indexOf("--near"),F=null;if(M>=0){let _=Number(o[M+1]),P=Number(o[M+2]);(!Number.isFinite(_)||!Number.isFinite(P))&&(console.error(" --near requires two numbers: --near <x> <y>"),process.exit(1)),F={x:_,y:P}}let W=JSON.stringify({query:e,exact:b,role:p,within:m,minX:B!==null?Number(B):null,maxX:N!==null?Number(N):null,minY:w!==null?Number(w):null,maxY:O!==null?Number(O):null,near:F,nth:n,first:f}),g=await l.send({type:"evaluate",code:`(async () => {
341
- const t = window.__sootsimTest
342
- if (!t) return { error: 'bridge-not-ready' }
343
- const F = ${W}
344
-
345
- const res = await t.queryTextCandidates({
346
- query: F.query,
347
- exact: !!F.exact,
348
- ...(F.role ? { role: F.role } : {}),
349
- })
350
-
351
- let candidates = res.candidates || []
352
-
353
- candidates = candidates.filter((c) => {
354
- const ax = c.info.absolutePosition && c.info.absolutePosition.x
355
- const ay = c.info.absolutePosition && c.info.absolutePosition.y
356
- if (F.minX !== null && !(ax >= F.minX)) return false
357
- if (F.maxX !== null && !(ax <= F.maxX)) return false
358
- if (F.minY !== null && !(ay >= F.minY)) return false
359
- if (F.maxY !== null && !(ay <= F.maxY)) return false
360
- if (F.within && !c.ancestorTestIDs.includes(F.within)) return false
361
- return true
362
- })
363
-
364
- if (F.near) {
365
- candidates.sort((a, b) => {
366
- const ax = (a.info.absolutePosition && a.info.absolutePosition.x) || 0
367
- const ay = (a.info.absolutePosition && a.info.absolutePosition.y) || 0
368
- const bx = (b.info.absolutePosition && b.info.absolutePosition.x) || 0
369
- const by = (b.info.absolutePosition && b.info.absolutePosition.y) || 0
370
- return (
371
- Math.hypot(ax - F.near.x, ay - F.near.y) -
372
- Math.hypot(bx - F.near.x, by - F.near.y)
373
- )
374
- })
375
- } else {
376
- candidates.sort((a, b) => {
377
- const ay = (a.info.absolutePosition && a.info.absolutePosition.y) || 0
378
- const by = (b.info.absolutePosition && b.info.absolutePosition.y) || 0
379
- if (Math.abs(ay - by) > 2) return ay - by
380
- const ax = (a.info.absolutePosition && a.info.absolutePosition.x) || 0
381
- const bx = (b.info.absolutePosition && b.info.absolutePosition.x) || 0
382
- return ax - bx
383
- })
384
- }
385
-
386
- const total = candidates.length
387
- if (total === 0) return { matched: 0, total: 0 }
388
-
389
- let idx = 0
390
- if (F.nth !== null) {
391
- idx = F.nth < 0 ? total + F.nth : F.nth
392
- if (idx < 0 || idx >= total) {
393
- return { matched: 0, total, nthOutOfRange: true, nth: F.nth }
394
- }
395
- } else if (total > 1 && !F.first && !F.near) {
396
- return {
397
- ambiguous: true,
398
- total,
399
- candidates: candidates.slice(0, 10).map((c, i) => ({
400
- idx: i,
401
- nodeId: c.info.nodeId,
402
- type: c.info.type,
403
- testID: c.info.testID,
404
- text: (c.info.text || '').slice(0, 60),
405
- abs: c.info.absolutePosition,
406
- layout: c.info.layout
407
- ? {
408
- width: Math.round(c.info.layout.width || 0),
409
- height: Math.round(c.info.layout.height || 0),
410
- }
411
- : null,
412
- ancestorTestIDs: (c.ancestorTestIDs || []).slice(0, 5),
413
- })),
414
- }
415
- }
416
-
417
- const picked = candidates[idx]
418
- const n = picked.info
419
- if (!n.absolutePosition || !n.layout) return { matched: 0, total }
420
-
421
- const resolved =
422
- typeof n.nodeId === 'number' &&
423
- typeof t.resolveTapTarget === 'function'
424
- ? await t.resolveTapTarget(n.nodeId)
425
- : null
426
- const target = (resolved && resolved.target) || n
427
- const cx =
428
- resolved && typeof resolved.cx === 'number'
429
- ? resolved.cx
430
- : n.absolutePosition.x + (n.layout.width || 0) / 2
431
- const cy =
432
- resolved && typeof resolved.cy === 'number'
433
- ? resolved.cy
434
- : n.absolutePosition.y + (n.layout.height || 0) / 2
435
- return {
436
- cx,
437
- cy,
438
- match: {
439
- nodeId: n.nodeId ?? null,
440
- id: n.id,
441
- testID: n.testID,
442
- type: n.type,
443
- },
444
- target: {
445
- nodeId: target.nodeId ?? null,
446
- id: target.id,
447
- testID: target.testID,
448
- type: target.type,
449
- },
450
- strategy: (resolved && resolved.strategy) || 'matched-node',
451
- total,
452
- idx,
453
- }
454
- })()`});if(g?.error==="bridge-not-ready"&&(console.error(" sootsim test bridge not ready"),process.exit(1)),g?.ambiguous){let _=g.candidates;console.error(` ambiguous: ${g.total} matches for "${e}"`);for(let P of _){let re=P.abs?`@(${Math.round(P.abs.x)},${Math.round(P.abs.y)})`:"",it=P.layout?` ${P.layout.width}x${P.layout.height}`:"",lt=P.testID?` #${P.testID}`:"",ct=P.text?` "${P.text}"`:"",dt=P.ancestorTestIDs.length>0?` within ${P.ancestorTestIDs.slice(0,3).map(ut=>`#${ut}`).join(" > ")}`:"";console.error(` [${P.idx}] <${P.type}>${ct}${lt} ${re}${it}${dt}`)}g.total>_.length&&console.error(` ... and ${g.total-_.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)}g?.nthOutOfRange&&(console.error(` not found: nth ${g.nth} of ${g.total} match${g.total===1?"":"es"} for "${e}"`),process.exit(1)),(!g||typeof g.cx!="number")&&(console.error(` not found: ${e}`),process.exit(1));let T=await l.send({type:"tap",x:g.cx,y:g.cy});if(T?.hit!==!1&&T?.ok!==!1){let _=st(e,{id:g.target?.id??null,testID:g.target?.testID??null,type:g.target?.type??null,cx:g.cx,cy:g.cy},"text");await L("inspect tap-text",_.step,_.summary)}console.log(JSON.stringify({matched:g.match,tapped:{nodeId:g.target?.nodeId??null,id:g.target?.id??null,testID:g.target?.testID??null,type:g.target?.type??null,cx:g.cx,cy:g.cy},...g.strategy&&g.strategy!=="matched-node"?{strategy:g.strategy}:{},...g.total>1||n!==null?{nth:{index:g.idx,total:g.total}}:{},result:T},null,2));break}case"tap-id":{let e=a[1];e||(console.error(S("tap-id","<id>")),process.exit(1));let t=JSON.stringify(e),s=await l.send({type:"evaluate",code:`(async () => {
455
- const t = window.__sootsimTest
456
- if (!t) return null
457
- const n = (await t.findByTestId(${t})) || (await t.findById(${t}))
458
- if (!n || !n.absolutePosition || !n.layout) return { cx: null }
459
- const resolved =
460
- typeof n.nodeId === 'number' && typeof t.resolveTapTarget === 'function'
461
- ? await t.resolveTapTarget(n.nodeId)
462
- : null
463
- const target = (resolved && resolved.target) || n
464
- const cx =
465
- resolved && typeof resolved.cx === 'number'
466
- ? resolved.cx
467
- : n.absolutePosition.x + (n.layout.width || 0) / 2
468
- const cy =
469
- resolved && typeof resolved.cy === 'number'
470
- ? resolved.cy
471
- : n.absolutePosition.y + (n.layout.height || 0) / 2
472
- return {
473
- cx,
474
- cy,
475
- match: {
476
- nodeId: n.nodeId ?? null,
477
- id: n.id,
478
- testID: n.testID,
479
- type: n.type,
480
- },
481
- target: {
482
- nodeId: target.nodeId ?? null,
483
- id: target.id,
484
- testID: target.testID,
485
- type: target.type,
486
- },
487
- strategy: (resolved && resolved.strategy) || 'matched-node',
488
- }
489
- })()`});(!s||typeof s.cx!="number")&&(console.error(` not found: ${e}`),process.exit(1));let r=await l.send({type:"tap",x:s.cx,y:s.cy});if(r?.hit!==!1&&r?.ok!==!1){let n=st(e,{id:s.target?.id??null,testID:s.target?.testID??null,type:s.target?.type??null,cx:s.cx,cy:s.cy},"id");await L("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=a[1],t=a.slice(2).join(" ");(!e||!t)&&(console.error(S("type-into","<id> <text>")),process.exit(1));let s=JSON.stringify(e),r=await l.send({type:"evaluate",code:`(async () => {
490
- const t = window.__sootsimTest
491
- if (!t) return null
492
- const n = await (t.findByTestId(${s}) || t.findById(${s}))
493
- if (!n || !n.absolutePosition || !n.layout) return null
494
- return {
495
- cx: n.absolutePosition.x + (n.layout.width || 0) / 2,
496
- cy: n.absolutePosition.y + (n.layout.height || 0) / 2,
497
- testID: n.testID,
498
- isTextInput: !!n.isTextInput,
499
- placeholder: n.placeholder || null,
500
- }
501
- })()`});(!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 l.send({type:"tap",x:r.cx,y:r.cy}),m=await Et(l);m.visible||(console.error(` keyboard did not open after tapping ${e}`),process.exit(1));let p=m.focusedInput;p&&(p.testID===e||p.id===e||(console.error(` focus routing mismatch after tap: requested ${JSON.stringify(e)} but focus is on ${JSON.stringify(p.testID??p.id??null)}. did the tap land on an outer Pressable wrapper?`),process.exit(1))),await l.send({type:"keyboard",action:"type",text:t}),await L("inspect type-into",{tapOn:{id:e},inputText:t},`type-into #${e} ${JSON.stringify(t)}`),console.log(JSON.stringify({target:e,isTextInput:r.isTextInput,keyboardOpened:m.visible??n?.keyboardOpened??!1,focusedInput:m.focusedInput??null,typed:t},null,2));break}case"type":{let e=a.slice(1).join(" ");e||(console.error(S("type","<text>")),process.exit(1)),await ue(l,"type"),await l.send({type:"keyboard",action:"type",text:e}),await L("inspect type",{inputText:e},`type ${JSON.stringify(e)}`),console.log(` typed: ${JSON.stringify(e)}`);break}case"key":{let e=a[1];e||(console.error(S("key","<name>")),process.exit(1)),await ue(l,"key"),await l.send({type:"keyboard",action:"press",text:e}),await L("inspect key",{pressKey:e},`key ${e}`),console.log(` pressed: ${e}`);break}case"key-sequence":{let e=a.slice(1);e.length===0&&(console.error(S("key-sequence","<key> [<key> ...]")),process.exit(1)),await ue(l,"key-sequence");for(let t of e)await l.send({type:"keyboard",action:"press",text:t});await L("inspect key-sequence",{pressKey:e.join(" ")},`key-sequence ${e.join(" ")}`),console.log(` pressed: ${e.join(", ")}`);break}case"keycode":{let e=a.slice(1);e.length===0&&(console.error(S("keycode","<code> [<code> ...]")),process.exit(1));let t=e.map(r=>({code:r,key:Rt(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 ue(l,"keycode");for(let r of t)await l.send({type:"keyboard",action:"press",text:r.key});await L("inspect keycode",{pressKey:t.map(r=>r.key).join(" ")},`keycode ${e.join(" ")}`),console.log(` pressed: ${e.join(", ")}`);break}case"dispatch":{let e=a[1];e||(console.error(S("dispatch","<char>")),process.exit(1)),await l.send({type:"keyboard",action:"dispatchKey",text:e}),await L("inspect dispatch",{dispatchKey:e},`dispatch ${JSON.stringify(e)}`),console.log(` dispatched: ${e}`);break}case"dismiss":{await l.send({type:"keyboard",action:"dismiss"}),await L("inspect dismiss",{hideKeyboard:!0},"dismiss keyboard"),console.log(" keyboard dismissed");break}case"double-tap":{let e=Number(a[1]),t=Number(a[2]),s=se(o);if(s){let p=await ce(l,s);p||(console.error(` not found: ${s.value}`),s.mode==="testid"&&U("wait-selector-for-missing-testid",s.value),process.exit(1)),e=p.x,t=p.y}let r=a[3]?Number(a[3]):80;(!Number.isFinite(e)||!Number.isFinite(t)||!Number.isFinite(r))&&(console.error(S("double-tap","<x> <y> [gapMs] | --testid <id>")),process.exit(1));let n=Math.max(0,Math.round(r)),m=await l.send({type:"evaluate",code:`(async () => {
502
- const interact = window.__sootsimInteract
503
- if (interact?.doubleTap) {
504
- return {
505
- ok: !!(await interact.doubleTap(${e}, ${t}, ${n})),
506
- gapMs: ${n},
507
- }
508
- }
509
- if (!interact?.tap) {
510
- return { ok: false, reason: 'no interact.tap', gapMs: ${n} }
511
- }
512
- const first = await interact.tap(${e}, ${t})
513
- if (!first || first.hit === false) {
514
- return { ok: false, reason: 'first tap missed', gapMs: ${n}, first }
515
- }
516
- await new Promise((resolve) => setTimeout(resolve, ${n}))
517
- const second = await interact.tap(${e}, ${t})
518
- return {
519
- ok: !!second && second.hit !== false,
520
- gapMs: ${n},
521
- first,
522
- second,
523
- }
524
- })()`});m?.ok&&await L("inspect double-tap",{doubleTapAtCoords:{x:e,y:t,gapMs:n}},`double-tap @${e},${t}`),console.log(JSON.stringify(m,null,2));break}case"long-press":{let e=Number(a[1]),t=Number(a[2]),s=se(o);if(s){let m=await ce(l,s);m||(console.error(` not found: ${s.value}`),s.mode==="testid"&&U("wait-selector-for-missing-testid",s.value),process.exit(1)),e=m.x,t=m.y}let r=a[3]?Number(a[3]):600;(!Number.isFinite(e)||!Number.isFinite(t)||!Number.isFinite(r))&&(console.error(S("long-press","<x> <y> [durationMs] | --testid <id>")),process.exit(1));let n=await l.send({type:"evaluate",code:`(async () => {
525
- const interact = window.__sootsimInteract
526
- if (!interact?.longPress) return { ok: false, reason: 'no interact.longPress' }
527
- const value = await interact.longPress(${e}, ${t}, ${Math.max(0,Math.round(r))})
528
- return { ok: !!value, value }
529
- })()`});n?.ok&&await L("inspect long-press",{tapAtCoords:{x:e,y:t}},`long-press @${e},${t}`),console.log(JSON.stringify(n,null,2));break}case"touch":{let e=a[1],t=Number(a[2]),s=Number(a[3]),r=a[4]?Number(a[4]):999,n=e==="down"?"touchDown":e==="move"?"touchMove":e==="up"?"touchUp":e==="cancel"?"touchCancel":null;n||(console.error(S("touch","<down|move|up|cancel> <x> <y> [pointerId]")),process.exit(1)),e!=="cancel"&&(!Number.isFinite(t)||!Number.isFinite(s))&&(console.error(S("touch","<down|move|up|cancel> <x> <y> [pointerId]")),process.exit(1));let m=e==="down"?"tap":e==="move"?"move":null,p=m&&Number.isFinite(t)&&Number.isFinite(s)?`window.dispatchEvent(new CustomEvent('sootsim:agentAction', { detail: { type: '${m}', x: ${t}, y: ${s} } }));`:"",b=await l.send({type:"evaluate",code:`(async () => {
530
- ${p}
531
- const interact = window.__sootsimInteract
532
- if (!interact?.${n}) return { ok: false, reason: 'no interact.${n}' }
533
- const value = ${e==="cancel"?`await interact.${n}(${Math.max(1,Math.round(r))})`:`await interact.${n}(${t}, ${s}, ${Math.max(1,Math.round(r))})`}
534
- return { ok: !!value, value }
535
- })()`});b?.ok&&e!=="cancel"&&await L("inspect touch",{tapAtCoords:{x:t,y:s}},`touch ${e} @${t},${s}`),console.log(JSON.stringify(b,null,2));break}case"gesture":{let e=a[1],t=a[2]?Number(a[2]):220;(!e||!Number.isFinite(t))&&(console.error(S("gesture","<preset> [durationMs]")),process.exit(1));let s=await l.send({type:"evaluate",code:`(async () => {
536
- const spec = globalThis.__sootsimDeviceSpec || {}
537
- return {
538
- width: spec.width || window.innerWidth || 393,
539
- height: spec.height || window.innerHeight || 852,
540
- statusBarHeight: spec.statusBarHeight || 0,
541
- homeIndicatorHeight: spec.homeIndicatorHeight || 0,
542
- }
543
- })()`}),r=Number(s?.width)||393,n=Number(s?.height)||852,m=Number(s?.statusBarHeight)||0,p=Number(s?.homeIndicatorHeight)||0,b=Math.round(r/2),f=Math.round(n/2),w=Math.max(24,m+18),O=Math.max(24,p+18),B=18,N=Math.min(220,Math.round(n*.24)),M=Math.min(180,Math.round(r*.32)),F=b,W=f,g=b,T=f;switch(e){case"scroll-up":W=f+Math.round(N/2),T=f-Math.round(N/2);break;case"scroll-down":W=f-Math.round(N/2),T=f+Math.round(N/2);break;case"scroll-left":F=b+Math.round(M/2),g=b-Math.round(M/2);break;case"scroll-right":F=b-Math.round(M/2),g=b+Math.round(M/2);break;case"swipe-from-left-edge":F=B,W=f,g=Math.min(r-B,B+M);break;case"swipe-from-right-edge":F=r-B,W=f,g=Math.max(B,r-B-M);break;case"swipe-from-top-edge":F=b,W=w,T=Math.min(n-O,w+N);break;case"swipe-from-bottom-edge":F=b,W=n-O,T=Math.max(w,n-O-N);break;default:console.error(` unknown gesture preset: ${e}`),process.exit(1)}let _=Math.max(8,Math.round(t/16)),P=Math.max(1,Math.round(t/_)),re=await l.send({type:"evaluate",code:`(async () => {
544
- const interact = window.__sootsimInteract
545
- if (!interact?.drag) return { ok: false, reason: 'no interact.drag' }
546
- const value = await interact.drag(${F}, ${W}, ${g}, ${T}, ${_}, ${P})
547
- return { ok: !!value, value }
548
- })()`});re?.ok&&await L("inspect gesture",{swipe:{start:`${F}, ${W}`,end:`${g}, ${T}`,duration:Math.max(1,Math.round(t))}},`gesture ${e}`),console.log(JSON.stringify({preset:e,from:{x:F,y:W},to:{x:g,y:T},result:re},null,2));break}case"scroll":{let e=se(o),t=e?.mode==="testid"?e.value:a[1],s=Number(a[e?1:2]),r=Number(a[e?2:3]);(!t||!Number.isFinite(s)||!Number.isFinite(r))&&(console.error(S("scroll","<id> <dx> <dy> | --testid <id> <dx> <dy>")),process.exit(1));let n=await l.send({type:"evaluate",code:`(async () => {
549
- const t = window.__sootsimTest
550
- if (!t) return null
551
- const n = await t.findByTestId(${JSON.stringify(t)})
552
- || await t.findById(${JSON.stringify(t)})
553
- if (!n || !n.absolutePosition || !n.layout) return null
554
- return {
555
- cx: n.absolutePosition.x + (n.layout.width || 0) / 2,
556
- cy: n.absolutePosition.y + (n.layout.height || 0) / 2,
557
- }
558
- })()`}),m=await z(l,"scrollTo",t,s,r,!1);m?.ok&&await L("inspect scroll",{scrollTo:{id:t,x:s,y:r}},`scroll ${t} -> ${s},${r}`),console.log(JSON.stringify({...m,...n?{at:{x:n.cx,y:n.cy}}:{}},null,2));break}case"state":{let e=a[1];if(i==="get"&&!e){let s=await z(l,"getSessionState"),r=await l.send({type:"evaluate",code:`({
559
- errors: window.__sootsimConsole?.getErrors?.()?.length ?? 0,
560
- warnings: window.__sootsimConsole?.getWarnings?.()?.length ?? 0,
561
- })`});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(`
562
- ${y("state")} \u2014 dump raw runtime state
563
-
564
- subcommands:
565
- shell dump shell transition/layout state
566
- worker dump render-worker host/animation state
567
- keyboard dump keyboard visibility, mode, and focused input
568
- ownership dump surface ownership + pointerOnSurface delivery stats
569
- node <id> dump raw node info by id or testID
570
- scroll <id> dump scroll metrics and runtime state
571
- scroll-hit <x> <y> dump the nearest scroll ancestor at coordinates
572
- hit <x> <y> dump the hit-test ancestry at coordinates
573
- gesture <x> <y> dump gesture routing/debug info at coordinates
574
-
575
- examples:
576
- ${y("state")} shell
577
- ${y("state")} worker
578
- ${y("state")} keyboard
579
- ${y("state")} ownership
580
- ${y("state")} node photos
581
- ${y("state")} scroll feed
582
- ${y("state")} scroll-hit 360 420
583
- ${y("state")} hit 200 720
584
- `);break}let t;switch(e){case"shell":t=await V(l,500);break;case"worker":t=await ke(l,"__sootsimRenderHost.queryStats");break;case"ownership":t=await l.send({type:"evaluate",code:`(() => {
585
- const h = window.__sootsimRenderHost
586
- if (!h || typeof h.getOwnershipSnapshot !== 'function') {
587
- return { error: 'getOwnershipSnapshot not available' }
588
- }
589
- return h.getOwnershipSnapshot()
590
- })()`});break;case"keyboard":t=await l.send({type:"evaluate",code:`(async () => {
591
- const kb = window.__sootsimKeyboard
592
- const test = window.__sootsimTest
593
- if (!kb) return { error: 'keyboard bridge not available' }
594
- const layout = typeof kb.getLayout === 'function' ? kb.getLayout() : null
595
- const visible = kb.isVisible()
596
- const mode = kb.getMode()
597
- let focused = null
598
- if (test && typeof test.getFocusedNode === 'function') {
599
- try {
600
- focused = await test.getFocusedNode()
601
- } catch {}
602
- }
603
- return {
604
- visible,
605
- mode,
606
- layout,
607
- focusedInput: focused ? {
608
- nodeId: focused.nodeId ?? null,
609
- testID: focused.testID || null,
610
- id: focused.id || null,
611
- placeholder: focused.placeholder || null,
612
- text: focused.text || null,
613
- } : null,
614
- }
615
- })()`});break;case"node":{let s=a[2];s||(console.error(` usage: ${y("state")} node <id>`),process.exit(1)),t=await z(l,"findByTestId",s)||await z(l,"findById",s);break}case"scroll":{let s=a[2];s||(console.error(` usage: ${y("state")} scroll <id>`),process.exit(1)),t=await z(l,"getScrollState",s);break}case"scroll-hit":{let s=Number(a[2]),r=Number(a[3]);(!Number.isFinite(s)||!Number.isFinite(r))&&(console.error(` usage: ${y("state")} scroll-hit <x> <y>`),process.exit(1)),t=await z(l,"getScrollStateAt",s,r);break}case"hit":{let s=Number(a[2]),r=Number(a[3]);(!Number.isFinite(s)||!Number.isFinite(r))&&(console.error(` usage: ${y("state")} hit <x> <y>`),process.exit(1)),t=await z(l,"debugHitAt",s,r);break}case"gesture":{let s=Number(a[2]),r=Number(a[3]);(!Number.isFinite(s)||!Number.isFinite(r))&&(console.error(` usage: ${y("state")} gesture <x> <y>`),process.exit(1)),t=await z(l,"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=a[1];if(!e||e==="--help"||e==="-h"){console.log(`
616
- ${y("shell")} \u2014 run built-in shell commands
617
-
618
- subcommands:
619
- launch <appId> [waitMs] [--clear-state]
620
- launch app and wait for settled shell state
621
- home [waitMs] go home and wait for settled shell state
622
- switcher [waitMs] open switcher and wait for settled shell state
623
- open-card <appId> [waitMs]
624
- open a specific switcher card and wait for app settle
625
- appearance <light|dark|auto|toggle>
626
- update simulator appearance
627
- lock toggle device lock state
628
- shake trigger the simulator shake gesture
629
-
630
- examples:
631
- ${y("shell")} launch photos
632
- ${y("shell")} launch rn --clear-state
633
- ${y("shell")} launch photos 1500
634
- ${y("shell")} home 500
635
- ${y("shell")} switcher 800
636
- ${y("shell")} open-card clock 800
637
- ${y("shell")} appearance dark
638
- ${y("shell")} lock
639
- `);break}let t=e==="launch"||e==="open-card"||e==="home"||e==="switcher",s=e==="launch"||e==="open-card"?a[3]:a[2],r=s?Number(s):350;t&&(!Number.isFinite(r)||r<0)&&(console.error(S("shell",e==="launch"||e==="open-card"?"<launch|open-card> <appId> [settleMs]":"<home|switcher> [settleMs]")),process.exit(1));let n=!1,m=!1,p=null,b=o.includes("--clear-state");if(e==="launch"){let f=a[2];f||(console.error(S("shell","launch <appId> [settleMs] [--clear-state]")),process.exit(1)),b&&await l.send({type:"evaluate",code:Te}),n=!!await te(l,"launchApp",r,f),{settled:m,state:p}=await de(l,Math.round(r),w=>!!w&&w.state==="app"&&w.activeApp===f&&w.showSwitcher===!1&&w.switcherPhase==="idle"&&typeof w.launchProgress=="number"&&w.launchProgress>=.98),n&&await L("inspect shell launch",b?{launchApp:{clearState:!0}}:{launchApp:{}},b?"launch app (clear state)":"launch app")}else if(e==="home")n=!!await te(l,"goHome",r),{settled:m,state:p}=await de(l,Math.round(r),f=>!!f&&f.state==="home"&&f.activeApp==null&&f.showSwitcher===!1&&f.switcherPhase==="idle"&&typeof f.launchProgress=="number"&&f.launchProgress>=.98);else if(e==="switcher")n=!!await te(l,"openSwitcher",r),{settled:m,state:p}=await de(l,Math.round(r),f=>!!f&&f.state==="app"&&f.showSwitcher===!0&&f.switcherPhase==="idle"&&typeof f.zoomLevel=="number"&&Math.abs(f.zoomLevel)<=.02&&typeof f.horizontalZoom=="number"&&Math.abs(f.horizontalZoom)<=.02),m&&(await Y(Ot),p=await V(l));else if(e==="open-card"){let f=a[2];f||(console.error(S("shell","open-card <appId> [settleMs]")),process.exit(1)),n=!!await te(l,"openSwitcherCard",r,f),{settled:m,state:p}=await de(l,Math.round(r),w=>!!w&&w.state==="app"&&w.activeApp===f&&w.showSwitcher===!1&&w.switcherPhase==="idle"&&typeof w.zoomLevel=="number"&&w.zoomLevel>=.98&&typeof w.horizontalZoom=="number"&&w.horizontalZoom>=.98),n&&await L("inspect shell open-card",{openSwitcherCard:{appId:f}},`open switcher card ${f}`)}else if(e==="appearance"){let f=a[2];(!f||!["light","dark","auto","toggle"].includes(f))&&(console.error(S("shell","appearance <light|dark|auto|toggle>")),process.exit(1));let w=await ot(l,"appearance",f);n=!!w?.ok,p={appearance:w}}else if(e==="lock"||e==="shake"){let f=await ot(l,e);n=!!f?.ok,p={[e]:f}}else console.error(` unknown shell subcommand: ${e}`),process.exit(1);console.log(JSON.stringify({ok:n,settled:m,state:p},null,2));break}case"url":{await Ue(l,{args:d});break}case"reload":{let s=!1,r=!1;try{await l.send({type:"evaluate",code:"window.__sootsimConsole?.clear()"});let p=await l.send({type:"evaluate",code:`;(() => {
640
- const reloadExternalApp = window.SootSim?.bridges?.hotRemount?.reloadExternalApp
641
- if (typeof reloadExternalApp === 'function') {
642
- reloadExternalApp()
643
- return { kind: 'external-app' }
644
- }
645
- window.location.reload()
646
- return { kind: 'page' }
647
- })()`});r=!!p&&p.kind==="external-app",s=!0}catch{}console.log(" reloading...");let n=l,m=null;if(r)m=await fe(l,{timeoutMs:1e4,errorGraceMs:3e3});else{s&&await Y(300);let p=await Fe(A,j,k,{timeoutMs:1e4});p?(n=p,m=await fe(p,{timeoutMs:1e4,errorGraceMs:3e3})):(console.log(" \u26A0 reload: bridge never reconnected within 10000ms"),n=null)}if(m)if(m.ready){let p=m.source==="nodes-fallback"?" (no ready signal, node-count fallback)":"";console.log(` ready in ${m.elapsedMs}ms: ${m.nodes} nodes${p}`)}else m.source==="error-bail"?console.log(` \u26A0 reload bailed after ${m.elapsedMs}ms: ${m.errors} console error(s), ready signal never fired`):console.log(` \u26A0 reload timed out after ${m.elapsedMs}ms (${m.nodes} nodes, ${m.errors} errors)`);if(n)try{let p=await n.send({type:"evaluate",code:"window.__sootsimConsole?.getErrors(10) || []"});if(n!==l&&n.close(),Array.isArray(p)&&p.length>0){console.log(`
648
- \u26A0 ${p.length} error(s) during mount:
649
- `);for(let b of p){let f=b.args.map(w=>typeof w=="object"?JSON.stringify(w):w).join(" ");if(console.log(` ${f}`),b.stack){let w=b.stack.split(`
650
- `).slice(0,2);for(let O of w)console.log(` ${O.trim()}`)}}}}catch{}m&&!m.ready&&(process.exitCode=1);break}case"eval":case"js":{let e=a.slice(1).join(" ");e||(console.error(S("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(` ${y("js")} SootSim.bridges.test.findByText("Sign in")`),console.error(` ${y("js")} SootSim.bridges.debug.snapshot("before")`),console.error(` ${y("js")} SootSim.bridges.keyboard.type("hello")`),console.error(` ${y("js")} SootSim.state.root.children.length`),process.exit(1));let t=e;t.startsWith("(async")||(t=`(async () => ${t})()`);let s=await l.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&&U("prefer-cli-over-eval",n);break}case"globals":{let e=await l.send({type:"evaluate",code:`(async () => {
651
- const globals = {}
652
-
653
- // test bridge (proxy in worker mode)
654
- const testMethods = [
655
- 'findById', 'findByTestId', 'findByText', 'findByLabel', 'findByRole',
656
- 'findAllByRole', 'findByA11yState', 'findAllByA11yState', 'findByHint',
657
- 'findPressable', 'getStyle', 'getLayout', 'getAbsolutePosition', 'isVisible',
658
- 'queryAll', 'dumpTree', 'dumpAccessibilityTree', 'getNodeCount', 'getShellState',
659
- 'getScrollState', 'getScrollStateAt', 'scrollTo', 'waitForTree',
660
- 'waitForScreenTransitions', 'debugByText', 'debugByTestId', 'debugHitAt',
661
- 'debugGestureAt'
662
- ]
663
- globals['test (\u2192 __sootsimTest)'] = testMethods
664
-
665
- // debug
666
- if (window.__sootsimDebug) {
667
- globals['debug (\u2192 __sootsimDebug)'] = Object.keys(window.__sootsimDebug)
668
- }
669
-
670
- // interact
671
- if (window.__sootsimInteract) {
672
- globals['interact (\u2192 __sootsimInteract)'] = Object.keys(window.__sootsimInteract)
673
- }
674
-
675
- // keyboard
676
- if (window.__sootsimKeyboard) {
677
- globals['keyboard (\u2192 __sootsimKeyboard)'] = Object.keys(window.__sootsimKeyboard)
678
- }
679
-
680
- // other globals
681
- globals['other'] = [
682
- 'root (\u2192 __sootsimRoot) - live node tree',
683
- 'render() (\u2192 __sootsimForceRender) - force re-render'
684
- ]
685
-
686
- return globals
687
- })()`});console.log(` sootsim JS API:
688
- `);for(let[t,s]of Object.entries(e)){console.log(` ${t}:`);for(let r of s)console.log(` .${r}`);console.log("")}console.log(` use: ${y("js")} <expression>`),console.log(` example: ${y("js")} test.findByText("Sign in")`);break}case"describe":{await Ce({bridge:l,args:o,positional:a});break}case"perf":{let e=a[1];if(!e||e==="--help"||e==="-h"){console.log(`
689
- ${y("perf")} \u2014 performance profiling
690
-
691
- subcommands:
692
- stats one-shot stats (zero overhead query)
693
- start begin recording frame times
694
- stop stop recording and report results
695
- frames [n] get last N frame times (default: 50)
696
- transition <e> profile a shell transition (goHome, appSwitcher, lockScreen)
697
-
698
- examples:
699
- ${y("perf")} stats
700
- ${y("perf")} start
701
- # ... interact with the app ...
702
- ${y("perf")} stop
703
- ${y("perf")} transition goHome
704
- `);break}switch(e){case"stats":{let t=await l.send({type:"evaluate",code:`(async () => {
705
- // worker mode (host exposes these)
706
- if (window.__sootsimPerfStats) {
707
- return await window.__sootsimPerfStats()
708
- }
709
- // main-thread mode
710
- const perf = window.__sootsimPerf
711
- const a11y = window.__sootsimA11y
712
- if (!perf && !a11y) return { error: 'no perf globals available' }
713
-
714
- const frameStats = perf?.getFrameStats?.() || {}
715
- const profile = a11y?.profile?.() || {}
716
- const nodeCount = await window.__sootsimTest?.getNodeCount?.() || 0
717
-
718
- return {
719
- frames: frameStats.frames || profile.syncCount || 0,
720
- avgMs: frameStats.totalMs && frameStats.frames
721
- ? (frameStats.totalMs / frameStats.frames).toFixed(2)
722
- : profile.avgSyncMs?.toFixed(2) || '?',
723
- maxMs: frameStats.maxMs?.toFixed(2) || profile.maxSyncMs?.toFixed(2) || '?',
724
- layoutMs: frameStats.layoutTotalMs?.toFixed(2) || '?',
725
- nodeCount,
726
- jankFrames: frameStats.recentFrames?.filter(f => f > 16.67).length || 0,
727
- recentCount: frameStats.recentFrames?.length || 0,
728
- }
729
- })()`});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 l.send({type:"evaluate",code:`(async () => {
730
- // worker mode
731
- if (window.__sootsimPerfStart && window.__sootsimRenderHost) {
732
- const result = window.__sootsimPerfStart()
733
- window.${G} = {
734
- active: true,
735
- mode: 'render-worker',
736
- lastSamples: [],
737
- startedAt: performance.now(),
738
- }
739
- return result
740
- }
741
- // main-thread mode
742
- window.__sootsimPerf?.enableFrameStats?.(true)
743
- window.__sootsimA11y?.resetProfile?.()
744
- window.${G} = {
745
- active: true,
746
- mode: 'main-thread',
747
- lastSamples: [],
748
- startedAt: performance.now(),
749
- }
750
- return { started: true }
751
- })()`}),console.log(` profiling started \u2014 interact with the app, then run '${y("perf")} stop'`);break}case"stop":{let t=await l.send({type:"evaluate",code:`(async () => {
752
- // worker mode
753
- if (window.__sootsimRenderHost) {
754
- const session = window.${G} || {}
755
- const priorSamples = session.active && Array.isArray(session.lastSamples)
756
- ? session.lastSamples
757
- : []
758
- const flushedSamples = await window.__sootsimRenderHost.flushSamples()
759
- const samples = priorSamples.concat(flushedSamples)
760
- window.${G} = {
761
- ...session,
762
- active: false,
763
- mode: 'render-worker',
764
- lastSamples: samples,
765
- stoppedAt: performance.now(),
766
- }
767
-
768
- const frameTimes = samples.map(sample => sample[1])
769
- const layoutTimes = samples.map(sample => sample[2])
770
- const renderTimes = samples.map(sample => sample[3])
771
- const copyTimes = samples.map(sample => sample[4])
772
- const auxTimes = samples.map(sample => sample[5] || 0)
773
- const otherTimes = samples.map(sample => sample[6] || 0)
774
- const sorted = [...frameTimes].sort((a, b) => a - b)
775
- const total = frameTimes.reduce((a, b) => a + b, 0)
776
- const avg = frameTimes.length > 0 ? total / frameTimes.length : 0
777
- const max = Math.max(...frameTimes, 0)
778
- const layoutTotal = layoutTimes.reduce((a, b) => a + b, 0)
779
- const renderTotal = renderTimes.reduce((a, b) => a + b, 0)
780
- const copyTotal = copyTimes.reduce((a, b) => a + b, 0)
781
- const auxTotal = auxTimes.reduce((a, b) => a + b, 0)
782
- const otherTotal = otherTimes.reduce((a, b) => a + b, 0)
783
-
784
- return {
785
- mode: 'render-worker',
786
- frames: frameTimes.length,
787
- totalMs: total,
788
- avgMs: avg,
789
- maxMs: max,
790
- layoutTotalMs: layoutTotal,
791
- renderTotalMs: renderTotal,
792
- copyTotalMs: copyTotal,
793
- auxTotalMs: auxTotal,
794
- otherTotalMs: otherTotal,
795
- layoutAvgMs: frameTimes.length > 0 ? layoutTotal / frameTimes.length : 0,
796
- renderAvgMs: frameTimes.length > 0 ? renderTotal / frameTimes.length : 0,
797
- copyAvgMs: frameTimes.length > 0 ? copyTotal / frameTimes.length : 0,
798
- auxAvgMs: frameTimes.length > 0 ? auxTotal / frameTimes.length : 0,
799
- otherAvgMs: frameTimes.length > 0 ? otherTotal / frameTimes.length : 0,
800
- p50: sorted[Math.floor(sorted.length * 0.5)] || 0,
801
- p95: sorted[Math.floor(sorted.length * 0.95)] || 0,
802
- p99: sorted[Math.floor(sorted.length * 0.99)] || 0,
803
- jankFrames: frameTimes.filter((f) => f > 16.67).length,
804
- sampleCount: frameTimes.length,
805
- }
806
- }
807
- // main-thread mode
808
- const perf = window.__sootsimPerf
809
- const a11y = window.__sootsimA11y
810
- if (!perf && !a11y) return { error: 'no perf globals' }
811
-
812
- const frameStats = perf?.getFrameStats?.() || {}
813
- const profile = a11y?.profile?.() || {}
814
-
815
- // calculate distribution
816
- const recent = frameStats.recentFrames || []
817
- const sorted = [...recent].sort((a, b) => a - b)
818
- const p50 = sorted[Math.floor(sorted.length * 0.5)] || 0
819
- const p95 = sorted[Math.floor(sorted.length * 0.95)] || 0
820
- const p99 = sorted[Math.floor(sorted.length * 0.99)] || 0
821
-
822
- // disable collection
823
- perf?.disableFrameStats?.()
824
- window.${G} = {
825
- ...(window.${G} || {}),
826
- active: false,
827
- mode: 'main-thread',
828
- lastSamples: recent.map((ms, index) => [index, ms, 0, 0, 0, 0, 0]),
829
- stoppedAt: performance.now(),
830
- }
831
-
832
- return {
833
- mode: 'main-thread',
834
- frames: frameStats.frames || profile.syncCount || 0,
835
- totalMs: frameStats.totalMs || 0,
836
- avgMs: frameStats.totalMs && frameStats.frames
837
- ? frameStats.totalMs / frameStats.frames
838
- : profile.avgSyncMs || 0,
839
- maxMs: frameStats.maxMs || profile.maxSyncMs || 0,
840
- layoutTotalMs: frameStats.layoutTotalMs || 0,
841
- p50, p95, p99,
842
- jankFrames: recent.filter(f => f > 16.67).length,
843
- sampleCount: recent.length,
844
- }
845
- })()`});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:
846
- `),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=a[2]?Number(a[2]):50;(!Number.isFinite(t)||t<=0)&&(console.error(` error: expected a positive frame count, got "${a[2]}"`),process.exit(1));let s=await l.send({type:"evaluate",code:`(async () => {
847
- if (window.__sootsimRenderHost) {
848
- const session = window.${G} || {}
849
- if (session.active) {
850
- const priorSamples = Array.isArray(session.lastSamples) ? session.lastSamples : []
851
- const flushedSamples = await window.__sootsimRenderHost.flushSamples()
852
- const samples = priorSamples.concat(flushedSamples)
853
- window.__sootsimRenderHost.startSampling()
854
- window.${G} = {
855
- ...session,
856
- active: true,
857
- mode: 'render-worker',
858
- lastSamples: samples,
859
- lastFlushAt: performance.now(),
860
- }
861
- return {
862
- mode: 'render-worker',
863
- live: true,
864
- samples: samples.slice(-${t}),
865
- }
866
- }
867
- return {
868
- mode: 'render-worker',
869
- live: false,
870
- samples: (session.lastSamples || []).slice(-${t}),
871
- }
872
- }
873
- // main-thread mode
874
- const perf = window.__sootsimPerf
875
- if (!perf) return { error: 'no __sootsimPerf (try "perf start" first)' }
876
- const stats = perf.getFrameStats?.() || {}
877
- return {
878
- mode: 'main-thread',
879
- frames: (stats.recentFrames || []).slice(-${t}),
880
- }
881
- })()`});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 '${y("perf")} start' first`);break}console.log(` last ${n.length} sampled frames (ms):`),console.log(" total layout render copy aux other t+");for(let[m,p,b,f,w,O,B]of n)console.log(` ${p.toFixed(2).padStart(7)} ${b.toFixed(2).padStart(7)} ${f.toFixed(2).padStart(7)} ${w.toFixed(2).padStart(7)} ${O.toFixed(2).padStart(6)} ${B.toFixed(2).padStart(7)} ${String(m).padStart(5)}`);console.log(""),he(n.map(m=>m[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 '${y("perf")} start' first`);break}console.log(` last ${r.length} frame times (ms):`),console.log(` ${r.map(n=>n.toFixed(2)).join(", ")}`),he(r);break}case"worst":{let t=a[2]?Number(a[2]):20;(!Number.isFinite(t)||t<=0)&&(console.error(` error: expected a positive frame count, got "${a[2]}"`),process.exit(1));let s=await l.send({type:"evaluate",code:`(async () => {
882
- if (window.__sootsimRenderHost) {
883
- const session = window.${G} || {}
884
- if (session.active) {
885
- const priorSamples = Array.isArray(session.lastSamples) ? session.lastSamples : []
886
- const flushedSamples = await window.__sootsimRenderHost.flushSamples()
887
- const samples = priorSamples.concat(flushedSamples)
888
- window.__sootsimRenderHost.startSampling()
889
- window.${G} = {
890
- ...session,
891
- active: true,
892
- mode: 'render-worker',
893
- lastSamples: samples,
894
- lastFlushAt: performance.now(),
895
- }
896
- return {
897
- mode: 'render-worker',
898
- live: true,
899
- samples: samples
900
- .slice()
901
- .sort((a, b) => b[1] - a[1])
902
- .slice(0, ${t}),
903
- }
904
- }
905
- const samples = Array.isArray(session.lastSamples) ? session.lastSamples : []
906
- return {
907
- mode: 'render-worker',
908
- live: false,
909
- samples: samples
910
- .slice()
911
- .sort((a, b) => b[1] - a[1])
912
- .slice(0, ${t}),
913
- }
914
- }
915
- const perf = window.__sootsimPerf
916
- if (!perf) return { error: 'no __sootsimPerf (try "perf start" first)' }
917
- const stats = perf.getFrameStats?.() || {}
918
- const recent = Array.isArray(stats.recentFrames) ? stats.recentFrames : []
919
- return {
920
- mode: 'main-thread',
921
- frames: recent.slice().sort((a, b) => b - a).slice(0, ${t}),
922
- }
923
- })()`});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 '${y("perf")} start' first`);break}console.log(` worst ${n.length} sampled frames (ms):`),console.log(" total layout render copy aux other t+");for(let[m,p,b,f,w,O,B]of n)console.log(` ${p.toFixed(2).padStart(7)} ${b.toFixed(2).padStart(7)} ${f.toFixed(2).padStart(7)} ${w.toFixed(2).padStart(7)} ${O.toFixed(2).padStart(6)} ${B.toFixed(2).padStart(7)} ${String(m).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 '${y("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=a[2];if(!t||!["goHome","appSwitcher","lockScreen"].includes(t)){console.log(`
924
- ${y("perf")} transition <event> \u2014 profile a shell transition
925
-
926
- events:
927
- goHome swipe-to-home animation
928
- appSwitcher app switcher card animation
929
- lockScreen lock screen transition
930
-
931
- note: uses 600ms capture window \u2014 may need --timeout 10000 flag
932
-
933
- examples:
934
- ${y("perf")} transition goHome --timeout 10000
935
- ${y("perf")} transition appSwitcher
936
- `);break}let r=`sootsim:${t}`;console.log(` profiling ${t} transition...`),console.log(" (use --timeout 10000 if this times out)");let n=await l.send({type:"evaluate",code:`(async () => {
937
- // only supported in render-worker mode
938
- if (!window.__sootsimRenderHost) {
939
- return { error: 'transition profiling requires render-worker mode' }
940
- }
941
-
942
- // start sampling
943
- window.__sootsimRenderHost.startSampling()
944
-
945
- // give a frame for sampling to start
946
- await new Promise(r => requestAnimationFrame(() => r(undefined)))
947
-
948
- // dispatch the shell event
949
- window.dispatchEvent(new Event('${r}'))
950
-
951
- // wait 600ms for transition to complete (shell animations are ~300-500ms)
952
- // using fixed timing avoids complex animation-end detection
953
- await new Promise(r => setTimeout(r, 600))
954
-
955
- // flush samples and compute stats
956
- const samples = await window.__sootsimRenderHost.flushSamples()
957
- const frameTimes = samples.map(s => s[1])
958
- const layoutTimes = samples.map(s => s[2])
959
- const renderTimes = samples.map(s => s[3])
960
- const copyTimes = samples.map(s => s[4])
961
- const auxTimes = samples.map(s => s[5] || 0)
962
- const otherTimes = samples.map(s => s[6] || 0)
963
- const sorted = [...frameTimes].sort((a, b) => a - b)
964
- const total = frameTimes.reduce((a, b) => a + b, 0)
965
- const avg = frameTimes.length > 0 ? total / frameTimes.length : 0
966
- const max = Math.max(...frameTimes, 0)
967
- const layoutTotal = layoutTimes.reduce((a, b) => a + b, 0)
968
- const renderTotal = renderTimes.reduce((a, b) => a + b, 0)
969
- const copyTotal = copyTimes.reduce((a, b) => a + b, 0)
970
- const auxTotal = auxTimes.reduce((a, b) => a + b, 0)
971
- const otherTotal = otherTimes.reduce((a, b) => a + b, 0)
972
-
973
- return {
974
- event: '${t}',
975
- frames: frameTimes.length,
976
- totalMs: total,
977
- avgMs: avg,
978
- maxMs: max,
979
- layoutTotalMs: layoutTotal,
980
- renderTotalMs: renderTotal,
981
- copyTotalMs: copyTotal,
982
- auxTotalMs: auxTotal,
983
- otherTotalMs: otherTotal,
984
- layoutAvgMs: frameTimes.length > 0 ? layoutTotal / frameTimes.length : 0,
985
- renderAvgMs: frameTimes.length > 0 ? renderTotal / frameTimes.length : 0,
986
- copyAvgMs: frameTimes.length > 0 ? copyTotal / frameTimes.length : 0,
987
- auxAvgMs: frameTimes.length > 0 ? auxTotal / frameTimes.length : 0,
988
- otherAvgMs: frameTimes.length > 0 ? otherTotal / frameTimes.length : 0,
989
- p50: sorted[Math.floor(sorted.length * 0.5)] || 0,
990
- p95: sorted[Math.floor(sorted.length * 0.95)] || 0,
991
- p99: sorted[Math.floor(sorted.length * 0.99)] || 0,
992
- jankFrames: frameTimes.filter(f => f > 16.67).length,
993
- samples,
994
- }
995
- })()`});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 m=n.avgMs>0?(1e3/n.avgMs).toFixed(1):"?",p=n.frames>0?(n.jankFrames/n.frames*100).toFixed(1):"0";console.log(` ${t} transition profiled:
996
-
997
- frames: ${n.frames}
998
- total: ${n.totalMs.toFixed(1)}ms
999
- avg: ${n.avgMs.toFixed(2)}ms (${m} fps)
1000
- max: ${n.maxMs.toFixed(2)}ms
1001
-
1002
- breakdown (avg per frame):
1003
- layout: ${n.layoutAvgMs?.toFixed(2)||"?"}ms
1004
- render: ${n.renderAvgMs?.toFixed(2)||"?"}ms
1005
- copy: ${n.copyAvgMs?.toFixed(2)||"?"}ms
1006
- aux: ${n.auxAvgMs?.toFixed(2)||"?"}ms
1007
- other: ${n.otherAvgMs?.toFixed(2)||"?"}ms
1008
-
1009
- distribution (${n.frames} samples):
1010
- p50: ${n.p50.toFixed(2)}ms
1011
- p95: ${n.p95.toFixed(2)}ms
1012
- p99: ${n.p99.toFixed(2)}ms
1013
- jank: ${n.jankFrames} frames (${p}%) >16.67ms`),Array.isArray(n.samples)&&n.samples.length>0&&(console.log(""),he(n.samples.map(b=>b[1])));break}default:console.error(` unknown perf subcommand: ${e}`),process.exit(1)}break}case"errors":{let e=a[1];if(e==="clear"){await l.send({type:"evaluate",code:'window.__sootsimConsole?.clear(); "cleared"'}),E(d)?C({cleared:!0}):console.log(" error buffer cleared");break}let t=e?Number(e):20,s=await l.send({type:"evaluate",code:`window.__sootsimConsole?.getErrors(${t}) || []`}),r=Array.isArray(s)?s:[];if(E(d)){C(r);break}if(r.length===0){console.log(" no errors captured");break}console.log(` ${r.length} error(s):
1014
- `);for(let n of r){let m=new Date(n.timestamp).toLocaleTimeString(),p=n.args.map(b=>typeof b=="object"?JSON.stringify(b):b).join(" ");if(console.log(` [${m}] ${p}`),n.stack){let b=n.stack.split(`
1015
- `).slice(0,3);for(let f of b)console.log(` ${f.trim()}`)}}break}case"warnings":{let e=a[1]?Number(a[1]):20,t=await l.send({type:"evaluate",code:`window.__sootsimConsole?.getWarnings(${e}) || []`}),s=Array.isArray(t)?t:[];if(E(d)){C(s);break}if(s.length===0){console.log(" no warnings captured");break}console.log(` ${s.length} warning(s):
1016
- `);for(let r of s){let n=new Date(r.timestamp).toLocaleTimeString(),m=r.args.map(p=>typeof p=="object"?JSON.stringify(p):p).join(" ");console.log(` [${n}] ${m}`)}break}case"animations":{let e=await z(l,"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):
1017
- `);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),m=`${Math.round((t.progress??0)*100)}%`,p=`${Math.round(t.elapsedMs??0)}ms`,b=t.loop?" loop":"",f=t.layoutBound?" layout":"";console.log(` #${t.id} ${s} ${r.padEnd(14)} cur=${n.padEnd(7)} ${m.padStart(4)} ${p}${b}${f}`)}break}case"animation":{let e=a[1];(!e||e==="--help"||e==="-h")&&(console.error(` usage: ${y("animation")} <id>`),process.exit(1));let t=Number(e);Number.isFinite(t)||(console.error(` invalid id: ${e}`),process.exit(1));let s=await z(l,"getAnimation",t);console.log(JSON.stringify(s,null,2));break}case"stop-animation":{let e=a[1];(!e||e==="--help"||e==="-h")&&(console.error(` usage: ${y("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(l,"stopAnimation",t);console.log(` stopped ${s??0} animation(s)`);break}case"requests":{let e=a[1];if(e==="clear"){await z(l,"clearRequests"),E(d)?C({cleared:!0}):console.log(" request buffer cleared");break}let t=e==="all",s=t?a[2]:e,r=s?Number(s):20,n=t?await z(l,"getRequests",r):await z(l,"getFailedRequests",r),m=Array.isArray(n)?n:[];if(E(d)){C(m);break}if(m.length===0){console.log(t?" no requests captured":" no failed requests captured");break}console.log(` ${m.length} ${t?"request(s)":"failed request(s)"}:
1018
- `);for(let p of m){let b=new Date(p.timestamp).toLocaleTimeString();console.log(` [${b}] ${q(p)}`),p.responseBody?console.log(` ${p.responseBody}`):p.error&&console.log(` ${p.error}`)}break}case"network":{let e=a[1],t=null,s=null,r=!1,n=!1,m=!1;for(let N=0;N<d.length;N++){let M=d[N];if(M==="--filter")t=d[N+1]??null,N++;else if(M==="--limit"){let F=Number(d[N+1]);Number.isFinite(F)&&(s=F),N++}else M==="--failed"?r=!0:M==="--tail"||M==="-f"?n=!0:M==="--json"&&(m=!0)}if(e==="clear"){await l.send({type:"evaluate",code:'window.__sootsimObservability?.network.clear(); "cleared"'}),console.log(" network buffer cleared");break}if(e==="get"){let N=a[2];N||(console.error(" usage: sootsim network get <id>"),process.exit(1));let M=await l.send({type:"evaluate",code:`(() => {
1019
- const obs = window.__sootsimObservability;
1020
- if (!obs) return null;
1021
- return obs.network.getSnapshot().find(e => e.id === ${JSON.stringify(N)}) || null;
1022
- })()`});M||(console.error(` no entry with id ${N}`),process.exit(1)),m?console.log(JSON.stringify(M,null,2)):Ft(M);break}let p=s??(n?200:e?Number(e):20);Number.isFinite(p)||(console.error(` invalid limit: ${e}`),process.exit(1));let b=async()=>{let N=await l.send({type:"evaluate",code:`(() => {
1023
- const obs = window.__sootsimObservability;
1024
- if (!obs) return { ok: false };
1025
- return { ok: true, entries: obs.network.getSnapshot() };
1026
- })()`});if(!N||!N.ok)throw new Error("observability bridge not installed \u2014 is the engine running?");return N.entries??[]},f=N=>{let M=N;if(r&&(M=M.filter(F=>!!F.error||F.status!=null&&F.status>=400)),t){let F=t.toLowerCase();M=M.filter(W=>(W.displayUrl||W.url).toLowerCase().includes(F))}return M};if(!n){let N=await b(),M=f(N).slice(-p);if(m){console.log(JSON.stringify(M,null,2));break}if(M.length===0){console.log(N.length===0?" no network requests captured":" no matching requests");break}console.log(` ${M.length} request(s):
1027
- `);for(let F of M)Ze(F);break}console.log(` tailing network (ctrl-c to stop)...
1028
- `);let w=new Set,O=!0,B=()=>{O=!1};process.on("SIGINT",B);try{for(;O;){let N=await b(),M=f(N);for(let F of M)F.durationMs!=null&&(w.has(F.id)||(w.add(F.id),m?console.log(JSON.stringify(F)):Ze(F)));await Y(250)}}finally{process.off("SIGINT",B)}break}case"logs":{let e=a[1],t=null,s=null,r=null,n=!1,m=!1,p=!1;for(let g=0;g<d.length;g++){let T=d[g];if(T==="--filter")t=d[g+1]??null,g++;else if(T==="--limit"){let _=Number(d[g+1]);Number.isFinite(_)&&(s=_),g++}else T==="--level"?(r=d[g+1]??null,g++):T==="--tail"||T==="-f"?n=!0:T==="--json"?m=!0:(T==="--internal"||T==="--all")&&(p=!0)}let b=r?new Set(r.split(",").map(g=>g.trim()).filter(g=>g==="log"||g==="info"||g==="warn"||g==="error"||g==="debug")):null;if(e==="clear"){await l.send({type:"evaluate",code:'window.__sootsimObservability?.logs.clear(); "cleared"'}),console.log(" log buffer cleared");break}let f=!m&&process.stdout.isTTY===!0,w=s??(n?500:e?Number(e):50);Number.isFinite(w)||(console.error(` invalid limit: ${e}`),process.exit(1));let O=async()=>{let g=await l.send({type:"evaluate",code:`(() => {
1029
- const obs = window.__sootsimObservability;
1030
- if (!obs) return { ok: false };
1031
- return { ok: true, entries: obs.logs.getSnapshot() };
1032
- })()`});if(!g||!g.ok)throw new Error("observability bridge not installed \u2014 is the engine running?");return g.entries??[]},B=g=>{let T=g.args[0];return typeof T!="string"?!1:T.startsWith("[sootsim]")},N=g=>{let T=g;if(p||(T=T.filter(_=>!B(_))),b&&(T=T.filter(_=>b.has(_.level))),t){let _=t.toLowerCase();T=T.filter(P=>P.args.join(" ").toLowerCase().includes(_))}return T};if(!n){let g=await O(),T=N(g).slice(-w);if(m){console.log(JSON.stringify(T,null,2));break}if(T.length===0){console.log(g.length===0?" no logs captured":" no matching logs");break}console.log(` ${T.length} log(s):
1033
- `);for(let _ of T)et(_,f);break}console.log(` tailing logs (ctrl-c to stop)...
1034
- `);let M=new Set,F=!0,W=()=>{F=!1};process.on("SIGINT",W);try{for(;F;){let g=await O(),T=N(g);for(let _ of T)M.has(_.id)||(M.add(_.id),m?console.log(JSON.stringify(_)):et(_,f));await Y(250)}}finally{process.off("SIGINT",W)}break}default:console.error(` unknown subcommand: ${h}`),process.exit(1)}if(H.has(h)&&!o.includes("--no-wait")&&process.env.SOOTSIM_NO_AUTO_WAIT!=="1"&&await ne(l),!D.has(h)&&!E(d)){let e=await Z();try{await J({counts:e.console})}catch{}try{await x({counts:e.requests})}catch{}}}catch(e){let t=e instanceof Error?e.message:String(e);if(console.error(` ${h??"inspect"} failed: ${t}`),/^no browser connected( with id .+)?$/.test(t))Ae(A);else{try{await Me(l)}catch{}try{await J({includeTail:!0})}catch{}try{await x({includeTail:!0})}catch{}}process.exit(1)}finally{l.close()}}export{rs as runInspect};