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,638 +1 @@
1
- 'use strict';
2
-
3
- /**
4
- * The installer — reads a host's config, merges exactly one entry into it, and
5
- * writes it back without disturbing anything else in the file.
6
- *
7
- * The invariants this file exists to hold:
8
- *
9
- * 1. **Never destroy a user's config.** Every write is a merge of one key
10
- * into a parsed document, preceded by a timestamped backup whenever the
11
- * file exists and its bytes change. A config the user hand-tuned for four
12
- * other MCP servers must come out the other side with those four servers
13
- * intact — `test/editor-hosts.test.mjs` asserts exactly that.
14
- *
15
- * 2. **Idempotent.** Running `aegiscode mcp install vscode` twice leaves the
16
- * file byte-identical the second time (`changed: false`), so the command
17
- * is safe in a dotfiles script or a provisioning step.
18
- *
19
- * 3. **Never guess.** Unparseable JSON is refused, not overwritten. A TOML
20
- * file whose `[mcp_servers.aegis]` section sits under a construct this
21
- * minimal writer does not model is refused with the line number. Silent
22
- * data loss in someone's editor config is not an acceptable failure mode
23
- * for a convenience command.
24
- *
25
- * 4. **Dry-run is the default in the CLI, not here.** `plan()` computes the
26
- * exact bytes it would write; `apply()` is the only function that touches
27
- * the disk.
28
- */
29
-
30
- const fs = require('node:fs');
31
- const path = require('node:path');
32
-
33
- const { TARGETS, getTarget, appConfig } = require('./targets.js');
34
- const { buildSpec, resolveServer } = require('./spec.js');
35
-
36
- // ---------------------------------------------------------------------------
37
- // Context
38
- // ---------------------------------------------------------------------------
39
-
40
- /**
41
- * The environment a target resolves paths against. Tests pass an explicit ctx
42
- * so nothing here ever writes into the developer's real `~/.config`.
43
- */
44
- function hostCtx(overrides = {}) {
45
- return {
46
- env: process.env,
47
- platform: process.platform,
48
- home: null,
49
- cwd: process.cwd(),
50
- ...overrides,
51
- };
52
- }
53
-
54
- // ---------------------------------------------------------------------------
55
- // Document I/O — JSON and the one TOML target
56
- // ---------------------------------------------------------------------------
57
-
58
- function readText(file) {
59
- try {
60
- return { text: fs.readFileSync(file, 'utf8'), exists: true };
61
- } catch (err) {
62
- if (err.code === 'ENOENT') return { text: null, exists: false };
63
- throw err;
64
- }
65
- }
66
-
67
- /** A path that is a real file — the only thing `node <path>` can execute. */
68
- function isFile(file) {
69
- try {
70
- return fs.statSync(file).isFile();
71
- } catch {
72
- return false;
73
- }
74
- }
75
-
76
- function parseJson(text, file) {
77
- if (text === null || text.trim() === '') return {};
78
- try {
79
- return JSON.parse(text);
80
- } catch (err) {
81
- throw new Error(`${file} is not valid JSON (${err.message}) — refusing to overwrite it`);
82
- }
83
- }
84
-
85
- /** Set `a.b.c` without dropping siblings. */
86
- function setPath(doc, dotted, value) {
87
- const parts = dotted.split('.');
88
- let node = doc;
89
- for (const part of parts.slice(0, -1)) {
90
- if (node[part] === null || typeof node[part] !== 'object' || Array.isArray(node[part])) {
91
- node[part] = {};
92
- }
93
- node = node[part];
94
- }
95
- node[parts[parts.length - 1]] = value;
96
- return doc;
97
- }
98
-
99
- function getPath(doc, dotted) {
100
- let node = doc;
101
- for (const part of dotted.split('.')) {
102
- if (node === null || typeof node !== 'object') return undefined;
103
- node = node[part];
104
- }
105
- return node;
106
- }
107
-
108
- /**
109
- * Delete a leaf from a dotted path.
110
- *
111
- * @param {object} doc
112
- * @param {string} dotted
113
- * @param {boolean} prune Remove container objects left empty by the delete.
114
- * This is OFF by default, and the default is the safe one: an empty
115
- * `"mcpServers": {}` that the user wrote is a key in their file, and a
116
- * removal that never installed anything must not touch it. Callers pass
117
- * `true` only when they know the container was holding our own entry.
118
- */
119
- function delPath(doc, dotted, prune = false) {
120
- const parts = dotted.split('.');
121
- const parents = [];
122
- let node = doc;
123
- for (const part of parts.slice(0, -1)) {
124
- if (node === null || typeof node !== 'object') return doc;
125
- parents.push([node, part]);
126
- node = node[part];
127
- }
128
- if (node && typeof node === 'object') delete node[parts[parts.length - 1]];
129
- if (!prune) return doc;
130
- // If deleting our key emptied a container, nothing else of the user's was in
131
- // it, so dropping it is safe. (The one residue: a container the user had
132
- // written as an empty object is also removed — a no-op in every editor, and
133
- // the price of not leaving a stray `{}` behind.)
134
- for (let i = parents.length - 1; i >= 0; i--) {
135
- const [parent, key] = parents[i];
136
- const child = parent[key];
137
- if (child && typeof child === 'object' && Object.keys(child).length === 0) delete parent[key];
138
- else break;
139
- }
140
- return doc;
141
- }
142
-
143
- const TOML_BARE = /^[A-Za-z0-9_-]+$/;
144
-
145
- function tomlKey(key) {
146
- return TOML_BARE.test(key) ? key : JSON.stringify(key);
147
- }
148
-
149
- function tomlString(value) {
150
- return JSON.stringify(String(value));
151
- }
152
-
153
- function tomlArray(values) {
154
- return `[${values.map(tomlString).join(', ')}]`;
155
- }
156
-
157
- /**
158
- * Replace (or append) one `[a.b]` section, leaving every other line of the file
159
- * alone — including comments inside the section being replaced, which is why
160
- * the block is regenerated from the spec rather than patched key by key. A
161
- * generated section carries a header comment saying so.
162
- */
163
- /**
164
- * Is this line a TOML header for `sectionPath`, or for a subtable of it?
165
- *
166
- * `renderEntry` emits `[...env]` as a subtable, so "our section" is a SPAN of
167
- * the file — the header plus any `[section.…]` children — and not just one
168
- * header line. Comparing bare-line equality (as this used to) both missed the
169
- * subtable and mistook a foreign section for ours.
170
- */
171
- function tomlHeaderName(line) {
172
- const t = line.trim();
173
- if (!/^\[/.test(t)) return null;
174
- return t.replace(/^\[+\s*/, '').replace(/\s*\]+$/, '');
175
- }
176
-
177
- function ownedTomlHeader(line, sectionPath) {
178
- const name = tomlHeaderName(line);
179
- if (name === null) return false;
180
- return name === sectionPath || name.startsWith(`${sectionPath}.`);
181
- }
182
-
183
- /**
184
- * Replace (or append) a whole TOML section, header included.
185
- *
186
- * Idempotency is the requirement that shapes this: the second run must produce
187
- * the same bytes as the first, so the replacement has to consume exactly the
188
- * span the previous run wrote — the header, the body, and any owned subtable —
189
- * and leave every other byte of someone else's config alone.
190
- *
191
- * @param {string} text
192
- * @param {string} sectionPath e.g. `mcp_servers.aegis` (no brackets)
193
- * @param {string[]} bodyLines lines AFTER the header; may include own subtables
194
- */
195
- function upsertTomlSection(text, sectionPath, bodyLines) {
196
- const header = `[${sectionPath}]`;
197
- const lines = (text || '').split('\n');
198
- const out = [];
199
- let replaced = false;
200
- let i = 0;
201
- while (i < lines.length) {
202
- if (lines[i].trim() === header) {
203
- out.push(header, ...bodyLines, '');
204
- replaced = true;
205
- i++;
206
- // Consume the old body, then each subtable we own (the `.env` block),
207
- // stopping at the first header that is somebody else's.
208
- while (i < lines.length && !/^\s*\[/.test(lines[i])) i++;
209
- while (i < lines.length && ownedTomlHeader(lines[i], sectionPath)) {
210
- i++;
211
- while (i < lines.length && !/^\s*\[/.test(lines[i])) i++;
212
- }
213
- continue;
214
- }
215
- out.push(lines[i]);
216
- i++;
217
- }
218
- if (!replaced) {
219
- while (out.length && out[out.length - 1].trim() === '') out.pop();
220
- if (out.length) out.push('');
221
- out.push(header, ...bodyLines, '');
222
- }
223
- return out.join('\n');
224
- }
225
-
226
- function removeTomlSection(text, sectionPath) {
227
- const header = `[${sectionPath}]`;
228
- const lines = (text || '').split('\n');
229
- const out = [];
230
- let i = 0;
231
- while (i < lines.length) {
232
- if (lines[i].trim() === header) {
233
- i++;
234
- while (i < lines.length && !/^\s*\[/.test(lines[i])) i++;
235
- // The `.env` subtable is part of our section, not a section of its own:
236
- // leaving it behind would orphan a block of env keys under no header.
237
- while (i < lines.length && ownedTomlHeader(lines[i], sectionPath)) {
238
- i++;
239
- while (i < lines.length && !/^\s*\[/.test(lines[i])) i++;
240
- }
241
- continue;
242
- }
243
- out.push(lines[i]);
244
- i++;
245
- }
246
- return out.join('\n');
247
- }
248
-
249
- // ---------------------------------------------------------------------------
250
- // Rendering one target
251
- // ---------------------------------------------------------------------------
252
-
253
- function renderEntry(target, spec) {
254
- if (target.kind === 'mcp-toml') {
255
- const lines = [
256
- `# Added by \`aegiscode mcp install ${target.id}\`. Key resolution lives in`,
257
- '# ~/.aegiscode/.env and the 0600 store `aegiscode login` writes.',
258
- 'command = ' + tomlString(spec.command),
259
- 'args = ' + tomlArray(spec.args),
260
- ];
261
- if (spec.env && Object.keys(spec.env).length) {
262
- lines.push('', `[${target.container}.${spec.name}.env]`);
263
- for (const [k, v] of Object.entries(spec.env)) lines.push(`${tomlKey(k)} = ${tomlString(v)}`);
264
- }
265
- return lines;
266
- }
267
- return target.entry(spec);
268
- }
269
-
270
- /**
271
- * @returns {{target: object, scope: string, file: string, exists: boolean,
272
- * changed: boolean, before: string, after: string, error: Error|null,
273
- * backupOf: string|null}}
274
- */
275
- function planTarget(target, scope, opts = {}) {
276
- const ctx = opts.ctx || hostCtx();
277
- const spec = opts.spec || buildSpec(opts.specOpts || {});
278
- const file = target.path(scope, ctx);
279
- const result = {
280
- target, scope, file, exists: false, changed: false,
281
- before: null, after: null, error: null, backupOf: null,
282
- };
283
-
284
- let text = null;
285
- try {
286
- const read = readText(file);
287
- text = read.text;
288
- result.exists = read.exists;
289
- } catch (err) {
290
- result.error = err;
291
- return result;
292
- }
293
- if (result.exists) {
294
- try { result.mode = fs.statSync(file).mode & 0o777; } catch { /* keep default */ }
295
- }
296
-
297
- if (target.kind === 'mcp-toml') {
298
- const section = `${target.container}.${spec.name}`;
299
- const body = renderEntry(target, spec);
300
- result.before = text;
301
- result.after = upsertTomlSection(text, section, body);
302
- result.changed = result.after !== (text || '');
303
- return result;
304
- }
305
-
306
- let doc;
307
- try {
308
- doc = parseJson(text, file);
309
- } catch (err) {
310
- result.error = err;
311
- return result;
312
- }
313
- if (doc === null || typeof doc !== 'object' || Array.isArray(doc)) {
314
- result.error = new Error(`${file} does not contain a JSON object — refusing to overwrite it`);
315
- return result;
316
- }
317
-
318
- setPath(doc, `${target.container}.${spec.name}`, renderEntry(target, spec));
319
- if (typeof target.extras === 'function') {
320
- const extra = target.extras(spec);
321
- if (extra && extra.inputs) {
322
- const existing = Array.isArray(doc.inputs) ? doc.inputs : [];
323
- for (const input of extra.inputs) {
324
- const at = existing.findIndex((e) => e && e.id === input.id);
325
- if (at === -1) existing.push(input);
326
- else existing[at] = input;
327
- }
328
- doc.inputs = existing;
329
- }
330
- }
331
-
332
- result.before = text;
333
- result.after = JSON.stringify(doc, null, 2) + '\n';
334
- result.changed = result.after !== (text || '');
335
- return result;
336
- }
337
-
338
- function planRemove(target, scope, opts = {}) {
339
- const ctx = opts.ctx || hostCtx();
340
- const spec = opts.spec || buildSpec(opts.specOpts || {});
341
- const file = target.path(scope, ctx);
342
- const result = {
343
- target, scope, file, exists: false, changed: false,
344
- before: null, after: null, error: null, backupOf: null,
345
- };
346
-
347
- let text = null;
348
- try {
349
- const read = readText(file);
350
- text = read.text;
351
- result.exists = read.exists;
352
- } catch (err) {
353
- result.error = err;
354
- return result;
355
- }
356
- if (!result.exists) return result;
357
- try { result.mode = fs.statSync(file).mode & 0o777; } catch { /* keep default */ }
358
-
359
- if (target.kind === 'mcp-toml') {
360
- result.before = text;
361
- result.after = removeTomlSection(text, `${target.container}.${spec.name}`);
362
- // The env subtable header is removed by the same sweep (it is a section
363
- // header directly following ours).
364
- result.changed = result.after !== text;
365
- return result;
366
- }
367
-
368
- let doc;
369
- try {
370
- doc = parseJson(text, file);
371
- } catch (err) {
372
- result.error = err;
373
- return result;
374
- }
375
- // Is there anything of ours to remove? Asking first is what makes removal
376
- // idempotent AND non-destructive: re-serialising a document we changed
377
- // nothing in would rewrite the user's whole file — reformatted, key order
378
- // possibly altered — and report it as a change.
379
- const entryPath = `${target.container}.${spec.name}`;
380
- const hadEntry = getPath(doc, entryPath) !== undefined;
381
- const hadInput = Array.isArray(doc.inputs) && doc.inputs.some((e) => e && e.id === 'aegis-api-key');
382
- if (!hadEntry && !hadInput) {
383
- result.before = text;
384
- result.after = text;
385
- result.changed = false;
386
- return result;
387
- }
388
-
389
- delPath(doc, entryPath, true);
390
- const inputs = Array.isArray(doc.inputs) ? doc.inputs.filter((e) => !(e && e.id === 'aegis-api-key')) : null;
391
- if (inputs) {
392
- if (inputs.length) doc.inputs = inputs;
393
- else delete doc.inputs;
394
- }
395
- result.before = text;
396
- result.after = JSON.stringify(doc, null, 2) + '\n';
397
- result.changed = result.after !== text;
398
- return result;
399
- }
400
-
401
- // ---------------------------------------------------------------------------
402
- // Writing
403
- // ---------------------------------------------------------------------------
404
-
405
- /**
406
- * The mode the written file gets.
407
- *
408
- * A file that may hold an API key (`--with-key`) is 0600 and nothing else. A
409
- * file that provably does not keeps whatever mode it already had — so
410
- * installing into an existing 0644 config leaves it readable by the user's own
411
- * editor, which is what it was. A newly created config gets 0644, the ordinary
412
- * case for a file that carries no secret by construction.
413
- */
414
- function modeFor(plan) {
415
- if (plan.withKey) return 0o600;
416
- return plan.mode || 0o644;
417
- }
418
-
419
- function apply(plan, opts = {}) {
420
- if (plan.error) return { ...plan, applied: false };
421
- if (!plan.changed) return { ...plan, applied: false };
422
- if (opts.dryRun) return { ...plan, applied: false, dryRun: true };
423
-
424
- plan.withKey = Boolean(opts.withKey);
425
- fs.mkdirSync(path.dirname(plan.file), { recursive: true });
426
- if (plan.exists && plan.before !== null) {
427
- const backup = `${plan.file}.aegis-backup-${Date.now()}`;
428
- fs.writeFileSync(backup, plan.before, { mode: 0o600 });
429
- plan.backupOf = backup;
430
- }
431
- const tmp = `${plan.file}.aegis-tmp-${process.pid}`;
432
- try {
433
- fs.writeFileSync(tmp, plan.after, { mode: 0o600 });
434
- fs.renameSync(tmp, plan.file);
435
- fs.chmodSync(plan.file, modeFor(plan));
436
- } finally {
437
- try { fs.unlinkSync(tmp); } catch { /* already renamed */ }
438
- }
439
- return { ...plan, applied: true };
440
- }
441
-
442
- // ---------------------------------------------------------------------------
443
- // Status
444
- // ---------------------------------------------------------------------------
445
-
446
- /**
447
- * Read back the entry this module would have written, from a TOML section.
448
- *
449
- * Only the keys `renderEntry` emits are modelled, and a section that is absent
450
- * returns null. This is deliberately not a TOML parser: the file belongs to
451
- * someone else's editor and the only question asked of it is "is our entry
452
- * here, and what does it point at".
453
- */
454
- function parseTomlEntry(text, section) {
455
- if (!text) return null;
456
- const escaped = section.replace(/[.[\]*+?^$(){}|]/g, '\\$&');
457
- const at = new RegExp('^\\s*\\[' + escaped + '\\]\\s*$', 'm').exec(text);
458
- if (!at) return null;
459
- // The section is a SPAN — the header, its body, and its own subtables — so
460
- // the slice has to run to the first header that is NOT ours. Stopping at the
461
- // next header of any kind (as this used to) truncated the body before
462
- // `[<section>.env]`, which is where `renderEntry` puts every env var: the
463
- // parse succeeded and reported an empty env, which is worse than failing.
464
- const rest = text.slice(at.index + at[0].length);
465
- const lines = rest.split('\n');
466
- const body = [];
467
- let i = 0;
468
- while (i < lines.length) {
469
- if (/^\s*\[/.test(lines[i]) && !ownedTomlHeader(lines[i], section)) break;
470
- body.push(lines[i]);
471
- i++;
472
- }
473
- const entry = { command: null, args: [], env: {} };
474
- const cmd = /^\s*command\s*=\s*"((?:[^"\\]|\\.)*)"/m.exec(body.join('\n'));
475
- if (cmd) entry.command = JSON.parse('"' + cmd[1] + '"');
476
- const args = /^\s*args\s*=\s*\[([\s\S]*?)\]/m.exec(body.join('\n'));
477
- if (args) {
478
- entry.args = [...args[1].matchAll(/"((?:[^"\\]|\\.)*)"/g)].map((m) => JSON.parse('"' + m[1] + '"'));
479
- }
480
- for (const m of body.join('\n').matchAll(/^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*"((?:[^"\\]|\\.)*)"\s*$/gm)) {
481
- if (m[1] !== 'command' && m[1] !== 'args') entry.env[m[1]] = JSON.parse('"' + m[2] + '"');
482
- }
483
- return entry;
484
- }
485
-
486
- /**
487
- * The script an entry names, if any.
488
- *
489
- * `spec.js` always writes `command: node` plus an absolute path to
490
- * `mcp/server.js`, so the script is the first argument that looks like one. A
491
- * user who hand-edited their config to `npx aegiscode-mcp` has no such
492
- * argument and gets `null` — "cannot tell", which is honest, not "broken".
493
- */
494
- function entryServerPath(entry) {
495
- if (!entry) return null;
496
- const args = Array.isArray(entry.args) ? entry.args : [];
497
- return args.find((a) => typeof a === 'string' && /\.(js|mjs|cjs)$/.test(a)) || null;
498
- }
499
-
500
- /**
501
- * Host-expanded placeholders — `${CLAUDE_PLUGIN_ROOT}`, `$HOME`,
502
- * `%APPDATA%`.
503
- *
504
- * The EDITOR substitutes these at load time, not us. A plugin `.mcp.json`
505
- * ships `${CLAUDE_PLUGIN_ROOT}/mcp/server.js` precisely so one file works on
506
- * every machine. Existence is therefore not knowable from here, and crying
507
- * "the server is gone" would push a user to overwrite a deliberately portable
508
- * config with a machine-absolute path — the exact portability the placeholder
509
- * exists to preserve.
510
- */
511
- const HOST_VAR_RE = /\$\{?[A-Za-z_][A-Za-z0-9_]*\}?|%[A-Za-z_][A-Za-z0-9_]*%/;
512
-
513
- function hasHostVar(value) {
514
- return typeof value === 'string' && HOST_VAR_RE.test(value);
515
- }
516
-
517
- /**
518
- * Per target+scope: does the config exist, is our entry in it, and does the
519
- * command it names still exist on disk? The last question is the one that
520
- * catches a moved checkout — the silent failure this whole module is written
521
- * against.
522
- */
523
- function status(ids, opts = {}) {
524
- const ctx = opts.ctx || hostCtx();
525
- const spec = opts.spec || buildSpec(opts.specOpts || {});
526
- const targets = ids && ids.length ? ids.map((id) => getTarget(id)).filter(Boolean) : TARGETS;
527
- const rows = [];
528
-
529
- for (const target of targets) {
530
- for (const scope of target.scopes || ['user']) {
531
- const file = target.path(scope, ctx);
532
- const row = { id: target.id, label: target.label, scope, file, exists: false, installed: false, entry: null, error: null, docs: target.docs, verified: target.verified };
533
- let read;
534
- try {
535
- read = readText(file);
536
- } catch (err) {
537
- row.error = err.message;
538
- rows.push(row);
539
- continue;
540
- }
541
- row.exists = read.exists;
542
- if (read.exists && read.text !== null) {
543
- if (target.kind === 'mcp-toml') {
544
- row.entry = parseTomlEntry(read.text, `${target.container}.${spec.name}`);
545
- row.installed = Boolean(row.entry);
546
- } else {
547
- try {
548
- const doc = parseJson(read.text, file);
549
- row.entry = getPath(doc, `${target.container}.${spec.name}`) || null;
550
- row.installed = Boolean(row.entry);
551
- } catch (err) {
552
- row.error = err.message;
553
- }
554
- }
555
- }
556
- // The question the editor itself never asks: the config still names a
557
- // file, but does that file still exist? A checkout that moved, an npm
558
- // prefix that changed, or a `git clean` all leave a config that loads
559
- // fine and fails silently at tool-call time. Surfaced here so `status`
560
- // can say "installed, but pointing at nothing".
561
- if (row.installed) {
562
- row.serverPath = entryServerPath(row.entry);
563
- row.serverUnverifiable = hasHostVar(row.serverPath);
564
- row.serverExists =
565
- row.serverPath && !row.serverUnverifiable ? isFile(row.serverPath) : null;
566
- }
567
- rows.push(row);
568
- }
569
- }
570
- return rows;
571
- }
572
-
573
- /**
574
- * Which hosts are actually present on this machine — the input to "offer
575
- * something sensible" so a user is not shown thirteen hosts they do not have.
576
- *
577
- * Two signals count as present: a config file we already know how to write, or
578
- * the editor's own config DIRECTORY existing. The second matters most — the
579
- * whole point of this command is offering AEGIS to an editor that has never
580
- * heard of MCP, and that editor has no `mcp.json` yet.
581
- */
582
- function detected(opts = {}) {
583
- const ctx = opts.ctx || hostCtx();
584
- const found = new Set();
585
- for (const target of TARGETS) {
586
- for (const scope of target.scopes || ['user']) {
587
- try {
588
- fs.accessSync(target.path(scope, ctx));
589
- found.add(target.id);
590
- } catch { /* not installed */ }
591
- }
592
- }
593
- for (const [variant, id] of [
594
- ['Code', 'vscode'],
595
- ['Code - Insiders', 'vscode-insiders'],
596
- ['VSCodium', 'vscodium'],
597
- ['Cursor', 'cursor'],
598
- ]) {
599
- try {
600
- fs.accessSync(path.join(appConfig(ctx), variant));
601
- found.add(id);
602
- } catch { /* not installed */ }
603
- }
604
- for (const [rel, id] of [
605
- [['.codeium'], 'windsurf'],
606
- [['.gemini'], 'gemini'],
607
- [['.codex'], 'codex'],
608
- [['.continue'], 'continue'],
609
- [['.junie'], 'junie'],
610
- [['.cursor'], 'cursor'],
611
- ]) {
612
- try {
613
- fs.accessSync(path.join(ctx.home || ctx.env.HOME || ctx.env.USERPROFILE, ...rel));
614
- found.add(id);
615
- } catch { /* not installed */ }
616
- }
617
- return found;
618
- }
619
-
620
- module.exports = {
621
- hostCtx,
622
- planTarget,
623
- planRemove,
624
- apply,
625
- status,
626
- detected,
627
- renderEntry,
628
- entryServerPath,
629
- hasHostVar,
630
- parseTomlEntry,
631
- upsertTomlSection,
632
- removeTomlSection,
633
- setPath,
634
- getPath,
635
- delPath,
636
- readText,
637
- resolveServer,
638
- };
1
+ "use strict";const fs=require("node:fs"),path=require("node:path"),{TARGETS:TARGETS,getTarget:getTarget,appConfig:appConfig}=require("./targets.js"),{buildSpec:buildSpec,resolveServer:resolveServer}=require("./spec.js");function hostCtx(e={}){return{env:process.env,platform:process.platform,home:null,cwd:process.cwd(),...e}}function readText(e){try{return{text:fs.readFileSync(e,"utf8"),exists:!0}}catch(e){if("ENOENT"===e.code)return{text:null,exists:!1};throw e}}function isFile(e){try{return fs.statSync(e).isFile()}catch{return!1}}function parseJson(e,t){if(null===e||""===e.trim())return{};try{return JSON.parse(e)}catch(e){throw new Error(`${t} is not valid JSON (${e.message}) — refusing to overwrite it`)}}function setPath(e,t,r){const n=t.split(".");let s=e;for(const e of n.slice(0,-1))(null===s[e]||"object"!=typeof s[e]||Array.isArray(s[e]))&&(s[e]={}),s=s[e];return s[n[n.length-1]]=r,e}function getPath(e,t){let r=e;for(const e of t.split(".")){if(null===r||"object"!=typeof r)return;r=r[e]}return r}function delPath(e,t,r=!1){const n=t.split("."),s=[];let o=e;for(const t of n.slice(0,-1)){if(null===o||"object"!=typeof o)return e;s.push([o,t]),o=o[t]}if(o&&"object"==typeof o&&delete o[n[n.length-1]],!r)return e;for(let e=s.length-1;e>=0;e--){const[t,r]=s[e],n=t[r];if(!n||"object"!=typeof n||0!==Object.keys(n).length)break;delete t[r]}return e}const TOML_BARE=/^[A-Za-z0-9_-]+$/;function tomlKey(e){return TOML_BARE.test(e)?e:JSON.stringify(e)}function tomlString(e){return JSON.stringify(String(e))}function tomlArray(e){return`[${e.map(tomlString).join(", ")}]`}function tomlHeaderName(e){const t=e.trim();return/^\[/.test(t)?t.replace(/^\[+\s*/,"").replace(/\s*\]+$/,""):null}function ownedTomlHeader(e,t){const r=tomlHeaderName(e);return null!==r&&(r===t||r.startsWith(`${t}.`))}function upsertTomlSection(e,t,r){const n=`[${t}]`,s=(e||"").split("\n"),o=[];let i=!1,a=0;for(;a<s.length;)if(s[a].trim()!==n)o.push(s[a]),a++;else{for(o.push(n,...r,""),i=!0,a++;a<s.length&&!/^\s*\[/.test(s[a]);)a++;for(;a<s.length&&ownedTomlHeader(s[a],t);)for(a++;a<s.length&&!/^\s*\[/.test(s[a]);)a++}if(!i){for(;o.length&&""===o[o.length-1].trim();)o.pop();o.length&&o.push(""),o.push(n,...r,"")}return o.join("\n")}function removeTomlSection(e,t){const r=`[${t}]`,n=(e||"").split("\n"),s=[];let o=0;for(;o<n.length;)if(n[o].trim()!==r)s.push(n[o]),o++;else{for(o++;o<n.length&&!/^\s*\[/.test(n[o]);)o++;for(;o<n.length&&ownedTomlHeader(n[o],t);)for(o++;o<n.length&&!/^\s*\[/.test(n[o]);)o++}return s.join("\n")}function renderEntry(e,t){if("mcp-toml"===e.kind){const r=[`# Added by \`aegiscode mcp install ${e.id}\`. Key resolution lives in`,"# ~/.aegiscode/.env and the 0600 store `aegiscode login` writes.","command = "+tomlString(t.command),"args = "+tomlArray(t.args)];if(t.env&&Object.keys(t.env).length){r.push("",`[${e.container}.${t.name}.env]`);for(const[e,n]of Object.entries(t.env))r.push(`${tomlKey(e)} = ${tomlString(n)}`)}return r}return e.entry(t)}function planTarget(e,t,r={}){const n=r.ctx||hostCtx(),s=r.spec||buildSpec(r.specOpts||{}),o=e.path(t,n),i={target:e,scope:t,file:o,exists:!1,changed:!1,before:null,after:null,error:null,backupOf:null};let a,c=null;try{const e=readText(o);c=e.text,i.exists=e.exists}catch(e){return i.error=e,i}if(i.exists)try{i.mode=511&fs.statSync(o).mode}catch{}if("mcp-toml"===e.kind){const t=`${e.container}.${s.name}`,r=renderEntry(e,s);return i.before=c,i.after=upsertTomlSection(c,t,r),i.changed=i.after!==(c||""),i}try{a=parseJson(c,o)}catch(e){return i.error=e,i}if(null===a||"object"!=typeof a||Array.isArray(a))return i.error=new Error(`${o} does not contain a JSON object — refusing to overwrite it`),i;if(setPath(a,`${e.container}.${s.name}`,renderEntry(e,s)),"function"==typeof e.extras){const t=e.extras(s);if(t&&t.inputs){const e=Array.isArray(a.inputs)?a.inputs:[];for(const r of t.inputs){const t=e.findIndex((e=>e&&e.id===r.id));-1===t?e.push(r):e[t]=r}a.inputs=e}}return i.before=c,i.after=JSON.stringify(a,null,2)+"\n",i.changed=i.after!==(c||""),i}function planRemove(e,t,r={}){const n=r.ctx||hostCtx(),s=r.spec||buildSpec(r.specOpts||{}),o=e.path(t,n),i={target:e,scope:t,file:o,exists:!1,changed:!1,before:null,after:null,error:null,backupOf:null};let a,c=null;try{const e=readText(o);c=e.text,i.exists=e.exists}catch(e){return i.error=e,i}if(!i.exists)return i;try{i.mode=511&fs.statSync(o).mode}catch{}if("mcp-toml"===e.kind)return i.before=c,i.after=removeTomlSection(c,`${e.container}.${s.name}`),i.changed=i.after!==c,i;try{a=parseJson(c,o)}catch(e){return i.error=e,i}const l=`${e.container}.${s.name}`,u=void 0!==getPath(a,l),f=Array.isArray(a.inputs)&&a.inputs.some((e=>e&&"aegis-api-key"===e.id));if(!u&&!f)return i.before=c,i.after=c,i.changed=!1,i;delPath(a,l,!0);const p=Array.isArray(a.inputs)?a.inputs.filter((e=>!(e&&"aegis-api-key"===e.id))):null;return p&&(p.length?a.inputs=p:delete a.inputs),i.before=c,i.after=JSON.stringify(a,null,2)+"\n",i.changed=i.after!==c,i}function modeFor(e){return e.withKey?384:e.mode||420}function apply(e,t={}){if(e.error)return{...e,applied:!1};if(!e.changed)return{...e,applied:!1};if(t.dryRun)return{...e,applied:!1,dryRun:!0};if(e.withKey=Boolean(t.withKey),fs.mkdirSync(path.dirname(e.file),{recursive:!0}),e.exists&&null!==e.before){const t=`${e.file}.aegis-backup-${Date.now()}`;fs.writeFileSync(t,e.before,{mode:384}),e.backupOf=t}const r=`${e.file}.aegis-tmp-${process.pid}`;try{fs.writeFileSync(r,e.after,{mode:384}),fs.renameSync(r,e.file),fs.chmodSync(e.file,modeFor(e))}finally{try{fs.unlinkSync(r)}catch{}}return{...e,applied:!0}}function parseTomlEntry(e,t){if(!e)return null;const r=t.replace(/[.[\]*+?^$(){}|]/g,"\\$&"),n=new RegExp("^\\s*\\["+r+"\\]\\s*$","m").exec(e);if(!n)return null;const s=e.slice(n.index+n[0].length).split("\n"),o=[];let i=0;for(;i<s.length&&(!/^\s*\[/.test(s[i])||ownedTomlHeader(s[i],t));)o.push(s[i]),i++;const a={command:null,args:[],env:{}},c=/^\s*command\s*=\s*"((?:[^"\\]|\\.)*)"/m.exec(o.join("\n"));c&&(a.command=JSON.parse('"'+c[1]+'"'));const l=/^\s*args\s*=\s*\[([\s\S]*?)\]/m.exec(o.join("\n"));l&&(a.args=[...l[1].matchAll(/"((?:[^"\\]|\\.)*)"/g)].map((e=>JSON.parse('"'+e[1]+'"'))));for(const e of o.join("\n").matchAll(/^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*"((?:[^"\\]|\\.)*)"\s*$/gm))"command"!==e[1]&&"args"!==e[1]&&(a.env[e[1]]=JSON.parse('"'+e[2]+'"'));return a}function entryServerPath(e){return e&&(Array.isArray(e.args)?e.args:[]).find((e=>"string"==typeof e&&/\.(js|mjs|cjs)$/.test(e)))||null}const HOST_VAR_RE=/\$\{?[A-Za-z_][A-Za-z0-9_]*\}?|%[A-Za-z_][A-Za-z0-9_]*%/;function hasHostVar(e){return"string"==typeof e&&HOST_VAR_RE.test(e)}function status(e,t={}){const r=t.ctx||hostCtx(),n=t.spec||buildSpec(t.specOpts||{}),s=e&&e.length?e.map((e=>getTarget(e))).filter(Boolean):TARGETS,o=[];for(const t of s)for(const s of t.scopes||["user"]){const i=t.path(s,r),a={id:t.id,label:t.label,scope:s,file:i,exists:!1,installed:!1,entry:null,error:null,docs:t.docs,verified:t.verified};let c;try{c=readText(i)}catch(e){a.error=e.message,o.push(a);continue}if(a.exists=c.exists,c.exists&&null!==c.text)if("mcp-toml"===t.kind)a.entry=parseTomlEntry(c.text,`${t.container}.${n.name}`),a.installed=Boolean(a.entry);else try{const e=parseJson(c.text,i);a.entry=getPath(e,`${t.container}.${n.name}`)||null,a.installed=Boolean(a.entry)}catch(e){a.error=e.message}a.installed&&(a.serverPath=entryServerPath(a.entry),a.serverUnverifiable=hasHostVar(a.serverPath),a.serverExists=a.serverPath&&!a.serverUnverifiable?isFile(a.serverPath):null),o.push(a)}return o}function detected(e={}){const t=e.ctx||hostCtx(),r=new Set;for(const e of TARGETS)for(const n of e.scopes||["user"])try{fs.accessSync(e.path(n,t)),r.add(e.id)}catch{}for(const[e,n]of[["Code","vscode"],["Code - Insiders","vscode-insiders"],["VSCodium","vscodium"],["Cursor","cursor"]])try{fs.accessSync(path.join(appConfig(t),e)),r.add(n)}catch{}for(const[e,n]of[[[".codeium"],"windsurf"],[[".gemini"],"gemini"],[[".codex"],"codex"],[[".continue"],"continue"],[[".junie"],"junie"],[[".cursor"],"cursor"]])try{fs.accessSync(path.join(t.home||t.env.HOME||t.env.USERPROFILE,...e)),r.add(n)}catch{}return r}module.exports={hostCtx:hostCtx,planTarget:planTarget,planRemove:planRemove,apply:apply,status:status,detected:detected,renderEntry:renderEntry,entryServerPath:entryServerPath,hasHostVar:hasHostVar,parseTomlEntry:parseTomlEntry,upsertTomlSection:upsertTomlSection,removeTomlSection:removeTomlSection,setPath:setPath,getPath:getPath,delPath:delPath,readText:readText,resolveServer:resolveServer};