@ebowwa/workflows 0.1.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.
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Workflow Runner - Execution Engine
3
+ *
4
+ * Orchestrates workflow execution with job scheduling,
5
+ * step execution, and event emission for real-time updates.
6
+ */
7
+ import { EventEmitter } from 'node:events';
8
+ import type { Workflow, WorkflowRun, Trigger } from './types.js';
9
+ export interface RunnerOptions {
10
+ /** Default workspace directory */
11
+ workspace?: string;
12
+ /** Default environment variables */
13
+ env?: Record<string, string>;
14
+ /** Maximum concurrent jobs */
15
+ maxConcurrentJobs?: number;
16
+ }
17
+ export interface RunOptions {
18
+ /** Trigger that initiated this run */
19
+ trigger?: Trigger;
20
+ /** Environment variables for this run */
21
+ env?: Record<string, string>;
22
+ /** Workspace override */
23
+ workspace?: string;
24
+ /** Pre-generated run ID (optional) */
25
+ runId?: string;
26
+ }
27
+ /**
28
+ * Workflow Runner - executes workflows with process isolation
29
+ */
30
+ export declare class WorkflowRunner extends EventEmitter {
31
+ private sandbox;
32
+ private workspace;
33
+ private env;
34
+ private maxConcurrentJobs;
35
+ private activeRuns;
36
+ constructor(options?: RunnerOptions);
37
+ /**
38
+ * Run a workflow
39
+ */
40
+ runWorkflow(workflow: Workflow, options?: RunOptions): Promise<WorkflowRun>;
41
+ private executeJobs;
42
+ private executeJob;
43
+ /**
44
+ * Cancel a running workflow
45
+ */
46
+ cancelRun(runId: string): boolean;
47
+ /**
48
+ * Check if a run is active
49
+ */
50
+ isRunActive(runId: string): boolean;
51
+ /**
52
+ * Get all active run IDs
53
+ */
54
+ getActiveRuns(): string[];
55
+ private emitEvent;
56
+ private emitLog;
57
+ }
58
+ /**
59
+ * Create a workflow runner
60
+ */
61
+ export declare function createRunner(options?: RunnerOptions): WorkflowRunner;
62
+ //# sourceMappingURL=runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runner.d.ts","sourceRo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,OAAO;CAGhB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,cAAc,CAEpE"}
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Process-level isolation for step execution
3
+ *
4
+ * Provides secure execution of workflow steps with process isolation,
5
+ * timeout handling, retry logic, and real-time log streaming.
6
+ */
7
+ import type { ChildProcess } from 'node:child_process';
8
+ import type { Step, StepContext, StepResult, LogEntry } from './types.js';
9
+ export interface SandboxOptions {
10
+ /** Default timeout for steps (ms) */
11
+ defaultTimeout?: number;
12
+ /** Default retry count */
13
+ defaultRetry?: number;
14
+ /** Log callback for real-time streaming */
15
+ onLog?: (entry: LogEntry) => void;
16
+ }
17
+ export interface ActiveProcess {
18
+ pid: number;
19
+ jobId: string;
20
+ stepId: string;
21
+ process: ChildProcess;
22
+ cancelled: boolean;
23
+ }
24
+ /**
25
+ * Process Sandbox for isolated step execution
26
+ */
27
+ export declare class ProcessSandbox {
28
+ private activeProcesses;
29
+ private defaultTimeout;
30
+ private defaultRetry;
31
+ private onLog?;
32
+ constructor(options?: SandboxOptions);
33
+ /**
34
+ * Execute a step in an isolated process
35
+ */
36
+ executeStep(step: Step, context: StepContext): Promise<StepResult>;
37
+ private executeStepOnce;
38
+ /**
39
+ * Cancel a running step
40
+ */
41
+ cancelStep(runId: string, jobId: string, stepId: string): boolean;
42
+ /**
43
+ * Cancel all steps for a run
44
+ */
45
+ cancelRun(runId: string): number;
46
+ /**
47
+ * Get all active processes
48
+ */
49
+ getActiveProcesses(): ActiveProcess[];
50
+ private killProcess;
51
+ private emitLog;
52
+ }
53
+ /**
54
+ * Evaluate a condition expression
55
+ * Supports simple expressions like "success()", "failure()", "always()"
56
+ * and basic comparisons
57
+ */
58
+ export declare function evaluateCondition(condition: string | undefined, context: {
59
+ previousSteps: {
60
+ succeeded: boolean;
61
+ }[];
62
+ }): boolean;
63
+ /**
64
+ * Create a sandbox instance with log streaming
65
+ */
66
+ export declare function createSandbox(onLog?: (entry: LogEntry) => void): ProcessSandbox;
67
+ //# sourceMappingURL=sandbox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../src/sandbox.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE1E,MAAM,WAAW,cAAc;IAC7B,qCAAqC;IACrC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,0BAA0B;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,2CAA2C;IAC3C,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,CAAC;CACnC;AAED,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,YAAY,CAAC;IACtB,SAAS,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,eAAe,CAAoC;IAC3D,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,KAAK,CAAC,CAA4B;gBAE9B,OAAO,GAAE,cAAmB;IAMxC;;OAEG;IACG,WAAW,CACf,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC,UAAU,CAAC;YAmCR,eAAe;IAiI7B;;OAEG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO;IAajE;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAchC;;OAEG;IACH,kBAAkB,IAAI,aAAa,EAAE;IAIrC,OAAO,CAAC,WAAW;IAgBnB,OAAO,CAAC,OAAO;CAKhB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,OAAO,EAAE;IAAE,aAAa,EAAE;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,EAAE,CAAA;CAAE,GACnD,OAAO,CAaT;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,GAAG,cAAc,CAE/E"}
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Job Scheduler with dependency resolution
3
+ *
4
+ * Handles job ordering, parallel execution where possible,
5
+ * and dependency graph management.
6
+ */
7
+ import type { Job } from './types.js';
8
+ export interface JobNode {
9
+ id: string;
10
+ job: Job;
11
+ dependencies: string[];
12
+ dependents: string[];
13
+ }
14
+ export interface ExecutionPlan {
15
+ /** Jobs that can run in parallel, grouped by level */
16
+ levels: string[][];
17
+ /** Total number of jobs */
18
+ total: number;
19
+ /** Whether the graph has cycles */
20
+ hasCycles: boolean;
21
+ }
22
+ /**
23
+ * Build a dependency graph from jobs
24
+ */
25
+ export declare function buildDependencyGraph(jobs: Record<string, Job>): Map<string, JobNode>;
26
+ /**
27
+ * Create an execution plan from jobs
28
+ * Groups jobs by dependency level for parallel execution
29
+ */
30
+ export declare function createExecutionPlan(jobs: Record<string, Job>): ExecutionPlan;
31
+ /**
32
+ * Get jobs that are ready to run (all dependencies satisfied)
33
+ */
34
+ export declare function getReadyJobs(graph: Map<string, JobNode>, completed: Set<string>, running: Set<string>, failed: Set<string>): string[];
35
+ /**
36
+ * Job Scheduler class
37
+ */
38
+ export declare class JobScheduler {
39
+ private graph;
40
+ private completed;
41
+ private running;
42
+ private failed;
43
+ private skipped;
44
+ constructor(jobs: Record<string, Job>);
45
+ /**
46
+ * Get the execution plan
47
+ */
48
+ getPlan(): ExecutionPlan;
49
+ /**
50
+ * Get jobs ready to run
51
+ */
52
+ getReadyJobs(): string[];
53
+ /**
54
+ * Mark a job as started
55
+ */
56
+ startJob(jobId: string): void;
57
+ /**
58
+ * Mark a job as completed
59
+ */
60
+ completeJob(jobId: string, success: boolean): void;
61
+ /**
62
+ * Skip a job (due to failed dependencies)
63
+ */
64
+ skipJob(jobId: string): void;
65
+ /**
66
+ * Check if all jobs are done
67
+ */
68
+ isComplete(): boolean;
69
+ /**
70
+ * Get status summary
71
+ */
72
+ getStatus(): {
73
+ total: number;
74
+ completed: number;
75
+ running: number;
76
+ failed: number;
77
+ skipped: number;
78
+ pending: number;
79
+ };
80
+ /**
81
+ * Get job by ID
82
+ */
83
+ getJob(jobId: string): Job | undefined;
84
+ /**
85
+ * Get all job IDs
86
+ */
87
+ getJobIds(): string[];
88
+ /**
89
+ * Check for cycles in the dependency graph
90
+ */
91
+ hasCycles(): boolean;
92
+ }
93
+ //# sourceMappingURL=scheduler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAuC,MAAM,YAAY,CAAC;AAE3E,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,GAAG,CAAC;IACT,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,aAAa;IAC5B,sDAAsD;IACtD,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC;IACnB,2BAA2B;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,mCAAmC;IACnC,SAAS,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAwBpF;AAED;;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