@parcha/agentrun 0.3.6 → 0.4.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/README.md +13 -3
- package/lib/cli.mjs +202 -38
- package/lib/commands.generated.mjs +577 -61
- package/lib/follow.mjs +260 -0
- package/lib/login.mjs +208 -0
- package/lib/skill.mjs +88 -0
- package/lib/start.mjs +102 -14
- package/lib/template.mjs +75 -0
- package/package.json +5 -4
- package/skills/agentrun-cli/SKILL.md +138 -0
- package/skills/agentrun-cli/references/commands.md +793 -0
package/lib/start.mjs
CHANGED
|
@@ -27,27 +27,37 @@ export function openLineUrl(line, publicUrl) {
|
|
|
27
27
|
return publicUrl !== undefined && URL.canParse(publicUrl) && url.origin === new URL(publicUrl).origin ? word : undefined;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
/** The line an API-only server (AGENTRUN_API_ONLY=1) prints in place of its "Open " line: it has no console to open, so
|
|
31
|
+
* the address this command names is the server's API, from the AGENTRUN_BASE_URL line before it. */
|
|
32
|
+
export const API_ONLY_LINE = /^API only \(AGENTRUN_API_ONLY=1\)/;
|
|
33
|
+
|
|
30
34
|
/** How many of the server's last output lines a start that fails shows. */
|
|
31
35
|
export const TAIL_LINES = 20;
|
|
32
36
|
|
|
33
37
|
/** The server's lines this command says too, as they come: its banner's boxes line (whether new agents get the Docker
|
|
34
|
-
* box, or why not)
|
|
35
|
-
|
|
38
|
+
* box, or why not), the Docker box image's first build, as it starts and ends, and, on a server with a public address
|
|
39
|
+
* and no password yet, the setup link with its code, which setup at that address asks for. */
|
|
40
|
+
export const SAID = /^(Boxes: |Preparing the Docker box image |The Docker box image |Set up this server: )/;
|
|
36
41
|
|
|
37
42
|
/** The address a person opens first, as the server says it: the URL of the first "Open " line of its output that names
|
|
38
43
|
* one (openLineUrl). That line is the server's interface for it (the plain address today, a single-use sign-in link
|
|
39
|
-
* once the server prints one), so this command never builds the address itself.
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
|
|
44
|
+
* once the server prints one), so this command never builds the address itself. An API-only server prints no such line:
|
|
45
|
+
* its API-only line (API_ONLY_LINE) stands for it, and the address is its AGENTRUN_BASE_URL line's, held to the same
|
|
46
|
+
* hosts as an "Open " line's. Resolves undefined when the output ends
|
|
47
|
+
* without one. Until then, the last TAIL_LINES lines before it are kept in `seen`: what a start that fails shows, and each
|
|
48
|
+
* goes to `onBefore`. Every whole line after it goes to `onLine`; the rest of the output is read and dropped, so the
|
|
49
|
+
* server never blocks on a full pipe. */
|
|
50
|
+
export function openUrl(stdout, publicUrl, seen = [], onLine = () => {}, onBefore = () => {}) {
|
|
44
51
|
const keep = (line) => {
|
|
52
|
+
onBefore(line);
|
|
45
53
|
seen.push(line);
|
|
46
54
|
if (seen.length > TAIL_LINES) seen.shift();
|
|
47
55
|
};
|
|
48
56
|
return new Promise((resolve) => {
|
|
49
57
|
let pending = "";
|
|
50
58
|
let found;
|
|
59
|
+
// The API's address, from the banner's AGENTRUN_BASE_URL line: what an API-only server's line stands for.
|
|
60
|
+
let base;
|
|
51
61
|
stdout.setEncoding("utf8");
|
|
52
62
|
stdout.on("data", (chunk) => {
|
|
53
63
|
pending += chunk;
|
|
@@ -56,7 +66,12 @@ export function openUrl(stdout, publicUrl, seen = [], onLine = () => {}) {
|
|
|
56
66
|
pending = pending.slice(end + 1);
|
|
57
67
|
if (found !== undefined) onLine(line);
|
|
58
68
|
else if ((found = openLineUrl(line, publicUrl)) !== undefined) resolve(found);
|
|
59
|
-
else
|
|
69
|
+
else if (base !== undefined && API_ONLY_LINE.test(line)) resolve((found = base));
|
|
70
|
+
else {
|
|
71
|
+
const named = /^AGENTRUN_BASE_URL=(\S+)$/.exec(line)?.[1];
|
|
72
|
+
if (named !== undefined && openLineUrl(`Open ${named}`, publicUrl) !== undefined) base = named;
|
|
73
|
+
keep(line);
|
|
74
|
+
}
|
|
60
75
|
}
|
|
61
76
|
});
|
|
62
77
|
stdout.on("end", () => {
|
|
@@ -99,7 +114,7 @@ export function npmExecOf(env, from = process.ppid) {
|
|
|
99
114
|
}
|
|
100
115
|
|
|
101
116
|
export const USAGE = `Usage: npx @parcha/agentrun [--port N] [--data DIR] [--no-open] start the server
|
|
102
|
-
npx @parcha/agentrun import|reset-password [--data DIR] a server command
|
|
117
|
+
npx @parcha/agentrun import|reset-password|runner [--data DIR] a server command (runner: one more runner on this store)
|
|
103
118
|
npx @parcha/agentrun <command> [args] the server's API: agents, runs, triggers, ..., api (npx @parcha/agentrun help)`;
|
|
104
119
|
|
|
105
120
|
/** The server's launcher, installed with this package (its dependency), or undefined. */
|
|
@@ -115,8 +130,61 @@ export function installedServer(resolve = createRequire(import.meta.url).resolve
|
|
|
115
130
|
* --open, which itself skips a CI run and a machine with no display). */
|
|
116
131
|
export const serverArgs = (argv) => (argv.includes("--no-open") ? argv.filter((arg) => arg !== "--no-open") : ["--open", ...argv]);
|
|
117
132
|
|
|
133
|
+
/** The server's own commands (its CLI's first word), which this command runs on its store: every other first word is
|
|
134
|
+
* the CLI's, which names a command it has or says it has none. */
|
|
135
|
+
export const SERVER_COMMANDS = ["eval-template", "import", "reset-password", "runner", "validate-template"];
|
|
136
|
+
|
|
137
|
+
/** How many of the server's refusals and ignored deliveries a start says, each route and reason once, before one line
|
|
138
|
+
* that says the rest are not: under this command the server's log goes nowhere else (its stdout is read here and dropped). */
|
|
139
|
+
export const TOLD_MAX = 20;
|
|
140
|
+
|
|
141
|
+
/** Why a request was refused, in words, by the server's reason; any other reason is said as the server names it. */
|
|
142
|
+
const REFUSED = new Map([
|
|
143
|
+
["wrong_token", "the API token is not this server's"],
|
|
144
|
+
["no_credential", "it carried no API token"],
|
|
145
|
+
["wrong_password", "the password is wrong"],
|
|
146
|
+
["sign_in_table_full", "a sign-in from more addresses than the limit counts one by one"],
|
|
147
|
+
]);
|
|
148
|
+
|
|
149
|
+
/** The fields of one of the server's log lines (print.ts: `key=value` or `key="value"`); a repeated key keeps its first
|
|
150
|
+
* value, the line's own event. */
|
|
151
|
+
function fieldsOf(line) {
|
|
152
|
+
const fields = {};
|
|
153
|
+
for (const [, key, quoted, plain] of line.matchAll(/(?:^| )([\w-]+)=(?:"([^"]*)"|(\S+))/g)) if (!(key in fields)) fields[key] = quoted ?? plain;
|
|
154
|
+
return fields;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** A teller for one start: given a line of the server's output, what to say of it to the person, or undefined. A refused
|
|
158
|
+
* request (auth_failed) and a verified webhook delivery its trigger does not take (hook_ignored) are said in words, with
|
|
159
|
+
* their route and reason and never what was sent, each route and reason once, at most TOLD_MAX. With AGENTRUN_LOG=quiet,
|
|
160
|
+
* as this command starts the server, those lines are all an operator would otherwise miss. */
|
|
161
|
+
export function tellerOf() {
|
|
162
|
+
const said = new Set();
|
|
163
|
+
let full = false;
|
|
164
|
+
return (line) => {
|
|
165
|
+
const fields = fieldsOf(line);
|
|
166
|
+
let words;
|
|
167
|
+
let key;
|
|
168
|
+
if (fields.event === "auth_failed" && fields.route) {
|
|
169
|
+
key = `auth ${fields.route} ${fields.reason}`;
|
|
170
|
+
words = `AgentRun refused a request to ${fields.route}: ${REFUSED.get(fields.reason) ?? fields.reason}.`;
|
|
171
|
+
} else if (fields.event === "trigger" && fields.condition === "hook_ignored" && fields.route) {
|
|
172
|
+
const hookEvent = [...line.matchAll(/ event=(\S+)/g)][1]?.[1];
|
|
173
|
+
key = `hook ${fields.route} ${fields.reason}`;
|
|
174
|
+
words = `AgentRun ignored a webhook delivery to ${fields.route} (${fields.source}${hookEvent ? `, event ${hookEvent}` : ""}): ${fields.reason}.`;
|
|
175
|
+
} else return undefined;
|
|
176
|
+
if (said.has(key) || full) return undefined;
|
|
177
|
+
if (said.size >= TOLD_MAX) return (full = true), "AgentRun refuses more requests than this terminal shows; it says no more of them here.";
|
|
178
|
+
said.add(key);
|
|
179
|
+
return said.size === 1 ? `${words} (Each route and reason is said once.)` : words;
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
118
183
|
export async function main(argv, env = process.env) {
|
|
119
|
-
|
|
184
|
+
// The first argument, past --data and its value: a word there names a command (the server's own, or else the CLI's),
|
|
185
|
+
// and a flag starts the server, whose flags with values (--listen ADDR) follow.
|
|
186
|
+
const first = argv.find((arg, i) => arg !== "--data" && !arg.startsWith("--data=") && argv[i - 1] !== "--data");
|
|
187
|
+
if (NOUNS.has(words(argv)[0]) || (first !== undefined && !first.startsWith("-") && !SERVER_COMMANDS.includes(first))) return cli(argv, env);
|
|
120
188
|
if (argv.includes("--help") || argv.includes("-h")) return console.log(USAGE), 0;
|
|
121
189
|
if (process.platform === "win32") return console.error("AgentRun's server runs on macOS and Linux; on Windows, use WSL or its container."), 1;
|
|
122
190
|
const launcher = installedServer();
|
|
@@ -144,7 +212,21 @@ export async function main(argv, env = process.env) {
|
|
|
144
212
|
// A name that starts with a dash keeps the equals form: the server's parser reads "--data -x" as a missing value.
|
|
145
213
|
const data = dataDir.startsWith("-") ? [`--data=${dataDir}`] : ["--data", dataDir];
|
|
146
214
|
if (rest[0] && !rest[0].startsWith("-")) {
|
|
147
|
-
|
|
215
|
+
// A server command (an eval among them, which spends while it runs): a stop sent to this command alone (a job
|
|
216
|
+
// runner's SIGTERM, a SIGHUP) is passed on, and this waits for the command to clean up and end. A hangup is passed
|
|
217
|
+
// on as a SIGTERM, which every server command stops on.
|
|
218
|
+
const child = spawn(launcher, [rest[0], ...data, ...rest.slice(1)], { stdio: "inherit", env: childEnv });
|
|
219
|
+
const codes = { SIGINT: 130, SIGTERM: 143, SIGHUP: 129 };
|
|
220
|
+
const pass = Object.fromEntries(Object.keys(codes).map((signal) => [signal, () => child.kill(signal === "SIGHUP" ? "SIGTERM" : signal)]));
|
|
221
|
+
for (const [signal, on] of Object.entries(pass)) process.on(signal, on);
|
|
222
|
+
return new Promise((resolve) => {
|
|
223
|
+
const done = (code) => {
|
|
224
|
+
for (const [signal, on] of Object.entries(pass)) process.off(signal, on);
|
|
225
|
+
resolve(code);
|
|
226
|
+
};
|
|
227
|
+
child.on("error", () => done(1));
|
|
228
|
+
child.on("exit", (code, signal) => done(code ?? codes[signal] ?? 1));
|
|
229
|
+
});
|
|
148
230
|
}
|
|
149
231
|
// The server's banner and request lines stay out of this terminal: one line here says where to go, the URL of the
|
|
150
232
|
// server's own "Open " line; the lines SAID names go to stderr after it, for the person, so stdout stays that one line.
|
|
@@ -175,14 +257,20 @@ export async function main(argv, env = process.env) {
|
|
|
175
257
|
let timer;
|
|
176
258
|
let told = false;
|
|
177
259
|
const held = [];
|
|
178
|
-
const
|
|
260
|
+
const teller = tellerOf();
|
|
261
|
+
const tell = (line) => {
|
|
262
|
+
const said = SAID.test(line) ? line : teller(line);
|
|
263
|
+
if (said !== undefined) told ? console.error(said) : held.push(said);
|
|
264
|
+
};
|
|
265
|
+
// A SAID line can come before the "Open " line too (the setup link is printed as the server attaches its owner, before
|
|
266
|
+
// its banner): it is held and said first, in order.
|
|
179
267
|
const seen = [];
|
|
180
|
-
const url = await Promise.race([openUrl(child.stdout, env.AGENTRUN_PUBLIC_URL, seen, tell), new Promise((resolve) => { timer = setTimeout(resolve, 60_000); })]);
|
|
268
|
+
const url = await Promise.race([openUrl(child.stdout, env.AGENTRUN_PUBLIC_URL, seen, tell, tell), new Promise((resolve) => { timer = setTimeout(resolve, 60_000); })]);
|
|
181
269
|
clearTimeout(timer);
|
|
182
270
|
if (url === undefined) {
|
|
183
271
|
child.kill("SIGTERM");
|
|
184
272
|
// Its stdout is kept out of this terminal, so its last lines are shown here: with its stderr above, they say why.
|
|
185
|
-
console.error(seen.length > 0 ? `AgentRun did not start. The server's last lines:\n${seen.map((line) => ` ${line}`).join("\n")}` : "AgentRun did not start
|
|
273
|
+
console.error(seen.length > 0 ? `AgentRun did not start. The server's last lines:\n${seen.map((line) => ` ${line}`).join("\n")}` : "AgentRun did not start; the server's own message, if it gave one, is above.");
|
|
186
274
|
return (await exited) || 1;
|
|
187
275
|
}
|
|
188
276
|
console.log(`AgentRun is running at ${url}`);
|
package/lib/template.mjs
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// `agentrun template validate DIR`: a template package folder checked on this machine by the server's own validator,
|
|
2
|
+
// the one a server runs on the packages it ships at its start. The server installed with this command checks it
|
|
3
|
+
// (agentrun-serve validate-template), as it runs import and reset-password: this command reaches the server through its
|
|
4
|
+
// launcher and its API alone. Nothing in the package runs.
|
|
5
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
6
|
+
import { resolve } from "node:path";
|
|
7
|
+
|
|
8
|
+
export const TEMPLATE_VALIDATE = {
|
|
9
|
+
command: ["template", "validate"],
|
|
10
|
+
pathParams: ["dir"],
|
|
11
|
+
summary: "Check a template package folder (agent.md, skills/, rules/, evals/) as a server does before it applies one",
|
|
12
|
+
help: [["DIR", "the package's folder: its name is the package's name. Prints what it holds, or each problem (exit 1)"]],
|
|
13
|
+
options: {},
|
|
14
|
+
async run({ args, cli }) {
|
|
15
|
+
// Loaded here: start.mjs loads cli.mjs, which loads this module.
|
|
16
|
+
const { installedServer } = await import("./start.mjs");
|
|
17
|
+
const launcher = installedServer();
|
|
18
|
+
if (launcher === undefined) throw cli.fail(2, "AgentRun's server is not installed beside this command, and it is the server that checks a package.");
|
|
19
|
+
return spawnSync(launcher, ["validate-template", resolve(args[0])], { stdio: "inherit" }).status ?? 1;
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// `agentrun template eval DIR`: the package's eval cases run as real runs of its agent and graded (agentrun-serve
|
|
24
|
+
// eval-template, templates/README.md "Running the evals"), on a server the command starts in its own process over a temp
|
|
25
|
+
// data directory, or with --server on that one, its token found as every other command finds it (AGENTRUN_API_KEY, the
|
|
26
|
+
// CLI's config, or the data directory's .token for the server on this machine) and handed to the server's launcher in
|
|
27
|
+
// AGENTRUN_API_KEY, which moves it to a pipe: never in an argument, never printed. Its exit is the eval's: 0 every case
|
|
28
|
+
// passed, 1 one failed, 2 nothing ran (the flags, the package or a case are wrong).
|
|
29
|
+
export const TEMPLATE_EVAL = {
|
|
30
|
+
command: ["template", "eval"],
|
|
31
|
+
pathParams: ["dir"],
|
|
32
|
+
summary: "Run a template package's eval cases as real runs of its agent and grade each run (real models cost money)",
|
|
33
|
+
help: [
|
|
34
|
+
["DIR", "the package's folder"],
|
|
35
|
+
["--case NAME", "a case to run (repeat it); without one, every case"],
|
|
36
|
+
["--runs N", "how many runs of each case, in place of each case's own runs"],
|
|
37
|
+
["--server URL", "run on that server, with its token (AGENTRUN_API_KEY), instead of on a server of its own over a temp data directory"],
|
|
38
|
+
["--grader-model PROVIDER/MODEL", "the model of the llm graders (default: the server's)"],
|
|
39
|
+
["--report FILE", "the whole report, as JSON (a summary goes to stdout either way)"],
|
|
40
|
+
["--faux MODULE", "answer every model request from MODULE's default export: no key, no network"],
|
|
41
|
+
],
|
|
42
|
+
options: { case: { type: "string", multiple: true }, runs: { type: "string" }, server: { type: "string" }, "grader-model": { type: "string" }, report: { type: "string" }, faux: { type: "string" } },
|
|
43
|
+
async run({ values, args, env, cli }) {
|
|
44
|
+
const { installedServer } = await import("./start.mjs");
|
|
45
|
+
const launcher = installedServer();
|
|
46
|
+
if (launcher === undefined) throw cli.fail(2, "AgentRun's server is not installed beside this command, and it is the server that runs an eval.");
|
|
47
|
+
const argv = ["eval-template", resolve(args[0])];
|
|
48
|
+
for (const name of values.case ?? []) argv.push("--case", name);
|
|
49
|
+
if (values.runs !== undefined) argv.push("--runs", values.runs);
|
|
50
|
+
if (values["grader-model"] !== undefined) argv.push("--grader-model", values["grader-model"]);
|
|
51
|
+
if (values.report !== undefined) argv.push("--report", resolve(values.report));
|
|
52
|
+
if (values.faux !== undefined) argv.push("--faux", resolve(values.faux));
|
|
53
|
+
let childEnv = env;
|
|
54
|
+
if (values.server !== undefined) {
|
|
55
|
+
const { base, token } = cli.targetOf({ ...values, "base-url": values.server }, env);
|
|
56
|
+
argv.push("--server", base);
|
|
57
|
+
childEnv = { ...env, AGENTRUN_API_KEY: token };
|
|
58
|
+
}
|
|
59
|
+
// A stop sent to this command alone (a job runner's SIGTERM, a SIGHUP) is passed on to the eval, which cancels its
|
|
60
|
+
// run and cleans up before it exits, as it does on the Ctrl-C a terminal sends both: this command waits for that.
|
|
61
|
+
const child = spawn(launcher, argv, { stdio: "inherit", env: childEnv });
|
|
62
|
+
const signals = { SIGINT: 130, SIGTERM: 143, SIGHUP: 129 };
|
|
63
|
+
// The eval stops on SIGINT and SIGTERM; a hangup is passed on as a SIGTERM, which it cleans up after.
|
|
64
|
+
const pass = Object.fromEntries(Object.keys(signals).map((signal) => [signal, () => child.kill(signal === "SIGHUP" ? "SIGTERM" : signal)]));
|
|
65
|
+
for (const [signal, on] of Object.entries(pass)) process.on(signal, on);
|
|
66
|
+
try {
|
|
67
|
+
return await new Promise((done) => {
|
|
68
|
+
child.on("error", () => done(1));
|
|
69
|
+
child.on("exit", (code, signal) => done(code ?? signals[signal] ?? 1));
|
|
70
|
+
});
|
|
71
|
+
} finally {
|
|
72
|
+
for (const [signal, on] of Object.entries(pass)) process.off(signal, on);
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcha/agentrun",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.4.1",
|
|
4
|
+
"description": "AgentRun, the open-source platform that supercharges your agents (self-improvement, durable execution and a control plane on top of your favorite agent harness), on this machine with one command: npx @parcha/agentrun",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"bin": {
|
|
@@ -10,18 +10,19 @@
|
|
|
10
10
|
"files": [
|
|
11
11
|
"bin",
|
|
12
12
|
"lib",
|
|
13
|
+
"skills",
|
|
13
14
|
"README.md",
|
|
14
15
|
"LICENSE",
|
|
15
16
|
"NOTICE"
|
|
16
17
|
],
|
|
17
18
|
"dependencies": {
|
|
18
|
-
"@parcha/agentrun-serve": "0.1.0-beta.
|
|
19
|
+
"@parcha/agentrun-serve": "0.1.0-beta.33"
|
|
19
20
|
},
|
|
20
21
|
"scripts": {
|
|
21
22
|
"test": "node --test 'test/*.test.mjs'"
|
|
22
23
|
},
|
|
23
24
|
"engines": {
|
|
24
|
-
"node": ">=
|
|
25
|
+
"node": ">=24.11.0"
|
|
25
26
|
},
|
|
26
27
|
"repository": {
|
|
27
28
|
"type": "git",
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: agentrun-cli
|
|
3
|
+
description: Drive an AgentRun server from a shell with the agentrun CLI. Make an agent from a definition file, start a run with a spend cap and wait for it, answer a run that asks a question, read the files it wrote and what it cost, save tool keys, and call any other route of the server. Use when asked to run or manage AgentRun agents from the terminal or a script, or for anything the server's MCP tools do not cover (files, tool keys, triggers, webhooks, revisions, learning).
|
|
4
|
+
---
|
|
5
|
+
<!-- Generated by scripts/generate-clients.mjs from the server's OpenAPI document and its skill template. Do not edit: run node scripts/generate-clients.mjs. -->
|
|
6
|
+
<!-- SHA-256 of what the command table is made of (operationsOf in scripts/generate-clients.mjs): e6a39ba1ef14ca4138503e3dd9e66e9bebd6d9beb91fad5fbfec0a38296841d8 -->
|
|
7
|
+
|
|
8
|
+
# AgentRun CLI
|
|
9
|
+
|
|
10
|
+
`agentrun` drives an AgentRun server (the open platform's server for agents) through its API. It is the command `npm install -g @parcha/agentrun` puts on the PATH; without it, write `npx @parcha/agentrun` in its place. Each command prints the server's JSON answer on stdout, one line when piped, and an error's JSON on stderr. `agentrun help` lists the commands, `agentrun GROUP COMMAND --help` gives one's flags, and [references/commands.md](references/commands.md) has every command with its flags and route.
|
|
11
|
+
|
|
12
|
+
## The server and the token
|
|
13
|
+
|
|
14
|
+
The first of these that is set wins:
|
|
15
|
+
|
|
16
|
+
1. `--base-url URL` (the API, ending `/v2`), else `AGENTRUN_BASE_URL`, with the token in `AGENTRUN_API_KEY`.
|
|
17
|
+
2. The config file `$XDG_CONFIG_HOME/agentrun/config.json` (else `~/.config/agentrun/config.json`), written by `agentrun login`, which checks the token first. The CLI refuses the file if anyone else can read it.
|
|
18
|
+
3. The server started on this machine with `npx @parcha/agentrun`, whose data directory (`~/.agentrun`, or `--data DIR`) says where it listens and holds its token: nothing to set.
|
|
19
|
+
|
|
20
|
+
The token goes on stdin, never on the command line:
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
agentrun login --base-url "$AGENTRUN_BASE_URL" < token.txt
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Never print, echo or log the token, and never pass it as an argument; the CLI never prints it. `agentrun logout` removes the config file. Keys and other secrets are set in the console, signed in: the token can't write one, so no command does (`agentrun tool-keys list` names the keys and fields, and whether each is set, never a value).
|
|
27
|
+
|
|
28
|
+
## Recipes
|
|
29
|
+
|
|
30
|
+
Run them in order, in one working directory: each writes `out.json`, the run as its command printed it, and the next reads it. The last line of each block says how its last command exits.
|
|
31
|
+
|
|
32
|
+
### 1. Make an agent from a definition file
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
cat > agent.json <<'EOF'
|
|
36
|
+
{"definition": {"id": "notes", "version": 1, "name": "Notes", "instructions": "Do what you are asked, and write what you make to a file.", "skills": [], "tools": ["write", "ask_person"]}}
|
|
37
|
+
EOF
|
|
38
|
+
agentrun agents create --body @agent.json
|
|
39
|
+
# exit 0: the agent; exit 1 with error.code agent_exists: agentrun agents update notes --body @agent.json makes its next revision
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Ask the person before you create or change an agent. `agentrun server capabilities` lists the harnesses, models and tools this server has.
|
|
43
|
+
|
|
44
|
+
### 2. Start a run with a spend cap and wait for it
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
agentrun runs start notes --max-cost-usd 5 --body '{"input": {"content": "Write notes.md with three facts about the Moon."}}' --wait > out.json
|
|
48
|
+
# exit 0 completed (result.final_answer); 1 failed or cancelled (error says why); 8 it waits on a person (recipe 3)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
`--wait` follows the run until it ends or needs a person, and `--timeout SECONDS` stops waiting (exit 1, the run goes on). `agentrun runs wait RUN_ID` waits again; `agentrun runs timeline RUN_ID --follow` prints each step as it comes.
|
|
52
|
+
|
|
53
|
+
### 3. Answer a run that asks
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
agentrun runs start notes --max-cost-usd 5 --body '{"input": {"content": "Ask me which region to cover, then write region.md about it."}}' --wait > out.json
|
|
57
|
+
# exit 8: it waits on a person; out.json has pending.kind question and pending.question, what it asks
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Answer only what the person told you, or ask them. Then:
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
run=$(node -p 'require("./out.json").run_id')
|
|
64
|
+
agentrun runs message "$run" --content "Europe"
|
|
65
|
+
agentrun runs wait "$run" > out.json
|
|
66
|
+
# exit 0 completed, as in recipe 2
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 4. Read what it wrote and what it cost
|
|
70
|
+
|
|
71
|
+
```sh
|
|
72
|
+
run=$(node -p 'require("./out.json").run_id')
|
|
73
|
+
agentrun runs files "$run"
|
|
74
|
+
agentrun runs read-file "$run" region.md
|
|
75
|
+
agentrun runs get "$run" > out.json && node -p 'JSON.stringify(require("./out.json").cost)'
|
|
76
|
+
# exit 0: files lists each path, read-file prints one file, cost.usd is what it spent and cap_usd its cap
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`cost.usd` is null while the cost is unknown: never report it as $0. Tell the person the outcome and give them the run's `console_url`.
|
|
80
|
+
|
|
81
|
+
### 5. Raise a cap or approve a call
|
|
82
|
+
|
|
83
|
+
A run stopped at its spend cap, or waiting for a tool call to be approved, exits 8 with `pending.kind` `budget` or `approval` in out.json.
|
|
84
|
+
|
|
85
|
+
A cap too small for the task stops the run before a request it cannot pay for. With `--cap-mode strict` no request is sent that the cap cannot cover; under the default, `expected`, a request that misses the cache can go over by at most the run's `cost.overshoot_bound_usd`:
|
|
86
|
+
|
|
87
|
+
```sh
|
|
88
|
+
agentrun runs start notes --max-cost-usd 0.05 --cap-mode strict --body '{"input": {"content": "Write moon.md with everything known about the Moon."}}' --wait > out.json
|
|
89
|
+
# exit 8 once it stops at its cap: out.json has pending.kind budget, with cap_usd, spent_usd and suggested_cap_usd; 0 if the cap was enough
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Only the person who set the cap raises it: ask them for the new cap (`pending.suggested_cap_usd` is one that lets it go on). Then the run goes on from where it stopped:
|
|
93
|
+
|
|
94
|
+
```sh
|
|
95
|
+
run=$(node -p 'require("./out.json").run_id')
|
|
96
|
+
agentrun runs raise-cap "$run" --max-cost-usd 1
|
|
97
|
+
agentrun runs wait "$run" > out.json
|
|
98
|
+
# exit 0 completed, as in recipe 2
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
A tool call waiting for approval (`pending.kind` `approval`) is answered by the person in the console (the run's `console_url`): the server takes that answer only from their own session there, never from a token, so the CLI has no command for it. Tell them, then `agentrun runs wait "$run"` once they have.
|
|
102
|
+
|
|
103
|
+
## Exit codes
|
|
104
|
+
|
|
105
|
+
- 0: done; for `runs wait` and `runs start --wait`, the run completed.
|
|
106
|
+
- 1: the server refused (its error JSON on stderr); for a wait, the run failed or was cancelled, or `--timeout` passed.
|
|
107
|
+
- 2: bad usage, nothing sent: a bad flag or argument, or a base URL that is not http or https or has a query, a fragment, a user or a password.
|
|
108
|
+
- 3: the server cannot be reached.
|
|
109
|
+
- 4: no token, the token was refused, or the config file, the local server's record or its token file was refused (open to others, or not what it should hold).
|
|
110
|
+
- 8: the run waits on a person: a question, its spend cap, a stopped turn, or a paused workflow. stderr says what to run next.
|
|
111
|
+
|
|
112
|
+
## From a program
|
|
113
|
+
|
|
114
|
+
Two clients call the same API from code, with the same server and token. `@parcha/agentrun-client` is the TypeScript one, `new AgentRun({ baseUrl, apiKey })`; `npm install @parcha/agentrun-client` installs it. `parcha-agentrun` (python/) is the Python one, `AgentRun(base_url=..., api_key=...)` from the `agentrun` module; `pip install parcha-agentrun` installs it. Both default to `AGENTRUN_BASE_URL` and `AGENTRUN_API_KEY` and read no config file. Each command here is a method, grouped the same way: `agentrun runs start` is `client.runs.start`, and `client.runs.wait` and `client.runs.follow` do what `--wait` and `--follow` do.
|
|
115
|
+
|
|
116
|
+
## Commands
|
|
117
|
+
|
|
118
|
+
- `agentrun agents`: archive, create, forget-sign-in, get, list, runs, unarchive, update
|
|
119
|
+
- `agentrun files`: create, delete, get, list, upload
|
|
120
|
+
- `agentrun home`: delete, list, read, write
|
|
121
|
+
- `agentrun learning`: get, log, notes, read, retire, write
|
|
122
|
+
- `agentrun local`: connect-git-hub, delete-workspace-archil, disconnect-git-hub, get-git-hub-connection, get-workspace-archil, git-hub-callback, git-hub-installed, list-computers, receive-hook-github, test-computer, test-workspace-archil
|
|
123
|
+
- `agentrun login`: Check a server's token, read from stdin, and keep it with the server's address in the config file
|
|
124
|
+
- `agentrun logout`: Remove the config file login wrote, its address and token
|
|
125
|
+
- `agentrun mcp-servers`: delete, get, list, oauth-client, private-hosts, refresh
|
|
126
|
+
- `agentrun revisions`: list, set-current
|
|
127
|
+
- `agentrun runs`: archive, cancel, create-inline-run, files, get, graph, hand-back-run-computer, learning, learning-diff, list, message, pause, raise-cap, read-file, resume, start, stop, take-over-run-computer, timeline, unarchive, wait
|
|
128
|
+
- `agentrun server`: capabilities, health, mcp, openapi
|
|
129
|
+
- `agentrun skill`: install
|
|
130
|
+
- `agentrun stats`: Counts and cost over every agent and run
|
|
131
|
+
- `agentrun template`: apply, eval, list, validate
|
|
132
|
+
- `agentrun tool-keys`: list
|
|
133
|
+
- `agentrun tool-settings`: get, save
|
|
134
|
+
- `agentrun triggers`: create, delete, fire, firings, get, list, rotate-secret, update
|
|
135
|
+
- `agentrun usage`: Usage by meter over a period
|
|
136
|
+
- `agentrun webhook`: delete, deliveries, get, redeliver, save, test
|
|
137
|
+
- `agentrun workflows`: validate
|
|
138
|
+
- `agentrun api METHOD PATH [--body JSON|@FILE|-]`: any route, PATH under the base URL
|