@parcha/agentrun 0.4.31 → 0.4.33

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 CHANGED
@@ -150,6 +150,9 @@ Where a new agent that names no place goes, by mode:
150
150
  is `null`. So is `agentrun deploy` of a package that names no `tools` and no `computer` list, at its preview: name its tools
151
151
  (`tools: []` keeps the runner) or its computer list.
152
152
  - In Mode 2, where the runner's shell is Archil's serverless exec, it is not refused: it runs on the runner, as before.
153
+ - In Mode 2 on an Archil region with no serverless exec (`gcp-us-central1`), bash needs a box. A new agent with a shell
154
+ tool and no computer is refused at its create and at `agentrun deploy`: "bash needs a box (a sandbox computer): …".
155
+ Give it a sandbox computer, or leave `bash` out of its tools.
153
156
 
154
157
  A Docker box's image is built on its first run, which shows that on its timeline. `AGENTRUN_BOXES=none` turns boxes off.
155
158
 
package/install.sh CHANGED
@@ -880,7 +880,8 @@ services:
880
880
  AGENTRUN_TOKEN: ${AGENTRUN_TOKEN:?run the installer again}
881
881
  AGENTRUN_PUBLIC_URL: ${AGENTRUN_PUBLIC_URL:?run the installer again}
882
882
  restart: unless-stopped
883
- stop_grace_period: 15s
883
+ # At least a signed-in server's stop bound (27 s: a ChatGPT plan renewal saves its new pair), as the quickstart's.
884
+ stop_grace_period: 35s
884
885
  volumes:
885
886
  agentrun-data:
886
887
  EOF
@@ -2268,6 +2268,26 @@ export const COMMANDS = [
2268
2268
  "raw": false,
2269
2269
  "summary": "The model gateway in force: the environment's, the one saved here, or none"
2270
2270
  },
