@orthograph/prove 0.0.0-stage → 0.1.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +2 -2
  3. package/dist/index.d.ts +32 -0
  4. package/dist/index.js +32 -0
  5. package/dist/modules/build/internal/manifest.d.ts +15 -0
  6. package/dist/modules/build/internal/manifest.js +38 -0
  7. package/dist/modules/build/service.d.ts +2 -0
  8. package/dist/modules/build/service.js +74 -0
  9. package/dist/modules/build/types.d.ts +39 -0
  10. package/dist/modules/build/types.js +4 -0
  11. package/dist/modules/environments/internal/collector.d.ts +2 -0
  12. package/dist/modules/environments/internal/collector.js +5 -0
  13. package/dist/modules/environments/internal/config.d.ts +32 -0
  14. package/dist/modules/environments/internal/config.js +42 -0
  15. package/dist/modules/environments/internal/identity.d.ts +3 -0
  16. package/dist/modules/environments/internal/identity.js +17 -0
  17. package/dist/modules/environments/internal/logbook.d.ts +10 -0
  18. package/dist/modules/environments/internal/logbook.js +23 -0
  19. package/dist/modules/environments/internal/process.d.ts +41 -0
  20. package/dist/modules/environments/internal/process.js +103 -0
  21. package/dist/modules/environments/internal/secrets.d.ts +9 -0
  22. package/dist/modules/environments/internal/secrets.js +23 -0
  23. package/dist/modules/environments/internal/status.d.ts +7 -0
  24. package/dist/modules/environments/internal/status.js +31 -0
  25. package/dist/modules/environments/service.d.ts +2 -0
  26. package/dist/modules/environments/service.js +97 -0
  27. package/dist/modules/environments/types.d.ts +80 -0
  28. package/dist/modules/environments/types.js +4 -0
  29. package/dist/modules/evals/internal/calls.d.ts +19 -0
  30. package/dist/modules/evals/internal/calls.js +168 -0
  31. package/dist/modules/evals/internal/evidence.d.ts +13 -0
  32. package/dist/modules/evals/internal/evidence.js +29 -0
  33. package/dist/modules/evals/internal/run.d.ts +12 -0
  34. package/dist/modules/evals/internal/run.js +85 -0
  35. package/dist/modules/evals/internal/secrets.d.ts +5 -0
  36. package/dist/modules/evals/internal/secrets.js +72 -0
  37. package/dist/modules/evals/service.d.ts +2 -0
  38. package/dist/modules/evals/service.js +29 -0
  39. package/dist/modules/evals/testing.d.ts +12 -0
  40. package/dist/modules/evals/testing.js +15 -0
  41. package/dist/modules/evals/types.d.ts +43 -0
  42. package/dist/modules/evals/types.js +1 -0
  43. package/dist/modules/impact/internal/changed.d.ts +6 -0
  44. package/dist/modules/impact/internal/changed.js +34 -0
  45. package/dist/modules/impact/internal/closure.d.ts +12 -0
  46. package/dist/modules/impact/internal/closure.js +69 -0
  47. package/dist/modules/impact/internal/digest.d.ts +1 -0
  48. package/dist/modules/impact/internal/digest.js +2 -0
  49. package/dist/modules/impact/internal/files.d.ts +11 -0
  50. package/dist/modules/impact/internal/files.js +48 -0
  51. package/dist/modules/impact/internal/ledger.d.ts +5 -0
  52. package/dist/modules/impact/internal/ledger.js +25 -0
  53. package/dist/modules/impact/internal/linked.d.ts +4 -0
  54. package/dist/modules/impact/internal/linked.js +56 -0
  55. package/dist/modules/impact/internal/scan.d.ts +12 -0
  56. package/dist/modules/impact/internal/scan.js +66 -0
  57. package/dist/modules/impact/service.d.ts +2 -0
  58. package/dist/modules/impact/service.js +88 -0
  59. package/dist/modules/impact/types.d.ts +109 -0
  60. package/dist/modules/impact/types.js +1 -0
  61. package/dist/modules/journeys/internal/checks.d.ts +25 -0
  62. package/dist/modules/journeys/internal/checks.js +155 -0
  63. package/dist/modules/journeys/internal/d1-facts.d.ts +10 -0
  64. package/dist/modules/journeys/internal/d1-facts.js +53 -0
  65. package/dist/modules/journeys/internal/database-facts.d.ts +2 -0
  66. package/dist/modules/journeys/internal/database-facts.js +41 -0
  67. package/dist/modules/journeys/internal/device.d.ts +16 -0
  68. package/dist/modules/journeys/internal/device.js +68 -0
  69. package/dist/modules/journeys/internal/keepers.d.ts +6 -0
  70. package/dist/modules/journeys/internal/keepers.js +6 -0
  71. package/dist/modules/journeys/internal/load.d.ts +4 -0
  72. package/dist/modules/journeys/internal/load.js +94 -0
  73. package/dist/modules/journeys/internal/stand-call.d.ts +10 -0
  74. package/dist/modules/journeys/internal/stand-call.js +22 -0
  75. package/dist/modules/journeys/internal/subject.d.ts +8 -0
  76. package/dist/modules/journeys/internal/subject.js +15 -0
  77. package/dist/modules/journeys/internal/world.d.ts +70 -0
  78. package/dist/modules/journeys/internal/world.js +133 -0
  79. package/dist/modules/journeys/service.d.ts +2 -0
  80. package/dist/modules/journeys/service.js +231 -0
  81. package/dist/modules/journeys/types.d.ts +132 -0
  82. package/dist/modules/journeys/types.js +5 -0
  83. package/dist/modules/portal-feed/internal/listen.d.ts +10 -0
  84. package/dist/modules/portal-feed/internal/listen.js +32 -0
  85. package/dist/modules/portal-feed/service.d.ts +2 -0
  86. package/dist/modules/portal-feed/service.js +6 -0
  87. package/dist/modules/portal-feed/types.d.ts +30 -0
  88. package/dist/modules/portal-feed/types.js +5 -0
  89. package/dist/modules/promote/internal/environment.d.ts +6 -0
  90. package/dist/modules/promote/internal/environment.js +10 -0
  91. package/dist/modules/promote/internal/gate.d.ts +9 -0
  92. package/dist/modules/promote/internal/gate.js +37 -0
  93. package/dist/modules/promote/internal/publishing.d.ts +23 -0
  94. package/dist/modules/promote/internal/publishing.js +21 -0
  95. package/dist/modules/promote/service.d.ts +2 -0
  96. package/dist/modules/promote/service.js +112 -0
  97. package/dist/modules/promote/types.d.ts +54 -0
  98. package/dist/modules/promote/types.js +8 -0
  99. package/dist/modules/prove/internal/changed-run.d.ts +9 -0
  100. package/dist/modules/prove/internal/changed-run.js +14 -0
  101. package/dist/modules/prove/internal/device-host.d.ts +16 -0
  102. package/dist/modules/prove/internal/device-host.js +60 -0
  103. package/dist/modules/prove/internal/empty-world.d.ts +5 -0
  104. package/dist/modules/prove/internal/empty-world.js +26 -0
  105. package/dist/modules/prove/internal/exercise.d.ts +35 -0
  106. package/dist/modules/prove/internal/exercise.js +47 -0
  107. package/dist/modules/prove/internal/proof-verdicts.d.ts +5 -0
  108. package/dist/modules/prove/internal/proof-verdicts.js +37 -0
  109. package/dist/modules/prove/internal/report.d.ts +35 -0
  110. package/dist/modules/prove/internal/report.js +169 -0
  111. package/dist/modules/prove/internal/staged.d.ts +9 -0
  112. package/dist/modules/prove/internal/staged.js +30 -0
  113. package/dist/modules/prove/internal/stand.d.ts +40 -0
  114. package/dist/modules/prove/internal/stand.js +155 -0
  115. package/dist/modules/prove/internal/structured.d.ts +78 -0
  116. package/dist/modules/prove/internal/structured.js +55 -0
  117. package/dist/modules/prove/internal/test-run.d.ts +7 -0
  118. package/dist/modules/prove/internal/test-run.js +63 -0
  119. package/dist/modules/prove/service.d.ts +2 -0
  120. package/dist/modules/prove/service.js +98 -0
  121. package/dist/modules/prove/types.d.ts +120 -0
  122. package/dist/modules/prove/types.js +5 -0
  123. package/dist/modules/publish/internal/bundle.d.ts +24 -0
  124. package/dist/modules/publish/internal/bundle.js +46 -0
  125. package/dist/modules/publish/internal/env.d.ts +3 -0
  126. package/dist/modules/publish/internal/env.js +2 -0
  127. package/dist/modules/publish/internal/plan.d.ts +28 -0
  128. package/dist/modules/publish/internal/plan.js +28 -0
  129. package/dist/modules/publish/internal/registry.d.ts +24 -0
  130. package/dist/modules/publish/internal/registry.js +55 -0
  131. package/dist/modules/publish/internal/sea.d.ts +20 -0
  132. package/dist/modules/publish/internal/sea.js +77 -0
  133. package/dist/modules/publish/internal/source.d.ts +4 -0
  134. package/dist/modules/publish/internal/source.js +41 -0
  135. package/dist/modules/publish/internal/stage.d.ts +14 -0
  136. package/dist/modules/publish/internal/stage.js +95 -0
  137. package/dist/modules/publish/internal/tap.d.ts +22 -0
  138. package/dist/modules/publish/internal/tap.js +61 -0
  139. package/dist/modules/publish/service.d.ts +2 -0
  140. package/dist/modules/publish/service.js +99 -0
  141. package/dist/modules/publish/types.d.ts +80 -0
  142. package/dist/modules/publish/types.js +4 -0
  143. package/dist/modules/releases/internal/http.d.ts +12 -0
  144. package/dist/modules/releases/internal/http.js +14 -0
  145. package/dist/modules/releases/internal/stale.d.ts +13 -0
  146. package/dist/modules/releases/internal/stale.js +43 -0
  147. package/dist/modules/releases/service.d.ts +2 -0
  148. package/dist/modules/releases/service.js +59 -0
  149. package/dist/modules/releases/types.d.ts +81 -0
  150. package/dist/modules/releases/types.js +6 -0
  151. package/dist/modules/secrets/internal/file.d.ts +5 -0
  152. package/dist/modules/secrets/internal/file.js +25 -0
  153. package/dist/modules/secrets/service.d.ts +2 -0
  154. package/dist/modules/secrets/service.js +38 -0
  155. package/dist/modules/secrets/types.d.ts +44 -0
  156. package/dist/modules/secrets/types.js +7 -0
  157. package/dist/modules/server-config/internal/jsonc.d.ts +2 -0
  158. package/dist/modules/server-config/internal/jsonc.js +29 -0
  159. package/dist/modules/server-config/service.d.ts +2 -0
  160. package/dist/modules/server-config/service.js +21 -0
  161. package/dist/modules/server-config/types.d.ts +22 -0
  162. package/dist/modules/server-config/types.js +3 -0
  163. package/dist/modules/sinks/internal/axiom.d.ts +29 -0
  164. package/dist/modules/sinks/internal/axiom.js +25 -0
  165. package/dist/modules/sinks/internal/keychain.d.ts +2 -0
  166. package/dist/modules/sinks/internal/keychain.js +13 -0
  167. package/dist/modules/sinks/service.d.ts +2 -0
  168. package/dist/modules/sinks/service.js +26 -0
  169. package/dist/modules/sinks/types.d.ts +37 -0
  170. package/dist/modules/sinks/types.js +5 -0
  171. package/dist/modules/telemetry/internal/axiom-source.d.ts +2 -0
  172. package/dist/modules/telemetry/internal/axiom-source.js +108 -0
  173. package/dist/modules/telemetry/internal/binary.d.ts +11 -0
  174. package/dist/modules/telemetry/internal/binary.js +66 -0
  175. package/dist/modules/telemetry/internal/config.d.ts +13 -0
  176. package/dist/modules/telemetry/internal/config.js +22 -0
  177. package/dist/modules/telemetry/internal/file-metrics.d.ts +2 -0
  178. package/dist/modules/telemetry/internal/file-metrics.js +60 -0
  179. package/dist/modules/telemetry/internal/file-source.d.ts +2 -0
  180. package/dist/modules/telemetry/internal/file-source.js +38 -0
  181. package/dist/modules/telemetry/internal/journey-root.d.ts +44 -0
  182. package/dist/modules/telemetry/internal/journey-root.js +36 -0
  183. package/dist/modules/telemetry/internal/local.d.ts +11 -0
  184. package/dist/modules/telemetry/internal/local.js +57 -0
  185. package/dist/modules/telemetry/internal/otlp.d.ts +15 -0
  186. package/dist/modules/telemetry/internal/otlp.js +53 -0
  187. package/dist/modules/telemetry/internal/private-keys.d.ts +7 -0
  188. package/dist/modules/telemetry/internal/private-keys.js +28 -0
  189. package/dist/modules/telemetry/internal/process.d.ts +27 -0
  190. package/dist/modules/telemetry/internal/process.js +96 -0
  191. package/dist/modules/telemetry/internal/runs.d.ts +17 -0
  192. package/dist/modules/telemetry/internal/runs.js +48 -0
  193. package/dist/modules/telemetry/service.d.ts +9 -0
  194. package/dist/modules/telemetry/service.js +48 -0
  195. package/dist/modules/telemetry/types.d.ts +138 -0
  196. package/dist/modules/telemetry/types.js +13 -0
  197. package/dist/modules/test-worlds/internal/lifetime.d.ts +3 -0
  198. package/dist/modules/test-worlds/internal/lifetime.js +19 -0
  199. package/dist/modules/test-worlds/service.d.ts +2 -0
  200. package/dist/modules/test-worlds/service.js +35 -0
  201. package/dist/modules/test-worlds/types.d.ts +41 -0
  202. package/dist/modules/test-worlds/types.js +4 -0
  203. package/dist/modules/trace-trees/service.d.ts +2 -0
  204. package/dist/modules/trace-trees/service.js +40 -0
  205. package/dist/modules/trace-trees/types.d.ts +9 -0
  206. package/dist/modules/trace-trees/types.js +1 -0
  207. package/dist/modules/verdicts/internal/proof.d.ts +24 -0
  208. package/dist/modules/verdicts/internal/proof.js +59 -0
  209. package/dist/modules/verdicts/service.d.ts +16 -0
  210. package/dist/modules/verdicts/service.js +71 -0
  211. package/dist/modules/verdicts/types.d.ts +80 -0
  212. package/dist/modules/verdicts/types.js +4 -0
  213. package/dist/modules/warm/internal/source.d.ts +7 -0
  214. package/dist/modules/warm/internal/source.js +27 -0
  215. package/dist/modules/warm/service.d.ts +2 -0
  216. package/dist/modules/warm/service.js +76 -0
  217. package/dist/modules/warm/types.d.ts +43 -0
  218. package/dist/modules/warm/types.js +4 -0
  219. package/dist/modules/watch/internal/choose.d.ts +20 -0
  220. package/dist/modules/watch/internal/choose.js +24 -0
  221. package/dist/modules/watch/internal/evidence.d.ts +9 -0
  222. package/dist/modules/watch/internal/evidence.js +26 -0
  223. package/dist/modules/watch/internal/report.d.ts +18 -0
  224. package/dist/modules/watch/internal/report.js +59 -0
  225. package/dist/modules/watch/internal/tasks.d.ts +5 -0
  226. package/dist/modules/watch/internal/tasks.js +35 -0
  227. package/dist/modules/watch/service.d.ts +2 -0
  228. package/dist/modules/watch/service.js +38 -0
  229. package/dist/modules/watch/types.d.ts +44 -0
  230. package/dist/modules/watch/types.js +4 -0
  231. package/dist/modules/world/internal/ports.d.ts +8 -0
  232. package/dist/modules/world/internal/ports.js +30 -0
  233. package/dist/modules/world/internal/wrangler.d.ts +46 -0
  234. package/dist/modules/world/internal/wrangler.js +112 -0
  235. package/dist/modules/world/service.d.ts +2 -0
  236. package/dist/modules/world/service.js +46 -0
  237. package/dist/modules/world/types.d.ts +97 -0
  238. package/dist/modules/world/types.js +4 -0
  239. package/dist/modules/world-clock/internal/door.d.ts +8 -0
  240. package/dist/modules/world-clock/internal/door.js +9 -0
  241. package/dist/modules/world-clock/service.d.ts +2 -0
  242. package/dist/modules/world-clock/service.js +9 -0
  243. package/dist/modules/world-clock/types.d.ts +34 -0
  244. package/dist/modules/world-clock/types.js +1 -0
  245. package/package.json +38 -3
