aegisone 0.0.0-stage → 1.0.3

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 (266) hide show
  1. package/README.md +98 -2
  2. package/bin/aegis.js +295 -0
  3. package/install.ps1 +151 -0
  4. package/install.sh +178 -0
  5. package/package.json +44 -4
  6. package/scripts/bump.mjs +184 -0
  7. package/scripts/bundle.js +126 -0
  8. package/scripts/predist.mjs +673 -0
  9. package/src/child.js +163 -0
  10. package/src/dispatch.js +265 -0
  11. package/src/doctor.js +636 -0
  12. package/src/host.js +108 -0
  13. package/src/permissions.js +239 -0
  14. package/src/probes.js +156 -0
  15. package/src/release.js +397 -0
  16. package/vendor/cli/LICENSE +661 -0
  17. package/vendor/cli/README.md +745 -0
  18. package/vendor/cli/bin/aegiscode.js +742 -0
  19. package/vendor/cli/package.json +42 -0
  20. package/vendor/cli/scripts/check.mjs +50 -0
  21. package/vendor/cli/scripts/demo.mjs +92 -0
  22. package/vendor/cli/scripts/predist.mjs +48 -0
  23. package/vendor/cli/scripts/runtests.mjs +54 -0
  24. package/vendor/cli/src/agents.js +136 -0
  25. package/vendor/cli/src/app.js +2164 -0
  26. package/vendor/cli/src/art.js +286 -0
  27. package/vendor/cli/src/autonomous.js +468 -0
  28. package/vendor/cli/src/caps.js +876 -0
  29. package/vendor/cli/src/chatflow.js +2389 -0
  30. package/vendor/cli/src/checkpoint.js +87 -0
  31. package/vendor/cli/src/clipboard.js +421 -0
  32. package/vendor/cli/src/cloudsync.js +525 -0
  33. package/vendor/cli/src/commands.js +3014 -0
  34. package/vendor/cli/src/config.js +527 -0
  35. package/vendor/cli/src/credentials.js +30 -0
  36. package/vendor/cli/src/deps.js +106 -0
  37. package/vendor/cli/src/devrun.js +184 -0
  38. package/vendor/cli/src/diff.js +330 -0
  39. package/vendor/cli/src/diffview.js +293 -0
  40. package/vendor/cli/src/engine.js +142 -0
  41. package/vendor/cli/src/entitlement.js +320 -0
  42. package/vendor/cli/src/events.js +694 -0
  43. package/vendor/cli/src/export.js +64 -0
  44. package/vendor/cli/src/fingerprint.js +559 -0
  45. package/vendor/cli/src/format.js +84 -0
  46. package/vendor/cli/src/fuzzy.js +116 -0
  47. package/vendor/cli/src/gate.js +45 -0
  48. package/vendor/cli/src/history.js +398 -0
  49. package/vendor/cli/src/init.js +172 -0
  50. package/vendor/cli/src/input.js +136 -0
  51. package/vendor/cli/src/keys.js +153 -0
  52. package/vendor/cli/src/markdown.js +303 -0
  53. package/vendor/cli/src/mcp.js +683 -0
  54. package/vendor/cli/src/models.js +409 -0
  55. package/vendor/cli/src/naming.js +226 -0
  56. package/vendor/cli/src/overlays.js +338 -0
  57. package/vendor/cli/src/panels.js +1402 -0
  58. package/vendor/cli/src/permissions.js +237 -0
  59. package/vendor/cli/src/ping.js +223 -0
  60. package/vendor/cli/src/presence.js +235 -0
  61. package/vendor/cli/src/render.js +469 -0
  62. package/vendor/cli/src/screen.js +504 -0
  63. package/vendor/cli/src/screens.js +776 -0
  64. package/vendor/cli/src/secret.js +56 -0
  65. package/vendor/cli/src/securefs.js +356 -0
  66. package/vendor/cli/src/settings.js +152 -0
  67. package/vendor/cli/src/shared.js +49 -0
  68. package/vendor/cli/src/sharedpaths.js +50 -0
  69. package/vendor/cli/src/signup.js +153 -0
  70. package/vendor/cli/src/summarize.js +92 -0
  71. package/vendor/cli/src/system.js +37 -0
  72. package/vendor/cli/src/theme.js +567 -0
  73. package/vendor/cli/src/title.js +217 -0
  74. package/vendor/cli/src/todos.js +109 -0
  75. package/vendor/cli/src/tokens.js +230 -0
  76. package/vendor/cli/src/topup.js +207 -0
  77. package/vendor/cli/src/update.js +87 -0
  78. package/vendor/cli/vendor/client/aegis.js +1738 -0
  79. package/vendor/cli/vendor/client/attest.js +439 -0
  80. package/vendor/cli/vendor/client/authorship-key.js +407 -0
  81. package/vendor/cli/vendor/client/auto-provision.js +52 -0
  82. package/vendor/cli/vendor/client/brain-catalog.js +265 -0
  83. package/vendor/cli/vendor/client/byok-catalog.js +192 -0
  84. package/vendor/cli/vendor/client/credentials.js +478 -0
  85. package/vendor/cli/vendor/client/device-fingerprint.js +145 -0
  86. package/vendor/cli/vendor/client/env-file.js +1016 -0
  87. package/vendor/cli/vendor/client/fingerprint.js +1061 -0
  88. package/vendor/cli/vendor/client/foreign-memory.js +666 -0
  89. package/vendor/cli/vendor/client/hooks.js +427 -0
  90. package/vendor/cli/vendor/client/platform.js +934 -0
  91. package/vendor/cli/vendor/client/prefs.js +348 -0
  92. package/vendor/cli/vendor/client/presence-constants.js +104 -0
  93. package/vendor/cli/vendor/client/presence.js +435 -0
  94. package/vendor/cli/vendor/client/record-vault.js +834 -0
  95. package/vendor/cli/vendor/client/session-store.js +545 -0
  96. package/vendor/cli/vendor/client/topup.js +294 -0
  97. package/vendor/cli/vendor/client/touch.js +455 -0
  98. package/vendor/cli/vendor/client/update.js +343 -0
  99. package/vendor/cli/vendor/covenant/README.md +21 -0
  100. package/vendor/cli/vendor/covenant/aegis.seal +177 -0
  101. package/vendor/cli/vendor/desktop/lib/local/aegis-seal.mjs +236 -0
  102. package/vendor/cli/vendor/desktop/lib/local/agents.js +102 -0
  103. package/vendor/cli/vendor/desktop/lib/local/autonomous.js +921 -0
  104. package/vendor/cli/vendor/desktop/lib/local/context.js +92 -0
  105. package/vendor/cli/vendor/desktop/lib/local/covenant.js +562 -0
  106. package/vendor/cli/vendor/desktop/lib/local/engine.js +2155 -0
  107. package/vendor/cli/vendor/desktop/lib/local/entitlement.js +568 -0
  108. package/vendor/cli/vendor/desktop/lib/local/git-scope.js +225 -0
  109. package/vendor/cli/vendor/desktop/lib/local/local.js +2132 -0
  110. package/vendor/cli/vendor/desktop/lib/local/prompt.js +242 -0
  111. package/vendor/cli/vendor/desktop/lib/local/queue.js +557 -0
  112. package/vendor/cli/vendor/desktop/lib/local/session-rounds.js +205 -0
  113. package/vendor/cli/vendor/desktop/lib/local/shell.js +603 -0
  114. package/vendor/cli/vendor/desktop/lib/local/tools.js +1197 -0
  115. package/vendor/cli/vendor/desktop/lib/local/turn-guard.js +297 -0
  116. package/vendor/cli/vendor/desktop/lib/local/worktree-lock.js +232 -0
  117. package/vendor/cli/vendor/desktop/lib/settings.js +846 -0
  118. package/vendor/cli/vendor/desktop/renderer/usage.js +964 -0
  119. package/vendor/cli/vendor/hosts/install.js +638 -0
  120. package/vendor/cli/vendor/hosts/openai-shim.js +516 -0
  121. package/vendor/cli/vendor/hosts/spec.js +164 -0
  122. package/vendor/cli/vendor/hosts/targets.js +346 -0
  123. package/vendor/cli/vendor/mcp/server.js +217 -0
  124. package/vendor/cli/vendor/mcp/tools.js +405 -0
  125. package/vendor/cli/vendor/tools/agent-gate.mjs +1180 -0
  126. package/vendor/desktop/README.md +365 -0
  127. package/vendor/desktop/bin/aegis.js +30 -0
  128. package/vendor/desktop/lib/auto.js +423 -0
  129. package/vendor/desktop/lib/avatar/companion.js +695 -0
  130. package/vendor/desktop/lib/avatar/cosmetics.js +529 -0
  131. package/vendor/desktop/lib/avatar/events.js +341 -0
  132. package/vendor/desktop/lib/avatar/holder-turn.js +347 -0
  133. package/vendor/desktop/lib/avatar/holders.js +609 -0
  134. package/vendor/desktop/lib/avatar/identity.js +638 -0
  135. package/vendor/desktop/lib/avatar/level.js +365 -0
  136. package/vendor/desktop/lib/avatar/mirror.js +521 -0
  137. package/vendor/desktop/lib/avatar/packs/README.md +47 -0
  138. package/vendor/desktop/lib/avatar/packs/core-wardrobe.pack.json +15 -0
  139. package/vendor/desktop/lib/avatar/packs/local-voice-core.pack.json +16 -0
  140. package/vendor/desktop/lib/avatar/packs/seasonal-winter.pack.json +14 -0
  141. package/vendor/desktop/lib/avatar/persona.js +385 -0
  142. package/vendor/desktop/lib/avatar/profile.js +974 -0
  143. package/vendor/desktop/lib/avatar/register.js +304 -0
  144. package/vendor/desktop/lib/avatar/store.js +469 -0
  145. package/vendor/desktop/lib/avatar/tiers.js +35 -0
  146. package/vendor/desktop/lib/avatar/transfer.js +412 -0
  147. package/vendor/desktop/lib/avatar/turn.js +213 -0
  148. package/vendor/desktop/lib/avatar/voice.js +325 -0
  149. package/vendor/desktop/lib/avatar/xp.js +401 -0
  150. package/vendor/desktop/lib/deep-link.js +83 -0
  151. package/vendor/desktop/lib/fingerprint.js +327 -0
  152. package/vendor/desktop/lib/local/aegis-seal.mjs +236 -0
  153. package/vendor/desktop/lib/local/agents.js +102 -0
  154. package/vendor/desktop/lib/local/autonomous.js +921 -0
  155. package/vendor/desktop/lib/local/context.js +92 -0
  156. package/vendor/desktop/lib/local/covenant.js +562 -0
  157. package/vendor/desktop/lib/local/engine.js +2155 -0
  158. package/vendor/desktop/lib/local/entitlement.js +568 -0
  159. package/vendor/desktop/lib/local/git-scope.js +225 -0
  160. package/vendor/desktop/lib/local/local.js +2132 -0
  161. package/vendor/desktop/lib/local/prompt.js +242 -0
  162. package/vendor/desktop/lib/local/queue.js +557 -0
  163. package/vendor/desktop/lib/local/session-rounds.js +205 -0
  164. package/vendor/desktop/lib/local/shell.js +603 -0
  165. package/vendor/desktop/lib/local/telemetry.js +467 -0
  166. package/vendor/desktop/lib/local/tools.js +1197 -0
  167. package/vendor/desktop/lib/local/turn-guard.js +297 -0
  168. package/vendor/desktop/lib/local/worktree-lock.js +232 -0
  169. package/vendor/desktop/lib/provider-key-mirror.js +136 -0
  170. package/vendor/desktop/lib/quick-launcher.js +81 -0
  171. package/vendor/desktop/lib/settings.js +846 -0
  172. package/vendor/desktop/lib/sync/memory-queue.js +57 -0
  173. package/vendor/desktop/lib/sync/persist-gate.js +145 -0
  174. package/vendor/desktop/lib/sync/sessions.js +103 -0
  175. package/vendor/desktop/lib/window-state.js +63 -0
  176. package/vendor/desktop/main.js +3726 -0
  177. package/vendor/desktop/package.json +70 -0
  178. package/vendor/desktop/preload.js +557 -0
  179. package/vendor/desktop/renderer/app.js +5080 -0
  180. package/vendor/desktop/renderer/avatar/assemble.js +332 -0
  181. package/vendor/desktop/renderer/avatar/avatar.css +260 -0
  182. package/vendor/desktop/renderer/avatar/avatar.js +377 -0
  183. package/vendor/desktop/renderer/avatar/cards.js +138 -0
  184. package/vendor/desktop/renderer/avatar/hud.js +203 -0
  185. package/vendor/desktop/renderer/avatar/machine.js +210 -0
  186. package/vendor/desktop/renderer/avatar/pane.js +436 -0
  187. package/vendor/desktop/renderer/avatar/parts.js +434 -0
  188. package/vendor/desktop/renderer/budget.js +156 -0
  189. package/vendor/desktop/renderer/diff.js +356 -0
  190. package/vendor/desktop/renderer/diffview.js +333 -0
  191. package/vendor/desktop/renderer/fingerprint.css +143 -0
  192. package/vendor/desktop/renderer/fingerprint.js +583 -0
  193. package/vendor/desktop/renderer/fonts/4iCs6KVjbNBYlgoKcQ72j00.woff2 +0 -0
  194. package/vendor/desktop/renderer/fonts/4iCs6KVjbNBYlgoKcg72j00.woff2 +0 -0
  195. package/vendor/desktop/renderer/fonts/4iCs6KVjbNBYlgoKcw72j00.woff2 +0 -0
  196. package/vendor/desktop/renderer/fonts/4iCs6KVjbNBYlgoKew72j00.woff2 +0 -0
  197. package/vendor/desktop/renderer/fonts/4iCs6KVjbNBYlgoKfA72j00.woff2 +0 -0
  198. package/vendor/desktop/renderer/fonts/4iCs6KVjbNBYlgoKfw72.woff2 +0 -0
  199. package/vendor/desktop/renderer/fonts/4iCu6KVjbNBYlgoKej70l0k.woff2 +0 -0
  200. package/vendor/desktop/renderer/fonts/4iCu6KVjbNBYlgoKej73l0mwFg.woff2 +0 -0
  201. package/vendor/desktop/renderer/fonts/4iCu6KVjbNBYlgoKej74l0mwFg.woff2 +0 -0
  202. package/vendor/desktop/renderer/fonts/4iCu6KVjbNBYlgoKej75l0mwFg.woff2 +0 -0
  203. package/vendor/desktop/renderer/fonts/4iCu6KVjbNBYlgoKej76l0mwFg.woff2 +0 -0
  204. package/vendor/desktop/renderer/fonts/4iCu6KVjbNBYlgoKej7wl0mwFg.woff2 +0 -0
  205. package/vendor/desktop/renderer/fonts/4iCv6KVjbNBYlgoCjC3js2yNL4U.woff2 +0 -0
  206. package/vendor/desktop/renderer/fonts/4iCv6KVjbNBYlgoCjC3jsGyN.woff2 +0 -0
  207. package/vendor/desktop/renderer/fonts/4iCv6KVjbNBYlgoCjC3jtGyNL4U.woff2 +0 -0
  208. package/vendor/desktop/renderer/fonts/4iCv6KVjbNBYlgoCjC3jvGyNL4U.woff2 +0 -0
  209. package/vendor/desktop/renderer/fonts/4iCv6KVjbNBYlgoCjC3jvWyNL4U.woff2 +0 -0
  210. package/vendor/desktop/renderer/fonts/4iCv6KVjbNBYlgoCjC3jvmyNL4U.woff2 +0 -0
  211. package/vendor/desktop/renderer/fonts/4iCv6KVjbNBYlgoCxCvjs2yNL4U.woff2 +0 -0
  212. package/vendor/desktop/renderer/fonts/4iCv6KVjbNBYlgoCxCvjsGyN.woff2 +0 -0
  213. package/vendor/desktop/renderer/fonts/4iCv6KVjbNBYlgoCxCvjtGyNL4U.woff2 +0 -0
  214. package/vendor/desktop/renderer/fonts/4iCv6KVjbNBYlgoCxCvjvGyNL4U.woff2 +0 -0
  215. package/vendor/desktop/renderer/fonts/4iCv6KVjbNBYlgoCxCvjvWyNL4U.woff2 +0 -0
  216. package/vendor/desktop/renderer/fonts/4iCv6KVjbNBYlgoCxCvjvmyNL4U.woff2 +0 -0
  217. package/vendor/desktop/renderer/fonts/8vIH7w4qzmVxm25L9Hz_.woff2 +0 -0
  218. package/vendor/desktop/renderer/fonts/8vIH7w4qzmVxm2BL9A.woff2 +0 -0
  219. package/vendor/desktop/renderer/fonts/8vIH7w4qzmVxm2NL9Hz_.woff2 +0 -0
  220. package/vendor/desktop/renderer/fonts/NOTICE.md +57 -0
  221. package/vendor/desktop/renderer/fonts/aFTR7PB1QTsUX8KYvrGyEY2tbZX9.woff2 +0 -0
  222. package/vendor/desktop/renderer/fonts/aFTR7PB1QTsUX8KYvrGyEYOtbQ.woff2 +0 -0
  223. package/vendor/desktop/renderer/fonts/aFTR7PB1QTsUX8KYvumzEY2tbZX9.woff2 +0 -0
  224. package/vendor/desktop/renderer/fonts/aFTR7PB1QTsUX8KYvumzEYOtbQ.woff2 +0 -0
  225. package/vendor/desktop/renderer/fonts/aFTU7PB1QTsUX8KYthSQBLyM.woff2 +0 -0
  226. package/vendor/desktop/renderer/fonts/aFTU7PB1QTsUX8KYthqQBA.woff2 +0 -0
  227. package/vendor/desktop/renderer/fonts/aFTW7PB1QTsUX8KYth-gBqSI.woff2 +0 -0
  228. package/vendor/desktop/renderer/fonts/aFTW7PB1QTsUX8KYth-gCKSIUKw.woff2 +0 -0
  229. package/vendor/desktop/renderer/fonts/fonts.css +368 -0
  230. package/vendor/desktop/renderer/index.html +864 -0
  231. package/vendor/desktop/renderer/markdown.js +165 -0
  232. package/vendor/desktop/renderer/quick.css +151 -0
  233. package/vendor/desktop/renderer/quick.html +42 -0
  234. package/vendor/desktop/renderer/quick.js +188 -0
  235. package/vendor/desktop/renderer/stream-policy.js +281 -0
  236. package/vendor/desktop/renderer/style.css +2519 -0
  237. package/vendor/desktop/renderer/transcript-view.js +320 -0
  238. package/vendor/desktop/renderer/usage.js +964 -0
  239. package/vendor/desktop/renderer/vendor/NOTICE.md +20 -0
  240. package/vendor/desktop/renderer/vendor/aegis-highlight.js +135 -0
  241. package/vendor/desktop/renderer/vendor/marked.umd.js +80 -0
  242. package/vendor/desktop/renderer/vendor/purify.min.js +3 -0
  243. package/vendor/desktop/vendor/aegis.js +1738 -0
  244. package/vendor/desktop/vendor/agent-gate.mjs +1180 -0
  245. package/vendor/desktop/vendor/attest.js +439 -0
  246. package/vendor/desktop/vendor/authorship-key.js +407 -0
  247. package/vendor/desktop/vendor/auto-provision.js +52 -0
  248. package/vendor/desktop/vendor/brain-catalog.js +265 -0
  249. package/vendor/desktop/vendor/byok-catalog.js +192 -0
  250. package/vendor/desktop/vendor/covenant/README.md +21 -0
  251. package/vendor/desktop/vendor/covenant/aegis.seal +177 -0
  252. package/vendor/desktop/vendor/credentials.js +478 -0
  253. package/vendor/desktop/vendor/device-fingerprint.js +145 -0
  254. package/vendor/desktop/vendor/env-file.js +1016 -0
  255. package/vendor/desktop/vendor/fingerprint.js +1061 -0
  256. package/vendor/desktop/vendor/foreign-memory.js +666 -0
  257. package/vendor/desktop/vendor/hooks.js +427 -0
  258. package/vendor/desktop/vendor/platform.js +934 -0
  259. package/vendor/desktop/vendor/prefs.js +348 -0
  260. package/vendor/desktop/vendor/presence-constants.js +104 -0
  261. package/vendor/desktop/vendor/presence.js +435 -0
  262. package/vendor/desktop/vendor/record-vault.js +834 -0
  263. package/vendor/desktop/vendor/session-store.js +545 -0
  264. package/vendor/desktop/vendor/topup.js +294 -0
  265. package/vendor/desktop/vendor/touch.js +455 -0
  266. package/vendor/desktop/vendor/update.js +343 -0
