sootsim 0.1.227 → 0.1.228
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/README.md +14 -14
- package/detox/element-types.ts +3 -3
- package/detox/expectations.ts +29 -24
- package/detox/gestures.ts +16 -16
- package/detox/index.ts +34 -32
- package/dist-cli/bin.js +4 -4
- package/dist-cli/chunks/{agent-HBVXCRJT.js → agent-6P5T2QHC.js} +2 -2
- package/dist-cli/chunks/{agent-wrapper-X376DPV2.js → agent-wrapper-SMEMJZXI.js} +2 -2
- package/dist-cli/chunks/{app-fonts-LIQTD5RP.js → app-fonts-6OQTLX3U.js} +2 -2
- package/dist-cli/chunks/{assert-X6PPLN72.js → assert-ZAYFOW6R.js} +2 -2
- package/dist-cli/chunks/{auth-INRWIM2C.js → auth-Y53UANSH.js} +2 -2
- package/dist-cli/chunks/beta-ZQCASJ7C.js +2 -0
- package/dist-cli/chunks/{camera-LGFHYCJ5.js → camera-AJQWSOO4.js} +2 -2
- package/dist-cli/chunks/{chunk-2BQOZATN.js → chunk-2I62CFYI.js} +3 -3
- package/dist-cli/chunks/{chunk-E3DLUOFK.js → chunk-34MFG4IM.js} +7 -7
- package/dist-cli/chunks/{chunk-J7IFVTWX.js → chunk-4A6HM2K3.js} +1 -1
- package/dist-cli/chunks/chunk-4QOY4T27.js +3 -0
- package/dist-cli/chunks/{chunk-HRYKZ5YY.js → chunk-6Q2B7QHC.js} +5 -5
- package/dist-cli/chunks/{chunk-F5HOYUD2.js → chunk-6U3GMNTP.js} +1 -1
- package/dist-cli/chunks/{chunk-RNWJQ4UR.js → chunk-72AQH53U.js} +1 -1
- package/dist-cli/chunks/{chunk-NIN75M5H.js → chunk-7HMRWJHH.js} +1 -1
- package/dist-cli/chunks/{chunk-YB2LM6VB.js → chunk-7TJVPCQA.js} +6 -6
- package/dist-cli/chunks/{chunk-LM544J6V.js → chunk-A5SO4OGE.js} +1 -1
- package/dist-cli/chunks/{chunk-D42IRY2Y.js → chunk-AJ3CDBW6.js} +2 -2
- package/dist-cli/chunks/chunk-ALE5MU5Z.js +2 -0
- package/dist-cli/chunks/{chunk-NHE3YHDU.js → chunk-AVS7RL73.js} +2 -2
- package/dist-cli/chunks/chunk-AWF575Y5.js +1 -0
- package/dist-cli/chunks/chunk-BHNOPI7I.js +2 -0
- package/dist-cli/chunks/{chunk-LCJSTEIR.js → chunk-D2QUTBZP.js} +2 -2
- package/dist-cli/chunks/{chunk-ESK7B2BQ.js → chunk-DEVNCWS4.js} +6 -6
- package/dist-cli/chunks/{chunk-GUCFICA4.js → chunk-E5FOMYR6.js} +1 -1
- package/dist-cli/chunks/{chunk-2XXPF6LP.js → chunk-EFMPSG7T.js} +2 -2
- package/dist-cli/chunks/{chunk-4J7BIXEB.js → chunk-EKWOBYJO.js} +2 -2
- package/dist-cli/chunks/{chunk-E75EBS77.js → chunk-EPQ5EZBJ.js} +2 -2
- package/dist-cli/chunks/{chunk-Q4FB222M.js → chunk-FDSFA7WL.js} +3 -3
- package/dist-cli/chunks/{chunk-UGWURWHN.js → chunk-FSKQZHM2.js} +2 -2
- package/dist-cli/chunks/{chunk-QWRYD2QV.js → chunk-G42TLJVQ.js} +18 -18
- package/dist-cli/chunks/{chunk-HXHB5A6R.js → chunk-JA52F67H.js} +2 -2
- package/dist-cli/chunks/chunk-JKZY5CPQ.js +2 -0
- package/dist-cli/chunks/{chunk-MG6JE3AM.js → chunk-JV43GSZB.js} +2 -2
- package/dist-cli/chunks/{chunk-7L5IKIHC.js → chunk-JWZMAJC7.js} +1 -1
- package/dist-cli/chunks/{chunk-F53C5HAB.js → chunk-KIL5F7KD.js} +1 -1
- package/dist-cli/chunks/chunk-KY2KLPYL.js +1 -0
- package/dist-cli/chunks/{chunk-DB3GMVOH.js → chunk-LBXHG4AU.js} +2 -2
- package/dist-cli/chunks/{chunk-SBIAPF6E.js → chunk-MCMMRIJV.js} +1 -1
- package/dist-cli/chunks/{chunk-A4BOYB55.js → chunk-MWZOCZ7J.js} +2 -2
- package/dist-cli/chunks/{chunk-HXSV263V.js → chunk-NCXHUU7N.js} +1 -1
- package/dist-cli/chunks/{chunk-HTVB3FW2.js → chunk-NME4QWJ3.js} +2 -2
- package/dist-cli/chunks/{chunk-J2JAOIMN.js → chunk-OETQYAI2.js} +2 -2
- package/dist-cli/chunks/chunk-PJBYZZWR.js +2 -0
- package/dist-cli/chunks/{chunk-NU755HCE.js → chunk-PNPH4JLS.js} +1 -1
- package/dist-cli/chunks/chunk-RT3OS624.js +118 -0
- package/dist-cli/chunks/{chunk-7LDHOQ7B.js → chunk-SACWV3LZ.js} +20 -20
- package/dist-cli/chunks/chunk-SPJSTRXX.js +24 -0
- package/dist-cli/chunks/{chunk-3L5EXWCP.js → chunk-UYLESZU3.js} +1 -1
- package/dist-cli/chunks/{chunk-XESYTWFM.js → chunk-WWZL7HNB.js} +29 -29
- package/dist-cli/chunks/{chunk-T6MEERRI.js → chunk-ZBJ5JMXM.js} +2 -2
- package/dist-cli/chunks/chunk-ZWJEJR73.js +4 -0
- package/dist-cli/chunks/cli-version-V4GJYM74.js +2 -0
- package/dist-cli/chunks/{compat-MH673TEJ.js → compat-W7E4744D.js} +3 -3
- package/dist-cli/chunks/{config-SSCDV5ZJ.js → config-N7G65EY2.js} +2 -2
- package/dist-cli/chunks/{control-54R2XDLV.js → control-7VDFEVWU.js} +2 -2
- package/dist-cli/chunks/daemon-UI3PQ47F.js +2 -0
- package/dist-cli/chunks/{debug-PFP646II.js → debug-ZKUCSCOU.js} +3 -3
- package/dist-cli/chunks/{desktop-BPYYJ3EM.js → desktop-L3OXTT45.js} +3 -3
- package/dist-cli/chunks/{detox-BIUVHXYH.js → detox-QG4IBZAG.js} +2 -2
- package/dist-cli/chunks/{device-BNSPNIP6.js → device-QC6MDI7W.js} +2 -2
- package/dist-cli/chunks/{diagnose-BPTDSGOB.js → diagnose-HTUDENJK.js} +2 -2
- package/dist-cli/chunks/drivers-L2BXXDI7.js +2 -0
- package/dist-cli/chunks/{film-ILA6VSOG.js → film-CT7FHNLE.js} +3 -3
- package/dist-cli/chunks/flow-XUBXWJHL.js +2 -0
- package/dist-cli/chunks/help-7CIGANJN.js +2 -0
- package/dist-cli/chunks/{hidden-runtime-alias-TD7IVAPF.js → hidden-runtime-alias-YTUEPZ3U.js} +2 -2
- package/dist-cli/chunks/{home-paths-H36JDTNO.js → home-paths-7K6HDXOP.js} +2 -2
- package/dist-cli/chunks/inspect-ZY3QI7VJ.js +2 -0
- package/dist-cli/chunks/install-desktop-CVPRYFFV.js +2 -0
- package/dist-cli/chunks/{login-5WGZX2ZD.js → login-XHOOXAOW.js} +4 -4
- package/dist-cli/chunks/{logout-V53WTVIZ.js → logout-7BISNC5F.js} +2 -2
- package/dist-cli/chunks/{maestro-HGKYRD54.js → maestro-YD3G7LSG.js} +3 -3
- package/dist-cli/chunks/{maestro-generate-6DNZSKDP.js → maestro-generate-WNOWZC5K.js} +3 -3
- package/dist-cli/chunks/{mode-YFMKORE5.js → mode-Y6JJMXU5.js} +2 -2
- package/dist-cli/chunks/optional-demo-registry-YUXURWKX.js +2 -0
- package/dist-cli/chunks/{perf-EOIGFDWM.js → perf-AY3ZKTDS.js} +2 -2
- package/dist-cli/chunks/{record-2F54QS6Y.js → record-ZC4W6QN6.js} +10 -10
- package/dist-cli/chunks/runtime-MVYAP3UX.js +2 -0
- package/dist-cli/chunks/screenshot-command-NRKTGTSJ.js +151 -0
- package/dist-cli/chunks/{screenshots-capture-DIICN24R.js → screenshots-capture-LZR3AHWN.js} +3 -3
- package/dist-cli/chunks/{serve-66NC6PPZ.js → serve-4X2WI5XF.js} +5 -5
- package/dist-cli/chunks/{setup-ZYN4BTBR.js → setup-KODPGJBJ.js} +3 -3
- package/dist-cli/chunks/{skills-MDBIER7U.js → skills-DEAUDOAN.js} +2 -2
- package/dist-cli/chunks/{storage-AQ3SEO4Y.js → storage-P7FQRH5T.js} +2 -2
- package/dist-cli/chunks/store-PTRXOHHV.js +2 -0
- package/dist-cli/chunks/telemetry-JHKOHSI2.js +2 -0
- package/dist-cli/chunks/{timeline-VEGHQZ36.js → timeline-7ISYXLR3.js} +2 -2
- package/dist-cli/chunks/{upgrade-RNDCRPLJ.js → upgrade-NZBJS5L2.js} +3 -3
- package/dist-cli/chunks/upload-J34H5SXV.js +2 -0
- package/dist-cli/chunks/{version-XUMPKQUM.js → version-J6BLGLTO.js} +2 -2
- package/dist-cli/chunks/{web-ESQGHVPD.js → web-Y6UVYM3Z.js} +2 -2
- package/dist-cli/chunks/{what-happened-6NJENKUF.js → what-happened-YKXXY6W2.js} +2 -2
- package/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/agent-identity.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 +2 -2
- package/dist-lib/backend-origin.cjs +18 -18
- package/dist-lib/beta.cjs +1 -1
- package/dist-lib/beta.mjs +1 -1
- package/dist-lib/bridge-constants.cjs +4 -4
- package/dist-lib/cli-constants.cjs +1 -1
- package/dist-lib/config.cjs +1 -1
- package/dist-lib/detox/index.cjs +321 -79
- package/dist-lib/dev-bundle-resolution.cjs +2 -2
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +18 -13
- package/dist-lib/host/fetch-proxy-handler.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +1 -1
- package/dist-lib/jump-to-source-babel.cjs +1 -1
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +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/scripts/dev-server-scanner.cjs +7 -7
- package/dist-lib/sdk.cjs +12 -4
- package/dist-lib/sdk.mjs +12 -4
- package/dist-lib/skills.cjs +425 -169
- package/dist-lib/vite.cjs +1 -1
- package/package.json +4 -4
- package/scripts/dev-server-scanner.ts +5 -5
- package/scripts/postinstall.cjs +1 -1
- package/scripts/preuninstall.cjs +1 -1
- package/skills/{soot → contrast}/SKILL.md +4 -4
- package/skills/sootsim-perf/SKILL.md +3 -1
- package/src/auth/shared-session.ts +1 -1
- package/src/backend-origin.ts +11 -11
- package/src/bridge-constants.ts +3 -3
- package/src/home-paths.ts +1 -1
- package/src/host/agent-host.ts +2 -2
- package/src/host/bridge-host.ts +21 -21
- package/src/native-dev-bundle-url.ts +3 -3
- package/src/runtime-assets.ts +3 -3
- package/src/runtime-delivery.ts +10 -4
- package/src/screenshots/compose.ts +4 -1
- package/src/screenshots/frame-compose.ts +4 -1
- package/src/screenshots/orchestrate.ts +7 -2
- package/src/vite-plugin-one.ts +3 -3
- package/src/vite-plugin.ts +3 -3
- package/dist-cli/chunks/beta-WLLSIVLW.js +0 -2
- package/dist-cli/chunks/chunk-35EAEAN4.js +0 -24
- package/dist-cli/chunks/chunk-44Z2X5R4.js +0 -2
- package/dist-cli/chunks/chunk-4BLOZ3AF.js +0 -2
- package/dist-cli/chunks/chunk-7K5K5NKB.js +0 -2
- package/dist-cli/chunks/chunk-7RWDQCIT.js +0 -1
- package/dist-cli/chunks/chunk-BVD2JFOX.js +0 -1
- package/dist-cli/chunks/chunk-HBEEYWK5.js +0 -2
- package/dist-cli/chunks/chunk-JNUGPBWC.js +0 -118
- package/dist-cli/chunks/chunk-KBSJA7HK.js +0 -3
- package/dist-cli/chunks/chunk-Z2E2DDIQ.js +0 -4
- package/dist-cli/chunks/cli-version-NNBCIQKL.js +0 -2
- package/dist-cli/chunks/daemon-GL5GQTWB.js +0 -2
- package/dist-cli/chunks/drivers-KBKJVF2Y.js +0 -2
- package/dist-cli/chunks/flow-L247VVBM.js +0 -2
- package/dist-cli/chunks/help-QIZEANNK.js +0 -2
- package/dist-cli/chunks/inspect-6OAVS27G.js +0 -2
- package/dist-cli/chunks/install-desktop-LKYAUUQY.js +0 -2
- package/dist-cli/chunks/optional-demo-registry-YGNESGBH.js +0 -2
- package/dist-cli/chunks/runtime-FYVV4DCQ.js +0 -2
- package/dist-cli/chunks/screenshot-command-R535TYXY.js +0 -151
- package/dist-cli/chunks/store-6ZGLOTZI.js +0 -2
- package/dist-cli/chunks/telemetry-V76UPVDV.js +0 -2
- package/dist-cli/chunks/upload-KRBS3Y7Q.js +0 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/*! sootsim v0.1.
|
|
2
|
-
import{a as
|
|
1
|
+
/*! sootsim v0.1.228 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
|
|
2
|
+
import{a as ot}from"./chunk-OETQYAI2.js";import{a as it}from"./chunk-4QOY4T27.js";import{a as me,c as ge,d as we,e as et,f as ye,g as be,h as tt,i as Se,j as nt}from"./chunk-WWZL7HNB.js";import{a as Qe}from"./chunk-AJ3CDBW6.js";import{a as rt}from"./chunk-34MFG4IM.js";import{h as qe,p as Ye,r as Ze,v as Xe}from"./chunk-DEVNCWS4.js";import{f as Ue}from"./chunk-EKWOBYJO.js";import{a as Ke}from"./chunk-NCXHUU7N.js";import{a as He}from"./chunk-A5SO4OGE.js";import{h as fe,m as ze}from"./chunk-LBXHG4AU.js";import{I as J,m as We,n as je,o as Ve,p as Je}from"./chunk-G42TLJVQ.js";import{g as pe,h as he,i as Ge}from"./chunk-SPJSTRXX.js";import{a as Be,b as de}from"./chunk-BHNOPI7I.js";import{e as ue,f as Ne}from"./chunk-EPQ5EZBJ.js";import{g as Le,h as Ce}from"./chunk-7HMRWJHH.js";import*as $ from"fs";import{createHash as Gt,randomUUID as zt}from"node:crypto";import{tmpdir as K}from"os";import*as w from"path";import*as S from"fs";import*as b from"path";var $t="inset 0 0 0 0.5px #000, inset 0 0 0 2px #757575, inset 0 0 0 5px #212121",at=1;function Pt(r){let e=Ce(r),t=e.scale,n=e.statusBarHeight>0&&!e.dynamicIsland&&e.homeIndicatorHeight===0&&e.cornerRadius===0,i=e.width,o=e.height,a=n?e.width+58:e.width+e.bezelWidth*2,s=n?e.height+111+111:e.height+e.bezelWidth*2,l=9.5,u=at,p=a+l*2,g=s+at*2,I=l+(n?29:e.bezelWidth),m=n?111:e.bezelWidth,P=n?52:e.cornerRadius+e.bezelWidth,k=[{side:"right",top:e.hardwareButtons.lock.top,height:e.hardwareButtons.lock.height,width:e.hardwareButtons.width},{side:"left",top:e.hardwareButtons.ringToggle.top,height:e.hardwareButtons.ringToggle.height,width:e.hardwareButtons.width},{side:"left",top:e.hardwareButtons.volumeUp.top,height:e.hardwareButtons.volumeUp.height,width:e.hardwareButtons.width},{side:"left",top:e.hardwareButtons.volumeDown.top,height:e.hardwareButtons.volumeDown.height,width:e.hardwareButtons.width}];return{model:r,renderScale:t,outerWidth:Math.round(p*t),outerHeight:Math.round(g*t),logicalOuterWidth:p,logicalOuterHeight:g,logicalFrameWidth:a,logicalFrameHeight:s,logicalFrameLeft:l,logicalFrameTop:u,logicalScreenWidth:i,logicalScreenHeight:o,logicalScreenLeft:I,logicalScreenTop:m,logicalScreenRadius:n?0:e.cornerRadius,logicalFrameRadius:P,frameBackground:n?"linear-gradient(180deg, #1b1c20 0%, #0f1012 42%, #050608 100%)":"#000000",frameOutline:n?"0 0 0 1px #1f2125":"0 0 0 1px #333",metallicRingShadow:n?null:$t,buttons:k,legacyHomeButton:n?{top:111+e.height+47/2,left:e.width/2-64/2+29,size:64,ring:1.5}:null,showHomeIndicator:e.homeIndicatorHeight>0,logicalHomeIndicatorStripHeight:e.homeIndicatorHeight}}function kt(r){let e=r.side==="right",t=e?"inset(-3px -3px -3px 0)":"inset(-3px 0 -3px -3px)";return`
|
|
3
3
|
<div
|
|
4
4
|
aria-hidden="true"
|
|
5
5
|
style="
|
|
@@ -24,7 +24,7 @@ import{a as rt}from"./chunk-J2JAOIMN.js";import{a as me,c as ge,d as we,e as et,
|
|
|
24
24
|
z-index:2;
|
|
25
25
|
"
|
|
26
26
|
></div>
|
|
27
|
-
`}function
|
|
27
|
+
`}function At(r,e){let t=r.buttons.map(kt).join(""),n=r.metallicRingShadow?`
|
|
28
28
|
<div
|
|
29
29
|
aria-hidden="true"
|
|
30
30
|
style="
|
|
@@ -177,7 +177,7 @@ import{a as rt}from"./chunk-J2JAOIMN.js";import{a as me,c as ge,d as we,e as et,
|
|
|
177
177
|
</div>
|
|
178
178
|
</div>
|
|
179
179
|
</body>
|
|
180
|
-
</html>`}async function
|
|
180
|
+
</html>`}async function lt(r,e){let{chromium:t}=await import("playwright"),n=await it(i=>t.launch(i),{headless:!0});try{let i=await Mt(n);try{return await i.compose(r,e)}finally{await i.close()}}finally{await n.close()}}async function Mt(r){let e=new Map;async function t(n){let i=e.get(n);if(i)return i;let o=Pt(n),a=await r.newContext({viewport:{width:o.outerWidth,height:o.outerHeight},deviceScaleFactor:1}),s=await a.newPage(),l={layout:o,context:a,page:s};return e.set(n,l),l}return{async compose(n,i){let o=await t(i),a=`data:image/png;base64,${n.toString("base64")}`;return await o.page.setContent(At(o.layout,a),{waitUntil:"load"}),await o.page.waitForTimeout(20),await o.page.screenshot({type:"png",clip:{x:0,y:0,width:o.layout.outerWidth,height:o.layout.outerHeight},omitBackground:!0})},async close(){for(let n of e.values())await n.context.close();e.clear()}}}import{spawnSync as Rt}from"child_process";import*as C from"vm";var Ot=3e5,_t=`
|
|
181
181
|
let input = '';
|
|
182
182
|
process.stdin.on('data', (c) => { input += c });
|
|
183
183
|
process.stdin.on('end', async () => {
|
|
@@ -199,7 +199,7 @@ process.stdin.on('end', async () => {
|
|
|
199
199
|
process.exitCode = 1;
|
|
200
200
|
}
|
|
201
201
|
});
|
|
202
|
-
`;function G(r,e,t){if(t?.multipartForm)throw new Error("http: multipartForm is not supported by sootsim yet");let n={...process.env};for(let s of Object.keys(n))(s.startsWith("BUN_INSPECT")||s==="NODE_OPTIONS")&&delete n[s];let i=
|
|
202
|
+
`;function G(r,e,t){if(t?.multipartForm)throw new Error("http: multipartForm is not supported by sootsim yet");let n={...process.env};for(let s of Object.keys(n))(s.startsWith("BUN_INSPECT")||s==="NODE_OPTIONS")&&delete n[s];let i=Rt(process.execPath,["-e",_t],{input:JSON.stringify({url:r,method:e,headers:t?.headers,body:t?.body}),encoding:"utf8",timeout:Ot,maxBuffer:64*1024*1024,env:n});if(i.error)throw new Error(`http ${e} ${r} failed: ${i.error.message}`);let o;try{o=JSON.parse(i.stdout||"")}catch{throw new Error(`http ${e} ${r} failed: no response (${(i.stderr||"").trim().slice(0,200)})`)}let a=o;if(a.__error)throw new Error(`http ${e} ${r} failed: ${a.__error}`);return a}var Dt=/(?<!\\)\$\{([^$]*)\}/g,Bt=/\\(\$\{[^$]*\})/g,Lt=/^[A-Za-z_$][A-Za-z0-9_$]*$/,X=class{context;envBinding=new Map;envScopeStack=[];syncedEnvKeys=new Set;output={};maestro;constructor(e={}){this.maestro={copiedText:null,platform:e.platform??"ios"};let t=e.onLog??(i=>console.log(`[flow] js: ${i}`)),n={output:this.output,maestro:this.maestro,http:{get:(i,o)=>G(i,"GET",o),post:(i,o)=>G(i,"POST",o),put:(i,o)=>G(i,"PUT",o),delete:(i,o)=>G(i,"DELETE",o),request:(i,o)=>G(i,(o?.method??"GET").toUpperCase(),o)},console:{log:(...i)=>t(i.map(o=>typeof o=="string"?o:ct(o)).join(" "))}};this.context=C.createContext(n),C.runInContext(`
|
|
203
203
|
globalThis.__maestroScope = new Proxy(globalThis, {
|
|
204
204
|
has() { return true },
|
|
205
205
|
get(target, key) { return target[key] },
|
|
@@ -210,7 +210,7 @@ process.stdin.on('end', async () => {
|
|
|
210
210
|
var yPercent = Math.ceil(y * 100) + '%'
|
|
211
211
|
return xPercent + ',' + yPercent
|
|
212
212
|
}
|
|
213
|
-
`,this.context);for(let[i,o]of Object.entries(process.env))o!==void 0&&this.envBinding.set(i,o)}putEnv(e,t){this.envBinding.set(e,t)}setCopiedText(e){this.maestro.copiedText=e}enterEnvScope(){this.envScopeStack.push(new Map(this.envBinding))}leaveEnvScope(){let e=this.envScopeStack.pop();if(e){this.envBinding.clear();for(let[t,n]of e)this.envBinding.set(t,n)}}evaluate(e,t={}){let n=t.env;if(n&&Object.keys(n).length>0){this.enterEnvScope();try{for(let[i,o]of Object.entries(n))this.envBinding.set(i,o);return this.evalRaw(e)}finally{this.leaveEnvScope()}}return this.evalRaw(e)}evalRaw(e){this.syncEnvToContext();let t=e.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${");return C.runInContext(`(function(){ with(__maestroScope){ return eval(\`${t}\`) } })()`,this.context)}syncEnvToContext(){let e=C.runInContext("globalThis",this.context);for(let t of this.syncedEnvKeys)this.envBinding.has(t)||delete e[t];this.syncedEnvKeys=new Set;for(let[t,n]of this.envBinding)try{e[t]=n,this.syncedEnvKeys.add(t)}catch{}}evaluateStringTemplate(e){return e.replace(
|
|
213
|
+
`,this.context);for(let[i,o]of Object.entries(process.env))o!==void 0&&this.envBinding.set(i,o)}putEnv(e,t){this.envBinding.set(e,t)}setCopiedText(e){this.maestro.copiedText=e}enterEnvScope(){this.envScopeStack.push(new Map(this.envBinding))}leaveEnvScope(){let e=this.envScopeStack.pop();if(e){this.envBinding.clear();for(let[t,n]of e)this.envBinding.set(t,n)}}evaluate(e,t={}){let n=t.env;if(n&&Object.keys(n).length>0){this.enterEnvScope();try{for(let[i,o]of Object.entries(n))this.envBinding.set(i,o);return this.evalRaw(e)}finally{this.leaveEnvScope()}}return this.evalRaw(e)}evalRaw(e){this.syncEnvToContext();let t=e.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$\{/g,"\\${");return C.runInContext(`(function(){ with(__maestroScope){ return eval(\`${t}\`) } })()`,this.context)}syncEnvToContext(){let e=C.runInContext("globalThis",this.context);for(let t of this.syncedEnvKeys)this.envBinding.has(t)||delete e[t];this.syncedEnvKeys=new Set;for(let[t,n]of this.envBinding)try{e[t]=n,this.syncedEnvKeys.add(t)}catch{}}evaluateStringTemplate(e){return e.replace(Dt,(n,i)=>{if(i.trim().length===0)return"";let o=this.evaluate(i);if(o===void 0&&Lt.test(i.trim()))throw new Error(`missing variable for flow placeholder: ${i.trim()}`);return ct(o)}).replace(Bt,(n,i)=>i)}interpolateStep(e){return this.interpolateValue(e,null)}interpolateValue(e,t){return typeof e=="string"?t==="evalScript"?e:this.evaluateStringTemplate(e):Array.isArray(e)?t==="commands"||t==="onFlowStart"||t==="onFlowComplete"?e:e.map(n=>this.interpolateValue(n,t)):e&&typeof e=="object"?Object.fromEntries(Object.entries(e).map(([n,i])=>[n,this.interpolateValue(i,n)])):e}};function ct(r){if(r===void 0)return"undefined";if(r===null)return"null";if(typeof r=="object")try{return JSON.stringify(r)}catch{return String(r)}return String(r)}function dt(r){if(r==null)return!1;if(typeof r=="boolean")return r;let e=String(r);if(e.trim().length===0||e.toLowerCase()==="false"||e==="undefined"||e==="null")return!1;let t=Number(e);return!(!Number.isNaN(t)&&t===0)}var Q=1e4,Ct=Math.min(10,Math.max(1,Number(process.env.SOOTSIM_FLOW_TIMEOUT_SCALE)||1)),Ee=r=>Math.round(r*Ct),te=393,N=852;function f(r){return new Promise(e=>setTimeout(e,r))}function Ie(r){return!!(r&&typeof r=="object"&&!Array.isArray(r))}function z(r,e){if(!Ie(r))return null;let t=r[e];return typeof t=="string"&&t.length>0?t:null}function Nt(r,e){return Ie(r)?r[e]===!0:!1}function Ht(r){if(!r)return null;let e=r.recentApps;if(Array.isArray(e))for(let n of e){let i=z(n,"id");if(i)return i}let t=r.surfaceBindings;return z(t,"app:one")||z(t,"app:two")||null}function Ut(r){return r?b.basename(r)===".maestro"?b.dirname(r):r:process.cwd()}function Wt(r,e,t){let n=e.endsWith(".png")?e:`${e}.png`;if(b.isAbsolute(n))return n;if(t.mode==="flow"&&/[\\/]/.test(n)){let i=n.startsWith("./")||n.startsWith("../")?t.flowDir??process.cwd():Ut(t.flowDir);return b.resolve(i,n)}return b.join(r,n)}function jt(r){if(typeof r=="string")return{path:r,withFrame:!1};let e=r.path?.trim()||r.name?.trim();if(!e)throw new Error("takeScreenshot object form requires path or name");return{path:e,withFrame:r.withFrame===!0,layers:r.layers}}function ee(r,e){let[t,n]=r.split(",").map(s=>s.trim()),i=(s,l)=>s.endsWith("%")?Number.parseFloat(s)/100*l:Number.parseFloat(s),o=e?.x??0,a=e?.y??0;return{x:o+i(t,e?.width??te),y:a+i(n,e?.height??N)}}function ut(r){switch(r){case"back":return{back:!0};case"hideKeyboard":return{hideKeyboard:!0};case"waitForAnimationToEnd":return{waitForAnimationToEnd:!0};case"stopApp":return{stopApp:!0};case"clearState":return{clearState:!0};case"clearKeychain":return{clearKeychain:!0};case"eraseText":return{eraseText:50};case"scroll":case"scrollDown":return{scroll:{direction:"DOWN"}};case"scrollUp":return{scroll:{direction:"UP"}};default:return{[r]:!0}}}function Vt(r){let e=r.split(/^---$/m),t=e.length>1?e[e.length-1]:r,n=Qe.parse(t);return Array.isArray(n)?n:[]}var ne=class{constructor(e,t){this.bridge=e;this.opts=t}stepDelay=0;js=new X({platform:"ios",onLog:e=>console.log(`[flow] js: ${e}`)});firstLaunchDone=!1;profilingEnabled=!1;recordingEnabled=!1;recordingAccessChecked=!1;recordingStartedAtMs=null;lastRecordingStartedAtMs=null;lastRecordingDurationMs=null;lastRecordingFrameStats=null;flowTraceSteps=[];lastVisualSettledAtMs=0;simRouteHint=null;lastFailedStep=null;get simId(){return this.opts.simId}setSimRouteHint(e){this.simRouteHint=this.normalizeSimRoute(e)}normalizeSimRoute(e){if(!e)return null;try{let t=new URL(e);t.searchParams.delete("inspectOpen");let n=t.searchParams.toString();return`${t.origin}${t.pathname}${n?`?${n}`:""}`}catch{return e}}async refreshSimId(){if(this.opts.simId)try{let e=await this.bridge.listSims(),t=e.find(l=>l.id===this.opts.simId);if(t&&(this.simRouteHint=this.normalizeSimRoute(t.url||t.origin)),e.find(l=>l.id===this.opts.simId&&l.readyState==="open")||!this.simRouteHint)return;let i=this.simRouteHint&&e.find(l=>l.readyState==="open"&&this.normalizeSimRoute(l.url||l.origin)===this.simRouteHint);if(!i)return;let o=e.find(l=>l.isPrimary&&l.readyState==="open"),a=e.find(l=>l.readyState==="open"),s=i??o??a;s&&(this.opts.simId=s.id,console.log(` [flow] sim rotated to ${s.id}`))}catch{}}async evaluate(e,t){return this.bridge.send({type:"evaluate",simId:this.opts.simId,code:e},t?{timeoutMs:t}:void 0)}async callTest(e,...t){return this.bridge.send({type:"call",simId:this.opts.simId,path:`__sootsimTest.${e}`,args:t})}async waitForTree(e=Q){let t=Date.now()+Ee(e),n=Date.now(),i=null,o=0,a=0,s=-1,l=n;for(;Date.now()<t;){try{let p=await this.evaluate(We,8e3);if(o=0,p?.externalError)throw new Error(`app failed to load: ${p.externalError}`);if(p){let g=Date.now();p.nodes!==s&&(s=p.nodes,l=g);let I=p.flag===!0&&Ve(p),m=p.flag!==!0&&Je(p);if((I||m)&&p.externalReady!==!1&&!p.externalError&&!p.loadingText&&g-l>=je)return}}catch(p){if(i=p instanceof Error?p:new Error(String(p)),i.message.startsWith("app failed to load:"))throw i;if(o++,o>=4)throw new Error(`target sim is not responding to the bridge (${i.message}). it is likely a stale orphan \u2014 run \`sootsim list\`, then close it with \`sootsim close <id>\` or start a fresh one with \`sootsim open --new <port>\`.`);await this.refreshSimId()}let u=Date.now()-n;u-a>=5e3&&(a=u,console.log(` [flow] waiting for app to be ready\u2026 (${Math.round(u/1e3)}s)`)),await f(500)}throw i?.message.startsWith("app failed to load:")?i:new Error(`app not ready after ${e}ms`)}async ensureRecordingStarted(){if(!this.opts.recordingOutputDir)throw new Error("recording output directory not configured");this.recordingAccessChecked||(this.opts.requireRecordingEntitlement&&await ot("flow --video",{originOverride:this.opts.billingOriginOverride,allowGitHubAuth:this.opts.allowGitHubRecording}),this.recordingAccessChecked=!0);let e=Date.now(),t=await this.evaluate(`(() => {
|
|
214
214
|
const rec = window.__sootsimRecorder
|
|
215
215
|
if (!rec) return { ok: false, error: 'recorder unavailable on this page' }
|
|
216
216
|
const format = ${JSON.stringify(this.opts.recordingFormat??"webm")}
|
|
@@ -386,7 +386,7 @@ process.stdin.on('end', async () => {
|
|
|
386
386
|
visible: !!keyboard?.isVisible?.(),
|
|
387
387
|
focused: !!test?.isTextInputFocused?.(),
|
|
388
388
|
}
|
|
389
|
-
})()`);if(!t?.visible&&!t?.focused){await f(80);return}await f(80)}}async eraseText(e){for(let t=0;t<e;t++)await this.bridge.send({type:"keyboard",simId:this.opts.simId,action:"dispatchKey",text:"Backspace"});await f(100)}async waitFor(e){let t=Date.now()+Ee(e.timeout||Q);for(;Date.now()<t;){if(await this.findElement(e))return;await f(200)}let n=await this.findElement(e),i=n?` (matched node y=${Math.round(n.absolutePosition.y)} \u2014 still off-screen at deadline)`:"";throw new Error(`waitFor: ${JSON.stringify(e)} not found after ${e.timeout||Q}ms${i}`)}async takeScreenshot(e){if(!this.hasFreshVisualSettle())try{await this.waitForVisualSettle(),await f(250)}catch{}let t=
|
|
389
|
+
})()`);if(!t?.visible&&!t?.focused){await f(80);return}await f(80)}}async eraseText(e){for(let t=0;t<e;t++)await this.bridge.send({type:"keyboard",simId:this.opts.simId,action:"dispatchKey",text:"Backspace"});await f(100)}async waitFor(e){let t=Date.now()+Ee(e.timeout||Q);for(;Date.now()<t;){if(await this.findElement(e))return;await f(200)}let n=await this.findElement(e),i=n?` (matched node y=${Math.round(n.absolutePosition.y)} \u2014 still off-screen at deadline)`:"";throw new Error(`waitFor: ${JSON.stringify(e)} not found after ${e.timeout||Q}ms${i}`)}async takeScreenshot(e){if(!this.hasFreshVisualSettle())try{await this.waitForVisualSettle(),await f(250)}catch{}let t=jt(e),n=Wt(this.opts.screenshotDir,t.path,{mode:this.opts.screenshotPathMode??"dir",flowDir:this.opts.flowDir});S.mkdirSync(b.dirname(n),{recursive:!0});let i=t.layers??this.opts.screenshotLayers,o={type:"screenshot",simId:this.opts.simId};i&&i!=="full"&&(o.layers=i);let s=(await this.bridge.send(o)).replace(/^data:image\/png;base64,/,""),l=Buffer.from(s,"base64");if(t.withFrame){let u=await this.readCurrentDeviceModel();if(!u)throw new Error("could not read current device model for framed screenshot");let p=await lt(l,u);return S.writeFileSync(n,p),console.log(`[flow] screenshot: ${n} (frame: ${u})`),n}return S.writeFileSync(n,l),console.log(`[flow] screenshot: ${n}`),n}async readCurrentDeviceModel(){let e=await this.bridge.send({type:"call",simId:this.opts.simId,path:"SootSim.bridges.settings.get",args:[]}),t=e&&typeof e.deviceModel=="string"?e.deviceModel:null;return!t||!(t in Le)?null:t}async captureScreenshot(e){S.mkdirSync(b.dirname(e),{recursive:!0});let n=(await this.bridge.send({type:"screenshot",simId:this.opts.simId})).replace(/^data:image\/png;base64,/,"");S.writeFileSync(e,Buffer.from(n,"base64"))}async captureFailureBundle(e,t){S.mkdirSync(e,{recursive:!0});let n=(p,g)=>{try{S.writeFileSync(b.join(e,p),g)}catch{}},i=async p=>{try{return await this.bridge.send({type:"evaluate",simId:this.opts.simId,code:p})}catch{return null}},o=await i(`(async () => {
|
|
390
390
|
const out = {
|
|
391
391
|
simId: window.__sootsimBridge?.id ?? window.SootSim?.state?.simId ?? null,
|
|
392
392
|
url: location.href,
|
|
@@ -441,7 +441,7 @@ process.stdin.on('end', async () => {
|
|
|
441
441
|
${e.steps||12}, ${e.stepMs||16}
|
|
442
442
|
)
|
|
443
443
|
return { ok: !!ok, reason: ok ? null : 'pinch returned false' }
|
|
444
|
-
})()`);if(!t?.ok)throw new Error(`pinch failed: ${t?.reason||"unknown error"}`);await f(250)}async dumpTree(e=6){let t=await this.bridge.send({type:"tree",simId:this.opts.simId,depth:e});return console.log("[flow] tree:"),console.log(typeof t=="string"?t:JSON.stringify(t,null,2)),typeof t=="string"?t:JSON.stringify(t)}async assertTreeContains(e){if(!(await this.dumpTree(8)).includes(e))throw new Error(`assertTreeContains: "${e}" not in tree`)}async waitForAnimationToEnd(e=2e3){let t=Math.max(0,Math.round(e));if(t<=0)return;(await Se({bridge:this.bridge,simId:this.opts.simId,maxMs:t,pollMs:32,stablePolls:2,strict:!0})).settled&&this.markVisualSettled()}async back(){try{await this.tapOn("\u2039")}catch{await this.tapOn("<")}}async scrollUntilVisible(e){let t=Date.now()+(e.timeout||15e3),n=e.direction?.toUpperCase()||"DOWN",i=n==="DOWN"?"UP":n==="UP"?"DOWN":n;for(;Date.now()<t;){let o=await this.findElement({text:e.element});if(o&&o.absolutePosition.y>=0&&o.absolutePosition.y+o.layout.height>0&&o.absolutePosition.y<N-50){if(e.centerElement){let a=N/2,s=o.absolutePosition.y-a;if(Math.abs(s)>100){let l=Math.min(150,Math.abs(s)*.5),u=s>0?a-l:a+l;await this.drag(te/2,a,te/2,u,10,16)}}return}await this.swipe(i,250),await f(500)}throw new Error(`scrollUntilVisible: "${e.element}" not found`)}async extendedWaitUntil(e){let t=Date.now()+Ee(e.timeout||Q);for(;Date.now()<t;){let n=e.visible?await this.isElementVisible(typeof e.visible=="string"?{text:e.visible}:e.visible):!0,i=e.notVisible?!await this.isElementVisible(typeof e.notVisible=="string"?{text:e.notVisible}:e.notVisible):!0;if(n&&i)return;await f(200)}throw new Error("extendedWaitUntil timed out")}async reloadGuestApp(e){if(e){let i=!1;for(let o=0;o<3&&!i;o++)try{i=await this.evaluate(me(!0),2e4)}catch{await f(1e3)}i||console.warn(" warn: tenant storage clear did not ack \u2014 hard-reloading anyway (worker reset follows)")}await this.evaluate("window.location.reload()").catch(()=>{}),await f(500),await this.refreshSimId()}async softReloadGuestApp(e){if(!await this.evaluate(me(e),12e4))throw new Error("guest app soft reload bridge unavailable")}async rearmCaptureAfterRuntimeReload(){if(!this.recordingEnabled&&!this.profilingEnabled)return;let e=Date.now()+1e4,t=null;for(;Date.now()<e;){await this.refreshSimId();try{this.recordingEnabled&&await this.ensureRecordingStarted(),this.profilingEnabled&&await this.startProfile();return}catch(n){t=n,await f(250)}}throw new Error(`capture re-arm failed after app reload: ${t instanceof Error?t.message:String(t)}`)}async launchApp(e){await this.refreshSimId(),e&&typeof e=="object"&&e.arguments&&console.log("[flow] launchApp.arguments ignored (sootsim has no native process)");let t=!!(e&&typeof e=="object"&&e.clearState),n=
|
|
444
|
+
})()`);if(!t?.ok)throw new Error(`pinch failed: ${t?.reason||"unknown error"}`);await f(250)}async dumpTree(e=6){let t=await this.bridge.send({type:"tree",simId:this.opts.simId,depth:e});return console.log("[flow] tree:"),console.log(typeof t=="string"?t:JSON.stringify(t,null,2)),typeof t=="string"?t:JSON.stringify(t)}async assertTreeContains(e){if(!(await this.dumpTree(8)).includes(e))throw new Error(`assertTreeContains: "${e}" not in tree`)}async waitForAnimationToEnd(e=2e3){let t=Math.max(0,Math.round(e));if(t<=0)return;(await Se({bridge:this.bridge,simId:this.opts.simId,maxMs:t,pollMs:32,stablePolls:2,strict:!0})).settled&&this.markVisualSettled()}async back(){try{await this.tapOn("\u2039")}catch{await this.tapOn("<")}}async scrollUntilVisible(e){let t=Date.now()+(e.timeout||15e3),n=e.direction?.toUpperCase()||"DOWN",i=n==="DOWN"?"UP":n==="UP"?"DOWN":n;for(;Date.now()<t;){let o=await this.findElement({text:e.element});if(o&&o.absolutePosition.y>=0&&o.absolutePosition.y+o.layout.height>0&&o.absolutePosition.y<N-50){if(e.centerElement){let a=N/2,s=o.absolutePosition.y-a;if(Math.abs(s)>100){let l=Math.min(150,Math.abs(s)*.5),u=s>0?a-l:a+l;await this.drag(te/2,a,te/2,u,10,16)}}return}await this.swipe(i,250),await f(500)}throw new Error(`scrollUntilVisible: "${e.element}" not found`)}async extendedWaitUntil(e){let t=Date.now()+Ee(e.timeout||Q);for(;Date.now()<t;){let n=e.visible?await this.isElementVisible(typeof e.visible=="string"?{text:e.visible}:e.visible):!0,i=e.notVisible?!await this.isElementVisible(typeof e.notVisible=="string"?{text:e.notVisible}:e.notVisible):!0;if(n&&i)return;await f(200)}throw new Error("extendedWaitUntil timed out")}async reloadGuestApp(e){if(e){let i=!1;for(let o=0;o<3&&!i;o++)try{i=await this.evaluate(me(!0),2e4)}catch{await f(1e3)}i||console.warn(" warn: tenant storage clear did not ack \u2014 hard-reloading anyway (worker reset follows)")}await this.evaluate("window.location.reload()").catch(()=>{}),await f(500),await this.refreshSimId()}async softReloadGuestApp(e){if(!await this.evaluate(me(e),12e4))throw new Error("guest app soft reload bridge unavailable")}async rearmCaptureAfterRuntimeReload(){if(!this.recordingEnabled&&!this.profilingEnabled)return;let e=Date.now()+1e4,t=null;for(;Date.now()<e;){await this.refreshSimId();try{this.recordingEnabled&&await this.ensureRecordingStarted(),this.profilingEnabled&&await this.startProfile();return}catch(n){t=n,await f(250)}}throw new Error(`capture re-arm failed after app reload: ${t instanceof Error?t.message:String(t)}`)}async launchApp(e){await this.refreshSimId(),e&&typeof e=="object"&&e.arguments&&console.log("[flow] launchApp.arguments ignored (sootsim has no native process)");let t=!!(e&&typeof e=="object"&&e.clearState),n=Nt(e,"resetRuntime");if(!this.firstLaunchDone&&!t){if(this.firstLaunchDone=!0,n){let i=await J(this.bridge).catch(()=>null),o=i?.state==="home"&&i.activeApp==null;await this.softReloadGuestApp(!1),await this.waitForTree(12e4),o&&(await fe(this.bridge,"goHome",1e3),await this.waitForShellHome(1e3)),await this.launchShellAppFromHomeIfNeeded(e,o?{...i??{},state:"home",activeApp:null}:null)}else await this.launchShellAppFromHomeIfNeeded(e);await this.waitForTree(3e4)}else if(this.firstLaunchDone=!0,await this.reloadGuestApp(t),await this.waitForTree(12e4),this.opts.onAfterLaunch)try{await this.opts.onAfterLaunch()}catch(i){console.warn(` warn: onAfterLaunch hook threw: ${i instanceof Error?i.message:i}`)}this.profilingEnabled&&await this.startProfile(),this.recordingEnabled&&(await this.waitForVisualSettle(),await this.ensureRecordingStarted())}async waitForVisualSettle(){try{await this.evaluate(`new Promise((resolve) => {
|
|
445
445
|
requestAnimationFrame(() => {
|
|
446
446
|
requestAnimationFrame(() => {
|
|
447
447
|
requestAnimationFrame(() => {
|
|
@@ -449,7 +449,7 @@ process.stdin.on('end', async () => {
|
|
|
449
449
|
})
|
|
450
450
|
})
|
|
451
451
|
})
|
|
452
|
-
})`),this.markVisualSettled()}catch{await f(180),this.markVisualSettled()}}markVisualSettled(){this.lastVisualSettledAtMs=Date.now()}hasFreshVisualSettle(){return Date.now()-this.lastVisualSettledAtMs<750}resolveShellLaunchAppId(e,t){if(typeof e=="string"&&e.length>0)return e;if(Ie(e)){let n=z(e,"appId")||z(e,"id");if(n)return n}return
|
|
452
|
+
})`),this.markVisualSettled()}catch{await f(180),this.markVisualSettled()}}markVisualSettled(){this.lastVisualSettledAtMs=Date.now()}hasFreshVisualSettle(){return Date.now()-this.lastVisualSettledAtMs<750}resolveShellLaunchAppId(e,t){if(typeof e=="string"&&e.length>0)return e;if(Ie(e)){let n=z(e,"appId")||z(e,"id");if(n)return n}return Ht(t)||"connect"}async waitForShellAppLaunched(e,t){let n=Date.now()+t,i=null;for(;Date.now()<n;){try{i=await J(this.bridge)}catch{i=null}if(i?.state==="app"&&i.activeApp===e&&i.showSwitcher===!1&&typeof i.launchProgress=="number"&&i.launchProgress>=.98)return;await f(16)}}async waitForShellHome(e){let t=Date.now()+e;for(;Date.now()<t;){let n=await J(this.bridge).catch(()=>null);if(n?.state==="home"&&n.activeApp==null&&n.showSwitcher===!1)return;await f(16)}}async launchShellAppFromHomeIfNeeded(e,t){let n=null;if(t)n=t;else try{n=await J(this.bridge)}catch{return!1}if(n?.state!=="home"||n.activeApp!=null)return!1;let i=this.resolveShellLaunchAppId(e,n);return this.recordingEnabled&&await this.ensureRecordingStarted(),await fe(this.bridge,"launchApp",1e3,i),await this.waitForShellAppLaunched(i,1e3),!0}async startProfile(){let e=await this.evaluate(`(() => {
|
|
453
453
|
if (!window.__sootsimShellPerf) {
|
|
454
454
|
return { error: "shell frame profile unavailable (__sootsimShellPerf missing on the page)" }
|
|
455
455
|
}
|
|
@@ -460,7 +460,7 @@ process.stdin.on('end', async () => {
|
|
|
460
460
|
return { error: "shell frame profile unavailable (__sootsimShellPerf missing on the page)" }
|
|
461
461
|
}
|
|
462
462
|
return await window.__sootsimShellPerf.stop()
|
|
463
|
-
})()`);if(this.profilingEnabled=!1,e?.error)throw new Error(e.error);return e}async stopApp(){await this.reloadGuestApp(!1),await this.rearmCaptureAfterRuntimeReload()}async clearState(){await this.reloadGuestApp(!0),await this.rearmCaptureAfterRuntimeReload()}clearKeychain(){console.warn("[flow] clearKeychain: sootsim has no keychain surface \u2014 no-op (warning)")}async copyTextFrom(e){let t=typeof e=="string"?{id:e}:e,n=await this.findElement(t);if(!n)throw new Error(`copyTextFrom: element not found: ${JSON.stringify(t)}`);let i=n.text??n.testID??"";this.js.setCopiedText(i),this.js.putEnv("maestroCopiedText",i),console.log(`[flow] copied text: ${JSON.stringify(i)}`)}evalScript(e){let n=/(?<!\\)\$\{[^$]*\}/.test(e)?this.js.evaluateStringTemplate(e):this.js.evaluate(e);n!==void 0&&n!==""&&console.log("[flow] evalScript ->",n)}runScript(e){let t=typeof e=="string"?{file:e}:e;if(!t.file)throw new Error("runScript requires a file");let n=b.resolve(this.opts.flowDir,t.file),i=S.readFileSync(n,"utf8");this.js.evaluate(i,{env:t.env}),console.log(`[flow] runScript: ${t.file} done`)}async openLink(e){let t=typeof e=="string"?e:e.link;if(!t)throw new Error("openLink: missing link");let n=await this.callTest("openDeepLink",t);if(!n?.ok)throw new Error(`openLink failed: ${n?.error||"no test bridge"}`);await f(300)}async evaluateWhen(e){if(e.visible!==void 0){let t=typeof e.visible=="string"?{text:e.visible}:e.visible;return!!await this.findElement(t)}if(e.notVisible!==void 0){let t=typeof e.notVisible=="string"?{text:e.notVisible}:e.notVisible;return!await this.findElement(t)}return e.platform!==void 0?e.platform.toLowerCase()===this.js.maestro.platform.toLowerCase():e.true!==void 0?ct(e.true):!0}isOptional(e){if(e.optional===!0)return!0;let n=Object.entries(e).find(([o])=>o!=="when"&&o!=="optional"),i=n?n[1]:void 0;return!!(i&&typeof i=="object"&&"optional"in i&&i.optional)}async runStep(e,t){let n=typeof e=="string"?dt(e):e,i=Object.keys(n).find(l=>l!=="when")||Object.keys(n)[0];console.log(`[flow] step ${t+1}: ${i}`);let o=Date.now(),a=this.flowStepTargetLabel(n,i),s;try{s=this.js.interpolateStep(n),a=this.flowStepTargetLabel(s,i)??a}catch(l){if(this.isOptional(n)){console.log(`[flow] (optional, skipped: ${l.message.slice(0,80)})`),this.recordFlowTraceStep({stepIndex:t,stepName:i,targetLabel:a,startedAtMs:o,status:"skipped",error:l});return}throw this.lastFailedStep={index:t,kind:i,target:n[i]},this.recordFlowTraceStep({stepIndex:t,stepName:i,targetLabel:a,startedAtMs:o,status:"failure",error:l}),l}if(s.when&&!await this.evaluateWhen(s.when)){console.log("[flow] (when: predicate false, skipped)"),this.recordFlowTraceStep({stepIndex:t,stepName:i,targetLabel:a,startedAtMs:o,status:"skipped"});return}try{let l=!!(s.extendedWaitUntil||s.waitFor||s.scrollUntilVisible||s.launchApp||s.runFlow||s.runScript),u=1e4,p=this.runStepInner(s),g;if(l){let m=await p;typeof m=="string"&&(g=m)}else{let m=null,P=new Promise((k,re)=>{m=setTimeout(()=>{re(new Error(`step watchdog: ${i} made no progress in ${u}ms \u2014 bridge or bundle probably hung`))},u)});try{let k=await Promise.race([p,P]);typeof k=="string"&&(g=k)}finally{m&&clearTimeout(m)}}let I=!!(s.assertVisible||s.assertNotVisible||s.extendedWaitUntil||s.waitFor);this.stepDelay>0&&!I&&await f(this.stepDelay),this.recordFlowTraceStep({stepIndex:t,stepName:i,targetLabel:a,startedAtMs:o,status:"success",screenshotPath:g})}catch(l){if(this.isOptional(s)){console.log(`[flow] (optional, skipped: ${l.message.slice(0,80)})`),this.recordFlowTraceStep({stepIndex:t,stepName:i,targetLabel:a,startedAtMs:o,status:"skipped",error:l});return}throw this.lastFailedStep={index:t,kind:i,target:s[i]},this.recordFlowTraceStep({stepIndex:t,stepName:i,targetLabel:a,startedAtMs:o,status:"failure",error:l}),l}}async runStepInner(e){if(e.tapOn)await this.tapOn(e.tapOn);else if(e.longPressOn)await this.longPressOn(e.longPressOn);else if(e.scrollUntilVisible)await this.scrollUntilVisible(e.scrollUntilVisible);else if(e.extendedWaitUntil)await this.extendedWaitUntil(e.extendedWaitUntil);else if(e.assertVisible)await this.assertVisible(e.assertVisible);else if(e.assertNotVisible)await this.assertNotVisible(e.assertNotVisible);else if(e.inputText)await this.inputText(e.inputText);else if(e.pressKey)await this.pressKey(e.pressKey);else if(e.dispatchKey)await this.dispatchKey(e.dispatchKey);else if(e.waitFor)await this.waitFor(e.waitFor);else{if(e.takeScreenshot)return this.takeScreenshot(e.takeScreenshot);if(e.swipe)e.swipe.start&&e.swipe.end?await this.swipeCoords(e.swipe.start,e.swipe.end,e.swipe.duration):e.swipe.from?await this.swipeFrom(e.swipe.from,e.swipe.direction,e.swipe.duration):await this.swipe(e.swipe.direction,e.swipe.duration);else if(e.scroll)await this.swipe(e.scroll.direction==="DOWN"?"UP":"DOWN");else if(e.scrollTo){let t=typeof e.scrollTo.nodeId=="number"?{nodeId:e.scrollTo.nodeId}:e.scrollTo.id;if(!t)throw new Error("scrollTo requires id or nodeId");await this.scrollTo(t,e.scrollTo.x,e.scrollTo.y)}else if(e.pinch)await this.pinch(e.pinch);else if(e.waitForAnimationToEnd){let t=e.waitForAnimationToEnd;await this.waitForAnimationToEnd(typeof t=="number"?t:typeof t=="object"&&typeof t.timeout=="number"?t.timeout:2e3)}else if(e.back)await this.back();else if(e.hideKeyboard)await this.hideKeyboard();else if(e.launchApp)await this.launchApp(e.launchApp);else if(typeof e.wait=="number")await f(e.wait);else if(e.dumpTree)await this.dumpTree(e.dumpTree);else if(e.tapAtCoords)await this.tapAtCoords(e.tapAtCoords.x,e.tapAtCoords.y);else if(e.doubleTapAtCoords)await this.doubleTapAtCoords(e.doubleTapAtCoords.x,e.doubleTapAtCoords.y,e.doubleTapAtCoords.gapMs);else if(e.assertTreeContains)await this.assertTreeContains(e.assertTreeContains);else if(typeof e.eraseText=="number")await this.eraseText(e.eraseText);else if(e.repeat&&Array.isArray(e.repeat.commands)){let t=e.repeat.times,n=t==null||t===""?Number.MAX_SAFE_INTEGER:Number(t);if(!Number.isFinite(n))throw new Error(`repeat.times is not a number: ${t}`);let i=e.repeat.when??e.repeat.condition,o=async()=>i?this.evaluateWhen(i):!0,a=i?n:Math.min(n,1e3),s=0;for(;s<a&&await o();){for(let l=0;l<e.repeat.commands.length;l++)await this.runStep(e.repeat.commands[l],l);s++}}else if(e.stopApp!==void 0)await this.stopApp();else if(e.clearState!==void 0)await this.clearState();else if(e.clearKeychain!==void 0)this.clearKeychain();else if(e.copyTextFrom!==void 0)await this.copyTextFrom(e.copyTextFrom);else if(typeof e.evalScript=="string")this.evalScript(e.evalScript);else if(e.runScript){let t=e.runScript,n=typeof t=="string"?void 0:t.when;if(n&&!await this.evaluateWhen(n)){console.log("[flow] runScript skipped (when predicate false)");return}this.runScript(t)}else if(e.openLink!==void 0)await this.openLink(e.openLink);else if(e.runFlow){let t=e.runFlow,n=typeof t=="string"?t:t.file,i=typeof t=="string"?void 0:t.commands,o=typeof t=="string"?void 0:t.env,a=typeof t=="string"?void 0:t.when;if(a&&!await this.evaluateWhen(a)){console.log(`[flow] runFlow skipped (when predicate false): ${n??"inline commands"}`);return}if(!n&&!i)throw new Error("runFlow requires either file or commands");this.js.enterEnvScope();try{if(o)for(let[s,l]of Object.entries(o))this.js.putEnv(s,l);if(n){let s=b.resolve(this.opts.flowDir,n),l=S.readFileSync(s,"utf8"),u=this.opts.flowDir;this.opts.flowDir=b.dirname(s);try{await this.runFlow(jt(l))}finally{this.opts.flowDir=u}}else if(i)for(let s=0;s<i.length;s++)await this.runStep(i[s],s)}finally{this.js.leaveEnvScope()}}else throw new Error(`unsupported flow step: ${JSON.stringify(e)}`)}}liveStatus=null;async runFlow(e){let t=[],n=[],i=[];for(let a of e){let s=Object.keys(a);if(s.length===1&&s[0]==="onFlowStart"&&Array.isArray(a.onFlowStart)){t.push(...a.onFlowStart);continue}if(s.length===1&&s[0]==="onFlowComplete"&&Array.isArray(a.onFlowComplete)){n.push(...a.onFlowComplete);continue}i.push(a)}if(this.liveStatus&&await this.liveStatus.plan(i.map((a,s)=>{let l=typeof a=="string"?dt(a):a,u=Object.keys(l).find(p=>p!=="when")??Object.keys(l)[0];return{index:s,name:u,target:this.flowStepTargetLabel(l,u)}})),t.length>0){console.log(`[flow] onFlowStart (${t.length} steps)`);for(let a=0;a<t.length;a++)await this.runStep(t[a],a)}let o=null;try{await this.runFlowBody(i)}catch(a){o=a instanceof Error?a:new Error(String(a))}if(n.length>0){console.log(`[flow] onFlowComplete (${n.length} steps)`);for(let a=0;a<n.length;a++)try{await this.runStep(n[a],a)}catch(s){console.warn(`[flow] onFlowComplete step ${a+1} failed: ${s instanceof Error?s.message:s}`)}}if(o)throw o}async runFlowBody(e){for(let t=0;t<e.length;t++){let n=e[t],i=typeof n.wait=="number"?n.wait:0,o=typeof n.waitFor?.timeout=="number"?n.waitFor.timeout:0,a=Math.max(6e4,i+15e3,o+15e3);this.liveStatus&&(await this.liveStatus.waitWhilePaused(),await this.liveStatus.step(t,"running"));let s=Date.now(),l=async(u,p)=>{if(!this.liveStatus)return;let g=this.flowTraceSteps[this.flowTraceSteps.length-1],I=g&&g.stepIndex===t&&g.startedAtMs>=s;await this.liveStatus.step(t,u?"failure":I&&g.status==="skipped"?"skipped":"success",{durationMs:Date.now()-s,error:u?p instanceof Error?p.message.slice(0,300):String(p).slice(0,300):I&&g.error||void 0})};try{n.runFlow||n.launchApp?await this.runStep(n,t):await Promise.race([this.runStep(n,t),new Promise((u,p)=>setTimeout(()=>p(new Error(`step ${t+1} (${Object.keys(n)[0]}) exceeded ${a}ms deadline`)),a))])}catch(u){throw await l(!0,u),u}await l(!1)}}};function Vt(r){if(typeof r!="object"||r==null||!("control"in r))return!1;let e=r.control;return typeof e=="object"&&e!=null&&"paused"in e&&e.paused===!0}var ie=class{constructor(e,t,n){this.bridge=e;this.flowName=t;this.getSimId=n}disabled=!1;paused=!1;lastSimId;plannedSteps=null;completedSteps=new Map;runId=`flr_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`;async send(e,t){let n=await this.bridge.send({type:"flowStatus",simId:t,status:{runId:this.runId,flowName:this.flowName,...e}});this.paused=Vt(n)}async push(e){if(!this.disabled)try{let t=this.getSimId?.();if(t!==this.lastSimId&&this.lastSimId!=null&&this.plannedSteps&&e.phase!=="plan"){await this.send({phase:"plan",state:"running",steps:this.plannedSteps},t);for(let n of this.completedSteps.values())await this.send({phase:"step",state:"running",step:n},t)}this.lastSimId=t,await this.send(e,t)}catch(t){this.disabled=!0,console.log(`[flow] live status unavailable (${t instanceof Error?t.message.slice(0,120):t}) \u2014 continuing without the devtools rail`)}}async plan(e){this.plannedSteps=e.map(t=>({...t})),this.completedSteps.clear(),await this.push({phase:"plan",state:"running",steps:e})}async step(e,t,n){let i={index:e,status:t,...n};await this.push({phase:"step",state:"running",step:i}),this.completedSteps.set(e,i)}async end(e){await this.push({phase:"end",state:e})}async waitWhilePaused(){if(!this.disabled)for(;this.paused;){for(console.log("[flow] paused from devtools \u2014 waiting\u2026");this.paused&&!this.disabled;)await new Promise(e=>setTimeout(e,400)),await this.push({phase:"heartbeat",state:"paused"});this.disabled||console.log("[flow] resumed")}}};var Fe=null;function Cn(){return Fe}var $e=[];function Nn(){return $e}async function zt(r){if(!r)return"";let e=r.trim();if(!e)return"";if(/^\d+$/.test(e)||e.startsWith("http://")||e.startsWith("https://"))return e;let n=(await He()).find(i=>i.name.toLowerCase()===e.toLowerCase());return n?String(n.preferredPort):e}async function Kt(){let r=await Ue(),e=r.find(n=>n.patched);if(e)return`http://localhost:${e.port}/__soot/`;let t=r[0];return t?`http://localhost:${t.port}/__soot/`:null}async function pt(r){Fe=null,$e=[],(r.length===0||r.includes("--help")||r.includes("-h"))&&(console.log(`
|
|
463
|
+
})()`);if(this.profilingEnabled=!1,e?.error)throw new Error(e.error);return e}async stopApp(){await this.reloadGuestApp(!1),await this.rearmCaptureAfterRuntimeReload()}async clearState(){await this.reloadGuestApp(!0),await this.rearmCaptureAfterRuntimeReload()}clearKeychain(){console.warn("[flow] clearKeychain: sootsim has no keychain surface \u2014 no-op (warning)")}async copyTextFrom(e){let t=typeof e=="string"?{id:e}:e,n=await this.findElement(t);if(!n)throw new Error(`copyTextFrom: element not found: ${JSON.stringify(t)}`);let i=n.text??n.testID??"";this.js.setCopiedText(i),this.js.putEnv("maestroCopiedText",i),console.log(`[flow] copied text: ${JSON.stringify(i)}`)}evalScript(e){let n=/(?<!\\)\$\{[^$]*\}/.test(e)?this.js.evaluateStringTemplate(e):this.js.evaluate(e);n!==void 0&&n!==""&&console.log("[flow] evalScript ->",n)}runScript(e){let t=typeof e=="string"?{file:e}:e;if(!t.file)throw new Error("runScript requires a file");let n=b.resolve(this.opts.flowDir,t.file),i=S.readFileSync(n,"utf8");this.js.evaluate(i,{env:t.env}),console.log(`[flow] runScript: ${t.file} done`)}async openLink(e){let t=typeof e=="string"?e:e.link;if(!t)throw new Error("openLink: missing link");let n=await this.callTest("openDeepLink",t);if(!n?.ok)throw new Error(`openLink failed: ${n?.error||"no test bridge"}`);await f(300)}async evaluateWhen(e){if(e.visible!==void 0){let t=typeof e.visible=="string"?{text:e.visible}:e.visible;return!!await this.findElement(t)}if(e.notVisible!==void 0){let t=typeof e.notVisible=="string"?{text:e.notVisible}:e.notVisible;return!await this.findElement(t)}return e.platform!==void 0?e.platform.toLowerCase()===this.js.maestro.platform.toLowerCase():e.true!==void 0?dt(e.true):!0}isOptional(e){if(e.optional===!0)return!0;let n=Object.entries(e).find(([o])=>o!=="when"&&o!=="optional"),i=n?n[1]:void 0;return!!(i&&typeof i=="object"&&"optional"in i&&i.optional)}async runStep(e,t){let n=typeof e=="string"?ut(e):e,i=Object.keys(n).find(l=>l!=="when")||Object.keys(n)[0];console.log(`[flow] step ${t+1}: ${i}`);let o=Date.now(),a=this.flowStepTargetLabel(n,i),s;try{s=this.js.interpolateStep(n),a=this.flowStepTargetLabel(s,i)??a}catch(l){if(this.isOptional(n)){console.log(`[flow] (optional, skipped: ${l.message.slice(0,80)})`),this.recordFlowTraceStep({stepIndex:t,stepName:i,targetLabel:a,startedAtMs:o,status:"skipped",error:l});return}throw this.lastFailedStep={index:t,kind:i,target:n[i]},this.recordFlowTraceStep({stepIndex:t,stepName:i,targetLabel:a,startedAtMs:o,status:"failure",error:l}),l}if(s.when&&!await this.evaluateWhen(s.when)){console.log("[flow] (when: predicate false, skipped)"),this.recordFlowTraceStep({stepIndex:t,stepName:i,targetLabel:a,startedAtMs:o,status:"skipped"});return}try{let l=!!(s.extendedWaitUntil||s.waitFor||s.scrollUntilVisible||s.launchApp||s.runFlow||s.runScript),u=1e4,p=this.runStepInner(s),g;if(l){let m=await p;typeof m=="string"&&(g=m)}else{let m=null,P=new Promise((k,re)=>{m=setTimeout(()=>{re(new Error(`step watchdog: ${i} made no progress in ${u}ms \u2014 bridge or bundle probably hung`))},u)});try{let k=await Promise.race([p,P]);typeof k=="string"&&(g=k)}finally{m&&clearTimeout(m)}}let I=!!(s.assertVisible||s.assertNotVisible||s.extendedWaitUntil||s.waitFor);this.stepDelay>0&&!I&&await f(this.stepDelay),this.recordFlowTraceStep({stepIndex:t,stepName:i,targetLabel:a,startedAtMs:o,status:"success",screenshotPath:g})}catch(l){if(this.isOptional(s)){console.log(`[flow] (optional, skipped: ${l.message.slice(0,80)})`),this.recordFlowTraceStep({stepIndex:t,stepName:i,targetLabel:a,startedAtMs:o,status:"skipped",error:l});return}throw this.lastFailedStep={index:t,kind:i,target:s[i]},this.recordFlowTraceStep({stepIndex:t,stepName:i,targetLabel:a,startedAtMs:o,status:"failure",error:l}),l}}async runStepInner(e){if(e.tapOn)await this.tapOn(e.tapOn);else if(e.longPressOn)await this.longPressOn(e.longPressOn);else if(e.scrollUntilVisible)await this.scrollUntilVisible(e.scrollUntilVisible);else if(e.extendedWaitUntil)await this.extendedWaitUntil(e.extendedWaitUntil);else if(e.assertVisible)await this.assertVisible(e.assertVisible);else if(e.assertNotVisible)await this.assertNotVisible(e.assertNotVisible);else if(e.inputText)await this.inputText(e.inputText);else if(e.pressKey)await this.pressKey(e.pressKey);else if(e.dispatchKey)await this.dispatchKey(e.dispatchKey);else if(e.waitFor)await this.waitFor(e.waitFor);else{if(e.takeScreenshot)return this.takeScreenshot(e.takeScreenshot);if(e.swipe)e.swipe.start&&e.swipe.end?await this.swipeCoords(e.swipe.start,e.swipe.end,e.swipe.duration):e.swipe.from?await this.swipeFrom(e.swipe.from,e.swipe.direction,e.swipe.duration):await this.swipe(e.swipe.direction,e.swipe.duration);else if(e.scroll)await this.swipe(e.scroll.direction==="DOWN"?"UP":"DOWN");else if(e.scrollTo){let t=typeof e.scrollTo.nodeId=="number"?{nodeId:e.scrollTo.nodeId}:e.scrollTo.id;if(!t)throw new Error("scrollTo requires id or nodeId");await this.scrollTo(t,e.scrollTo.x,e.scrollTo.y)}else if(e.pinch)await this.pinch(e.pinch);else if(e.waitForAnimationToEnd){let t=e.waitForAnimationToEnd;await this.waitForAnimationToEnd(typeof t=="number"?t:typeof t=="object"&&typeof t.timeout=="number"?t.timeout:2e3)}else if(e.back)await this.back();else if(e.hideKeyboard)await this.hideKeyboard();else if(e.launchApp)await this.launchApp(e.launchApp);else if(typeof e.wait=="number")await f(e.wait);else if(e.dumpTree)await this.dumpTree(e.dumpTree);else if(e.tapAtCoords)await this.tapAtCoords(e.tapAtCoords.x,e.tapAtCoords.y);else if(e.doubleTapAtCoords)await this.doubleTapAtCoords(e.doubleTapAtCoords.x,e.doubleTapAtCoords.y,e.doubleTapAtCoords.gapMs);else if(e.assertTreeContains)await this.assertTreeContains(e.assertTreeContains);else if(typeof e.eraseText=="number")await this.eraseText(e.eraseText);else if(e.repeat&&Array.isArray(e.repeat.commands)){let t=e.repeat.times,n=t==null||t===""?Number.MAX_SAFE_INTEGER:Number(t);if(!Number.isFinite(n))throw new Error(`repeat.times is not a number: ${t}`);let i=e.repeat.when??e.repeat.condition,o=async()=>i?this.evaluateWhen(i):!0,a=i?n:Math.min(n,1e3),s=0;for(;s<a&&await o();){for(let l=0;l<e.repeat.commands.length;l++)await this.runStep(e.repeat.commands[l],l);s++}}else if(e.stopApp!==void 0)await this.stopApp();else if(e.clearState!==void 0)await this.clearState();else if(e.clearKeychain!==void 0)this.clearKeychain();else if(e.copyTextFrom!==void 0)await this.copyTextFrom(e.copyTextFrom);else if(typeof e.evalScript=="string")this.evalScript(e.evalScript);else if(e.runScript){let t=e.runScript,n=typeof t=="string"?void 0:t.when;if(n&&!await this.evaluateWhen(n)){console.log("[flow] runScript skipped (when predicate false)");return}this.runScript(t)}else if(e.openLink!==void 0)await this.openLink(e.openLink);else if(e.runFlow){let t=e.runFlow,n=typeof t=="string"?t:t.file,i=typeof t=="string"?void 0:t.commands,o=typeof t=="string"?void 0:t.env,a=typeof t=="string"?void 0:t.when;if(a&&!await this.evaluateWhen(a)){console.log(`[flow] runFlow skipped (when predicate false): ${n??"inline commands"}`);return}if(!n&&!i)throw new Error("runFlow requires either file or commands");this.js.enterEnvScope();try{if(o)for(let[s,l]of Object.entries(o))this.js.putEnv(s,l);if(n){let s=b.resolve(this.opts.flowDir,n),l=S.readFileSync(s,"utf8"),u=this.opts.flowDir;this.opts.flowDir=b.dirname(s);try{await this.runFlow(Vt(l))}finally{this.opts.flowDir=u}}else if(i)for(let s=0;s<i.length;s++)await this.runStep(i[s],s)}finally{this.js.leaveEnvScope()}}else throw new Error(`unsupported flow step: ${JSON.stringify(e)}`)}}liveStatus=null;async runFlow(e){let t=[],n=[],i=[];for(let a of e){let s=Object.keys(a);if(s.length===1&&s[0]==="onFlowStart"&&Array.isArray(a.onFlowStart)){t.push(...a.onFlowStart);continue}if(s.length===1&&s[0]==="onFlowComplete"&&Array.isArray(a.onFlowComplete)){n.push(...a.onFlowComplete);continue}i.push(a)}if(this.liveStatus&&await this.liveStatus.plan(i.map((a,s)=>{let l=typeof a=="string"?ut(a):a,u=Object.keys(l).find(p=>p!=="when")??Object.keys(l)[0];return{index:s,name:u,target:this.flowStepTargetLabel(l,u)}})),t.length>0){console.log(`[flow] onFlowStart (${t.length} steps)`);for(let a=0;a<t.length;a++)await this.runStep(t[a],a)}let o=null;try{await this.runFlowBody(i)}catch(a){o=a instanceof Error?a:new Error(String(a))}if(n.length>0){console.log(`[flow] onFlowComplete (${n.length} steps)`);for(let a=0;a<n.length;a++)try{await this.runStep(n[a],a)}catch(s){console.warn(`[flow] onFlowComplete step ${a+1} failed: ${s instanceof Error?s.message:s}`)}}if(o)throw o}async runFlowBody(e){for(let t=0;t<e.length;t++){let n=e[t],i=typeof n.wait=="number"?n.wait:0,o=typeof n.waitFor?.timeout=="number"?n.waitFor.timeout:0,a=Math.max(6e4,i+15e3,o+15e3);this.liveStatus&&(await this.liveStatus.waitWhilePaused(),await this.liveStatus.step(t,"running"));let s=Date.now(),l=async(u,p)=>{if(!this.liveStatus)return;let g=this.flowTraceSteps[this.flowTraceSteps.length-1],I=g&&g.stepIndex===t&&g.startedAtMs>=s;await this.liveStatus.step(t,u?"failure":I&&g.status==="skipped"?"skipped":"success",{durationMs:Date.now()-s,error:u?p instanceof Error?p.message.slice(0,300):String(p).slice(0,300):I&&g.error||void 0})};try{n.runFlow||n.launchApp?await this.runStep(n,t):await Promise.race([this.runStep(n,t),new Promise((u,p)=>setTimeout(()=>p(new Error(`step ${t+1} (${Object.keys(n)[0]}) exceeded ${a}ms deadline`)),a))])}catch(u){throw await l(!0,u),u}await l(!1)}}};function Jt(r){if(typeof r!="object"||r==null||!("control"in r))return!1;let e=r.control;return typeof e=="object"&&e!=null&&"paused"in e&&e.paused===!0}var ie=class{constructor(e,t,n){this.bridge=e;this.flowName=t;this.getSimId=n}disabled=!1;paused=!1;lastSimId;plannedSteps=null;completedSteps=new Map;runId=`flr_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`;async send(e,t){let n=await this.bridge.send({type:"flowStatus",simId:t,status:{runId:this.runId,flowName:this.flowName,...e}});this.paused=Jt(n)}async push(e){if(!this.disabled)try{let t=this.getSimId?.();if(t!==this.lastSimId&&this.lastSimId!=null&&this.plannedSteps&&e.phase!=="plan"){await this.send({phase:"plan",state:"running",steps:this.plannedSteps},t);for(let n of this.completedSteps.values())await this.send({phase:"step",state:"running",step:n},t)}this.lastSimId=t,await this.send(e,t)}catch(t){this.disabled=!0,console.log(`[flow] live status unavailable (${t instanceof Error?t.message.slice(0,120):t}) \u2014 continuing without the devtools rail`)}}async plan(e){this.plannedSteps=e.map(t=>({...t})),this.completedSteps.clear(),await this.push({phase:"plan",state:"running",steps:e})}async step(e,t,n){let i={index:e,status:t,...n};await this.push({phase:"step",state:"running",step:i}),this.completedSteps.set(e,i)}async end(e){await this.push({phase:"end",state:e})}async waitWhilePaused(){if(!this.disabled)for(;this.paused;){for(console.log("[flow] paused from devtools \u2014 waiting\u2026");this.paused&&!this.disabled;)await new Promise(e=>setTimeout(e,400)),await this.push({phase:"heartbeat",state:"paused"});this.disabled||console.log("[flow] resumed")}}};var Fe=null;function Hn(){return Fe}var $e=[];function Un(){return $e}async function Kt(r){if(!r)return"";let e=r.trim();if(!e)return"";if(/^\d+$/.test(e)||e.startsWith("http://")||e.startsWith("https://"))return e;let n=(await He()).find(i=>i.name.toLowerCase()===e.toLowerCase());return n?String(n.preferredPort):e}async function qt(){let r=await Ue(),e=r.find(n=>n.patched);if(e)return`http://localhost:${e.port}/__soot/`;let t=r[0];return t?`http://localhost:${t.port}/__soot/`:null}async function ht(r){Fe=null,$e=[],(r.length===0||r.includes("--help")||r.includes("-h"))&&(console.log(`
|
|
464
464
|
sootsim maestro \u2014 author and run Maestro YAML flows
|
|
465
465
|
|
|
466
466
|
usage:
|
|
@@ -540,28 +540,28 @@ flow extension:
|
|
|
540
540
|
takeScreenshot:
|
|
541
541
|
path: marketing/hero
|
|
542
542
|
withFrame: true
|
|
543
|
-
`),process.exit(0));let e=r[0];$.existsSync(e)||(console.error(` error: ${e} not found`),process.exit(1));let t=h=>r.find((c,y)=>r[y-1]===h),n=r.includes("--profile"),i=r.includes("--headed"),o=r.includes("--new")||i,a=t("--out")||"/tmp/sootsim-recordings",s=t("--screenshots")||(t("--out")?a:"/tmp/sootsim-flow"),l=t("--screenshot-paths")==="flow"?"flow":"dir",u=r.includes("--no-shell")?"tenant":r.includes("--shell-only")?"shell":void 0,p=t("--device")?.trim()||"",g=r.includes("--slow")?+(t("--slow")||"500"):0,I=r.includes("--electron"),m=r.includes("--preview"),P=await
|
|
543
|
+
`),process.exit(0));let e=r[0];$.existsSync(e)||(console.error(` error: ${e} not found`),process.exit(1));let t=h=>r.find((c,y)=>r[y-1]===h),n=r.includes("--profile"),i=r.includes("--headed"),o=r.includes("--new")||i,a=t("--out")||"/tmp/sootsim-recordings",s=t("--screenshots")||(t("--out")?a:"/tmp/sootsim-flow"),l=t("--screenshot-paths")==="flow"?"flow":"dir",u=r.includes("--no-shell")?"tenant":r.includes("--shell-only")?"shell":void 0,p=t("--device")?.trim()||"",g=r.includes("--slow")?+(t("--slow")||"500"):0,I=r.includes("--electron"),m=r.includes("--preview"),P=await rt(t("--preview-origin")),k=t("--preview-public-origin"),re=r.includes("--preview-open"),Pe=t("--owner")?.trim()||"",ke=t("--repo")?.trim()||"",H=t("--billing-kind")?.trim()||"",ft=m?`maestro:${process.env.GITHUB_RUN_ID?`github:${process.env.GITHUB_RUN_ID}:attempt:${process.env.GITHUB_RUN_ATTEMPT||"1"}:job:${process.env.GITHUB_JOB||"preview"}`:`local:${zt()}`}:flow:${Gt("sha256").update(w.relative(process.cwd(),w.resolve(e))).digest("hex").slice(0,16)}`:"";H&&H!=="test_run"&&(console.error(` error: invalid --billing-kind: ${H}`),process.exit(1));let mt=r.flatMap((h,c)=>r[c-1]==="--replace"?["--replace",h]:[]),gt=r.flatMap((h,c)=>r[c-1]==="--remap"?["--remap",h]:[]),M=r.includes("--record")||m,wt=r.includes("--tail-wait")?Math.max(0,+(t("--tail-wait")||"2000")):M?m?6e3:2e3:0,yt=$.readFileSync(e,"utf8"),{frontmatter:x,steps:R}=ge(yt);R.length===0&&(console.error(" error: flow file must contain a YAML array of steps"),process.exit(1));let U=p||x.device||"",Ae=x.theme||"",q=I||x.electron===!0,bt=x.app===void 0||x.app===null?"":typeof x.app=="number"?String(x.app):x.app,oe=await Kt(bt),Me={stripBooleanFlags:["--record","--profile","--electron","--new","--preview","--preview-open","--headless","--headed"],stripValueFlags:["--out","--device","--slow","--tail-wait","--url","--replace","--remap","--screenshots","--screenshot-paths","--preview-origin","--preview-public-origin","--driver","--billing-kind","--owner","--repo"]},v=pe(r,Me),St=t("--url")||"";q&&!Ke()&&(console.error(" error: desktop companion not found. install or build it first with `bun run build:electron`"),process.exit(1));let Re=q?"desktop companion":"bridge",vt=oe?` | target: ${oe}`:"";console.log(`
|
|
544
544
|
sootsim maestro \u2014 ${w.basename(e)}
|
|
545
|
-
${R.length} steps | ${Re}${
|
|
546
|
-
`),m&&Be({event:"preview_flow_started",properties:{flowName:w.basename(e),stepCount:R.length,mode:Re,electron:q,record:M,profile:n,previewOrigin:P}});let A=
|
|
545
|
+
${R.length} steps | ${Re}${vt}${M?" | recording":""}${n?" | profiling":""}${g?` | ${g}ms delay`:""}
|
|
546
|
+
`),m&&Be({event:"preview_flow_started",properties:{flowName:w.basename(e),stepCount:R.length,mode:Re,electron:q,record:M,profile:n,previewOrigin:P}});let A=St||oe||"",se=o||q&&v.simIdSource!=="flag",Oe=t("--driver")||"",ae=!1,le=new Set,_e=!1;if(!A&&!se&&v.simIdSource==="none"){let h=Ge(v);try{let c=await h.listSims(),y=c.find(D=>D.isPrimary&&D.readyState==="open"),F=c.find(D=>D.readyState==="open"),V=y??F;V&&(_e=!0,console.log(` reusing active sim: ${V.id}`))}catch{}finally{h.close()}}if(!A&&!_e&&(se||v.simIdSource==="none")){let h=await qt();h||(console.error(" error: no current sim and no sootsim target found"),await de(),process.exit(1)),A=h}if(A&&U){let h=new URL(await qe(A));h.searchParams.set("device",U),A=h.toString()}if(A){let h=[A];if(h.push(...mt),h.push(...gt),se&&h.push("--new"),h.push("--no-describe"),v.simIdSource==="flag"&&v.simId&&h.push("--sim",v.simId),Oe&&(h.push("--driver",Oe),ae=!0),r.includes("--headless")&&!i&&h.push("--headless"),await Ze(h,{port:v.wsPort,timeoutMs:v.commandTimeoutMs}),ae){let c=ue();c&&le.add(c)}}let B=pe(r,Me),Y=B.simIdSource==="flag"?B.simId:ue()||B.simId,xt=B.simIdSource==="flag"?"flag":Y?"saved":"none",T=he(B.wsPort,{commandTimeoutMs:B.commandTimeoutMs,simId:Y,simIdSource:xt}),d,De=async()=>{if(Ae&&await T.send({type:"call",simId:d.simId,path:"SootSim.bridges.settings.set",args:["colorScheme",Ae]}),!U)return!1;let h=await T.send({type:"evaluate",simId:d.simId,code:"window.location.href"});if(typeof h=="string"&&h.length>0){let c=new URL(h);c.searchParams.set("device",U),d.setSimRouteHint(c.toString())}return!!await T.send({type:"call",simId:d.simId,path:"SootSim.bridges.settings.set",args:["deviceModel",U]})};if(d=new ne(T,{screenshotDir:s,flowDir:w.dirname(w.resolve(e)),screenshotPathMode:l,screenshotLayers:u,simId:Y,recordingOutputDir:M?a:void 0,recordingFormat:m?"mp4":"webm",billingOriginOverride:m?P:void 0,allowGitHubRecording:m,requireRecordingEntitlement:m,onAfterLaunch:async()=>{await De()&&await d.waitForTree(12e4),m&&await T.send({type:"evaluate",simId:d.simId,code:`(() => {
|
|
547
547
|
const r = window.SootSim?.bridges?.eventRecorder ?? window.__sootsimEventRecorder
|
|
548
548
|
return r?.start?.() ?? false
|
|
549
549
|
})()`})}}),g&&(d.stepDelay=g),d.liveStatus=new ie(T,w.basename(e),()=>d.simId),d.js.putEnv("MAESTRO_FILENAME",w.basename(e,w.extname(e))),x.env&&typeof x.env=="object")for(let[h,c]of Object.entries(x.env))d.js.putEnv(h,c);let O=null,E=null,L=null,_=null,W=null,ce=null,j=0,Z=!!R[0]?.launchApp;try{Z||await d.waitForTree(12e4),await De()&&!Z&&await d.waitForTree(12e4),m&&!Z&&!process.env.SOOTSIM_PREVIEW_RESET_DONE&&await d.launchApp({clearState:!0}),M&&(Z?d.prepareRecording():await d.startRecording()),n&&await d.startProfile(),m&&(await T.send({type:"evaluate",simId:d.simId,code:`(() => {
|
|
550
550
|
const r = window.SootSim?.bridges?.eventRecorder ?? window.__sootsimEventRecorder
|
|
551
551
|
return r?.start?.() ?? false
|
|
552
|
-
})()`})||console.warn(" warn: eventRecorder.start() returned false \u2014 preview will upload bundle without replay events")),await d.runFlow(R),n&&(O=await d.stopProfile()),await d.waitForRecordingTail({maxMs:
|
|
552
|
+
})()`})||console.warn(" warn: eventRecorder.start() returned false \u2014 preview will upload bundle without replay events")),await d.runFlow(R),n&&(O=await d.stopProfile()),await d.waitForRecordingTail({maxMs:wt,smart:m}),M&&(E=await d.stopRecording(),L=d.getLastRecordingDurationMs()),m&&(_=await T.send({type:"evaluate",simId:d.simId,code:`(() => {
|
|
553
553
|
const r = window.SootSim?.bridges?.eventRecorder ?? window.__sootsimEventRecorder
|
|
554
554
|
return r?.stop?.() ?? []
|
|
555
555
|
})()`}),console.log(` captured ${_.length} replay events`),W=w.join(s,"preview-final.png"),await d.captureScreenshot(W),console.log(` final screenshot: ${W}`));let c=R.filter(y=>y&&typeof y=="object"&&"takeScreenshot"in y).length;console.log(`
|
|
556
|
-
+ completed (${R.length} steps)`),c>0&&console.log(` screenshots: ${c} \u2192 ${s}`),O&&
|
|
556
|
+
+ completed (${R.length} steps)`),c>0&&console.log(` screenshots: ${c} \u2192 ${s}`),O&&pt(O),E&&console.log(` video: ${E}`),console.log()}catch(h){if(n&&!O)try{O=await d.stopProfile()}catch{}if(M&&!E)try{E=await d.stopRecording(),L=d.getLastRecordingDurationMs()}catch(c){console.warn(` recording stop failed: ${c?.message||String(c)}`)}if(m&&!_)try{_=await T.send({type:"evaluate",simId:d.simId,code:`(() => {
|
|
557
557
|
const r = window.SootSim?.bridges?.eventRecorder ?? window.__sootsimEventRecorder
|
|
558
558
|
return r?.stop?.() ?? []
|
|
559
559
|
})()`}),console.log(` captured ${_.length} partial replay events`)}catch(c){console.warn(` event recorder stop failed: ${c?.message||String(c)}`)}console.error(`
|
|
560
560
|
x failed: ${h.message}
|
|
561
|
-
`),O&&(console.log(" partial profile:"),
|
|
562
|
-
preparing preview upload\u2026`);let F=d.getFlowTraceSteps();F.length>0&&c.push("--timeline-events",await
|
|
561
|
+
`),O&&(console.log(" partial profile:"),pt(O)),E&&console.log(` partial video: ${E}`);try{let c=d.lastFailedStep,y=c?`step-${String(c.index+1).padStart(2,"0")}-${c.kind}`:"unstaged",F=w.join(s,y);await d.captureFailureBundle(F,{error:h,stepIndex:c?.index,stepKind:c?.kind,stepTarget:c?.target}),ce=F,console.log(` failure bundle: ${F}`),console.log(" (contents: screenshot.png, describe.json, a11y.txt, tree.txt, console.json, error.json)")}catch(c){try{let y=w.join(s,"error.png");await d.captureScreenshot(y),console.log(` error screenshot: ${y}`)}catch{}console.log(` (failure bundle capture failed: ${c instanceof Error?c.message:String(c)})`)}await ze(T,{errorsCommand:`sootsim get errors 5${d.simId?` --sim ${d.simId}`:""}`,warningsCommand:`sootsim get warnings 5${d.simId?` --sim ${d.simId}`:""}`,requestsCommand:`sootsim get requests 5${d.simId?` --sim ${d.simId}`:""}`}),j=1}if(await d.liveStatus?.end(j===0?"passed":"failed"),m&&(j===0||E||_))try{let h=await Zt(_??[]),c=["--origin",P,"--events",h];k&&c.push("--public-origin",k),E&&c.push("--video",E),W&&c.push("--screenshot",W),E&&L&&Number.isFinite(L)&&(c.push("--video-duration-ms",String(Math.round(L))),c.push("--recorded-duration-ms",String(Math.round(L))));let y=d.getLastRecordingStartedAtMs();y&&Number.isFinite(y)&&c.push("--recording-started-at-ms",String(Math.round(y))),v.wsPort&&c.push("--port",String(v.wsPort)),d.simId&&c.push("--sim",d.simId),re&&c.push("--open"),Pe&&c.push("--owner",Pe),ke&&c.push("--repo",ke),c.push("--run-scope",ft),H&&c.push("--billing-kind",H),console.log(`
|
|
562
|
+
preparing preview upload\u2026`);let F=d.getFlowTraceSteps();F.length>0&&c.push("--timeline-events",await Xt(F));let V=await Qt(F,y);V&&c.push("--snapshot-manifest",V),ce&&c.push("--failure-bundle",ce);let D=d.getLastRecordingFrameStats();D&&c.push("--trace-frame-stats",await en(D));let{runUpload:Tt}=await import("./upload-J34H5SXV.js");Fe=await Tt(c,{})}catch(h){console.error(` preview upload failed: ${h?.message||h}`),j=1}return $e=d.getFlowTraceSteps(),T.close(),ae?(d.simId&&le.add(d.simId),await Yt(v.wsPort,v.commandTimeoutMs,[...le])):d.simId&&d.simId!==Y&&Ne(d.simId),await de(),j}async function Yt(r,e,t){let n=[...new Set(t.filter(Boolean))];if(n.length===0)return;let i=he(r,{commandTimeoutMs:e});try{let o=await i.listSims(),a=n.filter(l=>o.some(u=>u.id===l&&u.readyState==="open"));if(a.length===0)return;let s=await Xe(i,r,e,a);await Ye(o,a),s.closed.length>0&&console.log(` closed flow sim(s): ${s.closed.join(", ")}`),s.remaining.length>0&&console.warn(` warn: flow sim(s) still connected after close: ${s.remaining.join(", ")}`)}catch(o){console.warn(` warn: failed to close flow sim(s): ${o instanceof Error?o.message:String(o)}`)}finally{i.close()}}async function Zt(r){let{gzipSync:e}=await import("zlib"),t=r.map(o=>JSON.stringify(o)).join(`
|
|
563
563
|
`)+(r.length?`
|
|
564
|
-
`:""),n=e(Buffer.from(t,"utf8")),i=w.join(K(),`sootsim-events-${Date.now()}.jsonl.gz`);return $.writeFileSync(i,n),console.log(` events: ${r.length} written to ${i} (${n.length} bytes gz)`),i}async function
|
|
564
|
+
`:""),n=e(Buffer.from(t,"utf8")),i=w.join(K(),`sootsim-events-${Date.now()}.jsonl.gz`);return $.writeFileSync(i,n),console.log(` events: ${r.length} written to ${i} (${n.length} bytes gz)`),i}async function Xt(r){let{gzipSync:e}=await import("zlib"),t=r.map((a,s)=>({schemaVersion:1,t:a.endedAtMs,seq:1e6+s,context:"host",kind:"flow-step",id:`flow-step-${a.stepIndex}`,data:{stepIndex:a.stepIndex,stepNumber:a.stepIndex+1,stepName:a.stepName,...a.targetLabel?{targetLabel:a.targetLabel}:{},status:a.status,durationMs:a.durationMs,startedAtMs:a.startedAtMs,endedAtMs:a.endedAtMs,...a.error?{error:a.error}:{}}})),n=t.map(a=>JSON.stringify(a)).join(`
|
|
565
565
|
`)+`
|
|
566
|
-
`,i=e(Buffer.from(n,"utf8")),o=w.join(K(),`sootsim-flow-steps-${Date.now()}.jsonl.gz`);return $.writeFileSync(o,i),console.log(` flow trace: ${t.length} step events written to ${o} (${i.length} bytes gz)`),o}async function
|
|
567
|
-
validation failed \u2014 draft preserved so you can keep iterating`),process.exitCode=u;return}ye(),console.log(` flow draft validated (${s.stepCount} step${s.stepCount===1?"":"s"})`),s.outputPath&&console.log(` saved: ${s.outputPath}`),o&&console.log(" video: recorded during validation run");return}if(ye(),console.log(` flow draft ended (${s.stepCount} step${s.stepCount===1?"":"s"})`),s.outputPath){console.log(` saved: ${s.outputPath}`),console.log(` next: sootsim maestro test ${s.outputPath} --record`);return}console.log(""),process.stdout.write(s.yaml);return}case"validate":{let n=r[1];(!n||n.startsWith("-"))&&(console.error(" usage: sootsim maestro validate <path>"),process.exit(1));let i=we(n);if(i.length>0){console.error(` x ${n} failed validation:`);for(let o of i)console.error(` - ${o}`);process.exit(1)}console.log(` + ${n} looks valid`);return}}}function
|
|
566
|
+
`,i=e(Buffer.from(n,"utf8")),o=w.join(K(),`sootsim-flow-steps-${Date.now()}.jsonl.gz`);return $.writeFileSync(o,i),console.log(` flow trace: ${t.length} step events written to ${o} (${i.length} bytes gz)`),o}async function Qt(r,e){if(!e)return null;let t=r.flatMap(i=>i.screenshotPath?[{id:`flow-step-${i.stepIndex}`,label:i.targetLabel??`Step ${i.stepIndex+1}`,kind:"interaction",t:Math.max(0,i.endedAtMs-e),path:i.screenshotPath}]:[]);if(t.length===0)return null;let n=w.join(K(),`sootsim-flow-snapshots-${Date.now()}.json`);return $.writeFileSync(n,JSON.stringify(t)),console.log(` flow snapshots: ${t.length} written to ${n}`),n}async function en(r){let e=w.join(K(),`sootsim-frame-stats-${Date.now()}.json`);return $.writeFileSync(e,JSON.stringify(r)),console.log(` frame stats: written to ${e}`),e}async function tn(r){let e=r[0],t=n=>r.find((i,o)=>r[o-1]===n);switch(e){case"start":{let{path:n,state:i}=et();console.log(" flow draft started"),console.log(` session: ${n}`),console.log(` steps: ${i.steps.length}`);return}case"keep":case"good":{let n=be();if(n.active||(console.error(" no active flow draft \u2014 run `sootsim maestro start` first"),process.exit(1)),!n.kept){console.log(" no pending action to keep");return}console.log(` kept: ${n.candidate.summary}`),console.log(` steps: ${n.stepCount}`);return}case"end":{let n=t("--output")||(r[1]&&!r[1].startsWith("-")?r[1]:void 0),i=r.includes("--validate")||r.includes("--video"),o=r.includes("--video"),a=be();a.active&&a.kept&&console.log(` auto-kept trailing action: ${a.candidate.summary}`);let s=tt(n||(i?rn():void 0));if(s.active||(console.error(" no active flow draft \u2014 run `sootsim maestro start` first"),process.exit(1)),!s.valid){console.error(" flow draft is not valid:");for(let l of s.issues)console.error(` - ${l}`);console.error(" draft preserved \u2014 keep at least one real interaction or run `sootsim maestro start` to reset"),process.exit(1)}if(i){let l=on(r,s.outputPath),u=await ht(l);if(u!==0){console.error(`
|
|
567
|
+
validation failed \u2014 draft preserved so you can keep iterating`),process.exitCode=u;return}ye(),console.log(` flow draft validated (${s.stepCount} step${s.stepCount===1?"":"s"})`),s.outputPath&&console.log(` saved: ${s.outputPath}`),o&&console.log(" video: recorded during validation run");return}if(ye(),console.log(` flow draft ended (${s.stepCount} step${s.stepCount===1?"":"s"})`),s.outputPath){console.log(` saved: ${s.outputPath}`),console.log(` next: sootsim maestro test ${s.outputPath} --record`);return}console.log(""),process.stdout.write(s.yaml);return}case"validate":{let n=r[1];(!n||n.startsWith("-"))&&(console.error(" usage: sootsim maestro validate <path>"),process.exit(1));let i=we(n);if(i.length>0){console.error(` x ${n} failed validation:`);for(let o of i)console.error(` - ${o}`);process.exit(1)}console.log(` + ${n} looks valid`);return}}}function nn(r){return r[0]==="--sim"&&r.length>=2?[...r.slice(2),"--sim",r[1]]:r}async function Wn(r){let e=nn(r),t=e[0];if(t==="start"||t==="keep"||t==="good"||t==="end"||t==="validate")return await tn(e),0;let n=await ht(e);return n!==0&&(process.exitCode=n),n}function pt(r){console.log(""),nt(r)}function rn(){return w.join(K(),`sootsim-flow-draft-${Date.now()}.yaml`)}function on(r,e){if(!e)throw new Error("validated flow draft requires an output path");let t=[e];for(let n=1;n<r.length;n++){let i=r[n];if(!(i==="--validate"||i==="--video")){if(i==="--output"){n+=1;continue}n===1&&!i.startsWith("-")||t.push(i)}}return!t.includes("--record")&&r.includes("--video")&&t.push("--record"),t}export{lt as a,Mt as b,Hn as c,Un as d,qt as e,ht as f,nn as g,Wn as h};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*! sootsim v0.1.228 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
|
|
2
|
+
import{c as b}from"./chunk-4A6HM2K3.js";import{b as F,e as T,g as A}from"./chunk-EPQ5EZBJ.js";import{M as w,N as S,O as I,P as B}from"./chunk-PNPH4JLS.js";import{WebSocket as W}from"ws";var P=null;function O(){return P||(P=M(),P)}function M(){let i=S();if(i&&B(i))return{source:"dev-bridge",bridgePort:i.bridgePort,shellBaseUrl:i.shellPort?`http://localhost:${i.shellPort}/`:b};let r=w();return r&&I(r)?{source:"daemon",bridgePort:r.bridgePort,shellBaseUrl:r.runtimePort>0?`http://localhost:${r.runtimePort}/`:b}:{source:"default",bridgePort:7668,shellBaseUrl:b}}function U(i){let r=S();if(r&&B(r)&&r.bridgePort===i)return{source:"dev-bridge",shellBaseUrl:r.shellPort?`http://localhost:${r.shellPort}/`:b};let e=w();return e&&I(e)&&e.bridgePort===i?{source:"daemon",shellBaseUrl:e.runtimePort>0?`http://localhost:${e.runtimePort}/`:b}:null}function G(i){let r;try{let l=new URL(i);r=l.port?Number(l.port):l.protocol==="https:"?443:80}catch{return null}if(!Number.isFinite(r)||r<=0)return null;let e=S();if(e&&B(e)&&(e.shellPort===r||e.runtimePort===r||e.bridgePort===r))return e.bridgePort;let d=w();return d&&I(d)&&(d.runtimePort===r||d.bridgePort===r)?d.bridgePort:null}function _(){return O().bridgePort}function K(i,r){let e=U(i),d=e?.source==="dev-bridge"?"dev bridge":e?.source==="daemon"?"daemon bridge":"bridge",l=e?`${e.source}.json`:"no lockfile",t=r??e?.shellBaseUrl;process.stderr.write(` \u2192 ${d} :${i} (${t?`shell ${t}, `:""}${l})
|
|
3
|
+
`)}var $=class extends Error{lock;constructor(r,e){super(r),this.name="BridgeSimLockedError",this.lock=e}};function N(i){return i==="flag"?"via --sim":i==="saved"?"saved via `sootsim use`":"primary fallback \u2014 no sim pinned"}function Q(i,r={}){let e=new Set,d=r.port??_(),l=r.commandTimeoutMs??15e3,t,u="none",v=new Set(r.stripBooleanFlags??[]),p=new Set(r.stripValueFlags??[]);for(let n=0;n<i.length;n++){let a=i[n];if(a==="--port"||a==="-p"){e.add(n),n+1<i.length&&(e.add(n+1),d=Number(i[n+1])),n++;continue}if(a.startsWith("--port=")){e.add(n),d=Number(a.slice(7));continue}if(a==="--timeout"){e.add(n),n+1<i.length&&(e.add(n+1),l=Number(i[n+1])),n++;continue}if(a==="--sim"||a==="--session"||a==="--tab"){e.add(n),n+1<i.length&&(e.add(n+1),t=i[n+1]?.trim()||void 0,u="flag"),n++;continue}let s=a.startsWith("--sim=")?a.slice(6):a.startsWith("--session=")?a.slice(10):a.startsWith("--tab=")?a.slice(6):void 0;if(s!==void 0){e.add(n),t=s.trim()||void 0,u="flag";continue}if(v.has(a)){e.add(n);continue}p.has(a)&&(e.add(n),n+1<i.length&&e.add(n+1),n++)}if(!t){let n=T();n&&(t=n.trim()||void 0,u="saved")}return{positional:i.filter((n,a)=>!e.has(a)),wsPort:d,simId:t,simIdSource:u,commandTimeoutMs:l}}function R(i,r={}){let e=1,d=r.commandTimeoutMs??15e3,l=new Map,t=new W(`ws://localhost:${i}`),u=F(),v=new Promise((s,o)=>{t.on("open",()=>{try{t.send(JSON.stringify({type:"bridge:hello",id:0,cliIdentityKey:u.key,cliIdentitySource:u.source,cliLabel:r.cliLabel}))}catch{}s()}),t.on("error",c=>{let m=c.message?`: ${c.message}`:"";o(new Error(`could not connect to ws://localhost:${i}${m}`))})}),p=!1,n=!1;function a(s,o){if(n||process.env.SOOTSIM_QUIET_TARGET_NOTICE==="1"||s.startsWith("bridge:")||s==="focus"||s==="close")return;n=!0;let c=o??"primary",m=N(o?r.simIdSource:"none");process.stderr.write(` \u2192 ${c} (${m})
|
|
4
|
+
`)}return t.on("message",s=>{let o;try{o=JSON.parse(s.toString())}catch{return}if(o.id===0)return;let c=l.get(o.id);c&&(l.delete(o.id),o._otherCliCount>0&&!p&&(p=!0,process.stderr.write(`
|
|
5
|
+
\u26A0 ${o._otherCliCount} other CLI identity/identities are driving this sim
|
|
6
|
+
taps, scrolls, and keyboard input from multiple agents will collide on
|
|
7
|
+
the same screen state (this is not a bridge throughput limit).
|
|
8
|
+
use \`sootsim open --new\` for an isolated sim per agent.
|
|
9
|
+
|
|
10
|
+
`)),o.error?o._locked?c.reject(new $(o.error,o._locked)):c.reject(new Error(o.error)):c.resolve(o.result))}),t.on("close",(s,o)=>{let c=o?.toString()||"connection closed";for(let[m,f]of l)l.delete(m),f.reject(new Error(`sim disconnected: ${c} (code ${s})`))}),{async send(s,o){let c=o?.timeoutMs??d,m=async g=>{await v;let h=e++;return new Promise((L,C)=>{let x=setTimeout(()=>{l.delete(h),C(new Error(`command timed out after ${Math.round(c/1e3)}s`))},c);l.set(h,{resolve:k=>{clearTimeout(x),L(k)},reject:k=>{clearTimeout(x),C(k)}});let y={...s,id:h};y.simId===void 0&&g&&(y.simId=g),a(s.type??"",y.simId),t.send(JSON.stringify(y))})},f=r.simIdSource==="flag"?r.simId:T()??r.simId;try{return await m(f)}catch(g){let h=g instanceof Error?g.message:String(g);throw r.simIdSource!=="flag"&&f&&s.simId===void 0&&h===`no sim connected with id ${f}`?(A(),new Error(`saved sim ${f} is gone; run \`sootsim list\` and \`sootsim use <sim>\`, or open a fresh sim`)):g}},async listSims(){let s=await this.send({type:"bridge:list-sims"});return Array.isArray(s)?s:[]},async openUrl(s,o={}){return this.send({type:"bridge:open",url:s,newWindow:o.newWindow===!0})},async focusSim(s){return this.send({type:"focus",simId:s})},async closeSim(s){return this.send({type:"close",simId:s})},async claim(s,o={}){return await this.send({type:"bridge:claim",simId:s,force:o.force===!0})},close(){try{t.readyState===W.OPEN&&t.send(JSON.stringify({type:"bridge:bye",id:0}))}catch{}t.close();let s=setTimeout(()=>{t.readyState!==W.CLOSED&&t.terminate()},250)}}}function z(i){return R(i.wsPort,{commandTimeoutMs:i.commandTimeoutMs,simId:i.simId,simIdSource:i.simIdSource})}function D(i,r){let e=i.filter(t=>t.readyState==="open"&&t.id!==r),d=e.find(t=>t.userFocused)??e.find(t=>t.userVisible===!0&&t.isPrimary)??e.find(t=>t.userVisible===!0)??e.find(t=>t.isPrimary);if(!d)return null;let l=[d.isPrimary?"primary":null,d.userVisible===!1?"hidden":d.userVisible===!0?"visible":null,d.userFocused?"focused":null].filter(Boolean);return`${d.id}${l.length?` [${l.join(", ")}]`:""}`}async function X(i){try{let r=await i.send({type:"evaluate",code:`(() => ({
|
|
11
|
+
hidden: document.hidden,
|
|
12
|
+
visibilityState: document.visibilityState,
|
|
13
|
+
hasFocus: typeof document.hasFocus === 'function' ? document.hasFocus() : null,
|
|
14
|
+
simId: window.__sootsimBridge?.id ?? window.SootSim?.state?.simId ?? null,
|
|
15
|
+
url: location.href
|
|
16
|
+
}))()`}),e=typeof r=="object"&&r!==null?r:{hidden:r===!0};if(e.hidden===!0===!0){let l=null;try{l=D(await i.listSims(),e.simId)}catch{}return process.stderr.write(`
|
|
17
|
+
\u26A0 target sim${e.simId?` ${e.simId}`:""} is hidden (document.hidden = true)
|
|
18
|
+
`+(e.visibilityState?` visibility: ${e.visibilityState}
|
|
19
|
+
`:"")+` animations and rAF callbacks are throttled \u2014 coordinates may be wrong
|
|
20
|
+
and launch/transition animations will not complete.
|
|
21
|
+
`+(l?` another open sim looks usable: ${l}; target it with --sim.
|
|
22
|
+
`:" run `sootsim list` to find the visible sim and target it with --sim.\n")+` page-level window.focus() cannot unhide a browser tab.
|
|
23
|
+
|
|
24
|
+
`),{hidden:!0,warned:!0,simId:e.simId}}return{hidden:!1,warned:!1,simId:e.simId}}catch{return{hidden:!1,warned:!1}}}async function Y(i,r,e={}){let d={type:"evaluate",code:r};return e.acquireLock&&(d.acquireLock=!0),i.send(d)}async function Z(i,r,...e){return i.send({type:"call",path:r,args:e})}async function ee(i,r,...e){return i.send({type:"call",path:r,args:e,acquireLock:!0})}export{O as a,U as b,G as c,_ as d,K as e,$ as f,Q as g,R as h,z as i,X as j,Y as k,Z as l,ee as m};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! sootsim v0.1.
|
|
1
|
+
/*! sootsim v0.1.228 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
|
|
2
2
|
import{execFileSync as d,spawn as g}from"child_process";import{existsSync as m}from"fs";import{homedir as h}from"os";import{join as C}from"path";var f=["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome","~/Applications/Google Chrome.app/Contents/MacOS/Google Chrome","/Applications/Chromium.app/Contents/MacOS/Chromium","~/Applications/Chromium.app/Contents/MacOS/Chromium","/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge","~/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge","/Applications/Brave Browser.app/Contents/MacOS/Brave Browser","~/Applications/Brave Browser.app/Contents/MacOS/Brave Browser","/Applications/Arc.app/Contents/MacOS/Arc","~/Applications/Arc.app/Contents/MacOS/Arc"],O=["/usr/bin/google-chrome","/usr/bin/chromium","/usr/bin/chromium-browser","/usr/bin/microsoft-edge","/usr/bin/brave-browser","/snap/bin/chromium"],w=["C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe","C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe","C:\\Program Files\\Microsoft\\Edge\\Application\\msedge.exe","C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe","C:\\Program Files\\BraveSoftware\\Brave-Browser\\Application\\brave.exe","C:\\Program Files (x86)\\BraveSoftware\\Brave-Browser\\Application\\brave.exe"],U=["google-chrome","chromium","chromium-browser","microsoft-edge","brave-browser"],M=["chrome","msedge","brave"];function A(r){return r.startsWith("~/")?C(h(),r.slice(2)):r}function a(r){for(let n of r){let o=A(n);if(m(o))return o}return null}function x(r,n){try{let e=d(n==="win32"?"where":"which",[r],{encoding:"utf8",timeout:1500,stdio:["ignore","pipe","ignore"]}).trim();return e?e.split(/\r?\n/)[0]:null}catch{return null}}function c(r=process.platform){let n=process.env.CHROME_PATH||process.env.CHROMIUM_PATH;if(n&&m(n))return n;let o=a(r==="darwin"?f:r==="win32"?w:O);if(o)return o;let e=r==="win32"?M:U;for(let t of e){let i=x(t,r);if(i)return i}return null}function p(r,n={}){if(!r)throw new Error("openUrl requires a url");let o=n.platform??process.platform;return n.newWindow?s(r,{...n,platform:o,newWindow:!0}):o==="darwin"?{command:"open",args:n.background===!1?[r]:["-g",r],via:"system"}:o==="win32"?{command:"cmd",args:["/c","start","",r],via:"system"}:{command:"xdg-open",args:[r],via:"system"}}function s(r,n={}){if(!r)throw new Error("openUrl requires a url");let o=n.platform??process.platform,e="chromiumBinary"in n?n.chromiumBinary:c(o);if(!e)throw new Error("browser launch requires Chrome, Chromium, Edge, Brave, or Arc");let t=[];return n.newWindow!==!1&&t.push("--new-window"),t.push(r),{command:e,args:t,via:"chromium",target:e}}async function l(r,n,o){return new Promise((e,t)=>{let i=g(r,n,{detached:o,stdio:"ignore"});i.once("error",t),i.once("spawn",()=>{o&&i.unref(),e(i.pid)})})}async function u(r,n={}){let o=p(r,n),e=await l(o.command,o.args,n.detached??!0);return{...o,pid:e,attachUrl:r}}async function b(r,n={}){let o=s(r,n),e=await l(o.command,o.args,n.detached??!0);return{...o,pid:e,attachUrl:r}}async function v(r,n={}){await u(r,n)}export{c as a,u as b,b as c,v as d};
|