@barnum/barnum 0.2.3 → 0.4.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 (115) hide show
  1. package/artifacts/linux-arm64/barnum +0 -0
  2. package/artifacts/linux-x64/barnum +0 -0
  3. package/artifacts/macos-arm64/barnum +0 -0
  4. package/artifacts/macos-x64/barnum +0 -0
  5. package/artifacts/win-x64/barnum.exe +0 -0
  6. package/cli.cjs +33 -0
  7. package/dist/all.d.ts +43 -0
  8. package/dist/all.d.ts.map +1 -0
  9. package/dist/all.js +8 -0
  10. package/dist/ast.d.ts +476 -0
  11. package/dist/ast.d.ts.map +1 -0
  12. package/dist/ast.js +419 -0
  13. package/dist/bind.d.ts +59 -0
  14. package/dist/bind.d.ts.map +1 -0
  15. package/dist/bind.js +69 -0
  16. package/dist/builtins/array.d.ts +36 -0
  17. package/dist/builtins/array.d.ts.map +1 -0
  18. package/dist/builtins/array.js +93 -0
  19. package/dist/builtins/index.d.ts +6 -0
  20. package/dist/builtins/index.d.ts.map +1 -0
  21. package/dist/builtins/index.js +5 -0
  22. package/dist/builtins/scalar.d.ts +12 -0
  23. package/dist/builtins/scalar.d.ts.map +1 -0
  24. package/dist/builtins/scalar.js +41 -0
  25. package/dist/builtins/struct.d.ts +25 -0
  26. package/dist/builtins/struct.d.ts.map +1 -0
  27. package/dist/builtins/struct.js +67 -0
  28. package/dist/builtins/tagged-union.d.ts +54 -0
  29. package/dist/builtins/tagged-union.d.ts.map +1 -0
  30. package/dist/builtins/tagged-union.js +81 -0
  31. package/dist/builtins/with-resource.d.ts +23 -0
  32. package/dist/builtins/with-resource.d.ts.map +1 -0
  33. package/dist/builtins/with-resource.js +35 -0
  34. package/dist/chain.d.ts +3 -0
  35. package/dist/chain.d.ts.map +1 -0
  36. package/dist/chain.js +8 -0
  37. package/dist/effect-id.d.ts +15 -0
  38. package/dist/effect-id.d.ts.map +1 -0
  39. package/dist/effect-id.js +16 -0
  40. package/dist/handler.d.ts +51 -0
  41. package/dist/handler.d.ts.map +1 -0
  42. package/dist/handler.js +130 -0
  43. package/dist/index.d.ts +12 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +7 -0
  46. package/dist/iterator.d.ts +32 -0
  47. package/dist/iterator.d.ts.map +1 -0
  48. package/dist/iterator.js +123 -0
  49. package/dist/option.d.ts +74 -0
  50. package/dist/option.d.ts.map +1 -0
  51. package/dist/option.js +141 -0
  52. package/dist/pipe.d.ts +12 -0
  53. package/dist/pipe.d.ts.map +1 -0
  54. package/dist/pipe.js +12 -0
  55. package/dist/race.d.ts +54 -0
  56. package/dist/race.d.ts.map +1 -0
  57. package/dist/race.js +116 -0
  58. package/dist/recursive.d.ts +40 -0
  59. package/dist/recursive.d.ts.map +1 -0
  60. package/dist/recursive.js +58 -0
  61. package/dist/result.d.ts +50 -0
  62. package/dist/result.d.ts.map +1 -0
  63. package/dist/result.js +117 -0
  64. package/dist/run.d.ts +14 -0
  65. package/dist/run.d.ts.map +1 -0
  66. package/dist/run.js +160 -0
  67. package/dist/runtime.d.ts +6 -0
  68. package/dist/runtime.d.ts.map +1 -0
  69. package/dist/runtime.js +7 -0
  70. package/dist/schema.d.ts +9 -0
  71. package/dist/schema.d.ts.map +1 -0
  72. package/dist/schema.js +95 -0
  73. package/dist/schemas.d.ts +5 -0
  74. package/dist/schemas.d.ts.map +1 -0
  75. package/dist/schemas.js +13 -0
  76. package/dist/try-catch.d.ts +24 -0
  77. package/dist/try-catch.d.ts.map +1 -0
  78. package/dist/try-catch.js +37 -0
  79. package/dist/values.d.ts +6 -0
  80. package/dist/values.d.ts.map +1 -0
  81. package/dist/values.js +12 -0
  82. package/dist/worker.d.ts +15 -0
  83. package/dist/worker.d.ts.map +1 -0
  84. package/dist/worker.js +58 -0
  85. package/package.json +42 -16
  86. package/src/all.ts +133 -0
  87. package/src/ast.ts +1301 -0
  88. package/src/bind.ts +162 -0
  89. package/src/builtins/array.ts +121 -0
  90. package/src/builtins/index.ts +17 -0
  91. package/src/builtins/scalar.ts +49 -0
  92. package/src/builtins/struct.ts +111 -0
  93. package/src/builtins/tagged-union.ts +142 -0
  94. package/src/builtins/with-resource.ts +69 -0
  95. package/src/chain.ts +17 -0
  96. package/src/effect-id.ts +30 -0
  97. package/src/handler.ts +263 -0
  98. package/src/index.ts +37 -0
  99. package/src/iterator.ts +243 -0
  100. package/src/option.ts +199 -0
  101. package/src/pipe.ts +138 -0
  102. package/src/race.ts +173 -0
  103. package/src/recursive.ts +129 -0
  104. package/src/result.ts +168 -0
  105. package/src/run.ts +209 -0
  106. package/src/runtime.ts +16 -0
  107. package/src/schema.ts +118 -0
  108. package/src/schemas.ts +21 -0
  109. package/src/try-catch.ts +57 -0
  110. package/src/values.ts +21 -0
  111. package/src/worker.ts +71 -0
  112. package/README.md +0 -19
  113. package/barnum-config-schema.json +0 -408
  114. package/cli.js +0 -20
  115. package/index.js +0 -23
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Worker script: invoked as `tsx worker.ts <module> <export>`.
3
+ *
4
+ * Protocol:
5
+ * Rust → stdin: JSON `{ "value": <any> }`
6
+ * stdout → Rust: JSON result (handler return value)
7
+ *
8
+ * stdout is reserved for the protocol. All console output is redirected to
9
+ * stderr so that handler code can freely use console.log for debugging.
10
+ *
11
+ * If the handler throws or the module/export can't be resolved, the
12
+ * process exits non-zero. Rust interprets that as a fatal workflow error.
13
+ */
14
+ export {};
15
+ //# sourceMappingURL=worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG"}
package/dist/worker.js ADDED
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Worker script: invoked as `tsx worker.ts <module> <export>`.
3
+ *
4
+ * Protocol:
5
+ * Rust → stdin: JSON `{ "value": <any> }`
6
+ * stdout → Rust: JSON result (handler return value)
7
+ *
8
+ * stdout is reserved for the protocol. All console output is redirected to
9
+ * stderr so that handler code can freely use console.log for debugging.
10
+ *
11
+ * If the handler throws or the module/export can't be resolved, the
12
+ * process exits non-zero. Rust interprets that as a fatal workflow error.
13
+ */
14
+ // Redirect all console output to stderr — stdout is the protocol channel.
15
+ // This must happen before any handler code is imported or executed.
16
+ import { Console } from "node:console";
17
+ const stderrConsole = new Console({ stdout: process.stderr });
18
+ globalThis.console = stderrConsole;
19
+ // Suppress EPIPE — when the Rust binary exits (e.g., a race was resolved),
20
+ // orphan workers get broken pipe on stdout. This is expected, not an error.
21
+ process.stdout.on("error", (error) => {
22
+ if (error.code === "EPIPE") {
23
+ process.exit(0);
24
+ }
25
+ throw error;
26
+ });
27
+ async function main() {
28
+ const [modulePath, exportName = "default"] = process.argv.slice(2);
29
+ if (!modulePath) {
30
+ process.stderr.write("worker: missing module path argument\n");
31
+ process.exit(1);
32
+ }
33
+ // Read entire stdin
34
+ const chunks = [];
35
+ for await (const chunk of process.stdin) {
36
+ chunks.push(chunk);
37
+ }
38
+ const input = JSON.parse(Buffer.concat(chunks).toString());
39
+ // Import handler, call it
40
+ const mod = await import(modulePath);
41
+ const handler = mod[exportName];
42
+ if (!handler?.__definition?.handle) {
43
+ process.stderr.write(`worker: ${modulePath}:${exportName} is not a barnum handler\n`);
44
+ process.exit(1);
45
+ }
46
+ const result = await handler.__definition.handle({ value: input.value });
47
+ // Write result to stdout, then exit. Explicit exit is required because
48
+ // importing the handler module may leave open handles (timers, servers,
49
+ // etc.) that keep the Node event loop alive indefinitely.
50
+ const json = JSON.stringify(result) ?? "null";
51
+ process.stdout.write(json, () => {
52
+ process.exit(0);
53
+ });
54
+ }
55
+ main().catch((error) => {
56
+ process.stderr.write(`worker: ${error}\n`);
57
+ process.exit(1);
58
+ });
package/package.json CHANGED
@@ -1,10 +1,30 @@
1
1
  {
2
2
  "name": "@barnum/barnum",
3
- "version": "0.2.3",
4
- "description": "Barnum CLI - workflow engine for agents.",
5
- "main": "index.js",
3
+ "version": "0.4.0",
4
+ "description": "Barnum workflow engine",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ "./pipeline": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ },
13
+ "./runtime": {
14
+ "types": "./dist/runtime.d.ts",
15
+ "default": "./dist/runtime.js"
16
+ },
17
+ "./package.json": "./package.json"
18
+ },
6
19
  "bin": {
7
- "barnum": "cli.js"
20
+ "barnum": "cli.cjs"
21
+ },
22
+ "scripts": {
23
+ "prepack": "tsc -p tsconfig.build.json",
24
+ "build": "tsc -p tsconfig.build.json",
25
+ "test": "vitest run",
26
+ "typecheck": "tsc --noEmit",
27
+ "lint": "oxlint src/ tests/"
8
28
  },