2271
+ {
2272
+ "command": [
2273
+ "local",
2274
+ "get-prices"
2275
+ ],
2276
+ "operationId": "getPrices",
2277
+ "method": "GET",
2278
+ "path": "/settings/prices",
2279
+ "pathParams": [],
2280
+ "multiSegment": [],
2281
+ "query": [],
2282
+ "headers": [],
2283
+ "bodyFlags": [],
2284
+ "hasBody": false,
2285
+ "bodyRequired": false,
2286
+ "bodyTypes": [],
2287
+ "secretBody": false,
2288
+ "raw": false,
2289
+ "summary": "The prices this server meters computer time and browser time at, with where each comes from"
2290
+ },
2271
2291
  {
2272
2292
  "command": [
2273
2293
  "local",
@@ -3574,6 +3594,12 @@ export const COMMANDS = [
3574
3594
  "required": true,
3575
3595
  "description": "At most `limits.max_message_chars`. Not only whitespace."
3576
3596
  },
3597
+ {
3598
+ "name": "said",
3599
+ "type": "string",
3600
+ "required": false,
3601
+ "description": "The person's own words, when `content` is a host's text around them (a preamble, an earlier report, turn instructions): what the run's learning keeps of this message (the one line it appends to the agent's corrections.md, and the follow-up in its compile turn's traces), in place of `content`. The model gets `content` only, never `said`; `said` need not appear inside it. Absent, learning keeps `content`, as before. 422 `input_invalid` at `said`, nothing written: reason `wrong_type` when it is not a string, `empty` when it is empty after trimming, `too_long` past 4000 characters, counted in Unicode code points (an emoji is one). Text shaped like a secret is not refused here: the learning's checks refuse its line, as any correction's. Offered where `features.messages.said` is true."
3602
+ },
3577
3603
  {
3578
3604
  "name": "model_key",
3579
3605
  "type": "string",
package/lib/deploy.mjs CHANGED
@@ -117,7 +117,7 @@ async function readFolder(dir, fail) {
117
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
118
118
  * newlines or control characters), and any other bytes base64. So the body stays within the base64 size the server's
119
119
  * upload limit allows for. */
120
- const filesBody = (files) => [...files].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)).map(([path, data]) => {
120
+ export const filesBody = (files) => [...files].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)).map(([path, data]) => {
121
121
  const text = data.toString("utf8");
122
122
  const base64 = data.toString("base64");
123
123
  return Buffer.from(text, "utf8").equals(data) && Buffer.byteLength(JSON.stringify(text)) <= base64.length + 2 ? { path, encoding: "utf8", content: text } : { path, encoding: "base64", content: base64 };
package/lib/service.mjs CHANGED
@@ -27,7 +27,9 @@ const xml = (text) => text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(
27
27
  const unxml = (text) => text.replace(/&quot;/g, '"').replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&amp;/g, "&");
28
28
 
29
29
  /** The LaunchAgent: started at login (RunAtLoad), started again when it exits with a failure (KeepAlive), its output in
30
- * `log`, with the PATH of the shell that installed it (launchd's own has no Homebrew, so no docker) and `env`. */
30
+ * `log`, with the PATH of the shell that installed it (launchd's own has no Homebrew, so no docker) and `env`. A stop
31
+ * gets 35 s before launchd's SIGKILL (ExitTimeOut; its default is 20 s): a signed-in server's stop takes up to 27 s, and
32
+ * a ChatGPT renewal its runner sends (served at most 4 s into the stop) up to 25 s more to save its new pair. */
31
33
  export function plistText({ program, args, path, log, env = {} }) {
32
34
  const strings = [program, ...args].map((arg) => ` <string>${xml(arg)}</string>`).join("\n");
33
35
  const vars = Object.entries({ PATH: path, ...env }).map(([key, value]) => ` <key>${xml(key)}</key>\n <string>${xml(value)}</string>`).join("\n");
@@ -52,6 +54,8 @@ ${vars}
52
54
  <key>SuccessfulExit</key>
53
55
  <false/>
54
56
  </dict>
57
+ <key>ExitTimeOut</key>
58
+ <integer>35</integer>
55
59
  <key>StandardOutPath</key>
56
60
  <string>${xml(log)}</string>
57
61
  <key>StandardErrorPath</key>
package/lib/start.mjs CHANGED
@@ -294,7 +294,7 @@ const inCi = (env) => Boolean(env.CI) && env.CI !== "false" && env.CI !== "0";
294
294
 
295
295
  /** The server's own commands (its CLI's first word), which this command runs on its store: every other first word is
296
296
  * the CLI's, which names a command it has or says it has none. */
297
- 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"];
297
+ 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", "workspace-backfill"];
298
298
 
299
299
  /** How many of the server's refusals and ignored deliveries a start says, each route and reason once, before one line
300
300
  * that says the rest are not: under this command the server's log goes nowhere else (its stdout is read here and dropped). */
package/lib/template.mjs CHANGED
@@ -5,6 +5,7 @@
5
5
  import { spawnSync } from "node:child_process";
6
6
  import { readdirSync, statSync } from "node:fs";
7
7
  import { join, resolve } from "node:path";
8
+ import { filesBody } from "./deploy.mjs";
8
9
 
9
10
  /** The refusal of the cases `names` lists that the package in `dir` does not have (a case is a folder in its evals/), in
10
11
  * the words the server uses (template-eval.ts readCases), or undefined: every one is there, or `dir` is no folder, which
@@ -36,10 +37,83 @@ export const TEMPLATE_VALIDATE = {
36
37
  },
37
38
  };
38
39
 
40
+ /** Whether a refusal of `{source}` says the server takes uploads ({files}) alone: serve's API-only profile (422
41
+ * input_invalid, its field `source` not_allowed) or a hosted tier's (422 files_only). Read from the error's code and
42
+ * fields, never its words. */
43
+ function takesUploadsOnly(status, text) {
44
+ if (status !== 422) return false;
45
+ let error;
46
+ try {
47
+ error = JSON.parse(text)?.error;
48
+ } catch {
49
+ return false;
50
+ }
51
+ if (error?.code === "files_only") return true;
52
+ return error?.code === "input_invalid" && Array.isArray(error.fields) && error.fields.some((one) => one?.field === "source" && one?.reason === "not_allowed");
53
+ }
54
+
55
+ /** GitHub's API, where this command reads a package anonymously. A test points it at a faux GitHub through
56
+ * AGENTRUN_TEST_GITHUB_API, honoured under a test runner alone (node --test's NODE_TEST_CONTEXT), as serve's own test
57
+ * seams are. */
58
+ function githubReach(env, hosts) {
59
+ const test = env.NODE_TEST_CONTEXT ? env.AGENTRUN_TEST_GITHUB_API : undefined;
60
+ const anonymous = "this command reads GitHub without a token";
61
+ return test ? { api: test, hosts: [new URL(test).host], anonymous } : { api: "https://api.github.com", hosts, anonymous };
62
+ }
63
+
64
+ /** The package `args[0]` names read from GitHub here, by the server's own reader (its `template-source` export, with its
65
+ * import's limits), at the commit its ref is at now, and uploaded ({files}, encoded as `agentrun deploy` sends a
66
+ * folder's) with --dry-run passed on: for a server that takes uploads alone. The upload is the folder whole, as the
67
+ * server's own import of the source keeps it, so the server checks the same package and refuses what that import
68
+ * refuses. The reader skips a hidden file or folder, as both of the server's paths do. An upload keeps no publisher,
69
+ * so without --dry-run it needs --trust, asked before anything is read. `{ response, bytes, code, read }`, `read` the
70
+ * source and the commit uploaded. */
71
+ async function uploadFromGithub({ values, args, env, io, cli, client }) {
72
+ if (!values.trust && !values["dry-run"]) throw cli.fail(1, `This server takes uploaded packages only and keeps no publisher's trust, so this command reads ${args[0]} from GitHub itself and uploads its files. Read it first (--dry-run), then run this again with --trust.`);
73
+ // Loaded here: start.mjs loads cli.mjs, which loads this module.
74
+ const { SERVE_PACKAGE } = await import("./start.mjs");
75
+ let reader;
76
+ try {
77
+ reader = await import(`${SERVE_PACKAGE}/template-source`);
78
+ } catch {
79
+ throw cli.fail(2, `AgentRun's server (${SERVE_PACKAGE}) is not installed beside this command, and it is the server's reader that reads a package from GitHub: nothing was sent.`);
80
+ }
81
+ const reach = githubReach(env, reader.GITHUB_HOSTS);
82
+ const signal = AbortSignal.timeout(reader.IMPORT_LIMITS.ms);
83
+ let source, sha, files;
84
+ try {
85
+ source = reader.parseSource(args[0]);
86
+ sha = await reader.resolveSha(source, reach, signal);
87
+ files = await reader.fetchPackageFiles(source, sha, reach, signal);
88
+ } catch (error) {
89
+ throw cli.fail(1, `${args[0]} could not be read from GitHub, so nothing was uploaded: ${error.message}`);
90
+ }
91
+ // A source's package is named by its folder (the path's last part, or the repository's for a root package), and the
92
+ // server's own import refuses an agent.md that says otherwise; an upload is named by its agent.md alone, so that check
93
+ // is made here, before anything is sent. A manifest that names nothing is left to the server to refuse.
94
+ const manifest = files.get("agent.md");
95
+ if (manifest !== undefined) {
96
+ let manifestOf;
97
+ try {
98
+ ({ manifestOf } = await import(`${SERVE_PACKAGE}/manifest`));
99
+ } catch {
100
+ throw cli.fail(2, `AgentRun's server (${SERVE_PACKAGE}) is not installed beside this command, and it is the server's reader that reads agent.md: nothing was sent.`);
101
+ }
102
+ const named = manifestOf(manifest.toString("utf8"))?.name;
103
+ const folder = source.id.split("/").at(-1);
104
+ if (typeof named === "string" && named !== folder) throw cli.fail(1, `${source.id}'s agent.md names the package ${JSON.stringify(named)}, and a package's name is its folder's, ${JSON.stringify(folder)}: the server's own import of the source refuses it, so nothing was uploaded.`);
105
+ }
106
+ io.stderr.write(`This server takes uploaded packages only, so this command read ${source.id} from GitHub itself at ${sha} and uploads its files.\n`);
107
+ const body = JSON.stringify({ files: filesBody(files), ...(values["dry-run"] ? { dry_run: true } : {}) });
108
+ return { ...(await cli.request(client, { method: "POST", path: "/templates/import", body, type: "application/json" })), read: { source, sha } };
109
+ }
110
+
39
111
  // `agentrun template install SOURCE`: a package on GitHub imported into the server (POST /v2/templates/import), which
40
112
  // resolves the ref to a commit, reads the package at it and checks it as it checks its own; nothing in it runs. With
41
113
  // --dry-run the package is shown whole (its instructions and every skill file) and stored nowhere. The first package from
42
114
  // a publisher needs --trust, said once, after reading it. Prints what was imported and the console page that applies it.
115
+ // A server that takes uploads alone refuses the source: this command then reads the package from GitHub itself, at the
116
+ // commit its ref is at, and uploads its files (uploadFromGithub), which needs --trust each time unless it is a dry run.
43
117
  export const TEMPLATE_INSTALL = {
44
118
  command: ["template", "install"],
45
119
  pathParams: ["source"],
@@ -47,19 +121,29 @@ export const TEMPLATE_INSTALL = {
47
121
  help: [
48
122
  ["SOURCE", "github:OWNER/REPO[/PATH][@REF], or https://github.com/OWNER/REPO/tree/REF/PATH. The ref is resolved to a commit first"],
49
123
  ["--dry-run", "check the package and print it whole (instructions, skill files); store nothing"],
50
- ["--trust", "trust the package's publisher (the GitHub owner): the first package from one needs it"],
124
+ ["--trust", "trust the package's publisher (the GitHub owner): the first package from one needs it, and every install on a server that takes uploads only, where this command reads GitHub itself"],
51
125
  ],
52
126
  options: { "dry-run": { type: "boolean" }, trust: { type: "boolean" } },
53
127
  async run({ values, args, env, io, cli }) {
54
128
  const client = cli.clientOf(cli.targetOf(values, env), io);
55
129
  let refusal = "";
130
+ let uploadsOnly = false;
56
131
  const refused = client.refused;
57
- client.refused = (response, bytes) => ((refusal = bytes.toString("utf8")), refused(response, bytes));
132
+ // A server that takes uploads alone: its refusal is not printed, as this command reads the package itself instead.
133
+ client.refused = (response, bytes) => {
134
+ refusal = bytes.toString("utf8");
135
+ if (takesUploadsOnly(response.status, refusal)) return (uploadsOnly = true), 1;
136
+ return refused(response, bytes);
137
+ };
58
138
  const body = JSON.stringify({ source: args[0], ...(values["dry-run"] ? { dry_run: true } : {}), ...(values.trust ? { trust_publisher: true } : {}) });
59
- const { response, bytes, code } = await cli.request(client, { method: "POST", path: "/templates/import", body, type: "application/json" });
139
+ let { response, bytes, code, read } = await cli.request(client, { method: "POST", path: "/templates/import", body, type: "application/json" });
140
+ if (uploadsOnly) {
141
+ client.refused = refused;
142
+ ({ response, bytes, code, read } = await uploadFromGithub({ values, args, env, io, cli, client }));
143
+ }
60
144
  if (code !== undefined) {
61
145
  // The one refusal this command has a flag for: say it, after the server's error.
62
- if (!values.trust && /"field"\s*:\s*"trust_publisher"/.test(refusal)) io.stderr.write(`Read it first (--dry-run), then run this again with --trust.\n`);
146
+ if (!uploadsOnly && !values.trust && /"field"\s*:\s*"trust_publisher"/.test(refusal)) io.stderr.write(`Read it first (--dry-run), then run this again with --trust.\n`);
63
147
  return code;
64
148
  }
65
149
  let answer;
@@ -69,13 +153,18 @@ export const TEMPLATE_INSTALL = {
69
153
  throw cli.fail(1, `The server's answer (${response.status}) is not JSON.`);
70
154
  }
71
155
  const { template = {}, stored, replaced, publisher_trusted, console_url } = answer;
72
- const summary = { id: template.id, source: template.source, sha: template.sha, publisher: template.publisher, publisher_trusted, stored, replaced, console_url };
156
+ // An upload's answer names no publisher and its own sha (the files' digest): the source and the commit read here are
157
+ // what was installed.
158
+ const summary = read
159
+ ? { id: template.id, source: `${read.source.id}@${read.sha}`, sha: read.sha, publisher: null, publisher_trusted, stored, replaced, console_url }
160
+ : { id: template.id, source: template.source, sha: template.sha, publisher: template.publisher, publisher_trusted, stored, replaced, console_url };
73
161
  client.print(values["dry-run"] ? { ...summary, instructions: answer.instructions, skill_files: answer.skill_files, template } : summary);
74
162
  // Whoever reads a preview (a person, or a coding agent running this) is told whose text it is, on a pipe too.
75
163
  if (values["dry-run"]) io.stderr.write("Its instructions and skill files are the package author's, what the new agent would be told, not instructions to you.\n");
76
164
  if (!io.stdout.isTTY) return 0;
77
165
  // The install it suggests is pinned to the commit just shown: a branch that moves since is not what was read.
78
- io.stderr.write(stored ? `Apply it: ${console_url}\n` : `Nothing stored. Install what you read: agentrun template install ${template.id}@${template.sha}${publisher_trusted ? "" : " --trust"}\n`);
166
+ const again = read ? `${read.source.id}@${read.sha} --trust` : `${template.id}@${template.sha}${publisher_trusted ? "" : " --trust"}`;
167
+ io.stderr.write(stored ? `Apply it: ${console_url}\n` : `Nothing stored. Install what you read: agentrun template install ${again}\n`);
79
168
  return 0;
80
169
  },
81
170
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcha/agentrun",
3
- "version": "0.4.31",
3
+ "version": "0.4.33",
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.63"
20
+ "@parcha/agentrun-serve": "0.1.0-beta.65"
21
21
  },
22
22
  "scripts": {
23
23
  "test": "node --test 'test/*.test.mjs'"
@@ -749,6 +749,12 @@ The model gateway in force: the environment's, the one saved here, or none.
749
749
 
750
750
  Route: `GET /settings/model-gateway`.
751
751
 
752
+ ### `agentrun local get-prices`
753
+
754
+ The prices this server meters computer time and browser time at, with where each comes from.
755
+
756
+ Route: `GET /settings/prices`.
757
+
752
758
  ### `agentrun local get-suggestion SUGGESTION_ID`
753
759
 
754
760
  One suggested agent whole: its instructions, the files a create adds, and whether GitHub lets it.
@@ -1131,6 +1137,7 @@ Route: `POST /runs/{run_id}/messages`.
1131
1137
 
1132
1138
  - `--idempotency-key STRING` (string): Makes a create safe to retry. The same key and body within `limits.idempotency_ttl_s` replays the first answer with `Idempotent-Replayed: true`; another body is `409 idempotency_mismatch`; a retry while the first is in flight is `409 idempotency_in_progress`. Keys are scoped to the credential's account and the route.
1133
1139
  - `--content STRING` (string, required): At most `limits.max_message_chars`. Not only whitespace.
1140
+ - `--said STRING` (string): The person's own words, when `content` is a host's text around them (a preamble, an earlier report, turn instructions): what the run's learning keeps of this message (the one line it appends to the agent's corrections.md, and the follow-up in its compile turn's traces), in place of `content`. The model gets `content` only, never `said`; `said` need not appear inside it. Absent, learning keeps `content`, as before. 422 `input_invalid` at `said`, nothing written: reason `wrong_type` when it is not a string, `empty` when it is empty after trimming, `too_long` past 4000 characters, counted in Unicode code points (an emoji is one). Text shaped like a secret is not refused here: the learning's checks refuse its line, as any correction's. Offered where `features.messages.said` is true.
1134
1141
  - `--model-key STRING` (string): The run's own model key: a key for the model gateway at AGENT_MODEL_BASE_URL, such as a LiteLLM virtual key minted for this run, which every model request tied to the run carries in place of the server's own key (its turns, its subagents, its learned workflows' nodes, a workflow's model nodes, its end-of-run compile turn, and the learning work it starts: a learned workflow's check replay runs and an audit's shadow run). AgentRun never mints, lists or revokes it. Sealed into the run's launch bound to the gateway's origin, read at each claim (a reclaim after a crash among them), erased from the store by the write that ends the run's turn. A replay or shadow run the run starts while its claim holds the key takes a copy sealed for that run alone, erased by the write that ends that run (or its purge): such a run starts at the run's end, capped at its share of what the run's cap leaves then (none left: it is dropped, nothing spent), and it is listed in the run's `learning_work` until it ends; revoke the key once the run is terminal and `learning_work.state` is not `running`. Never in its saved body, its timeline, its view, a log or an Idempotency-Key's fingerprint (a retry with a new key answers the first request's run, its first key kept). The harness, its tools and its sandbox never see it. 422 `invalid` at `model_key` for a key under 8 characters (no cut could hold it) or one with a character that is not visible ASCII (a space, a control character, anything past ASCII); 422 at `model_key` when the run's model never goes to that gateway (no AGENT_MODEL_BASE_URL here, a native run, or a model routed elsewhere). Absent, the run spends on the server's key for its route; where the server holds none (no AGENT_MODEL_API_KEY, none saved in Settings), a start without it is 422 `model_key_required`, never a failure at its first model call. On a message it replaces the run's key from the run's next model request on, a turn still going included, and it is the first key of a run that started on the server's (mint one per turn); a message without one keeps the key the run holds, which is none once its last turn ended: then, where the server holds no key for the run's model, the message is 422 `model_key_required` and nothing is written.
1135
1142
  - `--body JSON|@FILE|-` (application/json, required): The whole body: inline, from a file or from stdin. The flags above win over a JSON body's fields.
1136
1143
  - `--body-type TYPE` (string): The body's type, one of application/json; any other than JSON is sent as given.
@@ -1535,7 +1542,7 @@ Import a template package from GitHub (github:OWNER/REPO[/PATH][@REF]) and print
1535
1542
  Route: none, it runs on this machine.
1536
1543
 
1537
1544
  - `--dry-run` (boolean, this CLI's own): check the package and print it whole (instructions, skill files); store nothing
1538
- - `--trust` (boolean, this CLI's own): trust the package's publisher (the GitHub owner): the first package from one needs it
1545
+ - `--trust` (boolean, this CLI's own): trust the package's publisher (the GitHub owner): the first package from one needs it, and every install on a server that takes uploads only, where this command reads GitHub itself
1539
1546
 
1540
1547
  ### `agentrun template list`
1541
1548