@@ -0,0 +1,673 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * AEGISONE — the ONLY vendoring stager (plan D6).
4
+ *
5
+ * Before this file there were two stagers with two hand-maintained manifests:
6
+ * `cli/scripts/predist.mjs` (about forty modules, staged under `cli/vendor/`
7
+ * keeping the repo's relative shape) and `desktop/scripts/predist.mjs` (a
8
+ * subset of the same modules, staged FLAT into `desktop/vendor/`, because
9
+ * electron-builder cannot reach outside the app directory). Two lists of the
10
+ * same repo-relative paths, drifting independently, each with its own copy of
11
+ * the "why is this file here" reasoning.
12
+ *
13
+ * Now there is ONE manifest — `MANIFEST`, below — and it is the only place a
14
+ * staged path is written down. Each row records which SHAPE(s) that module must
15
+ * appear in:
16
+ *
17
+ * mirror → `<cli>/vendor/<repo-relative path>` (the CLI's self-similar tree)
18
+ * flat → `<desktop>/vendor/<basename>` (electron-builder's app dir)
19
+ * nested → `<desktop>/vendor/<repo-relative path>` (artifacts whose SHAPE is
20
+ * load-bearing: the seal is
21
+ * resolved at ../../vendor/
22
+ * covenant/aegis.seal)
23
+ *
24
+ * …plus a fourth output that only AEGISONE needs: the PRODUCT BUNDLE
25
+ * (`one/vendor/cli/**`, `one/vendor/desktop/**`), which is what makes
26
+ * `npm i -g aegisone` a single install with both faces inside it. The bundle
27
+ * is a copy of the already-staged trees, so it inherits both shapes verbatim
28
+ * and `sharedpaths.js`'s two-layout rule resolves inside it with no change.
29
+ *
30
+ * Two things this file refuses to do:
31
+ *
32
+ * 1. **It never trusts a copy.** Every staged file is re-read and compared
33
+ * against its source; a mismatch is a hard failure, because a stale vendor
34
+ * tree is how a published package ships last month's behaviour.
35
+ * 2. **It never trusts a comment.** Both existing proofs are carried over and
36
+ * actually executed here: the CLI's staged registry must LOAD from inside
37
+ * `cli/vendor/` (not from the repo), and the desktop's flattened tree must
38
+ * be self-contained (no staged file may require a path that escapes
39
+ * `vendor/`) — which is the property flattening silently depends on.
40
+ *
41
+ * THE SEAM RULE (Phase 30.1, and the standing rule for everything under `one/`):
42
+ * no `process.*` read happens at module scope. Every read is inside a function,
43
+ * `main(argv, io)` takes its streams and arguments as parameters, and this
44
+ * module is therefore importable by a test without running the staging. There
45
+ * is also no `process.platform` anywhere in this file: nothing here branches on
46
+ * the OS. Where a host list is needed it comes from `client/platform.js`, and
47
+ * the copies themselves are `fs` calls with no platform vocabulary in them.
48
+ */
49
+
50
+ import fs from 'node:fs';
51
+ import path from 'node:path';
52
+ import { spawnSync } from 'node:child_process';
53
+ import { fileURLToPath, pathToFileURL } from 'node:url';
54
+ import { createRequire } from 'node:module';
55
+
56
+ const HERE = path.dirname(fileURLToPath(import.meta.url));
57
+ const require = createRequire(import.meta.url);
58
+
59
+ /** `one/` */
60
+ export const ONE_DIR = path.join(HERE, '..');
61
+ /** the repository root (`aegiscode-plugin/`) */
62
+ export const REPO_DIR = path.join(ONE_DIR, '..');
63
+ export const CLI_DIR = path.join(REPO_DIR, 'cli');
64
+ export const DESKTOP_DIR = path.join(REPO_DIR, 'desktop');
65
+ export const CLI_VENDOR = path.join(CLI_DIR, 'vendor');
66
+ export const DESKTOP_VENDOR = path.join(DESKTOP_DIR, 'vendor');
67
+ export const ONE_VENDOR = path.join(ONE_DIR, 'vendor');
68
+
69
+ // ---------------------------------------------------------------------------
70
+ // THE MANIFEST — one row per shared module, one place a path is written down.
71
+ // ---------------------------------------------------------------------------
72
+ //
73
+ // `src` repo-relative path of the file that lives at the repo root.
74
+ // `shapes` where it must appear: 'mirror' (cli/vendor, repo-shaped),
75
+ // 'flat' (desktop/vendor, basename only), 'nested' (desktop/vendor,
76
+ // repo-shaped — only for artifacts whose shape the requiring code
77
+ // depends on).
78
+ //
79
+ // A row appears ONCE even when both hosts need it. That is the whole point of
80
+ // D6: the desktop's flat set is a subset of the CLI's mirror set, and the old
81
+ // pair of scripts restated those nineteen paths in two files.
82
+ //
83
+ // Comment discipline: the old per-file notes are preserved verbatim-ish, but
84
+ // none of them is load-bearing any more. Nothing parses these comments (the
85
+ // `src:`/`shapes:` fields are matched as an object by test/one-vendor.test.mjs),
86
+ // so a stray apostrophe can no longer swallow the next manifest row — which is
87
+ // exactly the trap the old single-quote-paired parsers fell into.
88
+ export const MANIFEST = [
89
+ // ── the shared client: transport, stores, identity, catalogues ───────────
90
+ { src: 'client/aegis.js', shapes: ['mirror', 'flat'],
91
+ note: 'the thin transport — the one implementation of the wire format' },
92
+ { src: 'client/update.js', shapes: ['mirror', 'flat'],
93
+ note: 'the npm update checker (the desktop own update path)' },
94
+ { src: 'client/foreign-memory.js', shapes: ['mirror', 'flat'],
95
+ note: 'required by mcp/tools.js as ../client/foreign-memory.js' },
96
+ { src: 'client/credentials.js', shapes: ['mirror', 'flat'],
97
+ note: 'the account credential store, shared by all three hosts' },
98
+ { src: 'client/session-store.js', shapes: ['mirror', 'flat'],
99
+ note: 'the unified session store — one list in every host' },
100
+ { src: 'client/prefs.js', shapes: ['mirror', 'flat'],
101
+ note: 'the shared non-secret preference store (D5) — the CLI and the desktop store both read/write it' },
102
+ { src: 'client/env-file.js', shapes: ['mirror', 'flat'],
103
+ note: 'the shared ~/.aegiscode/.env loader, resolved before any key is read' },
104
+ { src: 'client/auto-provision.js', shapes: ['mirror', 'flat'],
105
+ note: 'free device key on first launch; requires ./device-fingerprint.js' },
106
+ { src: 'client/device-fingerprint.js', shapes: ['mirror', 'flat'],
107
+ note: 'the machine identity auto-provision.js and presence.js require' },
108
+ { src: 'client/presence.js', shapes: ['mirror', 'flat'],
109
+ note: 'the heartbeat beacon; requires ./presence-constants.js and ./device-fingerprint.js' },
110
+ { src: 'client/presence-constants.js', shapes: ['mirror', 'flat'],
111
+ note: 'the beacon constants — a package without them loses the beacon silently' },
112
+ { src: 'client/touch.js', shapes: ['mirror', 'flat'],
113
+ note: 'phi(alpha): the digest module fingerprint.js requires as ./touch.js' },
114
+ { src: 'client/fingerprint.js', shapes: ['mirror', 'flat'],
115
+ note: 'phi(alpha): the sealed session record, resolved by src/fingerprint.js' },
116
+ { src: 'client/authorship-key.js', shapes: ['mirror', 'flat'],
117
+ note: 'phi(alpha): the authorship key, required by ./attest.js and ./record-vault.js' },
118
+ { src: 'client/attest.js', shapes: ['mirror', 'flat'],
119
+ note: 'phi(alpha): attestation, requires ./fingerprint.js and ./authorship-key.js' },
120
+ { src: 'client/record-vault.js', shapes: ['mirror', 'flat'],
121
+ note: 'the vault, and its refusal to copy the key with the record' },
122
+ { src: 'client/brain-catalog.js', shapes: ['mirror', 'flat'],
123
+ note: 'the pooled-brain rule, required at load time by the engine and src/models.js' },
124
+ { src: 'client/byok-catalog.js', shapes: ['mirror', 'flat'],
125
+ note: 'the BYOK model additions the server catalog does not name' },
126
+ { src: 'client/hooks.js', shapes: ['mirror', 'flat'],
127
+ note: 'the shared hook layer behind /hooks and the repo guard installer' },
128
+ { src: 'client/platform.js', shapes: ['mirror', 'flat'],
129
+ note: 'the ONE place that decides which OS this is (Phase 30.1)' },
130
+ { src: 'client/topup.js', shapes: ['mirror', 'flat'],
131
+ note: 'the token-bank top-up: amount bounds, the balance reading, and the credit watch every host drives' },
132
+
133
+ // ── the MCP host surface ────────────────────────────────────────────────
134
+ { src: 'mcp/tools.js', shapes: ['mirror'],
135
+ note: 'the shared tool registry; requires ../client/foreign-memory.js' },
136
+ { src: 'mcp/server.js', shapes: ['mirror'],
137
+ note: 'the stdio MCP server every installed editor config names (compiled, never required)' },
138
+ { src: 'hosts/spec.js', shapes: ['mirror'],
139
+ note: 'the canonical server spec, staged under its own directory so it finds vendor/mcp/server.js' },
140
+ { src: 'hosts/targets.js', shapes: ['mirror'],
141
+ note: 'the editor target registry' },
142
+ { src: 'hosts/install.js', shapes: ['mirror'],
143
+ note: 'the merge-only installer behind aegiscode mcp install' },
144
+ { src: 'hosts/openai-shim.js', shapes: ['mirror'],
145
+ note: 'the loopback OpenAI-compatible shim' },
146
+
147
+ // ── the engine the CLI reuses from the desktop app ──────────────────────
148
+ { src: 'desktop/renderer/usage.js', shapes: ['mirror'],
149
+ note: 'the pure usage mapping shared by the window and the terminal' },
150
+ { src: 'desktop/lib/local/engine.js', shapes: ['mirror'],
151
+ note: 'the agent loop, reused as-is (one loop, not a second one drifting)' },
152
+ { src: 'desktop/lib/local/local.js', shapes: ['mirror'],
153
+ note: 'the local model transport and its fail-closed base-URL check' },
154
+ // The row whose ABSENCE broke the packaged CLI: `local.js` requires
155
+ // `./context.js` at load (for the token-budget trimmer), context.js is a
156
+ // committed module — and it had no manifest row, so no staged tree ever
157
+ // carried it. `require('./context.js')` then threw MODULE_NOT_FOUND from
158
+ // inside vendor/, which is the failure test/cli-approval.test.mjs and
159
+ // test/cli-package.test.mjs were reporting: the packaged CLI could not load
160
+ // at all. A manifest that lists a module's DEPENDENCIES by hand is exactly
161
+ // where this hides, so test/one-manifest-complete.test.mjs now derives the
162
+ // rule instead of trusting the list.
163
+ { src: 'desktop/lib/local/context.js', shapes: ['mirror'],
164
+ note: 'the token-budget trimmer local.js requires at load' },
165
+ { src: 'desktop/lib/local/session-rounds.js', shapes: ['mirror'],
166
+ note: 'interrupted-turn bookkeeping; required at load by engine.js' },
167
+ { src: 'desktop/lib/local/tools.js', shapes: ['mirror'],
168
+ note: 'the tool implementations (persistent shell, editFile, grep, exec)' },
169
+ { src: 'desktop/lib/local/shell.js', shapes: ['mirror'],
170
+ note: 'the persistent shell, required by tools.js' },
171
+ { src: 'desktop/lib/local/agents.js', shapes: ['mirror'],
172
+ note: 'Task subagents' },
173
+ { src: 'desktop/lib/local/prompt.js', shapes: ['mirror'],
174
+ note: 'the system prompt builder' },
175
+ { src: 'desktop/lib/settings.js', shapes: ['mirror'],
176
+ note: 'the provider-config store (base URL + key per provider)' },
177
+ { src: 'desktop/lib/local/turn-guard.js', shapes: ['mirror'],
178
+ note: 'engine.js requires it at load; it requires ./git-scope.js' },
179
+ { src: 'desktop/lib/local/worktree-lock.js', shapes: ['mirror'],
180
+ note: 'engine.js requires it at load' },
181
+ { src: 'desktop/lib/local/git-scope.js', shapes: ['mirror'],
182
+ note: 'the write-scope rule turn-guard.js and the queues share' },
183
+ { src: 'desktop/lib/local/queue.js', shapes: ['mirror'],
184
+ note: 'the autonomous work queue' },
185
+ { src: 'desktop/lib/local/autonomous.js', shapes: ['mirror'],
186
+ note: 'the unattended worker; requires ./queue.js and ./git-scope.js' },
187
+ { src: 'desktop/lib/local/entitlement.js', shapes: ['mirror'],
188
+ note: 'the shared Pro gate (account probe injected by the caller)' },
189
+ { src: 'desktop/lib/local/covenant.js', shapes: ['mirror'],
190
+ note: 'the pre-action gate engine.js requires unconditionally at load' },
191
+ { src: 'desktop/lib/local/aegis-seal.mjs', shapes: ['mirror'],
192
+ note: 'the codec covenant.js requires the first time it decodes' },
193
+
194
+ // ── the sealed covenant: the one row whose SHAPE is load-bearing ────────
195
+ // covenant.js resolves the artifact at `../../vendor/covenant/aegis.seal`
196
+ // relative to itself, so it must keep the repo's path under vendor/ — flat
197
+ // staging would place it where nothing looks, and the host would then report
198
+ // `available: false` and enforce only the hard-coded immutable trio while
199
+ // every other clause is silently gone.
200
+ { src: 'covenant/aegis.seal', shapes: ['mirror', 'nested'],
201
+ note: 'the sealed covenant (AES/1 container) — path shape is load-bearing' },
202
+ { src: 'covenant/README.md', shapes: ['mirror', 'nested'],
203
+ note: 'the decode notice shipped beside the artifact' },
204
+
205
+ // ── the agent-key gate ─────────────────────────────────────────────────
206
+ { src: 'tools/agent-gate.mjs', shapes: ['mirror', 'flat'],
207
+ note: 'the in-process half of the lock; without it a packaged app had NO gate' },
208
+ ];
209
+
210
+ /** Rows in a given shape: `{src, dest}` pairs, destination computed here only. */
211
+ export function entriesFor(shape) {
212
+ const out = [];
213
+ for (const row of MANIFEST) {
214
+ if (!row.shapes.includes(shape)) continue;
215
+ let dest;
216
+ if (shape === 'mirror') dest = path.join(CLI_VENDOR, row.src);
217
+ else if (shape === 'flat') dest = path.join(DESKTOP_VENDOR, path.basename(row.src));
218
+ else if (shape === 'nested') dest = path.join(DESKTOP_VENDOR, row.src);
219
+ else throw new Error(`predist: unknown shape ${shape}`);
220
+ out.push({ src: row.src, dest, from: path.join(REPO_DIR, row.src) });
221
+ }
222
+ return out;
223
+ }
224
+
225
+ /** Every distinct shape named by the manifest, in a stable order. */
226
+ export const SHAPES = ['mirror', 'flat', 'nested'];
227
+
228
+ // ---------------------------------------------------------------------------
229
+ // The product bundle: `one/vendor/cli/**` and `one/vendor/desktop/**`
230
+ // ---------------------------------------------------------------------------
231
+ //
232
+ // `npm pack one/` has to produce a package that BOOTS. The two faces keep their
233
+ // self-similar shape inside it, which is why no resolver changed to make this
234
+ // work: `cli/src/sharedpaths.js` tries `<cli>/../../client` (absent in the
235
+ // bundle, so it falls through) and then `<cli>/vendor/client` — staged above,
236
+ // inside the bundle. The bundle is copied from the already-verified trees, so
237
+ // the byte-identity proof covers these bytes too.
238
+ const BUNDLE_SOURCES = [
239
+ ['cli', CLI_DIR, ['bin', 'src', 'vendor', 'scripts', 'package.json', 'README.md', 'LICENSE']],
240
+ [
241
+ 'desktop',
242
+ DESKTOP_DIR,
243
+ ['main.js', 'preload.js', 'lib', 'renderer', 'bin', 'vendor', 'package.json', 'README.md'],
244
+ ],
245
+ ];
246
+
247
+ /** Directory names that must never be copied into a published bundle. */
248
+ const BUNDLE_EXCLUDE = new Set(['node_modules', 'release', '.git', '.cache', 'out']);
249
+
250
+ function copyTree(from, toDir) {
251
+ const skip = (name) => BUNDLE_EXCLUDE.has(name) || name.endsWith('.log');
252
+ const copyFile = (file, dest) => {
253
+ fs.mkdirSync(path.dirname(dest), { recursive: true });
254
+ fs.copyFileSync(file, dest);
255
+ if (!fs.readFileSync(file).equals(fs.readFileSync(dest))) {
256
+ throw new Error(`predist: bundle copy differs from source: ${path.relative(REPO_DIR, file)}`);
257
+ }
258
+ };
259
+ const walk = (dir, rel) => {
260
+ const stat = fs.lstatSync(dir);
261
+ // Symlinks are skipped rather than followed: a bundle that resolved through
262
+ // one would pack a path that only exists on the machine that built it.
263
+ if (stat.isSymbolicLink()) return;
264
+ if (stat.isFile()) {
265
+ copyFile(dir, path.join(toDir, rel));
266
+ return;
267
+ }
268
+ for (const name of fs.readdirSync(dir)) {
269
+ if (skip(name)) continue;
270
+ walk(path.join(dir, name), rel ? path.join(rel, name) : name);
271
+ }
272
+ };
273
+ // When `from` is a file, `toDir` is the file's FINAL path — not a directory to
274
+ // append the basename to. The bundle's `parts` mix directories and files
275
+ // (`bin`, `src`, … alongside `package.json`, `main.js`, `LICENSE`), and
276
+ // treating both as directories nested every file one level too deep:
277
+ // `one/vendor/cli/package.json/package.json`, `one/vendor/desktop/main.js/main.js`.
278
+ // The module-resolution proof did not notice, because `deps.js` resolves the
279
+ // shared modules and never the face's own entry point — so the tarball packed
280
+ // and installed cleanly with no `main.js` anywhere in it. Only
281
+ // `test/one-pack-boot.test.mjs` (ON2's real gate: pack → temp prefix → run)
282
+ // exposed it; `proveBundle` now asserts the shapes directly.
283
+ if (fs.lstatSync(from).isFile()) copyFile(from, toDir);
284
+ else walk(from, '');
285
+ }
286
+
287
+ // ---------------------------------------------------------------------------
288
+ // Staging primitives
289
+ // ---------------------------------------------------------------------------
290
+
291
+ function stageFiles(entries, removeRoot) {
292
+ if (removeRoot) fs.rmSync(removeRoot, { recursive: true, force: true });
293
+ const staged = [];
294
+ for (const entry of entries) {
295
+ if (!fs.existsSync(entry.from)) {
296
+ throw new Error(`predist: missing shared module: ${entry.src} (expected at ${entry.from})`);
297
+ }
298
+ fs.mkdirSync(path.dirname(entry.dest), { recursive: true });
299
+ fs.copyFileSync(entry.from, entry.dest);
300
+ if (!fs.readFileSync(entry.from).equals(fs.readFileSync(entry.dest))) {
301
+ throw new Error(`predist: staged copy differs from source: ${entry.src}`);
302
+ }
303
+ staged.push(entry);
304
+ }
305
+ return staged;
306
+ }
307
+
308
+ // ---------------------------------------------------------------------------
309
+ // Proofs
310
+ // ---------------------------------------------------------------------------
311
+
312
+ /**
313
+ * The CLI's standalone-load proof, carried over unchanged in substance: the
314
+ * staged registry must build from inside `cli/vendor/`, the editor layer must
315
+ * resolve the STAGED server (not a checkout path), and the staged gate module
316
+ * must load.
317
+ */
318
+ function proveMirror(staged) {
319
+ const toolsPath = path.join(CLI_VENDOR, 'mcp', 'tools.js');
320
+ delete require.cache[require.resolve(toolsPath)];
321
+ const { createTools } = require(toolsPath);
322
+ const tools = createTools({
323
+ apiBase: 'http://127.0.0.1',
324
+ apiKey: 'predist-probe',
325
+ randomUUID: () => 'id',
326
+ });
327
+ const count = tools.toolList().length;
328
+ if (count === 0) throw new Error('predist: staged registry exposes no tools');
329
+
330
+ // mcp/server.js registers process.stdin handlers at LOAD time and exports
331
+ // nothing, so requiring it would take over this process's stdin and it would
332
+ // never exit. It is verified by COMPILING it instead.
333
+ const vm = require('node:vm');
334
+ const serverJs = path.join(CLI_VENDOR, 'mcp', 'server.js');
335
+ new vm.Script(fs.readFileSync(serverJs, 'utf8'), { filename: serverJs });
336
+
337
+ const hostsDir = path.join(CLI_VENDOR, 'hosts');
338
+ const spec = require(path.join(hostsDir, 'spec.js'));
339
+ const install = require(path.join(hostsDir, 'install.js'));
340
+ const targets = require(path.join(hostsDir, 'targets.js'));
341
+
342
+ // An empty AEGIS_MCP_SERVER so a developer's own override cannot mask a
343
+ // broken staged tree: the candidate asserted on must be the staged one.
344
+ const resolved = spec.resolveServer({ AEGIS_MCP_SERVER: '' });
345
+ if (!resolved.exists || resolved.path !== serverJs) {
346
+ throw new Error(
347
+ `predist: staged hosts/spec.js resolves the server as ${resolved.path} ` +
348
+ `(exists: ${resolved.exists}), expected ${serverJs}. An installed aegiscode ` +
349
+ `would write editor configs pointing at a file the package never shipped. ` +
350
+ `Candidates were:\n ${resolved.candidates.join('\n ')}`
351
+ );
352
+ }
353
+
354
+ // Plan one real install against a throwaway home: the exact document
355
+ // `aegiscode mcp install vscode` would write, so the cheapest possible proof
356
+ // that the packaged command points at a file that exists.
357
+ const vscode = targets.getTarget('vscode');
358
+ const plan = install.planTarget(vscode, 'user', {
359
+ ctx: install.hostCtx({ home: path.join(CLI_VENDOR, '.predist-home'), env: {}, cwd: REPO_DIR }),
360
+ specOpts: { env: { AEGIS_MCP_SERVER: '' } },
361
+ });
362
+ const wrote = JSON.stringify(plan.after || '');
363
+ if (
364
+ plan.error ||
365
+ !plan.changed ||
366
+ !wrote.includes(JSON.stringify(serverJs).slice(1, -1))
367
+ ) {
368
+ throw new Error(
369
+ `predist: a planned vscode install does not name the staged server ` +
370
+ `(error: ${plan.error && plan.error.message}, changed: ${plan.changed})`
371
+ );
372
+ }
373
+
374
+ const shim = require(path.join(hostsDir, 'openai-shim.js'));
375
+ if (typeof shim.createShimServer !== 'function') {
376
+ throw new Error('predist: staged hosts/openai-shim.js exposes no createShimServer');
377
+ }
378
+
379
+ return { count, targets: targets.targetIds().length, staged: staged.length };
380
+ }
381
+
382
+ /** The gate is an ES module, so its proof is a dynamic import. */
383
+ async function proveGate() {
384
+ const gateStagedPath = path.join(CLI_VENDOR, 'tools', 'agent-gate.mjs');
385
+ const gateMod = await import(pathToFileURL(gateStagedPath).href);
386
+ if (typeof gateMod.run !== 'function') {
387
+ throw new Error('predist: staged tools/agent-gate.mjs exposes no run()');
388
+ }
389
+ return gateStagedPath;
390
+ }
391
+
392
+ /**
393
+ * The desktop's standalone-load proof — the property flattening depends on and
394
+ * which nothing asserted before: a flat-staged module must resolve its siblings
395
+ * from the SAME vendor directory. A `require('../client/...')` that survived
396
+ * flattening would resolve outside the packaged app (electron-builder cannot
397
+ * ship those files at all), so it is a hard failure here rather than a
398
+ * MODULE_NOT_FOUND in a user's window.
399
+ */
400
+ /**
401
+ * Drop comments before scanning for requires. `client/aegis.js` documents its
402
+ * own usage as `require('./client/aegis.js')` inside a JSDoc block, which a raw
403
+ * scan reads as a self-referential dependency — the first run of this proof
404
+ * failed on exactly that line, which is why the strip is here and not in a
405
+ * comment promising it happens.
406
+ */
407
+ function stripComments(source) {
408
+ return source.replace(/\/\*[\s\S]*?\*\//g, '').replace(/(^|[^:])\/\/.*$/gm, '$1');
409
+ }
410
+
411
+ function proveFlat(staged) {
412
+ const flatNames = new Set(staged.map((e) => path.basename(e.dest)));
413
+ for (const entry of staged) {
414
+ const src = stripComments(fs.readFileSync(entry.dest, 'utf8'));
415
+ for (const m of src.matchAll(/require\(\s*'((?:\.\.?\/)[^']+)'\s*\)/g)) {
416
+ const spec = m[1];
417
+ const target = path.basename(spec).replace(/\.[cm]?js$/, '');
418
+ const sibling = spec.replace(/^\.\//, '');
419
+ if (sibling.startsWith('../')) {
420
+ throw new Error(
421
+ `predist: flat-staged ${path.basename(entry.dest)} requires '${spec}', ` +
422
+ 'which escapes vendor/ — flattening only works for same-directory requires ' +
423
+ `(add the target to the manifest, or stop staging this file flat)${target ? '' : ''}`
424
+ );
425
+ }
426
+ const asFile = spec.replace(/^\.\//, '');
427
+ if (!flatNames.has(asFile)) {
428
+ throw new Error(
429
+ `predist: flat-staged ${path.basename(entry.dest)} requires '${spec}', ` +
430
+ `which is not staged into desktop/vendor/ — the packaged app would throw ` +
431
+ 'MODULE_NOT_FOUND before the window could open'
432
+ );
433
+ }
434
+ }
435
+ }
436
+
437
+ // …and the transport itself must actually LOAD from the flattened tree.
438
+ const transport = require(path.join(DESKTOP_VENDOR, 'aegis.js'));
439
+ if (!transport || Object.keys(transport).length === 0) {
440
+ throw new Error('predist: staged desktop/vendor/aegis.js loads but exports nothing');
441
+ }
442
+ return { files: staged.length, exports: Object.keys(transport).length };
443
+ }
444
+
445
+ /**
446
+ * The bundle proof: `one/vendor/cli` must resolve EVERY shared module from
447
+ * inside the PRODUCT BUNDLE (`one/vendor/`), never from the repo checkout.
448
+ *
449
+ * The boundary is the bundle root and not `one/vendor/cli`, and that is not a
450
+ * softened assertion — it is the layout rule itself. The bundle keeps the repo's
451
+ * shape with the two faces as SIBLINGS (`one/vendor/cli`, `one/vendor/desktop`),
452
+ * so `cli/src/deps.js`'s repo-shaped candidate `../desktop/renderer/usage.js`
453
+ * lands on the bundled desktop face exactly as it does in a checkout. The first
454
+ * run of this proof failed on that path, which is how the rule got written down
455
+ * here instead of being assumed: it is the sibling face copy, one directory
456
+ * over, not the repo.
457
+ *
458
+ * It runs as a child process with its cwd inside the bundle, so a path that only
459
+ * exists in the repo fails here rather than after `npm i -g aegisone`.
460
+ */
461
+ function proveBundle() {
462
+ const bundleCli = path.join(ONE_VENDOR, 'cli');
463
+ const depsPath = path.join(bundleCli, 'src', 'deps.js');
464
+ const script =
465
+ 'const d=require(process.argv[1]);' +
466
+ 'console.log(JSON.stringify(d.paths))';
467
+ const res = spawnSync(process.execPath, ['-e', script, depsPath], {
468
+ cwd: bundleCli,
469
+ encoding: 'utf8',
470
+ });
471
+ if (res.status !== 0) {
472
+ throw new Error(`predist: the bundled CLI does not load: ${res.stderr || res.stdout}`);
473
+ }
474
+ const paths = JSON.parse(res.stdout);
475
+ const outside = [];
476
+ let inSiblingFace = 0;
477
+ for (const [name, p] of Object.entries(paths)) {
478
+ const rel = path.relative(ONE_VENDOR, p);
479
+ if (rel.startsWith('..') || path.isAbsolute(rel)) {
480
+ outside.push(`${name} -> ${p}`);
481
+ continue;
482
+ }
483
+ if (rel.split(path.sep)[0] !== 'cli') inSiblingFace++;
484
+ }
485
+ if (outside.length) {
486
+ throw new Error(
487
+ 'predist: the bundled CLI resolves these shared modules OUTSIDE the bundle ' +
488
+ `(${ONE_VENDOR}) — the product tarball would depend on a repo checkout:\n ` +
489
+ outside.join('\n ')
490
+ );
491
+ }
492
+ const binShipped = fs.existsSync(path.join(bundleCli, 'bin', 'aegiscode.js'));
493
+ if (!binShipped) throw new Error('predist: the bundle has no cli/bin/aegiscode.js');
494
+
495
+ // Every bundled part keeps the shape its SOURCE had. This is the assertion
496
+ // that would have caught `main.js/main.js`: the module-resolution proof above
497
+ // says nothing about a face's own entry point, so a bundle can pass every
498
+ // check here and still pack without the file the desktop face is launched by.
499
+ const wrongShape = [];
500
+ for (const [name, dir, parts] of BUNDLE_SOURCES) {
501
+ for (const part of parts) {
502
+ const dest = path.join(ONE_VENDOR, name, part);
503
+ let srcStat = null;
504
+ let destStat = null;
505
+ try {
506
+ srcStat = fs.lstatSync(path.join(dir, part));
507
+ } catch {
508
+ continue; // reported by the staging loop
509
+ }
510
+ try {
511
+ destStat = fs.lstatSync(dest);
512
+ } catch {
513
+ wrongShape.push(`${name}/${part} -> missing`);
514
+ continue;
515
+ }
516
+ if (srcStat.isFile() && !destStat.isFile()) wrongShape.push(`${name}/${part} -> not a regular file`);
517
+ if (srcStat.isDirectory() && !destStat.isDirectory()) wrongShape.push(`${name}/${part} -> not a directory`);
518
+ }
519
+ }
520
+ if (wrongShape.length) {
521
+ throw new Error(`predist: the bundle staged these in the wrong shape:\n ${wrongShape.join('\n ')}`);
522
+ }
523
+ return { modules: Object.keys(paths).length, inSiblingFace };
524
+ }
525
+
526
+ // ---------------------------------------------------------------------------
527
+ // The one entry point
528
+ // ---------------------------------------------------------------------------
529
+
530
+ /**
531
+ * Stage every requested shape, then prove what was staged.
532
+ *
533
+ * @param {object} [opts]
534
+ * @param {string[]} [opts.shapes] subset of SHAPES plus 'bundle'
535
+ * @param {object} [opts.io] { stdout, stderr } — injectable, so a test can
536
+ * capture this without capturing the process
537
+ * @returns {Promise<object>} a report of what was staged and proven
538
+ */
539
+ export async function stage(opts) {
540
+ const o = opts || {};
541
+ const io = o.io || {};
542
+ const out = io.stdout || process.stdout;
543
+ const errOut = io.stderr || process.stderr;
544
+ const shapes = Array.isArray(o.shapes) ? o.shapes : [...SHAPES, 'bundle'];
545
+ const want = (s) => shapes.includes(s);
546
+ const log = (line) => out.write(`${line}\n`);
547
+
548
+ const report = { mirror: null, flat: null, nested: null, bundle: null };
549
+
550
+ if (want('mirror')) {
551
+ const staged = stageFiles(entriesFor('mirror'), CLI_VENDOR);
552
+ log(`predist: staged ${staged.length} shared modules into cli/vendor/`);
553
+ for (const e of staged) log(` ${e.src} -> vendor/${e.src}`);
554
+ report.mirror = { staged: staged.length };
555
+ }
556
+
557
+ if (want('nested')) {
558
+ report.nested = { staged: stageFiles(entriesFor('nested'), null).length };
559
+ }
560
+
561
+ if (want('flat')) {
562
+ const staged = stageFiles(entriesFor('flat'), null);
563
+ for (const e of staged) log(`staged ${e.dest}`);
564
+ report.flat = { staged: staged.length };
565
+ }
566
+
567
+ // One manifest, two shapes: wherever a module appears twice, the two copies
568
+ // must be byte-identical to EACH OTHER as well as to the source. Nothing
569
+ // asserted this before, and it is the whole payoff of a single manifest.
570
+ if (want('mirror') && want('flat')) {
571
+ for (const row of MANIFEST) {
572
+ if (!row.shapes.includes('mirror') || !row.shapes.includes('flat')) continue;
573
+ const a = path.join(CLI_VENDOR, row.src);
574
+ const b = path.join(DESKTOP_VENDOR, path.basename(row.src));
575
+ if (!fs.readFileSync(a).equals(fs.readFileSync(b))) {
576
+ throw new Error(`predist: the two shapes disagree for ${row.src}`);
577
+ }
578
+ }
579
+ }
580
+
581
+ if (want('mirror')) {
582
+ const p = proveMirror(entriesFor('mirror'));
583
+ log(`predist: staged registry loads standalone (${p.count} tools)`);
584
+ log(
585
+ `predist: editor layer verified (${p.targets} host targets, ` +
586
+ `server resolves to vendor/mcp/server.js, shim loads)`
587
+ );
588
+ const gate = await proveGate();
589
+ log(`predist: ${path.relative(REPO_DIR, gate)} loads standalone and exposes run()`);
590
+ report.mirror.proof = p;
591
+ }
592
+
593
+ if (want('flat')) {
594
+ const p = proveFlat(entriesFor('flat'));
595
+ log(
596
+ `predist: flattened tree is self-contained (${p.files} files, ` +
597
+ `${p.exports} transport exports) — no staged module escapes vendor/`
598
+ );
599
+ report.flat.proof = p;
600
+ }
601
+
602
+ if (want('bundle')) {
603
+ for (const [name, dir, parts] of BUNDLE_SOURCES) {
604
+ const to = path.join(ONE_VENDOR, name);
605
+ fs.rmSync(to, { recursive: true, force: true });
606
+ for (const part of parts) {
607
+ const from = path.join(dir, part);
608
+ if (!fs.existsSync(from)) {
609
+ if (part === 'LICENSE' || part === 'README.md') continue;
610
+ throw new Error(`predist: bundle source missing: ${path.relative(REPO_DIR, from)}`);
611
+ }
612
+ copyTree(from, path.join(to, part));
613
+ }
614
+ log(`staged the ${name} face into one/vendor/${name}/`);
615
+ }
616
+ const p = proveBundle();
617
+ log(
618
+ `predist: the bundled CLI resolves ${p.modules} shared modules from inside ` +
619
+ `one/vendor/ (${p.inSiblingFace} through the bundled desktop face) — ` +
620
+ 'no repo checkout needed'
621
+ );
622
+ report.bundle = p;
623
+ }
624
+
625
+ return report;
626
+ }
627
+
628
+ /**
629
+ * CLI entry. `argv` and the streams are parameters so the seam survives: a test
630
+ * passes its own, and nothing in this file reads the process at module scope.
631
+ */
632
+ export async function main(argv, io) {
633
+ const o = io || {};
634
+ const out = o.stdout || process.stdout;
635
+ const errOut = o.stderr || process.stderr;
636
+ const args = Array.isArray(argv) ? argv : [];
637
+ let shapes;
638
+ if (args.includes('--mirror-only')) shapes = ['mirror'];
639
+ else if (args.includes('--flat-only')) shapes = ['flat', 'nested'];
640
+ else if (args.includes('--bundle-only')) shapes = ['bundle'];
641
+ try {
642
+ await stage({ shapes, io: { stdout: out, stderr: errOut } });
643
+ return 0;
644
+ } catch (error) {
645
+ errOut.write(`${error && error.message}\n`);
646
+ return 1;
647
+ }
648
+ }
649
+
650
+ /**
651
+ * Run when — and only when — this file was started directly
652
+ * (`node one/scripts/predist.mjs`). The process reads live inside a function on
653
+ * purpose: the seam rule for `one/` is that no `process.*` is read at module
654
+ * scope, and this is the file that would have broken it.
655
+ */
656
+ function runIfDirect() {
657
+ const entry = process.argv[1];
658
+ let direct = false;
659
+ if (entry) {
660
+ try {
661
+ direct = path.resolve(entry) === fileURLToPath(import.meta.url);
662
+ } catch {
663
+ direct = false;
664
+ }
665
+ }
666
+ if (!direct) return false;
667
+ main(process.argv.slice(2)).then((code) => {
668
+ process.exitCode = code;
669
+ });
670
+ return true;
671
+ }
672
+
673
+ runIfDirect();