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,898 +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
- * Onboarding screens — trust check, theme picker, welcome.
10
- *
11
- * A direct port of the upstream engine reference, which is where the
12
- * reference's session actually begins: a genuine first run is
13
- *
14
- * showTrustCheck(ctx) → showThemePicker(ctx) → updateConfig() → welcome
15
- *
16
- * and every later run goes straight to the welcome box. The CLI had none of
17
- * this — `runInteractive` went directly into `chatflow.runSession`, so the
18
- * trust check, the theme picker and the pre-session welcome did not exist and
19
- * `configExists()` was dead code with zero callers. That is the gap this file
20
- * closes; the ordering and the copy are the reference's.
21
- *
22
- * Two deliberate departures, both so this client stays honest:
23
- *
24
- * - `runOnboarding` **returns** whether the user declined rather than calling
25
- * `process.exit` from inside a library function, so the caller owns process
26
- * lifecycle (and a test can drive the whole flow).
27
- * - The right-hand box is about *this* client: the commands that add a model
28
- * and set a key, each held to this package's own registry. It used to be a
29
- * `What's new` list of *this* package's release notes — never Aegiscodex's,
30
- * printing another project's changelog in our banner would be a lie about
31
- * what the user just installed — but a changelog is stale the moment the
32
- * next release lands, and it answered no question a new user has.
33
- *
34
- * Every screen is split into a pure line-builder (`trustLines`,
35
- * `themePickerLines`, `welcomeLines`) plus a thin key loop, so the exact
36
- * content of each screen is asserted by tests with no terminal and no timing.
37
- */
38
-
39
- const { getSize, paint, span, lineWidth, clip, w } = require('./screen.js');
40
- const events = require('./events.js');
41
- const { nextKey, KEY } = events;
42
- const { C, BOLD, BOLD_OFF, GLYPH, THEME_TABLE, themeOf, themeIsLight, terminalIsLight } = require('./theme.js');
43
- const { TAGLINE, TAGLINE_SHORT, welcomeArtParts } = require('./art.js');
44
- const { renderDiffPreview } = require('./markdown.js');
45
- const render = require('./render.js');
46
- const { updateConfig, configExists, loadConfig } = require('./config.js');
47
- const { updateNotice, updateLine, serverNotice, serverUpdateLine } = require('./update.js');
48
- const credentials = require('./credentials.js');
49
- const { signupUrl, signupDisplayUrl } = require('./signup.js');
50
- const { createSettingsStore, isReservedNamespace } = require('./deps.js');
51
-
52
- const VERSION = require('../package.json').version;
53
-
54
- const PRODUCT = 'AEGIS Code';
55
-
56
- /** The two boxes' contents. The right-hand box is `KEY_HELP` — the commands
57
- * that add a model and set a key — not a changelog; see its comment below. */
58
- const TIPS = [
59
- ' Run /init to create an AEGIS.md',
60
- ' Use ↑↓ to recall past prompts',
61
- ' Press / for commands',
62
- ' Press Tab to complete a command',
63
- ' Press ? for shortcuts',
64
- ];
65
-
66
- /**
67
- * The second box: what this build can DO for you, not what changed in it.
68
- *
69
- * It used to be a hand-written `What's new` patch list, and that shape was the
70
- * problem: a changelog on a welcome screen is read once and then goes stale by
71
- * construction, so the box spent most of its life advertising releases the user
72
- * was not running (it sat four minors behind while the package shipped 6.7.3)
73
- * or, worse, patch notes for a version nobody can act on. The four things a new
74
- * user actually has to know to get a turn running are all commands: how to add a
75
- * model, how to set a provider key, how to set an AEGIS account key, and how to
76
- * switch between the models they now hold. Those do not go stale — every command
77
- * named here is asserted to exist in the registry by test/cli-onboarding.test.mjs,
78
- * so a rename fails the suite instead of quietly leaving a dead route on the
79
- * first screen the user reads.
80
- *
81
- * The row count is load-bearing, exactly as the patch list's was: at 80×24 the
82
- * welcome screen fills rows-1 exactly (23 of 24), and `boxes()` receives an
83
- * `avail` it never reads, so a tenth row would push the footer hint off the
84
- * bottom of the commonest terminal there is. `test/cli-onboarding.test.mjs`
85
- * pins the total; retire a row rather than adding one. Each provider row wraps
86
- * its `argument list` onto a second row on purpose — a 60-cell command on a
87
- * 39-cell box would be clipped mid-word by `boxLines()`, which reads as a
88
- * rendering fault rather than as an example.
89
- */
90
- const KEY_HELP = [
91
- ' Add a model: /model add',
92
- ' <id> <name> <model> <url>',
93
- ' Set a provider key: /byok-key',
94
- ' <provider> — openai, anthropic',
95
- ' Set your account key: /key <key>',
96
- ' Switch model: /model, or alt+p',
97
- ' Reasoning effort: /effort',
98
- ' All commands: press / for the list',
99
- ];
100
-
101
- /**
102
- * The connect block — the two ways to power this client, plus the one-line
103
- * answer to "why would I want the app". Shown under the boxes on the welcome
104
- * screen, in place of the desktop host's welcome panel (BYOK + AEGIS Cloud).
105
- *
106
- * It is two plain rows and not a third box, and the reason is the same row
107
- * budget `KEY_HELP` is held to: at 80×24 the rule, mark, title, tagline and
108
- * the Tips/Models-and-keys pair already come to 21 of the 23 usable rows, so a
109
- * boxed third panel (three rows minimum, two of them rules) would push the
110
- * footer hint off the bottom of the commonest terminal there is. Two rows fit
111
- * exactly: one route row, and the desktop line under it.
112
- *
113
- * WHICH route row is the part that matters, and it is composed by
114
- * `connectRows()` below rather than being a constant, because the two routes
115
- * have separate gates. They used to share a single one that short-circuited on
116
- * the account key, so the `/byok-key` row disappeared the moment a user
117
- * redeemed an AEGIS key — see `byokRouteNeeded()`. Holding the block to two
118
- * rows is why the both-owed case merges the routes into one row again: at
119
- * 80×24 a third row is the footer hint.
120
- *
121
- * Both commands named here are real registry entries — `/byok-key` saves a
122
- * provider key, `/key` saves the AEGIS account key — and the URL is the shared
123
- * signup deep link from signup.js, not a hand-written one: it lands on the
124
- * register panel with the key page queued behind it and the channel attached,
125
- * which the bare `aegiscloud.org` this row used to print did not. Nothing here
126
- * is a URL or a command that only exists in this comment.
127
- */
128
- const CONNECT_BYOK = [
129
- 'Your own provider key: /byok-key <provider> — works with your AEGIS key',
130
- ];
131
-
132
- // The AEGIS Cloud route. The URL in the desktop row below is the shared signup
133
- // deep link from signup.js, not a hand-written one: it lands on the register
134
- // panel with the key page queued behind it and the channel attached, which the
135
- // bare `aegiscloud.org` that row used to print did not.
136
- //
137
- // The scheme-less form, and this is the only link in the CLI that uses it. The
138
- // row's copy spends 45 of the 75 cells `wrapped()` allows at 80 columns
139
- // (cols - 4 - indent), so `https://aegiscloud.org/key?s=cli` makes the row 77
140
- // and wraps — a line the 80x24 screen does not have, because the connect
141
- // block sits on row 21 of 23 and the row it pushes out is the footer hint.
142
- // `s=cli` is the parameter that files the signup, so it is the scheme that
143
- // goes, not the channel: see signup.js `signupDisplayUrl()`. Editing this copy
144
- // means re-measuring; test/cli-onboarding.test.mjs fails on the row count if
145
- // the row grows past the budget, and names the row that caused it.
146
- const CONNECT_CLOUD = [
147
- 'AEGIS Cloud, one account key: /key — no provider signup',
148
- ];
149
-
150
- // Both routes still owed (a fresh install): one row naming both, the original
151
- // copy. Two rows is the whole budget, so this is not a third line — see the
152
- // block comment above.
153
- const CONNECT_BOTH = [
154
- 'Your key, your bill: /byok-key <provider> — or AEGIS Cloud, /key',
155
- ];
156
-
157
- const CONNECT_DESKTOP = [
158
- `AEGIS Desktop: same engine on your machine — ${signupDisplayUrl()}`,
159
- ];
160
-
161
- /**
162
- * The connect rows to draw, in order, for the machine as it stands now.
163
- *
164
- * `[]` means nothing to say — both routes are configured — and the caller then
165
- * draws no block at all. Otherwise: one route row (both-owed merges into a
166
- * single row, the 80×24 budget above, and the desktop pointer always shares
167
- * the block with it).
168
- *
169
- * The gates are independent on purpose. An AEGIS key does not cancel the
170
- * `/byok-key` row and a provider route does not cancel the `/key` row: the two
171
- * are not alternatives, they are two ways in, and the row a user has already
172
- * taken is the only one that may be dropped.
173
- */
174
- function connectRows() {
175
- const rows = [];
176
- const byok = byokRouteNeeded();
177
- const cloud = cloudRouteNeeded();
178
- if (byok && cloud) rows.push(...CONNECT_BOTH);
179
- else if (byok) rows.push(...CONNECT_BYOK);
180
- else if (cloud) rows.push(...CONNECT_CLOUD);
181
- // The desktop pointer is not a route, so it is not gated on one: whenever the
182
- // block is drawn at all, the "why would I want the app" answer is in it.
183
- if (rows.length) rows.push(...CONNECT_DESKTOP);
184
- return rows;
185
- }
186
-
187
- /** Centre a plain string, returning one span line. Clip first, or a string
188
- * wider than the terminal produces a row that wraps and shears the frame. */
189
- function centered(text, cols, style) {
190
- const t = clip(String(text), Math.max(1, cols));
191
- const pad = Math.max(0, Math.floor((cols - w(t)) / 2));
192
- return [span('', ' '.repeat(pad)), span(style, t)];
193
- }
194
-
195
- /** Wrap body copy to `cols - 4`, one span line per row (the reference's
196
- * wrapGray, kept here because screen.js's wrapBlock takes spans). */
197
- function wrapped(text, cols, style, indent = 0) {
198
- const words = String(text).split(' ');
199
- const out = [];
200
- let line = [];
201
- let len = 0;
202
- for (const word of words) {
203
- if (len + w(word) + 1 > cols - 4 - indent && line.length) {
204
- out.push([span('', ' '.repeat(indent)), span(style, line.join(' '))]);
205
- line = [word];
206
- len = w(word);
207
- } else {
208
- if (line.length) len++;
209
- line.push(word);
210
- len += w(word);
211
- }
212
- }
213
- if (line.length) out.push([span('', ' '.repeat(indent)), span(style, line.join(' '))]);
214
- return out;
215
- }
216
-
217
- // ── trust check ──────────────────────────────────────────────────────────────
218
-
219
- /** The trust screen's lines. `sel` is 0 = trust, 1 = exit. Pure. */
220
- function trustLines(ctx, cols, sel = 0, cwd = process.cwd()) {
221
- const lines = [];
222
- lines.push([span(C.gold, '─'.repeat(Math.max(1, cols)))]);
223
- lines.push([span(C.white + BOLD, 'Accessing workspace:')]);
224
- lines.push([span(C.white + BOLD, clip(cwd, Math.max(1, cols - 1)))]);
225
- lines.push([span('', '')]);
226
- for (const l of wrapped(
227
- `Quick safety check: Is this a project you created or one you trust? (Like your own code, a well-known open source project, or work from your team). If not, take a moment to review what's in this folder first.`,
228
- cols,
229
- C.white
230
- )) {
231
- lines.push(l);
232
- }
233
- lines.push([span('', '')]);
234
- lines.push([span(C.white, `${PRODUCT} will be able to read, edit, and execute files here.`)]);
235
- lines.push([span('', '')]);
236
- lines.push([span(C.white + BOLD, 'Security guide')]);
237
- lines.push([span('', '')]);
238
- for (let i = 0; i < 2; i++) {
239
- const active = sel === i;
240
- const left = active ? span(C.lavender, GLYPH.cursor) : span('', ' ');
241
- const n = span(C.gray, ` ${i + 1}.`);
242
- const label = i === 0 ? 'Yes, I trust this folder' : 'No, exit';
243
- lines.push([
244
- left,
245
- n,
246
- span(active ? C.lavender : C.white, label),
247
- ]);
248
- }
249
- lines.push([span('', '')]);
250
- lines.push([span(C.gray, `Enter to confirm ${GLYPH.bullet} Esc to cancel`)]);
251
- return lines;
252
- }
253
-
254
- /**
255
- * The trust check. Resolves true when the folder is trusted, false when the
256
- * user declines — the caller must abort the session on false, as the reference
257
- * does (it never reaches `session(ctx)`).
258
- */
259
- async function showTrustCheck(ctx) {
260
- const { cols } = getSize();
261
- let sel = 0;
262
- const renderScreen = () => paint(trustLines(ctx, cols, sel));
263
- renderScreen();
264
- for (;;) {
265
- const key = await nextKey();
266
- if (key.name === KEY.UP || key.name === KEY.DOWN || key.name === KEY.TAB) {
267
- sel = 1 - sel;
268
- renderScreen();
269
- } else if (key.name === KEY.ENTER) {
270
- return sel === 0;
271
- } else if (key.name === KEY.ESC || key.name === KEY.CTRL_C || key.name === KEY.CTRL_D) {
272
- return false;
273
- } else if (key.name === 'char') {
274
- const c = String(key.ch).trim();
275
- if (c === '1') {
276
- sel = 0;
277
- renderScreen();
278
- }
279
- if (c === '2') {
280
- sel = 1;
281
- renderScreen();
282
- }
283
- }
284
- }
285
- }
286
-
287
- // ── theme picker ─────────────────────────────────────────────────────────────
288
-
289
- /** Apply a picker row to a context: both the row index and the light flag, the
290
- * way the reference commits (`ctx.light = sel === 2 || sel === 4 || sel === 6`).
291
- * Row 0 is "Auto (match terminal)", whose flag is resolved from the terminal's
292
- * reported background by `themeIsLight` — reading the row's own `light` field
293
- * would commit the dark fallback and make the one auto row a dark row. */
294
- function applyTheme(ctx, sel) {
295
- const row = THEME_TABLE[sel] || THEME_TABLE[1];
296
- ctx.themeIndex = sel;
297
- ctx.light = themeIsLight(sel);
298
- return sel;
299
- }
300
-
301
- /** The theme picker's lines. Pure, so the 7 rows and their notes are testable. */
302
- function themePickerLines(ctx, cols, rows, sel) {
303
- const lines = [];
304
- lines.push([span(C.coral, `Welcome to ${PRODUCT} v${VERSION}`)]);
305
- lines.push([span(C.white + BOLD, "Let's get started.")]);
306
- lines.push([span(C.white, 'Choose the text style that looks best with your terminal')]);
307
- lines.push([span(C.gray, 'To change this later, run /theme')]);
308
- lines.push([span('', '')]);
309
- for (let i = 0; i < THEME_TABLE.length; i++) {
310
- const t = THEME_TABLE[i];
311
- const active = sel === i;
312
- const left = active ? span(C.lavender, GLYPH.cursor) : span('', ' ');
313
- const n = span(C.gray, `${i + 1}.`);
314
- const check = active ? span(C.green, ' ' + GLYPH.check) : span('', '');
315
- lines.push([
316
- left,
317
- n,
318
- span(active ? C.lavender : C.white, t.name),
319
- ...(t.note ? [span(C.gray, ' ' + t.note)] : []),
320
- check,
321
- ]);
322
- }
323
- // The diff preview is drawn in this terminal's palette, so a row actually
324
- // shows what it will look like rather than describing it.
325
- for (const l of renderDiffPreview(cols, ctx)) lines.push(l);
326
- lines.push([span(C.gray, ' Syntax theme: Monokai Extended (ctrl+t to disable)')]);
327
- while (lines.length < rows - 1) lines.push([span('', '')]);
328
- return lines;
329
- }
330
-
331
- /**
332
- * The theme picker. Resolves the chosen row index. Esc commits the highlighted
333
- * row rather than discarding it, matching the reference — there is no "cancel"
334
- * that leaves the theme unset on a first run.
335
- */
336
- async function showThemePicker(ctx, title = `Welcome to ${PRODUCT}`) {
337
- const { cols, rows } = getSize();
338
- // The highlighted row is a proposal about *this* terminal, so a first run
339
- // proposes the one it can show: a light terminal opened on "Dark mode" is the
340
- // same white-on-white mistake one keystroke away, this time as a default the
341
- // user is asked to accept. Nothing is committed until they answer.
342
- let sel = typeof ctx.themeIndex === 'number' ? ctx.themeIndex : terminalIsLight() ? 2 : 1;
343
- const renderScreen = () => paint(themePickerLines(ctx, cols, rows, sel));
344
- renderScreen();
345
- for (;;) {
346
- const key = await nextKey();
347
- if (key.name === KEY.UP) {
348
- sel = Math.max(0, sel - 1);
349
- renderScreen();
350
- } else if (key.name === KEY.DOWN) {
351
- sel = Math.min(THEME_TABLE.length - 1, sel + 1);
352
- renderScreen();
353
- } else if (key.name === KEY.ENTER || key.name === KEY.ESC || key.name === KEY.CTRL_C || key.name === KEY.CTRL_D) {
354
- return applyTheme(ctx, sel);
355
- } else if (key.name === KEY.CTRL_T) {
356
- ctx.light = !ctx.light;
357
- renderScreen();
358
- } else if (key.name === 'char') {
359
- const n = parseInt(key.ch, 10);
360
- if (n >= 1 && n <= THEME_TABLE.length) {
361
- sel = n - 1;
362
- renderScreen();
363
- }
364
- }
365
- }
366
- }
367
-
368
- // ── welcome ──────────────────────────────────────────────────────────────────
369
-
370
- /**
371
- * The welcome screen's lines: gold rule, the wordmark, the coral title,
372
- * the two boxes, the footer hint. Pure, so a test can assert all of it.
373
- *
374
- * The mark reuses `render.artRow`, the same renderer the scrollback banner
375
- * uses, so the mark cannot render two different ways in two places.
376
- */
377
- function welcomeLines(ctx, cols, rows, firstRun = true) {
378
- const t = themeOf(ctx);
379
- const lines = [];
380
- lines.push([span(t.gold, '━' + '─'.repeat(Math.max(0, cols - 2)) + '━')]);
381
- lines.push([span('', '')]);
382
-
383
- // A newer release, if the last run found one. Reads cache only — the
384
- // refresh it may kick off lands for the NEXT launch, so drawing this box
385
- // never waits on the registry.
386
- let updateMsg = null;
387
- try {
388
- const cfg = loadConfig();
389
- const notice = updateNotice({
390
- current: VERSION,
391
- cache: cfg.updateCheck,
392
- save: (v) => { try { updateConfig({ updateCheck: v }); } catch { /* not fatal */ } },
393
- });
394
- updateMsg = updateLine({ current: VERSION, ...notice });
395
-
396
- // The server's own verdict, which outranks the registry's: "a newer
397
- // release exists" is a suggestion, "this build is no longer served" is
398
- // the app about to stop working. aegis1 refuses clients below
399
- // MIN_CLIENT_VERSION with a 426, so without this line a user learns it
400
- // by being cut off mid-task instead of by reading their welcome box.
401
- // Same cache-read-only rule: the refresh lands for the next launch.
402
- const srv = serverNotice({
403
- current: VERSION,
404
- cache: cfg.updateCheckServer,
405
- save: (v) => { try { updateConfig({ updateCheckServer: v }); } catch { /* not fatal */ } },
406
- });
407
- updateMsg = serverUpdateLine(srv) || updateMsg;
408
- } catch {
409
- // An update notice is never worth failing a launch over.
410
- }
411
-
412
- const parts = welcomeArtParts();
413
- if (cols >= parts.width + 2) {
414
- const leftPad = Math.max(0, Math.floor((cols - parts.width) / 2));
415
- for (const row of parts.rows) {
416
- lines.push(wrapPlain(render.artRow(ctx, row, parts, leftPad)));
417
- }
418
- } else {
419
- lines.push(centered(`${PRODUCT}`, cols, t.gold + BOLD));
420
- }
421
- if (updateMsg) {
422
- lines.push([span('', '')]);
423
- lines.push(centered(updateMsg, cols, t.gold));
424
- }
425
- lines.push([span('', '')]);
426
-
427
- const title = firstRun ? `Welcome to ${PRODUCT}` : 'Welcome back!';
428
- lines.push(centered(title, cols, t.coral + BOLD));
429
- // Shorten the subtitle rather than clipping it: a truncated tagline reads as
430
- // a rendering fault, a shorter one just reads as a shorter one. The threshold
431
- // is derived from the string's own width, not a fixed column count — the copy
432
- // lives in `art.js` now, so a hardcoded breakpoint here would silently start
433
- // clipping the moment the tagline grew by a word.
434
- const tagline = cols >= w(TAGLINE) + 4 ? TAGLINE : TAGLINE_SHORT;
435
- lines.push(centered(tagline, cols, t.gray));
436
- lines.push([span('', '')]);
437
-
438
- lines.push(...boxes(t, cols, rows - lines.length - 4));
439
- lines.push([span('', '')]);
440
- // The connect block, before the footer hint. The rows are composed by
441
- // `connectRows()` — the two routes gate SEPARATELY, so an AEGIS-key holder
442
- // with no provider route of their own is still told `/byok-key` exists,
443
- // which is the whole point: holding an account key is not a reason to hide
444
- // the bring-your-own-key route. `wrapped` splits rather than clips, so a
445
- // narrow terminal gets short rows instead of sheared ones; the height budget
446
- // is unaffected at 80×24, where each row still fits on one line.
447
- for (const text of connectRows()) lines.push(...wrapped(text, cols, t.white, 1));
448
- lines.push([span(t.gray, GLYPH.hint), span(t.white, ' Try "write a test for <filepath>"')]);
449
- while (lines.length < rows - 1) lines.push([span('', '')]);
450
- return lines;
451
- }
452
-
453
- /**
454
- * One box: a `╭─ Header ────╮` top rule, the body rows, a bottom rule. The
455
- * reference draws only the side rails, which reads as a table next to the
456
- * identity panel's rules; the rounds match the CLI's overlay frames.
457
- */
458
- function boxLines(t, header, rows, boxW) {
459
- const inner = Math.max(1, boxW - 4);
460
- // The top rule must be exactly `boxW` cells, like the body rows and the
461
- // bottom rule: `╭` + `─` + head + dashes + `╮`. Deriving the pad from
462
- // `inner + 2 - head.length` made the rule one cell too wide, so a full-width
463
- // pair of boxes overran the terminal by two columns and wrapped, shearing the
464
- // frame. The header is clipped rather than allowed to push the box open.
465
- const head = ` ${clip(header, Math.max(0, boxW - 4))} `;
466
- const top = [
467
- span(t.gray, '╭─'),
468
- span(t.gray + BOLD, head),
469
- span(t.gray, '─'.repeat(Math.max(0, boxW - 3 - head.length)) + '╮'),
470
- ];
471
- const out = [top];
472
- for (const r of rows) {
473
- const text = clip(String(r), inner);
474
- out.push([span(t.gray, '│ '), span(t.white, text + ' '.repeat(Math.max(0, inner - w(text)))), span(t.gray, ' │')]);
475
- }
476
- out.push([span(t.gray, '╰' + '─'.repeat(inner + 2) + '╯')]);
477
- return out;
478
- }
479
-
480
- /** The Tips + Models-and-keys boxes, side by side (stacked when too narrow). */
481
- function boxes(t, cols, avail) {
482
- const gap = 2;
483
- const twoUp = Math.floor((cols - gap) / 2);
484
- const tipRows = TIPS.map((s) => `${GLYPH.pointer}${s}`);
485
- const newsRows = KEY_HELP;
486
- // Name the running build in the header. The rows below are commands and
487
- // cannot go stale, but the header is the only place the screen says which
488
- // build is running, and it is derived from `VERSION` rather than typed — so
489
- // a user on a newer build is never reading notes written for an older one.
490
- const newsHead = `Models & keys · v${VERSION}`;
491
- if (twoUp >= 30) {
492
- let a = boxLines(t, 'Tips for getting started', tipRows, twoUp);
493
- let b = boxLines(t, newsHead, newsRows, twoUp);
494
- // Equalise the heights so both bottom rules land on the same row — boxes of
495
- // different heights leave a ragged pair of corners otherwise.
496
- const h = Math.max(a.length, b.length);
497
- const padBox = (box) => {
498
- if (box.length >= h) return box;
499
- const out = box.slice(0, box.length - 1);
500
- const blank = [span(t.gray, '│ '), span('', ' '.repeat(Math.max(0, twoUp - 4))), span(t.gray, ' │')];
501
- while (out.length < h - 1) out.push(blank);
502
- out.push(box[box.length - 1]);
503
- return out;
504
- };
505
- a = padBox(a);
506
- b = padBox(b);
507
- const out = [];
508
- for (let i = 0; i < h; i++) {
509
- out.push([...a[i], span('', ' '.repeat(gap)), ...b[i]]);
510
- }
511
- return out;
512
- }
513
- // Narrow: stack, so neither box is rendered at an unreadable width.
514
- const wd = Math.max(20, cols - 1);
515
- return [...boxLines(t, 'Tips for getting started', tipRows, wd), ...boxLines(t, newsHead, newsRows, wd)];
516
- }
517
-
518
- /**
519
- * Split a plain ANSI string back into the span model `paint` expects. Only the
520
- * SGR prefixes `render.artRow` emits are recognised, and every non-SGR run is
521
- * taken verbatim, so an unknown escape degrades to visible text rather than
522
- * being silently dropped.
523
- */
524
- function wrapPlain(s) {
525
- const out = [];
526
- const re = /\x1b\[[0-9;]*m/g;
527
- let last = 0;
528
- let style = '';
529
- let m;
530
- while ((m = re.exec(s)) !== null) {
531
- if (m.index > last) out.push(make(style, s.slice(last, m.index)));
532
- style = m[0];
533
- last = m.index + m[0].length;
534
- }
535
- if (last < s.length) out.push(make(style, s.slice(last)));
536
- return out;
537
- }
538
-
539
- function make(style, text) {
540
- const sp = span(style, text);
541
- if (style) {
542
- sp.s = style;
543
- sp.w = w(text);
544
- }
545
- return sp;
546
- }
547
-
548
- /**
549
- * Whether this machine holds a BYOK provider route of the user's own — the
550
- * desktop host's `providerRouteConfigured()`, ported here because the CLI's
551
- * `/byok-key <provider>` writes the exact same `byok:<provider>` row (see
552
- * `engine.js`'s `byokNamespace`) into the exact same settings.json, and
553
- * `connectNeeded()` below used to only ever check the AEGIS account key —
554
- * so a CLI user who did BYOK and never touched the account key got the
555
- * connect block re-pitched at them on every single launch.
556
- *
557
- * `settings.list()` goes through `get()`, which never puts a plaintext key on
558
- * a row (only the `configured` boolean already derived from it) — that field
559
- * is what a row counts on, not a `key` string that doesn't exist on it.
560
- *
561
- * Failure reads as "no configured route found", which keeps the block
562
- * visible — same fail-toward-showing-it bias as the account-key read below.
563
- */
564
- function providerRouteConfigured() {
565
- try {
566
- const store = createSettingsStore({ dir: credentials.aegisHome() });
567
- return store.list().some((row) => {
568
- if (!row || !row.provider || isReservedNamespace(row.provider)) return false;
569
- const baseURL = typeof row.baseURL === 'string' ? row.baseURL.trim() : '';
570
- return Boolean(row.configured || baseURL);
571
- });
572
- } catch {
573
- return false;
574
- }
575
- }
576
-
577
- /**
578
- * Whether ANY part of the connect block is still owed to this machine.
579
- *
580
- * It is the OR of the two route gates, and it is deliberately not the thing
581
- * `welcomeLines` branches on any more: the rows are composed one at a time by
582
- * `connectRows()`, so a machine that holds an AEGIS account key and no
583
- * provider route still gets the `/byok-key` row. This helper is the coarse
584
- * question ("is there anything left to say") — a caller that wants the rows
585
- * should ask `connectRows()` instead.
586
- *
587
- * A read that fails (no credentials file, an unreadable one) resolves to
588
- * "show it": the block is exactly what a user with no key needs, and a
589
- * failed status read must never be the reason a new install is told nothing
590
- * about how to start.
591
- */
592
- function connectNeeded() {
593
- try {
594
- return byokRouteNeeded() || cloudRouteNeeded();
595
- } catch {
596
- return true;
597
- }
598
- }
599
-
600
- /**
601
- * The two halves of the connect block, gated SEPARATELY — this is the fix.
602
- *
603
- * They used to share one gate that short-circuited on the account key, so a
604
- * user who redeemed an AEGIS key was never told BYOK exists at all: the row
605
- * naming `/byok-key` was retired at the exact moment they had an account and
606
- * were most likely to want a provider route of their own (unlimited/no relay
607
- * billing, a model the pool does not carry). An account key and a provider
608
- * route are not alternatives — `/byok-key` works alongside one — so the BYOK
609
- * row is now gated on the BYOK route alone and an AEGIS-key holder still
610
- * reads it. The Cloud row keeps the old account-key gate, because that is the
611
- * thing it pitches.
612
- *
613
- * Both reads fail toward SHOWING the row: a failed status read must never be
614
- * the reason a new install is told nothing about how to start.
615
- */
616
- function byokRouteNeeded() {
617
- try {
618
- return !providerRouteConfigured();
619
- } catch {
620
- return true;
621
- }
622
- }
623
-
624
- function cloudRouteNeeded() {
625
- try {
626
- return !credentials.keyStatus().configured;
627
- } catch {
628
- return true;
629
- }
630
- }
631
-
632
- /**
633
- * The welcome screen. Enter or Esc continues into the session; ctrl+c/d is the
634
- * user asking to leave, which is returned to the caller as `{ exit: true }`
635
- * rather than calling `process.exit` from here.
636
- */
637
- async function showWelcome(ctx, firstRun = true) {
638
- const renderScreen = () => {
639
- const { cols, rows } = getSize();
640
- paint(welcomeLines(ctx, cols, rows, firstRun));
641
- };
642
- renderScreen();
643
- for (;;) {
644
- const key = await nextKey();
645
- if (key.name === KEY.ENTER || key.name === KEY.ESC) return { exit: false };
646
- if (key.name === KEY.CTRL_C || key.name === KEY.CTRL_D) return { exit: true };
647
- }
648
- }
649
-
650
- // ── the account key ──────────────────────────────────────────────────────────
651
-
652
- // The key screen is the highest-intent moment in the CLI: the user pressed
653
- // Enter on a bare /key, so they have already decided they want an account.
654
- // The link is the short aegis1 deep link (see signup.js) — it lands on the
655
- // register panel with the key page queued behind it, which is the round trip
656
- // that used to be left to the user to figure out from the homepage.
657
- const KEY_URL = signupUrl('key_screen');
658
-
659
- /**
660
- * The key screen's lines. Pure, so what the user is told is asserted directly.
661
- *
662
- * `value` is echoed back as bullets: this is the one screen in the product
663
- * where the thing being typed is a secret, and a screen that echoes it would
664
- * put the key in a scrollback buffer, a screenshot and a screen share.
665
- */
666
- function keyLines(ctx, cols, { value = '', error = null, verify = false } = {}) {
667
- const t = themeOf(ctx);
668
- const lines = [];
669
- lines.push([span(t.gold, '─'.repeat(Math.max(1, cols)))]);
670
- lines.push([span(t.white + BOLD, 'Connect your AEGIS account')]);
671
- lines.push([span('', '')]);
672
- for (const l of wrapped(
673
- 'Paste an API key to use AEGIS Cloud. It is stored in your user config ' +
674
- 'directory with owner-only permissions, so later launches and scripts ' +
675
- 'pick it up without an export.',
676
- cols,
677
- t.white
678
- )) {
679
- lines.push(l);
680
- }
681
- // The link gets its own row whenever it would otherwise run past the edge:
682
- // a URL sheared across two lines is not typeable, and this is the one screen
683
- // where the user has nothing to copy it out of.
684
- lines.push([span('', '')]);
685
- const invite = ' No key yet? Free one at ';
686
- if (w(invite) + w(KEY_URL) + 2 <= cols) {
687
- lines.push([span(t.white, invite), span(t.cyan, KEY_URL)]);
688
- } else {
689
- lines.push([span(t.white, ' No key yet? Free one:')]);
690
- lines.push([span(t.cyan, ` ${KEY_URL}`)]);
691
- }
692
- lines.push([span('', '')]);
693
- lines.push([
694
- span(t.lavender, GLYPH.cursor),
695
- span(t.gray, ' API key: '),
696
- span(t.white, '•'.repeat(String(value).length)),
697
- span(verify ? t.cyan : t.gray, verify ? ' verifying…' : ''),
698
- ]);
699
- if (error) lines.push([span(t.coral, ` ${error}`)]);
700
- lines.push([span('', '')]);
701
- lines.push([
702
- span(t.gray, ` ${GLYPH.check} `),
703
- span(t.gray, 'Enter to save'),
704
- span(t.gray, ' · '),
705
- span(t.gray, 'Esc to skip'),
706
- ]);
707
- return lines;
708
- }
709
-
710
- /**
711
- * Ask for the account key. Resolves `{key}` when submitted, `{skipped:true}`
712
- * when the user declines, `{exit:true}` on ctrl+c.
713
- *
714
- * `submit(key)` is the caller's verification+persistence step; its rejection
715
- * message is shown on the screen and the user stays on it, because the failure
716
- * mode this prevents is a key that is accepted into the config while the
717
- * account behind it rejects every call.
718
- */
719
- async function requestApiKey(ctx, o = {}) {
720
- const submit = o.submit || (async () => ({ ok: true }));
721
- const { cols } = getSize();
722
- let value = '';
723
- let error = null;
724
- let verify = false;
725
- const paintScreen = () => paint(keyLines(ctx, cols, { value, error, verify }));
726
- paintScreen();
727
-
728
- for (;;) {
729
- const key = await nextKey();
730
- if (key.name === KEY.ENTER) {
731
- if (!value.trim()) return { skipped: true };
732
- verify = true;
733
- error = null;
734
- paintScreen();
735
- let res;
736
- try {
737
- res = await submit(value);
738
- } catch (e) {
739
- res = { ok: false, message: (e && e.message) || String(e) };
740
- }
741
- verify = false;
742
- if (res && res.ok === false) {
743
- error = res.message || 'that key was refused';
744
- paintScreen();
745
- continue;
746
- }
747
- return { key: value, result: res };
748
- }
749
- if (key.name === KEY.ESC) return { skipped: true };
750
- if (key.name === KEY.CTRL_C || key.name === KEY.CTRL_D) return { exit: true };
751
- if (key.name === KEY.BACKSPACE) {
752
- value = value.slice(0, -1);
753
- error = null;
754
- paintScreen();
755
- continue;
756
- }
757
- if (key.name === 'char') {
758
- const ch = key.ch;
759
- if (ch && ch >= ' ') {
760
- value += ch;
761
- error = null;
762
- paintScreen();
763
- }
764
- continue;
765
- }
766
- // A paste arrives as its own event (events.js rushes multi-char reads);
767
- // without this a pasted key is dropped on the floor.
768
- if (key.name === 'paste' && key.text) {
769
- value = (value + String(key.text)).replace(/\s+/g, '');
770
- error = null;
771
- paintScreen();
772
- }
773
- }
774
- }
775
-
776
- // ── the sequence ─────────────────────────────────────────────────────────────
777
-
778
- /**
779
- * Run the pre-session onboarding, exactly as the reference orders it.
780
- *
781
- * @param {object} ctx the shared command context (in: themeIndex, light)
782
- * @param {object} [o]
783
- * @param {boolean} [o.continue] skip onboarding (the reference's --continue)
784
- * @param {() => boolean} [o.seen] an explicit "has run before" probe; defaults
785
- * to the config file's existence
786
- * @param {(patch:object)=>void} [o.save] persist patch; defaults to updateConfig
787
- * @param {() => boolean} [o.needsKey] true when no account key is configured —
788
- * the key screen is shown only then
789
- * @param {(key:string)=>Promise<object>} [o.submitKey] verify + persist a key
790
- * @returns {Promise<{ok:boolean, firstRun:boolean, themeIndex:number,
791
- * key:{set:boolean, skipped:boolean}}>} `ok` is false when the user
792
- * declined the trust check or asked to exit.
793
- */
794
- async function runOnboarding(ctx, o = {}) {
795
- const seen = o.seen || configExists;
796
- const save = o.save || updateConfig;
797
- // Injectable so the *sequence* — which screens run, in what order, and what is
798
- // persisted — can be asserted without a terminal. The screens themselves are
799
- // tested directly through their pure line-builders.
800
- const ui = {
801
- showTrustCheck,
802
- showThemePicker,
803
- showWelcome,
804
- requestApiKey: (c, opts) =>
805
- requestApiKey(c, { submit: o.submitKey || (async () => ({ ok: true })), ...opts }),
806
- // An injected `ui` overrides the screens it names and inherits the rest, so
807
- // a caller testing the sequence does not have to supply a key screen it
808
- // never wants to exercise.
809
- ...(o.ui || {}),
810
- };
811
- // No key is the one state where the session cannot do anything at all, so it
812
- // is asked for in-band rather than left to a shell export the user has to
813
- // discover. Default reads the credential store so a caller that forgets to
814
- // pass it still gets the right behaviour.
815
- const needsKey = o.needsKey || (() => !credentials.hasApiKey());
816
- // …but only where a question can actually be asked. Without this a library
817
- // caller with no TTY reaches a screen that waits on a key queue nothing will
818
- // ever feed — a hang instead of a missing credential.
819
- const canPrompt = o.canPrompt || (() => !!(process.stdin && process.stdin.isTTY));
820
- // Declared out here because both the sequence and its key step report on it.
821
- const key = { set: false, skipped: false };
822
- if (o.continue) return { ok: true, firstRun: false, themeIndex: ctx.themeIndex, key: { set: false, skipped: false } };
823
-
824
- // Onboarding runs *before* the session loop, and the session loop is what
825
- // normally attaches the key pump — so without this the first screen paints and
826
- // then blocks forever on a key queue nothing feeds. Only attach if nobody
827
- // else has (the chatflow re-attaches for the session), and only ever detach
828
- // what we attached.
829
- const owns = !events.isKeyStreamAttached() && !!(process.stdin && process.stdin.isTTY);
830
- if (owns) events.attachKeyStream(process.stdin);
831
- try {
832
- return await runScreens();
833
- } finally {
834
- if (owns) events.detachKeyStream();
835
- }
836
-
837
- async function runScreens() {
838
- if (!seen()) {
839
- // Genuine first run: trust check, then the theme picker, then persist so
840
- // neither is ever shown again. Re-running this every launch greeted
841
- // returning users with "Let's get started." and discarded their session.
842
- const trusted = await ui.showTrustCheck(ctx);
843
- if (!trusted) return { ok: false, firstRun: true, themeIndex: ctx.themeIndex, key };
844
- await ui.showThemePicker(ctx);
845
- save({ themeIndex: ctx.themeIndex, light: ctx.light });
846
- if (await askKey()) return { ok: false, firstRun: true, themeIndex: ctx.themeIndex, key };
847
- const welcome = await ui.showWelcome(ctx, true);
848
- if (welcome && welcome.exit) return { ok: false, firstRun: true, themeIndex: ctx.themeIndex, key };
849
- return { ok: true, firstRun: true, themeIndex: ctx.themeIndex, key };
850
- }
851
-
852
- if (await askKey()) return { ok: false, firstRun: false, themeIndex: ctx.themeIndex, key };
853
- const welcome = await ui.showWelcome(ctx, false);
854
- if (welcome && welcome.exit) return { ok: false, firstRun: false, themeIndex: ctx.themeIndex, key };
855
- return { ok: true, firstRun: false, themeIndex: ctx.themeIndex, key };
856
- }
857
-
858
- /** @returns {Promise<boolean>} true when the user asked to exit. */
859
- async function askKey() {
860
- if (!needsKey() || !canPrompt()) return false;
861
- const res = await ui.requestApiKey(ctx);
862
- if (res && res.exit) return true;
863
- if (res && res.key) key.set = true;
864
- else key.skipped = true;
865
- return false;
866
- }
867
- }
868
-
869
- module.exports = {
870
- PRODUCT,
871
- TIPS,
872
- KEY_HELP,
873
- CONNECT_BYOK,
874
- CONNECT_CLOUD,
875
- CONNECT_BOTH,
876
- CONNECT_DESKTOP,
877
- connectRows,
878
- connectNeeded,
879
- byokRouteNeeded,
880
- cloudRouteNeeded,
881
- providerRouteConfigured,
882
- trustLines,
883
- themePickerLines,
884
- keyLines,
885
- applyTheme,
886
- welcomeLines,
887
- boxes,
888
- boxLines,
889
- centered,
890
- wrapped,
891
- wrapPlain,
892
- showTrustCheck,
893
- showThemePicker,
894
- requestApiKey,
895
- showWelcome,
896
- runOnboarding,
897
- KEY_URL,
898
- };
3
+ "use strict";const{getSize:getSize,paint:paint,span:span,lineWidth:lineWidth,clip:clip,w:w}=require("./screen.js"),events=require("./events.js"),{nextKey:nextKey,KEY:KEY}=events,{C:C,BOLD:BOLD,BOLD_OFF:BOLD_OFF,GLYPH:GLYPH,THEME_TABLE:THEME_TABLE,themeOf:themeOf,themeIsLight:themeIsLight,terminalIsLight:terminalIsLight}=require("./theme.js"),{TAGLINE:TAGLINE,TAGLINE_SHORT:TAGLINE_SHORT,welcomeArtParts:welcomeArtParts}=require("./art.js"),{renderDiffPreview:renderDiffPreview}=require("./markdown.js"),render=require("./render.js"),{updateConfig:updateConfig,configExists:configExists,loadConfig:loadConfig}=require("./config.js"),{updateNotice:updateNotice,updateLine:updateLine,serverNotice:serverNotice,serverUpdateLine:serverUpdateLine}=require("./update.js"),credentials=require("./credentials.js"),{signupUrl:signupUrl,signupDisplayUrl:signupDisplayUrl}=require("./signup.js"),{createSettingsStore:createSettingsStore,isReservedNamespace:isReservedNamespace}=require("./deps.js"),VERSION=require("../package.json").version,PRODUCT="AEGIS Code",TIPS=[" Run /init to create an AEGIS.md"," Use ↑↓ to recall past prompts"," Press / for commands"," Press Tab to complete a command"," Press ? for shortcuts"],KEY_HELP=[" Add a model: /model add"," <id> <name> <model> <url>"," Set a provider key: /byok-key"," <provider> — openai, anthropic"," Set your account key: /key <key>"," Switch model: /model, or alt+p"," Reasoning effort: /effort"," All commands: press / for the list"],CONNECT_BYOK=["Your own provider key: /byok-key <provider> — works with your AEGIS key"],CONNECT_CLOUD=["AEGIS Cloud, one account key: /key — no provider signup"],CONNECT_BOTH=["Your key, your bill: /byok-key <provider> — or AEGIS Cloud, /key"],CONNECT_DESKTOP=[`AEGIS Desktop: same engine on your machine — ${signupDisplayUrl()}`];function connectRows(){const e=[],t=byokRouteNeeded(),n=cloudRouteNeeded();return t&&n?e.push(...CONNECT_BOTH):t?e.push(...CONNECT_BYOK):n&&e.push(...CONNECT_CLOUD),e.length&&e.push(...CONNECT_DESKTOP),e}function centered(e,t,n){const s=clip(String(e),Math.max(1,t)),r=Math.max(0,Math.floor((t-w(s))/2));return[span(""," ".repeat(r)),span(n,s)]}function wrapped(e,t,n,s=0){const r=String(e).split(" "),o=[];let a=[],i=0;for(const e of r)i+w(e)+1>t-4-s&&a.length?(o.push([span(""," ".repeat(s)),span(n,a.join(" "))]),a=[e],i=w(e)):(a.length&&i++,a.push(e),i+=w(e));return a.length&&o.push([span(""," ".repeat(s)),span(n,a.join(" "))]),o}function trustLines(e,t,n=0,s=process.cwd()){const r=[];r.push([span(C.gold,"─".repeat(Math.max(1,t)))]),r.push([span(C.white+BOLD,"Accessing workspace:")]),r.push([span(C.white+BOLD,clip(s,Math.max(1,t-1)))]),r.push([span("","")]);for(const e of wrapped("Quick safety check: Is this a project you created or one you trust? (Like your own code, a well-known open source project, or work from your team). If not, take a moment to review what's in this folder first.",t,C.white))r.push(e);r.push([span("","")]),r.push([span(C.white,`${PRODUCT} will be able to read, edit, and execute files here.`)]),r.push([span("","")]),r.push([span(C.white+BOLD,"Security guide")]),r.push([span("","")]);for(let e=0;e<2;e++){const t=n===e,s=t?span(C.lavender,GLYPH.cursor):span(""," "),o=span(C.gray,` ${e+1}.`),a=0===e?"Yes, I trust this folder":"No, exit";r.push([s,o,span(t?C.lavender:C.white,a)])}return r.push([span("","")]),r.push([span(C.gray,`Enter to confirm ${GLYPH.bullet} Esc to cancel`)]),r}async function showTrustCheck(e){const{cols:t}=getSize();let n=0;const s=()=>paint(trustLines(e,t,n));for(s();;){const e=await nextKey();if(e.name===KEY.UP||e.name===KEY.DOWN||e.name===KEY.TAB)n=1-n,s();else{if(e.name===KEY.ENTER)return 0===n;if(e.name===KEY.ESC||e.name===KEY.CTRL_C||e.name===KEY.CTRL_D)return!1;if("char"===e.name){const t=String(e.ch).trim();"1"===t&&(n=0,s()),"2"===t&&(n=1,s())}}}}function applyTheme(e,t){return THEME_TABLE[t]||THEME_TABLE[1],e.themeIndex=t,e.light=themeIsLight(t),t}function themePickerLines(e,t,n,s){const r=[];r.push([span(C.coral,`Welcome to ${PRODUCT} v${VERSION}`)]),r.push([span(C.white+BOLD,"Let's get started.")]),r.push([span(C.white,"Choose the text style that looks best with your terminal")]),r.push([span(C.gray,"To change this later, run /theme")]),r.push([span("","")]);for(let e=0;e<THEME_TABLE.length;e++){const t=THEME_TABLE[e],n=s===e,o=n?span(C.lavender,GLYPH.cursor):span(""," "),a=span(C.gray,`${e+1}.`),i=n?span(C.green," "+GLYPH.check):span("","");r.push([o,a,span(n?C.lavender:C.white,t.name),...t.note?[span(C.gray," "+t.note)]:[],i])}for(const n of renderDiffPreview(t,e))r.push(n);for(r.push([span(C.gray," Syntax theme: Monokai Extended (ctrl+t to disable)")]);r.length<n-1;)r.push([span("","")]);return r}async function showThemePicker(e,t=`Welcome to ${PRODUCT}`){const{cols:n,rows:s}=getSize();let r="number"==typeof e.themeIndex?e.themeIndex:terminalIsLight()?2:1;const o=()=>paint(themePickerLines(e,n,s,r));for(o();;){const t=await nextKey();if(t.name===KEY.UP)r=Math.max(0,r-1),o();else if(t.name===KEY.DOWN)r=Math.min(THEME_TABLE.length-1,r+1),o();else{if(t.name===KEY.ENTER||t.name===KEY.ESC||t.name===KEY.CTRL_C||t.name===KEY.CTRL_D)return applyTheme(e,r);if(t.name===KEY.CTRL_T)e.light=!e.light,o();else if("char"===t.name){const e=parseInt(t.ch,10);e>=1&&e<=THEME_TABLE.length&&(r=e-1,o())}}}}function welcomeLines(e,t,n,s=!0){const r=themeOf(e),o=[];o.push([span(r.gold,"━"+"─".repeat(Math.max(0,t-2))+"━")]),o.push([span("","")]);let a=null;try{const e=loadConfig(),t=updateNotice({current:VERSION,cache:e.updateCheck,save:e=>{try{updateConfig({updateCheck:e})}catch{}}});a=updateLine({current:VERSION,...t});const n=serverNotice({current:VERSION,cache:e.updateCheckServer,save:e=>{try{updateConfig({updateCheckServer:e})}catch{}}});a=serverUpdateLine(n)||a}catch{}const i=welcomeArtParts();if(t>=i.width+2){const n=Math.max(0,Math.floor((t-i.width)/2));for(const t of i.rows)o.push(wrapPlain(render.artRow(e,t,i,n)))}else o.push(centered(`${PRODUCT}`,t,r.gold+BOLD));a&&(o.push([span("","")]),o.push(centered(a,t,r.gold))),o.push([span("","")]);const c=s?`Welcome to ${PRODUCT}`:"Welcome back!";o.push(centered(c,t,r.coral+BOLD));const p=t>=w(TAGLINE)+4?TAGLINE:TAGLINE_SHORT;o.push(centered(p,t,r.gray)),o.push([span("","")]),o.push(...boxes(r,t,n-o.length-4)),o.push([span("","")]);for(const e of connectRows())o.push(...wrapped(e,t,r.white,1));for(o.push([span(r.gray,GLYPH.hint),span(r.white,' Try "write a test for <filepath>"')]);o.length<n-1;)o.push([span("","")]);return o}function boxLines(e,t,n,s){const r=Math.max(1,s-4),o=` ${clip(t,Math.max(0,s-4))} `,a=[[span(e.gray,"╭─"),span(e.gray+BOLD,o),span(e.gray,"─".repeat(Math.max(0,s-3-o.length))+"╮")]];for(const t of n){const n=clip(String(t),r);a.push([span(e.gray,"│ "),span(e.white,n+" ".repeat(Math.max(0,r-w(n)))),span(e.gray," │")])}return a.push([span(e.gray,"╰"+"─".repeat(r+2)+"╯")]),a}function boxes(e,t,n){const s=Math.floor((t-2)/2),r=TIPS.map((e=>`${GLYPH.pointer}${e}`)),o=KEY_HELP,a=`Models & keys · v${VERSION}`;if(s>=30){let t=boxLines(e,"Tips for getting started",r,s),n=boxLines(e,a,o,s);const i=Math.max(t.length,n.length),c=t=>{if(t.length>=i)return t;const n=t.slice(0,t.length-1),r=[span(e.gray,"│ "),span(""," ".repeat(Math.max(0,s-4))),span(e.gray," │")];for(;n.length<i-1;)n.push(r);return n.push(t[t.length-1]),n};t=c(t),n=c(n);const p=[];for(let e=0;e<i;e++)p.push([...t[e],span(""," ".repeat(2)),...n[e]]);return p}const i=Math.max(20,t-1);return[...boxLines(e,"Tips for getting started",r,i),...boxLines(e,a,o,i)]}function wrapPlain(e){const t=[],n=/\x1b\[[0-9;]*m/g;let s,r=0,o="";for(;null!==(s=n.exec(e));)s.index>r&&t.push(make(o,e.slice(r,s.index))),o=s[0],r=s.index+s[0].length;return r<e.length&&t.push(make(o,e.slice(r))),t}function make(e,t){const n=span(e,t);return e&&(n.s=e,n.w=w(t)),n}function providerRouteConfigured(){try{return createSettingsStore({dir:credentials.aegisHome()}).list().some((e=>{if(!e||!e.provider||isReservedNamespace(e.provider))return!1;const t="string"==typeof e.baseURL?e.baseURL.trim():"";return Boolean(e.configured||t)}))}catch{return!1}}function connectNeeded(){try{return byokRouteNeeded()||cloudRouteNeeded()}catch{return!0}}function byokRouteNeeded(){try{return!providerRouteConfigured()}catch{return!0}}function cloudRouteNeeded(){try{return!credentials.keyStatus().configured}catch{return!0}}async function showWelcome(e,t=!0){for((()=>{const{cols:n,rows:s}=getSize();paint(welcomeLines(e,n,s,t))})();;){const e=await nextKey();if(e.name===KEY.ENTER||e.name===KEY.ESC)return{exit:!1};if(e.name===KEY.CTRL_C||e.name===KEY.CTRL_D)return{exit:!0}}}const KEY_URL=signupUrl("key_screen");function keyLines(e,t,{value:n="",error:s=null,verify:r=!1}={}){const o=themeOf(e),a=[];a.push([span(o.gold,"─".repeat(Math.max(1,t)))]),a.push([span(o.white+BOLD,"Connect your AEGIS account")]),a.push([span("","")]);for(const e of wrapped("Paste an API key to use AEGIS Cloud. It is stored in your user config directory with owner-only permissions, so later launches and scripts pick it up without an export.",t,o.white))a.push(e);a.push([span("","")]);const i=" No key yet? Free one at ";return w(i)+w(KEY_URL)+2<=t?a.push([span(o.white,i),span(o.cyan,KEY_URL)]):(a.push([span(o.white," No key yet? Free one:")]),a.push([span(o.cyan,` ${KEY_URL}`)])),a.push([span("","")]),a.push([span(o.lavender,GLYPH.cursor),span(o.gray," API key: "),span(o.white,"•".repeat(String(n).length)),span(r?o.cyan:o.gray,r?" verifying…":"")]),s&&a.push([span(o.coral,` ${s}`)]),a.push([span("","")]),a.push([span(o.gray,` ${GLYPH.check} `),span(o.gray,"Enter to save"),span(o.gray," · "),span(o.gray,"Esc to skip")]),a}async function requestApiKey(e,t={}){const n=t.submit||(async()=>({ok:!0})),{cols:s}=getSize();let r="",o=null,a=!1;const i=()=>paint(keyLines(e,s,{value:r,error:o,verify:a}));for(i();;){const e=await nextKey();if(e.name===KEY.ENTER){if(!r.trim())return{skipped:!0};let e;a=!0,o=null,i();try{e=await n(r)}catch(t){e={ok:!1,message:t&&t.message||String(t)}}if(a=!1,e&&!1===e.ok){o=e.message||"that key was refused",i();continue}return{key:r,result:e}}if(e.name===KEY.ESC)return{skipped:!0};if(e.name===KEY.CTRL_C||e.name===KEY.CTRL_D)return{exit:!0};if(e.name!==KEY.BACKSPACE)if("char"!==e.name)"paste"===e.name&&e.text&&(r=(r+String(e.text)).replace(/\s+/g,""),o=null,i());else{const t=e.ch;t&&t>=" "&&(r+=t,o=null,i())}else r=r.slice(0,-1),o=null,i()}}async function runOnboarding(e,t={}){const n=t.seen||configExists,s=t.save||updateConfig,r={showTrustCheck:showTrustCheck,showThemePicker:showThemePicker,showWelcome:showWelcome,requestApiKey:(e,n)=>requestApiKey(e,{submit:t.submitKey||(async()=>({ok:!0})),...n}),...t.ui||{}},o=t.needsKey||(()=>!credentials.hasApiKey()),a=t.canPrompt||(()=>!(!process.stdin||!process.stdin.isTTY)),i={set:!1,skipped:!1};if(t.continue)return{ok:!0,firstRun:!1,themeIndex:e.themeIndex,key:{set:!1,skipped:!1}};const c=!events.isKeyStreamAttached()&&!(!process.stdin||!process.stdin.isTTY);c&&events.attachKeyStream(process.stdin);try{return await async function(){if(!n()){if(!await r.showTrustCheck(e))return{ok:!1,firstRun:!0,themeIndex:e.themeIndex,key:i};if(await r.showThemePicker(e),s({themeIndex:e.themeIndex,light:e.light}),await p())return{ok:!1,firstRun:!0,themeIndex:e.themeIndex,key:i};const t=await r.showWelcome(e,!0);return t&&t.exit?{ok:!1,firstRun:!0,themeIndex:e.themeIndex,key:i}:{ok:!0,firstRun:!0,themeIndex:e.themeIndex,key:i}}if(await p())return{ok:!1,firstRun:!1,themeIndex:e.themeIndex,key:i};const t=await r.showWelcome(e,!1);return t&&t.exit?{ok:!1,firstRun:!1,themeIndex:e.themeIndex,key:i}:{ok:!0,firstRun:!1,themeIndex:e.themeIndex,key:i}}()}finally{c&&events.detachKeyStream()}async function p(){if(!o()||!a())return!1;const t=await r.requestApiKey(e);return!(!t||!t.exit)||(t&&t.key?i.set=!0:i.skipped=!0,!1)}}module.exports={PRODUCT:PRODUCT,TIPS:TIPS,KEY_HELP:KEY_HELP,CONNECT_BYOK:CONNECT_BYOK,CONNECT_CLOUD:CONNECT_CLOUD,CONNECT_BOTH:CONNECT_BOTH,CONNECT_DESKTOP:CONNECT_DESKTOP,connectRows:connectRows,connectNeeded:connectNeeded,byokRouteNeeded:byokRouteNeeded,cloudRouteNeeded:cloudRouteNeeded,providerRouteConfigured:providerRouteConfigured,trustLines:trustLines,themePickerLines:themePickerLines,keyLines:keyLines,applyTheme:applyTheme,welcomeLines:welcomeLines,boxes:boxes,boxLines:boxLines,centered:centered,wrapped:wrapped,wrapPlain:wrapPlain,showTrustCheck:showTrustCheck,showThemePicker:showThemePicker,requestApiKey:requestApiKey,showWelcome:showWelcome,runOnboarding:runOnboarding,KEY_URL:KEY_URL};