@cascade-flow/runner 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.
- package/README.md +104 -0
- package/dist/discovery.d.ts +25 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13085 -0
- package/dist/index.js.map +80 -0
- package/dist/step-executor.d.ts +25 -0
- package/dist/step-executor.d.ts.map +1 -0
- package/dist/subprocess-executor.d.ts +26 -0
- package/dist/subprocess-executor.d.ts.map +1 -0
- package/dist/types.d.ts +127 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/validation.d.ts +13 -0
- package/dist/validation.d.ts.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* Step executor - runs a single step in isolation
|
|
4
|
+
*
|
|
5
|
+
* Receives via stdin:
|
|
6
|
+
* {
|
|
7
|
+
* "stepPath": "/path/to/step.ts",
|
|
8
|
+
* "dependencies": { "depName": <serialized-output> },
|
|
9
|
+
* "ctx": { "runId": "...", ... }
|
|
10
|
+
* }
|
|
11
|
+
*
|
|
12
|
+
* Environment variables:
|
|
13
|
+
* - STEP_OUTPUT_FILE: If set, write step result to this file (enables stdout/stderr capture)
|
|
14
|
+
*
|
|
15
|
+
* When STEP_OUTPUT_FILE is set:
|
|
16
|
+
* - Outputs to file: Step result as JSON
|
|
17
|
+
* - Outputs to stdout: console.log/info output
|
|
18
|
+
* - Outputs to stderr: console.error/warn output
|
|
19
|
+
*
|
|
20
|
+
* When STEP_OUTPUT_FILE is NOT set (backward compatibility):
|
|
21
|
+
* - Outputs to stdout: Step result as JSON
|
|
22
|
+
* - Outputs to stderr: All console output (redirected)
|
|
23
|
+
*/
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=step-executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step-executor.d.ts","sourceRoot":"","sources":["../src/step-executor.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;;;;;;GAqBG"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { LogEntry } from "@cascade-flow/backend-interface";
|
|
2
|
+
import type { StepOutput, RunnerContext } from "./types.ts";
|
|
3
|
+
type SubprocessOptions = {
|
|
4
|
+
signal?: AbortSignal;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Execute a step in an isolated child process
|
|
8
|
+
*
|
|
9
|
+
* Spawns a subprocess using step-executor.ts, captures stdout/stderr,
|
|
10
|
+
* and reads the step output from a file.
|
|
11
|
+
*
|
|
12
|
+
* @param stepFile - Absolute path to the step.ts file
|
|
13
|
+
* @param stepId - Unique identifier of the step (directory name)
|
|
14
|
+
* @param dependencies - Resolved dependency outputs
|
|
15
|
+
* @param ctx - Runner context passed to step
|
|
16
|
+
* @param attemptNumber - Current attempt number (for retries)
|
|
17
|
+
* @param outputPath - Path where subprocess should write output JSON
|
|
18
|
+
* @param onLog - Optional callback for real-time log emission
|
|
19
|
+
* @returns Promise resolving to step result and collected logs
|
|
20
|
+
*/
|
|
21
|
+
export declare function executeStepInSubprocess(stepFile: string, stepId: string, dependencies: Record<string, unknown>, ctx: RunnerContext, attemptNumber: number, outputPath: string, onLog?: (log: LogEntry) => void | Promise<void>, options?: SubprocessOptions): Promise<{
|
|
22
|
+
result: StepOutput;
|
|
23
|
+
logs: LogEntry[];
|
|
24
|
+
}>;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=subprocess-executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subprocess-executor.d.ts","sourceRoot":"","sources":["../src/subprocess-executor.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAEhE,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAc5D,KAAK,iBAAiB,GAAG;IACvB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,CAAC;AAiDF;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,uBAAuB,CAC3C,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACrC,GAAG,EAAE,aAAa,EAClB,aAAa,EAAE,MAAM,EACrB,UAAU,EAAE,MAAM,EAClB,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,QAAQ,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EAC/C,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,QAAQ,EAAE,CAAA;CAAE,CAAC,CA4JnD"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types for the workflow runner
|
|
3
|
+
*/
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
/**
|
|
6
|
+
* JSON primitive types
|
|
7
|
+
*/
|
|
8
|
+
export type JSONPrimitive = string | number | boolean | null;
|
|
9
|
+
/**
|
|
10
|
+
* JSON array - an array of JSON values
|
|
11
|
+
*/
|
|
12
|
+
export interface JSONArray extends Array<JSONValue> {
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* JSON object - an object with string keys and JSON values
|
|
16
|
+
*/
|
|
17
|
+
export interface JSONObject {
|
|
18
|
+
[key: string]: JSONValue;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* JSON value - any valid JSON type
|
|
22
|
+
*/
|
|
23
|
+
export type JSONValue = JSONPrimitive | JSONArray | JSONObject;
|
|
24
|
+
/**
|
|
25
|
+
* Step output must be JSON-serializable
|
|
26
|
+
*/
|
|
27
|
+
export type StepOutput = JSONValue;
|
|
28
|
+
/**
|
|
29
|
+
* Base step definition with common properties
|
|
30
|
+
* Generic over dependencies type and function signature
|
|
31
|
+
*/
|
|
32
|
+
export type BaseStepDefinition<TDeps = any, TFn = any> = {
|
|
33
|
+
name?: string;
|
|
34
|
+
dependencies?: TDeps;
|
|
35
|
+
exportOutput?: boolean;
|
|
36
|
+
maxRetries?: number;
|
|
37
|
+
retryDelayMs?: number;
|
|
38
|
+
timeoutMs?: number;
|
|
39
|
+
fn: TFn;
|
|
40
|
+
};
|
|
41
|
+
export type StepModuleExport = {
|
|
42
|
+
step: BaseStepDefinition<Record<string, any>, // other steps' `step` objects
|
|
43
|
+
(args: {
|
|
44
|
+
dependencies: Record<string, StepOutput>;
|
|
45
|
+
ctx: RunnerContext;
|
|
46
|
+
}) => Promise<StepOutput> | StepOutput>;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Loaded step representation after discovery
|
|
50
|
+
* - id: The step's unique identifier (always the directory name)
|
|
51
|
+
* - name: The step's display name (from step.name or falls back to directory name)
|
|
52
|
+
* - dir: Absolute path to the step directory
|
|
53
|
+
*/
|
|
54
|
+
export type LoadedStep = {
|
|
55
|
+
id: string;
|
|
56
|
+
name: string;
|
|
57
|
+
dir: string;
|
|
58
|
+
fn: StepModuleExport["step"]["fn"];
|
|
59
|
+
exportOutput?: boolean;
|
|
60
|
+
maxRetries?: number;
|
|
61
|
+
retryDelayMs?: number;
|
|
62
|
+
timeoutMs?: number;
|
|
63
|
+
dependencies: Record<string, LoadedStep>;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Workflow configuration from workflow.json - Zod schema
|
|
67
|
+
*/
|
|
68
|
+
export declare const workflowConfigSchema: z.ZodObject<{
|
|
69
|
+
name: z.ZodString;
|
|
70
|
+
}, z.core.$strip>;
|
|
71
|
+
/**
|
|
72
|
+
* Workflow configuration type inferred from Zod schema
|
|
73
|
+
*/
|
|
74
|
+
export type WorkflowConfig = z.infer<typeof workflowConfigSchema>;
|
|
75
|
+
/**
|
|
76
|
+
* Step configuration validation schema
|
|
77
|
+
* Validates optional step properties during discovery
|
|
78
|
+
*/
|
|
79
|
+
export declare const stepConfigSchema: z.ZodObject<{
|
|
80
|
+
name: z.ZodOptional<z.ZodString>;
|
|
81
|
+
dependencies: z.ZodOptional<z.ZodAny>;
|
|
82
|
+
exportOutput: z.ZodOptional<z.ZodBoolean>;
|
|
83
|
+
maxRetries: z.ZodOptional<z.ZodNumber>;
|
|
84
|
+
retryDelayMs: z.ZodOptional<z.ZodNumber>;
|
|
85
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
86
|
+
fn: z.ZodFunction<z.core.$ZodFunctionArgs, z.core.$ZodFunctionOut>;
|
|
87
|
+
}, z.core.$strict>;
|
|
88
|
+
/**
|
|
89
|
+
* Local workflow metadata after discovery (filesystem-specific)
|
|
90
|
+
* Extends backend WorkflowMetadata with local filesystem paths for direct execution
|
|
91
|
+
*/
|
|
92
|
+
export type LocalWorkflowMetadata = {
|
|
93
|
+
slug: string;
|
|
94
|
+
name: string;
|
|
95
|
+
dir: string;
|
|
96
|
+
stepsDir: string;
|
|
97
|
+
inputSchema?: z.ZodSchema<any>;
|
|
98
|
+
};
|
|
99
|
+
export type RunnerContext = {
|
|
100
|
+
runId: string;
|
|
101
|
+
workflow: {
|
|
102
|
+
slug: string;
|
|
103
|
+
name: string;
|
|
104
|
+
};
|
|
105
|
+
input?: unknown;
|
|
106
|
+
log: (...args: any[]) => void;
|
|
107
|
+
};
|
|
108
|
+
export type InferStepOutput<T> = T extends {
|
|
109
|
+
fn: (...args: any[]) => infer R;
|
|
110
|
+
} ? Awaited<R> : never;
|
|
111
|
+
/**
|
|
112
|
+
* Unwrap an OptionalDependency to get the underlying step type
|
|
113
|
+
* @internal
|
|
114
|
+
*/
|
|
115
|
+
export type UnwrapOptional<T> = T extends import("@cascade-flow/workflow").OptionalDependency<infer U extends {
|
|
116
|
+
fn: (...args: any[]) => any;
|
|
117
|
+
}> ? U : T;
|
|
118
|
+
/**
|
|
119
|
+
* Infer the output type of a dependency, making it optional if wrapped with optional()
|
|
120
|
+
* - Regular dependency: returns the step's output type
|
|
121
|
+
* - Optional dependency: returns the step's output type | undefined
|
|
122
|
+
*
|
|
123
|
+
* Uses branded type check (__optional property) for unambiguous type narrowing
|
|
124
|
+
* @internal
|
|
125
|
+
*/
|
|
126
|
+
export type InferDependencyOutput<T> = '__optional' extends keyof T ? InferStepOutput<UnwrapOptional<T>> | undefined : InferStepOutput<T>;
|
|
127
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAE7D;;GAEG;AACH,MAAM,WAAW,SAAU,SAAQ,KAAK,CAAC,SAAS,CAAC;CAAG;AAEtD;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,SAAS,GAAG,UAAU,CAAC;AAE/D;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,SAAS,CAAC;AAEnC;;;GAGG;AACH,MAAM,MAAM,kBAAkB,CAAC,KAAK,GAAG,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI;IACvD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,KAAK,CAAC;IACrB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,EAAE,EAAE,GAAG,CAAC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AAE,MAAM,CAAC;IACd,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;CAE/B,CAAC;AAEF,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,CAAC,SAAS;IAAE,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC,CAAA;CAAE,GAC1E,OAAO,CAAC,CAAC,CAAC,GACV,KAAK,CAAC;AAEV;;;GAGG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,CAAC,SAAS,OAAO,wBAAwB,EAAE,kBAAkB,CAAC,MAAM,CAAC,SAAS;IAAE,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAA;CAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAEvJ;;;;;;;GAOG;AACH,MAAM,MAAM,qBAAqB,CAAC,CAAC,IAAI,YAAY,SAAS,MAAM,CAAC,GAC/D,eAAe,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,GAC9C,eAAe,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Step validation - detects circular dependencies and other graph issues
|
|
3
|
+
*/
|
|
4
|
+
import type { LoadedStep } from "./types.ts";
|
|
5
|
+
/**
|
|
6
|
+
* Detects circular dependencies in the step dependency graph
|
|
7
|
+
* Uses depth-first search to find cycles
|
|
8
|
+
*
|
|
9
|
+
* @param steps - Array of loaded steps to validate
|
|
10
|
+
* @throws Error if a cycle is detected
|
|
11
|
+
*/
|
|
12
|
+
export declare function detectCycles(steps: LoadedStep[]): void;
|
|
13
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,IAAI,CAgBtD"}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cascade-flow/runner",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"module": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "rm -rf dist && bun build src/index.ts --outdir dist --target node --sourcemap=external --external=@cascade-flow/* && tsc -p tsconfig.build.json",
|
|
17
|
+
"prepublishOnly": "bun run build",
|
|
18
|
+
"test": "bun test",
|
|
19
|
+
"test:unit": "bun test tests/unit",
|
|
20
|
+
"test:integration": "bun test tests/integration",
|
|
21
|
+
"test:e2e": "bun test tests/e2e",
|
|
22
|
+
"test:coverage": "bun test --coverage"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@cascade-flow/backend-filesystem": "0.1.0",
|
|
26
|
+
"@cascade-flow/backend-interface": "0.1.0",
|
|
27
|
+
"@cascade-flow/workflow": "0.1.0",
|
|
28
|
+
"zod": "^4.1.12"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/bun": "latest"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"typescript": "^5"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist"
|
|
38
|
+
],
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "https://github.com/cascadeflow/cascadeflow.git",
|
|
45
|
+
"directory": "packages/runner"
|
|
46
|
+
},
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"description": "Core workflow execution engine for CascadeFlow with dependency-aware parallel task execution",
|
|
49
|
+
"keywords": [
|
|
50
|
+
"workflow",
|
|
51
|
+
"orchestrator",
|
|
52
|
+
"dag",
|
|
53
|
+
"execution",
|
|
54
|
+
"parallel",
|
|
55
|
+
"dependencies"
|
|
56
|
+
]
|
|
57
|
+
}
|