@eloxiv/cli 0.0.0-stage → 0.1.1

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 (294) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -2
  3. package/dist/AgentSkills.d.ts +51 -0
  4. package/dist/AgentSkills.d.ts.map +1 -0
  5. package/dist/AgentSkills.js +264 -0
  6. package/dist/AgentSkills.js.map +1 -0
  7. package/dist/AgentWeb.d.ts +83 -0
  8. package/dist/AgentWeb.d.ts.map +1 -0
  9. package/dist/AgentWeb.js +436 -0
  10. package/dist/AgentWeb.js.map +1 -0
  11. package/dist/App.d.ts +213 -0
  12. package/dist/App.d.ts.map +1 -0
  13. package/dist/App.js +357 -0
  14. package/dist/App.js.map +1 -0
  15. package/dist/Blueprint.d.ts +47 -0
  16. package/dist/Blueprint.d.ts.map +1 -0
  17. package/dist/Blueprint.js +241 -0
  18. package/dist/Blueprint.js.map +1 -0
  19. package/dist/Brand.d.ts +42 -0
  20. package/dist/Brand.d.ts.map +1 -0
  21. package/dist/Brand.js +370 -0
  22. package/dist/Brand.js.map +1 -0
  23. package/dist/Changelog.d.ts +22 -0
  24. package/dist/Changelog.d.ts.map +1 -0
  25. package/dist/Changelog.js +117 -0
  26. package/dist/Changelog.js.map +1 -0
  27. package/dist/Cli.d.ts +17 -0
  28. package/dist/Cli.d.ts.map +1 -0
  29. package/dist/Cli.js +810 -0
  30. package/dist/Cli.js.map +1 -0
  31. package/dist/DbAdmin.d.ts +18 -0
  32. package/dist/DbAdmin.d.ts.map +1 -0
  33. package/dist/DbAdmin.js +91 -0
  34. package/dist/DbAdmin.js.map +1 -0
  35. package/dist/Dependencies.d.ts +53 -0
  36. package/dist/Dependencies.d.ts.map +1 -0
  37. package/dist/Dependencies.js +132 -0
  38. package/dist/Dependencies.js.map +1 -0
  39. package/dist/Deploy.d.ts +39 -0
  40. package/dist/Deploy.d.ts.map +1 -0
  41. package/dist/Deploy.js +458 -0
  42. package/dist/Deploy.js.map +1 -0
  43. package/dist/Docs.d.ts +71 -0
  44. package/dist/Docs.d.ts.map +1 -0
  45. package/dist/Docs.js +240 -0
  46. package/dist/Docs.js.map +1 -0
  47. package/dist/Doctor.d.ts +56 -0
  48. package/dist/Doctor.d.ts.map +1 -0
  49. package/dist/Doctor.js +368 -0
  50. package/dist/Doctor.js.map +1 -0
  51. package/dist/Dossier.d.ts +23 -0
  52. package/dist/Dossier.d.ts.map +1 -0
  53. package/dist/Dossier.js +92 -0
  54. package/dist/Dossier.js.map +1 -0
  55. package/dist/Emit.d.ts +26 -0
  56. package/dist/Emit.d.ts.map +1 -0
  57. package/dist/Emit.js +51 -0
  58. package/dist/Emit.js.map +1 -0
  59. package/dist/Errors.d.ts +26 -0
  60. package/dist/Errors.d.ts.map +1 -0
  61. package/dist/Errors.js +17 -0
  62. package/dist/Errors.js.map +1 -0
  63. package/dist/Evals.d.ts +52 -0
  64. package/dist/Evals.d.ts.map +1 -0
  65. package/dist/Evals.js +126 -0
  66. package/dist/Evals.js.map +1 -0
  67. package/dist/Files.d.ts +47 -0
  68. package/dist/Files.d.ts.map +1 -0
  69. package/dist/Files.js +145 -0
  70. package/dist/Files.js.map +1 -0
  71. package/dist/Generate.d.ts +80 -0
  72. package/dist/Generate.d.ts.map +1 -0
  73. package/dist/Generate.js +310 -0
  74. package/dist/Generate.js.map +1 -0
  75. package/dist/Guards.d.ts +45 -0
  76. package/dist/Guards.d.ts.map +1 -0
  77. package/dist/Guards.js +530 -0
  78. package/dist/Guards.js.map +1 -0
  79. package/dist/Inspect.d.ts +125 -0
  80. package/dist/Inspect.d.ts.map +1 -0
  81. package/dist/Inspect.js +270 -0
  82. package/dist/Inspect.js.map +1 -0
  83. package/dist/Keychain.d.ts +57 -0
  84. package/dist/Keychain.d.ts.map +1 -0
  85. package/dist/Keychain.js +73 -0
  86. package/dist/Keychain.js.map +1 -0
  87. package/dist/Lock.d.ts +13 -0
  88. package/dist/Lock.d.ts.map +1 -0
  89. package/dist/Lock.js +145 -0
  90. package/dist/Lock.js.map +1 -0
  91. package/dist/Mcp.d.ts +91 -0
  92. package/dist/Mcp.d.ts.map +1 -0
  93. package/dist/Mcp.js +128 -0
  94. package/dist/Mcp.js.map +1 -0
  95. package/dist/Merge.d.ts +18 -0
  96. package/dist/Merge.d.ts.map +1 -0
  97. package/dist/Merge.js +43 -0
  98. package/dist/Merge.js.map +1 -0
  99. package/dist/Migrate.d.ts +78 -0
  100. package/dist/Migrate.d.ts.map +1 -0
  101. package/dist/Migrate.js +288 -0
  102. package/dist/Migrate.js.map +1 -0
  103. package/dist/Plugins.d.ts +36 -0
  104. package/dist/Plugins.d.ts.map +1 -0
  105. package/dist/Plugins.js +304 -0
  106. package/dist/Plugins.js.map +1 -0
  107. package/dist/Postgres.d.ts +73 -0
  108. package/dist/Postgres.d.ts.map +1 -0
  109. package/dist/Postgres.js +294 -0
  110. package/dist/Postgres.js.map +1 -0
  111. package/dist/Publish.d.ts +23 -0
  112. package/dist/Publish.d.ts.map +1 -0
  113. package/dist/Publish.js +59 -0
  114. package/dist/Publish.js.map +1 -0
  115. package/dist/Registry.d.ts +539 -0
  116. package/dist/Registry.d.ts.map +1 -0
  117. package/dist/Registry.js +340 -0
  118. package/dist/Registry.js.map +1 -0
  119. package/dist/Remote.d.ts +90 -0
  120. package/dist/Remote.d.ts.map +1 -0
  121. package/dist/Remote.js +1006 -0
  122. package/dist/Remote.js.map +1 -0
  123. package/dist/Run.d.ts +120 -0
  124. package/dist/Run.d.ts.map +1 -0
  125. package/dist/Run.js +477 -0
  126. package/dist/Run.js.map +1 -0
  127. package/dist/SyncGen.d.ts +118 -0
  128. package/dist/SyncGen.d.ts.map +1 -0
  129. package/dist/SyncGen.js +392 -0
  130. package/dist/SyncGen.js.map +1 -0
  131. package/dist/Update.d.ts +301 -0
  132. package/dist/Update.d.ts.map +1 -0
  133. package/dist/Update.js +627 -0
  134. package/dist/Update.js.map +1 -0
  135. package/dist/bin.d.ts +3 -0
  136. package/dist/bin.d.ts.map +1 -0
  137. package/dist/bin.js +42 -0
  138. package/dist/bin.js.map +1 -0
  139. package/dist/docs/backlog.md +56 -0
  140. package/dist/docs/ci.md +277 -0
  141. package/dist/docs/cli.md +696 -0
  142. package/dist/docs/connectors/google.md +115 -0
  143. package/dist/docs/connectors/http-openapi.md +7 -0
  144. package/dist/docs/connectors/mcp.md +8 -0
  145. package/dist/docs/connectors/microsoft-graph.md +75 -0
  146. package/dist/docs/connectors/openai.md +25 -0
  147. package/dist/docs/connectors/slack.md +162 -0
  148. package/dist/docs/connectors/workos.md +39 -0
  149. package/dist/docs/contracts/README.md +173 -0
  150. package/dist/docs/contracts/action-consent.md +92 -0
  151. package/dist/docs/contracts/action-registry.md +85 -0
  152. package/dist/docs/contracts/actor.md +100 -0
  153. package/dist/docs/contracts/agent-resources.md +90 -0
  154. package/dist/docs/contracts/agent-runtime.md +257 -0
  155. package/dist/docs/contracts/approvals.md +126 -0
  156. package/dist/docs/contracts/audit.md +75 -0
  157. package/dist/docs/contracts/auth-provider.md +74 -0
  158. package/dist/docs/contracts/calendar-provider.md +46 -0
  159. package/dist/docs/contracts/client-sdk.md +245 -0
  160. package/dist/docs/contracts/collab-document.md +151 -0
  161. package/dist/docs/contracts/command.md +44 -0
  162. package/dist/docs/contracts/connections.md +235 -0
  163. package/dist/docs/contracts/context-accounting.md +50 -0
  164. package/dist/docs/contracts/daemon.md +243 -0
  165. package/dist/docs/contracts/db-tx.md +53 -0
  166. package/dist/docs/contracts/delegation.md +68 -0
  167. package/dist/docs/contracts/device-control.md +103 -0
  168. package/dist/docs/contracts/directory-provider.md +36 -0
  169. package/dist/docs/contracts/directory.md +161 -0
  170. package/dist/docs/contracts/document-source.md +33 -0
  171. package/dist/docs/contracts/files.md +115 -0
  172. package/dist/docs/contracts/flags.md +83 -0
  173. package/dist/docs/contracts/host.md +68 -0
  174. package/dist/docs/contracts/http-api.md +43 -0
  175. package/dist/docs/contracts/ingestion.md +130 -0
  176. package/dist/docs/contracts/ingress.md +141 -0
  177. package/dist/docs/contracts/invocation.md +260 -0
  178. package/dist/docs/contracts/local-client.md +110 -0
  179. package/dist/docs/contracts/locale.md +56 -0
  180. package/dist/docs/contracts/machine-identity.md +117 -0
  181. package/dist/docs/contracts/mail-provider.md +49 -0
  182. package/dist/docs/contracts/memory.md +53 -0
  183. package/dist/docs/contracts/messaging.md +40 -0
  184. package/dist/docs/contracts/metering.md +139 -0
  185. package/dist/docs/contracts/model-provider.md +84 -0
  186. package/dist/docs/contracts/module-manifest.md +213 -0
  187. package/dist/docs/contracts/notification-channel.md +90 -0
  188. package/dist/docs/contracts/notifications.md +123 -0
  189. package/dist/docs/contracts/outbox.md +80 -0
  190. package/dist/docs/contracts/privacy.md +110 -0
  191. package/dist/docs/contracts/progress.md +52 -0
  192. package/dist/docs/contracts/query-surface.md +108 -0
  193. package/dist/docs/contracts/readiness.md +63 -0
  194. package/dist/docs/contracts/release.md +142 -0
  195. package/dist/docs/contracts/result-rendering.md +61 -0
  196. package/dist/docs/contracts/sandbox.md +186 -0
  197. package/dist/docs/contracts/scheduler.md +148 -0
  198. package/dist/docs/contracts/screen-context.md +81 -0
  199. package/dist/docs/contracts/search.md +120 -0
  200. package/dist/docs/contracts/secrets.md +74 -0
  201. package/dist/docs/contracts/settings.md +109 -0
  202. package/dist/docs/contracts/sharing.md +77 -0
  203. package/dist/docs/contracts/slot.md +48 -0
  204. package/dist/docs/contracts/space.md +67 -0
  205. package/dist/docs/contracts/storage-adapter.md +45 -0
  206. package/dist/docs/contracts/storage-backend.md +56 -0
  207. package/dist/docs/contracts/sync.md +213 -0
  208. package/dist/docs/contracts/telemetry.md +80 -0
  209. package/dist/docs/contracts/theme-tokens.md +50 -0
  210. package/dist/docs/contracts/tool-source.md +58 -0
  211. package/dist/docs/contracts/versioning.md +99 -0
  212. package/dist/docs/contracts/view.md +65 -0
  213. package/dist/docs/contracts/work-items.md +99 -0
  214. package/dist/docs/contracts/workflow.md +82 -0
  215. package/dist/docs/decisions.md +163 -0
  216. package/dist/docs/example-app.md +192 -0
  217. package/dist/docs/getting-started.md +927 -0
  218. package/dist/docs/goal.md +54 -0
  219. package/dist/docs/parity.md +29 -0
  220. package/dist/docs/performance.md +129 -0
  221. package/dist/docs/registry/README.md +74 -0
  222. package/dist/docs/registry/app.md +38 -0
  223. package/dist/docs/registry/approvals-ui-foldkit.md +28 -0
  224. package/dist/docs/registry/calendar-ui-foldkit.md +27 -0
  225. package/dist/docs/registry/calendar.md +35 -0
  226. package/dist/docs/registry/chat-ui-foldkit.md +30 -0
  227. package/dist/docs/registry/desktop-rune.md +50 -0
  228. package/dist/docs/registry/desktop.md +32 -0
  229. package/dist/docs/registry/eloxiv-action.md +25 -0
  230. package/dist/docs/registry/eloxiv-connector.md +25 -0
  231. package/dist/docs/registry/eloxiv-module.md +25 -0
  232. package/dist/docs/registry/eloxiv-policy.md +25 -0
  233. package/dist/docs/registry/eloxiv-view.md +25 -0
  234. package/dist/docs/registry/hello-ui-foldkit.md +29 -0
  235. package/dist/docs/registry/hello.md +39 -0
  236. package/dist/docs/registry/home-ui-foldkit.md +27 -0
  237. package/dist/docs/registry/home.md +29 -0
  238. package/dist/docs/registry/inbox-ui-foldkit.md +27 -0
  239. package/dist/docs/registry/mail-ui-foldkit.md +27 -0
  240. package/dist/docs/registry/mail.md +34 -0
  241. package/dist/docs/registry/meeting-prep.md +26 -0
  242. package/dist/docs/registry/members-ui-foldkit.md +28 -0
  243. package/dist/docs/registry/mobile.md +37 -0
  244. package/dist/docs/registry/notes-ui-foldkit.md +27 -0
  245. package/dist/docs/registry/notes.md +26 -0
  246. package/dist/docs/registry/people-ui-foldkit.md +28 -0
  247. package/dist/docs/registry/people.md +38 -0
  248. package/dist/docs/registry/shell-foldkit.md +35 -0
  249. package/dist/docs/registry/theme.md +25 -0
  250. package/dist/docs/registry/ui-conformance.md +30 -0
  251. package/dist/docs/release.md +100 -0
  252. package/dist/docs/scaffold.md +826 -0
  253. package/dist/docs/security/threat-model.md +299 -0
  254. package/dist/docs/upstream/zero-cache-socket-handoff.md +105 -0
  255. package/dist/index.d.ts +8 -0
  256. package/dist/index.d.ts.map +1 -0
  257. package/dist/index.js +8 -0
  258. package/dist/index.js.map +1 -0
  259. package/package.json +48 -3
  260. package/src/AgentSkills.ts +329 -0
  261. package/src/AgentWeb.ts +507 -0
  262. package/src/App.ts +435 -0
  263. package/src/Blueprint.ts +276 -0
  264. package/src/Brand.ts +415 -0
  265. package/src/Changelog.ts +136 -0
  266. package/src/Cli.ts +1458 -0
  267. package/src/DbAdmin.ts +115 -0
  268. package/src/Dependencies.ts +170 -0
  269. package/src/Deploy.ts +563 -0
  270. package/src/Docs.ts +309 -0
  271. package/src/Doctor.ts +424 -0
  272. package/src/Dossier.ts +148 -0
  273. package/src/Emit.ts +68 -0
  274. package/src/Errors.ts +18 -0
  275. package/src/Evals.ts +153 -0
  276. package/src/Files.ts +152 -0
  277. package/src/Generate.ts +402 -0
  278. package/src/Guards.ts +541 -0
  279. package/src/Inspect.ts +358 -0
  280. package/src/Keychain.ts +107 -0
  281. package/src/Lock.ts +174 -0
  282. package/src/Mcp.ts +159 -0
  283. package/src/Merge.ts +70 -0
  284. package/src/Migrate.ts +331 -0
  285. package/src/Plugins.ts +347 -0
  286. package/src/Postgres.ts +353 -0
  287. package/src/Publish.ts +64 -0
  288. package/src/Registry.ts +405 -0
  289. package/src/Remote.ts +1158 -0
  290. package/src/Run.ts +541 -0
  291. package/src/SyncGen.ts +570 -0
  292. package/src/Update.ts +873 -0
  293. package/src/bin.ts +46 -0
  294. package/src/index.ts +7 -0
