@floless/app 0.167.0 → 0.168.0

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 (257) hide show
  1. package/autostart.mjs +169 -63
  2. package/desktop-shell.mjs +335 -0
  3. package/dist/floless-server.cjs +14518 -11361
  4. package/dist/schemas/steel.model.v2.schema.json +2 -1
  5. package/dist/skills/floless-app-onboarding/SKILL.md +13 -4
  6. package/dist/skills/floless-app-onboarding/references/floless-surfaces.md +3 -0
  7. package/dist/skills/floless-app-steel-takeoff/SKILL.md +21 -2
  8. package/dist/skills/floless-app-ui/SKILL.md +2 -2
  9. package/dist/skills/floless-app-workflows/SKILL.md +2 -2
  10. package/dist/web/agents.js +1 -1
  11. package/dist/web/app.css +165 -8
  12. package/dist/web/app.js +53 -13
  13. package/dist/web/aware-update-client.js +13 -5
  14. package/dist/web/aware.js +183 -39
  15. package/dist/web/chat.css +2 -1
  16. package/dist/web/chat.js +410 -80
  17. package/dist/web/commands-filter.js +5 -5
  18. package/dist/web/commands-shell.js +172 -10
  19. package/dist/web/commands-steel.js +1 -1
  20. package/dist/web/desktop-window.js +435 -0
  21. package/dist/web/drawing-check-editor.js +18 -10
  22. package/dist/web/failure-copy.js +14 -1
  23. package/dist/web/guide.js +75 -9
  24. package/dist/web/index.html +64 -6
  25. package/dist/web/instructor.js +1 -1
  26. package/dist/web/leave-guard.js +347 -14
  27. package/dist/web/pages.js +5 -1
  28. package/dist/web/panels.js +5 -2
  29. package/dist/web/pdf-view.js +421 -0
  30. package/dist/web/project-history.js +2 -1
  31. package/dist/web/project-modules.js +3 -1
  32. package/dist/web/project-rfis.js +3 -1
  33. package/dist/web/project-workflows.js +4 -2
  34. package/dist/web/reference-geometry-worker.js +11 -2
  35. package/dist/web/revit-editor.html +1 -0
  36. package/dist/web/revit-editor.js +37 -8
  37. package/dist/web/shared-prefs.js +364 -0
  38. package/dist/web/steel-editor.html +204 -43
  39. package/dist/web/steel-filter-flo.js +74 -18
  40. package/dist/web/steel-filter.html +22 -6
  41. package/dist/web/tab-signal.js +36 -1
  42. package/dist/web/tekla-editor.html +1 -0
  43. package/dist/web/tool-updates.js +159 -38
  44. package/dist/web/vector-3d.html +14 -3
  45. package/dist/web/vector-editor.html +10 -2
  46. package/dist/web/vendor/README.md +23 -0
  47. package/dist/web/vendor/pdfjs/LICENSE +177 -0
  48. package/dist/web/vendor/pdfjs/cmaps/78-EUC-H.bcmap +0 -0
  49. package/dist/web/vendor/pdfjs/cmaps/78-EUC-V.bcmap +0 -0
  50. package/dist/web/vendor/pdfjs/cmaps/78-H.bcmap +0 -0
  51. package/dist/web/vendor/pdfjs/cmaps/78-RKSJ-H.bcmap +0 -0
  52. package/dist/web/vendor/pdfjs/cmaps/78-RKSJ-V.bcmap +0 -0
  53. package/dist/web/vendor/pdfjs/cmaps/78-V.bcmap +0 -0
  54. package/dist/web/vendor/pdfjs/cmaps/78ms-RKSJ-H.bcmap +0 -0
  55. package/dist/web/vendor/pdfjs/cmaps/78ms-RKSJ-V.bcmap +0 -0
  56. package/dist/web/vendor/pdfjs/cmaps/83pv-RKSJ-H.bcmap +0 -0
  57. package/dist/web/vendor/pdfjs/cmaps/90ms-RKSJ-H.bcmap +0 -0
  58. package/dist/web/vendor/pdfjs/cmaps/90ms-RKSJ-V.bcmap +0 -0
  59. package/dist/web/vendor/pdfjs/cmaps/90msp-RKSJ-H.bcmap +0 -0
  60. package/dist/web/vendor/pdfjs/cmaps/90msp-RKSJ-V.bcmap +0 -0
  61. package/dist/web/vendor/pdfjs/cmaps/90pv-RKSJ-H.bcmap +0 -0
  62. package/dist/web/vendor/pdfjs/cmaps/90pv-RKSJ-V.bcmap +0 -0
  63. package/dist/web/vendor/pdfjs/cmaps/Add-H.bcmap +0 -0
  64. package/dist/web/vendor/pdfjs/cmaps/Add-RKSJ-H.bcmap +0 -0
  65. package/dist/web/vendor/pdfjs/cmaps/Add-RKSJ-V.bcmap +0 -0
  66. package/dist/web/vendor/pdfjs/cmaps/Add-V.bcmap +0 -0
  67. package/dist/web/vendor/pdfjs/cmaps/Adobe-CNS1-0.bcmap +0 -0
  68. package/dist/web/vendor/pdfjs/cmaps/Adobe-CNS1-1.bcmap +0 -0
  69. package/dist/web/vendor/pdfjs/cmaps/Adobe-CNS1-2.bcmap +0 -0
  70. package/dist/web/vendor/pdfjs/cmaps/Adobe-CNS1-3.bcmap +0 -0
  71. package/dist/web/vendor/pdfjs/cmaps/Adobe-CNS1-4.bcmap +0 -0
  72. package/dist/web/vendor/pdfjs/cmaps/Adobe-CNS1-5.bcmap +0 -0
  73. package/dist/web/vendor/pdfjs/cmaps/Adobe-CNS1-6.bcmap +0 -0
  74. package/dist/web/vendor/pdfjs/cmaps/Adobe-CNS1-UCS2.bcmap +0 -0
  75. package/dist/web/vendor/pdfjs/cmaps/Adobe-GB1-0.bcmap +0 -0
  76. package/dist/web/vendor/pdfjs/cmaps/Adobe-GB1-1.bcmap +0 -0
  77. package/dist/web/vendor/pdfjs/cmaps/Adobe-GB1-2.bcmap +0 -0
  78. package/dist/web/vendor/pdfjs/cmaps/Adobe-GB1-3.bcmap +0 -0
  79. package/dist/web/vendor/pdfjs/cmaps/Adobe-GB1-4.bcmap +0 -0
  80. package/dist/web/vendor/pdfjs/cmaps/Adobe-GB1-5.bcmap +0 -0
  81. package/dist/web/vendor/pdfjs/cmaps/Adobe-GB1-UCS2.bcmap +0 -0
  82. package/dist/web/vendor/pdfjs/cmaps/Adobe-Japan1-0.bcmap +0 -0
  83. package/dist/web/vendor/pdfjs/cmaps/Adobe-Japan1-1.bcmap +0 -0
  84. package/dist/web/vendor/pdfjs/cmaps/Adobe-Japan1-2.bcmap +0 -0
  85. package/dist/web/vendor/pdfjs/cmaps/Adobe-Japan1-3.bcmap +0 -0
  86. package/dist/web/vendor/pdfjs/cmaps/Adobe-Japan1-4.bcmap +0 -0
  87. package/dist/web/vendor/pdfjs/cmaps/Adobe-Japan1-5.bcmap +0 -0
  88. package/dist/web/vendor/pdfjs/cmaps/Adobe-Japan1-6.bcmap +0 -0
  89. package/dist/web/vendor/pdfjs/cmaps/Adobe-Japan1-UCS2.bcmap +0 -0
  90. package/dist/web/vendor/pdfjs/cmaps/Adobe-Korea1-0.bcmap +0 -0
  91. package/dist/web/vendor/pdfjs/cmaps/Adobe-Korea1-1.bcmap +0 -0
  92. package/dist/web/vendor/pdfjs/cmaps/Adobe-Korea1-2.bcmap +0 -0
  93. package/dist/web/vendor/pdfjs/cmaps/Adobe-Korea1-UCS2.bcmap +0 -0
  94. package/dist/web/vendor/pdfjs/cmaps/B5-H.bcmap +0 -0
  95. package/dist/web/vendor/pdfjs/cmaps/B5-V.bcmap +0 -0
  96. package/dist/web/vendor/pdfjs/cmaps/B5pc-H.bcmap +0 -0
  97. package/dist/web/vendor/pdfjs/cmaps/B5pc-V.bcmap +0 -0
  98. package/dist/web/vendor/pdfjs/cmaps/CNS-EUC-H.bcmap +0 -0
  99. package/dist/web/vendor/pdfjs/cmaps/CNS-EUC-V.bcmap +0 -0
  100. package/dist/web/vendor/pdfjs/cmaps/CNS1-H.bcmap +0 -0
  101. package/dist/web/vendor/pdfjs/cmaps/CNS1-V.bcmap +0 -0
  102. package/dist/web/vendor/pdfjs/cmaps/CNS2-H.bcmap +0 -0
  103. package/dist/web/vendor/pdfjs/cmaps/CNS2-V.bcmap +3 -0
  104. package/dist/web/vendor/pdfjs/cmaps/ETHK-B5-H.bcmap +0 -0
  105. package/dist/web/vendor/pdfjs/cmaps/ETHK-B5-V.bcmap +0 -0
  106. package/dist/web/vendor/pdfjs/cmaps/ETen-B5-H.bcmap +0 -0
  107. package/dist/web/vendor/pdfjs/cmaps/ETen-B5-V.bcmap +0 -0
  108. package/dist/web/vendor/pdfjs/cmaps/ETenms-B5-H.bcmap +3 -0
  109. package/dist/web/vendor/pdfjs/cmaps/ETenms-B5-V.bcmap +0 -0
  110. package/dist/web/vendor/pdfjs/cmaps/EUC-H.bcmap +0 -0
  111. package/dist/web/vendor/pdfjs/cmaps/EUC-V.bcmap +0 -0
  112. package/dist/web/vendor/pdfjs/cmaps/Ext-H.bcmap +0 -0
  113. package/dist/web/vendor/pdfjs/cmaps/Ext-RKSJ-H.bcmap +0 -0
  114. package/dist/web/vendor/pdfjs/cmaps/Ext-RKSJ-V.bcmap +0 -0
  115. package/dist/web/vendor/pdfjs/cmaps/Ext-V.bcmap +0 -0
  116. package/dist/web/vendor/pdfjs/cmaps/GB-EUC-H.bcmap +0 -0
  117. package/dist/web/vendor/pdfjs/cmaps/GB-EUC-V.bcmap +0 -0
  118. package/dist/web/vendor/pdfjs/cmaps/GB-H.bcmap +4 -0
  119. package/dist/web/vendor/pdfjs/cmaps/GB-V.bcmap +0 -0
  120. package/dist/web/vendor/pdfjs/cmaps/GBK-EUC-H.bcmap +0 -0
  121. package/dist/web/vendor/pdfjs/cmaps/GBK-EUC-V.bcmap +0 -0
  122. package/dist/web/vendor/pdfjs/cmaps/GBK2K-H.bcmap +0 -0
  123. package/dist/web/vendor/pdfjs/cmaps/GBK2K-V.bcmap +0 -0
  124. package/dist/web/vendor/pdfjs/cmaps/GBKp-EUC-H.bcmap +0 -0
  125. package/dist/web/vendor/pdfjs/cmaps/GBKp-EUC-V.bcmap +0 -0
  126. package/dist/web/vendor/pdfjs/cmaps/GBT-EUC-H.bcmap +0 -0
  127. package/dist/web/vendor/pdfjs/cmaps/GBT-EUC-V.bcmap +0 -0
  128. package/dist/web/vendor/pdfjs/cmaps/GBT-H.bcmap +0 -0
  129. package/dist/web/vendor/pdfjs/cmaps/GBT-V.bcmap +0 -0
  130. package/dist/web/vendor/pdfjs/cmaps/GBTpc-EUC-H.bcmap +0 -0
  131. package/dist/web/vendor/pdfjs/cmaps/GBTpc-EUC-V.bcmap +0 -0
  132. package/dist/web/vendor/pdfjs/cmaps/GBpc-EUC-H.bcmap +0 -0
  133. package/dist/web/vendor/pdfjs/cmaps/GBpc-EUC-V.bcmap +0 -0
  134. package/dist/web/vendor/pdfjs/cmaps/H.bcmap +0 -0
  135. package/dist/web/vendor/pdfjs/cmaps/HKdla-B5-H.bcmap +0 -0
  136. package/dist/web/vendor/pdfjs/cmaps/HKdla-B5-V.bcmap +0 -0
  137. package/dist/web/vendor/pdfjs/cmaps/HKdlb-B5-H.bcmap +0 -0
  138. package/dist/web/vendor/pdfjs/cmaps/HKdlb-B5-V.bcmap +0 -0
  139. package/dist/web/vendor/pdfjs/cmaps/HKgccs-B5-H.bcmap +0 -0
  140. package/dist/web/vendor/pdfjs/cmaps/HKgccs-B5-V.bcmap +0 -0
  141. package/dist/web/vendor/pdfjs/cmaps/HKm314-B5-H.bcmap +0 -0
  142. package/dist/web/vendor/pdfjs/cmaps/HKm314-B5-V.bcmap +0 -0
  143. package/dist/web/vendor/pdfjs/cmaps/HKm471-B5-H.bcmap +0 -0
  144. package/dist/web/vendor/pdfjs/cmaps/HKm471-B5-V.bcmap +0 -0
  145. package/dist/web/vendor/pdfjs/cmaps/HKscs-B5-H.bcmap +0 -0
  146. package/dist/web/vendor/pdfjs/cmaps/HKscs-B5-V.bcmap +0 -0
  147. package/dist/web/vendor/pdfjs/cmaps/Hankaku.bcmap +0 -0
  148. package/dist/web/vendor/pdfjs/cmaps/Hiragana.bcmap +0 -0
  149. package/dist/web/vendor/pdfjs/cmaps/KSC-EUC-H.bcmap +0 -0
  150. package/dist/web/vendor/pdfjs/cmaps/KSC-EUC-V.bcmap +0 -0
  151. package/dist/web/vendor/pdfjs/cmaps/KSC-H.bcmap +0 -0
  152. package/dist/web/vendor/pdfjs/cmaps/KSC-Johab-H.bcmap +0 -0
  153. package/dist/web/vendor/pdfjs/cmaps/KSC-Johab-V.bcmap +0 -0
  154. package/dist/web/vendor/pdfjs/cmaps/KSC-V.bcmap +0 -0
  155. package/dist/web/vendor/pdfjs/cmaps/KSCms-UHC-H.bcmap +0 -0
  156. package/dist/web/vendor/pdfjs/cmaps/KSCms-UHC-HW-H.bcmap +0 -0
  157. package/dist/web/vendor/pdfjs/cmaps/KSCms-UHC-HW-V.bcmap +0 -0
  158. package/dist/web/vendor/pdfjs/cmaps/KSCms-UHC-V.bcmap +0 -0
  159. package/dist/web/vendor/pdfjs/cmaps/KSCpc-EUC-H.bcmap +0 -0
  160. package/dist/web/vendor/pdfjs/cmaps/KSCpc-EUC-V.bcmap +0 -0
  161. package/dist/web/vendor/pdfjs/cmaps/Katakana.bcmap +0 -0
  162. package/dist/web/vendor/pdfjs/cmaps/LICENSE +36 -0
  163. package/dist/web/vendor/pdfjs/cmaps/NWP-H.bcmap +0 -0
  164. package/dist/web/vendor/pdfjs/cmaps/NWP-V.bcmap +0 -0
  165. package/dist/web/vendor/pdfjs/cmaps/RKSJ-H.bcmap +0 -0
  166. package/dist/web/vendor/pdfjs/cmaps/RKSJ-V.bcmap +0 -0
  167. package/dist/web/vendor/pdfjs/cmaps/Roman.bcmap +0 -0
  168. package/dist/web/vendor/pdfjs/cmaps/UniCNS-UCS2-H.bcmap +0 -0
  169. package/dist/web/vendor/pdfjs/cmaps/UniCNS-UCS2-V.bcmap +0 -0
  170. package/dist/web/vendor/pdfjs/cmaps/UniCNS-UTF16-H.bcmap +0 -0
  171. package/dist/web/vendor/pdfjs/cmaps/UniCNS-UTF16-V.bcmap +0 -0
  172. package/dist/web/vendor/pdfjs/cmaps/UniCNS-UTF32-H.bcmap +0 -0
  173. package/dist/web/vendor/pdfjs/cmaps/UniCNS-UTF32-V.bcmap +0 -0
  174. package/dist/web/vendor/pdfjs/cmaps/UniCNS-UTF8-H.bcmap +0 -0
  175. package/dist/web/vendor/pdfjs/cmaps/UniCNS-UTF8-V.bcmap +0 -0
  176. package/dist/web/vendor/pdfjs/cmaps/UniGB-UCS2-H.bcmap +0 -0
  177. package/dist/web/vendor/pdfjs/cmaps/UniGB-UCS2-V.bcmap +0 -0
  178. package/dist/web/vendor/pdfjs/cmaps/UniGB-UTF16-H.bcmap +0 -0
  179. package/dist/web/vendor/pdfjs/cmaps/UniGB-UTF16-V.bcmap +0 -0
  180. package/dist/web/vendor/pdfjs/cmaps/UniGB-UTF32-H.bcmap +0 -0
  181. package/dist/web/vendor/pdfjs/cmaps/UniGB-UTF32-V.bcmap +0 -0
  182. package/dist/web/vendor/pdfjs/cmaps/UniGB-UTF8-H.bcmap +0 -0
  183. package/dist/web/vendor/pdfjs/cmaps/UniGB-UTF8-V.bcmap +0 -0
  184. package/dist/web/vendor/pdfjs/cmaps/UniJIS-UCS2-H.bcmap +0 -0
  185. package/dist/web/vendor/pdfjs/cmaps/UniJIS-UCS2-HW-H.bcmap +0 -0
  186. package/dist/web/vendor/pdfjs/cmaps/UniJIS-UCS2-HW-V.bcmap +0 -0
  187. package/dist/web/vendor/pdfjs/cmaps/UniJIS-UCS2-V.bcmap +0 -0
  188. package/dist/web/vendor/pdfjs/cmaps/UniJIS-UTF16-H.bcmap +0 -0
  189. package/dist/web/vendor/pdfjs/cmaps/UniJIS-UTF16-V.bcmap +0 -0
  190. package/dist/web/vendor/pdfjs/cmaps/UniJIS-UTF32-H.bcmap +0 -0
  191. package/dist/web/vendor/pdfjs/cmaps/UniJIS-UTF32-V.bcmap +0 -0
  192. package/dist/web/vendor/pdfjs/cmaps/UniJIS-UTF8-H.bcmap +0 -0
  193. package/dist/web/vendor/pdfjs/cmaps/UniJIS-UTF8-V.bcmap +0 -0
  194. package/dist/web/vendor/pdfjs/cmaps/UniJIS2004-UTF16-H.bcmap +0 -0
  195. package/dist/web/vendor/pdfjs/cmaps/UniJIS2004-UTF16-V.bcmap +0 -0
  196. package/dist/web/vendor/pdfjs/cmaps/UniJIS2004-UTF32-H.bcmap +0 -0
  197. package/dist/web/vendor/pdfjs/cmaps/UniJIS2004-UTF32-V.bcmap +0 -0
  198. package/dist/web/vendor/pdfjs/cmaps/UniJIS2004-UTF8-H.bcmap +0 -0
  199. package/dist/web/vendor/pdfjs/cmaps/UniJIS2004-UTF8-V.bcmap +0 -0
  200. package/dist/web/vendor/pdfjs/cmaps/UniJISPro-UCS2-HW-V.bcmap +0 -0
  201. package/dist/web/vendor/pdfjs/cmaps/UniJISPro-UCS2-V.bcmap +0 -0
  202. package/dist/web/vendor/pdfjs/cmaps/UniJISPro-UTF8-V.bcmap +0 -0
  203. package/dist/web/vendor/pdfjs/cmaps/UniJISX0213-UTF32-H.bcmap +0 -0
  204. package/dist/web/vendor/pdfjs/cmaps/UniJISX0213-UTF32-V.bcmap +0 -0
  205. package/dist/web/vendor/pdfjs/cmaps/UniJISX02132004-UTF32-H.bcmap +0 -0
  206. package/dist/web/vendor/pdfjs/cmaps/UniJISX02132004-UTF32-V.bcmap +0 -0
  207. package/dist/web/vendor/pdfjs/cmaps/UniKS-UCS2-H.bcmap +0 -0
  208. package/dist/web/vendor/pdfjs/cmaps/UniKS-UCS2-V.bcmap +0 -0
  209. package/dist/web/vendor/pdfjs/cmaps/UniKS-UTF16-H.bcmap +0 -0
  210. package/dist/web/vendor/pdfjs/cmaps/UniKS-UTF16-V.bcmap +0 -0
  211. package/dist/web/vendor/pdfjs/cmaps/UniKS-UTF32-H.bcmap +0 -0
  212. package/dist/web/vendor/pdfjs/cmaps/UniKS-UTF32-V.bcmap +0 -0
  213. package/dist/web/vendor/pdfjs/cmaps/UniKS-UTF8-H.bcmap +0 -0
  214. package/dist/web/vendor/pdfjs/cmaps/UniKS-UTF8-V.bcmap +0 -0
  215. package/dist/web/vendor/pdfjs/cmaps/V.bcmap +0 -0
  216. package/dist/web/vendor/pdfjs/cmaps/WP-Symbol.bcmap +0 -0
  217. package/dist/web/vendor/pdfjs/iccs/CGATS001Compat-v2-micro.icc +0 -0
  218. package/dist/web/vendor/pdfjs/iccs/LICENSE +116 -0
  219. package/dist/web/vendor/pdfjs/pdf.min.mjs +28 -0
  220. package/dist/web/vendor/pdfjs/pdf.worker.mjs +64908 -0
  221. package/dist/web/vendor/pdfjs/standard_fonts/FoxitDingbats.pfb +0 -0
  222. package/dist/web/vendor/pdfjs/standard_fonts/FoxitFixed.pfb +0 -0
  223. package/dist/web/vendor/pdfjs/standard_fonts/FoxitFixedBold.pfb +0 -0
  224. package/dist/web/vendor/pdfjs/standard_fonts/FoxitFixedBoldItalic.pfb +0 -0
  225. package/dist/web/vendor/pdfjs/standard_fonts/FoxitFixedItalic.pfb +0 -0
  226. package/dist/web/vendor/pdfjs/standard_fonts/FoxitSerif.pfb +0 -0
  227. package/dist/web/vendor/pdfjs/standard_fonts/FoxitSerifBold.pfb +0 -0
  228. package/dist/web/vendor/pdfjs/standard_fonts/FoxitSerifBoldItalic.pfb +0 -0
  229. package/dist/web/vendor/pdfjs/standard_fonts/FoxitSerifItalic.pfb +0 -0
  230. package/dist/web/vendor/pdfjs/standard_fonts/FoxitSymbol.pfb +0 -0
  231. package/dist/web/vendor/pdfjs/standard_fonts/LICENSE_FOXIT +27 -0
  232. package/dist/web/vendor/pdfjs/standard_fonts/LICENSE_LIBERATION +363 -0
  233. package/dist/web/vendor/pdfjs/standard_fonts/LiberationSans-Bold.ttf +0 -0
  234. package/dist/web/vendor/pdfjs/standard_fonts/LiberationSans-BoldItalic.ttf +0 -0
  235. package/dist/web/vendor/pdfjs/standard_fonts/LiberationSans-Italic.ttf +0 -0
  236. package/dist/web/vendor/pdfjs/standard_fonts/LiberationSans-Regular.ttf +0 -0
  237. package/dist/web/vendor/pdfjs/wasm/LICENSE_JBIG2 +196 -0
  238. package/dist/web/vendor/pdfjs/wasm/LICENSE_OPENJPEG +39 -0
  239. package/dist/web/vendor/pdfjs/wasm/LICENSE_PDFJS_JBIG2 +13 -0
  240. package/dist/web/vendor/pdfjs/wasm/LICENSE_PDFJS_OPENJPEG +22 -0
  241. package/dist/web/vendor/pdfjs/wasm/LICENSE_PDFJS_QCMS +19 -0
  242. package/dist/web/vendor/pdfjs/wasm/LICENSE_QCMS +21 -0
  243. package/dist/web/vendor/pdfjs/wasm/jbig2.wasm +0 -0
  244. package/dist/web/vendor/pdfjs/wasm/jbig2_nowasm_fallback.js +15 -0
  245. package/dist/web/vendor/pdfjs/wasm/openjpeg.wasm +0 -0
  246. package/dist/web/vendor/pdfjs/wasm/openjpeg_nowasm_fallback.js +17 -0
  247. package/dist/web/vendor/pdfjs/wasm/qcms_bg.wasm +0 -0
  248. package/dist/web/workspaces.js +167 -26
  249. package/home-env.mjs +28 -0
  250. package/install-path.mjs +59 -3
  251. package/launch-starting-page.mjs +35 -15
  252. package/launch.mjs +358 -51
  253. package/package.json +2 -1
  254. package/pin-home.mjs +6 -0
  255. package/post-update-marker.mjs +14 -0
  256. package/preferences-file.mjs +289 -0
  257. package/supervisor-lock.mjs +195 -0
