@parcha/agentrun 0.4.36 → 0.4.37
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 +9 -5
- package/lib/deploy.mjs +1 -1
- package/lib/follow.mjs +63 -3
- package/lib/race.mjs +6 -3
- package/package.json +3 -2
- package/skills/agentrun-cli/references/commands.md +1 -1
package/README.md
CHANGED
|
@@ -11,8 +11,10 @@ npx @parcha/agentrun
|
|
|
11
11
|
It starts [AgentRun Server](https://github.com/Parcha-ai/agentrun/tree/main/packages/serve) on the first free port from
|
|
12
12
|
7340 on this machine's loopback, keeps its data in `~/.agentrun`, prints the address the server says to open and opens
|
|
13
13
|
it in your browser (`--no-open`, a CI run or a machine with no display skips that). The server,
|
|
14
|
-
`@parcha/agentrun-serve`, is this package's
|
|
15
|
-
each version of this command runs the server it was released with.
|
|
14
|
+
`@parcha/agentrun-serve`, is this package's dependency at its exact version, so `npx` installs the two together and
|
|
15
|
+
each version of this command runs the server it was released with. Beside it, this package pins `@earendil-works/pi-ai`,
|
|
16
|
+
which the server takes as a peer, at the version the server is tested with, so `npx` installs one pi-ai and not the
|
|
17
|
+
newest one beside a copy of the tested one under each pi package. Node.js 24.22.3 or newer, on macOS or Linux; an older
|
|
16
18
|
Node gets one line naming that floor and the installer's command.
|
|
17
19
|
|
|
18
20
|
No Node.js on the machine, or an older one? The installer brings its own and keeps AgentRun running after the terminal
|
|
@@ -202,9 +204,11 @@ which would read the arguments again.
|
|
|
202
204
|
a run and does the same. Its exit code says how it stopped: 0 completed, 1 failed or cancelled, 8 it waits on a person
|
|
203
205
|
(a question, its spend cap, a stopped turn, a paused workflow run), with a line on stderr saying what to do next, such as
|
|
204
206
|
`runs message RUN_ID --content "..."` to answer. `--timeout SECONDS` stops waiting after that long and exits 1; the run
|
|
205
|
-
goes on. `runs timeline RUN_ID --follow` prints the timeline as it changes
|
|
206
|
-
|
|
207
|
-
|
|
207
|
+
goes on. `runs timeline RUN_ID --follow` prints the timeline as it changes. On a terminal it prints one line per row
|
|
208
|
+
(its time, kind and what it says, the run's text without control characters) and the run's status as it changes. Piped,
|
|
209
|
+
it prints one page per line (NDJSON): upsert its `rows` by `id`, delete its `drop` ids, and drop everything first on a
|
|
210
|
+
page with `reset: true`. It resumes a dropped connection where it left off and ends when the run ends, 0 completed, 1
|
|
211
|
+
failed or cancelled.
|
|
208
212
|
|
|
209
213
|
The TypeScript client for this server is `@parcha/agentrun-client` (packages/client), and the Python client is
|
|
210
214
|
`parcha-agentrun` (python/).
|
package/lib/deploy.mjs
CHANGED
|
@@ -44,7 +44,7 @@ export function packageSha256(files) {
|
|
|
44
44
|
return hash.digest("hex");
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
/** The server's manifest reader (its `manifest` export; the server is this package's
|
|
47
|
+
/** The server's manifest reader (its `manifest` export; the server is this package's dependency), so agent.md is
|
|
48
48
|
* read here as the target reads it. Loaded for a folder's deploy alone. */
|
|
49
49
|
async function serverManifest(fail) {
|
|
50
50
|
// Loaded here: start.mjs loads cli.mjs, which loads this module.
|
package/lib/follow.mjs
CHANGED
|
@@ -33,7 +33,7 @@ export const FLAGS = {
|
|
|
33
33
|
},
|
|
34
34
|
getTimeline: {
|
|
35
35
|
options: { follow: { type: "boolean" } },
|
|
36
|
-
help: [["--follow", "the timeline as it changes,
|
|
36
|
+
help: [["--follow", "the timeline as it changes, until the run ends; resumes a dropped connection. On a terminal one line per row, piped one page per line (NDJSON)"]],
|
|
37
37
|
},
|
|
38
38
|
};
|
|
39
39
|
|
|
@@ -202,6 +202,63 @@ async function* events(body, heard) {
|
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
+
/** The longest line `rowLine` prints, in characters; a longer one is cut and ends with an ellipsis. */
|
|
206
|
+
const LINE_MAX = 200;
|
|
207
|
+
/** Characters a row's text loses before it reaches a terminal: C0 and C1 controls (escape sequences among them), line
|
|
208
|
+
* and paragraph separators, and bidirectional overrides and isolates, each run of them one space. */
|
|
209
|
+
const UNPRINTABLE = /[\u0000-\u001f\u007f-\u009f\u2028\u2029\u202a-\u202e\u2066-\u2069]+/g;
|
|
210
|
+
/** A row's text made safe to print on one line: the run's text (a model's, a tool's, a person's) never moves the cursor
|
|
211
|
+
* or recolours the terminal. */
|
|
212
|
+
const printable = (text) => String(text).replace(UNPRINTABLE, " ").replace(/ {2,}/g, " ").trim();
|
|
213
|
+
/** Dollars to four places; `upper_bound` (a request counted at the most it could have cost) reads "at most". */
|
|
214
|
+
const money = (usd, upperBound) => `${upperBound === true ? "at most " : ""}$${usd.toFixed(4)}`;
|
|
215
|
+
|
|
216
|
+
/** A timeline row as one line for a person: its time (UTC, to the second), the subagent that wrote it when one did, its
|
|
217
|
+
* kind, and what it says. A tool call names its tool and input, a tool result its tool, `ok` or `failed`, and output, a
|
|
218
|
+
* usage row its dollars when priced ("at most" when that is an upper bound); any other row its summary, else its text. */
|
|
219
|
+
export function rowLine(row) {
|
|
220
|
+
const time = typeof row.timestamp === "string" && /T\d\d:\d\d:\d\d/.test(row.timestamp) ? row.timestamp.slice(11, 19) : "--:--:--";
|
|
221
|
+
const what =
|
|
222
|
+
row.kind === "tool_use"
|
|
223
|
+
? [row.tool_name, row.tool_input_preview]
|
|
224
|
+
: row.kind === "tool_result"
|
|
225
|
+
? [row.tool_name, row.tool_status === "success" ? "ok" : row.tool_status, row.tool_result_preview]
|
|
226
|
+
: row.kind === "usage" && typeof row.usage?.usd === "number"
|
|
227
|
+
? [money(row.usage.usd, row.usage.upper_bound), row.summary]
|
|
228
|
+
: [row.summary ?? row.text];
|
|
229
|
+
const parts = [row.agent_label && `[${row.agent_label}]`, row.kind, ...what].filter((part) => typeof part === "string" && part !== "").map(printable).filter(Boolean);
|
|
230
|
+
const line = `${time} ${parts.join(" ")}`;
|
|
231
|
+
return line.length > LINE_MAX ? `${line.slice(0, LINE_MAX - 1)}\u2026` : line;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** The run's status as a line for a person, and on the final page its cost when it has one ("at most" when the cost
|
|
235
|
+
* counts an interrupted request at the most it could have cost). */
|
|
236
|
+
const statusLine = (page) => {
|
|
237
|
+
const cost = page.final && typeof page.cost?.usd === "number" ? `, ${money(page.cost.usd, page.cost.upper_bound)} (${printable(page.cost.basis)})` : "";
|
|
238
|
+
return `${" ".repeat(8)} run ${printable(page.status ?? "unknown")}${cost}`;
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
/** `--follow`'s printer on a terminal: a row's line when the row comes and again only when its line changes (a row keeps
|
|
242
|
+
* its id when the server changes it), so a reconnect or a `reset` that sends rows again prints none of them twice; a
|
|
243
|
+
* dropped row stays on the screen, as anything printed does. */
|
|
244
|
+
function forPerson(stdout) {
|
|
245
|
+
const printed = new Map();
|
|
246
|
+
let said;
|
|
247
|
+
return (page) => {
|
|
248
|
+
for (const row of Array.isArray(page.rows) ? page.rows : []) {
|
|
249
|
+
if (!isObject(row)) continue;
|
|
250
|
+
const line = rowLine(row);
|
|
251
|
+
if (printed.get(row.id) === line) continue;
|
|
252
|
+
printed.set(row.id, line);
|
|
253
|
+
stdout.write(`${line}\n`);
|
|
254
|
+
}
|
|
255
|
+
if (page.status !== said || page.final) {
|
|
256
|
+
said = page.status;
|
|
257
|
+
stdout.write(`${statusLine(page)}\n`);
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
205
262
|
/** `runs timeline RUN_ID --follow`: the route's event stream, each `rows` event's page as one line of JSON on stdout, as
|
|
206
263
|
* the server sent it (its rows, its drops, `reset` when the rows held are to go first). A dropped connection, or the
|
|
207
264
|
* server's `end` with `reason: reconnect`, or a stream silent past three keepalives, reconnects with `Last-Event-ID`, so
|
|
@@ -209,9 +266,12 @@ async function* events(body, heard) {
|
|
|
209
266
|
* in a row, exit 3. It ends with the server's `end` with `reason: terminal`, which comes right after the first page with
|
|
210
267
|
* `final: true`: exit 0 when the run completed, 1 when it failed or was cancelled. A run that waits on a person keeps
|
|
211
268
|
* the stream open, as the server does. `path` is the route with its query (`after` is where it starts), and `headers`
|
|
212
|
-
* the command's (its `--last-event-id` wins over `after`, as the route says).
|
|
269
|
+
* the command's (its `--last-event-id` wins over `after`, as the route says). On a terminal it prints for a person
|
|
270
|
+
* instead: each row as one line (`rowLine`) when it comes and again when its line changes, and the run's status when it
|
|
271
|
+
* changes and on the final page. */
|
|
213
272
|
export async function followTimeline(client, path, headers = {}) {
|
|
214
273
|
const { "Last-Event-ID": from, ...rest } = headers;
|
|
274
|
+
const show = client.io.stdout.isTTY === true ? forPerson(client.io.stdout) : (page) => client.io.stdout.write(`${JSON.stringify(page)}\n`);
|
|
215
275
|
let reached = false;
|
|
216
276
|
let last = from;
|
|
217
277
|
let retryMs = 0;
|
|
@@ -243,7 +303,7 @@ export async function followTimeline(client, path, headers = {}) {
|
|
|
243
303
|
}
|
|
244
304
|
if (event === "rows") {
|
|
245
305
|
const page = json.value;
|
|
246
|
-
|
|
306
|
+
show(page);
|
|
247
307
|
status = page.status;
|
|
248
308
|
progress = true;
|
|
249
309
|
}
|
package/lib/race.mjs
CHANGED
|
@@ -88,7 +88,7 @@ async function call(cli, target, io, method, path, value, headers = {}) {
|
|
|
88
88
|
...cli.clientOf(target, io),
|
|
89
89
|
refused: (response, bytes) => {
|
|
90
90
|
const answer = parsed(bytes);
|
|
91
|
-
said = { status: response.status, code: answer?.error?.code ?? answer?.code ?? `http_${response.status}`, message: answer?.error?.message ?? answer?.message ?? `HTTP ${response.status}
|
|
91
|
+
said = { status: response.status, code: answer?.error?.code ?? answer?.code ?? `http_${response.status}`, message: answer?.error?.message ?? answer?.message ?? `HTTP ${response.status}`, reason: answer?.error?.details?.reason };
|
|
92
92
|
return 1;
|
|
93
93
|
},
|
|
94
94
|
};
|
|
@@ -252,10 +252,13 @@ export const RACE_START = {
|
|
|
252
252
|
const target = cli.targetOf(values, env);
|
|
253
253
|
// What a new agent gets here: the server's tools for each harness, where its default place is, and the runner's shell.
|
|
254
254
|
// Both are read before any lane starts, as the console's form waits for them: without the computers, a lane on the
|
|
255
|
-
// runner would start without the shell its runner runs.
|
|
255
|
+
// runner would start without the shell its runner runs. A server that does not serve its computers to a request in a
|
|
256
|
+
// workspace (403, reason not_scoped) runs no shell of its own for it: the lanes go on with none. Any other refusal of
|
|
257
|
+
// either read stops the race, in the server's words.
|
|
256
258
|
for (const path of ["/capabilities", "/computers"]) {
|
|
257
259
|
const read = await call(cli, target, io, "GET", path);
|
|
258
|
-
if (read.refused
|
|
260
|
+
if (path === "/computers" && read.refused?.status === 403 && read.refused.reason === "not_scoped") continue;
|
|
261
|
+
if (read.refused) throw cli.fail(1, `GET ${path}: ${read.refused.message.replace(/\.$/, "")}. No lane was started.`);
|
|
259
262
|
reads[path] = read.answer;
|
|
260
263
|
}
|
|
261
264
|
// Every lane at once, each on its own: one refused, or cut off, leaves the others started and every lane reported.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcha/agentrun",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.37",
|
|
4
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",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"NOTICE"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@
|
|
20
|
+
"@earendil-works/pi-ai": "1.5.2",
|
|
21
|
+
"@parcha/agentrun-serve": "0.1.0-beta.69"
|
|
21
22
|
},
|
|
22
23
|
"scripts": {
|
|
23
24
|
"test": "node --test 'test/*.test.mjs'"
|
|
@@ -1259,7 +1259,7 @@ Route: `GET /runs/{run_id}/timeline`.
|
|
|
1259
1259
|
- `--limit INTEGER` (integer): At most this many rows in a page (1 to 500, default 500; with `calls=whole`, 1 to 100, default 100); has_more says when another waits.
|
|
1260
1260
|
- `--calls whole` (string, one of these): `whole`: each `tool_use` row carries its call's arguments (`tool_input`) and each `tool_result` row its output whole to 120000 characters (`tool_result_text`; a web call's every url, only its long texts cut), both through the run's redaction, for a reader that grades the run (a template eval). Its rows are another page sequence: a cursor (`after`, `Last-Event-ID`) from one read goes with the same `calls`.
|
|
1261
1261
|
- `--last-event-id STRING` (string): SSE reconnect. Same meaning as `after`, and wins over it.
|
|
1262
|
-
- `--follow` (boolean, this CLI's own): the timeline as it changes,
|
|
1262
|
+
- `--follow` (boolean, this CLI's own): the timeline as it changes, until the run ends; resumes a dropped connection. On a terminal one line per row, piped one page per line (NDJSON)
|
|
1263
1263
|
|
|
1264
1264
|
### `agentrun runs trace RUN_ID`
|
|
1265
1265
|
|