aegisone 1.0.34 → 1.0.37

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 (372) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +1 -1
  3. package/SOURCE-OFFER.txt +9 -0
  4. package/bin/aegis.js +1 -322
  5. package/package.json +4 -5
  6. package/scripts/bump.mjs +1 -211
  7. package/scripts/bundle.js +1 -129
  8. package/scripts/predist.mjs +1 -976
  9. package/src/child.js +1 -285
  10. package/src/dispatch.js +1 -269
  11. package/src/doctor.js +1 -639
  12. package/src/host.js +1 -111
  13. package/src/iface/paths.js +3 -0
  14. package/src/iface/pty.js +3 -0
  15. package/src/iface/update.js +3 -0
  16. package/src/iface/window.js +3 -0
  17. package/src/permissions.js +1 -383
  18. package/src/probes.js +1 -159
  19. package/src/protocol.js +3 -0
  20. package/src/release.js +1 -409
  21. package/src/selfhost.js +3 -0
  22. package/vendor/cli/package.json +3 -7
  23. package/vendor/cli/scripts/check.mjs +1 -52
  24. package/vendor/cli/scripts/demo.mjs +1 -94
  25. package/vendor/cli/scripts/predist.mjs +1 -75
  26. package/vendor/cli/scripts/runtests.mjs +1 -56
  27. package/vendor/cli/scripts/seal-gate.mjs +1 -74
  28. package/vendor/cli/src/agents.js +1 -139
  29. package/vendor/cli/src/app.js +1 -2957
  30. package/vendor/cli/src/art.js +1 -289
  31. package/vendor/cli/src/chatflow.js +1 -3023
  32. package/vendor/cli/src/checkpoint.js +1 -90
  33. package/vendor/cli/src/clipboard.js +1 -424
  34. package/vendor/cli/src/cloudsync.js +1 -528
  35. package/vendor/cli/src/commands.js +1 -4089
  36. package/vendor/cli/src/config.js +1 -581
  37. package/vendor/cli/src/connect.js +1 -349
  38. package/vendor/cli/src/credentials.js +1 -33
  39. package/vendor/cli/src/deps.js +1 -232
  40. package/vendor/cli/src/devrun.js +1 -187
  41. package/vendor/cli/src/diff.js +1 -333
  42. package/vendor/cli/src/diffview.js +1 -296
  43. package/vendor/cli/src/engine.js +1 -297
  44. package/vendor/cli/src/entitlement.js +1 -355
  45. package/vendor/cli/src/events.js +1 -707
  46. package/vendor/cli/src/export.js +1 -67
  47. package/vendor/cli/src/filepreview.js +1 -153
  48. package/vendor/cli/src/fingerprint.js +1 -592
  49. package/vendor/cli/src/format.js +1 -259
  50. package/vendor/cli/src/fuzzy.js +1 -119
  51. package/vendor/cli/src/history.js +1 -423
  52. package/vendor/cli/src/init.js +1 -175
  53. package/vendor/cli/src/input.js +1 -139
  54. package/vendor/cli/src/keys.js +1 -183
  55. package/vendor/cli/src/markdown.js +1 -306
  56. package/vendor/cli/src/models.js +1 -507
  57. package/vendor/cli/src/naming.js +1 -57
  58. package/vendor/cli/src/overlays.js +1 -462
  59. package/vendor/cli/src/panels.js +1 -1418
  60. package/vendor/cli/src/ping.js +1 -226
  61. package/vendor/cli/src/presence.js +1 -238
  62. package/vendor/cli/src/render.js +1 -516
  63. package/vendor/cli/src/screen.js +1 -518
  64. package/vendor/cli/src/screens.js +1 -896
  65. package/vendor/cli/src/secret.js +1 -59
  66. package/vendor/cli/src/securefs.js +1 -359
  67. package/vendor/cli/src/settings.js +1 -155
  68. package/vendor/cli/src/shared.js +1 -52
  69. package/vendor/cli/src/sharedpaths.js +1 -53
  70. package/vendor/cli/src/signup.js +1 -156
  71. package/vendor/cli/src/summarize.js +1 -95
  72. package/vendor/cli/src/sysdiag.js +1 -585
  73. package/vendor/cli/src/system.js +1 -40
  74. package/vendor/cli/src/theme.js +1 -570
  75. package/vendor/cli/src/title.js +1 -220
  76. package/vendor/cli/src/todos.js +1 -115
  77. package/vendor/cli/src/tokens.js +1 -263
  78. package/vendor/cli/src/topup.js +1 -210
  79. package/vendor/cli/src/update.js +1 -191
  80. package/vendor/cli/vendor/client/aegis.js +1 -2441
  81. package/vendor/cli/vendor/client/attest.js +1 -518
  82. package/vendor/cli/vendor/client/authorship-key.js +1 -410
  83. package/vendor/cli/vendor/client/auto-provision.js +1 -134
  84. package/vendor/cli/vendor/client/brain-catalog.js +1 -268
  85. package/vendor/cli/vendor/client/byok-catalog.js +1 -199
  86. package/vendor/cli/vendor/client/catalog-client.js +1 -487
  87. package/vendor/cli/vendor/client/conversation-export.js +1 -177
  88. package/vendor/cli/vendor/client/credentials.js +1 -494
  89. package/vendor/cli/vendor/client/device-fingerprint.js +1 -141
  90. package/vendor/cli/vendor/client/drive-connect.js +1 -110
  91. package/vendor/cli/vendor/client/drive-upload.js +1 -234
  92. package/vendor/cli/vendor/client/env-file.js +1 -1273
  93. package/vendor/cli/vendor/client/fingerprint.js +1 -1064
  94. package/vendor/cli/vendor/client/foreign-memory.js +1 -669
  95. package/vendor/cli/vendor/client/google-signin.js +1 -133
  96. package/vendor/cli/vendor/client/hooks.js +1 -430
  97. package/vendor/cli/vendor/client/model-discovery.js +1 -373
  98. package/vendor/cli/vendor/client/naming.js +1 -283
  99. package/vendor/cli/vendor/client/platform.js +1 -937
  100. package/vendor/cli/vendor/client/prefs.js +1 -351
  101. package/vendor/cli/vendor/client/presence-constants.js +1 -107
  102. package/vendor/cli/vendor/client/presence.js +1 -438
  103. package/vendor/cli/vendor/client/record-vault.js +3 -1055
  104. package/vendor/cli/vendor/client/session-store.js +1 -575
  105. package/vendor/cli/vendor/client/topup.js +1 -297
  106. package/vendor/cli/vendor/client/touch.js +1 -458
  107. package/vendor/cli/vendor/client/update.js +1 -763
  108. package/vendor/cli/vendor/client/user-models.js +1 -381
  109. package/vendor/cli/vendor/desktop/lib/local/agents.js +1 -105
  110. package/vendor/cli/vendor/desktop/lib/local/attachments.js +1 -276
  111. package/vendor/cli/vendor/desktop/lib/local/autonomous.js +1 -1045
  112. package/vendor/cli/vendor/desktop/lib/local/claude-pro.js +1 -1028
  113. package/vendor/cli/vendor/desktop/lib/local/context.js +1 -125
  114. package/vendor/cli/vendor/desktop/lib/local/engine.js +1 -3666
  115. package/vendor/cli/vendor/desktop/lib/local/entitlement.js +1 -660
  116. package/vendor/cli/vendor/desktop/lib/local/git-scope.js +1 -228
  117. package/vendor/cli/vendor/desktop/lib/local/integrity.js +1 -1
  118. package/vendor/cli/vendor/desktop/lib/local/local.js +1 -2145
  119. package/vendor/cli/vendor/desktop/lib/local/prompt.js +1 -280
  120. package/vendor/cli/vendor/desktop/lib/local/queue.js +1 -560
  121. package/vendor/cli/vendor/desktop/lib/local/session-rounds.js +1 -238
  122. package/vendor/cli/vendor/desktop/lib/local/spill.js +1 -75
  123. package/vendor/cli/vendor/desktop/lib/local/turn-guard.js +1 -300
  124. package/vendor/cli/vendor/desktop/lib/local/worktree-lock.js +1 -235
  125. package/vendor/cli/vendor/desktop/lib/settings.js +1 -890
  126. package/vendor/cli/vendor/desktop/main.js +67 -1
  127. package/vendor/cli/vendor/desktop/renderer/usage.js +1 -1239
  128. package/vendor/cli/vendor/hosts/install.js +1 -638
  129. package/vendor/cli/vendor/hosts/openai-shim.js +1 -515
  130. package/vendor/cli/vendor/hosts/spec.js +1 -164
  131. package/vendor/cli/vendor/hosts/targets.js +1 -346
  132. package/vendor/cli/vendor/mcp/server.js +1 -221
  133. package/vendor/cli/vendor/mcp/tools.js +1 -408
  134. package/vendor/cli/vendor/one/src/child.js +1 -285
  135. package/vendor/cli/vendor/one/src/permissions.js +1 -383
  136. package/vendor/cli/vendor/one/src/selfhost.js +3 -0
  137. package/vendor/desktop/bin/aegis.js +1 -32
  138. package/vendor/desktop/lib/account-key.js +1 -56
  139. package/vendor/desktop/lib/auto.js +1 -461
  140. package/vendor/desktop/lib/avatar/companion.js +1 -698
  141. package/vendor/desktop/lib/avatar/cosmetics.js +1 -532
  142. package/vendor/desktop/lib/avatar/events.js +1 -344
  143. package/vendor/desktop/lib/avatar/holder-turn.js +1 -350
  144. package/vendor/desktop/lib/avatar/holders.js +1 -612
  145. package/vendor/desktop/lib/avatar/identity.js +1 -641
  146. package/vendor/desktop/lib/avatar/level.js +1 -368
  147. package/vendor/desktop/lib/avatar/mirror.js +1 -524
  148. package/vendor/desktop/lib/avatar/persona.js +1 -388
  149. package/vendor/desktop/lib/avatar/profile.js +1 -977
  150. package/vendor/desktop/lib/avatar/register.js +1 -307
  151. package/vendor/desktop/lib/avatar/store.js +1 -472
  152. package/vendor/desktop/lib/avatar/tiers.js +1 -38
  153. package/vendor/desktop/lib/avatar/transfer.js +1 -415
  154. package/vendor/desktop/lib/avatar/turn.js +1 -216
  155. package/vendor/desktop/lib/avatar/voice.js +1 -328
  156. package/vendor/desktop/lib/avatar/xp.js +1 -404
  157. package/vendor/desktop/lib/deep-link.js +1 -120
  158. package/vendor/desktop/lib/fingerprint.js +2 -347
  159. package/vendor/desktop/lib/google-connect.js +1 -323
  160. package/vendor/desktop/lib/local/agents.js +1 -105
  161. package/vendor/desktop/lib/local/attachments.js +1 -276
  162. package/vendor/desktop/lib/local/autonomous.js +1 -1045
  163. package/vendor/desktop/lib/local/claude-pro.js +1 -1028
  164. package/vendor/desktop/lib/local/context.js +1 -125
  165. package/vendor/desktop/lib/local/engine.js +1 -3666
  166. package/vendor/desktop/lib/local/entitlement.js +1 -660
  167. package/vendor/desktop/lib/local/git-scope.js +1 -228
  168. package/vendor/desktop/lib/local/integrity.js +1 -1
  169. package/vendor/desktop/lib/local/local.js +1 -2145
  170. package/vendor/desktop/lib/local/prompt.js +1 -280
  171. package/vendor/desktop/lib/local/queue.js +1 -560
  172. package/vendor/desktop/lib/local/session-rounds.js +1 -238
  173. package/vendor/desktop/lib/local/spill.js +1 -75
  174. package/vendor/desktop/lib/local/telemetry.js +1 -470
  175. package/vendor/desktop/lib/local/turn-guard.js +1 -300
  176. package/vendor/desktop/lib/local/worktree-lock.js +1 -235
  177. package/vendor/desktop/lib/provider-key-mirror.js +1 -252
  178. package/vendor/desktop/lib/quick-launcher.js +1 -84
  179. package/vendor/desktop/lib/settings.js +1 -890
  180. package/vendor/desktop/lib/sync/memory-queue.js +1 -60
  181. package/vendor/desktop/lib/sync/persist-gate.js +1 -148
  182. package/vendor/desktop/lib/sync/sessions.js +1 -106
  183. package/vendor/desktop/lib/window-state.js +1 -66
  184. package/vendor/desktop/main.js +67 -1
  185. package/vendor/desktop/package.json +3 -5
  186. package/vendor/desktop/preload.js +1 -679
  187. package/vendor/desktop/renderer/app.js +1 -7250
  188. package/vendor/desktop/renderer/avatar/assemble.js +1 -335
  189. package/vendor/desktop/renderer/avatar/avatar.js +1 -380
  190. package/vendor/desktop/renderer/avatar/cards.js +1 -141
  191. package/vendor/desktop/renderer/avatar/hud.js +1 -206
  192. package/vendor/desktop/renderer/avatar/machine.js +1 -213
  193. package/vendor/desktop/renderer/avatar/pane.js +1 -439
  194. package/vendor/desktop/renderer/avatar/parts.js +1 -437
  195. package/vendor/desktop/renderer/budget.js +1 -172
  196. package/vendor/desktop/renderer/companion.js +1 -223
  197. package/vendor/desktop/renderer/diff.js +1 -359
  198. package/vendor/desktop/renderer/diffview.js +1 -336
  199. package/vendor/desktop/renderer/filepreview.js +1 -211
  200. package/vendor/desktop/renderer/fingerprint.js +3 -789
  201. package/vendor/desktop/renderer/markdown.js +1 -168
  202. package/vendor/desktop/renderer/provider-mark.js +1 -311
  203. package/vendor/desktop/renderer/provider-toolbar.js +1 -134
  204. package/vendor/desktop/renderer/providers.js +1 -259
  205. package/vendor/desktop/renderer/quick.js +1 -285
  206. package/vendor/desktop/renderer/stream-policy.js +1 -387
  207. package/vendor/desktop/renderer/transcript-view.js +1 -323
  208. package/vendor/desktop/renderer/usage.js +1 -1239
  209. package/vendor/desktop/vendor/aegis.js +1 -2441
  210. package/vendor/desktop/vendor/attest.js +1 -518
  211. package/vendor/desktop/vendor/authorship-key.js +1 -410
  212. package/vendor/desktop/vendor/auto-provision.js +1 -134
  213. package/vendor/desktop/vendor/brain-catalog.js +1 -268
  214. package/vendor/desktop/vendor/byok-catalog.js +1 -199
  215. package/vendor/desktop/vendor/catalog-client.js +1 -487
  216. package/vendor/desktop/vendor/conversation-export.js +1 -177
  217. package/vendor/desktop/vendor/credentials.js +1 -494
  218. package/vendor/desktop/vendor/device-fingerprint.js +1 -141
  219. package/vendor/desktop/vendor/drive-connect.js +1 -110
  220. package/vendor/desktop/vendor/drive-upload.js +1 -234
  221. package/vendor/desktop/vendor/env-file.js +1 -1273
  222. package/vendor/desktop/vendor/faces/cli/LICENSE +661 -0
  223. package/vendor/desktop/vendor/faces/cli/README.md +784 -0
  224. package/vendor/desktop/vendor/faces/cli/bin/aegiscode.js +20 -0
  225. package/vendor/desktop/vendor/faces/cli/package.json +44 -0
  226. package/vendor/desktop/vendor/faces/cli/scripts/check.mjs +4 -0
  227. package/vendor/desktop/vendor/faces/cli/scripts/demo.mjs +4 -0
  228. package/vendor/desktop/vendor/faces/cli/scripts/predist.mjs +4 -0
  229. package/vendor/desktop/vendor/faces/cli/scripts/runtests.mjs +4 -0
  230. package/vendor/desktop/vendor/faces/cli/scripts/seal-gate.mjs +3 -0
  231. package/vendor/desktop/vendor/faces/cli/src/agents.js +3 -0
  232. package/vendor/desktop/vendor/faces/cli/src/app.js +3 -0
  233. package/vendor/desktop/vendor/faces/cli/src/art.js +3 -0
  234. package/vendor/desktop/vendor/faces/cli/src/autonomous.js +3 -0
  235. package/vendor/desktop/vendor/faces/cli/src/caps.js +3 -0
  236. package/vendor/desktop/vendor/faces/cli/src/chatflow.js +3 -0
  237. package/vendor/desktop/vendor/faces/cli/src/checkpoint.js +3 -0
  238. package/vendor/desktop/vendor/faces/cli/src/clipboard.js +3 -0
  239. package/vendor/desktop/vendor/faces/cli/src/cloudsync.js +3 -0
  240. package/vendor/desktop/vendor/faces/cli/src/commands.js +3 -0
  241. package/vendor/desktop/vendor/faces/cli/src/config.js +3 -0
  242. package/vendor/desktop/vendor/faces/cli/src/connect.js +3 -0
  243. package/vendor/desktop/vendor/faces/cli/src/credentials.js +3 -0
  244. package/vendor/desktop/vendor/faces/cli/src/deps.js +3 -0
  245. package/vendor/desktop/vendor/faces/cli/src/devrun.js +3 -0
  246. package/vendor/desktop/vendor/faces/cli/src/diff.js +3 -0
  247. package/vendor/desktop/vendor/faces/cli/src/diffview.js +3 -0
  248. package/vendor/desktop/vendor/faces/cli/src/engine.js +3 -0
  249. package/vendor/desktop/vendor/faces/cli/src/entitlement.js +3 -0
  250. package/vendor/desktop/vendor/faces/cli/src/events.js +3 -0
  251. package/vendor/desktop/vendor/faces/cli/src/export.js +3 -0
  252. package/vendor/desktop/vendor/faces/cli/src/filepreview.js +3 -0
  253. package/vendor/desktop/vendor/faces/cli/src/fingerprint.js +3 -0
  254. package/vendor/desktop/vendor/faces/cli/src/format.js +3 -0
  255. package/vendor/desktop/vendor/faces/cli/src/fuzzy.js +3 -0
  256. package/vendor/desktop/vendor/faces/cli/src/gate.js +3 -0
  257. package/vendor/desktop/vendor/faces/cli/src/history.js +3 -0
  258. package/vendor/desktop/vendor/faces/cli/src/init.js +3 -0
  259. package/vendor/desktop/vendor/faces/cli/src/input.js +3 -0
  260. package/vendor/desktop/vendor/faces/cli/src/keys.js +3 -0
  261. package/vendor/desktop/vendor/faces/cli/src/limits.js +3 -0
  262. package/vendor/desktop/vendor/faces/cli/src/markdown.js +3 -0
  263. package/vendor/desktop/vendor/faces/cli/src/mcp.js +3 -0
  264. package/vendor/desktop/vendor/faces/cli/src/models.js +3 -0
  265. package/vendor/desktop/vendor/faces/cli/src/naming.js +3 -0
  266. package/vendor/desktop/vendor/faces/cli/src/overlays.js +3 -0
  267. package/vendor/desktop/vendor/faces/cli/src/panels.js +3 -0
  268. package/vendor/desktop/vendor/faces/cli/src/permissions.js +3 -0
  269. package/vendor/desktop/vendor/faces/cli/src/ping.js +3 -0
  270. package/vendor/desktop/vendor/faces/cli/src/presence.js +3 -0
  271. package/vendor/desktop/vendor/faces/cli/src/provenance.js +58 -0
  272. package/vendor/desktop/vendor/faces/cli/src/provenance.lock.json +36 -0
  273. package/vendor/desktop/vendor/faces/cli/src/render.js +3 -0
  274. package/vendor/desktop/vendor/faces/cli/src/screen.js +3 -0
  275. package/vendor/desktop/vendor/faces/cli/src/screens.js +3 -0
  276. package/vendor/desktop/vendor/faces/cli/src/secret.js +3 -0
  277. package/vendor/desktop/vendor/faces/cli/src/securefs.js +3 -0
  278. package/vendor/desktop/vendor/faces/cli/src/settings.js +3 -0
  279. package/vendor/desktop/vendor/faces/cli/src/shared.js +3 -0
  280. package/vendor/desktop/vendor/faces/cli/src/sharedpaths.js +3 -0
  281. package/vendor/desktop/vendor/faces/cli/src/signup.js +3 -0
  282. package/vendor/desktop/vendor/faces/cli/src/summarize.js +3 -0
  283. package/vendor/desktop/vendor/faces/cli/src/sysdiag.js +3 -0
  284. package/vendor/desktop/vendor/faces/cli/src/system.js +3 -0
  285. package/vendor/desktop/vendor/faces/cli/src/theme.js +3 -0
  286. package/vendor/desktop/vendor/faces/cli/src/title.js +3 -0
  287. package/vendor/desktop/vendor/faces/cli/src/todos.js +3 -0
  288. package/vendor/desktop/vendor/faces/cli/src/tokens.js +3 -0
  289. package/vendor/desktop/vendor/faces/cli/src/topup.js +3 -0
  290. package/vendor/desktop/vendor/faces/cli/src/update.js +3 -0
  291. package/vendor/desktop/vendor/faces/cli/vendor/client/aegis.js +4 -0
  292. package/vendor/desktop/vendor/faces/cli/vendor/client/attest.js +3 -0
  293. package/vendor/desktop/vendor/faces/cli/vendor/client/authorship-key.js +3 -0
  294. package/vendor/desktop/vendor/faces/cli/vendor/client/auto-provision.js +3 -0
  295. package/vendor/desktop/vendor/faces/cli/vendor/client/brain-catalog.js +3 -0
  296. package/vendor/desktop/vendor/faces/cli/vendor/client/byok-catalog.js +3 -0
  297. package/vendor/desktop/vendor/faces/cli/vendor/client/catalog-client.js +3 -0
  298. package/vendor/desktop/vendor/faces/cli/vendor/client/conversation-export.js +3 -0
  299. package/vendor/desktop/vendor/faces/cli/vendor/client/credentials.js +3 -0
  300. package/vendor/desktop/vendor/faces/cli/vendor/client/device-fingerprint.js +3 -0
  301. package/vendor/desktop/vendor/faces/cli/vendor/client/drive-connect.js +3 -0
  302. package/vendor/desktop/vendor/faces/cli/vendor/client/drive-upload.js +3 -0
  303. package/vendor/desktop/vendor/faces/cli/vendor/client/env-file.js +3 -0
  304. package/vendor/desktop/vendor/faces/cli/vendor/client/fingerprint.js +3 -0
  305. package/vendor/desktop/vendor/faces/cli/vendor/client/foreign-memory.js +3 -0
  306. package/vendor/desktop/vendor/faces/cli/vendor/client/google-signin.js +3 -0
  307. package/vendor/desktop/vendor/faces/cli/vendor/client/hooks.js +3 -0
  308. package/vendor/desktop/vendor/faces/cli/vendor/client/model-discovery.js +3 -0
  309. package/vendor/desktop/vendor/faces/cli/vendor/client/naming.js +3 -0
  310. package/vendor/desktop/vendor/faces/cli/vendor/client/platform.js +3 -0
  311. package/vendor/desktop/vendor/faces/cli/vendor/client/prefs.js +3 -0
  312. package/vendor/desktop/vendor/faces/cli/vendor/client/presence-constants.js +3 -0
  313. package/vendor/desktop/vendor/faces/cli/vendor/client/presence.js +3 -0
  314. package/vendor/desktop/vendor/faces/cli/vendor/client/record-vault.js +105 -0
  315. package/vendor/desktop/vendor/faces/cli/vendor/client/session-store.js +3 -0
  316. package/vendor/desktop/vendor/faces/cli/vendor/client/topup.js +3 -0
  317. package/vendor/desktop/vendor/faces/cli/vendor/client/touch.js +3 -0
  318. package/vendor/desktop/vendor/faces/cli/vendor/client/update.js +3 -0
  319. package/vendor/desktop/vendor/faces/cli/vendor/client/user-models.js +3 -0
  320. package/vendor/desktop/vendor/faces/cli/vendor/covenant/README.md +21 -0
  321. package/vendor/desktop/vendor/faces/cli/vendor/covenant/aegis.seal +177 -0
  322. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/aegis-seal.mjs +241 -0
  323. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/agents.js +3 -0
  324. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/attachments.js +3 -0
  325. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/autonomous.js +3 -0
  326. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/claude-pro.js +3 -0
  327. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/context.js +3 -0
  328. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/covenant.js +567 -0
  329. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/engine.js +3 -0
  330. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/entitlement.js +3 -0
  331. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/exec-plan.js +3 -0
  332. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/git-scope.js +3 -0
  333. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/integrity.js +3 -0
  334. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/local.js +3 -0
  335. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/prompt.js +3 -0
  336. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/queue.js +3 -0
  337. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/session-rounds.js +3 -0
  338. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/shell.js +3 -0
  339. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/spill.js +3 -0
  340. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/tools.js +3 -0
  341. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/turn-guard.js +3 -0
  342. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/local/worktree-lock.js +3 -0
  343. package/vendor/desktop/vendor/faces/cli/vendor/desktop/lib/settings.js +3 -0
  344. package/vendor/desktop/vendor/faces/cli/vendor/desktop/main.js +4 -0
  345. package/vendor/desktop/vendor/faces/cli/vendor/desktop/renderer/usage.js +3 -0
  346. package/vendor/desktop/vendor/faces/cli/vendor/hosts/install.js +1 -0
  347. package/vendor/desktop/vendor/faces/cli/vendor/hosts/openai-shim.js +2 -0
  348. package/vendor/desktop/vendor/faces/cli/vendor/hosts/spec.js +1 -0
  349. package/vendor/desktop/vendor/faces/cli/vendor/hosts/targets.js +1 -0
  350. package/vendor/desktop/vendor/faces/cli/vendor/mcp/server.js +4 -0
  351. package/vendor/desktop/vendor/faces/cli/vendor/mcp/tools.js +3 -0
  352. package/vendor/desktop/vendor/faces/cli/vendor/one/src/child.js +3 -0
  353. package/vendor/desktop/vendor/faces/cli/vendor/one/src/permissions.js +3 -0
  354. package/vendor/desktop/vendor/faces/cli/vendor/one/src/selfhost.js +3 -0
  355. package/vendor/desktop/vendor/faces/cli/vendor/tools/agent-gate.mjs +1203 -0
  356. package/vendor/desktop/vendor/fingerprint.js +1 -1064
  357. package/vendor/desktop/vendor/foreign-memory.js +1 -669
  358. package/vendor/desktop/vendor/google-signin.js +1 -133
  359. package/vendor/desktop/vendor/hooks.js +1 -430
  360. package/vendor/desktop/vendor/model-discovery.js +1 -373
  361. package/vendor/desktop/vendor/naming.js +1 -283
  362. package/vendor/desktop/vendor/platform.js +1 -937
  363. package/vendor/desktop/vendor/prefs.js +1 -351
  364. package/vendor/desktop/vendor/presence-constants.js +1 -107
  365. package/vendor/desktop/vendor/presence.js +1 -438
  366. package/vendor/desktop/vendor/record-vault.js +3 -1055
  367. package/vendor/desktop/vendor/selfhost.js +3 -0
  368. package/vendor/desktop/vendor/session-store.js +1 -575
  369. package/vendor/desktop/vendor/topup.js +1 -297
  370. package/vendor/desktop/vendor/touch.js +1 -458
  371. package/vendor/desktop/vendor/update.js +1 -763
  372. package/vendor/desktop/vendor/user-models.js +1 -381
