yaml-flow 3.1.0 → 4.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 (149) hide show
  1. package/README.md +81 -20
  2. package/board-live-cards-cli.js +37 -0
  3. package/browser/card-compute.js +132 -431
  4. package/browser/live-cards.js +41 -27
  5. package/browser/live-cards.schema.json +59 -77
  6. package/dist/card-compute/index.cjs +135 -415
  7. package/dist/card-compute/index.cjs.map +1 -1
  8. package/dist/card-compute/index.d.cts +52 -49
  9. package/dist/card-compute/index.d.ts +52 -49
  10. package/dist/card-compute/index.js +134 -415
  11. package/dist/card-compute/index.js.map +1 -1
  12. package/dist/cli/board-live-cards-cli.cjs +2379 -0
  13. package/dist/cli/board-live-cards-cli.cjs.map +1 -0
  14. package/dist/cli/board-live-cards-cli.d.cts +213 -0
  15. package/dist/cli/board-live-cards-cli.d.ts +213 -0
  16. package/dist/cli/board-live-cards-cli.js +2332 -0
  17. package/dist/cli/board-live-cards-cli.js.map +1 -0
  18. package/dist/{constants-B2zqu10b.d.ts → constants-DuzE5n03.d.ts} +2 -2
  19. package/dist/{constants-DJZU1pwJ.d.cts → constants-ozjf1Ejw.d.cts} +2 -2
  20. package/dist/continuous-event-graph/index.cjs +201 -448
  21. package/dist/continuous-event-graph/index.cjs.map +1 -1
  22. package/dist/continuous-event-graph/index.d.cts +16 -340
  23. package/dist/continuous-event-graph/index.d.ts +16 -340
  24. package/dist/continuous-event-graph/index.js +198 -448
  25. package/dist/continuous-event-graph/index.js.map +1 -1
  26. package/dist/event-graph/index.cjs +4 -4
  27. package/dist/event-graph/index.cjs.map +1 -1
  28. package/dist/event-graph/index.d.cts +5 -5
  29. package/dist/event-graph/index.d.ts +5 -5
  30. package/dist/event-graph/index.js +4 -4
  31. package/dist/event-graph/index.js.map +1 -1
  32. package/dist/index.cjs +278 -533
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.cts +8 -7
  35. package/dist/index.d.ts +8 -7
  36. package/dist/index.js +278 -533
  37. package/dist/index.js.map +1 -1
  38. package/dist/inference/index.cjs +138 -19
  39. package/dist/inference/index.cjs.map +1 -1
  40. package/dist/inference/index.d.cts +2 -2
  41. package/dist/inference/index.d.ts +2 -2
  42. package/dist/inference/index.js +138 -19
  43. package/dist/inference/index.js.map +1 -1
  44. package/dist/journal-BJDjWb5Q.d.cts +343 -0
  45. package/dist/journal-B_2JnBMF.d.ts +343 -0
  46. package/dist/step-machine/index.cjs +18 -1
  47. package/dist/step-machine/index.cjs.map +1 -1
  48. package/dist/step-machine/index.d.cts +2 -2
  49. package/dist/step-machine/index.d.ts +2 -2
  50. package/dist/step-machine/index.js +18 -1
  51. package/dist/step-machine/index.js.map +1 -1
  52. package/dist/stores/file.d.cts +1 -1
  53. package/dist/stores/file.d.ts +1 -1
  54. package/dist/stores/index.d.cts +1 -1
  55. package/dist/stores/index.d.ts +1 -1
  56. package/dist/stores/localStorage.d.cts +1 -1
  57. package/dist/stores/localStorage.d.ts +1 -1
  58. package/dist/stores/memory.d.cts +1 -1
  59. package/dist/stores/memory.d.ts +1 -1
  60. package/dist/{types-BwvgvlOO.d.cts → types-BzLD8bjb.d.cts} +1 -1
  61. package/dist/{types-ClRA8hzC.d.ts → types-C2eJ7DAV.d.ts} +1 -1
  62. package/dist/{types-DEj7OakX.d.cts → types-CMFSIjpc.d.cts} +39 -4
  63. package/dist/{types-DEj7OakX.d.ts → types-CMFSIjpc.d.ts} +39 -4
  64. package/dist/{types-FZ_eyErS.d.cts → types-ycun84cq.d.cts} +1 -0
  65. package/dist/{types-FZ_eyErS.d.ts → types-ycun84cq.d.ts} +1 -0
  66. package/dist/{validate-DEZ2Ymdb.d.ts → validate-DJQTQ6bP.d.ts} +1 -1
  67. package/dist/{validate-DqKTZg_o.d.cts → validate-ke92Cleg.d.cts} +1 -1
  68. package/examples/browser/boards/portfolio-tracker/cards/holdings-table.json +22 -0
  69. package/examples/browser/boards/portfolio-tracker/cards/portfolio-form.json +16 -0
  70. package/examples/browser/boards/portfolio-tracker/cards/portfolio-value.json +15 -0
  71. package/examples/browser/boards/portfolio-tracker/cards/price-fetch.json +15 -0
  72. package/examples/browser/boards/portfolio-tracker/fetch-prices.js +43 -0
  73. package/examples/browser/boards/portfolio-tracker/portfolio-tracker.bat +7 -0
  74. package/examples/browser/boards/portfolio-tracker/portfolio-tracker.js +189 -0
  75. package/examples/browser/livecards-browser/index.html +688 -0
  76. package/examples/browser/step-machine-browser/index.html +367 -0
  77. package/examples/cli/step-machine-cli/portfolio-tracker/cards/holdings-table.json +22 -0
  78. package/examples/cli/step-machine-cli/portfolio-tracker/cards/portfolio-form.json +43 -0
  79. package/examples/cli/step-machine-cli/portfolio-tracker/cards/portfolio-value.json +15 -0
  80. package/examples/cli/step-machine-cli/portfolio-tracker/cards/price-fetch.json +15 -0
  81. package/examples/cli/step-machine-cli/portfolio-tracker/fetch-prices.js +48 -0
  82. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/_board-cli.js +58 -0
  83. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/add-cards-cli.js +27 -0
  84. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/init-board-cli.js +25 -0
  85. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/reset-board-dir-cli.js +29 -0
  86. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/retrigger-cli.js +27 -0
  87. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/status-cli.js +25 -0
  88. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/update-holdings-cli.js +37 -0
  89. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/wait-completed-cli.js +53 -0
  90. package/examples/cli/step-machine-cli/portfolio-tracker/handlers/write-prices-cli.js +35 -0
  91. package/examples/cli/step-machine-cli/portfolio-tracker/portfolio-tracker.flow.yaml +227 -0
  92. package/examples/cli/step-machine-cli/portfolio-tracker/portfolio-tracker.input.json +38 -0
  93. package/examples/cli/step-machine-cli/portfolio-tracker/run-portfolio-tracker.bat +29 -0
  94. package/examples/cli/step-machine-demo/jsonata-init-board-cli.js +36 -0
  95. package/examples/cli/step-machine-demo/jsonata-init-board.flow.yaml +30 -0
  96. package/examples/cli/step-machine-demo/one-step-cli-only.flow.yaml +19 -0
  97. package/examples/cli/step-machine-demo/step-cli-echo-y.js +15 -0
  98. package/examples/cli/step-machine-demo/step2-double-cli.js +39 -0
  99. package/examples/cli/step-machine-demo/two-step-math-handlers.js +32 -0
  100. package/examples/cli/step-machine-demo/two-step-math.flow.yaml +31 -0
  101. package/examples/cli/step-machine-demo/two-step-mixed-handlers.js +24 -0
  102. package/examples/cli/step-machine-demo/two-step-mixed.flow.yaml +35 -0
  103. package/examples/index.html +792 -0
  104. package/examples/ingest.js +733 -0
  105. package/examples/npm-libs/batch/batch-step-machine.ts +121 -0
  106. package/examples/npm-libs/continuous-event-graph/live-cards-board.ts +215 -0
  107. package/examples/npm-libs/continuous-event-graph/live-portfolio-dashboard.ts +555 -0
  108. package/examples/npm-libs/continuous-event-graph/portfolio-tracker.ts +287 -0
  109. package/examples/npm-libs/continuous-event-graph/reactive-monitoring.ts +265 -0
  110. package/examples/npm-libs/continuous-event-graph/reactive-pipeline.ts +168 -0
  111. package/examples/npm-libs/continuous-event-graph/soc-incident-board.ts +287 -0
  112. package/examples/npm-libs/continuous-event-graph/stock-dashboard.ts +229 -0
  113. package/examples/npm-libs/event-graph/ci-cd-pipeline.ts +243 -0
  114. package/examples/npm-libs/event-graph/executor-diamond.ts +165 -0
  115. package/examples/npm-libs/event-graph/executor-pipeline.ts +161 -0
  116. package/examples/npm-libs/event-graph/research-pipeline.ts +137 -0
  117. package/examples/npm-libs/flows/ai-conversation.yaml +116 -0
  118. package/examples/npm-libs/flows/order-processing.yaml +143 -0
  119. package/examples/npm-libs/flows/simple-greeting.yaml +54 -0
  120. package/examples/npm-libs/graph-of-graphs/multi-stage-etl.ts +307 -0
  121. package/examples/npm-libs/graph-of-graphs/url-processing-pipeline.ts +254 -0
  122. package/examples/npm-libs/inference/azure-deployment.ts +149 -0
  123. package/examples/npm-libs/inference/copilot-cli.ts +138 -0
  124. package/examples/npm-libs/inference/data-pipeline.ts +145 -0
  125. package/examples/npm-libs/inference/pluggable-adapters.ts +254 -0
  126. package/examples/npm-libs/node/ai-conversation.ts +195 -0
  127. package/examples/npm-libs/node/simple-greeting.ts +101 -0
  128. package/examples/step-machine-cli/portfolio-tracker/cards/holdings-table.json +22 -0
  129. package/examples/step-machine-cli/portfolio-tracker/cards/portfolio-form.json +43 -0
  130. package/examples/step-machine-cli/portfolio-tracker/cards/portfolio-value.json +15 -0
  131. package/examples/step-machine-cli/portfolio-tracker/cards/price-fetch.json +15 -0
  132. package/examples/step-machine-cli/portfolio-tracker/fetch-prices.js +48 -0
  133. package/examples/step-machine-cli/portfolio-tracker/handlers/_board-cli.js +58 -0
  134. package/examples/step-machine-cli/portfolio-tracker/handlers/add-cards-cli.js +27 -0
  135. package/examples/step-machine-cli/portfolio-tracker/handlers/init-board-cli.js +25 -0
  136. package/examples/step-machine-cli/portfolio-tracker/handlers/reset-board-dir-cli.js +29 -0
  137. package/examples/step-machine-cli/portfolio-tracker/handlers/retrigger-cli.js +27 -0
  138. package/examples/step-machine-cli/portfolio-tracker/handlers/status-cli.js +25 -0
  139. package/examples/step-machine-cli/portfolio-tracker/handlers/update-holdings-cli.js +37 -0
  140. package/examples/step-machine-cli/portfolio-tracker/handlers/wait-completed-cli.js +53 -0
  141. package/examples/step-machine-cli/portfolio-tracker/handlers/write-prices-cli.js +35 -0
  142. package/examples/step-machine-cli/portfolio-tracker/portfolio-tracker.flow.yaml +227 -0
  143. package/examples/step-machine-cli/portfolio-tracker/portfolio-tracker.input.json +38 -0
  144. package/examples/step-machine-cli/portfolio-tracker/run-portfolio-tracker.bat +29 -0
  145. package/package.json +14 -2
  146. package/schema/board-status.schema.json +118 -0
  147. package/schema/flow.schema.json +5 -0
  148. package/schema/live-cards.schema.json +59 -77
  149. package/step-machine-cli.js +674 -0
