@acpus/workflow-compiler 0.1.0-alpha.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 (79) hide show
  1. package/LICENSE +21 -0
  2. package/dist/.tsbuildinfo +1 -0
  3. package/dist/check/authoring-rules/index.d.ts +10 -0
  4. package/dist/check/authoring-rules/index.d.ts.map +1 -0
  5. package/dist/check/authoring-rules/index.js +222 -0
  6. package/dist/check/authoring-rules/index.js.map +1 -0
  7. package/dist/check/authoring-rules/output-admissibility.d.ts +4 -0
  8. package/dist/check/authoring-rules/output-admissibility.d.ts.map +1 -0
  9. package/dist/check/authoring-rules/output-admissibility.js +537 -0
  10. package/dist/check/authoring-rules/output-admissibility.js.map +1 -0
  11. package/dist/check/runner.d.ts +6 -0
  12. package/dist/check/runner.d.ts.map +1 -0
  13. package/dist/check/runner.js +35 -0
  14. package/dist/check/runner.js.map +1 -0
  15. package/dist/check/typescript.d.ts +9 -0
  16. package/dist/check/typescript.d.ts.map +1 -0
  17. package/dist/check/typescript.js +86 -0
  18. package/dist/check/typescript.js.map +1 -0
  19. package/dist/compiler/compile-worker.d.ts +2 -0
  20. package/dist/compiler/compile-worker.d.ts.map +1 -0
  21. package/dist/compiler/compile-worker.js +33 -0
  22. package/dist/compiler/compile-worker.js.map +1 -0
  23. package/dist/compiler/ir-walk.d.ts +3 -0
  24. package/dist/compiler/ir-walk.d.ts.map +1 -0
  25. package/dist/compiler/ir-walk.js +29 -0
  26. package/dist/compiler/ir-walk.js.map +1 -0
  27. package/dist/compiler/module.d.ts +35 -0
  28. package/dist/compiler/module.d.ts.map +1 -0
  29. package/dist/compiler/module.js +100 -0
  30. package/dist/compiler/module.js.map +1 -0
  31. package/dist/compiler/process.d.ts +9 -0
  32. package/dist/compiler/process.d.ts.map +1 -0
  33. package/dist/compiler/process.js +21 -0
  34. package/dist/compiler/process.js.map +1 -0
  35. package/dist/compiler/worker.d.ts +12 -0
  36. package/dist/compiler/worker.d.ts.map +1 -0
  37. package/dist/compiler/worker.js +35 -0
  38. package/dist/compiler/worker.js.map +1 -0
  39. package/dist/index.d.ts +3 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +3 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/internal/eslint-plugin/index.d.ts +5 -0
  44. package/dist/internal/eslint-plugin/index.d.ts.map +1 -0
  45. package/dist/internal/eslint-plugin/index.js +71 -0
  46. package/dist/internal/eslint-plugin/index.js.map +1 -0
  47. package/dist/preflight/index.d.ts +53 -0
  48. package/dist/preflight/index.d.ts.map +1 -0
  49. package/dist/preflight/index.js +113 -0
  50. package/dist/preflight/index.js.map +1 -0
  51. package/dist/preflight/temp.d.ts +2 -0
  52. package/dist/preflight/temp.d.ts.map +1 -0
  53. package/dist/preflight/temp.js +7 -0
  54. package/dist/preflight/temp.js.map +1 -0
  55. package/dist/task-analysis/ast.d.ts +9 -0
  56. package/dist/task-analysis/ast.d.ts.map +1 -0
  57. package/dist/task-analysis/ast.js +61 -0
  58. package/dist/task-analysis/ast.js.map +1 -0
  59. package/dist/task-analysis/callsites.d.ts +6 -0
  60. package/dist/task-analysis/callsites.d.ts.map +1 -0
  61. package/dist/task-analysis/callsites.js +77 -0
  62. package/dist/task-analysis/callsites.js.map +1 -0
  63. package/dist/task-analysis/index.d.ts +8 -0
  64. package/dist/task-analysis/index.d.ts.map +1 -0
  65. package/dist/task-analysis/index.js +122 -0
  66. package/dist/task-analysis/index.js.map +1 -0
  67. package/dist/task-analysis/inline-capture.d.ts +3 -0
  68. package/dist/task-analysis/inline-capture.d.ts.map +1 -0
  69. package/dist/task-analysis/inline-capture.js +51 -0
  70. package/dist/task-analysis/inline-capture.js.map +1 -0
  71. package/dist/task-analysis/types.d.ts +58 -0
  72. package/dist/task-analysis/types.d.ts.map +1 -0
  73. package/dist/task-analysis/types.js +2 -0
  74. package/dist/task-analysis/types.js.map +1 -0
  75. package/dist/task-analysis/workflow-symbols.d.ts +8 -0
  76. package/dist/task-analysis/workflow-symbols.d.ts.map +1 -0
  77. package/dist/task-analysis/workflow-symbols.js +165 -0
  78. package/dist/task-analysis/workflow-symbols.js.map +1 -0
  79. package/package.json +57 -0
