@dual-os/cli 0.0.0-stage → 0.11.0-next.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 (254) hide show
  1. package/LICENSE +4 -0
  2. package/README.md +15 -2
  3. package/dist/_virtual/_rolldown/runtime.js +13 -0
  4. package/dist/auth/credentials.d.ts +17 -0
  5. package/dist/auth/credentials.d.ts.map +1 -0
  6. package/dist/auth/credentials.js +57 -0
  7. package/dist/auth/credentials.js.map +1 -0
  8. package/dist/auth/destination.d.ts +22 -0
  9. package/dist/auth/destination.d.ts.map +1 -0
  10. package/dist/auth/destination.js +49 -0
  11. package/dist/auth/destination.js.map +1 -0
  12. package/dist/auth/http.d.ts +12 -0
  13. package/dist/auth/http.d.ts.map +1 -0
  14. package/dist/auth/http.js +34 -0
  15. package/dist/auth/http.js.map +1 -0
  16. package/dist/auth/login.d.ts +22 -0
  17. package/dist/auth/login.d.ts.map +1 -0
  18. package/dist/auth/login.js +98 -0
  19. package/dist/auth/login.js.map +1 -0
  20. package/dist/auth/protocol.d.ts +26 -0
  21. package/dist/auth/protocol.d.ts.map +1 -0
  22. package/dist/auth/protocol.js +31 -0
  23. package/dist/auth/protocol.js.map +1 -0
  24. package/dist/baseline.d.ts +18 -0
  25. package/dist/baseline.d.ts.map +1 -0
  26. package/dist/baseline.js +22 -0
  27. package/dist/baseline.js.map +1 -0
  28. package/dist/bin.d.ts +1 -0
  29. package/dist/bin.js +7 -0
  30. package/dist/bin.js.map +1 -0
  31. package/dist/cli.d.ts +19 -0
  32. package/dist/cli.d.ts.map +1 -0
  33. package/dist/cli.js +492 -0
  34. package/dist/cli.js.map +1 -0
  35. package/dist/create/choices.d.ts +58 -0
  36. package/dist/create/choices.d.ts.map +1 -0
  37. package/dist/create/choices.js +121 -0
  38. package/dist/create/choices.js.map +1 -0
  39. package/dist/create/deployment.d.ts +48 -0
  40. package/dist/create/deployment.d.ts.map +1 -0
  41. package/dist/create/deployment.js +66 -0
  42. package/dist/create/deployment.js.map +1 -0
  43. package/dist/create/scaffold.d.ts +57 -0
  44. package/dist/create/scaffold.d.ts.map +1 -0
  45. package/dist/create/scaffold.js +198 -0
  46. package/dist/create/scaffold.js.map +1 -0
  47. package/dist/create/source-reference.d.ts +39 -0
  48. package/dist/create/source-reference.d.ts.map +1 -0
  49. package/dist/create/source-reference.js +185 -0
  50. package/dist/create/source-reference.js.map +1 -0
  51. package/dist/create/template.d.ts +116 -0
  52. package/dist/create/template.d.ts.map +1 -0
  53. package/dist/create/template.js +211 -0
  54. package/dist/create/template.js.map +1 -0
  55. package/dist/diagnostics.d.ts +6 -0
  56. package/dist/diagnostics.d.ts.map +1 -0
  57. package/dist/diagnostics.js +18 -0
  58. package/dist/diagnostics.js.map +1 -0
  59. package/dist/help.d.ts +16 -0
  60. package/dist/help.d.ts.map +1 -0
  61. package/dist/help.js +73 -0
  62. package/dist/help.js.map +1 -0
  63. package/dist/openapi/bundle.d.ts +18 -0
  64. package/dist/openapi/bundle.d.ts.map +1 -0
  65. package/dist/openapi/bundle.js +201 -0
  66. package/dist/openapi/bundle.js.map +1 -0
  67. package/dist/openapi/discovery.d.ts +30 -0
  68. package/dist/openapi/discovery.d.ts.map +1 -0
  69. package/dist/openapi/discovery.js +325 -0
  70. package/dist/openapi/discovery.js.map +1 -0
  71. package/dist/openapi/emit.d.ts +52 -0
  72. package/dist/openapi/emit.d.ts.map +1 -0
  73. package/dist/openapi/emit.js +596 -0
  74. package/dist/openapi/emit.js.map +1 -0
  75. package/dist/openapi/graphql.d.ts +102 -0
  76. package/dist/openapi/graphql.d.ts.map +1 -0
  77. package/dist/openapi/graphql.js +294 -0
  78. package/dist/openapi/graphql.js.map +1 -0
  79. package/dist/openapi/identity.d.ts +88 -0
  80. package/dist/openapi/identity.d.ts.map +1 -0
  81. package/dist/openapi/identity.js +98 -0
  82. package/dist/openapi/identity.js.map +1 -0
  83. package/dist/openapi/mcp.d.ts +21 -0
  84. package/dist/openapi/mcp.d.ts.map +1 -0
  85. package/dist/openapi/mcp.js +133 -0
  86. package/dist/openapi/mcp.js.map +1 -0
  87. package/dist/openapi/operations.d.ts +165 -0
  88. package/dist/openapi/operations.d.ts.map +1 -0
  89. package/dist/openapi/operations.js +361 -0
  90. package/dist/openapi/operations.js.map +1 -0
  91. package/dist/openapi/overlay.d.ts +23 -0
  92. package/dist/openapi/overlay.d.ts.map +1 -0
  93. package/dist/openapi/overlay.js +115 -0
  94. package/dist/openapi/overlay.js.map +1 -0
  95. package/dist/openapi/plugin.d.ts +83 -0
  96. package/dist/openapi/plugin.d.ts.map +1 -0
  97. package/dist/openapi/plugin.js +468 -0
  98. package/dist/openapi/plugin.js.map +1 -0
  99. package/dist/openapi/polymorphism.d.ts +21 -0
  100. package/dist/openapi/polymorphism.d.ts.map +1 -0
  101. package/dist/openapi/polymorphism.js +96 -0
  102. package/dist/openapi/polymorphism.js.map +1 -0
  103. package/dist/openapi/postman.d.ts +21 -0
  104. package/dist/openapi/postman.d.ts.map +1 -0
  105. package/dist/openapi/postman.js +286 -0
  106. package/dist/openapi/postman.js.map +1 -0
  107. package/dist/openapi/schema.d.ts +178 -0
  108. package/dist/openapi/schema.d.ts.map +1 -0
  109. package/dist/openapi/schema.js +1234 -0
  110. package/dist/openapi/schema.js.map +1 -0
  111. package/dist/openapi/select.d.ts +22 -0
  112. package/dist/openapi/select.d.ts.map +1 -0
  113. package/dist/openapi/select.js +79 -0
  114. package/dist/openapi/select.js.map +1 -0
  115. package/dist/openapi/spec.d.ts +147 -0
  116. package/dist/openapi/spec.d.ts.map +1 -0
  117. package/dist/openapi/spec.js +263 -0
  118. package/dist/openapi/spec.js.map +1 -0
  119. package/dist/openapi/swagger.d.ts +166 -0
  120. package/dist/openapi/swagger.d.ts.map +1 -0
  121. package/dist/openapi/swagger.js +298 -0
  122. package/dist/openapi/swagger.js.map +1 -0
  123. package/dist/openapi/versions.d.ts +52 -0
  124. package/dist/openapi/versions.d.ts.map +1 -0
  125. package/dist/openapi/versions.js +120 -0
  126. package/dist/openapi/versions.js.map +1 -0
  127. package/dist/plugin/archive.d.ts +27 -0
  128. package/dist/plugin/archive.d.ts.map +1 -0
  129. package/dist/plugin/archive.js +170 -0
  130. package/dist/plugin/archive.js.map +1 -0
  131. package/dist/plugin/bundle.d.ts +27 -0
  132. package/dist/plugin/bundle.d.ts.map +1 -0
  133. package/dist/plugin/bundle.js +328 -0
  134. package/dist/plugin/bundle.js.map +1 -0
  135. package/dist/plugin/init.d.ts +18 -0
  136. package/dist/plugin/init.d.ts.map +1 -0
  137. package/dist/plugin/init.js +121 -0
  138. package/dist/plugin/init.js.map +1 -0
  139. package/dist/plugin/inspection.d.ts +24 -0
  140. package/dist/plugin/inspection.d.ts.map +1 -0
  141. package/dist/plugin/inspection.js +24 -0
  142. package/dist/plugin/inspection.js.map +1 -0
  143. package/dist/plugin/package.d.ts +26 -0
  144. package/dist/plugin/package.d.ts.map +1 -0
  145. package/dist/plugin/package.js +73 -0
  146. package/dist/plugin/package.js.map +1 -0
  147. package/dist/plugin/publication.d.ts +29 -0
  148. package/dist/plugin/publication.d.ts.map +1 -0
  149. package/dist/plugin/publication.js +65 -0
  150. package/dist/plugin/publication.js.map +1 -0
  151. package/dist/plugin/validation.d.ts +15 -0
  152. package/dist/plugin/validation.d.ts.map +1 -0
  153. package/dist/plugin/validation.js +119 -0
  154. package/dist/plugin/validation.js.map +1 -0
  155. package/dist/release/archives.d.ts +33 -0
  156. package/dist/release/archives.d.ts.map +1 -0
  157. package/dist/release/archives.js +81 -0
  158. package/dist/release/archives.js.map +1 -0
  159. package/dist/release/release-manifest.d.ts +182 -0
  160. package/dist/release/release-manifest.d.ts.map +1 -0
  161. package/dist/release/release-manifest.js +79 -0
  162. package/dist/release/release-manifest.js.map +1 -0
  163. package/dist/release/releases.d.ts +36 -0
  164. package/dist/release/releases.d.ts.map +1 -0
  165. package/dist/release/releases.js +122 -0
  166. package/dist/release/releases.js.map +1 -0
  167. package/dist/skills.d.ts +35 -0
  168. package/dist/skills.d.ts.map +1 -0
  169. package/dist/skills.js +257 -0
  170. package/dist/skills.js.map +1 -0
  171. package/package.json +73 -4
  172. package/skills/dual-fde/SKILL.md +38 -0
  173. package/skills/dual-fde/references/access.md +62 -0
  174. package/skills/dual-fde/references/author-plugins.md +54 -0
  175. package/skills/dual-fde/references/cli.md +97 -0
  176. package/skills/dual-fde/references/manage-plugins.md +78 -0
  177. package/skills/dual-fde/references/migrations-deployment.md +84 -0
  178. package/skills/dual-fde/references/openapi-plugins.md +47 -0
  179. package/skills/dual-fde/references/sdk-docs.md +56 -0
  180. package/skills/dual-fde/references/upgrades.md +115 -0
  181. package/skills/dual-fde/references/working-context.md +69 -0
  182. package/src/auth/credentials.ts +84 -0
  183. package/src/auth/destination.ts +83 -0
  184. package/src/auth/http.ts +39 -0
  185. package/src/auth/login.ts +177 -0
  186. package/src/auth/protocol.ts +37 -0
  187. package/src/baseline.ts +15 -0
  188. package/src/bin.ts +4 -0
  189. package/src/cli.ts +969 -0
  190. package/src/create/choices.ts +177 -0
  191. package/src/create/deployment.ts +96 -0
  192. package/src/create/scaffold.ts +334 -0
  193. package/src/create/source-reference.ts +212 -0
  194. package/src/create/template.ts +300 -0
  195. package/src/diagnostics.ts +8 -0
  196. package/src/help.ts +142 -0
  197. package/src/openapi/bundle.ts +290 -0
  198. package/src/openapi/discovery.ts +438 -0
  199. package/src/openapi/emit.ts +1031 -0
  200. package/src/openapi/graphql.ts +375 -0
  201. package/src/openapi/identity.ts +153 -0
  202. package/src/openapi/mcp.ts +165 -0
  203. package/src/openapi/operations.ts +781 -0
  204. package/src/openapi/overlay.ts +195 -0
  205. package/src/openapi/plugin.ts +856 -0
  206. package/src/openapi/polymorphism.ts +207 -0
  207. package/src/openapi/postman.ts +403 -0
  208. package/src/openapi/schema.ts +2138 -0
  209. package/src/openapi/select.ts +113 -0
  210. package/src/openapi/spec.ts +401 -0
  211. package/src/openapi/swagger.ts +422 -0
  212. package/src/openapi/versions.ts +174 -0
  213. package/src/plugin/archive.ts +244 -0
  214. package/src/plugin/bundle.ts +572 -0
  215. package/src/plugin/init.ts +178 -0
  216. package/src/plugin/inspection.ts +19 -0
  217. package/src/plugin/package.ts +140 -0
  218. package/src/plugin/publication.ts +128 -0
  219. package/src/plugin/validation.ts +213 -0
  220. package/src/release/archives.ts +133 -0
  221. package/src/release/release-manifest.ts +79 -0
  222. package/src/release/releases.ts +210 -0
  223. package/src/skills.ts +434 -0
  224. package/templates/compose/.env.compose.example.hbs +3 -0
  225. package/templates/compose/.env.host.example.hbs +4 -0
  226. package/templates/compose/Dockerfile.hbs +12 -0
  227. package/templates/compose/OPERATIONS.md.hbs +159 -0
  228. package/templates/compose/_dockerignore +14 -0
  229. package/templates/compose/compose.external.yaml +7 -0
  230. package/templates/compose/compose.host-linux.yaml +5 -0
  231. package/templates/compose/compose.host.yaml.hbs +15 -0
  232. package/templates/compose/compose.yaml.hbs +85 -0
  233. package/templates/compose/release.env.hbs +2 -0
  234. package/templates/default/.env.example.hbs +79 -0
  235. package/templates/default/README.md.hbs +150 -0
  236. package/templates/default/_gitignore +11 -0
  237. package/templates/default/packages/customer-plugin/src/Customer.ts.hbs +17 -0
  238. package/templates/default/packages/customer-plugin/tsconfig.json +15 -0
  239. package/templates/default/packages/execution-layer/src/App.ts.hbs +7 -0
  240. package/templates/default/packages/execution-layer/src/Host.ts.hbs +31 -0
  241. package/templates/default/packages/execution-layer/src/Telemetry.ts.hbs +23 -0
  242. package/templates/default/packages/execution-layer/src/api.ts.hbs +21 -0
  243. package/templates/default/packages/execution-layer/src/bootstrap.ts +22 -0
  244. package/templates/default/packages/execution-layer/src/migrate.ts +11 -0
  245. package/templates/default/packages/execution-layer/src/registry-check.ts +29 -0
  246. package/templates/default/packages/execution-layer/src/registry-sync.ts +14 -0
  247. package/templates/default/packages/execution-layer/src/worker.ts.hbs +16 -0
  248. package/templates/default/packages/execution-layer/test/app.host-test.ts.hbs +58 -0
  249. package/templates/default/packages/execution-layer/test/app.test.ts.hbs +16 -0
  250. package/templates/default/tsconfig.json +5 -0
  251. package/templates/default/vitest.config.ts +5 -0
  252. package/templates/default/vitest.host.config.ts +6 -0
  253. package/templates/opensandbox/OPEN-SANDBOX.md +25 -0
  254. package/templates/opensandbox/docker/agent-sandbox.Dockerfile +41 -0