package/src/Deploy.ts ADDED
@@ -0,0 +1,563 @@
1
+ /**
2
+ * Deployment recipes (docs/cli.md, "Deploying"):
3
+ *
4
+ * eloxiv deploy <docker|fly|railway> [--dry-run] write the target's files into the app (never overwriting
5
+ * your edits without --overwrite); nothing is built, pushed,
6
+ * published or deployed
7
+ * eloxiv deploy check [--env-file <file>] the production environment checked before a deploy
8
+ *
9
+ * The hosts are decisions.md's: a long-running server per deployment, self-hosted (Docker), Railway or Fly. Every
10
+ * recipe runs the same image and the same four roles, each `eloxiv start <role>`: `setup` (the release step, before
11
+ * new kernels start), `kernel`, `zero` (zero-cache, on a persistent volume for its replica) and `shell` (the built
12
+ * shell with its security headers). Serverless and edge hosts are not targets: sync needs long-running processes.
13
+ */
14
+ import { existsSync, readFileSync } from "node:fs"
15
+ import { join } from "node:path"
16
+ import { checkUrls } from "./Postgres.ts"
17
+ import { shellDir } from "./Run.ts"
18
+
19
+ export const DEPLOY_TARGETS = ["docker", "fly", "railway"] as const
20
+ export type DeployTarget = (typeof DEPLOY_TARGETS)[number]
21
+
22
+ export interface DeployFile {
23
+ readonly path: string
24
+ readonly content: string
25
+ }
26
+
27
+ interface AppFacts {
28
+ readonly name: string
29
+ readonly shell: boolean
30
+ }
31
+
32
+ /** One environment variable a deployment sets. */
33
+ interface EnvVar {
34
+ readonly name: string
35
+ readonly roles: ReadonlyArray<"kernel" | "zero" | "shell" | "setup">
36
+ readonly secret: boolean
37
+ readonly example: string
38
+ readonly what: string
39
+ }
40
+
41
+ /** What a production deployment sets, per role. */
42
+ export const PRODUCTION_ENV: ReadonlyArray<EnvVar> = [
43
+ {
44
+ name: "ELOXIV_ENV",
45
+ roles: ["kernel", "setup", "zero"],
46
+ secret: false,
47
+ example: "production",
48
+ what: "production: setup refuses unsafe pg_hba rules, zero-cache requires its admin password",
49
+ },
50
+ {
51
+ name: "ELOXIV_BASE_URL",
52
+ roles: ["kernel", "shell"],
53
+ secret: false,
54
+ example: "https://api.example.com",
55
+ what: "the kernel's public URL (tokens and cookies are bound to it)",
56
+ },
57
+ {
58
+ name: "ELOXIV_ZERO_URL",
59
+ roles: ["shell"],
60
+ secret: false,
61
+ example: "https://sync.example.com",
62
+ what: "zero-cache's public URL",
63
+ },
64
+ {
65
+ name: "ELOXIV_TRUSTED_ORIGINS",
66
+ roles: ["kernel"],
67
+ secret: false,
68
+ example: "https://app.example.com",
69
+ what: "origins allowed by CORS and sign-in: the shell's (and tauri://localhost for the desktop host)",
70
+ },
71
+ {
72
+ name: "ELOXIV_DATABASE_URL",
73
+ roles: ["kernel", "setup", "zero"],
74
+ secret: true,
75
+ example: "postgres://eloxiv_kernel:<password>@db.example.com:5432/eloxiv?sslmode=require",
76
+ what: "the kernel's runtime role on the app's database (setup creates the role)",
77
+ },
78
+ {
79
+ name: "ELOXIV_ADMIN_DATABASE_URL",
80
+ roles: ["setup", "kernel", "zero"],
81
+ secret: true,
82
+ example: "postgres://postgres:<password>@db.example.com:5432/postgres?sslmode=require",
83
+ what: "setup's role, directly (no transaction pooler): eloxiv db host <provider>",
84
+ },
85
+ {
86
+ name: "ELOXIV_AUTH_SECRET",
87
+ roles: ["kernel", "setup"],
88
+ secret: true,
89
+ example: "<openssl rand -base64 48>",
90
+ what: "signs sessions; at least 32 characters",
91
+ },
92
+ {
93
+ name: "ELOXIV_MAKE_ROLE_KEY",
94
+ roles: ["kernel", "setup"],
95
+ secret: true,
96
+ example: "<openssl rand -base64 48>",
97
+ what: "derives MAKE modules' role passwords",
98
+ },
99
+ {
100
+ name: "ELOXIV_SECRETS_KEYS",
101
+ roles: ["kernel"],
102
+ secret: true,
103
+ example: "<key id>:<openssl rand -base64 32>",
104
+ what: "encrypts stored credentials (Secrets); several keys rotate",
105
+ },
106
+ {
107
+ name: "ELOXIV_ZERO_APP_ID",
108
+ roles: ["kernel", "setup", "zero"],
109
+ secret: false,
110
+ example: "zero",
111
+ what: "zero-cache's app id; the same for the kernel and zero-cache",
112
+ },
113
+ {
114
+ name: "ELOXIV_ZERO_API_KEY",
115
+ roles: ["kernel", "zero"],
116
+ secret: true,
117
+ example: "<openssl rand -base64 32>",
118
+ what: "the key zero-cache sends with each push (its ZERO_MUTATE_API_KEY); the same for both",
119
+ },
120
+ {
121
+ name: "ZERO_ADMIN_PASSWORD",
122
+ roles: ["zero"],
123
+ secret: true,
124
+ example: "<openssl rand -base64 24>",
125
+ what: "zero-cache's admin password (required in production)",
126
+ },
127
+ {
128
+ name: "ZERO_REPLICA_FILE",
129
+ roles: ["zero"],
130
+ secret: false,
131
+ example: "/data/replica.db",
132
+ what: "zero-cache's SQLite replica, on a persistent volume",
133
+ },
134
+ {
135
+ name: "ELOXIV_KERNEL_INTERNAL_URL",
136
+ roles: ["zero"],
137
+ secret: false,
138
+ example: "http://kernel:4100",
139
+ what: "where zero-cache reaches the kernel's /zero/query and /zero/mutate (default ELOXIV_BASE_URL)",
140
+ },
141
+ ]
142
+
143
+ /**
144
+ * How a recipe runs the CLI: its built entry on Bun, so the kernel it starts runs on Bun (decisions.md's runtime;
145
+ * `pnpm exec eloxiv` would run it on Node, the fallback). zero-cache still runs on the image's Node.
146
+ */
147
+ export const RECIPE_CLI = ["bun", "node_modules/@eloxiv/cli/dist/bin.js"] as const
148
+ const cli = (role: string) => `${RECIPE_CLI.join(" ")} start ${role}`
149
+ const cliArray = (role: string) => JSON.stringify([...RECIPE_CLI, "start", role]).replaceAll(",", ", ")
150
+
151
+ const header = (target: DeployTarget) =>
152
+ `# Generated by \`eloxiv deploy ${target}\` (docs/cli.md, "Deploying"). It is yours: edit it, keep it in git.\n`
153
+
154
+ const dockerfile = (target: DeployTarget, app: AppFacts) => `# syntax=docker/dockerfile:1
155
+ ${header(target)}# One image for every role: eloxiv start setup | kernel | zero | shell.
156
+ # No secret enters the image: .dockerignore keeps every env file and .npmrc out of the build context, and a private
157
+ # registry's credentials reach pnpm only as the build secret \`npmrc\` (an .npmrc), mounted for the install alone.
158
+ FROM node:24-bookworm-slim AS base
159
+ # The kernel runs on Bun; zero-cache needs Node.
160
+ COPY --from=oven/bun:1.4 /usr/local/bin/bun /usr/local/bin/bun
161
+ RUN corepack enable
162
+ WORKDIR /app
163
+
164
+ FROM base AS build
165
+ COPY . .
166
+ RUN --mount=type=secret,id=npmrc,target=/root/.npmrc,required=false pnpm install --frozen-lockfile
167
+ ${
168
+ app.shell
169
+ ? `# The URLs the deployed shell talks to are compiled into it.
170
+ ARG VITE_ELOXIV_URL
171
+ ARG VITE_ELOXIV_SYNC_URL
172
+ RUN test -n "$VITE_ELOXIV_URL" && test -n "$VITE_ELOXIV_SYNC_URL" && ${RECIPE_CLI.join(" ")} build
173
+ `
174
+ : ""
175
+ }
176
+ FROM base
177
+ ENV NODE_ENV=production ELOXIV_ENV=production
178
+ COPY --from=build /app /app
179
+ EXPOSE 4100 4848${app.shell ? " 8080" : ""}
180
+ CMD ${cliArray("kernel")}
181
+ `
182
+
183
+ /** Kept out of the build context, so out of every image: dependencies and outputs, and every file that may hold a secret. */
184
+ const DOCKERIGNORE = `node_modules
185
+ **/node_modules
186
+ **/dist
187
+ .eloxiv
188
+ .git
189
+ desktop/src-tauri/target
190
+ desktop-rune/target
191
+ *.log
192
+ # Environment files at any depth (.env, .env.production, deploy/.env, prod.env, ...), and package credentials.
193
+ **/.env
194
+ **/.env.*
195
+ **/*.env
196
+ **/.npmrc
197
+ **/.yarnrc.yml
198
+ `
199
+
200
+ /** A role's variables as a Compose mapping, each taken from deploy/.env (`--env-file`); fixed ones are the recipe's. */
201
+ const roleEnvironment = (role: "zero" | "shell") =>
202
+ PRODUCTION_ENV.filter(
203
+ // ELOXIV_ENV is the image's (production); the zero-cache paths are fixed below.
204
+ (v) =>
205
+ v.roles.includes(role) && !["ELOXIV_ENV", "ZERO_REPLICA_FILE", "ELOXIV_KERNEL_INTERNAL_URL"].includes(v.name),
206
+ )
207
+ .map((v) => ` ${v.name}: \${${v.name}}`)
208
+ .join("\n")
209
+
210
+ const readyProbe = `["CMD", "node", "-e", "fetch('http://localhost:4100/ready').then((r) => process.exit(r.ok ? 0 : 1), () => process.exit(1))"]`
211
+
212
+ const compose = (
213
+ app: AppFacts,
214
+ ) => `${header("docker")}# docker compose -f deploy/compose.yaml --env-file deploy/.env up -d --build (PostgreSQL is yours: eloxiv db host <provider>)
215
+ # The kernel and setup read the whole of deploy/.env (connector and model settings included); zero-cache and the
216
+ # shell get only what their role needs, so the static shell never holds a database URL, a session secret or a key.
217
+ x-app: &app
218
+ image: ${app.name}:latest
219
+ restart: unless-stopped
220
+
221
+ services:
222
+ setup:
223
+ <<: *app
224
+ build:
225
+ context: ..
226
+ dockerfile: deploy/Dockerfile
227
+ secrets: [npmrc]${
228
+ app.shell
229
+ ? `
230
+ args:
231
+ VITE_ELOXIV_URL: \${ELOXIV_BASE_URL}
232
+ VITE_ELOXIV_SYNC_URL: \${ELOXIV_ZERO_URL}`
233
+ : ""
234
+ }
235
+ command: ${cliArray("setup")}
236
+ env_file: .env
237
+ restart: "no"
238
+ kernel:
239
+ <<: *app
240
+ command: ${cliArray("kernel")}
241
+ env_file: .env
242
+ depends_on:
243
+ setup:
244
+ condition: service_completed_successfully
245
+ ports: ["4100:4100"]
246
+ healthcheck:
247
+ test: ${readyProbe}
248
+ interval: 10s
249
+ start_period: 30s
250
+ zero:
251
+ <<: *app
252
+ command: ${cliArray("zero")}
253
+ environment:
254
+ ${roleEnvironment("zero")}
255
+ ZERO_REPLICA_FILE: /data/replica.db
256
+ ELOXIV_KERNEL_INTERNAL_URL: http://kernel:4100
257
+ volumes: ["zero-replica:/data"]
258
+ depends_on:
259
+ kernel:
260
+ condition: service_healthy
261
+ ports: ["4848:4848"]${
262
+ app.shell
263
+ ? `
264
+ shell:
265
+ <<: *app
266
+ command: ${cliArray("shell")}
267
+ environment:
268
+ ${roleEnvironment("shell")}
269
+ PORT: "8080"
270
+ ports: ["8080:8080"]`
271
+ : ""
272
+ }
273
+
274
+ volumes:
275
+ zero-replica:
276
+
277
+ secrets:
278
+ # A private registry's .npmrc for the install (NPMRC_FILE=~/.npmrc); none: an empty one.
279
+ npmrc:
280
+ file: \${NPMRC_FILE:-/dev/null}
281
+ `
282
+
283
+ const flyApp = (app: AppFacts, role: "kernel" | "zero" | "shell") => {
284
+ const name = `${app.name}-${role}`
285
+ const port = role === "kernel" ? 4100 : role === "zero" ? 4848 : 8080
286
+ const env =
287
+ role === "kernel"
288
+ ? [`ELOXIV_PORT = "4100"`, `ELOXIV_BASE_URL = "https://${name}.fly.dev"`]
289
+ : role === "zero"
290
+ ? [
291
+ `ZERO_REPLICA_FILE = "/data/replica.db"`,
292
+ `ELOXIV_KERNEL_INTERNAL_URL = "http://${app.name}-kernel.internal:4100"`,
293
+ ]
294
+ : [
295
+ `PORT = "8080"`,
296
+ `ELOXIV_BASE_URL = "https://${app.name}-kernel.fly.dev"`,
297
+ `ELOXIV_ZERO_URL = "https://${app.name}-zero.fly.dev"`,
298
+ ]
299
+ return [
300
+ header("fly").trimEnd(),
301
+ `# fly deploy -c deploy/fly/${role}.toml (set secrets with fly secrets set -a ${name} ...)`,
302
+ `app = "${name}"`,
303
+ `primary_region = "iad"`,
304
+ "",
305
+ "[build]",
306
+ ` dockerfile = "../Dockerfile"`,
307
+ // One Dockerfile for every role: with a shell it builds the shell, so every role's image needs its URLs.
308
+ ...(app.shell
309
+ ? [
310
+ "",
311
+ "[build.args]",
312
+ ` VITE_ELOXIV_URL = "https://${app.name}-kernel.fly.dev"`,
313
+ ` VITE_ELOXIV_SYNC_URL = "https://${app.name}-zero.fly.dev"`,
314
+ ]
315
+ : []),
316
+ ...(role === "kernel"
317
+ ? [
318
+ "",
319
+ "[deploy]",
320
+ " # Setup runs once per release, before new kernels start (Release: one setup at a time, under its lease).",
321
+ ` release_command = "${cli("setup")}"`,
322
+ ]
323
+ : []),
324
+ "",
325
+ "[env]",
326
+ ` ELOXIV_ENV = "production"`,
327
+ ...env.map((line) => ` ${line}`),
328
+ "",
329
+ "[processes]",
330
+ ` app = "${cli(role)}"`,
331
+ ...(role === "zero"
332
+ ? [
333
+ "",
334
+ "# zero-cache's replica survives restarts; one machine per volume.",
335
+ "[[mounts]]",
336
+ ` source = "zero_replica"`,
337
+ ` destination = "/data"`,
338
+ ]
339
+ : []),
340
+ "",
341
+ "[http_service]",
342
+ ` internal_port = ${port}`,
343
+ " force_https = true",
344
+ " # The kernel and sync hold long-lived connections: never scale to zero.",
345
+ ` auto_stop_machines = "off"`,
346
+ " min_machines_running = 1",
347
+ ...(role === "kernel"
348
+ ? [
349
+ "",
350
+ "[[http_service.checks]]",
351
+ ` path = "/ready"`,
352
+ ` interval = "15s"`,
353
+ ` timeout = "5s"`,
354
+ ` grace_period = "30s"`,
355
+ ]
356
+ : []),
357
+ "",
358
+ ].join("\n")
359
+ }
360
+
361
+ const railwayService = (role: "kernel" | "zero" | "shell") =>
362
+ `${JSON.stringify(
363
+ {
364
+ $schema: "https://railway.com/railway.schema.json",
365
+ build: { builder: "DOCKERFILE", dockerfilePath: "deploy/Dockerfile" },
366
+ deploy: {
367
+ startCommand: cli(role),
368
+ ...(role === "kernel"
369
+ ? { preDeployCommand: [cli("setup")], healthcheckPath: "/ready", healthcheckTimeout: 120 }
370
+ : {}),
371
+ restartPolicyType: "ON_FAILURE",
372
+ // Long-lived sync and kernel connections: no sleeping.
373
+ sleepApplication: false,
374
+ },
375
+ },
376
+ null,
377
+ 2,
378
+ )}\n`
379
+
380
+ const envExample = (target: DeployTarget, app: AppFacts) =>
381
+ `${header(target)}# Copy to deploy/.env (never commit it) or set each in the host's secrets, then run eloxiv deploy check.
382
+ ${PRODUCTION_ENV.filter((v) => app.shell || !(v.roles.length === 1 && v.roles[0] === "shell"))
383
+ .map((v) => `\n# ${v.what} [${v.roles.join(", ")}]${v.secret ? " (secret)" : ""}\n${v.name}=${v.example}`)
384
+ .join("\n")}
385
+ `
386
+
387
+ /** The files `eloxiv deploy <target>` writes for the app in `dir`. */
388
+ export const deployFiles = (dir: string, target: DeployTarget, name: string): ReadonlyArray<DeployFile> => {
389
+ const app: AppFacts = { name: name.toLowerCase().replace(/[^a-z0-9-]/g, "-"), shell: shellDir(dir) !== undefined }
390
+ const roles = app.shell ? (["kernel", "zero", "shell"] as const) : (["kernel", "zero"] as const)
391
+ const common = [
392
+ { path: "deploy/Dockerfile", content: dockerfile(target, app) },
393
+ { path: ".dockerignore", content: DOCKERIGNORE },
394
+ { path: "deploy/env.example", content: envExample(target, app) },
395
+ ]
396
+ switch (target) {
397
+ case "docker":
398
+ return [...common, { path: "deploy/compose.yaml", content: compose(app) }]
399
+ case "fly":
400
+ return [...common, ...roles.map((role) => ({ path: `deploy/fly/${role}.toml`, content: flyApp(app, role) }))]
401
+ case "railway":
402
+ return [
403
+ ...common,
404
+ ...roles.map((role) => ({ path: `deploy/railway/${role}.json`, content: railwayService(role) })),
405
+ ]
406
+ }
407
+ }
408
+
409
+ /** The next steps printed after the files are written: the operator deploys, never the CLI. */
410
+ export const deployNextSteps = (target: DeployTarget): ReadonlyArray<string> => {
411
+ const common = [
412
+ "Fill deploy/env.example's values into your host's secrets (or deploy/.env, never committed), then run eloxiv deploy check --env-file <file>.",
413
+ "Pick and prepare PostgreSQL: eloxiv db host <neon|supabase|rds|azure|cloud-sql|postgres>, then eloxiv db check --live.",
414
+ "A private package registry: give its .npmrc to the build as the secret npmrc (never COPY it; .dockerignore keeps it and every env file out of the image).",
415
+ ]
416
+ switch (target) {
417
+ case "docker":
418
+ return [
419
+ ...common,
420
+ "Build and start: docker compose -f deploy/compose.yaml --env-file deploy/.env up -d --build (with a private registry: NPMRC_FILE=~/.npmrc before it)",
421
+ ]
422
+ case "fly":
423
+ return [
424
+ ...common,
425
+ "Create the apps (fly apps create <name>-kernel, -zero, -shell) and zero's volume (fly volumes create zero_replica -a <name>-zero), set secrets, then fly deploy -c deploy/fly/<role>.toml for kernel, zero, then shell (with a private registry: --build-secret npmrc=\"$(cat ~/.npmrc)\"); set each app only its role's secrets (deploy/env.example names the roles)",
426
+ ]
427
+ case "railway":
428
+ return [
429
+ ...common,
430
+ "Create one Railway service per role from this repository, point each at deploy/railway/<role>.json (Settings → Config-as-code), give zero a volume mounted at /data, set the variables",
431
+ ]
432
+ }
433
+ }
434
+
435
+ export interface PreflightCheck {
436
+ readonly id: string
437
+ readonly status: "pass" | "warn" | "fail" | "not-run"
438
+ readonly detail: string
439
+ }
440
+
441
+ const DEV_SECRET = "eloxiv-dev-secret-change-me-0123456789"
442
+
443
+ /** Parse a dotenv file: `NAME=value` lines; `#` comments; surrounding quotes removed. */
444
+ export const parseEnvFile = (text: string): Record<string, string> =>
445
+ Object.fromEntries(
446
+ text
447
+ .split(/\r?\n/)
448
+ .map((line) => line.trim())
449
+ .filter((line) => line !== "" && !line.startsWith("#") && line.includes("="))
450
+ .map((line) => {
451
+ const at = line.indexOf("=")
452
+ const value = line.slice(at + 1).trim()
453
+ return [
454
+ line
455
+ .slice(0, at)
456
+ .trim()
457
+ .replace(/^export\s+/, ""),
458
+ value.replace(/^(["'])(.*)\1$/, "$2"),
459
+ ]
460
+ }),
461
+ )
462
+
463
+ const https = (value: string | undefined) => {
464
+ try {
465
+ return value !== undefined && new URL(value).protocol === "https:"
466
+ } catch {
467
+ return false
468
+ }
469
+ }
470
+
471
+ /**
472
+ * The production environment `env` checked against what the kernel, setup and zero-cache need, plus the app in
473
+ * `dir` (its server entry, the CLI the recipes run). Placeholders left from env.example fail.
474
+ */
475
+ export const preflight = (dir: string, env: NodeJS.ProcessEnv): ReadonlyArray<PreflightCheck> => {
476
+ const checks: Array<PreflightCheck> = []
477
+ const add = (id: string, ok: boolean, detail: string, otherwise: "fail" | "warn" = "fail") =>
478
+ checks.push({ id, status: ok ? "pass" : otherwise, detail })
479
+ const placeholders = Object.entries(env)
480
+ .filter(([name, value]) => /^(ELOXIV|ZERO)_/.test(name) && value?.includes("<") === true)
481
+ .map(([name]) => name)
482
+ add(
483
+ "placeholders",
484
+ placeholders.length === 0,
485
+ placeholders.length === 0 ? "none left" : `still placeholders: ${placeholders.join(", ")}`,
486
+ )
487
+ add("ELOXIV_ENV", env["ELOXIV_ENV"] === "production", `ELOXIV_ENV=${env["ELOXIV_ENV"] ?? "(unset: development)"}`)
488
+ add(
489
+ "ELOXIV_BASE_URL",
490
+ https(env["ELOXIV_BASE_URL"]),
491
+ `${env["ELOXIV_BASE_URL"] ?? "(unset)"}: the kernel's public https URL`,
492
+ )
493
+ const secret = env["ELOXIV_AUTH_SECRET"] ?? ""
494
+ add(
495
+ "ELOXIV_AUTH_SECRET",
496
+ secret.length >= 32 && secret !== DEV_SECRET,
497
+ secret === ""
498
+ ? "unset: sessions would be signed with the development secret"
499
+ : secret === DEV_SECRET
500
+ ? "the development secret"
501
+ : secret.length < 32
502
+ ? "shorter than 32 characters"
503
+ : "set",
504
+ )
505
+ add(
506
+ "ELOXIV_MAKE_ROLE_KEY",
507
+ (env["ELOXIV_MAKE_ROLE_KEY"] ?? "") !== "",
508
+ env["ELOXIV_MAKE_ROLE_KEY"] ? "set" : "unset: required in production",
509
+ )
510
+ add(
511
+ "ELOXIV_SECRETS_KEYS",
512
+ (env["ELOXIV_SECRETS_KEYS"] ?? "") !== "",
513
+ env["ELOXIV_SECRETS_KEYS"] ? "set" : "unset: stored credentials (Connections) cannot be encrypted",
514
+ "warn",
515
+ )
516
+ const origins = (env["ELOXIV_TRUSTED_ORIGINS"] ?? "")
517
+ .split(",")
518
+ .map((o) => o.trim())
519
+ .filter((o) => o !== "")
520
+ const loose = origins.filter((o) => !https(o) && !o.startsWith("tauri://") && o !== "http://tauri.localhost")
521
+ add(
522
+ "ELOXIV_TRUSTED_ORIGINS",
523
+ origins.length > 0 && loose.length === 0,
524
+ origins.length === 0
525
+ ? "unset: only localhost origins would be trusted"
526
+ : loose.length > 0
527
+ ? `not https: ${loose.join(", ")}`
528
+ : origins.join(", "),
529
+ )
530
+ add(
531
+ "ELOXIV_ZERO_API_KEY",
532
+ (env["ELOXIV_ZERO_API_KEY"] ?? "") !== "",
533
+ env["ELOXIV_ZERO_API_KEY"] ? "set" : "unset: the kernel refuses zero-cache's pushes in production",
534
+ )
535
+ add(
536
+ "ZERO_ADMIN_PASSWORD",
537
+ (env["ZERO_ADMIN_PASSWORD"] ?? "") !== "",
538
+ env["ZERO_ADMIN_PASSWORD"] ? "set" : "unset: zero-cache refuses to start in production",
539
+ )
540
+ if (shellDir(dir) !== undefined) {
541
+ add(
542
+ "ELOXIV_ZERO_URL",
543
+ https(env["ELOXIV_ZERO_URL"]),
544
+ `${env["ELOXIV_ZERO_URL"] ?? "(unset)"}: sync's public https URL, compiled into the shell`,
545
+ )
546
+ }
547
+ for (const check of checkUrls(env)) {
548
+ checks.push({ id: check.env, status: check.status === "not-run" ? "fail" : check.status, detail: check.detail })
549
+ }
550
+ add("server entry", existsSync(join(dir, "server", "main.ts")), "server/main.ts (the app item)")
551
+ let pkg: Record<string, Record<string, string> | undefined> = {}
552
+ try {
553
+ pkg = JSON.parse(readFileSync(join(dir, "package.json"), "utf8"))
554
+ } catch {
555
+ // reported by the check below
556
+ }
557
+ add(
558
+ "@eloxiv/cli",
559
+ pkg["dependencies"]?.["@eloxiv/cli"] !== undefined || pkg["devDependencies"]?.["@eloxiv/cli"] !== undefined,
560
+ "the recipes run eloxiv start <role> (node_modules/@eloxiv/cli): @eloxiv/cli in package.json",
561
+ )
562
+ return checks
563
+ }