@trama-dev/cli 0.4.0 → 0.6.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/README.md +2 -1
- package/dist/index.js +37 -7
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ The CLI for [trama](https://github.com/NaNhkNaN/trama) — the agentic runtime t
|
|
|
8
8
|
npm install -g @trama-dev/cli
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Six commands. That's the whole interface.
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
14
|
trama create optimizer "improve sort.ts by benchmarking alternatives"
|
|
@@ -16,6 +16,7 @@ trama run optimizer
|
|
|
16
16
|
trama update optimizer "also track memory usage"
|
|
17
17
|
trama list
|
|
18
18
|
trama logs optimizer
|
|
19
|
+
trama journal optimizer
|
|
19
20
|
```
|
|
20
21
|
|
|
21
22
|
`create` generates a complete agent program from one sentence. `run` executes it — with auto-repair if it crashes. `update` rewrites it with new requirements. The output is real TypeScript you can read, diff, and share. Anyone can `git clone && trama run`.
|
package/dist/index.js
CHANGED
|
@@ -34,6 +34,11 @@ function leaveBySignal(name) {
|
|
|
34
34
|
// Still here a moment later: nothing kills this process that way (process 1).
|
|
35
35
|
setTimeout(() => process.exit(128 + SIGNALS[name]), 100);
|
|
36
36
|
}
|
|
37
|
+
/** While `work` goes on, a signal stops it rather than this process. */
|
|
38
|
+
function stoppable(work) {
|
|
39
|
+
running = true;
|
|
40
|
+
return work(stopRun.signal).finally(() => { running = false; });
|
|
41
|
+
}
|
|
37
42
|
function collectArg(value, previous) {
|
|
38
43
|
return [...previous, value];
|
|
39
44
|
}
|
|
@@ -51,13 +56,36 @@ function parseArgs(args) {
|
|
|
51
56
|
}
|
|
52
57
|
return result;
|
|
53
58
|
}
|
|
59
|
+
/** Turn repeated `--budget cap=number` options into a budget (undefined if none were given). What a cap may be is the runner's to say. */
|
|
60
|
+
function parseBudget(caps) {
|
|
61
|
+
if (caps.length === 0)
|
|
62
|
+
return undefined;
|
|
63
|
+
const given = [];
|
|
64
|
+
for (const cap of caps) {
|
|
65
|
+
const eq = cap.indexOf("=");
|
|
66
|
+
const amount = eq === -1 || cap.slice(eq + 1).trim() === "" ? NaN : Number(cap.slice(eq + 1));
|
|
67
|
+
if (Number.isNaN(amount)) {
|
|
68
|
+
throw new Error(`Invalid --budget format: "${cap}". Expected cap=number, as in cost=2.50, tokens=500000 or calls=40.`);
|
|
69
|
+
}
|
|
70
|
+
const name = cap.slice(0, eq);
|
|
71
|
+
if (given.some(([had]) => had === name))
|
|
72
|
+
throw new Error(`--budget ${name} is given twice.`);
|
|
73
|
+
given.push([name, amount]);
|
|
74
|
+
}
|
|
75
|
+
// (Made of its pairs: a cap by a name every object has from birth is then a cap like any other, to be refused as one.)
|
|
76
|
+
return Object.fromEntries(given);
|
|
77
|
+
}
|
|
54
78
|
/** Wrap a command so any failure is reported as a one-line error with a non-zero exit. */
|
|
55
79
|
function command(run) {
|
|
56
80
|
return async (...args) => {
|
|
57
81
|
try {
|
|
58
82
|
await run(...args);
|
|
83
|
+
if (received)
|
|
84
|
+
return leaveBySignal(received);
|
|
59
85
|
}
|
|
60
86
|
catch (err) {
|
|
87
|
+
if (received)
|
|
88
|
+
return leaveBySignal(received);
|
|
61
89
|
console.error(`Error: ${err instanceof Error ? err.message : err}`);
|
|
62
90
|
process.exit(1);
|
|
63
91
|
}
|
|
@@ -75,13 +103,15 @@ cli
|
|
|
75
103
|
.option("--model <model>", "LLM model to use")
|
|
76
104
|
.option("--arg <key=value>", "Pass argument to the program (repeatable)", collectArg, [])
|
|
77
105
|
.action(command(async (name, prompt, opts) => {
|
|
78
|
-
|
|
106
|
+
const args = parseArgs(opts.arg);
|
|
107
|
+
await stoppable((signal) => createProject(name, prompt, { model: opts.model, args, signal }));
|
|
79
108
|
}));
|
|
80
109
|
cli
|
|
81
110
|
.command("run <name>")
|
|
82
111
|
.description("Execute a program")
|
|
83
112
|
.option("--timeout <ms>", "Per-phase timeout in ms (applies to each run and repair attempt separately)")
|
|
84
113
|
.option("--arg <key=value>", "Pass argument to the program (repeatable)", collectArg, [])
|
|
114
|
+
.option("--budget <cap=number>", "Cap what the run may use of a model: cost (US dollars), tokens or calls (repeatable)", collectArg, [])
|
|
85
115
|
.action(command(async (name, opts) => {
|
|
86
116
|
let timeout;
|
|
87
117
|
if (opts.timeout !== undefined) {
|
|
@@ -91,12 +121,10 @@ cli
|
|
|
91
121
|
}
|
|
92
122
|
}
|
|
93
123
|
const args = parseArgs(opts.arg);
|
|
124
|
+
const budget = parseBudget(opts.budget);
|
|
94
125
|
const projectDir = resolveProject(name);
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
.finally(() => { running = false; });
|
|
98
|
-
if (received)
|
|
99
|
-
return leaveBySignal(received);
|
|
126
|
+
const result = await stoppable((signal) => runProgram({ projectDir, timeout, args, budget, signal }));
|
|
127
|
+
// (A run that a signal stopped has failed, and is not reported as that: see `command`.)
|
|
100
128
|
if (result.status === "failed") {
|
|
101
129
|
throw new Error(`Program failed: ${result.reason}`);
|
|
102
130
|
}
|
|
@@ -104,7 +132,9 @@ cli
|
|
|
104
132
|
cli
|
|
105
133
|
.command("update <name> <prompt>")
|
|
106
134
|
.description("Update an existing program with new requirements")
|
|
107
|
-
.action(command(
|
|
135
|
+
.action(command(async (name, prompt) => {
|
|
136
|
+
await stoppable((signal) => updateProject(name, prompt, { signal }));
|
|
137
|
+
}));
|
|
108
138
|
cli
|
|
109
139
|
.command("list")
|
|
110
140
|
.description("List all projects")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trama-dev/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"trama": "dist/index.js"
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"node": ">=22.19.0"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@trama-dev/runtime": "0.
|
|
34
|
-
"@trama-dev/session": "0.
|
|
33
|
+
"@trama-dev/runtime": "0.6.0",
|
|
34
|
+
"@trama-dev/session": "0.6.0",
|
|
35
35
|
"commander": "15.1.0"
|
|
36
36
|
}
|
|
37
37
|
}
|