@elie-laloum/outpost 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (300) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/adapters/agents/claude-diagnostics.d.ts +1 -0
  3. package/dist/adapters/agents/claude-diagnostics.js +7 -0
  4. package/dist/adapters/agents/claude-diagnostics.js.map +1 -0
  5. package/dist/adapters/agents/cli-diagnostics.constants.d.ts +12 -0
  6. package/dist/adapters/agents/cli-diagnostics.constants.js +24 -0
  7. package/dist/adapters/agents/cli-diagnostics.constants.js.map +1 -0
  8. package/dist/adapters/agents/cli-diagnostics.d.ts +4 -0
  9. package/dist/adapters/agents/cli-diagnostics.js +14 -0
  10. package/dist/adapters/agents/cli-diagnostics.js.map +1 -0
  11. package/dist/adapters/agents/cli-diagnostics.types.d.ts +13 -0
  12. package/dist/adapters/agents/cli-diagnostics.types.js +2 -0
  13. package/dist/adapters/agents/cli-diagnostics.types.js.map +1 -0
  14. package/dist/adapters/agents/codex-diagnostics.d.ts +1 -0
  15. package/dist/adapters/agents/codex-diagnostics.js +7 -0
  16. package/dist/adapters/agents/codex-diagnostics.js.map +1 -0
  17. package/dist/adapters/agents/protocol-fixtures.constants.d.ts +2 -0
  18. package/dist/adapters/agents/protocol-fixtures.constants.js +68 -0
  19. package/dist/adapters/agents/protocol-fixtures.constants.js.map +1 -0
  20. package/dist/adapters/agents/protocol-fixtures.types.d.ts +6 -0
  21. package/dist/adapters/agents/protocol-fixtures.types.js +2 -0
  22. package/dist/adapters/agents/protocol-fixtures.types.js.map +1 -0
  23. package/dist/application/diagnostic-probe.d.ts +3 -0
  24. package/dist/application/diagnostic-probe.js +55 -0
  25. package/dist/application/diagnostic-probe.js.map +1 -0
  26. package/dist/application/doctor-agent.constants.d.ts +9 -0
  27. package/dist/application/doctor-agent.constants.js +8 -0
  28. package/dist/application/doctor-agent.constants.js.map +1 -0
  29. package/dist/application/doctor-agent.d.ts +3 -0
  30. package/dist/application/doctor-agent.js +53 -0
  31. package/dist/application/doctor-agent.js.map +1 -0
  32. package/dist/application/doctor-image.d.ts +3 -0
  33. package/dist/application/doctor-image.js +133 -0
  34. package/dist/application/doctor-image.js.map +1 -0
  35. package/dist/application/doctor-protocol.d.ts +3 -0
  36. package/dist/application/doctor-protocol.js +29 -0
  37. package/dist/application/doctor-protocol.js.map +1 -0
  38. package/dist/application/doctor-protocol.types.d.ts +10 -0
  39. package/dist/application/doctor-protocol.types.js +2 -0
  40. package/dist/application/doctor-protocol.types.js.map +1 -0
  41. package/dist/application/doctor-sandbox.constants.d.ts +5 -0
  42. package/dist/application/doctor-sandbox.constants.js +6 -0
  43. package/dist/application/doctor-sandbox.constants.js.map +1 -0
  44. package/dist/application/doctor-sandbox.d.ts +4 -0
  45. package/dist/application/doctor-sandbox.js +133 -0
  46. package/dist/application/doctor-sandbox.js.map +1 -0
  47. package/dist/application/doctor-sandbox.types.d.ts +23 -0
  48. package/dist/application/doctor-sandbox.types.js +2 -0
  49. package/dist/application/doctor-sandbox.types.js.map +1 -0
  50. package/dist/application/doctor-transfers.constants.d.ts +6 -0
  51. package/dist/application/doctor-transfers.constants.js +7 -0
  52. package/dist/application/doctor-transfers.constants.js.map +1 -0
  53. package/dist/application/doctor-transfers.d.ts +4 -0
  54. package/dist/application/doctor-transfers.js +88 -0
  55. package/dist/application/doctor-transfers.js.map +1 -0
  56. package/dist/application/doctor.constants.d.ts +9 -0
  57. package/dist/application/doctor.constants.js +15 -0
  58. package/dist/application/doctor.constants.js.map +1 -0
  59. package/dist/application/doctor.d.ts +3 -0
  60. package/dist/application/doctor.js +106 -0
  61. package/dist/application/doctor.js.map +1 -0
  62. package/dist/application/doctor.types.d.ts +39 -0
  63. package/dist/application/doctor.types.js +2 -0
  64. package/dist/application/doctor.types.js.map +1 -0
  65. package/dist/application/execution.js +1 -0
  66. package/dist/application/execution.js.map +1 -1
  67. package/dist/application/outpost.types.d.ts +2 -0
  68. package/dist/application/outpost.types.js.map +1 -1
  69. package/dist/application/recovery-checksum-capture.d.ts +2 -0
  70. package/dist/application/recovery-checksum-capture.js +32 -0
  71. package/dist/application/recovery-checksum-capture.js.map +1 -0
  72. package/dist/application/recovery-checksum-paths.d.ts +2 -0
  73. package/dist/application/recovery-checksum-paths.js +11 -0
  74. package/dist/application/recovery-checksum-paths.js.map +1 -0
  75. package/dist/application/recovery-checksums.constants.d.ts +5 -0
  76. package/dist/application/recovery-checksums.constants.js +6 -0
  77. package/dist/application/recovery-checksums.constants.js.map +1 -0
  78. package/dist/application/recovery-checksums.d.ts +3 -0
  79. package/dist/application/recovery-checksums.js +94 -0
  80. package/dist/application/recovery-checksums.js.map +1 -0
  81. package/dist/application/recovery-checksums.types.d.ts +17 -0
  82. package/dist/application/recovery-checksums.types.js +2 -0
  83. package/dist/application/recovery-checksums.types.js.map +1 -0
  84. package/dist/application/recovery-inspection.d.ts +2 -0
  85. package/dist/application/recovery-inspection.js +27 -0
  86. package/dist/application/recovery-inspection.js.map +1 -0
  87. package/dist/application/recovery-inspection.types.d.ts +15 -0
  88. package/dist/application/recovery-inspection.types.js +2 -0
  89. package/dist/application/recovery-inspection.types.js.map +1 -0
  90. package/dist/application/recovery-restorability.d.ts +2 -0
  91. package/dist/application/recovery-restorability.js +137 -0
  92. package/dist/application/recovery-restorability.js.map +1 -0
  93. package/dist/application/recovery-retention-policy.d.ts +2 -0
  94. package/dist/application/recovery-retention-policy.js +21 -0
  95. package/dist/application/recovery-retention-policy.js.map +1 -0
  96. package/dist/application/recovery-retention.constants.d.ts +3 -0
  97. package/dist/application/recovery-retention.constants.js +2 -0
  98. package/dist/application/recovery-retention.constants.js.map +1 -0
  99. package/dist/application/recovery-retention.d.ts +4 -0
  100. package/dist/application/recovery-retention.js +202 -0
  101. package/dist/application/recovery-retention.js.map +1 -0
  102. package/dist/application/recovery-retention.types.d.ts +52 -0
  103. package/dist/application/recovery-retention.types.js +2 -0
  104. package/dist/application/recovery-retention.types.js.map +1 -0
  105. package/dist/application/recovery-verification.constants.d.ts +5 -0
  106. package/dist/application/recovery-verification.constants.js +10 -0
  107. package/dist/application/recovery-verification.constants.js.map +1 -0
  108. package/dist/application/recovery-verification.d.ts +2 -0
  109. package/dist/application/recovery-verification.js +107 -0
  110. package/dist/application/recovery-verification.js.map +1 -0
  111. package/dist/application/recovery-verification.types.d.ts +26 -0
  112. package/dist/application/recovery-verification.types.js +2 -0
  113. package/dist/application/recovery-verification.types.js.map +1 -0
  114. package/dist/application/remote-apply.js +24 -6
  115. package/dist/application/remote-apply.js.map +1 -1
  116. package/dist/application/remote-backup.js +6 -2
  117. package/dist/application/remote-backup.js.map +1 -1
  118. package/dist/application/remote-download.js +36 -4
  119. package/dist/application/remote-download.js.map +1 -1
  120. package/dist/application/remote-validation.js +19 -0
  121. package/dist/application/remote-validation.js.map +1 -1
  122. package/dist/application/remote-workspace.constants.d.ts +3 -0
  123. package/dist/application/remote-workspace.constants.js +2 -0
  124. package/dist/application/remote-workspace.constants.js.map +1 -0
  125. package/dist/application/remote-workspace.js +6 -0
  126. package/dist/application/remote-workspace.js.map +1 -1
  127. package/dist/application/remote-workspace.types.d.ts +3 -1
  128. package/dist/application/remote-workspace.types.js.map +1 -1
  129. package/dist/application/sandbox.js +11 -0
  130. package/dist/application/sandbox.js.map +1 -1
  131. package/dist/application/task-usage.d.ts +4 -0
  132. package/dist/application/task-usage.js +41 -0
  133. package/dist/application/task-usage.js.map +1 -0
  134. package/dist/application/task-usage.types.d.ts +5 -0
  135. package/dist/application/task-usage.types.js +2 -0
  136. package/dist/application/task-usage.types.js.map +1 -0
  137. package/dist/application/tasks.js +23 -2
  138. package/dist/application/tasks.js.map +1 -1
  139. package/dist/cli/commands.js +4 -0
  140. package/dist/cli/commands.js.map +1 -1
  141. package/dist/cli/doctor-command.d.ts +3 -0
  142. package/dist/cli/doctor-command.js +38 -0
  143. package/dist/cli/doctor-command.js.map +1 -0
  144. package/dist/cli/main.constants.d.ts +28 -1
  145. package/dist/cli/main.constants.js +15 -0
  146. package/dist/cli/main.constants.js.map +1 -1
  147. package/dist/cli/recovery-command.d.ts +2 -0
  148. package/dist/cli/recovery-command.js +69 -0
  149. package/dist/cli/recovery-command.js.map +1 -0
  150. package/dist/cli/recovery-prune-command.d.ts +2 -0
  151. package/dist/cli/recovery-prune-command.js +34 -0
  152. package/dist/cli/recovery-prune-command.js.map +1 -0
  153. package/dist/cli/recovery-verify-command.d.ts +2 -0
  154. package/dist/cli/recovery-verify-command.js +43 -0
  155. package/dist/cli/recovery-verify-command.js.map +1 -0
  156. package/dist/domain/ports.d.ts +1 -1
  157. package/dist/domain/ports.js.map +1 -1
  158. package/dist/domain/sandbox.types.d.ts +12 -0
  159. package/dist/domain/sandbox.types.js.map +1 -1
  160. package/dist/domain/workflow/budget.constants.d.ts +1 -0
  161. package/dist/domain/workflow/budget.constants.js +7 -0
  162. package/dist/domain/workflow/budget.constants.js.map +1 -0
  163. package/dist/domain/workflow/budget.d.ts +9 -0
  164. package/dist/domain/workflow/budget.js +67 -0
  165. package/dist/domain/workflow/budget.js.map +1 -0
  166. package/dist/domain/workflow/budget.types.d.ts +15 -0
  167. package/dist/domain/workflow/budget.types.js +2 -0
  168. package/dist/domain/workflow/budget.types.js.map +1 -0
  169. package/dist/domain/workflow/task-runner.js +8 -1
  170. package/dist/domain/workflow/task-runner.js.map +1 -1
  171. package/dist/domain/workflow/workflow-scheduler.js +4 -2
  172. package/dist/domain/workflow/workflow-scheduler.js.map +1 -1
  173. package/dist/domain/workflow/workflow-state.js +29 -0
  174. package/dist/domain/workflow/workflow-state.js.map +1 -1
  175. package/dist/domain/workflow.d.ts +2 -0
  176. package/dist/domain/workflow.js +1 -0
  177. package/dist/domain/workflow.js.map +1 -1
  178. package/dist/domain/workflow.types.d.ts +10 -1
  179. package/dist/domain/workflow.types.js.map +1 -1
  180. package/dist/index.d.ts +12 -3
  181. package/dist/index.js +5 -1
  182. package/dist/index.js.map +1 -1
  183. package/dist/infrastructure/file-manifest.d.ts +6 -0
  184. package/dist/infrastructure/file-manifest.js +91 -0
  185. package/dist/infrastructure/file-manifest.js.map +1 -0
  186. package/dist/infrastructure/git/lock-inspection.constants.d.ts +4 -0
  187. package/dist/infrastructure/git/lock-inspection.constants.js +5 -0
  188. package/dist/infrastructure/git/lock-inspection.constants.js.map +1 -0
  189. package/dist/infrastructure/git/lock-inspection.d.ts +3 -0
  190. package/dist/infrastructure/git/lock-inspection.js +64 -0
  191. package/dist/infrastructure/git/lock-inspection.js.map +1 -0
  192. package/dist/infrastructure/git/lock-inspection.types.d.ts +27 -0
  193. package/dist/infrastructure/git/lock-inspection.types.js +2 -0
  194. package/dist/infrastructure/git/lock-inspection.types.js.map +1 -0
  195. package/dist/infrastructure/git/lock.d.ts +1 -0
  196. package/dist/infrastructure/git/lock.js +70 -29
  197. package/dist/infrastructure/git/lock.js.map +1 -1
  198. package/dist/infrastructure/git/process-identity.d.ts +3 -0
  199. package/dist/infrastructure/git/process-identity.js +73 -0
  200. package/dist/infrastructure/git/process-identity.js.map +1 -0
  201. package/dist/infrastructure/git/process-identity.types.d.ts +10 -0
  202. package/dist/infrastructure/git/process-identity.types.js +2 -0
  203. package/dist/infrastructure/git/process-identity.types.js.map +1 -0
  204. package/dist/infrastructure/git/verification-command.d.ts +1 -0
  205. package/dist/infrastructure/git/verification-command.js +36 -0
  206. package/dist/infrastructure/git/verification-command.js.map +1 -0
  207. package/dist/infrastructure/git/workspace-lease.js +1 -0
  208. package/dist/infrastructure/git/workspace-lease.js.map +1 -1
  209. package/dist/infrastructure/git/workspace.js +5 -1
  210. package/dist/infrastructure/git/workspace.js.map +1 -1
  211. package/dist/infrastructure/git/worktree-inspection.constants.d.ts +5 -0
  212. package/dist/infrastructure/git/worktree-inspection.constants.js +16 -0
  213. package/dist/infrastructure/git/worktree-inspection.constants.js.map +1 -0
  214. package/dist/infrastructure/git/worktree-inspection.d.ts +3 -0
  215. package/dist/infrastructure/git/worktree-inspection.js +120 -0
  216. package/dist/infrastructure/git/worktree-inspection.js.map +1 -0
  217. package/dist/infrastructure/git/worktree-inspection.types.d.ts +19 -0
  218. package/dist/infrastructure/git/worktree-inspection.types.js +2 -0
  219. package/dist/infrastructure/git/worktree-inspection.types.js.map +1 -0
  220. package/dist/infrastructure/inspection-file.constants.d.ts +1 -0
  221. package/dist/infrastructure/inspection-file.constants.js +5 -0
  222. package/dist/infrastructure/inspection-file.constants.js.map +1 -0
  223. package/dist/infrastructure/inspection-file.d.ts +1 -0
  224. package/dist/infrastructure/inspection-file.js +43 -0
  225. package/dist/infrastructure/inspection-file.js.map +1 -0
  226. package/dist/infrastructure/inspection-hash.constants.d.ts +1 -0
  227. package/dist/infrastructure/inspection-hash.constants.js +2 -0
  228. package/dist/infrastructure/inspection-hash.constants.js.map +1 -0
  229. package/dist/infrastructure/inspection-hash.d.ts +2 -0
  230. package/dist/infrastructure/inspection-hash.js +62 -0
  231. package/dist/infrastructure/inspection-hash.js.map +1 -0
  232. package/dist/infrastructure/inspection-hash.types.d.ts +5 -0
  233. package/dist/infrastructure/inspection-hash.types.js +2 -0
  234. package/dist/infrastructure/inspection-hash.types.js.map +1 -0
  235. package/dist/infrastructure/journal-retention.constants.d.ts +4 -0
  236. package/dist/infrastructure/journal-retention.constants.js +5 -0
  237. package/dist/infrastructure/journal-retention.constants.js.map +1 -0
  238. package/dist/infrastructure/journal-retention.d.ts +2 -0
  239. package/dist/infrastructure/journal-retention.js +51 -0
  240. package/dist/infrastructure/journal-retention.js.map +1 -0
  241. package/dist/infrastructure/journal.js +37 -13
  242. package/dist/infrastructure/journal.js.map +1 -1
  243. package/dist/infrastructure/opentelemetry.constants.d.ts +10 -0
  244. package/dist/infrastructure/opentelemetry.constants.js +11 -0
  245. package/dist/infrastructure/opentelemetry.constants.js.map +1 -0
  246. package/dist/infrastructure/opentelemetry.d.ts +3 -0
  247. package/dist/infrastructure/opentelemetry.js +131 -0
  248. package/dist/infrastructure/opentelemetry.js.map +1 -0
  249. package/dist/infrastructure/opentelemetry.types.d.ts +21 -0
  250. package/dist/infrastructure/opentelemetry.types.js +2 -0
  251. package/dist/infrastructure/opentelemetry.types.js.map +1 -0
  252. package/dist/infrastructure/storage-inventory.constants.d.ts +6 -0
  253. package/dist/infrastructure/storage-inventory.constants.js +11 -0
  254. package/dist/infrastructure/storage-inventory.constants.js.map +1 -0
  255. package/dist/infrastructure/storage-inventory.d.ts +2 -0
  256. package/dist/infrastructure/storage-inventory.js +123 -0
  257. package/dist/infrastructure/storage-inventory.js.map +1 -0
  258. package/dist/infrastructure/storage-inventory.types.d.ts +38 -0
  259. package/dist/infrastructure/storage-inventory.types.js +2 -0
  260. package/dist/infrastructure/storage-inventory.types.js.map +1 -0
  261. package/dist/infrastructure/transfer.js +12 -0
  262. package/dist/infrastructure/transfer.js.map +1 -1
  263. package/dist/providers/cloud.constants.d.ts +1 -0
  264. package/dist/providers/cloud.constants.js +1 -0
  265. package/dist/providers/cloud.constants.js.map +1 -1
  266. package/dist/providers/container-cache.constants.d.ts +11 -0
  267. package/dist/providers/container-cache.constants.js +9 -0
  268. package/dist/providers/container-cache.constants.js.map +1 -0
  269. package/dist/providers/container-cache.d.ts +4 -0
  270. package/dist/providers/container-cache.js +48 -0
  271. package/dist/providers/container-cache.js.map +1 -0
  272. package/dist/providers/container-cache.types.d.ts +8 -0
  273. package/dist/providers/container-cache.types.js +2 -0
  274. package/dist/providers/container-cache.types.js.map +1 -0
  275. package/dist/providers/container-plan.js +3 -1
  276. package/dist/providers/container-plan.js.map +1 -1
  277. package/dist/providers/container.js +31 -1
  278. package/dist/providers/container.js.map +1 -1
  279. package/dist/providers/container.types.d.ts +2 -0
  280. package/dist/providers/container.types.js.map +1 -1
  281. package/dist/providers/daytona-command.js +7 -4
  282. package/dist/providers/daytona-command.js.map +1 -1
  283. package/dist/providers/daytona.js +13 -4
  284. package/dist/providers/daytona.js.map +1 -1
  285. package/dist/providers/diagnostic-container.d.ts +4 -0
  286. package/dist/providers/diagnostic-container.js +15 -0
  287. package/dist/providers/diagnostic-container.js.map +1 -0
  288. package/dist/providers/docker.d.ts +1 -0
  289. package/dist/providers/docker.js.map +1 -1
  290. package/dist/providers/file-batches.constants.d.ts +10 -0
  291. package/dist/providers/file-batches.constants.js +57 -0
  292. package/dist/providers/file-batches.constants.js.map +1 -0
  293. package/dist/providers/file-batches.d.ts +2 -0
  294. package/dist/providers/file-batches.js +151 -0
  295. package/dist/providers/file-batches.js.map +1 -0
  296. package/dist/providers/podman.d.ts +1 -0
  297. package/dist/providers/podman.js.map +1 -1
  298. package/dist/providers/vercel.js +3 -1
  299. package/dist/providers/vercel.js.map +1 -1
  300. package/package.json +12 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inspection-file.constants.js","sourceRoot":"","sources":["../../src/infrastructure/inspection-file.constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC,MAAM,CAAC,MAAM,mBAAmB,GAC9B,SAAS,CAAC,QAAQ;IAClB,CAAC,SAAS,CAAC,UAAU,IAAI,CAAC,CAAC;IAC3B,CAAC,SAAS,CAAC,UAAU,IAAI,CAAC,CAAC,CAAC","sourcesContent":["import { constants } from \"node:fs\";\n\nexport const inspectionFileFlags =\n constants.O_RDONLY |\n (constants.O_NOFOLLOW ?? 0) |\n (constants.O_NONBLOCK ?? 0);\n"]}