9
29
  "author": "Robert Balicki",
10
30
  "license": "MIT",
@@ -16,18 +36,24 @@
16
36
  "access": "public",
17
37
  "registry": "https://registry.npmjs.org"
18
38
  },
19
- "keywords": [
20
- "barnum",
21
- "ai",
22
- "agents",
23
- "automation",
24
- "cli"
25
- ],
26
39
  "files": [
27
- "index.js",
28
- "cli.js",
29
- "artifacts/**/*",
30
- "barnum-config-schema.json"
40
+ "dist/**/*",
41
+ "src/**/*.ts",
42
+ "cli.cjs",
43
+ "artifacts/**/*"
31
44
  ],
32
- "sideEffects": false
45
+ "sideEffects": false,
46
+ "devDependencies": {
47
+ "@oxlint/binding-darwin-arm64": "^1.57.0",
48
+ "@types/json-schema": "^7.0.15",
49
+ "@types/node": "^25.5.0",
50
+ "oxlint": "^1.57.0",
51
+ "prettier": "^3.8.1",
52
+ "tsx": "^4.21.0",
53
+ "typescript": "^6.0.3",
54
+ "vitest": "^3.0.0"
55
+ },
56
+ "peerDependencies": {
57
+ "zod": "^4.3.6"
58
+ }
33
59
  }
