@parcha/agentrun 0.4.25 → 0.4.26

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/lib/cli.mjs CHANGED
@@ -165,8 +165,21 @@ function baseOf(given, where) {
165
165
 
166
166
  const isBase = (url) => checkedBase(url) !== undefined;
167
167
 
168
+ /** The token of the server on this machine whose data directory is `data` and whose record is `record`: one started with
169
+ * its token in AGENTRUN_TOKEN (its record names no token file) takes AGENTRUN_API_KEY, else AGENTRUN_TOKEN, and is
170
+ * refused (exit 4) when neither is set; else the directory's private .token. Undefined when that file is not there.
171
+ * Every command (targetOf) and the doctor read it so. */
172
+ function localToken({ data, record, env }) {
173
+ if (record && !record.token_file) {
174
+ const token = env.AGENTRUN_API_KEY || env.AGENTRUN_TOKEN;
175
+ if (!token) throw new Exit(4, `The server recorded in ${join(data, ".server.json")} was started with its token in AGENTRUN_TOKEN; set AGENTRUN_API_KEY (or AGENTRUN_TOKEN) to it.`);
176
+ return token;
177
+ }
178
+ return privateFile(join(data, ".token"))?.trim() || undefined;
179
+ }
180
+
168
181
  /** Where the request goes and the token it carries. A token goes only with the address it came with: the local
169
- * server's own token is never sent to another server. The local token is DIR/.token, whatever the record says. */
182
+ * server's own token is never sent to another server. The local token is localToken's. */
170
183
  function targetOf(values, env) {
171
184
  const data = resolve(values.data ?? join(homedir(), ".agentrun"));
172
185
  const configFile = join(env.XDG_CONFIG_HOME || join(homedir(), ".config"), "agentrun", "config.json");
@@ -191,14 +204,9 @@ function targetOf(values, env) {
191
204
  let token = env.AGENTRUN_API_KEY || (config.base_url && base === apiBase(config.base_url) ? config.api_key : undefined);
192
205
  const isLocal = base === local;
193
206
  if (isLocal && record && !alive(record.pid)) throw new Exit(3, stale);
194
- if (!token && isLocal) {
195
- // A server started with its token in AGENTRUN_TOKEN (no .token file): the variable is that server's token, and only
196
- // here, on its own address, is it sent; another address takes AGENTRUN_API_KEY or the token kept for it.
197
- if (record && !record.token_file) {
198
- token = env.AGENTRUN_TOKEN;
199
- if (!token) throw new Exit(4, `The server recorded in ${recordFile} was started with its token in AGENTRUN_TOKEN; set AGENTRUN_API_KEY (or AGENTRUN_TOKEN) to it.`);
200
- } else token = privateFile(join(data, ".token"))?.trim();
201
- }
207
+ // Only here, on the local server's own address, is AGENTRUN_TOKEN sent; another address takes AGENTRUN_API_KEY or the
208
+ // token kept for it.
209
+ if (!token && isLocal) token = localToken({ data, record, env });
202
210
  if (!token) {
203
211
  throw new Exit(4, isLocal
204
212
  ? `No token: AGENTRUN_API_KEY is not set and ${join(data, ".token")} does not exist; ${START}.`
@@ -521,7 +529,7 @@ async function local(entry, argv, env, io) {
521
529
  const count = entry.pathParams.length;
522
530
  // An entry whose arguments a flag can stand in for (`harness install --recipe FILE`) takes none too; its run checks.
523
531
  if (args.length !== count && !(entry.argsOptional && args.length === 0)) throw usageError(`${helpOf(entry, entry.help)}\n\n${usageOf(entry)} takes ${count || "no"} argument${count === 1 ? "" : "s"}, given ${args.length}.`);
524
- const cli = { fail: (code, message) => new Exit(code, message), baseOf, targetOf, clientOf, request, privateFile, alive, BAD_HEADER };
532
+ const cli = { fail: (code, message) => new Exit(code, message), baseOf, targetOf, localToken, clientOf, request, privateFile, alive, BAD_HEADER };
525
533
  return entry.run({ values, args, env, io, cli });
526
534
  }
527
535
 
@@ -3439,6 +3439,12 @@ export const COMMANDS = [
3439
3439
  "type": "string",
3440
3440
  "required": false,
3441
3441
  "description": "Only runs holding this label: `<key>:<value>`, split at the first `:` (a key holds none). Once per request; a second `label`, or one that does not read as a label, is 400."
3442
+ },
3443
+ {
3444
+ "name": "source",
3445
+ "type": "string",
3446
+ "required": false,
3447
+ "description": "Only runs imported from this source, a source's name as the run's `imported_from.source` holds it (`claude-code`, `codex`, ...), or `live` for the runs made here, not imported. A name no run holds lists none. Once per request; a second `source`, or one that does not read as a name, is 400."
3442
3448
  }
3443
3449
  ],
3444
3450
  "headers": [],
package/lib/deploy.mjs CHANGED
@@ -9,12 +9,10 @@
9
9
  // refused unless --force. `deploy rollback` makes the agent's previous revision current; `deploy delete` deletes the
10
10
  // agent there and the lock here. Exit codes: 0 done or up to date, 2 refused (bad input, a link in the folder, edited on
11
11
  // the target, not confirmed), 3 not runnable yet (keys or MCP servers the target lacks: nothing is made, the setup page
12
- // printed when the target gives one), 1 the target refused otherwise or could not be reached, 4 no token for it, 5 an
13
- // operation the target does not offer.
14
- import { spawnSync } from "node:child_process";
12
+ // printed when the target gives one), 1 the target refused otherwise or could not be reached, or deployed but
13
+ // --pause-source left a schedule on, 4 no token for it, 5 an operation the target does not offer.
15
14
  import { createHash } from "node:crypto";
16
15
  import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, rmdirSync, statSync, writeFileSync } from "node:fs";
17
- import { createRequire } from "node:module";
18
16
  import { homedir, hostname } from "node:os";
19
17
  import { dirname, join, resolve } from "node:path";
20
18
  import { createInterface } from "node:readline/promises";
@@ -58,29 +56,6 @@ async function serverManifest(fail) {
58
56
  }
59
57
  }
60
58
 
61
- /** The package checked as the target's import checks it, before anything is sent: the server installed beside this
62
- * command runs the import's own check (its `check-upload` command, template-import.ts checkUpload) on the body this
63
- * deploy is about to send. A package the target would refuse (a category it has not, an answer's schema it would not
64
- * read, a file over its limits) exits 2 here, in the target's words, with no request made. The check runs in a process
65
- * of its own, started as this node on the server's cli.js, never through its shell launcher, which runs nowhere without
66
- * a POSIX shell: loading the server here would take every key out of this command's environment (secrets.ts), the
67
- * target's token among them. */
68
- async function checkedHere(files, fail) {
69
- // Loaded here: start.mjs loads cli.mjs, which loads this module.
70
- const { SERVE_PACKAGE } = await import("./start.mjs");
71
- let cli;
72
- try {
73
- cli = join(dirname(createRequire(import.meta.url).resolve(`${SERVE_PACKAGE}/package.json`)), "dist", "cli.js");
74
- } catch {
75
- throw fail(2, `AgentRun's server (${SERVE_PACKAGE}) is not installed beside this command, and it is the server's import that checks a package: nothing was sent.`);
76
- }
77
- const checked = spawnSync(process.execPath, [cli, "check-upload"], { input: JSON.stringify({ files: filesBody(files) }), encoding: "utf8", maxBuffer: 4 * MAX_BYTES, windowsHide: true });
78
- if (checked.status === 0) return;
79
- const reasons = (checked.stderr ?? "").trim().split("\n").filter(Boolean);
80
- if (checked.status === 1 && reasons.length) throw fail(2, `The package does not check, so nothing was sent: ${reasons.join("; ")}`);
81
- throw fail(2, `The server beside this command could not check the package (${checked.error?.code ?? `exit ${checked.status ?? checked.signal}`}): nothing was sent.`);
82
- }
83
-
84
59
  /** The answer's schema file agent.md names (`output: {schema}`) when it is a file at the package's root other than
85
60
  * agent.md. One under skills/, rules/ or evals/ goes with its tree, and the target takes no other folder. None when
86
61
  * the manifest names none or does not parse: the target refuses it then, in its own words. */
@@ -92,10 +67,10 @@ function rootSchemaOf(manifest, manifestOf) {
92
67
 
93
68
  /** A folder's package by path, each file its bytes: agent.md, the skills/, rules/ and evals/ trees, and the answer's
94
69
  * schema file the manifest names at the root. Nothing else of the folder is sent (a .env, a key, a README, another
95
- * folder), nor a hidden file or folder inside the trees. Each hidden path left out, at the top or in a tree, is said by
96
- * name before anything is sent (a hidden folder once, never what it holds; this CLI's own .agentrun/ is not said). No
97
- * agent.md, a symbolic link, or anything that is neither a file nor a folder refuses the deploy with nothing sent. */
98
- async function readFolder(dir, fail, io) {
70
+ * folder), nor a hidden file or folder inside the trees: `hidden` names each one left out, at the top or in a tree (a
71
+ * hidden folder once, never what it holds; this CLI's own .agentrun/ is not named). No agent.md, a symbolic link, or
72
+ * anything that is neither a file nor a folder refuses the deploy with nothing sent. */
73
+ async function readFolder(dir, fail) {
99
74
  const files = new Map();
100
75
  const hidden = [];
101
76
  const leftOut = (rel, entry) => hidden.push(`${rel}${entry.isDirectory() ? "/" : ""}`);
@@ -136,8 +111,7 @@ async function readFolder(dir, fail, io) {
136
111
  const entry = schema === undefined ? undefined : entryOf(schema);
137
112
  if (entry && !entry.isDirectory()) take(schema, entry);
138
113
  for (const one of readdirSync(dir, { withFileTypes: true })) if (one.name.startsWith(".") && one.name !== LOCK_DIR) leftOut(one.name, one);
139
- if (hidden.length) say(io, `Left out, hidden: ${hidden.sort().join(", ")}`);
140
- return files;
114
+ return { files, hidden: hidden.sort() };
141
115
  }
142
116
 
143
117
  /** The files as an upload sends them: text as it is, unless JSON's escapes make it longer than base64 would (a file of
@@ -151,7 +125,7 @@ const filesBody = (files) => [...files].sort(([a], [b]) => (a < b ? -1 : a > b ?
151
125
 
152
126
  /** The package folder `dir` as a deploy uploads it (POST /templates/import's `files`); `fail(code, message)` makes the
153
127
  * refusal a folder that is no package throws. */
154
- export const packageFiles = async (dir, fail) => filesBody(await readFolder(dir, fail));
128
+ export const packageFiles = async (dir, fail) => filesBody((await readFolder(dir, fail)).files);
155
129
 
156
130
  /** A lock read back from its file's text (none when there is no file): its fields as written, or a refusal naming the
157
131
  * file. */
@@ -424,7 +398,12 @@ async function sourceOf({ values, args, env, io, cli, releases }, fail) {
424
398
  const lock = folderLock(dir, cli);
425
399
  releases.push(lock.hold());
426
400
  const write = (written) => (lock.write(written), cliFiles(env, cli).learn(written.target));
427
- return { kind: "folder", dir, lock: { ...lock, write }, files: () => readFolder(dir, fail, io) };
401
+ const files = async () => {
402
+ const { files, hidden } = await readFolder(dir, fail);
403
+ if (hidden.length) say(io, `Left out, hidden: ${hidden.join(", ")}`);
404
+ return files;
405
+ };
406
+ return { kind: "folder", dir, lock: { ...lock, write }, files };
428
407
  }
429
408
  if (/[\\/]/.test(given) || given.startsWith(".")) throw fail(2, `${given} is not a folder: deploy takes a package folder or an agent id of this install.`);
430
409
  // The install the agent is on: --base-url, else as every command finds it; never with AGENTRUN_API_KEY, which is the
@@ -494,7 +473,6 @@ async function deploy(ctx) {
494
473
  const fail = cli.fail;
495
474
  const from = await sourceOf(ctx, fail);
496
475
  const files = await from.files();
497
- await checkedHere(files, fail);
498
476
  const sha = packageSha256(files);
499
477
  let parameters;
500
478
  if (values.params !== undefined) {
@@ -698,7 +676,7 @@ export const DEPLOY = {
698
676
  ["--pause-source", "an install agent: turn its schedules off on this install once deployed (else they fire in both places); exits 1, once deployed, when it could not turn every one off"],
699
677
  ["--agent ID|new", "with no lock for the target: deploy onto its agent ID, or make another agent (new), where it has one this package made with these parameters; with a lock, only the lock's agent while it is there (one gone from the target, any)"],
700
678
  ["", TOKEN],
701
- ["", "Exit codes: 0 deployed or up to date, 2 refused (bad input, edited on the target, an agent there this package made that no lock names, not confirmed), 3 not runnable yet there (nothing made), 1 the target refused or was not reached."],
679
+ ["", "Exit codes: 0 deployed or up to date, 2 refused (bad input, edited on the target, an agent there this package made that no lock names, not confirmed), 3 not runnable yet there (nothing made), 1 the target refused or was not reached, or deployed but --pause-source left a schedule on."],
702
680
  ],
703
681
  options: { to: { type: "string" }, yes: { type: "boolean" }, force: { type: "boolean" }, params: { type: "string" }, "pause-source": { type: "boolean" }, agent: { type: "string" } },
704
682
  run: ending(deploy),
package/lib/doctor.mjs CHANGED
@@ -162,13 +162,13 @@ export async function doctorOf({
162
162
  try {
163
163
  token = readToken({ data, record, env });
164
164
  } catch (error) {
165
- capsWhy = error.message;
165
+ capsWhy = error.message.replace(/\.$/, "");
166
166
  }
167
167
  if (token) {
168
168
  const answer = await getJson(`${base}/capabilities`, { authorization: `Bearer ${token}` });
169
169
  if (answer.status === 200 && answer.body && typeof answer.body === "object") caps = answer.body;
170
170
  else capsWhy = `GET /v2/capabilities answered ${answer.status || answer.error}`;
171
- } else capsWhy ??= `no token to read the server's capabilities with: ${join(data, ".token")} is not there${record?.token_file ? "" : " (the server was started with AGENTRUN_TOKEN; set AGENTRUN_API_KEY or AGENTRUN_TOKEN to it)"}`;
171
+ } else capsWhy ??= `no token to read the server's capabilities with: ${join(data, ".token")} is not there`;
172
172
  }
173
173
  const version = caps?.server?.version;
174
174
 
@@ -370,11 +370,7 @@ export const DOCTOR = {
370
370
  options: { json: { type: "boolean" } },
371
371
  async run({ values, io, env, cli }) {
372
372
  if (values["base-url"] !== undefined) throw cli.fail(2, "agentrun doctor checks the AgentRun on this machine, the server of --data (default ~/.agentrun); it takes no --base-url.");
373
- const readToken = ({ data, record, env: vars }) => {
374
- if (record && !record.token_file) return vars.AGENTRUN_API_KEY || vars.AGENTRUN_TOKEN || undefined;
375
- return cli.privateFile(join(data, ".token"))?.trim() || undefined;
376
- };
377
- const report = await doctorOf({ data: values.data, env, readRecord: cli.privateFile, readToken });
373
+ const report = await doctorOf({ data: values.data, env, readRecord: cli.privateFile, readToken: cli.localToken });
378
374
  io.stdout.write(values.json ? `${JSON.stringify(report, null, 2)}\n` : textOf(report));
379
375
  return report.exit;
380
376
  },
package/lib/start.mjs CHANGED
@@ -266,7 +266,7 @@ const inCi = (env) => Boolean(env.CI) && env.CI !== "false" && env.CI !== "0";
266
266
 
267
267
  /** The server's own commands (its CLI's first word), which this command runs on its store: every other first word is
268
268
  * the CLI's, which names a command it has or says it has none. */
269
- export const SERVER_COMMANDS = ["check-harness", "check-upload", "eval-template", "import", "install-harness", "learning", "native", "remote-bridge", "reset-password", "runner", "scrub", "sign-in-harness", "store-schema", "validate-template"];
269
+ export const SERVER_COMMANDS = ["check-harness", "eval-template", "import", "install-harness", "learning", "native", "remote-bridge", "reset-password", "runner", "scrub", "sign-in-harness", "store-schema", "validate-template"];
270
270
 
271
271
  /** How many of the server's refusals and ignored deliveries a start says, each route and reason once, before one line
272
272
  * that says the rest are not: under this command the server's log goes nowhere else (its stdout is read here and dropped). */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcha/agentrun",
3
- "version": "0.4.25",
3
+ "version": "0.4.26",
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,7 @@
17
17
  "NOTICE"
18
18
  ],
19
19
  "dependencies": {
20
- "@parcha/agentrun-serve": "0.1.0-beta.57"
20
+ "@parcha/agentrun-serve": "0.1.0-beta.58"
21
21
  },
22
22
  "scripts": {
23
23
  "test": "node --test 'test/*.test.mjs'"
@@ -115,6 +115,8 @@ agentrun runs wait "$run" > out.json
115
115
 
116
116
  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.
117
117
 
118
+ A year of the person's own coding-agent work (tokens, cost, models, harnesses, when they work) is `agentrun wrapped --year 2025`: numbers and names only, read from the session files on the machine the server runs on, and answered only by a server on loopback with no public URL (any other is 403). The console shows it at `#/wrapped`.
119
+
118
120
  ## Exit codes
119
121
 
120
122
  - 0: done; for `runs wait` and `runs start --wait`, the run completed.
@@ -1098,6 +1098,7 @@ Route: `GET /runs`.
1098
1098
  - `--status queued|working|paused|input_required|completed|failed|cancelled` (string, one of these): Only runs with this status.
1099
1099
  - `--archived` (boolean): true lists only archived runs; false, the default, the others.
1100
1100
  - `--label STRING` (string): Only runs holding this label: `<key>:<value>`, split at the first `:` (a key holds none). Once per request; a second `label`, or one that does not read as a label, is 400.
1101
+ - `--source STRING` (string): Only runs imported from this source, a source's name as the run's `imported_from.source` holds it (`claude-code`, `codex`, ...), or `live` for the runs made here, not imported. A name no run holds lists none. Once per request; a second `source`, or one that does not read as a name, is 400.
1101
1102
  - `--all` (boolean, this CLI's own): every page: follows next_cursor and prints one list, its next_cursor null; stops past 1000 pages, exit 1
1102
1103
 
1103
1104
  ### `agentrun runs message RUN_ID`