@relayflows/sdk 2.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 (231) hide show
  1. package/dist/authored-flow-error.d.ts +9 -0
  2. package/dist/authored-flow-error.d.ts.map +1 -0
  3. package/dist/authored-flow-error.js +13 -0
  4. package/dist/authored-flow-error.js.map +1 -0
  5. package/dist/authored-flow-executor.d.ts +28 -0
  6. package/dist/authored-flow-executor.d.ts.map +1 -0
  7. package/dist/authored-flow-executor.js +203 -0
  8. package/dist/authored-flow-executor.js.map +1 -0
  9. package/dist/authored-flow-lifecycle.d.ts +61 -0
  10. package/dist/authored-flow-lifecycle.d.ts.map +1 -0
  11. package/dist/authored-flow-lifecycle.js +284 -0
  12. package/dist/authored-flow-lifecycle.js.map +1 -0
  13. package/dist/authored-flow-loader.d.ts +7 -0
  14. package/dist/authored-flow-loader.d.ts.map +1 -0
  15. package/dist/authored-flow-loader.js +39 -0
  16. package/dist/authored-flow-loader.js.map +1 -0
  17. package/dist/authored-flow-operation.d.ts +43 -0
  18. package/dist/authored-flow-operation.d.ts.map +1 -0
  19. package/dist/authored-flow-operation.js +176 -0
  20. package/dist/authored-flow-operation.js.map +1 -0
  21. package/dist/authored-flow.d.ts +12 -0
  22. package/dist/authored-flow.d.ts.map +1 -0
  23. package/dist/authored-flow.js +13 -0
  24. package/dist/authored-flow.js.map +1 -0
  25. package/dist/authored-promise-graph.d.ts +67 -0
  26. package/dist/authored-promise-graph.d.ts.map +1 -0
  27. package/dist/authored-promise-graph.js +206 -0
  28. package/dist/authored-promise-graph.js.map +1 -0
  29. package/dist/backlog-picker.d.ts +55 -0
  30. package/dist/backlog-picker.d.ts.map +1 -0
  31. package/dist/backlog-picker.js +117 -0
  32. package/dist/backlog-picker.js.map +1 -0
  33. package/dist/canonical.d.ts +18 -0
  34. package/dist/canonical.d.ts.map +1 -0
  35. package/dist/canonical.js +55 -0
  36. package/dist/canonical.js.map +1 -0
  37. package/dist/cli/check.d.ts +30 -0
  38. package/dist/cli/check.d.ts.map +1 -0
  39. package/dist/cli/check.js +324 -0
  40. package/dist/cli/check.js.map +1 -0
  41. package/dist/cli/direct-run.d.ts +3 -0
  42. package/dist/cli/direct-run.d.ts.map +1 -0
  43. package/dist/cli/direct-run.js +69 -0
  44. package/dist/cli/direct-run.js.map +1 -0
  45. package/dist/cli/hn-monitor.d.ts +107 -0
  46. package/dist/cli/hn-monitor.d.ts.map +1 -0
  47. package/dist/cli/hn-monitor.js +220 -0
  48. package/dist/cli/hn-monitor.js.map +1 -0
  49. package/dist/cli/interruptible-sleep.d.ts +13 -0
  50. package/dist/cli/interruptible-sleep.d.ts.map +1 -0
  51. package/dist/cli/interruptible-sleep.js +31 -0
  52. package/dist/cli/interruptible-sleep.js.map +1 -0
  53. package/dist/cli/run.d.ts +54 -0
  54. package/dist/cli/run.d.ts.map +1 -0
  55. package/dist/cli/run.js +316 -0
  56. package/dist/cli/run.js.map +1 -0
  57. package/dist/cli/tick-runner.d.ts +151 -0
  58. package/dist/cli/tick-runner.d.ts.map +1 -0
  59. package/dist/cli/tick-runner.js +258 -0
  60. package/dist/cli/tick-runner.js.map +1 -0
  61. package/dist/cli-adapter.d.ts +29 -0
  62. package/dist/cli-adapter.d.ts.map +1 -0
  63. package/dist/cli-adapter.js +92 -0
  64. package/dist/cli-adapter.js.map +1 -0
  65. package/dist/cli-executable.d.ts +3 -0
  66. package/dist/cli-executable.d.ts.map +1 -0
  67. package/dist/cli-executable.js +10 -0
  68. package/dist/cli-executable.js.map +1 -0
  69. package/dist/cli.d.ts +9 -0
  70. package/dist/cli.d.ts.map +1 -0
  71. package/dist/cli.js +348 -0
  72. package/dist/cli.js.map +1 -0
  73. package/dist/compile.d.ts +42 -0
  74. package/dist/compile.d.ts.map +1 -0
  75. package/dist/compile.js +515 -0
  76. package/dist/compile.js.map +1 -0
  77. package/dist/demo-hn-monitor.d.ts +2 -0
  78. package/dist/demo-hn-monitor.d.ts.map +1 -0
  79. package/dist/demo-hn-monitor.js +118 -0
  80. package/dist/demo-hn-monitor.js.map +1 -0
  81. package/dist/dir-watcher-poller.d.ts +73 -0
  82. package/dist/dir-watcher-poller.d.ts.map +1 -0
  83. package/dist/dir-watcher-poller.js +80 -0
  84. package/dist/dir-watcher-poller.js.map +1 -0
  85. package/dist/direct-input.d.ts +10 -0
  86. package/dist/direct-input.d.ts.map +1 -0
  87. package/dist/direct-input.js +61 -0
  88. package/dist/direct-input.js.map +1 -0
  89. package/dist/failure-kinds.d.ts +25 -0
  90. package/dist/failure-kinds.d.ts.map +1 -0
  91. package/dist/failure-kinds.js +64 -0
  92. package/dist/failure-kinds.js.map +1 -0
  93. package/dist/gate-contract.d.ts +24 -0
  94. package/dist/gate-contract.d.ts.map +1 -0
  95. package/dist/gate-contract.js +50 -0
  96. package/dist/gate-contract.js.map +1 -0
  97. package/dist/hn-poller.d.ts +50 -0
  98. package/dist/hn-poller.d.ts.map +1 -0
  99. package/dist/hn-poller.js +79 -0
  100. package/dist/hn-poller.js.map +1 -0
  101. package/dist/index.d.ts +21 -0
  102. package/dist/index.d.ts.map +1 -0
  103. package/dist/index.js +30 -0
  104. package/dist/index.js.map +1 -0
  105. package/dist/journal-client.d.ts +122 -0
  106. package/dist/journal-client.d.ts.map +1 -0
  107. package/dist/journal-client.js +277 -0
  108. package/dist/journal-client.js.map +1 -0
  109. package/dist/json-schema-bound.d.ts +7 -0
  110. package/dist/json-schema-bound.d.ts.map +1 -0
  111. package/dist/json-schema-bound.js +353 -0
  112. package/dist/json-schema-bound.js.map +1 -0
  113. package/dist/json-schema.d.ts +5 -0
  114. package/dist/json-schema.d.ts.map +1 -0
  115. package/dist/json-schema.js +72 -0
  116. package/dist/json-schema.js.map +1 -0
  117. package/dist/json-value.d.ts +6 -0
  118. package/dist/json-value.d.ts.map +1 -0
  119. package/dist/json-value.js +94 -0
  120. package/dist/json-value.js.map +1 -0
  121. package/dist/model-name.d.ts +7 -0
  122. package/dist/model-name.d.ts.map +1 -0
  123. package/dist/model-name.js +21 -0
  124. package/dist/model-name.js.map +1 -0
  125. package/dist/output-schema.d.ts +8 -0
  126. package/dist/output-schema.d.ts.map +1 -0
  127. package/dist/output-schema.js +28 -0
  128. package/dist/output-schema.js.map +1 -0
  129. package/dist/preflight.d.ts +80 -0
  130. package/dist/preflight.d.ts.map +1 -0
  131. package/dist/preflight.js +361 -0
  132. package/dist/preflight.js.map +1 -0
  133. package/dist/protocol.d.ts +359 -0
  134. package/dist/protocol.d.ts.map +1 -0
  135. package/dist/protocol.js +15 -0
  136. package/dist/protocol.js.map +1 -0
  137. package/dist/spec.d.ts +294 -0
  138. package/dist/spec.d.ts.map +1 -0
  139. package/dist/spec.js +13 -0
  140. package/dist/spec.js.map +1 -0
  141. package/dist/step-dependencies.d.ts +2 -0
  142. package/dist/step-dependencies.d.ts.map +1 -0
  143. package/dist/step-dependencies.js +88 -0
  144. package/dist/step-dependencies.js.map +1 -0
  145. package/dist/step-fields.d.ts +17 -0
  146. package/dist/step-fields.d.ts.map +1 -0
  147. package/dist/step-fields.js +32 -0
  148. package/dist/step-fields.js.map +1 -0
  149. package/dist/tick-source.d.ts +205 -0
  150. package/dist/tick-source.d.ts.map +1 -0
  151. package/dist/tick-source.js +234 -0
  152. package/dist/tick-source.js.map +1 -0
  153. package/dist/unknown-keys.d.ts +7 -0
  154. package/dist/unknown-keys.d.ts.map +1 -0
  155. package/dist/unknown-keys.js +47 -0
  156. package/dist/unknown-keys.js.map +1 -0
  157. package/dist/validate.d.ts +7 -0
  158. package/dist/validate.d.ts.map +1 -0
  159. package/dist/validate.js +458 -0
  160. package/dist/validate.js.map +1 -0
  161. package/dist/work-package-consumer.d.ts +33 -0
  162. package/dist/work-package-consumer.d.ts.map +1 -0
  163. package/dist/work-package-consumer.js +44 -0
  164. package/dist/work-package-consumer.js.map +1 -0
  165. package/dist/work-package-validator.d.ts +15 -0
  166. package/dist/work-package-validator.d.ts.map +1 -0
  167. package/dist/work-package-validator.js +72 -0
  168. package/dist/work-package-validator.js.map +1 -0
  169. package/dist/worker-cli.d.ts +16 -0
  170. package/dist/worker-cli.d.ts.map +1 -0
  171. package/dist/worker-cli.js +77 -0
  172. package/dist/worker-cli.js.map +1 -0
  173. package/dist/worker.d.ts +57 -0
  174. package/dist/worker.d.ts.map +1 -0
  175. package/dist/worker.js +129 -0
  176. package/dist/worker.js.map +1 -0
  177. package/dist/wrapper-runtime.d.ts +10 -0
  178. package/dist/wrapper-runtime.d.ts.map +1 -0
  179. package/dist/wrapper-runtime.js +83 -0
  180. package/dist/wrapper-runtime.js.map +1 -0
  181. package/dist/wrapper-session.d.ts +16 -0
  182. package/dist/wrapper-session.d.ts.map +1 -0
  183. package/dist/wrapper-session.js +244 -0
  184. package/dist/wrapper-session.js.map +1 -0
  185. package/package.json +50 -0
  186. package/src/authored-flow-error.ts +31 -0
  187. package/src/authored-flow-executor.ts +365 -0
  188. package/src/authored-flow-lifecycle.ts +344 -0
  189. package/src/authored-flow-loader.ts +44 -0
  190. package/src/authored-flow-operation.ts +252 -0
  191. package/src/authored-flow.ts +21 -0
  192. package/src/authored-promise-graph.ts +196 -0
  193. package/src/backlog-picker.ts +153 -0
  194. package/src/canonical.ts +57 -0
  195. package/src/cli/check.ts +391 -0
  196. package/src/cli/direct-run.ts +86 -0
  197. package/src/cli/hn-monitor.ts +286 -0
  198. package/src/cli/interruptible-sleep.ts +27 -0
  199. package/src/cli/run.ts +439 -0
  200. package/src/cli/tick-runner.ts +378 -0
  201. package/src/cli-adapter.ts +115 -0
  202. package/src/cli-executable.ts +12 -0
  203. package/src/cli.ts +364 -0
  204. package/src/compile.ts +573 -0
  205. package/src/demo-hn-monitor.ts +132 -0
  206. package/src/dir-watcher-poller.ts +122 -0
  207. package/src/direct-input.ts +69 -0
  208. package/src/failure-kinds.ts +77 -0
  209. package/src/gate-contract.ts +72 -0
  210. package/src/hn-poller.ts +104 -0
  211. package/src/index.ts +195 -0
  212. package/src/journal-client.ts +379 -0
  213. package/src/json-schema-bound.ts +357 -0
  214. package/src/json-schema.ts +65 -0
  215. package/src/json-value.ts +110 -0
  216. package/src/model-name.ts +20 -0
  217. package/src/output-schema.ts +33 -0
  218. package/src/preflight.ts +482 -0
  219. package/src/protocol.ts +364 -0
  220. package/src/spec.ts +343 -0
  221. package/src/step-dependencies.ts +100 -0
  222. package/src/step-fields.ts +36 -0
  223. package/src/tick-source.ts +334 -0
  224. package/src/unknown-keys.ts +52 -0
  225. package/src/validate.ts +503 -0
  226. package/src/work-package-consumer.ts +73 -0
  227. package/src/work-package-validator.ts +90 -0
  228. package/src/worker-cli.ts +110 -0
  229. package/src/worker.ts +150 -0
  230. package/src/wrapper-runtime.ts +93 -0
  231. package/src/wrapper-session.ts +287 -0
