@trama-dev/cli 0.1.5 → 0.2.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 (2) hide show
  1. package/dist/index.js +35 -66
  2. package/package.json +7 -3
package/dist/index.js CHANGED
@@ -1,12 +1,14 @@
1
1
  #!/usr/bin/env node
2
+ import { readFileSync } from "node:fs";
2
3
  import { Command } from "commander";
3
4
  import { createProject, runProgram, updateProject, listProjects, showLogs, resolveProject, } from "@trama-dev/runtime/runner";
4
5
  function collectArg(value, previous) {
5
6
  return [...previous, value];
6
7
  }
8
+ /** Turn repeated `--arg key=value` options into an args object (undefined if none were given). */
7
9
  function parseArgs(args) {
8
10
  if (args.length === 0)
9
- return {};
11
+ return undefined;
10
12
  const result = {};
11
13
  for (const arg of args) {
12
14
  const eq = arg.indexOf("=");
@@ -17,94 +19,61 @@ function parseArgs(args) {
17
19
  }
18
20
  return result;
19
21
  }
22
+ /** Wrap a command so any failure is reported as a one-line error with a non-zero exit. */
23
+ function command(run) {
24
+ return async (...args) => {
25
+ try {
26
+ await run(...args);
27
+ }
28
+ catch (err) {
29
+ console.error(`Error: ${err instanceof Error ? err.message : err}`);
30
+ process.exit(1);
31
+ }
32
+ };
33
+ }
34
+ // Read the version from package.json (shipped next to dist/) so it can't drift from the published version.
35
+ const { version } = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf-8"));
20
36
  const cli = new Command()
21
37
  .name("trama")
22
38
  .description("A minimal runtime for agent-authored programs")
23
- .version("0.1.4");
39
+ .version(version);
24
40
  cli
25
41
  .command("create <name> <prompt>")
26
42
  .description("Generate a new program from a natural language prompt")
27
43
  .option("--model <model>", "LLM model to use")
28
44
  .option("--arg <key=value>", "Pass argument to the program (repeatable)", collectArg, [])
29
- .action(async (name, prompt, opts) => {
30
- try {
31
- const args = parseArgs(opts.arg);
32
- await createProject(name, prompt, {
33
- model: opts.model,
34
- args: Object.keys(args).length > 0 ? args : undefined,
35
- });
36
- }
37
- catch (err) {
38
- console.error(`Error: ${err instanceof Error ? err.message : err}`);
39
- process.exit(1);
40
- }
41
- });
45
+ .action(command(async (name, prompt, opts) => {
46
+ await createProject(name, prompt, { model: opts.model, args: parseArgs(opts.arg) });
47
+ }));
42
48
  cli
43
49
  .command("run <name>")
44
50
  .description("Execute a program")
45
51
  .option("--timeout <ms>", "Per-phase timeout in ms (applies to each run and repair attempt separately)")
46
52
  .option("--arg <key=value>", "Pass argument to the program (repeatable)", collectArg, [])
47
- .action(async (name, opts) => {
48
- try {
49
- let timeout;
50
- if (opts.timeout !== undefined) {
51
- timeout = Number(opts.timeout);
52
- if (!Number.isFinite(timeout) || timeout <= 0) {
53
- console.error(`Error: --timeout must be a positive number (got "${opts.timeout}")`);
54
- process.exit(1);
55
- }
56
- }
57
- const args = parseArgs(opts.arg);
58
- const projectDir = resolveProject(name);
59
- const result = await runProgram({
60
- projectDir,
61
- timeout,
62
- args: Object.keys(args).length > 0 ? args : undefined,
63
- });
64
- if (result.status === "failed") {
65
- console.error(`Error: Program failed: ${result.reason}`);
66
- process.exit(1);
53
+ .action(command(async (name, opts) => {
54
+ let timeout;
55
+ if (opts.timeout !== undefined) {
56
+ timeout = Number(opts.timeout);
57
+ if (!Number.isFinite(timeout) || timeout <= 0) {
58
+ throw new Error(`--timeout must be a positive number (got "${opts.timeout}")`);
67
59
  }
68
60
  }
69
- catch (err) {
70
- console.error(`Error: ${err instanceof Error ? err.message : err}`);
71
- process.exit(1);
61
+ const args = parseArgs(opts.arg);
62
+ const result = await runProgram({ projectDir: resolveProject(name), timeout, args });
63
+ if (result.status === "failed") {
64
+ throw new Error(`Program failed: ${result.reason}`);
72
65
  }
73
- });
66
+ }));
74
67
  cli
75
68
  .command("update <name> <prompt>")
76
69
  .description("Update an existing program with new requirements")
77
- .action(async (name, prompt) => {
78
- try {
79
- await updateProject(name, prompt);
80
- }
81
- catch (err) {
82
- console.error(`Error: ${err instanceof Error ? err.message : err}`);
83
- process.exit(1);
84
- }
85
- });
70
+ .action(command(updateProject));
86
71
  cli
87
72
  .command("list")
88
73
  .description("List all projects")
89
- .action(async () => {
90
- try {
91
- await listProjects();
92
- }
93
- catch (err) {
94
- console.error(`Error: ${err instanceof Error ? err.message : err}`);
95
- process.exit(1);
96
- }
97
- });
74
+ .action(command(listProjects));
98
75
  cli
99
76
  .command("logs <name>")
100
77
  .description("Show logs from last run")
101
- .action(async (name) => {
102
- try {
103
- await showLogs(name);
104
- }
105
- catch (err) {
106
- console.error(`Error: ${err instanceof Error ? err.message : err}`);
107
- process.exit(1);
108
- }
109
- });
78
+ .action(command(showLogs));
110
79
  cli.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trama-dev/cli",
3
- "version": "0.1.5",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "trama": "./dist/index.js"
@@ -26,8 +26,12 @@
26
26
  "LICENSE"
27
27
  ],
28
28
  "os": ["darwin", "linux"],
29
+ "engines": {
30
+ "node": ">=22.19.0"
31
+ },
29
32
  "dependencies": {
30
- "@trama-dev/runtime": "0.1.5",
31
- "commander": "^14.0.0"
33
+ "@trama-dev/runtime": "0.2.0",
34
+ "@trama-dev/session": "0.2.0",
35
+ "commander": "^15.1.0"
32
36
  }
33
37
  }