@patodo/localapp 0.1.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 (527) hide show
  1. package/.localapp-artifact.json +2731 -0
  2. package/LICENSE +21 -0
  3. package/README.md +288 -0
  4. package/bin/localapp.mjs +34182 -0
  5. package/package.json +21 -0
  6. package/runtime/bootstrap/localapp-daemon-bootstrap.mjs +150 -0
  7. package/runtime/native/adapter-manifest.json +85 -0
  8. package/runtime/native/darwin-arm64/LocalAppBridge.app/Contents/Info.plist +21 -0
  9. package/runtime/native/darwin-arm64/LocalAppBridge.app/Contents/MacOS/LocalAppBridge +0 -0
  10. package/runtime/native/darwin-arm64/LocalAppBridge.app/Contents/Resources/localapp-native-ipc-client.mjs +940 -0
  11. package/runtime/native/darwin-arm64/LocalAppBridge.app/Contents/_CodeSignature/CodeResources +128 -0
  12. package/runtime/native/darwin-x64/LocalAppBridge.app/Contents/Info.plist +21 -0
  13. package/runtime/native/darwin-x64/LocalAppBridge.app/Contents/MacOS/LocalAppBridge +0 -0
  14. package/runtime/native/darwin-x64/LocalAppBridge.app/Contents/Resources/localapp-native-ipc-client.mjs +940 -0
  15. package/runtime/native/darwin-x64/LocalAppBridge.app/Contents/_CodeSignature/CodeResources +128 -0
  16. package/runtime/native/linux-x64/localapp-native-ipc-client.mjs +940 -0
  17. package/runtime/native/linux-x64/localapp-notifications +0 -0
  18. package/runtime/native/win32-x64/localapp-native-ipc-client.mjs +940 -0
  19. package/runtime/native/win32-x64/localapp-native.exe +0 -0
  20. package/runtime/server/.localapp-server-runtime.json +133 -0
  21. package/runtime/server/bin/server-cli.cjs +8343 -0
  22. package/runtime/server/bin/server.mjs +8 -0
  23. package/runtime/server/bin/worker.cjs +144339 -0
  24. package/runtime/server/node_modules/sql.js/dist/sql-wasm.js +185 -0
  25. package/runtime/server/node_modules/sql.js/dist/sql-wasm.wasm +0 -0
  26. package/runtime/server/node_modules/sql.js/package.json +58 -0
  27. package/runtime/server/package.json +11 -0
  28. package/runtime/server/runner/localapp-runner.mjs +324 -0
  29. package/runtime/server/web/404.html +1 -0
  30. package/runtime/server/web/_next/static/CqtRUQyhpQ2FmEc3vaVz3/_buildManifest.js +1 -0
  31. package/runtime/server/web/_next/static/CqtRUQyhpQ2FmEc3vaVz3/_ssgManifest.js +1 -0
  32. package/runtime/server/web/_next/static/chunks/184-184da63eba05808f.js +1 -0
  33. package/runtime/server/web/_next/static/chunks/265-a58973dbf631dc41.js +1 -0
  34. package/runtime/server/web/_next/static/chunks/308-d74213c6f5179bf0.js +1 -0
  35. package/runtime/server/web/_next/static/chunks/416-53d48ad9442eb7b2.js +1 -0
  36. package/runtime/server/web/_next/static/chunks/448-280e06e915001cb5.js +1 -0
  37. package/runtime/server/web/_next/static/chunks/66-6f6658280a10fbca.js +1 -0
  38. package/runtime/server/web/_next/static/chunks/740d80ee-6c0a9504f1fd46f8.js +1 -0
  39. package/runtime/server/web/_next/static/chunks/86-7105ac54171494a1.js +1 -0
  40. package/runtime/server/web/_next/static/chunks/900-743e38de13217291.js +1 -0
  41. package/runtime/server/web/_next/static/chunks/app/(dashboard)/inbox/page-32b885c019043e48.js +1 -0
  42. package/runtime/server/web/_next/static/chunks/app/(dashboard)/layout-4b3a212263712a5c.js +1 -0
  43. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/analytics/page-6af9adc14ccfa925.js +1 -0
  44. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/apps/[name]/settings/page-8b6f809eeccdbd22.js +1 -0
  45. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/apps/page-7f1ddf07889da248.js +1 -0
  46. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/dashboard/page-a25eb621fb18491d.js +1 -0
  47. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/device-actions/page-e6045823829567f7.js +1 -0
  48. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/device-notifications/page-377ed49cf55da81d.js +1 -0
  49. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/favorites/page-82f292daebf98a2f.js +1 -0
  50. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/groups/page-fe4ed80c7b11920f.js +1 -0
  51. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/info/page-d5d5075eec069ce3.js +1 -0
  52. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/keys/page-35ed01bf39a163b6.js +1 -0
  53. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/layout-5481d53aae3a0ce1.js +1 -0
  54. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/orgs/page-44c606ff2233f1a8.js +1 -0
  55. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/page-f2331bbbe09541aa.js +1 -0
  56. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/pages/page-6bf4e160a99411ce.js +1 -0
  57. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/peers/page-27041dd149601002.js +1 -0
  58. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/recent/page-f321688d374a8ff3.js +1 -0
  59. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/settings/page-64e724318dc3a584.js +1 -0
  60. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/studio/page-a2c0c34538ac62b3.js +1 -0
  61. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/subscriptions/page-57cdaafe12347e32.js +1 -0
  62. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/system/page-96d2e1f8c2fb22b0.js +1 -0
  63. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/tasks/page-bf16b78ed6749d78.js +1 -0
  64. package/runtime/server/web/_next/static/chunks/app/(dashboard)/my/users/page-c47d4524d2a156b8.js +1 -0
  65. package/runtime/server/web/_next/static/chunks/app/(dashboard)/page-f4641be7b88818a2.js +1 -0
  66. package/runtime/server/web/_next/static/chunks/app/_not-found/page-f4902e6b69eebd4c.js +1 -0
  67. package/runtime/server/web/_next/static/chunks/app/layout-5557bc90d966fded.js +1 -0
  68. package/runtime/server/web/_next/static/chunks/app/platform-shell/[userId]/[name]/page-da0d5e71857f33d1.js +1 -0
  69. package/runtime/server/web/_next/static/chunks/app/platform-shell-preview/page-52fa7e8c8b480934.js +1 -0
  70. package/runtime/server/web/_next/static/chunks/app/setup/page-9e29d6f66825a8f8.js +1 -0
  71. package/runtime/server/web/_next/static/chunks/framework-1c02a2e60068b586.js +1 -0
  72. package/runtime/server/web/_next/static/chunks/main-21ea4d4d10f4a256.js +1 -0
  73. package/runtime/server/web/_next/static/chunks/main-app-5b3c67453d8c5b99.js +1 -0
  74. package/runtime/server/web/_next/static/chunks/pages/_app-649f81c9fedecf29.js +1 -0
  75. package/runtime/server/web/_next/static/chunks/pages/_error-64e3bd84e2ecae08.js +1 -0
  76. package/runtime/server/web/_next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
  77. package/runtime/server/web/_next/static/chunks/webpack-0bed2fdf6baa566e.js +1 -0
  78. package/runtime/server/web/_next/static/css/afdc0938fca59693.css +3 -0
  79. package/runtime/server/web/_next/static/media/013b72fa676f92e0-s.woff2 +0 -0
  80. package/runtime/server/web/_next/static/media/22a5144ee8d83bca-s.p.woff2 +0 -0
  81. package/runtime/server/web/_next/static/media/2b5b02fc7e511755-s.woff2 +0 -0
  82. package/runtime/server/web/_next/static/media/65f03d54ccadf4a8-s.woff2 +0 -0
  83. package/runtime/server/web/_next/static/media/7d4881bb7e1bf84d-s.p.woff2 +0 -0
  84. package/runtime/server/web/_next/static/media/9766a7e9e2e0ad5a-s.woff2 +0 -0
  85. package/runtime/server/web/_next/static/media/aa016aab0e6d1295-s.woff2 +0 -0
  86. package/runtime/server/web/_next/static/media/b66cf8e69499582a-s.woff2 +0 -0
  87. package/runtime/server/web/_next/static/media/b9408752a0c24fb9-s.woff2 +0 -0
  88. package/runtime/server/web/_next/static/media/e038a29029a234f2-s.woff2 +0 -0
  89. package/runtime/server/web/_next/static/media/f639721981034f88-s.woff2 +0 -0
  90. package/runtime/server/web/home/redline-launch-hero.png +0 -0
  91. package/runtime/server/web/inbox.html +1 -0
  92. package/runtime/server/web/inbox.txt +27 -0
  93. package/runtime/server/web/index.html +1 -0
  94. package/runtime/server/web/index.txt +27 -0
  95. package/runtime/server/web/my/analytics.html +1 -0
  96. package/runtime/server/web/my/analytics.txt +27 -0
  97. package/runtime/server/web/my/apps/placeholder/settings.html +1 -0
  98. package/runtime/server/web/my/apps/placeholder/settings.txt +24 -0
  99. package/runtime/server/web/my/apps.html +1 -0
  100. package/runtime/server/web/my/apps.txt +27 -0
  101. package/runtime/server/web/my/dashboard.html +1 -0
  102. package/runtime/server/web/my/dashboard.txt +27 -0
  103. package/runtime/server/web/my/device-actions.html +1 -0
  104. package/runtime/server/web/my/device-actions.txt +24 -0
  105. package/runtime/server/web/my/device-notifications.html +1 -0
  106. package/runtime/server/web/my/device-notifications.txt +24 -0
  107. package/runtime/server/web/my/favorites.html +1 -0
  108. package/runtime/server/web/my/favorites.txt +27 -0
  109. package/runtime/server/web/my/groups.html +1 -0
  110. package/runtime/server/web/my/groups.txt +27 -0
  111. package/runtime/server/web/my/info.html +1 -0
  112. package/runtime/server/web/my/info.txt +27 -0
  113. package/runtime/server/web/my/keys.html +1 -0
  114. package/runtime/server/web/my/keys.txt +27 -0
  115. package/runtime/server/web/my/orgs.html +1 -0
  116. package/runtime/server/web/my/orgs.txt +27 -0
  117. package/runtime/server/web/my/pages.html +1 -0
  118. package/runtime/server/web/my/pages.txt +27 -0
  119. package/runtime/server/web/my/peers.html +1 -0
  120. package/runtime/server/web/my/peers.txt +24 -0
  121. package/runtime/server/web/my/recent.html +1 -0
  122. package/runtime/server/web/my/recent.txt +27 -0
  123. package/runtime/server/web/my/settings.html +1 -0
  124. package/runtime/server/web/my/settings.txt +27 -0
  125. package/runtime/server/web/my/studio.html +1 -0
  126. package/runtime/server/web/my/studio.txt +24 -0
  127. package/runtime/server/web/my/subscriptions.html +1 -0
  128. package/runtime/server/web/my/subscriptions.txt +27 -0
  129. package/runtime/server/web/my/system.html +1 -0
  130. package/runtime/server/web/my/system.txt +24 -0
  131. package/runtime/server/web/my/tasks.html +1 -0
  132. package/runtime/server/web/my/tasks.txt +24 -0
  133. package/runtime/server/web/my/users.html +1 -0
  134. package/runtime/server/web/my/users.txt +27 -0
  135. package/runtime/server/web/my.html +1 -0
  136. package/runtime/server/web/my.txt +27 -0
  137. package/runtime/server/web/platform-shell/placeholder/placeholder.html +1 -0
  138. package/runtime/server/web/platform-shell/placeholder/placeholder.txt +23 -0
  139. package/runtime/server/web/platform-shell-preview.html +1 -0
  140. package/runtime/server/web/platform-shell-preview.txt +23 -0
  141. package/runtime/server/web/setup.html +1 -0
  142. package/runtime/server/web/setup.txt +23 -0
  143. package/template/.claude/skills/agent-tool-patterns/SKILL.md +195 -0
  144. package/template/.claude/skills/localapp/SKILL.md +80 -0
  145. package/template/.claude/skills/localapp-auth/SKILL.md +299 -0
  146. package/template/.claude/skills/localapp-business/SKILL.md +325 -0
  147. package/template/.claude/skills/localapp-data/SKILL.md +381 -0
  148. package/template/.claude/skills/localapp-device-actions/SKILL.md +60 -0
  149. package/template/.claude/skills/localapp-notify/SKILL.md +118 -0
  150. package/template/.claude/skills/localapp-transitions/SKILL.md +238 -0
  151. package/template/.claude/skills/localapp-ui/SKILL.md +67 -0
  152. package/template/.claude/skills/localapp-upload/SKILL.md +172 -0
  153. package/template/AGENTS.md +33 -0
  154. package/template/CLAUDE.md +117 -0
  155. package/template/ISSUES.md +32 -0
  156. package/template/backend/resources/work_items/mutations.json +83 -0
  157. package/template/backend/resources/work_items/queries.json +83 -0
  158. package/template/backend/resources/work_items/schema.json +31 -0
  159. package/template/backend/schemas/mutations.schema.json +15 -0
  160. package/template/backend/schemas/queries.schema.json +36 -0
  161. package/template/backend/schemas/resource-schema.schema.json +25 -0
  162. package/template/components.json +25 -0
  163. package/template/index.html +12 -0
  164. package/template/migrations/001_work_items.sql +6 -0
  165. package/template/package.json +70 -0
  166. package/template/postcss.config.js +5 -0
  167. package/template/runtime/dev-shell.tsx +6398 -0
  168. package/template/runtime/hooks/use-mobile.ts +19 -0
  169. package/template/runtime/issue-reference.ts +44 -0
  170. package/template/runtime/lib/utils.ts +6 -0
  171. package/template/runtime/package.json +14 -0
  172. package/template/runtime/platform-capabilities.json +109 -0
  173. package/template/runtime/sdk/agent/package.json +51 -0
  174. package/template/runtime/sdk/agent/src/agent-chat.tsx +188 -0
  175. package/template/runtime/sdk/agent/src/assistant-ui-adapter.ts +87 -0
  176. package/template/runtime/sdk/agent/src/context.ts +56 -0
  177. package/template/runtime/sdk/agent/src/dev-bridge.ts +21 -0
  178. package/template/runtime/sdk/agent/src/index.ts +19 -0
  179. package/template/runtime/sdk/agent/src/llm-adapter.ts +263 -0
  180. package/template/runtime/sdk/agent/src/native-registry.ts +61 -0
  181. package/template/runtime/sdk/agent/src/platform-runtime.ts +164 -0
  182. package/template/runtime/sdk/agent/src/postmessage-bridge.ts +60 -0
  183. package/template/runtime/sdk/agent/src/postmessage-types.ts +150 -0
  184. package/template/runtime/sdk/agent/src/tools.ts +70 -0
  185. package/template/runtime/sdk/agent/src/types.ts +27 -0
  186. package/template/runtime/sdk/agent/src/use-agent.ts +139 -0
  187. package/template/runtime/sdk/agent/src/use-register-edit-session.ts +54 -0
  188. package/template/runtime/sdk/agent/src/use-register-tools.ts +92 -0
  189. package/template/runtime/sdk/agent/tests/platform-runtime.test.ts +154 -0
  190. package/template/runtime/sdk/agent/tests/postmessage-bridge.test.ts +119 -0
  191. package/template/runtime/sdk/agent/tests/shell-integration.test.ts +71 -0
  192. package/template/runtime/sdk/agent/tests/use-register-edit-session.test.tsx +125 -0
  193. package/template/runtime/sdk/agent/tests/use-register-tools.test.ts +208 -0
  194. package/template/runtime/sdk/agent/tsconfig.json +18 -0
  195. package/template/runtime/sdk/agent/vitest.config.ts +8 -0
  196. package/template/runtime/sdk/backend/package.json +15 -0
  197. package/template/runtime/sdk/backend/src/index.ts +92 -0
  198. package/template/runtime/sdk/backend/tsconfig.json +8 -0
  199. package/template/runtime/sdk/core/package.json +15 -0
  200. package/template/runtime/sdk/core/src/client.ts +317 -0
  201. package/template/runtime/sdk/core/src/collaboration.ts +66 -0
  202. package/template/runtime/sdk/core/src/desktop.ts +469 -0
  203. package/template/runtime/sdk/core/src/device.ts +112 -0
  204. package/template/runtime/sdk/core/src/index.ts +6 -0
  205. package/template/runtime/sdk/core/src/invalidate.ts +40 -0
  206. package/template/runtime/sdk/core/src/types.ts +108 -0
  207. package/template/runtime/sdk/core/tests/capabilities.test.ts +64 -0
  208. package/template/runtime/sdk/core/tests/client.test.ts +424 -0
  209. package/template/runtime/sdk/core/tests/collaboration.test.ts +92 -0
  210. package/template/runtime/sdk/core/tests/desktop.test.ts +310 -0
  211. package/template/runtime/sdk/core/tests/device.test.ts +69 -0
  212. package/template/runtime/sdk/core/tsconfig.json +17 -0
  213. package/template/runtime/sdk/react/package.json +34 -0
  214. package/template/runtime/sdk/react/src/client.ts +7 -0
  215. package/template/runtime/sdk/react/src/components/can.tsx +24 -0
  216. package/template/runtime/sdk/react/src/hooks/use-action.ts +34 -0
  217. package/template/runtime/sdk/react/src/hooks/use-capabilities.ts +35 -0
  218. package/template/runtime/sdk/react/src/hooks/use-count.ts +37 -0
  219. package/template/runtime/sdk/react/src/hooks/use-create.ts +37 -0
  220. package/template/runtime/sdk/react/src/hooks/use-delete.ts +36 -0
  221. package/template/runtime/sdk/react/src/hooks/use-desktop-action.ts +94 -0
  222. package/template/runtime/sdk/react/src/hooks/use-device-action.ts +62 -0
  223. package/template/runtime/sdk/react/src/hooks/use-get.ts +37 -0
  224. package/template/runtime/sdk/react/src/hooks/use-group-members.ts +31 -0
  225. package/template/runtime/sdk/react/src/hooks/use-groups.ts +31 -0
  226. package/template/runtime/sdk/react/src/hooks/use-list.ts +53 -0
  227. package/template/runtime/sdk/react/src/hooks/use-me.ts +35 -0
  228. package/template/runtime/sdk/react/src/hooks/use-mutation.ts +30 -0
  229. package/template/runtime/sdk/react/src/hooks/use-permissions.ts +37 -0
  230. package/template/runtime/sdk/react/src/hooks/use-platform-data.ts +94 -0
  231. package/template/runtime/sdk/react/src/hooks/use-query.ts +30 -0
  232. package/template/runtime/sdk/react/src/hooks/use-time.ts +36 -0
  233. package/template/runtime/sdk/react/src/hooks/use-transaction.ts +30 -0
  234. package/template/runtime/sdk/react/src/hooks/use-transitions.ts +82 -0
  235. package/template/runtime/sdk/react/src/hooks/use-update.ts +37 -0
  236. package/template/runtime/sdk/react/src/hooks/use-upload.ts +30 -0
  237. package/template/runtime/sdk/react/src/hooks/use-users.ts +31 -0
  238. package/template/runtime/sdk/react/src/index.ts +40 -0
  239. package/template/runtime/sdk/react/src/permissions.ts +94 -0
  240. package/template/runtime/sdk/react/tests/permissions.test.ts +176 -0
  241. package/template/runtime/sdk/react/tests/use-action.test.tsx +64 -0
  242. package/template/runtime/sdk/react/tests/use-capabilities.test.tsx +48 -0
  243. package/template/runtime/sdk/react/tests/use-desktop-action.test.tsx +144 -0
  244. package/template/runtime/sdk/react/tests/use-permissions.test.tsx +162 -0
  245. package/template/runtime/sdk/react/tests/use-platform-data.test.tsx +89 -0
  246. package/template/runtime/sdk/react/tests/use-transaction.test.tsx +65 -0
  247. package/template/runtime/sdk/react/tests/use-transitions.test.ts +149 -0
  248. package/template/runtime/sdk/react/tsconfig.json +18 -0
  249. package/template/runtime/sdk/react/vitest.config.ts +9 -0
  250. package/template/runtime/sdk/react/vitest.setup.ts +6 -0
  251. package/template/runtime/server-core/dist/generated/platform-capabilities.d.ts +84 -0
  252. package/template/runtime/server-core/dist/generated/platform-capabilities.d.ts.map +1 -0
  253. package/template/runtime/server-core/dist/generated/platform-capabilities.js +115 -0
  254. package/template/runtime/server-core/dist/generated/platform-capabilities.js.map +1 -0
  255. package/template/runtime/server-core/dist/index.d.ts +19 -0
  256. package/template/runtime/server-core/dist/index.d.ts.map +1 -0
  257. package/template/runtime/server-core/dist/index.js +35 -0
  258. package/template/runtime/server-core/dist/index.js.map +1 -0
  259. package/template/runtime/server-core/dist/lib/__tests__/action-runtime-hardening.test.d.ts +2 -0
  260. package/template/runtime/server-core/dist/lib/__tests__/action-runtime-hardening.test.d.ts.map +1 -0
  261. package/template/runtime/server-core/dist/lib/__tests__/action-runtime-hardening.test.js +475 -0
  262. package/template/runtime/server-core/dist/lib/__tests__/action-runtime-hardening.test.js.map +1 -0
  263. package/template/runtime/server-core/dist/lib/__tests__/app-api-contract.test.d.ts +2 -0
  264. package/template/runtime/server-core/dist/lib/__tests__/app-api-contract.test.d.ts.map +1 -0
  265. package/template/runtime/server-core/dist/lib/__tests__/app-api-contract.test.js +65 -0
  266. package/template/runtime/server-core/dist/lib/__tests__/app-api-contract.test.js.map +1 -0
  267. package/template/runtime/server-core/dist/lib/__tests__/app-runtime.test.d.ts +2 -0
  268. package/template/runtime/server-core/dist/lib/__tests__/app-runtime.test.d.ts.map +1 -0
  269. package/template/runtime/server-core/dist/lib/__tests__/app-runtime.test.js +103 -0
  270. package/template/runtime/server-core/dist/lib/__tests__/app-runtime.test.js.map +1 -0
  271. package/template/runtime/server-core/dist/lib/__tests__/backend-actions.test.d.ts +2 -0
  272. package/template/runtime/server-core/dist/lib/__tests__/backend-actions.test.d.ts.map +1 -0
  273. package/template/runtime/server-core/dist/lib/__tests__/backend-actions.test.js +358 -0
  274. package/template/runtime/server-core/dist/lib/__tests__/backend-actions.test.js.map +1 -0
  275. package/template/runtime/server-core/dist/lib/__tests__/backend-contract.test.d.ts +2 -0
  276. package/template/runtime/server-core/dist/lib/__tests__/backend-contract.test.d.ts.map +1 -0
  277. package/template/runtime/server-core/dist/lib/__tests__/backend-contract.test.js +786 -0
  278. package/template/runtime/server-core/dist/lib/__tests__/backend-contract.test.js.map +1 -0
  279. package/template/runtime/server-core/dist/lib/__tests__/content-capabilities.test.d.ts +2 -0
  280. package/template/runtime/server-core/dist/lib/__tests__/content-capabilities.test.d.ts.map +1 -0
  281. package/template/runtime/server-core/dist/lib/__tests__/content-capabilities.test.js +82 -0
  282. package/template/runtime/server-core/dist/lib/__tests__/content-capabilities.test.js.map +1 -0
  283. package/template/runtime/server-core/dist/lib/__tests__/database-write-guard.test.d.ts +2 -0
  284. package/template/runtime/server-core/dist/lib/__tests__/database-write-guard.test.d.ts.map +1 -0
  285. package/template/runtime/server-core/dist/lib/__tests__/database-write-guard.test.js +42 -0
  286. package/template/runtime/server-core/dist/lib/__tests__/database-write-guard.test.js.map +1 -0
  287. package/template/runtime/server-core/dist/lib/__tests__/issue-collaboration.test.d.ts +2 -0
  288. package/template/runtime/server-core/dist/lib/__tests__/issue-collaboration.test.d.ts.map +1 -0
  289. package/template/runtime/server-core/dist/lib/__tests__/issue-collaboration.test.js +144 -0
  290. package/template/runtime/server-core/dist/lib/__tests__/issue-collaboration.test.js.map +1 -0
  291. package/template/runtime/server-core/dist/lib/__tests__/issue-comment-minimization.test.d.ts +2 -0
  292. package/template/runtime/server-core/dist/lib/__tests__/issue-comment-minimization.test.d.ts.map +1 -0
  293. package/template/runtime/server-core/dist/lib/__tests__/issue-comment-minimization.test.js +75 -0
  294. package/template/runtime/server-core/dist/lib/__tests__/issue-comment-minimization.test.js.map +1 -0
  295. package/template/runtime/server-core/dist/lib/__tests__/issue-comment-pins.test.d.ts +2 -0
  296. package/template/runtime/server-core/dist/lib/__tests__/issue-comment-pins.test.d.ts.map +1 -0
  297. package/template/runtime/server-core/dist/lib/__tests__/issue-comment-pins.test.js +85 -0
  298. package/template/runtime/server-core/dist/lib/__tests__/issue-comment-pins.test.js.map +1 -0
  299. package/template/runtime/server-core/dist/lib/__tests__/issue-cross-references.test.d.ts +2 -0
  300. package/template/runtime/server-core/dist/lib/__tests__/issue-cross-references.test.d.ts.map +1 -0
  301. package/template/runtime/server-core/dist/lib/__tests__/issue-cross-references.test.js +75 -0
  302. package/template/runtime/server-core/dist/lib/__tests__/issue-cross-references.test.js.map +1 -0
  303. package/template/runtime/server-core/dist/lib/__tests__/issue-dependencies.test.d.ts +2 -0
  304. package/template/runtime/server-core/dist/lib/__tests__/issue-dependencies.test.d.ts.map +1 -0
  305. package/template/runtime/server-core/dist/lib/__tests__/issue-dependencies.test.js +78 -0
  306. package/template/runtime/server-core/dist/lib/__tests__/issue-dependencies.test.js.map +1 -0
  307. package/template/runtime/server-core/dist/lib/__tests__/issue-duplicates.test.d.ts +2 -0
  308. package/template/runtime/server-core/dist/lib/__tests__/issue-duplicates.test.d.ts.map +1 -0
  309. package/template/runtime/server-core/dist/lib/__tests__/issue-duplicates.test.js +66 -0
  310. package/template/runtime/server-core/dist/lib/__tests__/issue-duplicates.test.js.map +1 -0
  311. package/template/runtime/server-core/dist/lib/__tests__/issue-list.test.d.ts +2 -0
  312. package/template/runtime/server-core/dist/lib/__tests__/issue-list.test.d.ts.map +1 -0
  313. package/template/runtime/server-core/dist/lib/__tests__/issue-list.test.js +322 -0
  314. package/template/runtime/server-core/dist/lib/__tests__/issue-list.test.js.map +1 -0
  315. package/template/runtime/server-core/dist/lib/__tests__/issue-potential-duplicates.test.d.ts +2 -0
  316. package/template/runtime/server-core/dist/lib/__tests__/issue-potential-duplicates.test.d.ts.map +1 -0
  317. package/template/runtime/server-core/dist/lib/__tests__/issue-potential-duplicates.test.js +49 -0
  318. package/template/runtime/server-core/dist/lib/__tests__/issue-potential-duplicates.test.js.map +1 -0
  319. package/template/runtime/server-core/dist/lib/__tests__/issue-reactions.test.d.ts +2 -0
  320. package/template/runtime/server-core/dist/lib/__tests__/issue-reactions.test.d.ts.map +1 -0
  321. package/template/runtime/server-core/dist/lib/__tests__/issue-reactions.test.js +67 -0
  322. package/template/runtime/server-core/dist/lib/__tests__/issue-reactions.test.js.map +1 -0
  323. package/template/runtime/server-core/dist/lib/__tests__/issue-revisions.test.d.ts +2 -0
  324. package/template/runtime/server-core/dist/lib/__tests__/issue-revisions.test.d.ts.map +1 -0
  325. package/template/runtime/server-core/dist/lib/__tests__/issue-revisions.test.js +91 -0
  326. package/template/runtime/server-core/dist/lib/__tests__/issue-revisions.test.js.map +1 -0
  327. package/template/runtime/server-core/dist/lib/__tests__/issue-saved-views.test.d.ts +2 -0
  328. package/template/runtime/server-core/dist/lib/__tests__/issue-saved-views.test.d.ts.map +1 -0
  329. package/template/runtime/server-core/dist/lib/__tests__/issue-saved-views.test.js +69 -0
  330. package/template/runtime/server-core/dist/lib/__tests__/issue-saved-views.test.js.map +1 -0
  331. package/template/runtime/server-core/dist/lib/__tests__/issue-sub-issues.test.d.ts +2 -0
  332. package/template/runtime/server-core/dist/lib/__tests__/issue-sub-issues.test.d.ts.map +1 -0
  333. package/template/runtime/server-core/dist/lib/__tests__/issue-sub-issues.test.js +159 -0
  334. package/template/runtime/server-core/dist/lib/__tests__/issue-sub-issues.test.js.map +1 -0
  335. package/template/runtime/server-core/dist/lib/__tests__/issue-task-conversion.test.d.ts +2 -0
  336. package/template/runtime/server-core/dist/lib/__tests__/issue-task-conversion.test.d.ts.map +1 -0
  337. package/template/runtime/server-core/dist/lib/__tests__/issue-task-conversion.test.js +102 -0
  338. package/template/runtime/server-core/dist/lib/__tests__/issue-task-conversion.test.js.map +1 -0
  339. package/template/runtime/server-core/dist/lib/__tests__/issue-templates.test.d.ts +2 -0
  340. package/template/runtime/server-core/dist/lib/__tests__/issue-templates.test.d.ts.map +1 -0
  341. package/template/runtime/server-core/dist/lib/__tests__/issue-templates.test.js +65 -0
  342. package/template/runtime/server-core/dist/lib/__tests__/issue-templates.test.js.map +1 -0
  343. package/template/runtime/server-core/dist/lib/__tests__/issue-timeline.test.d.ts +2 -0
  344. package/template/runtime/server-core/dist/lib/__tests__/issue-timeline.test.d.ts.map +1 -0
  345. package/template/runtime/server-core/dist/lib/__tests__/issue-timeline.test.js +226 -0
  346. package/template/runtime/server-core/dist/lib/__tests__/issue-timeline.test.js.map +1 -0
  347. package/template/runtime/server-core/dist/lib/__tests__/issue-types.test.d.ts +2 -0
  348. package/template/runtime/server-core/dist/lib/__tests__/issue-types.test.d.ts.map +1 -0
  349. package/template/runtime/server-core/dist/lib/__tests__/issue-types.test.js +64 -0
  350. package/template/runtime/server-core/dist/lib/__tests__/issue-types.test.js.map +1 -0
  351. package/template/runtime/server-core/dist/lib/__tests__/migrations.test.d.ts +2 -0
  352. package/template/runtime/server-core/dist/lib/__tests__/migrations.test.d.ts.map +1 -0
  353. package/template/runtime/server-core/dist/lib/__tests__/migrations.test.js +101 -0
  354. package/template/runtime/server-core/dist/lib/__tests__/migrations.test.js.map +1 -0
  355. package/template/runtime/server-core/dist/lib/__tests__/platform-capabilities.test.d.ts +2 -0
  356. package/template/runtime/server-core/dist/lib/__tests__/platform-capabilities.test.d.ts.map +1 -0
  357. package/template/runtime/server-core/dist/lib/__tests__/platform-capabilities.test.js +69 -0
  358. package/template/runtime/server-core/dist/lib/__tests__/platform-capabilities.test.js.map +1 -0
  359. package/template/runtime/server-core/dist/lib/__tests__/transitions.test.d.ts +2 -0
  360. package/template/runtime/server-core/dist/lib/__tests__/transitions.test.d.ts.map +1 -0
  361. package/template/runtime/server-core/dist/lib/__tests__/transitions.test.js +32 -0
  362. package/template/runtime/server-core/dist/lib/__tests__/transitions.test.js.map +1 -0
  363. package/template/runtime/server-core/dist/lib/access-control.d.ts +34 -0
  364. package/template/runtime/server-core/dist/lib/access-control.d.ts.map +1 -0
  365. package/template/runtime/server-core/dist/lib/access-control.js +138 -0
  366. package/template/runtime/server-core/dist/lib/access-control.js.map +1 -0
  367. package/template/runtime/server-core/dist/lib/app-api-contract.d.ts +69 -0
  368. package/template/runtime/server-core/dist/lib/app-api-contract.d.ts.map +1 -0
  369. package/template/runtime/server-core/dist/lib/app-api-contract.js +57 -0
  370. package/template/runtime/server-core/dist/lib/app-api-contract.js.map +1 -0
  371. package/template/runtime/server-core/dist/lib/app-db.d.ts +486 -0
  372. package/template/runtime/server-core/dist/lib/app-db.d.ts.map +1 -0
  373. package/template/runtime/server-core/dist/lib/app-db.js +2581 -0
  374. package/template/runtime/server-core/dist/lib/app-db.js.map +1 -0
  375. package/template/runtime/server-core/dist/lib/app-runtime.d.ts +28 -0
  376. package/template/runtime/server-core/dist/lib/app-runtime.d.ts.map +1 -0
  377. package/template/runtime/server-core/dist/lib/app-runtime.js +56 -0
  378. package/template/runtime/server-core/dist/lib/app-runtime.js.map +1 -0
  379. package/template/runtime/server-core/dist/lib/backend-actions.d.ts +149 -0
  380. package/template/runtime/server-core/dist/lib/backend-actions.d.ts.map +1 -0
  381. package/template/runtime/server-core/dist/lib/backend-actions.js +926 -0
  382. package/template/runtime/server-core/dist/lib/backend-actions.js.map +1 -0
  383. package/template/runtime/server-core/dist/lib/backend-contract.d.ts +399 -0
  384. package/template/runtime/server-core/dist/lib/backend-contract.d.ts.map +1 -0
  385. package/template/runtime/server-core/dist/lib/backend-contract.js +1148 -0
  386. package/template/runtime/server-core/dist/lib/backend-contract.js.map +1 -0
  387. package/template/runtime/server-core/dist/lib/content-capabilities.d.ts +30 -0
  388. package/template/runtime/server-core/dist/lib/content-capabilities.d.ts.map +1 -0
  389. package/template/runtime/server-core/dist/lib/content-capabilities.js +133 -0
  390. package/template/runtime/server-core/dist/lib/content-capabilities.js.map +1 -0
  391. package/template/runtime/server-core/dist/lib/issue-saved-replies.d.ts +7 -0
  392. package/template/runtime/server-core/dist/lib/issue-saved-replies.d.ts.map +1 -0
  393. package/template/runtime/server-core/dist/lib/issue-saved-replies.js +22 -0
  394. package/template/runtime/server-core/dist/lib/issue-saved-replies.js.map +1 -0
  395. package/template/runtime/server-core/dist/lib/issue-saved-views.d.ts +43 -0
  396. package/template/runtime/server-core/dist/lib/issue-saved-views.d.ts.map +1 -0
  397. package/template/runtime/server-core/dist/lib/issue-saved-views.js +201 -0
  398. package/template/runtime/server-core/dist/lib/issue-saved-views.js.map +1 -0
  399. package/template/runtime/server-core/dist/lib/issue-task-conversion.d.ts +11 -0
  400. package/template/runtime/server-core/dist/lib/issue-task-conversion.d.ts.map +1 -0
  401. package/template/runtime/server-core/dist/lib/issue-task-conversion.js +66 -0
  402. package/template/runtime/server-core/dist/lib/issue-task-conversion.js.map +1 -0
  403. package/template/runtime/server-core/dist/lib/issue-templates.d.ts +16 -0
  404. package/template/runtime/server-core/dist/lib/issue-templates.d.ts.map +1 -0
  405. package/template/runtime/server-core/dist/lib/issue-templates.js +89 -0
  406. package/template/runtime/server-core/dist/lib/issue-templates.js.map +1 -0
  407. package/template/runtime/server-core/dist/lib/migrations.d.ts +31 -0
  408. package/template/runtime/server-core/dist/lib/migrations.d.ts.map +1 -0
  409. package/template/runtime/server-core/dist/lib/migrations.js +180 -0
  410. package/template/runtime/server-core/dist/lib/migrations.js.map +1 -0
  411. package/template/runtime/server-core/dist/lib/notify-permission-sql.d.ts +21 -0
  412. package/template/runtime/server-core/dist/lib/notify-permission-sql.d.ts.map +1 -0
  413. package/template/runtime/server-core/dist/lib/notify-permission-sql.js +71 -0
  414. package/template/runtime/server-core/dist/lib/notify-permission-sql.js.map +1 -0
  415. package/template/runtime/server-core/dist/lib/record-access.d.ts +34 -0
  416. package/template/runtime/server-core/dist/lib/record-access.d.ts.map +1 -0
  417. package/template/runtime/server-core/dist/lib/record-access.js +81 -0
  418. package/template/runtime/server-core/dist/lib/record-access.js.map +1 -0
  419. package/template/runtime/server-core/dist/lib/runtime-errors.d.ts +28 -0
  420. package/template/runtime/server-core/dist/lib/runtime-errors.d.ts.map +1 -0
  421. package/template/runtime/server-core/dist/lib/runtime-errors.js +67 -0
  422. package/template/runtime/server-core/dist/lib/runtime-errors.js.map +1 -0
  423. package/template/runtime/server-core/dist/lib/transitions.d.ts +55 -0
  424. package/template/runtime/server-core/dist/lib/transitions.d.ts.map +1 -0
  425. package/template/runtime/server-core/dist/lib/transitions.js +142 -0
  426. package/template/runtime/server-core/dist/lib/transitions.js.map +1 -0
  427. package/template/runtime/server-core/dist/types/models.d.ts +163 -0
  428. package/template/runtime/server-core/dist/types/models.d.ts.map +1 -0
  429. package/template/runtime/server-core/dist/types/models.js +3 -0
  430. package/template/runtime/server-core/dist/types/models.js.map +1 -0
  431. package/template/runtime/server-core/package.json +24 -0
  432. package/template/runtime/styles/preset.css +282 -0
  433. package/template/runtime/sync-template-command.cjs +19 -0
  434. package/template/runtime/sync-template.cjs +71 -0
  435. package/template/runtime/tsconfig.base.json +20 -0
  436. package/template/runtime/version.json +3 -0
  437. package/template/runtime/vite-plugin.mjs +309 -0
  438. package/template/src/App.tsx +273 -0
  439. package/template/src/components/ui/accordion.tsx +79 -0
  440. package/template/src/components/ui/alert-dialog.tsx +197 -0
  441. package/template/src/components/ui/alert.tsx +76 -0
  442. package/template/src/components/ui/aspect-ratio.tsx +11 -0
  443. package/template/src/components/ui/avatar.tsx +110 -0
  444. package/template/src/components/ui/badge.tsx +49 -0
  445. package/template/src/components/ui/breadcrumb.tsx +122 -0
  446. package/template/src/components/ui/button-group.tsx +83 -0
  447. package/template/src/components/ui/button.tsx +67 -0
  448. package/template/src/components/ui/calendar.tsx +221 -0
  449. package/template/src/components/ui/card.tsx +103 -0
  450. package/template/src/components/ui/carousel.tsx +240 -0
  451. package/template/src/components/ui/chart.tsx +373 -0
  452. package/template/src/components/ui/checkbox.tsx +31 -0
  453. package/template/src/components/ui/collapsible.tsx +33 -0
  454. package/template/src/components/ui/combobox.tsx +299 -0
  455. package/template/src/components/ui/command.tsx +193 -0
  456. package/template/src/components/ui/context-menu.tsx +261 -0
  457. package/template/src/components/ui/dialog.tsx +168 -0
  458. package/template/src/components/ui/direction.tsx +22 -0
  459. package/template/src/components/ui/drawer.tsx +132 -0
  460. package/template/src/components/ui/dropdown-menu.tsx +269 -0
  461. package/template/src/components/ui/empty.tsx +104 -0
  462. package/template/src/components/ui/field.tsx +238 -0
  463. package/template/src/components/ui/hover-card.tsx +42 -0
  464. package/template/src/components/ui/input-group.tsx +154 -0
  465. package/template/src/components/ui/input-otp.tsx +87 -0
  466. package/template/src/components/ui/input.tsx +19 -0
  467. package/template/src/components/ui/item.tsx +196 -0
  468. package/template/src/components/ui/kbd.tsx +26 -0
  469. package/template/src/components/ui/label.tsx +22 -0
  470. package/template/src/components/ui/menubar.tsx +280 -0
  471. package/template/src/components/ui/native-select.tsx +61 -0
  472. package/template/src/components/ui/navigation-menu.tsx +164 -0
  473. package/template/src/components/ui/pagination.tsx +129 -0
  474. package/template/src/components/ui/popover.tsx +87 -0
  475. package/template/src/components/ui/progress.tsx +31 -0
  476. package/template/src/components/ui/radio-group.tsx +42 -0
  477. package/template/src/components/ui/resizable.tsx +50 -0
  478. package/template/src/components/ui/scroll-area.tsx +53 -0
  479. package/template/src/components/ui/select.tsx +192 -0
  480. package/template/src/components/ui/separator.tsx +26 -0
  481. package/template/src/components/ui/sheet.tsx +145 -0
  482. package/template/src/components/ui/sidebar.tsx +700 -0
  483. package/template/src/components/ui/skeleton.tsx +13 -0
  484. package/template/src/components/ui/slider.tsx +59 -0
  485. package/template/src/components/ui/sonner.tsx +47 -0
  486. package/template/src/components/ui/spinner.tsx +10 -0
  487. package/template/src/components/ui/switch.tsx +33 -0
  488. package/template/src/components/ui/table.tsx +114 -0
  489. package/template/src/components/ui/tabs.tsx +90 -0
  490. package/template/src/components/ui/textarea.tsx +18 -0
  491. package/template/src/components/ui/toggle-group.tsx +89 -0
  492. package/template/src/components/ui/toggle.tsx +45 -0
  493. package/template/src/components/ui/tooltip.tsx +57 -0
  494. package/template/src/hooks/use-mobile.ts +3 -0
  495. package/template/src/index.css +4 -0
  496. package/template/src/lib/utils.ts +3 -0
  497. package/template/src/main.tsx +10 -0
  498. package/template/src/vite-env.d.ts +1 -0
  499. package/template/template.gitignore +10 -0
  500. package/template/template.npmrc +1 -0
  501. package/template/tests/agent-context.test.ts +69 -0
  502. package/template/tests/agent-guidance-template.test.ts +49 -0
  503. package/template/tests/agent-runtime.test.ts +198 -0
  504. package/template/tests/agent-tools.test.ts +150 -0
  505. package/template/tests/agent-use-agent.test.ts +86 -0
  506. package/template/tests/assistant-ui-adapter.test.ts +211 -0
  507. package/template/tests/business-modeling-template.test.ts +71 -0
  508. package/template/tests/client.test.ts +382 -0
  509. package/template/tests/dev-issue-search-suggestions.test.ts +36 -0
  510. package/template/tests/dev-shell-context.test.tsx +40 -0
  511. package/template/tests/dev-shell-template.test.ts +2593 -0
  512. package/template/tests/invalidation.test.ts +126 -0
  513. package/template/tests/main-tsx.test.ts +28 -0
  514. package/template/tests/media-preview-template.test.ts +21 -0
  515. package/template/tests/mutations.test.ts +224 -0
  516. package/template/tests/react.test.ts +302 -0
  517. package/template/tests/redirect.test.ts +51 -0
  518. package/template/tests/skill-docs.test.ts +76 -0
  519. package/template/tests/state-transitions-template.test.ts +61 -0
  520. package/template/tests/template-ui.test.ts +145 -0
  521. package/template/tests/upload.test.ts +143 -0
  522. package/template/tests/vite-plugin.test.ts +426 -0
  523. package/template/tests/vite-proxy-security.test.ts +153 -0
  524. package/template/tsconfig.json +11 -0
  525. package/template/vite.config.ts +7 -0
  526. package/template/vitest.config.ts +16 -0
  527. package/template/vitest.setup.ts +1 -0
