@eloxiv/cli 0.0.0-stage → 0.1.0

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 +108 -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 +49 -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 +34 -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/Doctor.ts ADDED
@@ -0,0 +1,424 @@
1
+ /**
2
+ * Checking an app and tidying it:
3
+ *
4
+ * eloxiv doctor every check of the app's assembly, each passed, failed, warned or not run (and why), and
5
+ * the inactive replication slots of its database (ELOXIV_DATABASE_URL) and the WAL they hold
6
+ * eloxiv clean remove what is rebuilt on demand (build outputs, caches); a dry run unless --yes
7
+ *
8
+ * A check that could not run (the registry unreachable, dependencies not installed) says so: it is never reported
9
+ * as passed.
10
+ */
11
+ import type { ProvenanceEntry } from "@eloxiv/contracts"
12
+ import { Console, Effect, FileSystem, Path } from "effect"
13
+ import { spawnSync } from "node:child_process"
14
+ import {
15
+ CLI_VERSION,
16
+ CliError,
17
+ CONFIG_FILE,
18
+ AppConfig,
19
+ composition,
20
+ LOCK_FILE,
21
+ lockPath,
22
+ readConfig,
23
+ readJson,
24
+ readLock,
25
+ readPackage,
26
+ type MutableLock,
27
+ } from "./App.ts"
28
+ import { DEPENDENCY_FIELDS, specMap } from "./Dependencies.ts"
29
+ import { asText, readAppBytes, safeAppPath, sha256Bytes } from "./Files.ts"
30
+ import { moduleSyncTables, staleMutatorsFiles } from "./Generate.ts"
31
+ import { migrate } from "./Dossier.ts"
32
+ import { GUARD_RULES, guardFindings } from "./Guards.ts"
33
+ import { hasConflictMarkers } from "./Merge.ts"
34
+ import { fetchItem } from "./Registry.ts"
35
+ import { fetchBase, kindOf } from "./Update.ts"
36
+
37
+ export type CheckStatus = "pass" | "warn" | "fail" | "not-run"
38
+
39
+ export interface Check {
40
+ readonly id: string
41
+ readonly status: CheckStatus
42
+ readonly detail: string
43
+ }
44
+
45
+ export interface DoctorReport {
46
+ readonly checks: ReadonlyArray<Check>
47
+ /** Whether any check failed. Checks that did not run do not fail the app, but are never counted as passed. */
48
+ readonly failed: boolean
49
+ }
50
+
51
+ /** The runtimes the CLI and the kernel support (the workspace's `engines`). */
52
+ export const SUPPORTED_RUNTIMES = { node: [24, 11], bun: [1, 4] } as const
53
+
54
+ /** Whether this process runs on a supported Node or Bun: `undefined` when it does, else why not. */
55
+ export const runtimeProblem = (versions: { readonly node?: string; readonly bun?: string } = process.versions) => {
56
+ const below = (version: string, [major, minor]: readonly [number, number]) => {
57
+ const [x = 0, y = 0] = version.split(".").map(Number)
58
+ return x < major || (x === major && y < minor)
59
+ }
60
+ if (versions.bun !== undefined) {
61
+ return below(versions.bun, SUPPORTED_RUNTIMES.bun)
62
+ ? `Bun ${versions.bun} is too old: Eloxiv needs Bun ${SUPPORTED_RUNTIMES.bun.join(".")} or later`
63
+ : undefined
64
+ }
65
+ if (versions.node === undefined) return "Eloxiv runs on Node or Bun"
66
+ return below(versions.node, SUPPORTED_RUNTIMES.node)
67
+ ? `Node ${versions.node} is too old: Eloxiv needs Node ${SUPPORTED_RUNTIMES.node.join(".")} or later`
68
+ : undefined
69
+ }
70
+
71
+ /** Files of the app that differ from `expected` (missing ones included). */
72
+ const stale = (dir: string, expected: ReadonlyArray<readonly [string, string]>) =>
73
+ Effect.gen(function* () {
74
+ const out: Array<string> = []
75
+ for (const [file, content] of expected) {
76
+ const bytes = yield* readAppBytes(dir, file)
77
+ if (bytes === undefined || asText(bytes) !== content) out.push(lockPath(file))
78
+ }
79
+ return out
80
+ })
81
+
82
+ const itemChecks = (dir: string, registry: string, entry: ProvenanceEntry) =>
83
+ Effect.gen(function* () {
84
+ const checks: Array<Check> = []
85
+ const id = (what: string) => `${entry.name}: ${what}`
86
+ // The files as installed: missing, edited, or holding conflict markers.
87
+ const missing: Array<string> = []
88
+ const edited: Array<string> = []
89
+ const markers: Array<string> = []
90
+ for (const file of entry.files) {
91
+ const path = lockPath(file.path)
92
+ const bytes = yield* readAppBytes(dir, path)
93
+ if (bytes === undefined) {
94
+ missing.push(path)
95
+ continue
96
+ }
97
+ if ((yield* sha256Bytes(bytes)) === file.sha256) continue
98
+ edited.push(path)
99
+ const text = asText(bytes)
100
+ if (text !== undefined && hasConflictMarkers(text)) markers.push(path)
101
+ }
102
+ const conflicts = (entry.conflicts ?? []).map((c) => c.path)
103
+ if (conflicts.length > 0 || markers.length > 0) {
104
+ checks.push({
105
+ id: id("conflicts"),
106
+ status: "fail",
107
+ detail: `unresolved: ${[...new Set([...conflicts, ...markers])].join(", ")} (resolve them, then eloxiv update --continue)`,
108
+ })
109
+ } else if (entry.owner === "app") {
110
+ checks.push({ id: id("files"), status: "pass", detail: "app-owned: its files are the app's" })
111
+ } else if (missing.length > 0) {
112
+ checks.push({ id: id("files"), status: "warn", detail: `deleted locally: ${missing.join(", ")}` })
113
+ } else {
114
+ checks.push({
115
+ id: id("files"),
116
+ status: "pass",
117
+ detail: edited.length === 0 ? "as installed" : `edited locally: ${edited.join(", ")}`,
118
+ })
119
+ }
120
+ if (entry.owner === "app") return checks
121
+ // The installed version can be fetched again, unchanged: the base of the next update.
122
+ const base = yield* fetchBase(registry, entry).pipe(Effect.result)
123
+ if (base._tag === "Failure") checks.push({ id: id("base"), status: "fail", detail: base.failure.message })
124
+ else if (base.success === undefined) {
125
+ // Unpublished, or the registry cannot be reached: tell the two apart.
126
+ const latest = yield* fetchItem(registry, entry.name).pipe(Effect.result)
127
+ checks.push(
128
+ latest._tag === "Failure" && !latest.failure.message.startsWith("No item")
129
+ ? { id: id("base"), status: "not-run", detail: `the registry could not be read: ${latest.failure.message}` }
130
+ : {
131
+ id: id("base"),
132
+ status: "fail",
133
+ detail: `${entry.registryVersion} is not published in the registry: update cannot merge without it`,
134
+ },
135
+ )
136
+ } else checks.push({ id: id("base"), status: "pass", detail: `${entry.registryVersion} is published, unchanged` })
137
+ return checks
138
+ })
139
+
140
+ /** `eloxiv doctor`: check the app's assembly. */
141
+ export const doctor = Effect.fn("Doctor.doctor")(function* (dir: string) {
142
+ const fs = yield* FileSystem.FileSystem
143
+ const path = yield* Path.Path
144
+ const checks: Array<Check> = []
145
+ const problem = runtimeProblem()
146
+ checks.push({
147
+ id: "runtime",
148
+ status: problem === undefined ? "pass" : "fail",
149
+ detail:
150
+ problem ??
151
+ (process.versions["bun"] !== undefined ? `Bun ${process.versions["bun"]}` : `Node ${process.versions.node}`) +
152
+ `, eloxiv ${CLI_VERSION}`,
153
+ })
154
+ const config = yield* readJson(AppConfig, path.join(dir, CONFIG_FILE)).pipe(Effect.result)
155
+ if (config._tag === "Failure") {
156
+ checks.push({ id: "config", status: "fail", detail: config.failure.message })
157
+ return { checks, failed: true } satisfies DoctorReport
158
+ }
159
+ checks.push({ id: "config", status: "pass", detail: `registry ${config.success.registry}` })
160
+ const lockFile = path.join(dir, LOCK_FILE)
161
+ if (!(yield* fs.exists(lockFile))) {
162
+ checks.push({ id: "lockfile", status: "warn", detail: `no ${LOCK_FILE}: nothing installed yet (eloxiv add)` })
163
+ return { checks, failed: checks.some((c) => c.status === "fail") } satisfies DoctorReport
164
+ }
165
+ const lock = yield* readLock(dir).pipe(Effect.result)
166
+ if (lock._tag === "Failure") {
167
+ checks.push({ id: "lockfile", status: "fail", detail: lock.failure.message })
168
+ return { checks, failed: true } satisfies DoctorReport
169
+ }
170
+ checks.push({ id: "lockfile", status: "pass", detail: `${Object.keys(lock.success.items).length} items installed` })
171
+ const { registry } = yield* readConfig(dir)
172
+ for (const entry of Object.values(lock.success.items).sort((a, b) => a.name.localeCompare(b.name)))
173
+ checks.push(...(yield* itemChecks(dir, registry, entry)))
174
+
175
+ // The composition files are what the generator writes for what is installed.
176
+ // (The same inputs as the generator: model connectors and the kernel modules UI items ask for included.)
177
+ const { modules, files } = yield* composition(dir, lock.success)
178
+ const outdated = yield* stale(dir, files)
179
+ checks.push(
180
+ outdated.length === 0
181
+ ? {
182
+ id: "composition",
183
+ status: "pass",
184
+ detail: "eloxiv.modules.ts, eloxiv.server.ts, eloxiv.schema.ts, eloxiv.sync.ts are current",
185
+ }
186
+ : { id: "composition", status: "fail", detail: `not current: ${outdated.join(", ")} (run eloxiv generate)` },
187
+ )
188
+
189
+ // package.json has every npm dependency an installed item asks for (another version is the app's pin).
190
+ const pkg = yield* readPackage(dir).pipe(Effect.result)
191
+ if (pkg._tag === "Failure") checks.push({ id: "dependencies", status: "fail", detail: pkg.failure.message })
192
+ else {
193
+ const missing: Array<string> = []
194
+ const pinned: Array<string> = []
195
+ for (const entry of Object.values(lock.success.items)) {
196
+ if (entry.owner === "app") continue
197
+ const base = yield* fetchBase(registry, entry).pipe(Effect.orElseSucceed(() => undefined))
198
+ if (base === undefined) continue
199
+ for (const field of DEPENDENCY_FIELDS) {
200
+ for (const [name, version] of specMap(base[field])) {
201
+ const have =
202
+ pkg.success[field]?.[name] ??
203
+ pkg.success[field === "dependencies" ? "devDependencies" : "dependencies"]?.[name]
204
+ if (have === undefined) missing.push(`${name}@${version} (${entry.name})`)
205
+ else if (have !== version) pinned.push(`${name}@${have}, ${entry.name} asks for ${version}`)
206
+ }
207
+ }
208
+ }
209
+ checks.push(
210
+ missing.length > 0
211
+ ? {
212
+ id: "dependencies",
213
+ status: "fail",
214
+ detail: `missing from package.json: ${[...new Set(missing)].join(", ")}`,
215
+ }
216
+ : pinned.length > 0
217
+ ? { id: "dependencies", status: "warn", detail: `pinned by the app: ${[...new Set(pinned)].join("; ")}` }
218
+ : { id: "dependencies", status: "pass", detail: "package.json has every dependency the items ask for" },
219
+ )
220
+ }
221
+
222
+ // The modules' generated sync tables match their Drizzle tables and entities: needs the app's dependencies.
223
+ if (modules.length === 0) checks.push({ id: "sync tables", status: "pass", detail: "no modules" })
224
+ else if (!(yield* fs.exists(path.join(dir, "node_modules")))) {
225
+ checks.push({
226
+ id: "sync tables",
227
+ status: "not-run",
228
+ detail: "the app's dependencies are not installed (pnpm install)",
229
+ })
230
+ } else {
231
+ const generated = yield* Effect.tryPromise({
232
+ try: () => moduleSyncTables(dir, modules),
233
+ catch: (e) => (e instanceof Error ? e.message : String(e)),
234
+ }).pipe(Effect.result)
235
+ if (generated._tag === "Failure") {
236
+ checks.push({
237
+ id: "sync tables",
238
+ status: "not-run",
239
+ detail: `the modules' contracts could not be loaded: ${generated.failure}`,
240
+ })
241
+ } else {
242
+ const out = [
243
+ ...(yield* stale(dir, generated.success)),
244
+ ...staleMutatorsFiles(dir, modules, generated.success).map(lockPath),
245
+ ]
246
+ checks.push(
247
+ out.length === 0
248
+ ? { id: "sync tables", status: "pass", detail: "every module's sync.gen.ts is current" }
249
+ : { id: "sync tables", status: "fail", detail: `not current: ${out.join(", ")} (run eloxiv generate)` },
250
+ )
251
+ }
252
+ }
253
+ // Imports of what an installed item's compatibility migrations moved (eloxiv migrate fixes them).
254
+ const moved = yield* migrate(dir, [], { dryRun: true }).pipe(Effect.orElseSucceed(() => undefined))
255
+ if (moved === undefined)
256
+ checks.push({ id: "moved imports", status: "not-run", detail: "the migrations could not be read" })
257
+ else {
258
+ const shown = moved.slice(0, 10).map((m) => `${m.file}:${m.line} ${m.detail}`)
259
+ checks.push(
260
+ moved.length === 0
261
+ ? { id: "moved imports", status: "pass", detail: "no file imports what a migration moved" }
262
+ : {
263
+ id: "moved imports",
264
+ status: "fail",
265
+ detail: `${shown.join("; ")}${moved.length > 10 ? `; and ${moved.length - 10} more` : ""} (run eloxiv migrate${moved.some((m) => m.kind === "manual") ? "; some need a change by hand" : ""})`,
266
+ },
267
+ )
268
+ }
269
+ checks.push(...guardChecks(dir))
270
+ checks.push(replicationSlotsCheck())
271
+ return { checks, failed: checks.some((c) => c.status === "fail") } satisfies DoctorReport
272
+ })
273
+
274
+ /** The architecture and security guards over the app's own source (Guards.ts), one check per rule. */
275
+ export const guardChecks = (dir: string): ReadonlyArray<Check> => {
276
+ const findings = guardFindings(dir)
277
+ return GUARD_RULES.map((rule) => {
278
+ const mine = findings.filter((f) => f.rule === rule)
279
+ const shown = mine.slice(0, 10).map((f) => `${f.file}:${f.line} ${f.detail}`)
280
+ return mine.length === 0
281
+ ? { id: rule, status: "pass" as const, detail: "nothing found" }
282
+ : {
283
+ id: rule,
284
+ status: "fail" as const,
285
+ detail: `${shown.join("; ")}${mine.length > 10 ? `; and ${mine.length - 10} more` : ""}`,
286
+ }
287
+ })
288
+ }
289
+
290
+ /** An inactive replication slot of the app's database and the WAL it holds back (bytes). */
291
+ export interface InactiveSlot {
292
+ readonly name: string
293
+ readonly retainedBytes: number
294
+ }
295
+
296
+ /** WAL an inactive slot may hold back before doctor warns (1 GiB). */
297
+ export const SLOT_WARN_BYTES = 1024 * 1024 * 1024
298
+
299
+ const mib = (bytes: number) => `${Math.round(bytes / 1024 / 1024)} MiB`
300
+
301
+ /**
302
+ * The replication-slots check, from the inactive slots of the app's database: a slot nobody reads holds back WAL
303
+ * without end (a development database's zero-cache slot held 58 GB). Every inactive slot is reported with what it
304
+ * holds; one over `SLOT_WARN_BYTES` warns. (`mise run dev` drops Eloxiv's own stale zero-cache slots itself.)
305
+ */
306
+ export const slotsCheck = (slots: ReadonlyArray<InactiveSlot>): Check => {
307
+ if (slots.length === 0) return { id: "replication slots", status: "pass", detail: "no inactive replication slot" }
308
+ const listed = slots.map((s) => `${s.name} (${mib(s.retainedBytes)})`).join(", ")
309
+ const large = slots.filter((s) => s.retainedBytes >= SLOT_WARN_BYTES)
310
+ // The exact command for each, to run if nothing will read the slot again (a replica resumes from its slot).
311
+ const drop = slots.map((s) => `SELECT pg_drop_replication_slot('${s.name.replaceAll("'", "''")}');`).join(" ")
312
+ return large.length > 0
313
+ ? {
314
+ id: "replication slots",
315
+ status: "warn",
316
+ detail:
317
+ `inactive slots hold back WAL: ${listed}. ${large.map((s) => s.name).join(", ")} over ${mib(SLOT_WARN_BYTES)}. ` +
318
+ `To drop one nothing will read again: ${drop}`,
319
+ }
320
+ : { id: "replication slots", status: "pass", detail: `inactive slots: ${listed}. To drop one: ${drop}` }
321
+ }
322
+
323
+ /** Reads the inactive slots of the app's database (`ELOXIV_DATABASE_URL`) with `psql`; not run without either. */
324
+ const replicationSlotsCheck = (env: NodeJS.ProcessEnv = process.env): Check => {
325
+ const url = env["ELOXIV_DATABASE_URL"]
326
+ if (url === undefined || url === "") {
327
+ return { id: "replication slots", status: "not-run", detail: "ELOXIV_DATABASE_URL is not set" }
328
+ }
329
+ const answer = spawnSync(
330
+ "psql",
331
+ [
332
+ "-X",
333
+ "-At",
334
+ url,
335
+ "-c",
336
+ `SELECT coalesce(json_agg(json_build_object('name', slot_name,
337
+ 'retainedBytes', coalesce(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn), 0)) ORDER BY slot_name), '[]')
338
+ FROM pg_catalog.pg_replication_slots WHERE database = current_database() AND NOT active`,
339
+ ],
340
+ { encoding: "utf8", timeout: 15_000 },
341
+ )
342
+ if (answer.error !== undefined || answer.status !== 0) {
343
+ const why = answer.error?.message ?? answer.stderr.trim().split("\n")[0] ?? `psql exited ${answer.status}`
344
+ return { id: "replication slots", status: "not-run", detail: `could not read the database's slots: ${why}` }
345
+ }
346
+ return slotsCheck(JSON.parse(answer.stdout.trim()) as ReadonlyArray<InactiveSlot>)
347
+ }
348
+
349
+ export const formatDoctor = (report: DoctorReport) => {
350
+ const label: Record<CheckStatus, string> = { pass: "ok ", warn: "warn", fail: "FAIL", "not-run": "skip" }
351
+ return [
352
+ ...report.checks.map((check) => `${label[check.status]} ${check.id}: ${check.detail}`),
353
+ report.failed
354
+ ? "Some checks failed."
355
+ : report.checks.some((c) => c.status === "not-run")
356
+ ? "No check failed; some could not run (skip)."
357
+ : "Every check passed.",
358
+ ].join("\n")
359
+ }
360
+
361
+ // ---------------------------------------------------------------------------------------------------------
362
+ // clean
363
+
364
+ /** What `clean` may remove: build outputs and caches the tools write again on demand. Never source or data. */
365
+ const cleanable = (lock: MutableLock) => {
366
+ // Each shell's directory: the top directory of its files.
367
+ const shells = new Set<string>()
368
+ for (const entry of Object.values(lock.items)) {
369
+ if (kindOf(entry) !== "shell") continue
370
+ for (const file of entry.files) {
371
+ const top = lockPath(file.path).split("/")[0]
372
+ if (top !== undefined && top !== "") shells.add(top)
373
+ }
374
+ }
375
+ const paths = new Set<string>()
376
+ for (const shell of shells) {
377
+ paths.add(`${shell}/dist`)
378
+ paths.add(`${shell}/node_modules/.vite`)
379
+ }
380
+ paths.add("node_modules/.vite")
381
+ paths.add(".eloxiv/tmp")
382
+ // Each desktop host's Cargo build output, beside its Cargo.lock (Tauri's desktop/src-tauri/target, the Rune host's
383
+ // desktop-rune/target).
384
+ for (const entry of Object.values(lock.items)) {
385
+ if (kindOf(entry) !== "desktop") continue
386
+ for (const file of entry.files) {
387
+ const path = lockPath(file.path)
388
+ if (path.endsWith("/Cargo.lock")) paths.add(`${path.slice(0, -"/Cargo.lock".length)}/target`)
389
+ }
390
+ }
391
+ return paths
392
+ }
393
+
394
+ export interface CleanReport {
395
+ readonly dryRun: boolean
396
+ readonly removed: ReadonlyArray<string>
397
+ }
398
+
399
+ /** `eloxiv clean`: remove build outputs and caches. Lists them only, unless `yes`. */
400
+ export const clean = Effect.fn("Doctor.clean")(function* (dir: string, options: { readonly yes: boolean }) {
401
+ const fs = yield* FileSystem.FileSystem
402
+ const lock = yield* readLock(dir)
403
+ // Every target is checked (safeAppPath's rule: no linked ancestor, inside the app once resolved) before anything is
404
+ // deleted; a target that is itself a symbolic link is removed as a link, never followed.
405
+ const planned: Array<{ readonly relative: string; readonly absolute: string; readonly directory: boolean }> = []
406
+ for (const relative of cleanable(lock)) {
407
+ const absolute = yield* safeAppPath(dir, relative, "remove")
408
+ const info = yield* fs.lstat(absolute).pipe(Effect.option)
409
+ if (info._tag === "None") continue
410
+ planned.push({ relative, absolute, directory: info.value.type === "Directory" })
411
+ }
412
+ const found = planned.map((target) => target.relative)
413
+ if (options.yes) {
414
+ for (const target of planned) {
415
+ yield* fs
416
+ .remove(target.absolute, { recursive: target.directory })
417
+ .pipe(Effect.mapError((e) => new CliError({ message: `Cannot remove ${target.relative}: ${e.message}` })))
418
+ }
419
+ }
420
+ for (const relative of found) yield* Console.log(`${options.yes ? "removed" : "would remove"} ${relative}`)
421
+ if (found.length === 0) yield* Console.log("nothing to clean")
422
+ else if (!options.yes) yield* Console.log("run eloxiv clean --yes to remove them")
423
+ return { dryRun: !options.yes, removed: found } satisfies CleanReport
424
+ })
package/src/Dossier.ts ADDED
@@ -0,0 +1,148 @@
1
+ /**
2
+ * `eloxiv migrate`: apply the installed items' compatibility migrations to the app's own files again (code written
3
+ * since the update), and `eloxiv migrate --dossier`: a portable migration brief, in Markdown, for a person or a coding
4
+ * agent to carry an app to the registry's latest versions (docs/cli.md, "migrate").
5
+ *
6
+ * The dossier is data the CLI already has, gathered in one place: per item, the installed and latest versions, what
7
+ * upstream changed (files, npm and registry dependencies), the app's local edits and which of them upstream also
8
+ * changed (where the three-way merge may conflict), the compatibility migrations between the two versions with their
9
+ * notes, the app files that use what moves, and the commands to run in order. Nothing is written.
10
+ */
11
+ import { Effect } from "effect"
12
+ import { readConfig, readLock } from "./App.ts"
13
+ import { CliError } from "./Errors.ts"
14
+ import { applyMigrations, migrationsBetween, type Migration, type MigrationChange } from "./Migrate.ts"
15
+ import { EloxivMeta, fetchItem, redactToken } from "./Registry.ts"
16
+ import { diff, selectEntries } from "./Update.ts"
17
+ import { Schema } from "effect"
18
+
19
+ const COMPOSITION = new Set(["eloxiv.modules.ts", "eloxiv.server.ts", "eloxiv.schema.ts", "eloxiv.sync.ts"])
20
+
21
+ const installedMigrations = (meta: unknown) =>
22
+ Schema.decodeUnknownOption(EloxivMeta)(meta).pipe((o) => (o._tag === "Some" ? (o.value.migrations ?? []) : []))
23
+
24
+ /**
25
+ * The migrations of every installed item (`names`, all when empty) up to its installed version, applied to the app's
26
+ * own files (nothing written with `dryRun`).
27
+ */
28
+ export const migrate = Effect.fn("Dossier.migrate")(function* (
29
+ dir: string,
30
+ names: ReadonlyArray<string>,
31
+ options: { readonly dryRun: boolean },
32
+ ) {
33
+ const lock = yield* readLock(dir)
34
+ const pending: Array<{ item: string; migration: Migration }> = []
35
+ for (const entry of yield* selectEntries(lock, names)) {
36
+ for (const migration of migrationsBetween(installedMigrations(entry.meta), undefined, entry.registryVersion))
37
+ pending.push({ item: entry.name, migration })
38
+ }
39
+ return applyMigrations(dir, pending, { dryRun: options.dryRun, exclude: COMPOSITION })
40
+ })
41
+
42
+ const list = (values: ReadonlyArray<string>, empty = "none") =>
43
+ values.length === 0 ? [`- ${empty}`] : values.map((v) => `- ${v}`)
44
+
45
+ const describeMove = (m: NonNullable<Migration["moves"]>[number]) =>
46
+ m.symbol === undefined
47
+ ? `module \`${m.from}\` → \`${m.to}\``
48
+ : `\`${m.symbol}\` from \`${m.from}\` → \`${m.as ?? m.symbol}\` from \`${m.to}\``
49
+
50
+ const migrationLines = (migrations: ReadonlyArray<Migration>) => {
51
+ const out: Array<string> = []
52
+ for (const m of migrations) {
53
+ for (const move of m.moves ?? []) out.push(`${m.since}: ${describeMove(move)} (applied by eloxiv update)`)
54
+ if (m.note !== undefined) out.push(`${m.since}: **by hand:** ${m.note}`)
55
+ }
56
+ return out
57
+ }
58
+
59
+ /** The migration dossier for `names` (all installed items when empty), as Markdown. */
60
+ export const dossier = Effect.fn("Dossier.dossier")(function* (dir: string, names: ReadonlyArray<string>) {
61
+ const { config, registry } = yield* readConfig(dir)
62
+ const report = yield* diff(dir, names)
63
+ const out: Array<string> = [
64
+ `# Migration dossier: ${config.name}`,
65
+ "",
66
+ `Generated by \`eloxiv migrate --dossier\` on ${new Date().toISOString().slice(0, 10)} from ${redactToken(registry)}. It describes; it changes nothing. Work through "Steps" at the end.`,
67
+ "",
68
+ "| Item | Kind | Installed | Latest | Local edits | Upstream changes | Likely conflicts |",
69
+ "| --- | --- | --- | --- | --- | --- | --- |",
70
+ ]
71
+ const sections: Array<string> = []
72
+ const manualAll: Array<MigrationChange> = []
73
+ for (const item of report.items) {
74
+ const upstreamPaths = new Set(item.upstream.map((u) => u.path))
75
+ const overlapping = item.local.filter((l) => upstreamPaths.has(l.path)).map((l) => l.path)
76
+ out.push(
77
+ `| ${item.name} | ${item.kind} | ${item.installed.version} | ${item.latest?.version ?? "not published"} | ${item.local.length} | ${item.upstream.length} | ${item.owner === "app" ? "app-owned" : overlapping.length} |`,
78
+ )
79
+ if (item.owner === "app" || item.latest === null || item.latest.contentHash === item.installed.contentHash) continue
80
+ const latest = yield* fetchItem(registry, item.name).pipe(
81
+ Effect.mapError((e) => new CliError({ message: e.message })),
82
+ )
83
+ const migrations = migrationsBetween(
84
+ latest.meta.eloxiv.migrations ?? [],
85
+ item.installed.version,
86
+ item.latest.version,
87
+ )
88
+ const affected = applyMigrations(
89
+ dir,
90
+ migrations.map((migration) => ({ item: item.name, migration })),
91
+ {
92
+ dryRun: true,
93
+ exclude: new Set([...COMPOSITION, ...upstreamPaths]),
94
+ },
95
+ )
96
+ manualAll.push(...affected.filter((a) => a.kind === "manual"))
97
+ sections.push(
98
+ "",
99
+ `## ${item.name} ${item.installed.version} → ${item.latest.version}`,
100
+ "",
101
+ "Upstream changes:",
102
+ ...list(item.upstream.map((u) => `${u.change} \`${u.path}\``)),
103
+ ...(item.dependencies.length +
104
+ item.registryDependencies.added.length +
105
+ item.registryDependencies.removed.length ===
106
+ 0
107
+ ? []
108
+ : [
109
+ "",
110
+ "Dependencies:",
111
+ ...item.dependencies.map(
112
+ (d) => `- ${d.field} \`${d.name}\`: ${d.from ?? "(none)"} → ${d.to ?? "(removed)"}`,
113
+ ),
114
+ ...item.registryDependencies.added.map((d) => `- registry item \`${d}\` installed with it`),
115
+ ...item.registryDependencies.removed.map((d) => `- registry item \`${d}\` no longer needed`),
116
+ ]),
117
+ "",
118
+ "Your local edits:",
119
+ ...list(
120
+ item.local.map(
121
+ (l) =>
122
+ `${l.change} \`${l.path}\`${upstreamPaths.has(l.path) ? " (also changed upstream: merged line by line, a conflict where both changed the same lines)" : ""}`,
123
+ ),
124
+ ),
125
+ "",
126
+ "Compatibility migrations:",
127
+ ...list(migrationLines(migrations)),
128
+ "",
129
+ "Your files that use what moves:",
130
+ ...list(affected.map((a) => `\`${a.file}:${a.line}\` ${a.detail}${a.kind === "manual" ? " (**by hand**)" : ""}`)),
131
+ )
132
+ }
133
+ out.push(...sections)
134
+ const targets = names.length === 0 ? "" : ` ${names.join(" ")}`
135
+ out.push(
136
+ "",
137
+ "## Steps",
138
+ "",
139
+ "1. Commit or stash your work, so every change below can be reviewed as a diff.",
140
+ `2. \`eloxiv update${targets} --dry-run\`: what the merge will do, file by file, and which migrations it will apply.`,
141
+ `3. \`eloxiv update${targets}\`.`,
142
+ "4. Resolve each CONFLICT (remove the `<<<<<<<` `|||||||` `=======` `>>>>>>>` lines, keeping what you want), then `eloxiv update --continue`.",
143
+ `5. Finish what migrations leave by hand${manualAll.length === 0 ? " (none found now)" : ` (${manualAll.length} found now)`} and any note above, then \`eloxiv migrate\` for code written since.`,
144
+ "6. `eloxiv generate`, `eloxiv doctor`, `eloxiv typecheck`, and the app's tests.",
145
+ "",
146
+ )
147
+ return out.join("\n")
148
+ })
package/src/Emit.ts ADDED
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Writing files a command generates into the app (deploy recipes, agent-web files, brand tokens): every file is
3
+ * checked before any is written, a file that exists with other content is never replaced without `overwrite`, and a
4
+ * dry run writes nothing. Paths follow the CLI's one rule (inside the app, never through a symbolic link).
5
+ */
6
+ import { Console, Effect } from "effect"
7
+ import { CliError } from "./Errors.ts"
8
+ import { asText, readAppBytes, writablePath, writeAppFile } from "./Files.ts"
9
+
10
+ export interface GeneratedFile {
11
+ readonly path: string
12
+ readonly content: string
13
+ }
14
+
15
+ export type EmitStatus = "create" | "replace" | "unchanged" | "keep"
16
+
17
+ export interface Emitted {
18
+ readonly path: string
19
+ readonly status: EmitStatus
20
+ }
21
+
22
+ /**
23
+ * Plan and (unless `dryRun`) write `files`. A file that exists with other content is `replace` with `overwrite`;
24
+ * without it the whole write is refused (nothing written), naming the files.
25
+ */
26
+ export const emitFiles = (
27
+ dir: string,
28
+ files: ReadonlyArray<GeneratedFile>,
29
+ options: { readonly dryRun: boolean; readonly overwrite: boolean; readonly quiet?: boolean },
30
+ ) =>
31
+ Effect.gen(function* () {
32
+ const plan: Array<Emitted> = []
33
+ for (const file of files) {
34
+ yield* writablePath(dir, file.path)
35
+ const existing = yield* readAppBytes(dir, file.path)
36
+ const status: EmitStatus =
37
+ existing === undefined
38
+ ? "create"
39
+ : asText(existing) === file.content
40
+ ? "unchanged"
41
+ : options.overwrite
42
+ ? "replace"
43
+ : "keep"
44
+ plan.push({ path: file.path, status })
45
+ }
46
+ const kept = plan.filter((p) => p.status === "keep")
47
+ if (kept.length > 0 && !options.dryRun) {
48
+ return yield* new CliError({
49
+ message: `${kept.map((p) => p.path).join(", ")} already exist${kept.length === 1 ? "s" : ""} with other content (your edits?): nothing written; pass --overwrite to replace, or --dry-run to compare`,
50
+ })
51
+ }
52
+ for (const entry of plan) {
53
+ if (!options.quiet) {
54
+ const verb = options.dryRun
55
+ ? {
56
+ create: "would create",
57
+ replace: "would replace",
58
+ unchanged: "unchanged",
59
+ keep: "differs (kept without --overwrite)",
60
+ }[entry.status]
61
+ : { create: "created", replace: "replaced", unchanged: "unchanged", keep: "kept" }[entry.status]
62
+ yield* Console.log(`${verb.padEnd(12)} ${entry.path}`)
63
+ }
64
+ if (options.dryRun || entry.status === "unchanged" || entry.status === "keep") continue
65
+ yield* writeAppFile(dir, entry.path, files.find((f) => f.path === entry.path)!.content)
66
+ }
67
+ return plan
68
+ })
package/src/Errors.ts ADDED
@@ -0,0 +1,18 @@
1
+ /** The CLI's failures and exit statuses. */
2
+ import { Data, Runtime, Schema } from "effect"
3
+
4
+ /** A failure of the command itself (exit code 2: bad input, unreachable registry, refused operation). */
5
+ export class CliError extends Schema.TaggedError<CliError>()("CliError", { message: Schema.String }) {
6
+ override readonly [Runtime.errorExitCode] = 2
7
+ // bin.ts prints the message alone, without a stack trace.
8
+ override readonly [Runtime.errorReported] = false
9
+ }
10
+
11
+ /**
12
+ * The command ran but has something to report to a script: `diff` found differences, `update` left
13
+ * conflicts or was blocked (exit code 1). Its report has already been printed.
14
+ */
15
+ export class ExitStatus extends Data.TaggedError("ExitStatus")<{ readonly code: number; readonly reason: string }> {
16
+ override readonly [Runtime.errorExitCode]: number = this.code
17
+ override readonly [Runtime.errorReported] = false
18
+ }