@sdxc/kit 0.0.0-stage → 2026.10.17

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 (298) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +93 -2
  3. package/changelog.jsonl +1097 -0
  4. package/config.schema.json +89 -0
  5. package/dist/author.d.ts +36 -0
  6. package/dist/author.js +107 -0
  7. package/dist/bin.d.ts +9 -0
  8. package/dist/bin.js +10 -0
  9. package/dist/cli.d.ts +33 -0
  10. package/dist/cli.js +58 -0
  11. package/dist/commands/create.d.ts +20 -0
  12. package/dist/commands/create.js +169 -0
  13. package/dist/commands/init.d.ts +16 -0
  14. package/dist/commands/init.js +27 -0
  15. package/dist/commands/make.d.ts +335 -0
  16. package/dist/commands/make.js +152 -0
  17. package/dist/commands/run.d.ts +23 -0
  18. package/dist/commands/run.js +53 -0
  19. package/dist/commands/ui/add.d.ts +23 -0
  20. package/dist/commands/ui/add.js +50 -0
  21. package/dist/commands/ui/diff.d.ts +20 -0
  22. package/dist/commands/ui/diff.js +28 -0
  23. package/dist/commands/ui/list.d.ts +24 -0
  24. package/dist/commands/ui/list.js +45 -0
  25. package/dist/commands/ui/remove.d.ts +22 -0
  26. package/dist/commands/ui/remove.js +48 -0
  27. package/dist/commands/ui/update.d.ts +23 -0
  28. package/dist/commands/ui/update.js +37 -0
  29. package/dist/commands/upgrade.d.ts +30 -0
  30. package/dist/commands/upgrade.js +184 -0
  31. package/dist/config.d.ts +81 -0
  32. package/dist/config.js +157 -0
  33. package/dist/contract.d.ts +161 -0
  34. package/dist/contract.js +308 -0
  35. package/dist/create/github.d.ts +63 -0
  36. package/dist/create/github.js +172 -0
  37. package/dist/create/target.d.ts +31 -0
  38. package/dist/create/target.js +56 -0
  39. package/dist/create/templates.d.ts +69 -0
  40. package/dist/create/templates.js +251 -0
  41. package/dist/dependencies.d.ts +34 -0
  42. package/dist/dependencies.js +76 -0
  43. package/dist/diff.d.ts +14 -0
  44. package/dist/diff.js +103 -0
  45. package/dist/format.d.ts +21 -0
  46. package/dist/format.js +40 -0
  47. package/dist/init.d.ts +40 -0
  48. package/dist/init.js +100 -0
  49. package/dist/lock.d.ts +74 -0
  50. package/dist/lock.js +214 -0
  51. package/dist/make/declare.d.ts +54 -0
  52. package/dist/make/declare.js +598 -0
  53. package/dist/make/generate.d.ts +62 -0
  54. package/dist/make/generate.js +160 -0
  55. package/dist/make/imports.d.ts +43 -0
  56. package/dist/make/imports.js +105 -0
  57. package/dist/make/index.d.ts +43 -0
  58. package/dist/make/index.js +140 -0
  59. package/dist/make/kinds.d.ts +40 -0
  60. package/dist/make/kinds.js +96 -0
  61. package/dist/make/migrations.d.ts +41 -0
  62. package/dist/make/migrations.js +116 -0
  63. package/dist/make/names.d.ts +31 -0
  64. package/dist/make/names.js +47 -0
  65. package/dist/make/stubs.d.ts +44 -0
  66. package/dist/make/stubs.js +89 -0
  67. package/dist/middleware.d.ts +44 -0
  68. package/dist/middleware.js +49 -0
  69. package/dist/package-manager.d.ts +41 -0
  70. package/dist/package-manager.js +80 -0
  71. package/dist/project.d.ts +19 -0
  72. package/dist/project.js +42 -0
  73. package/dist/releases.d.ts +40 -0
  74. package/dist/releases.js +110 -0
  75. package/dist/testing.d.ts +60 -0
  76. package/dist/testing.js +148 -0
  77. package/dist/ui/commands.d.ts +114 -0
  78. package/dist/ui/commands.js +432 -0
  79. package/dist/ui/imports.d.ts +46 -0
  80. package/dist/ui/imports.js +160 -0
  81. package/dist/ui/layout.d.ts +48 -0
  82. package/dist/ui/layout.js +138 -0
  83. package/dist/ui/registry.d.ts +58 -0
  84. package/dist/ui/registry.js +82 -0
  85. package/dist/upgrade/changelog.d.ts +50 -0
  86. package/dist/upgrade/changelog.js +69 -0
  87. package/dist/upgrade/project.d.ts +62 -0
  88. package/dist/upgrade/project.js +132 -0
  89. package/dist/upgrade/prompt.d.ts +51 -0
  90. package/dist/upgrade/prompt.js +227 -0
  91. package/dist/upgrade/registry.d.ts +33 -0
  92. package/dist/upgrade/registry.js +50 -0
  93. package/lock.schema.json +60 -0
  94. package/package.json +44 -5
  95. package/registry/ui/accordion.json +15 -0
  96. package/registry/ui/alert-dialog.json +20 -0
  97. package/registry/ui/alert.json +15 -0
  98. package/registry/ui/aspect-ratio.json +13 -0
  99. package/registry/ui/attachment.json +15 -0
  100. package/registry/ui/avatar.json +15 -0
  101. package/registry/ui/badge.json +13 -0
  102. package/registry/ui/breadcrumbs.json +15 -0
  103. package/registry/ui/bubble.json +13 -0
  104. package/registry/ui/button.json +16 -0
  105. package/registry/ui/calendar.json +16 -0
  106. package/registry/ui/card.json +18 -0
  107. package/registry/ui/carousel.json +15 -0
  108. package/registry/ui/chart.json +13 -0
  109. package/registry/ui/checkbox-group.json +13 -0
  110. package/registry/ui/checkbox.json +16 -0
  111. package/registry/ui/color-area.json +13 -0
  112. package/registry/ui/color-field.json +20 -0
  113. package/registry/ui/color-picker.json +17 -0
  114. package/registry/ui/color-slider.json +13 -0
  115. package/registry/ui/color-swatch-picker.json +15 -0
  116. package/registry/ui/color-swatch.json +13 -0
  117. package/registry/ui/color-wheel.json +13 -0
  118. package/registry/ui/combobox.json +15 -0
  119. package/registry/ui/command.json +13 -0
  120. package/registry/ui/confirm.json +19 -0
  121. package/registry/ui/context-menu.json +16 -0
  122. package/registry/ui/date-field.json +19 -0
  123. package/registry/ui/date-picker.json +15 -0
  124. package/registry/ui/date-range-picker.json +16 -0
  125. package/registry/ui/description.json +13 -0
  126. package/registry/ui/dialog.json +19 -0
  127. package/registry/ui/disclosure.json +18 -0
  128. package/registry/ui/drawer.json +18 -0
  129. package/registry/ui/drop-indicator.json +13 -0
  130. package/registry/ui/drop-zone.json +13 -0
  131. package/registry/ui/empty.json +15 -0
  132. package/registry/ui/field-error.json +13 -0
  133. package/registry/ui/file-trigger.json +13 -0
  134. package/registry/ui/form.json +21 -0
  135. package/registry/ui/grid-list.json +18 -0
  136. package/registry/ui/group.json +13 -0
  137. package/registry/ui/header.json +13 -0
  138. package/registry/ui/heading-scope.json +20 -0
  139. package/registry/ui/heading.json +15 -0
  140. package/registry/ui/highlight.json +16 -0
  141. package/registry/ui/hover-card.json +13 -0
  142. package/registry/ui/image-placeholder.json +16 -0
  143. package/registry/ui/input.json +13 -0
  144. package/registry/ui/item.json +13 -0
  145. package/registry/ui/keyboard.json +13 -0
  146. package/registry/ui/label.json +13 -0
  147. package/registry/ui/link-button.json +16 -0
  148. package/registry/ui/link.json +13 -0
  149. package/registry/ui/listbox.json +15 -0
  150. package/registry/ui/logo.json +15 -0
  151. package/registry/ui/marker.json +13 -0
  152. package/registry/ui/menu.json +19 -0
  153. package/registry/ui/menubar.json +13 -0
  154. package/registry/ui/message-scroller.json +16 -0
  155. package/registry/ui/message.json +13 -0
  156. package/registry/ui/meter.json +13 -0
  157. package/registry/ui/modal.json +15 -0
  158. package/registry/ui/nav-link.json +13 -0
  159. package/registry/ui/navigation-menu.json +15 -0
  160. package/registry/ui/number-field.json +15 -0
  161. package/registry/ui/otp-field.json +15 -0
  162. package/registry/ui/overlay-arrow.json +13 -0
  163. package/registry/ui/pagination.json +16 -0
  164. package/registry/ui/popover.json +13 -0
  165. package/registry/ui/progress-bar.json +13 -0
  166. package/registry/ui/radio-group.json +13 -0
  167. package/registry/ui/range-calendar.json +16 -0
  168. package/registry/ui/resizable.json +13 -0
  169. package/registry/ui/scroll-area.json +13 -0
  170. package/registry/ui/search-field.json +16 -0
  171. package/registry/ui/section.json +13 -0
  172. package/registry/ui/select.json +13 -0
  173. package/registry/ui/selection-indicator.json +13 -0
  174. package/registry/ui/sentinel-row.json +16 -0
  175. package/registry/ui/separator.json +13 -0
  176. package/registry/ui/shared-element.json +13 -0
  177. package/registry/ui/sheet.json +15 -0
  178. package/registry/ui/shortcut-list.json +18 -0
  179. package/registry/ui/sidebar.json +20 -0
  180. package/registry/ui/skeleton.json +13 -0
  181. package/registry/ui/slider.json +16 -0
  182. package/registry/ui/spinner.json +13 -0
  183. package/registry/ui/switch.json +16 -0
  184. package/registry/ui/table.json +16 -0
  185. package/registry/ui/tabs.json +17 -0
  186. package/registry/ui/tag-group.json +18 -0
  187. package/registry/ui/text-field.json +19 -0
  188. package/registry/ui/text.json +13 -0
  189. package/registry/ui/textarea.json +13 -0
  190. package/registry/ui/time-field.json +19 -0
  191. package/registry/ui/toast.json +16 -0
  192. package/registry/ui/toggle-button.json +17 -0
  193. package/registry/ui/toolbar.json +13 -0
  194. package/registry/ui/tooltip.json +16 -0
  195. package/registry/ui/tree.json +18 -0
  196. package/registry/ui/typeset.json +16 -0
  197. package/registry/ui/youtube-embed.json +16 -0
  198. package/stubs/command.stub +16 -0
  199. package/stubs/command.test.stub +21 -0
  200. package/stubs/controller.api.stub +21 -0
  201. package/stubs/controller.api.test.stub +18 -0
  202. package/stubs/controller.form.stub +63 -0
  203. package/stubs/controller.form.test.stub +61 -0
  204. package/stubs/controller.stub +24 -0
  205. package/stubs/controller.test.stub +18 -0
  206. package/stubs/email.stub +26 -0
  207. package/stubs/email.test.stub +21 -0
  208. package/stubs/factory.stub +13 -0
  209. package/stubs/initializer.stub +9 -0
  210. package/stubs/initializer.test.stub +16 -0
  211. package/stubs/job.cron.stub +16 -0
  212. package/stubs/job.stub +15 -0
  213. package/stubs/job.test.stub +18 -0
  214. package/stubs/mcp.resource.stub +15 -0
  215. package/stubs/mcp.stub +13 -0
  216. package/stubs/mcp.test.stub +18 -0
  217. package/stubs/middleware.stub +16 -0
  218. package/stubs/middleware.test.stub +16 -0
  219. package/stubs/migration.stub +1 -0
  220. package/stubs/model.stub +33 -0
  221. package/stubs/model.test.stub +18 -0
  222. package/stubs/policy.stub +16 -0
  223. package/stubs/policy.test.stub +20 -0
  224. package/stubs/service.stub +17 -0
  225. package/stubs/service.test.stub +17 -0
  226. package/stubs/validator.stub +17 -0
  227. package/stubs/validator.test.stub +25 -0
  228. package/templates/app/.env.example +16 -0
  229. package/templates/app/README.md +84 -0
  230. package/templates/app/app/commands/about.test.ts +29 -0
  231. package/templates/app/app/commands/about.ts +34 -0
  232. package/templates/app/app/commands/db/console.ts +6 -0
  233. package/templates/app/app/commands/db/migrate.test.ts +30 -0
  234. package/templates/app/app/commands/db/migrate.ts +55 -0
  235. package/templates/app/app/commands/index.ts +31 -0
  236. package/templates/app/app/commands/typegen.test.ts +17 -0
  237. package/templates/app/app/commands/typegen.ts +16 -0
  238. package/templates/app/app/http/controllers/api/health.tsx +15 -0
  239. package/templates/app/app/http/controllers/api/not-found.tsx +16 -0
  240. package/templates/app/app/http/controllers/api/openapi.tsx +17 -0
  241. package/templates/app/app/http/controllers/home.tsx +30 -0
  242. package/templates/app/app/http/controllers/mcp.tsx +16 -0
  243. package/templates/app/app/http/controllers/not-found.tsx +30 -0
  244. package/templates/app/app/http/controllers/robots.test.ts +18 -0
  245. package/templates/app/app/http/controllers/robots.ts +24 -0
  246. package/templates/app/app/http/controllers/sitemap.test.ts +28 -0
  247. package/templates/app/app/http/controllers/sitemap.ts +25 -0
  248. package/templates/app/app/http/middleware/api.ts +10 -0
  249. package/templates/app/app/http/middleware/page.test.ts +40 -0
  250. package/templates/app/app/http/middleware/page.ts +49 -0
  251. package/templates/app/app/http/middleware/server-timing.test.ts +15 -0
  252. package/templates/app/app/http/middleware/server-timing.ts +42 -0
  253. package/templates/app/app/initializers/assets.ts +11 -0
  254. package/templates/app/app/initializers/captcha.ts +11 -0
  255. package/templates/app/app/initializers/cli.ts +75 -0
  256. package/templates/app/app/initializers/database.test.ts +18 -0
  257. package/templates/app/app/initializers/database.ts +18 -0
  258. package/templates/app/app/initializers/dispatcher.ts +36 -0
  259. package/templates/app/app/initializers/honeypot.ts +11 -0
  260. package/templates/app/app/initializers/i18n.test.ts +16 -0
  261. package/templates/app/app/initializers/i18n.ts +28 -0
  262. package/templates/app/app/initializers/local-database.test.ts +33 -0
  263. package/templates/app/app/initializers/local-database.ts +53 -0
  264. package/templates/app/app/initializers/logger.ts +10 -0
  265. package/templates/app/app/initializers/mail.test.ts +27 -0
  266. package/templates/app/app/initializers/mail.ts +11 -0
  267. package/templates/app/app/initializers/mcp.ts +16 -0
  268. package/templates/app/app/initializers/openapi.ts +21 -0
  269. package/templates/app/app/initializers/router.test.ts +61 -0
  270. package/templates/app/app/initializers/router.tsx +111 -0
  271. package/templates/app/app/initializers/seo.ts +15 -0
  272. package/templates/app/app/initializers/session.test.ts +34 -0
  273. package/templates/app/app/initializers/session.ts +29 -0
  274. package/templates/app/app/initializers/spam.ts +10 -0
  275. package/templates/app/app/jobs/index.ts +10 -0
  276. package/templates/app/app/mcp/resources/index.ts +9 -0
  277. package/templates/app/app/mcp/tools/index.ts +10 -0
  278. package/templates/app/app/models/index.ts +10 -0
  279. package/templates/app/app/services/migrations.test.ts +45 -0
  280. package/templates/app/app/services/migrations.ts +60 -0
  281. package/templates/app/app/test/cloudflare-workers.ts +25 -0
  282. package/templates/app/bootstrap/browser.ts +27 -0
  283. package/templates/app/bootstrap/cli.ts +9 -0
  284. package/templates/app/bootstrap/worker.ts +31 -0
  285. package/templates/app/cloudflare.config.ts +56 -0
  286. package/templates/app/config/constants.ts +19 -0
  287. package/templates/app/config/problems.ts +24 -0
  288. package/templates/app/config/security-policy.ts +34 -0
  289. package/templates/app/config/security-txt.ts +28 -0
  290. package/templates/app/database/migrations/.gitkeep +0 -0
  291. package/templates/app/gitignore +9 -0
  292. package/templates/app/package.json +68 -0
  293. package/templates/app/resources/layouts/document.tsx +79 -0
  294. package/templates/app/resources/locales/en.json +10 -0
  295. package/templates/app/routes/api.ts +29 -0
  296. package/templates/app/routes/web.ts +14 -0
  297. package/templates/app/tsconfig.json +40 -0
  298. package/templates/app/vite.config.ts +44 -0