@@ -0,0 +1,940 @@
1
+ #!/usr/bin/env node
2
+
3
+ // packages/localapp/src/errors.ts
4
+ var LocalAppLifecycleError = class extends Error {
5
+ constructor(code, message) {
6
+ super(message);
7
+ this.code = code;
8
+ this.name = "LocalAppLifecycleError";
9
+ }
10
+ code;
11
+ };
12
+ function lifecycleError(code, message) {
13
+ return new LocalAppLifecycleError(code, message);
14
+ }
15
+
16
+ // packages/server/src/lib/device-action-types.ts
17
+ var DEVICE_ACTION_PROTOCOL_VERSION = 2;
18
+ var DEVICE_ACTION_SCRIPT_MAX_BYTES = 256 * 1024;
19
+ var DEVICE_ACTION_INPUT_MAX_BYTES = 1024 * 1024;
20
+ var DEVICE_ACTION_RESULT_MAX_BYTES = 1024 * 1024;
21
+ var DEVICE_ACTION_ERROR_MAX_BYTES = 64 * 1024;
22
+ var DeviceActionPolicyError = class extends Error {
23
+ constructor(code, message = code) {
24
+ super(message);
25
+ this.code = code;
26
+ this.name = "DeviceActionPolicyError";
27
+ }
28
+ code;
29
+ };
30
+ var ACTION_ID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
31
+ var NONCE_PATTERN = /^[A-Za-z0-9_-]{16,128}$/;
32
+ function isDeviceActionId(value) {
33
+ return ACTION_ID_PATTERN.test(value);
34
+ }
35
+ function isDeviceActionNonce(value) {
36
+ return NONCE_PATTERN.test(value);
37
+ }
38
+ function normalizeDeviceActionOrigin(value) {
39
+ if (typeof value !== "string" || value.length > 2048) {
40
+ throw new DeviceActionPolicyError("DEVICE_ACTION_INVALID_ORIGIN");
41
+ }
42
+ let parsed;
43
+ try {
44
+ parsed = new URL(value);
45
+ } catch {
46
+ throw new DeviceActionPolicyError("DEVICE_ACTION_INVALID_ORIGIN");
47
+ }
48
+ if (!["http:", "https:"].includes(parsed.protocol) || parsed.username || parsed.password || parsed.pathname !== "/" || parsed.search || parsed.hash) {
49
+ throw new DeviceActionPolicyError("DEVICE_ACTION_INVALID_ORIGIN");
50
+ }
51
+ return parsed.origin;
52
+ }
53
+
54
+ // packages/server/src/lib/device-action-ticket.ts
55
+ var TICKET_KEYS = ["protocolVersion", "sourceOrigin", "actionId", "nonce"];
56
+ function invalid() {
57
+ throw new DeviceActionPolicyError("DEVICE_ACTION_INVALID_TICKET");
58
+ }
59
+ function parseDeviceActivationTicket(value) {
60
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return invalid();
61
+ const input = value;
62
+ if (Object.keys(input).some((key) => !TICKET_KEYS.includes(key))) return invalid();
63
+ if (input.protocolVersion !== DEVICE_ACTION_PROTOCOL_VERSION || typeof input.sourceOrigin !== "string" || typeof input.actionId !== "string" || typeof input.nonce !== "string") return invalid();
64
+ let sourceOrigin;
65
+ try {
66
+ sourceOrigin = normalizeDeviceActionOrigin(input.sourceOrigin);
67
+ } catch {
68
+ return invalid();
69
+ }
70
+ if (!isDeviceActionId(input.actionId) || input.actionId !== input.actionId.toLowerCase() || !isDeviceActionNonce(input.nonce)) return invalid();
71
+ return {
72
+ protocolVersion: DEVICE_ACTION_PROTOCOL_VERSION,
73
+ sourceOrigin,
74
+ actionId: input.actionId,
75
+ nonce: input.nonce
76
+ };
77
+ }
78
+ function createDeviceActivationUrl(ticket) {
79
+ const canonical = parseDeviceActivationTicket(ticket);
80
+ return `localapp://action/${canonical.actionId}?origin=${encodeURIComponent(canonical.sourceOrigin)}&nonce=${encodeURIComponent(canonical.nonce)}&protocolVersion=${canonical.protocolVersion}`;
81
+ }
82
+ function parseDeviceActivationUrl(value) {
83
+ if (typeof value !== "string" || Buffer.byteLength(value, "utf8") > 4096) return invalid();
84
+ let url;
85
+ try {
86
+ url = new URL(value);
87
+ } catch {
88
+ return invalid();
89
+ }
90
+ if (url.protocol !== "localapp:" || url.hostname !== "action" || url.username || url.password || url.hash || !isDeviceActionId(url.pathname.slice(1)) || url.pathname !== `/${url.pathname.slice(1).toLowerCase()}`) return invalid();
91
+ const entries = [...url.searchParams.entries()];
92
+ if (entries.length !== 3 || new Set(entries.map(([key]) => key)).size !== 3 || !entries.every(([key]) => ["origin", "nonce", "protocolVersion"].includes(key))) return invalid();
93
+ const protocolVersion = url.searchParams.get("protocolVersion");
94
+ const origin = url.searchParams.get("origin");
95
+ const nonce = url.searchParams.get("nonce");
96
+ if (protocolVersion !== String(DEVICE_ACTION_PROTOCOL_VERSION) || origin === null || nonce === null) return invalid();
97
+ const ticket = parseDeviceActivationTicket({
98
+ protocolVersion: DEVICE_ACTION_PROTOCOL_VERSION,
99
+ sourceOrigin: origin,
100
+ actionId: url.pathname.slice(1),
101
+ nonce
102
+ });
103
+ if (value !== createDeviceActivationUrl(ticket)) return invalid();
104
+ return ticket;
105
+ }
106
+
107
+ // packages/localapp/src/activation/activation-url.ts
108
+ var ACTIVATION_URL_LIMIT_BYTES = 4096;
109
+ var NOTIFICATION_TICKET = /^[A-Za-z0-9_-]{16,256}$/;
110
+ function parseActivationUrl(value) {
111
+ if (typeof value !== "string" || Buffer.byteLength(value, "utf8") > ACTIVATION_URL_LIMIT_BYTES) return invalid2();
112
+ if (value.startsWith("localapp://action/")) {
113
+ try {
114
+ return { kind: "device-action", ticket: parseDeviceActivationUrl(value) };
115
+ } catch {
116
+ return invalid2();
117
+ }
118
+ }
119
+ if (!value.startsWith("localapp://notification/open?")) return invalid2();
120
+ let parsed;
121
+ try {
122
+ parsed = new URL(value);
123
+ } catch {
124
+ return invalid2();
125
+ }
126
+ if (parsed.protocol !== "localapp:" || parsed.hostname !== "notification" || parsed.port !== "" || parsed.username || parsed.password || parsed.hash || parsed.pathname !== "/open") return invalid2();
127
+ const entries = [...parsed.searchParams.entries()];
128
+ if (entries.length !== 1 || entries[0]?.[0] !== "ticket" || !NOTIFICATION_TICKET.test(entries[0]?.[1] ?? "")) return invalid2();
129
+ const ticket = entries[0][1];
130
+ if (value !== `localapp://notification/open?ticket=${ticket}`) return invalid2();
131
+ return { kind: "notification", ticket };
132
+ }
133
+ function invalid2() {
134
+ throw lifecycleError("activation_url_invalid", "ACTIVATION_URL_INVALID");
135
+ }
136
+
137
+ // packages/localapp/src/activation/activation-broker.ts
138
+ async function forwardActivationToDaemon(options) {
139
+ parseActivationUrl(options.url);
140
+ const deadline = Date.now() + (options.deadlineMs ?? 1e4);
141
+ let started = false;
142
+ let lastError;
143
+ while (Date.now() <= deadline) {
144
+ try {
145
+ const response = await beforeDeadline(() => options.ipcClient.request({ type: "activation", url: options.url }), deadline);
146
+ if (response.ok && response.type === "activation") return;
147
+ throw lifecycleError("activation_ipc_rejected", "The LocalApp daemon rejected the Scheme activation");
148
+ } catch (error) {
149
+ if (!isUnreachable(error)) throw error;
150
+ lastError = error;
151
+ if (!started) {
152
+ started = true;
153
+ try {
154
+ await beforeDeadline((signal) => options.service.start(signal), deadline, { awaitWorkAfterAbort: true });
155
+ } catch (startError) {
156
+ if (!isDeadlineElapsed(startError)) throw startError;
157
+ break;
158
+ }
159
+ }
160
+ if (Date.now() >= deadline) break;
161
+ try {
162
+ await beforeDeadline(
163
+ (signal) => (options.delay ?? delay)(Math.min(100, Math.max(1, deadline - Date.now())), signal),
164
+ deadline
165
+ );
166
+ } catch (delayError) {
167
+ if (!isDeadlineElapsed(delayError)) throw delayError;
168
+ break;
169
+ }
170
+ }
171
+ }
172
+ throw lastError instanceof Error ? lastError : lifecycleError("activation_ipc_unreachable", "The LocalApp daemon activation endpoint is unavailable");
173
+ }
174
+ function isUnreachable(error) {
175
+ return typeof error === "object" && error !== null && "code" in error && error.code === "ipc_unreachable";
176
+ }
177
+ function isDeadlineElapsed(error) {
178
+ return typeof error === "object" && error !== null && "code" in error && error.code === "activation_deadline_elapsed";
179
+ }
180
+ async function beforeDeadline(operation, deadline, options = {}) {
181
+ const remaining = deadline - Date.now();
182
+ if (remaining <= 0) throw lifecycleError("activation_deadline_elapsed", "The LocalApp activation deadline elapsed");
183
+ const controller = new AbortController();
184
+ let timer;
185
+ let timedOut = false;
186
+ let work;
187
+ try {
188
+ work = Promise.resolve().then(() => operation(controller.signal));
189
+ return await Promise.race([
190
+ work,
191
+ new Promise((_resolve, reject) => {
192
+ timer = setTimeout(() => {
193
+ timedOut = true;
194
+ controller.abort();
195
+ reject(lifecycleError("activation_deadline_elapsed", "The LocalApp activation deadline elapsed"));
196
+ }, remaining);
197
+ timer.unref?.();
198
+ })
199
+ ]);
200
+ } catch (error) {
201
+ if (timedOut && options.awaitWorkAfterAbort && work !== void 0) await settleAbortedService(work);
202
+ throw error;
203
+ } finally {
204
+ if (timer !== void 0) clearTimeout(timer);
205
+ if (timedOut && !controller.signal.aborted) controller.abort();
206
+ }
207
+ }
208
+ async function settleAbortedService(work) {
209
+ await work.then(() => void 0, () => void 0);
210
+ }
211
+ function delay(milliseconds, signal) {
212
+ return new Promise((resolve, reject) => {
213
+ if (signal?.aborted) {
214
+ reject(signal.reason);
215
+ return;
216
+ }
217
+ const timer = setTimeout(cleanupAndResolve, milliseconds);
218
+ const abort = () => {
219
+ clearTimeout(timer);
220
+ cleanup();
221
+ reject(signal?.reason);
222
+ };
223
+ const cleanup = () => signal?.removeEventListener("abort", abort);
224
+ function cleanupAndResolve() {
225
+ cleanup();
226
+ resolve();
227
+ }
228
+ signal?.addEventListener("abort", abort, { once: true });
229
+ });
230
+ }
231
+
232
+ // packages/localapp/src/daemon/ipc-client.ts
233
+ import net from "node:net";
234
+
235
+ // packages/localapp/src/daemon/control-protocol.ts
236
+ import { TextDecoder } from "node:util";
237
+ var CONTROL_FRAME_LIMIT_BYTES = 64 * 1024;
238
+ var decoder = new TextDecoder("utf-8", { fatal: true });
239
+ var REQUEST_TYPES = /* @__PURE__ */ new Set(["status", "stop", "restart", "activation"]);
240
+ var RESPONSE_ERROR_CODE = /^[A-Z][A-Z0-9_]{1,63}$/;
241
+ var BOOT_ID = /^[A-Za-z0-9_-]{16,128}$/;
242
+ function encodeControlRequest(request) {
243
+ return encodeFrame(validateControlRequest(request));
244
+ }
245
+ function parseControlResponseFrame(frame) {
246
+ const value = parseFrame(frame);
247
+ return validateControlResponse(value);
248
+ }
249
+ function parseFrame(frame) {
250
+ if (frame.byteLength > CONTROL_FRAME_LIMIT_BYTES) throw protocolError("IPC_MESSAGE_TOO_LARGE");
251
+ let text;
252
+ try {
253
+ text = decoder.decode(frame);
254
+ } catch {
255
+ throw protocolError("IPC_INVALID_UTF8");
256
+ }
257
+ const newline = text.indexOf("\n");
258
+ if (newline < 0) throw protocolError("IPC_FRAME_INCOMPLETE");
259
+ const trailing = text.slice(newline + 1);
260
+ if (trailing.length > 0) {
261
+ throw protocolError(trailing.includes("\n") ? "IPC_MULTIPLE_FRAMES" : "IPC_TRAILING_DATA");
262
+ }
263
+ const json = text.slice(0, newline);
264
+ let parsed;
265
+ try {
266
+ parsed = JSON.parse(json);
267
+ } catch {
268
+ throw protocolError("IPC_JSON_INVALID");
269
+ }
270
+ assertNoDuplicateJsonKeys(json);
271
+ return parsed;
272
+ }
273
+ function encodeFrame(value) {
274
+ const frame = Buffer.from(`${JSON.stringify(value)}
275
+ `, "utf8");
276
+ if (frame.byteLength > CONTROL_FRAME_LIMIT_BYTES) throw protocolError("IPC_MESSAGE_TOO_LARGE");
277
+ return frame;
278
+ }
279
+ function validateControlRequest(value) {
280
+ if (!isRecord(value) || typeof value.type !== "string") throw protocolError("IPC_REQUEST_INVALID");
281
+ if (!REQUEST_TYPES.has(value.type)) throw protocolError("IPC_REQUEST_UNSUPPORTED");
282
+ if (value.type === "activation") {
283
+ if (!hasExactKeys(value, ["type", "url"]) || typeof value.url !== "string" || Buffer.byteLength(value.url, "utf8") > 4096) {
284
+ throw protocolError("IPC_REQUEST_INVALID");
285
+ }
286
+ return { type: "activation", url: value.url };
287
+ }
288
+ if (!hasExactKeys(value, ["type"])) throw protocolError("IPC_REQUEST_INVALID");
289
+ return { type: value.type };
290
+ }
291
+ function validateControlResponse(value) {
292
+ if (!isRecord(value) || typeof value.ok !== "boolean") throw protocolError("IPC_RESPONSE_INVALID");
293
+ if (!value.ok) {
294
+ if (!hasExactKeys(value, ["ok", "code", "message"]) || typeof value.code !== "string" || !RESPONSE_ERROR_CODE.test(value.code) || typeof value.message !== "string" || value.message.length < 1 || value.message.length > 512 || /[\r\n]/.test(value.message)) throw protocolError("IPC_RESPONSE_INVALID");
295
+ return { ok: false, code: value.code, message: value.message };
296
+ }
297
+ if (value.type === "stop" || value.type === "restart" || value.type === "activation") {
298
+ if (!hasExactKeys(value, ["ok", "type"])) throw protocolError("IPC_RESPONSE_INVALID");
299
+ return { ok: true, type: value.type };
300
+ }
301
+ if (value.type !== "status" || !hasExactKeys(value, ["ok", "type", "data"]) || !isRecord(value.data)) {
302
+ throw protocolError("IPC_RESPONSE_INVALID");
303
+ }
304
+ const data = value.data;
305
+ if (!hasExactKeys(data, ["bootId", "pid", "server"]) || typeof data.bootId !== "string" || !BOOT_ID.test(data.bootId) || typeof data.pid !== "number" || !Number.isSafeInteger(data.pid) || data.pid <= 0 || !isRecord(data.server)) throw protocolError("IPC_RESPONSE_INVALID");
306
+ const server = validateServerStatus(data.server);
307
+ return { ok: true, type: "status", data: { bootId: data.bootId, pid: data.pid, server } };
308
+ }
309
+ function validateServerStatus(value) {
310
+ const statuses = /* @__PURE__ */ new Set(["starting", "ready", "stopping", "stopped", "error"]);
311
+ if (typeof value.status !== "string" || !statuses.has(value.status)) {
312
+ throw protocolError("IPC_RESPONSE_INVALID");
313
+ }
314
+ const expectedKeys = value.listenUrl === void 0 ? ["status"] : value.setupUrl === void 0 ? ["status", "listenUrl"] : ["status", "listenUrl", "setupUrl"];
315
+ if (!hasExactKeys(value, expectedKeys)) throw protocolError("IPC_RESPONSE_INVALID");
316
+ if (value.listenUrl !== void 0) {
317
+ if (value.status !== "ready" || typeof value.listenUrl !== "string" || !isLoopbackHttpOrigin(value.listenUrl)) {
318
+ throw protocolError("IPC_RESPONSE_INVALID");
319
+ }
320
+ if (value.setupUrl !== void 0 && (typeof value.setupUrl !== "string" || !isSetupUrl(value.setupUrl, value.listenUrl))) {
321
+ throw protocolError("IPC_RESPONSE_INVALID");
322
+ }
323
+ return {
324
+ status: value.status,
325
+ listenUrl: value.listenUrl,
326
+ ...typeof value.setupUrl === "string" ? { setupUrl: value.setupUrl } : {}
327
+ };
328
+ }
329
+ if (value.status === "ready") throw protocolError("IPC_RESPONSE_INVALID");
330
+ return { status: value.status };
331
+ }
332
+ function isSetupUrl(value, listenUrl) {
333
+ try {
334
+ const url = new URL(value);
335
+ const token = url.searchParams.get("token");
336
+ return url.origin === listenUrl && url.pathname === "/setup" && url.hash === "" && [...url.searchParams.keys()].length === 1 && typeof token === "string" && token.length >= 16 && token.length <= 512;
337
+ } catch {
338
+ return false;
339
+ }
340
+ }
341
+ function isLoopbackHttpOrigin(value) {
342
+ try {
343
+ const url = new URL(value);
344
+ return url.protocol === "http:" && (url.hostname === "127.0.0.1" || url.hostname === "[::1]") && url.username === "" && url.password === "" && url.pathname === "/" && url.search === "" && url.hash === "" && url.port !== "";
345
+ } catch {
346
+ return false;
347
+ }
348
+ }
349
+ function protocolError(code) {
350
+ return lifecycleError(code, code);
351
+ }
352
+ function assertNoDuplicateJsonKeys(json) {
353
+ let index = 0;
354
+ const whitespace = () => {
355
+ while (index < json.length && /[\t\n\r ]/.test(json[index])) index += 1;
356
+ };
357
+ const stringValue = () => {
358
+ const start = index;
359
+ index += 1;
360
+ while (index < json.length) {
361
+ if (json[index] === "\\") {
362
+ index += 2;
363
+ continue;
364
+ }
365
+ if (json[index] === '"') {
366
+ index += 1;
367
+ return JSON.parse(json.slice(start, index));
368
+ }
369
+ index += 1;
370
+ }
371
+ throw protocolError("IPC_JSON_INVALID");
372
+ };
373
+ const value = () => {
374
+ whitespace();
375
+ const first = json[index];
376
+ if (first === "{") {
377
+ index += 1;
378
+ whitespace();
379
+ const keys = /* @__PURE__ */ new Set();
380
+ if (json[index] === "}") {
381
+ index += 1;
382
+ return;
383
+ }
384
+ while (index < json.length) {
385
+ whitespace();
386
+ if (json[index] !== '"') throw protocolError("IPC_JSON_INVALID");
387
+ const key = stringValue();
388
+ if (keys.has(key)) throw protocolError("IPC_JSON_DUPLICATE_KEY");
389
+ keys.add(key);
390
+ whitespace();
391
+ if (json[index] !== ":") throw protocolError("IPC_JSON_INVALID");
392
+ index += 1;
393
+ value();
394
+ whitespace();
395
+ if (json[index] === "}") {
396
+ index += 1;
397
+ return;
398
+ }
399
+ if (json[index] !== ",") throw protocolError("IPC_JSON_INVALID");
400
+ index += 1;
401
+ }
402
+ throw protocolError("IPC_JSON_INVALID");
403
+ }
404
+ if (first === "[") {
405
+ index += 1;
406
+ whitespace();
407
+ if (json[index] === "]") {
408
+ index += 1;
409
+ return;
410
+ }
411
+ while (index < json.length) {
412
+ value();
413
+ whitespace();
414
+ if (json[index] === "]") {
415
+ index += 1;
416
+ return;
417
+ }
418
+ if (json[index] !== ",") throw protocolError("IPC_JSON_INVALID");
419
+ index += 1;
420
+ }
421
+ throw protocolError("IPC_JSON_INVALID");
422
+ }
423
+ if (first === '"') {
424
+ stringValue();
425
+ return;
426
+ }
427
+ while (index < json.length && !/[\t\n\r ,\]}]/.test(json[index])) index += 1;
428
+ };
429
+ value();
430
+ whitespace();
431
+ if (index !== json.length) throw protocolError("IPC_JSON_INVALID");
432
+ }
433
+ function hasExactKeys(value, expected) {
434
+ const keys = Object.keys(value).sort();
435
+ const sorted = [...expected].sort();
436
+ return keys.length === sorted.length && keys.every((key, index) => key === sorted[index]);
437
+ }
438
+ function isRecord(value) {
439
+ return value !== null && typeof value === "object" && !Array.isArray(value);
440
+ }
441
+
442
+ // packages/localapp/src/daemon/ipc-client.ts
443
+ var DEFAULT_TIMEOUT_MS = 5e3;
444
+ function createIpcClient(options) {
445
+ return { request: (request) => requestIpc(options.endpoint, request, options.timeoutMs ?? DEFAULT_TIMEOUT_MS, options.createConnection ?? net.createConnection) };
446
+ }
447
+ function requestIpc(endpoint, request, timeoutMs, connect) {
448
+ return new Promise((resolve, reject) => {
449
+ const socket = connect(endpoint);
450
+ let bytes = Buffer.alloc(0);
451
+ let settled = false;
452
+ const finish = (error, response) => {
453
+ if (settled) return;
454
+ settled = true;
455
+ clearTimeout(timer);
456
+ socket.destroy();
457
+ error === void 0 ? resolve(response) : reject(error);
458
+ };
459
+ const timer = setTimeout(() => finish(lifecycleError("ipc_timeout", "The LocalApp daemon control request timed out")), timeoutMs);
460
+ timer.unref?.();
461
+ socket.once("error", (error) => finish(transportError(error)));
462
+ socket.once("connect", () => socket.end(encodeControlRequest(request)));
463
+ socket.on("data", (chunk) => {
464
+ if (settled) return;
465
+ if (bytes.byteLength + chunk.byteLength > CONTROL_FRAME_LIMIT_BYTES) return finish(lifecycleError("ipc_response_invalid", "The LocalApp daemon response is too large"));
466
+ bytes = Buffer.concat([bytes, chunk]);
467
+ if (bytes.indexOf(10) < 0) return;
468
+ if (bytes.indexOf(10) !== bytes.byteLength - 1) return finish(lifecycleError("ipc_response_invalid", "The LocalApp daemon response has trailing data"));
469
+ });
470
+ socket.once("end", () => {
471
+ if (settled) return;
472
+ try {
473
+ finish(void 0, parseControlResponseFrame(bytes));
474
+ } catch {
475
+ finish(lifecycleError("ipc_response_invalid", "The LocalApp daemon response is invalid"));
476
+ }
477
+ });
478
+ });
479
+ }
480
+ function transportError(error) {
481
+ if (error.code === "ENOENT" || error.code === "ECONNREFUSED") return lifecycleError("ipc_unreachable", "The LocalApp daemon control endpoint is unavailable");
482
+ return lifecycleError("ipc_transport_failed", "The LocalApp daemon control transport failed");
483
+ }
484
+
485
+ // packages/localapp/src/daemon/runtime-layout.ts
486
+ import crypto from "node:crypto";
487
+ import { homedir } from "node:os";
488
+ import path from "node:path";
489
+ function createRuntimeLayout(options = {}) {
490
+ const platform = options.platform ?? process.platform;
491
+ const env = options.env ?? process.env;
492
+ const homeDirectory = options.homeDir ?? homedir();
493
+ const pathApi = platform === "win32" ? path.win32 : path.posix;
494
+ const supportDir = options.supportDir ?? defaultSupportDirectory(platform, env, homeDirectory, pathApi);
495
+ const runtimeDir = options.runtimeDir ?? defaultRuntimeDirectory(platform, env, homeDirectory, supportDir, options.uid, pathApi);
496
+ const dataDir = options.dataDir ?? pathApi.join(supportDir, "data");
497
+ const releasesDir = pathApi.join(supportDir, "releases");
498
+ const controlEndpoint = platform === "win32" ? `\\\\.\\pipe\\localapp-${crypto.createHash("sha256").update(supportDir.toLowerCase()).digest("hex").slice(0, 24)}` : pathApi.join(runtimeDir, "control.sock");
499
+ return {
500
+ platform,
501
+ supportDir,
502
+ dataDir,
503
+ releasesDir,
504
+ currentManifestPath: pathApi.join(supportDir, "current.json"),
505
+ launcherPath: pathApi.join(supportDir, "bin", "localapp-daemon-bootstrap.mjs"),
506
+ logsDir: pathApi.join(supportDir, "logs"),
507
+ daemonLogPath: pathApi.join(supportDir, "logs", "daemon.log"),
508
+ runtimeDir,
509
+ lockPath: pathApi.join(runtimeDir, "daemon.lock"),
510
+ releaseLockPath: pathApi.join(runtimeDir, "release.lock"),
511
+ controlEndpoint
512
+ };
513
+ }
514
+ function defaultSupportDirectory(platform, env, homeDirectory, pathApi) {
515
+ if (platform === "darwin") return pathApi.join(homeDirectory, "Library", "Application Support", "LocalApp");
516
+ if (platform === "win32") {
517
+ return pathApi.join(env.LOCALAPPDATA ?? pathApi.join(homeDirectory, "AppData", "Local"), "LocalApp");
518
+ }
519
+ return pathApi.join(env.XDG_DATA_HOME ?? pathApi.join(homeDirectory, ".local", "share"), "localapp");
520
+ }
521
+ function defaultRuntimeDirectory(platform, env, homeDirectory, supportDirectory, uid, pathApi) {
522
+ if (platform === "win32") return pathApi.join(supportDirectory, "run");
523
+ if (platform === "linux") {
524
+ return env.XDG_RUNTIME_DIR ? pathApi.join(env.XDG_RUNTIME_DIR, "localapp") : pathApi.join(homeDirectory, ".cache", "localapp", "run");
525
+ }
526
+ if (env.TMPDIR) return pathApi.join(env.TMPDIR, `localapp-${uid ?? "user"}`);
527
+ return pathApi.join(homeDirectory, "Library", "Caches", "LocalApp", "run");
528
+ }
529
+
530
+ // packages/localapp/src/service/service-manager.ts
531
+ import fs5 from "node:fs/promises";
532
+ import { spawn } from "node:child_process";
533
+
534
+ // packages/localapp/src/service/linux-systemd-user.ts
535
+ import fs2 from "node:fs/promises";
536
+ import path3 from "node:path";
537
+
538
+ // packages/localapp/src/service/service-files.ts
539
+ import crypto2 from "node:crypto";
540
+ import fs from "node:fs/promises";
541
+ import path2 from "node:path";
542
+ async function writeServiceFile(filePath, value) {
543
+ const existing = await fs.readFile(filePath, "utf8").catch((error) => {
544
+ if (error.code === "ENOENT") return void 0;
545
+ throw error;
546
+ });
547
+ if (existing === value) return false;
548
+ await fs.mkdir(path2.dirname(filePath), { recursive: true, mode: 448 });
549
+ const temporary = path2.join(path2.dirname(filePath), `.${path2.basename(filePath)}.${process.pid}.${crypto2.randomUUID()}.next`);
550
+ let handle;
551
+ try {
552
+ handle = await fs.open(temporary, "wx", 384);
553
+ await handle.writeFile(value, "utf8");
554
+ await handle.sync();
555
+ await handle.close();
556
+ handle = void 0;
557
+ await fs.rename(temporary, filePath);
558
+ if (process.platform !== "win32") await fs.chmod(filePath, 384);
559
+ return true;
560
+ } finally {
561
+ await handle?.close();
562
+ await fs.rm(temporary, { force: true });
563
+ }
564
+ }
565
+ function xmlEscape(value) {
566
+ return value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&apos;");
567
+ }
568
+
569
+ // packages/localapp/src/service/linux-systemd-user.ts
570
+ var UNIT_NAME = "localapp.service";
571
+ function createLinuxSystemdUserService(options) {
572
+ const configHome = options.env?.XDG_CONFIG_HOME ?? path3.join(options.homeDir, ".config");
573
+ const registrationPath = path3.join(configHome, "systemd", "user", UNIT_NAME);
574
+ const unit = buildUnit(options);
575
+ const systemctl = options.env?.SYSTEMCTL_PATH ?? "systemctl";
576
+ return {
577
+ registrationPath,
578
+ async install() {
579
+ const installed = await writeServiceFile(registrationPath, unit);
580
+ const reload = await options.run({ command: systemctl, args: ["--user", "daemon-reload"] }).catch(() => void 0);
581
+ if (reload === void 0 || reload.code !== 0 && /connect to bus|no medium found|not been booted with systemd/i.test(reload.stderr)) {
582
+ return { mode: "foreground", installed: false, reason: "systemd user manager unavailable" };
583
+ }
584
+ if (reload.code !== 0) throw lifecycleError("user_service_command_failed", "The systemd user manager could not reload LocalApp");
585
+ await runServiceCommand(options.run, { command: systemctl, args: ["--user", "enable", "--now", UNIT_NAME] });
586
+ return { mode: "service", installed };
587
+ },
588
+ async start(signal) {
589
+ await runServiceCommand(options.run, withAbortSignal({ command: systemctl, args: ["--user", "start", UNIT_NAME] }, signal));
590
+ },
591
+ async stop() {
592
+ const result = await options.run({ command: systemctl, args: ["--user", "stop", UNIT_NAME] });
593
+ if (result.code !== 0 && !isMissingUnit(result.stderr)) {
594
+ throw lifecycleError("user_service_command_failed", "The systemd user service could not be stopped");
595
+ }
596
+ },
597
+ async restart() {
598
+ await runServiceCommand(options.run, { command: systemctl, args: ["--user", "restart", UNIT_NAME] });
599
+ },
600
+ async status() {
601
+ const result = await options.run({ command: systemctl, args: ["--user", "is-active", "--quiet", UNIT_NAME] });
602
+ if (result.code === 0) return true;
603
+ if ([3, 4].includes(result.code)) return false;
604
+ throw lifecycleError("user_service_command_failed", "The systemd user service status is unavailable");
605
+ },
606
+ async uninstall() {
607
+ const disabled = await options.run({ command: systemctl, args: ["--user", "disable", "--now", UNIT_NAME] });
608
+ if (disabled.code !== 0 && !isMissingUnit(disabled.stderr)) {
609
+ throw lifecycleError("user_service_command_failed", "The systemd user service could not be removed");
610
+ }
611
+ await fs2.rm(registrationPath, { force: true });
612
+ await runServiceCommand(options.run, { command: systemctl, args: ["--user", "daemon-reload"] });
613
+ }
614
+ };
615
+ }
616
+ function isMissingUnit(stderr) {
617
+ return /not loaded|not found|does not exist|no such file/i.test(stderr);
618
+ }
619
+ function buildUnit(options) {
620
+ const environment = Object.entries(options.serviceEnvironment).map(([key, value]) => `Environment=${systemdQuote(`${key}=${value}`)}`).join("\n");
621
+ return `[Unit]
622
+ Description=LocalApp per-user daemon
623
+ After=network.target
624
+
625
+ [Service]
626
+ Type=simple
627
+ ExecStart=${systemdQuote(options.nodePath)} ${systemdQuote(options.layout.launcherPath)}
628
+ Restart=on-failure
629
+ RestartSec=2
630
+ StandardOutput=append:${systemdQuote(options.layout.daemonLogPath)}
631
+ StandardError=append:${systemdQuote(options.layout.daemonLogPath)}
632
+ ${environment ? `${environment}
633
+ ` : ""}
634
+ [Install]
635
+ WantedBy=default.target
636
+ `;
637
+ }
638
+ function systemdQuote(value) {
639
+ if (value.includes("\0") || /[\r\n]/.test(value)) {
640
+ throw lifecycleError("user_service_configuration_invalid", "The systemd service command path is invalid");
641
+ }
642
+ return `"${value.replaceAll("\\", "\\\\").replaceAll('"', '\\"').replaceAll("%", "%%").replaceAll("$", "$$")}"`;
643
+ }
644
+
645
+ // packages/localapp/src/service/macos-launch-agent.ts
646
+ import crypto3 from "node:crypto";
647
+ import fs3 from "node:fs/promises";
648
+ import path4 from "node:path";
649
+ var LABEL = "com.localapp.daemon";
650
+ function createMacosLaunchAgent(options) {
651
+ const uid = options.uid ?? (typeof process.getuid === "function" ? process.getuid() : void 0);
652
+ if (!Number.isSafeInteger(uid) || (uid ?? -1) < 0) {
653
+ throw lifecycleError("user_service_configuration_invalid", "The current macOS user identity is unavailable");
654
+ }
655
+ const registrationPath = path4.join(options.homeDir, "Library", "LaunchAgents", `${LABEL}.plist`);
656
+ const domain = `gui/${uid}`;
657
+ const target = `${domain}/${LABEL}`;
658
+ const plist = buildPlist(options);
659
+ const receiptPath = `${registrationPath}.loaded`;
660
+ const plistDigest = crypto3.createHash("sha256").update(plist).digest("hex");
661
+ return {
662
+ registrationPath,
663
+ async install() {
664
+ const installed = await writeServiceFile(registrationPath, plist);
665
+ const receipt = await fs3.readFile(receiptPath, "utf8").then((value) => value.trim(), () => void 0);
666
+ const loaded = await options.run({ command: "/bin/launchctl", args: ["print", target] });
667
+ if (loaded.code === 0 && receipt === plistDigest) return { mode: "service", installed };
668
+ if (loaded.code !== 0 && !isMissingService(loaded.stderr)) {
669
+ throw lifecycleError("user_service_command_failed", "The macOS LaunchAgent status could not be verified");
670
+ }
671
+ const removed = await options.run({ command: "/bin/launchctl", args: ["bootout", target] });
672
+ if (removed.code !== 0 && !isMissingService(removed.stderr)) {
673
+ throw lifecycleError("user_service_command_failed", "The previous macOS LaunchAgent could not be removed");
674
+ }
675
+ const result = await options.run({ command: "/bin/launchctl", args: ["bootstrap", domain, registrationPath] });
676
+ if (result.code !== 0) {
677
+ throw lifecycleError("user_service_command_failed", "The macOS LaunchAgent could not be registered");
678
+ }
679
+ await writeServiceFile(receiptPath, `${plistDigest}
680
+ `);
681
+ return { mode: "service", installed };
682
+ },
683
+ async start(signal) {
684
+ const loaded = await options.run(withAbortSignal({ command: "/bin/launchctl", args: ["print", target] }, signal));
685
+ if (loaded.code !== 0) {
686
+ const result = await options.run(withAbortSignal({ command: "/bin/launchctl", args: ["bootstrap", domain, registrationPath] }, signal));
687
+ if (result.code !== 0) throw lifecycleError("user_service_command_failed", "The macOS LaunchAgent could not be registered");
688
+ }
689
+ await runServiceCommand(options.run, withAbortSignal({ command: "/bin/launchctl", args: ["kickstart", "-k", target] }, signal));
690
+ },
691
+ async stop() {
692
+ const result = await options.run({ command: "/bin/launchctl", args: ["bootout", domain, registrationPath] });
693
+ if (result.code !== 0 && !/could not find service|no such process/i.test(result.stderr)) {
694
+ throw lifecycleError("user_service_command_failed", "The macOS LaunchAgent could not be stopped");
695
+ }
696
+ },
697
+ async restart() {
698
+ await runServiceCommand(options.run, { command: "/bin/launchctl", args: ["kickstart", "-k", target] });
699
+ },
700
+ async status() {
701
+ const result = await options.run({ command: "/bin/launchctl", args: ["print", target] });
702
+ return result.code === 0;
703
+ },
704
+ async uninstall() {
705
+ const result = await options.run({ command: "/bin/launchctl", args: ["bootout", domain, registrationPath] });
706
+ if (result.code !== 0 && !/could not find service|no such process/i.test(result.stderr)) {
707
+ throw lifecycleError("user_service_command_failed", "The macOS LaunchAgent could not be removed");
708
+ }
709
+ await fs3.rm(registrationPath, { force: true });
710
+ await fs3.rm(receiptPath, { force: true });
711
+ }
712
+ };
713
+ }
714
+ function isMissingService(stderr) {
715
+ return /could not find service|service (?:is )?not found|no such process/i.test(stderr);
716
+ }
717
+ function buildPlist(options) {
718
+ const environment = Object.entries(options.serviceEnvironment).map(
719
+ ([key, value]) => ` <key>${xmlEscape(key)}</key>
720
+ <string>${xmlEscape(value)}</string>`
721
+ ).join("\n");
722
+ return `<?xml version="1.0" encoding="UTF-8"?>
723
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
724
+ <plist version="1.0">
725
+ <dict>
726
+ <key>Label</key><string>${LABEL}</string>
727
+ <key>ProgramArguments</key>
728
+ <array>
729
+ <string>${xmlEscape(options.nodePath)}</string>
730
+ <string>${xmlEscape(options.layout.launcherPath)}</string>
731
+ </array>
732
+ <key>RunAtLoad</key><true/>
733
+ <key>KeepAlive</key><true/>
734
+ <key>ProcessType</key><string>Interactive</string>
735
+ <key>StandardOutPath</key><string>${xmlEscape(options.layout.daemonLogPath)}</string>
736
+ <key>StandardErrorPath</key><string>${xmlEscape(options.layout.daemonLogPath)}</string>
737
+ ${environment ? ` <key>EnvironmentVariables</key>
738
+ <dict>
739
+ ${environment}
740
+ </dict>
741
+ ` : ""}</dict>
742
+ </plist>
743
+ `;
744
+ }
745
+
746
+ // packages/localapp/src/service/windows-user-task.ts
747
+ import fs4 from "node:fs/promises";
748
+ import path5 from "node:path";
749
+ var TASK_NAME = "LocalApp User Daemon";
750
+ function createWindowsUserTask(options) {
751
+ const registrationPath = path5.join(options.layout.supportDir, "service", "windows-user-task.json");
752
+ const systemRoot = options.env?.SystemRoot ?? options.env?.SYSTEMROOT ?? "C:\\Windows";
753
+ const scheduler = path5.win32.join(systemRoot, "System32", "schtasks.exe");
754
+ const taskCommand = `${quoteWindowsArgument(options.nodePath)} ${quoteWindowsArgument(options.layout.launcherPath)}`;
755
+ const metadata = `${JSON.stringify({
756
+ schemaVersion: 1,
757
+ taskName: TASK_NAME,
758
+ command: taskCommand,
759
+ environment: options.serviceEnvironment
760
+ }, null, 2)}
761
+ `;
762
+ return {
763
+ registrationPath,
764
+ async install() {
765
+ const installed = await writeServiceFile(registrationPath, metadata);
766
+ await runServiceCommand(options.run, {
767
+ command: scheduler,
768
+ args: ["/Create", "/TN", TASK_NAME, "/SC", "ONLOGON", "/RL", "LIMITED", "/TR", taskCommand, "/F"]
769
+ });
770
+ return { mode: "service", installed };
771
+ },
772
+ async start(signal) {
773
+ await runServiceCommand(options.run, withAbortSignal({ command: scheduler, args: ["/Run", "/TN", TASK_NAME] }, signal));
774
+ },
775
+ async stop() {
776
+ const result = await options.run({ command: scheduler, args: ["/End", "/TN", TASK_NAME] });
777
+ if (result.code !== 0 && !/cannot find|does not exist|not currently running/i.test(result.stderr)) {
778
+ throw lifecycleError("user_service_command_failed", "The Windows user task could not be stopped");
779
+ }
780
+ },
781
+ async restart() {
782
+ await this.stop();
783
+ await this.start();
784
+ },
785
+ async status() {
786
+ const result = await options.run({ command: scheduler, args: ["/Query", "/TN", TASK_NAME, "/FO", "LIST"] });
787
+ return result.code === 0;
788
+ },
789
+ async uninstall() {
790
+ const result = await options.run({ command: scheduler, args: ["/Delete", "/TN", TASK_NAME, "/F"] });
791
+ if (result.code !== 0 && !/cannot find|does not exist/i.test(result.stderr)) {
792
+ throw lifecycleError("user_service_command_failed", "The Windows user task could not be removed");
793
+ }
794
+ await fs4.rm(registrationPath, { force: true });
795
+ }
796
+ };
797
+ }
798
+ function quoteWindowsArgument(value) {
799
+ if (value.includes("\0") || /[\r\n]/.test(value)) {
800
+ throw lifecycleError("user_service_configuration_invalid", "The Windows service command path is invalid");
801
+ }
802
+ return `"${value.replace(/(\\*)"/g, '$1$1\\"').replace(/(\\+)$/g, "$1$1")}"`;
803
+ }
804
+
805
+ // packages/localapp/src/service/service-manager.ts
806
+ function createServiceManager(options) {
807
+ const platform = options.platform ?? process.platform;
808
+ const serviceEnvironment = validateServiceEnvironment(options.serviceEnvironment ?? {});
809
+ const normalized = { ...options, platform, serviceEnvironment };
810
+ if (platform === "darwin") return withLogs(createMacosLaunchAgent(normalized), options.layout);
811
+ if (platform === "win32") return withLogs(createWindowsUserTask(normalized), options.layout);
812
+ if (platform === "linux") return withLogs(createLinuxSystemdUserService(normalized), options.layout);
813
+ throw lifecycleError("user_service_unsupported", `LocalApp user services are unsupported on ${platform}`);
814
+ }
815
+ function createCurrentUserServiceManager(layout) {
816
+ return createServiceManager({
817
+ layout,
818
+ nodePath: process.execPath,
819
+ homeDir: process.env.HOME ?? process.env.USERPROFILE ?? process.cwd(),
820
+ serviceEnvironment: runtimeLayoutServiceEnvironment(layout),
821
+ run: createSpawnServiceCommandRunner()
822
+ });
823
+ }
824
+ function runtimeLayoutServiceEnvironment(layout) {
825
+ return {
826
+ LOCALAPP_SUPPORT_DIR: layout.supportDir,
827
+ LOCALAPP_RUNTIME_DIR: layout.runtimeDir,
828
+ LOCALAPP_DATA_DIR: layout.dataDir
829
+ };
830
+ }
831
+ function createSpawnServiceCommandRunner() {
832
+ return async ({ command, args, signal }) => await new Promise((resolve) => {
833
+ if (signal?.aborted) {
834
+ resolve({ code: 1, stdout: "", stderr: "aborted" });
835
+ return;
836
+ }
837
+ const child = spawn(command, args, {
838
+ shell: false,
839
+ windowsHide: true,
840
+ stdio: ["ignore", "pipe", "pipe"],
841
+ // A service command that traps SIGTERM must not outlive the one broker
842
+ // deadline. Node maps this to forced process termination on Windows too.
843
+ ...signal === void 0 ? {} : { signal, killSignal: "SIGKILL" }
844
+ });
845
+ let stdout = "";
846
+ let stderr = "";
847
+ let settled = false;
848
+ const finish = (code) => {
849
+ if (settled) return;
850
+ settled = true;
851
+ resolve({ code, stdout, stderr });
852
+ };
853
+ child.stdout?.on("data", (chunk) => {
854
+ stdout += String(chunk);
855
+ });
856
+ child.stderr?.on("data", (chunk) => {
857
+ stderr += String(chunk);
858
+ });
859
+ child.once("error", (error) => {
860
+ stderr += error.message;
861
+ if (child.pid === void 0) finish(1);
862
+ });
863
+ child.once("close", (code) => finish(code ?? 1));
864
+ });
865
+ }
866
+ async function runServiceCommand(run, invocation, toleratedCodes = []) {
867
+ let result;
868
+ try {
869
+ result = await run(invocation);
870
+ } catch {
871
+ throw lifecycleError("user_service_command_unavailable", "The current-user service manager is unavailable");
872
+ }
873
+ if (result.code !== 0 && !toleratedCodes.includes(result.code)) {
874
+ throw lifecycleError("user_service_command_failed", "The current-user service manager command failed");
875
+ }
876
+ return result;
877
+ }
878
+ function withAbortSignal(invocation, signal) {
879
+ return signal === void 0 ? invocation : { ...invocation, signal };
880
+ }
881
+ function validateServiceEnvironment(value) {
882
+ const output = {};
883
+ for (const [key, entry] of Object.entries(value)) {
884
+ if (!/^[A-Z][A-Z0-9_]{0,63}$/.test(key) || /(API_?KEY|PASSWORD|SECRET|TOKEN|CREDENTIAL)/i.test(key) || typeof entry !== "string" || entry.includes("\0") || entry.length > 4096) {
885
+ throw lifecycleError("user_service_configuration_invalid", "The LocalApp user service configuration is invalid");
886
+ }
887
+ output[key] = entry;
888
+ }
889
+ return output;
890
+ }
891
+ function withLogs(manager, layout) {
892
+ return {
893
+ ...manager,
894
+ async logs(lines = 200) {
895
+ if (!Number.isSafeInteger(lines) || lines < 1 || lines > 1e4) {
896
+ throw lifecycleError("user_service_logs_invalid", "The requested log line count is invalid");
897
+ }
898
+ const handle = await fs5.open(layout.daemonLogPath, "r").catch((error) => {
899
+ if (error.code === "ENOENT") return void 0;
900
+ throw error;
901
+ });
902
+ if (handle === void 0) return "";
903
+ try {
904
+ const stat = await handle.stat();
905
+ const cap = 1024 * 1024;
906
+ const size = Math.min(stat.size, cap);
907
+ const buffer = Buffer.alloc(size);
908
+ await handle.read(buffer, 0, size, Math.max(0, stat.size - size));
909
+ const text = buffer.toString("utf8");
910
+ const tail = text.split(/\r?\n/).slice(-(lines + 1), -1).join("\n");
911
+ return stat.size > cap ? `[truncated to ${cap} bytes]
912
+ ${tail}` : tail;
913
+ } finally {
914
+ await handle.close();
915
+ }
916
+ }
917
+ };
918
+ }
919
+
920
+ // packages/localapp/src/native/native-ipc-client.ts
921
+ async function main(argv) {
922
+ if (argv.length !== 1) {
923
+ process.exitCode = 1;
924
+ return;
925
+ }
926
+ const url = argv[0];
927
+ const layout = createRuntimeLayout({
928
+ supportDir: process.env.LOCALAPP_SUPPORT_DIR,
929
+ runtimeDir: process.env.LOCALAPP_RUNTIME_DIR,
930
+ dataDir: process.env.LOCALAPP_DATA_DIR
931
+ });
932
+ await forwardActivationToDaemon({
933
+ url,
934
+ ipcClient: createIpcClient({ endpoint: layout.controlEndpoint, timeoutMs: 1e3 }),
935
+ service: createCurrentUserServiceManager(layout)
936
+ });
937
+ }
938
+ void main(process.argv.slice(2)).catch(() => {
939
+ process.exitCode = 1;
940
+ });