@trama-dev/cli 0.1.4 → 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.
- package/dist/index.js +35 -62
- 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,90 +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(
|
|
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
|
-
|
|
31
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
console.error(`Error: --timeout must be a positive number (got "${opts.timeout}")`);
|
|
54
|
-
process.exit(1);
|
|
55
|
-
}
|
|
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}")`);
|
|
56
59
|
}
|
|
57
|
-
const args = parseArgs(opts.arg);
|
|
58
|
-
const projectDir = resolveProject(name);
|
|
59
|
-
await runProgram({
|
|
60
|
-
projectDir,
|
|
61
|
-
timeout,
|
|
62
|
-
args: Object.keys(args).length > 0 ? args : undefined,
|
|
63
|
-
});
|
|
64
60
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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}`);
|
|
68
65
|
}
|
|
69
|
-
});
|
|
66
|
+
}));
|
|
70
67
|
cli
|
|
71
68
|
.command("update <name> <prompt>")
|
|
72
69
|
.description("Update an existing program with new requirements")
|
|
73
|
-
.action(
|
|
74
|
-
try {
|
|
75
|
-
await updateProject(name, prompt);
|
|
76
|
-
}
|
|
77
|
-
catch (err) {
|
|
78
|
-
console.error(`Error: ${err instanceof Error ? err.message : err}`);
|
|
79
|
-
process.exit(1);
|
|
80
|
-
}
|
|
81
|
-
});
|
|
70
|
+
.action(command(updateProject));
|
|
82
71
|
cli
|
|
83
72
|
.command("list")
|
|
84
73
|
.description("List all projects")
|
|
85
|
-
.action(
|
|
86
|
-
try {
|
|
87
|
-
await listProjects();
|
|
88
|
-
}
|
|
89
|
-
catch (err) {
|
|
90
|
-
console.error(`Error: ${err instanceof Error ? err.message : err}`);
|
|
91
|
-
process.exit(1);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
74
|
+
.action(command(listProjects));
|
|
94
75
|
cli
|
|
95
76
|
.command("logs <name>")
|
|
96
77
|
.description("Show logs from last run")
|
|
97
|
-
.action(
|
|
98
|
-
try {
|
|
99
|
-
await showLogs(name);
|
|
100
|
-
}
|
|
101
|
-
catch (err) {
|
|
102
|
-
console.error(`Error: ${err instanceof Error ? err.message : err}`);
|
|
103
|
-
process.exit(1);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
78
|
+
.action(command(showLogs));
|
|
106
79
|
cli.parse();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trama-dev/cli",
|
|
3
|
-
"version": "0.
|
|
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.
|
|
31
|
-
"
|
|
33
|
+
"@trama-dev/runtime": "0.2.0",
|
|
34
|
+
"@trama-dev/session": "0.2.0",
|
|
35
|
+
"commander": "^15.1.0"
|
|
32
36
|
}
|
|
33
37
|
}
|