yaml-flow 1.0.0 → 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 (50) hide show
  1. package/README.md +486 -255
  2. package/dist/constants-D1fTEbbM.d.cts +330 -0
  3. package/dist/constants-D1fTEbbM.d.ts +330 -0
  4. package/dist/event-graph/index.cjs +895 -0
  5. package/dist/event-graph/index.cjs.map +1 -0
  6. package/dist/event-graph/index.d.cts +53 -0
  7. package/dist/event-graph/index.d.ts +53 -0
  8. package/dist/event-graph/index.js +855 -0
  9. package/dist/event-graph/index.js.map +1 -0
  10. package/dist/index.cjs +1128 -312
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +3 -2
  13. package/dist/index.d.ts +3 -2
  14. package/dist/index.js +1093 -306
  15. package/dist/index.js.map +1 -1
  16. package/dist/step-machine/index.cjs +513 -0
  17. package/dist/step-machine/index.cjs.map +1 -0
  18. package/dist/step-machine/index.d.cts +77 -0
  19. package/dist/step-machine/index.d.ts +77 -0
  20. package/dist/step-machine/index.js +502 -0
  21. package/dist/step-machine/index.js.map +1 -0
  22. package/dist/stores/file.cjs.map +1 -1
  23. package/dist/stores/file.d.cts +4 -4
  24. package/dist/stores/file.d.ts +4 -4
  25. package/dist/stores/file.js.map +1 -1
  26. package/dist/stores/index.cjs +232 -0
  27. package/dist/stores/index.cjs.map +1 -0
  28. package/dist/stores/index.d.cts +4 -0
  29. package/dist/stores/index.d.ts +4 -0
  30. package/dist/stores/index.js +228 -0
  31. package/dist/stores/index.js.map +1 -0
  32. package/dist/stores/localStorage.cjs.map +1 -1
  33. package/dist/stores/localStorage.d.cts +4 -4
  34. package/dist/stores/localStorage.d.ts +4 -4
  35. package/dist/stores/localStorage.js.map +1 -1
  36. package/dist/stores/memory.cjs.map +1 -1
  37. package/dist/stores/memory.d.cts +4 -4
  38. package/dist/stores/memory.d.ts +4 -4
  39. package/dist/stores/memory.js.map +1 -1
  40. package/dist/types-FZ_eyErS.d.cts +115 -0
  41. package/dist/types-FZ_eyErS.d.ts +115 -0
  42. package/package.json +16 -6
  43. package/dist/core/index.cjs +0 -557
  44. package/dist/core/index.cjs.map +0 -1
  45. package/dist/core/index.d.cts +0 -102
  46. package/dist/core/index.d.ts +0 -102
  47. package/dist/core/index.js +0 -549
  48. package/dist/core/index.js.map +0 -1
  49. package/dist/types-BoWndaAJ.d.cts +0 -237
  50. package/dist/types-BoWndaAJ.d.ts +0 -237
