@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/Mcp.ts ADDED
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Connecting coding agents to a kernel over MCP (docs/cli.md, "mcp"):
3
+ *
4
+ * eloxiv mcp install [--host ...] write the kernel's MCP server into the agent hosts' project configuration
5
+ * eloxiv mcp uninstall [--host ...] remove it again
6
+ * eloxiv mcp status which hosts list it, and whether the kernel serves MCP with OAuth there
7
+ *
8
+ * The configuration names the kernel's MCP endpoint (`<kernel>/mcp`) and nothing else: no credential is written.
9
+ * The host signs the person in itself, through the kernel's OAuth authorisation server (MachineIdentity: dynamic
10
+ * client registration, PKCE, a token bound to the MCP resource), so what the agent may call is what the person may,
11
+ * within the scope they allow.
12
+ */
13
+ import { Console, Effect, FileSystem, Path } from "effect"
14
+ import { CliError } from "./Errors.ts"
15
+ import { writablePath, writeAppFile } from "./Files.ts"
16
+ import { resolveKernelUrl } from "./Remote.ts"
17
+
18
+ /** The agent hosts whose project configuration the CLI writes, and how each lists an HTTP MCP server. */
19
+ export const MCP_HOSTS = {
20
+ claude: { file: ".mcp.json", key: "mcpServers", entry: (url: string) => ({ type: "http", url }) },
21
+ cursor: { file: ".cursor/mcp.json", key: "mcpServers", entry: (url: string) => ({ url }) },
22
+ vscode: { file: ".vscode/mcp.json", key: "servers", entry: (url: string) => ({ type: "http", url }) },
23
+ } as const
24
+ export type McpHost = keyof typeof MCP_HOSTS
25
+ export const MCP_HOST_NAMES = Object.keys(MCP_HOSTS) as ReadonlyArray<McpHost>
26
+
27
+ const SERVER_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/
28
+
29
+ const readConfigFile = (dir: string, host: McpHost) =>
30
+ Effect.gen(function* () {
31
+ const fs = yield* FileSystem.FileSystem
32
+ const path = yield* Path.Path
33
+ const file = path.join(dir, MCP_HOSTS[host].file)
34
+ if (!(yield* fs.exists(file))) return undefined
35
+ const text = yield* fs
36
+ .readFileString(file)
37
+ .pipe(Effect.mapError((e) => new CliError({ message: `Cannot read ${MCP_HOSTS[host].file}: ${e.message}` })))
38
+ try {
39
+ const parsed = JSON.parse(text) as unknown
40
+ if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) return parsed as Record<string, any>
41
+ } catch {
42
+ // Refused below.
43
+ }
44
+ return yield* new CliError({ message: `${MCP_HOSTS[host].file} is not a JSON object; fix or remove it first` })
45
+ })
46
+
47
+ const writeConfigFile = (dir: string, host: McpHost, config: Record<string, unknown>) =>
48
+ Effect.gen(function* () {
49
+ yield* writablePath(dir, MCP_HOSTS[host].file)
50
+ yield* writeAppFile(dir, MCP_HOSTS[host].file, `${JSON.stringify(config, null, 2)}\n`)
51
+ })
52
+
53
+ const serverName = (name: string) =>
54
+ SERVER_NAME.test(name)
55
+ ? Effect.succeed(name)
56
+ : Effect.fail(new CliError({ message: `--name ${name} is not a server name (letters, digits, . _ -)` }))
57
+
58
+ /** The kernel's MCP endpoint for `url`. */
59
+ export const mcpEndpoint = (url: string) => `${url.replace(/\/+$/u, "")}/mcp`
60
+
61
+ /**
62
+ * `eloxiv mcp install`: list the kernel's MCP server (`<kernel>/mcp`, as `name`) in each host's project file, keeping
63
+ * every other server the file lists. Returns the files written.
64
+ */
65
+ export const installMcp = Effect.fn("Mcp.installMcp")(function* (
66
+ dir: string,
67
+ options: { readonly url: string | undefined; readonly hosts: ReadonlyArray<McpHost>; readonly name: string },
68
+ ) {
69
+ const name = yield* serverName(options.name)
70
+ const endpoint = mcpEndpoint(yield* resolveKernelUrl(options.url))
71
+ const written: Array<string> = []
72
+ for (const host of options.hosts) {
73
+ const spec = MCP_HOSTS[host]
74
+ const config = (yield* readConfigFile(dir, host)) ?? {}
75
+ const servers = (config[spec.key] ?? {}) as Record<string, unknown>
76
+ if (typeof servers !== "object" || Array.isArray(servers)) {
77
+ return yield* new CliError({ message: `${spec.file}'s ${spec.key} is not an object; fix it first` })
78
+ }
79
+ yield* writeConfigFile(dir, host, { ...config, [spec.key]: { ...servers, [name]: spec.entry(endpoint) } })
80
+ written.push(spec.file)
81
+ yield* Console.log(`${spec.file}: ${name} -> ${endpoint}`)
82
+ }
83
+ yield* Console.log("The host signs you in to the kernel the first time it connects (OAuth); no token is stored here.")
84
+ return written
85
+ })
86
+
87
+ /** `eloxiv mcp uninstall`: remove `name` from each host's project file; other servers stay. Returns the files changed. */
88
+ export const uninstallMcp = Effect.fn("Mcp.uninstallMcp")(function* (
89
+ dir: string,
90
+ options: { readonly hosts: ReadonlyArray<McpHost>; readonly name: string },
91
+ ) {
92
+ const name = yield* serverName(options.name)
93
+ const changed: Array<string> = []
94
+ for (const host of options.hosts) {
95
+ const spec = MCP_HOSTS[host]
96
+ const config = yield* readConfigFile(dir, host)
97
+ const servers = config?.[spec.key] as Record<string, unknown> | undefined
98
+ if (config === undefined || servers === undefined || !(name in servers)) continue
99
+ const { [name]: _removed, ...rest } = servers
100
+ yield* writeConfigFile(dir, host, { ...config, [spec.key]: rest })
101
+ changed.push(spec.file)
102
+ yield* Console.log(`${spec.file}: removed ${name}`)
103
+ }
104
+ if (changed.length === 0) yield* Console.log(`no host lists ${name}`)
105
+ return changed
106
+ })
107
+
108
+ export interface McpStatus {
109
+ readonly name: string
110
+ readonly hosts: ReadonlyArray<{ readonly host: McpHost; readonly file: string; readonly url: string | null }>
111
+ /** The kernel's protected-resource metadata for MCP (RFC 9728), when a kernel was named. */
112
+ readonly kernel: {
113
+ readonly url: string
114
+ readonly reachable: boolean
115
+ readonly detail: string
116
+ } | null
117
+ }
118
+
119
+ /** `eloxiv mcp status`: which hosts list `name` (and the URL each has), and whether the kernel serves MCP with OAuth. */
120
+ export const mcpStatus = Effect.fn("Mcp.mcpStatus")(function* (
121
+ dir: string,
122
+ options: { readonly url: string | undefined; readonly name: string },
123
+ ) {
124
+ const name = yield* serverName(options.name)
125
+ const hosts: Array<McpStatus["hosts"][number]> = []
126
+ for (const host of MCP_HOST_NAMES) {
127
+ const spec = MCP_HOSTS[host]
128
+ const config = yield* readConfigFile(dir, host)
129
+ const entry = (config?.[spec.key] as Record<string, { readonly url?: unknown }> | undefined)?.[name]
130
+ hosts.push({
131
+ host,
132
+ file: spec.file,
133
+ url: entry === undefined ? null : typeof entry.url === "string" ? entry.url : null,
134
+ })
135
+ }
136
+ const url = yield* resolveKernelUrl(options.url).pipe(Effect.option)
137
+ let kernel: McpStatus["kernel"] = null
138
+ if (url._tag === "Some") {
139
+ const metadata = `${url.value}/.well-known/oauth-protected-resource/mcp`
140
+ const response = yield* Effect.tryPromise(() => fetch(metadata, { signal: AbortSignal.timeout(20_000) })).pipe(
141
+ Effect.option,
142
+ )
143
+ kernel =
144
+ response._tag === "None"
145
+ ? { url: url.value, reachable: false, detail: `cannot reach ${metadata}` }
146
+ : response.value.ok
147
+ ? { url: url.value, reachable: true, detail: `serves MCP at ${mcpEndpoint(url.value)}, signed in with OAuth` }
148
+ : { url: url.value, reachable: false, detail: `${metadata} answered ${response.value.status}` }
149
+ }
150
+ return { name, hosts, kernel } satisfies McpStatus
151
+ })
152
+
153
+ export const formatMcpStatus = (status: McpStatus) =>
154
+ [
155
+ ...status.hosts.map((h) => `${h.host.padEnd(6)} ${h.file.padEnd(16)} ${h.url ?? `does not list ${status.name}`}`),
156
+ status.kernel === null
157
+ ? "no kernel named (--url, ELOXIV_URL or eloxiv login)"
158
+ : `kernel ${status.kernel.url}: ${status.kernel.detail}`,
159
+ ].join("\n")
package/src/Merge.ts ADDED
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Line-based text merging and diffs for `eloxiv diff` and `eloxiv update`.
3
+ *
4
+ * The three-way merge is diff3 (node-diff3): `ours` is the app's file, `base` the version the app
5
+ * installed, `theirs` the new version. Changes on one side only are taken; overlapping changes are
6
+ * conflicts, written in diff3 style with the base section:
7
+ *
8
+ * <<<<<<< app
9
+ * ...the app's lines...
10
+ * ||||||| hello@0.1.0
11
+ * ...the base's lines...
12
+ * =======
13
+ * ...the new version's lines...
14
+ * >>>>>>> hello@0.2.0
15
+ */
16
+ import { createTwoFilesPatch } from "diff"
17
+ import { mergeDiff3 } from "node-diff3"
18
+
19
+ export interface MergeLabels {
20
+ readonly ours: string
21
+ readonly base: string
22
+ readonly theirs: string
23
+ }
24
+
25
+ export interface MergeResult {
26
+ readonly clean: boolean
27
+ readonly text: string
28
+ }
29
+
30
+ const lines = (text: string) => text.split("\n")
31
+
32
+ export const mergeText = (ours: string, base: string, theirs: string, labels: MergeLabels): MergeResult => {
33
+ if (ours === theirs) return { clean: true, text: ours }
34
+ if (ours === base) return { clean: true, text: theirs }
35
+ if (theirs === base) return { clean: true, text: ours }
36
+ const result = mergeDiff3(lines(ours), lines(base), lines(theirs), {
37
+ excludeFalseConflicts: true,
38
+ label: { a: labels.ours, o: labels.base, b: labels.theirs },
39
+ })
40
+ return { clean: !result.conflict, text: result.result.join("\n") }
41
+ }
42
+
43
+ const MARKER = /^(<<<<<<<|>>>>>>>)( |$)/m
44
+
45
+ /** Whether a file still holds conflict markers (the `=======` separator alone is ordinary Markdown). */
46
+ export const hasConflictMarkers = (text: string) => MARKER.test(text)
47
+
48
+ /** A unified diff (three lines of context), or `""` when the texts are equal. */
49
+ export const unifiedDiff = (
50
+ path: string,
51
+ before: string | undefined,
52
+ after: string | undefined,
53
+ labels: {
54
+ readonly before: string
55
+ readonly after: string
56
+ },
57
+ ) => {
58
+ if (before === after) return ""
59
+ const patch = createTwoFilesPatch(
60
+ before === undefined ? "/dev/null" : `a/${path}`,
61
+ after === undefined ? "/dev/null" : `b/${path}`,
62
+ before ?? "",
63
+ after ?? "",
64
+ labels.before,
65
+ labels.after,
66
+ { context: 3 },
67
+ )
68
+ // Drop the "Index:" and "=====" banner jsdiff prints before the file headers.
69
+ return patch.slice(patch.indexOf("--- "))
70
+ }
package/src/Migrate.ts ADDED
@@ -0,0 +1,331 @@
1
+ /**
2
+ * Compatibility migrations (docs/cli.md, "Compatibility migrations"): a registry item's version can declare what it
3
+ * moved, so apps that import it keep building after an update.
4
+ *
5
+ * "migrations": [{ "since": "0.5.0", "note": "...", "moves": [
6
+ * { "from": "./modules/hello/contract.ts", "symbol": "greet", "to": "./modules/hello/api.ts", "as": "greetPerson" },
7
+ * { "from": "@eloxiv/kernel", "symbol": "runServer", "to": "@eloxiv/kernel/runtime/bun" },
8
+ * { "from": "./shell-foldkit/src/old.css", "to": "./shell-foldkit/src/theme.css" } ] }]
9
+ *
10
+ * A move names a module (`./` and a path from the app's root, or a package specifier) and optionally one of its
11
+ * exports; `to` is where it now lives and `as` its new name. `eloxiv update` applies the migrations of every version
12
+ * it moves an item past (`since` after the installed version, up to the new one) to the app's own files: an import of
13
+ * a moved module is pointed at the new one; a moved export is imported from its new module under its old local name
14
+ * (`import { greetPerson as greet }`), so no other line of the file changes; a stylesheet's `@import` follows its
15
+ * file. What a codemod cannot rewrite safely (a namespace import of a module an export left) is reported for a
16
+ * person or agent to finish. `eloxiv migrate` applies them again (code written since), `--dossier` prints a portable
17
+ * migration brief, and `eloxiv doctor` fails while an app file still imports something a migration moved.
18
+ */
19
+ import { parse, type ParserOptions } from "@babel/parser"
20
+ import { lstatSync, readdirSync, readFileSync, realpathSync, writeFileSync } from "node:fs"
21
+ import { dirname, extname, join, relative, resolve, sep } from "node:path"
22
+ import { Schema } from "effect"
23
+
24
+ export const Move = Schema.Struct({
25
+ /** The module that held it: `./<path from the app's root>` or a package specifier. */
26
+ from: Schema.String,
27
+ /** One export of `from` that moved; without it, the whole module moved. */
28
+ symbol: Schema.optional(Schema.String),
29
+ /** Where it now lives (the same as `from` for a rename). */
30
+ to: Schema.String,
31
+ /** The export's new name (default: `symbol`). */
32
+ as: Schema.optional(Schema.String),
33
+ })
34
+ export type Move = typeof Move.Type
35
+
36
+ export const Migration = Schema.Struct({
37
+ /** The version that made the change: applied when an app moves from an earlier version to this one or later. */
38
+ since: Schema.String,
39
+ moves: Schema.optional(Schema.Array(Move)),
40
+ /** What a person or agent must still do by hand (shown by update, migrate and the dossier). */
41
+ note: Schema.optional(Schema.String),
42
+ })
43
+ export type Migration = typeof Migration.Type
44
+
45
+ /** Numeric, dot-separated comparison; a prerelease (`-x`) sorts before its release. */
46
+ export const compareVersions = (a: string, b: string) => {
47
+ const [mainA = "", preA] = a.split("-", 2)
48
+ const [mainB = "", preB] = b.split("-", 2)
49
+ const pa = mainA.split(".").map(Number)
50
+ const pb = mainB.split(".").map(Number)
51
+ for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
52
+ const d = (pa[i] ?? 0) - (pb[i] ?? 0)
53
+ if (d !== 0) return d
54
+ }
55
+ if (preA === undefined) return preB === undefined ? 0 : 1
56
+ if (preB === undefined) return -1
57
+ return preA.localeCompare(preB)
58
+ }
59
+
60
+ /** The migrations of versions after `from` up to and including `to` (`from` undefined: every one up to `to`). */
61
+ export const migrationsBetween = (migrations: ReadonlyArray<Migration>, from: string | undefined, to: string) =>
62
+ migrations
63
+ .filter((m) => (from === undefined || compareVersions(m.since, from) > 0) && compareVersions(m.since, to) <= 0)
64
+ .sort((a, b) => compareVersions(a.since, b.since))
65
+
66
+ export interface MigrationChange {
67
+ readonly item: string
68
+ readonly since: string
69
+ /** Relative to the app, with `/`. */
70
+ readonly file: string
71
+ readonly line: number
72
+ /** `module`: an import pointed at a moved module; `symbol`: a moved export; `manual`: left for a person. */
73
+ readonly kind: "module" | "symbol" | "manual"
74
+ readonly detail: string
75
+ }
76
+
77
+ const SOURCE = new Set([".ts", ".tsx", ".mts", ".cts", ".js", ".mjs", ".jsx", ".css"])
78
+ const SKIP = new Set(["node_modules", "dist", ".eloxiv", ".git", "target", ".vite"])
79
+
80
+ /** The app's own source files a migration may rewrite (relative paths), skipping `exclude` and symbolic links. */
81
+ export const appSources = (dir: string, exclude: ReadonlySet<string> = new Set()) => {
82
+ const out: Array<string> = []
83
+ const walk = (sub: string) => {
84
+ for (const name of readdirSync(join(dir, sub))) {
85
+ if (SKIP.has(name) || name.startsWith(".")) continue
86
+ const rel = sub === "" ? name : `${sub}/${name}`
87
+ // Never through a symbolic link: a linked directory may be another checkout's, a linked file anyone's.
88
+ const info = lstatSync(join(dir, rel), { throwIfNoEntry: false })
89
+ if (info === undefined || info.isSymbolicLink()) continue
90
+ if (info.isDirectory()) walk(rel)
91
+ else if (SOURCE.has(extname(name)) && !exclude.has(rel) && info.size < 2_000_000) out.push(rel)
92
+ }
93
+ }
94
+ walk("")
95
+ return out
96
+ }
97
+
98
+ const stripExtension = (path: string) => path.replace(/\.(ts|tsx|mts|cts|js|mjs|jsx)$/, "")
99
+
100
+ /** Whether `specifier`, written in the app file `file`, names the module `module` (a move's `from`). */
101
+ const names = (file: string, specifier: string, module: string) => {
102
+ if (!module.startsWith("./")) return specifier === module
103
+ if (!specifier.startsWith(".")) return false
104
+ const target = relative(".", join(dirname(file), specifier))
105
+ .split(sep)
106
+ .join("/")
107
+ const wanted = module.slice(2)
108
+ return target === wanted || (extname(wanted) !== ".css" && stripExtension(target) === stripExtension(wanted))
109
+ }
110
+
111
+ /** How the app file `file` writes an import of `module` (a move's `to`). */
112
+ const specifierFor = (file: string, module: string) => {
113
+ if (!module.startsWith("./")) return module
114
+ const path = relative(dirname(file), module.slice(2)).split(sep).join("/")
115
+ return path.startsWith(".") ? path : `./${path}`
116
+ }
117
+
118
+ const CSS_IMPORT = /@import\s+(?:url\(\s*)?(["'])([^"']+)\1/g
119
+
120
+ const lineAt = (text: string, index: number) => text.slice(0, index).split("\n").length
121
+
122
+ interface Rewrite {
123
+ readonly start: number
124
+ readonly end: number
125
+ readonly text: string
126
+ }
127
+
128
+ type Change = Omit<MigrationChange, "item" | "since">
129
+
130
+ /** The name an import or export specifier refers to (an identifier, or a string literal `"a-b"`). */
131
+ const nameOf = (node: { readonly type: string; readonly name?: string; readonly value?: unknown }) =>
132
+ node.type === "StringLiteral" ? String(node.value) : (node.name ?? "")
133
+
134
+ const PARSE_PLUGINS: Record<string, ParserOptions["plugins"]> = {
135
+ ts: ["typescript"],
136
+ tsx: ["typescript", "jsx"],
137
+ js: ["jsx"],
138
+ }
139
+
140
+ /**
141
+ * Apply `moves` to one file's text: returns the new text and what changed. The file is parsed (Babel's parser, with
142
+ * TypeScript and JSX), and only the spans of real import and export declarations are rewritten; every rewrite keeps
143
+ * the file's local names, so no other line changes. A file that does not parse is left as it is and reported.
144
+ */
145
+ export const migrateText = (file: string, text: string, moves: ReadonlyArray<Move>) => {
146
+ const rewrites: Array<Rewrite> = []
147
+ const changes: Array<Change> = []
148
+ if (extname(file) === ".css") {
149
+ for (const match of text.matchAll(CSS_IMPORT)) {
150
+ const move = moves.find((m) => m.symbol === undefined && names(file, match[2]!, m.from))
151
+ if (move === undefined) continue
152
+ const start = match.index + match[0].lastIndexOf(match[2]!)
153
+ rewrites.push({ start, end: start + match[2]!.length, text: specifierFor(file, move.to) })
154
+ changes.push({
155
+ file,
156
+ line: lineAt(text, match.index),
157
+ kind: "module",
158
+ detail: `@import ${match[2]} → ${specifierFor(file, move.to)}`,
159
+ })
160
+ }
161
+ return { text: apply(text, rewrites), changes }
162
+ }
163
+ const ext = extname(file).slice(1)
164
+ let program: ReturnType<typeof parse>["program"]
165
+ try {
166
+ program = parse(text, {
167
+ sourceType: "module",
168
+ // Declarations Babel finds wrong but can still read (a name imported twice) are the compiler's to report.
169
+ errorRecovery: true,
170
+ plugins:
171
+ PARSE_PLUGINS[ext === "tsx" ? "tsx" : ext.startsWith("ts") || ext === "mts" || ext === "cts" ? "ts" : "js"] ??
172
+ [],
173
+ }).program
174
+ } catch (e) {
175
+ return {
176
+ text,
177
+ changes: [
178
+ {
179
+ file,
180
+ line: 1,
181
+ kind: "manual" as const,
182
+ detail: `could not be parsed (${e instanceof Error ? e.message : String(e)}): migrate its imports by hand`,
183
+ },
184
+ ],
185
+ }
186
+ }
187
+ for (const node of program.body) {
188
+ if (
189
+ node.type !== "ImportDeclaration" &&
190
+ node.type !== "ExportNamedDeclaration" &&
191
+ node.type !== "ExportAllDeclaration"
192
+ )
193
+ continue
194
+ const source = node.source
195
+ if (source === null || source === undefined) continue
196
+ const specifier = source.value
197
+ const relevant = moves.filter((m) => names(file, specifier, m.from))
198
+ if (relevant.length === 0) continue
199
+ const line = node.loc?.start.line ?? lineAt(text, node.start ?? 0)
200
+ const quote = text[source.start!] === "'" ? "'" : '"'
201
+ const q = (value: string) => `${quote}${value}${quote}`
202
+ const semi = text[node.end! - 1] === ";" ? ";" : ""
203
+ const whole = relevant.find((m) => m.symbol === undefined)
204
+ const symbolMoves = relevant.filter((m) => m.symbol !== undefined)
205
+ const target = whole === undefined ? specifier : specifierFor(file, whole.to)
206
+ const typeOnly = (node.type === "ImportDeclaration" ? node.importKind : node.exportKind) === "type" ? " type" : ""
207
+ const keyword = node.type === "ImportDeclaration" ? "import" : "export"
208
+ if (node.type === "ExportAllDeclaration") {
209
+ if (whole === undefined) continue
210
+ rewrites.push({ start: source.start!, end: source.end!, text: q(target) })
211
+ changes.push({ file, line, kind: "module", detail: `${specifier} → ${target}` })
212
+ continue
213
+ }
214
+ const specifiers = node.specifiers as ReadonlyArray<{
215
+ readonly type: string
216
+ readonly start?: number | null
217
+ readonly end?: number | null
218
+ readonly imported?: { readonly type: string; readonly name?: string; readonly value?: unknown }
219
+ readonly local?: { readonly type: string; readonly name?: string; readonly value?: unknown }
220
+ readonly exported?: { readonly type: string; readonly name?: string; readonly value?: unknown }
221
+ readonly importKind?: string | null
222
+ readonly exportKind?: string | null
223
+ }>
224
+ // For an import: the name in the module and the local binding; for a re-export: the name and the exported one.
225
+ const named = specifiers
226
+ .filter((sp) => sp.type === "ImportSpecifier" || sp.type === "ExportSpecifier")
227
+ .map((sp) => ({
228
+ sp,
229
+ name: nameOf(sp.type === "ImportSpecifier" ? sp.imported! : sp.local!),
230
+ binding: nameOf(sp.type === "ImportSpecifier" ? sp.local! : sp.exported!),
231
+ type: sp.importKind === "type" || sp.exportKind === "type",
232
+ }))
233
+ const moved = named.flatMap((n) => {
234
+ const move = symbolMoves.find((m) => m.symbol === n.name)
235
+ return move === undefined ? [] : [{ n, move }]
236
+ })
237
+ if (moved.length === 0 && whole === undefined) {
238
+ // A namespace import: its uses of a moved export (`K.runServer`) are left for a person.
239
+ const namespace = specifiers.find((sp) => sp.type === "ImportNamespaceSpecifier")?.local?.name
240
+ const used = symbolMoves.filter(
241
+ (m) => namespace !== undefined && new RegExp(`(^|[^\\w$.])${namespace}\\s*\\.\\s*${m.symbol}\\b`).test(text),
242
+ )
243
+ if (used.length > 0) {
244
+ changes.push({
245
+ file,
246
+ line,
247
+ kind: "manual",
248
+ detail: `${used.map((m) => `${namespace}.${m.symbol}`).join(", ")}: ${used.map((m) => `${m.symbol} moved to ${m.to}${m.as === undefined ? "" : ` as ${m.as}`}`).join("; ")}; change these uses by hand`,
249
+ })
250
+ }
251
+ continue
252
+ }
253
+ const raw = (sp: { readonly start?: number | null; readonly end?: number | null }) => text.slice(sp.start!, sp.end!)
254
+ const keep = named.filter((n) => !moved.some((m) => m.n === n))
255
+ const head = specifiers
256
+ .filter(
257
+ (sp) =>
258
+ sp.type === "ImportDefaultSpecifier" ||
259
+ sp.type === "ImportNamespaceSpecifier" ||
260
+ sp.type === "ExportNamespaceSpecifier",
261
+ )
262
+ .map(raw)
263
+ const parts: Array<string> = []
264
+ const clause = [...head, ...(keep.length > 0 ? [`{ ${keep.map((k) => raw(k.sp)).join(", ")} }`] : [])].join(", ")
265
+ if (clause !== "") parts.push(`${keyword}${typeOnly} ${clause} from ${q(target)}`)
266
+ else if (specifiers.length === 0 && node.type === "ImportDeclaration") parts.push(`import ${q(target)}`)
267
+ for (const { n, move } of moved) {
268
+ const now = move.as ?? move.symbol!
269
+ const toSpecifier = specifierFor(file, move.to)
270
+ const binding = now === n.binding ? now : `${now} as ${n.binding}`
271
+ parts.push(`${keyword}${typeOnly} { ${n.type ? "type " : ""}${binding} } from ${q(toSpecifier)}`)
272
+ changes.push({ file, line, kind: "symbol", detail: `${n.name} from ${specifier} → ${now} from ${toSpecifier}` })
273
+ }
274
+ if (whole !== undefined && (keep.length > 0 || head.length > 0 || specifiers.length === 0)) {
275
+ changes.push({ file, line, kind: "module", detail: `${specifier} → ${target}` })
276
+ }
277
+ rewrites.push({ start: node.start!, end: node.end!, text: parts.map((p) => `${p}${semi}`).join("\n") })
278
+ }
279
+ return { text: apply(text, rewrites), changes }
280
+ }
281
+
282
+ const apply = (text: string, rewrites: ReadonlyArray<Rewrite>) => {
283
+ let out = text
284
+ for (const r of [...rewrites].sort((a, b) => b.start - a.start))
285
+ out = out.slice(0, r.start) + r.text + out.slice(r.end)
286
+ return out
287
+ }
288
+
289
+ /**
290
+ * Whether the app file `path` may be written: a regular file, not a symbolic link, whose real path is inside the
291
+ * app's (the CLI's one rule for writes, as `Files.ts`'s `safeAppPath` applies it).
292
+ */
293
+ const writableInside = (root: string, path: string) => {
294
+ const info = lstatSync(path, { throwIfNoEntry: false })
295
+ if (info === undefined || info.isSymbolicLink() || !info.isFile()) return false
296
+ const real = realpathSync(path)
297
+ return real.startsWith(realpathSync(root) + sep)
298
+ }
299
+
300
+ /**
301
+ * Apply each item's migrations to the app's own files (`exclude`: files the caller writes itself). With `dryRun`
302
+ * nothing is written; the changes are what would be.
303
+ */
304
+ export const applyMigrations = (
305
+ dir: string,
306
+ pending: ReadonlyArray<{ readonly item: string; readonly migration: Migration }>,
307
+ options: { readonly dryRun: boolean; readonly exclude?: ReadonlySet<string> },
308
+ ): ReadonlyArray<MigrationChange> => {
309
+ const withMoves = pending.filter((p) => (p.migration.moves ?? []).length > 0)
310
+ if (withMoves.length === 0) return []
311
+ const changes: Array<MigrationChange> = []
312
+ for (const file of appSources(resolve(dir), options.exclude)) {
313
+ const path = join(dir, file)
314
+ let text = readFileSync(path, "utf8")
315
+ const original = text
316
+ for (const { item, migration } of withMoves) {
317
+ const result = migrateText(file, text, migration.moves ?? [])
318
+ text = result.text
319
+ for (const change of result.changes) changes.push(Object.assign({}, change, { item, since: migration.since }))
320
+ }
321
+ if (!options.dryRun && text !== original && writableInside(dir, path)) writeFileSync(path, text)
322
+ }
323
+ return changes
324
+ }
325
+
326
+ export const formatMigrationChanges = (changes: ReadonlyArray<MigrationChange>, dryRun: boolean) =>
327
+ changes.map((c) =>
328
+ c.kind === "manual"
329
+ ? ` MANUAL ${c.file}:${c.line} ${c.detail} (${c.item} ${c.since})`
330
+ : ` ${dryRun ? "would migrate" : "migrated"} ${c.file}:${c.line} ${c.detail} (${c.item} ${c.since})`,
331
+ )