@@ -1,440 +1,3 @@
1
1
  // SPDX-License-Identifier: AGPL-3.0-or-later
2
2
  // Copyright (C) 2026 Niklas Borneklint — AEGIS Code (aegiscode) / Aegiscloud.
3
- // AEGIS Code (aegiscode) — source: https://github.com/aegisinfo/aegiscode-plugin
4
- // Conveying a modified copy, or running one as a network service, owes the
5
- // corresponding source under this licence (§5/§13) — see LICENSING.md.
6
- 'use strict';
7
-
8
- /**
9
- * Client presence beacon — the client half of aegis1's `/api/v1/heartbeat`.
10
- *
11
- * WHAT IT IS FOR. aegis1 already had `/api/heartbeat` (the dashboard's own JS
12
- * pinging to bump `users.last_active_at`). What it did NOT have was any way to
13
- * answer "who is running aegiscode right now, which app, which build, how many
14
- * machines?" — a user sitting in a session but not making model calls was
15
- * invisible. `heartbeat_v1()` in aegis1/app.py closes that gap by writing a
16
- * `client_presence` row keyed on (user_id, app, install), and this module is
17
- * the beacon that feeds it. Same for both hosts: the CLI's `aegiscode` binary
18
- * and the desktop's main process require this one file.
19
- *
20
- * THE SERVER CONTRACT (aegis1/app.py `heartbeat_v1`, do not change one side
21
- * without the other):
22
- *
23
- * POST /api/v1/heartbeat X-API-Key: <the user's aegis key>
24
- * {"app": "desktop", "version": "0.8.12", "platform": "linux",
25
- * "install": "9f3c1a2b4d5e6f70", "queue": 2, "autonomous": false}
26
- * -> 200 {"ok": true, "online": true, "seen_at": ..., "beat_interval_s": 300}
27
- *
28
- * Auth is the ordinary `@login_required`, which already accepts X-API-Key or
29
- * Bearer — the same key every host signs in with. So the beacon introduces NO
30
- * second credential and no new client secret, and a host with no key has
31
- * nothing to beacon AT: `apiKey` absent means this module is inert by
32
- * construction (see `disabledPresence()`), never a 401 loop.
33
- *
34
- * `install` IS THE FINGERPRINT. Not a second identifier invented here: it is
35
- * `machineFingerprint()` from ./device-fingerprint.js, the same SHA-256 the
36
- * device-registration path uses. That is deliberate and it is the property the
37
- * admin panel needs — "how many machines does this user run" has to count
38
- * machines, so the beacon must carry the machine's identity, not a random
39
- * per-run token that would make one laptop look like fifty. It is a 64-char
40
- * lowercase hex digest and aegis1's `_presence_token(install, 64)` accepts
41
- * exactly that width. Note what this does and does not imply: it is a stable
42
- * pseudonym for a machine, so a user's own rows join up; it is NOT a
43
- * cross-account tracking device and the server never sees the raw machine id it
44
- * was derived from.
45
- *
46
- * FOUR PROPERTIES, in order of importance — the same discipline
47
- * `lib/local/telemetry.js` is built around, for the same reason:
48
- *
49
- * 1. It cannot break the host. `beat()` returns a boolean and NEVER throws,
50
- * whatever the network, the DNS, the JSON, or an injected `fetch` does.
51
- * A beacon that can take down a CLI session or an Electron main process
52
- * is worse than no beacon at all.
53
- * 2. It cannot leak. The request body is rebuilt field by field from the
54
- * arguments — never spread, never `JSON.stringify(callerObject)` — and
55
- * only `app`, `version`, `platform`, `install`, `queue`, `autonomous` can
56
- * ever be sent. No conversation content, no file paths, no model output,
57
- * no email, no prompt text. `sane()` additionally truncates each field to
58
- * the same width the server enforces, so a caller cannot smuggle a blob
59
- * through a field this module owns.
60
- * 3. It cannot keep the process alive. The timer is `unref()`d, so `stop()`
61
- * is a convenience, not a requirement: an interrupted CLI exits on time
62
- * even if nobody ever calls it, and the desktop's quit path does not have
63
- * to thread a handle through.
64
- * 4. It cannot hammer. The cadence is the SERVER's (`beat_interval_s` in the
65
- * response), so the beacon can be slowed or sped up without shipping a
66
- * client release; failures back off exponentially instead of retrying on
67
- * the same rhythm, which is what turns a dead endpoint from a client
68
- * problem into a server problem.
69
- *
70
- * Nothing in this file may import Electron: it is plain Node so the CLI, the
71
- * desktop main process and the tests can all drive the same code. Each host
72
- * injects its own `app` name, version, platform and queue depth.
73
- */
74
-
75
- const {
76
- PRESENCE_PATH,
77
- DEFAULT_INTERVAL_MS,
78
- MIN_INTERVAL_MS,
79
- MAX_INTERVAL_MS,
80
- BACKOFF_FACTOR,
81
- MAX_BACKOFF_MS,
82
- REQUEST_TIMEOUT_MS,
83
- APP_NAMES,
84
- saneToken,
85
- saneCount,
86
- } = require('./presence-constants.js');
87
-
88
- const DEFAULT_API_BASE = 'https://aegiscloud.org';
89
-
90
- /**
91
- * The store returned when there is nothing to beacon (no key, or a host that
92
- * explicitly opted out). Every method answers, nothing happens, no timer is
93
- * created and no request is made: `enabled` is false and `beat()` is a no-op
94
- * that reports `false`. Checked by test/presence.test.mjs.
95
- */
96
- function disabledPresence(reason) {
97
- const state = {
98
- enabled: false,
99
- reason: String(reason || 'disabled'),
100
- beats: 0,
101
- failures: 0,
102
- lastError: null,
103
- lastSeenAt: null,
104
- intervalMs: null,
105
- install: null,
106
- app: null,
107
- running: false,
108
- };
109
- return {
110
- enabled: false,
111
- reason: state.reason,
112
- install: null,
113
- beat: () => Promise.resolve(false),
114
- start: () => false,
115
- stop: () => false,
116
- state: () => ({ ...state }),
117
- };
118
- }
119
-
120
- /** One ISO-8601 UTC string, or null. Never throws on a hostile clock. */
121
- function isoOf(ms) {
122
- try {
123
- const n = Number(ms);
124
- if (!Number.isFinite(n)) return null;
125
- return new Date(n).toISOString();
126
- } catch {
127
- return null;
128
- }
129
- }
130
-
131
- /**
132
- * @param {object} opts
133
- * @param {string} [opts.apiKey] the aegis key; absent ⇒ inert
134
- * @param {string} [opts.baseUrl] defaults to https://aegiscloud.org
135
- * @param {string} [opts.app] 'desktop' | 'cli' | ... (see APP_NAMES)
136
- * @param {string} [opts.version] the host's own build string
137
- * @param {string} [opts.platform] process.platform
138
- * @param {string} [opts.install] machine fingerprint (default: computed)
139
- * @param {number|function} [opts.queueDepth] pending queue tasks (may be a fn)
140
- * @param {boolean|function} [opts.autonomous] a drain is running (may be a fn)
141
- * @param {number} [opts.intervalMs] initial cadence before the server answers
142
- * @param {boolean} [opts.enabled] explicit kill switch (default true)
143
- * @param {string} [opts.clientVersion] X-AEGIS-Version header (version gate)
144
- * @param {function} [opts.fetchImpl] fetch override (tests)
145
- * @param {function} [opts.now] clock override (tests)
146
- * @param {function} [opts.log] (level, message, err) => void
147
- * @param {function} [opts.setTimer] setTimeout override (tests)
148
- * @param {function} [opts.clearTimer] clearTimeout override (tests)
149
- */
150
- function createPresence(opts = {}) {
151
- const apiKey = typeof opts.apiKey === 'string' ? opts.apiKey.trim() : '';
152
- if (!apiKey) return disabledPresence('no-api-key');
153
- if (opts.enabled === false) return disabledPresence('disabled');
154
-
155
- const log = typeof opts.log === 'function' ? opts.log : () => {};
156
- // A logger that throws is not allowed to matter — same rule as telemetry.js.
157
- function debugOnce(kind) {
158
- if (logged.has(kind)) return;
159
- logged.add(kind);
160
- try {
161
- log('debug', `presence: ${kind}`);
162
- } catch {
163
- /* a broken logger is not an error path */
164
- }
165
- }
166
- const logged = new Set();
167
-
168
- const now = typeof opts.now === 'function' ? opts.now : () => Date.now();
169
- const setTimer = typeof opts.setTimer === 'function' ? opts.setTimer : setTimeout;
170
- const clearTimer = typeof opts.clearTimer === 'function' ? opts.clearTimer : clearTimeout;
171
-
172
- // The fingerprint. Required lazily so a host that never beacons (the tests
173
- // for the other modules) does not touch the filesystem at require time.
174
- //
175
- // An injected `fingerprint` is an IDENTITY SOURCE, not a first choice: when a
176
- // host hands one in, that is the machine's identity and the built-in ladder
177
- // is not consulted. That matters for the packaged hosts, which resolve the
178
- // fingerprint once at their own call site (cli/src/presence.js, desktop
179
- // main.js) and must be able to fail loudly if it cannot — a silent fallback
180
- // here would hide a broken identity by substituting a different one, and the
181
- // panel would count the same laptop as two machines.
182
- let install = saneToken(opts.install, 64);
183
- if (!install && typeof opts.fingerprint === 'function') {
184
- try {
185
- install = saneToken(opts.fingerprint(), 64);
186
- } catch {
187
- debugOnce('fingerprint');
188
- }
189
- } else if (!install) {
190
- try {
191
- install = saneToken(require('./device-fingerprint.js').machineFingerprint(), 64);
192
- } catch {
193
- debugOnce('fingerprint');
194
- }
195
- }
196
- if (!install) {
197
- // No machine identity could be resolved at all (an exotic sandbox). A
198
- // beacon without an install key would write a NEW presence row on every
199
- // beat — one user, infinite machines in the panel. Better to stay out of
200
- // the table than to poison it: see device-fingerprint.js for the ladder
201
- // (machine id -> persisted install id -> hostname) that makes this rare.
202
- return disabledPresence('no-install-identity');
203
- }
204
-
205
- const app = saneToken(opts.app, 24).toLowerCase() || 'other';
206
- const version = saneToken(opts.version, 32);
207
- const rawPlatform = saneToken(opts.platform, 16).toLowerCase();
208
- const platform = rawPlatform || (typeof process !== 'undefined' && process.platform ? process.platform : '');
209
- const baseUrl = String(opts.baseUrl || (typeof process !== 'undefined' && process.env && process.env.AEGIS_API_BASE) || DEFAULT_API_BASE).replace(/\/+$/, '');
210
- const path = PRESENCE_PATH;
211
- const fetchImpl =
212
- typeof opts.fetchImpl === 'function'
213
- ? opts.fetchImpl
214
- : typeof fetch === 'function'
215
- ? fetch
216
- : null;
217
-
218
- /** A caller passing a function is asking to be read at send time, so the
219
- * beacon reports the LIVE queue depth rather than the depth at boot. */
220
- function readDynamic(value, fallback) {
221
- try {
222
- return typeof value === 'function' ? value() : value;
223
- } catch {
224
- return fallback;
225
- }
226
- }
227
-
228
- let intervalMs = clampInterval(opts.intervalMs);
229
- const state = {
230
- enabled: true,
231
- reason: null,
232
- beats: 0,
233
- failures: 0,
234
- lastError: null,
235
- lastSeenAt: null,
236
- intervalMs,
237
- install,
238
- app,
239
- version: version || null,
240
- platform: platform || null,
241
- running: false,
242
- };
243
-
244
- let timer = null;
245
- let inflight = null;
246
- let backoffMs = 0;
247
- let stopped = false;
248
-
249
- function clampInterval(ms) {
250
- const n = Number(ms);
251
- if (!Number.isFinite(n) || n <= 0) return DEFAULT_INTERVAL_MS;
252
- return Math.min(MAX_INTERVAL_MS, Math.max(MIN_INTERVAL_MS, Math.floor(n)));
253
- }
254
-
255
- /** The ONLY body shape this module can ever send. Field by field, on purpose. */
256
- function body() {
257
- return {
258
- app,
259
- version: version || undefined,
260
- platform: platform || undefined,
261
- install,
262
- queue: saneCount(readDynamic(opts.queueDepth, 0)),
263
- autonomous: Boolean(readDynamic(opts.autonomous, false)),
264
- };
265
- }
266
-
267
- /**
268
- * Send one beat. Resolves `true` when the server acknowledged, `false` on
269
- * every other outcome — no key, offline, DNS failure, 500, a malformed body,
270
- * an aborted request. It never rejects, so a caller may `void beat()` without
271
- * an unhandled-rejection guard, and a concurrent call while one is in flight
272
- * is answered by the in-flight promise rather than by a second request (two
273
- * beacons racing would double-count `beats` on the server).
274
- */
275
- function beat() {
276
- if (stopped) return Promise.resolve(false);
277
- if (inflight) return inflight;
278
- if (!fetchImpl) {
279
- debugOnce('no-fetch');
280
- state.lastError = 'no fetch implementation';
281
- state.failures += 1;
282
- return Promise.resolve(false);
283
- }
284
-
285
- const startedAt = now();
286
- inflight = (async () => {
287
- let timedOut = false;
288
- let cancel = null;
289
- try {
290
- const controller = typeof AbortController === 'function' ? new AbortController() : null;
291
- if (controller) {
292
- const t = setTimer(() => {
293
- timedOut = true;
294
- try {
295
- controller.abort();
296
- } catch {
297
- /* already gone */
298
- }
299
- }, REQUEST_TIMEOUT_MS);
300
- if (t && typeof t.unref === 'function') t.unref();
301
- cancel = () => clearTimer(t);
302
- }
303
-
304
- const res = await fetchImpl(`${baseUrl}${path}`, {
305
- method: 'POST',
306
- headers: {
307
- 'Content-Type': 'application/json',
308
- 'X-API-Key': apiKey,
309
- 'X-AEGIS-Version': saneToken(opts.clientVersion, 32) || version || '',
310
- },
311
- body: JSON.stringify(body()),
312
- ...(controller ? { signal: controller.signal } : {}),
313
- });
314
- if (cancel) cancel();
315
-
316
- // `ok` on the response, not `res.ok === true` semantics: a 404 (server
317
- // predates the route) and a 401 (key revoked) are both just "not this
318
- // time" — the beacon must not retry storm either of them.
319
- if (!res || typeof res.status !== 'number' || res.status < 200 || res.status >= 300) {
320
- state.failures += 1;
321
- state.lastError = `http ${res && res.status ? res.status : 'error'}`;
322
- backoffMs = nextBackoff(backoffMs);
323
- return false;
324
- }
325
-
326
- let data = null;
327
- try {
328
- data = await res.json();
329
- } catch {
330
- // A 200 with an unreadable body is still a successful beat: the
331
- // server wrote the row before it serialised the answer. Only the
332
- // cadence hint is lost, and the current one stays in force.
333
- data = null;
334
- }
335
-
336
- state.beats += 1;
337
- state.failures = 0;
338
- state.lastError = null;
339
- state.lastSeenAt = isoOf(now());
340
- backoffMs = 0;
341
- // The server owns the cadence. An unrecognised/hostile value is clamped
342
- // rather than trusted: a `beat_interval_s` of 0 would be a hot loop.
343
- if (data && typeof data === 'object' && data.beat_interval_s != null) {
344
- const secs = Number(data.beat_interval_s);
345
- if (Number.isFinite(secs) && secs > 0) intervalMs = clampInterval(secs * 1000);
346
- }
347
- state.intervalMs = intervalMs;
348
- return true;
349
- } catch (err) {
350
- if (cancel) cancel();
351
- state.failures += 1;
352
- state.lastError = timedOut ? 'timeout' : String((err && err.message) || err || 'error').slice(0, 200);
353
- backoffMs = nextBackoff(backoffMs);
354
- if (state.failures === 1) debugOnce('beat-failed'); // once, then quiet
355
- return false;
356
- } finally {
357
- inflight = null;
358
- if (state.running) schedule(Math.max(0, intervalMs + backoffMs - (now() - startedAt)));
359
- }
360
- })();
361
-
362
- return inflight;
363
- }
364
-
365
- function nextBackoff(current) {
366
- const base = current > 0 ? current * BACKOFF_FACTOR : Math.max(MIN_INTERVAL_MS, intervalMs);
367
- return Math.min(MAX_BACKOFF_MS, Math.floor(base));
368
- }
369
-
370
- /** One timer at a time, always unref'd, always cleared before replacing. */
371
- function schedule(delayMs) {
372
- if (stopped || typeof setTimer !== 'function') return;
373
- if (timer) clearTimer(timer);
374
- const delay = Math.max(1000, Math.floor(Number(delayMs) || intervalMs));
375
- timer = setTimer(() => {
376
- timer = null;
377
- void beat();
378
- }, delay);
379
- if (timer && typeof timer.unref === 'function') timer.unref();
380
- }
381
-
382
- /**
383
- * Start beaconing and send the FIRST beat immediately. A host that is opened
384
- * and closed in under a minute still registers — waiting one full interval
385
- * before the first beat would make the panel blind to exactly the short
386
- * sessions the route was added for.
387
- */
388
- function start() {
389
- if (stopped) return false;
390
- state.running = true;
391
- void beat();
392
- return true;
393
- }
394
-
395
- /** Stop beaconing. Idempotent, and safe to call when start() never ran. */
396
- function stop() {
397
- stopped = true;
398
- state.running = false;
399
- if (timer) {
400
- try {
401
- clearTimer(timer);
402
- } catch {
403
- /* a timer that already fired is not an error */
404
- }
405
- timer = null;
406
- }
407
- return true;
408
- }
409
-
410
- return {
411
- enabled: true,
412
- app,
413
- install,
414
- beat,
415
- start,
416
- stop,
417
- /**
418
- * The in-flight beat, or null. Exposed for one reason: a SHORT-LIVED host
419
- * (`aegiscode -p "…"`, `aegiscode autonomous run`) finishes its work in
420
- * well under a second and calls `process.exit()`, which kills an in-flight
421
- * request and loses the beat entirely — the machine is silently absent from
422
- * the panel even though it just ran. The CLI awaits this before exiting
423
- * (see `flush()` in cli/src/presence.js). A long-lived host can ignore it.
424
- */
425
- pending: () => inflight,
426
- state: () => ({ ...state, intervalMs }),
427
- };
428
- }
429
-
430
- module.exports = {
431
- createPresence,
432
- disabledPresence,
433
- PRESENCE_PATH,
434
- DEFAULT_INTERVAL_MS,
435
- MIN_INTERVAL_MS,
436
- MAX_INTERVAL_MS,
437
- MAX_BACKOFF_MS,
438
- REQUEST_TIMEOUT_MS,
439
- APP_NAMES,
440
- };
3
+ "use strict";const{PRESENCE_PATH:PRESENCE_PATH,DEFAULT_INTERVAL_MS:DEFAULT_INTERVAL_MS,MIN_INTERVAL_MS:MIN_INTERVAL_MS,MAX_INTERVAL_MS:MAX_INTERVAL_MS,BACKOFF_FACTOR:BACKOFF_FACTOR,MAX_BACKOFF_MS:MAX_BACKOFF_MS,REQUEST_TIMEOUT_MS:REQUEST_TIMEOUT_MS,APP_NAMES:APP_NAMES,saneToken:saneToken,saneCount:saneCount}=require("./presence-constants.js"),DEFAULT_API_BASE="https://aegiscloud.org";function disabledPresence(e){const n={enabled:!1,reason:String(e||"disabled"),beats:0,failures:0,lastError:null,lastSeenAt:null,intervalMs:null,install:null,app:null,running:!1};return{enabled:!1,reason:n.reason,install:null,beat:()=>Promise.resolve(!1),start:()=>!1,stop:()=>!1,state:()=>({...n})}}function isoOf(e){try{const n=Number(e);return Number.isFinite(n)?new Date(n).toISOString():null}catch{return null}}function createPresence(e={}){const n="string"==typeof e.apiKey?e.apiKey.trim():"";if(!n)return disabledPresence("no-api-key");if(!1===e.enabled)return disabledPresence("disabled");const t="function"==typeof e.log?e.log:()=>{};function r(e){if(!o.has(e)){o.add(e);try{t("debug",`presence: ${e}`)}catch{}}}const o=new Set,s="function"==typeof e.now?e.now:()=>Date.now(),i="function"==typeof e.setTimer?e.setTimer:setTimeout,a="function"==typeof e.clearTimer?e.clearTimer:clearTimeout;let l=saneToken(e.install,64);if(l||"function"!=typeof e.fingerprint){if(!l)try{l=saneToken(require("./device-fingerprint.js").machineFingerprint(),64)}catch{r("fingerprint")}}else try{l=saneToken(e.fingerprint(),64)}catch{r("fingerprint")}if(!l)return disabledPresence("no-install-identity");const u=saneToken(e.app,24).toLowerCase()||"other",c=saneToken(e.version,32),f=saneToken(e.platform,16).toLowerCase()||("undefined"!=typeof process&&process.platform?process.platform:""),_=String(e.baseUrl||"undefined"!=typeof process&&process.env&&process.env.AEGIS_API_BASE||DEFAULT_API_BASE).replace(/\/+$/,""),A=PRESENCE_PATH,E="function"==typeof e.fetchImpl?e.fetchImpl:"function"==typeof fetch?fetch:null;function M(e,n){try{return"function"==typeof e?e():e}catch{return n}}let p=b(e.intervalMs);const T={enabled:!0,reason:null,beats:0,failures:0,lastError:null,lastSeenAt:null,intervalMs:p,install:l,app:u,version:c||null,platform:f||null,running:!1};let S=null,m=null,d=0,N=!1;function b(e){const n=Number(e);return!Number.isFinite(n)||n<=0?DEFAULT_INTERVAL_MS:Math.min(MAX_INTERVAL_MS,Math.max(MIN_INTERVAL_MS,Math.floor(n)))}function y(){if(N)return Promise.resolve(!1);if(m)return m;if(!E)return r("no-fetch"),T.lastError="no fetch implementation",T.failures+=1,Promise.resolve(!1);const t=s();return m=(async()=>{let o=!1,P=null;try{const t="function"==typeof AbortController?new AbortController:null;if(t){const e=i((()=>{o=!0;try{t.abort()}catch{}}),REQUEST_TIMEOUT_MS);e&&"function"==typeof e.unref&&e.unref(),P=()=>a(e)}const r=await E(`${_}${A}`,{method:"POST",headers:{"Content-Type":"application/json","X-API-Key":n,"X-AEGIS-Version":saneToken(e.clientVersion,32)||c||""},body:JSON.stringify({app:u,version:c||void 0,platform:f||void 0,install:l,queue:saneCount(M(e.queueDepth,0)),autonomous:Boolean(M(e.autonomous,!1))}),...t?{signal:t.signal}:{}});if(P&&P(),!r||"number"!=typeof r.status||r.status<200||r.status>=300)return T.failures+=1,T.lastError=`http ${r&&r.status?r.status:"error"}`,d=I(d),!1;let S=null;try{S=await r.json()}catch{S=null}if(T.beats+=1,T.failures=0,T.lastError=null,T.lastSeenAt=isoOf(s()),d=0,S&&"object"==typeof S&&null!=S.beat_interval_s){const e=Number(S.beat_interval_s);Number.isFinite(e)&&e>0&&(p=b(1e3*e))}return T.intervalMs=p,!0}catch(e){return P&&P(),T.failures+=1,T.lastError=o?"timeout":String(e&&e.message||e||"error").slice(0,200),d=I(d),1===T.failures&&r("beat-failed"),!1}finally{m=null,T.running&&function(e){if(N||"function"!=typeof i)return;S&&a(S);const n=Math.max(1e3,Math.floor(Number(e)||p));S=i((()=>{S=null,y()}),n),S&&"function"==typeof S.unref&&S.unref()}(Math.max(0,p+d-(s()-t)))}})(),m}function I(e){const n=e>0?e*BACKOFF_FACTOR:Math.max(MIN_INTERVAL_MS,p);return Math.min(MAX_BACKOFF_MS,Math.floor(n))}return{enabled:!0,app:u,install:l,beat:y,start:function(){return!N&&(T.running=!0,y(),!0)},stop:function(){if(N=!0,T.running=!1,S){try{a(S)}catch{}S=null}return!0},pending:()=>m,state:()=>({...T,intervalMs:p})}}module.exports={createPresence:createPresence,disabledPresence:disabledPresence,PRESENCE_PATH:PRESENCE_PATH,DEFAULT_INTERVAL_MS:DEFAULT_INTERVAL_MS,MIN_INTERVAL_MS:MIN_INTERVAL_MS,MAX_INTERVAL_MS:MAX_INTERVAL_MS,MAX_BACKOFF_MS:MAX_BACKOFF_MS,REQUEST_TIMEOUT_MS:REQUEST_TIMEOUT_MS,APP_NAMES:APP_NAMES};