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,112 +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
- * drive-connect.js — the desktop half of aegis1's Google Drive OAuth.
10
- *
11
- * aegis1 already runs the full web side of this: `/connect/drive` sends the
12
- * browser through Google's consent screen with the `drive.file` scope, saves
13
- * the resulting tokens on whichever account that Google identity resolves
14
- * to, and lands on a static "connected" page. `/api/drive/token` then hands
15
- * back a fresh (server-refreshed) access token for that account, authenticated
16
- * with the ordinary AEGIS API key — see `client/aegis.js`'s `driveToken()`.
17
- *
18
- * Unlike `/auth/google` (see `client/google-signin.js`), `/connect/drive` has
19
- * no desktop round-trip: it never redirects back to a local callback, so
20
- * there is nothing here to listen for. This module does the other honest
21
- * thing instead — open the browser to it, and POLL the status endpoint
22
- * (this machine's own API key) until the account shows connected, or give up
23
- * after a timeout. The caller provides the actual browser-opening (Electron's
24
- * `shell.openExternal`); this module is Electron-free so it can be driven by
25
- * a test with a stub `aegis` client and no network.
26
- *
27
- * ONE PRECONDITION THIS MODULE DOES NOT ENFORCE, BECAUSE IT CANNOT:
28
- * `/connect/drive` resolves the account by Google identity (google_id, then
29
- * email), not by whatever account this machine's API key already belongs to.
30
- * So polling only ever reports connected when THIS machine is already signed
31
- * in with that same Google identity — otherwise the browser attaches the
32
- * Drive tokens to a different account than the one being polled, and the
33
- * poll simply times out. `desktop/lib/google-connect.js` is what sequences
34
- * "sign in with Google first" ahead of this.
35
- */
36
-
37
- /** `${apiBase}/connect/drive` — the one URL this flow opens. */
38
- function driveConnectUrl(apiBase) {
39
- return `${String(apiBase || '').replace(/\/+$/, '')}/connect/drive`;
40
- }
41
-
42
- /**
43
- * One status check: is a Drive token on file for this account, and is the
44
- * account tied to a Google identity at all?
45
- *
46
- * `googleLinked` comes from the server (`/api/drive/token`'s `google_linked`,
47
- * derived from `users.google_id`) and is NOT the same question as "does this
48
- * machine have an API key". Every install auto-provisions an anonymous device
49
- * key, so a key always exists while the account behind it may never have
50
- * touched Google. Connecting Drive in that state attaches the tokens to
51
- * whatever Google account the browser happens to hold — a different account
52
- * than the one this machine polls — and the poll just times out. Callers need
53
- * this flag to refuse that ordering.
54
- *
55
- * Older servers answer `google_linked` not at all; a connected account is
56
- * proof enough (only a Google round-trip can store those tokens), so a
57
- * missing flag next to a live token reads as linked rather than as a
58
- * regression that would disable the button for everyone.
59
- *
60
- * @param {{driveToken: () => Promise<{connected:boolean, email?:string, google_linked?:boolean}>}} aegis
61
- */
62
- async function driveStatus(aegis) {
63
- const data = await aegis.driveToken();
64
- const connected = Boolean(data && data.connected);
65
- const raw = data && data.google_linked;
66
- // Did the server actually answer the question? A server that predates the
67
- // field omits it entirely, and an account with no Drive token answers 404
68
- // with no flag — both look exactly like an explicit `false` once collapsed
69
- // to a boolean. Callers that must not block a real sign-in need to tell
70
- // "not linked" apart from "nobody asked the server".
71
- const known = typeof raw === 'boolean';
72
- return {
73
- connected,
74
- googleLinked: connected || raw === true,
75
- googleLinkedKnown: known || connected,
76
- email: (data && data.email) || null,
77
- };
78
- }
79
-
80
- /**
81
- * Poll `driveStatus` until it reports connected, or time out.
82
- *
83
- * The browser round-trip has no signal of its own to wait on (unlike
84
- * `startGoogleSignIn`'s local callback server), so this is the only way the
85
- * caller learns the user actually finished the consent screen — or gave up
86
- * on it, which is why this is bounded rather than polled forever.
87
- *
88
- * @param {object} aegis a client exposing `driveToken()`
89
- * @param {{timeoutMs?:number, pollMs?:number, signal?:AbortSignal}} [opts]
90
- */
91
- async function waitForDriveConnected(aegis, opts = {}) {
92
- const timeoutMs = Number(opts.timeoutMs) > 0 ? Number(opts.timeoutMs) : 3 * 60 * 1000;
93
- const pollMs = Number(opts.pollMs) > 0 ? Number(opts.pollMs) : 2000;
94
- const signal = opts.signal || null;
95
- const deadline = Date.now() + timeoutMs;
96
-
97
- for (;;) {
98
- const status = await driveStatus(aegis);
99
- if (status.connected) return status;
100
- if (signal && signal.aborted) {
101
- const e = new Error('cancelled');
102
- e.name = 'AbortError';
103
- throw e;
104
- }
105
- if (Date.now() >= deadline) {
106
- throw new Error(`timed out after ${Math.round(timeoutMs / 1000)}s waiting for Google Drive to connect`);
107
- }
108
- await new Promise((resolve) => setTimeout(resolve, pollMs));
109
- }
110
- }
111
-
112
- module.exports = { driveConnectUrl, driveStatus, waitForDriveConnected };
3
+ "use strict";function driveConnectUrl(e){return`${String(e||"").replace(/\/+$/,"")}/connect/drive`}async function driveStatus(e){const n=await e.driveToken(),o=Boolean(n&&n.connected),t=n&&n.google_linked;return{connected:o,googleLinked:o||!0===t,googleLinkedKnown:"boolean"==typeof t||o,email:n&&n.email||null}}async function waitForDriveConnected(e,n={}){const o=Number(n.timeoutMs)>0?Number(n.timeoutMs):18e4,t=Number(n.pollMs)>0?Number(n.pollMs):2e3,r=n.signal||null,i=Date.now()+o;for(;;){const n=await driveStatus(e);if(n.connected)return n;if(r&&r.aborted){const e=new Error("cancelled");throw e.name="AbortError",e}if(Date.now()>=i)throw new Error(`timed out after ${Math.round(o/1e3)}s waiting for Google Drive to connect`);await new Promise((e=>setTimeout(e,t)))}}module.exports={driveConnectUrl:driveConnectUrl,driveStatus:driveStatus,waitForDriveConnected:waitForDriveConnected};
@@ -1,236 +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
- * drive-upload.js — a Drive v3 REST client, scoped to exactly one job:
10
- * keep a single memory-backup file, in a single app folder, up to date.
11
- *
12
- * This talks to Google's API directly with the access token
13
- * `client/drive-connect.js` obtains (via `/api/drive/token`) — it never goes
14
- * through aegis1, and aegis1 never sees the memory content this uploads.
15
- *
16
- * Scoped to `drive.file` (the scope `/connect/drive` requests): that grant
17
- * only ever sees files this app itself creates, which is why every write
18
- * here goes through `findOrCreateFolder`/`findFileInFolder` rather than
19
- * assuming some well-known id — there is no well-known id this scope could
20
- * resolve, and a file this app did not create is invisible to it even by
21
- * name. One stable file is overwritten in place on every sync rather than
22
- * creating a new one each time, so a daily backup habit does not pile up a
23
- * thousand same-named files with no way to tell them apart.
24
- */
25
-
26
- const DRIVE_FILES_URL = 'https://www.googleapis.com/drive/v3/files';
27
- const DRIVE_UPLOAD_URL = 'https://www.googleapis.com/upload/drive/v3/files';
28
- const FOLDER_MIME = 'application/vnd.google-apps.folder';
29
- const BOUNDARY = 'aegiscode-drive-upload-boundary';
30
-
31
- const DEFAULT_FOLDER = 'AEGIS Memory';
32
- const DEFAULT_FILE = 'aegis-memory-backup.json';
33
- /** Conversations get their own subfolder so a saved chat never sits among the
34
- * rolling memory files, and never collides with them by name. */
35
- const DEFAULT_CONVERSATIONS_FOLDER = 'conversations';
36
-
37
- function resolveFetch(fetchImpl) {
38
- const f = fetchImpl || (typeof fetch === 'function' ? fetch : null);
39
- if (!f) throw new Error('drive: this Node has no global fetch — upgrade to Node 22+');
40
- return f;
41
- }
42
-
43
- /** Escape a value for Drive's `q=` string-literal quoting rules. */
44
- function escapeQ(value) {
45
- return String(value).replace(/\\/g, '\\\\').replace(/'/g, "\\'");
46
- }
47
-
48
- async function driveRequest(fetchImpl, url, { method = 'GET', accessToken, body, headers } = {}) {
49
- const f = resolveFetch(fetchImpl);
50
- const res = await f(url, {
51
- method,
52
- headers: { Authorization: `Bearer ${accessToken}`, ...(headers || {}) },
53
- body,
54
- });
55
- const text = await res.text();
56
- let data = null;
57
- try {
58
- data = text ? JSON.parse(text) : null;
59
- } catch {
60
- data = null;
61
- }
62
- if (!res.ok) {
63
- const rawMsg = (data && data.error && (data.error.message || data.error)) || text.slice(0, 200) || `HTTP ${res.status}`;
64
- const err = new Error(`drive: ${method} ${url.split('?')[0]} failed — ${typeof rawMsg === 'string' ? rawMsg : JSON.stringify(rawMsg)}`);
65
- err.status = res.status;
66
- err.data = data;
67
- throw err;
68
- }
69
- return data || {};
70
- }
71
-
72
- /** The first file matching an exact query, or null. */
73
- async function findOne(fetchImpl, accessToken, query) {
74
- const url = `${DRIVE_FILES_URL}?q=${encodeURIComponent(query)}&fields=${encodeURIComponent('files(id,name)')}&pageSize=1`;
75
- const data = await driveRequest(fetchImpl, url, { accessToken });
76
- const files = Array.isArray(data.files) ? data.files : [];
77
- return files[0] || null;
78
- }
79
-
80
- /**
81
- * This app's folder by name, creating it the first time. Returns its id.
82
- *
83
- * `parentId`, when given, scopes BOTH the search and the create, so a subfolder
84
- * is never confused with a same-named folder at the Drive root — without it,
85
- * `conversations/` would match some unrelated folder of that name if the user
86
- * ever made one.
87
- */
88
- async function findOrCreateFolder(accessToken, name, { fetchImpl, parentId = null } = {}) {
89
- const parentClause = parentId ? `'${escapeQ(parentId)}' in parents and ` : '';
90
- const query = `${parentClause}mimeType='${FOLDER_MIME}' and name='${escapeQ(name)}' and trashed=false`;
91
- const existing = await findOne(fetchImpl, accessToken, query);
92
- if (existing) return existing.id;
93
- const metadata = { name, mimeType: FOLDER_MIME };
94
- if (parentId) metadata.parents = [parentId];
95
- const created = await driveRequest(fetchImpl, DRIVE_FILES_URL, {
96
- method: 'POST',
97
- accessToken,
98
- headers: { 'Content-Type': 'application/json' },
99
- body: JSON.stringify(metadata),
100
- });
101
- return created.id;
102
- }
103
-
104
- /** One file by name inside a given folder, or null. */
105
- async function findFileInFolder(accessToken, name, folderId, { fetchImpl } = {}) {
106
- const query = `'${escapeQ(folderId)}' in parents and name='${escapeQ(name)}' and trashed=false`;
107
- return findOne(fetchImpl, accessToken, query);
108
- }
109
-
110
- /**
111
- * Create a new file: a multipart/related body (metadata part naming the
112
- * parent folder, content part carrying the bytes) — the shape Drive's
113
- * `uploadType=multipart` requires for a create, since a plain media upload
114
- * has nowhere to say which folder the file belongs in.
115
- */
116
- async function createFile(accessToken, { name, folderId, content, mimeType }, { fetchImpl } = {}) {
117
- const metadata = JSON.stringify({ name, parents: [folderId] });
118
- const body =
119
- `--${BOUNDARY}\r\n` +
120
- `Content-Type: application/json; charset=UTF-8\r\n\r\n${metadata}\r\n` +
121
- `--${BOUNDARY}\r\n` +
122
- `Content-Type: ${mimeType}\r\n\r\n${content}\r\n` +
123
- `--${BOUNDARY}--`;
124
- return driveRequest(
125
- fetchImpl,
126
- `${DRIVE_UPLOAD_URL}?uploadType=multipart&fields=${encodeURIComponent('id,webViewLink')}`,
127
- {
128
- method: 'POST',
129
- accessToken,
130
- headers: { 'Content-Type': `multipart/related; boundary=${BOUNDARY}` },
131
- body,
132
- }
133
- );
134
- }
135
-
136
- /**
137
- * Overwrite an existing file's content in place. A plain media upload is
138
- * enough here — the name and parent folder never change on a resync, so
139
- * there is nothing a metadata part would need to say.
140
- */
141
- async function updateFileContent(accessToken, fileId, content, mimeType, { fetchImpl } = {}) {
142
- return driveRequest(
143
- fetchImpl,
144
- `${DRIVE_UPLOAD_URL}/${encodeURIComponent(fileId)}?uploadType=media&fields=${encodeURIComponent('id,webViewLink')}`,
145
- {
146
- method: 'PATCH',
147
- accessToken,
148
- headers: { 'Content-Type': mimeType },
149
- body: content,
150
- }
151
- );
152
- }
153
-
154
- /**
155
- * Upload (create or overwrite) one memory backup file in the user's Drive.
156
- *
157
- * @param {string} accessToken a live Drive access token (client/drive-connect.js / aegis.driveToken())
158
- * @param {string} content the file's bytes — the caller serialises; this module never shapes the memory export itself
159
- * @param {{folderName?:string, fileName?:string, mimeType?:string, fetchImpl?:Function}} [opts]
160
- * @returns {Promise<{fileId:string, webViewLink:string|null, updated:boolean}>}
161
- */
162
- async function uploadMemoryBackup(accessToken, content, opts = {}) {
163
- const folderName = opts.folderName || DEFAULT_FOLDER;
164
- const fileName = opts.fileName || DEFAULT_FILE;
165
- const mimeType = opts.mimeType || 'application/json';
166
- const fetchImpl = opts.fetchImpl;
167
-
168
- const folderId = await findOrCreateFolder(accessToken, folderName, { fetchImpl });
169
- const existing = await findFileInFolder(accessToken, fileName, folderId, { fetchImpl });
170
- const result = existing
171
- ? await updateFileContent(accessToken, existing.id, content, mimeType, { fetchImpl })
172
- : await createFile(accessToken, { name: fileName, folderId, content, mimeType }, { fetchImpl });
173
-
174
- return {
175
- fileId: result.id || (existing && existing.id) || null,
176
- webViewLink: result.webViewLink || null,
177
- updated: Boolean(existing),
178
- };
179
- }
180
-
181
- /**
182
- * Save ONE conversation as a new `.md` file in `AEGIS Memory/conversations/`.
183
- *
184
- * Deliberately the opposite of `uploadMemoryBackup`: this NEVER overwrites.
185
- * A conversation is a thing that happened at a time; saving it twice should
186
- * leave two dated files, not silently replace the first. (The memory backup is
187
- * the other case exactly — one rolling file, updated in place, because it is a
188
- * current state rather than an event.)
189
- *
190
- * The content already carries its authorship header
191
- * (client/conversation-export.js) — this function moves bytes and decides where
192
- * they land; it never shapes what the file says about who wrote it.
193
- *
194
- * @param {string} accessToken a live Drive access token
195
- * @param {{name:string, content:string, folderName?:string, subfolder?:string,
196
- * mimeType?:string, fetchImpl?:Function}} opts
197
- * @returns {Promise<{fileId:string, webViewLink:string|null, created:true,
198
- * folder:string, path:string}>}
199
- */
200
- async function uploadConversation(accessToken, opts = {}) {
201
- const name = opts.name;
202
- const content = opts.content;
203
- if (!name) throw new Error('drive: uploadConversation needs a file name');
204
- if (typeof content !== 'string') throw new Error('drive: uploadConversation needs the file content as a string');
205
-
206
- const folderName = opts.folderName || DEFAULT_FOLDER;
207
- const subfolder = opts.subfolder === undefined ? DEFAULT_CONVERSATIONS_FOLDER : opts.subfolder;
208
- const mimeType = opts.mimeType || 'text/markdown';
209
- const fetchImpl = opts.fetchImpl;
210
-
211
- const rootId = await findOrCreateFolder(accessToken, folderName, { fetchImpl });
212
- const folderId = subfolder
213
- ? await findOrCreateFolder(accessToken, subfolder, { fetchImpl, parentId: rootId })
214
- : rootId;
215
-
216
- const result = await createFile(accessToken, { name, folderId, content, mimeType }, { fetchImpl });
217
- return {
218
- fileId: result.id || null,
219
- webViewLink: result.webViewLink || null,
220
- created: true,
221
- folder: subfolder ? `${folderName}/${subfolder}` : folderName,
222
- path: subfolder ? `${folderName}/${subfolder}/${name}` : `${folderName}/${name}`,
223
- };
224
- }
225
-
226
- module.exports = {
227
- DEFAULT_FOLDER,
228
- DEFAULT_FILE,
229
- DEFAULT_CONVERSATIONS_FOLDER,
230
- findOrCreateFolder,
231
- findFileInFolder,
232
- createFile,
233
- updateFileContent,
234
- uploadMemoryBackup,
235
- uploadConversation,
236
- };
3
+ "use strict";const DRIVE_FILES_URL="https://www.googleapis.com/drive/v3/files",DRIVE_UPLOAD_URL="https://www.googleapis.com/upload/drive/v3/files",FOLDER_MIME="application/vnd.google-apps.folder",BOUNDARY="aegiscode-drive-upload-boundary",DEFAULT_FOLDER="AEGIS Memory",DEFAULT_FILE="aegis-memory-backup.json",DEFAULT_CONVERSATIONS_FOLDER="conversations";function resolveFetch(e){const n=e||("function"==typeof fetch?fetch:null);if(!n)throw new Error("drive: this Node has no global fetch — upgrade to Node 22+");return n}function escapeQ(e){return String(e).replace(/\\/g,"\\\\").replace(/'/g,"\\'")}async function driveRequest(e,n,{method:t="GET",accessToken:o,body:r,headers:a}={}){const i=resolveFetch(e),d=await i(n,{method:t,headers:{Authorization:`Bearer ${o}`,...a||{}},body:r}),l=await d.text();let s=null;try{s=l?JSON.parse(l):null}catch{s=null}if(!d.ok){const e=s&&s.error&&(s.error.message||s.error)||l.slice(0,200)||`HTTP ${d.status}`,o=new Error(`drive: ${t} ${n.split("?")[0]} failed — ${"string"==typeof e?e:JSON.stringify(e)}`);throw o.status=d.status,o.data=s,o}return s||{}}async function findOne(e,n,t){const o=`${DRIVE_FILES_URL}?q=${encodeURIComponent(t)}&fields=${encodeURIComponent("files(id,name)")}&pageSize=1`,r=await driveRequest(e,o,{accessToken:n});return(Array.isArray(r.files)?r.files:[])[0]||null}async function findOrCreateFolder(e,n,{fetchImpl:t,parentId:o=null}={}){const r=`${o?`'${escapeQ(o)}' in parents and `:""}mimeType='${FOLDER_MIME}' and name='${escapeQ(n)}' and trashed=false`,a=await findOne(t,e,r);if(a)return a.id;const i={name:n,mimeType:FOLDER_MIME};return o&&(i.parents=[o]),(await driveRequest(t,DRIVE_FILES_URL,{method:"POST",accessToken:e,headers:{"Content-Type":"application/json"},body:JSON.stringify(i)})).id}async function findFileInFolder(e,n,t,{fetchImpl:o}={}){return findOne(o,e,`'${escapeQ(t)}' in parents and name='${escapeQ(n)}' and trashed=false`)}async function createFile(e,{name:n,folderId:t,content:o,mimeType:r},{fetchImpl:a}={}){const i=JSON.stringify({name:n,parents:[t]}),d=`--${BOUNDARY}\r\nContent-Type: application/json; charset=UTF-8\r\n\r\n${i}\r\n--${BOUNDARY}\r\nContent-Type: ${r}\r\n\r\n${o}\r\n--${BOUNDARY}--`;return driveRequest(a,`${DRIVE_UPLOAD_URL}?uploadType=multipart&fields=${encodeURIComponent("id,webViewLink")}`,{method:"POST",accessToken:e,headers:{"Content-Type":`multipart/related; boundary=${BOUNDARY}`},body:d})}async function updateFileContent(e,n,t,o,{fetchImpl:r}={}){return driveRequest(r,`${DRIVE_UPLOAD_URL}/${encodeURIComponent(n)}?uploadType=media&fields=${encodeURIComponent("id,webViewLink")}`,{method:"PATCH",accessToken:e,headers:{"Content-Type":o},body:t})}async function uploadMemoryBackup(e,n,t={}){const o=t.folderName||"AEGIS Memory",r=t.fileName||DEFAULT_FILE,a=t.mimeType||"application/json",i=t.fetchImpl,d=await findOrCreateFolder(e,o,{fetchImpl:i}),l=await findFileInFolder(e,r,d,{fetchImpl:i}),s=l?await updateFileContent(e,l.id,n,a,{fetchImpl:i}):await createFile(e,{name:r,folderId:d,content:n,mimeType:a},{fetchImpl:i});return{fileId:s.id||l&&l.id||null,webViewLink:s.webViewLink||null,updated:Boolean(l)}}async function uploadConversation(e,n={}){const t=n.name,o=n.content;if(!t)throw new Error("drive: uploadConversation needs a file name");if("string"!=typeof o)throw new Error("drive: uploadConversation needs the file content as a string");const r=n.folderName||"AEGIS Memory",a=void 0===n.subfolder?"conversations":n.subfolder,i=n.mimeType||"text/markdown",d=n.fetchImpl,l=await findOrCreateFolder(e,r,{fetchImpl:d}),s=a?await findOrCreateFolder(e,a,{fetchImpl:d,parentId:l}):l,c=await createFile(e,{name:t,folderId:s,content:o,mimeType:i},{fetchImpl:d});return{fileId:c.id||null,webViewLink:c.webViewLink||null,created:!0,folder:a?`${r}/${a}`:r,path:a?`${r}/${a}/${t}`:`${r}/${t}`}}module.exports={DEFAULT_FOLDER:"AEGIS Memory",DEFAULT_FILE:DEFAULT_FILE,DEFAULT_CONVERSATIONS_FOLDER:"conversations",findOrCreateFolder:findOrCreateFolder,findFileInFolder:findFileInFolder,createFile:createFile,updateFileContent:updateFileContent,uploadMemoryBackup:uploadMemoryBackup,uploadConversation:uploadConversation};