@ontrails/core 1.0.0-beta.15 → 1.0.0-beta.16

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 (348) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/README.md +61 -16
  3. package/package.json +9 -8
  4. package/src/activation-provenance.ts +111 -0
  5. package/src/activation-source-compatibility.ts +430 -0
  6. package/src/activation-source-projection.ts +221 -0
  7. package/src/activation-source.ts +91 -0
  8. package/src/blob-ref.ts +51 -0
  9. package/src/context.ts +4 -0
  10. package/src/{internal/cross-batch.ts → cross-batch.ts} +3 -11
  11. package/src/detours.ts +8 -0
  12. package/src/draft.ts +4 -0
  13. package/src/error-projection.ts +51 -0
  14. package/src/errors.ts +192 -39
  15. package/src/execute.ts +443 -44
  16. package/src/fire.ts +965 -91
  17. package/src/index.ts +285 -38
  18. package/src/layer-projection.ts +192 -0
  19. package/src/layer.ts +32 -1
  20. package/src/observe.ts +361 -0
  21. package/src/permits.ts +12 -0
  22. package/src/redaction/patterns.ts +6 -3
  23. package/src/resilience.ts +8 -8
  24. package/src/resource-config.ts +477 -44
  25. package/src/resource.ts +21 -1
  26. package/src/result.ts +18 -0
  27. package/src/run.ts +2 -2
  28. package/src/schedule-runtime.ts +689 -0
  29. package/src/schedule.ts +324 -0
  30. package/src/serialization.ts +90 -57
  31. package/src/signal-diagnostics.ts +633 -0
  32. package/src/{internal/signal-ref.ts → signal-ref.ts} +1 -1
  33. package/src/signal.ts +37 -0
  34. package/src/store/accessor-protocol.ts +5 -5
  35. package/src/structured-examples.ts +245 -0
  36. package/src/surface-derivation.ts +91 -0
  37. package/src/surface-filter.ts +7 -13
  38. package/src/topo.ts +386 -6
  39. package/src/tracing.ts +345 -0
  40. package/src/trail.ts +168 -22
  41. package/src/trails/derive-trail.ts +1 -1
  42. package/src/trails/ingest.ts +7 -15
  43. package/src/{internal/trails-db.ts → trails-db.ts} +42 -21
  44. package/src/transport-error-map.ts +146 -28
  45. package/src/types.ts +82 -28
  46. package/src/validate-established-topo.ts +6 -0
  47. package/src/validate-topo.ts +212 -5
  48. package/src/validation.ts +58 -1
  49. package/src/webhook.ts +276 -0
  50. package/src/{internal/zod-wrappers.ts → zod-wrappers.ts} +0 -6
  51. package/.turbo/turbo-build.log +0 -1
  52. package/.turbo/turbo-lint.log +0 -3
  53. package/.turbo/turbo-typecheck.log +0 -1
  54. package/dist/blob-ref.d.ts +0 -20
  55. package/dist/blob-ref.d.ts.map +0 -1
  56. package/dist/blob-ref.js +0 -22
  57. package/dist/blob-ref.js.map +0 -1
  58. package/dist/branded.d.ts +0 -36
  59. package/dist/branded.d.ts.map +0 -1
  60. package/dist/branded.js +0 -89
  61. package/dist/branded.js.map +0 -1
  62. package/dist/collections.d.ts +0 -31
  63. package/dist/collections.d.ts.map +0 -1
  64. package/dist/collections.js +0 -60
  65. package/dist/collections.js.map +0 -1
  66. package/dist/context.d.ts +0 -22
  67. package/dist/context.d.ts.map +0 -1
  68. package/dist/context.js +0 -37
  69. package/dist/context.js.map +0 -1
  70. package/dist/contour.d.ts +0 -81
  71. package/dist/contour.d.ts.map +0 -1
  72. package/dist/contour.js +0 -176
  73. package/dist/contour.js.map +0 -1
  74. package/dist/cross-schema.d.ts +0 -18
  75. package/dist/cross-schema.d.ts.map +0 -1
  76. package/dist/cross-schema.js +0 -29
  77. package/dist/cross-schema.js.map +0 -1
  78. package/dist/derive.d.ts +0 -44
  79. package/dist/derive.d.ts.map +0 -1
  80. package/dist/derive.js +0 -149
  81. package/dist/derive.js.map +0 -1
  82. package/dist/draft.d.ts +0 -28
  83. package/dist/draft.d.ts.map +0 -1
  84. package/dist/draft.js +0 -157
  85. package/dist/draft.js.map +0 -1
  86. package/dist/errors.d.ts +0 -141
  87. package/dist/errors.d.ts.map +0 -1
  88. package/dist/errors.js +0 -185
  89. package/dist/errors.js.map +0 -1
  90. package/dist/execute.d.ts +0 -52
  91. package/dist/execute.d.ts.map +0 -1
  92. package/dist/execute.js +0 -511
  93. package/dist/execute.js.map +0 -1
  94. package/dist/fetch.d.ts +0 -15
  95. package/dist/fetch.d.ts.map +0 -1
  96. package/dist/fetch.js +0 -102
  97. package/dist/fetch.js.map +0 -1
  98. package/dist/fire.d.ts +0 -43
  99. package/dist/fire.d.ts.map +0 -1
  100. package/dist/fire.js +0 -185
  101. package/dist/fire.js.map +0 -1
  102. package/dist/guards.d.ts +0 -17
  103. package/dist/guards.d.ts.map +0 -1
  104. package/dist/guards.js +0 -25
  105. package/dist/guards.js.map +0 -1
  106. package/dist/index.d.ts +0 -59
  107. package/dist/index.d.ts.map +0 -1
  108. package/dist/index.js +0 -61
  109. package/dist/index.js.map +0 -1
  110. package/dist/internal/cross-batch.d.ts +0 -44
  111. package/dist/internal/cross-batch.d.ts.map +0 -1
  112. package/dist/internal/cross-batch.js +0 -58
  113. package/dist/internal/cross-batch.js.map +0 -1
  114. package/dist/internal/fork-ctx.d.ts +0 -41
  115. package/dist/internal/fork-ctx.d.ts.map +0 -1
  116. package/dist/internal/fork-ctx.js +0 -47
  117. package/dist/internal/fork-ctx.js.map +0 -1
  118. package/dist/internal/signal-ref.d.ts +0 -15
  119. package/dist/internal/signal-ref.d.ts.map +0 -1
  120. package/dist/internal/signal-ref.js +0 -41
  121. package/dist/internal/signal-ref.js.map +0 -1
  122. package/dist/internal/topo-saves.d.ts +0 -53
  123. package/dist/internal/topo-saves.d.ts.map +0 -1
  124. package/dist/internal/topo-saves.js +0 -449
  125. package/dist/internal/topo-saves.js.map +0 -1
  126. package/dist/internal/topo-snapshots.d.ts +0 -57
  127. package/dist/internal/topo-snapshots.d.ts.map +0 -1
  128. package/dist/internal/topo-snapshots.js +0 -372
  129. package/dist/internal/topo-snapshots.js.map +0 -1
  130. package/dist/internal/topo-store-read.d.ts +0 -70
  131. package/dist/internal/topo-store-read.d.ts.map +0 -1
  132. package/dist/internal/topo-store-read.js +0 -221
  133. package/dist/internal/topo-store-read.js.map +0 -1
  134. package/dist/internal/topo-store.d.ts +0 -26
  135. package/dist/internal/topo-store.d.ts.map +0 -1
  136. package/dist/internal/topo-store.js +0 -621
  137. package/dist/internal/topo-store.js.map +0 -1
  138. package/dist/internal/tracing.d.ts +0 -98
  139. package/dist/internal/tracing.d.ts.map +0 -1
  140. package/dist/internal/tracing.js +0 -102
  141. package/dist/internal/tracing.js.map +0 -1
  142. package/dist/internal/trails-db.d.ts +0 -16
  143. package/dist/internal/trails-db.d.ts.map +0 -1
  144. package/dist/internal/trails-db.js +0 -118
  145. package/dist/internal/trails-db.js.map +0 -1
  146. package/dist/internal/zod-wrappers.d.ts +0 -40
  147. package/dist/internal/zod-wrappers.d.ts.map +0 -1
  148. package/dist/internal/zod-wrappers.js +0 -59
  149. package/dist/internal/zod-wrappers.js.map +0 -1
  150. package/dist/layer.d.ts +0 -23
  151. package/dist/layer.d.ts.map +0 -1
  152. package/dist/layer.js +0 -21
  153. package/dist/layer.js.map +0 -1
  154. package/dist/path-security.d.ts +0 -28
  155. package/dist/path-security.d.ts.map +0 -1
  156. package/dist/path-security.js +0 -63
  157. package/dist/path-security.js.map +0 -1
  158. package/dist/patterns/bulk.d.ts +0 -15
  159. package/dist/patterns/bulk.d.ts.map +0 -1
  160. package/dist/patterns/bulk.js +0 -14
  161. package/dist/patterns/bulk.js.map +0 -1
  162. package/dist/patterns/change.d.ts +0 -10
  163. package/dist/patterns/change.d.ts.map +0 -1
  164. package/dist/patterns/change.js +0 -10
  165. package/dist/patterns/change.js.map +0 -1
  166. package/dist/patterns/date-range.d.ts +0 -10
  167. package/dist/patterns/date-range.d.ts.map +0 -1
  168. package/dist/patterns/date-range.js +0 -10
  169. package/dist/patterns/date-range.js.map +0 -1
  170. package/dist/patterns/index.d.ts +0 -9
  171. package/dist/patterns/index.d.ts.map +0 -1
  172. package/dist/patterns/index.js +0 -9
  173. package/dist/patterns/index.js.map +0 -1
  174. package/dist/patterns/pagination.d.ts +0 -18
  175. package/dist/patterns/pagination.d.ts.map +0 -1
  176. package/dist/patterns/pagination.js +0 -18
  177. package/dist/patterns/pagination.js.map +0 -1
  178. package/dist/patterns/progress.d.ts +0 -11
  179. package/dist/patterns/progress.d.ts.map +0 -1
  180. package/dist/patterns/progress.js +0 -11
  181. package/dist/patterns/progress.js.map +0 -1
  182. package/dist/patterns/sorting.d.ts +0 -13
  183. package/dist/patterns/sorting.d.ts.map +0 -1
  184. package/dist/patterns/sorting.js +0 -10
  185. package/dist/patterns/sorting.js.map +0 -1
  186. package/dist/patterns/status.d.ts +0 -15
  187. package/dist/patterns/status.d.ts.map +0 -1
  188. package/dist/patterns/status.js +0 -9
  189. package/dist/patterns/status.js.map +0 -1
  190. package/dist/patterns/timestamps.d.ts +0 -10
  191. package/dist/patterns/timestamps.d.ts.map +0 -1
  192. package/dist/patterns/timestamps.js +0 -10
  193. package/dist/patterns/timestamps.js.map +0 -1
  194. package/dist/redaction/index.d.ts +0 -4
  195. package/dist/redaction/index.d.ts.map +0 -1
  196. package/dist/redaction/index.js +0 -3
  197. package/dist/redaction/index.js.map +0 -1
  198. package/dist/redaction/patterns.d.ts +0 -9
  199. package/dist/redaction/patterns.d.ts.map +0 -1
  200. package/dist/redaction/patterns.js +0 -39
  201. package/dist/redaction/patterns.js.map +0 -1
  202. package/dist/redaction/redactor.d.ts +0 -27
  203. package/dist/redaction/redactor.d.ts.map +0 -1
  204. package/dist/redaction/redactor.js +0 -89
  205. package/dist/redaction/redactor.js.map +0 -1
  206. package/dist/resilience.d.ts +0 -34
  207. package/dist/resilience.d.ts.map +0 -1
  208. package/dist/resilience.js +0 -164
  209. package/dist/resilience.js.map +0 -1
  210. package/dist/resource-config.d.ts +0 -22
  211. package/dist/resource-config.d.ts.map +0 -1
  212. package/dist/resource-config.js +0 -210
  213. package/dist/resource-config.js.map +0 -1
  214. package/dist/resource.d.ts +0 -74
  215. package/dist/resource.d.ts.map +0 -1
  216. package/dist/resource.js +0 -61
  217. package/dist/resource.js.map +0 -1
  218. package/dist/result.d.ts +0 -57
  219. package/dist/result.d.ts.map +0 -1
  220. package/dist/result.js +0 -156
  221. package/dist/result.js.map +0 -1
  222. package/dist/run.d.ts +0 -28
  223. package/dist/run.d.ts.map +0 -1
  224. package/dist/run.js +0 -35
  225. package/dist/run.js.map +0 -1
  226. package/dist/serialization.d.ts +0 -27
  227. package/dist/serialization.d.ts.map +0 -1
  228. package/dist/serialization.js +0 -154
  229. package/dist/serialization.js.map +0 -1
  230. package/dist/signal.d.ts +0 -33
  231. package/dist/signal.d.ts.map +0 -1
  232. package/dist/signal.js +0 -17
  233. package/dist/signal.js.map +0 -1
  234. package/dist/store/accessor-protocol.d.ts +0 -51
  235. package/dist/store/accessor-protocol.d.ts.map +0 -1
  236. package/dist/store/accessor-protocol.js +0 -2
  237. package/dist/store/accessor-protocol.js.map +0 -1
  238. package/dist/store/index.d.ts +0 -2
  239. package/dist/store/index.d.ts.map +0 -1
  240. package/dist/store/index.js +0 -2
  241. package/dist/store/index.js.map +0 -1
  242. package/dist/surface-filter.d.ts +0 -13
  243. package/dist/surface-filter.d.ts.map +0 -1
  244. package/dist/surface-filter.js +0 -76
  245. package/dist/surface-filter.js.map +0 -1
  246. package/dist/topo-store.d.ts +0 -62
  247. package/dist/topo-store.d.ts.map +0 -1
  248. package/dist/topo-store.js +0 -319
  249. package/dist/topo-store.js.map +0 -1
  250. package/dist/topo.d.ts +0 -39
  251. package/dist/topo.d.ts.map +0 -1
  252. package/dist/topo.js +0 -241
  253. package/dist/topo.js.map +0 -1
  254. package/dist/trail.d.ts +0 -163
  255. package/dist/trail.d.ts.map +0 -1
  256. package/dist/trail.js +0 -75
  257. package/dist/trail.js.map +0 -1
  258. package/dist/trails/derive-trail.d.ts +0 -66
  259. package/dist/trails/derive-trail.d.ts.map +0 -1
  260. package/dist/trails/derive-trail.js +0 -378
  261. package/dist/trails/derive-trail.js.map +0 -1
  262. package/dist/trails/index.d.ts +0 -5
  263. package/dist/trails/index.d.ts.map +0 -1
  264. package/dist/trails/index.js +0 -3
  265. package/dist/trails/index.js.map +0 -1
  266. package/dist/trails/ingest.d.ts +0 -24
  267. package/dist/trails/ingest.d.ts.map +0 -1
  268. package/dist/trails/ingest.js +0 -63
  269. package/dist/trails/ingest.js.map +0 -1
  270. package/dist/transport-error-map.d.ts +0 -106
  271. package/dist/transport-error-map.d.ts.map +0 -1
  272. package/dist/transport-error-map.js +0 -24
  273. package/dist/transport-error-map.js.map +0 -1
  274. package/dist/type-checks.test-d.d.ts +0 -71
  275. package/dist/type-checks.test-d.d.ts.map +0 -1
  276. package/dist/type-checks.test-d.js +0 -12
  277. package/dist/type-checks.test-d.js.map +0 -1
  278. package/dist/type-utils.d.ts +0 -33
  279. package/dist/type-utils.d.ts.map +0 -1
  280. package/dist/type-utils.js +0 -12
  281. package/dist/type-utils.js.map +0 -1
  282. package/dist/types.d.ts +0 -177
  283. package/dist/types.d.ts.map +0 -1
  284. package/dist/types.js +0 -3
  285. package/dist/types.js.map +0 -1
  286. package/dist/validate-established-topo.d.ts +0 -76
  287. package/dist/validate-established-topo.d.ts.map +0 -1
  288. package/dist/validate-established-topo.js +0 -43
  289. package/dist/validate-established-topo.js.map +0 -1
  290. package/dist/validate-topo.d.ts +0 -24
  291. package/dist/validate-topo.d.ts.map +0 -1
  292. package/dist/validate-topo.js +0 -193
  293. package/dist/validate-topo.js.map +0 -1
  294. package/dist/validation.d.ts +0 -27
  295. package/dist/validation.d.ts.map +0 -1
  296. package/dist/validation.js +0 -165
  297. package/dist/validation.js.map +0 -1
  298. package/dist/workspace.d.ts +0 -25
  299. package/dist/workspace.d.ts.map +0 -1
  300. package/dist/workspace.js +0 -57
  301. package/dist/workspace.js.map +0 -1
  302. package/src/__tests__/blob-ref.test.ts +0 -103
  303. package/src/__tests__/branded.test.ts +0 -148
  304. package/src/__tests__/collections.test.ts +0 -126
  305. package/src/__tests__/context.test.ts +0 -77
  306. package/src/__tests__/contour.test.ts +0 -263
  307. package/src/__tests__/derive-trail.test.ts +0 -668
  308. package/src/__tests__/derive.test.ts +0 -260
  309. package/src/__tests__/errors.test.ts +0 -427
  310. package/src/__tests__/execute.test.ts +0 -1563
  311. package/src/__tests__/fetch.test.ts +0 -217
  312. package/src/__tests__/fire.test.ts +0 -1056
  313. package/src/__tests__/fork-ctx.test.ts +0 -83
  314. package/src/__tests__/guards.test.ts +0 -102
  315. package/src/__tests__/ingest.test.ts +0 -191
  316. package/src/__tests__/layer.test.ts +0 -125
  317. package/src/__tests__/path-security.test.ts +0 -114
  318. package/src/__tests__/patterns.test.ts +0 -273
  319. package/src/__tests__/redaction.test.ts +0 -244
  320. package/src/__tests__/resilience.test.ts +0 -246
  321. package/src/__tests__/resource.test.ts +0 -204
  322. package/src/__tests__/result.test.ts +0 -155
  323. package/src/__tests__/run.test.ts +0 -181
  324. package/src/__tests__/serialization.test.ts +0 -401
  325. package/src/__tests__/service-config.test.ts +0 -224
  326. package/src/__tests__/signal.test.ts +0 -82
  327. package/src/__tests__/surface-filter.test.ts +0 -196
  328. package/src/__tests__/topo-store-read.test.ts +0 -256
  329. package/src/__tests__/topo-store.test.ts +0 -869
  330. package/src/__tests__/topo.test.ts +0 -573
  331. package/src/__tests__/trail-permit.test.ts +0 -60
  332. package/src/__tests__/trail.test.ts +0 -426
  333. package/src/__tests__/trails-db.test.ts +0 -198
  334. package/src/__tests__/transport-error-map.test.ts +0 -82
  335. package/src/__tests__/type-utils.test.ts +0 -118
  336. package/src/__tests__/validate-topo.test.ts +0 -611
  337. package/src/__tests__/validation.test.ts +0 -336
  338. package/src/__tests__/workspace.test.ts +0 -183
  339. package/src/__tests__/zod-wrappers.test.ts +0 -62
  340. package/src/internal/topo-snapshots.ts +0 -517
  341. package/src/internal/topo-store-read.ts +0 -481
  342. package/src/internal/topo-store.ts +0 -1192
  343. package/src/internal/tracing.ts +0 -187
  344. package/src/topo-store.ts +0 -510
  345. package/src/type-checks.test-d.ts +0 -106
  346. package/tsconfig.json +0 -9
  347. package/tsconfig.tests.json +0 -10
  348. package/tsconfig.tsbuildinfo +0 -1
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  // Result
2
- export { Result } from './result.js';
2
+ export { Result, resultAccessorNames } from './result.js';
3
+ export type { ResultAccessorName } from './result.js';
3
4
 
