@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,25 @@
1
+ // An environment's `secrets.env`: `NAME=value` lines, owner-only. Read and written whole; a value is never logged.
2
+ import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
+ import { dirname, join, resolve } from "node:path";
4
+ import { Names } from "orthograph/server";
5
+ export const fileOf = (root, env) => join(resolve(root), Names.folder, "environments", env, "secrets.env");
6
+ /** 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`. */
7
+ export const valuesOf = (file) => new Map((existsSync(file) ? readFileSync(file, "utf8") : "").split("\n").flatMap((line) => {
8
+ const at = line.indexOf("=");
9
+ return at > 0 && at < line.length - 1 ? [[line.slice(0, at), line.slice(at + 1)]] : [];
10
+ }));
11
+ /** Replace or add one line, keeping every other as it is. The mode is 0600 before the value is written, and after. */
12
+ export const keep = (file, name, value) => {
13
+ mkdirSync(dirname(file), { recursive: true });
14
+ const lines = (existsSync(file) ? readFileSync(file, "utf8") : "").split("\n").filter((line) => line !== "");
15
+ const at = lines.findIndex((line) => line.startsWith(`${name}=`));
16
+ const line = `${name}=${value}`;
17
+ if (at >= 0)
18
+ lines[at] = line;
19
+ else
20
+ lines.push(line);
21
+ if (existsSync(file))
22
+ chmodSync(file, 0o600);
23
+ writeFileSync(file, `${lines.join("\n")}\n`, { mode: 0o600 });
24
+ chmodSync(file, 0o600);
25
+ };
@@ -0,0 +1,2 @@
1
+ import { type SecretsApi } from "./types.ts";
2
+ export declare const Secrets: SecretsApi;
@@ -0,0 +1,38 @@
1
+ import { Effect } from "effect";
2
+ import { SecretsRefused } from "./types.js";
3
+ import { fileOf, keep, valuesOf } from "./internal/file.js";
4
+ const declared = (model) => Object.entries(model.secrets ?? {}).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
5
+ /** `local` always exists; any other environment is a file in `blueprint/environments/`. */
6
+ const known = (model, env) => env === "local" || model.environments?.[env] !== undefined ? Effect.void
7
+ : Effect.fail(new SecretsRefused({ message: `no environment "${env}" in blueprint/environments/ (${Object.keys(model.environments ?? {}).join(", ") || "none"})` }));
8
+ export const Secrets = {
9
+ rows: ({ root, env, model }) => Effect.gen(function* () {
10
+ yield* known(model, env);
11
+ const have = yield* Effect.sync(() => valuesOf(fileOf(root, env)));
12
+ const cloud = model.environments?.[env]?.cloud != null;
13
+ return declared(model).map(([name, s]) => ({
14
+ name, how: s.how, kind: s.kind,
15
+ status: s.kind !== "runtime" ? "in CI"
16
+ : have.has(name) ? "set"
17
+ : s.how === "stored" ? "missing"
18
+ : cloud ? "missing (promote makes it)" : "set (made when first needed)",
19
+ }));
20
+ }),
21
+ set: ({ root, env, name, value, model }) => Effect.gen(function* () {
22
+ yield* known(model, env);
23
+ const secret = model.secrets?.[name];
24
+ if (!secret)
25
+ return yield* new SecretsRefused({ message: `no secret named ${name}: the blueprint declares ${declared(model).map(([n]) => n).join(", ") || "none"}` });
26
+ if (secret.kind !== "runtime")
27
+ return yield* new SecretsRefused({ message: `${name} is a ${secret.kind} secret: ${secret.kind === "release" ? "CI holds it" : "a developer's machine holds it"}, so it is not set here` });
28
+ if (value === "")
29
+ return yield* new SecretsRefused({ message: `no value for ${name}: pipe it in, e.g. \`printf %s "$VALUE" | ortho secrets set ${name}\`` });
30
+ if (/[\r\n]/.test(value))
31
+ return yield* new SecretsRefused({ message: `the value for ${name} runs over more than one line, and secrets.env keeps one line a value` });
32
+ yield* Effect.sync(() => keep(fileOf(root, env), name, value));
33
+ }),
34
+ missing: ({ root, target, model }) => Effect.sync(() => {
35
+ const have = valuesOf(fileOf(root, target));
36
+ return declared(model).flatMap(([name, s]) => (s.kind === "runtime" && s.how === "stored" && !have.has(name) ? [name] : []));
37
+ }),
38
+ };
@@ -0,0 +1,44 @@
1
+ import { type Effect } from "effect";
2
+ import type { Model } from "@orthograph/compiler";
3
+ declare const SecretsRefused_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 & {
4
+ readonly _tag: "SecretsRefused";
5
+ } & Readonly<A>;
6
+ /** A secret command the rules turn away: an environment or a name nothing declares, an empty value, a secret CI holds. */
7
+ export declare class SecretsRefused extends SecretsRefused_base<{
8
+ readonly message: string;
9
+ }> {
10
+ }
11
+ /** One declared secret in one environment: `how` it is given, whose it is (`kind`), and its state in words (`set`, `missing`, `in CI`). */
12
+ export interface SecretRow {
13
+ readonly name: string;
14
+ readonly how: "generated" | "stored";
15
+ readonly kind: "runtime" | "release" | "builder";
16
+ readonly status: string;
17
+ }
18
+ export interface SecretsApi {
19
+ /** Every declared secret, sorted by name, with its state in `env`. Refuses an environment the blueprint doesn't have. */
20
+ readonly rows: (options: {
21
+ readonly root: string;
22
+ readonly env: string;
23
+ readonly model: Model;
24
+ }) => Effect.Effect<ReadonlyArray<SecretRow>, SecretsRefused>;
25
+ /**
26
+ * Keep `value` (as given) for `name` in `env`'s `secrets.env`, mode 0600, leaving every other line as it was. Refuses an
27
+ * environment or a name the blueprint doesn't declare, a release or builder secret (CI's and a developer's, not a running
28
+ * place's), and an empty value or one that runs over a line.
29
+ */
30
+ readonly set: (options: {
31
+ readonly root: string;
32
+ readonly env: string;
33
+ readonly name: string;
34
+ readonly value: string;
35
+ readonly model: Model;
36
+ }) => Effect.Effect<void, SecretsRefused>;
37
+ /** The stored runtime secrets that `target` has no value for, sorted: what `promote` refuses on. A declared `test` value doesn't count. */
38
+ readonly missing: (options: {
39
+ readonly root: string;
40
+ readonly target: string;
41
+ readonly model: Model;
42
+ }) => Effect.Effect<ReadonlyArray<string>>;
43
+ }
44
+ export {};
@@ -0,0 +1,7 @@
1
+ // Secrets, as an environment holds them: which of the model's declared secrets have a value in an environment, and
2
+ // setting one. Values live in `.ortho/environments/<env>/secrets.env` (mode 0600, gitignored) in the local pass; this module
3
+ // returns names and set/unset, never a value.
4
+ import { Data } from "effect";
5
+ /** A secret command the rules turn away: an environment or a name nothing declares, an empty value, a secret CI holds. */
6
+ export class SecretsRefused extends Data.TaggedError("SecretsRefused") {
7
+ }
@@ -0,0 +1,2 @@
1
+ /** Wrangler's config is JSONC: this takes the comments out, leaving every string alone, and parses what is left. */
2
+ export declare const parseJsonc: (text: string) => unknown;
@@ -0,0 +1,29 @@
1
+ /** Wrangler's config is JSONC: this takes the comments out, leaving every string alone, and parses what is left. */
2
+ export const parseJsonc = (text) => {
3
+ let out = "";
4
+ let i = 0;
5
+ while (i < text.length) {
6
+ const c = text[i];
7
+ const next = text[i + 1];
8
+ if (c === '"') {
9
+ let j = i + 1;
10
+ while (j < text.length && text[j] !== '"')
11
+ j += text[j] === "\\" ? 2 : 1;
12
+ out += text.slice(i, j + 1);
13
+ i = j + 1;
14
+ }
15
+ else if (c === "/" && next === "/") {
16
+ while (i < text.length && text[i] !== "\n")
17
+ i++;
18
+ }
19
+ else if (c === "/" && next === "*") {
20
+ const end = text.indexOf("*/", i + 2);
21
+ i = end < 0 ? text.length : end + 2;
22
+ }
23
+ else {
24
+ out += c;
25
+ i++;
26
+ }
27
+ }
28
+ return JSON.parse(out.replace(/,(\s*[}\]])/g, "$1"));
29
+ };
@@ -0,0 +1,2 @@
1
+ import type { ServerConfigApi } from "./types.ts";
2
+ export declare const ServerConfig: ServerConfigApi;
@@ -0,0 +1,21 @@
1
+ import { existsSync } from "node:fs";
2
+ import { createRequire } from "node:module";
3
+ import { dirname, join, resolve } from "node:path";
4
+ import { Effect } from "effect";
5
+ import { parseJsonc } from "./internal/jsonc.js";
6
+ /** The Worker's binding to the portal's static files: the one place the name is written here; `@orthograph/portal/server` reads it as `env.PORTAL_ASSETS`. */
7
+ const ASSETS_BINDING = "PORTAL_ASSETS";
8
+ const assets = (directory) => ({ directory, binding: ASSETS_BINDING, run_worker_first: true });
9
+ const clientOf = (root) => Effect.runSync(Effect.try({ try: () => dirname(createRequire(join(resolve(root), "package.json")).resolve("@orthograph/portal/package.json")), catch: () => undefined }).pipe(Effect.map((portal) => join(portal, "dist/client")), Effect.map((client) => (existsSync(join(client, "index.html")) ? client : undefined)), Effect.catch(() => Effect.succeed(undefined))));
10
+ const derive = (root, baseText, client) => {
11
+ const base = parseJsonc(baseText);
12
+ const folder = resolve(root, "generated/server");
13
+ const config = {
14
+ ...base,
15
+ main: resolve(folder, base.main ?? "main.ts"),
16
+ d1_databases: (base.d1_databases ?? []).map((db) => ({ ...db, migrations_dir: resolve(folder, String(db["migrations_dir"] ?? "migrations")) })),
17
+ ...(client === undefined ? {} : { assets: assets(client) }),
18
+ };
19
+ return `// Generated by ortho from generated/server/wrangler.jsonc. Do not edit.\n${JSON.stringify(config, null, 2)}\n`;
20
+ };
21
+ export const ServerConfig = { parse: parseJsonc, clientOf, assets, derive };
@@ -0,0 +1,22 @@
1
+ export interface ServerConfigApi {
2
+ /** Wrangler's config is JSONC: the comments taken out, every string left alone, and the rest parsed. */
3
+ readonly parse: (text: string) => unknown;
4
+ /**
5
+ * The portal's built client for a project: `dist/client` of the `@orthograph/portal` its `package.json` resolves, when that has been
6
+ * built (it is built once, in this repository, with the licence). `undefined` when it is not there: the Worker then has no portal pages
7
+ * and says so, and nothing fails.
8
+ */
9
+ readonly clientOf: (root: string) => string | undefined;
10
+ /**
11
+ * The generated config as a world or a build runs it from another folder: `main` and each migrations folder as absolute paths, and, when
12
+ * there is a client, its folder as the Worker's static assets, bound as `PORTAL_ASSETS`, with the Worker answering first (it routes
13
+ * `/portal`, serves the files itself and falls back to the shell for a route).
14
+ */
15
+ readonly derive: (root: string, baseText: string, client: string | undefined) => string;
16
+ /** The `assets` block of a config for a folder of the portal's client: what a world, a build and an environment all write, from here alone. */
17
+ readonly assets: (directory: string) => {
18
+ readonly directory: string;
19
+ readonly binding: string;
20
+ readonly run_worker_first: true;
21
+ };
22
+ }
@@ -0,0 +1,3 @@
1
+ // The generated Worker's wrangler config, read and derived (K19). `generated/server/wrangler.jsonc` is the project's and is never edited
2
+ // by a run; a world, a build or an environment runs a config derived from it, which is where the portal's static files are added.
3
+ export {};
@@ -0,0 +1,29 @@
1
+ import { Effect } from "effect";
2
+ import type { Env, Reader } from "../types.ts";
3
+ /** What the Worker's `OTLP_SINKS` holds for one sink: one endpoint and its headers for each signal. */
4
+ export interface Exporter {
5
+ readonly id: string;
6
+ readonly traces: {
7
+ readonly url: string;
8
+ readonly headers: Readonly<Record<string, string>>;
9
+ };
10
+ readonly logs: {
11
+ readonly url: string;
12
+ readonly headers: Readonly<Record<string, string>>;
13
+ };
14
+ readonly metrics: {
15
+ readonly url: string;
16
+ readonly headers: Readonly<Record<string, string>>;
17
+ };
18
+ }
19
+ /** `capxul-test` is read from `capxul-ingest-test`, `capxul-real` from `capxul-ingest-real`: one token per group, by name. */
20
+ export declare const tokenService: (group: string) => string;
21
+ export type Axiom = {
22
+ readonly kind: "ready";
23
+ readonly exporter: Exporter;
24
+ } | {
25
+ readonly kind: "skipped";
26
+ readonly note: string;
27
+ };
28
+ /** One Axiom group's exporter, or why it is left out. Credentials are read here and only here. */
29
+ export declare const axiom: (group: string, env: Env, read: Reader) => Effect.Effect<Axiom>;
@@ -0,0 +1,25 @@
1
+ // Axiom as a sink: OTLP/HTTP straight from the Worker to the organisation's edge, a dataset per signal.
2
+ import { Effect } from "effect";
3
+ /** `capxul-test` is read from `capxul-ingest-test`, `capxul-real` from `capxul-ingest-real`: one token per group, by name. */
4
+ export const tokenService = (group) => {
5
+ const at = group.lastIndexOf("-");
6
+ return at < 0 ? `${group}-ingest` : `${group.slice(0, at)}-ingest-${group.slice(at + 1)}`;
7
+ };
8
+ /** The edge domain from `AXIOM_DOMAIN` (CI) or the keychain's `axiom-domain`; a full URL is kept as it is (a stand-in). */
9
+ const baseOf = (domain) => (domain.includes("://") ? domain.replace(/\/+$/, "") : `https://${domain}`);
10
+ /** One Axiom group's exporter, or why it is left out. Credentials are read here and only here. */
11
+ export const axiom = (group, env, read) => Effect.gen(function* () {
12
+ const service = tokenService(group);
13
+ const token = env["AXIOM_TOKEN"] || (yield* read(service));
14
+ if (!token)
15
+ return { kind: "skipped", note: `axiom ${group}: skipped, no token (AXIOM_TOKEN, or the keychain item ${service})` };
16
+ const domain = env["AXIOM_DOMAIN"] || (yield* read("axiom-domain"));
17
+ if (!domain)
18
+ return { kind: "skipped", note: `axiom ${group}: skipped, no edge domain (AXIOM_DOMAIN, or the keychain item axiom-domain)` };
19
+ const base = baseOf(domain);
20
+ const endpoint = (signal) => ({
21
+ url: `${base}/v1/${signal}`,
22
+ headers: { authorization: `Bearer ${token}`, [signal === "metrics" ? "x-axiom-metrics-dataset" : "x-axiom-dataset"]: `${group}-${signal}` },
23
+ });
24
+ return { kind: "ready", exporter: { id: `axiom ${group}`, traces: endpoint("traces"), logs: endpoint("logs"), metrics: endpoint("metrics") } };
25
+ });
@@ -0,0 +1,2 @@
1
+ import type { Reader } from "../types.ts";
2
+ export declare const keychain: Reader;
@@ -0,0 +1,13 @@
1
+ // The macOS keychain, read by service name. The value goes to the caller and nowhere else: it is not logged, not put in
2
+ // an error, not kept.
3
+ import { execFile } from "node:child_process";
4
+ import { Effect } from "effect";
5
+ export const keychain = (service) => process.platform !== "darwin"
6
+ ? Effect.succeed(undefined)
7
+ : Effect.callback((resume) => {
8
+ const child = execFile("security", ["find-generic-password", "-s", service, "-w"], { encoding: "utf8", timeout: 10_000 }, (error, stdout) => {
9
+ const value = stdout.trim();
10
+ resume(Effect.succeed(error === null && value !== "" ? value : undefined));
11
+ });
12
+ return Effect.sync(() => void child.kill());
13
+ });
@@ -0,0 +1,2 @@
1
+ import type { SinksApi } from "./types.ts";
2
+ export declare const Sinks: SinksApi;
@@ -0,0 +1,26 @@
1
+ import { Effect } from "effect";
2
+ import { axiom, tokenService } from "./internal/axiom.js";
3
+ import { keychain } from "./internal/keychain.js";
4
+ export const Sinks = {
5
+ tokenService,
6
+ keychain,
7
+ resolve: ({ sinks, env, read = keychain }) => Effect.gen(function* () {
8
+ const active = [];
9
+ const notes = [];
10
+ const exporters = [];
11
+ for (const sink of sinks) {
12
+ if (sink.sink === "local") {
13
+ active.push("local");
14
+ continue;
15
+ }
16
+ const found = yield* axiom(sink.group, env, read);
17
+ if (found.kind === "skipped")
18
+ notes.push(found.note);
19
+ else {
20
+ exporters.push(found.exporter);
21
+ active.push(found.exporter.id);
22
+ }
23
+ }
24
+ return { secretEnv: exporters.length === 0 ? {} : { OTLP_SINKS: JSON.stringify(exporters) }, notes, active };
25
+ }),
26
+ };
@@ -0,0 +1,37 @@
1
+ import { type Effect } from "effect";
2
+ import type { SinkModel } from "@orthograph/compiler";
3
+ declare const SinksFailed_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 & {
4
+ readonly _tag: "SinksFailed";
5
+ } & Readonly<A>;
6
+ export declare class SinksFailed extends SinksFailed_base<{
7
+ readonly message: string;
8
+ }> {
9
+ }
10
+ /** The process environment, as only an entry file reads it. */
11
+ export type Env = Readonly<Record<string, string | undefined>>;
12
+ /** Where a secret is read from by its name: the machine's keychain. Injected, so a test never touches it. */
13
+ export type Reader = (service: string) => Effect.Effect<string | undefined>;
14
+ export interface Resolved {
15
+ /**
16
+ * Environment variables for the world's process and no one else's: `OTLP_SINKS` (each exporter's endpoints and
17
+ * headers, the token among them). Passed through the process environment, never a file, an argument or a log.
18
+ */
19
+ readonly secretEnv: Readonly<Record<string, string>>;
20
+ /** One line for each sink that was left out, and why. Never a value. A skipped sink is never an error. */
21
+ readonly notes: ReadonlyArray<string>;
22
+ /** The sinks that will receive telemetry, by name (`local`, `axiom capxul-test`). */
23
+ readonly active: ReadonlyArray<string>;
24
+ }
25
+ export interface SinksApi {
26
+ /** Read these sinks into what a world needs. `local` needs nothing; Axiom needs a token and an edge domain, found by name. */
27
+ readonly resolve: (options: {
28
+ readonly sinks: ReadonlyArray<SinkModel>;
29
+ readonly env: Env;
30
+ readonly read?: Reader;
31
+ }) => Effect.Effect<Resolved>;
32
+ /** The keychain service that holds an Axiom group's ingest token: `capxul-test` is `capxul-ingest-test`. */
33
+ readonly tokenService: (group: string) => string;
34
+ /** The macOS keychain: `security find-generic-password -s <name> -w`. Nothing on any other system. */
35
+ readonly keychain: Reader;
36
+ }
37
+ export {};
@@ -0,0 +1,5 @@
1
+ // Telemetry sinks, resolved for a world: the environment's `telemetry: [...]` list read into what a Worker needs to
2
+ // export to each, with every credential read by name at the moment the world starts and never kept (O1, D3 #100 to #104).
3
+ import { Data } from "effect";
4
+ export class SinksFailed extends Data.TaggedError("SinksFailed") {
5
+ }
@@ -0,0 +1,2 @@
1
+ import { type AxiomSourceApi } from "../types.ts";
2
+ export declare const AxiomSource: AxiomSourceApi;
@@ -0,0 +1,108 @@
1
+ // Axiom's query API as a TraceSource (O1, D3 #140): APL over `<group>-traces`, and `<group>-logs` for the logs of refused calls.
2
+ // The columns are the ones the live check read (D3 #121): a span's own attributes are the map `attributes.custom`, the
3
+ // resource's are `resource.custom`, `status.code` is OK / ERROR / UNSET and `_time` is when the span started.
4
+ import { Effect, Schedule } from "effect";
5
+ import { Sinks } from "#modules/sinks/service.js";
6
+ import { SourceFailed } from "../types.js";
7
+ import { arrived } from "./otlp.js";
8
+ const NAME = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/;
9
+ const HEX = /^[0-9a-f]{1,64}$/;
10
+ /** Axiom takes a span some seconds after it ended; a window that stops a little short never judges a trace still arriving. */
11
+ const LAG_SECONDS = 15;
12
+ const SPAN_LIMIT = 50_000;
13
+ const LOG_LIMIT = 10_000;
14
+ const CHUNK = 100;
15
+ const object = (v) => (typeof v === "object" && v !== null && !Array.isArray(v) ? v : {});
16
+ const text = (v) => (typeof v === "string" ? v : "");
17
+ const spanOf = (r) => ({
18
+ traceId: text(r["trace_id"]), spanId: text(r["span_id"]), parentSpanId: text(r["parent_span_id"]), name: text(r["name"]),
19
+ attrs: object(r["attributes.custom"]),
20
+ status: r["status.code"] === "OK" ? 1 : r["status.code"] === "ERROR" ? 2 : 0,
21
+ ms: Number(r["ms"]) || 0,
22
+ start: Date.parse(text(r["_time"])) || 0,
23
+ });
24
+ const logOf = (r) => ({ traceId: text(r["trace_id"]), spanId: text(r["span_id"]), body: text(r["body"]), attrs: {} });
25
+ /** Axiom's tabular answer: `fields` name the columns, each column holds that field's value for every row. */
26
+ const rowsOf = (answer) => {
27
+ const tables = object(answer)["tables"];
28
+ const table = object(Array.isArray(tables) ? tables[0] : undefined);
29
+ const fields = table["fields"] ?? [];
30
+ const columns = table["columns"] ?? [];
31
+ return (columns[0] ?? []).map((_, i) => Object.fromEntries(fields.map((f, j) => [f.name, columns[j]?.[i]])));
32
+ };
33
+ const ask = (c, apl) => Effect.tryPromise({
34
+ try: (signal) => c.fetch(`${c.base}/v1/query/_apl?format=tabular`, {
35
+ method: "POST",
36
+ headers: { authorization: `Bearer ${c.token}`, "content-type": "application/json", ...(c.org ? { "x-axiom-org-id": c.org } : {}) },
37
+ body: JSON.stringify({ apl }),
38
+ signal,
39
+ }).then((r) => r.text().then((body) => ({ status: r.status, body }))),
40
+ catch: () => new SourceFailed({ message: "Axiom's query edge didn't answer" }),
41
+ }).pipe(Effect.flatMap(({ status, body }) => status >= 300
42
+ ? Effect.fail(new SourceFailed({ message: `Axiom answered ${status} to the query: ${body.slice(0, 200)}` }))
43
+ : Effect.try({ try: () => rowsOf(JSON.parse(body)), catch: () => new SourceFailed({ message: "Axiom's answer wasn't the tabular shape" }) })));
44
+ const SPANS = "extend ms = toreal(duration / 1ms) | project name, ms, ['status.code'], _time, ['attributes.custom'], trace_id, span_id, parent_span_id";
45
+ /** Group rows into traces, then attach the logs of the traces whose calls were refused (the only logs an eval reads). */
46
+ const assemble = (c, group, spans) => Effect.gen(function* () {
47
+ const byTrace = new Map();
48
+ for (const row of spans) {
49
+ const s = spanOf(row);
50
+ (byTrace.get(s.traceId) ?? byTrace.set(s.traceId, { spans: [], logs: [] }).get(s.traceId)).spans.push(s);
51
+ }
52
+ const refused = [...byTrace].filter(([id, t]) => HEX.test(id) && t.spans.some((s) => typeof s.attrs["refusal"] === "string")).map(([id]) => id);
53
+ for (let i = 0; i < refused.length; i += CHUNK) {
54
+ const ids = refused.slice(i, i + CHUNK).map((id) => `'${id}'`).join(", ");
55
+ const logs = yield* ask(c, `['${group}-logs'] | where trace_id in (${ids}) | project body, trace_id, span_id | take ${LOG_LIMIT}`);
56
+ for (const row of logs)
57
+ byTrace.get(text(row["trace_id"]))?.logs.push(logOf(row));
58
+ }
59
+ return byTrace;
60
+ });
61
+ const sourceOf = (c, group, environment) => {
62
+ const byIds = (ids) => ask(c, `['${group}-traces'] | where trace_id in (${ids.map((id) => `'${id}'`).join(", ")}) | ${SPANS} | take ${SPAN_LIMIT}`).pipe(Effect.flatMap((rows) => assemble(c, group, rows)));
63
+ return {
64
+ window: (since) => ask(c, [
65
+ `['${group}-traces']`,
66
+ `where _time > ago(${Math.max(1, Math.ceil(since / 1000))}s) and _time < ago(${LAG_SECONDS}s)`,
67
+ `where ['resource.custom']['deployment.environment'] == '${environment}'`,
68
+ SPANS,
69
+ `take ${SPAN_LIMIT}`,
70
+ ].join(" | ")).pipe(Effect.flatMap((rows) => assemble(c, group, rows))),
71
+ find: (trace) => (HEX.test(trace) ? byIds([trace]).pipe(Effect.map((m) => m.get(trace)), Effect.orElseSucceed(() => undefined)) : Effect.succeed(undefined)),
72
+ traces: (wanted) => Effect.gen(function* () {
73
+ const ids = wanted.map((w) => w.trace).filter((id) => HEX.test(id));
74
+ let last = new Map();
75
+ // Axiom has no quiet period and its ingestion lags: an empty trace that may stay empty is believed only on a
76
+ // second look, a second later, so the late spans of a handler that ran after all are still seen.
77
+ let looks = 0;
78
+ const settled = (ids.length === 0 ? Effect.succeed(new Map()) : byIds(ids)).pipe(Effect.map((got) => {
79
+ last = got;
80
+ looks += 1;
81
+ return wanted.every((w) => arrived(got.get(w.trace), looks > 1 ? w : { ...w, mayBeEmpty: false }));
82
+ }), Effect.orElseSucceed(() => true));
83
+ yield* settled.pipe(Effect.repeat({ schedule: Schedule.spaced("1 second"), until: (done) => done }), Effect.timeoutOption("10 seconds"));
84
+ return new Map(wanted.map((w) => [w.trace, last.get(w.trace) ?? { spans: [], logs: [] }]));
85
+ }),
86
+ };
87
+ };
88
+ const baseOf = (domain) => (domain.includes("://") ? domain.replace(/\/+$/, "") : `https://${domain}`);
89
+ const read = (env, override, service, reader) => Effect.gen(function* () {
90
+ const given = env[override];
91
+ return given ? given : yield* reader(service);
92
+ });
93
+ export const AxiomSource = {
94
+ open: ({ group, environment, env, read: reader = Sinks.keychain, fetch: fetcher = fetch }) => Effect.gen(function* () {
95
+ if (!NAME.test(group))
96
+ return yield* new SourceFailed({ message: `"${group}" isn't a dataset group name` });
97
+ if (!NAME.test(environment))
98
+ return yield* new SourceFailed({ message: `"${environment}" isn't an environment name` });
99
+ const token = yield* read(env, "AXIOM_QUERY_TOKEN", "capxul-query", reader);
100
+ if (!token)
101
+ return yield* new SourceFailed({ message: "no query token for Axiom: AXIOM_QUERY_TOKEN, or the keychain item capxul-query" });
102
+ const domain = yield* read(env, "AXIOM_DOMAIN", "axiom-domain", reader);
103
+ if (!domain)
104
+ return yield* new SourceFailed({ message: "no edge domain for Axiom: AXIOM_DOMAIN, or the keychain item axiom-domain" });
105
+ const org = yield* read(env, "AXIOM_ORG_ID", "axiom-org-id", reader);
106
+ return sourceOf({ base: baseOf(domain), token, org, fetch: fetcher }, group, environment);
107
+ }),
108
+ };
@@ -0,0 +1,11 @@
1
+ import { Effect } from "effect";
2
+ import { CollectorFailed } from "../types.ts";
3
+ /** v0.164.0 of the contrib distribution, published 26 October 2026 (the version the spike and every gate ran). */
4
+ export declare const VERSION = "0.164.0";
5
+ /** SHA-256 of each platform's archive, as the release lists it (the `.sha256` asset beside each archive says the same). */
6
+ export declare const DIGESTS: Readonly<Record<string, string>>;
7
+ /** `ORTHO_CACHE_DIR`, else `$XDG_CACHE_HOME/orthograph`, else `~/.cache/orthograph`: never inside a repository. */
8
+ export declare const cacheRoot: () => string;
9
+ export declare const platform: () => string;
10
+ /** The Collector's path: `ORTHO_COLLECTOR_BIN` when set, else the cached pinned binary, fetched when it isn't there yet. */
11
+ export declare const collectorBinary: Effect.Effect<string, CollectorFailed>;
@@ -0,0 +1,66 @@
1
+ // The Collector as its pinned binary (K10 section 8): `otelcol-contrib` from the official opentelemetry-collector-releases,
2
+ // fetched once, checked against the digest pinned here and kept outside the repository, so the Mac, a sandbox and CI run
3
+ // the same file. Nothing here runs a container.
4
+ import { spawnSync } from "node:child_process";
5
+ import { createHash } from "node:crypto";
6
+ import { chmodSync, createWriteStream, existsSync, mkdirSync, readFileSync, renameSync, rmSync } from "node:fs";
7
+ import { homedir } from "node:os";
8
+ import { join } from "node:path";
9
+ import { Readable } from "node:stream";
10
+ import { pipeline } from "node:stream/promises";
11
+ import { Effect } from "effect";
12
+ import { CollectorFailed } from "../types.js";
13
+ /** v0.164.0 of the contrib distribution, published 26 October 2026 (the version the spike and every gate ran). */
14
+ export const VERSION = "0.164.0";
15
+ /** SHA-256 of each platform's archive, as the release lists it (the `.sha256` asset beside each archive says the same). */
16
+ export const DIGESTS = {
17
+ darwin_arm64: "af6a0c56886e3cc36ccebe849fa167bad2bc47a97a48fd8497a0d6f93d0cf73a",
18
+ darwin_amd64: "b53ab416e9a90625c1453692f1d3a3c4eba72904424e31516866f73064b65d4f",
19
+ linux_amd64: "f0c1ce9f661399beb4a58b711924716e08ea70c3802db0715fcfde3cbbada2d4",
20
+ linux_arm64: "8bd4a7f443405522a2175cc1a8675f9e99cc047c7181b73461efd08efbba38d3",
21
+ };
22
+ /** `ORTHO_CACHE_DIR`, else `$XDG_CACHE_HOME/orthograph`, else `~/.cache/orthograph`: never inside a repository. */
23
+ export const cacheRoot = () => process.env["ORTHO_CACHE_DIR"] ?? join(process.env["XDG_CACHE_HOME"] ?? join(homedir(), ".cache"), "orthograph");
24
+ export const platform = () => `${process.platform}_${process.arch === "x64" ? "amd64" : process.arch}`;
25
+ const releaseUrl = (kind) => `https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v${VERSION}/otelcol-contrib_${VERSION}_${kind}.tar.gz`;
26
+ const failed = (message) => new CollectorFailed({ message });
27
+ const download = (url, to) => Effect.tryPromise({
28
+ try: () => fetch(url).then((response) => response.ok && response.body !== null ? pipeline(Readable.fromWeb(response.body), createWriteStream(to)) : Promise.reject(new Error(`${response.status}`))),
29
+ catch: (e) => failed(`couldn't fetch the collector from ${url}: ${e instanceof Error ? e.message : "failed"}`),
30
+ });
31
+ /** Fetch, verify and unpack into a folder of our own, then move it into place: two processes asking at once both end with one good copy. */
32
+ const install = (kind, folder) => Effect.gen(function* () {
33
+ const wanted = DIGESTS[kind];
34
+ if (wanted === undefined)
35
+ return yield* failed(`no pinned collector for ${kind}: set ORTHO_COLLECTOR_BIN to one`);
36
+ const scratch = `${folder}.tmp-${process.pid}-${Math.floor(Math.random() * 1e9)}`;
37
+ yield* Effect.addFinalizer(() => Effect.sync(() => rmSync(scratch, { recursive: true, force: true })));
38
+ mkdirSync(scratch, { recursive: true });
39
+ const archive = join(scratch, "archive.tar.gz");
40
+ yield* download(releaseUrl(kind), archive);
41
+ const got = createHash("sha256").update(readFileSync(archive)).digest("hex");
42
+ if (got !== wanted)
43
+ return yield* failed(`the collector archive for ${kind} has digest ${got}, not the pinned ${wanted}: it was not used`);
44
+ const unpacked = spawnSync("tar", ["-xzf", archive, "-C", scratch, "otelcol-contrib"], { encoding: "utf8" });
45
+ if (unpacked.status !== 0)
46
+ return yield* failed(`couldn't unpack the collector: ${unpacked.stderr.trim()}`);
47
+ rmSync(archive);
48
+ chmodSync(join(scratch, "otelcol-contrib"), 0o755);
49
+ yield* Effect.try({ try: () => renameSync(scratch, folder), catch: () => failed("couldn't place the collector") }).pipe(
50
+ // Someone else placed it first: theirs is the same verified file.
51
+ Effect.catch((e) => (existsSync(join(folder, "otelcol-contrib")) ? Effect.void : Effect.fail(e))));
52
+ }).pipe(Effect.scoped);
53
+ /** The Collector's path: `ORTHO_COLLECTOR_BIN` when set, else the cached pinned binary, fetched when it isn't there yet. */
54
+ export const collectorBinary = Effect.gen(function* () {
55
+ const given = process.env["ORTHO_COLLECTOR_BIN"];
56
+ if (given !== undefined && given !== "")
57
+ return existsSync(given) ? given : yield* failed(`ORTHO_COLLECTOR_BIN names ${given}, which isn't there`);
58
+ const kind = platform();
59
+ const folder = join(cacheRoot(), "otelcol-contrib", VERSION, kind);
60
+ const binary = join(folder, "otelcol-contrib");
61
+ if (!existsSync(binary)) {
62
+ mkdirSync(join(cacheRoot(), "otelcol-contrib", VERSION), { recursive: true });
63
+ yield* install(kind, folder);
64
+ }
65
+ return binary;
66
+ });
@@ -0,0 +1,13 @@
1
+ /** What a collector is started with: attribute keys to delete (L2.P), where it listens and where it writes. */
2
+ export interface CollectorOptions {
3
+ readonly strip: ReadonlyArray<string>;
4
+ readonly port: number;
5
+ readonly dir: string;
6
+ }
7
+ /**
8
+ * Every pipeline first drops the person the agent SDK's records name (`user.*`, `organization.id`), then, with `strip`
9
+ * keys, deletes each from every span and log record (L2.P: the second guard behind the runtime's allowlist), before any
10
+ * exporter sees it. The Collector's own metrics server is off: two collectors on one machine would fight for its port.
11
+ * Keys are written as JSON strings, which YAML reads as the same string.
12
+ */
13
+ export declare const collectorConfig: ({ strip, port, dir }: CollectorOptions) => string;
@@ -0,0 +1,22 @@
1
+ // The Collector's config: written as a file next to what it writes, read from there by the process.
2
+ /**
3
+ * Every pipeline first drops the person the agent SDK's records name (`user.*`, `organization.id`), then, with `strip`
4
+ * keys, deletes each from every span and log record (L2.P: the second guard behind the runtime's allowlist), before any
5
+ * exporter sees it. The Collector's own metrics server is off: two collectors on one machine would fight for its port.
6
+ * Keys are written as JSON strings, which YAML reads as the same string.
7
+ */
8
+ export const collectorConfig = ({ strip, port, dir }) => {
9
+ const chain = ["attributes/personal", "resource/personal", ...(strip.length > 0 ? ["attributes/private"] : [])];
10
+ return [
11
+ "receivers:", " otlp:", " protocols:", " http:", ` endpoint: 127.0.0.1:${port}`,
12
+ "processors:",
13
+ " attributes/personal:", " actions:", " - { pattern: '^(user\\..*|organization\\.id)$', action: delete }",
14
+ " resource/personal:", " attributes:", " - { pattern: '^(user\\..*|organization\\.id)$', action: delete }",
15
+ ...(strip.length > 0 ? [" attributes/private:", " actions:", ...strip.flatMap((k) => [` - key: ${JSON.stringify(k)}`, " action: delete"])] : []),
16
+ "exporters:",
17
+ ...["traces", "logs", "metrics"].flatMap((signal) => [` file/${signal}:`, ` path: ${JSON.stringify(`${dir}/${signal}.jsonl`)}`, " flush_interval: 10ms"]),
18
+ "service:", " telemetry:", " metrics:", " level: none", " pipelines:",
19
+ ...["traces", "logs", "metrics"].map((signal) => ` ${signal}: { receivers: [otlp], processors: [${chain.join(", ")}], exporters: [file/${signal}] }`),
20
+ "",
21
+ ].join("\n");
22
+ };
@@ -0,0 +1,2 @@
1
+ import { type MetricsSource } from "../types.ts";
2
+ export declare const fileMetrics: (dirs: ReadonlyArray<string>) => MetricsSource;