package/src/all.ts ADDED
@@ -0,0 +1,133 @@
1
+ import {
2
+ type Action,
3
+ type Pipeable,
4
+ type TypedAction,
5
+ typedAction,
6
+ } from "./ast.js";
7
+ import { constant } from "./builtins/index.js";
8
+
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ export function all(): TypedAction<any, []>;
11
+ export function all<TInput, TOut1>(
12
+ a1: Pipeable<TInput, TOut1>,
13
+ ): TypedAction<TInput, [TOut1]>;
14
+ export function all<TInput, TOut1, TOut2>(
15
+ a1: Pipeable<TInput, TOut1>,
16
+ a2: Pipeable<TInput, TOut2>,
17
+ ): TypedAction<TInput, [TOut1, TOut2]>;
18
+ export function all<TInput, TOut1, TOut2, TOut3>(
19
+ a1: Pipeable<TInput, TOut1>,
20
+ a2: Pipeable<TInput, TOut2>,
21
+ a3: Pipeable<TInput, TOut3>,
22
+ ): TypedAction<TInput, [TOut1, TOut2, TOut3]>;
23
+ export function all<TInput, TOut1, TOut2, TOut3, TOut4>(
24
+ a1: Pipeable<TInput, TOut1>,
25
+ a2: Pipeable<TInput, TOut2>,
26
+ a3: Pipeable<TInput, TOut3>,
27
+ a4: Pipeable<TInput, TOut4>,
28
+ ): TypedAction<TInput, [TOut1, TOut2, TOut3, TOut4]>;
29
+ export function all<TInput, TOut1, TOut2, TOut3, TOut4, TOut5>(
30
+ a1: Pipeable<TInput, TOut1>,
31
+ a2: Pipeable<TInput, TOut2>,
32
+ a3: Pipeable<TInput, TOut3>,
33
+ a4: Pipeable<TInput, TOut4>,
34
+ a5: Pipeable<TInput, TOut5>,
35
+ ): TypedAction<TInput, [TOut1, TOut2, TOut3, TOut4, TOut5]>;
36
+ export function all<TInput, TOut1, TOut2, TOut3, TOut4, TOut5, TOut6>(
37
+ a1: Pipeable<TInput, TOut1>,
38
+ a2: Pipeable<TInput, TOut2>,
39
+ a3: Pipeable<TInput, TOut3>,
40
+ a4: Pipeable<TInput, TOut4>,
41
+ a5: Pipeable<TInput, TOut5>,
42
+ a6: Pipeable<TInput, TOut6>,
43
+ ): TypedAction<TInput, [TOut1, TOut2, TOut3, TOut4, TOut5, TOut6]>;
44
+ export function all<TInput, TOut1, TOut2, TOut3, TOut4, TOut5, TOut6, TOut7>(
45
+ a1: Pipeable<TInput, TOut1>,
46
+ a2: Pipeable<TInput, TOut2>,
47
+ a3: Pipeable<TInput, TOut3>,
48
+ a4: Pipeable<TInput, TOut4>,
49
+ a5: Pipeable<TInput, TOut5>,
50
+ a6: Pipeable<TInput, TOut6>,
51
+ a7: Pipeable<TInput, TOut7>,
52
+ ): TypedAction<TInput, [TOut1, TOut2, TOut3, TOut4, TOut5, TOut6, TOut7]>;
53
+ export function all<
54
+ TInput,
55
+ TOut1,
56
+ TOut2,
57
+ TOut3,
58
+ TOut4,
59
+ TOut5,
60
+ TOut6,
61
+ TOut7,
62
+ TOut8,
63
+ >(
64
+ a1: Pipeable<TInput, TOut1>,
65
+ a2: Pipeable<TInput, TOut2>,
66
+ a3: Pipeable<TInput, TOut3>,
67
+ a4: Pipeable<TInput, TOut4>,
68
+ a5: Pipeable<TInput, TOut5>,
69
+ a6: Pipeable<TInput, TOut6>,
70
+ a7: Pipeable<TInput, TOut7>,
71
+ a8: Pipeable<TInput, TOut8>,
72
+ ): TypedAction<
73
+ TInput,
74
+ [TOut1, TOut2, TOut3, TOut4, TOut5, TOut6, TOut7, TOut8]
75
+ >;
76
+ export function all<
77
+ TInput,
78
+ TOut1,
79
+ TOut2,
80
+ TOut3,
81
+ TOut4,
82
+ TOut5,
83
+ TOut6,
84
+ TOut7,
85
+ TOut8,
86
+ TOut9,
87
+ >(
88
+ a1: Pipeable<TInput, TOut1>,
89
+ a2: Pipeable<TInput, TOut2>,
90
+ a3: Pipeable<TInput, TOut3>,
91
+ a4: Pipeable<TInput, TOut4>,
92
+ a5: Pipeable<TInput, TOut5>,
93
+ a6: Pipeable<TInput, TOut6>,
94
+ a7: Pipeable<TInput, TOut7>,
95
+ a8: Pipeable<TInput, TOut8>,
96
+ a9: Pipeable<TInput, TOut9>,
97
+ ): TypedAction<
98
+ TInput,
99
+ [TOut1, TOut2, TOut3, TOut4, TOut5, TOut6, TOut7, TOut8, TOut9]
100
+ >;
101
+ export function all<
102
+ TInput,
103
+ TOut1,
104
+ TOut2,
105
+ TOut3,
106
+ TOut4,
107
+ TOut5,
108
+ TOut6,
109
+ TOut7,
110
+ TOut8,
111
+ TOut9,
112
+ TOut10,
113
+ >(
114
+ a1: Pipeable<TInput, TOut1>,
115
+ a2: Pipeable<TInput, TOut2>,
116
+ a3: Pipeable<TInput, TOut3>,
117
+ a4: Pipeable<TInput, TOut4>,
118
+ a5: Pipeable<TInput, TOut5>,
119
+ a6: Pipeable<TInput, TOut6>,
120
+ a7: Pipeable<TInput, TOut7>,
121
+ a8: Pipeable<TInput, TOut8>,
122
+ a9: Pipeable<TInput, TOut9>,
123
+ a10: Pipeable<TInput, TOut10>,
124
+ ): TypedAction<
125
+ TInput,
126
+ [TOut1, TOut2, TOut3, TOut4, TOut5, TOut6, TOut7, TOut8, TOut9, TOut10]
127
+ >;
128
+ export function all(...actions: Action[]): Action {
129
+ if (actions.length === 0) {
130
+ return constant([]);
131
+ }
132
+ return typedAction({ kind: "All", actions });
133
+ }