4
5
  // Errors
5
6
  export {
@@ -11,6 +12,7 @@ export {
11
12
  AlreadyExistsError,
12
13
  ConflictError,
13
14
  PermissionError,
15
+ PermitError,
14
16
  TimeoutError,
15
17
  RateLimitError,
16
18
  NetworkError,
@@ -18,6 +20,9 @@ export {
18
20
  AuthError,
19
21
  CancelledError,
20
22
  DerivationError,
23
+ RecoverableCompletionError,
24
+ codesByCategory,
25
+ errorClasses,
21
26
  errorCategories,
22
27
  exitCodeMap,
23
28
  statusCodeMap,
@@ -27,20 +32,40 @@ export {
27
32
  isRetryable,
28
33
  isTrailsError,
29
34
  } from './errors.js';
30
- export type { ErrorCategory } from './errors.js';
35
+ export type {
36
+ DynamicErrorClassRegistryEntry,
37
+ ErrorCategory,
38
+ ErrorCategoryCodes,
39
+ ErrorClassConstructor,
40
+ ErrorClassRegistryEntry,
41
+ FixedErrorClassRegistryEntry,
42
+ } from './errors.js';
31
43
  export {
32
- createTransportErrorMapper,
33
- mapTransportError,
34
- transportErrorMap,
35
- transportErrorRegistry,
36
- transportNames,
44
+ createSurfaceErrorMapper,
45
+ mapSurfaceError,
46
+ projectErrorClassSurface,
47
+ projectPublicSurfaceError,
48
+ projectSurfaceError,
49
+ surfaceErrorMap,
50
+ surfaceErrorRegistry,
51
+ surfaceNames,
37
52
  } from './transport-error-map.js';
38
53
  export type {
39
- TransportErrorCode,
40
- TransportErrorMapper,
41
- TransportErrorMappings,
42
- TransportName,
54
+ ErrorClassSurfaceProjection,
55
+ SurfaceErrorCode,
56
+ SurfaceErrorMapper,
57
+ SurfaceErrorMappings,
58
+ SurfaceErrorProjection,
59
+ SurfaceName,
43
60
  } from './transport-error-map.js';
61
+ export {
62
+ INTERNAL_ERROR_PUBLIC_MESSAGE,
63
+ projectErrorDiagnostics,
64
+ redactErrorContext,
65
+ redactErrorStack,
66
+ redactErrorString,
67
+ } from './error-projection.js';
68
+ export type { ErrorDiagnosticsProjection } from './error-projection.js';
44
69
 
45
70
  // Types
46
71
  export type {
@@ -52,14 +77,34 @@ export type {
52
77
  CrossBatchOptions,
53
78
  CrossFn,
54
79
  FireFn,
55
- BasePermit,
80
+ LogLevel,
81
+ LogFormatter,
82
+ LogRecord,
83
+ LogSink,
56
84
  PermitRequirement,
57
85
  ProgressCallback,
58
86
  ProgressEvent,
59
87
  Logger,
60
88
  ResourceLookup,
61
89
  } from './types.js';
62
- export { TRAILHEAD_KEY } from './types.js';
90
+ export { basePermitSchema } from './permits.js';
91
+ export type { BasePermit } from './permits.js';
92
+ export {
93
+ LAYER_INPUTS_KEY,
94
+ SURFACE_KEY,
95
+ SURFACE_LAYER_NAMES_KEY,
96
+ } from './types.js';
97
+ export {
98
+ ACTIVATION_PROVENANCE_KEY,
99
+ buildActivationProvenanceTraceAttrs,
100
+ getActivationProvenance,
101
+ withActivationProvenance,
102
+ } from './activation-provenance.js';
103
+ export type {
104
+ ActivationProvenance,
105
+ ActivationProvenanceCarrier,
106
+ ActivationProvenanceSource,
107
+ } from './activation-provenance.js';
63
108
 
64
109
  // Context factory
65
110
  export { createTrailContext, passthroughTrace } from './context.js';
@@ -71,16 +116,48 @@ export {
71
116
  isResource,
72
117
  resource,
73
118
  } from './resource.js';
119
+ export { drainResources, resolveResourceConfig } from './resource-config.js';
120
+ export type {
121
+ ResourceConfigValues,
122
+ ResourceDrainReport,
123
+ } from './resource-config.js';
74
124
  export type {
75
125
  AnyResource,
76
126
  Resource,
77
127
  ResourceContext,
78
128
  ResourceOverrideMap,
79
129
  ResourceSpec,
130
+ ResourceUnmockable,
80
131
  } from './resource.js';
81
132
 
82
133
  // Trail
83
- export { trail } from './trail.js';
134
+ export {
135
+ activationSourceKinds,
136
+ getActivationWherePredicate,
137
+ isActivationEntrySpec,
138
+ isActivationSource,
139
+ isKnownActivationSourceKind,
140
+ } from './activation-source.js';
141
+ export type {
142
+ ActivationEntry,
143
+ ActivationEntrySpec,
144
+ ActivationSource,
145
+ ActivationSourceKind,
146
+ ActivationSourceMeta,
147
+ ActivationSourceRef,
148
+ ActivationWhere,
149
+ ActivationWhereExample,
150
+ ActivationWherePredicate,
151
+ ActivationWhereSpec,
152
+ BuiltinActivationSourceKind,
153
+ } from './activation-source.js';
154
+ export {
155
+ activationSourceDeclarationSignature,
156
+ activationSourceKey,
157
+ projectActivationSourceDeclaration,
158
+ } from './activation-source-projection.js';
159
+ export type { ActivationSourceProjection } from './activation-source-projection.js';
160
+ export { intentValues, trail } from './trail.js';
84
161
  export type {
85
162
  AnyTrail,
86
163
  BlazeInput,
@@ -88,6 +165,7 @@ export type {
88
165
  Trail,
89
166
  TrailSpec,
90
167
  TrailExample,
168
+ TrailExampleSignalAssertion,
91
169
  TrailVisibility,
92
170
  } from './trail.js';
93
171
  export {
@@ -96,6 +174,31 @@ export {
96
174
  shouldIncludeTrailForSurface,
97
175
  } from './surface-filter.js';
98
176
  export type { SurfaceFilterOptions } from './surface-filter.js';
177
+ export {
178
+ shouldValidateSurfaceTopo,
179
+ validateSurfaceTopo,
180
+ withSurfaceLayerNames,
181
+ withSurfaceMarker,
182
+ } from './surface-derivation.js';
183
+ export type {
184
+ BaseSurfaceOptions,
185
+ SurfaceConfigValues,
186
+ SurfaceSelectionOptions,
187
+ SurfaceMarkedContext,
188
+ SurfaceValidationOptions,
189
+ } from './surface-derivation.js';
190
+ export {
191
+ deriveStructuredSignalExamples,
192
+ deriveStructuredTrailExamples,
193
+ } from './structured-examples.js';
194
+ export type {
195
+ StructuredSignalExample,
196
+ StructuredSignalExampleProvenance,
197
+ StructuredTrailExample,
198
+ StructuredTrailExampleKind,
199
+ StructuredTrailExampleProvenance,
200
+ StructuredTrailExampleSignalAssertion,
201
+ } from './structured-examples.js';
99
202
 
100
203
  // Type utilities
101
204
  export type {
@@ -109,6 +212,100 @@ export { inputOf, outputOf } from './type-utils.js';
109
212
  // Signal
110
213
  export { signal } from './signal.js';
111
214
  export type { AnySignal, Signal, SignalSpec } from './signal.js';
215
+ export { schedule, validateScheduleSource } from './schedule.js';
216
+ export type {
217
+ ScheduleSource,
218
+ ScheduleSpec,
219
+ ScheduleValidationIssue,
220
+ } from './schedule.js';
221
+ export {
222
+ getWebhookHeader,
223
+ getWebhookHeaders,
224
+ validateWebhookSource,
225
+ verifyWebhookRequest,
226
+ webhook,
227
+ webhookMethods,
228
+ } from './webhook.js';
229
+ export type {
230
+ WebhookMethod,
231
+ WebhookMethodInput,
232
+ WebhookSource,
233
+ WebhookSpec,
234
+ WebhookValidationIssue,
235
+ WebhookVerify,
236
+ WebhookVerifyHeaders,
237
+ WebhookVerifyRequest,
238
+ } from './webhook.js';
239
+ export { createScheduleRuntime } from './schedule-runtime.js';
240
+ export type {
241
+ ScheduleCronFactory,
242
+ ScheduleCronHandler,
243
+ ScheduleCronJob,
244
+ ScheduleRuntime,
245
+ ScheduleRuntimeLogger,
246
+ ScheduleRuntimeOptions,
247
+ ScheduleRuntimeRegistrationReport,
248
+ ScheduleRuntimeRunRecord,
249
+ ScheduleRuntimeRunStatus,
250
+ ScheduleRuntimeSkipReason,
251
+ ScheduleRuntimeStartReport,
252
+ ScheduleRuntimeState,
253
+ ScheduleRuntimeStopReport,
254
+ ScheduleRuntimeWarning,
255
+ ScheduleRuntimeWarningCode,
256
+ } from './schedule-runtime.js';
257
+ export {
258
+ SIGNAL_DIAGNOSTICS_SINK_KEY,
259
+ SIGNAL_DIAGNOSTICS_STRICT_MODE_KEY,
260
+ createSignalFireSuppressedDiagnostic,
261
+ createSignalHandlerFailedDiagnostic,
262
+ createSignalHandlerRejectedDiagnostic,
263
+ createSignalInvalidDiagnostic,
264
+ createSignalPredicateFailedDiagnostic,
265
+ createSignalUnknownDiagnostic,
266
+ recordSignalDiagnostic,
267
+ shouldPromoteSignalDiagnostic,
268
+ signalDiagnosticDefinitions,
269
+ summarizeSignalPayload,
270
+ } from './signal-diagnostics.js';
271
+ export type {
272
+ CreateSignalFireSuppressedDiagnosticInput,
273
+ CreateSignalHandlerDiagnosticInput,
274
+ CreateSignalInvalidDiagnosticInput,
275
+ SignalDiagnostic,
276
+ SignalDiagnosticCategory,
277
+ SignalDiagnosticCause,
278
+ SignalDiagnosticCode,
279
+ SignalDiagnosticCommonInput,
280
+ SignalDiagnosticContext,
281
+ SignalDiagnosticLevel,
282
+ SignalDiagnosticPathSegment,
283
+ SignalDiagnosticRecordResult,
284
+ SignalDiagnosticSchemaIssue,
285
+ SignalDiagnosticSink,
286
+ SignalDiagnosticOrigin,
287
+ SignalDiagnosticSourceLocation,
288
+ SignalDiagnosticStrictMode,
289
+ SignalFireSuppressedDiagnostic,
290
+ SignalHandlerFailedDiagnostic,
291
+ SignalHandlerRejectedDiagnostic,
292
+ SignalInvalidDiagnostic,
293
+ SignalPredicateFailedDiagnostic,
294
+ SignalPayloadShape,
295
+ SignalPayloadSummary,
296
+ SignalUnknownDiagnostic,
297
+ } from './signal-diagnostics.js';
298
+ export {
299
+ attachLateBoundSignalRef,
300
+ cloneSignalWithId,
301
+ createLateBoundSignalMarker,
302
+ getLateBoundSignalRef,
303
+ parseLateBoundSignalMarker,
304
+ } from './signal-ref.js';
305
+ export type {
306
+ LateBoundSignalMarker,
307
+ LateBoundSignalRef,
308
+ } from './signal-ref.js';
112
309
 
113
310
  // Contour
114
311
  export { contour } from './contour.js';
@@ -131,27 +328,24 @@ export type {
131
328
  // Topo
132
329
  export { topo } from './topo.js';
133
330
  export type { Topo, TopoIdentity } from './topo.js';
331
+
332
+ // Generic trails-db helpers (shared framework infrastructure per ADR-0014).
333
+ // The topo-store public API that previously lived here moved to
334
+ // `@ontrails/topographer` per ADR-0042.
134
335
  export {
135
- createTopoSnapshot,
136
- createMockTopoStore,
137
- createTopoStore,
138
- listTopoSnapshots,
139
- pinTopoSnapshot,
140
- topoStore,
141
- unpinTopoSnapshot,
142
- } from './topo-store.js';
336
+ deriveTrailsDbPath,
337
+ deriveTrailsDir,
338
+ ensureSubsystemSchema,
339
+ ensureTrailsWorkspace,
340
+ openReadTrailsDb,
341
+ openWriteTrailsDb,
342
+ WORKSPACE_GITIGNORE_CONTENT,
343
+ WORKSPACE_GITIGNORE_LINES,
344
+ } from './trails-db.js';
143
345
  export type {
144
- CreateTopoSnapshotInput,
145
- ListTopoSnapshotsOptions,
146
- MockTopoStoreSeed,
147
- ReadOnlyTopoStore,
148
- TopoSnapshot,
149
- TopoStoreExportRecord,
150
- TopoStoreResourceRecord,
151
- TopoStoreRef,
152
- TopoStoreTrailDetailRecord,
153
- TopoStoreTrailRecord,
154
- } from './topo-store.js';
346
+ EnsureSubsystemSchemaOptions,
347
+ TrailsDbLocationOptions,
348
+ } from './trails-db.js';
155
349
 
156
350
  // Draft state
157
351
  export {
@@ -174,7 +368,21 @@ export { validateEstablishedTopo } from './validate-established-topo.js';
174
368
 
175
369
  // Layer
176
370
  export { composeLayers } from './layer.js';
177
- export type { Layer } from './layer.js';
371
+ export type { Layer, LayerInputSchema } from './layer.js';
372
+ export {
373
+ collectAttachedTypedLayers,
374
+ LAYER_FIELD_RESERVED_NAMES,
375
+ LAYER_FIELD_RESERVED_NAMES_KEBAB,
376
+ projectLayerFieldName,
377
+ } from './layer-projection.js';
378
+ export type {
379
+ AttachedLayerScope,
380
+ AttachedTypedLayer,
381
+ LayerFieldProjection,
382
+ LayerFieldRenameReason,
383
+ ProjectedLayerField,
384
+ RenamedLayerFieldProjection,
385
+ } from './layer-projection.js';
178
386
 
179
387
  // Derive
180
388
  export { deriveCliPath, deriveFields } from './derive.js';
@@ -182,28 +390,55 @@ export type { Field, FieldOverride } from './derive.js';
182
390
 
183
391
  // Cross schema
184
392
  export { buildCrossValidationSchema } from './cross-schema.js';
393
+ export {
394
+ claimNextCrossBatchIndex,
395
+ createCrossBatchValidationResults,
396
+ normalizeCrossBatchConcurrency,
397
+ } from './cross-batch.js';
185
398
 
186
399
  // Execute
400
+ export { DETOUR_MAX_ATTEMPTS_CAP } from './detours.js';
187
401
  export { executeTrail } from './execute.js';
188
402
  export type { ExecuteTrailOptions } from './execute.js';
189
403
 
190
404
  // Intrinsic tracing
191
405
  export {
192
406
  clearTraceSink,
407
+ createActivationTraceRecord,
193
408
  createTraceRecord,
194
409
  getTraceContext,
195
410
  getTraceSink,
196
411
  NOOP_SINK,
197
412
  registerTraceSink,
198
413
  TRACE_CONTEXT_KEY,
199
- } from './internal/tracing.js';
414
+ traceContextFromRecord,
415
+ writeActivationTraceRecord,
416
+ } from './tracing.js';
200
417
  export type {
418
+ ActivationTraceRecordName,
419
+ SignalTraceRecordName,
201
420
  TraceContext,
202
421
  TraceRecord,
203
422
  TraceSink,
204
- } from './internal/tracing.js';
423
+ } from './tracing.js';
205
424
  export type { TraceFn } from './types.js';
206
425
 
426
+ // Observe
427
+ export {
428
+ createObserveLogger,
429
+ isLogSink,
430
+ isLogger,
431
+ isObserveInput,
432
+ isTraceSink,
433
+ normalizeObserve,
434
+ } from './observe.js';
435
+ export type {
436
+ ObserveCapabilities,
437
+ ObserveConfig,
438
+ ObserveInput,
439
+ TopoOptions,
440
+ } from './observe.js';
441
+
207
442
  // Run
208
443
  export { run } from './run.js';
209
444
  export type { RunOptions } from './run.js';
@@ -226,6 +461,10 @@ export {
226
461
  formatZodIssues,
227
462
  zodToJsonSchema,
228
463
  } from './validation.js';
464
+ export {
465
+ stripDefaultWrappers,
466
+ stripDefaultsFromShape,
467
+ } from './zod-wrappers.js';
229
468
 
230
469
  // Serialization
231
470
  export { serializeError, deserializeError } from './serialization.js';
@@ -272,8 +511,16 @@ export {
272
511
  } from './workspace.js';
273
512
 
274
513
  // Blob
275
- export { createBlobRef, isBlobRef } from './blob-ref.js';
276
- export type { BlobRef } from './blob-ref.js';
514
+ export {
515
+ BLOB_REF_SCHEMA_META_KEY,
516
+ blobRefDescriptorSchema,
517
+ blobRefJsonSchema,
518
+ blobRefSchema,
519
+ createBlobRef,
520
+ isBlobRef,
521
+ toBlobRefDescriptor,
522
+ } from './blob-ref.js';
523
+ export type { BlobRef, BlobRefDescriptor } from './blob-ref.js';
277
524
 
278
525
  // Guards
279
526
  export {
@@ -0,0 +1,192 @@
1
+ /**
2
+ * Shared, surface-agnostic helpers for projecting typed layer `input` schemas
3
+ * onto a surface's native idiom.
4
+ *
5
+ * Layer projection has two halves:
6
+ * 1. **Collection** — walk the trail's effective layers (topo → surface →
7
+ * trail) and keep only the ones that declare an `input` schema. These
8
+ * are the layers a surface needs to project.
9
+ * 2. **Naming/collision policy** — when a layer field's projected name
10
+ * collides with a name already claimed by the trail, by another layer,
11
+ * or by a surface-reserved name, the field is renamed using the
12
+ * deterministic `<layerName>-<originalField>` rule. The collision-detection
13
+ * logic itself is surface-agnostic; the *shape* of the projected name
14
+ * (kebab-case CLI flag, camelCase MCP parameter, HTTP request field)
15
+ * stays per-surface.
16
+ *
17
+ * This module owns the surface-agnostic half. CLI/MCP/HTTP each layer their
18
+ * own projection on top: see `@ontrails/cli/build`, `@ontrails/mcp/build`,
19
+ * and `@ontrails/http/build`.
20
+ *
21
+ * @see TRL-473 for the CLI projection that introduced this contract.
22
+ * @see TRL-474 for the MCP and HTTP projections that lifted these helpers.
23
+ */
24
+
25
+ import type { Layer } from './layer.js';
26
+ import type { Topo } from './topo.js';
27
+ import type { AnyTrail } from './trail.js';
28
+
29
+ export const LAYER_FIELD_RESERVED_NAMES: ReadonlySet<string> = new Set([
30
+ 'all',
31
+ 'devPermit',
32
+ 'dryRun',
33
+ 'input',
34
+ 'inputJson',
35
+ 'json',
36
+ 'jsonl',
37
+ 'output',
38
+ 'permit',
39
+ 'quiet',
40
+ 'token',
41
+ 'trace',
42
+ 'watch',
43
+ ]);
44
+
45
+ const toKebabCase = (name: string): string =>
46
+ name.replaceAll(/[A-Z]/g, (ch) => `-${ch.toLowerCase()}`);
47
+
48
+ export const LAYER_FIELD_RESERVED_NAMES_KEBAB: ReadonlySet<string> = new Set(
49
+ [...LAYER_FIELD_RESERVED_NAMES].map(toKebabCase)
50
+ );
51
+
52
+ // ---------------------------------------------------------------------------
53
+ // Collection
54
+ // ---------------------------------------------------------------------------
55
+
56
+ /**
57
+ * Source of a typed layer attached to a trail.
58
+ *
59
+ * Surfaces may want to know whether a layer came from topo-, surface-, or
60
+ * trail-scope (e.g. for descriptive errors). The collection helper preserves
61
+ * this information so callers don't have to recompute it.
62
+ */
63
+ export type AttachedLayerScope = 'topo' | 'surface' | 'trail';
64
+
65
+ export interface AttachedTypedLayer {
66
+ readonly layer: Layer;
67
+ readonly scope: AttachedLayerScope;
68
+ }
69
+
70
+ /**
71
+ * Collect every typed layer attached to a trail in the same composition order
72
+ * the executor uses (topo → surface → trail). Layers without an `input`
73
+ * schema are skipped — they have nothing to project onto a surface.
74
+ *
75
+ * @param graph - The topo carrying topo-scope layers.
76
+ * @param trail - The trail whose effective layers we are projecting.
77
+ * @param surfaceLayers - Layers attached at surface scope (`options.layers`
78
+ * on the surface builder).
79
+ */
80
+ export const collectAttachedTypedLayers = (
81
+ graph: Topo,
82
+ trail: AnyTrail,
83
+ surfaceLayers?: readonly Layer[] | undefined
84
+ ): readonly AttachedTypedLayer[] => {
85
+ const layers: AttachedTypedLayer[] = [];
86
+ for (const layer of graph.layers) {
87
+ if (layer.input !== undefined) {
88
+ layers.push({ layer, scope: 'topo' });
89
+ }
90
+ }
91
+ if (surfaceLayers !== undefined) {
92
+ for (const layer of surfaceLayers) {
93
+ if (layer.input !== undefined) {
94
+ layers.push({ layer, scope: 'surface' });
95
+ }
96
+ }
97
+ }
98
+ for (const layer of trail.layers) {
99
+ if (layer.input !== undefined) {
100
+ layers.push({ layer, scope: 'trail' });
101
+ }
102
+ }
103
+ return layers;
104
+ };
105
+
106
+ // ---------------------------------------------------------------------------
107
+ // Collision rename rule
108
+ // ---------------------------------------------------------------------------
109
+
110
+ /**
111
+ * Reason a layer field was renamed during projection.
112
+ *
113
+ * Surfaces map this onto their own warning/error idiom. CLI emits a stderr
114
+ * warning, while MCP/HTTP rely on the projected schema as the source of truth.
115
+ */
116
+ export type LayerFieldRenameReason = 'reserved-name' | 'flag-collision';
117
+
118
+ /**
119
+ * Outcome of projecting a single layer field's name.
120
+ *
121
+ * `claimedName` is the name the surface will publish to consumers; it is the
122
+ * field name when no collision was detected, or `<layerName>-<fieldName>` (or
123
+ * an analogous transformed form, depending on the surface's convention) when
124
+ * a collision required a rename. `routingTarget` is the original field name
125
+ * the value should be assigned back to inside the layer's runtime input.
126
+ */
127
+ export interface LayerFieldProjection {
128
+ readonly claimedName: string;
129
+ readonly routingTarget: string;
130
+ readonly renamed: false;
131
+ }
132
+
133
+ export interface RenamedLayerFieldProjection {
134
+ readonly claimedName: string;
135
+ readonly routingTarget: string;
136
+ readonly renamed: true;
137
+ readonly originalName: string;
138
+ readonly reason: LayerFieldRenameReason;
139
+ }
140
+
141
+ export type ProjectedLayerField =
142
+ | LayerFieldProjection
143
+ | RenamedLayerFieldProjection;
144
+
145
+ /**
146
+ * Apply the deterministic collision rename rule to a single projected layer
147
+ * field name.
148
+ *
149
+ * @param layerName - The layer's logical name (used as the rename prefix).
150
+ * @param originalName - The layer field's name as authored on its schema.
151
+ * @param projectedName - The candidate name in the surface's native idiom
152
+ * (e.g. kebab-case for CLI, camelCase for MCP, request field for HTTP).
153
+ * @param renamedName - The fallback name applied when a collision is detected.
154
+ * Surfaces compute this with their own casing rule.
155
+ * @param claimedNames - Names already taken by the trail's input or by
156
+ * previous layer projections. Updated in place when a name is claimed.
157
+ * @param reservedNames - Framework-owned names that force a rename across
158
+ * surface projections.
159
+ */
160
+ export const projectLayerFieldName = (
161
+ _layerName: string,
162
+ originalName: string,
163
+ projectedName: string,
164
+ renamedName: string,
165
+ claimedNames: Set<string>,
166
+ reservedNames: ReadonlySet<string>
167
+ ): ProjectedLayerField => {
168
+ const collidesWithClaimed = claimedNames.has(projectedName);
169
+ const collidesWithReserved = reservedNames.has(projectedName);
170
+
171
+ if (!collidesWithClaimed && !collidesWithReserved) {
172
+ claimedNames.add(projectedName);
173
+ return {
174
+ claimedName: projectedName,
175
+ renamed: false,
176
+ routingTarget: originalName,
177
+ };
178
+ }
179
+
180
+ let claimedName = renamedName;
181
+ for (let suffix = 2; claimedNames.has(claimedName); suffix += 1) {
182
+ claimedName = `${renamedName}${suffix}`;
183
+ }
184
+ claimedNames.add(claimedName);
185
+ return {
186
+ claimedName,
187
+ originalName: projectedName,
188
+ reason: collidesWithReserved ? 'reserved-name' : 'flag-collision',
189
+ renamed: true,
190
+ routingTarget: originalName,
191
+ };
192
+ };
package/src/layer.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import type { z } from 'zod';
2
+
1
3
  import type { AnyTrail } from './trail.js';
2
4
  import type { Implementation } from './types.js';
3
5
 
@@ -5,11 +7,40 @@ import type { Implementation } from './types.js';
5
7
  // Layer interface
6
8
  // ---------------------------------------------------------------------------
7
9
 
8
- /** A composable layer that wraps trail implementations. */
10
+ /**
11
+ * A composable, named layer that wraps trail implementations.
12
+ *
13
+ * Layers attach at trail, surface, or topo scope and may declare an object
14
+ * `input` schema describing the configuration they need from the surrounding
15
+ * surface. Surface packages (CLI, MCP, HTTP) project this schema onto their
16
+ * native idioms — flags, tool parameters, query strings — alongside the
17
+ * trail's own input schema.
18
+ *
19
+ * @remarks
20
+ * The `input` schema is metadata for surface projection. It must be an object
21
+ * schema so every surface can project named fields consistently. It is
22
+ * optional; layers without an `input` schema behave as plain wrappers. The
23
+ * layer's `wrap` function is the runtime contract.
24
+ */
25
+ export type LayerInputSchema = z.ZodObject<z.ZodRawShape>;
26
+
9
27
  export interface Layer {
10
28
  readonly name: string;
11
29
  readonly description?: string | undefined;
12
30
 
31
+ /**
32
+ * Authored configuration the layer needs from the surrounding surface.
33
+ *
34
+ * Surface packages project this schema onto their native idioms (CLI flags,
35
+ * MCP tool parameters, HTTP query strings) so a layer's input fields appear
36
+ * alongside the trail's own input fields. Optional — layers that wrap purely
37
+ * by behavior, with no surface-visible inputs, may omit it.
38
+ *
39
+ * @see TRL-473 for CLI flag projection.
40
+ * @see TRL-474 for MCP and HTTP projection.
41
+ */
42
+ readonly input?: LayerInputSchema | undefined;
43
+
13
44
  /**
14
45
  * Wrap a trail's implementation, returning a new implementation.
15
46
  *