@@ -0,0 +1,359 @@
1
+ import type { KernelRunSpec, StepType } from './spec.js';
2
+ /** Stamped per segment; readers read every past version, writers write newest. */
3
+ export declare const PROTOCOL_VERSION: 0;
4
+ /** A journal append that fails fails the step (AGENTS.md rule 4). */
5
+ export declare const JOURNAL_WRITE_FAILED: "journal_write_failed";
6
+ export type ProtocolError = {
7
+ code: string;
8
+ message: string;
9
+ };
10
+ /** Client -> server. */
11
+ export interface Request<P = unknown> {
12
+ id: string;
13
+ verb: string;
14
+ params: P;
15
+ }
16
+ /** Server -> client response, correlated by `id`. */
17
+ export type Response<R = unknown> = {
18
+ id: string;
19
+ ok: true;
20
+ result: R;
21
+ } | {
22
+ id: string;
23
+ ok: false;
24
+ error: ProtocolError;
25
+ };
26
+ /** Server -> client push (no `id`). */
27
+ export interface ServerEvent {
28
+ event: string;
29
+ data: unknown;
30
+ }
31
+ export type Verb = 'hello' | 'run.start' | 'run.resume' | 'run.cancel' | 'run.get' | 'run.watch' | 'worker.attach' | 'step.heartbeat' | 'effect.record' | 'effect.confirm' | 'step.complete' | 'event.emit' | 'event.submit' | 'stream.append' | 'stream.read' | 'journal.read';
32
+ export interface HelloParams {
33
+ protocol: 0;
34
+ client: string;
35
+ }
36
+ export interface HelloResult {
37
+ protocol: 0;
38
+ server: string;
39
+ }
40
+ export interface RunStartParams {
41
+ /**
42
+ * The kernel spec dialect — the ONE boundary shape `RunSpec::parse`
43
+ * accepts (snake_case, flat v0 verification, defaults materialized).
44
+ * The authoring `FlowSpec` never crosses the wire; `JournalClient.runStart`
45
+ * converts via `toKernelSpec`.
46
+ */
47
+ spec: KernelRunSpec;
48
+ }
49
+ export type RunStatus = 'running' | 'completed' | 'failed' | 'interrupted' | 'parked';
50
+ export type RunCompletionReason = 'success' | 'step_failed' | 'canceled' | 'budget_exceeded';
51
+ export interface RunOutcome {
52
+ run_id: string;
53
+ status: RunStatus;
54
+ completion_reason: RunCompletionReason | null;
55
+ completed_steps: number;
56
+ }
57
+ export type RunStartResult = RunOutcome;
58
+ export interface RunResumeParams {
59
+ run_id: string;
60
+ }
61
+ export type RunResumeResult = RunOutcome;
62
+ export interface RunCancelParams {
63
+ run_id: string;
64
+ }
65
+ export type RunCancelResult = RunOutcome;
66
+ export interface RunGetParams {
67
+ run_id: string;
68
+ }
69
+ export type StepStatus = 'pending' | 'runnable' | 'running' | 'backoff' | 'waiting' | 'needs_human' | 'done';
70
+ export interface StepSnapshot {
71
+ type: StepType;
72
+ state: StepStatus;
73
+ lease_deadline_ms?: number;
74
+ }
75
+ export interface RunGetResult {
76
+ run_id: string;
77
+ status: RunStatus;
78
+ steps: Record<string, StepSnapshot>;
79
+ budget: {
80
+ tokens_in: number;
81
+ tokens_out: number;
82
+ dollars: string;
83
+ };
84
+ }
85
+ export interface RunWatchParams {
86
+ run_id: string;
87
+ }
88
+ export interface RunWatchResult {
89
+ watching: string;
90
+ }
91
+ /** `run.watch` opens a push stream of `{event: "entry", data: Entry}`. */
92
+ export interface WorkerAttachParams {
93
+ worker_id: string;
94
+ step_types: StepType[];
95
+ /** Maximum concurrent assignments. Omitted means the conservative default 1. */
96
+ capacity?: number;
97
+ /**
98
+ * The surfaces this worker holds, as opaque revisions/offsets. Required when
99
+ * `step_types` includes `agent` — an agent attempt's start pins come from
100
+ * here (Appendix A rule 2), so an agent worker with no pins is refused at
101
+ * attach rather than failing in the middle of a run.
102
+ */
103
+ pins?: Pins;
104
+ }
105
+ export interface WorkerAttachResult {
106
+ worker_id: string;
107
+ }
108
+ /**
109
+ * Wake-context payload assembled kernel-side at `subscription.matched`.
110
+ * The two fields typed below are the ones every current consumer keys
111
+ * against; additional kernel-side fields flow through as extra
112
+ * properties without breaking this type.
113
+ */
114
+ export interface WakeContext {
115
+ triggering_event?: {
116
+ type: string;
117
+ payload?: unknown;
118
+ };
119
+ epoch_summary?: {
120
+ open_steps?: string[];
121
+ };
122
+ [additionalKernelFields: string]: unknown;
123
+ }
124
+ /** Server then pushes `step.dispatch` events to the attached worker. */
125
+ export interface StepDispatchEvent {
126
+ run_id: string;
127
+ step_id: string;
128
+ attempt: number;
129
+ step_type: StepType;
130
+ spec: unknown;
131
+ lease_id: string;
132
+ idempotency_key: string;
133
+ pins: Pins;
134
+ /**
135
+ * The `wake_context` payload from the run's `subscription.matched`
136
+ * journal entry — carries the triggering event and any epoch summary
137
+ * the flow needs to know why this step is running. Present when the
138
+ * run was spawned by an event; `undefined` for runs started directly
139
+ * (no trigger fired). A real agent needs this to see the event
140
+ * payload (e.g. the HN story ID).
141
+ *
142
+ * Shape is assembled kernel-side in
143
+ * `kernel/relayflowd/src/engine/wake.rs` (grep for
144
+ * `wake_context` — the Rust field is written with quoted
145
+ * JSON keys so `"wake_context":` hits the assembly site
146
+ * directly). The narrow type below pins the two fields
147
+ * every consumer currently reads —
148
+ * `triggering_event.type`/`payload` and `epoch_summary` — while
149
+ * keeping the container `unknown`-permissive so a kernel-side
150
+ * addition (a new nested field) does not break the SDK type. A
151
+ * kernel-side RENAME of these two fields does break every
152
+ * consumer; that is deliberate and preferable to silent drift.
153
+ */
154
+ wake_context?: WakeContext;
155
+ recovery?: {
156
+ mode: 'reset' | 'inspect' | 'manual';
157
+ restore_pins?: Pins;
158
+ previous_completion_reason?: CompletionReason;
159
+ trajectory_tail?: unknown;
160
+ };
161
+ lease_deadline_ms: number;
162
+ }
163
+ export interface StepHeartbeatParams {
164
+ run_id: string;
165
+ step_id: string;
166
+ attempt: number;
167
+ lease_id: string;
168
+ }
169
+ export interface StepHeartbeatResult {
170
+ lease_deadline_ms: number;
171
+ }
172
+ /** completionReason mirrors kernel DESIGN.md §1.3. */
173
+ export type CompletionReason = 'success' | 'verification_failed' | 'retries_exhausted' | 'lease_expired' | 'crashed' | 'timeout' | 'worker_error' | 'budget_exceeded' | 'canceled';
174
+ export interface Pins {
175
+ workspace?: {
176
+ surface: string;
177
+ revision_id: string;
178
+ }[];
179
+ streams?: {
180
+ stream: string;
181
+ read_offset: number;
182
+ }[];
183
+ }
184
+ export interface EffectRef {
185
+ surface_path: string;
186
+ idempotency_key: string;
187
+ }
188
+ export interface EffectRecordParams {
189
+ run_id: string;
190
+ step_id: string;
191
+ attempt: number;
192
+ idempotency_key: string;
193
+ surface_path: string;
194
+ revision_before: string;
195
+ revision_after: string;
196
+ }
197
+ export interface EffectRecordResult {
198
+ /**
199
+ * True only when a *confirmed* election already covers this
200
+ * `(step_id, idempotency_key, surface_path)`: the writeback provably
201
+ * happened, so this attempt must not call the provider. An election that was
202
+ * never confirmed does not dedupe — this attempt reclaims it and owes the
203
+ * call, which is what keeps an effect from being lost to a worker that died
204
+ * between recording and performing.
205
+ */
206
+ deduped: boolean;
207
+ }
208
+ /** Phase two: the elected attempt performed the writeback. */
209
+ export interface EffectConfirmParams {
210
+ run_id: string;
211
+ step_id: string;
212
+ attempt: number;
213
+ idempotency_key: string;
214
+ surface_path: string;
215
+ }
216
+ export interface EffectConfirmResult {
217
+ confirmed: string;
218
+ }
219
+ export interface StepCompleteParams {
220
+ run_id: string;
221
+ step_id: string;
222
+ attempt: number;
223
+ idempotency_key: string;
224
+ completionReason: CompletionReason;
225
+ output?: unknown;
226
+ usage?: {
227
+ tokens_in: number;
228
+ tokens_out: number;
229
+ dollars: string;
230
+ };
231
+ started_pins?: Pins;
232
+ end_pins?: Pins;
233
+ effects?: EffectRef[];
234
+ /** `inspect` evidence for the next attempt. Rejected over 16 KiB of JSON. */
235
+ trajectory_tail?: unknown;
236
+ }
237
+ export type StepCompleteResult = RunOutcome;
238
+ export interface EventEmitParams {
239
+ run_id: string;
240
+ event_key: string;
241
+ payload: unknown;
242
+ }
243
+ export interface EventEmitResult {
244
+ matched: number;
245
+ }
246
+ /**
247
+ * Submit an external event to a flow that declares an event trigger. The
248
+ * kernel matches it against the spec's subscriptions and, on a first match,
249
+ * spawns a run; a repeat of the same (flow, subscription, key) is deduped.
250
+ */
251
+ export interface EventSubmitParams {
252
+ spec: unknown;
253
+ event: {
254
+ type: string;
255
+ payload?: unknown;
256
+ /** Overrides the subscription's dedupeKeyTemplate when supplied. */
257
+ key?: string;
258
+ };
259
+ }
260
+ export interface EventSubmitResult {
261
+ matched: boolean;
262
+ deduped: boolean;
263
+ subscription_id?: string | null;
264
+ run?: unknown;
265
+ }
266
+ export interface StreamAppendParams {
267
+ run_id: string;
268
+ stream: string;
269
+ message: unknown;
270
+ }
271
+ export interface StreamAppendResult {
272
+ offset: number;
273
+ }
274
+ export interface StreamReadParams {
275
+ run_id: string;
276
+ stream: string;
277
+ from_offset: number;
278
+ limit?: number;
279
+ }
280
+ export interface StreamReadResult {
281
+ messages: unknown[];
282
+ next_offset: number;
283
+ }
284
+ export interface JournalReadParams {
285
+ run_id: string;
286
+ from_seq: number;
287
+ limit?: number;
288
+ }
289
+ export interface JournalReadResult {
290
+ entries: unknown[];
291
+ }
292
+ /** Typed map of verb -> { params, result }. Used by the client for type-safety. */
293
+ export interface VerbContract {
294
+ hello: {
295
+ params: HelloParams;
296
+ result: HelloResult;
297
+ };
298
+ 'run.start': {
299
+ params: RunStartParams;
300
+ result: RunStartResult;
301
+ };
302
+ 'run.resume': {
303
+ params: RunResumeParams;
304
+ result: RunResumeResult;
305
+ };
306
+ 'run.cancel': {
307
+ params: RunCancelParams;
308
+ result: RunCancelResult;
309
+ };
310
+ 'run.get': {
311
+ params: RunGetParams;
312
+ result: RunGetResult;
313
+ };
314
+ 'run.watch': {
315
+ params: RunWatchParams;
316
+ result: RunWatchResult;
317
+ };
318
+ 'worker.attach': {
319
+ params: WorkerAttachParams;
320
+ result: WorkerAttachResult;
321
+ };
322
+ 'step.heartbeat': {
323
+ params: StepHeartbeatParams;
324
+ result: StepHeartbeatResult;
325
+ };
326
+ 'effect.record': {
327
+ params: EffectRecordParams;
328
+ result: EffectRecordResult;
329
+ };
330
+ 'effect.confirm': {
331
+ params: EffectConfirmParams;
332
+ result: EffectConfirmResult;
333
+ };
334
+ 'step.complete': {
335
+ params: StepCompleteParams;
336
+ result: StepCompleteResult;
337
+ };
338
+ 'event.emit': {
339
+ params: EventEmitParams;
340
+ result: EventEmitResult;
341
+ };
342
+ 'event.submit': {
343
+ params: EventSubmitParams;
344
+ result: EventSubmitResult;
345
+ };
346
+ 'stream.append': {
347
+ params: StreamAppendParams;
348
+ result: StreamAppendResult;
349
+ };
350
+ 'stream.read': {
351
+ params: StreamReadParams;
352
+ result: StreamReadResult;
353
+ };
354
+ 'journal.read': {
355
+ params: JournalReadParams;
356
+ result: JournalReadResult;
357
+ };
358
+ }
359
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAEzD,kFAAkF;AAClF,eAAO,MAAM,gBAAgB,EAAG,CAAU,CAAC;AAE3C,qEAAqE;AACrE,eAAO,MAAM,oBAAoB,EAAG,sBAA+B,CAAC;AAEpE,MAAM,MAAM,aAAa,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9D,wBAAwB;AACxB,MAAM,WAAW,OAAO,CAAC,CAAC,GAAG,OAAO;IAClC,EAAE,EAA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AAM,EAAE,kBAAkB,CAAC;QAAC,MAAM,EAAE,kBAAkB,CAAA;KAAE,CAAC;IAC5E,YAAY,EAAE;QAAE,MAAM,EAAE,eAAe,CAAC;QAAC,MAAM,EAAE,eAAe,CAAA;KAAE,CAAC;IACnE,cAAc,EAAE;QAAE,MAAM,EAAE,iBAAiB,CAAC;QAAC,MAAM,EAAE,iBAAiB,CAAA;KAAE,CAAC;IACzE,eAAe,EAAE;QAAE,MAAM,EAAE,kBAAkB,CAAC;QAAC,MAAM,EAAE,kBAAkB,CAAA;KAAE,CAAC;IAC5E,aAAa,EAAE;QAAE,MAAM,EAAE,gBAAgB,CAAC;QAAC,MAAM,EAAE,gBAAgB,CAAA;KAAE,CAAC;IACtE,cAAc,EAAE;QAAE,MAAM,EAAE,iBAAiB,CAAC;QAAC,MAAM,EAAE,iBAAiB,CAAA;KAAE,CAAC;CAC1E"}
@@ -0,0 +1,15 @@
1
+ // Journal protocol v0 — the SDK boundary (kernel DESIGN.md §5).
2
+ //
3
+ // Transport: newline-delimited JSON over a unix socket at
4
+ // `<data-dir>/relayflowd.sock`. Requests `{id, verb, params}`; responses
5
+ // `{id, ok: true, result}` or `{id, ok: false, error: {code, message}}`;
6
+ // server-pushed events `{event, data}` (no `id`). Any verb whose journal
7
+ // append fails returns `error{code: "journal_write_failed"}` and the affected
8
+ // step fails — the protocol is fail-closed like everything behind it.
9
+ //
10
+ // This module is the typed wire surface; `journal-client.ts` implements it.
11
+ /** Stamped per segment; readers read every past version, writers write newest. */
12
+ export const PROTOCOL_VERSION = 0;
13
+ /** A journal append that fails fails the step (AGENTS.md rule 4). */
14
+ export const JOURNAL_WRITE_FAILED = 'journal_write_failed';
15
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,EAAE;AACF,0DAA0D;AAC1D,yEAAyE;AACzE,yEAAyE;AACzE,yEAAyE;AACzE,8EAA8E;AAC9E,sEAAsE;AACtE,EAAE;AACF,4EAA4E;AAI5E,kFAAkF;AAClF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAU,CAAC;AAE3C,qEAAqE;AACrE,MAAM,CAAC,MAAM,oBAAoB,GAAG,sBAA+B,CAAC"}
package/dist/spec.d.ts ADDED
@@ -0,0 +1,294 @@
1
+ import type { JsonOutputSchema } from './output-schema.js';
2
+ export type { JsonOutputSchema } from './output-schema.js';
3
+ /** The three rungs of the ladder (RFC §1; AGENTS.md rule 7). */
4
+ export type StepType = 'deterministic' | 'llm' | 'agent';
5
+ /**
6
+ * Verification is control flow, not decoration (kernel DESIGN.md §3).
7
+ * v0 gates are deterministic so verification is kernel-side and replayable.
8
+ */
9
+ export type VerificationGateType = 'exit_code' | 'output_contains' | 'json_schema';
10
+ /**
11
+ * `exit_code == 0` — the implicit gate for deterministic steps. v0 judges
12
+ * exactly zero (kernel DESIGN.md §4); it is not configurable, so this gate
13
+ * carries no parameters. Writing it explicitly is allowed and compiles to the
14
+ * same kernel spec as omitting it.
15
+ */
16
+ export interface ExitCodeGate {
17
+ type: 'exit_code';
18
+ }
19
+ /** Step output (stdout_tail / llm value, stringified) contains `value`. */
20
+ export interface OutputContainsGate {
21
+ type: 'output_contains';
22
+ value: string;
23
+ }
24
+ /** Step output validates against a JSON Schema. Used for `llm` structured output. */
25
+ export interface JsonSchemaGate {
26
+ type: 'json_schema';
27
+ schema: boolean | Record<string, unknown>;
28
+ }
29
+ export type VerificationSpec = ExitCodeGate | OutputContainsGate | JsonSchemaGate;
30
+ export type OutputVerificationSpec = OutputContainsGate | JsonSchemaGate;
31
+ /**
32
+ * Agent-step recovery modes (RFC Appendix A rule 4). Default is `reset`.
33
+ * `deterministic` / `llm` steps have no workspace, so these do not apply.
34
+ */
35
+ export type RecoveryMode = 'reset' | 'inspect' | 'manual';
36
+ /**
37
+ * Declared mutable surfaces for an agent step (RFC Appendix A rule 1).
38
+ * Anything undeclared is outside the contract and outside the step's
39
+ * permissions (gate 8 makes this enforceable, not advisory).
40
+ */
41
+ export interface WorkspaceSurface {
42
+ /** Relayfile mount path, or a named worktree. */
43
+ surface: string;
44
+ }
45
+ export interface StreamSurface {
46
+ /** Durable channel the agent may write (kernel DESIGN.md §1.8). */
47
+ stream: string;
48
+ }
49
+ export interface AgentSurfaces {
50
+ workspace?: WorkspaceSurface[];
51
+ streams?: StreamSurface[];
52
+ /** Integration writeback paths — mount writes per gate 6. */
53
+ external?: string[];
54
+ }
55
+ /** Permission model for an agent step (gate 8). `readonly` provably cannot write. */
56
+ export interface PermissionsSpec {
57
+ fileGlobs?: string[];
58
+ networkAllowlist?: string[];
59
+ accessPreset?: 'readonly' | 'readwrite';
60
+ }
61
+ /**
62
+ * Budget envelope. Per decision #10 every token has exactly one owner: an
63
+ * injected context pack spends the consuming step's budget. Money is a decimal
64
+ * string at the boundary (kernel DESIGN.md §1: no floats for money); tokens
65
+ * are integers.
66
+ */
67
+ export interface BudgetSpec {
68
+ maxTokensIn?: number;
69
+ maxTokensOut?: number;
70
+ /** Decimal string, e.g. "1.50". */
71
+ maxDollars?: string;
72
+ }
73
+ /** Fields shared by every step on the ladder. */
74
+ export interface BaseStepSpec {
75
+ /** Stable step identity; journaled as `step_id` and hashed into the idempotency key. */
76
+ id: string;
77
+ type: StepType;
78
+ /** Step dependencies — a step runs only after these complete. */
79
+ dependsOn?: string[];
80
+ /** Semantic retry bound (kernel DESIGN.md §1.2 `max_iterations`). Default 1. */
81
+ maxIterations?: number;
82
+ }
83
+ /**
84
+ * Rung 1 — a pure script. Executed by the `relayflowd` binary: spawn command,
85
+ * capture stdout/exit code. Output = `{exit_code, stdout_tail}`. Gate-1
86
+ * deterministic steps are pure (no pins).
87
+ */
88
+ export interface DeterministicStepSpec extends BaseStepSpec {
89
+ type: 'deterministic';
90
+ command: string;
91
+ /** Wall-clock command timeout; worker-backed verbs own their dispatch timeout. */
92
+ timeoutMs?: number;
93
+ /** Omit to get the implicit `exit_code` gate. */
94
+ verification?: VerificationSpec;
95
+ }
96
+ /**
97
+ * Rung 2 — a bare model call. No workspace, output is a value. The kernel
98
+ * never calls a model: it dispatches to an attached SDK worker (§5) which
99
+ * returns `{output, usage}`; the kernel then runs the verification gate.
100
+ */
101
+ export interface LlmStepSpec extends BaseStepSpec {
102
+ type: 'llm';
103
+ prompt: string;
104
+ verification?: OutputVerificationSpec;
105
+ model?: string;
106
+ /** Inert preflight declaration; overrides the flow/project CLI default. */
107
+ cli?: string;
108
+ /**
109
+ * Structured-output authoring sugar. Compiles to the existing `json_schema`
110
+ * verification primitive and is removed before the kernel boundary.
111
+ */
112
+ output?: JsonOutputSchema;
113
+ }
114
+ /**
115
+ * Rung 3 — a harnessed agent in a workspace. Dispatched like `llm`, plus
116
+ * Appendix A in full: pins declared workspace revisions and stream offsets;
117
+ * every writeback is a journaled `effect.recorded` deduped by
118
+ * `(step_id, idempotency_key, surface_path)`.
119
+ */
120
+ export interface AgentStepSpec extends BaseStepSpec {
121
+ type: 'agent';
122
+ instruction: string;
123
+ verification?: OutputVerificationSpec;
124
+ /** Named authoring declaration selected from `FlowSpec.agents`. Compiled away. */
125
+ agent?: string;
126
+ /** Inert preflight declaration; overrides the flow/project CLI default. */
127
+ cli?: string;
128
+ /**
129
+ * Model the declared CLI must use. Raw Claude/Codex adapters receive their
130
+ * real model flag; an identified Relayflows wrapper receives it in its
131
+ * same-process execution request. Declared here so the choice is journaled with the step
132
+ * instead of being ambient host state.
133
+ */
134
+ model?: string;
135
+ surfaces?: AgentSurfaces;
136
+ recoveryMode?: RecoveryMode;
137
+ permissions?: PermissionsSpec;
138
+ /**
139
+ * Structured-output authoring sugar. A successful CLI JSON object is the parsed
140
+ * value; the kernel persists it only after `json_schema` verification.
141
+ */
142
+ output?: JsonOutputSchema;
143
+ }
144
+ export type StepSpec = DeterministicStepSpec | LlmStepSpec | AgentStepSpec;
145
+ /**
146
+ * Reusable authoring declaration for an agent CLI/model pair. Both fields are
147
+ * required so selecting a named agent can never inherit a host model. The
148
+ * compiler lowers these values into the selected kernel agent step at the
149
+ * journal boundary; the kernel never receives this map or a new step field.
150
+ */
151
+ export interface NamedAgentSpec {
152
+ cli: string;
153
+ model: string;
154
+ }
155
+ /**
156
+ * A trigger is an entry condition, not a scheduler (RFC-0001 gate 2). It names
157
+ * the event type that wakes the flow, the payload subset that must match, the
158
+ * template that derives the dedupe key, and the silence budget after which the
159
+ * kernel's liveness sweep declares the subscription dead.
160
+ *
161
+ * The event-subscription fields were shipped in `testdata/` long before this
162
+ * interface described them: `hn-monitor.flow.yaml`, `dir-watcher.flow.yaml`
163
+ * and `event-triggered-flow.yaml` all carry `eventType`, `pattern` and
164
+ * `dedupeKeyTemplate`, and `validate.ts` has always accepted them. The type
165
+ * still said "inert gate-1 declaration" with only `id` and `executor`, so the
166
+ * authoring dialect disagreed with both the shipped specs and the kernel.
167
+ */
168
+ export interface TriggerSpec {
169
+ id: string;
170
+ /** Executor registration required before this trigger may start a run. */
171
+ executor: string;
172
+ /** Event type this trigger subscribes to. Lowers to `event_type`. */
173
+ eventType?: string;
174
+ /** Recursive-subset match against the event payload. Lowers to `pattern`. */
175
+ pattern?: Record<string, unknown>;
176
+ /** Derives the dedupe key. Lowers to `dedupe_key_template`. */
177
+ dedupeKeyTemplate?: string;
178
+ /**
179
+ * Silence budget in milliseconds. When no matching event arrives inside it,
180
+ * the kernel's liveness sweep journals `subscription.stale` and emits a
181
+ * `relayflowd: subscription.stale ...` line
182
+ * (`kernel/relayflowd/src/server/liveness.rs`). Omitted means the engine
183
+ * default (`DEFAULT_STALE_AFTER_MS`, 5 minutes) applies — which is a
184
+ * decision the author did not make, not the absence of a budget.
185
+ *
186
+ * A flow that is never triggered is silently zero (RFC-0001 §"Trigger
187
+ * liveness"), so declaring this is how a schedule stops being able to die
188
+ * quietly. Lowers to `stale_after_ms`.
189
+ */
190
+ staleAfterMs?: number;
191
+ }
192
+ /**
193
+ * A Relayflow spec in the authoring shape — the composable unit (RFC settled
194
+ * decision #5). Schema-validated, diffable, signable (gate 8), and emittable
195
+ * by a step (gate 9 self-authoring). What the kernel inlines in `run.spawned`
196
+ * is this spec mapped to the kernel dialect (`toKernelSpec`).
197
+ */
198
+ export interface FlowSpec {
199
+ /** Spec schema semver (RFC §7). Compilers always emit latest. */
200
+ version: string;
201
+ name?: string;
202
+ description?: string;
203
+ /** Inert preflight default for llm/agent steps that do not declare a CLI. */
204
+ cli?: string;
205
+ /** Named authoring declarations. Compiled into agent steps, never journaled as a new primitive. */
206
+ agents?: Record<string, NamedAgentSpec>;
207
+ /** Declarations checked by preflight; gate 1 never dispatches them. */
208
+ triggers?: TriggerSpec[];
209
+ steps: StepSpec[];
210
+ budget?: BudgetSpec;
211
+ }
212
+ /** Current spec schema version emitted by this SDK. */
213
+ export declare const SPEC_SCHEMA_VERSION = "0.1.0";
214
+ export interface KernelRetryPolicy {
215
+ initial_backoff_ms: number;
216
+ max_backoff_ms: number;
217
+ multiplier: number;
218
+ jitter_percent: number;
219
+ }
220
+ /**
221
+ * Flat v0 gates (kernel DESIGN.md §4): `exit_code == 0` is implicit for
222
+ * deterministic steps; these two are optional and combinable. An empty object
223
+ * means "implicit gates only".
224
+ */
225
+ export interface KernelVerificationSpec {
226
+ output_contains?: string;
227
+ json_schema?: boolean | Record<string, unknown>;
228
+ }
229
+ export interface KernelStepCommon {
230
+ id: string;
231
+ depends_on: string[];
232
+ max_iterations: number;
233
+ retry: KernelRetryPolicy;
234
+ verification: KernelVerificationSpec;
235
+ }
236
+ export interface KernelDeterministicStep extends KernelStepCommon {
237
+ type: 'deterministic';
238
+ command: string;
239
+ timeout_ms?: number;
240
+ }
241
+ export interface KernelLlmStep extends KernelStepCommon {
242
+ type: 'llm';
243
+ prompt: string;
244
+ model?: string;
245
+ cli?: string;
246
+ }
247
+ export interface KernelAgentSurfaces {
248
+ workspace?: {
249
+ surface: string;
250
+ }[];
251
+ streams?: {
252
+ stream: string;
253
+ }[];
254
+ external?: string[];
255
+ }
256
+ export interface KernelPermissionsSpec {
257
+ file_globs?: string[];
258
+ network_allowlist?: string[];
259
+ access_preset?: 'readonly' | 'readwrite';
260
+ }
261
+ export interface KernelAgentStep extends KernelStepCommon {
262
+ type: 'agent';
263
+ instruction: string;
264
+ cli?: string;
265
+ model?: string;
266
+ recovery_mode: RecoveryMode;
267
+ surfaces?: KernelAgentSurfaces;
268
+ permissions?: KernelPermissionsSpec;
269
+ }
270
+ export type KernelStepSpec = KernelDeterministicStep | KernelLlmStep | KernelAgentStep;
271
+ export interface KernelBudgetSpec {
272
+ max_tokens_in?: number;
273
+ max_tokens_out?: number;
274
+ max_dollars?: string;
275
+ }
276
+ export interface KernelTriggerSpec {
277
+ id: string;
278
+ executor: string;
279
+ event_type?: string;
280
+ pattern?: Record<string, unknown>;
281
+ dedupe_key_template?: string;
282
+ stale_after_ms?: number;
283
+ }
284
+ /** The compiled spec as the kernel parses, journals, and hashes it. */
285
+ export interface KernelRunSpec {
286
+ version: string;
287
+ name?: string;
288
+ description?: string;
289
+ cli?: string;
290
+ triggers?: KernelTriggerSpec[];
291
+ steps: KernelStepSpec[];
292
+ budget?: KernelBudgetSpec;
293
+ }
294
+ //# sourceMappingURL=spec.d.ts.map