@@ -0,0 +1,289 @@
1
+ // The preferences that follow the person across the FloLess window and the browser tab (#2963, epic #2960).
2
+ //
3
+ // One small JSON file under the FloLess home, read by the server AND by the launcher (which runs with no server up, so this
4
+ // module is dependency-free: Node built-ins only, like autostart.mjs and desktop-shell.mjs). Only the server writes it.
5
+ //
6
+ // { version:1, generation, revision, client, tray, trayExplained, theme?, lastProject?, whatsNewSeen?, chatRead:{id:n}, seededOwners:[] }
7
+ //
8
+ // - A field that is ABSENT has never been set: only then may the one-time migration from browser storage fill it. An explicit
9
+ // clear stores '' (lastProject, whatsNewSeen), which counts as set, so an old browser can never resurrect it.
10
+ // - `generation` is minted when the file is created and `revision` rises on every change, so a page can tell a stale answer
11
+ // from a newer one and knows when the store behind it was replaced.
12
+ // - Every change is one strict read-modify-write under an exclusive lock file, so two server processes sharing one home cannot
13
+ // lose each other's change. A file this build cannot read or does not understand is never overwritten.
14
+ import { closeSync, existsSync, mkdirSync, openSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
15
+ import { randomBytes } from 'node:crypto';
16
+ import { homedir } from 'node:os';
17
+ import { dirname, join } from 'node:path';
18
+
19
+ export const CLIENTS = ['browser', 'window'];
20
+ export const THEMES = ['dark', 'light'];
21
+ export const MAX_CHAT_CURSORS = 5000;
22
+ const LOCK_STALE_MS = 30_000;
23
+ const LOCK_WAIT_MS = 800; // short on purpose: the wait blocks this process's event loop
24
+
25
+ export const preferencesPath = () => join(process.env.FLOLESS_HOME ?? join(homedir(), '.floless'), 'preferences.json');
26
+
27
+ const isRecord = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
28
+ const CHAT_ID = /^[A-Za-z0-9._:-]{1,80}$/;
29
+ const OWNER_ID = /^[A-Za-z0-9._:/@-]{1,160}$/;
30
+ const sequence = (n) => Number.isSafeInteger(n) && n >= 0 && n <= 1_000_000_000;
31
+
32
+ /**
33
+ * What a missing file means: the defaults. `client` is null until a person (or the launcher, once, for a new install: see
34
+ * `resolveClientForOpen`) chooses it; null is never written back by a change to another preference, so "never chosen" stays visible.
35
+ */
36
+ export function defaultPreferences() {
37
+ return { version: 1, generation: null, revision: 0, client: null, tray: true, trayExplained: false, autostart: null, theme: null, lastProject: null,
38
+ whatsNewSeen: null, chatRead: {}, seededOwners: [] };
39
+ }
40
+
41
+ function normalise(raw) {
42
+ const d = defaultPreferences();
43
+ const out = { ...d, generation: typeof raw.generation === 'string' ? raw.generation : null,
44
+ revision: Number.isSafeInteger(raw.revision) && raw.revision >= 0 ? raw.revision : 0 };
45
+ if (CLIENTS.includes(raw.client)) out.client = raw.client;
46
+ if (typeof raw.tray === 'boolean') out.tray = raw.tray;
47
+ if (typeof raw.trayExplained === 'boolean') out.trayExplained = raw.trayExplained;
48
+ if (typeof raw.autostart === 'boolean') out.autostart = raw.autostart; // the explicit Start with Windows choice (#3070); null = never chosen
49
+ if (THEMES.includes(raw.theme)) out.theme = raw.theme;
50
+ if (typeof raw.lastProject === 'string' && raw.lastProject.length <= 200) out.lastProject = raw.lastProject;
51
+ if (typeof raw.whatsNewSeen === 'string' && raw.whatsNewSeen.length <= 64) out.whatsNewSeen = raw.whatsNewSeen;
52
+ if (isRecord(raw.chatRead)) {
53
+ for (const [id, n] of Object.entries(raw.chatRead)) if (CHAT_ID.test(id) && sequence(n)) out.chatRead[id] = n;
54
+ }
55
+ if (Array.isArray(raw.seededOwners)) out.seededOwners = raw.seededOwners.filter((o) => typeof o === 'string' && OWNER_ID.test(o)).slice(-200); // the newest owners survive the cap
56
+ return out;
57
+ }
58
+
59
+ /** { state: 'ok' | 'missing' | 'unreadable' | 'newer', prefs }. Reading never throws; a bad file reads as the defaults. */
60
+ export function readPreferences(path = preferencesPath()) {
61
+ let text;
62
+ // Windows can refuse a read for a moment while an atomic rename lands (EBUSY/EPERM/EACCES): retry before calling a file unreadable,
63
+ // because 'unreadable' reads as the defaults and a person's choice must not flip back for that.
64
+ for (let attempt = 0; ; attempt += 1) {
65
+ try { text = readFileSync(path, 'utf8'); break; }
66
+ catch (error) {
67
+ if (error?.code === 'ENOENT') return { state: 'missing', prefs: defaultPreferences() };
68
+ if (attempt < 3 && ['EBUSY', 'EPERM', 'EACCES'].includes(error?.code)) { sleepSync(20); continue; }
69
+ return { state: 'unreadable', prefs: defaultPreferences() };
70
+ }
71
+ }
72
+ let raw;
73
+ try { raw = JSON.parse(text); } catch { return { state: 'unreadable', prefs: defaultPreferences() }; }
74
+ if (!isRecord(raw)) return { state: 'unreadable', prefs: defaultPreferences() };
75
+ if (raw.version !== 1) return { state: 'newer', prefs: defaultPreferences() };
76
+ return { state: 'ok', prefs: normalise(raw) };
77
+ }
78
+
79
+ /** The client a page and an action report: the stored choice, else the browser (a never-chosen install has no window yet). */
80
+ export const effectiveClient = (prefs) => (prefs.client === 'window' ? 'window' : 'browser');
81
+
82
+ /** The stored client choice for `FlolessApp.exe open`: 'window' only when it was explicitly chosen. Never throws. */
83
+ export function readClientPreference(path = preferencesPath()) {
84
+ try { return effectiveClient(readPreferences(path).prefs); } catch { return 'browser'; }
85
+ }
86
+
87
+ // Entries the launcher, the shell and this file itself leave in the FloLess home: they say nothing about earlier use.
88
+ const NOT_PRIOR_USE = /^(shell|preferences\.json.*|autostart\.lock|supervisor\.(lock|json.*)|\.post-update.*|\.floless-post-update)$/;
89
+
90
+ /**
91
+ * Does the FloLess home hold anything a person's earlier use left behind (projects, settings, a signed-in session, history)?
92
+ * Only a home that is missing or empty (bar the launcher's own entries) is a new install. Never throws; on doubt, true (keep the browser).
93
+ */
94
+ export function homeHasPriorUse(home = process.env.FLOLESS_HOME ?? join(homedir(), '.floless')) {
95
+ try { return readdirSync(home).some((name) => !NOT_PRIOR_USE.test(name)); }
96
+ catch (error) { return error?.code === 'ENOENT' ? false : true; }
97
+ }
98
+
99
+ /**
100
+ * The Velopack install hook (`--veloapp-install`) is the one moment a FRESH install is known for certain: it is the first process of
101
+ * the new install, before the supervisor, autostart, skill sync or any server boot has written anything into the home. It settles
102
+ * the client then, with the same rule `open` uses (a home with earlier use, e.g. a reinstall over kept data, is not new), so nothing
103
+ * the first run writes can turn a new install into an "existing" one. Never throws.
104
+ */
105
+ export function settleClientOnInstall(path = preferencesPath(), opts) {
106
+ let answer = 'browser';
107
+ // A lock or write failure still answers, but would leave nothing stored for the first run to overwrite: try again a few times.
108
+ for (let attempt = 0; attempt < 5; attempt += 1) {
109
+ answer = resolveClientForOpen(path, opts);
110
+ try { const { state, prefs } = readPreferences(path); if (prefs.client || state === 'unreadable' || state === 'newer') break; } catch { /* retry */ }
111
+ sleepSync(300);
112
+ }
113
+ return answer;
114
+ }
115
+
116
+ /**
117
+ * The Velopack update hook (`--veloapp-updated`): an install that existed before this build keeps what it had. A client never
118
+ * chosen is written down as the browser tab now, so it cannot later read as new. A stored choice, and an unreadable or newer
119
+ * file, are left alone. Never throws.
120
+ */
121
+ export function settleClientOnUpdate(path = preferencesPath()) {
122
+ try {
123
+ updatePreferences((p) => { if (p.client) return false; p.client = 'browser'; return true; }, path);
124
+ } catch { /* unreadable, newer, busy: keep whatever is there */ }
125
+ }
126
+
127
+ /**
128
+ * Which client a plain `FlolessApp.exe open` shows (S3, #2964). A stored choice always wins. With none, a NEW install gets the
129
+ * window and an install that was in use before this build keeps what it had, the browser tab: the preferences file existing at all,
130
+ * or anything in the home from earlier use, means "existing". The answer is written once (under the lock, only if still unchosen)
131
+ * so a server that fills the home on the first run cannot turn a new install into an existing one on the next launch. A file this
132
+ * build cannot read or understand is never written and never forces the window. Never throws.
133
+ */
134
+ export function resolveClientForOpen(path = preferencesPath(), { prior = homeHasPriorUse } = {}) {
135
+ try {
136
+ const { state, prefs } = readPreferences(path);
137
+ if (prefs.client) return prefs.client;
138
+ if (state === 'unreadable' || state === 'newer') return 'browser';
139
+ // What this launch would give if nothing changes meanwhile; the decision itself is re-made under the lock below.
140
+ const guess = state === 'missing' && !prior() ? 'window' : 'browser';
141
+ try {
142
+ // Another process may have created the file between the read above and the lock: then this is no longer a new install.
143
+ const written = updatePreferences((p) => {
144
+ if (p.client) return false;
145
+ p.client = state === 'missing' && !existsSync(path) && !prior() ? 'window' : 'browser';
146
+ return true;
147
+ }, path);
148
+ return written.client ?? guess;
149
+ } catch (error) {
150
+ if (error instanceof PreferencesUnsafeError) return 'browser'; // the file turned unreadable or newer meanwhile
151
+ return guess; // busy or unwritable: still honour the answer for this launch
152
+ }
153
+ } catch { return 'browser'; }
154
+ }
155
+
156
+ /** Whether the tray is switched on (default on). Never throws. */
157
+ export function readTrayPreference(path = preferencesPath()) {
158
+ try { return readPreferences(path).prefs.tray !== false; } catch { return true; }
159
+ }
160
+
161
+ /**
162
+ * The person's explicit Start with Windows choice (#3070), as the launcher and the install hooks must read it:
163
+ * 'on' never chosen (missing file, or no choice stored) or chosen on: keep the sign-in task in place, as before
164
+ * 'off' the person turned it off: nothing may bring the task back
165
+ * 'unknown' the file is unreadable or from a newer build: change nothing, neither register nor remove
166
+ * Never throws.
167
+ */
168
+ export function readAutostartIntent(path = preferencesPath()) {
169
+ try {
170
+ const { state, prefs } = readPreferences(path);
171
+ if (state === 'unreadable' || state === 'newer') return 'unknown';
172
+ return prefs.autostart === false ? 'off' : 'on';
173
+ } catch { return 'unknown'; }
174
+ }
175
+
176
+ /** The raw stored choice: 'unset' (never chosen), 'on', 'off', or 'unknown' (unreadable or newer file). Never throws. */
177
+ export function readAutostartStored(path = preferencesPath()) {
178
+ try {
179
+ const { state, prefs } = readPreferences(path);
180
+ if (state === 'unreadable' || state === 'newer') return 'unknown';
181
+ return prefs.autostart === false ? 'off' : prefs.autostart === true ? 'on' : 'unset';
182
+ } catch { return 'unknown'; }
183
+ }
184
+
185
+ /** Store the explicit choice. Throws PreferencesUnsafeError / PreferencesBusyError instead of overwriting a file it cannot read. */
186
+ export function setAutostartIntent(enabled, path = preferencesPath(), opts) {
187
+ return updatePreferences((p) => { if (p.autostart === enabled) return false; p.autostart = enabled; return true; }, path, opts);
188
+ }
189
+
190
+ const sleepSync = (ms) => { try { Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms); } catch { /* no wait available: spin once */ } };
191
+
192
+ export function withLock(path, fn, { staleMs = LOCK_STALE_MS, waitMs = LOCK_WAIT_MS } = {}) {
193
+ const lock = `${path}.lock`;
194
+ mkdirSync(dirname(path), { recursive: true });
195
+ const until = Date.now() + waitMs;
196
+ for (;;) {
197
+ try { closeSync(openSync(lock, 'wx')); break; }
198
+ catch (error) {
199
+ if (error?.code !== 'EEXIST') throw error;
200
+ try { if (Date.now() - statSync(lock).mtimeMs > staleMs) { rmSync(lock, { force: true }); continue; } } catch { /* raced */ }
201
+ if (Date.now() > until) throw new PreferencesBusyError();
202
+ sleepSync(15);
203
+ }
204
+ }
205
+ try { return fn(); } finally { try { rmSync(lock, { force: true }); } catch { /* best effort */ } }
206
+ }
207
+
208
+ export class PreferencesBusyError extends Error { constructor() { super('the preferences file is in use'); this.code = 'PREFERENCES_BUSY'; } }
209
+ export class PreferencesUnsafeError extends Error { constructor(state) { super(`the preferences file is ${state}`); this.code = 'PREFERENCES_UNSAFE'; this.state = state; } }
210
+
211
+ /**
212
+ * Change the preferences: `mutate(prefs)` edits a copy and returns true when something changed. The file is rewritten (atomically,
213
+ * under the lock, revision +1) only then. An unreadable or newer file refuses the change instead of being overwritten.
214
+ */
215
+ export function updatePreferences(mutate, path = preferencesPath(), opts) {
216
+ return withLock(path, () => {
217
+ const { state, prefs } = readPreferences(path);
218
+ if (state === 'unreadable' || state === 'newer') throw new PreferencesUnsafeError(state);
219
+ const next = structuredClone(prefs);
220
+ if (!next.generation) next.generation = randomBytes(8).toString('hex');
221
+ // Nothing changed: nothing is written and no generation is minted (a never-written file keeps answering generation null).
222
+ if (!mutate(next)) return prefs;
223
+ next.revision = prefs.revision + 1;
224
+ const tmp = `${path}.${process.pid}.${randomBytes(3).toString('hex')}.tmp`;
225
+ writeFileSync(tmp, JSON.stringify(next));
226
+ renameSync(tmp, path);
227
+ return next;
228
+ }, opts);
229
+ }
230
+
231
+ /** Merge read cursors by maximum. `onlyNew` adds a cursor only for a chat that has none (the baseline seed). Returns whether anything changed. */
232
+ export function mergeChatRead(prefs, cursors, { onlyNew = false } = {}) {
233
+ let changed = false;
234
+ for (const [id, n] of Object.entries(cursors)) {
235
+ if (!CHAT_ID.test(id) || !sequence(n)) continue;
236
+ const has = Object.hasOwn(prefs.chatRead, id);
237
+ if (onlyNew && has) continue;
238
+ if (!has && Object.keys(prefs.chatRead).length >= MAX_CHAT_CURSORS) continue;
239
+ if (!has || n > prefs.chatRead[id]) { prefs.chatRead[id] = n; changed = true; }
240
+ }
241
+ return changed;
242
+ }
243
+
244
+ /** Validate a partial patch from the page or an action. { ok, value } or { ok:false, error } in plain words. */
245
+ export function validatePatch(body) {
246
+ if (!isRecord(body)) return { ok: false, error: 'Say which preference to change.' };
247
+ const value = {};
248
+ for (const [key, v] of Object.entries(body)) {
249
+ if (key === 'client') { if (!CLIENTS.includes(v)) return { ok: false, error: 'Choose window or browser.' }; value.client = v; }
250
+ else if (key === 'tray') { if (typeof v !== 'boolean') return { ok: false, error: 'Say whether the tray icon should be on or off.' }; value.tray = v; }
251
+ else if (key === 'trayExplained') { if (typeof v !== 'boolean') return { ok: false, error: 'Say whether the tray explanation was seen.' }; value.trayExplained = v; }
252
+ else if (key === 'theme') { if (!THEMES.includes(v)) return { ok: false, error: 'Choose the dark or the light theme.' }; value.theme = v; }
253
+ else if (key === 'lastProject') { if (typeof v !== 'string' || v.length > 200) return { ok: false, error: 'That project name is not valid.' }; value.lastProject = v; }
254
+ else if (key === 'whatsNewSeen') { if (typeof v !== 'string' || v.length > 64) return { ok: false, error: 'That version is not valid.' }; value.whatsNewSeen = v; }
255
+ else return { ok: false, error: 'FloLess does not know that preference.' };
256
+ }
257
+ return Object.keys(value).length ? { ok: true, value } : { ok: false, error: 'Say which preference to change.' };
258
+ }
259
+
260
+ export function applyPatch(prefs, patch) {
261
+ let changed = false;
262
+ for (const [k, v] of Object.entries(patch)) if (prefs[k] !== v) { prefs[k] = v; changed = true; }
263
+ return changed;
264
+ }
265
+
266
+ /** The one-time seed from a page's browser storage: each field only when the store has never had it; read cursors by maximum. */
267
+ export function applyMigration(prefs, body) {
268
+ if (!isRecord(body)) return false;
269
+ let changed = false;
270
+ if (prefs.theme === null && THEMES.includes(body.theme)) { prefs.theme = body.theme; changed = true; }
271
+ if (prefs.lastProject === null && typeof body.lastProject === 'string' && body.lastProject.length <= 200) { prefs.lastProject = body.lastProject; changed = true; }
272
+ if (prefs.whatsNewSeen === null && typeof body.whatsNewSeen === 'string' && body.whatsNewSeen.length <= 64) { prefs.whatsNewSeen = body.whatsNewSeen; changed = true; }
273
+ if (isRecord(body.chatRead) && mergeChatRead(prefs, body.chatRead)) changed = true;
274
+ return changed;
275
+ }
276
+
277
+ /** The first visit of an owner in any client: seed read cursors only for chats with none, once per owner. */
278
+ export function applySeed(prefs, owner, cursors) {
279
+ if (typeof owner !== 'string' || !OWNER_ID.test(owner) || prefs.seededOwners.includes(owner)) return false;
280
+ mergeChatRead(prefs, isRecord(cursors) ? cursors : {}, { onlyNew: true });
281
+ prefs.seededOwners.push(owner);
282
+ return true;
283
+ }
284
+
285
+ /** What a client may see: everything except nothing is secret here, but the shape is explicit. */
286
+ export function preferencesView(prefs) {
287
+ return { generation: prefs.generation, revision: prefs.revision, client: effectiveClient(prefs), tray: prefs.tray, trayExplained: prefs.trayExplained,
288
+ theme: prefs.theme, lastProject: prefs.lastProject, whatsNewSeen: prefs.whatsNewSeen, chatRead: prefs.chatRead, seededOwners: prefs.seededOwners };
289
+ }
@@ -0,0 +1,195 @@
1
+ // Who is the FloLess supervisor? (#3069, epic #2960)
2
+ //
3
+ // The supervisor keeps the server (and the tray) alive. It can be started from three places: the sign-in task, a manual
4
+ // Start (the stopped screen's link, floless://start, the tray's Start FloLess) and an update's recovery. Task Scheduler's
5
+ // "ignore new instance" rule cannot keep them apart, because the supervisor hands its loop to a detached copy of itself and
6
+ // the task finishes at once. So the LOOP itself takes ownership: one small file under the FloLess home names the process that
7
+ // owns it and is touched on every supervisor tick. A second supervisor sees a live owner and steps aside; a manual Start asks
8
+ // the same question and starts one only when nobody owns it. No process enumeration is involved (a failed enumeration reads as
9
+ // "nothing is running", which would start a second one).
10
+ //
11
+ // The file alone is not enough (#3091): if it cannot be written at all, ownership cannot be recorded and a second supervisor
12
+ // would start next to the first. So on Windows every supervisor also holds a NAMED PIPE for as long as it lives. A pipe name is
13
+ // an object the OS owns: only one process can listen on it, it vanishes the instant that process dies for any reason (no stale
14
+ // state to clean up, no port to collide with), and supervisor.json is not involved. Its name carries a per-home secret so no
15
+ // other user on the computer can squat it. The exclusivity is among supervisors that all claim
16
+ // the pipe; one that cannot (an older release, or a computer that refuses pipes) is still only fenced by the file's heartbeat.
17
+ //
18
+ // Dependency-free (Node built-ins and preferences-file.mjs's lock only), like the other launcher modules.
19
+ import { linkSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
20
+ import { homedir } from 'node:os';
21
+ import { basename, dirname, join, resolve } from 'node:path';
22
+ import { createHash, randomBytes } from 'node:crypto';
23
+ import net from 'node:net';
24
+ import { withLock } from './preferences-file.mjs';
25
+
26
+ /** An owner that has not touched the file for this long is gone, whatever its pid says (a pid can be reused). */
27
+ export const SUPERVISOR_STALE_MS = 30_000;
28
+
29
+ const home = () => process.env.FLOLESS_HOME ?? join(homedir(), '.floless');
30
+ export const supervisorFilePath = () => join(home(), 'supervisor.json');
31
+ const guardPath = () => join(home(), 'supervisor'); // withLock makes <this>.lock
32
+
33
+ const sleepSync = (ms) => { try { Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms); } catch { /* no wait available */ } };
34
+ const pidAlive = (pid) => {
35
+ if (!Number.isSafeInteger(pid) || pid <= 0) return false;
36
+ try { process.kill(pid, 0); return true; } catch (error) { return error?.code === 'EPERM'; }
37
+ };
38
+
39
+ /** The folder's canonical path: the nearest existing ancestor through realpath (junctions, 8.3 names), plus what does not exist yet. */
40
+ function canonicalFolder(dir) {
41
+ let head = resolve(dir);
42
+ const tail = [];
43
+ for (;;) {
44
+ try { head = realpathSync.native(head); break; } catch {
45
+ const up = dirname(head);
46
+ if (up === head) break;
47
+ tail.unshift(basename(head));
48
+ head = up;
49
+ }
50
+ }
51
+ return join(head, ...tail).replace(/[\\/]+$/, '').toLowerCase();
52
+ }
53
+
54
+ /**
55
+ * A pipe name lives in the machine-wide namespace, so another user or session on the computer could create a guessable
56
+ * one (say, derived from the home path) and make our supervisor believe another is running. The name therefore includes
57
+ * a random per-home secret kept in `supervisor.key` inside the home (made once, never rewritten, readable only where the
58
+ * home is). Whoever cannot read it cannot name the pipe. When no secret can be read or made there is no pipe at all and
59
+ * the file's heartbeat decides, as it did before the pipe existed.
60
+ */
61
+ function homeSecret(folder, create) {
62
+ const keyPath = join(folder, 'supervisor.key');
63
+ const read = () => { const v = readFileSync(keyPath, 'utf8').trim(); return /^[0-9a-f]{64}$/.test(v) ? v : null; };
64
+ try { const v = read(); if (v) return v; } catch { /* not there yet */ }
65
+ if (!create) return null;
66
+ const tmp = `${keyPath}.${process.pid}.${randomBytes(3).toString('hex')}.tmp`;
67
+ try {
68
+ mkdirSync(folder, { recursive: true });
69
+ writeFileSync(tmp, randomBytes(32).toString('hex'));
70
+ try { linkSync(tmp, keyPath); } catch (error) { if (error?.code !== 'EEXIST') throw error; } // another supervisor made it first: use theirs
71
+ } catch { return null; } finally { try { rmSync(tmp, { force: true }); } catch { /* best effort */ } }
72
+ try { return read(); } catch { return null; }
73
+ }
74
+
75
+ /** The pipe that names the supervisor of THIS FloLess home (null when the home's secret cannot be had). Isolated homes never share one. */
76
+ export function supervisorPipeName(folder = home(), { create = false } = {}) {
77
+ const secret = homeSecret(folder, create);
78
+ if (!secret) return null;
79
+ const key = createHash('sha256').update(`${canonicalFolder(folder)}\n${secret}`).digest('hex').slice(0, 32);
80
+ return `\\\\.\\pipe\\floless-supervisor-${key}`;
81
+ }
82
+
83
+ function readOwner(path) {
84
+ try {
85
+ const raw = JSON.parse(readFileSync(path, 'utf8'));
86
+ return raw && Number.isSafeInteger(raw.pid) && typeof raw.at === 'number' ? { pid: raw.pid, at: raw.at } : null;
87
+ } catch { return null; }
88
+ }
89
+
90
+ function writeOwner(path, owner) {
91
+ const tmp = `${path}.${process.pid}.${randomBytes(3).toString('hex')}.tmp`;
92
+ try {
93
+ writeFileSync(tmp, JSON.stringify(owner));
94
+ renameSync(tmp, path);
95
+ } catch (error) {
96
+ try { rmSync(tmp, { force: true }); } catch { /* best effort */ } // a destination that cannot be written must not leave a file per beat
97
+ throw error;
98
+ }
99
+ }
100
+
101
+ /**
102
+ * The supervisor's ownership of the loop.
103
+ * ownerAlive() true when a live supervisor other than this process owns it (read-only; what a manual Start asks)
104
+ * acquire() take ownership when nobody else holds it: { held:true } or { held:false, owner }. Under a short lock, so two
105
+ * supervisors starting together cannot both win. A lock that stays busy answers held:true: a duplicate loop
106
+ * is harmless for one more tick, a supervisor that gives up for nothing is not.
107
+ * beat() touch the file (call once per tick): false when another process has taken ownership meanwhile
108
+ * claimPipe() (Windows) take the home's named pipe for the life of this process: 'held' | 'taken' | 'unavailable'
109
+ * release() drop ownership if this process still holds it, and let go of the pipe
110
+ * `alive`, `now`, `pid` and `path` are injectable for tests.
111
+ */
112
+ export function createSupervisorOwnership({ path = supervisorFilePath(), guard = guardPath(), alive = pidAlive, now = Date.now, pid = process.pid,
113
+ usePipe = process.platform === 'win32', pipe: pipeOverride = null } = {}) {
114
+ const pipeFor = (create) => (!usePipe ? null : pipeOverride ?? supervisorPipeName(dirname(path), { create }));
115
+ const live = (owner) => !!owner && owner.pid !== pid && alive(owner.pid) && now() - owner.at < SUPERVISOR_STALE_MS;
116
+ let pipeProblem = null;
117
+ let pipeServer = null; // held for the life of this supervisor; the OS frees the name when the process ends, however it ends
118
+ return {
119
+ // A live owner in the file, or (Windows) another process listening on this home's pipe. The pipe probe is read-only: opening
120
+ // it for a moment is answered and dropped by the holder. Liveness here is process lifetime: a supervisor that is alive but
121
+ // hung keeps the pipe and is not replaced by a manual Start; Stop FloLess or the next sign-in ends it and the OS frees the name.
122
+ ownerAlive() {
123
+ if (live(readOwner(path))) return true;
124
+ const pipe = pipeServer ? null : pipeFor(false); // a home with no secret yet has no pipe, so nothing holds one
125
+ if (!pipe) return false;
126
+ try { statSync(pipe); return true; } catch (error) { return error?.code !== 'ENOENT'; } // only "no such pipe" means nobody holds it
127
+ },
128
+ /** Why the pipe could not be taken ('unavailable'), for the log; null otherwise. */
129
+ pipeProblem() { return pipeProblem; },
130
+ /**
131
+ * Take the pipe before anything else (async: a listen answers on an event). 'held' = this process owns it from now on;
132
+ * 'taken' = another supervisor does, so step aside; 'unavailable' = no pipe here (not Windows, or the computer refused),
133
+ * which leaves the file as the only signal. Called by the supervisor before acquire().
134
+ */
135
+ claimPipe() {
136
+ if (pipeServer) return Promise.resolve('held');
137
+ const pipe = pipeFor(true);
138
+ if (!pipe) { if (usePipe) pipeProblem = 'no private name could be made'; return Promise.resolve('unavailable'); }
139
+ return new Promise((done) => {
140
+ const server = net.createServer((socket) => socket.destroy());
141
+ server.once('error', (error) => {
142
+ if (error?.code === 'EADDRINUSE') return done('taken');
143
+ pipeProblem = String(error?.code ?? error?.message ?? 'unknown');
144
+ done('unavailable');
145
+ });
146
+ server.listen(pipe, () => {
147
+ server.unref();
148
+ pipeServer = server;
149
+ // A pipe that fails later no longer guards anything: say so rather than keep reporting it held.
150
+ server.on('error', (error) => { pipeProblem = String(error?.code ?? error?.message ?? 'unknown'); if (pipeServer === server) pipeServer = null; });
151
+ done('held');
152
+ });
153
+ });
154
+ },
155
+ acquire() {
156
+ let last = null;
157
+ // A write that fails is tried again a few times (a virus scanner or a brief permission change passes); only a folder that
158
+ // stays unwritable degrades, and then the caller is told.
159
+ for (let attempt = 0; attempt < 3; attempt += 1) {
160
+ try {
161
+ mkdirSync(join(path, '..'), { recursive: true });
162
+ return withLock(guard, () => {
163
+ const owner = readOwner(path);
164
+ if (live(owner)) return { held: false, owner };
165
+ writeOwner(path, { pid, at: now() });
166
+ return { held: true };
167
+ }, { waitMs: 3000 });
168
+ } catch (error) {
169
+ // Another supervisor is taking ownership at this very moment (the guard stayed busy): it wins, this one steps aside.
170
+ if (error?.code === 'PREFERENCES_BUSY') return { held: false, owner: null };
171
+ last = error;
172
+ if (attempt < 2) sleepSync(300);
173
+ }
174
+ }
175
+ // The ownership file cannot be written at all. Keep watching rather than give up for nothing: a supervisor that steps aside
176
+ // here would leave the server unwatched. This is the one case where the singleton is best-effort, and it is said out loud.
177
+ return { held: true, degraded: true, reason: String(last?.code ?? last?.message ?? 'unknown') };
178
+ },
179
+ // Under the same guard as acquire(), so an old loop that paused cannot overwrite a takeover it slept through.
180
+ beat() {
181
+ try {
182
+ return withLock(guard, () => {
183
+ const owner = readOwner(path);
184
+ if (owner && owner.pid !== pid && live(owner)) return false;
185
+ writeOwner(path, { pid, at: now() });
186
+ return true;
187
+ }, { waitMs: 500 });
188
+ } catch { return true; } // busy or unwritable: this beat is skipped, the next one tries again
189
+ },
190
+ release() {
191
+ try { if (readOwner(path)?.pid === pid) rmSync(path, { force: true }); } catch { /* best effort */ }
192
+ if (pipeServer) { try { pipeServer.close(); } catch { /* the OS frees it at exit anyway */ } pipeServer = null; }
193
+ },
194
+ };
195
+ }