@@ -0,0 +1,86 @@
1
+ import { writeFile } from "node:fs/promises";
2
+ import { dirname, join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { officialAuthoringTypeScriptPaths } from "@acpus/loader";
5
+ import ts from "typescript";
6
+ export async function checkTypeScript(entry, cwd, scratchDir) {
7
+ const tsconfig = await writeTypecheckConfig(entry, cwd, scratchDir);
8
+ const config = ts.readConfigFile(tsconfig, ts.sys.readFile);
9
+ if (config.error)
10
+ return { diagnostics: [toDiagnosticIR(config.error)] };
11
+ const parsed = ts.parseJsonConfigFileContent(config.config, ts.sys, dirname(tsconfig), undefined, tsconfig);
12
+ const programOptions = {
13
+ rootNames: parsed.fileNames,
14
+ options: parsed.options,
15
+ };
16
+ if (parsed.projectReferences)
17
+ programOptions.projectReferences = parsed.projectReferences;
18
+ const program = ts.createProgram(programOptions);
19
+ const diagnostics = [
20
+ ...parsed.errors,
21
+ ...program.getConfigFileParsingDiagnostics(),
22
+ ...program.getOptionsDiagnostics(),
23
+ ...program.getGlobalDiagnostics(),
24
+ ...program.getSyntacticDiagnostics(),
25
+ ...program.getSemanticDiagnostics(),
26
+ ].map(toDiagnosticIR);
27
+ const result = { diagnostics, program };
28
+ const sourceFile = program.getSourceFile(entry);
29
+ if (sourceFile)
30
+ result.sourceFile = sourceFile;
31
+ return result;
32
+ }
33
+ function toDiagnosticIR(diagnostic) {
34
+ const result = {
35
+ code: `TS${diagnostic.code}`,
36
+ severity: diagnostic.category === ts.DiagnosticCategory.Warning ? "warning" : "error",
37
+ message: ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"),
38
+ };
39
+ if (diagnostic.file && diagnostic.start !== undefined)
40
+ result.source = sourceLocation(diagnostic.file, diagnostic.start);
41
+ return result;
42
+ }
43
+ function sourceLocation(file, start) {
44
+ const position = file.getLineAndCharacterOfPosition(start);
45
+ return {
46
+ file: file.fileName,
47
+ line: position.line + 1,
48
+ column: position.character + 1,
49
+ };
50
+ }
51
+ async function writeTypecheckConfig(entry, cwd, scratchDir) {
52
+ const configPath = join(scratchDir, "tsconfig.acpus-run.json");
53
+ const compilerOptions = {
54
+ target: "ES2022",
55
+ lib: ["ES2022"],
56
+ module: "NodeNext",
57
+ moduleResolution: "NodeNext",
58
+ strict: true,
59
+ esModuleInterop: true,
60
+ noImplicitAny: true,
61
+ forceConsistentCasingInFileNames: true,
62
+ skipLibCheck: true,
63
+ noEmit: true,
64
+ types: ["node"],
65
+ typeRoots: typeRoots(cwd),
66
+ tsBuildInfoFile: join(scratchDir, ".tsbuildinfo"),
67
+ };
68
+ const officialImports = officialAuthoringTypeScriptPaths(scratchDir);
69
+ compilerOptions.paths = officialImports.paths;
70
+ if (officialImports.usesSource)
71
+ compilerOptions.customConditions = ["development"];
72
+ const config = { compilerOptions, files: [entry] };
73
+ await writeFile(configPath, `${JSON.stringify(config, null, 2)}\n`);
74
+ return configPath;
75
+ }
76
+ function typeRoots(cwd) {
77
+ const roots = [join(cwd, "node_modules/@types")];
78
+ try {
79
+ roots.push(dirname(dirname(fileURLToPath(import.meta.resolve("@types/node/package.json")))));
80
+ }
81
+ catch {
82
+ // If node types are unavailable, let TypeScript report its normal diagnostic.
83
+ }
84
+ return [...new Set(roots)];
85
+ }
86
+ //# sourceMappingURL=typescript.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typescript.js","sourceRoot":"","sources":["../../src/check/typescript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,gCAAgC,EAAE,MAAM,eAAe,CAAC;AAEjE,OAAO,EAAE,MAAM,Y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":["../../src/compiler/compile-worker.ts"],"names":[],"mappings":""}
@@ -0,0 +1,33 @@
1
+ import { writeFile } from "node:fs/promises";
2
+ import { tryCompileWorkflowModule } from "./module.js";
3
+ const [entry, sourcePath, out, cwd] = process.argv.slice(2);
4
+ if (!entry || !sourcePath || !out || !cwd) {
5
+ console.error("Usage: compile-worker <entry> <sourcePath> <out> <cwd>");
6
+ process.exit(2);
7
+ }
8
+ try {
9
+ const result = await tryCompileWorkflowModule(entry, {
10
+ sourcePath,
11
+ cwd,
12
+ });
13
+ if (result.isErr()) {
14
+ await writeFile(out, `${JSON.stringify({
15
+ ok: false,
16
+ type: result.error.type,
17
+ message: result.error.message,
18
+ }, null, 2)}\n`);
19
+ process.exit(1);
20
+ }
21
+ const ir = result.value;
22
+ await writeFile(out, `${JSON.stringify(ir, null, 2)}\n`);
23
+ }
24
+ catch (error) {
25
+ await writeFile(out, `${JSON.stringify({
26
+ ok: false,
27
+ type: "worker-system-failed",
28
+ message: error instanceof Error ? error.message : String(error),
29
+ stack: error instanceof Error ? error.stack : undefined,
30
+ }, null, 2)}\n`);
31
+ process.exit(1);
32
+ }
33
+ //# sourceMappingURL=compile-worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compile-worker.js","sourceRoot":"","sources":["../../src/compiler/compile-worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAEvD,MAAM,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAE5D,IAAI,CAAC,KAAK,IAAI,CAAC,UAAU,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC1C,OAAO,CAAC,KAAK,CAAC,wDAAwD,CAAC,CAAC;IACxE,OAAO,CAAC,IAAI,CAAC,CAAC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IR, visit: (node: TaskNodeIR) => void): void;
3
+ //# sourceMappingURL=ir-walk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ir-walk.d.ts","sourceRoot":"","sources":["../../src/compiler/ir-walk.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE1D,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,GAAG,IAAI,CAuBvF"}
@@ -0,0 +1,29 @@
1
+ export function forEachTaskNode(scope, visit) {
2
+ for (const node of scope.nodes) {
3
+ switch (node.kind) {
4
+ case "task":
5
+ visit(node);
6
+ break;
7
+ case "if":
8
+ forEachTaskNode(node.then, visit);
9
+ if (node.else)
10
+ forEachTaskNode(node.else, visit);
11
+ break;
12
+ case "switch":
13
+ for (const c of node.cases)
14
+ forEachTaskNode(c.then, visit);
15
+ if (node.default)
16
+ forEachTaskNode(node.default, visit);
17
+ break;
18
+ case "parallel":
19
+ for (const branch of Object.values(node.branches))
20
+ forEachTaskNode(branch.scope, visit);
21
+ break;
22
+ case "fanout":
23
+ case "loop":
24
+ forEachTaskNode(node.do, visit);
25
+ break;
26
+ }
27
+ }
28
+ }
29
+ //# sourceMappingURL=ir-walk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ir-walk.js","sourceRoot":"","sources":["../../src/compiler/ir-walk.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,eAAe,CAAC,KAAc,EAAE,KAAiC;IAC/E,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QAC/B,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;YAClB,KAAK,MAAM;gBACT,KAAK,CAAC,IAAI,CAAC,CAAC;gBACZ,MAAM;YACR,KAAK,IAAI;gBACP,eAAe,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;gBAClC,IAAI,IAAI,CAAC,IAAI;oBAAE,eAAe,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;gBACjD,MAAM;YACR,KAAK,QAAQ;gBACX,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,KAAK;oBAAE,eAAe,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;gBAC3D,IAAI,IAAI,CAAC,OAAO;oBAAE,eAAe,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;gBACvD,MAAM;YACR,KAAK,UAAU;gBACb,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;oBAAE,eAAe,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;gBACxF,MAAM;YACR,KAAK,QAAQ,CAAC;YACd,KAAK,MAAM;gBACT,eAAe,CAAC,IAAI,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;gBAChC,MAAM;QACV,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,35 @@
1
+ import { type WorkflowIR } from "@acpus/core/ir";
2
+ import { ResultAsync } from "neverthrow";
3
+ export type CompileOptions = {
4
+ sourcePath?: string;
5
+ cwd?: string;
6
+ };
7
+ export type CompileWorkflowModuleError = {
8
+ type: "workflow-source-read-failed";
9
+ entry: string;
10
+ message: string;
11
+ } | {
12
+ type: "module-import-failed";
13
+ entry: string;
14
+ message: string;
15
+ } | {
16
+ type: "invalid-default-export";
17
+ entry: string;
18
+ message: string;
19
+ } | {
20
+ type: "workflow-build-failed";
21
+ entry: string;
22
+ message: string;
23
+ } | {
24
+ type: "task-analysis-failed";
25
+ entry: string;
26
+ message: string;
27
+ } | {
28
+ type: "workflow-outside-workspace";
29
+ workflowFile: string;
30
+ cwd: string;
31
+ message: string;
32
+ };
33
+ export declare function compileWorkflowModule(entry: string, options?: CompileOptions): Promise<WorkflowIR>;
34
+ export declare function tryCompileWorkflowModule(entry: string, options?: CompileOptions): ResultAsync<WorkflowIR, CompileWorkflowModuleError>;
35
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/compiler/module.ts"],"names":[],"mappings":"AAMA,OAAO,EAAsB,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAErE,OAAO,EAAmB,WAAW,EAAmC,MAAM,YAAY,CAAC;AAG3F,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAClC;IAAE,IAAI,EAAE,6BAA6B,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACvE;IAAE,IAAI,EAAE,sBAAsB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAChE;IAAE,IAAI,EAAE,wBAAwB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAClE;IAAE,IAAI,EAAE,uBAAuB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACjE;IAAE,IAAI,EAAE,sBAAsB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAChE;IAAE,IAAI,EAAE,4BAA4B,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/F,wBAAsB,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,UAAU,CAAC,CAQ5G;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,GAAG,WAAW,CAAC,UAAU,EAAE,0BAA0B,CAAC,CAqDzI"}
@@ -0,0 +1,100 @@
1
+ import { createHash } from "node:crypto";
2
+ import { readFile } from "node:fs/promises";
3
+ import { resolve, relative } from "node:path";
4
+ import { pathToFileURL } from "node:url";
5
+ import { importAuthoringModule } from "@acpus/loader";
6
+ import { compileWorkflowDefinition, isWorkflowDefinition } from "@acpus/core/workflow";
7
+ import { validateWorkflowIR } from "@acpus/core/ir";
8
+ import { analyzeWorkflowTasks, resolveTaskReferenceMetadata } from "../task-analysis/index.js";
9
+ import { err, ok, Result, ResultAsync } from "neverthrow";
10
+ import { forEachTaskNode } from "./ir-walk.js";
11
+ export async function compileWorkflowModule(entry, options = {}) {
12
+ const result = await tryCompileWorkflowModule(entry, options);
13
+ return result.match(ir => ir, error => {
14
+ throw new Error(error.message);
15
+ });
16
+ }
17
+ export function tryCompileWorkflowModule(entry, options = {}) {
18
+ const absolute = resolve(entry);
19
+ return ResultAsync.fromPromise(readFile(absolute, "utf8"), cause => ({
20
+ type: "workflow-source-read-failed",
21
+ entry,
22
+ message: `Workflow source '${entry}' could not be read: ${causeMessage(cause)}`,
23
+ })).andThen(source => ResultAsync.fromPromise(importWorkflowModule(absolute), cause => ({
24
+ type: "module-import-failed",
25
+ entry,
26
+ message: `Workflow module '${entry}' could not be imported: ${causeMessage(cause)}`,
27
+ })).andThen(mod => {
28
+ const def = mod.default;
29
+ if (!isWorkflowDefinition(def)) {
30
+ return err({
31
+ type: "invalid-default-export",
32
+ entry,
33
+ message: `Default export of ${entry} is not an Acpus workflow definition.`,
34
+ });
35
+ }
36
+ const built = Result.fromThrowable(() => {
37
+ const ir = compileWorkflowDefinition(def, { source: options.sourcePath ?? entry, validate: false });
38
+ ir.lock.workflowSourceDigest = `sha256:${createHash("sha256").update(source).digest("hex")}`;
39
+ return ir;
40
+ }, cause => ({
41
+ type: "workflow-build-failed",
42
+ entry,
43
+ message: `Workflow '${entry}' could not be lowered: ${causeMessage(cause)}`,
44
+ }))();
45
+ if (built.isErr())
46
+ return err(built.error);
47
+ const ir = built.value;
48
+ return ResultAsync.fromPromise(analyzeWorkflowTasks(absolute, source), cause => ({
49
+ type: "task-analysis-failed",
50
+ entry,
51
+ message: `Workflow task analysis failed for '${entry}': ${causeMessage(cause)}`,
52
+ })).andThen(analysis => {
53
+ const referrerPath = toContainedWorkspacePath(options.cwd ?? process.cwd(), absolute);
54
+ if (referrerPath.isErr())
55
+ return err(referrerPath.error);
56
+ applyTaskReferenceMetadata(ir, resolveTaskReferenceMetadata(analysis), referrerPath.value);
57
+ ir.diagnostics.push(...validateWorkflowIR(ir));
58
+ return ok(ir);
59
+ });
60
+ }));
61
+ }
62
+ function importWorkflowModule(absolute) {
63
+ const url = pathToFileURL(absolute).href;
64
+ return importAuthoringModule(url, { parentURL: url });
65
+ }
66
+ function applyTaskReferenceMetadata(ir, metadata, referrerPath) {
67
+ forEachTaskNode(ir.root, node => {
68
+ if (node.run.target.kind !== "module")
69
+ return;
70
+ const task = metadata.get(node.id);
71
+ if (!task?.specifier || !task.exportName)
72
+ return;
73
+ node.run.target = {
74
+ kind: "module",
75
+ runtime: "node",
76
+ specifier: task.specifier,
77
+ exportName: task.exportName,
78
+ referrer: { kind: "workflow", path: referrerPath },
79
+ };
80
+ });
81
+ }
82
+ function toContainedWorkspacePath(cwd, workflowFile) {
83
+ const path = relative(cwd, workflowFile);
84
+ if (path.startsWith("..") || path === "" || path.split(/[\\/]/).includes("..")) {
85
+ return err({
86
+ type: "workflow-outside-workspace",
87
+ workflowFile,
88
+ cwd,
89
+ message: `Workflow file '${workflowFile}' must be inside workspace '${cwd}'.`,
90
+ });
91
+ }
92
+ return ok(toWorkspacePath(path));
93
+ }
94
+ function toWorkspacePath(path) {
95
+ return path.split(/[\\/]/).join("/");
96
+ }
97
+ function causeMessage(cause) {
98
+ return cause instanceof Error ? cause.message : String(cause);
99
+ }
100
+ //# sourceMapping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AAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC"}
@@ -0,0 +1,9 @@
1
+ export type ProcessResult = {
2
+ exitCode: number | null;
3
+ stdout: string;
4
+ stderr: string;
5
+ };
6
+ export declare function runProcess(command: string, args: string[], options?: {
7
+ cwd?: string;
8
+ }): Promise<ProcessResult>;
9
+ //# sourceMappingURL=process.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process.d.ts","sourceRoot":"","sources":["../../src/compiler/process.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,wBAAsB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,OAAO,CAAC,aAAa,CAAC,CAkBxH"}
@@ -0,0 +1,21 @@
1
+ import { spawn } from "node:child_process";
2
+ export async function runProcess(command, args, options = {}) {
3
+ return new Promise(resolveProcess => {
4
+ const child = spawn(command, args, { cwd: options.cwd, stdio: ["ignore", "pipe", "pipe"] });
5
+ const stdout = [];
6
+ const stderr = [];
7
+ child.stdout.on("data", chunk => stdout.push(Buffer.from(chunk)));
8
+ child.stderr.on("data", chunk => stderr.push(Buffer.from(chunk)));
9
+ child.on("close", exitCode => resolveProcess({
10
+ exitCode,
11
+ stdout: Buffer.concat(stdout).toString("utf8"),
12
+ stderr: Buffer.concat(stderr).toString("utf8"),
13
+ }));
14
+ child.on("error", error => resolveProcess({
15
+ exitCode: null,
16
+ stdout: "",
17
+ stderr: error.message,
18
+ }));
19
+ });
20
+ }
21
+ //# sourceMappingURL=process.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process.js","sourceRoot":"","sources":["../../src/compiler/process.ts"],"names":[],"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CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { WorkflowIR } from "@acpus/core/ir";
2
+ export type CompileWorkerResult = {
3
+ ok: true;
4
+ ir: WorkflowIR;
5
+ } | {
6
+ ok: false;
7
+ type: string;
8
+ message: string;
9
+ stack?: string;
10
+ };
11
+ export declare function compileWorkflow(entry: string, cwd: string, scratchDir: string): Promise<CompileWorkerResult>;
12
+ //# sourceMappingURL=worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../src/compiler/worker.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGjD,MAAM,MAAM,mBAAmB,GAC3B;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,EAAE,EAAE,UAAU,CAAA;CAAE,GAC5B;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjE,wBAAsB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAoBlH"}
@@ -0,0 +1,35 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { runProcess } from "./process.js";
5
+ export async function compileWorkflow(entry, cwd, scratchDir) {
6
+ const out = join(scratchDir, "workflow-ir.json");
7
+ const isSourceWorker = import.meta.url.endsWith(".ts");
8
+ const worker = fileURLToPath(new URL(isSourceWorker ? "./compile-worker.ts" : "./compile-worker.js", import.meta.url));
9
+ const args = [worker, entry, entry, out, cwd];
10
+ if (isSourceWorker) {
11
+ args.unshift("--import", await import.meta.resolve("tsx"));
12
+ // Workspace development should compile workflows against live core source.
13
+ // Published installs must omit this condition and resolve normal package dist.
14
+ args.unshift("--conditions=development");
15
+ }
16
+ const result = await runProcess(process.execPath, args);
17
+ if (result.exitCode !== 0) {
18
+ const payload = await readWorkerResult(out);
19
+ if (payload && !payload.ok)
20
+ return payload;
21
+ const message = [result.stderr, result.stdout].filter(Boolean).join("\n").trim() || "Workflow compile failed.";
22
+ return { ok: false, type: "compile-worker-failed", message };
23
+ }
24
+ const raw = await readFile(out, "utf8");
25
+ return { ok: true, ir: JSON.parse(raw) };
26
+ }
27
+ async function readWorkerResult(path) {
28
+ try {
29
+ return JSON.parse(await readFile(path, "utf8"));
30
+ }
31
+ catch {
32
+ return undefined;
33
+ }
34
+ }
35
+ //# sourceMappingURL=worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.js","sourceRoot":"","sources":["../../src/compiler/worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAM1C,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,KAAa,EAAE,GAAW,EAAE,UAAkB;IAClF,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;IACjD,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACvD,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,qBAAqB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IACvH,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAC9C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owModule, tryCompileWorkflowModule, type CompileOptions, type CompileWorkflowModuleError, } from "./compiler/module.js";
2
+ export { prepareWorkflow, tryPrepareWorkflow, type PreparedWorkflow, type WorkflowPreparationLock, type WorkflowPreparationOptions, WorkflowPreparationError, type WorkflowPreparationFailure, } from "./preflight/index.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,wBAAwB,EACxB,KAAK,cAAc,EACnB,KAAK,0BAA0B,GAChC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAC5B,KAAK,0BAA0B,EAC/B,wBAAwB,EACxB,KAAK,0BAA0B,GAChC,MAAM,sBAAsB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { compileWorkflowModule, tryCompileWorkflowModule, } from "./compiler/module.js";
2
+ export { prepareWorkflow, tryPrepareWorkflow, WorkflowPreparationError, } from "./preflight/index.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,wBAAwB,GAGzB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,eAAe,EACf,kBAAkB,EAIlB,wBAAwB,GAEzB,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { ESLint, Rule } from "eslint";
2
+ export declare const rules: Record<string, Rule.RuleModule>;
3
+ declare const plugin: ESLint.Plugin;
4
+ export default plugin;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/internal/eslint-plugin/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAqD3C,eAAO,MAAM,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,CAEjD,CAAC;AAEF,QAAA,MAAM,MAAM,EAAE,MAAM,CAAC,MAKpB,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -0,0 +1,71 @@
1
+ import ts from "typescript";
2
+ import { checkWorkflowAuthoring } from "../../check/authoring-rules/index.js";
3
+ import { analyzeWorkflowTasksSync } from "../../task-analysis/index.js";
4
+ const checkRule = {
5
+ meta: {
6
+ type: "problem",
7
+ docs: {
8
+ description: "Run internal Acpus authoring checks for workflow fixtures.",
9
+ },
10
+ schema: [],
11
+ },
12
+ create(context) {
13
+ return {
14
+ "Program:exit"(node) {
15
+ const sourceCode = context.sourceCode;
16
+ const services = parserServices(context);
17
+ const program = services?.program;
18
+ const sourceFile = sourceFileForNode(node, services) ?? program?.getSourceFile(context.filename);
19
+ if (!program || !sourceFile) {
20
+ context.report({
21
+ loc: { line: 1, column: 0 },
22
+ message: "Acpus internal check requires @typescript-eslint/parser with typed parser services. Configure parserOptions.project for workflow fixtures.",
23
+ });
24
+ return;
25
+ }
26
+ const diagnostics = checkWorkflowAuthoring({
27
+ program,
28
+ sourceFile,
29
+ taskAnalysis: analyzeWorkflowTasksSync(sourceFile.fileName, sourceCode.text),
30
+ });
31
+ for (const diagnostic of diagnostics) {
32
+ context.report({
33
+ loc: reportLocation(diagnostic),
34
+ message: reportMessage(diagnostic),
35
+ });
36
+ }
37
+ },
38
+ };
39
+ },
40
+ };
41
+ export const rules = {
42
+ check: checkRule,
43
+ };
44
+ const plugin = {
45
+ meta: {
46
+ name: "@acpus/workflow-compiler/internal/eslint-plugin",
47
+ },
48
+ rules,
49
+ };
50
+ export default plugin;
51
+ function parserServices(context) {
52
+ const sourceCode = context.sourceCode;
53
+ return sourceCode.parserServices
54
+ ?? context.parserServices;
55
+ }
56
+ function sourceFileForNode(node, services) {
57
+ const tsNode = services?.esTreeNodeToTSNodeMap?.get(node);
58
+ return tsNode?.getSourceFile();
59
+ }
60
+ function reportMessage(diagnostic) {
61
+ return `${diagnostic.code}: ${diagnostic.message}${diagnostic.hint ? `\nHint: ${diagnostic.hint}` : ""}`;
62
+ }
63
+ function reportLocation(diagnostic) {
64
+ if (!diagnostic.source)
65
+ return { line: 1, column: 0 };
66
+ return {
67
+ line: diagnostic.source.line ?? 1,
68
+ column: Math.max(0, (diagnostic.source.column ?? 1) - 1),
69
+ };
70
+ }
71
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/internal/eslint-plugin/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAWxE,MAAM,SAAS,GAAoB;IACjC,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EAAE,4DAA4D;SAC1E;QACD,MAAM,EAAE,EAAE;KACX;IACD,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,cAAc,CAAC,IAAa;gBAC1B,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;gBACtC,MAAM,QAAQ,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;gBACzC,MAAM,OAAO,GAAG,QAAQ,EAAE,OAAO,CAAC;gBAClC,MAAM,UAAU,GAAG,iBAAiB,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,OAAO,EAAE,aAAa,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;gBACjG,IAAI,CAAC,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC;oBAC5B,OAAO,CAAC,MAAM,CAAC;wBACb,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE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AC3G,CAAC;AAED,SAAS,cAAc,CAAC,UAAwB;IAC9C,IAAI,CAAC,UAAU,CAAC,MAAM;QAAE,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;IACtD,OAAO;QACL,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC;QACjC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;KACzD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,53 @@
1
+ import type { WorkflowIR } from "@acpus/core/ir";
2
+ import { ResultAsync } from "neverthrow";
3
+ export type WorkflowPreparationOptions = {
4
+ workflow: string;
5
+ cwd: string;
6
+ };
7
+ export type WorkflowPreparationLock = {
8
+ kind: "acpus_workflow_preparation_lock";
9
+ version: 1;
10
+ workflow: {
11
+ entry: string;
12
+ sourceDigest?: string;
13
+ };
14
+ ir: {
15
+ path: "workflow.ir.json";
16
+ digest: string;
17
+ };
18
+ packageLockDigest?: string;
19
+ sourceGraphDigest: string;
20
+ generatedAt: string;
21
+ };
22
+ export type PreparedWorkflow = {
23
+ workflowPath: string;
24
+ ir: WorkflowIR;
25
+ irJson: string;
26
+ irDigest: string;
27
+ sourceGraphDigest: string;
28
+ packageLockDigest?: string;
29
+ lock: WorkflowPreparationLock;
30
+ };
31
+ export type WorkflowPreparationFailure = {
32
+ type: "check-failed";
33
+ phase: "check";
34
+ message: string;
35
+ diagnostics: WorkflowIR["diagnostics"];
36
+ } | {
37
+ type: "compile-failed";
38
+ phase: "compile";
39
+ message: string;
40
+ } | {
41
+ type: "validate-failed";
42
+ phase: "validate";
43
+ message: string;
44
+ diagnostics: WorkflowIR["diagnostics"];
45
+ ir: WorkflowIR;
46
+ };
47
+ export declare class WorkflowPreparationError extends Error {
48
+ readonly failure: WorkflowPreparationFailure;
49
+ constructor(failure: WorkflowPreparationFailure);
50
+ }
51
+ export declare function prepareWorkflow(options: WorkflowPreparationOptions): Promise<PreparedWorkflow>;
52
+ export declare function tryPrepareWorkflow(options: WorkflowPreparationOptions): ResultAsync<PreparedWorkflow, WorkflowPreparationFailure>;
53
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/preflight/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAIjD,OAAO,EAAW,WAAW,EAAe,MAAM,YAAY,CAAC;AAE/D,MAAM,MAAM,0BAA0B,GAAG;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,CAAC,CAAC;IACX,QAAQ,EAAE;QACR,KAAK,EAAE,MAAM,CAAC;QACd,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;IACF,EAAE,EAAE;QACF,IAAI,EAAE,kBAAkB,CAAC;QACzB,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,YAAY,EAAE,MAAM,CAAC;IACrB,EAAE,EAAE,UAAU,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,IAAI,EAAE,uBAAuB,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAClC;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,KAAK,EAAE,OA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