@trama-dev/cli 0.5.0 → 0.6.1
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 +22 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -56,6 +56,25 @@ function parseArgs(args) {
|
|
|
56
56
|
}
|
|
57
57
|
return result;
|
|
58
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
|
+
}
|
|
59
78
|
/** Wrap a command so any failure is reported as a one-line error with a non-zero exit. */
|
|
60
79
|
function command(run) {
|
|
61
80
|
return async (...args) => {
|
|
@@ -92,6 +111,7 @@ cli
|
|
|
92
111
|
.description("Execute a program")
|
|
93
112
|
.option("--timeout <ms>", "Per-phase timeout in ms (applies to each run and repair attempt separately)")
|
|
94
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, [])
|
|
95
115
|
.action(command(async (name, opts) => {
|
|
96
116
|
let timeout;
|
|
97
117
|
if (opts.timeout !== undefined) {
|
|
@@ -101,8 +121,9 @@ cli
|
|
|
101
121
|
}
|
|
102
122
|
}
|
|
103
123
|
const args = parseArgs(opts.arg);
|
|
124
|
+
const budget = parseBudget(opts.budget);
|
|
104
125
|
const projectDir = resolveProject(name);
|
|
105
|
-
const result = await stoppable((signal) => runProgram({ projectDir, timeout, args, signal }));
|
|
126
|
+
const result = await stoppable((signal) => runProgram({ projectDir, timeout, args, budget, signal }));
|
|
106
127
|
// (A run that a signal stopped has failed, and is not reported as that: see `command`.)
|
|
107
128
|
if (result.status === "failed") {
|
|
108
129
|
throw new Error(`Program failed: ${result.reason}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trama-dev/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
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.1",
|
|
34
|
+
"@trama-dev/session": "0.6.1",
|
|
35
35
|
"commander": "15.1.0"
|
|
36
36
|
}
|
|
37
37
|
}
|