@@ -0,0 +1,212 @@
1
+ import { mkdir } from "node:fs/promises";
2
+ import { join, resolve } from "node:path";
3
+
4
+ import { Array, Context, Effect, Layer, Redacted, Schema, Stream, String } from "effect";
5
+
6
+ import { ChildProcess, ChildProcessSpawner } from "effect/process";
7
+
8
+ export const Record = Schema.Struct({
9
+ commit: Schema.Literal("1c8ad1122f14e798e3084fc3bc40cbf6e548ac3d"),
10
+ path: Schema.Literal("vendor/dual"),
11
+ url: Schema.Literal("git@git.datapizza.tech:dual/dual.git"),
12
+ });
13
+ export type Record = typeof Record.Type;
14
+ export const record: Record = {
15
+ commit: "1c8ad1122f14e798e3084fc3bc40cbf6e548ac3d",
16
+ path: "vendor/dual",
17
+ url: "git@git.datapizza.tech:dual/dual.git",
18
+ };
19
+
20
+ export const FdeDocsRecord = Schema.Struct({
21
+ commit: Schema.Literal("b7a1c2343758d77a55994ea1b7d5ac46f6547011"),
22
+ path: Schema.Literal("vendor/fdes-docs"),
23
+ url: Schema.Literal("git@git.datapizza.tech:dual/fdes-docs.git"),
24
+ });
25
+ export const fdeDocsRecord: typeof FdeDocsRecord.Type = {
26
+ commit: "b7a1c2343758d77a55994ea1b7d5ac46f6547011",
27
+ path: "vendor/fdes-docs",
28
+ url: "git@git.datapizza.tech:dual/fdes-docs.git",
29
+ };
30
+ const references = [record, fdeDocsRecord];
31
+ export const initCommand = `git submodule update --init -- ${Array.join(
32
+ Array.map(references, reference => reference.path),
33
+ " ",
34
+ )}`;
35
+
36
+ export const files = {
37
+ ".gitmodules": Array.join(
38
+ Array.map(
39
+ references,
40
+ reference =>
41
+ `[submodule "${String.slice("vendor/".length)(reference.path)}"]\n\tpath = ${reference.path}\n\turl = ${reference.url}\n\tupdate = checkout\n`,
42
+ ),
43
+ "",
44
+ ),
45
+ "AGENTS.md": `# Customer-owned Dual host\n\nBefore changing Dual host composition, plugins, or workflows, read\n[DUAL-SOURCE.md](DUAL-SOURCE.md), then consult the relevant source and docs in\n\`vendor/dual\`. If the checkout is absent, follow the explicit initialization\ninstructions there. Treat that checkout as read-only reference; use the installed\npublic \`@dual/*\` and \`@dual-os/*\` exports for application imports and verify APIs against the\ninstalled package versions. Keep changes in this customer's workspace.\n\nBefore scoping customer requirements, designing use cases, or planning delivery,\nread [FDE-DOCS.md](FDE-DOCS.md) for the read-only FDE guidance and access boundary.\n`,
46
+ "DUAL-SOURCE.md": `# Dual source reference\n
47
+ This repository registers a real Git submodule at \`${record.path}\`, pinned to
48
+ \`${record.commit}\` from \`${record.url}\`.
49
+
50
+ It is reference-only: never import it or use it as a runtime dependency or a
51
+ workspace dependency. Runtime packages come from the package registry; this
52
+ pinned source snapshot may differ from those packages.
53
+
54
+ Creation requires Git but does not fetch source or contact the network for this
55
+ reference, including during offline creation. Only .gitmodules and the pinned
56
+ gitlinks are staged; no commit is created and application files and secrets are
57
+ not staged. Commit them separately after reviewing what you want to publish.
58
+
59
+ To obtain the private source, explicitly run:
60
+
61
+ \`\`\`sh
62
+ git submodule update --init -- vendor/dual
63
+ \`\`\`
64
+
65
+ For the separate FDE guidance, read [FDE-DOCS.md](FDE-DOCS.md).
66
+ \`bun run source:init\` initializes both pinned references explicitly.
67
+
68
+ Supply Git/SSH credentials externally. No credentials are generated or stored by
69
+ the scaffold. There are no recursive automatic submodule updates: do not use
70
+ --recursive unless you deliberately want the source repository's own references.
71
+ `,
72
+ "FDE-DOCS.md": `# FDE documentation reference\n
73
+ This repository registers a read-only Git submodule at \`${fdeDocsRecord.path}\`,
74
+ pinned to \`${fdeDocsRecord.commit}\` from \`${fdeDocsRecord.url}\` (master).
75
+ The branch identifies the pin's origin; initialization checks out the committed
76
+ snapshot, not the latest branch tip.
77
+
78
+ For customer requirements, use-case design and delivery planning, start with
79
+ \`vendor/fdes-docs/README.md\` and \`vendor/fdes-docs/FOLDER_STRUCTURE.md\`, then
80
+ consult relevant guidance in \`vendor/fdes-docs/AGENTS.md\` and \`vendor/fdes-docs/dualos/\`.
81
+ Keep customer implementation and deliverables in this workspace. The upstream
82
+ instructions describe a separate writable engagement repository: do not adopt
83
+ its hook setup, workspace paths or write operations for this reference checkout.
84
+
85
+ The private repository includes other customers' material. Access to Dual does
86
+ not grant access to FDE docs or authorize reuse or disclosure of that material.
87
+ Consult only material authorized for the current engagement. Read-only is a
88
+ workspace policy, not a Git permission restriction.
89
+
90
+ Creation registers the gitlink without fetching or committing. To download only
91
+ this reference, configure external Git/SSH access to the FDE docs project and run:
92
+
93
+ \`\`\`sh
94
+ git submodule update --init -- vendor/fdes-docs
95
+ \`\`\`
96
+
97
+ \`bun run source:init\` explicitly downloads both references without recursion.
98
+ If access fails, request project access and check SSH/network configuration;
99
+ scaffolding and runtime packages do not depend on this checkout. Never import it
100
+ or add it as a runtime or workspace dependency. No credentials are stored by the
101
+ scaffold. See [DUAL-SOURCE.md](DUAL-SOURCE.md) for the product source reference.
102
+ `,
103
+ };
104
+
105
+ export class SourceReferenceError extends Schema.TaggedError<SourceReferenceError>()(
106
+ "SourceReferenceError",
107
+ { cause: Schema.Redacted(Schema.Defect()) },
108
+ ) {}
109
+ const failure = (cause: unknown) => new SourceReferenceError({ cause: Redacted.make(cause) });
110
+ const ObjectId = Schema.String.check(Schema.isPattern(/^[0-9a-f]{40}$/));
111
+
112
+ export type Interface = {
113
+ /** Register in a fresh, privately owned scaffold staging directory only. */
114
+ readonly register: (staging: string) => Effect.Effect<void, SourceReferenceError>;
115
+ };
116
+ export class Service extends Context.Service<Service, Interface>()(
117
+ "@dual-os/cli/SourceReference",
118
+ ) {}
119
+
120
+ export const layer = Layer.effect(
121
+ Service,
122
+ Effect.gen(function* () {
123
+ const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
124
+ const register = Effect.fn("SourceReference.register")(function* (staging: string) {
125
+ const cwd = resolve(staging);
126
+ // Exclusive creation refuses existing repositories and .git symlinks.
127
+ yield* Effect.tryPromise({
128
+ catch: failure,
129
+ try: async () => {
130
+ await mkdir(join(cwd, ".git"));
131
+ for (const reference of references) {
132
+ await mkdir(join(cwd, reference.path), { recursive: true });
133
+ }
134
+ },
135
+ }).pipe(Effect.uninterruptible);
136
+ const nullDevice = process.platform === "win32" ? "NUL" : "/dev/null";
137
+ // Replace, never extend, the inherited environment. In particular no GIT_*,
138
+ // HOME/XDG config, loader injection, shell startup, or credential variables.
139
+ // PATH selects the installed Git; SystemRoot is required by Windows.
140
+ const env = {
141
+ GIT_CONFIG_GLOBAL: nullDevice,
142
+ GIT_CONFIG_NOSYSTEM: "1",
143
+ GIT_CONFIG_SYSTEM: nullDevice,
144
+ GIT_TERMINAL_PROMPT: "0",
145
+ PATH: process.env["PATH"],
146
+ SystemRoot: process.platform === "win32" ? process.env["SystemRoot"] : undefined,
147
+ };
148
+ const run = Effect.fn("SourceReference.git")(
149
+ function* (args: readonly string[], capture = false) {
150
+ const handle = yield* spawner.spawn(
151
+ ChildProcess.make(
152
+ "git",
153
+ [
154
+ `--git-dir=${join(cwd, ".git")}`,
155
+ `--work-tree=${cwd}`,
156
+ "-c",
157
+ `core.hooksPath=${nullDevice}`,
158
+ "-c",
159
+ "core.fsmonitor=false",
160
+ "-c",
161
+ "submodule.recurse=false",
162
+ "-c",
163
+ "protocol.allow=never",
164
+ ...args,
165
+ ],
166
+ {
167
+ cwd,
168
+ env,
169
+ extendEnv: false,
170
+ stderr: "ignore",
171
+ stdin: "ignore",
172
+ stdout: capture ? "pipe" : "ignore",
173
+ },
174
+ ),
175
+ );
176
+ const output = capture ? yield* Stream.mkString(Stream.decodeText(handle.stdout)) : "";
177
+ const code = yield* handle.exitCode;
178
+ if (code !== 0) return yield* failure({ exitCode: code });
179
+ return output;
180
+ },
181
+ Effect.scoped,
182
+ Effect.mapError(cause => failure(cause)),
183
+ );
184
+ yield* run([
185
+ "-c",
186
+ "init.defaultBranch=main",
187
+ "init",
188
+ "--template=",
189
+ "--object-format=sha1",
190
+ cwd,
191
+ ]);
192
+ // Hash without filters and register only .gitmodules and fixed gitlinks. Never `add .`:
193
+ // user files, secrets, attributes, and external clean filters are excluded.
194
+ const output = yield* run(["hash-object", "-w", "--no-filters", "--", ".gitmodules"], true);
195
+ const objectId = yield* Schema.decodeUnknownEffect(ObjectId)(String.trim(output)).pipe(
196
+ Effect.mapError(cause => failure(cause)),
197
+ );
198
+ yield* run(["update-index", "--add", "--cacheinfo", `100644,${objectId},.gitmodules`]);
199
+ for (const reference of references) {
200
+ yield* run([
201
+ "update-index",
202
+ "--add",
203
+ "--cacheinfo",
204
+ `160000,${reference.commit},${reference.path}`,
205
+ ]);
206
+ }
207
+ });
208
+ return Service.of({ register });
209
+ }),
210
+ );
211
+
212
+ export * as SourceReference from "./source-reference.ts";
@@ -0,0 +1,300 @@
1
+ import { readdir, readFile } from "node:fs/promises";
2
+ import { isDeepStrictEqual } from "node:util";
3
+
4
+ import { Array, Boolean, Order, Record, Schema, String } from "effect";
5
+
6
+ import Handlebars from "handlebars";
7
+ import semver from "semver";
8
+
9
+ import { Baseline } from "../baseline.ts";
10
+ import { ReleaseManifest } from "../release/release-manifest.ts";
11
+
12
+ import { Choices } from "./choices.ts";
13
+ import { Deployment } from "./deployment.ts";
14
+ import { SourceReference } from "./source-reference.ts";
15
+
16
+ export const baseline = Baseline.versions;
17
+
18
+ // Conditional host artifact, deliberately not part of the just-bash baseline.
19
+ const workspacePackages = {
20
+ "just-bash": {},
21
+ opensandbox: { "@dual/workspace-opensandbox": "0.0.1" },
22
+ };
23
+ export const revision = "customer-bun-v13";
24
+ export const Replay = Schema.Struct({
25
+ bootstrapVersion: Schema.Null,
26
+ choices: Schema.Struct({ ...Choices.Host.fields, bare: Schema.Boolean }),
27
+ cliVersion: Schema.NonEmptyString,
28
+ deployment: Schema.NullOr(Deployment.ResolvedSelection),
29
+ fdeDocsReference: SourceReference.FdeDocsRecord,
30
+ packages: Schema.Record(Schema.String, Schema.String),
31
+ release: Schema.NullOr(ReleaseManifest.Selection),
32
+ schemaVersion: Schema.Literal(9),
33
+ sourceReference: SourceReference.Record,
34
+ template: Schema.Literal(revision),
35
+ }).check(
36
+ Schema.makeFilter(
37
+ record =>
38
+ JSON.stringify(
39
+ Array.sort(Record.toEntries(record.packages), (a, b) => String.Order(`${a}`, `${b}`)),
40
+ ) ===
41
+ JSON.stringify(
42
+ Array.sort(
43
+ record.release === null
44
+ ? [
45
+ ...Record.toEntries(baseline),
46
+ ...(record.choices.workspace === "opensandbox"
47
+ ? Record.toEntries(workspacePackages.opensandbox)
48
+ : []),
49
+ ]
50
+ : Object.entries(record.release.manifest.packages),
51
+ (a, b) => String.Order(`${a}`, `${b}`),
52
+ ),
53
+ ) &&
54
+ (record.release === null
55
+ ? record.deployment === null || Schema.is(Deployment.Selection)(record.deployment)
56
+ : record.release.manifest.compatibility.template === revision &&
57
+ semver.satisfies(record.cliVersion, record.release.manifest.compatibility.cli) &&
58
+ isDeepStrictEqual(record.deployment, {
59
+ pair: record.release.manifest.pair,
60
+ webImage: record.release.manifest.pair.webImage,
61
+ })) &&
62
+ Schema.is(Choices.Host)(record.choices),
63
+ ),
64
+ );
65
+ export type Replay = typeof Replay.Type;
66
+ export const record = (
67
+ versions: { readonly cli: string },
68
+ bare: boolean,
69
+ host: Choices.Host,
70
+ deployment: Deployment.ResolvedSelection | null = null,
71
+ release: ReleaseManifest.Selection | null = null,
72
+ ): Replay => ({
73
+ bootstrapVersion: null,
74
+ choices: { ...host, bare },
75
+ cliVersion: versions.cli,
76
+ deployment:
77
+ release === null
78
+ ? deployment
79
+ : { pair: release.manifest.pair, webImage: release.manifest.pair.webImage },
80
+ fdeDocsReference: SourceReference.fdeDocsRecord,
81
+ packages: release?.manifest.packages ?? { ...baseline, ...workspacePackages[host.workspace] },
82
+ release,
83
+ schemaVersion: 9,
84
+ sourceReference: SourceReference.record,
85
+ template: revision,
86
+ });
87
+ type JsonDocument = Readonly<Record<string, Schema.Json | undefined>>;
88
+ const json = (value: JsonDocument) => `${JSON.stringify(value, null, 2)}\n`;
89
+
90
+ interface RenderContext {
91
+ readonly bunImage: string;
92
+ readonly nameJson: string;
93
+ readonly appIdJson: string;
94
+ readonly pluginIdJson: string;
95
+ readonly pingIdJson: string;
96
+ readonly pluginPackageJson: string;
97
+ readonly pluginMetadataJson: string;
98
+ readonly apiServiceJson: string;
99
+ readonly workerServiceJson: string;
100
+ readonly httpPort: number;
101
+ readonly postgresPort: number;
102
+ readonly hostHttpPort: string;
103
+ readonly hostPostgresPort: string;
104
+ readonly s3: boolean;
105
+ readonly smtp: boolean;
106
+ readonly telemetryDisabled: boolean;
107
+ readonly compose: boolean;
108
+ readonly opensandbox: boolean;
109
+ readonly playground: boolean;
110
+ readonly siteAddress: string;
111
+ readonly apiPort: number;
112
+ readonly hostApiPort: string;
113
+ readonly appOrigin: string;
114
+ readonly apiOrigin: string;
115
+ readonly webImage: string;
116
+ readonly webPullPolicy: "never" | "missing";
117
+ }
118
+
119
+ // Keep assets beside both src/ and dist/. Only .hbs files are rendered; static
120
+ // files remain byte-for-byte copies. npm's special dotfile names use aliases.
121
+ const assets = async (
122
+ directory: URL,
123
+ context: RenderContext & { readonly envExample?: string },
124
+ prefix = "",
125
+ ): Promise<Record<string, string>> => {
126
+ const result: Record<string, string> = {};
127
+ const entries = await readdir(directory, { withFileTypes: true });
128
+ for (const entry of Array.sortWith(
129
+ entries,
130
+ entry => entry.name,
131
+ Order.make((a, b) => String.localeCompare(b)(a)),
132
+ )) {
133
+ const name =
134
+ entry.name === "_gitignore"
135
+ ? ".gitignore"
136
+ : entry.name === "_dockerignore"
137
+ ? ".dockerignore"
138
+ : String.endsWith(".hbs")(entry.name)
139
+ ? String.slice(0, -4)(entry.name)
140
+ : entry.name;
141
+ const path = `${prefix}${name}`;
142
+ if (entry.isDirectory()) {
143
+ Object.assign(
144
+ result,
145
+ await assets(new URL(`${encodeURIComponent(entry.name)}/`, directory), context, `${path}/`),
146
+ );
147
+ } else if (entry.isFile()) {
148
+ const source = await readFile(new URL(encodeURIComponent(entry.name), directory), "utf8");
149
+ // This is source/config, not HTML. Dynamic string literals are JSON-encoded
150
+ // in the context.
151
+ result[path] = String.endsWith(".hbs")(entry.name)
152
+ ? Handlebars.compile(source, { noEscape: true, strict: true })(context)
153
+ : source;
154
+ } else {
155
+ throw new Error("Starter assets must be regular files or directories");
156
+ }
157
+ }
158
+ return result;
159
+ };
160
+
161
+ /** No environment, registry credentials, paths or timestamps enter the template. */
162
+ export const files = async (input: Replay): Promise<Record<string, string>> => {
163
+ const replay = Schema.decodeUnknownSync(Replay, { onExcessProperty: "error" })(input);
164
+ const pins = replay.release?.manifest.packages ?? {
165
+ ...baseline,
166
+ ...workspacePackages.opensandbox,
167
+ };
168
+ const context: RenderContext = {
169
+ bunImage:
170
+ replay.release === null
171
+ ? "oven/bun@sha256:9114c058aeae42162ee16dd5084b95fe9473970bb6bcb5b232ab1630f0546895"
172
+ : `oven/bun:${String.slice(4)(replay.release.manifest.packageManager)}`,
173
+ nameJson: JSON.stringify(replay.choices.name),
174
+ appIdJson: JSON.stringify(replay.choices.appId),
175
+ pluginIdJson: JSON.stringify(replay.choices.pluginId),
176
+ pingIdJson: JSON.stringify(`${replay.choices.pluginId}/ping`),
177
+ pluginPackageJson: JSON.stringify(`${replay.choices.packageScope}/plugin`),
178
+ pluginMetadataJson: JSON.stringify(`${replay.choices.packageScope}/plugin/package.json`),
179
+ apiServiceJson: JSON.stringify(`${replay.choices.slug}-api`),
180
+ workerServiceJson: JSON.stringify(`${replay.choices.slug}-worker`),
181
+ httpPort: replay.choices.httpPort,
182
+ postgresPort: replay.choices.postgresPort,
183
+ hostHttpPort: `\${DUAL_HTTP_PORT:-${replay.choices.httpPort}}`,
184
+ hostPostgresPort: `\${DUAL_POSTGRES_PORT:-${replay.choices.postgresPort}}`,
185
+ s3: replay.choices.fileStorage === "s3",
186
+ smtp: replay.choices.email === "smtp",
187
+ telemetryDisabled: replay.choices.telemetry === "disabled",
188
+ compose: replay.deployment !== null,
189
+ opensandbox: replay.choices.workspace === "opensandbox",
190
+ playground: replay.choices.preset === "playground",
191
+ siteAddress:
192
+ replay.choices.hostname === "localhost" ? ":80" : `http://${replay.choices.hostname}:80`,
193
+ apiPort: replay.choices.apiPort,
194
+ hostApiPort: `\${DUAL_API_PORT:-${replay.choices.apiPort}}`,
195
+ appOrigin: `http://${replay.choices.hostname}:${replay.choices.httpPort}`,
196
+ apiOrigin: `http://${replay.choices.hostname}:${replay.deployment === null ? replay.choices.apiPort : replay.choices.httpPort}`,
197
+ webImage: replay.deployment?.webImage ?? "",
198
+ webPullPolicy: Boolean.match(String.startsWith("sha256:")(replay.deployment?.webImage ?? ""), {
199
+ onFalse: () => "missing" as const,
200
+ onTrue: () => "never" as const,
201
+ }),
202
+ };
203
+ const content = await assets(new URL("../../templates/default/", import.meta.url), context);
204
+ Object.assign(
205
+ content,
206
+ await assets(new URL("../../skills/", import.meta.url), context, ".agents/skills/"),
207
+ );
208
+ const envExample = content[".env.example"];
209
+ if (envExample === undefined) {
210
+ throw new Error("Missing environment template");
211
+ }
212
+ content[".env.host.example"] = envExample;
213
+ if (context.opensandbox) {
214
+ Object.assign(
215
+ content,
216
+ await assets(new URL("../../templates/opensandbox/", import.meta.url), context),
217
+ );
218
+ }
219
+ if (replay.deployment !== null) {
220
+ Object.assign(
221
+ content,
222
+ await assets(new URL("../../templates/compose/", import.meta.url), {
223
+ ...context,
224
+ envExample,
225
+ }),
226
+ );
227
+ content["dual.release.json"] = json(replay.release ?? replay.deployment.pair);
228
+ }
229
+ return {
230
+ ...content,
231
+ "dual.scaffold.json": json(replay),
232
+ "package.json": json({
233
+ devDependencies: {
234
+ "@deslop/coding-standards": pins["@deslop/coding-standards"],
235
+ "@effect/vitest": pins["@effect/vitest"],
236
+ "bun-types": pins["bun-types"],
237
+ // Bind the root test tool's peer to the same Effect as the host workspaces.
238
+ effect: pins.effect,
239
+ typescript: pins.typescript,
240
+ vitest: pins.vitest,
241
+ },
242
+ name: replay.choices.packageName,
243
+ // The adapter's caret dependency must not introduce a different Effect release family.
244
+ overrides: { "@effect/platform-node-shared": pins["@effect/platform-node"] },
245
+ packageManager: replay.release?.manifest.packageManager ?? "bun@1.4.2",
246
+ private: true,
247
+ scripts: {
248
+ api: "bun --env-file=.env packages/execution-layer/src/api.ts",
249
+ "api:local": "bun --env-file=.env.host packages/execution-layer/src/api.ts",
250
+ bootstrap: "bun --env-file=.env packages/execution-layer/src/bootstrap.ts",
251
+ "check-types": "tsc --noEmit",
252
+ "dev:api": "bun --watch --env-file=.env.host packages/execution-layer/src/api.ts",
253
+ "dev:worker": "bun --watch --env-file=.env.host packages/execution-layer/src/worker.ts",
254
+ migrate: "bun --env-file=.env packages/execution-layer/src/migrate.ts",
255
+ "registry:check": "bun --env-file=.env packages/execution-layer/src/registry-check.ts",
256
+ "registry:sync": "bun --env-file=.env packages/execution-layer/src/registry-sync.ts",
257
+ "source:init": SourceReference.initCommand,
258
+ test: "vitest run",
259
+ "test:host": "vitest run --config vitest.host.config.ts",
260
+ worker: "bun --env-file=.env packages/execution-layer/src/worker.ts",
261
+ "worker:local": "bun --env-file=.env.host packages/execution-layer/src/worker.ts",
262
+ },
263
+ type: "module",
264
+ version: "0.0.0",
265
+ workspaces: ["packages/*"],
266
+ }),
267
+ "packages/customer-plugin/package.json": json({
268
+ dependencies: { "@dual-os/sdk": pins["@dual-os/sdk"], effect: pins.effect },
269
+ devDependencies: { typescript: pins.typescript },
270
+ // `dual plugin push` builds dist/ and uploads it; the workspace tests import the source.
271
+ dual: { plugin: { entrypoint: "dist/Customer.js", export: "customerPlugin" } },
272
+ exports: { ".": "./src/Customer.ts", "./package.json": "./package.json" },
273
+ name: `${replay.choices.packageScope}/plugin`,
274
+ private: true,
275
+ scripts: { build: "tsc -p tsconfig.json" },
276
+ type: "module",
277
+ version: "0.0.0",
278
+ }),
279
+ "packages/execution-layer/package.json": json({
280
+ dependencies: {
281
+ [`${replay.choices.packageScope}/plugin`]: "workspace:*",
282
+ ...(replay.choices.workspace === "opensandbox"
283
+ ? { "@dual/workspace-opensandbox": pins["@dual/workspace-opensandbox"] }
284
+ : {}),
285
+ "@dual/core": pins["@dual/core"],
286
+ "@dual-os/sdk": pins["@dual-os/sdk"],
287
+ "@dual/dualspec": pins["@dual/dualspec"],
288
+ effect: pins.effect,
289
+ "@effect/platform-node": pins["@effect/platform-node"],
290
+ },
291
+ name: `${replay.choices.packageScope}/execution-layer`,
292
+ private: true,
293
+ scripts: { "check-types": "tsc --noEmit -p ../../tsconfig.json" },
294
+ type: "module",
295
+ version: "0.0.0",
296
+ }),
297
+ };
298
+ };
299
+
300
+ export * as Template from "./template.ts";
@@ -0,0 +1,8 @@
1
+ import { Formatter, Inspectable, Predicate } from "effect";
2
+
3
+ export function format(value: unknown) {
4
+ if (Predicate.isString(value)) return value;
5
+ return Formatter.format(Inspectable.toJson(value), { ignoreToString: true, space: 2 });
6
+ }
7
+
8
+ export * as Diagnostics from "./diagnostics.ts";
package/src/help.ts ADDED
@@ -0,0 +1,142 @@
1
+ import { Array, Option, Predicate, String } from "effect";
2
+
3
+ import { CliOutput, type HelpDoc } from "effect/cli";
4
+
5
+ type Row = { readonly label: string; readonly description: string };
6
+
7
+ // Wrap prose, never split tokens (flags, paths and example commands stay copyable).
8
+ const wrap = (text: string, width: number): string[] =>
9
+ Array.flatMap(String.split("\n")(text), paragraph => {
10
+ const wrapped = Array.reduce(
11
+ Array.filter(String.split(/\s+/)(paragraph), String.isNonEmpty),
12
+ { line: "", lines: Array.empty<string>() },
13
+ (state, word) =>
14
+ state.line && state.line.length + word.length + 1 > width
15
+ ? { line: word, lines: Array.append(state.lines, state.line) }
16
+ : { ...state, line: state.line ? `${state.line} ${word}` : word },
17
+ );
18
+ return Array.append(wrapped.lines, wrapped.line);
19
+ });
20
+
21
+ const flagRow = (flag: HelpDoc.FlagDoc): Row => {
22
+ const description = Option.getOrElse(flag.description, () => "");
23
+ // Effect already lists choice values in the description, including built-ins.
24
+ // Keep those values out of the label so log-level cannot widen every row.
25
+ const type =
26
+ String.startsWith("<")(flag.type) && String.includes("(choices:")(description)
27
+ ? "<value>"
28
+ : String.startsWith("<")(flag.type)
29
+ ? flag.type
30
+ : `<${flag.type}>`;
31
+ return {
32
+ description,
33
+ label:
34
+ Array.join([`--${flag.name}`, ...flag.aliases], ", ") +
35
+ (flag.type === "boolean" ? "" : ` ${type}`),
36
+ };
37
+ };
38
+
39
+ /** ANSI headings only on an interactive terminal, honouring NO_COLOR and TERM=dumb. */
40
+ export const colors = (
41
+ stdout: { readonly isTTY?: boolean },
42
+ env: Readonly<Record<string, string | undefined>>,
43
+ ): boolean => stdout.isTTY === true && (env["NO_COLOR"] ?? "") === "" && env["TERM"] !== "dumb";
44
+
45
+ /** Presentation only: Effect still owns help generation, parsing and exit behavior. */
46
+ export const formatter = (options: {
47
+ readonly columns: number;
48
+ readonly colors: boolean;
49
+ }): CliOutput.Formatter => {
50
+ const width = Math.max(20, Math.min(100, options.columns));
51
+ const heading = (text: string) => (options.colors ? `\u001b[1m${text}\u001b[0m` : text);
52
+ const prose = (text: string, indent = 0) =>
53
+ Array.join(
54
+ Array.map(wrap(text, width - indent), line => String.repeat(indent)(" ") + line),
55
+ "\n",
56
+ );
57
+ const table = (rows: readonly Row[]) => {
58
+ const column = Math.min(28, Math.max(0, ...Array.map(rows, row => row.label.length)));
59
+ return Array.join(
60
+ Array.map(rows, ({ label, description }) => {
61
+ if (!description) return ` ${label}`;
62
+ if (width < 72 || label.length > column) {
63
+ return ` ${label}\n${prose(description, 4)}`;
64
+ }
65
+ const lines = wrap(description, width - column - 4);
66
+ return Array.join(
67
+ Array.map(lines, (line, index) =>
68
+ index === 0
69
+ ? ` ${String.padEnd(column)(label)} ${line}`
70
+ : `${String.repeat(column + 4)(" ")}${line}`,
71
+ ),
72
+ "\n",
73
+ );
74
+ }),
75
+ "\n",
76
+ );
77
+ };
78
+
79
+ return {
80
+ ...CliOutput.defaultFormatter({ colors: options.colors }),
81
+ formatHelpDoc: doc => {
82
+ const section = (title: string, rows: readonly Row[]) =>
83
+ Array.isReadonlyArrayNonEmpty(rows) ? [`${heading(title)}\n${table(rows)}`] : [];
84
+ const sections = [
85
+ prose(`Usage: ${doc.usage}`),
86
+ ...(doc.description ? [prose(doc.description)] : []),
87
+ ...Array.flatMap(doc.subcommands ?? [], group =>
88
+ section(
89
+ group.group ?? "Commands",
90
+ Array.map(group.commands, command => ({
91
+ description: command.shortDescription ?? command.description,
92
+ label: Array.join(
93
+ Array.filter(
94
+ Array.filter([command.name, command.alias], Predicate.isNotUndefined),
95
+ String.isNonEmpty,
96
+ ),
97
+ ", ",
98
+ ),
99
+ })),
100
+ ),
101
+ ),
102
+ ...section(
103
+ "Arguments",
104
+ Array.map(doc.args ?? [], arg => ({
105
+ description: Array.join(
106
+ Array.filter(
107
+ [Option.getOrElse(arg.description, () => ""), arg.required ? "" : "(optional)"],
108
+ Boolean,
109
+ ),
110
+ " ",
111
+ ),
112
+ label: `${arg.name}${arg.variadic ? "..." : ""} <${arg.type}>`,
113
+ })),
114
+ ),
115
+ ...section("Options", Array.map(doc.flags, flagRow)),
116
+ ...(doc.examples?.length
117
+ ? [
118
+ `${heading("Examples")}\n${Array.join(
119
+ Array.map(doc.examples, example =>
120
+ Array.join(
121
+ [
122
+ ...(example.description
123
+ ? Array.map(wrap(example.description, width - 4), line => ` # ${line}`)
124
+ : []),
125
+ // Keep the authored shell command intact even on narrow terminals.
126
+ ` ${example.command}`,
127
+ ],
128
+ "\n",
129
+ ),
130
+ ),
131
+ "\n",
132
+ )}`,
133
+ ]
134
+ : []),
135
+ ...section("Global options", Array.map(doc.globalFlags ?? [], flagRow)),
136
+ ];
137
+ return Array.join(sections, "\n\n");
138
+ },
139
+ };
140
+ };
141
+
142
+ export * as Help from "./help.ts";