@@ -0,0 +1 @@
1
+ export declare function readInspectionFile(path: string, maxBytes: number): Promise<Buffer>;
@@ -0,0 +1,43 @@
1
+ import { lstat, open, realpath } from "node:fs/promises";
2
+ import { resolve } from "node:path";
3
+ import { positive } from "../domain/errors.js";
4
+ import { inspectionFileFlags } from "./inspection-file.constants.js";
5
+ function unchanged(before, after) {
6
+ return (before.dev === after.dev &&
7
+ before.ino === after.ino &&
8
+ before.size === after.size &&
9
+ before.mtimeMs === after.mtimeMs &&
10
+ before.ctimeMs === after.ctimeMs);
11
+ }
12
+ export async function readInspectionFile(path, maxBytes) {
13
+ positive(maxBytes, "maxBytes");
14
+ const before = await lstat(path);
15
+ if (!before.isFile() || (await realpath(path)) !== resolve(path))
16
+ throw new Error("Inspection path changed");
17
+ if (before.size > maxBytes)
18
+ throw new Error("Inspection file is too large");
19
+ const file = await open(path, inspectionFileFlags);
20
+ try {
21
+ const opened = await file.stat();
22
+ if (!opened.isFile() || !unchanged(before, opened))
23
+ throw new Error("Inspection file changed");
24
+ const buffer = Buffer.alloc(maxBytes + 1);
25
+ let length = 0;
26
+ while (length < buffer.length) {
27
+ const { bytesRead } = await file.read(buffer, length, buffer.length - length, length);
28
+ if (!bytesRead)
29
+ break;
30
+ length += bytesRead;
31
+ }
32
+ if (length > maxBytes)
33
+ throw new Error("Inspection file is too large");
34
+ if (!unchanged(opened, await file.stat()) ||
35
+ !unchanged(opened, await lstat(path)))
36
+ throw new Error("Inspection file changed");
37
+ return buffer.subarray(0, length);
38
+ }
39
+ finally {
40
+ await file.close();
41
+ }
42
+ }
43
+ //# sourceMappingURL=inspection-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inspection-file.js","sourceRoot":"","sources":["../../src/infrastructure/inspection-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAErE,SAAS,SAAS,CAAC,MAAa,EAAE,KAAY;IAC5C,OAAO,CACL,MAAM,CAAC,GAAG,KAAK,KAAK,CAAC,GAAG;QACxB,MAAM,CAAC,GAAG,KAAK,KAAK,CAAC,GAAG;QACxB,MAAM,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI;QAC1B,MAAM,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO;QAChC,MAAM,CAAC,OAAO,KAAK,KAAK,C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CAAC,CAAC;QACvE,IACE,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;YACrC,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC;YAErC,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAC7C,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IACpC,CAAC;YAAS,CAAC;QACT,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;AACH,CAAC","sourcesContent":["import { lstat, open, realpath } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport type { Stats } from \"node:fs\";\nimport { positive } from \"../domain/errors.ts\";\nimport { inspectionFileFlags } from \"./inspection-file.constants.ts\";\n\nfunction unchanged(before: Stats, after: Stats): boolean {\n return (\n before.dev === after.dev &&\n before.ino === after.ino &&\n before.size === after.size &&\n before.mtimeMs === after.mtimeMs &&\n before.ctimeMs === after.ctimeMs\n );\n}\n\nexport async function readInspectionFile(\n path: string,\n maxBytes: number,\n): Promise<Buffer> {\n positive(maxBytes, \"maxBytes\");\n const before = await lstat(path);\n if (!before.isFile() || (await realpath(path)) !== resolve(path))\n throw new Error(\"Inspection path changed\");\n if (before.size > maxBytes) throw new Error(\"Inspection file is too large\");\n const file = await open(path, inspectionFileFlags);\n try {\n const opened = await file.stat();\n if (!opened.isFile() || !unchanged(before, opened))\n throw new Error(\"Inspection file changed\");\n const buffer = Buffer.alloc(maxBytes + 1);\n let length = 0;\n while (length < buffer.length) {\n const { bytesRead } = await file.read(\n buffer,\n length,\n buffer.length - length,\n length,\n );\n if (!bytesRead) break;\n length += bytesRead;\n }\n if (length > maxBytes) throw new Error(\"Inspection file is too large\");\n if (\n !unchanged(opened, await file.stat()) ||\n !unchanged(opened, await lstat(path))\n )\n throw new Error(\"Inspection file changed\");\n return buffer.subarray(0, length);\n } finally {\n await file.close();\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ export declare const inspectionHashChunkBytes = 65536;
@@ -0,0 +1,2 @@
1
+ export const inspectionHashChunkBytes = 65_536;
2
+ //# sourceMappingURL=inspection-hash.constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inspection-hash.constants.js","sourceRoot":"","sources":["../../src/infrastructure/inspection-hash.constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC","sourcesContent":["export const inspectionHashChunkBytes = 65_536;\n"]}
@@ -0,0 +1,2 @@
1
+ import type { InspectionHash } from "./inspection-hash.types.ts";
2
+ export declare function hashInspectionEntry(path: string, maxBytes?: number): Promise<InspectionHash>;
@@ -0,0 +1,62 @@
1
+ import { createHash } from "node:crypto";
2
+ import { lstat, open, readlink, realpath } from "node:fs/promises";
3
+ import { dirname, resolve } from "node:path";
4
+ import { OutpostError } from "../domain/errors.js";
5
+ import { inspectionFileFlags } from "./inspection-file.constants.js";
6
+ import { inspectionHashChunkBytes } from "./inspection-hash.constants.js";
7
+ function unchanged(before, after) {
8
+ return (before.dev === after.dev &&
9
+ before.ino === after.ino &&
10
+ before.size === after.size &&
11
+ before.mtimeMs === after.mtimeMs &&
12
+ before.ctimeMs === after.ctimeMs);
13
+ }
14
+ export async function hashInspectionEntry(path, maxBytes = Number.MAX_SAFE_INTEGER) {
15
+ const before = await lstat(path);
16
+ if ((await realpath(dirname(path))) !== resolve(dirname(path)))
17
+ throw new Error("Hash path traverses a symlink");
18
+ const hash = createHash("sha256");
19
+ if (before.isSymbolicLink()) {
20
+ const target = await readlink(path, { encoding: "buffer" });
21
+ if (target.length > maxBytes)
22
+ throw new OutpostError("workspace", "Checksum byte limit exceeded", {
23
+ reason: "CHECKSUM_LIMIT",
24
+ });
25
+ if (!unchanged(before, await lstat(path)))
26
+ throw new Error("Hash source changed");
27
+ return {
28
+ kind: "symlink",
29
+ bytes: target.length,
30
+ sha256: hash.update(target).digest("hex"),
31
+ };
32
+ }
33
+ if (!before.isFile())
34
+ throw new Error("Hash source is not a regular file");
35
+ if (before.size > maxBytes)
36
+ throw new OutpostError("workspace", "Checksum byte limit exceeded", {
37
+ reason: "CHECKSUM_LIMIT",
38
+ });
39
+ const file = await open(path, inspectionFileFlags);
40
+ try {
41
+ const opened = await file.stat();
42
+ if (!opened.isFile() || !unchanged(before, opened))
43
+ throw new Error("Hash source changed");
44
+ const buffer = Buffer.alloc(inspectionHashChunkBytes);
45
+ let bytes = 0;
46
+ while (bytes < opened.size) {
47
+ const result = await file.read(buffer, 0, Math.min(buffer.length, opened.size - bytes), bytes);
48
+ if (!result.bytesRead)
49
+ throw new Error("Hash source truncated");
50
+ bytes += result.bytesRead;
51
+ hash.update(buffer.subarray(0, result.bytesRead));
52
+ }
53
+ if (!unchanged(opened, await file.stat()) ||
54
+ !unchanged(opened, await lstat(path)))
55
+ throw new Error("Hash source changed");
56
+ return { kind: "file", bytes, sha256: hash.digest("hex") };
57
+ }
58
+ finally {
59
+ await file.close();
60
+ }
61
+ }
62
+ //# sourceMappingURL=inspection-hash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inspection-hash.js","sourceRoot":"","sources":["../../src/infrastructure/inspection-hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAG1E,SAAS,SAAS,CAAC,MAAa,EAAE,KAAY;IAC5C,OAAO,CACL,MAAM,CAAC,GAAG,KAAK,KAAK,CAAC,GAAG;Q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YAErC,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACzC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;IAC7D,CAAC;YAAS,CAAC;QACT,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;AACH,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { lstat, open, readlink, realpath } from \"node:fs/promises\";\nimport { dirname, resolve } from \"node:path\";\nimport type { Stats } from \"node:fs\";\nimport { OutpostError } from \"../domain/errors.ts\";\nimport { inspectionFileFlags } from \"./inspection-file.constants.ts\";\nimport { inspectionHashChunkBytes } from \"./inspection-hash.constants.ts\";\nimport type { InspectionHash } from \"./inspection-hash.types.ts\";\n\nfunction unchanged(before: Stats, after: Stats): boolean {\n return (\n before.dev === after.dev &&\n before.ino === after.ino &&\n before.size === after.size &&\n before.mtimeMs === after.mtimeMs &&\n before.ctimeMs === after.ctimeMs\n );\n}\n\nexport async function hashInspectionEntry(\n path: string,\n maxBytes = Number.MAX_SAFE_INTEGER,\n): Promise<InspectionHash> {\n const before = await lstat(path);\n if ((await realpath(dirname(path))) !== resolve(dirname(path)))\n throw new Error(\"Hash path traverses a symlink\");\n const hash = createHash(\"sha256\");\n if (before.isSymbolicLink()) {\n const target = await readlink(path, { encoding: \"buffer\" });\n if (target.length > maxBytes)\n throw new OutpostError(\"workspace\", \"Checksum byte limit exceeded\", {\n reason: \"CHECKSUM_LIMIT\",\n });\n if (!unchanged(before, await lstat(path)))\n throw new Error(\"Hash source changed\");\n return {\n kind: \"symlink\",\n bytes: target.length,\n sha256: hash.update(target).digest(\"hex\"),\n };\n }\n if (!before.isFile()) throw new Error(\"Hash source is not a regular file\");\n if (before.size > maxBytes)\n throw new OutpostError(\"workspace\", \"Checksum byte limit exceeded\", {\n reason: \"CHECKSUM_LIMIT\",\n });\n const file = await open(path, inspectionFileFlags);\n try {\n const opened = await file.stat();\n if (!opened.isFile() || !unchanged(before, opened))\n throw new Error(\"Hash source changed\");\n const buffer = Buffer.alloc(inspectionHashChunkBytes);\n let bytes = 0;\n while (bytes < opened.size) {\n const result = await file.read(\n buffer,\n 0,\n Math.min(buffer.length, opened.size - bytes),\n bytes,\n );\n if (!result.bytesRead) throw new Error(\"Hash source truncated\");\n bytes += result.bytesRead;\n hash.update(buffer.subarray(0, result.bytesRead));\n }\n if (\n !unchanged(opened, await file.stat()) ||\n !unchanged(opened, await lstat(path))\n )\n throw new Error(\"Hash source changed\");\n return { kind: \"file\", bytes, sha256: hash.digest(\"hex\") };\n } finally {\n await file.close();\n }\n}\n"]}
@@ -0,0 +1,5 @@
1
+ export interface InspectionHash {
2
+ readonly kind: "file" | "symlink";
3
+ readonly bytes: number;
4
+ readonly sha256: string;
5
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=inspection-hash.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inspection-hash.types.js","sourceRoot":"","sources":["../../src/infrastructure/inspection-hash.types.ts"],"names":[],"mappings":"","sourcesContent":["export interface InspectionHash {\n readonly kind: \"file\" | \"symlink\";\n readonly bytes: number;\n readonly sha256: string;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ export declare const journalRetentionLimits: {
2
+ readonly maxMarkerBytes: 4096;
3
+ readonly maxLogBytes: 1073741824;
4
+ };
@@ -0,0 +1,5 @@
1
+ export const journalRetentionLimits = {
2
+ maxMarkerBytes: 4096,
3
+ maxLogBytes: 1_073_741_824,
4
+ };
5
+ //# sourceMappingURL=journal-retention.constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"journal-retention.constants.js","sourceRoot":"","sources":["../../src/infrastructure/journal-retention.constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,cAAc,EAAE,IAAI;IACpB,WAAW,EAAE,aAAa;CAClB,CAAC","sourcesContent":["export const journalRetentionLimits = {\n maxMarkerBytes: 4096,\n maxLogBytes: 1_073_741_824,\n} as const;\n"]}
@@ -0,0 +1,2 @@
1
+ export declare function markJournalClosed(file: string): Promise<void>;
2
+ export declare function closedJournal(file: string): Promise<boolean>;
@@ -0,0 +1,51 @@
1
+ import { journalRetentionLimits } from "./journal-retention.constants.js";
2
+ import { lstat, writeFile } from "node:fs/promises";
3
+ import { hashInspectionEntry } from "./inspection-hash.js";
4
+ import { readInspectionFile } from "./inspection-file.js";
5
+ export async function markJournalClosed(file) {
6
+ const info = await lstat(file);
7
+ const fingerprint = await hashInspectionEntry(file);
8
+ await writeFile(`${file}.closed.json`, JSON.stringify({
9
+ version: 1,
10
+ closedAt: new Date().toISOString(),
11
+ dev: info.dev,
12
+ ino: info.ino,
13
+ mtimeMs: info.mtimeMs,
14
+ ctimeMs: info.ctimeMs,
15
+ ...fingerprint,
16
+ }), { flag: "wx", mode: 0o600 });
17
+ }
18
+ export async function closedJournal(file) {
19
+ try {
20
+ const record = JSON.parse((await readInspectionFile(`${file}.closed.json`, journalRetentionLimits.maxMarkerBytes)).toString("utf8"));
21
+ if (!record ||
22
+ typeof record !== "object" ||
23
+ !("version" in record) ||
24
+ record.version !== 1 ||
25
+ !("closedAt" in record) ||
26
+ typeof record.closedAt !== "string" ||
27
+ !Number.isFinite(Date.parse(record.closedAt)) ||
28
+ !("kind" in record) ||
29
+ record.kind !== "file" ||
30
+ !("bytes" in record) ||
31
+ typeof record.bytes !== "number" ||
32
+ !Number.isSafeInteger(record.bytes) ||
33
+ record.bytes < 0 ||
34
+ !("sha256" in record) ||
35
+ typeof record.sha256 !== "string" ||
36
+ !/^[a-f0-9]{64}$/.test(record.sha256))
37
+ return false;
38
+ const info = await lstat(file);
39
+ for (const key of ["dev", "ino", "mtimeMs", "ctimeMs"])
40
+ if (Object.getOwnPropertyDescriptor(record, key)?.value !== info[key])
41
+ return false;
42
+ const current = await hashInspectionEntry(file, journalRetentionLimits.maxLogBytes);
43
+ return (current.kind === "file" &&
44
+ current.bytes === record.bytes &&
45
+ current.sha256 === record.sha256);
46
+ }
47
+ catch {
48
+ return false;
49
+ }
50
+ }
51
+ //# sourceMappingURL=journal-retention.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"journal-retention.js","sourceRoot":"","sources":["../../src/infrastructure/journal-retention.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,IAAY;IAClD,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/B,MAAM,WAAW,GAAG,MAAM,mBAAmB,CAAC,IAAI,CAAC,CAAC;IACpD,MAAM,SAAS,CACb,GAAG,IAAI,cAAc,EACrB,IAAI,CAAC,SAAS,CAAC;QACb,OAAO,EAAE,CAAC;QACV,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QAClC,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,GAAG,WAAW;KACf,CAAC,EACF,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAC5B,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,IAAY;IAC9C,IAAI,CAAC;QACH,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAChC,CACE,MAAM,kBAAkB,CACtB,GAAG,IAAI,cAAc,EACrB,sBAAsB,CAAC,cAAc,CACtC,CACF,CAAC,QAAQ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AK;YAC9B,OAAO,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,CACjC,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC","sourcesContent":["import { journalRetentionLimits } from \"./journal-retention.constants.ts\";\nimport { lstat, writeFile } from \"node:fs/promises\";\nimport { hashInspectionEntry } from \"./inspection-hash.ts\";\nimport { readInspectionFile } from \"./inspection-file.ts\";\n\nexport async function markJournalClosed(file: string): Promise<void> {\n const info = await lstat(file);\n const fingerprint = await hashInspectionEntry(file);\n await writeFile(\n `${file}.closed.json`,\n JSON.stringify({\n version: 1,\n closedAt: new Date().toISOString(),\n dev: info.dev,\n ino: info.ino,\n mtimeMs: info.mtimeMs,\n ctimeMs: info.ctimeMs,\n ...fingerprint,\n }),\n { flag: \"wx\", mode: 0o600 },\n );\n}\n\nexport async function closedJournal(file: string): Promise<boolean> {\n try {\n const record: unknown = JSON.parse(\n (\n await readInspectionFile(\n `${file}.closed.json`,\n journalRetentionLimits.maxMarkerBytes,\n )\n ).toString(\"utf8\"),\n );\n if (\n !record ||\n typeof record !== \"object\" ||\n !(\"version\" in record) ||\n record.version !== 1 ||\n !(\"closedAt\" in record) ||\n typeof record.closedAt !== \"string\" ||\n !Number.isFinite(Date.parse(record.closedAt)) ||\n !(\"kind\" in record) ||\n record.kind !== \"file\" ||\n !(\"bytes\" in record) ||\n typeof record.bytes !== \"number\" ||\n !Number.isSafeInteger(record.bytes) ||\n record.bytes < 0 ||\n !(\"sha256\" in record) ||\n typeof record.sha256 !== \"string\" ||\n !/^[a-f0-9]{64}$/.test(record.sha256)\n )\n return false;\n const info = await lstat(file);\n for (const key of [\"dev\", \"ino\", \"mtimeMs\", \"ctimeMs\"] as const)\n if (Object.getOwnPropertyDescriptor(record, key)?.value !== info[key])\n return false;\n const current = await hashInspectionEntry(\n file,\n journalRetentionLimits.maxLogBytes,\n );\n return (\n current.kind === \"file\" &&\n current.bytes === record.bytes &&\n current.sha256 === record.sha256\n );\n } catch {\n return false;\n }\n}\n"]}
@@ -1,5 +1,7 @@
1
+ import { lock } from "./git/lock.js";
2
+ import { markJournalClosed } from "./journal-retention.js";
1
3
  import { randomUUID } from "node:crypto";
2
- import { mkdir, open } from "node:fs/promises";
4
+ import { mkdir, open, rm } from "node:fs/promises";
3
5
  import { dirname, join, resolve } from "node:path";
4
6
  import { reporter } from "./reporter.js";
5
7
  export async function journal(repository, logging = {}, label) {
@@ -9,20 +11,32 @@ export async function journal(repository, logging = {}, label) {
9
11
  : undefined;
10
12
  let handle, pending = Promise.resolve();
11
13
  let failure;
14
+ let release;
15
+ let closing;
16
+ const managed = !!logging && logging !== "stdout" && logging.file === undefined;
12
17
  const display = reporter({ ...(label ? { label } : {}) });
13
18
  if (file) {
14
19
  await mkdir(dirname(file), { recursive: true });
15
- handle = await open(file, "a", 0o600);
16
- await handle.write(JSON.stringify({
17
- kind: "dispatch-start",
18
- at: new Date().toISOString(),
19
- label,
20
- }) + "\n");
20
+ release = await lock(repository, `journal:${file}`);
21
+ try {
22
+ await rm(`${file}.closed.json`, { force: true });
23
+ handle = await open(file, managed ? "wx" : "a", 0o600);
24
+ await handle.write(JSON.stringify({
25
+ kind: "dispatch-start",
26
+ at: new Date().toISOString(),
27
+ label,
28
+ }) + "\n");
29
+ }
30
+ catch (error) {
31
+ await handle?.close();
32
+ await release();
33
+ throw error;
34
+ }
21
35
  }
22
36
  return {
23
37
  ...(file ? { file } : {}),
24
38
  record(event) {
25
- if (!logging)
39
+ if (!logging || closing)
26
40
  return;
27
41
  if (event.kind === "raw" && logging !== "stdout" && !logging.verbose)
28
42
  return;
@@ -42,11 +56,21 @@ export async function journal(repository, logging = {}, label) {
42
56
  failure = error;
43
57
  });
44
58
  },
45
- async close() {
46
- await pending;
47
- await handle?.close();
48
- if (failure)
49
- throw failure;
59
+ close() {
60
+ closing ??= (async () => {
61
+ try {
62
+ await pending;
63
+ await handle?.close();
64
+ if (failure)
65
+ throw failure;
66
+ if (file && managed)
67
+ await markJournalClosed(file);
68
+ }
69
+ finally {
70
+ await release?.();
71
+ }
72
+ })();
73
+ return closing;
50
74
  },
51
75
  };
52
76
  }
@@ -1 +1 @@
1
- {"version":3,"file":"journal.js","sourceRoot":"","sources":["../../src/infrastructure/journal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEnD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAIzC,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,UAAkB,EAClB,UAAmB,EAAE,EACrB,KAAc;IAEd,MAAM,IAAI,GACR,OAAO,IAAI,OAAO,KAAK,QAAQ;QAC7B,CAAC,CAAC,OAAO,CACL,UAAU,EACV,OAAO,CAAC,IAAI;YACV,IAAI,CACF,UAAU,EACV,MAAM,EACN,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,UAAU,EAAE,QAAQ,CACjJ,CACJ;QACH,CAAC,CAAC,SAAS,CAAC;IAChB,IAAI,MAA8B,EAChC,OAAO,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAC9B,IAAI,OAAgB,CAAC;IACrB,MAAM,OAAO,GAAG,QAAQ,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAC1D,IAAI,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C,KAAK;YACT,MAAM,OAAO,CAAC;YACd,MAAM,MAAM,EAAE,KAAK,EAAE,CAAC;YACtB,IAAI,OAAO;gBAAE,MAAM,OAAO,CAAC;QAC7B,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { FileHandle } from \"node:fs/promises\";\nimport { mkdir, open } from \"node:fs/promises\";\nimport { dirname, join, resolve } from \"node:path\";\nimport type { Journal, Logging } from \"./journal.types.ts\";\nimport { reporter } from \"./reporter.ts\";\n\nexport type { Logging } from \"./journal.types.ts\";\n\nexport async function journal(\n repository: string,\n logging: Logging = {},\n label?: string,\n): Promise<Journal> {\n const file =\n logging && logging !== \"stdout\"\n ? resolve(\n repository,\n logging.file ??\n join(\n \".outpost\",\n \"logs\",\n `${label ? label.replace(/[^A-Za-z0-9_-]/g, \"-\").slice(0, 64) + \"-\" : \"\"}${new Date().toISOString().replaceAll(\":\", \"-\")}-${randomUUID()}.jsonl`,\n ),\n )\n : undefined;\n let handle: FileHandle | undefined,\n pending = Promise.resolve();\n let failure: unknown;\n const display = reporter({ ...(label ? { label } : {}) });\n if (file) {\n await mkdir(dirname(file), { recursive: true });\n handle = await open(file, \"a\", 0o600);\n await handle.write(\n JSON.stringify({\n kind: \"dispatch-start\",\n at: new Date().toISOString(),\n label,\n }) + \"\\n\",\n );\n }\n return {\n ...(file ? { file } : {}),\n record(event) {\n if (!logging) return;\n if (event.kind === \"raw\" && logging !== \"stdout\" && !logging.verbose)\n return;\n const line =\n JSON.stringify({\n at: new Date().toISOString(),\n ...(label ? { label } : {}),\n ...event,\n }) + \"\\n\";\n if (logging === \"stdout\") display(event);\n else\n pending = pending\n .then(async () => {\n await handle?.write(line);\n })\n .catch((error) => {\n failure = error;\n });\n },\n async close() {\n await pending;\n await handle?.close();\n if (failure) throw failure;\n },\n };\n}\n"]}
1
+ {"version":3,"file":"journal.js","sourceRoot":"","sources":["../../src/infrastructure/journal.ts"],"names":[],"mappings":"AAAA,O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AAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC3B,GAAG,KAAK;aACT,CAAC,GAAG,IAAI,CAAC;YACZ,IAAI,OAAO,KAAK,QAAQ;gBAAE,OAAO,CAAC,KAAK,CAAC,CAAC;;gBAEvC,OAAO,GAAG,OAAO;qBACd,IAAI,CAAC,KAAK,IAAI,EAAE;oBACf,MAAM,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;gBAC5B,CAAC,CAAC;qBACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;oBACf,OAAO,GAAG,KAAK,CAAC;gBAClB,CAAC,CAAC,CAAC;QACT,CAAC;QACD,KAAK;YACH,OAAO,KAAK,CAAC,KAAK,IAAI,EAAE;gBACtB,IAAI,CAAC;oBACH,MAAM,OAAO,CAAC;oBACd,MAAM,MAAM,EAAE,KAAK,EAAE,CAAC;oBACtB,IAAI,OAAO;wBAAE,MAAM,OAAO,CAAC;oBAC3B,IAAI,IAAI,IAAI,OAAO;wBAAE,MAAM,iBAAiB,CAAC,IAAI,CAAC,CAAC;gBACrD,CAAC;wBAAS,CAAC;oBACT,MAAM,OAAO,EAAE,EAAE,CAAC;gBACpB,CAAC;YACH,CAAC,CAAC,EAAE,CAAC;YACL,OAAO,OAAO,CAAC;QACjB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { lock } from \"./git/lock.ts\";\nimport { markJournalClosed } from \"./journal-retention.ts\";\nimport { randomUUID } from \"node:crypto\";\nimport type { FileHandle } from \"node:fs/promises\";\nimport { mkdir, open, rm } from \"node:fs/promises\";\nimport { dirname, join, resolve } from \"node:path\";\nimport type { Journal, Logging } from \"./journal.types.ts\";\nimport { reporter } from \"./reporter.ts\";\n\nexport type { Logging } from \"./journal.types.ts\";\n\nexport async function journal(\n repository: string,\n logging: Logging = {},\n label?: string,\n): Promise<Journal> {\n const file =\n logging && logging !== \"stdout\"\n ? resolve(\n repository,\n logging.file ??\n join(\n \".outpost\",\n \"logs\",\n `${label ? label.replace(/[^A-Za-z0-9_-]/g, \"-\").slice(0, 64) + \"-\" : \"\"}${new Date().toISOString().replaceAll(\":\", \"-\")}-${randomUUID()}.jsonl`,\n ),\n )\n : undefined;\n let handle: FileHandle | undefined,\n pending = Promise.resolve();\n let failure: unknown;\n let release: (() => Promise<void>) | undefined;\n let closing: Promise<void> | undefined;\n const managed =\n !!logging && logging !== \"stdout\" && logging.file === undefined;\n const display = reporter({ ...(label ? { label } : {}) });\n if (file) {\n await mkdir(dirname(file), { recursive: true });\n release = await lock(repository, `journal:${file}`);\n try {\n await rm(`${file}.closed.json`, { force: true });\n handle = await open(file, managed ? \"wx\" : \"a\", 0o600);\n await handle.write(\n JSON.stringify({\n kind: \"dispatch-start\",\n at: new Date().toISOString(),\n label,\n }) + \"\\n\",\n );\n } catch (error) {\n await handle?.close();\n await release();\n throw error;\n }\n }\n return {\n ...(file ? { file } : {}),\n record(event) {\n if (!logging || closing) return;\n if (event.kind === \"raw\" && logging !== \"stdout\" && !logging.verbose)\n return;\n const line =\n JSON.stringify({\n at: new Date().toISOString(),\n ...(label ? { label } : {}),\n ...event,\n }) + \"\\n\";\n if (logging === \"stdout\") display(event);\n else\n pending = pending\n .then(async () => {\n await handle?.write(line);\n })\n .catch((error) => {\n failure = error;\n });\n },\n close() {\n closing ??= (async () => {\n try {\n await pending;\n await handle?.close();\n if (failure) throw failure;\n if (file && managed) await markJournalClosed(file);\n } finally {\n await release?.();\n }\n })();\n return closing;\n },\n };\n}\n"]}
@@ -0,0 +1,10 @@
1
+ export declare const telemetryNames: {
2
+ readonly workflows: "outpost.workflow.executions";
3
+ readonly tasks: "outpost.task.executions";
4
+ readonly attempts: "outpost.task.attempts";
5
+ readonly retries: "outpost.task.retries";
6
+ readonly usage: "outpost.agent.tokens";
7
+ readonly workflowDuration: "outpost.workflow.duration";
8
+ readonly taskDuration: "outpost.task.duration";
9
+ readonly attemptDuration: "outpost.task.attempt.duration";
10
+ };
@@ -0,0 +1,11 @@
1
+ export const telemetryNames = {
2
+ workflows: "outpost.workflow.executions",
3
+ tasks: "outpost.task.executions",
4
+ attempts: "outpost.task.attempts",
5
+ retries: "outpost.task.retries",
6
+ usage: "outpost.agent.tokens",
7
+ workflowDuration: "outpost.workflow.duration",
8
+ taskDuration: "outpost.task.duration",
9
+ attemptDuration: "outpost.task.attempt.duration",
10
+ };
11
+ //# sourceMappingURL=opentelemetry.constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opentelemetry.constants.js","sourceRoot":"","sources":["../../src/infrastructure/opentelemetry.constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,SAAS,EAAE,6BAA6B;IACxC,KAAK,EAAE,yBAAyB;IAChC,QAAQ,EAAE,uBAAuB;IACjC,OAAO,EAAE,sBAAsB;IAC/B,KAAK,EAAE,sBAAsB;IAC7B,gBAAgB,EAAE,2BAA2B;IAC7C,YAAY,EAAE,uBAAuB;IACrC,eAAe,EAAE,+BAA+B;CACxC,CAAC","sourcesContent":["export const telemetryNames = {\n workflows: \"outpost.workflow.executions\",\n tasks: \"outpost.task.executions\",\n attempts: \"outpost.task.attempts\",\n retries: \"outpost.task.retries\",\n usage: \"outpost.agent.tokens\",\n workflowDuration: \"outpost.workflow.duration\",\n taskDuration: \"outpost.task.duration\",\n attemptDuration: \"outpost.task.attempt.duration\",\n} as const;\n"]}
@@ -0,0 +1,3 @@
1
+ import type { OpenTelemetryObserver, OpenTelemetryOptions } from "./opentelemetry.types.ts";
2
+ export type { OpenTelemetryObserver, OpenTelemetryOptions, } from "./opentelemetry.types.ts";
3
+ export declare function openTelemetry(options: OpenTelemetryOptions): OpenTelemetryObserver;
@@ -0,0 +1,131 @@
1
+ import { context, trace, SpanStatusCode } from "@opentelemetry/api";
2
+ import { usageDimensions } from "../domain/workflow/budget.constants.js";
3
+ import { telemetryNames } from "./opentelemetry.constants.js";
4
+ export function openTelemetry(options) {
5
+ function safe(action) {
6
+ try {
7
+ return action();
8
+ }
9
+ catch (error) {
10
+ try {
11
+ options.onError?.(error);
12
+ }
13
+ catch { }
14
+ }
15
+ }
16
+ const counters = {
17
+ workflows: safe(() => options.meter.createCounter(telemetryNames.workflows)),
18
+ tasks: safe(() => options.meter.createCounter(telemetryNames.tasks)),
19
+ attempts: safe(() => options.meter.createCounter(telemetryNames.attempts)),
20
+ retries: safe(() => options.meter.createCounter(telemetryNames.retries)),
21
+ usage: safe(() => options.meter.createCounter(telemetryNames.usage, { unit: "{token}" })),
22
+ };
23
+ const durations = {
24
+ workflow: safe(() => options.meter.createHistogram(telemetryNames.workflowDuration, {
25
+ unit: "s",
26
+ })),
27
+ task: safe(() => options.meter.createHistogram(telemetryNames.taskDuration, { unit: "s" })),
28
+ attempt: safe(() => options.meter.createHistogram(telemetryNames.attemptDuration, {
29
+ unit: "s",
30
+ })),
31
+ };
32
+ const executions = new Map();
33
+ let closed = false;
34
+ function start(name, parent, at) {
35
+ const span = safe(() => options.tracer.startSpan(name, { startTime: at }, parent));
36
+ return {
37
+ span,
38
+ context: span ? trace.setSpan(parent, span) : parent,
39
+ started: at,
40
+ };
41
+ }
42
+ function finish(operation, status, at, duration) {
43
+ if (!operation)
44
+ return;
45
+ const attributes = { "outpost.status": status };
46
+ safe(() => operation.span?.setAttributes(attributes));
47
+ if (status !== "skipped")
48
+ safe(() => operation.span?.setStatus({
49
+ code: status === "done" ? SpanStatusCode.OK : SpanStatusCode.ERROR,
50
+ }));
51
+ safe(() => operation.span?.end(at));
52
+ safe(() => duration?.record(Math.max(0, at - operation.started) / 1000, attributes));
53
+ }
54
+ function complete(execution, status, at) {
55
+ for (const attempt of execution.attempts.values())
56
+ finish(attempt, status, at, durations.attempt);
57
+ for (const task of execution.tasks.values())
58
+ finish(task, status, at, durations.task);
59
+ finish(execution.workflow, status, at, durations.workflow);
60
+ safe(() => counters.workflows?.add(1, { "outpost.status": status }));
61
+ }
62
+ return {
63
+ observe(event) {
64
+ if (closed)
65
+ return;
66
+ const at = Date.parse(event.timestamp);
67
+ if (!Number.isFinite(at))
68
+ return;
69
+ if (event.type === "start") {
70
+ if (executions.has(event.executionId))
71
+ return;
72
+ executions.set(event.executionId, {
73
+ workflow: start("outpost.workflow", context.active(), at),
74
+ tasks: new Map(),
75
+ attempts: new Map(),
76
+ });
77
+ return;
78
+ }
79
+ const execution = executions.get(event.executionId);
80
+ if (!execution)
81
+ return;
82
+ if (event.type === "finish") {
83
+ executions.delete(event.executionId);
84
+ complete(execution, event.status ?? "done", at);
85
+ return;
86
+ }
87
+ if (event.type === "usage") {
88
+ for (const dimension of usageDimensions) {
89
+ const value = event.usage?.[dimension];
90
+ if (value !== undefined && Number.isFinite(value) && value > 0)
91
+ safe(() => counters.usage?.add(value, { "outpost.token.type": dimension }));
92
+ }
93
+ return;
94
+ }
95
+ if (event.key === undefined)
96
+ return;
97
+ if (event.type === "attempt") {
98
+ execution.attempts.set(event.key, start("outpost.task.attempt", execution.tasks.get(event.key)?.context ??
99
+ execution.workflow.context, at));
100
+ safe(() => counters.attempts?.add(1));
101
+ return;
102
+ }
103
+ if (event.type === "retry") {
104
+ finish(execution.attempts.get(event.key), "failed", at, durations.attempt);
105
+ execution.attempts.delete(event.key);
106
+ safe(() => counters.retries?.add(1));
107
+ return;
108
+ }
109
+ if (event.type === "task" && event.status === "active") {
110
+ execution.tasks.set(event.key, start("outpost.task", execution.workflow.context, at));
111
+ return;
112
+ }
113
+ if (event.type === "task" && event.status) {
114
+ finish(execution.attempts.get(event.key), event.status, at, durations.attempt);
115
+ finish(execution.tasks.get(event.key), event.status, at, durations.task);
116
+ execution.attempts.delete(event.key);
117
+ execution.tasks.delete(event.key);
118
+ safe(() => counters.tasks?.add(1, { "outpost.status": event.status }));
119
+ }
120
+ },
121
+ close() {
122
+ if (closed)
123
+ return;
124
+ closed = true;
125
+ for (const execution of executions.values())
126
+ complete(execution, "cancelled", Date.now());
127
+ executions.clear();
128
+ },
129
+ };
130
+ }
131
+ //# sourceMappingURL=opentelemetry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opentelemetry.js","sourceRoot":"","sources":["../../src/infrastructure/opentelemetry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGpE,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAa9D,MAAM,UAAU,aAAa,CAC3B,OAA6B;IAE7B,SAAS,IAAI,CAAI,MAAe;QAC9B,IAAI,CAAC;YACH,OAAO,MAAM,EAAE,CAAC;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC;gBACH,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;YAC3B,CAAC;YAAC,MAAM,CAAC,CAAA,CAAC;QACZ,CAAC;IACH,CAAC;IACD,MAAM,QAAQ,GAAG;QACf,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,CACnB,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,cAAc,CAAC,SAAS,CAAC,CACtD;QACD,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QACpE,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QAC1E,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QACxE,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,CACf,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,cAAc,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EA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,MAAM,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;gBAC1C,MAAM,CACJ,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,EACjC,KAAK,CAAC,MAAM,EACZ,EAAE,EACF,SAAS,CAAC,OAAO,CAClB,CAAC;gBACF,MAAM,CACJ,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,EAC9B,KAAK,CAAC,MAAM,EACZ,EAAE,EACF,SAAS,CAAC,IAAI,CACf,CAAC;gBACF,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACrC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBAClC,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,EAAE,EAAE,gBAAgB,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;YACzE,CAAC;QACH,CAAC;QACD,KAAK;YACH,IAAI,MAAM;gBAAE,OAAO;YACnB,MAAM,GAAG,IAAI,CAAC;YACd,KAAK,MAAM,SAAS,IAAI,UAAU,CAAC,MAAM,EAAE;gBACzC,QAAQ,CAAC,SAAS,EAAE,WAAW,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;YAC/C,UAAU,CAAC,KAAK,EAAE,CAAC;QACrB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { context, trace, SpanStatusCode } from \"@opentelemetry/api\";\nimport type { Context, Histogram } from \"@opentelemetry/api\";\nimport type { WorkflowEvent } from \"../domain/workflow.types.ts\";\nimport { usageDimensions } from \"../domain/workflow/budget.constants.ts\";\nimport { telemetryNames } from \"./opentelemetry.constants.ts\";\nimport type {\n OpenTelemetryObserver,\n OpenTelemetryOptions,\n TelemetryExecution,\n TelemetryOperation,\n} from \"./opentelemetry.types.ts\";\n\nexport type {\n OpenTelemetryObserver,\n OpenTelemetryOptions,\n} from \"./opentelemetry.types.ts\";\n\nexport function openTelemetry(\n options: OpenTelemetryOptions,\n): OpenTelemetryObserver {\n function safe<T>(action: () => T): T | undefined {\n try {\n return action();\n } catch (error) {\n try {\n options.onError?.(error);\n } catch {}\n }\n }\n const counters = {\n workflows: safe(() =>\n options.meter.createCounter(telemetryNames.workflows),\n ),\n tasks: safe(() => options.meter.createCounter(telemetryNames.tasks)),\n attempts: safe(() => options.meter.createCounter(telemetryNames.attempts)),\n retries: safe(() => options.meter.createCounter(telemetryNames.retries)),\n usage: safe(() =>\n options.meter.createCounter(telemetryNames.usage, { unit: \"{token}\" }),\n ),\n };\n const durations = {\n workflow: safe(() =>\n options.meter.createHistogram(telemetryNames.workflowDuration, {\n unit: \"s\",\n }),\n ),\n task: safe(() =>\n options.meter.createHistogram(telemetryNames.taskDuration, { unit: \"s\" }),\n ),\n attempt: safe(() =>\n options.meter.createHistogram(telemetryNames.attemptDuration, {\n unit: \"s\",\n }),\n ),\n };\n const executions = new Map<string, TelemetryExecution>();\n let closed = false;\n function start(\n name: string,\n parent: Context,\n at: number,\n ): TelemetryOperation {\n const span = safe(() =>\n options.tracer.startSpan(name, { startTime: at }, parent),\n );\n return {\n span,\n context: span ? trace.setSpan(parent, span) : parent,\n started: at,\n };\n }\n function finish(\n operation: TelemetryOperation | undefined,\n status: string,\n at: number,\n duration: Histogram | undefined,\n ): void {\n if (!operation) return;\n const attributes = { \"outpost.status\": status };\n safe(() => operation.span?.setAttributes(attributes));\n if (status !== \"skipped\")\n safe(() =>\n operation.span?.setStatus({\n code: status === \"done\" ? SpanStatusCode.OK : SpanStatusCode.ERROR,\n }),\n );\n safe(() => operation.span?.end(at));\n safe(() =>\n duration?.record(Math.max(0, at - operation.started) / 1000, attributes),\n );\n }\n function complete(\n execution: TelemetryExecution,\n status: string,\n at: number,\n ): void {\n for (const attempt of execution.attempts.values())\n finish(attempt, status, at, durations.attempt);\n for (const task of execution.tasks.values())\n finish(task, status, at, durations.task);\n finish(execution.workflow, status, at, durations.workflow);\n safe(() => counters.workflows?.add(1, { \"outpost.status\": status }));\n }\n return {\n observe(event: WorkflowEvent) {\n if (closed) return;\n const at = Date.parse(event.timestamp);\n if (!Number.isFinite(at)) return;\n if (event.type === \"start\") {\n if (executions.has(event.executionId)) return;\n executions.set(event.executionId, {\n workflow: start(\"outpost.workflow\", context.active(), at),\n tasks: new Map(),\n attempts: new Map(),\n });\n return;\n }\n const execution = executions.get(event.executionId);\n if (!execution) return;\n if (event.type === \"finish\") {\n executions.delete(event.executionId);\n complete(execution, event.status ?? \"done\", at);\n return;\n }\n if (event.type === \"usage\") {\n for (const dimension of usageDimensions) {\n const value = event.usage?.[dimension];\n if (value !== undefined && Number.isFinite(value) && value > 0)\n safe(() =>\n counters.usage?.add(value, { \"outpost.token.type\": dimension }),\n );\n }\n return;\n }\n if (event.key === undefined) return;\n if (event.type === \"attempt\") {\n execution.attempts.set(\n event.key,\n start(\n \"outpost.task.attempt\",\n execution.tasks.get(event.key)?.context ??\n execution.workflow.context,\n at,\n ),\n );\n safe(() => counters.attempts?.add(1));\n return;\n }\n if (event.type === \"retry\") {\n finish(\n execution.attempts.get(event.key),\n \"failed\",\n at,\n durations.attempt,\n );\n execution.attempts.delete(event.key);\n safe(() => counters.retries?.add(1));\n return;\n }\n if (event.type === \"task\" && event.status === \"active\") {\n execution.tasks.set(\n event.key,\n start(\"outpost.task\", execution.workflow.context, at),\n );\n return;\n }\n if (event.type === \"task\" && event.status) {\n finish(\n execution.attempts.get(event.key),\n event.status,\n at,\n durations.attempt,\n );\n finish(\n execution.tasks.get(event.key),\n event.status,\n at,\n durations.task,\n );\n execution.attempts.delete(event.key);\n execution.tasks.delete(event.key);\n safe(() => counters.tasks?.add(1, { \"outpost.status\": event.status }));\n }\n },\n close() {\n if (closed) return;\n closed = true;\n for (const execution of executions.values())\n complete(execution, \"cancelled\", Date.now());\n executions.clear();\n },\n };\n}\n"]}
@@ -0,0 +1,21 @@
1
+ import type { Context, Meter, Span, Tracer } from "@opentelemetry/api";
2
+ import type { WorkflowEvent } from "../domain/workflow.types.ts";
3
+ export interface OpenTelemetryOptions {
4
+ readonly tracer: Tracer;
5
+ readonly meter: Meter;
6
+ readonly onError?: (error: unknown) => void;
7
+ }
8
+ export interface OpenTelemetryObserver {
9
+ observe(event: WorkflowEvent): void;
10
+ close(): void;
11
+ }
12
+ export interface TelemetryOperation {
13
+ readonly span: Span | undefined;
14
+ readonly context: Context;
15
+ readonly started: number;
16
+ }
17
+ export interface TelemetryExecution {
18
+ readonly workflow: TelemetryOperation;
19
+ readonly tasks: Map<string, TelemetryOperation>;
20
+ readonly attempts: Map<string, TelemetryOperation>;
21
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=opentelemetry.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opentelemetry.types.js","sourceRoot":"","sources":["../../src/infrastructure/opentelemetry.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Context, Meter, Span, Tracer } from \"@opentelemetry/api\";\nimport type { WorkflowEvent } from \"../domain/workflow.types.ts\";\n\nexport interface OpenTelemetryOptions {\n readonly tracer: Tracer;\n readonly meter: Meter;\n readonly onError?: (error: unknown) => void;\n}\n\nexport interface OpenTelemetryObserver {\n observe(event: WorkflowEvent): void;\n close(): void;\n}\n\nexport interface TelemetryOperation {\n readonly span: Span | undefined;\n readonly context: Context;\n readonly started: number;\n}\n\nexport interface TelemetryExecution {\n readonly workflow: TelemetryOperation;\n readonly tasks: Map<string, TelemetryOperation>;\n readonly attempts: Map<string, TelemetryOperation>;\n}\n"]}
@@ -0,0 +1,6 @@
1
+ import type { StorageCategoryName } from "./storage-inventory.types.ts";
2
+ export declare const storageCategories: readonly StorageCategoryName[];
3
+ export declare const storageInventoryDefaults: Readonly<{
4
+ maxEntries: 100000;
5
+ maxDepth: 64;
6
+ }>;
@@ -0,0 +1,11 @@
1
+ export const storageCategories = [
2
+ "recovery",
3
+ "logs",
4
+ "locks",
5
+ "workspaces",
6
+ ];
7
+ export const storageInventoryDefaults = Object.freeze({
8
+ maxEntries: 100_000,
9
+ maxDepth: 64,
10
+ });
11
+ //# sourceMappingURL=storage-inventory.constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage-inventory.constants.js","sourceRoot":"","sources":["../../src/infrastructure/storage-inventory.constants.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,iBAAiB,GAAmC;IAC/D,UAAU;IACV,MAAM;IACN,OAAO;IACP,YAAY;CACb,CAAC;AACF,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC,MAAM,CAAC;IACpD,UAAU,EAAE,OAAO;IACnB,QAAQ,EAAE,EAAE;CACb,CAAC,CAAC","sourcesContent":["import type { StorageCategoryName } from \"./storage-inventory.types.ts\";\n\nexport const storageCategories: readonly StorageCategoryName[] = [\n \"recovery\",\n \"logs\",\n \"locks\",\n \"workspaces\",\n];\nexport const storageInventoryDefaults = Object.freeze({\n maxEntries: 100_000,\n maxDepth: 64,\n});\n"]}
@@ -0,0 +1,2 @@
1
+ import type { StorageInventory } from "./storage-inventory.types.ts";
2
+ export declare function storageInventory(root: string, maxEntries?: number): Promise<StorageInventory>;