sootsim 0.1.36 → 0.1.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/README.md +20 -5
  2. package/dist-cli/bin.js +15 -20
  3. package/dist-cli/chunks/{agent-YZB6D3DR.js → agent-CGQWOOOL.js} +2 -2
  4. package/dist-cli/chunks/{agent-wrapper-VHCVS22I.js → agent-wrapper-M6P53GJ2.js} +10 -10
  5. package/dist-cli/chunks/{assert-AIVCKKLG.js → assert-O7N2SYJZ.js} +2 -2
  6. package/dist-cli/chunks/auto-bootstrap-DF4KYGPS.js +2 -0
  7. package/dist-cli/chunks/beta-AK25X3AU.js +2 -0
  8. package/dist-cli/chunks/chunk-23YMXBQ2.js +1 -0
  9. package/dist-cli/chunks/chunk-2ABGQIW7.js +4 -0
  10. package/dist-cli/chunks/chunk-5HNZO5AI.js +7 -0
  11. package/dist-cli/chunks/chunk-5XI3AB4I.js +3 -0
  12. package/dist-cli/chunks/{chunk-IJMYFYDZ.js → chunk-67K3WAEZ.js} +2 -2
  13. package/dist-cli/chunks/chunk-6UJXRT7F.js +5 -0
  14. package/dist-cli/chunks/chunk-ARH3T5NK.js +66 -0
  15. package/dist-cli/chunks/{chunk-VFDRZNPN.js → chunk-B4VH67D3.js} +1 -1
  16. package/dist-cli/chunks/chunk-BEY2QVU5.js +3 -0
  17. package/dist-cli/chunks/chunk-CB4PUMI2.js +1 -0
  18. package/dist-cli/chunks/chunk-CHMHTTI7.js +11 -0
  19. package/dist-cli/chunks/chunk-E473YTRQ.js +2 -0
  20. package/dist-cli/chunks/chunk-FCOCFEBU.js +27 -0
  21. package/dist-cli/chunks/chunk-FRE5TY3C.js +1 -0
  22. package/dist-cli/chunks/chunk-FX3PPKSJ.js +2 -0
  23. package/dist-cli/chunks/{chunk-27P763IZ.js → chunk-FXY5FWVY.js} +2 -2
  24. package/dist-cli/chunks/{chunk-A5BRCXYE.js → chunk-G23GIRBM.js} +1 -1
  25. package/dist-cli/chunks/chunk-G62Q2MQI.js +1 -0
  26. package/dist-cli/chunks/chunk-GWQUPWVO.js +2 -0
  27. package/dist-cli/chunks/{chunk-EWSQSALM.js → chunk-H6CG42HE.js} +4 -4
  28. package/dist-cli/chunks/chunk-HNAGYNWN.js +16 -0
  29. package/dist-cli/chunks/{chunk-KAXZHEKM.js → chunk-IE2WYVJF.js} +1 -1
  30. package/dist-cli/chunks/chunk-IKVIHHWE.js +2 -0
  31. package/dist-cli/chunks/chunk-JJVZMGRM.js +2 -0
  32. package/dist-cli/chunks/{chunk-HWCKZXNJ.js → chunk-LNRBXCUI.js} +2 -2
  33. package/dist-cli/chunks/{chunk-CYCXOAVZ.js → chunk-MTPWS4JK.js} +4 -4
  34. package/dist-cli/chunks/{chunk-G7XQD4KC.js → chunk-NKYTISAN.js} +2 -2
  35. package/dist-cli/chunks/chunk-NSZBULGG.js +348 -0
  36. package/dist-cli/chunks/chunk-P32FCOS3.js +4 -0
  37. package/dist-cli/chunks/chunk-P722XCFT.js +3 -0
  38. package/dist-cli/chunks/chunk-PFRPXFSL.js +117 -0
  39. package/dist-cli/chunks/chunk-QD22CQLH.js +5 -0
  40. package/dist-cli/chunks/chunk-QI4VLQ3A.js +5 -0
  41. package/dist-cli/chunks/{chunk-OXN2PEB7.js → chunk-SKNHJDYO.js} +3 -3
  42. package/dist-cli/chunks/{chunk-YIO6S3R5.js → chunk-T442FYM5.js} +1 -1
  43. package/dist-cli/chunks/chunk-TR554AIH.js +17 -0
  44. package/dist-cli/chunks/chunk-UD5ILFN5.js +3 -0
  45. package/dist-cli/chunks/{chunk-LHDWH7VS.js → chunk-VIEK76DX.js} +1 -1
  46. package/dist-cli/chunks/chunk-VVUEWU2P.js +64 -0
  47. package/dist-cli/chunks/{chunk-RMW5BO3S.js → chunk-Z2PBRNJP.js} +2 -2
  48. package/dist-cli/chunks/chunk-ZEVZN3S4.js +2 -0
  49. package/dist-cli/chunks/{compat-Y2O2U7FL.js → compat-DNQWSPFQ.js} +2 -2
  50. package/dist-cli/chunks/{config-SRBOFUCI.js → config-ABR5BGUO.js} +2 -2
  51. package/dist-cli/chunks/control-DEHRU4XZ.js +2 -0
  52. package/dist-cli/chunks/cpu-profile-Y5YDH6X2.js +22 -0
  53. package/dist-cli/chunks/daemon-2Z4DAJT6.js +83 -0
  54. package/dist-cli/chunks/{debug-BIDMW2PE.js → debug-R36UPOJP.js} +4 -4
  55. package/dist-cli/chunks/demo-app-registry-DMMWYL7G.js +2 -0
  56. package/dist-cli/chunks/detox-FQJWEWLT.js +49 -0
  57. package/dist-cli/chunks/device-SXKLDZEC.js +16 -0
  58. package/dist-cli/chunks/diagnose-M7RKNI2H.js +41 -0
  59. package/dist-cli/chunks/drivers-NSCX5CRA.js +2 -0
  60. package/dist-cli/chunks/electron-YUAKGT4H.js +18 -0
  61. package/dist-cli/chunks/flow-UQSRNEZD.js +2 -0
  62. package/dist-cli/chunks/hints-SDD7L3VS.js +2 -0
  63. package/dist-cli/chunks/home-paths-QMCX2227.js +2 -0
  64. package/dist-cli/chunks/inspect-6FPPW7GS.js +1101 -0
  65. package/dist-cli/chunks/install-TTH3PM3B.js +2 -0
  66. package/dist-cli/chunks/{install-desktop-2MYEI4FM.js → install-desktop-EKMYRDQH.js} +3 -3
  67. package/dist-cli/chunks/{keys-7PNASIQR.js → keys-ODG3TDUP.js} +2 -2
  68. package/dist-cli/chunks/{launch-JNS47LAQ.js → launch-7HUL745I.js} +3 -3
  69. package/dist-cli/chunks/{login-YWZWUHBS.js → login-BJKQMJYT.js} +4 -4
  70. package/dist-cli/chunks/{logout-O6SXMSBP.js → logout-7NG3KGJD.js} +2 -2
  71. package/dist-cli/chunks/maestro-VFEUWV3Q.js +80 -0
  72. package/dist-cli/chunks/{preview-WGKJO5FS.js → preview-WZ6XNOBC.js} +2 -2
  73. package/dist-cli/chunks/profile-DXFEZOHB.js +22 -0
  74. package/dist-cli/chunks/react-QP7PL5CZ.js +30 -0
  75. package/dist-cli/chunks/{record-QPWLYH5R.js → record-AFE25EMH.js} +5 -5
  76. package/dist-cli/chunks/{runtime-KEMO2MSB.js → runtime-GFWS3QLZ.js} +3 -3
  77. package/dist-cli/chunks/screenshot-U6VFOVFW.js +28 -0
  78. package/dist-cli/chunks/screenshot-mode-HNGV3AFC.js +17 -0
  79. package/dist-cli/chunks/screenshots-GYMRDUJR.js +70 -0
  80. package/dist-cli/chunks/server-3Q22YYM6.js +35 -0
  81. package/dist-cli/chunks/setup-repo-NNDWIGZR.js +2 -0
  82. package/dist-cli/chunks/{skills-MO7BFNVM.js → skills-FT76ZVAV.js} +2 -2
  83. package/dist-cli/chunks/start-N573LFCF.js +23 -0
  84. package/dist-cli/chunks/store-6NTDGLPH.js +2 -0
  85. package/dist-cli/chunks/telemetry-SNZBIRGL.js +2 -0
  86. package/dist-cli/chunks/{test-XUI3KNNQ.js → test-AJPY2Q6W.js} +3 -3
  87. package/dist-cli/chunks/three-mode-JZZVOMTG.js +39 -0
  88. package/dist-cli/chunks/timeline-GTSCF5P6.js +22 -0
  89. package/dist-cli/chunks/upload-UHTVCGGR.js +2 -0
  90. package/dist-cli/chunks/what-happened-N3AQ6I7O.js +15 -0
  91. package/dist-cli/chunks/whoami-FOIMN6UC.js +2 -0
  92. package/dist-lib/agent-daemon-client.cjs +4 -1
  93. package/dist-lib/agent-events.cjs +1 -1
  94. package/dist-lib/agent-sessions.cjs +41 -39
  95. package/dist-lib/attached-projects.cjs +30 -28
  96. package/dist-lib/auth/shared-session.cjs +35 -27
  97. package/dist-lib/backend-origin.cjs +1 -1
  98. package/dist-lib/bridge-constants.cjs +1 -1
  99. package/dist-lib/cli-constants.cjs +1 -1
  100. package/dist-lib/config.cjs +6 -2
  101. package/dist-lib/dev-bundle-resolution.cjs +5 -50
  102. package/dist-lib/home-paths.cjs +94 -38
  103. package/dist-lib/host/bridge-host.cjs +2144 -1330
  104. package/dist-lib/host/fetch-proxy-handler.cjs +248 -0
  105. package/dist-lib/index.cjs +21 -21
  106. package/dist-lib/metro.cjs +21 -21
  107. package/dist-lib/profiles.cjs +246 -0
  108. package/dist-lib/render-mode.cjs +1 -1
  109. package/dist-lib/vite-base.cjs +3410 -1632
  110. package/dist-lib/vite.cjs +1 -1
  111. package/package.json +7 -1
  112. package/dist-cli/chunks/auto-bootstrap-MLNTX23H.js +0 -2
  113. package/dist-cli/chunks/chunk-3UIWOHC2.js +0 -62
  114. package/dist-cli/chunks/chunk-5KGFHWVR.js +0 -1
  115. package/dist-cli/chunks/chunk-5QIUJNT3.js +0 -5
  116. package/dist-cli/chunks/chunk-6GGMKFWJ.js +0 -4
  117. package/dist-cli/chunks/chunk-6Z275LCY.js +0 -2
  118. package/dist-cli/chunks/chunk-75LBYBKW.js +0 -11
  119. package/dist-cli/chunks/chunk-DFN3GGH7.js +0 -5
  120. package/dist-cli/chunks/chunk-EBEHZJRG.js +0 -117
  121. package/dist-cli/chunks/chunk-EJLNUMMP.js +0 -3
  122. package/dist-cli/chunks/chunk-FE7UI3MT.js +0 -4
  123. package/dist-cli/chunks/chunk-G663654J.js +0 -1
  124. package/dist-cli/chunks/chunk-GW7XY5KC.js +0 -2
  125. package/dist-cli/chunks/chunk-H2QO4TDV.js +0 -22
  126. package/dist-cli/chunks/chunk-HWFHBMAQ.js +0 -27
  127. package/dist-cli/chunks/chunk-J7CTD37P.js +0 -1
  128. package/dist-cli/chunks/chunk-N32NCVL2.js +0 -3
  129. package/dist-cli/chunks/chunk-NIZBR7EK.js +0 -2
  130. package/dist-cli/chunks/chunk-NYY36OKU.js +0 -308
  131. package/dist-cli/chunks/chunk-PJL25JQV.js +0 -5
  132. package/dist-cli/chunks/chunk-SHO54NET.js +0 -2
  133. package/dist-cli/chunks/chunk-SMVJOWSV.js +0 -16
  134. package/dist-cli/chunks/chunk-TC6V7YFC.js +0 -3
  135. package/dist-cli/chunks/chunk-YLIIVTTQ.js +0 -3
  136. package/dist-cli/chunks/chunk-YR7BGGYE.js +0 -2
  137. package/dist-cli/chunks/chunk-ZEW3RF5Q.js +0 -1
  138. package/dist-cli/chunks/control-PL2V2O6S.js +0 -2
  139. package/dist-cli/chunks/daemon-IZC32PZW.js +0 -50
  140. package/dist-cli/chunks/demo-app-registry-5JFOUU3D.js +0 -2
  141. package/dist-cli/chunks/detox-B3FDOIS3.js +0 -49
  142. package/dist-cli/chunks/device-ZZSI363W.js +0 -16
  143. package/dist-cli/chunks/drivers-S4NGK4DB.js +0 -2
  144. package/dist-cli/chunks/electron-5YFHXEOI.js +0 -15
  145. package/dist-cli/chunks/flow-JJBO6TFY.js +0 -2
  146. package/dist-cli/chunks/hints-G5HBBV2O.js +0 -2
  147. package/dist-cli/chunks/home-paths-VWC3FWA3.js +0 -2
  148. package/dist-cli/chunks/inspect-POOPWUQI.js +0 -1034
  149. package/dist-cli/chunks/install-MP6FHXNZ.js +0 -2
  150. package/dist-cli/chunks/install-dev-desktop-SKH3KEHY.js +0 -100
  151. package/dist-cli/chunks/maestro-CW6XVUKV.js +0 -75
  152. package/dist-cli/chunks/profile-SUOBRPIC.js +0 -22
  153. package/dist-cli/chunks/screenshot-JTY46V7G.js +0 -26
  154. package/dist-cli/chunks/screenshot-mode-7OYBBX6D.js +0 -17
  155. package/dist-cli/chunks/screenshots-QISKC4GD.js +0 -70
  156. package/dist-cli/chunks/server-YSFJAKAV.js +0 -34
  157. package/dist-cli/chunks/setup-repo-LFB3HBEO.js +0 -2
  158. package/dist-cli/chunks/store-6MFL53I4.js +0 -2
  159. package/dist-cli/chunks/telemetry-CN42GMVC.js +0 -2
  160. package/dist-cli/chunks/upload-6FUT7AX5.js +0 -2
  161. package/dist-cli/chunks/whoami-TQFHY42N.js +0 -2
