@barnum/barnum 0.0.0-main-bca0b910 → 0.0.0-main-51883efe

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.
Binary file
Binary file
Binary file
Binary file
Binary file
package/index.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from "./barnum-config-schema.zod.js";
2
2
  export * from "./barnum-cli-schema.zod.js";
3
+ export { barnum, barnumRun, barnumConfig, barnumVersion } from "./run.js";
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@barnum/barnum",
3
- "version": "0.0.0-main-bca0b910",
3
+ "version": "0.0.0-main-51883efe",
4
+ "type": "module",
4
5
  "description": "Barnum CLI - workflow engine for agents.",
5
6
  "main": "index.ts",
6
7
  "types": "index.ts",
@@ -8,10 +9,10 @@
8
9
  ".": "./index.ts",
9
10
  "./schema": "./barnum-config-schema.zod.ts",
10
11
  "./cli-schema": "./barnum-cli-schema.zod.ts",
11
- "./binary": "./index.js"
12
+ "./binary": "./index.cjs"
12
13
  },
13
14
  "bin": {
14
- "barnum": "cli.js"
15
+ "barnum": "cli.cjs"
15
16
  },
16
17
  "author": "Robert Balicki",
17
18
  "license": "MIT",
@@ -32,12 +33,13 @@
32
33
  ],
33
34
  "files": [
34
35
  "index.ts",
35
- "index.js",
36
- "cli.js",
36
+ "index.cjs",
37
+ "cli.cjs",
37
38
  "artifacts/**/*",
38
39
  "barnum-config-schema.json",
39
40
  "barnum-config-schema.zod.ts",
40
- "barnum-cli-schema.zod.ts"
41
+ "barnum-cli-schema.zod.ts",
42
+ "run.ts"
41
43
  ],
42
44
  "scripts": {
43
45
  "typecheck": "tsc --noEmit"
@@ -46,6 +48,7 @@
46
48
  "zod": "^3.0.0"
47
49
  },
48
50
  "devDependencies": {
51
+ "@types/node": "^25.5.0",
49
52
  "typescript": "^5.9.3"
50
53
  },
51
54
  "sideEffects": false
package/run.ts ADDED
@@ -0,0 +1,97 @@
1
+ import { spawn, type ChildProcess } from "node:child_process";
2
+ import { chmodSync } from "node:fs";
3
+ import { createRequire } from "node:module";
4
+ import type { Cli, Command, ConfigCommand } from "./barnum-cli-schema.zod.js";
5
+
6
+ const require = createRequire(import.meta.url);
7
+ const binaryPath: string = process.env.BARNUM ?? require("./index.cjs");
8
+
9
+ function spawnBarnum(args: string[]): ChildProcess {
10
+ try {
11
+ chmodSync(binaryPath, 0o755);
12
+ } catch {}
13
+ return spawn(binaryPath, args, { stdio: "inherit" });
14
+ }
15
+
16
+ function camelToKebab(s: string): string {
17
+ return s.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
18
+ }
19
+
20
+ function pushFields(
21
+ args: string[],
22
+ obj: Record<string, unknown>,
23
+ skip: string[],
24
+ ): void {
25
+ for (const [key, value] of Object.entries(obj)) {
26
+ if (skip.includes(key) || value == null) continue;
27
+ if (typeof value === "boolean") {
28
+ if (value) args.push(`--${camelToKebab(key)}`);
29
+ } else {
30
+ args.push(`--${camelToKebab(key)}`, String(value));
31
+ }
32
+ }
33
+ }
34
+
35
+ function pushGlobalArgs(args: string[], cli: Partial<Cli>): void {
36
+ if (cli.root) args.push("--root", cli.root);
37
+ if (cli.logLevel) args.push("--log-level", cli.logLevel);
38
+ }
39
+
40
+ export function barnum(cli: Cli): ChildProcess {
41
+ const args: string[] = [];
42
+ pushGlobalArgs(args, cli);
43
+
44
+ switch (cli.command.kind) {
45
+ case "Run": {
46
+ args.push("run");
47
+ pushFields(args, cli.command, ["kind"]);
48
+ return spawnBarnum(args);
49
+ }
50
+ case "Config": {
51
+ args.push("config");
52
+ const sub = cli.command.command;
53
+ args.push(sub.kind.toLowerCase());
54
+ pushFields(args, sub, ["kind"]);
55
+ return spawnBarnum(args);
56
+ }
57
+ case "Version": {
58
+ args.push("version");
59
+ pushFields(args, cli.command, ["kind"]);
60
+ return spawnBarnum(args);
61
+ }
62
+ }
63
+ }
64
+
65
+ type GlobalOpts = { root?: string; logLevel?: Cli["logLevel"] };
66
+ type RunOpts = Omit<Extract<Command, { kind: "Run" }>, "kind">;
67
+
68
+ export function barnumRun(opts: RunOpts & GlobalOpts): ChildProcess {
69
+ const { root, logLevel, ...runOpts } = opts;
70
+ return barnum({
71
+ root,
72
+ logLevel,
73
+ command: { kind: "Run", ...runOpts },
74
+ } as Cli);
75
+ }
76
+
77
+ export function barnumConfig(
78
+ opts: { command: ConfigCommand } & GlobalOpts,
79
+ ): ChildProcess {
80
+ const { root, logLevel, command } = opts;
81
+ return barnum({
82
+ root,
83
+ logLevel,
84
+ command: { kind: "Config", command },
85
+ } as Cli);
86
+ }
87
+
88
+ export function barnumVersion(
89
+ opts?: Omit<Extract<Command, { kind: "Version" }>, "kind"> & GlobalOpts,
90
+ ): ChildProcess {
91
+ const { root, logLevel, ...rest } = opts ?? {};
92
+ return barnum({
93
+ root,
94
+ logLevel,
95
+ command: { kind: "Version", json: false, ...rest },
96
+ } as Cli);
97
+ }
File without changes
File without changes