@@ -0,0 +1,95 @@
1
+ // An npm package built from the generated code: one bundled file, its dependencies as the project has them installed, and for the
2
+ // SDK its type declarations. What `npm pack --dry-run` lists is what `npm publish` sends.
3
+ import { spawnSync } from "node:child_process";
4
+ import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
5
+ import { dirname, join, resolve } from "node:path";
6
+ import { Effect, Schema } from "effect";
7
+ import { PublishFailed } from "../types.js";
8
+ import { bundle, installedVersion } from "./bundle.js";
9
+ import { cleanEnv } from "./env.js";
10
+ /** `node_modules/.bin/<name>` in the project or the nearest folder above it that has one. */
11
+ export const binOf = (root, name) => {
12
+ for (let at = resolve(root);; at = dirname(at)) {
13
+ const bin = join(at, "node_modules/.bin", name);
14
+ if (existsSync(bin))
15
+ return bin;
16
+ if (dirname(at) === at)
17
+ return undefined;
18
+ }
19
+ };
20
+ const filesUnder = (dir) => readdirSync(dir, { withFileTypes: true }).flatMap((d) => (d.isDirectory() ? filesUnder(join(dir, d.name)) : [join(dir, d.name)]));
21
+ /** tsc writes `.ts` specifiers into declarations as they stand in the source; a consumer's compiler wants the `.js` ones. */
22
+ const rewriteSpecifiers = (dir) => {
23
+ for (const file of filesUnder(dir).filter((f) => f.endsWith(".d.ts"))) {
24
+ const text = readFileSync(file, "utf8");
25
+ const fixed = text.replace(/(["'])(\.\.?\/[^"']*)\.ts\1/g, "$1$2.js$1");
26
+ if (fixed !== text)
27
+ writeFileSync(file, fixed);
28
+ }
29
+ };
30
+ /** The SDK's declarations: the project's own tsc over the generated SDK and what it imports, declarations only. */
31
+ const declarations = (root, dir) => Effect.try({
32
+ try: () => {
33
+ const tsc = binOf(root, "tsc");
34
+ if (tsc === undefined)
35
+ throw new Error("no tsc in node_modules/.bin to write the SDK's type declarations with");
36
+ const types = join(dir, "types");
37
+ const config = join(dir, "tsconfig.types.json");
38
+ writeFileSync(config, JSON.stringify({
39
+ extends: join(resolve(root), "tsconfig.json"),
40
+ include: [],
41
+ files: [join(resolve(root), "generated/sdk/src/index.ts")],
42
+ compilerOptions: { noEmit: false, emitDeclarationOnly: true, declaration: true, rewriteRelativeImportExtensions: true, allowImportingTsExtensions: false, outDir: types, rootDir: resolve(root) },
43
+ }));
44
+ const run = spawnSync(tsc, ["-p", config, "--pretty", "false"], { cwd: resolve(root), encoding: "utf8" });
45
+ rmSync(config);
46
+ if (run.status !== 0)
47
+ throw new Error(`tsc couldn't write the SDK's declarations:\n${(run.stdout + run.stderr).trim().split("\n").slice(0, 6).join("\n")}`);
48
+ rewriteSpecifiers(types);
49
+ return "types/generated/sdk/src/index.d.ts";
50
+ },
51
+ catch: (e) => new PublishFailed({ message: String(e.message ?? e) }),
52
+ });
53
+ /** What `npm pack --dry-run` says the package holds: the files and their sizes, exactly as `npm publish` would send them. */
54
+ const packFailure = (e) => new PublishFailed({ message: String(e) });
55
+ const listing = (dir, env) => Effect.gen(function* () {
56
+ const run = yield* Effect.try({ try: () => spawnSync("npm", ["pack", "--dry-run", "--json", "--ignore-scripts"], { cwd: dir, encoding: "utf8", env: cleanEnv(env) }), catch: packFailure });
57
+ if (run.status !== 0)
58
+ return yield* new PublishFailed({ message: `npm pack failed: ${run.stderr?.trim().split("\n")[0] ?? run.error?.message ?? "unknown failure"}` });
59
+ const raw = yield* Effect.try({ try: () => JSON.parse(run.stdout), catch: packFailure });
60
+ const packs = yield* Schema.decodeUnknownEffect(Schema.Array(Schema.Struct({ integrity: Schema.String, files: Schema.Array(Schema.Struct({ path: Schema.String, size: Schema.Number })) })))(raw).pipe(Effect.mapError(() => new PublishFailed({ message: "npm pack did not report package integrity and files" })));
61
+ const pack = packs[0];
62
+ if (!pack?.integrity)
63
+ return yield* new PublishFailed({ message: "npm pack did not report package integrity" });
64
+ return { integrity: pack.integrity, files: pack.files.map((f) => ({ path: f.path, bytes: f.size })).sort((a, b) => a.path.localeCompare(b.path)) };
65
+ });
66
+ /** Build `@<project>/<kind>` at `version` into `<out>/<kind>/`, ready for `npm publish`. */
67
+ export const stage = (options) => Effect.gen(function* () {
68
+ const { root, project, kind, version } = options;
69
+ const dir = join(options.out, kind);
70
+ yield* Effect.try({ try: () => { rmSync(dir, { recursive: true, force: true }); mkdirSync(join(dir, "dist"), { recursive: true }); }, catch: (e) => new PublishFailed({ message: String(e) }) });
71
+ const entry = kind === "sdk" ? "generated/sdk/src/index.ts" : "generated/cli/src/main.ts";
72
+ if (!existsSync(join(resolve(root), entry)))
73
+ return yield* new PublishFailed({ message: `${entry} is missing: run \`ortho generate\` first` });
74
+ const bundled = yield* bundle({ root, entry, outfile: join(dir, "dist", kind === "sdk" ? "index.js" : "main.js"), format: "esm", platform: kind === "sdk" ? "neutral" : "node", version });
75
+ const dependencies = {};
76
+ for (const name of bundled.imports) {
77
+ const have = installedVersion(root, name);
78
+ if (have === undefined)
79
+ return yield* new PublishFailed({ message: `the ${kind} imports ${name}, which is not installed in ${resolve(root)}: run your package manager's install` });
80
+ dependencies[name] = have;
81
+ }
82
+ const types = kind === "sdk" ? yield* declarations(root, dir) : undefined;
83
+ const manifest = {
84
+ name: `@${project}/${kind}`,
85
+ version,
86
+ description: kind === "sdk" ? `The ${project} client, generated from its blueprint.` : `The ${project} command line, generated from its blueprint.`,
87
+ type: "module",
88
+ ...(kind === "sdk" ? { exports: { ".": { types: `./${types}`, default: "./dist/index.js" } }, types: `./${types}` } : { bin: { [project]: "./dist/main.js" } }),
89
+ files: kind === "sdk" ? ["dist", "types"] : ["dist"],
90
+ dependencies,
91
+ publishConfig: { access: "public" },
92
+ };
93
+ yield* Effect.try({ try: () => writeFileSync(join(dir, "package.json"), JSON.stringify(manifest, null, 2) + "\n"), catch: (e) => new PublishFailed({ message: String(e) }) });
94
+ return { name: manifest.name, version, dir, ...(yield* listing(dir, options.env)) };
95
+ });
@@ -0,0 +1,22 @@
1
+ import { Effect } from "effect";
2
+ import { PublishFailed, type Binary } from "../types.ts";
3
+ /** `acme-ab12` is the class `AcmeAb12`, which is what Homebrew looks for in `Formula/acme-ab12.rb`. */
4
+ export declare const classOf: (formula: string) => string;
5
+ /**
6
+ * The formula: the version, one tarball per platform built, and a test that runs the binary. `skip_clean` is insurance: on the
7
+ * Homebrew tried (macOS and Linux) the installed bytes were identical to the tarball's, but a later strip would break an
8
+ * executable that carries its program as a blob.
9
+ */
10
+ export declare const formulaText: (options: {
11
+ readonly formula: string;
12
+ readonly project: string;
13
+ readonly version: string;
14
+ readonly binaries: ReadonlyArray<Binary>;
15
+ }) => string;
16
+ /** Write `Formula/<formula>.rb` into the tap repository (made as a git repository when it isn't one yet) and commit it, when it changed. Returns the file. */
17
+ export declare const writeFormula: (options: {
18
+ readonly repo: string;
19
+ readonly formula: string;
20
+ readonly text: string;
21
+ readonly version: string;
22
+ }) => Effect.Effect<string, PublishFailed>;
@@ -0,0 +1,61 @@
1
+ // The Homebrew tap on this machine: a git repository whose formula points at the binaries' tarballs by `file://` URL and sha256 (D3 #9).
2
+ import { spawnSync } from "node:child_process";
3
+ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
4
+ import { join, resolve } from "node:path";
5
+ import { Effect } from "effect";
6
+ import { PublishFailed } from "../types.js";
7
+ /** `acme-ab12` is the class `AcmeAb12`, which is what Homebrew looks for in `Formula/acme-ab12.rb`. */
8
+ export const classOf = (formula) => formula.split(/[-_.]/).filter(Boolean).map((p) => p[0].toUpperCase() + p.slice(1)).join("");
9
+ const blocks = (binaries) => {
10
+ const one = (target, os, cpu) => {
11
+ const b = binaries.find((x) => x.target === target);
12
+ return b === undefined ? [] : [` on_${os} do`, ` on_${cpu} do`, ` url "file://${b.tarball}"`, ` sha256 "${b.sha256}"`, " end", " end", ""];
13
+ };
14
+ return [...one("darwin-arm64", "macos", "arm"), ...one("linux-x64", "linux", "intel")];
15
+ };
16
+ /**
17
+ * The formula: the version, one tarball per platform built, and a test that runs the binary. `skip_clean` is insurance: on the
18
+ * Homebrew tried (macOS and Linux) the installed bytes were identical to the tarball's, but a later strip would break an
19
+ * executable that carries its program as a blob.
20
+ */
21
+ export const formulaText = (options) => [
22
+ `class ${classOf(options.formula)} < Formula`,
23
+ ` desc "The ${options.project} command line"`,
24
+ ` homepage "https://example.invalid/${options.project}"`,
25
+ ` version "${options.version}"`,
26
+ "",
27
+ ...blocks(options.binaries),
28
+ ` skip_clean "bin/${options.project}"`,
29
+ "",
30
+ " def install",
31
+ ` bin.install "${options.project}"`,
32
+ " end",
33
+ "",
34
+ " test do",
35
+ ` assert_match version.to_s, shell_output("#{bin}/${options.project} --version")`,
36
+ " end",
37
+ "end",
38
+ "",
39
+ ].join("\n");
40
+ const git = (repo, ...args) => {
41
+ const r = spawnSync("git", ["-c", "user.name=ortho", "-c", "user.email=ortho@localhost", "-c", "commit.gpgsign=false", ...args], { cwd: repo, encoding: "utf8" });
42
+ if (r.status !== 0)
43
+ throw new Error(`git ${args[0]} in ${repo} failed: ${(r.stderr || r.stdout).trim()}`);
44
+ return r.stdout.trim();
45
+ };
46
+ /** Write `Formula/<formula>.rb` into the tap repository (made as a git repository when it isn't one yet) and commit it, when it changed. Returns the file. */
47
+ export const writeFormula = (options) => Effect.try({
48
+ try: () => {
49
+ const repo = resolve(options.repo);
50
+ mkdirSync(join(repo, "Formula"), { recursive: true });
51
+ if (!existsSync(join(repo, ".git")))
52
+ git(repo, "init", "-q", "-b", "main");
53
+ const file = join(repo, "Formula", `${options.formula}.rb`);
54
+ writeFileSync(file, options.text);
55
+ git(repo, "add", "-A");
56
+ if (spawnSync("git", ["diff", "--cached", "--quiet"], { cwd: repo }).status !== 0)
57
+ git(repo, "commit", "-q", "-m", `${options.formula} ${options.version}`);
58
+ return file;
59
+ },
60
+ catch: (e) => new PublishFailed({ message: String(e.message ?? e) }),
61
+ });
@@ -0,0 +1,2 @@
1
+ import { type PublishApi } from "./types.ts";
2
+ export declare const Publish: PublishApi;
@@ -0,0 +1,99 @@
1
+ import { Names } from "orthograph/server";
2
+ import { mkdirSync, mkdtempSync } from "node:fs";
3
+ import { homedir } from "node:os";
4
+ import { join, relative, resolve } from "node:path";
5
+ import { Effect } from "effect";
6
+ import { Compiler, nodeSource } from "@orthograph/compiler";
7
+ import { PublishFailed } from "./types.js";
8
+ import { isPrerelease, planOf, projectName } from "./internal/plan.js";
9
+ import { isNpmjs, nextPrerelease, publishPackage, registryOf, versionsOf } from "./internal/registry.js";
10
+ import { buildBinary, hostTarget, NODE_VERSION } from "./internal/sea.js";
11
+ import { stage } from "./internal/stage.js";
12
+ import { withSource } from "./internal/source.js";
13
+ import { formulaText, writeFormula } from "./internal/tap.js";
14
+ const kb = (bytes) => `${(bytes / 1024).toFixed(1)} kB`;
15
+ const prerelease = ({ root, env, version }) => Effect.gen(function* () {
16
+ const registry = registryOf(env);
17
+ if (registry === undefined)
18
+ return yield* new PublishFailed({ message: "no registry: set ORTHO_REGISTRY to the registry to publish to" });
19
+ const project = projectName(root);
20
+ return yield* nextPrerelease(registry, [`@${project}/sdk`, `@${project}/cli`], version);
21
+ });
22
+ /** The tap repository this run writes to: the one named, or `.ortho/tap/` for a run that is local by its own say-so. */
23
+ const tapOf = (root, env, localTap) => {
24
+ const given = env[Names.variable("TAP_REPO")]?.trim();
25
+ return given ? resolve(given) : localTap ? join(resolve(root), Names.folder, "tap") : undefined;
26
+ };
27
+ const publishCaptured = ({ root, env, environment, version, mode, localTap, say }, source) => Effect.gen(function* () {
28
+ const model = yield* Compiler.model.pipe(Effect.provide(nodeSource(source)), Effect.mapError((e) => new PublishFailed({ message: e._tag === "BlueprintInvalid" ? `the blueprint is invalid:\n - ${e.problems.join("\n - ")}` : e.message })));
29
+ const declared = model.environments?.[environment];
30
+ if (declared === undefined)
31
+ return yield* new PublishFailed({ message: `no environment "${environment}" in blueprint/environments/` });
32
+ const plan = planOf(root, declared, version);
33
+ const dry = mode === "dry-run";
34
+ const registry = registryOf(env);
35
+ if (registry !== undefined && isNpmjs(registry))
36
+ return yield* new PublishFailed({ message: `${registry} is the real npm: publishing there is the cloud pass's` });
37
+ const out = yield* Effect.try({ try: () => {
38
+ const parent = join(resolve(root), Names.folder, "publish", version);
39
+ mkdirSync(parent, { recursive: true });
40
+ return mkdtempSync(join(parent, "run-"));
41
+ }, catch: (e) => new PublishFailed({ message: String(e) }) });
42
+ yield* say(dry ? `publish --dry-run: ${plan.project} ${version}, ${environment}'s publish list; nothing is sent anywhere` : `publish ${plan.project} ${version}, ${environment}'s publish list`);
43
+ const packages = [];
44
+ if (!dry && registry === undefined && plan.npm.length > 0)
45
+ yield* say("skipped npm (set ORTHO_REGISTRY to a registry on this machine to publish to)");
46
+ for (const pkg of plan.npm.filter(() => dry || registry !== undefined)) {
47
+ const staged = yield* stage({ root: source, env, project: plan.project, kind: pkg.kind, version, out });
48
+ packages.push(staged);
49
+ if (dry) {
50
+ yield* say(`npm ${pkg.name}@${version} --tag ${pkg.tag} to ${registry ?? "no registry set"} (${staged.files.length} files, ${kb(staged.files.reduce((n, f) => n + f.bytes, 0))})`);
51
+ for (const f of staged.files)
52
+ yield* say(` ${f.path} ${f.bytes} B`);
53
+ continue;
54
+ }
55
+ const have = yield* versionsOf(registry, pkg.name);
56
+ if (have.versions.includes(version)) {
57
+ if (have.integrities[version] !== staged.integrity)
58
+ return yield* new PublishFailed({ message: `refused: ${pkg.name}@${version} has different or unknown package integrity on the registry` });
59
+ yield* say(`npm ${pkg.name}@${version} is already on ${registry}: left alone`);
60
+ continue;
61
+ }
62
+ yield* publishPackage({ dir: staged.dir, registry: registry, tag: pkg.tag, env });
63
+ yield* say(`npm ${pkg.name}@${version} published --tag ${pkg.tag} to ${registry}`);
64
+ }
65
+ // The CLI as a single executable and a formula pointing at it: for the platform this machine is.
66
+ let binary;
67
+ let formula;
68
+ if (plan.homebrew !== undefined) {
69
+ const name = env[Names.variable("FORMULA")]?.trim() || plan.project;
70
+ const tap = tapOf(root, env, localTap);
71
+ const target = hostTarget();
72
+ const tarball = `${plan.project}-${version}-${target ?? `${process.platform}-${process.arch}`}.tar.gz`;
73
+ if (dry) {
74
+ yield* say(target === undefined ? `skipped binary (no single executable for ${process.platform}-${process.arch})` : `binary ${tarball} (Node ${NODE_VERSION} single executable, built when published)`);
75
+ yield* say(`homebrew ${plan.homebrew}: Formula/${name}.rb in ${tap === undefined ? "ORTHO_TAP_REPO (not set)" : relative(resolve(root), tap) || tap}`);
76
+ }
77
+ else if (tap === undefined) {
78
+ yield* say("skipped homebrew (set ORTHO_TAP_REPO to a git repository to commit the formula to)");
79
+ }
80
+ else if (target === undefined) {
81
+ yield* say(`skipped binary (no single executable for ${process.platform}-${process.arch})`);
82
+ }
83
+ else {
84
+ binary = yield* buildBinary({ root: source, project: plan.project, version, out, cache: env[Names.variable("CACHE")] || join(homedir(), ".cache", Names.short), target });
85
+ yield* say(`binary ${tarball} sha256:${binary.sha256} (${kb(binary.bytes)})`);
86
+ formula = yield* writeFormula({ repo: tap, formula: name, text: formulaText({ formula: name, project: plan.project, version, binaries: [binary] }), version });
87
+ yield* say(`homebrew ${plan.homebrew}: Formula/${name}.rb committed to ${tap}`);
88
+ }
89
+ }
90
+ if (plan.githubReleases)
91
+ yield* say("skipped github releases (cloud pass)");
92
+ if (plan.npm.length > 0 && (dry || registry !== undefined))
93
+ yield* say("skipped npmjs.org (cloud pass)");
94
+ if (dry)
95
+ yield* say("dry run: the registry, the tap and Node's download were left alone");
96
+ return { version, tag: plan.npm[0]?.tag ?? (isPrerelease(version) ? "next" : "latest"), packages, ...(binary ? { binary } : {}), ...(formula ? { formula } : {}) };
97
+ });
98
+ const run = (options) => withSource(options.root, options.sourceRevision, (source) => publishCaptured(options, source));
99
+ export const Publish = { run, prerelease, registry: registryOf };
@@ -0,0 +1,80 @@
1
+ import { type Effect } from "effect";
2
+ declare const PublishFailed_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
3
+ readonly _tag: "PublishFailed";
4
+ } & Readonly<A>;
5
+ export declare class PublishFailed extends PublishFailed_base<{
6
+ readonly message: string;
7
+ }> {
8
+ }
9
+ /** The process environment, as only an entry file reads it. */
10
+ export type Env = Readonly<Record<string, string | undefined>>;
11
+ /** Whose `publish` list applies: staging publishes prereleases, production the release. */
12
+ export type PublishTarget = "staging" | "production";
13
+ /** What one npm package is, built and ready to go. */
14
+ export interface Staged {
15
+ readonly name: string;
16
+ readonly version: string;
17
+ /** Where the package was built, ready for `npm publish`. */
18
+ readonly dir: string;
19
+ /** Every file `npm publish` would send, by path. */
20
+ /** npm pack’s integrity for precisely these package files. */
21
+ readonly integrity: string;
22
+ readonly files: ReadonlyArray<{
23
+ readonly path: string;
24
+ readonly bytes: number;
25
+ }>;
26
+ }
27
+ /** The CLI as a Node single executable for one platform, tarred, with the hash its formula pins. */
28
+ export interface Binary {
29
+ readonly target: string;
30
+ readonly tarball: string;
31
+ readonly sha256: string;
32
+ readonly bytes: number;
33
+ }
34
+ export interface Published {
35
+ readonly version: string;
36
+ /** The dist-tag the npm packages went (or would go) out under: `latest` only ever for a release. */
37
+ readonly tag: string;
38
+ readonly packages: ReadonlyArray<Staged>;
39
+ readonly binary?: Binary;
40
+ /** The formula's file, in the tap repository. */
41
+ readonly formula?: string;
42
+ }
43
+ export interface PublishApi {
44
+ /**
45
+ * Publish the SDK as `@<project>/sdk` and the CLI as `@<project>/cli` at `version`, as `environment`'s `publish` list in
46
+ * the blueprint says, and `say` every line of what happened. The project's name is its folder's, as the generators have it.
47
+ *
48
+ * - `dry-run` builds the packages and lists exactly what would go out (each package's files, the binary, the formula) and
49
+ * publishes, writes and downloads nothing.
50
+ * - `publish` sends the packages to the registry in `ORTHO_REGISTRY` (Verdaccio on this machine) and, when the
51
+ * environment declares them, builds the CLI binary for this machine's platform, writes the formula into the tap
52
+ * repository (`ORTHO_TAP_REPO`, else `.ortho/tap/` when `tap: "default"`) and says what it can't reach
53
+ * (`skipped npmjs.org (cloud pass)`, `skipped github releases (cloud pass)`).
54
+ *
55
+ * A prerelease (`1.1.0-next.2`) is always published under a dist-tag that is not `latest`, whatever the blueprint says.
56
+ * A version already on the registry is reused only when its npm integrity matches these staged bytes.
57
+ * Per-invocation output remains under the original root after temporary captured source is removed.
58
+ */
59
+ readonly run: (options: {
60
+ readonly root: string;
61
+ /** Promotion callers pin the full Git commit; source is archived privately before staging any output. */
62
+ readonly sourceRevision?: string;
63
+ readonly env: Env;
64
+ readonly environment: PublishTarget;
65
+ readonly version: string;
66
+ readonly mode: "dry-run" | "publish";
67
+ /** With `publish`: the formula goes to `.ortho/tap/` when `ORTHO_TAP_REPO` is not set, and the binary is built for it. */
68
+ readonly localTap: boolean;
69
+ readonly say: (line: string) => Effect.Effect<void>;
70
+ }) => Effect.Effect<Published, PublishFailed>;
71
+ /** The registry a run publishes to: `ORTHO_REGISTRY` with its trailing slash; undefined when none is set (a run then skips npm and says so). */
72
+ readonly registry: (env: Env) => string | undefined;
73
+ /** The next free prerelease of `version` on the registry: `<version>-next.<n>`, one past the highest `n` either package has. */
74
+ readonly prerelease: (options: {
75
+ readonly root: string;
76
+ readonly env: Env;
77
+ readonly version: string;
78
+ }) => Effect.Effect<string, PublishFailed>;
79
+ }
80
+ export {};
@@ -0,0 +1,4 @@
1
+ // Publishing the generated SDK and CLI, at the model's version: npm packages, a CLI binary, a Homebrew formula (D3 #9, #110 to #119).
2
+ import { Data } from "effect";
3
+ export class PublishFailed extends Data.TaggedError("PublishFailed") {
4
+ }
@@ -0,0 +1,12 @@
1
+ import { Effect } from "effect";
2
+ import { ReleaseFailed } from "../types.ts";
3
+ export interface Answer {
4
+ readonly status: number;
5
+ readonly body: unknown;
6
+ }
7
+ export declare const call: (method: string, url: string, options?: {
8
+ readonly token?: string;
9
+ readonly body?: string;
10
+ }) => Effect.Effect<Answer, ReleaseFailed>;
11
+ /** A 200 answer's body, or a failure that says what the logbook said. */
12
+ export declare const ok: (what: string, answer: Answer) => Effect.Effect<unknown, ReleaseFailed>;
@@ -0,0 +1,14 @@
1
+ // The logbook's routes over HTTP: status and parsed body, or a ReleaseFailed that names what could not be reached.
2
+ import { Effect, Option, Schema } from "effect";
3
+ import { ReleaseFailed } from "../types.js";
4
+ const parse = Schema.decodeUnknownOption(Schema.fromJsonString(Schema.Unknown));
5
+ export const call = (method, url, options = {}) => Effect.tryPromise({
6
+ try: () => fetch(url, {
7
+ method,
8
+ headers: { ...(options.body === undefined ? {} : { "content-type": "application/json" }), ...(options.token === undefined ? {} : { authorization: `Bearer ${options.token}` }) },
9
+ ...(options.body === undefined ? {} : { body: options.body }),
10
+ }).then((r) => r.text().then((text) => ({ status: r.status, body: Option.getOrElse(parse(text), () => text) }))),
11
+ catch: (e) => new ReleaseFailed({ message: `the logbook at ${url} did not answer: ${String(e)}` }),
12
+ });
13
+ /** A 200 answer's body, or a failure that says what the logbook said. */
14
+ export const ok = (what, answer) => answer.status === 200 ? Effect.succeed(answer.body) : Effect.fail(new ReleaseFailed({ message: `the logbook refused ${what}: ${answer.status} ${JSON.stringify(answer.body)}` }));
@@ -0,0 +1,13 @@
1
+ import { Effect } from "effect";
2
+ import { type Model } from "@orthograph/compiler";
3
+ import { ReleaseFailed, type StaleIn } from "../types.ts";
4
+ /** The model the logbook holds for a revision. */
5
+ export declare const modelAt: (logbook: string, revision: string) => Effect.Effect<Model, ReleaseFailed>;
6
+ /**
7
+ * For staging and production: the latest passing verdict of each operation among those posted from `main` (a pull
8
+ * request's verdict never counts, D3 #8), judged against the model of the revision it proved.
9
+ */
10
+ export declare const staleness: (logbook: string, model: Model, root?: string) => Effect.Effect<{
11
+ readonly stale: ReadonlyArray<StaleIn>;
12
+ readonly proven: ReadonlyArray<string>;
13
+ }, ReleaseFailed>;
@@ -0,0 +1,43 @@
1
+ // What the logbook's verdicts say about the working model: a proof is stale when what it rested on has changed since.
2
+ import { Effect, Schema } from "effect";
3
+ import { Compare } from "@orthograph/compiler";
4
+ import { ReleaseFailed, SHIPPED } from "../types.js";
5
+ import { evidenceHolds, modelHash, storyHash } from "#modules/verdicts/internal/proof.js";
6
+ import { VerdictRows } from "#modules/verdicts/service.js";
7
+ import { call, ok } from "./http.js";
8
+ /** The model the logbook holds for a revision. */
9
+ export const modelAt = (logbook, revision) => call("GET", `${logbook}/models/${encodeURIComponent(revision)}`).pipe(Effect.flatMap((a) => ok(`the model of ${revision}`, a)), Effect.map((body) => body));
10
+ /** Every hash the operation's proof rested on, as it was in `proved`, still the same in `now`. */
11
+ const holds = (now, proved, operation) => Object.entries(Compare.dependsOn(proved, operation)).every(([key, hash]) => Compare.hashOf(now, key) === hash);
12
+ /**
13
+ * For staging and production: the latest passing verdict of each operation among those posted from `main` (a pull
14
+ * request's verdict never counts, D3 #8), judged against the model of the revision it proved.
15
+ */
16
+ export const staleness = (logbook, model, root) => Effect.gen(function* () {
17
+ const models = new Map();
18
+ const staleIn = new Map();
19
+ const proven = new Set();
20
+ for (const environment of SHIPPED) {
21
+ const body = yield* call("GET", `${logbook}/verdicts/latest?environment=${environment}&ref=refs/heads/main`).pipe(Effect.flatMap((a) => ok(`${environment}'s verdicts`, a)));
22
+ const rows = yield* Schema.decodeUnknownEffect(VerdictRows)(body).pipe(Effect.mapError((e) => new ReleaseFailed({ message: `the logbook's verdicts were not as expected: ${e.message}` })));
23
+ for (const row of rows) {
24
+ if (row.verdict !== "pass" || !(row.operation in model.operations))
25
+ continue;
26
+ if (!models.has(row.revision))
27
+ models.set(row.revision, yield* modelAt(logbook, row.revision));
28
+ const proved = models.get(row.revision);
29
+ if (!(row.operation in proved.operations))
30
+ continue;
31
+ const evidence = row.journeys;
32
+ const matches = evidence == null || root === undefined ||
33
+ (evidence.every((v) => v.modelHash === modelHash(proved)) &&
34
+ evidenceHolds(root, model, row.operation, storyHash(proved, row.operation, evidence.map((v) => v.journey)), evidence));
35
+ if (matches && holds(model, proved, row.operation))
36
+ proven.add(row.operation);
37
+ else
38
+ staleIn.set(row.operation, [...(staleIn.get(row.operation) ?? []), environment]);
39
+ }
40
+ }
41
+ const stale = [...staleIn].sort(([a], [b]) => a.localeCompare(b)).map(([operation, environments]) => ({ operation, environments }));
42
+ return { stale, proven: [...proven].filter((op) => !staleIn.has(op)).sort() };
43
+ });
@@ -0,0 +1,2 @@
1
+ import { type ReleasesApi } from "./types.ts";
2
+ export declare const Releases: ReleasesApi;
@@ -0,0 +1,59 @@
1
+ import { Names } from "orthograph/server";
2
+ import { mkdirSync, writeFileSync } from "node:fs";
3
+ import { dirname, join } from "node:path";
4
+ import { Effect, Redacted } from "effect";
5
+ import { Compare, canonical } from "@orthograph/compiler";
6
+ import { Environments } from "#modules/environments/service.js";
7
+ import { Verdicts } from "#modules/verdicts/service.js";
8
+ import { ReleaseFailed } from "./types.js";
9
+ import { call, ok } from "./internal/http.js";
10
+ import { modelAt, staleness } from "./internal/stale.js";
11
+ /** The last production release's version and revision, or undefined when there has been none. */
12
+ const lastRelease = (logbook) => call("GET", `${logbook}/releases/latest`).pipe(Effect.flatMap((a) => {
13
+ if (a.status === 404)
14
+ return Effect.succeed(undefined);
15
+ return ok("the last release", a).pipe(Effect.map((body) => body));
16
+ }));
17
+ const shipping = (logbook, model, root) => Effect.gen(function* () {
18
+ const last = yield* lastRelease(logbook);
19
+ const { stale, proven } = yield* staleness(logbook, model, root);
20
+ if (last === undefined)
21
+ return { from: null, version: "1.0.0", bump: null, changes: [], proven, stale };
22
+ const released = Compare.release(yield* modelAt(logbook, last.revision), model);
23
+ const version = Compare.next(last.version, released.bump);
24
+ if (version === undefined)
25
+ return yield* new ReleaseFailed({ message: `the last release's version is not x.y.z: ${last.version}` });
26
+ return { from: last.version, version, bump: released.bump, changes: released.changes, proven, stale };
27
+ });
28
+ const changesJson = (s) => JSON.stringify({ from: s.from, to: s.version, changes: s.changes, stale: s.stale.map((x) => x.operation), proven: s.proven }, null, 2) + "\n";
29
+ /** The same token source as a verdict's: one place decides it (D3 #90). Minted per write, because the issuer's tokens are short-lived. */
30
+ const writeToken = (env) => Verdicts.sourceOf(env).pipe(Effect.flatMap(Verdicts.mint), Effect.map(Redacted.value), Effect.mapError((e) => new ReleaseFailed({ message: e.message })));
31
+ /** A token from a source already chosen (a prove's own), minted for this write. */
32
+ const tokenFrom = (source) => Verdicts.mint(source).pipe(Effect.map(Redacted.value), Effect.mapError((e) => new ReleaseFailed({ message: e.message })));
33
+ export const Releases = {
34
+ locate: ({ root, env }) => {
35
+ const given = env[Names.variable("LOGBOOK_URL")];
36
+ if (given)
37
+ return Effect.succeed(given.replace(/\/+$/, ""));
38
+ return Environments.status({ root, name: "logbook" }).pipe(Effect.map((s) => (s.state === "up" ? s.url : undefined)), Effect.mapError((e) => new ReleaseFailed({ message: e.message })));
39
+ },
40
+ last: (logbook) => lastRelease(logbook),
41
+ shipping,
42
+ next: (logbook, model) => Effect.map(shipping(logbook, model), (s) => s.version),
43
+ keep: ({ logbook, env, source, model, revision }) => Effect.gen(function* () {
44
+ const token = yield* (source === undefined ? writeToken(env ?? {}) : tokenFrom(source));
45
+ const put = yield* call("PUT", `${logbook}/models/${encodeURIComponent(revision)}`, { token, body: canonical(model) });
46
+ yield* ok(`the model of ${revision}`, put);
47
+ }),
48
+ record: ({ logbook, env, model, revision, version }) => Effect.gen(function* () {
49
+ yield* Releases.keep({ logbook, env, model, revision });
50
+ const posted = yield* call("POST", `${logbook}/releases`, { token: yield* writeToken(env), body: JSON.stringify({ version, revision }) });
51
+ yield* ok(`release ${version}`, posted);
52
+ }),
53
+ changesJson,
54
+ writeChanges: (root, s) => Effect.sync(() => {
55
+ const path = join(root, "generated/model/changes.json");
56
+ mkdirSync(dirname(path), { recursive: true });
57
+ writeFileSync(path, changesJson(s));
58
+ }),
59
+ };
@@ -0,0 +1,81 @@
1
+ import { type Effect } from "effect";
2
+ import type { Bump, Model, Versioned } from "@orthograph/compiler";
3
+ import type { TokenSource } from "#modules/verdicts/types.js";
4
+ declare const ReleaseFailed_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
5
+ readonly _tag: "ReleaseFailed";
6
+ } & Readonly<A>;
7
+ export declare class ReleaseFailed extends ReleaseFailed_base<{
8
+ readonly message: string;
9
+ }> {
10
+ }
11
+ /** The process environment, as only an entry file reads it. */
12
+ export type Env = Readonly<Record<string, string | undefined>>;
13
+ /** The environments that ship: staging and production. `test` is proven afresh on every push, so it is never stale. */
14
+ export declare const SHIPPED: readonly ["staging", "production"];
15
+ /** An operation whose proof in some shipped environment rests on something that has changed since. */
16
+ export interface StaleIn {
17
+ readonly operation: string;
18
+ readonly environments: ReadonlyArray<string>;
19
+ }
20
+ /** What shipping the working model would be: its version, what changes since the last release, and what is stale. */
21
+ export interface Shipping {
22
+ /** The last production release's version, or null when there is none. */
23
+ readonly from: string | null;
24
+ /** `from` bumped by what changed; `1.0.0` when there is no release. */
25
+ readonly version: string;
26
+ /** The largest bump the changes make; null with no release to compare to. */
27
+ readonly bump: Bump | null;
28
+ readonly changes: ReadonlyArray<Versioned>;
29
+ /** Proven by a `main` verdict in staging or production, and still holding. */
30
+ readonly proven: ReadonlyArray<string>;
31
+ readonly stale: ReadonlyArray<StaleIn>;
32
+ }
33
+ export interface ReleasesApi {
34
+ /**
35
+ * Where the logbook is: `ORTHO_LOGBOOK_URL` when set, otherwise the running `logbook` environment's URL (its pidfile
36
+ * and port under `.ortho/environments/logbook/`, as `ortho env up logbook` keeps them). Undefined when neither.
37
+ */
38
+ readonly locate: (options: {
39
+ readonly root: string;
40
+ readonly env: Env;
41
+ }) => Effect.Effect<string | undefined, ReleaseFailed>;
42
+ /** The last production release, or undefined when there has been none. */
43
+ readonly last: (logbook: string) => Effect.Effect<{
44
+ readonly version: string;
45
+ readonly revision: string;
46
+ } | undefined, ReleaseFailed>;
47
+ /** The working model against the last production release's model, and the logbook's latest `main` verdicts. */
48
+ readonly shipping: (logbook: string, model: Model, root?: string) => Effect.Effect<Shipping, ReleaseFailed>;
49
+ /** `ortho version --next`: the version the working model would release as. */
50
+ readonly next: (logbook: string, model: Model) => Effect.Effect<string, ReleaseFailed>;
51
+ /**
52
+ * Keep a revision's model in the logbook (`PUT /models/<revision>`; a revision's model is written once, and the same model
53
+ * again is fine). Staleness judges a verdict against the model of the revision it proved, so whoever posts a shipped
54
+ * environment's verdicts keeps the model first (`promote --to staging` does).
55
+ */
56
+ readonly keep: (options: {
57
+ readonly logbook: string;
58
+ /** Who signs the write: the process environment's token source (`Verdicts.sourceOf`), or one already chosen. One of the two. */
59
+ readonly env?: Env;
60
+ readonly source?: TokenSource;
61
+ readonly model: Model;
62
+ readonly revision: string;
63
+ }) => Effect.Effect<void, ReleaseFailed>;
64
+ /**
65
+ * Record a release: the model is kept, then `POST /releases { version, revision }`. Both are writes, so they carry a
66
+ * verified OIDC token from `Verdicts.sourceOf`, the one token source verdicts use too (`ORTHO_LOGBOOK_TOKEN`, else the
67
+ * local issuer, else GitHub's own). `promote --to production` calls it.
68
+ */
69
+ readonly record: (options: {
70
+ readonly logbook: string;
71
+ readonly env: Env;
72
+ readonly model: Model;
73
+ readonly revision: string;
74
+ readonly version: string;
75
+ }) => Effect.Effect<void, ReleaseFailed>;
76
+ /** `generated/model/changes.json` as the docs show it. */
77
+ readonly changesJson: (shipping: Shipping) => string;
78
+ /** Write it into `root`. The generators never write or delete this file: it depends on the logbook, not on the blueprint. */
79
+ readonly writeChanges: (root: string, shipping: Shipping) => Effect.Effect<void>;
80
+ }
81
+ export {};
@@ -0,0 +1,6 @@
1
+ // Releases against the logbook: what the next version is, what is stale where, and recording a release (D3 #1, #31).
2
+ import { Data } from "effect";
3
+ export class ReleaseFailed extends Data.TaggedError("ReleaseFailed") {
4
+ }
5
+ /** The environments that ship: staging and production. `test` is proven afresh on every push, so it is never stale. */
6
+ export const SHIPPED = ["staging", "production"];
@@ -0,0 +1,5 @@
1
+ export declare const fileOf: (root: string, env: string) => string;
2
+ /** The values that are set: a name with an empty value is not set, as `secrets set` refuses an empty one. One predicate for the listing and for `promote`. */
3
+ export declare const valuesOf: (file: string) => ReadonlyMap<string, string>;
4
+ /** Replace or add one line, keeping every other as it is. The mode is 0600 before the value is written, and after. */
5
+ export declare const keep: (file: string, name: string, value: string) => void;