@parcha/agentrun-serve 0.0.0-stage → 0.1.0-beta.29
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/CHANGELOG.md +560 -0
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +1723 -2
- package/dist/adapters.d.ts +205 -0
- package/dist/adapters.js +459 -0
- package/dist/agents.d.ts +124 -0
- package/dist/agents.js +302 -0
- package/dist/app.d.ts +7 -0
- package/dist/app.js +324 -0
- package/dist/bound-files.d.ts +4 -0
- package/dist/bound-files.js +164 -0
- package/dist/box/record.d.ts +6 -0
- package/dist/box/record.js +41 -0
- package/dist/box/sweep.d.ts +53 -0
- package/dist/box/sweep.js +193 -0
- package/dist/box-image.d.ts +98 -0
- package/dist/box-image.js +283 -0
- package/dist/box-relay.d.ts +42 -0
- package/dist/box-relay.js +222 -0
- package/dist/boxes.d.ts +54 -0
- package/dist/boxes.js +182 -0
- package/dist/cap.d.ts +224 -0
- package/dist/cap.js +721 -0
- package/dist/catalog.d.ts +20 -0
- package/dist/catalog.js +53 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +167 -0
- package/dist/coding-tools.d.ts +31 -0
- package/dist/coding-tools.js +81 -0
- package/dist/console/THIRD-PARTY-NOTICES.txt +1141 -0
- package/dist/console/assets/index-BN7oVcO4.js +445 -0
- package/dist/console/assets/index-By-jkqki.css +1 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-CIEtRijs.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-BB5xRk30.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-EVf6-Yzo.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-BHyURHCj.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-C_uLvvQ5.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-Dj6eZy5f.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-DpeVePZf.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-greek-400-normal-CNojz0t3.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-600-normal-3KAm9r92.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-600-normal-H7WoG9Et.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-400-normal-B11XCQ5g.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-600-normal-C8RAYTDA.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-600-normal-DXv3JcnD.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-DHMOLxAi.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-BfB_LPfz.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-DiQlUoE6.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-BeU3T8wf.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-ByoDsISC.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-CSpzN4cI.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-Dtizs43-.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-400-normal-Cph9ettZ.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-400-normal-DfGZKnlb.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-600-normal-BGBUNdzT.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-600-normal-COje25QW.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-4l4lq8zr.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-BGzXWJeR.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-8_E36CQj.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-C27an7Zc.woff +0 -0
- package/dist/console/index.html +15 -0
- package/dist/daytona-api.d.ts +21 -0
- package/dist/daytona-api.js +101 -0
- package/dist/decision-rows.d.ts +11 -0
- package/dist/decision-rows.js +116 -0
- package/dist/decisions.d.ts +94 -0
- package/dist/decisions.js +184 -0
- package/dist/effort-guidance.d.ts +5 -0
- package/dist/effort-guidance.js +14 -0
- package/dist/environment.d.ts +5 -0
- package/dist/environment.js +11 -0
- package/dist/errors.d.ts +72 -0
- package/dist/errors.js +66 -0
- package/dist/exa-keyless.d.ts +35 -0
- package/dist/exa-keyless.js +202 -0
- package/dist/fetch-page.d.ts +114 -0
- package/dist/fetch-page.js +182 -0
- package/dist/files.d.ts +60 -0
- package/dist/files.js +153 -0
- package/dist/grade.d.ts +96 -0
- package/dist/grade.js +348 -0
- package/dist/graph-view.d.ts +100 -0
- package/dist/graph-view.js +212 -0
- package/dist/harness-app.d.ts +38 -0
- package/dist/harness-app.js +626 -0
- package/dist/harness.d.ts +53 -0
- package/dist/harness.js +74 -0
- package/dist/home-path.d.ts +27 -0
- package/dist/home-path.js +78 -0
- package/dist/host-tools.d.ts +20 -0
- package/dist/host-tools.js +140 -0
- package/dist/host.d.ts +39 -0
- package/dist/host.js +81 -0
- package/dist/hosted-search.d.ts +27 -0
- package/dist/hosted-search.js +129 -0
- package/dist/import-sources.d.ts +104 -0
- package/dist/import-sources.js +629 -0
- package/dist/import-summary.d.ts +25 -0
- package/dist/import-summary.js +75 -0
- package/dist/import-worker.d.ts +26 -0
- package/dist/import-worker.js +41 -0
- package/dist/import.d.ts +145 -0
- package/dist/import.js +1221 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +6 -0
- package/dist/key-check.d.ts +36 -0
- package/dist/key-check.js +108 -0
- package/dist/key-refusal.d.ts +51 -0
- package/dist/key-refusal.js +187 -0
- package/dist/learn/check.d.ts +99 -0
- package/dist/learn/check.js +259 -0
- package/dist/learn/grade.d.ts +79 -0
- package/dist/learn/grade.js +433 -0
- package/dist/learn/index.d.ts +7 -0
- package/dist/learn/index.js +11 -0
- package/dist/learn/invisible.d.ts +5 -0
- package/dist/learn/invisible.js +42 -0
- package/dist/learn/notes.d.ts +59 -0
- package/dist/learn/notes.js +146 -0
- package/dist/learn/reflect.d.ts +49 -0
- package/dist/learn/reflect.js +167 -0
- package/dist/learn/secrets.d.ts +18 -0
- package/dist/learn/secrets.js +111 -0
- package/dist/learn/skills.d.ts +84 -0
- package/dist/learn/skills.js +198 -0
- package/dist/learning-routes.d.ts +196 -0
- package/dist/learning-routes.js +609 -0
- package/dist/learning-run.d.ts +304 -0
- package/dist/learning-run.js +797 -0
- package/dist/learning-words.d.ts +73 -0
- package/dist/learning-words.js +171 -0
- package/dist/learning.d.ts +377 -0
- package/dist/learning.js +801 -0
- package/dist/llm.d.ts +40 -0
- package/dist/llm.js +37 -0
- package/dist/llms.txt +37 -0
- package/dist/mcp-servers.d.ts +115 -0
- package/dist/mcp-servers.js +445 -0
- package/dist/mcp.d.ts +51 -0
- package/dist/mcp.js +392 -0
- package/dist/model.d.ts +184 -0
- package/dist/model.js +484 -0
- package/dist/monid.d.ts +74 -0
- package/dist/monid.js +277 -0
- package/dist/openapi/agentrun-v2.openapi.json +4805 -0
- package/dist/openapi.d.ts +10 -0
- package/dist/openapi.js +1417 -0
- package/dist/owner.d.ts +55 -0
- package/dist/owner.js +222 -0
- package/dist/packs.d.ts +71 -0
- package/dist/packs.js +180 -0
- package/dist/page.d.ts +32 -0
- package/dist/page.js +133 -0
- package/dist/paid-calls.d.ts +46 -0
- package/dist/paid-calls.js +110 -0
- package/dist/pause.d.ts +68 -0
- package/dist/pause.js +97 -0
- package/dist/pdf-pages.d.ts +44 -0
- package/dist/pdf-pages.js +147 -0
- package/dist/place.d.ts +46 -0
- package/dist/place.js +105 -0
- package/dist/print.d.ts +20 -0
- package/dist/print.js +29 -0
- package/dist/propose.d.ts +38 -0
- package/dist/propose.js +82 -0
- package/dist/quiet-sqlite-warning.d.ts +1 -0
- package/dist/quiet-sqlite-warning.js +14 -0
- package/dist/request-start.d.ts +14 -0
- package/dist/request-start.js +226 -0
- package/dist/result.d.ts +3 -0
- package/dist/result.js +5 -0
- package/dist/rows.d.ts +46 -0
- package/dist/rows.js +121 -0
- package/dist/run-box.d.ts +134 -0
- package/dist/run-box.js +440 -0
- package/dist/run-manifest.d.ts +27 -0
- package/dist/run-manifest.js +60 -0
- package/dist/runnable.d.ts +80 -0
- package/dist/runnable.js +162 -0
- package/dist/runs.d.ts +840 -0
- package/dist/runs.js +2279 -0
- package/dist/secret-cut.d.ts +27 -0
- package/dist/secret-cut.js +109 -0
- package/dist/secrets.d.ts +50 -0
- package/dist/secrets.js +140 -0
- package/dist/server-lock.d.ts +44 -0
- package/dist/server-lock.js +140 -0
- package/dist/server.d.ts +626 -0
- package/dist/server.js +1756 -0
- package/dist/sessions.d.ts +4 -0
- package/dist/sessions.js +105 -0
- package/dist/skills.d.ts +31 -0
- package/dist/skills.js +68 -0
- package/dist/stats.d.ts +101 -0
- package/dist/stats.js +82 -0
- package/dist/tool-keys.d.ts +151 -0
- package/dist/tool-keys.js +273 -0
- package/dist/tool-plane.d.ts +143 -0
- package/dist/tool-plane.js +242 -0
- package/dist/tools.d.ts +147 -0
- package/dist/tools.js +253 -0
- package/dist/turn-end.d.ts +23 -0
- package/dist/turn-end.js +14 -0
- package/dist/turns.d.ts +34 -0
- package/dist/turns.js +202 -0
- package/dist/uploads.d.ts +104 -0
- package/dist/uploads.js +474 -0
- package/dist/usage.d.ts +29 -0
- package/dist/usage.js +58 -0
- package/dist/validate.d.ts +55 -0
- package/dist/validate.js +175 -0
- package/dist/web-fetch.d.ts +64 -0
- package/dist/web-fetch.js +262 -0
- package/dist/web-search.d.ts +54 -0
- package/dist/web-search.js +136 -0
- package/dist/webhooks.d.ts +182 -0
- package/dist/webhooks.js +487 -0
- package/dist/workspace-paths.d.ts +33 -0
- package/dist/workspace-paths.js +104 -0
- package/dist/workspace.d.ts +88 -0
- package/dist/workspace.js +369 -0
- package/launcher/agentrun-serve +109 -0
- package/package.json +94 -4
- package/skills/agentrun-serve/SKILL.md +128 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** A wire name: at most 52 characters, not the adapter's 64. One CLI gives the model the name with a 12-character
|
|
2
|
+
* `mcp__hands__` prefix, and the model API's 64-character limit is on the name the model sees, so 52 is the budget that
|
|
3
|
+
* holds on every harness. The one constant the identity branch and the length check both read: a plain 53-64 character
|
|
4
|
+
* name of valid characters must not skip the mapping and come out over budget. */
|
|
5
|
+
export declare const WIRE_NAME: RegExp;
|
|
6
|
+
/** A catalog name's wire name: itself when it already is one within the budget, else `:` and `/` to `__`, `.` to `_`,
|
|
7
|
+
* any other character to `_`, and a `-<8 hex of the catalog name>` suffix (prefix trimmed to fit) when the result is
|
|
8
|
+
* too long. The suffix makes a long name unique; a collision between two names is refused at the save (collisions,
|
|
9
|
+
* reverseOf), never suffixed away. The reverse is a lookup, never a parse. */
|
|
10
|
+
export declare function wireName(catalog: string): string;
|
|
11
|
+
/** The reverse of {@link wireName} over `names`: a map from each name's wire name back to the catalog name. A collision
|
|
12
|
+
* (two catalog names with one wire name) throws here, so a catalog that would shadow a name never loads; the save path
|
|
13
|
+
* reports the same collision as a 422 before it reaches this. */
|
|
14
|
+
export declare function reverseOf(names: Iterable<string>): ReadonlyMap<string, string>;
|
|
15
|
+
/** The catalog names in `names` whose wire names collide, each paired with the name it clashes with: a definition that
|
|
16
|
+
* holds a pair is refused (a 422 on the second one), so {@link reverseOf} never throws for a loaded catalog. */
|
|
17
|
+
export declare function collisions(names: readonly string[]): {
|
|
18
|
+
name: string;
|
|
19
|
+
clashesWith: string;
|
|
20
|
+
}[];
|
package/dist/catalog.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// The tool catalog's names, and the one mapping between a catalog name and the wire name a harness calls. A catalog name
|
|
2
|
+
// is what a revision writes (`read`, later `monid.discover`, `mcp:<server>/<tool>`); the wire name is what a CLI adapter
|
|
3
|
+
// registers and the model API sees, and both adapters refuse anything outside /^[A-Za-z0-9_-]{1,64}$/. The map is one
|
|
4
|
+
// deterministic, reversible function here, never in an adapter, so every harness gets the same wire name; the journal
|
|
5
|
+
// records the wire name (recovery matches a call by it), and a reader maps it back to the catalog name on the way out.
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
7
|
+
/** A wire name: at most 52 characters, not the adapter's 64. One CLI gives the model the name with a 12-character
|
|
8
|
+
* `mcp__hands__` prefix, and the model API's 64-character limit is on the name the model sees, so 52 is the budget that
|
|
9
|
+
* holds on every harness. The one constant the identity branch and the length check both read: a plain 53-64 character
|
|
10
|
+
* name of valid characters must not skip the mapping and come out over budget. */
|
|
11
|
+
export const WIRE_NAME = /^[A-Za-z0-9_-]{1,52}$/;
|
|
12
|
+
/** A catalog name's wire name: itself when it already is one within the budget, else `:` and `/` to `__`, `.` to `_`,
|
|
13
|
+
* any other character to `_`, and a `-<8 hex of the catalog name>` suffix (prefix trimmed to fit) when the result is
|
|
14
|
+
* too long. The suffix makes a long name unique; a collision between two names is refused at the save (collisions,
|
|
15
|
+
* reverseOf), never suffixed away. The reverse is a lookup, never a parse. */
|
|
16
|
+
export function wireName(catalog) {
|
|
17
|
+
if (WIRE_NAME.test(catalog))
|
|
18
|
+
return catalog;
|
|
19
|
+
const base = catalog.replace(/[:/]+/g, "__").replace(/[^A-Za-z0-9_-]/g, "_");
|
|
20
|
+
if (base.length <= 52)
|
|
21
|
+
return base;
|
|
22
|
+
const tag = `-${createHash("sha256").update(catalog).digest("hex").slice(0, 8)}`;
|
|
23
|
+
return base.slice(0, 52 - tag.length) + tag;
|
|
24
|
+
}
|
|
25
|
+
/** The reverse of {@link wireName} over `names`: a map from each name's wire name back to the catalog name. A collision
|
|
26
|
+
* (two catalog names with one wire name) throws here, so a catalog that would shadow a name never loads; the save path
|
|
27
|
+
* reports the same collision as a 422 before it reaches this. */
|
|
28
|
+
export function reverseOf(names) {
|
|
29
|
+
const reverse = new Map();
|
|
30
|
+
for (const name of names) {
|
|
31
|
+
const wire = wireName(name);
|
|
32
|
+
const had = reverse.get(wire);
|
|
33
|
+
if (had !== undefined && had !== name)
|
|
34
|
+
throw new Error(`the tools ${had} and ${name} both map to the wire name ${wire}`);
|
|
35
|
+
reverse.set(wire, name);
|
|
36
|
+
}
|
|
37
|
+
return reverse;
|
|
38
|
+
}
|
|
39
|
+
/** The catalog names in `names` whose wire names collide, each paired with the name it clashes with: a definition that
|
|
40
|
+
* holds a pair is refused (a 422 on the second one), so {@link reverseOf} never throws for a loaded catalog. */
|
|
41
|
+
export function collisions(names) {
|
|
42
|
+
const seen = new Map();
|
|
43
|
+
const clashes = [];
|
|
44
|
+
for (const name of names) {
|
|
45
|
+
const wire = wireName(name);
|
|
46
|
+
const had = seen.get(wire);
|
|
47
|
+
if (had !== undefined && had !== name)
|
|
48
|
+
clashes.push({ name, clashesWith: had });
|
|
49
|
+
else
|
|
50
|
+
seen.set(wire, name);
|
|
51
|
+
}
|
|
52
|
+
return clashes;
|
|
53
|
+
}
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// agentrun-serve: the Agentrun v2 API on this machine, over the agent store in a data directory.
|
|
3
|
+
// First: the secrets the launcher hands over, read and its pipe closed before anything else runs (secrets.ts). It loads
|
|
4
|
+
// nothing but node:fs and node:os.
|
|
5
|
+
import { secret } from "./secrets.js";
|
|
6
|
+
// Then, before anything loads node:sqlite, the filter for its ExperimentalWarning (quiet-sqlite-warning.ts).
|
|
7
|
+
import "./quiet-sqlite-warning.js";
|
|
8
|
+
import { parseArgs } from "node:util";
|
|
9
|
+
import { spawn } from "node:child_process";
|
|
10
|
+
import { defaultData } from "./files.js";
|
|
11
|
+
import { canOpen } from "./host.js";
|
|
12
|
+
import { resetPassword } from "./owner.js";
|
|
13
|
+
import { banner } from "./print.js";
|
|
14
|
+
import { DEFAULT_PORT, startServe } from "./server.js";
|
|
15
|
+
const USAGE = `usage: agentrun-serve [--data DIR] [--listen ADDR] [--port N] [--open] [--faux MODULE] [--allow-host NAME ...] [--max-runs N] [--drain-timeout D] [--documents DIR] [--allow-code-nodes] [--learning on|off] [--learning-budget BYTES] [--grade-model MODEL]
|
|
16
|
+
agentrun-serve reset-password [--data DIR]
|
|
17
|
+
agentrun-serve import [--data DIR] [--from claude-code,codex,pi] [--dry-run] [--include-deleted] [--all] [--verbose] [--port N]
|
|
18
|
+
|
|
19
|
+
--data DIR the agent store and its runs (default ~/.local/share/agentrun/agents); the token is DIR/.token, mode 0600
|
|
20
|
+
--listen ADDR the address to listen on (default 127.0.0.1); on any other, every Host name is served and the token
|
|
21
|
+
is the only lock, so put TLS in front of it
|
|
22
|
+
--port N the port (default: the first free one from ${DEFAULT_PORT}; 0 is any free port)
|
|
23
|
+
--open open the console in this machine's browser once the server listens (not in CI, nor on Linux with no
|
|
24
|
+
display)
|
|
25
|
+
--faux MODULE answer every model request from MODULE's default export: no key, no network
|
|
26
|
+
--allow-host NAME another Host name to accept (repeatable)
|
|
27
|
+
--max-runs N the most runs at once (default AGENTRUN_MAX_RUNS, else as many pi runs as this host's memory
|
|
28
|
+
holds); each run also reserves its harness's memory, and over either a new run is 429
|
|
29
|
+
--documents DIR a read-only directory of documents a workflow's pdf_pages calls read by file name (default
|
|
30
|
+
AGENTRUN_SERVE_DOCUMENTS)
|
|
31
|
+
--allow-code-nodes run workflows' code nodes, in the run's process with no sandbox (default off, or
|
|
32
|
+
AGENTRUN_SERVE_CODE_NODES=1); off, a workflow with one saves with a warning and its runs are refused
|
|
33
|
+
--drain-timeout D how long a busy run may finish its turn when the server stops (default 30s; the image's is 6s, inside
|
|
34
|
+
Docker's 10 s grace); a run cut off resumes at the next start
|
|
35
|
+
--learning on|off whether runs learn (default on, or AGENTRUN_SERVE_LEARNING): on, a run of an agent whose definition
|
|
36
|
+
says learning: true starts from what that agent learned and adds to it; off, no run does
|
|
37
|
+
--learning-budget BYTES how much of what an agent learned its run's instructions hold (default
|
|
38
|
+
AGENTRUN_SERVE_LEARNING_BUDGET, else 8000): every note whole while they fit, else the index and the
|
|
39
|
+
notes changed last, whole, while they fit
|
|
40
|
+
--grade-model MODEL the model that grades what a run proposes to learn (default AGENTRUN_SERVE_GRADE_MODEL, else the
|
|
41
|
+
strong tier, AGENT_MODEL_STRONG, else each run's own model), named as the strong tier takes one
|
|
42
|
+
|
|
43
|
+
Without --faux, a revision's model ("provider/model-id", or AGENT_MODEL when it names none; a workflow node's tier maps
|
|
44
|
+
to AGENT_MODEL_FAST or AGENT_MODEL_STRONG, each falling back to AGENT_MODEL) is served by pi-ai's providers with their
|
|
45
|
+
keys from the environment, or, with AGENT_MODEL_BASE_URL, by that one OpenAI Responses gateway (AGENT_MODEL_API_KEY when
|
|
46
|
+
it needs a key). AGENTRUN_TOKEN, when set, is the token in place of DIR/.token's, and is never printed; DIR/.token's is
|
|
47
|
+
printed only by the start that made it. AGENTRUN_PUBLIC_URL, when set, is the address people open (a container's
|
|
48
|
+
published port, or a proxy's URL), and the link printed uses it; with none, Render's RENDER_EXTERNAL_URL is. stdout gets one line per request, per run start and
|
|
49
|
+
end, and per refused credential; AGENTRUN_LOG=quiet leaves out the request lines.
|
|
50
|
+
|
|
51
|
+
The page is for one person, who signs in with a password (AGENTRUN_ACCOUNTS=0 turns this off; the token works for
|
|
52
|
+
scripts and the CLI either way). With no AGENTRUN_PUBLIC_URL the first visit to the page sets the password; with it, the
|
|
53
|
+
setup link this server prints carries a code. Forgot the password: \`agentrun-serve reset-password --data DIR\` where the
|
|
54
|
+
data directory is (inside the container) clears it and signs every browser out, and the next visit sets a new one.
|
|
55
|
+
|
|
56
|
+
\`agentrun-serve import\` reads the Claude Code, Codex and pi sessions in your own home (~/.claude/projects,
|
|
57
|
+
~/.codex/sessions, ~/.pi/agent/sessions) into the data directory, once: each project directory an agent, with its
|
|
58
|
+
CLAUDE.md or AGENTS.md and its skill folders, and each session a run you can read but not continue. Nothing leaves this
|
|
59
|
+
machine; the values of key-shaped environment variables are cut out of what is written. --dry-run lists what it would
|
|
60
|
+
import; run again, it imports only what it has not. Sessions written in the last 10 minutes wait for the next import;
|
|
61
|
+
What is left out is counted by why; --verbose lists each file. --include-deleted keeps projects whose directory is gone (a
|
|
62
|
+
deleted worktree's); --all keeps those and temporary ones too. Each run keeps what its session used (tokens, requests, tools,
|
|
63
|
+
time at work), priced at the catalog's list prices when its source did not price it. Both end with a summary of every
|
|
64
|
+
session found, those imported before included, and the address to open the console at (--port as the server takes it).`;
|
|
65
|
+
if (process.argv[2] === "reset-password") {
|
|
66
|
+
let dir;
|
|
67
|
+
try {
|
|
68
|
+
dir = parseArgs({ args: process.argv.slice(3), options: { data: { type: "string" } } }).values.data;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
console.error(`${error.message}\n\n${USAGE}`);
|
|
72
|
+
process.exit(2);
|
|
73
|
+
}
|
|
74
|
+
const target = dir ?? defaultData();
|
|
75
|
+
resetPassword(target);
|
|
76
|
+
console.log(`The password is cleared and every browser is signed out (${target}). The next visit to the page sets a new one.`);
|
|
77
|
+
process.exit(0);
|
|
78
|
+
}
|
|
79
|
+
if (process.argv[2] === "import") {
|
|
80
|
+
const { importCommand } = await import("./import.js");
|
|
81
|
+
process.exit(await importCommand(process.argv.slice(3), USAGE));
|
|
82
|
+
}
|
|
83
|
+
let values;
|
|
84
|
+
try {
|
|
85
|
+
({ values } = parseArgs({
|
|
86
|
+
// Named, not the default: started by the launcher, this module runs under `node -e`, where the default reads one more.
|
|
87
|
+
args: process.argv.slice(2),
|
|
88
|
+
options: {
|
|
89
|
+
data: { type: "string" },
|
|
90
|
+
listen: { type: "string" },
|
|
91
|
+
port: { type: "string" },
|
|
92
|
+
open: { type: "boolean", default: false },
|
|
93
|
+
faux: { type: "string" },
|
|
94
|
+
"allow-host": { type: "string", multiple: true, default: [] },
|
|
95
|
+
"max-runs": { type: "string" },
|
|
96
|
+
"drain-timeout": { type: "string" },
|
|
97
|
+
documents: { type: "string" },
|
|
98
|
+
"allow-code-nodes": { type: "boolean", default: false },
|
|
99
|
+
learning: { type: "string" },
|
|
100
|
+
"grade-model": { type: "string" },
|
|
101
|
+
"learning-budget": { type: "string" },
|
|
102
|
+
help: { type: "boolean", short: "h", default: false },
|
|
103
|
+
},
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
console.error(`${error.message}\n\n${USAGE}`);
|
|
108
|
+
process.exit(2);
|
|
109
|
+
}
|
|
110
|
+
if (values.help) {
|
|
111
|
+
console.log(USAGE);
|
|
112
|
+
process.exit(0);
|
|
113
|
+
}
|
|
114
|
+
const port = values.port === undefined ? DEFAULT_PORT : Number(values.port);
|
|
115
|
+
if (!Number.isInteger(port) || port < 0 || port > 65_535) {
|
|
116
|
+
console.error(`--port takes a port number\n\n${USAGE}`);
|
|
117
|
+
process.exit(2);
|
|
118
|
+
}
|
|
119
|
+
let publicUrl;
|
|
120
|
+
// Render sets RENDER_EXTERNAL_URL on every web service, so a deploy there is never an open setup.
|
|
121
|
+
const publicName = process.env.AGENTRUN_PUBLIC_URL ? "AGENTRUN_PUBLIC_URL" : process.env.RENDER_EXTERNAL_URL ? "RENDER_EXTERNAL_URL" : undefined;
|
|
122
|
+
if (publicName) {
|
|
123
|
+
const given = process.env[publicName];
|
|
124
|
+
const parsed = URL.canParse(given) ? new URL(given) : undefined;
|
|
125
|
+
if (!parsed || !/^https?:$/.test(parsed.protocol)) {
|
|
126
|
+
console.error(`${publicName} takes an http(s) URL\n\n${USAGE}`);
|
|
127
|
+
process.exit(2);
|
|
128
|
+
}
|
|
129
|
+
publicUrl = parsed.href.replace(/\/+$/, "");
|
|
130
|
+
}
|
|
131
|
+
const budget = values["learning-budget"];
|
|
132
|
+
if (budget !== undefined && !/^\d+$/.test(budget)) {
|
|
133
|
+
console.error(`--learning-budget takes a whole number of bytes\n\n${USAGE}`);
|
|
134
|
+
process.exit(2);
|
|
135
|
+
}
|
|
136
|
+
const data = values.data ?? defaultData();
|
|
137
|
+
const given = secret("AGENTRUN_TOKEN") || undefined;
|
|
138
|
+
// A stdout its reader closed (a pipe left behind) loses the log lines, never the server.
|
|
139
|
+
process.stdout.on("error", () => undefined);
|
|
140
|
+
const accounts = process.env.AGENTRUN_ACCOUNTS !== "0";
|
|
141
|
+
let serve;
|
|
142
|
+
try {
|
|
143
|
+
serve = await startServe({
|
|
144
|
+
data, port, ...(values.port === undefined ? { nextFreePort: true } : {}), ...(values.listen ? { host: values.listen } : {}), ...(given ? { token: given } : {}), ...(values.faux ? { faux: values.faux } : {}), allowHosts: values["allow-host"],
|
|
145
|
+
...(values["max-runs"] !== undefined ? { maxRuns: Number(values["max-runs"]) } : {}),
|
|
146
|
+
...(values["drain-timeout"] ? { drainTimeout: values["drain-timeout"] } : {}), ...(values.documents ? { documents: values.documents } : {}), ...(values["allow-code-nodes"] ? { allowCodeNodes: true } : {}), ...(values.learning !== undefined ? { learning: values.learning } : {}), ...(values["grade-model"] ? { gradeModel: values["grade-model"] } : {}), ...(budget !== undefined ? { learningBudget: Number(budget) } : {}), log: (line) => void process.stdout.write(`${line}\n`),
|
|
147
|
+
...(accounts ? { accounts, openSetup: !publicUrl, countSessions: true, ...(publicUrl ? { publicUrl } : {}) } : {}),
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
console.error(`agentrun-serve: ${error.message}`);
|
|
152
|
+
process.exit(1);
|
|
153
|
+
}
|
|
154
|
+
// A token from the environment is the operator's already, and the stored one is printed by the start that made it only.
|
|
155
|
+
const source = given ? "env" : serve.tokenMade ? "made" : "file";
|
|
156
|
+
for (const line of banner({ url: serve.url, baseUrl: serve.baseUrl, data, token: serve.token, source, accounts, boxes: serve.boxesLine, ...(values.listen ? { listen: values.listen } : {}), ...(publicUrl ? { publicUrl } : {}) }))
|
|
157
|
+
console.log(line);
|
|
158
|
+
// With a public address the setup link and its code are printed as the code is made (owner.ts).
|
|
159
|
+
if (serve.setupUrl && !publicUrl)
|
|
160
|
+
console.log(`Set your password: ${serve.setupUrl} (the first visit sets it)`);
|
|
161
|
+
// The console's page, once the server listens: never its sign-in link, whose token would sit in the opener's arguments
|
|
162
|
+
// and the browser's history.
|
|
163
|
+
if (values.open && canOpen(process.env))
|
|
164
|
+
spawn(process.platform === "darwin" ? "open" : "xdg-open", [`${publicUrl ?? serve.url}/`], { stdio: "ignore", detached: true }).on("error", () => { }).unref();
|
|
165
|
+
const stop = () => void serve.close().then(() => process.exit(0));
|
|
166
|
+
process.once("SIGINT", stop);
|
|
167
|
+
process.once("SIGTERM", stop);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Context } from "@earendil-works/chord";
|
|
2
|
+
import { type Extension, type ToolRegistration } from "@earendil-works/pi-durable";
|
|
3
|
+
import { type Place } from "./place.js";
|
|
4
|
+
/** pi's coding tools on the runner, without bash, each refusal of a path outside the workspace named by the path the
|
|
5
|
+
* call gave (`asGivenRefusals`): the model reads that refusal, and the run's timeline shows it. */
|
|
6
|
+
export declare const CodingTools: Extension;
|
|
7
|
+
/** The tools a box runs: pi's, by name. */
|
|
8
|
+
export declare const BOXED_TOOLS: readonly string[];
|
|
9
|
+
/** A run's coding tools and the extension a conversation selects for them. */
|
|
10
|
+
export type CodingSource = {
|
|
11
|
+
readonly extension: Extension;
|
|
12
|
+
readonly tools: readonly ToolRegistration[];
|
|
13
|
+
};
|
|
14
|
+
/** The environment a boxed tool's call runs on: the run's box's (run-box.ts). `note` writes a row on the run's timeline
|
|
15
|
+
* while the box is being had (its image still coming). `hostWork`: the run's own work/ on this machine, the source the
|
|
16
|
+
* box binds at BOX_WORK; `bound`, whether the box's provider binds it there (Docker does). */
|
|
17
|
+
export type BoxedEnv = {
|
|
18
|
+
env(context: Context, note?: (summary: string) => Promise<void>): Promise<unknown>;
|
|
19
|
+
hostWork?: string;
|
|
20
|
+
bound?(): Promise<boolean>;
|
|
21
|
+
leftEnded?(context: Context): Promise<void>;
|
|
22
|
+
};
|
|
23
|
+
/** A boxed file tool's path as the box names it, or undefined when it leaves the box's work dir (`~` and `file:`
|
|
24
|
+
* included). A path under the run's own host work dir (another harness's cwd can name one) is the same file at
|
|
25
|
+
* BOX_WORK, the bind renamed one for one; every other host path (the data root, another run) is never taken for a box
|
|
26
|
+
* path. */
|
|
27
|
+
export declare function boxPath(path: string, hostWork?: string): string | undefined;
|
|
28
|
+
/** A run's coding tools by its place: on the runner, CodingTools (no bash); in a box, pi's read, write, edit and bash,
|
|
29
|
+
* each with its arguments, output and replay as pi ships it and its environment the box's. A file tool's path stays in
|
|
30
|
+
* the box's work dir; bash's command is the box's own. */
|
|
31
|
+
export declare function codingSource(place: Place, box?: BoxedEnv): CodingSource;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// The coding tools a run's process registers: pi's (ArchilCodingTools, `read` declared replay-safe) without `bash`. A
|
|
2
|
+
// run gets no shell on this machine, so this is the only coding-tools extension serve installs (app.ts, tools.ts) and
|
|
3
|
+
// the only one its host tools are taken from (host-tools.ts). The tools left are pi's own, with only their execute
|
|
4
|
+
// wrapped so a refusal names the path the call gave (asGivenRefusals), and the extension keeps everything else pi's
|
|
5
|
+
// carries (its name, so a conversation selects it as before).
|
|
6
|
+
//
|
|
7
|
+
// A run whose place is a box gets codingSource's instead: pi's own read, write, edit and bash, each call made on the
|
|
8
|
+
// box's environment (run-box.ts), so the shell exists only in the box. One source feeds pi's tool table (tools.ts,
|
|
9
|
+
// app.ts) and another harness's host tools (host-tools.ts).
|
|
10
|
+
//
|
|
11
|
+
// Where the box binds the run's work/ from this machine and the confinement holds directory handles (Docker on Linux),
|
|
12
|
+
// read, write and edit run on this machine instead, on the bind's source (bound-files.ts): a command in the box costs
|
|
13
|
+
// far more than a file read. bash always runs in the box, and every tool of any other box (or of any host that reaches
|
|
14
|
+
// directories by path) does too.
|
|
15
|
+
import { posix } from "node:path";
|
|
16
|
+
import { ROOT_CONVERSATION_ID } from "@earendil-works/pi-durable";
|
|
17
|
+
import { FileError } from "@earendil-works/pi-durable/env";
|
|
18
|
+
import { HOST_PHASE } from "@parcha/pi-durable-agent/timeline";
|
|
19
|
+
import { ArchilCodingTools } from "@parcha/pi-durable-disk";
|
|
20
|
+
import { boundFiles } from "./bound-files.js";
|
|
21
|
+
import { BOX_WORK } from "./place.js";
|
|
22
|
+
import { asGivenRefusals, refuseOutsideWorkspace } from "./workspace-paths.js";
|
|
23
|
+
import { writesHeld } from "./workspace.js";
|
|
24
|
+
// pi-durable-disk's types name the pi-durable it resolves, which a build at another pi version (the pi-floor legs) can
|
|
25
|
+
// hold apart from this package's own: the extension crosses that boundary as a value, typed on this side.
|
|
26
|
+
const pis = ArchilCodingTools;
|
|
27
|
+
/** pi's coding tools on the runner, without bash, each refusal of a path outside the workspace named by the path the
|
|
28
|
+
* call gave (`asGivenRefusals`): the model reads that refusal, and the run's timeline shows it. */
|
|
29
|
+
export const CodingTools = { ...pis, tools: asGivenRefusals((pis.tools ?? []).filter((tool) => tool.name !== "bash")) };
|
|
30
|
+
/** The tools a box runs: pi's, by name. */
|
|
31
|
+
export const BOXED_TOOLS = ["read", "write", "edit", "bash"];
|
|
32
|
+
/** A failed call's error with what the file environment said, where pi's message gives only its code (edit's "Error
|
|
33
|
+
* code: permission_denied."), so the model reads why and what it can do. */
|
|
34
|
+
const withCause = (error) => {
|
|
35
|
+
const cause = error?.cause;
|
|
36
|
+
return error instanceof Error && cause instanceof FileError && !error.message.includes(cause.message) ? new Error(`${error.message} ${cause.message}`, { cause }) : error;
|
|
37
|
+
};
|
|
38
|
+
/** A boxed file tool's path as the box names it, or undefined when it leaves the box's work dir (`~` and `file:`
|
|
39
|
+
* included). A path under the run's own host work dir (another harness's cwd can name one) is the same file at
|
|
40
|
+
* BOX_WORK, the bind renamed one for one; every other host path (the data root, another run) is never taken for a box
|
|
41
|
+
* path. */
|
|
42
|
+
export function boxPath(path, hostWork) {
|
|
43
|
+
if (/^(~|file:)/.test(path))
|
|
44
|
+
return undefined;
|
|
45
|
+
const named = hostWork && (path === hostWork || path.startsWith(`${hostWork}/`)) ? `${BOX_WORK}${path.slice(hostWork.length)}` : path;
|
|
46
|
+
const at = posix.resolve(BOX_WORK, named);
|
|
47
|
+
return at === BOX_WORK || at.startsWith(`${BOX_WORK}/`) ? named : undefined;
|
|
48
|
+
}
|
|
49
|
+
/** A run's coding tools by its place: on the runner, CodingTools (no bash); in a box, pi's read, write, edit and bash,
|
|
50
|
+
* each with its arguments, output and replay as pi ships it and its environment the box's. A file tool's path stays in
|
|
51
|
+
* the box's work dir; bash's command is the box's own. */
|
|
52
|
+
export function codingSource(place, box) {
|
|
53
|
+
if (place.mode === "runner")
|
|
54
|
+
return { extension: CodingTools, tools: CodingTools.tools ?? [] };
|
|
55
|
+
if (!box)
|
|
56
|
+
throw new Error("a run whose place is a box needs its box for its coding tools");
|
|
57
|
+
const here = box.hostWork && writesHeld() ? boundFiles(box.hostWork) : undefined;
|
|
58
|
+
const tools = asGivenRefusals((pis.tools ?? []).filter((tool) => BOXED_TOOLS.includes(tool.name)).map((tool) => ({
|
|
59
|
+
...tool,
|
|
60
|
+
execute: async (args, api, context) => {
|
|
61
|
+
// A file tool's path in the box's words, or refused as the confined tools refuse (refuseOutsideWorkspace): named
|
|
62
|
+
// by the path the call gave and no other, the box's work dir included.
|
|
63
|
+
const path = args?.path;
|
|
64
|
+
const inBox = typeof path === "string" ? boxPath(path, box.hostWork) : undefined;
|
|
65
|
+
if (typeof path === "string" && inBox === undefined)
|
|
66
|
+
refuseOutsideWorkspace(path);
|
|
67
|
+
const given = inBox === undefined ? args : { ...args, path: inBox };
|
|
68
|
+
// read, write and edit on this machine's work/, where the box binds it; no box is made for them. A box an earlier
|
|
69
|
+
// process left has its left commands killed first, so none of them changes work/ under these tools.
|
|
70
|
+
if (here && tool.name !== "bash" && (await box.bound?.()) === true) {
|
|
71
|
+
await box.leftEnded?.(context);
|
|
72
|
+
return tool.execute(given, { ...api, env: here }, context).catch((error) => Promise.reject(withCause(error)));
|
|
73
|
+
}
|
|
74
|
+
// A row the box's wait writes goes on the run's root, as a host's phase (pi-durable-agent's timeline shows it).
|
|
75
|
+
const note = (summary) => api.commit(async (tx) => void (await tx.appendEntry(ROOT_CONVERSATION_ID, { kind: HOST_PHASE, data: { summary } })), context);
|
|
76
|
+
return tool.execute(given, { ...api, env: (await box.env(context, note)) }, context);
|
|
77
|
+
},
|
|
78
|
+
})));
|
|
79
|
+
// The permission gate (allow, ask, deny) wraps this source: the one call it takes, whichever of the two lands second.
|
|
80
|
+
return { extension: { ...pis, tools }, tools };
|
|
81
|
+
}
|