@@ -0,0 +1,330 @@
1
+ /**
2
+ * Event Graph — Core Types
3
+ *
4
+ * Type definitions for the stateless event-graph engine.
5
+ * Pure: f(state, event) → newState
6
+ */
7
+ interface GraphConfig {
8
+ id?: string;
9
+ settings: GraphSettings;
10
+ tasks: Record<string, TaskConfig>;
11
+ }
12
+ interface GraphSettings {
13
+ /** Completion strategy */
14
+ completion: CompletionStrategy;
15
+ /** Conflict resolution strategy */
16
+ conflict_strategy?: ConflictStrategy;
17
+ /** Execution mode */
18
+ execution_mode?: ExecutionMode;
19
+ /** Goal outputs — used with 'goal-reached' completion */
20
+ goal?: string[];
21
+ /** Max total scheduler iterations (safety limit, default: 1000) */
22
+ max_iterations?: number;
23
+ /** Timeout in ms (declared for drivers, not enforced by pure engine) */
24
+ timeout_ms?: number;
25
+ }
26
+ interface TaskConfig {
27
+ /** What this task needs to become eligible */
28
+ requires?: string[];
29
+ /** What this task produces on successful completion */
30
+ provides: string[];
31
+ /** Conditional provides based on handler result */
32
+ on?: Record<string, string[]>;
33
+ /** Tokens to inject into available outputs on failure */
34
+ on_failure?: string[];
35
+ /** Task execution method (informational — driver concern) */
36
+ method?: string;
37
+ /** Arbitrary task configuration (driver concern) */
38
+ config?: Record<string, unknown>;
39
+ /** Task priority (higher = preferred in conflict resolution) */
40
+ priority?: number;
41
+ /** Estimated duration in ms (used by duration-first strategy) */
42
+ estimatedDuration?: number;
43
+ /** Estimated cost (used by cost-optimized strategy) */
44
+ estimatedCost?: number;
45
+ /** Resource requirements (used by resource-aware strategy) */
46
+ estimatedResources?: Record<string, number>;
47
+ /** Retry configuration */
48
+ retry?: TaskRetryConfig;
49
+ /** Repeatable task configuration */
50
+ repeatable?: boolean | RepeatableConfig;
51
+ /** Circuit breaker: max executions before breaking */
52
+ circuit_breaker?: TaskCircuitBreakerConfig;
53
+ /** Description */
54
+ description?: string;
55
+ }
56
+ interface TaskRetryConfig {
57
+ max_attempts: number;
58
+ delay_ms?: number;
59
+ backoff_multiplier?: number;
60
+ }
61
+ interface RepeatableConfig {
62
+ /** Max times this task can repeat (undefined = unlimited) */
63
+ max?: number;
64
+ }
65
+ interface TaskCircuitBreakerConfig {
66
+ /** Max executions before injecting break tokens */
67
+ max_executions: number;
68
+ /** Tokens to inject when breaker trips */
69
+ on_break: string[];
70
+ }
71
+ interface ExecutionState {
72
+ /** Current status of the execution */
73
+ status: ExecutionStatus;
74
+ /** Task states keyed by task name */
75
+ tasks: Record<string, TaskState>;
76
+ /** Tokens currently available in the system */
77
+ availableOutputs: string[];
78
+ /** Stuck detection result */
79
+ stuckDetection: StuckDetection;
80
+ /** Last update timestamp */
81
+ lastUpdated: string;
82
+ /** Execution ID for this run */
83
+ executionId: string | null;
84
+ /** Execution configuration */
85
+ executionConfig: ExecutionConfig;
86
+ }
87
+ interface ExecutionConfig {
88
+ executionMode: ExecutionMode;
89
+ conflictStrategy: ConflictStrategy;
90
+ completionStrategy: CompletionStrategy;
91
+ }
92
+ interface TaskState {
93
+ status: TaskStatus;
94
+ executionCount: number;
95
+ retryCount: number;
96
+ lastEpoch: number;
97
+ startedAt?: string;
98
+ completedAt?: string;
99
+ failedAt?: string;
100
+ lastUpdated?: string;
101
+ error?: string;
102
+ messages?: TaskMessage[];
103
+ progress?: number | null;
104
+ }
105
+ interface TaskMessage {
106
+ message: string;
107
+ timestamp: string;
108
+ status: string;
109
+ }
110
+ interface StuckDetection {
111
+ is_stuck: boolean;
112
+ stuck_description: string | null;
113
+ outputs_unresolvable: string[];
114
+ tasks_blocked: string[];
115
+ }
116
+ type GraphEvent = TaskStartedEvent | TaskCompletedEvent | TaskFailedEvent | TaskProgressEvent | InjectTokensEvent | AgentActionEvent | TaskCreationEvent;
117
+ interface TaskStartedEvent {
118
+ type: 'task-started';
119
+ taskName: string;
120
+ timestamp: string;
121
+ executionId?: string;
122
+ }
123
+ interface TaskCompletedEvent {
124
+ type: 'task-completed';
125
+ taskName: string;
126
+ /** Handler result key — used for conditional routing via `on` */
127
+ result?: string;
128
+ /** Data payload from task execution */
129
+ data?: Record<string, unknown>;
130
+ timestamp: string;
131
+ executionId?: string;
132
+ }
133
+ interface TaskFailedEvent {
134
+ type: 'task-failed';
135
+ taskName: string;
136
+ error: string;
137
+ timestamp: string;
138
+ executionId?: string;
139
+ }
140
+ interface TaskProgressEvent {
141
+ type: 'task-progress';
142
+ taskName: string;
143
+ message?: string;
144
+ progress?: number;
145
+ timestamp: string;
146
+ executionId?: string;
147
+ }
148
+ interface InjectTokensEvent {
149
+ type: 'inject-tokens';
150
+ tokens: string[];
151
+ timestamp: string;
152
+ }
153
+ interface AgentActionEvent {
154
+ type: 'agent-action';
155
+ action: 'start' | 'stop' | 'pause' | 'resume';
156
+ timestamp: string;
157
+ config?: Partial<ExecutionConfig>;
158
+ }
159
+ interface TaskCreationEvent {
160
+ type: 'task-creation';
161
+ taskName: string;
162
+ taskConfig: TaskConfig;
163
+ timestamp: string;
164
+ }
165
+ interface SchedulerResult {
166
+ /** Tasks eligible for execution */
167
+ eligibleTasks: string[];
168
+ /** Whether the graph execution is complete */
169
+ isComplete: boolean;
170
+ /** Stuck detection result */
171
+ stuckDetection: StuckDetection;
172
+ /** Whether conflicts were detected */
173
+ hasConflicts: boolean;
174
+ /** Conflict groups: output → competing task names */
175
+ conflicts: Record<string, string[]>;
176
+ /** Strategy used for conflict resolution */
177
+ strategy: ConflictStrategy;
178
+ /** Processing log for diagnostics */
179
+ processingLog: string[];
180
+ }
181
+ type TaskStatus = 'not-started' | 'running' | 'completed' | 'failed' | 'inactivated';
182
+ type ExecutionStatus = 'created' | 'running' | 'paused' | 'stopped' | 'completed' | 'failed';
183
+ type CompletionStrategy = 'all-tasks-done' | 'all-outputs-done' | 'only-resolved' | 'goal-reached' | 'manual';
184
+ type ExecutionMode = 'dependency-mode' | 'eligibility-mode';
185
+ type ConflictStrategy = 'alphabetical' | 'priority-first' | 'duration-first' | 'cost-optimized' | 'resource-aware' | 'random-select' | 'user-choice' | 'parallel-all' | 'skip-conflicts' | 'round-robin';
186
+
187
+ /**
188
+ * Event Graph — Scheduler
189
+ *
190
+ * The core pure function: f(graph, state) → { eligibleTasks, isComplete, isStuck }
191
+ * No I/O, no side effects, deterministic.
192
+ */
193
+
194
+ /**
195
+ * Determine what tasks should be executed next.
196
+ * Pure function — the heart of the event-graph engine.
197
+ */
198
+ declare function next(graph: GraphConfig, state: ExecutionState): SchedulerResult;
199
+ /**
200
+ * Get candidate tasks whose dependencies are all met.
201
+ * Handles repeatable tasks and circuit breakers.
202
+ * Pure function.
203
+ */
204
+ declare function getCandidateTasks(graph: GraphConfig, state: ExecutionState): string[];
205
+
206
+ /**
207
+ * Event Graph — Reducer
208
+ *
209
+ * The core state transition function: f(state, event, graph) → newState
210
+ * No I/O, no side effects, deterministic.
211
+ */
212
+
213
+ /**
214
+ * Apply an event to the current execution state, producing a new state.
215
+ * Pure function — the heart of the event-graph reducer.
216
+ *
217
+ * @param state - Current execution state
218
+ * @param event - Event to apply
219
+ * @param graph - Graph configuration (needed for task definitions)
220
+ * @returns New execution state
221
+ */
222
+ declare function apply(state: ExecutionState, event: GraphEvent, graph: GraphConfig): ExecutionState;
223
+ /**
224
+ * Apply multiple events sequentially. Pure function.
225
+ */
226
+ declare function applyAll(state: ExecutionState, events: GraphEvent[], graph: GraphConfig): ExecutionState;
227
+
228
+ /**
229
+ * Event Graph — Graph Helpers
230
+ *
231
+ * Pure functions for manipulating the requires/provides task dependency graph.
232
+ * No I/O, no side effects.
233
+ */
234
+
235
+ declare function getProvides(task: TaskConfig | undefined): string[];
236
+ declare function getRequires(task: TaskConfig | undefined): string[];
237
+ declare function getAllTasks(graph: GraphConfig): Record<string, TaskConfig>;
238
+ declare function getTask(graph: GraphConfig, taskName: string): TaskConfig | undefined;
239
+ declare function hasTask(graph: GraphConfig, taskName: string): boolean;
240
+ declare function isNonActiveTask(taskState: TaskState | undefined): boolean;
241
+ declare function isTaskCompleted(taskState: TaskState | undefined): boolean;
242
+ declare function isTaskRunning(taskState: TaskState | undefined): boolean;
243
+ declare function isRepeatableTask(taskConfig: TaskConfig): boolean;
244
+ declare function getRepeatableMax(taskConfig: TaskConfig): number | undefined;
245
+ /**
246
+ * Dynamically compute available outputs from all completed tasks.
247
+ * For repeatable tasks, outputs are versioned by epoch.
248
+ * Pure function.
249
+ */
250
+ declare function computeAvailableOutputs(graph: GraphConfig, taskStates: Record<string, TaskState>): string[];
251
+ /**
252
+ * Group candidate tasks by the outputs they provide.
253
+ * Used to detect conflicts (multiple tasks providing the same output).
254
+ */
255
+ declare function groupTasksByProvides(candidateTaskNames: string[], tasks: Record<string, TaskConfig>): Record<string, string[]>;
256
+ /**
257
+ * Check if a task's outputs conflict with other candidates.
258
+ */
259
+ declare function hasOutputConflict(taskName: string, taskProvides: string[], candidates: string[], tasks: Record<string, TaskConfig>): boolean;
260
+ declare function addKeyToProvides(task: TaskConfig, key: string): TaskConfig;
261
+ declare function removeKeyFromProvides(task: TaskConfig, key: string): TaskConfig;
262
+ declare function addKeyToRequires(task: TaskConfig, key: string): TaskConfig;
263
+ declare function removeKeyFromRequires(task: TaskConfig, key: string): TaskConfig;
264
+ /**
265
+ * Add a new task to a graph config. Returns a new GraphConfig (immutable).
266
+ */
267
+ declare function addDynamicTask(graph: GraphConfig, taskName: string, taskConfig: TaskConfig): GraphConfig;
268
+ /**
269
+ * Create default task state for a new task.
270
+ */
271
+ declare function createDefaultTaskState(): TaskState;
272
+ /**
273
+ * Create the initial execution state for a graph.
274
+ */
275
+ declare function createInitialExecutionState(graph: GraphConfig, executionId: string): ExecutionState;
276
+
277
+ /**
278
+ * Event Graph — Completion Detection
279
+ *
280
+ * Pure functions to determine if a graph execution is complete.
281
+ */
282
+
283
+ interface CompletionResult {
284
+ isComplete: boolean;
285
+ expectedCompletion: {
286
+ taskNames: string[];
287
+ outputs: string[];
288
+ };
289
+ }
290
+ /**
291
+ * Check if graph execution is complete based on the configured strategy.
292
+ * Pure function.
293
+ */
294
+ declare function isExecutionComplete(graph: GraphConfig, state: ExecutionState): CompletionResult;
295
+
296
+ /**
297
+ * Event Graph — Stuck Detection
298
+ *
299
+ * Pure function to detect when a graph execution cannot make progress.
300
+ */
301
+
302
+ /**
303
+ * Detect if the graph execution is stuck.
304
+ * Stuck = no eligible tasks AND execution is not complete.
305
+ * Pure function.
306
+ */
307
+ declare function detectStuckState(params: {
308
+ graph: GraphConfig;
309
+ state: ExecutionState;
310
+ eligibleTasks: string[];
311
+ completionResult?: CompletionResult;
312
+ }): StuckDetection;
313
+
314
+ /**
315
+ * Event Graph — Constants
316
+ */
317
+
318
+ declare const TASK_STATUS: Record<string, TaskStatus>;
319
+ declare const EXECUTION_STATUS: Record<string, ExecutionStatus>;
320
+ declare const COMPLETION_STRATEGIES: Record<string, CompletionStrategy>;
321
+ declare const EXECUTION_MODES: Record<string, ExecutionMode>;
322
+ declare const CONFLICT_STRATEGIES: Record<string, ConflictStrategy>;
323
+ declare const DEFAULTS: {
324
+ readonly EXECUTION_MODE: ExecutionMode;
325
+ readonly CONFLICT_STRATEGY: ConflictStrategy;
326
+ readonly COMPLETION_STRATEGY: CompletionStrategy;
327
+ readonly MAX_ITERATIONS: 1000;
328
+ };
329
+
330
+ export { getRepeatableMax as $, type AgentActionEvent as A, getAllTasks as B, COMPLETION_STRATEGIES as C, DEFAULTS as D, EXECUTION_MODES as E, getCandidateTasks as F, type GraphConfig as G, getProvides as H, type InjectTokensEvent as I, getRequires as J, getTask as K, hasTask as L, isExecutionComplete as M, isNonActiveTask as N, isRepeatableTask as O, isTaskCompleted as P, isTaskRunning as Q, next as R, type SchedulerResult as S, type TaskConfig as T, type RepeatableConfig as U, type TaskCircuitBreakerConfig as V, type TaskMessage as W, type TaskProgressEvent as X, type TaskRetryConfig as Y, addKeyToProvides as Z, addKeyToRequires as _, CONFLICT_STRATEGIES as a, groupTasksByProvides as a0, hasOutputConflict as a1, removeKeyFromProvides as a2, removeKeyFromRequires as a3, type CompletionResult as b, type CompletionStrategy as c, type ConflictStrategy as d, EXECUTION_STATUS as e, type ExecutionConfig as f, type ExecutionMode as g, type ExecutionState as h, type ExecutionStatus as i, type GraphEvent as j, type GraphSettings as k, type StuckDetection as l, TASK_STATUS as m, type TaskCompletedEvent as n, type TaskCreationEvent as o, type TaskFailedEvent as p, type TaskStartedEvent as q, type TaskState as r, type TaskStatus as s, addDynamicTask as t, apply as u, applyAll as v, computeAvailableOutputs as w, createDefaultTaskState as x, createInitialExecutionState as y, detectStuckState as z };
@@ -0,0 +1,330 @@
1
+ /**
2
+ * Event Graph — Core Types
3
+ *
4
+ * Type definitions for the stateless event-graph engine.
5
+ * Pure: f(state, event) → newState
6
+ */
7
+ interface GraphConfig {
8
+ id?: string;
9
+ settings: GraphSettings;
10
+ tasks: Record<string, TaskConfig>;
11
+ }
12
+ interface GraphSettings {
13
+ /** Completion strategy */
14
+ completion: CompletionStrategy;
15
+ /** Conflict resolution strategy */
16
+ conflict_strategy?: ConflictStrategy;
17
+ /** Execution mode */
18
+ execution_mode?: ExecutionMode;
19
+ /** Goal outputs — used with 'goal-reached' completion */
20
+ goal?: string[];
21
+ /** Max total scheduler iterations (safety limit, default: 1000) */
22
+ max_iterations?: number;
23
+ /** Timeout in ms (declared for drivers, not enforced by pure engine) */
24
+ timeout_ms?: number;
25
+ }
26
+ interface TaskConfig {
27
+ /** What this task needs to become eligible */
28
+ requires?: string[];
29
+ /** What this task produces on successful completion */
30
+ provides: string[];
31
+ /** Conditional provides based on handler result */
32
+ on?: Record<string, string[]>;
33
+ /** Tokens to inject into available outputs on failure */
34
+ on_failure?: string[];
35
+ /** Task execution method (informational — driver concern) */
36
+ method?: string;
37
+ /** Arbitrary task configuration (driver concern) */
38
+ config?: Record<string, unknown>;
39
+ /** Task priority (higher = preferred in conflict resolution) */
40
+ priority?: number;
41
+ /** Estimated duration in ms (used by duration-first strategy) */
42
+ estimatedDuration?: number;
43
+ /** Estimated cost (used by cost-optimized strategy) */
44
+ estimatedCost?: number;
45
+ /** Resource requirements (used by resource-aware strategy) */
46
+ estimatedResources?: Record<string, number>;
47
+ /** Retry configuration */
48
+ retry?: TaskRetryConfig;
49
+ /** Repeatable task configuration */
50
+ repeatable?: boolean | RepeatableConfig;
51
+ /** Circuit breaker: max executions before breaking */
52
+ circuit_breaker?: TaskCircuitBreakerConfig;
53
+ /** Description */
54
+ description?: string;
55
+ }
56
+ interface TaskRetryConfig {
57
+ max_attempts: number;
58
+ delay_ms?: number;
59
+ backoff_multiplier?: number;
60
+ }
61
+ interface RepeatableConfig {
62
+ /** Max times this task can repeat (undefined = unlimited) */
63
+ max?: number;
64
+ }
65
+ interface TaskCircuitBreakerConfig {
66
+ /** Max executions before injecting break tokens */
67
+ max_executions: number;
68
+ /** Tokens to inject when breaker trips */
69
+ on_break: string[];
70
+ }
71
+ interface ExecutionState {
72
+ /** Current status of the execution */
73
+ status: ExecutionStatus;
74
+ /** Task states keyed by task name */
75
+ tasks: Record<string, TaskState>;
76
+ /** Tokens currently available in the system */
77
+ availableOutputs: string[];
78
+ /** Stuck detection result */
79
+ stuckDetection: StuckDetection;
80
+ /** Last update timestamp */
81
+ lastUpdated: string;
82
+ /** Execution ID for this run */
83
+ executionId: string | null;
84
+ /** Execution configuration */
85
+ executionConfig: ExecutionConfig;
86
+ }
87
+ interface ExecutionConfig {
88
+ executionMode: ExecutionMode;
89
+ conflictStrategy: ConflictStrategy;
90
+ completionStrategy: CompletionStrategy;
91
+ }
92
+ interface TaskState {
93
+ status: TaskStatus;
94
+ executionCount: number;
95
+ retryCount: number;
96
+ lastEpoch: number;
97
+ startedAt?: string;
98
+ completedAt?: string;
99
+ failedAt?: string;
100
+ lastUpdated?: string;
101
+ error?: string;
102
+ messages?: TaskMessage[];
103
+ progress?: number | null;
104
+ }
105
+ interface TaskMessage {
106
+ message: string;
107
+ timestamp: string;
108
+ status: string;
109
+ }
110
+ interface StuckDetection {
111
+ is_stuck: boolean;
112
+ stuck_description: string | null;
113
+ outputs_unresolvable: string[];
114
+ tasks_blocked: string[];
115
+ }
116
+ type GraphEvent = TaskStartedEvent | TaskCompletedEvent | TaskFailedEvent | TaskProgressEvent | InjectTokensEvent | AgentActionEvent | TaskCreationEvent;
117
+ interface TaskStartedEvent {
118
+ type: 'task-started';
119
+ taskName: string;
120
+ timestamp: string;
121
+ executionId?: string;
122
+ }
123
+ interface TaskCompletedEvent {
124
+ type: 'task-completed';
125
+ taskName: string;
126
+ /** Handler result key — used for conditional routing via `on` */
127
+ result?: string;
128
+ /** Data payload from task execution */
129
+ data?: Record<string, unknown>;
130
+ timestamp: string;
131
+ executionId?: string;
132
+ }
133
+ interface TaskFailedEvent {
134
+ type: 'task-failed';
135
+ taskName: string;
136
+ error: string;
137
+ timestamp: string;
138
+ executionId?: string;
139
+ }
140
+ interface TaskProgressEvent {
141
+ type: 'task-progress';
142
+ taskName: string;
143
+ message?: string;
144
+ progress?: number;
145
+ timestamp: string;
146
+ executionId?: string;
147
+ }
148
+ interface InjectTokensEvent {
149
+ type: 'inject-tokens';
150
+ tokens: string[];
151
+ timestamp: string;
152
+ }
153
+ interface AgentActionEvent {
154
+ type: 'agent-action';
155
+ action: 'start' | 'stop' | 'pause' | 'resume';
156
+ timestamp: string;
157
+ config?: Partial<ExecutionConfig>;
158
+ }
159
+ interface TaskCreationEvent {
160
+ type: 'task-creation';
161
+ taskName: string;
162
+ taskConfig: TaskConfig;
163
+ timestamp: string;
164
+ }
165
+ interface SchedulerResult {
166
+ /** Tasks eligible for execution */
167
+ eligibleTasks: string[];
168
+ /** Whether the graph execution is complete */
169
+ isComplete: boolean;
170
+ /** Stuck detection result */
171
+ stuckDetection: StuckDetection;
172
+ /** Whether conflicts were detected */
173
+ hasConflicts: boolean;
174
+ /** Conflict groups: output → competing task names */
175
+ conflicts: Record<string, string[]>;
176
+ /** Strategy used for conflict resolution */
177
+ strategy: ConflictStrategy;
178
+ /** Processing log for diagnostics */
179
+ processingLog: string[];
180
+ }
181
+ type TaskStatus = 'not-started' | 'running' | 'completed' | 'failed' | 'inactivated';
182
+ type ExecutionStatus = 'created' | 'running' | 'paused' | 'stopped' | 'completed' | 'failed';
183
+ type CompletionStrategy = 'all-tasks-done' | 'all-outputs-done' | 'only-resolved' | 'goal-reached' | 'manual';
184
+ type ExecutionMode = 'dependency-mode' | 'eligibility-mode';
185
+ type ConflictStrategy = 'alphabetical' | 'priority-first' | 'duration-first' | 'cost-optimized' | 'resource-aware' | 'random-select' | 'user-choice' | 'parallel-all' | 'skip-conflicts' | 'round-robin';
186
+
187
+ /**
188
+ * Event Graph — Scheduler
189
+ *
190
+ * The core pure function: f(graph, state) → { eligibleTasks, isComplete, isStuck }
191
+ * No I/O, no side effects, deterministic.
192
+ */
193
+
194
+ /**
195
+ * Determine what tasks should be executed next.
196
+ * Pure function — the heart of the event-graph engine.
197
+ */
198
+ declare function next(graph: GraphConfig, state: ExecutionState): SchedulerResult;
199
+ /**
200
+ * Get candidate tasks whose dependencies are all met.
201
+ * Handles repeatable tasks and circuit breakers.
202
+ * Pure function.
203
+ */
204
+ declare function getCandidateTasks(graph: GraphConfig, state: ExecutionState): string[];
205
+
206
+ /**
207
+ * Event Graph — Reducer
208
+ *
209
+ * The core state transition function: f(state, event, graph) → newState
210
+ * No I/O, no side effects, deterministic.
211
+ */
212
+
213
+ /**
214
+ * Apply an event to the current execution state, producing a new state.
215
+ * Pure function — the heart of the event-graph reducer.
216
+ *
217
+ * @param state - Current execution state
218
+ * @param event - Event to apply
219
+ * @param graph - Graph configuration (needed for task definitions)
220
+ * @returns New execution state
221
+ */
222
+ declare function apply(state: ExecutionState, event: GraphEvent, graph: GraphConfig): ExecutionState;
223
+ /**
224
+ * Apply multiple events sequentially. Pure function.
225
+ */
226
+ declare function applyAll(state: ExecutionState, events: GraphEvent[], graph: GraphConfig): ExecutionState;
227
+
228
+ /**
229
+ * Event Graph — Graph Helpers
230
+ *
231
+ * Pure functions for manipulating the requires/provides task dependency graph.
232
+ * No I/O, no side effects.
233
+ */
234
+
235
+ declare function getProvides(task: TaskConfig | undefined): string[];
236
+ declare function getRequires(task: TaskConfig | undefined): string[];
237
+ declare function getAllTasks(graph: GraphConfig): Record<string, TaskConfig>;
238
+ declare function getTask(graph: GraphConfig, taskName: string): TaskConfig | undefined;
239
+ declare function hasTask(graph: GraphConfig, taskName: string): boolean;
240
+ declare function isNonActiveTask(taskState: TaskState | undefined): boolean;
241
+ declare function isTaskCompleted(taskState: TaskState | undefined): boolean;
242
+ declare function isTaskRunning(taskState: TaskState | undefined): boolean;
243
+ declare function isRepeatableTask(taskConfig: TaskConfig): boolean;
244
+ declare function getRepeatableMax(taskConfig: TaskConfig): number | undefined;
245
+ /**
246
+ * Dynamically compute available outputs from all completed tasks.
247
+ * For repeatable tasks, outputs are versioned by epoch.
248
+ * Pure function.
249
+ */
250
+ declare function computeAvailableOutputs(graph: GraphConfig, taskStates: Record<string, TaskState>): string[];
251
+ /**
252
+ * Group candidate tasks by the outputs they provide.
253
+ * Used to detect conflicts (multiple tasks providing the same output).
254
+ */
255
+ declare function groupTasksByProvides(candidateTaskNames: string[], tasks: Record<string, TaskConfig>): Record<string, string[]>;
256
+ /**
257
+ * Check if a task's outputs conflict with other candidates.
258
+ */
259
+ declare function hasOutputConflict(taskName: string, taskProvides: string[], candidates: string[], tasks: Record<string, TaskConfig>): boolean;
260
+ declare function addKeyToProvides(task: TaskConfig, key: string): TaskConfig;
261
+ declare function removeKeyFromProvides(task: TaskConfig, key: string): TaskConfig;
262
+ declare function addKeyToRequires(task: TaskConfig, key: string): TaskConfig;
263
+ declare function removeKeyFromRequires(task: TaskConfig, key: string): TaskConfig;
264
+ /**
265
+ * Add a new task to a graph config. Returns a new GraphConfig (immutable).
266
+ */
267
+ declare function addDynamicTask(graph: GraphConfig, taskName: string, taskConfig: TaskConfig): GraphConfig;
268
+ /**
269
+ * Create default task state for a new task.
270
+ */
271
+ declare function createDefaultTaskState(): TaskState;
272
+ /**
273
+ * Create the initial execution state for a graph.
274
+ */
275
+ declare function createInitialExecutionState(graph: GraphConfig, executionId: string): ExecutionState;
276
+
277
+ /**
278
+ * Event Graph — Completion Detection
279
+ *
280
+ * Pure functions to determine if a graph execution is complete.
281
+ */
282
+
283
+ interface CompletionResult {
284
+ isComplete: boolean;
285
+ expectedCompletion: {
286
+ taskNames: string[];
287
+ outputs: string[];
288
+ };
289
+ }
290
+ /**
291
+ * Check if graph execution is complete based on the configured strategy.
292
+ * Pure function.
293
+ */
294
+ declare function isExecutionComplete(graph: GraphConfig, state: ExecutionState): CompletionResult;
295
+
296
+ /**
297
+ * Event Graph — Stuck Detection
298
+ *
299
+ * Pure function to detect when a graph execution cannot make progress.
300
+ */
301
+
302
+ /**
303
+ * Detect if the graph execution is stuck.
304
+ * Stuck = no eligible tasks AND execution is not complete.
305
+ * Pure function.
306
+ */
307
+ declare function detectStuckState(params: {
308
+ graph: GraphConfig;
309
+ state: ExecutionState;
310
+ eligibleTasks: string[];
311
+ completionResult?: CompletionResult;
312
+ }): StuckDetection;
313
+
314
+ /**
315
+ * Event Graph — Constants
316
+ */
317
+
318
+ declare const TASK_STATUS: Record<string, TaskStatus>;
319
+ declare const EXECUTION_STATUS: Record<string, ExecutionStatus>;
320
+ declare const COMPLETION_STRATEGIES: Record<string, CompletionStrategy>;
321
+ declare const EXECUTION_MODES: Record<string, ExecutionMode>;
322
+ declare const CONFLICT_STRATEGIES: Record<string, ConflictStrategy>;
323
+ declare const DEFAULTS: {
324
+ readonly EXECUTION_MODE: ExecutionMode;
325
+ readonly CONFLICT_STRATEGY: ConflictStrategy;
326
+ readonly COMPLETION_STRATEGY: CompletionStrategy;
327
+ readonly MAX_ITERATIONS: 1000;
328
+ };
329
+
330
+ export { getRepeatableMax as $, type AgentActionEvent as A, getAllTasks as B, COMPLETION_STRATEGIES as C, DEFAULTS as D, EXECUTION_MODES as E, getCandidateTasks as F, type GraphConfig as G, getProvides as H, type InjectTokensEvent as I, getRequires as J, getTask as K, hasTask as L, isExecutionComplete as M, isNonActiveTask as N, isRepeatableTask as O, isTaskCompleted as P, isTaskRunning as Q, next as R, type SchedulerResult as S, type TaskConfig as T, type RepeatableConfig as U, type TaskCircuitBreakerConfig as V, type TaskMessage as W, type TaskProgressEvent as X, type TaskRetryConfig as Y, addKeyToProvides as Z, addKeyToRequires as _, CONFLICT_STRATEGIES as a, groupTasksByProvides as a0, hasOutputConflict as a1, removeKeyFromProvides as a2, removeKeyFromRequires as a3, type CompletionResult as b, type CompletionStrategy as c, type ConflictStrategy as d, EXECUTION_STATUS as e, type ExecutionConfig as f, type ExecutionMode as g, type ExecutionState as h, type ExecutionStatus as i, type GraphEvent as j, type GraphSettings as k, type StuckDetection as l, TASK_STATUS as m, type TaskCompletedEvent as n, type TaskCreationEvent as o, type TaskFailedEvent as p, type TaskStartedEvent as q, type TaskState as r, type TaskStatus as s, addDynamicTask as t, apply as u, applyAll as v, computeAvailableOutputs as w, createDefaultTaskState as x, createInitialExecutionState as y, detectStuckState as z };