sootsim 0.1.66 → 0.1.68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-cli/bin.js +7 -28
- package/dist-cli/chunks/agent-RWWC5VLR.js +46 -0
- package/dist-cli/chunks/{agent-wrapper-5DJBERZP.js → agent-wrapper-AZ2TWUZV.js} +2 -2
- package/dist-cli/chunks/{assert-RHILK3WR.js → assert-YVADDYYY.js} +2 -2
- package/dist-cli/chunks/auto-bootstrap-E62IXD2G.js +2 -0
- package/dist-cli/chunks/beta-7MI67AHK.js +2 -0
- package/dist-cli/chunks/{chunk-XZ5SQJM2.js → chunk-2HVRBEOU.js} +128 -36
- package/dist-cli/chunks/chunk-2NFRZQ3K.js +73 -0
- package/dist-cli/chunks/{chunk-22CO2ZE3.js → chunk-3HF6BNSA.js} +2 -2
- package/dist-cli/chunks/{chunk-GDCMTHEU.js → chunk-3NNUNABL.js} +1 -1
- package/dist-cli/chunks/{chunk-BD76YSRN.js → chunk-3QA6YYSG.js} +2 -2
- package/dist-cli/chunks/{chunk-T4YLDM5C.js → chunk-52QFCYGQ.js} +3 -3
- package/dist-cli/chunks/chunk-5LDGAVAV.js +23 -0
- package/dist-cli/chunks/{chunk-LRBMW2WC.js → chunk-5QUYJKLU.js} +2 -2
- package/dist-cli/chunks/chunk-5SGAFI2M.js +23 -0
- package/dist-cli/chunks/{chunk-VRV2X4X2.js → chunk-6453CCSA.js} +1 -1
- package/dist-cli/chunks/{chunk-FXF2FHPI.js → chunk-6JGI2JVM.js} +2 -2
- package/dist-cli/chunks/chunk-6TQ2IBH6.js +2 -0
- package/dist-cli/chunks/chunk-72Y42WVX.js +186 -0
- package/dist-cli/chunks/{chunk-4LYNJPUM.js → chunk-BQLKO6NP.js} +2 -2
- package/dist-cli/chunks/{chunk-AYBGSHQK.js → chunk-C3R25CWY.js} +2 -2
- package/dist-cli/chunks/{chunk-TJEP4DBA.js → chunk-CFR6W2AH.js} +2 -2
- package/dist-cli/chunks/chunk-CMEWLMED.js +1 -0
- package/dist-cli/chunks/chunk-CZWZG7GL.js +2 -0
- package/dist-cli/chunks/chunk-D5LXWWGN.js +12 -0
- package/dist-cli/chunks/{chunk-EIQLQDKX.js → chunk-E7FCGYB5.js} +2 -2
- package/dist-cli/chunks/{chunk-DEQ7RED3.js → chunk-FBO7YRJM.js} +2 -2
- package/dist-cli/chunks/chunk-FITG7BVA.js +1 -0
- package/dist-cli/chunks/{chunk-BEQD2DSK.js → chunk-G3WXMB3Z.js} +1 -1
- package/dist-cli/chunks/chunk-GFXFPPNR.js +35 -0
- package/dist-cli/chunks/chunk-H6YUT7HX.js +372 -0
- package/dist-cli/chunks/{chunk-D4VEI6MI.js → chunk-HC43PTFD.js} +1 -1
- package/dist-cli/chunks/chunk-HPFXTPOD.js +1 -0
- package/dist-cli/chunks/{chunk-V4SZERWD.js → chunk-J7XCQWQI.js} +14 -14
- package/dist-cli/chunks/{chunk-HIN5TAAL.js → chunk-K6N6DEL5.js} +1 -1
- package/dist-cli/chunks/{chunk-6AP6LXVV.js → chunk-KKK4RTBP.js} +1 -1
- package/dist-cli/chunks/{chunk-NCSGLZRV.js → chunk-OFTI3N27.js} +2 -2
- package/dist-cli/chunks/{chunk-BTHB3PMG.js → chunk-QHAZOOK2.js} +3 -3
- package/dist-cli/chunks/{chunk-4NT6VRUU.js → chunk-QYFPV5YO.js} +1 -1
- package/dist-cli/chunks/chunk-TBVBPZRF.js +3 -0
- package/dist-cli/chunks/{chunk-LVFWALS4.js → chunk-TKDMCYGS.js} +2 -2
- package/dist-cli/chunks/{chunk-LCKLQSZX.js → chunk-TY5CBM3C.js} +2 -2
- package/dist-cli/chunks/{chunk-WAOLC7WV.js → chunk-TZYXNQHA.js} +1 -1
- package/dist-cli/chunks/chunk-U7KUAZJB.js +119 -0
- package/dist-cli/chunks/{chunk-M2Q4FXRE.js → chunk-WHJFB6AK.js} +1 -1
- package/dist-cli/chunks/{chunk-HWCZYW6M.js → chunk-WIW3G6HS.js} +2 -2
- package/dist-cli/chunks/chunk-WXISHMXL.js +2 -0
- package/dist-cli/chunks/{chunk-UMXVWFST.js → chunk-YSDIOWNN.js} +1 -1
- package/dist-cli/chunks/{chunk-EEMGSSWY.js → chunk-Z6BCORBY.js} +2 -2
- package/dist-cli/chunks/{chunk-UNSLXX7V.js → chunk-ZP7YYRHI.js} +2 -2
- package/dist-cli/chunks/cli-version-LM6OBGUK.js +2 -0
- package/dist-cli/chunks/{compat-I7JXYUJN.js → compat-Z3IFUQ73.js} +3 -3
- package/dist-cli/chunks/{config-3HR5RKVH.js → config-XBERIMLW.js} +2 -2
- package/dist-cli/chunks/control-SWOP3KB7.js +2 -0
- package/dist-cli/chunks/{cpu-profile-ZVHMTVAU.js → cpu-profile-SNX23Q5V.js} +2 -2
- package/dist-cli/chunks/daemon-QQPC4GOV.js +65 -0
- package/dist-cli/chunks/{debug-CQ6Y7GJ2.js → debug-WENYS45R.js} +5 -5
- package/dist-cli/chunks/demo-app-registry-QWOGX5C2.js +2 -0
- package/dist-cli/chunks/{detox-7ZKTGLDR.js → detox-P4N47V6P.js} +2 -2
- package/dist-cli/chunks/{device-4M6Z7E2N.js → device-5WWFV22H.js} +2 -2
- package/dist-cli/chunks/{diagnose-SMQLYGNX.js → diagnose-HJ4F3ER7.js} +2 -2
- package/dist-cli/chunks/drivers-GAEMIY75.js +2 -0
- package/dist-cli/chunks/{electron-6N2MIN5W.js → electron-JHFA2OGV.js} +3 -3
- package/dist-cli/chunks/flow-J67STV2Q.js +2 -0
- package/dist-cli/chunks/{hints-RJCZS2E3.js → hints-UHQ2T2RX.js} +2 -2
- package/dist-cli/chunks/{home-paths-DCUNA3CD.js → home-paths-NWDFFIX4.js} +2 -2
- package/dist-cli/chunks/inspect-O34RH4AE.js +970 -0
- package/dist-cli/chunks/install-ZB2AGO44.js +2 -0
- package/dist-cli/chunks/{install-desktop-C7424OSW.js → install-desktop-RYP35PHA.js} +3 -3
- package/dist-cli/chunks/{keys-TXUQOAZ3.js → keys-U5YI77TK.js} +2 -2
- package/dist-cli/chunks/{launch-MVA44QTC.js → launch-UFOGCQWO.js} +3 -3
- package/dist-cli/chunks/{login-NHO2WTHC.js → login-SPX6IK6Q.js} +4 -4
- package/dist-cli/chunks/{logout-SRRWADCE.js → logout-I6UE3XYL.js} +2 -2
- package/dist-cli/chunks/{maestro-UHNXEZAN.js → maestro-IPEULAUZ.js} +2 -2
- package/dist-cli/chunks/{preview-ETIUP7KC.js → preview-CE27FPGG.js} +2 -2
- package/dist-cli/chunks/{profile-MY5JFVIF.js → profile-JZSFMO2Y.js} +2 -2
- package/dist-cli/chunks/{react-KCMC4GL3.js → react-6IJQG4V3.js} +2 -2
- package/dist-cli/chunks/record-6WDKEBXL.js +70 -0
- package/dist-cli/chunks/runtime-P54OGI57.js +2 -0
- package/dist-cli/chunks/{runtime-delivery-LQZIWQU6.js → runtime-delivery-C4KG6ISS.js} +2 -2
- package/dist-cli/chunks/screenshot-VQTI6G32.js +33 -0
- package/dist-cli/chunks/{screenshot-mode-USPWASI3.js → screenshot-mode-JBDCHRSS.js} +2 -2
- package/dist-cli/chunks/{screenshots-EPEDNA6H.js → screenshots-HLMGN2OX.js} +2 -2
- package/dist-cli/chunks/{server-222QT33M.js → server-U3QLKQDX.js} +6 -6
- package/dist-cli/chunks/setup-repo-TZULA5RK.js +2 -0
- package/dist-cli/chunks/{skills-6XRREE2M.js → skills-SMML5DJP.js} +2 -2
- package/dist-cli/chunks/{start-YCAZBZEX.js → start-7SCU4I64.js} +4 -4
- package/dist-cli/chunks/store-WEIVIM3L.js +2 -0
- package/dist-cli/chunks/telemetry-U3BBVPLJ.js +2 -0
- package/dist-cli/chunks/{test-6TNRHSWC.js → test-UWFHFDN7.js} +3 -3
- package/dist-cli/chunks/{three-mode-MDOLHGXW.js → three-mode-CJUNGCIF.js} +2 -2
- package/dist-cli/chunks/{timeline-72MWE44G.js → timeline-DIRXVM6R.js} +3 -3
- package/dist-cli/chunks/{upgrade-IHZ4DFAE.js → upgrade-LQQU4GSZ.js} +2 -2
- package/dist-cli/chunks/upload-SSAFKJGF.js +2 -0
- package/dist-cli/chunks/web-AJU6QA43.js +2 -0
- package/dist-cli/chunks/what-happened-QFXDQ6VU.js +22 -0
- package/dist-cli/chunks/{whoami-2EYGCRDQ.js → whoami-HWXPDZEF.js} +2 -2
- package/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/agent-sessions.cjs +1 -1
- package/dist-lib/attached-projects.cjs +1 -1
- package/dist-lib/auth/shared-session.cjs +1 -1
- package/dist-lib/backend-origin.cjs +1 -1
- package/dist-lib/bridge-constants.cjs +1 -1
- package/dist-lib/cli-constants.cjs +1 -1
- package/dist-lib/config.cjs +1 -1
- package/dist-lib/dev-bundle-resolution.cjs +9 -2
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +23 -7
- package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/index.cjs +1 -1
- package/dist-lib/metro.cjs +1 -1
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/render-mode.cjs +1 -1
- package/dist-lib/vite-base.cjs +23 -7
- package/dist-lib/vite.cjs +1 -1
- package/package.json +1 -1
- package/dist-cli/chunks/agent-IW7CCSSI.js +0 -61
- package/dist-cli/chunks/auto-bootstrap-PS2UDBP7.js +0 -2
- package/dist-cli/chunks/beta-XLYWSKEA.js +0 -2
- package/dist-cli/chunks/chunk-5MVFADNH.js +0 -3
- package/dist-cli/chunks/chunk-7NYW73Q6.js +0 -2
- package/dist-cli/chunks/chunk-EMMX6RF7.js +0 -73
- package/dist-cli/chunks/chunk-FIIBCY5I.js +0 -3
- package/dist-cli/chunks/chunk-G4VWDOWB.js +0 -17
- package/dist-cli/chunks/chunk-GMKGJHVG.js +0 -1
- package/dist-cli/chunks/chunk-M3ZEZHOB.js +0 -34
- package/dist-cli/chunks/chunk-MWTMLNGM.js +0 -348
- package/dist-cli/chunks/chunk-NQKBIKUZ.js +0 -1
- package/dist-cli/chunks/chunk-QMRXLBPN.js +0 -11
- package/dist-cli/chunks/chunk-X4HQLK4V.js +0 -119
- package/dist-cli/chunks/chunk-XOTJSR4T.js +0 -2
- package/dist-cli/chunks/chunk-YSQV4D7P.js +0 -1
- package/dist-cli/chunks/chunk-Z6HSVZIO.js +0 -100
- package/dist-cli/chunks/cli-version-ESQ2S6N5.js +0 -2
- package/dist-cli/chunks/control-TDZXFNVT.js +0 -2
- package/dist-cli/chunks/daemon-VYRTYH55.js +0 -83
- package/dist-cli/chunks/demo-app-registry-JAYU7BBM.js +0 -2
- package/dist-cli/chunks/drivers-SIY6JBEM.js +0 -2
- package/dist-cli/chunks/flow-BZEWL7UQ.js +0 -2
- package/dist-cli/chunks/inspect-T5NC7HHB.js +0 -1025
- package/dist-cli/chunks/install-YTJI5RS7.js +0 -2
- package/dist-cli/chunks/record-DHDSXC2Y.js +0 -51
- package/dist-cli/chunks/runtime-AJP6V5LM.js +0 -2
- package/dist-cli/chunks/screenshot-4KPEEI6I.js +0 -28
- package/dist-cli/chunks/setup-repo-D56L3CEB.js +0 -2
- package/dist-cli/chunks/store-Z32KZ34K.js +0 -2
- package/dist-cli/chunks/telemetry-RFTX2BZK.js +0 -2
- package/dist-cli/chunks/upload-G5C7LJWG.js +0 -2
- package/dist-cli/chunks/web-JLJSJUS2.js +0 -2
- package/dist-cli/chunks/what-happened-BUXSJ3QS.js +0 -15
|
@@ -0,0 +1,970 @@
|
|
|
1
|
+
/*! sootsim v0.1.68 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
|
|
2
|
+
import{a as Q}from"./chunk-TBVBPZRF.js";import{a as pt,b as ft}from"./chunk-TZYXNQHA.js";import{a as He,h as ye,k as ee}from"./chunk-2HVRBEOU.js";import{b as gt,c as yt,i as ht}from"./chunk-D5LXWWGN.js";import"./chunk-WIW3G6HS.js";import{a as Z,b as j,c as J,d as ne,e as V,f as ge,g as de,h as dt,i as ut,j as Fe,k as mt}from"./chunk-GFXFPPNR.js";import{B as at,D as le,E as lt,K as ct,a as fe,b as Ue,c as Ke,d as ze,e as Ye,f as Ge,g as Xe,h as Me,i as Ie,n as Ne,o as Ve,p as Qe,q as Ze,r as et,s as tt,t as ot,u as st,v as nt,w as rt,x as it}from"./chunk-J7XCQWQI.js";import"./chunk-TY5CBM3C.js";import"./chunk-72Y42WVX.js";import"./chunk-3NNUNABL.js";import"./chunk-FITG7BVA.js";import"./chunk-C3R25CWY.js";import"./chunk-K6N6DEL5.js";import{a as Be}from"./chunk-WXISHMXL.js";import{a as Se,c as ke}from"./chunk-U7KUAZJB.js";import{a as De}from"./chunk-6TQ2IBH6.js";import{c as Je,e as Le,f as qe,g as We,h as Te}from"./chunk-5LDGAVAV.js";import{b as je}from"./chunk-6453CCSA.js";import"./chunk-CZWZG7GL.js";import"./chunk-G3WXMB3Z.js";import"./chunk-HC43PTFD.js";import{existsSync as eo,mkdirSync as to,readFileSync as oo,rmSync as bt,writeFileSync as so}from"fs";import{tmpdir as no}from"os";import{dirname as ro,join as io,resolve as ao}from"path";var ue=1,lo="SOOTSIM_INSPECT_NOTICE_PATH",co=300*1e3,uo=15e3;function wt(){return ao(process.env[lo]||io(no(),"sootsim-inspect-notice-state.json"))}function mo(o,l){return Object.fromEntries(Object.entries(o).filter(([,i])=>typeof i?.signature=="string"&&Number.isFinite(i?.updatedAt)&&l-i.updatedAt<=co))}function po(o){let l=wt();if(!eo(l))return{version:ue,entries:{}};try{let i=JSON.parse(oo(l,"utf8"));return i.version!==ue||!i.entries||typeof i.entries!="object"?(bt(l,{force:!0}),{version:ue,entries:{}}):{version:ue,entries:mo(i.entries,o)}}catch{return bt(l,{force:!0}),{version:ue,entries:{}}}}function fo(o){let l=wt();to(ro(l),{recursive:!0}),so(l,JSON.stringify(o,null,2)+`
|
|
3
|
+
`)}function go(o,l){let i=l.trim()||"default";return`${o}:${i}`}function _e(o,l,i,c={}){let f=c.nowMs??Date.now(),a=c.cooldownMs??uo,y=po(f),$=go(o,l),_=y.entries[$];return _&&_.signature===i&&f-_.updatedAt<a?!1:(y.entries[$]={signature:i,updatedAt:f},fo(y),!0)}async function xt(o,l={args:[]}){let i=await Ue(o);if(j(l.args)){J(i);return}console.log(` nodes: ${i.nodes}`)}function Ae(o,l){let i=o.indexOf(l);return i>=0&&i+1<o.length?o[i+1]:null}async function $t(o){let{bridge:l,args:i,positional:c}=o,f=i.includes("--verbose")||i.includes("-v"),a=j(i),y=f&&!a,$=i.includes("--watch")||i.includes("-w"),_=1e3,k=i.includes("--compact"),b=i.includes("--no-xy"),S=i.includes("--no-clipped"),M=Ae(i,"--testid-like"),I=Ae(i,"--only"),O=Ae(i,"--subtree"),D=c[1],u=D?/[*?]/.test(D):!1,H=!u&&!I?D:void 0,B=I??(u?D:void 0),C=async()=>{await ge(l,{verbose:y});let Y=await Ye(l,{describe:!0,verbose:f,filter:H||"",testIdLike:M||void 0,onlyGlob:B||void 0,subtreeRoot:O||void 0,compact:k,hideXy:b}),x=Y?.tree,T=Y?.shell,q=Y?.keyboard;if(a){J({shell:T,tree:x??"",keyboard:q});return}if(T&&typeof T=="object"){let E=[T.state?`state=${T.state}`:null,T.activeApp?`app=${T.activeApp}`:null,T.showSwitcher?"switcher":null,T.switcherPhase&&T.switcherPhase!=="idle"?`phase=${T.switcherPhase}`:null].filter(Boolean);E.length>0&&console.log(` shell: ${E.join(" ")}`)}if(typeof x=="string"&&x.startsWith("__SUBTREE_NOT_FOUND__:")){let E=x.slice(22);console.log(` subtree root not found: ${E}`),Q("subtree-root-not-found",E);return}if(!x){let E=Y?.nodeCount??0;console.log(" no matching nodes found"),!(H||M||B||O)&&E<10&&Q("app-still-loading",E);return}let z=x,G=0;if(S&&typeof z=="string"){let E=z.split(`
|
|
4
|
+
`),se=[];for(let pe of E){if(pe.includes("(clipped:")){G+=1;continue}se.push(pe)}z=se.join(`
|
|
5
|
+
`)}console.log(z),G>0&&console.log(` ${G} clipped row(s) hidden (omit --no-clipped to see)`);let re=H||M||B||O;if((H||M||B)&&!$&&Q("describe-filter-context"),!re&&!$&&x.split(`
|
|
6
|
+
`).length>=80&&Q("describe-use-filters"),q&&q.visible){let E=q.spec,se=[E?.keyboardType?`type=${E.keyboardType}`:null,E?.returnKeyType&&E.returnKeyType!=="default"?`return=${E.returnKeyType}`:null,q.mode!=="letters"?`mode=${q.mode}`:null,q.shifted?"shift":null,q.capsLock?"caps":null,E?.autoCapitalize&&E.autoCapitalize!=="sentences"?`autoCap=${E.autoCapitalize}`:null,q.accessoryBarId?`accessory=${q.accessoryBarId}`:null].filter(Boolean);console.log(`
|
|
7
|
+
keyboard: ${se.join(" ")||"visible"}`)}};if($)for(console.log(` watching... (Ctrl+C to stop)
|
|
8
|
+
`);;)console.clear(),await C(),await Z(_);else await C()}var yo=["SOOTSIM_AGENT","CLAUDECODE","CLAUDE_CODE_ENTRYPOINT","CLAUDE_CODE_SESSION_ID","CODEX_THREAD_ID","CURSOR_TRACE_ID","AIDER_MODEL"];function he(){if(process.env.SOOTSIM_AGENT==="0")return!1;for(let o of yo){let l=process.env[o];if(l&&l.trim()&&l!=="0")return!0}return!1}async function vt(o){let{bridge:l,args:i,effectiveArgs:c,positional:f,inspectUsage:a}=o,y=x=>{let T=c.indexOf(x);return T>=0&&T+1<c.length?c[T+1]:null},$=x=>c.includes(x),_=y("--testid")||y("--test-id"),k=y("--role"),b=y("--type"),S=y("--text"),M=$("--pressable"),I=$("--visible"),O=$("--interactive-targets")||$("--actions"),D=!_&&!k&&!b&&!S&&!M&&!I&&!O?f[1]:null,u=S??D,H=await Xe(l,{testId:_,role:k,type:b,text:u,pressable:M,visible:I,interactive:O});H||(console.error(a("find","<text> | --text <t> | --testid <id> | --role <r> | --type <t> | --pressable | --visible | --interactive-targets")),process.exit(1));let{mode:B,result:C}=H,oe=j(i),Y=i.includes("--verbose")||i.includes("--dump");if(oe)B==="interactive-targets"&&Array.isArray(C)?J(Me(C).map(x=>({...x,tap:Ie(x)}))):J(C??null);else if(Array.isArray(C))if(C.length===0){console.log(` no ${B} nodes found`);let x=await l.send({type:"evaluate",code:"(async () => (await window.__sootsimTest?.getNodeCount?.()) || 0)()"});typeof x=="number"&&x<10&&Q("app-still-loading",x)}else if(B==="interactive-targets"){let x=Me(C);console.log(` found ${x.length} interactive target${x.length===1?"":"s"} (sorted by score):`);for(let T of x.slice(0,20)){let q=T.absolutePosition?`@(${Math.round(T.absolutePosition.x)},${Math.round(T.absolutePosition.y)})`:"",z=T.layout?`${Math.round(T.layout.width)}x${Math.round(T.layout.height)}`:"?x?",G=T.text?` "${T.text.slice(0,30)}"`:"",re=T.testID?` #${T.testID}`:"",ie=T.accessibilityLabel?` \u24D8"${String(T.accessibilityLabel).slice(0,24)}"`:"",E=T.accessibilityRole?`[${T.accessibilityRole}]`:T.type,se=Ie(T);console.log(` ${E}${G}${ie}${re} ${z} ${q}`),console.log(` \u2192 ${se}`),Y&&console.log(Pe(JSON.stringify(T,null,2)," "))}x.length>20&&console.log(` ... and ${x.length-20} more`)}else{console.log(` found ${C.length} node${C.length===1?"":"s"} (${B}):`);for(let x of C.slice(0,20)){let T=x.absolutePosition?`@(${Math.round(x.absolutePosition.x)},${Math.round(x.absolutePosition.y)})`:"",q=x.layout?`${Math.round(x.layout.width)}x${Math.round(x.layout.height)}`:"?x?",z=x.text?` "${x.text.slice(0,30)}"`:"",G=x.testID?` #${x.testID}`:"",re=x.pressable?" (tap)":"",ie=x.accessibilityRole?`[${x.accessibilityRole}]`:x.type;console.log(` ${ie}${z}${G} ${q} ${T}${re}`),Y&&console.log(Pe(JSON.stringify(x,null,2)," "))}C.length>20&&console.log(` ... and ${C.length-20} more`)}else if(C==null)console.log(` not found: ${u||_||k||b||""||B}`),_&&Q("wait-selector-for-missing-testid",_);else{let x=C;if(x.type&&x.absolutePosition){let T=`@(${Math.round(x.absolutePosition.x)},${Math.round(x.absolutePosition.y)})`,q=x.layout?`${Math.round(x.layout.width)}x${Math.round(x.layout.height)}`:"?x?",z=x.text?` "${x.text.slice(0,40)}"`:"",G=x.testID?` #${x.testID}`:"",re=x.pressable?" (tap)":"",ie=x.accessibilityRole?`[${x.accessibilityRole}]`:x.type;console.log(` ${ie}${z}${G} ${q} ${T}${re}`),Y&&console.log(Pe(JSON.stringify(x,null,2)," "))}else console.log(JSON.stringify(C,null,2))}}function Pe(o,l){return o.split(`
|
|
9
|
+
`).map(i=>l+i).join(`
|
|
10
|
+
`)}async function St(o,l={}){let i=await at(o);if("error"in i&&(console.error(i.error),process.exit(1)),l.json){console.log(JSON.stringify(i,null,2));return}let{visible:c,spec:f,mode:a,shifted:y,capsLock:$,accessoryBarId:_}=i,k=[];k.push(`keyboard: ${c?"visible":"hidden"}`),f?(k.push(` type: ${f.keyboardType}`),k.push(` returnKey: ${f.returnKeyType}`),k.push(` autoCap: ${f.autoCapitalize}`),k.push(` autoCorrect: ${f.autoCorrect?"on":"off"}`),k.push(` appearance: ${f.keyboardAppearance}`),f.secureTextEntry&&k.push(" secureTextEntry: true"),f.enablesReturnKeyAutomatically&&k.push(` return: ${f.currentTextIsEmpty?"disabled (empty)":"enabled"}`)):k.push(" spec: <none> (shown via dev-tools with no TextInput)"),k.push(` mode: ${a}${y?" (shifted)":""}${$?" (caps)":""}`),_&&k.push(` accessoryBar: ${_}`),console.log(k.join(`
|
|
11
|
+
`))}async function kt(o){let l=await o.bridge.listSims();if(j(o.args)){J(l.map(i=>({...i,active:i.id===o.simId})));return}ht(l,o.simId)}function ae(o){return o<1024?`${o}B`:o<1024*1024?`${(o/1024).toFixed(1)}KB`:`${(o/1024/1024).toFixed(1)}MB`}function be(o,l){return l<=0?"?":`${(o/l*100).toFixed(0)}%`}async function Tt(o,l={args:[]}){let i=await ct(o);if(j(l.args)){J(i);return}if(console.log(" memory:"),i.imageLoader){let c=i.imageLoader;console.log(" image-loader cache"),console.log(` entries: ${c.cacheEntries} / ${c.cacheMaxEntries} (${be(c.cacheEntries,c.cacheMaxEntries)})`),console.log(` pixel bytes: ${ae(c.cachePixelBytes)} / ${ae(c.cachePixelBudget)} (${be(c.cachePixelBytes,c.cachePixelBudget)})`),console.log(` pending: ${c.pendingFetches} fetches, ${c.pendingBytes} bytes`),console.log(` failed uris: ${c.failedUris}`),console.log(` snapshots: ${c.snapshots}`),console.log(` camera frames: ${c.cameraFrames}`)}else console.log(" image-loader cache: not available (engine pre-rebuild?)");if(i.workerHeap){let c=i.workerHeap;console.log(" worker heap (chrome only)"),console.log(` used: ${ae(c.usedJSHeapSize)} / ${ae(c.jsHeapSizeLimit)} (${be(c.usedJSHeapSize,c.jsHeapSizeLimit)})`),console.log(` total: ${ae(c.totalJSHeapSize)}`)}if(i.hostHeap){let c=i.hostHeap;console.log(" host heap (chrome only)"),console.log(` used: ${ae(c.usedJSHeapSize)} / ${ae(c.jsHeapSizeLimit)} (${be(c.usedJSHeapSize,c.jsHeapSizeLimit)})`),console.log(` total: ${ae(c.totalJSHeapSize)}`)}}function me(o){let l=o.indexOf("--testid");if(l>=0&&o[l+1])return{mode:"testid",value:o[l+1]};let i=o.indexOf("--test-id");if(i>=0&&o[i+1])return{mode:"testid",value:o[i+1]};let c=o.indexOf("--text");return c>=0&&o[c+1]?{mode:"text",value:o[c+1]}:null}async function we(o,l){let i=JSON.stringify(l.value),c=l.mode==="testid"?`(await t.findByTestId(${i})) || (await t.findById(${i}))`:`await t.findByText(${i})`;return await o.send({type:"evaluate",code:`(async () => {
|
|
12
|
+
const t = window.__sootsimTest
|
|
13
|
+
if (!t) return null
|
|
14
|
+
const n = ${c}
|
|
15
|
+
if (!n || !n.absolutePosition || !n.layout) return null
|
|
16
|
+
const resolved =
|
|
17
|
+
typeof n.nodeId === 'number' && typeof t.resolveTapTarget === 'function'
|
|
18
|
+
? await t.resolveTapTarget(n.nodeId)
|
|
19
|
+
: null
|
|
20
|
+
const cx =
|
|
21
|
+
typeof resolved?.cx === 'number'
|
|
22
|
+
? resolved.cx
|
|
23
|
+
: n.absolutePosition.x + (n.layout.width || 0) / 2
|
|
24
|
+
const cy =
|
|
25
|
+
typeof resolved?.cy === 'number'
|
|
26
|
+
? resolved.cy
|
|
27
|
+
: n.absolutePosition.y + (n.layout.height || 0) / 2
|
|
28
|
+
return {
|
|
29
|
+
x: cx,
|
|
30
|
+
y: cy,
|
|
31
|
+
id: n.id ?? null,
|
|
32
|
+
testID: n.testID ?? null,
|
|
33
|
+
text: ${JSON.stringify(l.mode==="text")} ? ${i} : (n.text ?? n.accessibilityLabel ?? null),
|
|
34
|
+
type: n.type ?? null,
|
|
35
|
+
}
|
|
36
|
+
})()`})??null}async function Mt(o,l={}){let{nav:i,keyboard:c,shell:f}=await lt(o);if(l.json){console.log(JSON.stringify({shell:f??null,nav:i,keyboard:c},null,2));return}let a=[];if(f){let y=f.activeApp??f.state??"<none>",$=f.showSwitcher?" (app switcher open)":"",_=typeof f.launchProgress=="number"&&f.launchProgress<.98?` launching (${Math.round(f.launchProgress*100)}%)`:"";a.push(`shell: ${y}${$}${_}`)}else a.push("shell: <unavailable>");if(i){let y=i.transitionPhase!=="idle"?` (${i.transitionPhase}, ${i.activeTransitionCount} active)`:"";if(a.push(`nav: phase=${i.transitionPhase}${y}`),i.screens.length===0)a.push(" <no registered screens \u2014 app may not use react-native-screens>");else for(let $ of i.screens){let _=$.isActive?"\u25B6":" ",k=$.routeName?` ${$.routeName}`:"",b=$.headerHeight>0?` header=${$.headerHeight}`:"",S=$.largeTitleState&&$.largeTitleState!=="expanded"?` large-title=${$.largeTitleState}`:"";a.push(` ${_} #${$.id}${k}${b}${S}`)}}else a.push("nav: <runtime not available>");if(c&&c.visible){let y=c.spec?.keyboardType??"default",$=c.spec?.returnKeyType??"default";a.push(`keyboard: visible (${y}, return=${$}, mode=${c.mode??"?"})`)}else a.push("keyboard: hidden");console.log(a.join(`
|
|
37
|
+
`))}async function It(o){let{bridge:l,args:i,positional:c}=o,f=c[1]?Number(c[1])*1e3:3e3,a=i.includes("--strict"),{elapsed:y,settled:$}=await ee({bridge:l,maxMs:f,strict:a});console.log($?` settled in ${y}ms`:` timed out after ${y}ms (may still be animating)`)}async function Nt(o){let l=o.positional[1]?Number(o.positional[1]):.5;(!Number.isFinite(l)||l<0)&&(console.error(o.inspectUsage("sleep","[seconds]")),process.exit(1)),await Z(l*1e3),console.log(` slept ${l}s`)}async function Ft(o){let{bridge:l,args:i,positional:c}=o,f=c[1]?Number(c[1]):5,{tree:a}=await Ke(l,f);if(j(i)){J({depth:f,tree:a??null});return}console.log(typeof a=="string"?a:JSON.stringify(a,null,2))}async function _t(o,l={args:[]}){let i=await ze(o);if(j(l.args)){J(i);return}console.log(i.url)}async function At(o){let{wsPort:l,commandTimeoutMs:i,simId:c,simIdSource:f,positional:a}=o,y=a[1]?Number(a[1]):30,$=Math.max(1e3,(Number.isFinite(y)?y:30)*1e3),_=Math.max(1,Math.ceil($/500));console.log(" waiting for sim reconnect...");let k=await dt(l,i,c,{attempts:_,simIdSource:f});k||(console.error(" timed out waiting for sim reconnect"),process.exit(1)),k.bridge.close(),ye({source:"inspect wait",step:{wait:$},summary:`wait ${Math.round($/1e3)}s`}),console.log(` ready: ${k.count} nodes`)}var Pt=new Set(["app-launch","toast","keyboard","screen","route","alert","actionsheet","picker","notification","fetch","console","shell","scroll","gesture","text-input","react-commit","animation","reanimated"]);function xe(o,l){let i=o.indexOf(l);if(i>=0&&i+1<o.length)return o[i+1]}function ho(o,l){if(!l.filter&&!l.equals)return!0;let i=o.data,c=[];if(i&&typeof i=="object")for(let a of["url","displayUrl","message","name","activeName","path","pathname","title","phase","event","type","kind"]){let y=i[a];typeof y=="string"&&y.length>0&&c.push(y)}let f=c.join(" ");return l.equals?c.some(a=>a===l.equals):l.filter?f.toLowerCase().includes(l.filter.toLowerCase()):!0}async function Ot(o){let{bridge:l,args:i,positional:c,inspectUsage:f}=o,a=c[1];a||(console.error(f("wait event","<kind> [--max-ms 5000] [--filter <substring>] [--equals <exact>] [--since now|cursor]")),process.exit(1)),Pt.has(a)||console.error(` warning: '${a}' is not a known timeline kind \u2014 waiting anyway. known: ${[...Pt].sort().join(", ")}`);let y=xe(i,"--max-ms"),$=y&&Number.isFinite(Number(y))?Math.max(100,Number(y)):5e3,_=xe(i,"--filter"),k=xe(i,"--equals"),b=xe(i,"--since")??"now",S=i.includes("--json"),M=Date.now(),I=M+$,O=200,D=M;for(;Date.now()<I;){let H={kinds:[a],since:b==="cursor"?void 0:D,limit:50},B=await l.send({type:"evaluate",code:`(async () => {
|
|
38
|
+
const t = window.SootSim?.bridges?.timeline
|
|
39
|
+
if (!t) return { ok: false, error: 'timeline bridge missing' }
|
|
40
|
+
return { ok: true, result: await t.recent(${JSON.stringify(H)}) }
|
|
41
|
+
})()`});(!B||!B.ok)&&(console.error(` could not query timeline: ${B&&"error"in B?B.error:"unknown"}`),process.exit(1));let C=B.result.events??[];for(let oe of C)if(ho(oe,{filter:_,equals:k})){let Y=Date.now()-M;console.log(S?JSON.stringify({found:!0,elapsedMs:Y,event:oe}):` ${a} event after ${Y}ms${_?` (filter: ${_})`:""}${k?` (equals: ${k})`:""}`);return}B.result.watermark&&B.result.watermark>D&&(D=B.result.watermark),await new Promise(oe=>setTimeout(oe,O))}let u=Date.now()-M;S?console.log(JSON.stringify({found:!1,elapsedMs:u,kind:a,filter:_,equals:k})):console.error(` \u26A0 wait event ${a} timed out after ${u}ms${_?` (filter: ${_})`:""}${k?` (equals: ${k})`:""}`),process.exit(1)}async function Rt(o){let{bridge:l,args:i}=o,c=i.includes("--strict"),f=fe(i,3e3),{elapsed:a,settled:y}=await ee({bridge:l,maxMs:f,strict:c});y?console.log(` idle in ${a}ms`):(console.error(` \u26A0 wait idle timed out after ${a}ms (may still be animating)`),process.exit(1))}async function Et(o){let{bridge:l,args:i}=o,c=fe(i,2e4),{ready:f,elapsedMs:a,nodes:y,targets:$,flag:_,loadingText:k,externalReady:b,externalError:S,errors:M}=await Ve(l,c,{onProgress(O){console.error(` still waiting after ${O.elapsedMs}ms \u2014 ${Ne(O)} (nodes: ${O.nodes}, targets: ${O.targets}, errors: ${O.errors})`)}});if(f){let O=c-a,D=Math.max(100,Math.min(1e4,O)),u=await ee({bridge:l,maxMs:D,pollMs:32,stablePolls:2});u.settled||(console.error(` \u26A0 wait ready timed out after ${a+u.elapsed}ms \u2014 app mounted but did not settle (nodes: ${y}, targets: ${$})`),process.exit(1)),console.log(` ready in ${a+u.elapsed}ms: ${y} nodes, ${$} targets`);return}let I=Ne({externalError:S,loadingText:k,externalReady:b,flag:_,targets:$});console.error(` \u26A0 wait ready timed out after ${a}ms \u2014 ${I} (nodes: ${y}, targets: ${$}, errors: ${M})`),process.exit(1)}async function Ct(o){let{bridge:l,args:i,positional:c,inspectUsage:f}=o,a=c[1];a||(console.error(f("wait selector","<testid> [--max-ms 5000]")),process.exit(1));let y=i.indexOf("--max-ms"),$=y>=0&&i[y+1]?Math.max(100,Number(i[y+1])):5e3,{found:_,node:k,elapsed:b}=await Qe(l,a,$);if(_&&k){let S=k.absolutePosition?`@(${Math.round(k.absolutePosition.x)},${Math.round(k.absolutePosition.y)})`:"",M=k.layout?`${Math.round(k.layout.width)}x${Math.round(k.layout.height)}`:"?x?";console.log(` found #${a} in ${b}ms ${M} ${S}`)}else console.error(` \u26A0 wait selector #${a} timed out after ${b??$}ms`),process.exit(1)}function Wt(o){return o==null?"\u2014":o<1024?`${o}B`:o<1024*1024?`${(o/1024).toFixed(1)}K`:`${(o/1024/1024).toFixed(1)}M`}function Ht(o){return o==null?" \u2026":o<1e3?`${o}ms`.padStart(5):`${(o/1e3).toFixed(2)}s`.padStart(5)}async function wo(o,l){try{let i=await o.send({type:"evaluate",code:`(async () => {
|
|
42
|
+
const t = window.__sootsimTest
|
|
43
|
+
if (!t || typeof t.queryAll !== 'function') return []
|
|
44
|
+
try {
|
|
45
|
+
// queryAll is async in render-worker mode (the canonical mode now)
|
|
46
|
+
// because the call has to round-trip the worker \u2014 must await it.
|
|
47
|
+
// a sync result is still handled fine since await on a non-Promise
|
|
48
|
+
// is a no-op.
|
|
49
|
+
const nodes = await t.queryAll({})
|
|
50
|
+
if (!Array.isArray(nodes)) return []
|
|
51
|
+
const out = new Set()
|
|
52
|
+
for (const n of nodes) {
|
|
53
|
+
const id = n && (n.testID || n.id)
|
|
54
|
+
if (typeof id === 'string' && id) out.add(id)
|
|
55
|
+
}
|
|
56
|
+
return Array.from(out)
|
|
57
|
+
} catch {
|
|
58
|
+
return []
|
|
59
|
+
}
|
|
60
|
+
})()`});if(!Array.isArray(i)||i.length===0)return;let c=l.toLowerCase(),f=i.map(a=>({id:a,score:xo(c,a.toLowerCase())})).filter(a=>a.score<c.length+4).sort((a,y)=>a.score-y.score).slice(0,5);if(f.length===0)return;console.error(" similar testIDs:");for(let a of f)console.error(` ${a.id}`)}catch{}}function xo(o,l){if(l===o)return 0;if(l.includes(o))return 1;if(o.includes(l))return 2;let i=0;for(;i<o.length&&i<l.length&&o[i]===l[i];)i+=1;return $o(o,l)-i}function $o(o,l){if(o===l)return 0;if(!o.length)return l.length;if(!l.length)return o.length;let i=new Array(l.length+1),c=new Array(l.length+1);for(let f=0;f<=l.length;f++)i[f]=f;for(let f=1;f<=o.length;f++){c[0]=f;for(let y=1;y<=l.length;y++)c[y]=Math.min(i[y]+1,c[y-1]+1,i[y-1]+(o[f-1]===l[y-1]?0:1));let a=i;i=c,c=a}return i[l.length]}function vo(o){return o.error?"err":o.status==null?" \u2026 ":String(o.status)}function So(o){return o.externalError?`guest app errored: ${o.externalError}`:o.loadingText?`still showing "${o.loadingText}"`:o.externalReady===!1?"guest app is still loading":o.flag!==!0?"guest app has not emitted sootsim:externalAppReady":o.targets<=0?"ready flag emitted but no visible app content is inspectable yet":"node tree is still changing"}function Dt(o){let l=ne(o.startTs),i=vo(o).padEnd(3),c=o.method.padEnd(5),f=Wt(o.size).padStart(6),a=Ht(o.durationMs);console.log(` [${l}] ${i} ${c} ${f} ${a} ${o.displayUrl}`),o.error&&console.log(` error: ${o.error}`)}function ko(o){let l=[["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",ne(o.startTs)],["duration",Ht(o.durationMs).trim()],["size",Wt(o.size)],["content-type",o.type??"\u2014"]];for(let[i,c]of l)console.log(` ${i.padEnd(13)} ${c}`)}var To={error:"\x1B[31m",warn:"\x1B[33m",info:"\x1B[36m",debug:"\x1B[35m",log:"\x1B[37m"},Bt="\x1B[0m",Mo="\x1B[2m";function jt(o,l){let i=ne(o.ts),c=o.level.toUpperCase().padEnd(5),f=o.args.join(" ");if(l){let a=To[o.level];console.log(` ${Mo}[${i}]${Bt} ${a}${c}${Bt} ${f}`)}else console.log(` [${i}] ${c} ${f}`);if(o.stack&&o.level==="error"){let a=o.stack.split(`
|
|
61
|
+
`).slice(0,5);for(let y of a)console.log(` ${y.trim()}`)}}var te="__sootsimCliPerf",Io=120;async function Jt(o,l){let i=o.find((M,I)=>o[I-1]==="--id"),c=o.find((M,I)=>o[I-1]==="--text");if(i||c){let M=await l.send({type:"evaluate",code:pt({id:i,text:c})});if(!M)throw new Error(i?`no node with id "${i}"`:`no node matching text "${c}"`);let{x:I,y:O,w:D,h:u}=M;return{x:I,y:O,w:D,h:u}}let f=o.find((M,I)=>o[I-1]==="--area");if(f){let M=f.split(",").map(H=>Number(H.trim()));if(M.length!==4||M.some(H=>!Number.isFinite(H)))throw new Error(`--area expects x,y,w,h (got "${f}")`);let[I,O,D,u]=M;return{x:I,y:O,w:D,h:u}}let a=M=>{let I=o.find((D,u)=>o[u-1]===M);if(I==null)return null;let O=Number(I);return Number.isFinite(O)?O:null},y=a("--x"),$=a("--y"),_=a("--w"),k=a("--h");if(y!=null||$!=null||_!=null||k!=null)return{x:y??0,y:$??0,w:_??1,h:k??1};let S=o.filter((M,I)=>I>0&&!M.startsWith("-")&&o[I-1]!=="--output"&&o[I-1]!=="--area"&&o[I-1]!=="--id"&&o[I-1]!=="--text"&&o[I-1]!=="--x"&&o[I-1]!=="--y"&&o[I-1]!=="--w"&&o[I-1]!=="--h").map(Number).filter(M=>Number.isFinite(M));if(S.length>=2){let[M,I,O=1,D=1]=S;return{x:M,y:I,w:O,h:D}}return null}function Oe(o){let l={"<8":0,"8-12":0,"12-16":0,"16-20":0,"20-33":0,">33":0};for(let i of o)i<8?l["<8"]++:i<12?l["8-12"]++:i<16?l["12-16"]++:i<20?l["16-20"]++:i<33?l["20-33"]++:l[">33"]++;console.log(" histogram:");for(let[i,c]of Object.entries(l)){let f="\u2588".repeat(Math.ceil(c/o.length*40));console.log(` ${i.padEnd(6)} ${f} ${c}`)}}async function $e(o,l,i){let c=Date.now()+l,f=await le(o,l);for(;;){if(i(f))return{settled:!0,state:f};if(Date.now()>=c)return{settled:!1,state:f};await Z(16),f=await le(o)}}async function Ee(o){return o.send({type:"evaluate",code:`(async () => {
|
|
62
|
+
const kb = window.__sootsimKeyboard
|
|
63
|
+
const test = window.__sootsimTest
|
|
64
|
+
if (!kb) return { error: 'keyboard bridge not available' }
|
|
65
|
+
const visible = kb.isVisible()
|
|
66
|
+
const mode = kb.getMode()
|
|
67
|
+
let focused = null
|
|
68
|
+
if (test && typeof test.getFocusedNode === 'function') {
|
|
69
|
+
try {
|
|
70
|
+
focused = await test.getFocusedNode()
|
|
71
|
+
} catch {}
|
|
72
|
+
}
|
|
73
|
+
let runtimeSnapshot = null
|
|
74
|
+
if (test && typeof test.getFocusKeyboardSnapshot === 'function') {
|
|
75
|
+
try {
|
|
76
|
+
runtimeSnapshot = await test.getFocusKeyboardSnapshot()
|
|
77
|
+
} catch {}
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
visible,
|
|
81
|
+
mode,
|
|
82
|
+
focusedInput: focused ? {
|
|
83
|
+
nodeId: focused.nodeId ?? null,
|
|
84
|
+
testID: focused.testID || null,
|
|
85
|
+
id: focused.id || null,
|
|
86
|
+
placeholder: focused.placeholder || null,
|
|
87
|
+
text: focused.text || null,
|
|
88
|
+
} : null,
|
|
89
|
+
phase: runtimeSnapshot?.keyboard?.phase ?? null,
|
|
90
|
+
frame: runtimeSnapshot?.keyboard?.frame ?? null,
|
|
91
|
+
focusedRect: runtimeSnapshot?.focused?.rect ?? null,
|
|
92
|
+
}
|
|
93
|
+
})()`})}async function No(o,l=600){let i=Date.now()+l;for(;Date.now()<=i;){let c=await Ee(o);if(c.visible)return c;await Z(30)}return Ee(o)}async function ve(o,l){let i=await Ee(o);if(i.visible)return i;console.error(` ${l} 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 Lt(o,l,i){return l==="appearance"?o.send({type:"evaluate",code:`(async () => {
|
|
94
|
+
const requested = ${JSON.stringify(i??"toggle")}
|
|
95
|
+
const rootBg = (document.documentElement?.style?.background || '').toLowerCase()
|
|
96
|
+
const inferredCurrent = rootBg.includes('33') ? 'dark' : 'light'
|
|
97
|
+
let next = requested
|
|
98
|
+
if (requested === 'toggle') {
|
|
99
|
+
next = inferredCurrent === 'dark' ? 'light' : 'dark'
|
|
100
|
+
}
|
|
101
|
+
// engine accepts 'auto' since the schema picker landed; pass through.
|
|
102
|
+
window.postMessage({ type: 'soot-action', action: 'set-appearance', value: next }, '*')
|
|
103
|
+
const applied = next === 'auto'
|
|
104
|
+
? (window.matchMedia?.('(prefers-color-scheme: dark)')?.matches ? 'dark' : 'light')
|
|
105
|
+
: next
|
|
106
|
+
return { ok: true, requested, value: next, applied }
|
|
107
|
+
})()`}):o.send({type:"evaluate",code:`(async () => {
|
|
108
|
+
window.dispatchEvent(new CustomEvent(${JSON.stringify(l==="lock"?"sootsim:toggleLock":"sootsim:shake")}))
|
|
109
|
+
return { ok: true, action: ${JSON.stringify(l)} }
|
|
110
|
+
})()`})}function Fo(o){let l={Enter:"return",NumpadEnter:"return",Backspace:"delete",Delete:"delete",Space:"space",ShiftLeft:"shift",ShiftRight:"shift"};if(l[o])return l[o];let i=o.match(/^Digit([0-9])$/);if(i)return i[1];let c=o.match(/^Key([A-Z])$/);return c?c[1].toLowerCase():null}function _o(o){if(typeof o!="string")return null;let l=o.replace(/\s+/g," ").trim();return l?l.slice(0,80):null}function Ut(...o){for(let l of o){if(typeof l!="string")continue;let i=l.trim();if(i)return i}return null}function Ao(o){let l=o.indexOf("--node-id");if(l<0)return null;let i=o[l+1];if(!i)return null;let c=Number(i);return Number.isInteger(c)&&c>0?c:null}async function L(o,l,i){let c=ye({source:o,step:l,summary:i});c.active&&(c.replaced?console.error(` draft: replaced unkept action "${c.replaced.summary}" \u2014 \`flow keep\` commits one action at a time`):console.error(" draft: action pending \u2014 `sootsim flow keep` to commit"))}function qt(o,l,i){if(!i||i.hit===!1)return null;let c=Ut(i.responderTestID,i.testID);if(c)return{step:{tapOn:{id:c}},summary:`tap #${c}`};let f=_o(i.text);return f?{step:{tapOn:f},summary:`tap "${f}"`}:{step:{tapAtCoords:{x:o,y:l}},summary:`tap @${Math.round(o)},${Math.round(l)}`}}function Re(o,l,i){let c=Ut(l?.testID,l?.id);return c?{step:{tapOn:{id:c}},summary:`tap #${c}`}:i==="id"?{step:{tapOn:{id:o}},summary:`tap #${o}`}:{step:{tapOn:o},summary:`tap "${o}"`}}async function pn(o,l){let i=o[0]==="get"||o[0]==="do"||o[0]==="debug"||o[0]==="wait"?o[0]:null,c=i?o.slice(1):o,f=Je(c,{port:l.port,commandTimeoutMs:l.timeoutMs,stripBooleanFlags:["--verbose","-v","--help","-h","--clear-state","--json","--all","--watch","-w","--strict","--no-wait","--dump","--failed","--slow","--tail","-f","--interactive-targets","--actions","--internal"],stripValueFlags:["--output","--nth","--index","--testid","--test-id","--text","--node-id","--max-ms","--filter","--limit","--level","--threshold","--equals","--since"]}),a=f.positional,y=a[0],$=i==="get"||i==="do"||i==="debug"||i==="wait"?i:"inspect",_=typeof c[0]=="string"&&Be.has(c[0]),k=_?c[0]:null,b=e=>_&&e===c[0]?`sootsim ${e}`:`sootsim ${$} ${e}`,S=(e,t)=>` usage: ${b(e)}${t?` ${t}`:""}`;if(!y||o.includes("--help")||o.includes("-h")){let e={bridgePort:7668,defaultShellUrl:De};if($==="do"||$==="get"||$==="debug"||$==="wait"){let r=Se($,e);r&&(console.log(`${r}
|
|
111
|
+
`),process.exit(0))}if(k==="shell"){let r=ke("shell",e);r&&(console.log(`${r}
|
|
112
|
+
`),process.exit(0))}let t=ke("inspect",e),n=["do","get","debug","wait"].map(r=>Se(r,e)).filter(r=>r!=null).join(`
|
|
113
|
+
|
|
114
|
+
`);console.log(`${t??""}
|
|
115
|
+
|
|
116
|
+
${n}
|
|
117
|
+
`),process.exit(0)}let M=f.wsPort,I=f.simId,O=f.simIdSource,D=f.commandTimeoutMs;if(y==="list"&&c.some(e=>e==="--drivers"||e==="-D")){let{buildDriverListRows:e}=await import("./drivers-GAEMIY75.js"),t=e();console.log(` available drivers (${t.length}):
|
|
118
|
+
`);let n=Math.max(...t.map(s=>s.id.length),6),r=Math.max(...t.map(s=>s.kind.length),4);for(let s of t){let d=s.available?"\u2713":"\u2717",m=s.id.padEnd(n),g=s.kind.padEnd(r);console.log(` ${d} ${m} ${g} ${s.description}`),s.available&&s.detail?console.log(` ${s.detail}`):!s.available&&s.reason&&console.log(` unavailable: ${s.reason}`)}return}let u=Le(f),H=I||"default",B=new Set(["errors","warnings","requests","js","eval","reload","globals","perf","list","wait","sleep"]),C=200;function oe(e){let t=e.replace(/\s+/g," ").trim();if(!t)return"";if(/^<(!doctype html|html|\?xml)|<body[\s>]/i.test(t)){let r=/<title[^>]*>([^<]+)<\/title>/i.exec(e)?.[1]?.trim(),s=/<body[^>]*>([\s\S]*?)<\//i.exec(e)?.[1]?.replace(/<[^>]+>/g," ").replace(/\s+/g," ").trim().slice(0,80),d=r||s||"html error page";return`<html ${e.length}B> "${d}" (body elided \u2014 add --json for the full payload)`}return t.length<=C?t:`${t.slice(0,C)}\u2026 (+${t.length-C} more bytes)`}function Y(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 x(e){let t=he()?5e3:1500;try{let{settled:n,elapsed:r}=await ee({bridge:e,maxMs:t,pollMs:32,stablePolls:2});n||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.
|
|
119
|
+
`)}catch{}}function T(e){return!(!e||e.hit===!1||e.ok===!1||e.pointerTapHandled===!1&&!e.keyboardOpened&&!e.isTextInput)}function q(e,t){return{id:e.target?.id??e.match?.id??e.node?.id??null,testID:e.target?.testID??e.match?.testID??e.node?.testID??null,text:e.target?.text??e.target?.accessibilityLabel??e.match?.text??e.match?.accessibilityLabel??e.node?.text??t??null,type:e.target?.type??e.match?.type??e.node?.type??null}}async function z(e){let t=0,n=null,r=null;try{await ee({bridge:u,maxMs:he()?3e3:1200,pollMs:32,stablePolls:2})}catch{}let s=Date.now()+(he()?5e3:2500);for(;Date.now()<=s||t===0;){t++;let d=await e.resolve();if(n=d,d?.error==="bridge-not-ready"||d?.ambiguous||d?.nthOutOfRange)return{payload:d,result:null,attempts:t,failure:"special"};if(d&&typeof d.cx=="number"&&typeof d.cy=="number"){let g=await u.send({type:"tap",x:d.cx,y:d.cy,target:q(d,e.textFallback)});if(r=g,T(g))return{payload:d,result:g,attempts:t}}let m=s-Date.now();if(m<=0)break;try{await ee({bridge:u,maxMs:Math.min(m,700),pollMs:32,stablePolls:2})}catch{await Z(Math.min(120,m))}}return{payload:n,result:r,attempts:t,failure:n&&typeof n.cx=="number"?"missed":"not-found"}}function G(e,t){console.error(` tap failed: ${e} stayed visible but did not receive a hittable press after ${t.attempts} attempt${t.attempts===1?"":"s"}`),t.result&&console.error(` last result: ${JSON.stringify(t.result)}`)}async function re(){try{return await u.send({type:"evaluate",code:`(() => ({
|
|
120
|
+
console: window.__sootsimConsole?.count?.() || null,
|
|
121
|
+
requests: window.__sootsimTest?.getRequestCounts?.() || null,
|
|
122
|
+
}))()`})||{console:null,requests:null}}catch{return{console:null,requests:null}}}async function ie(e={}){let t=e.counts!==void 0?e.counts:await V(u,"getRequestCounts");if(!t||typeof t!="object")return;let n=Math.max(0,Number(t.failed)||0);if(n===0||!e.includeTail&&!_e("requests",H,String(n))||(console.log(`
|
|
123
|
+
network: ${n} failed request${n===1?"":"s"}`),console.log(` inspect: ${b("requests")} 5`),!e.includeTail))return;let r=await V(u,"getFailedRequests",5);if(!(!Array.isArray(r)||r.length===0)){console.log(`
|
|
124
|
+
recent failed requests:
|
|
125
|
+
`);for(let s of r){let d=ne(s.timestamp);console.log(` [${d}] ${Y(s)}`),s.responseBody?console.log(` ${oe(s.responseBody)}`):s.error&&console.log(` ${s.error}`)}}}async function E(e={}){let t=e.counts!==void 0?e.counts:await u.send({type:"evaluate",code:"window.__sootsimConsole?.count?.() || { errors: 0, warnings: 0, total: 0 }"});if(!t||typeof t!="object")return;let n=t,r=Math.max(0,Number(n.errors)||0),s=Math.max(0,Number(n.warnings)||0);if(r===0&&s===0||!e.includeTail&&!_e("console",H,`${r}:${s}`))return;let d=[];if(r>0&&d.push(`${r} console error${r===1?"":"s"}`),s>0&&d.push(`${s} console warning${s===1?"":"s"}`),console.log(`
|
|
126
|
+
console: ${d.join(", ")}`),console.log(` inspect: ${b("errors")} 5`),s>0&&console.log(` inspect: ${b("warnings")} 5`),!e.includeTail||r===0)return;let m=await u.send({type:"evaluate",code:"window.__sootsimConsole?.getErrors?.(5) || []"});if(!(!Array.isArray(m)||m.length===0)){console.log(`
|
|
127
|
+
recent console errors:
|
|
128
|
+
`);for(let g of m){let p=ne(g.timestamp),w=Array.isArray(g.args)?g.args.map(A=>typeof A=="object"?JSON.stringify(A):String(A)).join(" "):String(g);console.log(` [${p}] ${w}`)}}}let se=["console","fetch","toast","alert","notification","screen","app-launch","keyboard","route","actionsheet","picker","shell","scroll","gesture","text-input","animation","reanimated"];async function pe(e){let t=je(),n=null;try{n=await We(e,`(() => {
|
|
129
|
+
const tl = window.SootSim && window.SootSim.bridges && window.SootSim.bridges.timeline
|
|
130
|
+
if (!tl || typeof tl.summary !== 'function') return null
|
|
131
|
+
const cursorKey = ${JSON.stringify(t)}
|
|
132
|
+
const summary = tl.summary({ sinceCursor: cursorKey })
|
|
133
|
+
let consoleSplit = null
|
|
134
|
+
if (summary && summary.byKind && summary.byKind.console) {
|
|
135
|
+
const events = tl.recent({ sinceCursor: cursorKey, kinds: 'console', limit: 100000 }).events
|
|
136
|
+
consoleSplit = { error: 0, warn: 0 }
|
|
137
|
+
for (const ev of events) {
|
|
138
|
+
const lvl = ev && ev.data && ev.data.level
|
|
139
|
+
if (lvl === 'error') consoleSplit.error++
|
|
140
|
+
else if (lvl === 'warn') consoleSplit.warn++
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return summary ? { summary, consoleSplit } : null
|
|
144
|
+
})()`)}catch{return}if(!n||!n.summary||!n.summary.total)return;let r=n.summary.byKind??{},s=[],d=new Set;for(let m of se){let g=r[m];if(g)if(d.add(m),m==="console"&&n.consoleSplit){let{error:p,warn:w}=n.consoleSplit;p>0&&s.push(`${p} error${p===1?"":"s"}`),w>0&&s.push(`${w} warning${w===1?"":"s"}`)}else s.push(`${g} ${m}${g===1?"":"s"}`)}for(let[m,g]of Object.entries(r))!d.has(m)&&g&&s.push(`${g} ${m}${g===1?"":"s"}`);if(s.length!==0&&(console.log(`
|
|
145
|
+
since last: ${s.join(" \xB7 ")} \u2014 sootsim what-happened`),n.summary.lastAt))try{await Te(e,"SootSim.bridges.timeline.cursorAdvance",t,n.summary.lastAt)}catch{}}let Ce=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"]),Kt=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"]),zt=(o.includes("--verbose")||o.includes("-v"))&&!o.includes("--json");$==="do"&&y==="shell"&&(console.error(" `sootsim do shell` was removed. use `sootsim shell ...` instead."),process.exit(1)),Ce.has(y)&&await qe(u),Kt.has(y)&&await ge(u,{verbose:zt});try{switch(y){case"list":{await kt({bridge:u,simId:I,args:c});break}case"tree":{await Ft({bridge:u,args:c,positional:a});break}case"a11y":{let e=await Ge(u);if(!Array.isArray(e)||e.length===0){console.log(" no accessible nodes found");break}if(o.includes("--json"))console.log(JSON.stringify(e,null,2));else{console.log(` accessibility tree (${e.length} nodes):
|
|
146
|
+
`);for(let t of e){let n=[];if(n.push(`[${t.role}]`),t.label){let r=t.label.length>50?t.label.slice(0,47)+"...":t.label;n.push(`"${r}"`)}if(t.hint&&n.push(`(hint: "${t.hint}")`),t.testID&&n.push(`#${t.testID}`),t.state){let r=[];t.state.disabled&&r.push("disabled"),t.state.selected&&r.push("selected"),t.state.checked===!0&&r.push("checked"),t.state.checked==="mixed"&&r.push("mixed"),t.state.busy&&r.push("busy"),t.state.expanded===!0&&r.push("expanded"),t.state.expanded===!1&&r.push("collapsed"),r.length&&n.push(`{${r.join(", ")}}`)}t.position&&n.push(`@(${t.position.x},${t.position.y})`),t.size&&n.push(`${t.size.w}x${t.size.h}`),console.log(" "+n.join(" "))}}break}case"find":{await vt({bridge:u,args:o,effectiveArgs:c,positional:a,inspectUsage:S});break}case"count":{await xt(u,{args:c});break}case"keyboard":{await St(u,{json:o.includes("--json")});break}case"screens":{await Mt(u,{json:o.includes("--json")});break}case"memory":{await Tt(u,{args:c});break}case"wait":{await At({wsPort:M,commandTimeoutMs:D,simId:I,simIdSource:O,positional:a});break}case"sleep":{await Nt({positional:a,inspectUsage:S});break}case"settle":{await It({bridge:u,args:o,positional:a});break}case"ready":{await Et({bridge:u,args:o});break}case"idle":{await Rt({bridge:u,args:o,positional:a});break}case"selector":{await Ct({bridge:u,args:o,positional:a,inspectUsage:S});break}case"event":{await Ot({bridge:u,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 u.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((g,p)=>o[p-1]==="--output")||"/tmp/sootsim-inspect.png",n=await Jt(o,u),r={type:"screenshot"};n&&(r.crop=n);let d=(await u.send(r)).replace(/^data:image\/png;base64,/,"");n&&console.log(` area: x=${n.x} y=${n.y} w=${n.w} h=${n.h}`),(await import("fs")).writeFileSync(t,Buffer.from(d,"base64")),console.log(` saved: ${t}`);break}case"sample-color":{let e=await Jt(o,u);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 u.send({type:"evaluate",code:ft(e)});if(o.includes("--json"))console.log(JSON.stringify(t,null,2));else{let{r:n,g:r,b:s,a:d,hex:m,samples:g}=t,p=e.w===1&&e.h===1?`@(${e.x},${e.y})`:`@(${e.x},${e.y}) ${e.w}x${e.h}`;console.log(` ${m} rgba(${n}, ${r}, ${s}, ${d}) ${p} ${g} 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 u.send({type:"evaluate",code:`(async () => {
|
|
147
|
+
const t = window.__sootsimTest
|
|
148
|
+
const q = ${JSON.stringify(e)}
|
|
149
|
+
let node = null
|
|
150
|
+
let via = null
|
|
151
|
+
if (t.findByTestId) { node = await t.findByTestId(q); if (node) via = 'testID' }
|
|
152
|
+
if (!node && t.findById) { node = await t.findById(q); if (node) via = 'id' }
|
|
153
|
+
if (!node && t.findByText) { node = await t.findByText(q); if (node) via = 'text' }
|
|
154
|
+
if (!node) return { matcher: q, found: false }
|
|
155
|
+
|
|
156
|
+
// read the resolved transform (if any) off the style \u2014 useful
|
|
157
|
+
// because canvas nodes often animate via transform and describe
|
|
158
|
+
// output strips that.
|
|
159
|
+
const transform =
|
|
160
|
+
node.style && Array.isArray(node.style.transform)
|
|
161
|
+
? node.style.transform
|
|
162
|
+
: node.style && node.style.transform
|
|
163
|
+
? node.style.transform
|
|
164
|
+
: null
|
|
165
|
+
|
|
166
|
+
// parent chain \u2014 walk up from the node so the JSON dump is
|
|
167
|
+
// self-describing.
|
|
168
|
+
const parentChain = []
|
|
169
|
+
const root = window.__sootsimRoot
|
|
170
|
+
if (root && node.id != null) {
|
|
171
|
+
const findPath = (n, targetId, path) => {
|
|
172
|
+
if (!n) return null
|
|
173
|
+
if (n.id === targetId) return path
|
|
174
|
+
if (n.children) {
|
|
175
|
+
for (const child of n.children) {
|
|
176
|
+
const nextPath = [
|
|
177
|
+
...path,
|
|
178
|
+
{
|
|
179
|
+
type: n.type || 'view',
|
|
180
|
+
testID: n.props?.testID || null,
|
|
181
|
+
text: n.text || null,
|
|
182
|
+
},
|
|
183
|
+
]
|
|
184
|
+
const found = findPath(child, targetId, nextPath)
|
|
185
|
+
if (found) return found
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return null
|
|
189
|
+
}
|
|
190
|
+
const chain = findPath(root, node.id, [])
|
|
191
|
+
if (chain) parentChain.push(...chain)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return {
|
|
195
|
+
matcher: q,
|
|
196
|
+
found: true,
|
|
197
|
+
resolvedVia: via,
|
|
198
|
+
node,
|
|
199
|
+
transform,
|
|
200
|
+
parentChain,
|
|
201
|
+
}
|
|
202
|
+
})()`});console.log(JSON.stringify(t,null,2));break}case"tap":{let e=Number(a[1]),t=Number(a[2]),n=me(o);if(n){let d=await z({textFallback:n.mode==="text"?n.value:void 0,resolve:async()=>{let p=await we(u,n);return p?{cx:p.x,cy:p.y,match:{id:n.mode==="testid"?n.value:p.id??null,testID:n.mode==="testid"?n.value:p.testID??null,text:n.mode==="text"?n.value:p.text??null,type:p.type??null},target:{id:p.id??null,testID:p.testID??null,text:p.text??null,type:p.type??null}}:null}}),m=d.payload;(!m||typeof m.cx!="number")&&(console.error(` not found: ${n.value}`),n.mode==="testid"&&Q("wait-selector-for-missing-testid",n.value),process.exit(1)),T(d.result)||(G(`${n.mode} "${n.value}"`,d),process.exit(1));let g=qt(m.cx,m.cy,d.result);g&&await L("inspect tap",g.step,g.summary),console.log(JSON.stringify({...d.attempts>1?{attempts:d.attempts}:{},...d.result},null,2));break}(!Number.isFinite(e)||!Number.isFinite(t))&&(console.error(S("tap","<x> <y> | --testid <id> | --text <t>")),process.exit(1));let r=await u.send({type:"tap",x:e,y:t}),s=qt(e,t,r);s&&await L("inspect tap",s.step,s.summary),console.log(JSON.stringify(r,null,2));break}case"drag":case"swipe":{let e=Number(a[1]),t=Number(a[2]),n=Number(a[3]),r=Number(a[4]),s=y==="swipe"?10:12,d=y==="swipe"?8:16,m=a[5]?Number(a[5]):s,g=a[6]?Number(a[6]):d;(!Number.isFinite(e)||!Number.isFinite(t)||!Number.isFinite(n)||!Number.isFinite(r)||!Number.isFinite(m)||!Number.isFinite(g))&&(console.error(S(y,"<x1> <y1> <x2> <y2> [steps] [stepMs]")),process.exit(1));let p=await u.send({type:"evaluate",code:`(async () => {
|
|
203
|
+
const interact = window.__sootsimInteract
|
|
204
|
+
if (!interact?.drag) return { ok: false, reason: 'no interact.drag' }
|
|
205
|
+
const value = await interact.drag(${e}, ${t}, ${n}, ${r}, ${Math.max(1,Math.round(m))}, ${Math.max(0,Math.round(g))})
|
|
206
|
+
return { ok: !!value, value }
|
|
207
|
+
})()`});if(p?.ok){let w=Math.max(1,Math.round(Math.max(1,m)*Math.max(0,g)));await L(`inspect ${y}`,{swipe:{start:`${e}, ${t}`,end:`${n}, ${r}`,duration:w}},`${y} ${e},${t} -> ${n},${r}`)}console.log(JSON.stringify(p,null,2));break}case"pinch":{let e=Number(a[1]),t=Number(a[2]),n=Number(a[3]),r=Number(a[4]),s=Number(a[5]),d=Number(a[6]),m=Number(a[7]),g=Number(a[8]),p=a[9]?Number(a[9]):12,w=a[10]?Number(a[10]):16;(!Number.isFinite(e)||!Number.isFinite(t)||!Number.isFinite(n)||!Number.isFinite(r)||!Number.isFinite(s)||!Number.isFinite(d)||!Number.isFinite(m)||!Number.isFinite(g)||!Number.isFinite(p)||!Number.isFinite(w))&&(console.error(S("pinch","<x1> <y1> <x2> <y2> <x1'> <y1'> <x2'> <y2'> [steps] [stepMs]")),process.exit(1));let A=await u.send({type:"evaluate",code:`(async () => {
|
|
208
|
+
const interact = window.__sootsimInteract
|
|
209
|
+
if (!interact?.pinch) return { ok: false, reason: 'no interact.pinch' }
|
|
210
|
+
const value = await interact.pinch(${e}, ${t}, ${n}, ${r}, ${s}, ${d}, ${m}, ${g}, ${Math.max(1,Math.round(p))}, ${Math.max(0,Math.round(w))})
|
|
211
|
+
return { ok: !!value, value }
|
|
212
|
+
})()`});A?.ok&&await L("inspect pinch",{pinch:{from:[e,t,n,r],to:[s,d,m,g],steps:Math.max(1,Math.round(p)),stepMs:Math.max(0,Math.round(w))}},`pinch (${e},${t}) (${n},${r}) -> (${s},${d}) (${m},${g})`),console.log(JSON.stringify(A,null,2));break}case"tap-text":{let e=a[1];e||(console.error(S("tap-text","<text>")),process.exit(1));let t=X=>{let R=o.indexOf(X);return R>=0&&R+1<o.length?o[R+1]:null},n=X=>o.includes(X),r=t("--nth")??t("--index"),s=r!==null?Number(r):null;s!==null&&!Number.isFinite(s)&&(console.error(` --nth/--index requires an integer, got: ${r}`),process.exit(1));let d=t("--within"),m=t("--role"),g=n("--exact"),p=n("--first"),w=t("--min-y"),A=t("--max-y"),W=t("--min-x"),U=t("--max-x");for(let[X,R]of[["--min-y",w],["--max-y",A],["--min-x",W],["--max-x",U]])R!==null&&!Number.isFinite(Number(R))&&(console.error(` ${X} requires a number, got: ${R}`),process.exit(1));let K=o.indexOf("--near"),N=null;if(K>=0){let X=Number(o[K+1]),R=Number(o[K+2]);(!Number.isFinite(X)||!Number.isFinite(R))&&(console.error(" --near requires two numbers: --near <x> <y>"),process.exit(1)),N={x:X,y:R}}let h=JSON.stringify({query:e,exact:g,role:m,within:d,minX:W!==null?Number(W):null,maxX:U!==null?Number(U):null,minY:w!==null?Number(w):null,maxY:A!==null?Number(A):null,near:N,nth:s,first:p}),P=await z({textFallback:e,resolve:()=>u.send({type:"evaluate",code:`(async () => {
|
|
213
|
+
const t = window.__sootsimTest
|
|
214
|
+
if (!t) return { error: 'bridge-not-ready' }
|
|
215
|
+
const F = ${h}
|
|
216
|
+
|
|
217
|
+
const res = await t.queryTextCandidates({
|
|
218
|
+
query: F.query,
|
|
219
|
+
exact: !!F.exact,
|
|
220
|
+
...(F.role ? { role: F.role } : {}),
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
let candidates = res.candidates || []
|
|
224
|
+
|
|
225
|
+
candidates = candidates.filter((c) => {
|
|
226
|
+
const ax = c.info.absolutePosition && c.info.absolutePosition.x
|
|
227
|
+
const ay = c.info.absolutePosition && c.info.absolutePosition.y
|
|
228
|
+
if (F.minX !== null && !(ax >= F.minX)) return false
|
|
229
|
+
if (F.maxX !== null && !(ax <= F.maxX)) return false
|
|
230
|
+
if (F.minY !== null && !(ay >= F.minY)) return false
|
|
231
|
+
if (F.maxY !== null && !(ay <= F.maxY)) return false
|
|
232
|
+
if (F.within && !c.ancestorTestIDs.includes(F.within)) return false
|
|
233
|
+
return true
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
if (F.near) {
|
|
237
|
+
candidates.sort((a, b) => {
|
|
238
|
+
const ax = (a.info.absolutePosition && a.info.absolutePosition.x) || 0
|
|
239
|
+
const ay = (a.info.absolutePosition && a.info.absolutePosition.y) || 0
|
|
240
|
+
const bx = (b.info.absolutePosition && b.info.absolutePosition.x) || 0
|
|
241
|
+
const by = (b.info.absolutePosition && b.info.absolutePosition.y) || 0
|
|
242
|
+
return (
|
|
243
|
+
Math.hypot(ax - F.near.x, ay - F.near.y) -
|
|
244
|
+
Math.hypot(bx - F.near.x, by - F.near.y)
|
|
245
|
+
)
|
|
246
|
+
})
|
|
247
|
+
} else {
|
|
248
|
+
candidates.sort((a, b) => {
|
|
249
|
+
const ay = (a.info.absolutePosition && a.info.absolutePosition.y) || 0
|
|
250
|
+
const by = (b.info.absolutePosition && b.info.absolutePosition.y) || 0
|
|
251
|
+
if (Math.abs(ay - by) > 2) return ay - by
|
|
252
|
+
const ax = (a.info.absolutePosition && a.info.absolutePosition.x) || 0
|
|
253
|
+
const bx = (b.info.absolutePosition && b.info.absolutePosition.x) || 0
|
|
254
|
+
return ax - bx
|
|
255
|
+
})
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const total = candidates.length
|
|
259
|
+
if (total === 0) return { matched: 0, total: 0 }
|
|
260
|
+
|
|
261
|
+
let idx = 0
|
|
262
|
+
if (F.nth !== null) {
|
|
263
|
+
idx = F.nth < 0 ? total + F.nth : F.nth
|
|
264
|
+
if (idx < 0 || idx >= total) {
|
|
265
|
+
return { matched: 0, total, nthOutOfRange: true, nth: F.nth }
|
|
266
|
+
}
|
|
267
|
+
} else if (total > 1 && !F.first && !F.near) {
|
|
268
|
+
return {
|
|
269
|
+
ambiguous: true,
|
|
270
|
+
total,
|
|
271
|
+
candidates: candidates.slice(0, 10).map((c, i) => ({
|
|
272
|
+
idx: i,
|
|
273
|
+
nodeId: c.info.nodeId,
|
|
274
|
+
type: c.info.type,
|
|
275
|
+
testID: c.info.testID,
|
|
276
|
+
text: (c.info.text || '').slice(0, 60),
|
|
277
|
+
abs: c.info.absolutePosition,
|
|
278
|
+
layout: c.info.layout
|
|
279
|
+
? {
|
|
280
|
+
width: Math.round(c.info.layout.width || 0),
|
|
281
|
+
height: Math.round(c.info.layout.height || 0),
|
|
282
|
+
}
|
|
283
|
+
: null,
|
|
284
|
+
ancestorTestIDs: (c.ancestorTestIDs || []).slice(0, 5),
|
|
285
|
+
})),
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const picked = candidates[idx]
|
|
290
|
+
const n = picked.info
|
|
291
|
+
if (!n.absolutePosition || !n.layout) return { matched: 0, total }
|
|
292
|
+
|
|
293
|
+
const resolved =
|
|
294
|
+
typeof n.nodeId === 'number' &&
|
|
295
|
+
typeof t.resolveTapTarget === 'function'
|
|
296
|
+
? await t.resolveTapTarget(n.nodeId)
|
|
297
|
+
: null
|
|
298
|
+
const target = (resolved && resolved.target) || n
|
|
299
|
+
const cx =
|
|
300
|
+
resolved && typeof resolved.cx === 'number'
|
|
301
|
+
? resolved.cx
|
|
302
|
+
: n.absolutePosition.x + (n.layout.width || 0) / 2
|
|
303
|
+
const cy =
|
|
304
|
+
resolved && typeof resolved.cy === 'number'
|
|
305
|
+
? resolved.cy
|
|
306
|
+
: n.absolutePosition.y + (n.layout.height || 0) / 2
|
|
307
|
+
return {
|
|
308
|
+
cx,
|
|
309
|
+
cy,
|
|
310
|
+
match: {
|
|
311
|
+
nodeId: n.nodeId ?? null,
|
|
312
|
+
id: n.id,
|
|
313
|
+
testID: n.testID,
|
|
314
|
+
type: n.type,
|
|
315
|
+
},
|
|
316
|
+
target: {
|
|
317
|
+
nodeId: target.nodeId ?? null,
|
|
318
|
+
id: target.id,
|
|
319
|
+
testID: target.testID,
|
|
320
|
+
text:
|
|
321
|
+
target.text ??
|
|
322
|
+
target.accessibilityLabel ??
|
|
323
|
+
n.text ??
|
|
324
|
+
n.accessibilityLabel ??
|
|
325
|
+
null,
|
|
326
|
+
type: target.type,
|
|
327
|
+
},
|
|
328
|
+
strategy: (resolved && resolved.strategy) || 'matched-node',
|
|
329
|
+
total,
|
|
330
|
+
idx,
|
|
331
|
+
}
|
|
332
|
+
})()`})}),F=P.payload;if(F?.error==="bridge-not-ready"&&(console.error(" sootsim test bridge not ready"),process.exit(1)),F?.ambiguous){let X=F.candidates;console.error(` ambiguous: ${F.total} matches for "${e}"`);for(let R of X){let Yt=R.abs?`@(${Math.round(R.abs.x)},${Math.round(R.abs.y)})`:"",Gt=R.layout?` ${R.layout.width}x${R.layout.height}`:"",Xt=R.testID?` #${R.testID}`:"",Vt=R.text?` "${R.text}"`:"",Qt=R.ancestorTestIDs.length>0?` within ${R.ancestorTestIDs.slice(0,3).map(Zt=>`#${Zt}`).join(" > ")}`:"";console.error(` [${R.idx}] <${R.type}>${Vt}${Xt} ${Yt}${Gt}${Qt}`)}F.total>X.length&&console.error(` ... and ${F.total-X.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)}F?.nthOutOfRange&&(console.error(` not found: nth ${F.nth} of ${F.total} match${F.total===1?"":"es"} for "${e}"`),process.exit(1)),(!F||typeof F.cx!="number")&&(console.error(` not found: ${e}`),process.exit(1)),T(P.result)||(G(`text "${e}"`,P),process.exit(1));let ce=Re(e,{id:F.target?.id??null,testID:F.target?.testID??null,type:F.target?.type??null,cx:F.cx,cy:F.cy},"text");await L("inspect tap-text",ce.step,ce.summary),console.log(JSON.stringify({matched:F.match,tapped:{nodeId:F.target?.nodeId??null,id:F.target?.id??null,testID:F.target?.testID??null,type:F.target?.type??null,cx:F.cx,cy:F.cy},...F.strategy&&F.strategy!=="matched-node"?{strategy:F.strategy}:{},...F.total>1||s!==null?{nth:{index:F.idx,total:F.total}}:{},...P.attempts>1?{attempts:P.attempts}:{},result:P.result},null,2));break}case"tap-best":{let e=a[1];e||(console.error(S("tap-best","<query>")),process.exit(1));let t=JSON.stringify(e),r=await z({textFallback:e,resolve:async()=>{let g=await u.send({type:"evaluate",code:`(async () => {
|
|
333
|
+
const t = window.__sootsimTest
|
|
334
|
+
if (!t) return { error: 'bridge-not-ready' }
|
|
335
|
+
// try testID first \u2014 strongest signal of "this is the
|
|
336
|
+
// intended tap target".
|
|
337
|
+
const byTestId =
|
|
338
|
+
(await t.findByTestId(${t})) || (await t.findById(${t}))
|
|
339
|
+
if (byTestId && byTestId.absolutePosition && byTestId.layout) {
|
|
340
|
+
return {
|
|
341
|
+
strategy: 'testid',
|
|
342
|
+
node: {
|
|
343
|
+
nodeId: byTestId.nodeId ?? null,
|
|
344
|
+
id: byTestId.id,
|
|
345
|
+
testID: byTestId.testID,
|
|
346
|
+
type: byTestId.type,
|
|
347
|
+
text: byTestId.text,
|
|
348
|
+
absolutePosition: byTestId.absolutePosition,
|
|
349
|
+
layout: byTestId.layout,
|
|
350
|
+
},
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
// text fallback. findByText returns null when there are
|
|
354
|
+
// 0 or 2+ matches \u2014 to disambiguate we'd send the user
|
|
355
|
+
// back to tap-text with --nth, which is the right
|
|
356
|
+
// failure mode.
|
|
357
|
+
const byText = await t.findByText(${t})
|
|
358
|
+
if (byText && byText.absolutePosition && byText.layout) {
|
|
359
|
+
return {
|
|
360
|
+
strategy: 'text',
|
|
361
|
+
node: {
|
|
362
|
+
nodeId: byText.nodeId ?? null,
|
|
363
|
+
id: byText.id,
|
|
364
|
+
testID: byText.testID,
|
|
365
|
+
type: byText.type,
|
|
366
|
+
text: byText.text,
|
|
367
|
+
absolutePosition: byText.absolutePosition,
|
|
368
|
+
layout: byText.layout,
|
|
369
|
+
},
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return { strategy: 'none' }
|
|
373
|
+
})()`});if(!("node"in g))return g;let p=g.node,w=p.absolutePosition.x+p.layout.width/2,A=p.absolutePosition.y+p.layout.height/2;return{...g,cx:w,cy:A,target:{id:p.id,testID:p.testID,text:g.strategy==="text"?e:p.text,type:p.type}}}}),s=r.payload;s||(console.error(` tap-best: no testID or visible text matched "${e}". try \`sootsim find --interactive-targets\` to list candidates.`),process.exit(1)),"error"in s&&(console.error(` ${s.error}`),process.exit(1)),s.strategy==="none"&&(console.error(` tap-best: no testID or visible text matched "${e}". try \`sootsim find --interactive-targets\` to list candidates.`),process.exit(1));let d=s.node;T(r.result)||(G(`best "${e}"`,r),process.exit(1));let m=Re(e,{id:d.id,testID:d.testID,type:d.type,cx:s.cx,cy:s.cy},s.strategy==="testid"?"id":"text");await L("inspect tap-best",m.step,m.summary),console.log(JSON.stringify({matched:{strategy:s.strategy,nodeId:d.nodeId,id:d.id,testID:d.testID,type:d.type,text:d.text},tapped:{cx:s.cx,cy:s.cy},...r.attempts>1?{attempts:r.attempts}:{},result:r.result},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),r=await z({resolve:()=>u.send({type:"evaluate",code:`(async () => {
|
|
374
|
+
const t = window.__sootsimTest
|
|
375
|
+
if (!t) return null
|
|
376
|
+
const n = (await t.findByTestId(${t})) || (await t.findById(${t}))
|
|
377
|
+
if (!n || !n.absolutePosition || !n.layout) return { cx: null }
|
|
378
|
+
const resolved =
|
|
379
|
+
typeof n.nodeId === 'number' && typeof t.resolveTapTarget === 'function'
|
|
380
|
+
? await t.resolveTapTarget(n.nodeId)
|
|
381
|
+
: null
|
|
382
|
+
const target = (resolved && resolved.target) || n
|
|
383
|
+
const cx =
|
|
384
|
+
resolved && typeof resolved.cx === 'number'
|
|
385
|
+
? resolved.cx
|
|
386
|
+
: n.absolutePosition.x + (n.layout.width || 0) / 2
|
|
387
|
+
const cy =
|
|
388
|
+
resolved && typeof resolved.cy === 'number'
|
|
389
|
+
? resolved.cy
|
|
390
|
+
: n.absolutePosition.y + (n.layout.height || 0) / 2
|
|
391
|
+
return {
|
|
392
|
+
cx,
|
|
393
|
+
cy,
|
|
394
|
+
match: {
|
|
395
|
+
nodeId: n.nodeId ?? null,
|
|
396
|
+
id: n.id,
|
|
397
|
+
testID: n.testID,
|
|
398
|
+
text: n.text ?? n.accessibilityLabel ?? null,
|
|
399
|
+
type: n.type,
|
|
400
|
+
},
|
|
401
|
+
target: {
|
|
402
|
+
nodeId: target.nodeId ?? null,
|
|
403
|
+
id: target.id,
|
|
404
|
+
testID: target.testID,
|
|
405
|
+
text:
|
|
406
|
+
target.text ??
|
|
407
|
+
target.accessibilityLabel ??
|
|
408
|
+
n.text ??
|
|
409
|
+
n.accessibilityLabel ??
|
|
410
|
+
null,
|
|
411
|
+
type: target.type,
|
|
412
|
+
},
|
|
413
|
+
strategy: (resolved && resolved.strategy) || 'matched-node',
|
|
414
|
+
}
|
|
415
|
+
})()`})}),s=r.payload;(!s||typeof s.cx!="number")&&(console.error(` not found: ${e}`),await wo(u,e),process.exit(1)),T(r.result)||(G(`id "${e}"`,r),process.exit(1));let d=Re(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",d.step,d.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}:{},...r.attempts>1?{attempts:r.attempts}:{},result:r.result},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 n=JSON.stringify(e),r=await u.send({type:"evaluate",code:`(async () => {
|
|
416
|
+
const t = window.__sootsimTest
|
|
417
|
+
if (!t) return null
|
|
418
|
+
const n = await (t.findByTestId(${n}) || t.findById(${n}))
|
|
419
|
+
if (!n || !n.absolutePosition || !n.layout) return null
|
|
420
|
+
return {
|
|
421
|
+
cx: n.absolutePosition.x + (n.layout.width || 0) / 2,
|
|
422
|
+
cy: n.absolutePosition.y + (n.layout.height || 0) / 2,
|
|
423
|
+
id: n.id,
|
|
424
|
+
testID: n.testID,
|
|
425
|
+
type: n.type,
|
|
426
|
+
isTextInput: !!n.isTextInput,
|
|
427
|
+
placeholder: n.placeholder || null,
|
|
428
|
+
}
|
|
429
|
+
})()`});(!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 s=await u.send({type:"tap",x:r.cx,y:r.cy,target:{id:r.id??e,testID:r.testID??e,text:null,type:r.type??null}}),d=await No(u);d.visible||(console.error(` keyboard did not open after tapping ${e}`),process.exit(1));let m=d.focusedInput;m&&(m.testID===e||m.id===e||(console.error(` focus routing mismatch after tap: requested ${JSON.stringify(e)} but focus is on ${JSON.stringify(m.testID??m.id??null)}. did the tap land on an outer Pressable wrapper?`),process.exit(1))),await u.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:d.visible??s?.keyboardOpened??!1,focusedInput:d.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 ve(u,"type"),await u.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 ve(u,"key"),await u.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 ve(u,"key-sequence");for(let t of e)await u.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:Fo(r)})),n=t.filter(r=>!r.key);n.length>0&&(console.error(` unsupported keycode(s): ${n.map(r=>r.code).join(", ")}`),process.exit(1)),await ve(u,"keycode");for(let r of t)await u.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 u.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 u.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]),n=me(o);if(n){let m=await we(u,n);m||(console.error(` not found: ${n.value}`),n.mode==="testid"&&Q("wait-selector-for-missing-testid",n.value),process.exit(1)),e=m.x,t=m.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 s=Math.max(0,Math.round(r)),d=await u.send({type:"evaluate",code:`(async () => {
|
|
430
|
+
const interact = window.__sootsimInteract
|
|
431
|
+
if (interact?.doubleTap) {
|
|
432
|
+
return {
|
|
433
|
+
ok: !!(await interact.doubleTap(${e}, ${t}, ${s})),
|
|
434
|
+
gapMs: ${s},
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
if (!interact?.tap) {
|
|
438
|
+
return { ok: false, reason: 'no interact.tap', gapMs: ${s} }
|
|
439
|
+
}
|
|
440
|
+
const first = await interact.tap(${e}, ${t})
|
|
441
|
+
if (!first || first.hit === false) {
|
|
442
|
+
return { ok: false, reason: 'first tap missed', gapMs: ${s}, first }
|
|
443
|
+
}
|
|
444
|
+
await new Promise((resolve) => setTimeout(resolve, ${s}))
|
|
445
|
+
const second = await interact.tap(${e}, ${t})
|
|
446
|
+
return {
|
|
447
|
+
ok: !!second && second.hit !== false,
|
|
448
|
+
gapMs: ${s},
|
|
449
|
+
first,
|
|
450
|
+
second,
|
|
451
|
+
}
|
|
452
|
+
})()`});d?.ok&&await L("inspect double-tap",{doubleTapAtCoords:{x:e,y:t,gapMs:s}},`double-tap @${e},${t}`),console.log(JSON.stringify(d,null,2));break}case"long-press":{let e=Number(a[1]),t=Number(a[2]),n=me(o);if(n){let d=await we(u,n);d||(console.error(` not found: ${n.value}`),n.mode==="testid"&&Q("wait-selector-for-missing-testid",n.value),process.exit(1)),e=d.x,t=d.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 s=await u.send({type:"evaluate",code:`(async () => {
|
|
453
|
+
const interact = window.__sootsimInteract
|
|
454
|
+
if (!interact?.longPress) return { ok: false, reason: 'no interact.longPress' }
|
|
455
|
+
const value = await interact.longPress(${e}, ${t}, ${Math.max(0,Math.round(r))})
|
|
456
|
+
return { ok: !!value, value }
|
|
457
|
+
})()`});s?.ok&&await L("inspect long-press",{tapAtCoords:{x:e,y:t}},`long-press @${e},${t}`),console.log(JSON.stringify(s,null,2));break}case"touch":{let e=a[1],t=Number(a[2]),n=Number(a[3]),r=a[4]?Number(a[4]):999,s=e==="down"?"touchDown":e==="move"?"touchMove":e==="up"?"touchUp":e==="cancel"?"touchCancel":null;s||(console.error(S("touch","<down|move|up|cancel> <x> <y> [pointerId]")),process.exit(1)),e!=="cancel"&&(!Number.isFinite(t)||!Number.isFinite(n))&&(console.error(S("touch","<down|move|up|cancel> <x> <y> [pointerId]")),process.exit(1));let d=e==="down"?"tap":e==="move"?"move":null,m=d&&Number.isFinite(t)&&Number.isFinite(n)?`window.dispatchEvent(new CustomEvent('sootsim:agentAction', { detail: { type: '${d}', x: ${t}, y: ${n} } }));`:"",g=await u.send({type:"evaluate",code:`(async () => {
|
|
458
|
+
${m}
|
|
459
|
+
const interact = window.__sootsimInteract
|
|
460
|
+
if (!interact?.${s}) return { ok: false, reason: 'no interact.${s}' }
|
|
461
|
+
const value = ${e==="cancel"?`await interact.${s}(${Math.max(1,Math.round(r))})`:`await interact.${s}(${t}, ${n}, ${Math.max(1,Math.round(r))})`}
|
|
462
|
+
return { ok: !!value, value }
|
|
463
|
+
})()`});g?.ok&&e!=="cancel"&&await L("inspect touch",{tapAtCoords:{x:t,y:n}},`touch ${e} @${t},${n}`),console.log(JSON.stringify(g,null,2));break}case"gesture":{let e=["scroll-up","scroll-down","scroll-left","scroll-right","swipe-from-left-edge","swipe-from-right-edge","swipe-from-top-edge","swipe-from-bottom-edge"],t=a[1],n=a[2]?Number(a[2]):220;(!t||!Number.isFinite(n))&&(console.error(S("gesture","<preset> [durationMs]")),console.error(` presets: ${e.join(", ")}`),process.exit(1)),e.includes(t)||(console.error(` unknown gesture preset: ${t}`),console.error(` presets: ${e.join(", ")}`),process.exit(1));let r=await u.send({type:"evaluate",code:`(async () => {
|
|
464
|
+
const spec = globalThis.__sootsimDeviceSpec || {}
|
|
465
|
+
return {
|
|
466
|
+
width: spec.width || window.innerWidth || 393,
|
|
467
|
+
height: spec.height || window.innerHeight || 852,
|
|
468
|
+
statusBarHeight: spec.statusBarHeight || 0,
|
|
469
|
+
homeIndicatorHeight: spec.homeIndicatorHeight || 0,
|
|
470
|
+
}
|
|
471
|
+
})()`}),s=Number(r?.width)||393,d=Number(r?.height)||852,m=Number(r?.statusBarHeight)||0,g=Number(r?.homeIndicatorHeight)||0,p=Math.round(s/2),w=Math.round(d/2),A=Math.max(24,m+18),W=Math.max(24,g+18),U=18,K=Math.min(220,Math.round(d*.24)),N=Math.min(180,Math.round(s*.32)),h=p,v=w,P=p,F=w;switch(t){case"scroll-up":v=w+Math.round(K/2),F=w-Math.round(K/2);break;case"scroll-down":v=w-Math.round(K/2),F=w+Math.round(K/2);break;case"scroll-left":h=p+Math.round(N/2),P=p-Math.round(N/2);break;case"scroll-right":h=p-Math.round(N/2),P=p+Math.round(N/2);break;case"swipe-from-left-edge":h=U,v=w,P=Math.min(s-U,U+N);break;case"swipe-from-right-edge":h=s-U,v=w,P=Math.max(U,s-U-N);break;case"swipe-from-top-edge":h=p,v=A,F=Math.min(d-W,A+K);break;case"swipe-from-bottom-edge":h=p,v=d-W,F=Math.max(A,d-W-K);break}let ce=Math.max(8,Math.round(n/16)),X=Math.max(1,Math.round(n/ce)),R=await u.send({type:"evaluate",code:`(async () => {
|
|
472
|
+
const interact = window.__sootsimInteract
|
|
473
|
+
if (!interact?.drag) return { ok: false, reason: 'no interact.drag' }
|
|
474
|
+
const value = await interact.drag(${h}, ${v}, ${P}, ${F}, ${ce}, ${X})
|
|
475
|
+
return { ok: !!value, value }
|
|
476
|
+
})()`});R?.ok&&await L("inspect gesture",{swipe:{start:`${h}, ${v}`,end:`${P}, ${F}`,duration:Math.max(1,Math.round(n))}},`gesture ${t}`),console.log(JSON.stringify({preset:t,from:{x:h,y:v},to:{x:P,y:F},result:R},null,2));break}case"scroll":{let e=me(o),t=Ao(o),n=e?.mode==="testid"?e.value:t==null?a[1]:null,r=e||t!=null?1:2,s=Number(a[r]),d=Number(a[r+1]);(!n&&t==null||!Number.isFinite(s)||!Number.isFinite(d))&&(console.error(S("scroll","<id> <x> <y> | --testid <id> <x> <y> | --node-id <nodeId> <x> <y>")),process.exit(1));let m=await u.send({type:"evaluate",code:`(async () => {
|
|
477
|
+
const t = window.__sootsimTest
|
|
478
|
+
if (!t) return null
|
|
479
|
+
const n = ${t!=null?`await t.inspectByNodeId(${JSON.stringify(t)})`:`await t.findByTestId(${JSON.stringify(n)})
|
|
480
|
+
|| await t.findById(${JSON.stringify(n)})`}
|
|
481
|
+
if (!n || !n.absolutePosition || !n.layout) return null
|
|
482
|
+
return {
|
|
483
|
+
cx: n.absolutePosition.x + (n.layout.width || 0) / 2,
|
|
484
|
+
cy: n.absolutePosition.y + (n.layout.height || 0) / 2,
|
|
485
|
+
}
|
|
486
|
+
})()`}),g=await V(u,"scrollTo",t!=null?{nodeId:t}:n,s,d,!1);if(g?.ok){let p=t!=null?`node ${t}`:`#${n}`;await L("inspect scroll",{scrollTo:{...t!=null?{nodeId:t}:{id:n},x:s,y:d}},`scroll ${p} -> ${s},${d}`)}console.log(JSON.stringify({...g,...m?{at:{x:m.cx,y:m.cy}}:{}},null,2));break}case"state":{let e=a[1];if(i==="get"&&!e){let n=await V(u,"getRuntimeState"),r=await u.send({type:"evaluate",code:`({
|
|
487
|
+
errors: window.__sootsimConsole?.getErrors?.()?.length ?? 0,
|
|
488
|
+
warnings: window.__sootsimConsole?.getWarnings?.()?.length ?? 0,
|
|
489
|
+
})`});if(n&&typeof n=="object"&&n.diagnostics&&(n.diagnostics.errors=r?.errors??0,n.diagnostics.warnings=r?.warnings??0),n&&typeof n=="object"&&n.shell==null)try{let s=await le(u);s&&(n.shell=s)}catch{}console.log(JSON.stringify(n,null,2));break}if(!e||e==="--help"||e==="-h"){console.log(`
|
|
490
|
+
${b("state")} \u2014 dump raw runtime state
|
|
491
|
+
|
|
492
|
+
subcommands:
|
|
493
|
+
shell dump shell transition/layout state
|
|
494
|
+
worker dump render-worker host/animation state
|
|
495
|
+
keyboard dump keyboard visibility, mode, and focused input
|
|
496
|
+
ownership dump surface ownership + pointerOnSurface delivery stats
|
|
497
|
+
node <id> dump raw node info by id or testID
|
|
498
|
+
scroll <id> dump scroll metrics and runtime state
|
|
499
|
+
scroll-hit <x> <y> dump the nearest scroll ancestor at coordinates
|
|
500
|
+
hit <x> <y> dump the hit-test ancestry at coordinates
|
|
501
|
+
gesture <x> <y> dump gesture routing/debug info at coordinates
|
|
502
|
+
|
|
503
|
+
examples:
|
|
504
|
+
${b("state")} shell
|
|
505
|
+
${b("state")} worker
|
|
506
|
+
${b("state")} keyboard
|
|
507
|
+
${b("state")} ownership
|
|
508
|
+
${b("state")} node photos
|
|
509
|
+
${b("state")} scroll feed
|
|
510
|
+
${b("state")} scroll-hit 360 420
|
|
511
|
+
${b("state")} hit 200 720
|
|
512
|
+
`);break}let t;switch(e){case"shell":t=await le(u,500);break;case"worker":t=await Te(u,"__sootsimRenderHost.queryStats");break;case"ownership":t=await u.send({type:"evaluate",code:`(() => {
|
|
513
|
+
const h = window.__sootsimRenderHost
|
|
514
|
+
if (!h || typeof h.getOwnershipSnapshot !== 'function') {
|
|
515
|
+
return { error: 'getOwnershipSnapshot not available' }
|
|
516
|
+
}
|
|
517
|
+
return h.getOwnershipSnapshot()
|
|
518
|
+
})()`});break;case"keyboard":t=await u.send({type:"evaluate",code:`(async () => {
|
|
519
|
+
const kb = window.__sootsimKeyboard
|
|
520
|
+
const test = window.__sootsimTest
|
|
521
|
+
if (!kb) return { error: 'keyboard bridge not available' }
|
|
522
|
+
const layout = typeof kb.getLayout === 'function' ? kb.getLayout() : null
|
|
523
|
+
const visible = kb.isVisible()
|
|
524
|
+
const mode = kb.getMode()
|
|
525
|
+
let focused = null
|
|
526
|
+
if (test && typeof test.getFocusedNode === 'function') {
|
|
527
|
+
try {
|
|
528
|
+
focused = await test.getFocusedNode()
|
|
529
|
+
} catch {}
|
|
530
|
+
}
|
|
531
|
+
return {
|
|
532
|
+
visible,
|
|
533
|
+
mode,
|
|
534
|
+
layout,
|
|
535
|
+
focusedInput: focused ? {
|
|
536
|
+
nodeId: focused.nodeId ?? null,
|
|
537
|
+
testID: focused.testID || null,
|
|
538
|
+
id: focused.id || null,
|
|
539
|
+
placeholder: focused.placeholder || null,
|
|
540
|
+
text: focused.text || null,
|
|
541
|
+
} : null,
|
|
542
|
+
}
|
|
543
|
+
})()`});break;case"node":{let n=a[2];n||(console.error(` usage: ${b("state")} node <id>`),process.exit(1)),t=await V(u,"findByTestId",n)||await V(u,"findById",n);break}case"scroll":{let n=a[2];n||(console.error(` usage: ${b("state")} scroll <id>`),process.exit(1)),t=await V(u,"getScrollState",n);break}case"scroll-hit":{let n=Number(a[2]),r=Number(a[3]);(!Number.isFinite(n)||!Number.isFinite(r))&&(console.error(` usage: ${b("state")} scroll-hit <x> <y>`),process.exit(1)),t=await V(u,"getScrollStateAt",n,r);break}case"hit":{let n=Number(a[2]),r=Number(a[3]);(!Number.isFinite(n)||!Number.isFinite(r))&&(console.error(` usage: ${b("state")} hit <x> <y>`),process.exit(1)),t=await V(u,"debugHitAt",n,r);break}case"gesture":{let n=Number(a[2]),r=Number(a[3]);(!Number.isFinite(n)||!Number.isFinite(r))&&(console.error(` usage: ${b("state")} gesture <x> <y>`),process.exit(1)),t=await V(u,"debugGestureAt",n,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(`
|
|
544
|
+
${b("shell")} \u2014 run built-in shell commands
|
|
545
|
+
|
|
546
|
+
subcommands:
|
|
547
|
+
launch <appId> [waitMs] [--clear-state]
|
|
548
|
+
launch app and wait for settled shell state
|
|
549
|
+
home [waitMs] go home and wait for settled shell state
|
|
550
|
+
switcher [waitMs] open switcher and wait for settled shell state
|
|
551
|
+
open-card <appId> [waitMs]
|
|
552
|
+
open a specific switcher card and wait for app settle
|
|
553
|
+
appearance <light|dark|auto|toggle>
|
|
554
|
+
update simulator appearance
|
|
555
|
+
lock toggle device lock state
|
|
556
|
+
shake trigger the simulator shake gesture
|
|
557
|
+
|
|
558
|
+
examples:
|
|
559
|
+
${b("shell")} launch photos
|
|
560
|
+
${b("shell")} launch rn --clear-state
|
|
561
|
+
${b("shell")} launch photos 1500
|
|
562
|
+
${b("shell")} home 500
|
|
563
|
+
${b("shell")} switcher 800
|
|
564
|
+
${b("shell")} open-card clock 800
|
|
565
|
+
${b("shell")} appearance dark
|
|
566
|
+
${b("shell")} lock
|
|
567
|
+
`);break}let t=e==="launch"||e==="open-card"||e==="home"||e==="switcher",n=e==="launch"||e==="open-card"?a[3]:a[2],r=n?Number(n):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 s=!1,d=!1,m=null,g=o.includes("--clear-state");if(e==="launch"){let p=a[2];p||(console.error(S("shell","launch <appId> [settleMs] [--clear-state]")),process.exit(1)),g&&await u.send({type:"evaluate",code:He}),s=!!await de(u,"launchApp",r,p),{settled:d,state:m}=await $e(u,Math.round(r),w=>!!w&&w.state==="app"&&w.activeApp===p&&w.showSwitcher===!1&&w.switcherPhase==="idle"&&typeof w.launchProgress=="number"&&w.launchProgress>=.98),s&&await L("inspect shell launch",g?{launchApp:{clearState:!0}}:{launchApp:{}},g?"launch app (clear state)":"launch app")}else if(e==="home")s=!!await de(u,"goHome",r),{settled:d,state:m}=await $e(u,Math.round(r),p=>!!p&&p.state==="home"&&p.activeApp==null&&p.showSwitcher===!1&&p.switcherPhase==="idle"&&typeof p.launchProgress=="number"&&p.launchProgress>=.98);else if(e==="switcher")s=!!await de(u,"openSwitcher",r),{settled:d,state:m}=await $e(u,Math.round(r),p=>!!p&&p.state==="app"&&p.showSwitcher===!0&&p.switcherPhase==="idle"&&typeof p.zoomLevel=="number"&&Math.abs(p.zoomLevel)<=.02&&typeof p.horizontalZoom=="number"&&Math.abs(p.horizontalZoom)<=.02),d&&(await Z(Io),m=await le(u));else if(e==="open-card"){let p=a[2];p||(console.error(S("shell","open-card <appId> [settleMs]")),process.exit(1)),s=!!await de(u,"openSwitcherCard",r,p),{settled:d,state:m}=await $e(u,Math.round(r),w=>!!w&&w.state==="app"&&w.activeApp===p&&w.showSwitcher===!1&&w.switcherPhase==="idle"&&typeof w.zoomLevel=="number"&&w.zoomLevel>=.98&&typeof w.horizontalZoom=="number"&&w.horizontalZoom>=.98),s&&await L("inspect shell open-card",{openSwitcherCard:{appId:p}},`open switcher card ${p}`)}else if(e==="appearance"){let p=a[2];(!p||!["light","dark","auto","toggle"].includes(p))&&(console.error(S("shell","appearance <light|dark|auto|toggle>")),process.exit(1));let w=await Lt(u,"appearance",p);if(s=!!w?.ok,m={appearance:w},s){let A=w?.applied??p;console.log(` appearance: ${A}`)}}else if(e==="lock"||e==="shake"){let p=await Lt(u,e);s=!!p?.ok,m={[e]:p}}else console.error(` unknown shell subcommand: ${e}`),process.exit(1);console.log(JSON.stringify({ok:s,settled:d,state:m},null,2));break}case"url":{await _t(u,{args:c});break}case"reload":{let n=!1,r=!1;try{await u.send({type:"evaluate",code:"window.__sootsimConsole?.clear()"});let m=await u.send({type:"evaluate",code:`;(() => {
|
|
568
|
+
const reloadExternalApp = window.SootSim?.bridges?.hotRemount?.reloadExternalApp
|
|
569
|
+
if (typeof reloadExternalApp === 'function') {
|
|
570
|
+
reloadExternalApp()
|
|
571
|
+
return { kind: 'external-app' }
|
|
572
|
+
}
|
|
573
|
+
window.location.reload()
|
|
574
|
+
return { kind: 'page' }
|
|
575
|
+
})()`});r=!!m&&m.kind==="external-app",n=!0}catch{}console.log(" reloading...");let s=u,d=null;if(r)d=await Fe(u,{timeoutMs:1e4,errorGraceMs:3e3});else{n&&await Z(300);let m=await ut(M,D,I,{timeoutMs:1e4,simIdSource:O});m?(s=m,d=await Fe(m,{timeoutMs:1e4,errorGraceMs:3e3})):(console.log(" \u26A0 reload: bridge never reconnected within 10000ms"),s=null)}if(d)if(d.ready){let m=d.source==="nodes-fallback"?" (no ready signal, node-count fallback)":"";console.log(` ready in ${d.elapsedMs}ms: ${d.nodes} nodes${m}`)}else if(d.source==="error-bail")console.log(` \u26A0 reload bailed after ${d.elapsedMs}ms: ${d.errors} console error(s), ready signal never fired`);else{let m=So(d);console.log(` \u26A0 reload timed out after ${d.elapsedMs}ms \u2014 ${m} (nodes: ${d.nodes}, targets: ${d.targets}, errors: ${d.errors})`)}if(s)try{let m=await s.send({type:"evaluate",code:"window.__sootsimConsole?.getErrors(10) || []"});if(s!==u&&s.close(),Array.isArray(m)&&m.length>0){console.log(`
|
|
576
|
+
\u26A0 ${m.length} error(s) during mount:
|
|
577
|
+
`);for(let g of m){let p=g.args.map(w=>typeof w=="object"?JSON.stringify(w):w).join(" ");if(console.log(` ${p}`),g.stack){let w=g.stack.split(`
|
|
578
|
+
`).slice(0,2);for(let A of w)console.log(` ${A.trim()}`)}}}}catch{}d&&!d.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(` ${b("js")} SootSim.bridges.test.findByText("Sign in")`),console.error(` ${b("js")} SootSim.bridges.debug.snapshot("before")`),console.error(` ${b("js")} SootSim.bridges.keyboard.type("hello")`),console.error(` ${b("js")} SootSim.state.root.children.length`),process.exit(1));let t=e;t.startsWith("(async")||(t=`(async () => ${t})()`);let n=await u.send({type:"evaluate",code:t});console.log(JSON.stringify(n,null,2));let r=e.toLowerCase(),s=[];(r.includes("sootsim:gohome")||r.includes("gohome"))&&s.push("sootsim shell home"),(r.includes("sootsim:appswitcher")||r.includes("appswitcher"))&&s.push("sootsim shell switcher"),(r.includes("keyboard.isvisible")||r.includes("keyboard.getmode"))&&s.push("sootsim debug state keyboard"),r.includes("interact.tap")&&s.push("sootsim do tap <x> <y>"),r.includes("keyboard.type")&&s.push("sootsim do type <text>"),(r.includes("keyboard.press")||r.includes("keyboard.dispatchkey"))&&s.push("sootsim do key <name>"),r.includes("keyboard.dismiss")&&s.push("sootsim do dismiss"),r.includes("dumptree")&&s.push("sootsim get tree"),r.includes("dumpaccessibilitytree")&&s.push("sootsim get a11y"),r.includes("getnodecount")&&s.push("sootsim get count"),r.includes("findbytext")&&s.push("sootsim find <text>"),(r.includes("findbytestid")||r.includes("findbyid"))&&s.push("sootsim find --testid <id>"),r.includes("document.hidden")&&s.push("sootsim debug state keyboard (includes tab health)"),s.length>0&&Q("prefer-cli-over-eval",s);break}case"globals":{let e=await u.send({type:"evaluate",code:`(async () => {
|
|
579
|
+
const globals = {}
|
|
580
|
+
|
|
581
|
+
// test bridge (proxy in worker mode)
|
|
582
|
+
const testMethods = [
|
|
583
|
+
'findById', 'findByTestId', 'findByText', 'findByLabel', 'findByRole',
|
|
584
|
+
'findAllByRole', 'findByA11yState', 'findAllByA11yState', 'findByHint',
|
|
585
|
+
'findPressable', 'getStyle', 'getLayout', 'getAbsolutePosition', 'isVisible',
|
|
586
|
+
'queryAll', 'dumpTree', 'dumpAccessibilityTree', 'getNodeCount', 'getShellState',
|
|
587
|
+
'getScrollState', 'getScrollStateAt', 'scrollTo', 'waitForTree',
|
|
588
|
+
'waitForScreenTransitions', 'debugByText', 'debugByTestId', 'debugHitAt',
|
|
589
|
+
'debugGestureAt'
|
|
590
|
+
]
|
|
591
|
+
globals['test (\u2192 __sootsimTest)'] = testMethods
|
|
592
|
+
|
|
593
|
+
// debug
|
|
594
|
+
if (window.__sootsimDebug) {
|
|
595
|
+
globals['debug (\u2192 __sootsimDebug)'] = Object.keys(window.__sootsimDebug)
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
// interact
|
|
599
|
+
if (window.__sootsimInteract) {
|
|
600
|
+
globals['interact (\u2192 __sootsimInteract)'] = Object.keys(window.__sootsimInteract)
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
// keyboard
|
|
604
|
+
if (window.__sootsimKeyboard) {
|
|
605
|
+
globals['keyboard (\u2192 __sootsimKeyboard)'] = Object.keys(window.__sootsimKeyboard)
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// other globals
|
|
609
|
+
globals['other'] = [
|
|
610
|
+
'root (\u2192 __sootsimRoot) - live node tree',
|
|
611
|
+
'render() (\u2192 __sootsimForceRender) - force re-render'
|
|
612
|
+
]
|
|
613
|
+
|
|
614
|
+
return globals
|
|
615
|
+
})()`});console.log(` sootsim JS API:
|
|
616
|
+
`);for(let[t,n]of Object.entries(e)){console.log(` ${t}:`);for(let r of n)console.log(` .${r}`);console.log("")}console.log(` use: ${b("js")} <expression>`),console.log(` example: ${b("js")} test.findByText("Sign in")`);break}case"describe":{await $t({bridge:u,args:o,positional:a});break}case"perf":{let e=a[1];if(!e||e==="--help"||e==="-h"){console.log(`
|
|
617
|
+
${b("perf")} \u2014 performance profiling
|
|
618
|
+
|
|
619
|
+
subcommands:
|
|
620
|
+
stats one-shot stats (zero overhead query)
|
|
621
|
+
start begin recording frame times
|
|
622
|
+
stop stop recording and report results
|
|
623
|
+
frames [n] get last N frame times (default: 50)
|
|
624
|
+
transition <e> profile a shell transition (goHome, appSwitcher, lockScreen)
|
|
625
|
+
|
|
626
|
+
examples:
|
|
627
|
+
${b("perf")} stats
|
|
628
|
+
${b("perf")} start
|
|
629
|
+
# ... interact with the app ...
|
|
630
|
+
${b("perf")} stop
|
|
631
|
+
${b("perf")} transition goHome
|
|
632
|
+
`);break}switch(e){case"stats":{let t=await u.send({type:"evaluate",code:`(async () => {
|
|
633
|
+
// worker mode (host exposes these)
|
|
634
|
+
if (window.__sootsimPerfStats) {
|
|
635
|
+
return await window.__sootsimPerfStats()
|
|
636
|
+
}
|
|
637
|
+
// main-thread mode
|
|
638
|
+
const perf = window.__sootsimPerf
|
|
639
|
+
const a11y = window.__sootsimA11y
|
|
640
|
+
if (!perf && !a11y) return { error: 'no perf globals available' }
|
|
641
|
+
|
|
642
|
+
const frameStats = perf?.getFrameStats?.() || {}
|
|
643
|
+
const profile = a11y?.profile?.() || {}
|
|
644
|
+
const nodeCount = await window.__sootsimTest?.getNodeCount?.() || 0
|
|
645
|
+
|
|
646
|
+
return {
|
|
647
|
+
frames: frameStats.frames || profile.syncCount || 0,
|
|
648
|
+
avgMs: frameStats.totalMs && frameStats.frames
|
|
649
|
+
? (frameStats.totalMs / frameStats.frames).toFixed(2)
|
|
650
|
+
: profile.avgSyncMs?.toFixed(2) || '?',
|
|
651
|
+
maxMs: frameStats.maxMs?.toFixed(2) || profile.maxSyncMs?.toFixed(2) || '?',
|
|
652
|
+
layoutMs: frameStats.layoutTotalMs?.toFixed(2) || '?',
|
|
653
|
+
nodeCount,
|
|
654
|
+
jankFrames: frameStats.recentFrames?.filter(f => f > 16.67).length || 0,
|
|
655
|
+
recentCount: frameStats.recentFrames?.length || 0,
|
|
656
|
+
}
|
|
657
|
+
})()`});t.error&&(console.error(` error: ${t.error}`),process.exit(1));let n=t.avgMs==="?"&&t.maxMs==="?",r=t.avgMs!=="?"?(1e3/parseFloat(t.avgMs)).toFixed(1):"?";console.log(" perf stats:"),console.log(` frames: ${t.frames}`),console.log(` avg: ${t.avgMs}ms (${r} 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`),n&&process.stderr.write(`
|
|
658
|
+
\u26A0 frame timings are zero \u2014 enable them first:
|
|
659
|
+
sootsim debug perf start # begin recording
|
|
660
|
+
# \u2026 interact / run a flow / wait for the transition \u2026
|
|
661
|
+
sootsim debug perf stop # full report
|
|
662
|
+
sootsim debug perf stats # one-shot snapshot
|
|
663
|
+
`);break}case"start":{await u.send({type:"evaluate",code:`(async () => {
|
|
664
|
+
// worker mode
|
|
665
|
+
if (window.__sootsimPerfStart && window.__sootsimRenderHost) {
|
|
666
|
+
const result = window.__sootsimPerfStart()
|
|
667
|
+
window.${te} = {
|
|
668
|
+
active: true,
|
|
669
|
+
mode: 'render-worker',
|
|
670
|
+
lastSamples: [],
|
|
671
|
+
startedAt: performance.now(),
|
|
672
|
+
}
|
|
673
|
+
return result
|
|
674
|
+
}
|
|
675
|
+
// main-thread mode
|
|
676
|
+
window.__sootsimPerf?.enableFrameStats?.(true)
|
|
677
|
+
window.__sootsimA11y?.resetProfile?.()
|
|
678
|
+
window.${te} = {
|
|
679
|
+
active: true,
|
|
680
|
+
mode: 'main-thread',
|
|
681
|
+
lastSamples: [],
|
|
682
|
+
startedAt: performance.now(),
|
|
683
|
+
}
|
|
684
|
+
return { started: true }
|
|
685
|
+
})()`}),console.log(` profiling started \u2014 interact with the app, then run '${b("perf")} stop'`);break}case"stop":{let t=await u.send({type:"evaluate",code:`(async () => {
|
|
686
|
+
// worker mode
|
|
687
|
+
if (window.__sootsimRenderHost) {
|
|
688
|
+
const session = window.${te} || {}
|
|
689
|
+
const priorSamples = session.active && Array.isArray(session.lastSamples)
|
|
690
|
+
? session.lastSamples
|
|
691
|
+
: []
|
|
692
|
+
const flushedSamples = await window.__sootsimRenderHost.flushSamples()
|
|
693
|
+
const samples = priorSamples.concat(flushedSamples)
|
|
694
|
+
window.${te} = {
|
|
695
|
+
...session,
|
|
696
|
+
active: false,
|
|
697
|
+
mode: 'render-worker',
|
|
698
|
+
lastSamples: samples,
|
|
699
|
+
stoppedAt: performance.now(),
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
const frameTimes = samples.map(sample => sample[1])
|
|
703
|
+
const layoutTimes = samples.map(sample => sample[2])
|
|
704
|
+
const renderTimes = samples.map(sample => sample[3])
|
|
705
|
+
const copyTimes = samples.map(sample => sample[4])
|
|
706
|
+
const auxTimes = samples.map(sample => sample[5] || 0)
|
|
707
|
+
const otherTimes = samples.map(sample => sample[6] || 0)
|
|
708
|
+
const sorted = [...frameTimes].sort((a, b) => a - b)
|
|
709
|
+
const total = frameTimes.reduce((a, b) => a + b, 0)
|
|
710
|
+
const avg = frameTimes.length > 0 ? total / frameTimes.length : 0
|
|
711
|
+
const max = Math.max(...frameTimes, 0)
|
|
712
|
+
const layoutTotal = layoutTimes.reduce((a, b) => a + b, 0)
|
|
713
|
+
const renderTotal = renderTimes.reduce((a, b) => a + b, 0)
|
|
714
|
+
const copyTotal = copyTimes.reduce((a, b) => a + b, 0)
|
|
715
|
+
const auxTotal = auxTimes.reduce((a, b) => a + b, 0)
|
|
716
|
+
const otherTotal = otherTimes.reduce((a, b) => a + b, 0)
|
|
717
|
+
|
|
718
|
+
return {
|
|
719
|
+
mode: 'render-worker',
|
|
720
|
+
frames: frameTimes.length,
|
|
721
|
+
totalMs: total,
|
|
722
|
+
avgMs: avg,
|
|
723
|
+
maxMs: max,
|
|
724
|
+
layoutTotalMs: layoutTotal,
|
|
725
|
+
renderTotalMs: renderTotal,
|
|
726
|
+
copyTotalMs: copyTotal,
|
|
727
|
+
auxTotalMs: auxTotal,
|
|
728
|
+
otherTotalMs: otherTotal,
|
|
729
|
+
layoutAvgMs: frameTimes.length > 0 ? layoutTotal / frameTimes.length : 0,
|
|
730
|
+
renderAvgMs: frameTimes.length > 0 ? renderTotal / frameTimes.length : 0,
|
|
731
|
+
copyAvgMs: frameTimes.length > 0 ? copyTotal / frameTimes.length : 0,
|
|
732
|
+
auxAvgMs: frameTimes.length > 0 ? auxTotal / frameTimes.length : 0,
|
|
733
|
+
otherAvgMs: frameTimes.length > 0 ? otherTotal / frameTimes.length : 0,
|
|
734
|
+
p50: sorted[Math.floor(sorted.length * 0.5)] || 0,
|
|
735
|
+
p95: sorted[Math.floor(sorted.length * 0.95)] || 0,
|
|
736
|
+
p99: sorted[Math.floor(sorted.length * 0.99)] || 0,
|
|
737
|
+
jankFrames: frameTimes.filter((f) => f > 16.67).length,
|
|
738
|
+
sampleCount: frameTimes.length,
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
// main-thread mode
|
|
742
|
+
const perf = window.__sootsimPerf
|
|
743
|
+
const a11y = window.__sootsimA11y
|
|
744
|
+
if (!perf && !a11y) return { error: 'no perf globals' }
|
|
745
|
+
|
|
746
|
+
const frameStats = perf?.getFrameStats?.() || {}
|
|
747
|
+
const profile = a11y?.profile?.() || {}
|
|
748
|
+
|
|
749
|
+
// calculate distribution
|
|
750
|
+
const recent = frameStats.recentFrames || []
|
|
751
|
+
const sorted = [...recent].sort((a, b) => a - b)
|
|
752
|
+
const p50 = sorted[Math.floor(sorted.length * 0.5)] || 0
|
|
753
|
+
const p95 = sorted[Math.floor(sorted.length * 0.95)] || 0
|
|
754
|
+
const p99 = sorted[Math.floor(sorted.length * 0.99)] || 0
|
|
755
|
+
|
|
756
|
+
// disable collection
|
|
757
|
+
perf?.disableFrameStats?.()
|
|
758
|
+
window.${te} = {
|
|
759
|
+
...(window.${te} || {}),
|
|
760
|
+
active: false,
|
|
761
|
+
mode: 'main-thread',
|
|
762
|
+
lastSamples: recent.map((ms, index) => [index, ms, 0, 0, 0, 0, 0]),
|
|
763
|
+
stoppedAt: performance.now(),
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
return {
|
|
767
|
+
mode: 'main-thread',
|
|
768
|
+
frames: frameStats.frames || profile.syncCount || 0,
|
|
769
|
+
totalMs: frameStats.totalMs || 0,
|
|
770
|
+
avgMs: frameStats.totalMs && frameStats.frames
|
|
771
|
+
? frameStats.totalMs / frameStats.frames
|
|
772
|
+
: profile.avgSyncMs || 0,
|
|
773
|
+
maxMs: frameStats.maxMs || profile.maxSyncMs || 0,
|
|
774
|
+
layoutTotalMs: frameStats.layoutTotalMs || 0,
|
|
775
|
+
p50, p95, p99,
|
|
776
|
+
jankFrames: recent.filter(f => f > 16.67).length,
|
|
777
|
+
sampleCount: recent.length,
|
|
778
|
+
}
|
|
779
|
+
})()`});t.error&&(console.error(` error: ${t.error}`),process.exit(1));let n=t.avgMs>0?(1e3/t.avgMs).toFixed(1):"?",r=t.sampleCount>0?(t.jankFrames/t.sampleCount*100).toFixed(1):"0";console.log(` profiling stopped:
|
|
780
|
+
`),console.log(` frames: ${t.frames}`),console.log(` total: ${t.totalMs.toFixed(1)}ms`),console.log(` avg: ${t.avgMs.toFixed(2)}ms (${n} 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 n=await u.send({type:"evaluate",code:`(async () => {
|
|
781
|
+
if (window.__sootsimRenderHost) {
|
|
782
|
+
const session = window.${te} || {}
|
|
783
|
+
if (session.active) {
|
|
784
|
+
const priorSamples = Array.isArray(session.lastSamples) ? session.lastSamples : []
|
|
785
|
+
const flushedSamples = await window.__sootsimRenderHost.flushSamples()
|
|
786
|
+
const samples = priorSamples.concat(flushedSamples)
|
|
787
|
+
window.__sootsimRenderHost.startSampling()
|
|
788
|
+
window.${te} = {
|
|
789
|
+
...session,
|
|
790
|
+
active: true,
|
|
791
|
+
mode: 'render-worker',
|
|
792
|
+
lastSamples: samples,
|
|
793
|
+
lastFlushAt: performance.now(),
|
|
794
|
+
}
|
|
795
|
+
return {
|
|
796
|
+
mode: 'render-worker',
|
|
797
|
+
live: true,
|
|
798
|
+
samples: samples.slice(-${t}),
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
return {
|
|
802
|
+
mode: 'render-worker',
|
|
803
|
+
live: false,
|
|
804
|
+
samples: (session.lastSamples || []).slice(-${t}),
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
// main-thread mode
|
|
808
|
+
const perf = window.__sootsimPerf
|
|
809
|
+
if (!perf) return { error: 'no __sootsimPerf (try "perf start" first)' }
|
|
810
|
+
const stats = perf.getFrameStats?.() || {}
|
|
811
|
+
return {
|
|
812
|
+
mode: 'main-thread',
|
|
813
|
+
frames: (stats.recentFrames || []).slice(-${t}),
|
|
814
|
+
}
|
|
815
|
+
})()`});if(n.error&&(console.error(` error: ${n.error}`),process.exit(1)),n.mode==="render-worker"){let s=Array.isArray(n.samples)?n.samples:[];if(s.length===0){console.log(` no frame data \u2014 run '${b("perf")} start' first`);break}console.log(` last ${s.length} sampled frames (ms):`),console.log(" total layout render copy aux other t+");for(let[d,m,g,p,w,A,W]of s)console.log(` ${m.toFixed(2).padStart(7)} ${g.toFixed(2).padStart(7)} ${p.toFixed(2).padStart(7)} ${w.toFixed(2).padStart(7)} ${A.toFixed(2).padStart(6)} ${W.toFixed(2).padStart(7)} ${String(d).padStart(5)}`);console.log(""),Oe(s.map(d=>d[1])),n.live&&console.log(" sampling continues");break}let r=Array.isArray(n.frames)?n.frames:Array.isArray(n)?n:[];if(r.length===0){console.log(` no frame data \u2014 run '${b("perf")} start' first`);break}console.log(` last ${r.length} frame times (ms):`),console.log(` ${r.map(s=>s.toFixed(2)).join(", ")}`),Oe(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 n=await u.send({type:"evaluate",code:`(async () => {
|
|
816
|
+
if (window.__sootsimRenderHost) {
|
|
817
|
+
const session = window.${te} || {}
|
|
818
|
+
if (session.active) {
|
|
819
|
+
const priorSamples = Array.isArray(session.lastSamples) ? session.lastSamples : []
|
|
820
|
+
const flushedSamples = await window.__sootsimRenderHost.flushSamples()
|
|
821
|
+
const samples = priorSamples.concat(flushedSamples)
|
|
822
|
+
window.__sootsimRenderHost.startSampling()
|
|
823
|
+
window.${te} = {
|
|
824
|
+
...session,
|
|
825
|
+
active: true,
|
|
826
|
+
mode: 'render-worker',
|
|
827
|
+
lastSamples: samples,
|
|
828
|
+
lastFlushAt: performance.now(),
|
|
829
|
+
}
|
|
830
|
+
return {
|
|
831
|
+
mode: 'render-worker',
|
|
832
|
+
live: true,
|
|
833
|
+
samples: samples
|
|
834
|
+
.slice()
|
|
835
|
+
.sort((a, b) => b[1] - a[1])
|
|
836
|
+
.slice(0, ${t}),
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
const samples = Array.isArray(session.lastSamples) ? session.lastSamples : []
|
|
840
|
+
return {
|
|
841
|
+
mode: 'render-worker',
|
|
842
|
+
live: false,
|
|
843
|
+
samples: samples
|
|
844
|
+
.slice()
|
|
845
|
+
.sort((a, b) => b[1] - a[1])
|
|
846
|
+
.slice(0, ${t}),
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
const perf = window.__sootsimPerf
|
|
850
|
+
if (!perf) return { error: 'no __sootsimPerf (try "perf start" first)' }
|
|
851
|
+
const stats = perf.getFrameStats?.() || {}
|
|
852
|
+
const recent = Array.isArray(stats.recentFrames) ? stats.recentFrames : []
|
|
853
|
+
return {
|
|
854
|
+
mode: 'main-thread',
|
|
855
|
+
frames: recent.slice().sort((a, b) => b - a).slice(0, ${t}),
|
|
856
|
+
}
|
|
857
|
+
})()`});if(n.error&&(console.error(` error: ${n.error}`),process.exit(1)),n.mode==="render-worker"){let s=Array.isArray(n.samples)?n.samples:[];if(s.length===0){console.log(` no frame data \u2014 run '${b("perf")} start' first`);break}console.log(` worst ${s.length} sampled frames (ms):`),console.log(" total layout render copy aux other t+");for(let[d,m,g,p,w,A,W]of s)console.log(` ${m.toFixed(2).padStart(7)} ${g.toFixed(2).padStart(7)} ${p.toFixed(2).padStart(7)} ${w.toFixed(2).padStart(7)} ${A.toFixed(2).padStart(6)} ${W.toFixed(2).padStart(7)} ${String(d).padStart(5)}`);n.live&&(console.log(""),console.log(" sampling continues"));break}let r=Array.isArray(n.frames)?n.frames:Array.isArray(n)?n:[];if(r.length===0){console.log(` no frame data \u2014 run '${b("perf")} start' first`);break}console.log(` worst ${r.length} frame times (ms):`),console.log(` ${r.map(s=>s.toFixed(2)).join(", ")}`);break}case"transition":{let t=a[2];if(!t||!["goHome","appSwitcher","lockScreen"].includes(t)){console.log(`
|
|
858
|
+
${b("perf")} transition <event> \u2014 profile a shell transition
|
|
859
|
+
|
|
860
|
+
events:
|
|
861
|
+
goHome swipe-to-home animation
|
|
862
|
+
appSwitcher app switcher card animation
|
|
863
|
+
lockScreen lock screen transition
|
|
864
|
+
|
|
865
|
+
note: uses 600ms capture window \u2014 may need --timeout 10000 flag
|
|
866
|
+
|
|
867
|
+
examples:
|
|
868
|
+
${b("perf")} transition goHome --timeout 10000
|
|
869
|
+
${b("perf")} transition appSwitcher
|
|
870
|
+
`);break}let r=`sootsim:${t}`;console.log(` profiling ${t} transition...`),console.log(" (use --timeout 10000 if this times out)");let s=await u.send({type:"evaluate",code:`(async () => {
|
|
871
|
+
// only supported in render-worker mode
|
|
872
|
+
if (!window.__sootsimRenderHost) {
|
|
873
|
+
return { error: 'transition profiling requires render-worker mode' }
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
// start sampling
|
|
877
|
+
window.__sootsimRenderHost.startSampling()
|
|
878
|
+
|
|
879
|
+
// give a frame for sampling to start
|
|
880
|
+
await new Promise(r => requestAnimationFrame(() => r(undefined)))
|
|
881
|
+
|
|
882
|
+
// dispatch the shell event
|
|
883
|
+
window.dispatchEvent(new Event('${r}'))
|
|
884
|
+
|
|
885
|
+
// wait 600ms for transition to complete (shell animations are ~300-500ms)
|
|
886
|
+
// using fixed timing avoids complex animation-end detection
|
|
887
|
+
await new Promise(r => setTimeout(r, 600))
|
|
888
|
+
|
|
889
|
+
// flush samples and compute stats
|
|
890
|
+
const samples = await window.__sootsimRenderHost.flushSamples()
|
|
891
|
+
const frameTimes = samples.map(s => s[1])
|
|
892
|
+
const layoutTimes = samples.map(s => s[2])
|
|
893
|
+
const renderTimes = samples.map(s => s[3])
|
|
894
|
+
const copyTimes = samples.map(s => s[4])
|
|
895
|
+
const auxTimes = samples.map(s => s[5] || 0)
|
|
896
|
+
const otherTimes = samples.map(s => s[6] || 0)
|
|
897
|
+
const sorted = [...frameTimes].sort((a, b) => a - b)
|
|
898
|
+
const total = frameTimes.reduce((a, b) => a + b, 0)
|
|
899
|
+
const avg = frameTimes.length > 0 ? total / frameTimes.length : 0
|
|
900
|
+
const max = Math.max(...frameTimes, 0)
|
|
901
|
+
const layoutTotal = layoutTimes.reduce((a, b) => a + b, 0)
|
|
902
|
+
const renderTotal = renderTimes.reduce((a, b) => a + b, 0)
|
|
903
|
+
const copyTotal = copyTimes.reduce((a, b) => a + b, 0)
|
|
904
|
+
const auxTotal = auxTimes.reduce((a, b) => a + b, 0)
|
|
905
|
+
const otherTotal = otherTimes.reduce((a, b) => a + b, 0)
|
|
906
|
+
|
|
907
|
+
return {
|
|
908
|
+
event: '${t}',
|
|
909
|
+
frames: frameTimes.length,
|
|
910
|
+
totalMs: total,
|
|
911
|
+
avgMs: avg,
|
|
912
|
+
maxMs: max,
|
|
913
|
+
layoutTotalMs: layoutTotal,
|
|
914
|
+
renderTotalMs: renderTotal,
|
|
915
|
+
copyTotalMs: copyTotal,
|
|
916
|
+
auxTotalMs: auxTotal,
|
|
917
|
+
otherTotalMs: otherTotal,
|
|
918
|
+
layoutAvgMs: frameTimes.length > 0 ? layoutTotal / frameTimes.length : 0,
|
|
919
|
+
renderAvgMs: frameTimes.length > 0 ? renderTotal / frameTimes.length : 0,
|
|
920
|
+
copyAvgMs: frameTimes.length > 0 ? copyTotal / frameTimes.length : 0,
|
|
921
|
+
auxAvgMs: frameTimes.length > 0 ? auxTotal / frameTimes.length : 0,
|
|
922
|
+
otherAvgMs: frameTimes.length > 0 ? otherTotal / frameTimes.length : 0,
|
|
923
|
+
p50: sorted[Math.floor(sorted.length * 0.5)] || 0,
|
|
924
|
+
p95: sorted[Math.floor(sorted.length * 0.95)] || 0,
|
|
925
|
+
p99: sorted[Math.floor(sorted.length * 0.99)] || 0,
|
|
926
|
+
jankFrames: frameTimes.filter(f => f > 16.67).length,
|
|
927
|
+
samples,
|
|
928
|
+
}
|
|
929
|
+
})()`});if(s.error&&(console.error(` error: ${s.error}`),process.exit(1)),s.warning&&console.log(` warning: ${s.warning}`),s.frames===0){console.log(" no frames captured");break}let d=s.avgMs>0?(1e3/s.avgMs).toFixed(1):"?",m=s.frames>0?(s.jankFrames/s.frames*100).toFixed(1):"0";console.log(` ${t} transition profiled:
|
|
930
|
+
|
|
931
|
+
frames: ${s.frames}
|
|
932
|
+
total: ${s.totalMs.toFixed(1)}ms
|
|
933
|
+
avg: ${s.avgMs.toFixed(2)}ms (${d} fps)
|
|
934
|
+
max: ${s.maxMs.toFixed(2)}ms
|
|
935
|
+
|
|
936
|
+
breakdown (avg per frame):
|
|
937
|
+
layout: ${s.layoutAvgMs?.toFixed(2)||"?"}ms
|
|
938
|
+
render: ${s.renderAvgMs?.toFixed(2)||"?"}ms
|
|
939
|
+
copy: ${s.copyAvgMs?.toFixed(2)||"?"}ms
|
|
940
|
+
aux: ${s.auxAvgMs?.toFixed(2)||"?"}ms
|
|
941
|
+
other: ${s.otherAvgMs?.toFixed(2)||"?"}ms
|
|
942
|
+
|
|
943
|
+
distribution (${s.frames} samples):
|
|
944
|
+
p50: ${s.p50.toFixed(2)}ms
|
|
945
|
+
p95: ${s.p95.toFixed(2)}ms
|
|
946
|
+
p99: ${s.p99.toFixed(2)}ms
|
|
947
|
+
jank: ${s.jankFrames} frames (${m}%) >16.67ms`),Array.isArray(s.samples)&&s.samples.length>0&&(console.log(""),Oe(s.samples.map(g=>g[1])));break}default:console.error(` unknown perf subcommand: ${e}`),process.exit(1)}break}case"errors":{let e=a[1];if(e==="clear"){await tt(u),j(c)?J({cleared:!0}):console.log(" error buffer cleared");break}let t=e?Number(e):20,n=await Ze(u,t);if(j(c)){J(n);break}if(n.length===0){console.log(" no errors captured");break}console.log(` ${n.length} error(s):
|
|
948
|
+
`);for(let r of n){let s=ne(r.timestamp),d=r.args.map(m=>typeof m=="object"?JSON.stringify(m):m).join(" ");if(console.log(` [${s}] ${d}`),r.stack){let m=r.stack.split(`
|
|
949
|
+
`).slice(0,3);for(let g of m)console.log(` ${g.trim()}`)}}break}case"warnings":{let e=a[1]?Number(a[1]):20,t=await et(u,e);if(j(c)){J(t);break}if(t.length===0){console.log(" no warnings captured");break}console.log(` ${t.length} warning(s):
|
|
950
|
+
`);for(let n of t){let r=ne(n.timestamp),s=n.args.map(d=>typeof d=="object"?JSON.stringify(d):d).join(" ");console.log(` [${r}] ${s}`)}break}case"animations":{let e=await V(u,"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):
|
|
951
|
+
`);for(let t of e){let n=String(t.kind).padEnd(6),r=`${Number(t.from).toFixed(2)}\u2192${Number(t.to).toFixed(2)}`,s=Number(t.current??0).toFixed(2),d=`${Math.round((t.progress??0)*100)}%`,m=`${Math.round(t.elapsedMs??0)}ms`,g=t.loop?" loop":"",p=t.layoutBound?" layout":"";console.log(` #${t.id} ${n} ${r.padEnd(14)} cur=${s.padEnd(7)} ${d.padStart(4)} ${m}${g}${p}`)}break}case"animation":{let e=a[1];(!e||e==="--help"||e==="-h")&&(console.error(` usage: ${b("animation")} <id>`),process.exit(1));let t=Number(e);Number.isFinite(t)||(console.error(` invalid id: ${e}`),process.exit(1));let n=await V(u,"getAnimation",t);console.log(JSON.stringify(n,null,2));break}case"stop-animation":{let e=a[1];(!e||e==="--help"||e==="-h")&&(console.error(` usage: ${b("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 n=await V(u,"stopAnimation",t);console.log(` stopped ${n??0} animation(s)`);break}case"requests":{let e=a[1];if(e==="clear"){await st(u),j(c)?J({cleared:!0}):console.log(" request buffer cleared");break}let t=e==="all",n=t?a[2]:e,r=n?Number(n):20,s=await ot(u,{failed:!t,limit:r});if(j(c)){J(s);break}if(s.length===0){console.log(t?" no requests captured":" no failed requests captured");break}console.log(` ${s.length} ${t?"request(s)":"failed request(s)"}:
|
|
952
|
+
`);for(let d of s){let m=ne(d.timestamp);console.log(` [${m}] ${Y(d)}`),d.responseBody?console.log(` ${d.responseBody}`):d.error&&console.log(` ${d.error}`)}break}case"network":{let e=a[1],t=null,n=null,r=!1,s=!1,d=1e3,m=!1,g=!1;for(let N=0;N<c.length;N++){let h=c[N];if(h==="--filter")t=c[N+1]??null,N++;else if(h==="--limit"){let v=Number(c[N+1]);Number.isFinite(v)&&(n=v),N++}else if(h==="--threshold"){let v=Number(c[N+1]);Number.isFinite(v)&&v>0&&(d=v),N++}else h==="--failed"?r=!0:h==="--slow"?s=!0:h==="--tail"||h==="-f"?m=!0:h==="--json"&&(g=!0)}if(e==="clear"){await u.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 h=await u.send({type:"evaluate",code:`(() => {
|
|
953
|
+
const obs = window.__sootsimObservability;
|
|
954
|
+
if (!obs) return null;
|
|
955
|
+
return obs.network.getSnapshot().find(e => e.id === ${JSON.stringify(N)}) || null;
|
|
956
|
+
})()`});h||(console.error(` no entry with id ${N}`),process.exit(1)),g?console.log(JSON.stringify(h,null,2)):ko(h);break}let p=n??(m?200:e?Number(e):20);Number.isFinite(p)||(console.error(` invalid limit: ${e} \u2014 \`network\` takes a numeric count (e.g. ${b("network")} 100).
|
|
957
|
+
to target a specific sim, use \`--sim ${e}\` instead.`),process.exit(1));let w=async()=>{let N=await u.send({type:"evaluate",code:`(() => {
|
|
958
|
+
const obs = window.__sootsimObservability;
|
|
959
|
+
if (!obs) return { ok: false };
|
|
960
|
+
return { ok: true, entries: obs.network.getSnapshot() };
|
|
961
|
+
})()`});if(!N||!N.ok)throw new Error("observability bridge not installed \u2014 is the engine running?");return N.entries??[]},A=N=>{let h=N;if(r&&(h=h.filter(v=>!!v.error||v.status!=null&&v.status>=400)),s&&(h=h.filter(v=>v.durationMs!=null&&v.durationMs>=d)),t){let v=t.toLowerCase();h=h.filter(P=>(P.displayUrl||P.url).toLowerCase().includes(v))}return s&&!m&&(h=[...h].sort((v,P)=>(P.durationMs??0)-(v.durationMs??0))),h};if(!m){let N=await w(),h=A(N).slice(-p);if(g){console.log(JSON.stringify(h,null,2));break}if(h.length===0){N.length===0?console.log(" no network requests captured"):console.log(s?` no requests slower than ${d}ms (${N.length} total \u2014 try --threshold <ms>)`:" no matching requests");break}console.log(s?` ${h.length} request(s) slower than ${d}ms (sorted by duration desc):
|
|
962
|
+
`:` ${h.length} request(s):
|
|
963
|
+
`);for(let v of h)Dt(v);break}console.log(` tailing network (ctrl-c to stop)...
|
|
964
|
+
`);let W=new Set,U=!0,K=()=>{U=!1};process.on("SIGINT",K);try{for(;U;){let N=await w(),h=A(N);for(let v of h)v.durationMs!=null&&(W.has(v.id)||(W.add(v.id),g?console.log(JSON.stringify(v)):Dt(v)));await Z(250)}}finally{process.off("SIGINT",K)}break}case"logs":{let e=a[1],t=null,n=null,r=null,s=!1,d=!1,m=!1;for(let h=0;h<c.length;h++){let v=c[h];if(v==="--filter")t=c[h+1]??null,h++;else if(v==="--limit"){let P=Number(c[h+1]);Number.isFinite(P)&&(n=P),h++}else v==="--level"?(r=c[h+1]??null,h++):v==="--tail"||v==="-f"?s=!0:v==="--json"?d=!0:(v==="--internal"||v==="--all")&&(m=!0)}let g=r?new Set(r.split(",").map(h=>h.trim()).filter(h=>h==="log"||h==="info"||h==="warn"||h==="error"||h==="debug")):null;if(e==="clear"){await rt(u),console.log(" log buffer cleared");break}let p=!d&&process.stdout.isTTY===!0,w=n??(s?500:e?Number(e):50);Number.isFinite(w)||(console.error(` invalid limit: ${e} \u2014 \`logs\` takes a numeric count (e.g. ${b("logs")} 100).
|
|
965
|
+
to target a specific sim, use \`--sim ${e}\` instead.`),process.exit(1));let A=()=>nt(u),W=h=>it(h,{level:g,filter:t,showInternal:m});if(!s){let h=await A(),v=W(h).slice(-w);if(d){console.log(JSON.stringify(v,null,2));break}if(v.length===0){console.log(h.length===0?" no logs captured":" no matching logs");break}console.log(` ${v.length} log(s):
|
|
966
|
+
`);for(let P of v)jt(P,p);break}console.log(` tailing logs (ctrl-c to stop)...
|
|
967
|
+
`);let U=new Set,K=!0,N=()=>{K=!1};process.on("SIGINT",N);try{for(;K;){let h=await A(),v=W(h);for(let P of v)U.has(P.id)||(U.add(P.id),d?console.log(JSON.stringify(P)):jt(P,p));await Z(250)}}finally{process.off("SIGINT",N)}break}default:console.error(` unknown subcommand: ${y}`),process.exit(1)}if(Ce.has(y)&&!o.includes("--no-wait")&&process.env.SOOTSIM_NO_AUTO_WAIT!=="1"&&await x(u),!B.has(y)&&!j(c))try{await pe(u)}catch{}}catch(e){let t=e instanceof Error?e.message:String(e);console.error(` ${y??"inspect"} failed: ${t}`);let n=/^no sim connected with id (.+)$/.exec(t),r=/^command timed out after \d+s$/.test(t)||t.startsWith("sim disconnected:")||t.startsWith("bridge never reconnected")||t.startsWith("could not connect to ws://");if(n)await yt(u,M,n[1]);else if(/^no sim connected$/.test(t))gt(M);else if(r)process.stderr.write(` the sim is not responding. recover it with:
|
|
968
|
+
sootsim close --sim <id> # force-close the wedged sim
|
|
969
|
+
sootsim list # confirm it's gone
|
|
970
|
+
`);else{try{await mt(u)}catch{}try{await E({includeTail:!0})}catch{}try{await ie({includeTail:!0})}catch{}}process.exit(1)}finally{u.close()}}export{pn as runInspect};
|