@@ -1,2 +0,0 @@
1
- /*! sootsim v0.1.36 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
- import{a as o}from"./chunk-27P763IZ.js";import"./chunk-VFDRZNPN.js";import"./chunk-IJMYFYDZ.js";import"./chunk-EJLNUMMP.js";import"./chunk-TC6V7YFC.js";import"./chunk-SMVJOWSV.js";import"./chunk-6GGMKFWJ.js";import"./chunk-ZEW3RF5Q.js";import"./chunk-5QIUJNT3.js";import"./chunk-LHDWH7VS.js";async function t(n){console.error(" note: `sootsim install` is now `sootsim setup-repo`. forwarding\u2026\n"),await o(n)}export{t as runInstall};
@@ -1,100 +0,0 @@
1
- /*! sootsim v0.1.36 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
- import{a as b}from"./chunk-VFDRZNPN.js";import"./chunk-LHDWH7VS.js";import{spawnSync as m}from"child_process";import{chmodSync as $,existsSync as u,mkdirSync as y,rmSync as N,writeFileSync as g,cpSync as B}from"fs";import{dirname as p,join as s,resolve as k}from"path";import{fileURLToPath as S}from"url";var C=p(S(import.meta.resolve("sootsim-engine/package.json"))),I="sootsim-dev",E="dev.sootsim.simulator.dev";function w(e){let n={yes:e.includes("--yes")||e.includes("-y")||process.env.SOOTSIM_NO_PROMPT==="1"||process.env.CI==="1"||!process.stdin.isTTY,force:e.includes("--force"),appName:I,bundleId:E};for(let o=0;o<e.length;o++){let t=e[o];t==="--name"&&e[o+1]?n.appName=e[++o]:t==="--bundle-id"&&e[o+1]?n.bundleId=e[++o]:t==="--path"&&e[o+1]&&(n.installRoot=e[++o])}return n}function T(e){let r=process.platform==="darwin"?"electron/dist/Electron.app/Contents/MacOS/Electron":process.platform==="win32"?"electron/dist/electron.exe":"electron/dist/electron",c=e;for(let l=0;l<6;l++){let d=s(c,"node_modules",r);if(u(d))return d;let i=p(c);if(i===c)break;c=i}return null}function D(e){if(e)return k(e);let n="/Applications",o=k(process.env.HOME||"","Applications");try{let t=s(n,`.sootsim-dev-write-probe-${process.pid}`);if(m("touch",[t]).status===0&&u(t))return N(t,{force:!0}),n}catch{}return y(o,{recursive:!0}),o}function L(e){return`<?xml version="1.0" encoding="UTF-8"?>
3
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
4
- <plist version="1.0">
5
- <dict>
6
- <key>CFBundleDisplayName</key>
7
- <string>${e.appName}</string>
8
- <key>CFBundleName</key>
9
- <string>${e.appName}</string>
10
- <key>CFBundleExecutable</key>
11
- <string>${e.appName}</string>
12
- <key>CFBundleIconFile</key>
13
- <string>icon.icns</string>
14
- <key>CFBundleIdentifier</key>
15
- <string>${e.bundleId}</string>
16
- <key>CFBundleInfoDictionaryVersion</key>
17
- <string>6.0</string>
18
- <key>CFBundlePackageType</key>
19
- <string>APPL</string>
20
- <key>CFBundleShortVersionString</key>
21
- <string>${e.version}</string>
22
- <key>CFBundleVersion</key>
23
- <string>${e.version}</string>
24
- <key>LSApplicationCategoryType</key>
25
- <string>public.app-category.developer-tools</string>
26
- <key>LSMinimumSystemVersion</key>
27
- <string>12.0</string>
28
- <key>NSHighResolutionCapable</key>
29
- <true/>
30
- <key>NSAppTransportSecurity</key>
31
- <dict>
32
- <key>NSAllowsArbitraryLoads</key>
33
- <true/>
34
- <key>NSAllowsLocalNetworking</key>
35
- <true/>
36
- </dict>
37
- <key>CFBundleURLTypes</key>
38
- <array>
39
- <dict>
40
- <key>CFBundleTypeRole</key>
41
- <string>Viewer</string>
42
- <key>CFBundleURLName</key>
43
- <string>sootsim</string>
44
- <key>CFBundleURLSchemes</key>
45
- <array>
46
- <string>sootsim</string>
47
- </array>
48
- </dict>
49
- </array>
50
- </dict>
51
- </plist>
52
- `}function F(e){return`#!/bin/bash
53
- # auto-generated by: sootsim install-dev-desktop
54
- # checkout: ${e.checkoutRoot}
55
- # regenerate: cd ${e.checkoutRoot} && bun sootsim install-dev-desktop --force
56
- set -e
57
- ELECTRON_BIN=${JSON.stringify(e.electronBin)}
58
- ENGINE_DIR=${JSON.stringify(e.engineDir)}
59
- CHECKOUT_ROOT=${JSON.stringify(e.checkoutRoot)}
60
- if [ ! -x "$ELECTRON_BIN" ]; then
61
- /usr/bin/osascript -e "display alert \\"sootsim-dev\\" message \\"Electron not found at $ELECTRON_BIN. Run bun install in $CHECKOUT_ROOT, then re-run sootsim install-dev-desktop.\\""
62
- exit 1
63
- fi
64
- if [ ! -f "$ENGINE_DIR/dist-electron/main.cjs" ]; then
65
- /usr/bin/osascript -e "display alert \\"sootsim-dev\\" message \\"Engine not built at $ENGINE_DIR. Run bun dev (or bun run --cwd packages/sootsim-engine build:electron-main) in $CHECKOUT_ROOT.\\""
66
- exit 1
67
- fi
68
- cd "$CHECKOUT_ROOT"
69
- exec "$ELECTRON_BIN" "$ENGINE_DIR" "$@"
70
- `}function _(e,n){let o=s(e,"Contents"),t=s(o,"MacOS"),r=s(o,"Resources");y(t,{recursive:!0}),y(r,{recursive:!0}),g(s(o,"Info.plist"),L({appName:n.appName,bundleId:n.bundleId,version:n.version})),g(s(o,"PkgInfo"),"APPL????");let c=s(t,n.appName);g(c,F({electronBin:n.electronBin,engineDir:n.engineDir,checkoutRoot:n.checkoutRoot})),$(c,493),n.iconSource&&u(n.iconSource)&&B(n.iconSource,s(r,"icon.icns"))}async function j(e){(e.includes("--help")||e.includes("-h"))&&(console.log(`
71
- sootsim install-dev-desktop \u2014 create a Spotlight-launchable sootsim-dev.app
72
- that wraps this checkout's unpacked electron.
73
-
74
- the packaged /Applications/sootsim.app always loads the prod renderer
75
- (sootbean.com). this command generates a separate .app bundle that shells
76
- out to the local node_modules/.bin/electron against packages/sootsim-engine,
77
- so launching it from Spotlight drops you into the live :5173 dev renderer
78
- (or onboarding if no dev server is up).
79
-
80
- usage:
81
- sootsim install-dev-desktop [options]
82
-
83
- options:
84
- -y, --yes skip confirmation prompt
85
- --force overwrite existing bundle
86
- --name <name> .app bundle name (default: ${I})
87
- --bundle-id <id> CFBundleIdentifier (default: ${E})
88
- --path <dir> install root (default: /Applications, fallback ~/Applications)
89
-
90
- examples:
91
- bun sootsim install-dev-desktop
92
- bun sootsim install-dev-desktop --force
93
- bun sootsim install-dev-desktop --name sootsim-worktree --bundle-id dev.sootsim.simulator.wt
94
- `),process.exit(0));let n=w(e),o=C,t=s(o,"dist-electron/main.cjs");u(t)||(console.error(` dist-electron/main.cjs missing in ${o}.
95
- run:
96
- bun run --cwd packages/sootsim-engine build:electron-main
97
- (or keep it fresh with: bun run watch:sootsim:electron-main)
98
- `),process.exit(1));let r=T(o);r||(console.error(` no node_modules/.bin/electron found near ${o}.
99
- run \`bun install\` in the soot checkout first.
100
- `),process.exit(1));let c=process.platform==="darwin"?6:2,l=p(r);for(let a=0;a<c;a++)l=p(l);l=k(l);let d=D(n.installRoot),i=s(d,`${n.appName}.app`),f=s(o,"release/.icon-icns/icon.icns"),O=u(f)?f:null;if(console.log(` engine: ${o}`),console.log(` electron: ${r}`),console.log(` checkout: ${l}`),console.log(` install to: ${i}`),console.log(` bundle id: ${n.bundleId}`),console.log(),u(i)&&!n.force){console.log(` ${i} already exists. pass --force to overwrite.`);return}if(!n.yes){if(!await b("create the sootsim-dev bundle here?",!0)){console.log(" cancelled.");return}console.log()}let h="0.0.0";try{let a=S(import.meta.resolve("sootsim-engine/package.json")),{readFileSync:R}=await import("fs"),v=JSON.parse(R(a,"utf8"));typeof v.version=="string"&&(h=v.version)}catch{}u(i)&&N(i,{recursive:!0,force:!0});try{_(i,{appName:n.appName,bundleId:n.bundleId,electronBin:r,engineDir:o,checkoutRoot:l,version:h,iconSource:O})}catch(a){console.error(` bundle write failed: ${a instanceof Error?a.message:String(a)}`),process.exit(1)}m("/usr/bin/touch",[i]),m("/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister",["-f",i],{stdio:"ignore"}),console.log(` created: ${i}`),console.log(),console.log(" launch it:"),console.log(` open -a ${n.appName}`),console.log(" (or type its name into Spotlight)"),console.log(),console.log(" it runs this checkout's electron against the live dev renderer."),console.log(" start the dev server first: bun dev")}export{j as runInstallDevDesktop};
@@ -1,75 +0,0 @@
1
- /*! sootsim v0.1.36 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
- import{c as h}from"./chunk-NYY36OKU.js";import"./chunk-DFN3GGH7.js";import"./chunk-HWFHBMAQ.js";import"./chunk-EWSQSALM.js";import"./chunk-5KGFHWVR.js";import"./chunk-HWCKZXNJ.js";import"./chunk-H2QO4TDV.js";import"./chunk-3UIWOHC2.js";import"./chunk-YLIIVTTQ.js";import"./chunk-RMW5BO3S.js";import"./chunk-NIZBR7EK.js";import"./chunk-6Z275LCY.js";import"./chunk-IJMYFYDZ.js";import"./chunk-EJLNUMMP.js";import"./chunk-75LBYBKW.js";import"./chunk-GW7XY5KC.js";import"./chunk-OXN2PEB7.js";import"./chunk-YR7BGGYE.js";import"./chunk-PJL25JQV.js";import"./chunk-G663654J.js";import"./chunk-A5BRCXYE.js";import"./chunk-SHO54NET.js";import"./chunk-SMVJOWSV.js";import"./chunk-6GGMKFWJ.js";import"./chunk-ZEW3RF5Q.js";import"./chunk-5QIUJNT3.js";import"./chunk-LHDWH7VS.js";import*as i from"fs";import*as l from"path";var w=[".maestro","maestro"];function v(){console.log(`
3
- sootsim maestro \u2014 run maestro YAML flows against sootsim (drop-in)
4
-
5
- usage:
6
- sootsim maestro # discover .maestro/ or maestro/ in cwd, run all
7
- sootsim maestro test <flow-or-dir> # mirrors "maestro test"
8
- sootsim maestro test .maestro/ # every *.yaml / *.yml in a directory
9
- sootsim maestro init # scaffold .maestro/login.yaml
10
- sootsim maestro --list-compat # print supported/unsupported verbs
11
-
12
- options:
13
- --env KEY=VALUE set env vars for \${KEY} interpolation (repeatable)
14
- --continuous re-run the flow on file changes (alias for --watch)
15
- --format <fmt> accepted for maestro cli compat (not used)
16
- --new force a fresh browser window for this run
17
- --record record a webm while the flow runs
18
- --slow <ms> delay between steps for natural pacing
19
-
20
- examples:
21
- bun sootsim maestro test .maestro/login.yaml
22
- bun sootsim maestro test .maestro/
23
- bun sootsim maestro --env USERNAME=alice test .maestro/login.yaml
24
- bun sootsim maestro init
25
- `)}function x(){console.log(`
26
- sootsim maestro \u2014 compatibility matrix
27
-
28
- supported verbs:
29
- launchApp, stopApp, clearState, clearKeychain (warn-only),
30
- tapOn, tapAtCoords, longPressOn (via tapOn),
31
- inputText, pressKey, dispatchKey, hideKeyboard, eraseText,
32
- assertVisible, assertNotVisible, assertTreeContains,
33
- waitFor, extendedWaitUntil, waitForAnimationToEnd,
34
- scroll, scrollUntilVisible, scrollTo, swipe, pinch,
35
- takeScreenshot, dumpTree, back,
36
- repeat, runFlow, when: (visible/notVisible/platform/true),
37
- optional:, onFlowStart, onFlowComplete,
38
- copyTextFrom, evalScript, openLink,
39
- env var interpolation via \${NAME} (process.env + flow-scoped).
40
-
41
- partial:
42
- clearKeychain \u2014 warn-only, sootsim has no keychain surface.
43
- when.platform \u2014 matches "ios" only; sootsim emulates iOS.
44
- openLink \u2014 uses window.location; no OS-level app routing.
45
- takeScreenshot \u2014 maestro string form works unchanged; sootsim also accepts
46
- { path, withFrame } for framed export.
47
-
48
- not yet implemented (will throw "unsupported maestro verb"):
49
- travel, setLocation, setAirplaneMode, killApp,
50
- addMedia, startRecording, stopRecording (use --record flag),
51
- repeat.while (only repeat.times is supported).
52
- `)}function g(o){return o.startsWith("-")}function S(o){let s=[];for(let t=0;t<o.length;t++){if(o[t]==="--env"||o[t]==="-e"){let e=o[t+1];if(!e||!e.includes("="))throw new Error(`--env expects KEY=VALUE (got ${JSON.stringify(e??"")})`);let a=e.indexOf("="),r=e.slice(0,a),m=e.slice(a+1);process.env[r]=m,t+=1;continue}s.push(o[t])}return s}function $(o){let s=[];for(let t=0;t<o.length;t++){let e=o[t];if(e==="--format"||e==="--output"||e==="--device"||e==="-d"){t+=1;continue}if(e==="--continuous"){console.warn(" warn: --continuous is not yet implemented in sootsim \u2014 running once");continue}s.push(e)}return s}function y(o){for(let s of w){let t=l.join(o,s);if(i.existsSync(t)&&i.statSync(t).isDirectory())return t}return null}function E(o){let s=i.statSync(o);if(s.isFile())return[o];if(!s.isDirectory())throw new Error(`not a file or directory: ${o}`);let t=i.readdirSync(o),e=[];for(let a of t){if(a.startsWith("."))continue;let r=l.join(o,a);i.statSync(r).isFile()&&(a.endsWith(".yaml")||a.endsWith(".yml"))&&e.push(r)}return e.sort(),e}async function k(o){let s=l.join(o,".maestro");i.mkdirSync(s,{recursive:!0});let t=l.join(s,"login.yaml");return i.existsSync(t)?(console.error(` error: ${t} already exists`),1):(i.writeFileSync(t,`# sootsim maestro starter flow \u2014 drop-in compatible with the maestro cli.
53
- # run: bun sootsim maestro test .maestro/login.yaml
54
- appId: com.example.app
55
- ---
56
- - launchApp
57
- - tapOn:
58
- id: "email"
59
- - inputText: "user@example.com"
60
- - tapOn:
61
- id: "password"
62
- - inputText: "secret123"
63
- - tapOn: "Sign in"
64
- - assertVisible: "Welcome"
65
- `,"utf8"),console.log(` + wrote ${t}`),console.log(" next: bun sootsim maestro test .maestro/login.yaml"),0)}async function F(o,s={}){if(o.includes("--help")||o.includes("-h"))return v(),0;if(o.includes("--list-compat"))return x(),0;let t;try{t=S(o)}catch(n){return console.error(` error: ${n.message}`),1}t=$(t);let e=process.cwd(),a=t[0];if(a==="init")return k(e);let r=null,m;if(a==="test"){let n=t.slice(1).find(c=>!g(c));n?(r=l.resolve(e,n),m=t.slice(1).filter(c=>c!==n)):(r=y(e),m=t.slice(1))}else a&&!g(a)?(r=l.resolve(e,a),m=t.slice(1)):(r=y(e),m=t);if(!r)return console.error(`
66
- error: no maestro flows found.
67
- expected one of: ${w.map(n=>`./${n}/`).join(", ")}
68
- or pass a flow explicitly: bun sootsim maestro test path/to/flow.yaml
69
- or scaffold a starter flow: bun sootsim maestro init
70
- `),1;if(!i.existsSync(r))return console.error(` error: ${r} not found`),1;let u;try{u=E(r)}catch(n){return console.error(` error: ${n.message}`),1}if(u.length===0)return console.error(` error: no *.yaml or *.yml files found in ${r}`),1;console.log(`
71
- sootsim maestro \u2014 ${u.length} flow${u.length===1?"":"s"}
72
- root: ${l.relative(e,r)||"."}
73
- `);let d=0,f=[];for(let n of u){console.log(`
74
- \u25B6 ${l.relative(e,n)}`);let c=[n,...m];s.port&&!m.includes("--url")&&c.push("--url",String(s.port));let p=0;try{p=await h(c)}catch(b){console.error(` x ${b.message}`),p=1}f.push({file:n,exit:p}),p!==0&&d===0&&(d=p)}if(u.length>1){console.log(`
75
- maestro summary:`);for(let c of f){let p=c.exit===0?"pass":"fail";console.log(` ${p} ${l.relative(e,c.file)}`)}let n=f.filter(c=>c.exit===0).length;console.log(` ${n}/${f.length} passed`)}return d}export{F as runMaestro};
@@ -1,22 +0,0 @@
1
- /*! sootsim v0.1.36 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
- import{c as I,e as N,i as S}from"./chunk-SMVJOWSV.js";import"./chunk-6GGMKFWJ.js";import"./chunk-ZEW3RF5Q.js";import"./chunk-5QIUJNT3.js";import"./chunk-LHDWH7VS.js";import{createWriteStream as v,mkdirSync as k,writeFileSync as w}from"fs";import{dirname as T,resolve as x}from"path";import{Readable as y}from"stream";import{pipeline as C}from"stream/promises";import{createGzip as F}from"zlib";async function E(r,m){if(r.includes("--help")||r.includes("-h"))return console.log(`
3
- sootsim profile \u2014 capture a sampled CPU trace from the tenant worker
4
-
5
- usage:
6
- sootsim profile [options]
7
-
8
- options:
9
- --duration <seconds> recording duration (default: 5)
10
- --output <path> output file (default: /tmp/sootsim.cpuprofile)
11
- if the path ends in .gz, the output is gzipped
12
- --sample-interval <ms> requested sample interval in ms (default: 10 \u2014
13
- chrome may clamp upward)
14
- --max-buffer <n> max samples buffered (default: 100000)
15
- --session <tab-id> target a specific bridge tab
16
- --port <number> ws bridge port (default: 7668)
17
-
18
- examples:
19
- sootsim profile --duration 3
20
- sootsim profile --duration 10 --output /tmp/after.cpuprofile.gz
21
- sootsim profile --duration 3 -o /tmp/before.cpuprofile
22
- `),0;let n=Number(b(r,"--duration")??"5");if(!Number.isFinite(n)||n<=0)return console.error(" --duration must be a positive number (seconds)"),1;let l=Number(b(r,"--sample-interval")??"10");if(!Number.isFinite(l)||l<=0)return console.error(" --sample-interval must be a positive number (milliseconds)"),1;let s=Number(b(r,"--max-buffer")??"100000");if(!Number.isFinite(s)||s<=0)return console.error(" --max-buffer must be a positive number"),1;let p=b(r,"--output")??b(r,"-o"),a=x(process.cwd(),p??"/tmp/sootsim.cpuprofile"),g=a.endsWith(".gz"),h=I(r,{port:m.port,stripValueFlags:["--duration","--output","-o","--sample-interval","--max-buffer"]}),c=N({...h,commandTimeoutMs:Math.max(3e4,(n+20)*1e3)});try{let u=await S(c,"SootSim.bridges.workerCpuProfileStart",{sampleInterval:l,maxBufferSize:s});if(!u?.started)return console.error(" could not start tenant-worker profiler."),console.error(" is sootsim running? (try `bun sootsim list`)"),1;m.verbose&&console.error(` started: sampleInterval=${u.sampleInterval}ms buffer=${u.maxBufferSize}`),console.log(` recording for ${n}s\u2026`),await new Promise(o=>setTimeout(o,n*1e3));let t=await S(c,"SootSim.bridges.workerCpuProfileStop");if(!t||t.error||!t.trace)return console.error(` profile capture failed: ${t?.error??"no trace returned"}`),t?.error?.includes("not available")&&(console.error(" your browser or page is missing the JS Self-Profiler API."),console.error(" requires chromium-based browser and Document-Policy: js-profiling.")),1;let P=z(t.trace),e=JSON.stringify(P);k(T(a),{recursive:!0}),g?await C(y.from([e]),F(),v(a)):w(a,e);let i=(Buffer.byteLength(e)/1024/1024).toFixed(2);return console.log(` samples: ${P.samples.length} (${i} MB uncompressed)`),console.log(` saved: ${a}`),console.log(" open in chrome devtools \u2192 Performance \u2192 Load profile to inspect."),0}catch(u){let t=u?.message??String(u);return console.error(` profile failed: ${t}`),/could not connect|ECONNREFUSED/i.test(t)&&console.error(" is sootsim running? (try `bun sootsim list`)"),1}finally{c.close()}}function z(r){let m=r.frames??[],n=r.resources??[],l=r.stacks??[],s=r.samples??[],p=1,a=[{id:p,callFrame:{functionName:"(root)",scriptId:"0",url:"",lineNumber:-1,columnNumber:-1},hitCount:0,children:[]}];for(let e=0;e<l.length;e++){let i=l[e],o=m[i.frameId]??{name:"(unknown)"},f=o.resource!==void 0?n[o.resource]??"":"";a.push({id:e+2,callFrame:{functionName:o.name||"(anonymous)",scriptId:o.resource!==void 0?String(o.resource):"0",url:f,lineNumber:typeof o.line=="number"?o.line-1:-1,columnNumber:typeof o.column=="number"?o.column-1:-1},hitCount:0,children:[]})}for(let e=0;e<l.length;e++){let i=l[e],o=e+2,f=i.parentId!==void 0?i.parentId+2:p,d=a[f-1];d&&!d.children.includes(o)&&d.children.push(o)}let g=[],h=[],c=s.length>0?s[0].timestamp:0,u=c;for(let e=0;e<s.length;e++){let i=s[e],o=i.stackId!==void 0?i.stackId+2:p;g.push(o);let f=a[o-1];f&&f.hitCount++;let d=e===0?0:i.timestamp-u;h.push(Math.max(0,Math.round(d*1e3))),u=i.timestamp}let t=Math.round(c*1e3),P=s.length>0?Math.round(s[s.length-1].timestamp*1e3):t;return{nodes:a,startTime:t,endTime:P,samples:g,timeDeltas:h}}function b(r,m){let n=r.indexOf(m);if(!(n<0||n===r.length-1))return r[n+1]}export{E as runProfile};
@@ -1,26 +0,0 @@
1
- /*! sootsim v0.1.36 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
- import{a as x}from"./chunk-YIO6S3R5.js";import{a as v}from"./chunk-EWSQSALM.js";import"./chunk-5KGFHWVR.js";import"./chunk-RMW5BO3S.js";import"./chunk-NIZBR7EK.js";import{f}from"./chunk-6Z275LCY.js";import{c as h,d as g,e as w,h as y}from"./chunk-SMVJOWSV.js";import"./chunk-6GGMKFWJ.js";import"./chunk-ZEW3RF5Q.js";import"./chunk-5QIUJNT3.js";import"./chunk-LHDWH7VS.js";import{mkdirSync as _,writeFileSync as S}from"fs";import{dirname as R,resolve as B}from"path";async function V(e,t){(e.includes("--help")||e.includes("-h"))&&(console.log(`
3
- sootsim screenshot \u2014 capture the canvas as a PNG
4
-
5
- usage:
6
- sootsim screenshot [options]
7
-
8
- options:
9
- --output <path> output file path (default: /tmp/sootsim-inspect.png)
10
- --with-frame wrap the captured screen in a tight device frame
11
- --no-frame capture the raw screen bitmap (default)
12
- --no-shell exclude the simulated iOS chrome (status bar, keyboard,
13
- toasts) \u2014 captures the tenant surfaces only
14
- --shell-only capture only the shell chrome, no tenant content
15
- --area x,y,w,h crop to a logical sootsim rect
16
- --id <testID> crop to a node's bounding box
17
- --text <text> crop to a node found by text content
18
- --gallery crawl and capture multiple screens as HTML gallery
19
- --themes capture light and dark variants
20
-
21
- examples:
22
- sootsim screenshot
23
- sootsim screenshot --with-frame --output framed.png
24
- sootsim screenshot --area 0,200,393,400 --output hero.png
25
- sootsim screenshot --id loginButton --output button.png
26
- `),process.exit(0));let o=D(e);if(o.length>0){for(let{flag:u,suggestion:d}of o)console.error(d?` unknown flag: ${u} (did you mean ${d}?)`:` unknown flag: ${u}`);console.error(" run `sootsim screenshot --help` for the list of supported flags"),process.exit(1)}let a=e.includes("--gallery"),i=e.includes("--themes"),r=M(e),l=P(e);if(a||i)return r&&(console.error(" --with-frame is not supported with --gallery / --themes"),process.exit(1)),b(e,t);r&&e.some(u=>u==="--area"||u==="--id"||u==="--text")&&(console.error(" --with-frame only supports full-screen capture for now"),console.error(" remove --area / --id / --text, or capture raw and compose later"),process.exit(1));let n=h(e,{port:t.port,stripBooleanFlags:["--with-frame","--no-frame","--no-shell","--shell-only"],stripValueFlags:["--output","--area","--id","--text"]}),s=e.find((u,d)=>e[d-1]==="--output"),c=await A(e);if(await E(n.wsPort)){await O(n,s,c,r,l);return}r&&(console.error(" --with-frame requires a running sootsim bridge"),console.error(" open the app in a live sootsim session first, then rerun the command"),process.exit(1)),c&&(console.error(" --area / --id / --text require a running sootsim bridge"),console.error(" start one with `sootsim server`, `sootsim electron`, or your project dev server"),process.exit(1)),await b(e,t)}async function E(e){let t=g(e,{commandTimeoutMs:1e3});try{return await t.listBrowsers(),!0}catch{return!1}finally{t.close()}}async function A(e){let t=e.find((i,r)=>e[r-1]==="--area");if(t){let i=t.split(",").map(c=>Number(c.trim()));if(i.length!==4||i.some(c=>!Number.isFinite(c)))throw new Error(`--area expects x,y,w,h (got "${t}")`);let[r,l,n,s]=i;return{x:r,y:l,w:n,h:s}}let o=e.find((i,r)=>e[r-1]==="--id"),a=e.find((i,r)=>e[r-1]==="--text");return o||a?{__matcher:{id:o,text:a}}:null}async function O(e,t,o,a,i){let r=w({...e,commandTimeoutMs:1e4});try{let l=o,n=o?.__matcher;if(n){let p=await r.send({type:"evaluate",code:x(n)});if(!p)throw new Error(n.id?`no node with id "${n.id}"`:`no node matching text "${n.text}"`);l=p}let s=l?{x:l.x,y:l.y,w:l.w,h:l.h}:void 0,c={type:"screenshot"};i&&(c.layers=i),s&&(c.crop=s);let u=(await r.send(c)).replace(/^data:image\/png;base64,/,"");s&&console.log(` area: x=${s.x} y=${s.y} w=${s.w} h=${s.h}`),i&&console.log(` layers: ${i}`);let d=B(process.cwd(),t||"/tmp/sootsim-inspect.png");_(R(d),{recursive:!0});let m=Buffer.from(u,"base64");if(a){let p=await T(r);if(!p)throw new Error("could not read current device model from the target session");let $=await v(m,p);S(d,$),console.log(` frame: ${p}`)}else S(d,m);console.log(` saved: ${d}`)}finally{r.close()}}async function T(e){let t=await y(e,"SootSim.bridges.settings.get")??{deviceModel:null},o=typeof t.deviceModel=="string"?t.deviceModel:null;return!o||!(o in f)?null:o}function M(e){let t=!1;for(let o of e)o==="--with-frame"&&(t=!0),o==="--no-frame"&&(t=!1);return t}function P(e){if(e.includes("--shell-only"))return"shell";if(e.includes("--no-shell"))return"tenant"}var k=new Set(["--help","-h","--verbose","-v","--with-frame","--no-frame","--no-shell","--shell-only","--gallery","--themes"]),L=new Set(["--output","--area","--id","--text","--url","--port","--timeout","--session","--tab"]),N={"--rect":"--area","--crop":"--area","--region":"--area","--bounds":"--area","--box":"--area","--xywh":"--area","--out":"--output","-o":"--output","--file":"--output","--path":"--output","--testid":"--id","--test-id":"--id","--test_id":"--id"};function D(e){let t=[];for(let o=0;o<e.length;o++){let a=e[o];if(a.startsWith("-")){if(L.has(a)){o++;continue}k.has(a)||t.push({flag:a,suggestion:N[a]})}}return t}async function b(e,t){let o=e.find((n,s)=>e[s-1]==="--output")||"sootsim-screenshot.png",a=e.includes("--gallery"),i=e.find((n,s)=>e[s-1]==="--url")||`http://localhost:${t.port||5173}`,{chromium:r}=await import("playwright"),l=await r.launch({headless:!0});try{if(a)console.log(" capturing gallery..."),console.log(" (gallery mode not yet implemented)");else{let n=await l.newPage({viewport:{width:500,height:900}});await n.goto(i,{waitUntil:"networkidle"}),await n.waitForTimeout(2e3);let s=B(process.cwd(),o);_(R(s),{recursive:!0}),await n.screenshot({path:s}),console.log(` saved: ${s}`),await n.close()}}catch(n){console.error(` screenshot failed: ${n.message}`),process.exit(1)}finally{await l.close()}}export{V as runScreenshot};
@@ -1,17 +0,0 @@
1
- /*! sootsim v0.1.36 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
- import{c,e as i,h as d}from"./chunk-SMVJOWSV.js";import"./chunk-6GGMKFWJ.js";import"./chunk-ZEW3RF5Q.js";import"./chunk-5QIUJNT3.js";import"./chunk-LHDWH7VS.js";async function g(o,l){(o.includes("--help")||o.includes("-h"))&&(console.log(`
3
- sootsim screenshot-mode \u2014 toggle the screenshot-mode chrome overlay
4
-
5
- usage:
6
- sootsim screenshot-mode [on|off|toggle]
7
-
8
- arguments:
9
- on enable screenshot mode (enables showFrame if needed)
10
- off disable screenshot mode
11
- toggle flip the current state (default)
12
-
13
- examples:
14
- sootsim screenshot-mode
15
- sootsim screenshot-mode on
16
- sootsim screenshot-mode off
17
- `),process.exit(0));let r=c(o,{port:l.port}),e=r.positional[0]?.toLowerCase()??"toggle";e!=="on"&&e!=="off"&&e!=="toggle"&&(console.error(` unknown argument: "${e}" (expected on | off | toggle)`),process.exit(1));let s=i({...r,commandTimeoutMs:5e3});try{let t=!!(await d(s,"SootSim.bridges.settings.get"))?.screenshotMode,n=e==="on"?!0:e==="off"?!1:!t;if(t===n){console.log(` screenshot-mode: already ${n?"on":"off"}`);return}await s.send({type:"evaluate",code:"window.dispatchEvent(new CustomEvent('sootsim:shell-command', { detail: { type: 'fire-action', id: 'toggle-screenshot-mode' } }))"}),console.log(` screenshot-mode: ${t?"on":"off"} \u2192 ${n?"on":"off"}`)}finally{s.close()}}export{g as runScreenshotMode};
@@ -1,70 +0,0 @@
1
- /*! sootsim v0.1.36 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
- import{c as Y}from"./chunk-NYY36OKU.js";import"./chunk-DFN3GGH7.js";import"./chunk-HWFHBMAQ.js";import{b as j}from"./chunk-EWSQSALM.js";import"./chunk-5KGFHWVR.js";import{b as O}from"./chunk-HWCKZXNJ.js";import"./chunk-H2QO4TDV.js";import"./chunk-3UIWOHC2.js";import"./chunk-YLIIVTTQ.js";import"./chunk-RMW5BO3S.js";import"./chunk-NIZBR7EK.js";import{a as w,b as D,c as k,d as z,e as x,f as T}from"./chunk-6Z275LCY.js";import"./chunk-IJMYFYDZ.js";import"./chunk-EJLNUMMP.js";import"./chunk-75LBYBKW.js";import"./chunk-GW7XY5KC.js";import"./chunk-OXN2PEB7.js";import"./chunk-YR7BGGYE.js";import"./chunk-PJL25JQV.js";import"./chunk-G663654J.js";import"./chunk-A5BRCXYE.js";import"./chunk-SHO54NET.js";import"./chunk-SMVJOWSV.js";import"./chunk-6GGMKFWJ.js";import"./chunk-ZEW3RF5Q.js";import"./chunk-5QIUJNT3.js";import"./chunk-LHDWH7VS.js";import{mkdirSync as B,readFileSync as pe,writeFileSync as G}from"fs";import{tmpdir as je}from"os";import C from"path";import{mkdirSync as I,readFileSync as Q,writeFileSync as H}from"fs";import F from"path";function _(e){return e.replace(/\\/g,"/").replace(/\.png$/i,"").trim().split("/").filter(Boolean).join("--").replace(/[^A-Za-z0-9-]+/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")||"slide"}function v(e){return e.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll('"',"&quot;")}function ee(e){let t=e.trim();return/^#[0-9a-f]{3}$/i.test(t)?`#${t[1]}${t[1]}${t[2]}${t[2]}${t[3]}${t[3]}`:t}function M(e,t){let r=ee(e),i=Math.max(0,Math.min(1,t)),n=r.match(/^#([0-9a-f]{6})$/i);if(n){let s=n[1],o=Number.parseInt(s.slice(0,2),16),a=Number.parseInt(s.slice(2,4),16),u=Number.parseInt(s.slice(4,6),16);return`rgba(${o}, ${a}, ${u}, ${i})`}return r.startsWith("rgb(")?r.replace(/^rgb\((.+)\)$/i,`rgba($1, ${i})`):r}function te(e){if(e.type==="solid")return e.color||"#000000";let t=e.direction??180,r=e.stops?.map(i=>`${i.color} ${i.offset}%`).join(", ")||"#000000 0%, #111111 100%";return`linear-gradient(${t}deg, ${r})`}function oe(e){let t=e.glow;return t?`radial-gradient(circle at 50% 24%, ${M(t,.46)} 0%, ${M(t,.2)} 24%, rgba(0,0,0,0) 62%)`:"none"}function A(e){switch(e){case"tilted-left":return"perspective(2400px) rotateY(10deg) rotateZ(-2deg)";case"tilted-right":return"perspective(2400px) rotateY(-10deg) rotateZ(2deg)";case"cut-bottom":return"translateY(10%) scale(1.08)";case"cut-top":return"translateY(-16%) scale(1.08)";default:return"none"}}function L(...e){let t=e.map(r=>r.trim()).filter(r=>r.length>0&&r!=="none");return t.length>0?t.join(" "):"none"}function E(e){let t=M(e.color,e.opacity),r=M(e.color,e.opacity*.52);return`drop-shadow(0 34px ${e.spread}px ${r}) drop-shadow(0 0 ${e.blur}px ${t})`}function R(e,t){return!t.glow||e.color&&e.color!==w.color?e:{...e,color:t.glow}}function re(e,t){if(e==="editorial-left"){let n=Math.round(t.height*.056),s=Math.round(t.height*.022);return{copyStyle:["position:absolute",`top:${Math.round(t.height*.12)}px`,`left:${Math.round(t.width*.085)}px`,`width:${Math.round(t.width*.42)}px`,"text-align:left","z-index:3"].join(";"),titleStyle:`font-size:${n}px;line-height:0.92;`,subStyle:`font-size:${s}px;line-height:1.36;max-width:${Math.round(t.width*.36)}px;`,eyebrowStyle:"align-items:flex-start;",deviceStyle:(o,a,u)=>{let p=Math.round(t.width*.68*(a.scale??o.scale)),l=Math.round(t.height*(.03+o.offsetY+(a.offsetY??0))),c=a.pose||o.pose||"tilted-right",m=R(o.shadow,u);return["position:absolute",`top:${Math.round(t.height*.18)+l}px`,`left:${Math.round(t.width*.56)}px`,`width:${p}px`,"transform-origin:center center",`transform:${A(c)}`,`filter:${E(m)}`,"z-index:2"].join(";")}}}if(e==="minimal-bottom"){let n=Math.round(t.height*.041),s=Math.round(t.height*.019);return{copyStyle:["position:absolute",`left:${Math.round(t.width*.12)}px`,`right:${Math.round(t.width*.12)}px`,`bottom:${Math.round(t.height*.085)}px`,"text-align:center","z-index:3"].join(";"),titleStyle:`font-size:${n}px;line-height:0.96;`,subStyle:`font-size:${s}px;line-height:1.34;max-width:${Math.round(t.width*.56)}px;margin:0 auto;`,eyebrowStyle:"align-items:center;",deviceStyle:(o,a,u)=>{let p=Math.round(t.width*.84*(a.scale??o.scale)),l=Math.round(t.height*(o.offsetY+(a.offsetY??0))),c=a.pose||o.pose,m=R(o.shadow,u);return["position:absolute",`top:${Math.round(t.height*.075)+l}px`,"left:50%",`width:${p}px`,"transform-origin:center center",`transform:${L("translateX(-50%)",A(c))}`,`filter:${E(m)}`,"z-index:2"].join(";")}}}let r=Math.round(t.height*.04),i=Math.round(t.height*.019);return{copyStyle:["position:absolute",`top:${Math.round(t.height*.084)}px`,"left:50%",`width:${Math.round(t.width*.88)}px`,"transform:translateX(-50%)","text-align:center","z-index:3"].join(";"),titleStyle:`font-size:${r}px;line-height:0.92;`,subStyle:`font-size:${i}px;line-height:1.34;max-width:${Math.round(t.width*.6)}px;margin:0 auto;`,eyebrowStyle:"align-items:center;",deviceStyle:(n,s,o)=>{let a=t.name==="ipad-13"?.54:.64,u=Math.round(t.width*a*(s.scale??n.scale)),p=Math.round(t.height*(n.offsetY+(s.offsetY??0))),l=s.pose||n.pose,c=R(n.shadow,o);return["position:absolute",`top:${Math.round(t.height*(t.name==="ipad-13"?.25:.28))+p}px`,"left:50%",`width:${u}px`,"transform-origin:center top",`transform:${L("translateX(-50%)",A(l))}`,`filter:${E(c)}`,"z-index:2"].join(";")}}}function ne({canvas:e,compose:t,slide:r,imageDataUrl:i}){let n=r.background??t.background,s=re(t.text.preset,e),o=t.text.preset!=="none"&&!!(r.eyebrow||r.headline||r.subheadline),a=s.deviceStyle(t.frame,r,n),u=r.headline?`<div style="font-weight:780;white-space:pre-line;text-wrap:balance;${s.titleStyle}">${v(r.headline)}</div>`:"",p=r.subheadline?`<div style="margin-top:${Math.round(e.height*.018)}px;color:${t.text.subColor};white-space:pre-line;text-wrap:balance;${s.subStyle}">${v(r.subheadline)}</div>`:"",l=r.eyebrow?`<div style="display:flex;${s.eyebrowStyle}margin-bottom:${Math.round(e.height*.016)}px;"><div style="font-size:${Math.round(e.height*.014)}px;font-weight:700;letter-spacing:0.18em;text-transform:uppercase;color:${t.text.eyebrowColor};">${v(r.eyebrow)}</div></div>`:"";return`<!doctype html>
3
- <html>
4
- <head>
5
- <meta charset="utf-8" />
6
- <style>
7
- html, body {
8
- margin: 0;
9
- width: ${e.width}px;
10
- height: ${e.height}px;
11
- overflow: hidden;
12
- background: transparent;
13
- }
14
- body {
15
- font-family: "SF Pro Display", "Helvetica Neue", system-ui, sans-serif;
16
- }
17
- #canvas {
18
- position: relative;
19
- width: ${e.width}px;
20
- height: ${e.height}px;
21
- overflow: hidden;
22
- background: ${te(n)};
23
- color: ${t.text.color};
24
- isolation: isolate;
25
- }
26
- #glow {
27
- position: absolute;
28
- inset: 0;
29
- background: ${oe(n)};
30
- pointer-events: none;
31
- }
32
- #copy {
33
- ${s.copyStyle};
34
- }
35
- #device {
36
- ${a};
37
- }
38
- #device img {
39
- display: block;
40
- width: 100%;
41
- height: auto;
42
- }
43
- </style>
44
- </head>
45
- <body>
46
- <div id="canvas">
47
- <div id="glow"></div>
48
- ${o?`<div id="copy">${l}${u}${p}</div>`:""}
49
- <div id="device"><img src="${i}" alt="" /></div>
50
- </div>
51
- </body>
52
- </html>`}async function U(e,t,r){let i=[],n=r??await(async()=>{let{chromium:o}=await import("playwright");return o.launch({headless:!0})})();try{let o=await n.newContext({viewport:{width:1280,height:720}});try{for(let a of t){let p=`data:image/png;base64,${Q(a.imagePath).toString("base64")}`;for(let l of e.canvases){let c=await o.newPage();try{await c.setViewportSize({width:l.width,height:l.height}),await c.setContent(ne({canvas:l,compose:e,slide:a.slide,imageDataUrl:p}),{waitUntil:"load"}),await c.waitForTimeout(20);let m=F.join(e.outDir,l.name,e.locale);I(m,{recursive:!0});let f=F.join(m,`${a.slide.assetKey}.png`),P=await c.screenshot({type:"png",clip:{x:0,y:0,width:l.width,height:l.height}});H(f,P),i.push({slideId:a.slide.id,canvas:l.name,locale:e.locale,outputPath:f,sourcePath:a.imagePath})}finally{await c.close()}}}}finally{await o.close()}}finally{!r&&typeof n.close=="function"&&await n.close()}I(e.outDir,{recursive:!0});let s=F.join(e.outDir,"manifest.json");return H(s,JSON.stringify({generatedAt:new Date().toISOString(),locale:e.locale,outputs:i},null,2)),{manifestPath:s,outputs:i.map(o=>o.outputPath),entries:i}}import{readFileSync as se}from"fs";import y from"path";function d(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function $(e,t){if(!d(e))throw new Error(`${t} must be an object`);return e}function h(e,t=""){return typeof e=="string"?e:t}function g(e){return typeof e=="string"&&e.trim().length>0?e.trim():null}function K(e,t){return typeof e=="boolean"?e:t}function S(e,t){return typeof e=="number"&&Number.isFinite(e)?e:t}function q(e,t){return typeof e!="string"||e.trim().length===0?t:Object.prototype.hasOwnProperty.call(T,e)?e:null}function W(e,t){if(typeof e=="string"){let n=x(e);if(!n)throw new Error(`unknown background preset: ${e}`);return n}if(!d(e))return z(t);let r=e.type==="solid"||e.type==="gradient"?e.type:t.type;if(r==="solid")return{type:r,color:h(e.color,t.color??"#000000"),glow:g(e.glow)??t.glow};let i=Array.isArray(e.stops)?e.stops.map(n=>{if(!d(n))return null;let s=S(n.offset,Number.NaN),o=g(n.color);return!Number.isFinite(s)||!o?null:{offset:s,color:o}}).filter(n=>!!n):t.stops?.map(n=>({...n}))??[];return{type:r,direction:S(e.direction,t.direction??180),glow:g(e.glow)??t.glow,stops:i.length>0?i:t.stops?.map(n=>({...n}))??[]}}function ie(e){let r=(Array.isArray(e)?e:["iphone-6-9"]).map(i=>{if(typeof i!="string")throw new Error("compose.canvases entries must be strings");let n=k(i);if(!n)throw new Error(`unknown canvas preset: ${i}`);return n});if(r.length===0)throw new Error("compose.canvases must include at least one preset");return r}function ae(e){switch(e){case"editorial-left":case"minimal-bottom":case"none":case"bold-top":return e;default:return"bold-top"}}function ce(e){switch(e){case"plan":case"flow":case"auto":return e;default:return"auto"}}function X(e){switch(e){case"straight":case"tilted-left":case"tilted-right":case"cut-bottom":case"cut-top":return e;default:return}}function b(e,t){return y.isAbsolute(t)?t:y.resolve(e,t)}function le(e,t){if(!Array.isArray(e)||e.length===0)throw new Error("compose.slides must be a non-empty array");return e.map((r,i)=>{let n=$(r,`compose.slides[${i}]`),s=g(n.screenshot);if(!s)throw new Error(`compose.slides[${i}].screenshot is required`);let o=g(n.id),a=_(o||s);return{id:o||a,assetKey:a,screenshot:s,headline:h(n.headline),subheadline:h(n.subheadline),eyebrow:h(n.eyebrow),pose:X(n.pose),scale:typeof n.scale=="number"&&Number.isFinite(n.scale)?n.scale:void 0,offsetY:typeof n.offsetY=="number"&&Number.isFinite(n.offsetY)?n.offsetY:void 0,background:n.theme||n.background?W(n.theme??n.background,t):void 0}})}function V(e){let t=y.resolve(e),r=y.dirname(t),i=O.parse(se(t,"utf8")),n=$(i,"screenshots plan"),s=$(n.capture??{},"capture"),o=$(n.compose??{},"compose"),a=typeof n.app=="number"?String(n.app):g(n.app),u=q(n.device,null),p=b(r,h(s.out,y.join(".sootsim","screenshots","capture"))),l=g(s.from),c=g(s.flow);if(!l&&!c)throw new Error("capture.flow or capture.from is required");let m=s.mode==="raw"||s.mode==="framed"||s.mode==="raw+framed"?s.mode:"raw+framed",f=ce(s.pathMode),P=W(o.background??"cyan",x("cyan")),J={show:K(o.frame&&d(o.frame)?o.frame.show:void 0,!0),style:q(o.frame&&d(o.frame)?o.frame.style:null,null)||u||D,pose:X(o.frame&&d(o.frame)?o.frame.pose:void 0)||"straight",scale:S(o.frame&&d(o.frame)?o.frame.scale:void 0,1),offsetY:S(o.frame&&d(o.frame)?o.frame.offsetY:void 0,0),shadow:{color:h(o.frame&&d(o.frame)&&d(o.frame.shadow)?o.frame.shadow.color:void 0,w.color),blur:S(o.frame&&d(o.frame)&&d(o.frame.shadow)?o.frame.shadow.blur:void 0,w.blur),spread:S(o.frame&&d(o.frame)&&d(o.frame.shadow)?o.frame.shadow.spread:void 0,w.spread),opacity:S(o.frame&&d(o.frame)&&d(o.frame.shadow)?o.frame.shadow.opacity:void 0,w.opacity)}};return{planPath:t,planDir:r,appTarget:a,deviceModel:u,capture:{flowPath:c?b(r,c):null,fromDir:l?b(r,l):null,outDir:p,rawDir:l?b(r,l):y.join(p,"raw"),framedDir:y.join(p,"framed"),mode:m,pathMode:f,sessionId:g(s.session),openInNewSession:K(s.new,!1)},compose:{outDir:b(r,h(o.out,y.join(".sootsim","screenshots","exports"))),locale:h(o.locale,"en"),canvases:ie(o.canvases),frame:J,background:P,text:{preset:ae(o.text&&d(o.text)?o.text.preset:void 0),color:h(o.text&&d(o.text)?o.text.color:void 0,"#ffffff"),subColor:h(o.text&&d(o.text)?o.text.subColor:void 0,"rgba(232,240,247,0.86)"),eyebrowColor:h(o.text&&d(o.text)?o.text.eyebrowColor:void 0,"rgba(229,242,255,0.72)")},slides:le(o.slides,P)}}}function ue(e){return e.capture.pathMode==="plan"||e.capture.pathMode==="flow"?e.capture.pathMode:e.capture.fromDir?"flow":"plan"}function de(e,t){if(!e.capture.flowPath)throw new Error("capture flow path is required to build flow args");let r=[e.capture.flowPath],i=ue(e);r.push("--screenshots",e.capture.rawDir),i==="flow"&&r.push("--screenshot-paths","flow");let n=t.appTarget??e.appTarget,s=t.deviceModel??e.deviceModel,o=t.sessionId??e.capture.sessionId;return n&&r.push("--url",n),s&&r.push("--device",s),o&&r.push("--session",o),e.capture.openInNewSession&&r.push("--new"),r}function N(e,t){return C.isAbsolute(t)?t:C.join(e.capture.rawDir,t)}function me(e){return C.join(e.capture.outDir,"manifest.json")}async function he(e,t){if(!e.capture.flowPath)return;B(e.capture.rawDir,{recursive:!0});let r=de(e,t),i=await Y(r);if(i!==0)throw new Error(`flow capture failed with exit code ${i}`)}async function fe(e,t){let r=new Map;B(e.capture.framedDir,{recursive:!0});let i=t??await(async()=>{let{chromium:n}=await import("playwright");return n.launch({headless:!0})})();try{let n=await j(i);try{for(let s of e.compose.slides){let o=N(e,s.screenshot),a=pe(o),u=await n.compose(a,e.compose.frame.style),p=C.join(e.capture.framedDir,`${s.assetKey}.png`);G(p,u),r.set(s.id,p)}}finally{await n.close()}}finally{!t&&typeof i.close=="function"&&await i.close()}return r}function ge(e,t,r){let i=[],n=[];B(e.capture.outDir,{recursive:!0});let s=me(e),o=e.compose.slides.map(a=>{let u=N(e,a.screenshot),p=t.get(a.id)??null;return i.push(u),p&&n.push(p),{id:a.id,screenshot:a.screenshot,rawPath:u,framedPath:p}});return G(s,JSON.stringify({generatedAt:new Date().toISOString(),deviceModel:r,mode:e.capture.mode,rawDir:e.capture.rawDir,framedDir:e.capture.framedDir,slides:o},null,2)),{manifestPath:s,rawDir:e.capture.rawDir,framedDir:e.capture.framedDir,rawFiles:i,framedFiles:n}}function we(e,t){return e.compose.slides.map(r=>({slide:r,imagePath:e.compose.frame.show===!0?t.get(r.id)??N(e,r.screenshot):N(e,r.screenshot)}))}async function Z(e,t={}){let r=V(e),i=t.deviceModel??r.deviceModel;t.composeOnly||await he(r,t);let n=r.capture.mode!=="raw"||!t.captureOnly&&r.compose.frame.show===!0,o=n||!t.captureOnly?await(async()=>{let{chromium:a}=await import("playwright");return a.launch({headless:!0})})():null;try{let a=n?await fe(r,o??void 0):new Map,u=ge(r,a,i);if(t.captureOnly)return{plan:r,capture:u,compose:null};let p=we(r,a),l=await U(r.compose,p,o??void 0);return{plan:r,capture:u,compose:l}}finally{o&&typeof o.close=="function"&&await o.close()}}async function qe(e,t={}){if(e.includes("--help")||e.includes("-h"))return console.log(`
53
- sootsim screenshots \u2014 capture and compose app-store screenshot sets
54
-
55
- usage:
56
- sootsim screenshots --plan <plan.yaml> [options]
57
-
58
- options:
59
- --plan <path> screenshot plan yaml
60
- --session <id> reuse a live sootsim session for capture
61
- --app <target> override plan app target (port, url, or shell url)
62
- --device <model> override plan capture device for this run
63
- --capture-only stop after raw/framed intermediates
64
- --compose-only skip flow capture, reuse existing raw screenshots
65
-
66
- examples:
67
- sootsim screenshots --plan app-store.yaml
68
- sootsim screenshots --plan app-store.yaml --session tab-9
69
- sootsim screenshots --plan app-store.yaml --device iphone-14
70
- `),0;let r=c=>e.find((m,f)=>e[f-1]===c),i=new Set(["--plan","--session","--app","--device"]),n=e.filter((c,m)=>{if(c.startsWith("-"))return!1;let f=e[m-1];return!f||!i.has(f)}),s=r("--plan")||n[0];if(!s)return console.error(" error: screenshots plan path is required (`--plan <path>`)."),1;let o=r("--session")?.trim()||null,a=r("--app")?.trim()||null,u=r("--device")?.trim()||null,p=e.includes("--capture-only"),l=e.includes("--compose-only");try{let c=await Z(s,{sessionId:o,appTarget:a,deviceModel:u,captureOnly:p,composeOnly:l});return console.log(` capture manifest: ${c.capture.manifestPath}`),c.compose?(console.log(` compose manifest: ${c.compose.manifestPath}`),console.log(` exports: ${c.compose.outputs.length}`)):console.log(" compose skipped"),0}catch(c){return console.error(` screenshots failed: ${c.message}`),1}}export{qe as runScreenshots};
@@ -1,34 +0,0 @@
1
- /*! sootsim v0.1.36 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
- import{b as V,c as O,d as q,e as R,f as G,h as z,i as w,j as Y,k as X,l as Z,p as Q,s as b,t as ee,u as te,v as re,w as ie}from"./chunk-FE7UI3MT.js";import"./chunk-KAXZHEKM.js";import{a as J}from"./chunk-DFN3GGH7.js";import"./chunk-H2QO4TDV.js";import{e as H}from"./chunk-G7XQD4KC.js";import{a as $,b as j}from"./chunk-IJMYFYDZ.js";import"./chunk-EJLNUMMP.js";import"./chunk-GW7XY5KC.js";import{d as K}from"./chunk-A5BRCXYE.js";import"./chunk-ZEW3RF5Q.js";import{A as x,q as A,r as N,s as _,t as L,v as D,w as U,x as M,y as F,z as W}from"./chunk-5QIUJNT3.js";import"./chunk-LHDWH7VS.js";import{spawn as le}from"child_process";import v from"fs";import{createServer as ue}from"http";import y from"path";import{WebSocket as f,WebSocketServer as pe}from"ws";import se from"node:fs";import C from"node:path";var T=1;function ce(){return[Number(process.env.VITE_PORT_WEB||process.env.PORT||3e3),Number(process.env.VITE_PORT_ZERO||7849),Number(process.env.VITE_PORT_POSTGRES||7432),Number(process.env.VITE_PORT_R2||9500)].filter(h=>Number.isFinite(h)&&h>0)}var E=class{subscriptions=new Map;sessionsBySocket=new Map;allSockets=new Set;pendingPromptEchoes=new Map;pendingTurns=new Map;opts;constructor(e={}){this.opts=e}registerSocket(e){this.allSockets.add(e)}unregisterSocket(e){let t=this.sessionsBySocket.get(e);if(t){for(let r of t)this.decrementSubscription(r);this.sessionsBySocket.delete(e)}this.allSockets.delete(e)}async handleMessage(e,t){let r=t?.type;if(typeof r!="string"||!r.startsWith("agent:"))return!1;let o=t.id;try{let s=await this.dispatch(e,r,t);this.respond(e,o,s)}catch(s){s instanceof b?this.respondError(e,o,s.message,s.code):this.respondError(e,o,s instanceof Error?s.message:String(s))}return!0}async seedOnBoot(){try{await Z()}catch(e){process.stderr.write(`[sootsim-agent] seedFromDemoAppRegistry failed: ${e instanceof Error?e.message:String(e)}
3
- `)}}close(){for(let e of this.subscriptions.values())try{e.unsubscribe()}catch{}this.subscriptions.clear(),this.sessionsBySocket.clear(),this.allSockets.clear()}async dispatch(e,t,r){switch(t){case"agent:list-projects":return R();case"agent:upsert-project":return O(r.input??{});case"agent:delete-project":return z(String(r.projectId)),{ok:!0};case"agent:auto-attach-for-url":return this.autoAttachForUrl(r.input??{});case"agent:list-sessions":return Y(r.projectId?String(r.projectId):void 0);case"agent:start-session":return this.doStartSession(r.input??{});case"agent:send-prompt":{let s=String(r.sessionId),n=w(s);if(!n)throw new b("NO_SESSION",`no session: ${s}`);let i=this.normalizePromptEnvelope(r);return await te(s,i),this.notePromptAccepted(s,i,n.status==="working")}case"agent:end-session":this.dropSessionFanout(String(r.sessionId)),await re(String(r.sessionId));let o=w(String(r.sessionId));return o&&this.broadcastSessionStatus(o),{ok:!0};case"agent:get-transcript":return this.getTranscript(String(r.sessionId));case"agent:get-paths":return this.getPaths();case"agent:subscribe-events":return this.subscribeSocket(e,String(r.sessionId));case"agent:unsubscribe-events":return this.unsubscribeSocket(e,String(r.sessionId));default:throw new b("UNKNOWN_AGENT_MSG",`unknown agent message: ${t}`)}}async doStartSession(e){if(!q(e.projectId))throw new b("NO_PROJECT",`no project: ${e.projectId}`);let r=await ee(e);return this.broadcastSessionStatus(r.session),r}async autoAttachForUrl(e){let t=e.bundleUrl??"",r=(()=>{try{return new URL(t).port||null}catch{return null}})();if(!r)return{project:null};let o=this.opts.getExcludePorts?.()??ce(),n=(await J({excludePorts:o})).find(d=>String(d.port)===r);if(!n||!n.cwd)return{project:null};let i=R().find(d=>d.cwd===n.cwd)??null,a=Array.from(new Set([...i?.knownBundleUrls??[],n.bundleUrl,t]));return{project:O({cwd:n.cwd,name:n.projectName??C.basename(n.cwd),preferredProvider:e.provider??i?.preferredProvider,sourceRoots:i?.sourceRoots??[n.cwd],knownBundleUrls:a,framework:i?.framework??de(n.framework),bundleId:n.bundleId??i?.bundleId})}}getTranscript(e){let t=Q(e);return se.existsSync(t)?se.readFileSync(t,"utf8"):{error:"transcript not found",code:"NO_TRANSCRIPT"}}getPaths(){let e=V();return{userDataDir:e,storeFile:C.join(e,"attached-projects.json"),sessionsDir:C.join(e,"sessions"),transcriptsDir:C.join(e,"transcripts")}}subscribeSocket(e,t){let r=this.sessionsBySocket.get(e);if(r||(r=new Set,this.sessionsBySocket.set(e,r)),r.has(t))return{ok:!0,refCount:this.subscriptions.get(t)?.refCount??1};r.add(t);let o=this.subscriptions.get(t);if(o)return o.refCount++,{ok:!0,refCount:o.refCount};let s=ie(t,n=>{let i=this.coalescePromptEcho(t,n);if(i&&(this.applySessionEvent(t,i),this.fanOutEvent(t,i)),n.type==="turn-completed"){let a=w(t);if(a)try{G(a.projectId,{usd:n.costUsd,ts:n.ts})}catch(c){process.stderr.write(`[sootsim-agent] recordTurnTelemetry failed: ${c instanceof Error?c.message:String(c)}
4
- `)}}});return this.subscriptions.set(t,{unsubscribe:s,refCount:1}),{ok:!0,refCount:1}}unsubscribeSocket(e,t){let r=this.sessionsBySocket.get(e);return!r||!r.has(t)?{ok:!0,refCount:0}:(r.delete(t),this.decrementSubscription(t))}decrementSubscription(e){let t=this.subscriptions.get(e);if(!t)return{ok:!0,refCount:0};if(t.refCount--,t.refCount<=0){try{t.unsubscribe()}catch{}return this.subscriptions.delete(e),{ok:!0,refCount:0}}return{ok:!0,refCount:t.refCount}}dropSessionFanout(e){let t=this.subscriptions.get(e);if(t){try{t.unsubscribe()}catch{}this.subscriptions.delete(e)}for(let r of this.sessionsBySocket.values())r.delete(e);this.clearPromptTracking(e)}normalizePromptEnvelope(e){if(e?.prompt&&typeof e.prompt=="object"){let t=e.prompt;return{text:String(t.text??""),...typeof t.displayText=="string"?{displayText:t.displayText}:{},...typeof t.inspectSummary=="string"?{inspectSummary:t.inspectSummary}:{},...typeof t.inspectTrace=="string"?{inspectTrace:t.inspectTrace}:{}}}return{text:String(e?.text??""),...typeof e?.displayText=="string"?{displayText:e.displayText}:{},...typeof e?.inspectSummary=="string"?{inspectSummary:e.inspectSummary}:{},...typeof e?.inspectTrace=="string"?{inspectTrace:e.inspectTrace}:{}}}notePromptAccepted(e,t,r){let o=Date.now(),s=this.pendingPromptEchoes.get(e)??[];s.push({sentAt:o}),this.pendingPromptEchoes.set(e,s);let n=Math.max(this.pendingTurns.get(e)??0,r?1:0)+1;this.pendingTurns.set(e,n);let i=t.displayText??t.text;return this.patchSession(e,{lastPrompt:i,status:"working",needsAttention:!1}),this.fanOutEvent(e,{type:"prompt-received",text:i,...t.inspectSummary?{inspectSummary:t.inspectSummary}:{},...t.inspectTrace?{inspectTrace:t.inspectTrace}:{},ts:o}),{ok:!0,queued:n>1,pendingTurns:n,queueDepth:Math.max(0,n-1)}}applySessionEvent(e,t){switch(t.type){case"prompt-received":case"turn-started":this.patchSession(e,{status:"working",needsAttention:!1});return;case"turn-completed":{let r=this.consumeSettledTurn(e);this.patchSession(e,{status:r>0?"working":"idle",needsAttention:!1,lastTurnFiles:t.filesTouched,currentlyEditing:void 0});return}case"approval-needed":this.patchSession(e,{status:"needs-attention",needsAttention:!0});return;case"error":{let r=this.consumeSettledTurn(e);this.patchSession(e,{status:r>0?"working":"needs-attention",needsAttention:r<=0,currentlyEditing:void 0});return}case"exited":this.clearPromptTracking(e),this.patchSession(e,{status:"ended",needsAttention:!1,wrapperPid:void 0,currentlyEditing:void 0});return;case"ready":case"turn-reasoning":case"turn-message":case"turn-plan":case"tool-call":case"file-edited":case"file-diff-delta":return}}patchSession(e,t){X(e,t);let r=w(e);r&&this.broadcastSessionStatus(r)}coalescePromptEcho(e,t){if(t.type!=="prompt-received")return t;let r=this.pendingPromptEchoes.get(e);if(!r||r.length===0)return t;for(;r.length>0&&Date.now()-r[0].sentAt>15e3;)r.shift();return r.length===0?(this.pendingPromptEchoes.delete(e),t):(r.shift(),r.length===0?this.pendingPromptEchoes.delete(e):this.pendingPromptEchoes.set(e,r),null)}consumeSettledTurn(e){let t=Math.max(0,(this.pendingTurns.get(e)??1)-1);return t>0?this.pendingTurns.set(e,t):this.pendingTurns.delete(e),t}clearPromptTracking(e){this.pendingPromptEchoes.delete(e),this.pendingTurns.delete(e)}fanOutEvent(e,t){let r=JSON.stringify({type:"agent:event",sessionId:e,event:t});for(let[o,s]of this.sessionsBySocket)if(s.has(e)&&o.readyState===T)try{o.send(r)}catch{}}broadcastSessionStatus(e){let t=JSON.stringify({type:"agent:session-status",session:e});for(let r of this.allSockets)if(r.readyState===T)try{r.send(t)}catch{}}respond(e,t,r){if(e.readyState===T)try{e.send(JSON.stringify({id:t,result:r}))}catch{}}respondError(e,t,r,o){if(e.readyState===T)try{e.send(JSON.stringify({id:t,error:r,...o?{code:o}:{}}))}catch{}}};function de(h){return h==="expo"?"expo":h==="one"||h==="vxrn"?"one":"unknown"}var he=new Set(["tap","keyboard","close"]);function fe(h){return!h||typeof h.type!="string"?!1:h.acquireLock===!0?!0:h.readOnly===!0?!1:he.has(h.type)}var me=5e3,ge=3600*1e3,ye="SOOTSIM_RUNTIME_UPDATE_INTERVAL_MS",Se={".html":"text/html; charset=utf-8",".js":"application/javascript",".cjs":"application/javascript",".mjs":"application/javascript",".css":"text/css; charset=utf-8",".json":"application/json; charset=utf-8",".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".svg":"image/svg+xml",".webp":"image/webp",".avif":"image/avif",".ico":"image/x-icon",".wasm":"application/wasm",".ttf":"font/ttf",".otf":"font/otf",".woff":"font/woff",".woff2":"font/woff2",".map":"application/json",".txt":"text/plain; charset=utf-8"},P=class h{port;openUrlHandler;httpServer=null;wss=null;nextCommandId=1;nextBrowserId=1;browsers=new Map;primaryBrowserId=null;pendingCommands=new Map;cliBySentId=new Map;cliBrowserBySocket=new Map;cliLastCommandAt=new Map;cliSessionKeyBySocket=new Map;cliLabelBySocket=new Map;restorableBrowsers=new Map;nextCliFallbackId=1;cliIdleTimer=null;agentHost;static CLI_IDLE_TIMEOUT_MS=6e4;static CLI_LEASE_TTL_MS=6e5;static USER_ACTIVE_LEASE_TTL_MS=8e3;static USER_BOOT_LEASE_TTL_MS=6e4;static BROWSER_RECONNECT_TTL_MS=3e4;preferredPort;portFallbackCount;shouldWriteLockfile;effectivePort=0;startedAt=0;heartbeatTimer=null;runtimeUpdateTimer=null;runtimeUpdateInFlight=null;activeRuntimeVersion=null;activeRuntimeDirPath=null;constructor(e={}){this.preferredPort=e.port||7668,this.port=this.preferredPort,this.shouldWriteLockfile=e.writeLockfile===!0,this.portFallbackCount=Math.max(1,e.portFallbackCount??10),this.openUrlHandler=e.openUrl,this.agentHost=new E({getExcludePorts:e.agentScanExcludes})}getAgentHost(){return this.agentHost}start(e){this.startAsync(e)}async startAsync(e){if(this.httpServer||this.wss)return this.effectivePort;this.refreshActiveRuntime();for(let t=0;t<this.portFallbackCount;t++){let r=this.preferredPort+t;try{return await this.bindOnce(r,e?.silent===!0),this.effectivePort=r,this.port=r,this.startedAt=Date.now(),t>0&&!e?.silent&&process.stderr.write(`ws bridge bound to port ${r} (preferred ${this.preferredPort} was taken)
5
- `),this.afterBind(),r}catch(o){if(o?.code!=="EADDRINUSE")throw o;e?.silent||process.stderr.write(`ws bridge port ${r} already in use, trying ${r+1}
6
- `)}}throw new Error(`could not bind ws bridge after ${this.portFallbackCount} attempts starting at ${this.preferredPort}`)}bindOnce(e,t){return new Promise((r,o)=>{let s=ue((a,c)=>this.handleHttpRequest(a,c)),n=!1,i=a=>{if(!n){n=!0;try{s.close()}catch{}this.httpServer=null,this.wss=null,o(a)}};s.once("error",i),s.listen(e,"127.0.0.1",()=>{n||(n=!0,s.removeListener("error",i),s.on("error",a=>{process.stderr.write(`ws bridge http error: ${String(a)}
7
- `)}),this.httpServer=s,this.wss=new pe({server:s}),this.wireWebSocketServer(),r())})})}wireWebSocketServer(){this.wss&&this.wss.on("connection",(e,t)=>{let r=t.headers.origin,o=r?"browser":"cli",s=null;if(e.on("error",()=>{}),this.agentHost.registerSocket(e),o==="browser")s={id:`tab-${this.nextBrowserId++}`,ws:e,origin:r,connectedAt:Date.now(),lastSeenAt:Date.now(),lastActiveAt:0,recentActions:[]},this.browsers.set(s.id,s),this.shouldPromoteBrowser(s)&&(this.primaryBrowserId=s.id),this.broadcastBrowserAssignments(),this.broadcastBrowserClientStates();else{let n=`ws-${this.nextCliFallbackId++}`;this.cliSessionKeyBySocket.set(e,n)}e.on("message",n=>{let i;try{i=JSON.parse(n.toString())}catch{return}if(!(!i||typeof i!="object")){if(typeof i.type=="string"&&i.type.startsWith("agent:")){this.agentHost.handleMessage(e,i);return}if(i.type==="runtime:list"){let a=L(),c=this.getActiveRuntime(),d={type:"runtime:list:ok",id:i.id,installed:a,active:c.version,activeRuntimeDir:c.runtimeDir};try{e.send(JSON.stringify(d))}catch{}return}if(i.type==="runtime:use"){let a=typeof i.version=="string"?i.version:"";if(!L().includes(a)){try{e.send(JSON.stringify({type:"runtime:use:error",id:i.id,error:`runtime ${a||"(missing)"} is not installed`}))}catch{}return}let d=this.setActiveRuntime(a);try{e.send(JSON.stringify({type:"runtime:use:ok",id:i.id,version:d.version,runtimeDir:d.runtimeDir}))}catch{}return}if(i.type==="runtime:get"){let a=this.getActiveRuntime();try{e.send(JSON.stringify({type:"runtime:get:ok",id:i.id,active:a.version,activeRuntimeDir:a.runtimeDir}))}catch{}return}if(o==="browser"){if(s&&(s.lastSeenAt=Date.now()),i.type==="bridge:register"&&s){let d=i,l=this.tryRestoreBrowserId(s,d.browserId);s.url=d.url,s.title=d.title,s.userAgent=d.userAgent,l&&(this.broadcastBrowserAssignments(),this.broadcastBrowserClientStates());return}if(i.type==="bridge:user-focus-state"&&s){let d=i;this.updateUserFocusLease(s,d.focused===!0);return}if(i.type==="bridge:user-interact"&&s){this.updateUserActivity(s);return}if(i.type==="bridge:open-path"){let d=typeof i.path=="string"?i.path:"",l=typeof i.line=="number"&&Number.isFinite(i.line)?i.line:void 0,p=typeof i.column=="number"&&Number.isFinite(i.column)?i.column:void 0;d&&this.openPathInEditor(d,l,p);return}if(i.type==="bridge:boot-clients"&&s){let d=[];for(let[p,u]of this.cliBrowserBySocket)u===s.id&&d.push(p);for(let p of d){this.cliBrowserBySocket.delete(p);try{p.close(1e3,"booted by browser")}catch{}}let l=!!s.cliLease;s.cliLease={kind:"user-active",cliSessionKey:"__user-active__",cliLabel:"active user",expiresAt:Date.now()+h.USER_BOOT_LEASE_TTL_MS},process.stderr.write(`sootsim booted ${d.length} cli client(s)${l?" (overrode prior lease)":""}; held tab for user [${s.id}]
8
- `),this.recordBrowserAction(s.id,"browser booted cli clients"),this.broadcastBrowserClientStates();return}let a=this.pendingCommands.get(i.id);if(a){this.pendingCommands.delete(i.id),i.error?a.reject(new Error(i.error)):a.resolve(i.result);return}let c=this.cliBySentId.get(i.id);if(c&&(this.cliBySentId.delete(i.id),c.ws.readyState===f.OPEN)){let d=this.getOtherCliSessionCount(c.ws,c.browserId),l=d>0?{...i,id:c.originalId,i:d}:{...i,id:c.originalId};c.ws.send(JSON.stringify(l))}return}(async()=>{this.cliLastCommandAt.set(e,Date.now());try{if(i.type==="bridge:bye"){let p=this.cliBrowserBySocket.delete(e);this.cliLastCommandAt.delete(e),this.cliSessionKeyBySocket.delete(e),this.cliLabelBySocket.delete(e);for(let[u,g]of this.cliBySentId)g.ws===e&&this.cliBySentId.delete(u);p&&this.broadcastBrowserClientStates();return}if(i.type==="bridge:hello"){let p=typeof i.cliSessionKey=="string"&&i.cliSessionKey.trim()?i.cliSessionKey.trim():this.cliSessionKeyBySocket.get(e)||`ws-${this.nextCliFallbackId++}`;this.cliSessionKeyBySocket.set(e,p),typeof i.cliLabel=="string"&&i.cliLabel.trim()&&this.cliLabelBySocket.set(e,i.cliLabel.trim()),e.readyState===f.OPEN&&e.send(JSON.stringify({id:i.id,result:{cliSessionKey:p,leaseTtlMs:h.CLI_LEASE_TTL_MS,leasing:!0}}));return}if(i.type==="bridge:list-browsers"){e.readyState===f.OPEN&&e.send(JSON.stringify({id:i.id,result:this.listBrowsers()}));return}if(i.type==="bridge:open"){if(typeof i.url!="string"||!i.url)throw new Error("bridge:open requires a url");await this.openUrl(i.url,{newWindow:i.newWindow===!0}),e.readyState===f.OPEN&&e.send(JSON.stringify({id:i.id,result:{ok:!0,url:i.url}}));return}if(i.type==="bridge:claim"){let p=await this.waitForBrowser(i.browserId),u=this.tryAcquireLease(e,p,{force:i.force===!0});if(!u.granted){e.readyState===f.OPEN&&e.send(JSON.stringify({id:i.id,error:`tab ${p.id} is locked by another cli`,o:u.lock}));return}this.setCliBrowserTarget(e,p.id),this.recordBrowserAction(p.id,u.bootedCount>0?`cli force-claimed tab (booted ${u.bootedCount})`:"cli claimed tab"),e.readyState===f.OPEN&&e.send(JSON.stringify({id:i.id,result:{browserId:p.id,lockedBy:u.lease.cliSessionKey,lockExpiresAt:u.lease.expiresAt,bootedCount:u.bootedCount}}));return}let a=await this.waitForBrowser(i.browserId);if(fe(i)){let p=this.tryAcquireLease(e,a);if(!p.granted){e.readyState===f.OPEN&&e.send(JSON.stringify({id:i.id,error:`tab ${a.id} is locked by another cli \u2014 use \`sootsim claim ${a.id} --force\` or \`sootsim open --new\``,o:p.lock}));return}}else this.ensureCliSessionKey(e);this.setCliBrowserTarget(e,a.id),this.recordBrowserAction(a.id,this.describeForwardedCommand(i));let c=this.nextCommandId++;this.cliBySentId.set(c,{browserId:a.id,ws:e,originalId:i.id});let{browserId:d,...l}=i;a.ws.send(JSON.stringify({...l,id:c}))}catch(a){e.readyState===f.OPEN&&e.send(JSON.stringify({id:i.id,error:a instanceof Error?a.message:String(a)}))}})()}}),e.on("close",()=>{if(this.agentHost.unregisterSocket(e),o==="browser"&&s){this.rememberDisconnectedBrowser(s),this.primaryBrowserId===s.id&&(this.primaryBrowserId=this.getOpenBrowser()?.id??null);for(let[n,i]of this.pendingCommands)i.browserId===s.id&&(i.reject(new Error("browser disconnected")),this.pendingCommands.delete(n));for(let[n,i]of this.cliBySentId)i.browserId===s.id&&(i.ws.readyState===f.OPEN&&i.ws.send(JSON.stringify({id:i.originalId,error:"browser disconnected before responding"})),this.cliBySentId.delete(n));this.broadcastBrowserAssignments(),this.broadcastBrowserClientStates()}else if(o==="cli"){let n=this.cliBrowserBySocket.delete(e);this.cliLastCommandAt.delete(e),this.cliSessionKeyBySocket.delete(e),this.cliLabelBySocket.delete(e);for(let[i,a]of this.cliBySentId)a.ws===e&&this.cliBySentId.delete(i);n&&this.broadcastBrowserClientStates()}})})}afterBind(){if(process.stderr.write(`ws bridge listening on port ${this.port}
9
- `),this.cliIdleTimer=setInterval(()=>this.sweepIdleCliClients(),3e4),this.cliIdleTimer.unref(),this.shouldWriteLockfile){try{if(A(),!W(this.buildLockfileSnapshot()))throw new Error("another sootsim daemon wrote the lockfile during startup \u2014 aborting")}catch(e){throw process.stderr.write(`ws bridge failed to claim daemon lockfile: ${String(e)}
10
- `),e}this.heartbeatTimer=setInterval(()=>{try{this.writeLockfileSnapshot()}catch{}},me),this.heartbeatTimer.unref(),this.startRuntimeUpdater()}this.agentHost.seedOnBoot()}bootstrapping=!0;buildLockfileSnapshot(){return{schema:1,pid:process.pid,platform:process.platform,bridgePort:this.effectivePort,runtimePort:this.effectivePort,activeRuntime:this.activeRuntimeVersion,activeRuntimeDir:this.activeRuntimeDirPath,startedAt:this.startedAt,heartbeatAt:Date.now(),bootstrapping:this.bootstrapping}}writeLockfileSnapshot(){F(this.buildLockfileSnapshot())}refreshActiveRuntime(){this.activeRuntimeVersion=N(),this.activeRuntimeDirPath=D()}resolveRuntimeUpdateIntervalMs(){let e=Number(process.env[ye]);return Number.isFinite(e)&&e>0?Math.max(100,Math.round(e)):ge}startRuntimeUpdater(){if(!this.shouldWriteLockfile||this.runtimeUpdateTimer)return;this.runRuntimeUpdate("startup");let e=this.resolveRuntimeUpdateIntervalMs();this.runtimeUpdateTimer=setInterval(()=>{this.runRuntimeUpdate("periodic")},e),this.runtimeUpdateTimer.unref()}runRuntimeUpdate(e){return this.runtimeUpdateInFlight?this.runtimeUpdateInFlight:(this.runtimeUpdateInFlight=(async()=>{try{e==="startup"&&process.stderr.write(`sootsim: checking for runtime updates\u2026
11
- `);let t=await H();if(!t.updated||!t.latestVersion){e==="startup"&&process.stderr.write(`sootsim: runtime ${this.activeRuntimeVersion??"(none)"} is current
12
- `);return}let r=this.setActiveRuntime(t.latestVersion);process.stderr.write(`sootsim runtime updated to ${r.version} (${e})
13
- `)}catch(t){process.stderr.write(`sootsim runtime update failed (${e}): ${t instanceof Error?t.message:String(t)}
14
- `)}finally{if(this.runtimeUpdateInFlight=null,e==="startup"&&this.bootstrapping){if(this.bootstrapping=!1,this.shouldWriteLockfile&&this.httpServer)try{this.writeLockfileSnapshot()}catch{}process.stderr.write(`sootsim: ready
15
- `)}}})(),this.runtimeUpdateInFlight)}setActiveRuntime(e){if(_(e),this.refreshActiveRuntime(),this.shouldWriteLockfile&&this.httpServer)try{this.writeLockfileSnapshot()}catch{}let t=JSON.stringify({type:"runtime:changed",version:e,runtimeDir:this.activeRuntimeDirPath});for(let r of this.browsers.values())if(r.ws.readyState===f.OPEN)try{r.ws.send(t)}catch{}return{version:e,runtimeDir:this.activeRuntimeDirPath}}getActiveRuntime(){return{version:this.activeRuntimeVersion,runtimeDir:this.activeRuntimeDirPath}}removeLockfile(){if(this.shouldWriteLockfile)try{x()}catch{}}handleHttpRequest(e,t){let r=(e.method||"GET").toUpperCase();if(r!=="GET"&&r!=="HEAD"){t.writeHead(405,{Allow:"GET, HEAD"}),t.end("method not allowed");return}let o=new URL(e.url||"/","http://localhost");if(o.pathname==="/__bundle-proxy"){let c=o.searchParams.get("url");if(!c){t.writeHead(400,{"Content-Type":"text/plain"}),t.end("bundle-proxy: missing url query param");return}let d;try{d=new URL(c)}catch{t.writeHead(400,{"Content-Type":"text/plain"}),t.end("bundle-proxy: invalid url");return}let l=d.hostname;if(!(l==="localhost"||l==="127.0.0.1"||l==="::1"||l.endsWith(".localhost"))){t.writeHead(403,{"Content-Type":"text/plain"}),t.end("bundle-proxy: only loopback targets allowed");return}(async()=>{try{let u=await fetch(d.toString(),{redirect:"follow"}),g={},m=u.headers.get("content-type");if(m&&(g["Content-Type"]=m),g["Cache-Control"]="no-store",t.writeHead(u.status,g),!u.body){t.end();return}let S=u.body.getReader();for(;;){let{done:B,value:k}=await S.read();if(B)break;t.write(Buffer.from(k))}t.end()}catch(u){t.writeHead(502,{"Content-Type":"text/plain"}),t.end(`bundle-proxy: upstream fetch failed: ${u instanceof Error?u.message:String(u)}`)}})();return}if(o.pathname==="/healthz"){t.writeHead(200,{"Content-Type":"application/json","Cache-Control":"no-store"}),t.end(JSON.stringify({ok:!0,pid:process.pid,platform:process.platform,bridgePort:this.effectivePort,runtimePort:this.effectivePort,activeRuntime:this.activeRuntimeVersion,startedAt:this.startedAt,uptimeMs:this.startedAt>0?Date.now()-this.startedAt:0}));return}this.refreshActiveRuntime();let s=this.activeRuntimeDirPath;if(!s){t.writeHead(503,{"Content-Type":"text/plain; charset=utf-8"}),t.end("sootsim: no active runtime installed. run `sootsim runtime install` to fetch one.");return}let n=o.pathname;if(n==="/runtime"||n==="/runtime/"?n="/":n.startsWith("/runtime/")&&(n=n.slice(8)),(n===""||n==="/")&&(n="/index.html"),n.includes("\0")){t.writeHead(400),t.end("bad request");return}if(process.platform!=="win32"&&n.includes("\\")){t.writeHead(400),t.end("bad request");return}for(let c of n.split("/"))if(c===".."){t.writeHead(403),t.end("forbidden");return}let i=y.resolve(s,"."+n),a=s.endsWith(y.sep)?s:s+y.sep;if(!i.startsWith(a)&&i!==s){t.writeHead(403),t.end("forbidden");return}v.realpath(i,(c,d)=>{let l=c?i:d,p=l.endsWith(y.sep)?l:l+y.sep;if(!c){let u=(()=>{try{let g=v.realpathSync(s);return g.endsWith(y.sep)?g:g+y.sep}catch{return a}})();if(!p.startsWith(u)&&l+y.sep!==u){t.writeHead(403),t.end("forbidden");return}}v.stat(l,(u,g)=>{if(u||!g?.isFile()){let k=y.extname(n).toLowerCase();if(k&&k!==".html"){t.writeHead(404),t.end("not found");return}let ne=y.join(s,"index.html");v.readFile(ne,(oe,ae)=>{if(oe){t.writeHead(404),t.end("not found");return}if(t.writeHead(200,{"Content-Type":"text/html; charset=utf-8","Cache-Control":"no-store"}),r==="HEAD"){t.end();return}t.end(ae)});return}let m=y.extname(l).toLowerCase(),S=Se[m]||"application/octet-stream";if(t.writeHead(200,{"Content-Type":S,"Cache-Control":"no-store"}),r==="HEAD"){t.end();return}let B=v.createReadStream(l);B.pipe(t),B.on("error",()=>{try{t.end()}catch{}})})})}sweepIdleCliClients(){let e=Date.now(),t=!1;for(let[r,o]of this.cliBrowserBySocket){let s=this.cliLastCommandAt.get(r)??0;if(!(e-s<h.CLI_IDLE_TIMEOUT_MS)){this.cliBrowserBySocket.delete(r),this.cliLastCommandAt.delete(r);for(let[n,i]of this.cliBySentId)i.ws===r&&this.cliBySentId.delete(n);try{r.close(1e3,"idle timeout")}catch{}t=!0}}t&&this.broadcastBrowserClientStates(),this.sweepRestorableBrowsers(e)}listBrowsers(){return Array.from(this.browsers.values()).sort((e,t)=>e.id===this.primaryBrowserId?-1:t.id===this.primaryBrowserId?1:e.connectedAt-t.connectedAt).map(e=>this.describeBrowser(e))}async sendCommand(e){let t=await this.waitForBrowser(e.browserId),r=this.nextCommandId++;return new Promise((o,s)=>{let n=setTimeout(()=>{this.pendingCommands.delete(r),this.broadcastBrowserClientStates(),s(new Error("command timed out after 30s"))},3e4);this.pendingCommands.set(r,{browserId:t.id,resolve:c=>{clearTimeout(n),this.pendingCommands.delete(r),this.broadcastBrowserClientStates(),o(c)},reject:c=>{clearTimeout(n),this.pendingCommands.delete(r),this.broadcastBrowserClientStates(),s(c)}}),this.broadcastBrowserClientStates();let{browserId:i,...a}=e;t.ws.send(JSON.stringify({...a,id:r}))})}async evaluate(e,t){return this.sendCommand({type:"evaluate",code:e,browserId:t})}async focusBrowser(e){return this.sendCommand({type:"focus",browserId:e})}async closeBrowser(e){return this.sendCommand({type:"close",browserId:e})}async openPathInEditor(e,t,r){let o=t!=null?`:${t}${r!=null?`:${r}`:""}`:"",s=`${e}${o}`,n=(a,c)=>new Promise(d=>{try{let l=le(a,c,{detached:!0,stdio:"ignore"}),p=!1;l.on("error",()=>{p||(p=!0,d(!1))}),l.on("spawn",()=>{p||(p=!0,l.unref(),d(!0))})}catch{d(!1)}}),i=process.env.REACT_EDITOR||process.env.EDITOR;if(i){let a=i.split(" ").filter(Boolean);if(a.length&&await n(a[0],[...a.slice(1),"-g",s]))return}await n("cursor",["-g",s])||await n("code",["-g",s])||await this.openUrl(e)}async openUrl(e,t={}){if(this.openUrlHandler){await this.openUrlHandler(e,t);return}await K(e,t)}async close(){if(this.cliIdleTimer&&(clearInterval(this.cliIdleTimer),this.cliIdleTimer=null),this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null),this.runtimeUpdateTimer&&(clearInterval(this.runtimeUpdateTimer),this.runtimeUpdateTimer=null),this.shouldWriteLockfile)try{x()}catch{}this.effectivePort=0,this.startedAt=0,this.agentHost.close();for(let[r,o]of this.pendingCommands)o.reject(new Error("server closing")),this.pendingCommands.delete(r);for(let r of this.browsers.values())r.ws.close();this.browsers.clear(),this.primaryBrowserId=null;let e=this.wss,t=this.httpServer;if(this.wss=null,this.httpServer=null,e)try{e.close()}catch{}if(t)try{t.close()}catch{}}describeBrowser(e){let t;try{t=e.ws.readyState}catch{t=f.CLOSED}let r=this.getActiveLease(e);return{id:e.id,origin:e.origin,url:e.url,title:e.title,userAgent:e.userAgent,connectedAt:e.connectedAt,lastSeenAt:e.lastSeenAt,lastActiveAt:e.lastActiveAt||void 0,isPrimary:e.id===this.primaryBrowserId,readyState:t===f.OPEN?"open":t===f.CLOSING?"closing":"closed",attachedCliCount:this.getAttachedCliCount(e.id),lockedBy:r?r.cliLabel||r.cliSessionKey:void 0,lockedByKind:r?r.kind:void 0,lockExpiresAt:r?r.expiresAt:void 0,userFocused:e.userFocused||void 0}}getActiveLease(e){let t=e.cliLease;return t?Date.now()>=t.expiresAt?(e.cliLease=void 0,null):t:null}tryAcquireLease(e,t,r={}){let o=this.cliSessionKeyBySocket.get(e)??(()=>{let l=`ws-${this.nextCliFallbackId++}`;return this.cliSessionKeyBySocket.set(e,l),l})(),s=this.cliLabelBySocket.get(e),n=Date.now(),i=this.getActiveLease(t),a=i&&i.cliSessionKey===o,c=0;if(i&&!a&&!r.force)return{granted:!1,lease:i,lock:{by:i.cliLabel||i.cliSessionKey,expiresInMs:Math.max(0,i.expiresAt-n)},bootedCount:0};if(i&&!a&&r.force)for(let[l,p]of this.cliBrowserBySocket){if(p!==t.id)continue;let u=this.cliSessionKeyBySocket.get(l);if(u&&u!==o){this.cliBrowserBySocket.delete(l);try{l.close(1e3,"lease claimed by another cli")}catch{}c++}}let d={kind:"cli",cliSessionKey:o,cliLabel:s,expiresAt:n+h.CLI_LEASE_TTL_MS};return t.cliLease=d,{granted:!0,lease:d,bootedCount:c}}updateUserFocusLease(e,t){let r=t;e.userFocused!==r&&(e.userFocused=r,this.broadcastBrowserClientStates())}updateUserActivity(e){let t=this.getActiveLease(e);if(t&&t.kind==="cli")return;let o=Date.now()+h.USER_ACTIVE_LEASE_TTL_MS,s=t&&t.kind==="user-active"?Math.max(t.expiresAt,o):o;e.cliLease={kind:"user-active",cliSessionKey:"__user-active__",cliLabel:"active user",expiresAt:s},this.broadcastBrowserClientStates()}ensureCliSessionKey(e){let t=this.cliSessionKeyBySocket.get(e);if(t)return t;let r=`ws-${this.nextCliFallbackId++}`;return this.cliSessionKeyBySocket.set(e,r),r}getOpenBrowser(e){if(e){let r=this.browsers.get(e);return r?.ws.readyState===f.OPEN?r:null}let t=this.primaryBrowserId!=null?this.browsers.get(this.primaryBrowserId):null;if(t?.ws.readyState===f.OPEN)return t;for(let r of this.browsers.values())if(r.ws.readyState===f.OPEN)return r;return null}async waitForBrowser(e,t={}){let r=t.attempts??10,o=t.intervalMs??200;for(let s=0;s<r;s++){let n=this.getOpenBrowser(e);if(n)return n;await new Promise(i=>setTimeout(i,o))}throw new Error(e?`no browser connected with id ${e}`:"no browser connected")}shouldPromoteBrowser(e){let t=this.primaryBrowserId?this.browsers.get(this.primaryBrowserId):null,r=e.origin?.includes(":5173"),o=t?.origin?.includes(":5173");return!t||t.ws.readyState!==f.OPEN||!!r||!o}broadcastBrowserAssignments(){for(let e of this.browsers.values())e.ws.readyState===f.OPEN&&e.ws.send(JSON.stringify({type:"bridge:welcome",browserId:e.id,isPrimary:e.id===this.primaryBrowserId}))}broadcastBrowserClientStates(){for(let e of this.browsers.values()){if(e.ws.readyState!==f.OPEN)continue;let t=this.getActiveLease(e),r={type:"bridge:client-state",attachedCliCount:this.getAttachedCliCount(e.id),activeAgentCommandCount:this.getActiveAgentCommandCount(e.id),recentActions:e.recentActions,lockedBy:t?t.cliLabel||t.cliSessionKey:void 0,lockedByKind:t?t.kind:void 0,lockExpiresAt:t?t.expiresAt:void 0,userFocused:e.userFocused||void 0};e.ws.send(JSON.stringify(r))}}setCliBrowserTarget(e,t){let r=this.cliBrowserBySocket.get(e);r!==t&&(this.cliBrowserBySocket.set(e,t),this.recordBrowserAction(t,r?"cli switched tabs":"cli connected",!1),this.broadcastBrowserClientStates())}recordBrowserAction(e,t,r=!0){let o=t?.trim();if(!o)return;let s=this.browsers.get(e);if(!s)return;let n=Date.now();s.lastActiveAt=n,s.recentActions=[{label:o,at:n},...s.recentActions.filter(i=>i.label!==o)].slice(0,4),r&&this.broadcastBrowserClientStates()}describeForwardedCommand(e){switch(e?.type){case"evaluate":return"evaluated page state";case"screenshot":return"captured screenshot";case"tap":return"sent tap event";case"keyboard":return e?.action==="type"?"typed text":"used keyboard";case"tree":return"dumped tree";case"focus":return"focused tab";case"close":return"requested close";default:return typeof e?.type=="string"?e.type:null}}getAttachedCliCount(e){let t=new Set;for(let[r,o]of this.cliBrowserBySocket){if(o!==e||r.readyState!==f.OPEN)continue;let s=this.cliSessionKeyBySocket.get(r);t.add(s??`ws-unknown-${t.size}`)}return t.size}getOtherCliSessionCount(e,t){let r=this.cliSessionKeyBySocket.get(e),o=new Set;for(let[s,n]of this.cliBrowserBySocket){if(n!==t||s.readyState!==f.OPEN)continue;let i=this.cliSessionKeyBySocket.get(s);i&&i===r||o.add(i??`ws-unknown-${o.size}`)}return o.size}getActiveAgentCommandCount(e){let t=0;for(let r of this.pendingCommands.values())r.browserId===e&&t++;return t}tryRestoreBrowserId(e,t){let r=t?.trim();if(!r||r===e.id)return!1;let o=this.browsers.get(r);if(o&&o!==e&&o.ws.readyState===f.OPEN)return!1;let s=this.getRestorableBrowserState(r),n=e.id;this.browsers.delete(n),e.id=r,s&&(e.recentActions=s.recentActions.map(i=>({...i})),e.lastActiveAt=s.lastActiveAt,e.cliLease=s.cliLease?{...s.cliLease}:void 0,this.restorableBrowsers.delete(r)),this.browsers.set(e.id,e),this.primaryBrowserId===n&&(this.primaryBrowserId=e.id);for(let[i,a]of this.cliBrowserBySocket)a===n&&this.cliBrowserBySocket.set(i,e.id);return!0}rememberDisconnectedBrowser(e){let t=this.getActiveLease(e);this.restorableBrowsers.set(e.id,{recentActions:e.recentActions.map(r=>({...r})),lastActiveAt:e.lastActiveAt,cliLease:t&&t.kind==="cli"?{...t}:void 0,expiresAt:Date.now()+h.BROWSER_RECONNECT_TTL_MS}),this.browsers.delete(e.id)}getRestorableBrowserState(e){let t=this.restorableBrowsers.get(e);return t?t.expiresAt<=Date.now()?(this.restorableBrowsers.delete(e),null):(t.cliLease&&t.cliLease.expiresAt<=Date.now()&&(t.cliLease=void 0),t):null}sweepRestorableBrowsers(e=Date.now()){for(let[t,r]of this.restorableBrowsers)if(!(r.expiresAt>e)){this.restorableBrowsers.delete(t);for(let[o,s]of this.cliBrowserBySocket)s===t&&this.cliBrowserBySocket.delete(o)}}resetServerState(){this.cliIdleTimer&&(clearInterval(this.cliIdleTimer),this.cliIdleTimer=null),this.runtimeUpdateTimer&&(clearInterval(this.runtimeUpdateTimer),this.runtimeUpdateTimer=null);let e=this.wss,t=this.httpServer;if(this.wss=null,this.httpServer=null,e)try{e.close()}catch{}if(t)try{t.close()}catch{}}};function we(){return!!((process.env.XPC_SERVICE_NAME||"").includes("dev.sootsim.server")||process.env.INVOCATION_ID)}async function $e(h,e={}){(h.includes("--help")||h.includes("-h"))&&(console.log(`
16
- sootsim server \u2014 run the sootsim bridge daemon in the foreground
17
-
18
- hosts the WS bridge that CLI commands talk to. once running, any sootsim
19
- tab (browser, electron, headless playwright) that connects to port 7668
20
- becomes drivable from 'sootsim describe', 'sootsim tap', etc.
21
-
22
- usage:
23
- sootsim server [options]
24
-
25
- options:
26
- --port <n> bridge port (defaults to ${7668})
27
- --quiet suppress per-connection logging
28
-
29
- examples:
30
- sootsim server
31
- sootsim server --port 7668 --quiet
32
- `),process.exit(0));let t=h.indexOf("--port"),r=t>=0&&h[t+1]?Number(h[t+1]):e.port??7668;Number.isNaN(r)&&(console.error(` invalid --port value: ${h[t+1]}`),process.exit(1));let o=h.includes("--quiet")||h.includes("-q"),s=U();s&&M(s)&&(console.error(` a sootsim daemon is already running (pid ${s.pid}, port ${s.bridgePort})`),console.error(" stop it with 'sootsim daemon stop' first"),process.exit(1)),A();let n=new P({port:r,writeLockfile:!0}),i=await n.startAsync({silent:o}),a=Date.now(),c=u=>{o||process.stdout.write(`${u}
33
- `)},d=new Set,l=setInterval(()=>{let u=n.listBrowsers(),g=new Set(u.map(m=>m.id));for(let m of u)if(!d.has(m.id)){let S=m.title||m.url||m.origin||"(unknown)";c(` + ${m.id} ${S}`)}for(let m of d)g.has(m)||c(` - ${m}`);d.clear();for(let m of g)d.add(m)},500);$({event:"daemon_heartbeat",properties:{bridge_port:i,under_daemon:we(),platform:process.platform,subsource:"daemon"}}),j(),c(`sootsim bridge listening on ws://localhost:${i} (runtime http on same port)`),i!==r&&c(` (preferred port ${r} was taken \u2014 fell back to ${i})`),c(" ready for browser tabs, electron, or headless playwright to connect"),c(" (ctrl-c to stop)");let p=async u=>{clearInterval(l),c(`
34
- ${u} received \u2014 shutting down after ${Math.round((Date.now()-a)/1e3)}s`);try{await n.close()}catch{}process.exit(0)};process.on("SIGINT",()=>p("SIGINT")),process.on("SIGTERM",()=>p("SIGTERM")),process.on("SIGHUP",()=>p("SIGHUP")),process.on("exit",()=>{try{n.removeLockfile()}catch{}}),await new Promise(()=>{})}export{$e as runServer};
@@ -1,2 +0,0 @@
1
- /*! sootsim v0.1.36 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
- import{a}from"./chunk-27P763IZ.js";import"./chunk-VFDRZNPN.js";import"./chunk-IJMYFYDZ.js";import"./chunk-EJLNUMMP.js";import"./chunk-TC6V7YFC.js";import"./chunk-SMVJOWSV.js";import"./chunk-6GGMKFWJ.js";import"./chunk-ZEW3RF5Q.js";import"./chunk-5QIUJNT3.js";import"./chunk-LHDWH7VS.js";export{a as runSetupRepo};
@@ -1,2 +0,0 @@
1
- /*! sootsim v0.1.36 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
- import{a}from"./chunk-NIZBR7EK.js";import"./chunk-6Z275LCY.js";import"./chunk-LHDWH7VS.js";export{a as settingsStore};
@@ -1,2 +0,0 @@
1
- /*! sootsim v0.1.36 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
- import{a,b}from"./chunk-IJMYFYDZ.js";import"./chunk-EJLNUMMP.js";import"./chunk-5QIUJNT3.js";import"./chunk-LHDWH7VS.js";export{b as flushCliTelemetry,a as trackCliEvent};
@@ -1,2 +0,0 @@
1
- /*! sootsim v0.1.36 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
- import{a,b}from"./chunk-3UIWOHC2.js";import"./chunk-YLIIVTTQ.js";import"./chunk-IJMYFYDZ.js";import"./chunk-EJLNUMMP.js";import"./chunk-G663654J.js";import"./chunk-A5BRCXYE.js";import"./chunk-SMVJOWSV.js";import"./chunk-6GGMKFWJ.js";import"./chunk-ZEW3RF5Q.js";import"./chunk-5QIUJNT3.js";import"./chunk-LHDWH7VS.js";export{a as resolveDefaultUploadOrigin,b as runUpload};
@@ -1,2 +0,0 @@
1
- /*! sootsim v0.1.36 | (c) 2026 Tamagui LLC | Proprietary — see LICENSE */
2
- import{d as n}from"./chunk-EJLNUMMP.js";import"./chunk-LHDWH7VS.js";async function s(){let o=await n();o?.token||(console.log(" not signed in"),process.exit(1));let e=o.user;console.log(` ${e?.email||e?.name||e?.id||"signed in"}`),console.log(` origin: ${o.origin}`),console.log(` updated: ${o.updatedAt}`)}export{s as runWhoami};