@@ -0,0 +1,213 @@
1
+ import { b as LiveGraphSnapshot, L as LiveGraph } from '../types-BzLD8bjb.cjs';
2
+ import { J as Journal, a as LiveCard, R as ReactiveGraph } from '../journal-BJDjWb5Q.cjs';
3
+ import { f as GraphEvent, T as TaskConfig } from '../types-CMFSIjpc.cjs';
4
+
5
+ /**
6
+ * Board Live Cards — Disk persistence + CLI for ReactiveGraph.
7
+ *
8
+ * Library:
9
+ * initBoard(dir) — create dir + board-graph.json (idempotent)
10
+ * loadBoard(dir) — read board-graph.json → LiveGraph
11
+ * saveBoard(dir, rg) — rg.snapshot() → write board-graph.json
12
+ *
13
+ * CLI:
14
+ * board-live-cards init <dir>
15
+ * board-live-cards status --rg <dir>
16
+ * board-live-cards add-cards --rg <dir> --card <card.json>
17
+ * board-live-cards run-sources-internal --card <card.json> --token <callbackToken> --rg <dir>
18
+ *
19
+ * Card transform:
20
+ * liveCardToTaskConfig(card) — LiveCard → TaskConfig (handler mapping)
21
+ */
22
+
23
+ /** Envelope stored in board-graph.json — wraps the LiveGraph snapshot with journal pointer. */
24
+ interface BoardEnvelope {
25
+ lastDrainedJournalId: string;
26
+ graph: LiveGraphSnapshot;
27
+ }
28
+ interface JournalEntry {
29
+ id: string;
30
+ event: GraphEvent;
31
+ }
32
+ declare class BoardJournal implements Journal {
33
+ private readonly journalPath;
34
+ private lastDrainedId;
35
+ constructor(journalPath: string, lastDrainedJournalId: string);
36
+ append(event: GraphEvent): void;
37
+ drain(): GraphEvent[];
38
+ get size(): number;
39
+ get lastDrainedJournalId(): string;
40
+ }
41
+ interface CardInventoryEntry {
42
+ cardId: string;
43
+ cardFilePath: string;
44
+ addedAt: string;
45
+ }
46
+ declare function readCardInventory(boardDir: string): CardInventoryEntry[];
47
+ declare function lookupCardPath(boardDir: string, cardId: string): string | null;
48
+ declare function appendCardInventory(boardDir: string, entry: CardInventoryEntry): void;
49
+ /**
50
+ * Initialize a board directory.
51
+ * - Dir doesn't exist → create it, write empty board-graph.json
52
+ * - Dir exists + valid board-graph.json → no-op, return 'exists'
53
+ * - Dir exists + non-empty (no valid board-graph.json) → throw
54
+ */
55
+ declare function initBoard(dir: string): 'created' | 'exists';
56
+ declare function loadBoardEnvelope(dir: string): BoardEnvelope;
57
+ declare function loadBoard(dir: string): LiveGraph;
58
+ declare function saveBoard(dir: string, rg: ReactiveGraph, journal: BoardJournal): void;
59
+ /**
60
+ * Acquire an exclusive lock on the board, run `fn`, then release.
61
+ * Uses proper-lockfile on board-graph.json.
62
+ */
63
+ declare function withBoardLock<T>(boardDir: string, fn: () => T): T;
64
+ interface SourceTokenPayload {
65
+ /** Original callback token from the reactive graph (encodes taskName) */
66
+ cbk: string;
67
+ /** Board directory (absolute path) */
68
+ rg: string;
69
+ /** Card id */
70
+ cid: string;
71
+ /** sources[].bindTo */
72
+ b: string;
73
+ /** sources[].outputFile (relative to boardDir) */
74
+ d: string;
75
+ }
76
+ declare function encodeSourceToken(payload: SourceTokenPayload): string;
77
+ declare function decodeSourceToken(token: string): SourceTokenPayload | null;
78
+ interface SourceRuntimeEntry {
79
+ lastRequestedAt?: string;
80
+ lastFetchedAt?: string;
81
+ lastError?: string;
82
+ }
83
+ interface CardRuntimeState {
84
+ _sources: Record<string, SourceRuntimeEntry>;
85
+ }
86
+ /**
87
+ * Append a raw event to the journal file. No lock, no file read.
88
+ * Safe for hundreds of concurrent callers (appendFileSync is atomic for small writes).
89
+ */
90
+ declare function appendEventToJournal(boardDir: string, event: GraphEvent): void;
91
+ /**
92
+ * Read journal entries after the given ID. Pure file read, no mutation.
93
+ */
94
+ declare function getUndrainedEntries(boardDir: string, lastDrainedId: string): JournalEntry[];
95
+ /**
96
+ * Run one lock-guarded processing pass for this board.
97
+ *
98
+ * GUARANTEE (single-pass only):
99
+ * - At most one process performs this pass at a time (board lock).
100
+ * - If lock is acquired, exactly one drain/apply/save cycle is executed.
101
+ * - If lock is busy, returns false immediately (no waiting).
102
+ *
103
+ * This function does NOT guarantee full settlement; it only advances the baton
104
+ * by one cycle in the relay model.
105
+ */
106
+ declare function processAccumulatedEvents(boardDir: string): boolean;
107
+ /**
108
+ * Schedule continued draining until the board eventually settles.
109
+ *
110
+ * GUARANTEE (system-level eventual progress):
111
+ * - Default behavior launches a detached background worker process that runs
112
+ * `process-accumulated-events --inline-loop`.
113
+ * - Returns quickly to caller; does not synchronously wait for settlement.
114
+ * - Under relay assumptions, pending entries eventually drain to zero:
115
+ * 1) at least one runner continues, 2) no crash/forced exit in relay window,
116
+ * 3) lock remains healthy, 4) new events do not arrive forever.
117
+ *
118
+ * INTERNAL MODE:
119
+ * - `inlineLoop: true` executes the while(pending) loop in the current process.
120
+ * - Used by the worker command to avoid recursive worker spawning.
121
+ */
122
+ declare function processAccumulatedEventsInfinitePass(boardDir: string, settleDelayMs?: number, options?: {
123
+ inlineLoop?: boolean;
124
+ }): Promise<boolean>;
125
+ /**
126
+ * Forced drain entrypoint: first run one immediate pass, then delegate to
127
+ * infinite-pass continuation.
128
+ *
129
+ * GUARANTEE:
130
+ * - In default mode, this guarantees immediate forward progress (single pass)
131
+ * and guaranteed scheduling of eventual continuation (background worker).
132
+ * - In `inlineLoop` mode, this runs full in-process settle loop and returns
133
+ * only after pending reaches zero (or lock contention aborts loop).
134
+ */
135
+ declare function processAccumulatedEventsForced(boardDir: string, options?: {
136
+ inlineLoop?: boolean;
137
+ }): Promise<void>;
138
+ type BoardLiveCard = LiveCard;
139
+ /**
140
+ * Transform a LiveCard into a TaskConfig for the reactive graph.
141
+ *
142
+ * Every card gets handler: 'card-handler'.
143
+ * The handler inspects the card and decides what to do:
144
+ * run compute, invoke sources.
145
+ */
146
+ declare function liveCardToTaskConfig(card: BoardLiveCard): TaskConfig;
147
+ /**
148
+ * Spin up a ReactiveGraph from a board directory with all handlers wired.
149
+ *
150
+ * Single handler:
151
+ * card-handler — reads card.json, loads sourcesData from outputFiles, runs CardCompute,
152
+ * checks undelivered sources, emits task-completed or spawns run-sources-internal.
153
+ * Fire & forget — returns 'task-initiated' immediately.
154
+ */
155
+ interface BoardReactiveGraph {
156
+ rg: ReactiveGraph;
157
+ journal: BoardJournal;
158
+ }
159
+ declare function createBoardReactiveGraph(boardDir: string): BoardReactiveGraph;
160
+ interface BoardStatusCard {
161
+ name: string;
162
+ status: string;
163
+ error?: {
164
+ message: string;
165
+ code?: string;
166
+ at?: string;
167
+ source?: 'task-runtime' | 'source-fetch' | 'timeout' | 'unknown';
168
+ };
169
+ requires: string[];
170
+ requires_satisfied: string[];
171
+ requires_missing: string[];
172
+ provides_declared: string[];
173
+ provides_runtime: string[];
174
+ blocked_by: string[];
175
+ unblocks: string[];
176
+ runtime: {
177
+ attempt_count: number;
178
+ restart_count: number;
179
+ in_progress_since: string | null;
180
+ last_transition_at: string | null;
181
+ last_completed_at: string | null;
182
+ last_restarted_at: string | null;
183
+ status_age_ms: number | null;
184
+ };
185
+ }
186
+ interface BoardStatusObject {
187
+ schema_version: 'v1';
188
+ meta: {
189
+ board: {
190
+ path: string;
191
+ };
192
+ };
193
+ summary: {
194
+ card_count: number;
195
+ completed: number;
196
+ eligible: number;
197
+ pending: number;
198
+ blocked: number;
199
+ unresolved: number;
200
+ failed?: number;
201
+ in_progress?: number;
202
+ orphan_cards?: number;
203
+ topology?: {
204
+ edge_count: number;
205
+ max_fan_out_card: string | null;
206
+ max_fan_out: number;
207
+ };
208
+ };
209
+ cards: BoardStatusCard[];
210
+ }
211
+ declare function cli(argv: string[]): Promise<void>;
212
+
213
+ export { type BoardEnvelope, BoardJournal, type BoardLiveCard, type BoardReactiveGraph, type BoardStatusCard, type BoardStatusObject, type CardInventoryEntry, type CardRuntimeState, type JournalEntry, type SourceRuntimeEntry, type SourceTokenPayload, appendCardInventory, appendEventToJournal, cli, createBoardReactiveGraph, decodeSourceToken, encodeSourceToken, getUndrainedEntries, initBoard, liveCardToTaskConfig, loadBoard, loadBoardEnvelope, lookupCardPath, processAccumulatedEvents, processAccumulatedEventsForced, processAccumulatedEventsInfinitePass, readCardInventory, saveBoard, withBoardLock };
@@ -0,0 +1,213 @@
1
+ import { b as LiveGraphSnapshot, L as LiveGraph } from '../types-C2eJ7DAV.js';
2
+ import { J as Journal, a as LiveCard, R as ReactiveGraph } from '../journal-B_2JnBMF.js';
3
+ import { f as GraphEvent, T as TaskConfig } from '../types-CMFSIjpc.js';
4
+
5
+ /**
6
+ * Board Live Cards — Disk persistence + CLI for ReactiveGraph.
7
+ *
8
+ * Library:
9
+ * initBoard(dir) — create dir + board-graph.json (idempotent)
10
+ * loadBoard(dir) — read board-graph.json → LiveGraph
11
+ * saveBoard(dir, rg) — rg.snapshot() → write board-graph.json
12
+ *
13
+ * CLI:
14
+ * board-live-cards init <dir>
15
+ * board-live-cards status --rg <dir>
16
+ * board-live-cards add-cards --rg <dir> --card <card.json>
17
+ * board-live-cards run-sources-internal --card <card.json> --token <callbackToken> --rg <dir>
18
+ *
19
+ * Card transform:
20
+ * liveCardToTaskConfig(card) — LiveCard → TaskConfig (handler mapping)
21
+ */
22
+
23
+ /** Envelope stored in board-graph.json — wraps the LiveGraph snapshot with journal pointer. */
24
+ interface BoardEnvelope {
25
+ lastDrainedJournalId: string;
26
+ graph: LiveGraphSnapshot;
27
+ }
28
+ interface JournalEntry {
29
+ id: string;
30
+ event: GraphEvent;
31
+ }
32
+ declare class BoardJournal implements Journal {
33
+ private readonly journalPath;
34
+ private lastDrainedId;
35
+ constructor(journalPath: string, lastDrainedJournalId: string);
36
+ append(event: GraphEvent): void;
37
+ drain(): GraphEvent[];
38
+ get size(): number;
39
+ get lastDrainedJournalId(): string;
40
+ }
41
+ interface CardInventoryEntry {
42
+ cardId: string;
43
+ cardFilePath: string;
44
+ addedAt: string;
45
+ }
46
+ declare function readCardInventory(boardDir: string): CardInventoryEntry[];
47
+ declare function lookupCardPath(boardDir: string, cardId: string): string | null;
48
+ declare function appendCardInventory(boardDir: string, entry: CardInventoryEntry): void;
49
+ /**
50
+ * Initialize a board directory.
51
+ * - Dir doesn't exist → create it, write empty board-graph.json
52
+ * - Dir exists + valid board-graph.json → no-op, return 'exists'
53
+ * - Dir exists + non-empty (no valid board-graph.json) → throw
54
+ */
55
+ declare function initBoard(dir: string): 'created' | 'exists';
56
+ declare function loadBoardEnvelope(dir: string): BoardEnvelope;
57
+ declare function loadBoard(dir: string): LiveGraph;
58
+ declare function saveBoard(dir: string, rg: ReactiveGraph, journal: BoardJournal): void;
59
+ /**
60
+ * Acquire an exclusive lock on the board, run `fn`, then release.
61
+ * Uses proper-lockfile on board-graph.json.
62
+ */
63
+ declare function withBoardLock<T>(boardDir: string, fn: () => T): T;
64
+ interface SourceTokenPayload {
65
+ /** Original callback token from the reactive graph (encodes taskName) */
66
+ cbk: string;
67
+ /** Board directory (absolute path) */
68
+ rg: string;
69
+ /** Card id */
70
+ cid: string;
71
+ /** sources[].bindTo */
72
+ b: string;
73
+ /** sources[].outputFile (relative to boardDir) */
74
+ d: string;
75
+ }
76
+ declare function encodeSourceToken(payload: SourceTokenPayload): string;
77
+ declare function decodeSourceToken(token: string): SourceTokenPayload | null;
78
+ interface SourceRuntimeEntry {
79
+ lastRequestedAt?: string;
80
+ lastFetchedAt?: string;
81
+ lastError?: string;
82
+ }
83
+ interface CardRuntimeState {
84
+ _sources: Record<string, SourceRuntimeEntry>;
85
+ }
86
+ /**
87
+ * Append a raw event to the journal file. No lock, no file read.
88
+ * Safe for hundreds of concurrent callers (appendFileSync is atomic for small writes).
89
+ */
90
+ declare function appendEventToJournal(boardDir: string, event: GraphEvent): void;
91
+ /**
92
+ * Read journal entries after the given ID. Pure file read, no mutation.
93
+ */
94
+ declare function getUndrainedEntries(boardDir: string, lastDrainedId: string): JournalEntry[];
95
+ /**
96
+ * Run one lock-guarded processing pass for this board.
97
+ *
98
+ * GUARANTEE (single-pass only):
99
+ * - At most one process performs this pass at a time (board lock).
100
+ * - If lock is acquired, exactly one drain/apply/save cycle is executed.
101
+ * - If lock is busy, returns false immediately (no waiting).
102
+ *
103
+ * This function does NOT guarantee full settlement; it only advances the baton
104
+ * by one cycle in the relay model.
105
+ */
106
+ declare function processAccumulatedEvents(boardDir: string): boolean;
107
+ /**
108
+ * Schedule continued draining until the board eventually settles.
109
+ *
110
+ * GUARANTEE (system-level eventual progress):
111
+ * - Default behavior launches a detached background worker process that runs
112
+ * `process-accumulated-events --inline-loop`.
113
+ * - Returns quickly to caller; does not synchronously wait for settlement.
114
+ * - Under relay assumptions, pending entries eventually drain to zero:
115
+ * 1) at least one runner continues, 2) no crash/forced exit in relay window,
116
+ * 3) lock remains healthy, 4) new events do not arrive forever.
117
+ *
118
+ * INTERNAL MODE:
119
+ * - `inlineLoop: true` executes the while(pending) loop in the current process.
120
+ * - Used by the worker command to avoid recursive worker spawning.
121
+ */
122
+ declare function processAccumulatedEventsInfinitePass(boardDir: string, settleDelayMs?: number, options?: {
123
+ inlineLoop?: boolean;
124
+ }): Promise<boolean>;
125
+ /**
126
+ * Forced drain entrypoint: first run one immediate pass, then delegate to
127
+ * infinite-pass continuation.
128
+ *
129
+ * GUARANTEE:
130
+ * - In default mode, this guarantees immediate forward progress (single pass)
131
+ * and guaranteed scheduling of eventual continuation (background worker).
132
+ * - In `inlineLoop` mode, this runs full in-process settle loop and returns
133
+ * only after pending reaches zero (or lock contention aborts loop).
134
+ */
135
+ declare function processAccumulatedEventsForced(boardDir: string, options?: {
136
+ inlineLoop?: boolean;
137
+ }): Promise<void>;
138
+ type BoardLiveCard = LiveCard;
139
+ /**
140
+ * Transform a LiveCard into a TaskConfig for the reactive graph.
141
+ *
142
+ * Every card gets handler: 'card-handler'.
143
+ * The handler inspects the card and decides what to do:
144
+ * run compute, invoke sources.
145
+ */
146
+ declare function liveCardToTaskConfig(card: BoardLiveCard): TaskConfig;
147
+ /**
148
+ * Spin up a ReactiveGraph from a board directory with all handlers wired.
149
+ *
150
+ * Single handler:
151
+ * card-handler — reads card.json, loads sourcesData from outputFiles, runs CardCompute,
152
+ * checks undelivered sources, emits task-completed or spawns run-sources-internal.
153
+ * Fire & forget — returns 'task-initiated' immediately.
154
+ */
155
+ interface BoardReactiveGraph {
156
+ rg: ReactiveGraph;
157
+ journal: BoardJournal;
158
+ }
159
+ declare function createBoardReactiveGraph(boardDir: string): BoardReactiveGraph;
160
+ interface BoardStatusCard {
161
+ name: string;
162
+ status: string;
163
+ error?: {
164
+ message: string;
165
+ code?: string;
166
+ at?: string;
167
+ source?: 'task-runtime' | 'source-fetch' | 'timeout' | 'unknown';
168
+ };
169
+ requires: string[];
170
+ requires_satisfied: string[];
171
+ requires_missing: string[];
172
+ provides_declared: string[];
173
+ provides_runtime: string[];
174
+ blocked_by: string[];
175
+ unblocks: string[];
176
+ runtime: {
177
+ attempt_count: number;
178
+ restart_count: number;
179
+ in_progress_since: string | null;
180
+ last_transition_at: string | null;
181
+ last_completed_at: string | null;
182
+ last_restarted_at: string | null;
183
+ status_age_ms: number | null;
184
+ };
185
+ }
186
+ interface BoardStatusObject {
187
+ schema_version: 'v1';
188
+ meta: {
189
+ board: {
190
+ path: string;
191
+ };
192
+ };
193
+ summary: {
194
+ card_count: number;
195
+ completed: number;
196
+ eligible: number;
197
+ pending: number;
198
+ blocked: number;
199
+ unresolved: number;
200
+ failed?: number;
201
+ in_progress?: number;
202
+ orphan_cards?: number;
203
+ topology?: {
204
+ edge_count: number;
205
+ max_fan_out_card: string | null;
206
+ max_fan_out: number;
207
+ };
208
+ };
209
+ cards: BoardStatusCard[];
210
+ }
211
+ declare function cli(argv: string[]): Promise<void>;
212
+
213
+ export { type BoardEnvelope, BoardJournal, type BoardLiveCard, type BoardReactiveGraph, type BoardStatusCard, type BoardStatusObject, type CardInventoryEntry, type CardRuntimeState, type JournalEntry, type SourceRuntimeEntry, type SourceTokenPayload, appendCardInventory, appendEventToJournal, cli, createBoardReactiveGraph, decodeSourceToken, encodeSourceToken, getUndrainedEntries, initBoard, liveCardToTaskConfig, loadBoard, loadBoardEnvelope, lookupCardPath, processAccumulatedEvents, processAccumulatedEventsForced, processAccumulatedEventsInfinitePass, readCardInventory, saveBoard, withBoardLock };