@@ -0,0 +1,598 @@
1
+ /**
2
+ * Declares and maps what `make job`, `make controller`, `make mcp` and `make command` generate:
3
+ * the entry in the job map, route contract, MCP or command declaration module, and the mapping
4
+ * in the initializer that serves it, plus a page's sitemap decision; `make model` registers the
5
+ * model in `app/models/index.ts` the same way. Every edit is computed before anything is written;
6
+ * when one cannot be placed, none is made and the command prints them for the user instead.
7
+ *
8
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
9
+ * @copyright Sergio Xalambrí 2026
10
+ */
11
+ import { readdir, readFile } from "node:fs/promises";
12
+ import { dirname, join, posix } from "node:path";
13
+ import { addProperty, findModuleReferences, insertAfterLast } from "@sdxc/codemod";
14
+ import { failure, isFailure, isSuccess, success, wrap } from "@sdxc/result";
15
+ import { literal, memberAccess } from "./generate.js";
16
+ import { ensureImport, resolvesTo, specifierFor } from "./imports.js";
17
+ import { camel } from "./names.js";
18
+ /** The `remix/routes` helper each `--method` declares with; `form` adds a page and an action. */
19
+ const ROUTE_HELPERS = {
20
+ get: "get",
21
+ post: "post",
22
+ put: "put",
23
+ patch: "patch",
24
+ delete: "del",
25
+ form: "form",
26
+ };
27
+ /** The route helpers that declare a page, which a sitemap built with `fromRoutes` must decide. */
28
+ const PAGE_HELPERS = new Set(["get", "form"]);
29
+ /** The name an instance gets when the initializer that creates it cannot be read, by factory. */
30
+ const INSTANCE_NAMES = {
31
+ createRouter: "router",
32
+ createHandler: "mcp",
33
+ createCLI: "cli",
34
+ };
35
+ /** Plans the declaration and mapping for `request` in the project at `root`. */
36
+ export async function declare(request, root) {
37
+ if (request.kind === "job")
38
+ return declareJob(request, root);
39
+ if (request.kind === "controller")
40
+ return declareController(request, root);
41
+ if (request.kind === "command")
42
+ return declareCommand(request, root);
43
+ if (request.kind === "model")
44
+ return declareModel(request, root);
45
+ return declareMcp(request, root);
46
+ }
47
+ /** Declares a job in `app/jobs/index.ts` and maps it on the job dispatcher. */
48
+ async function declareJob(request, root) {
49
+ let declarations = "app/jobs/index.ts";
50
+ let module = "app/jobs/index";
51
+ let { name } = request;
52
+ let initializer = await findInitializer(root, module, "createJobDispatcher");
53
+ let instance = initializer === null ? "dispatcher" : instanceOf(initializer, "createJobDispatcher");
54
+ let local = initializer === null ? "jobs" : (defaultLocal(initializer, module) ?? "jobs");
55
+ let groups = initializer === null ? null : reusedGroup(initializer, instance, local, name);
56
+ let path = [...(groups ?? name.segments.slice(0, -1).map(camel)), name.key];
57
+ let value = request.variant === "cron"
58
+ ? `job({ cron: ${literal(request.cron ?? "")} })`
59
+ : "job({ input: s.object({}) })";
60
+ let handler = initializer === null ? `~/${request.handler}` : handlerSpecifier(initializer, request.handler);
61
+ let statement = `${instance}.map(${local}.${path.join(".")}, () => import(${literal(handler)}));`;
62
+ let manual = (reason) => ({
63
+ kind: "manual",
64
+ path: path.join("."),
65
+ reason,
66
+ instructions: instructions(`${declarations}, in jobs({ … })${groupNote(path)}`, `${path.at(-1)}: ${value},`, initializer?.path ?? "the job dispatcher's initializer", statement),
67
+ });
68
+ if (initializer === null)
69
+ return manual("no initializer in app/initializers/ creates the job dispatcher");
70
+ let file = await readSource(root, declarations);
71
+ if (isFailure(file))
72
+ return manual(`${declarations} could not be read`);
73
+ let jobsSpecifier = file.data.references.find((reference) => reference.kind === "import" && reference.names.some((bound) => bound.imported === "jobs"))?.specifier;
74
+ if (jobsSpecifier === undefined)
75
+ return manual(`${declarations} does not import jobs()`);
76
+ let builder = ensureImport(declarations, file.data.source, { kind: "named", name: "job" }, (specifier) => specifier === jobsSpecifier, jobsSpecifier, "job");
77
+ if (isFailure(builder))
78
+ return manual(builder.error.message);
79
+ let jobLocal = builder.data.local;
80
+ let source = builder.data.source;
81
+ value = value.replace(/^job\(/, `${jobLocal}(`);
82
+ if (request.variant !== "cron") {
83
+ let schema = ensureImport(declarations, source, { kind: "namespace" }, (specifier) => specifier === "remix/data-schema", "remix/data-schema", "s");
84
+ if (isFailure(schema))
85
+ return manual(schema.error.message);
86
+ value = `${jobLocal}({ input: ${schema.data.local}.object({}) })`;
87
+ source = schema.data.source;
88
+ }
89
+ let added = addProperty(declarations, source, {
90
+ call: "jobs",
91
+ path: path.slice(0, -1),
92
+ key: name.key,
93
+ value,
94
+ });
95
+ if (isFailure(added))
96
+ return manual(added.error.message);
97
+ let mapped = mapAfter(initializer, module, local, statement, `${instance}.map`, "createJobDispatcher");
98
+ if (isFailure(mapped))
99
+ return manual(mapped.error.message);
100
+ return {
101
+ kind: "edits",
102
+ path: path.join("."),
103
+ edits: [
104
+ { path: declarations, before: file.data.source, after: added.data.source },
105
+ { path: initializer.path, before: initializer.source, after: mapped.data },
106
+ ],
107
+ };
108
+ }
109
+ /** Declares a route in the contract `routes/<contract>.ts` and maps it on the router. */
110
+ async function declareController(request, root) {
111
+ let { name } = request;
112
+ let module = `routes/${request.routes}`;
113
+ let contract = await findContract(root, module);
114
+ let initializer = await findInitializer(root, module, "createRouter", "required");
115
+ let instance = initializer === null ? "router" : instanceOf(initializer, "createRouter");
116
+ let local = initializer === null ? "routes" : (defaultLocal(initializer, module) ?? "routes");
117
+ let path = [...name.segments.slice(0, -1).map(camel), name.key];
118
+ let helper = ROUTE_HELPERS[request.method] ?? "get";
119
+ let pattern = request.pattern ?? `/${name.segments.join("/")}`;
120
+ let value = `${helper}(${literal(pattern)})`;
121
+ let handler = initializer === null ? `~/${request.handler}` : handlerSpecifier(initializer, request.handler);
122
+ let lazyLocal = "lazy";
123
+ let statement = (lazy) => `${instance}.map(${local}.${path.join(".")}, ${lazy}(() => import(${literal(handler)})));`;
124
+ let sitemap = PAGE_HELPERS.has(helper) ? await findSitemap(root, module) : null;
125
+ let decision = sitemapDecision(helper, pattern);
126
+ let manual = (reason) => ({
127
+ kind: "manual",
128
+ path: path.join("."),
129
+ reason,
130
+ instructions: [
131
+ instructions(`${contract ?? `${module}.ts`}, in route({ … })${groupNote(path)}`, `${path.at(-1)}: ${value},`, initializer?.path ?? `the initializer that maps ${module}`, statement(lazyLocal)),
132
+ sitemap === null
133
+ ? null
134
+ : [
135
+ `In ${sitemap.path}, in fromRoutes(…)'s decisions${groupNote(path)}:`,
136
+ indent(`${path.at(-1)}: ${decision},`),
137
+ ].join("\n"),
138
+ ]
139
+ .filter((text) => text !== null)
140
+ .join("\n"),
141
+ });
142
+ if (contract === null)
143
+ return manual(`there is no route contract ${module}.ts`);
144
+ if (initializer === null)
145
+ return manual(`no initializer in app/initializers/ imports ${module}`);
146
+ let file = await readSource(root, contract);
147
+ if (isFailure(file))
148
+ return manual(`${contract} could not be read`);
149
+ let imported = ensureImport(contract, file.data.source, { kind: "named", name: helper }, (specifier) => specifier === "remix/routes", "remix/routes", helper);
150
+ if (isFailure(imported))
151
+ return manual(imported.error.message);
152
+ value = `${imported.data.local}(${literal(pattern)})`;
153
+ let added = addProperty(contract, imported.data.source, {
154
+ call: "route",
155
+ path: path.slice(0, -1),
156
+ key: name.key,
157
+ value,
158
+ });
159
+ if (isFailure(added))
160
+ return manual(added.error.message);
161
+ let lazy = ensureImport(initializer.path, initializer.source, { kind: "named", name: "lazy" }, (specifier) => specifier.endsWith("lazy-route"), "@sdxc/lazy-route", "lazy");
162
+ if (isFailure(lazy))
163
+ return manual(lazy.error.message);
164
+ lazyLocal = lazy.data.local;
165
+ let withLazy = { ...initializer, source: lazy.data.source };
166
+ let mapped = mapAfter(withLazy, module, local, statement(lazyLocal), `${instance}.map`, "createRouter");
167
+ if (isFailure(mapped))
168
+ return manual(mapped.error.message);
169
+ let edits = [
170
+ { path: contract, before: file.data.source, after: added.data.source },
171
+ { path: initializer.path, before: initializer.source, after: mapped.data },
172
+ ];
173
+ if (sitemap !== null) {
174
+ let decided = addProperty(sitemap.path, sitemap.source, {
175
+ call: "fromRoutes",
176
+ argument: 2,
177
+ path: path.slice(0, -1),
178
+ key: name.key,
179
+ value: decision,
180
+ });
181
+ if (isSuccess(decided)) {
182
+ edits.push({ path: sitemap.path, before: sitemap.source, after: decided.data.source });
183
+ }
184
+ else if (decided.error.code === "invalid-output") {
185
+ return manual(decided.error.message);
186
+ }
187
+ }
188
+ return { kind: "edits", path: path.join("."), edits };
189
+ }
190
+ /**
191
+ * The sitemap decision a new page starts with: listed, or an empty list of pages when its pattern
192
+ * has required params, so it is in the sitemap until the developer changes it. A `form` route
193
+ * decides its page under `index`.
194
+ */
195
+ function sitemapDecision(helper, pattern) {
196
+ let required = /[:*][A-Za-z_$]/.test(pattern.replace(/\([^)]*\)/g, ""));
197
+ let page = required ? "[]" : "true";
198
+ return helper === "form" ? `{ index: ${page} }` : page;
199
+ }
200
+ /**
201
+ * The controller that builds a sitemap with `fromRoutes` over the contract `module`, which needs
202
+ * a decision for every page the contract declares; `null` when the app has none.
203
+ */
204
+ async function findSitemap(root, module) {
205
+ let folder = "app/http/controllers";
206
+ let entries = await wrap(() => readdir(join(root, folder), { recursive: true }));
207
+ if (isFailure(entries))
208
+ return null;
209
+ for (let entry of entries.data.sort()) {
210
+ if (!/\.tsx?$/.test(entry) || /\.test\.tsx?$/.test(entry))
211
+ continue;
212
+ let file = await readSource(root, posix.join(folder, entry.split("\\").join("/")));
213
+ if (isFailure(file) || !file.data.source.includes("fromRoutes("))
214
+ continue;
215
+ let local = defaultLocal(file.data, module);
216
+ if (local === null)
217
+ continue;
218
+ if (new RegExp(`\\bfromRoutes\\(\\s*${escape(local)}\\s*,`).test(file.data.source)) {
219
+ return file.data;
220
+ }
221
+ }
222
+ return null;
223
+ }
224
+ /** Declares an MCP tool or resource beside the others and maps it on the MCP handler. */
225
+ async function declareMcp(request, root) {
226
+ let resource = request.variant === "resource";
227
+ let group = resource ? "resources" : "tools";
228
+ let module = `app/mcp/${group}/index`;
229
+ let declarations = `${module}.ts`;
230
+ let { name } = request;
231
+ let initializer = await findInitializer(root, module, "createHandler");
232
+ let instance = initializer === null ? "mcp" : instanceOf(initializer, "createHandler");
233
+ let preferred = resource ? "resourceset" : "toolset";
234
+ let local = initializer === null ? preferred : (defaultLocal(initializer, module) ?? preferred);
235
+ let path = [...name.segments.slice(0, -1).map(camel), name.key];
236
+ let builder = resource ? "resource" : "tool";
237
+ let body = resource
238
+ ? [`name: ${literal(request.title)},`, 'mimeType: "text/markdown",']
239
+ : [`description: ${literal(`${request.title}.`)},`, "input: s.object({}),"];
240
+ let first = resource ? request.uri : request.tool;
241
+ let valueWith = (callee, lines) => `${callee}(${literal(first)}, {\n${lines.map((line) => `\t${line}`).join("\n")}\n})`;
242
+ let value = valueWith(builder, body);
243
+ let handler = initializer === null ? `~/${request.handler}` : handlerSpecifier(initializer, request.handler);
244
+ let statement = (lazy) => `${instance}.${group}.map(${local}.${path.join(".")}, ${lazy}(() => import(${literal(handler)})));`;
245
+ let manual = (reason) => ({
246
+ kind: "manual",
247
+ path: path.join("."),
248
+ reason,
249
+ instructions: instructions(`${declarations}, in ${group}({ … })${groupNote(path)}`, `${path.at(-1)}: ${value},`, initializer?.path ?? "the MCP handler's initializer", statement("lazy")),
250
+ });
251
+ if (initializer === null)
252
+ return manual("no initializer in app/initializers/ creates the MCP handler");
253
+ let file = await readSource(root, declarations);
254
+ if (isFailure(file))
255
+ return manual(`${declarations} could not be read`);
256
+ let mcpSpecifier = file.data.references.find((reference) => reference.kind === "import" && reference.names.some((bound) => bound.imported === group))?.specifier;
257
+ if (mcpSpecifier === undefined)
258
+ return manual(`${declarations} does not import ${group}()`);
259
+ let builderImport = ensureImport(declarations, file.data.source, { kind: "named", name: builder }, (specifier) => specifier === mcpSpecifier, mcpSpecifier, builder);
260
+ if (isFailure(builderImport))
261
+ return manual(builderImport.error.message);
262
+ let source = builderImport.data.source;
263
+ if (!resource) {
264
+ let schemaSpecifier = mcpSpecifier.replace(/mcp$/, "json-schema");
265
+ let schema = ensureImport(declarations, source, { kind: "namespace" }, (specifier) => specifier === schemaSpecifier, schemaSpecifier, "s");
266
+ if (isFailure(schema))
267
+ return manual(schema.error.message);
268
+ source = schema.data.source;
269
+ body[1] = `input: ${schema.data.local}.object({}),`;
270
+ }
271
+ let added = addProperty(declarations, source, {
272
+ call: group,
273
+ path: path.slice(0, -1),
274
+ key: name.key,
275
+ value: valueWith(builderImport.data.local, body),
276
+ });
277
+ if (isFailure(added))
278
+ return manual(added.error.message);
279
+ let handlerSource = initializer.references.find((reference) => reference.kind === "import" &&
280
+ reference.names.some((bound) => bound.imported === "createHandler"))?.specifier;
281
+ if (handlerSource === undefined)
282
+ return manual(`${initializer.path} does not import createHandler`);
283
+ let lazy = ensureImport(initializer.path, initializer.source, { kind: "named", name: "lazy" }, (specifier) => specifier === handlerSource, handlerSource, "lazy");
284
+ if (isFailure(lazy))
285
+ return manual(lazy.error.message);
286
+ let withLazy = { ...initializer, source: lazy.data.source };
287
+ let mapped = mapAfter(withLazy, module, local, statement(lazy.data.local), `${instance}.${group}.map`, "createHandler");
288
+ if (isFailure(mapped))
289
+ return manual(mapped.error.message);
290
+ return {
291
+ kind: "edits",
292
+ path: path.join("."),
293
+ edits: [
294
+ { path: declarations, before: file.data.source, after: added.data.source },
295
+ { path: initializer.path, before: initializer.source, after: mapped.data },
296
+ ],
297
+ };
298
+ }
299
+ /**
300
+ * Declares a command in `app/commands/index.ts` and maps it on the command line. Each folder of
301
+ * the name is a `commands({ … })` group, created when missing, and the command's key is the
302
+ * word typed to run it, so `users/send-digest` runs as `users send-digest`.
303
+ */
304
+ async function declareCommand(request, root) {
305
+ let module = "app/commands/index";
306
+ let declarations = `${module}.ts`;
307
+ let segments = request.name.segments;
308
+ let groups = segments.slice(0, -1);
309
+ let leaf = segments.at(-1) ?? "";
310
+ let initializer = await findInitializer(root, module, "createCLI");
311
+ let instance = initializer === null ? "cli" : instanceOf(initializer, "createCLI");
312
+ let local = initializer === null ? "commandset" : (defaultLocal(initializer, module) ?? "commandset");
313
+ let description = literal(request.title);
314
+ let handler = initializer === null ? `~/${request.handler}` : handlerSpecifier(initializer, request.handler);
315
+ let statement = (lazy) => `${instance}.map(${local}${memberAccess(segments)}, ${lazy}(() => import(${literal(handler)})));`;
316
+ let manual = (reason) => ({
317
+ kind: "manual",
318
+ path: segments.join("."),
319
+ reason,
320
+ instructions: instructions(`${declarations}, in commands({ … })${groups.length > 0 ? `, inside a commands({ … }) group for each of ${groups.join(", ")}` : ""}`, `${keyText(leaf)}: command({ description: ${description} }),`, initializer?.path ?? "the command line's initializer", statement("lazy")),
321
+ });
322
+ if (initializer === null)
323
+ return manual("no initializer in app/initializers/ creates the command line");
324
+ let file = await readSource(root, declarations);
325
+ if (isFailure(file))
326
+ return manual(`${declarations} could not be read`);
327
+ let group = file.data.references.find((reference) => reference.kind === "import" && reference.names.some((bound) => bound.imported === "commands"));
328
+ let groupLocal = group?.names.find((bound) => bound.imported === "commands")?.local;
329
+ if (group === undefined || groupLocal === undefined)
330
+ return manual(`${declarations} does not import commands()`);
331
+ let builder = ensureImport(declarations, file.data.source, { kind: "named", name: "command" }, (specifier) => specifier === group.specifier, group.specifier, "command");
332
+ if (isFailure(builder))
333
+ return manual(builder.error.message);
334
+ let source = builder.data.source;
335
+ let depth = 0;
336
+ for (; depth < groups.length; depth += 1) {
337
+ let level = groups[depth] ?? "";
338
+ let probe = addProperty(declarations, source, {
339
+ call: groupLocal,
340
+ path: groups.slice(0, depth),
341
+ key: level,
342
+ value: "0",
343
+ });
344
+ if (isSuccess(probe))
345
+ break;
346
+ if (probe.error.code !== "duplicate-key")
347
+ return manual(probe.error.message);
348
+ let isGroup = new RegExp(`(?:^|[\\s{,])["']?${escape(level)}["']?\\s*:\\s*${escape(groupLocal)}\\(`);
349
+ if (!isGroup.test(source)) {
350
+ return manual(`\`${groups.slice(0, depth + 1).join(".")}\` is a command, not a group`);
351
+ }
352
+ }
353
+ let entry = `${keyText(leaf)}: ${builder.data.local}({ description: ${description} })`;
354
+ let added = depth === groups.length
355
+ ? addProperty(declarations, source, {
356
+ call: groupLocal,
357
+ path: groups,
358
+ key: leaf,
359
+ value: `${builder.data.local}({ description: ${description} })`,
360
+ })
361
+ : addProperty(declarations, source, {
362
+ call: groupLocal,
363
+ path: groups.slice(0, depth),
364
+ key: groups[depth] ?? "",
365
+ value: groupValue(groupLocal, groups.slice(depth + 1), entry),
366
+ });
367
+ if (isFailure(added))
368
+ return manual(added.error.message);
369
+ let cliSource = initializer.references.find((reference) => reference.kind === "import" &&
370
+ reference.names.some((bound) => bound.imported === "createCLI"))?.specifier;
371
+ if (cliSource === undefined)
372
+ return manual(`${initializer.path} does not import createCLI`);
373
+ let lazy = ensureImport(initializer.path, initializer.source, { kind: "named", name: "lazy" }, (specifier) => specifier === cliSource, cliSource, "lazy");
374
+ if (isFailure(lazy))
375
+ return manual(lazy.error.message);
376
+ let withLazy = { ...initializer, source: lazy.data.source };
377
+ let mapped = mapAfter(withLazy, module, local, statement(lazy.data.local), `${instance}.map`, "createCLI");
378
+ if (isFailure(mapped))
379
+ return manual(mapped.error.message);
380
+ return {
381
+ kind: "edits",
382
+ path: segments.join("."),
383
+ edits: [
384
+ { path: declarations, before: file.data.source, after: added.data.source },
385
+ { path: initializer.path, before: initializer.source, after: mapped.data },
386
+ ],
387
+ };
388
+ }
389
+ /**
390
+ * Registers a model in `app/models/index.ts`'s `createModels({ … })` under its key, as an import
391
+ * the registry runs on first use, so `ctx.models.<key>` reaches it on every request, job and
392
+ * command once the command finishes.
393
+ */
394
+ async function declareModel(request, root) {
395
+ let declarations = "app/models/index.ts";
396
+ let key = request.name.key;
397
+ let file = await readSource(root, declarations);
398
+ let specifier = isFailure(file)
399
+ ? `./${request.name.segments.join("/")}`
400
+ : specifierFor(declarations, request.handler, staticSpecifiers(file.data), false);
401
+ let value = `() => import(${literal(specifier)})`;
402
+ let manual = (reason) => ({
403
+ kind: "manual",
404
+ path: key,
405
+ reason,
406
+ instructions: [
407
+ `In ${declarations}, in createModels({ … }):`,
408
+ indent(`${keyText(key)}: ${value},`),
409
+ ].join("\n"),
410
+ });
411
+ if (isFailure(file))
412
+ return manual(`${declarations} could not be read`);
413
+ let call = file.data.references
414
+ .find((reference) => reference.kind === "import" &&
415
+ reference.names.some((bound) => bound.imported === "createModels"))
416
+ ?.names.find((bound) => bound.imported === "createModels")?.local;
417
+ if (call === undefined)
418
+ return manual(`${declarations} does not import createModels()`);
419
+ let added = addProperty(declarations, file.data.source, { call, path: [], key, value });
420
+ if (isFailure(added))
421
+ return manual(added.error.message);
422
+ return {
423
+ kind: "edits",
424
+ path: key,
425
+ edits: [{ path: declarations, before: file.data.source, after: added.data.source }],
426
+ };
427
+ }
428
+ /**
429
+ * A `commands({ … })` group holding `entry`, wrapped in one more group for each of `levels`,
430
+ * outermost first, for the folders of a command name that have no group yet.
431
+ */
432
+ function groupValue(call, levels, entry) {
433
+ let inner = entry;
434
+ for (let level of [...levels].reverse()) {
435
+ inner = `${keyText(level)}: ${call}({\n${indentTab(inner)},\n})`;
436
+ }
437
+ return `${call}({\n${indentTab(inner)},\n})`;
438
+ }
439
+ /** A command's key as an identifier when it is one, quoted otherwise. */
440
+ function keyText(key) {
441
+ return /^[A-Za-z_$][\w$]*$/.test(key) ? key : literal(key);
442
+ }
443
+ /** Every line of `text` indented by one tab. */
444
+ function indentTab(text) {
445
+ return text
446
+ .split("\n")
447
+ .map((line) => `\t${line}`)
448
+ .join("\n");
449
+ }
450
+ /**
451
+ * `file` with the declarations module imported as `local` (added when missing) and `statement`
452
+ * after the last call to `call`, or after the instance `factory` creates when there is none.
453
+ */
454
+ function mapAfter(file, module, local, statement, call, factory) {
455
+ let examples = staticSpecifiers(file);
456
+ let imported = ensureImport(file.path, file.source, { kind: "default" }, (specifier) => resolvesTo(specifier, file.path, module), specifierFor(file.path, module, examples, file.aliased ?? false), local);
457
+ if (isFailure(imported))
458
+ return imported;
459
+ if (imported.data.local !== local)
460
+ return failure(new Error(`${file.path} imports ${module} as ${imported.data.local}`));
461
+ let inserted = insertAfterLast(file.path, imported.data.source, {
462
+ call,
463
+ statement,
464
+ fallbackAfter: factory,
465
+ });
466
+ if (isFailure(inserted))
467
+ return inserted;
468
+ return success(inserted.data.source);
469
+ }
470
+ /**
471
+ * The initializer in `app/initializers/` that imports `module` and calls `factory`, else the
472
+ * first that imports it, else (unless `importing` is required) one that calls `factory`; `null`
473
+ * when none does. Test files are skipped.
474
+ */
475
+ async function findInitializer(root, module, factory, importing = "preferred") {
476
+ let folder = "app/initializers";
477
+ let entries = await wrap(() => readdir(join(root, folder)));
478
+ if (isFailure(entries))
479
+ return null;
480
+ let files = [];
481
+ for (let entry of entries.data.sort()) {
482
+ if (!/\.tsx?$/.test(entry) || /\.test\.tsx?$/.test(entry) || entry.endsWith(".d.ts"))
483
+ continue;
484
+ let file = await readSource(root, `${folder}/${entry}`);
485
+ if (isSuccess(file))
486
+ files.push(file.data);
487
+ }
488
+ let tsconfig = await wrap(() => readFile(join(root, "tsconfig.json"), "utf8"));
489
+ let aliased = !isFailure(tsconfig) && tsconfig.data.includes('"~/app/*"');
490
+ for (let file of files)
491
+ file.aliased = aliased;
492
+ let calling = factory === null ? null : new RegExp(`\\b${factory}\\(`);
493
+ let importers = files.filter((file) => file.references.some((reference) => reference.kind === "import" && resolvesTo(reference.specifier, file.path, module)));
494
+ let found = importers.find((file) => calling?.test(file.source) ?? true) ?? importers[0];
495
+ if (found !== undefined)
496
+ return found;
497
+ if (calling === null || importing === "required")
498
+ return null;
499
+ return files.find((file) => calling.test(file.source)) ?? null;
500
+ }
501
+ /** The route contract file for `module` (`routes/web`), `.ts` or `.tsx`, or `null`. */
502
+ async function findContract(root, module) {
503
+ for (let extension of [".ts", ".tsx"]) {
504
+ let path = `${module}${extension}`;
505
+ if (isSuccess(await wrap(() => readFile(join(root, path)))))
506
+ return path;
507
+ }
508
+ return null;
509
+ }
510
+ /** Reads a project file and scans its module references. */
511
+ async function readSource(root, path) {
512
+ let source = await wrap(() => readFile(join(root, path), "utf8"));
513
+ if (isFailure(source))
514
+ return source;
515
+ let references = findModuleReferences(path, source.data);
516
+ if (isFailure(references))
517
+ return references;
518
+ return success({ path, source: source.data, references: references.data });
519
+ }
520
+ /** The variable the instance `factory` creates is bound to, such as `dispatcher` or `router`. */
521
+ function instanceOf(file, factory) {
522
+ let match = new RegExp(`(?:const|let|var)\\s+([A-Za-z_$][\\w$]*)\\s*=\\s*${factory}\\(`).exec(file.source);
523
+ return match?.[1] ?? INSTANCE_NAMES[factory] ?? "dispatcher";
524
+ }
525
+ /** The local name `file` binds the default export of `module` to, or `null`. */
526
+ function defaultLocal(file, module) {
527
+ for (let reference of file.references) {
528
+ if (reference.kind !== "import" || !resolvesTo(reference.specifier, file.path, module))
529
+ continue;
530
+ let bound = reference.names.find((name) => name.imported === "default");
531
+ if (bound !== undefined)
532
+ return bound.local;
533
+ }
534
+ return null;
535
+ }
536
+ /**
537
+ * The group keys of an existing job mapping whose handler lives in the folder `name` names,
538
+ * so `activitypub/send` joins the `activityPub` group its siblings are mapped under.
539
+ */
540
+ function reusedGroup(file, instance, local, name) {
541
+ let folders = name.segments.slice(0, -1);
542
+ if (folders.length === 0)
543
+ return [];
544
+ let mapping = new RegExp(`${escape(instance)}\\.map\\(\\s*${escape(local)}\\.([\\w$.]+)\\s*,[^;]*?import\\(\\s*["']([^"']+)["']`, "g");
545
+ for (let match of file.source.matchAll(mapping)) {
546
+ let keys = (match[1] ?? "").split(".");
547
+ let target = projectPath(match[2] ?? "", file.path);
548
+ if (target === null || !target.startsWith("app/jobs/"))
549
+ continue;
550
+ let segments = target.slice("app/jobs/".length).split("/").slice(0, -1);
551
+ let sameFolder = segments.length === folders.length &&
552
+ segments.every((segment, index) => segment === folders[index]);
553
+ if (sameFolder && keys.length === folders.length + 1)
554
+ return keys.slice(0, -1);
555
+ }
556
+ return null;
557
+ }
558
+ /** A specifier written in `fromFile` as a project-relative path, or `null` for a package. */
559
+ function projectPath(specifier, fromFile) {
560
+ if (specifier.startsWith("~/"))
561
+ return specifier.slice(2);
562
+ if (specifier.startsWith("."))
563
+ return posix.join(dirname(fromFile), specifier);
564
+ return null;
565
+ }
566
+ /** How the initializer imports a new handler, following the form its existing mappings use. */
567
+ function handlerSpecifier(file, handler) {
568
+ let dynamic = file.references
569
+ .filter((reference) => reference.kind === "dynamic")
570
+ .map((reference) => reference.specifier);
571
+ let examples = dynamic.length > 0 ? dynamic : staticSpecifiers(file);
572
+ return specifierFor(file.path, handler, examples, file.aliased ?? false);
573
+ }
574
+ /** The specifiers of a file's static imports. */
575
+ function staticSpecifiers(file) {
576
+ return file.references
577
+ .filter((reference) => reference.kind === "import")
578
+ .map((reference) => reference.specifier);
579
+ }
580
+ /** Where a nested declaration goes, for the printed instructions. */
581
+ function groupNote(path) {
582
+ return path.length > 1 ? `, under ${path.slice(0, -1).join(".")}` : "";
583
+ }
584
+ /** The two edits to make by hand, as `make` prints them. */
585
+ function instructions(declarationsAt, declaration, initializer, mapping) {
586
+ return [`In ${declarationsAt}:`, indent(declaration), `In ${initializer}:`, indent(mapping)].join("\n");
587
+ }
588
+ /** Every line of `text` indented by two spaces. */
589
+ function indent(text) {
590
+ return text
591
+ .split("\n")
592
+ .map((line) => ` ${line}`)
593
+ .join("\n");
594
+ }
595
+ /** `text` with every regular-expression metacharacter escaped. */
596
+ function escape(text) {
597
+ return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
598
+ }
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Plans the files one `sdxc make` run writes: the file of the requested kind at the folder the
3
+ * layout gives it and, when tests are on, its test beside it, each rendered from its stub.
4
+ * Nothing is written while planning, and a file that already exists stops the plan.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import type { Result } from "@sdxc/result";
10
+ import type { Config } from "../config.js";
11
+ import type { KindName } from "./kinds.js";
12
+ import type { Name } from "./names.js";
13
+ /** One `make` request, as the command line spelled it. */
14
+ export interface MakeRequest {
15
+ kind: KindName;
16
+ name: Name;
17
+ /** The stub variant a flag selects: `form`, `cron` or `resource`. */
18
+ variant: string | null;
19
+ /** Whether to write a test beside the file. */
20
+ tests: boolean;
21
+ /** The migration chain, for `make migration`. */
22
+ chain?: string;
23
+ /** The route contract a controller is declared in, a module in `routes/`. */
24
+ routes: string;
25
+ }
26
+ /** A file the run writes, by path relative to the project root. */
27
+ export interface PlannedFile {
28
+ path: string;
29
+ content: string;
30
+ }
31
+ /** What one run writes and the placeholder values its stubs were rendered with. */
32
+ export interface Plan {
33
+ files: PlannedFile[];
34
+ values: Record<string, string>;
35
+ }
36
+ /**
37
+ * Plans `request` in the project at `root`. Every planned path must be free; an existing file
38
+ * is a failure naming it, before any stub is read.
39
+ *
40
+ * @param packageRoot - The `@sdxc/kit` package, whose `stubs/` holds the built-in stubs.
41
+ * @param overrides - Placeholder values a declaration decided, such as a job's reused group.
42
+ */
43
+ export declare function plan(request: MakeRequest, root: string, config: Config, packageRoot: string, overrides?: Readonly<Record<string, string>>): Promise<Result<Plan, Error>>;
44
+ /** The folder a kind's files go in; a migration's comes from its chain instead. */
45
+ export declare function folderOf(kind: KindName, variant: string | null): string;
46
+ /**
47
+ * `value` as a JavaScript string literal that is safe to splice into generated source: quotes,
48
+ * backslashes and control characters are escaped, and so are `<`, `>` and the two Unicode line
49
+ * separators, so a name or path can never close a script element or break the line it sits on.
50
+ */
51
+ export declare function literal(value: string): string;
52
+ /**
53
+ * The property access that reaches a command's declaration from its contract: `.users.grant`,
54
+ * with a segment that is no identifier read by its quoted key (`["send-digest"]`), since a
55
+ * command's key is the word typed to run it.
56
+ */
57
+ export declare function memberAccess(segments: readonly string[]): string;
58
+ /**
59
+ * The URI scheme an MCP resource is declared under: the project's package name without its
60
+ * scope, reduced to the characters a scheme allows, or `app` when nothing usable is left.
61
+ */
62
+ export declare function resourceScheme(root: string): Promise<string>;