@parcha/agentrun 0.4.12 → 0.4.13
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 +20 -5
- package/install.sh +314 -7
- package/lib/cli.mjs +4 -2
- package/lib/commands.generated.mjs +82 -276
- package/lib/harness.mjs +37 -0
- package/lib/service.mjs +34 -6
- package/lib/start.mjs +1 -1
- package/lib/tailscale.mjs +13 -10
- package/package.json +2 -2
- package/skills/agentrun-cli/SKILL.md +6 -5
- package/skills/agentrun-cli/references/commands.md +55 -91
package/README.md
CHANGED
|
@@ -37,7 +37,11 @@ first stops the AgentRun it started in the background itself, whatever version t
|
|
|
37
37
|
|
|
38
38
|
`agentrun service status` prints the console's address and its health. `start`, `stop`, `restart`, `logs [--follow]`,
|
|
39
39
|
`upgrade [--version V]` (the installer again, then a restart) and `uninstall` (the data stays) do what they say, and
|
|
40
|
-
`agentrun service install [--port N] [--data DIR]` installs the service after a `--no-start`.
|
|
40
|
+
`agentrun service install [--port N] [--data DIR]` installs the service after a `--no-start`. For a local model, such
|
|
41
|
+
as Ollama's, `agentrun service install --env AGENT_MODEL_BASE_URL=<its /v1 address> --env AGENT_MODEL_GATEWAY_IDS=bare --env
|
|
42
|
+
AGENT_MODEL=<tag> --env AGENT_MODEL_PRICE=0,0,0` writes those variables into the
|
|
43
|
+
service and restarts it. They stay through restarts, upgrades and later installs, and `--env KEY=` removes one. `--env`
|
|
44
|
+
takes those four names alone: model keys go in the console, never in a service file. On Linux, a user's
|
|
41
45
|
services stop at logout unless lingering is on: `install` and `status` print the one `sudo loginctl enable-linger` line
|
|
42
46
|
when it is off. To remove AgentRun, run `agentrun service uninstall`, then delete `~/.agentrun/bin`, `~/.agentrun/lib`,
|
|
43
47
|
`~/.agentrun/node` and the `PATH` line; the rest of `~/.agentrun` is your data.
|
|
@@ -62,6 +66,17 @@ Tailscale's operator may change what it serves, it prints the one `sudo tailscal
|
|
|
62
66
|
users, unlimited user devices ([pricing](https://tailscale.com/pricing)). The https address needs MagicDNS and HTTPS
|
|
63
67
|
certificates turned on in your tailnet's [DNS settings](https://login.tailscale.com/admin/dns).
|
|
64
68
|
|
|
69
|
+
On a Linux server you rent (Ubuntu or Debian, as root), `--vps` sets up AgentRun in Docker Compose instead, with a
|
|
70
|
+
shell for its agents in Docker sandboxes, on your tailnet when Tailscale is logged in and on the server's loopback
|
|
71
|
+
otherwise:
|
|
72
|
+
|
|
73
|
+
```sh
|
|
74
|
+
curl -fsSL https://agentrun.ai/install | sh -s -- --vps
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
[Deploying AgentRun](https://github.com/Parcha-ai/agentrun/blob/main/deploy/README.md#one-command-on-a-server-you-rent)
|
|
78
|
+
says what it installs and writes, and what `--public` exposes.
|
|
79
|
+
|
|
65
80
|
The server binds its port first and says so; this command then names the address on stderr at once, and prints its line
|
|
66
81
|
on stdout once the server is ready, which on a cold, slow disk can take minutes. A start that fails says why on stderr:
|
|
67
82
|
the step that failed, how the server ended (its exit code or signal, or still running after 60 seconds without printing
|
|
@@ -86,10 +101,10 @@ this app uses your ChatGPT plan. Manage usage in your ChatGPT settings. The sign
|
|
|
86
101
|
agents on this server with it.
|
|
87
102
|
|
|
88
103
|
Or add a model key. With no `AGENT_MODEL`, the server runs a current model of the first provider it has a key for,
|
|
89
|
-
Anthropic, then OpenAI, then OpenRouter: `ANTHROPIC_API_KEY`, `OPENAI_API_KEY
|
|
90
|
-
environment, or a key saved in the console's Settings → Model
|
|
91
|
-
ChatGPT, pi and Codex run on the plan's model by default, key or
|
|
92
|
-
commands are the server's:
|
|
104
|
+
Anthropic, then OpenAI, then Particle (pi only), then OpenRouter: `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`,
|
|
105
|
+
`PARTICLE_API_KEY` or `OPENROUTER_API_KEY` in your environment, or a key saved in the console's Settings → Model
|
|
106
|
+
keys, which counts from the save on. Signed in with ChatGPT, pi and Codex run on the plan's model by default, key or
|
|
107
|
+
not, unless `AGENT_MODEL` names another. Other commands are the server's:
|
|
93
108
|
`npx @parcha/agentrun import` brings in your local Claude Code, Codex and pi sessions, and
|
|
94
109
|
`npx @parcha/agentrun reset-password` clears the console's password. `--data DIR` and `--port N` change where it keeps
|
|
95
110
|
its data and the port it takes.
|
package/install.sh
CHANGED
|
@@ -19,6 +19,14 @@
|
|
|
19
19
|
# Either way it returns once AgentRun answers, and prints its address. With --tailscale it is also served over HTTPS on
|
|
20
20
|
# the person's own tailnet (lib/tailscale.mjs), on port 7340. Options: --help.
|
|
21
21
|
#
|
|
22
|
+
# With --vps it sets up a Linux server someone rents (Ubuntu or Debian, as root) in place of this user's install: Docker
|
|
23
|
+
# Engine and its compose plugin from Docker's apt repository when Docker is missing (an existing Docker is never
|
|
24
|
+
# changed), then /opt/agentrun with a compose file and an .env (mode 600) holding the API token and the seal key, made
|
|
25
|
+
# once and kept. Docker Compose runs the release's published server image with this machine's Docker socket, so a run's
|
|
26
|
+
# computer can be a Docker sandbox. It is private: on the person's tailnet when Tailscale is logged in (the same
|
|
27
|
+
# lib/tailscale.mjs, run in that image with this machine's tailscale and its socket), else on loopback with the steps to
|
|
28
|
+
# add Tailscale; on every address only with --public. Running it again upgrades to the release it names.
|
|
29
|
+
#
|
|
22
30
|
# The whole script is one function, called on its last line, so a download cut short runs nothing.
|
|
23
31
|
|
|
24
32
|
set -eu
|
|
@@ -31,23 +39,37 @@ main() {
|
|
|
31
39
|
node_version=
|
|
32
40
|
start=default
|
|
33
41
|
ts_flag=
|
|
42
|
+
vps=
|
|
43
|
+
vps_public=
|
|
44
|
+
image=
|
|
45
|
+
this_computer=
|
|
34
46
|
|
|
35
47
|
while [ $# -gt 0 ]; do
|
|
36
48
|
case $1 in
|
|
37
49
|
--version) [ $# -ge 2 ] || fail "--version takes a version or npm tag"; version=$2; shift ;;
|
|
38
50
|
--version=*) version=${1#--version=} ;;
|
|
39
|
-
--package) [ $# -ge 2 ] || fail "--package takes a tarball"; tarball=$2; shift ;;
|
|
40
|
-
--package=*) tarball=${1#--package=} ;;
|
|
41
|
-
--node-version) [ $# -ge 2 ] || fail "--node-version takes a Node.js version"; node_version=${2#v}; shift ;;
|
|
42
|
-
--node-version=*) node_version=${1#--node-version=}; node_version=${node_version#v} ;;
|
|
43
|
-
--no-start) start=none ;;
|
|
44
|
-
--service) start=service ;;
|
|
45
|
-
--tailscale | --no-tailscale) ts_flag=$1 ;;
|
|
51
|
+
--package) [ $# -ge 2 ] || fail "--package takes a tarball"; tarball=$2; this_computer=--package; shift ;;
|
|
52
|
+
--package=*) tarball=${1#--package=}; this_computer=--package ;;
|
|
53
|
+
--node-version) [ $# -ge 2 ] || fail "--node-version takes a Node.js version"; node_version=${2#v}; this_computer=--node-version; shift ;;
|
|
54
|
+
--node-version=*) node_version=${1#--node-version=}; node_version=${node_version#v}; this_computer=--node-version ;;
|
|
55
|
+
--no-start) start=none; this_computer=$1 ;;
|
|
56
|
+
--service) start=service; this_computer=$1 ;;
|
|
57
|
+
--tailscale | --no-tailscale) ts_flag=$1; this_computer=$1 ;;
|
|
58
|
+
--vps) vps=1 ;;
|
|
59
|
+
--public) vps_public=1 ;;
|
|
60
|
+
--image) [ $# -ge 2 ] || fail "--image takes an image"; image=$2; shift ;;
|
|
61
|
+
--image=*) image=${1#--image=} ;;
|
|
46
62
|
-h | --help) usage; return 0 ;;
|
|
47
63
|
*) fail "unknown option $1 (see --help)" ;;
|
|
48
64
|
esac
|
|
49
65
|
shift
|
|
50
66
|
done
|
|
67
|
+
if [ -n "$vps" ]; then
|
|
68
|
+
[ -z "$this_computer" ] || fail "$this_computer is for an install on this computer; --vps runs AgentRun in Docker (see --help)"
|
|
69
|
+
vps_install
|
|
70
|
+
return 0
|
|
71
|
+
fi
|
|
72
|
+
[ -z "$vps_public$image" ] || fail "--public and --image go with --vps (see --help)"
|
|
51
73
|
if [ -n "$node_version" ] && ! printf '%s\n' "$node_version" | grep -qx '[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*'; then
|
|
52
74
|
fail "--node-version $node_version is not a Node.js version (X.Y.Z)"
|
|
53
75
|
fi
|
|
@@ -196,6 +218,20 @@ Options:
|
|
|
196
218
|
(tailscale serve, never Funnel; Tailscale must be installed and logged in, and it says how when
|
|
197
219
|
not); --no-tailscale takes it off
|
|
198
220
|
-h, --help this help
|
|
221
|
+
|
|
222
|
+
On a Linux server you rent (Ubuntu or Debian, as root):
|
|
223
|
+
|
|
224
|
+
curl -fsSL https://agentrun.ai/install | sh -s -- --vps
|
|
225
|
+
|
|
226
|
+
--vps AgentRun in Docker Compose in /opt/agentrun, its agents' shell in Docker sandboxes. It installs
|
|
227
|
+
Docker Engine from Docker's apt repository when Docker is missing, and serves AgentRun on your
|
|
228
|
+
tailnet when Tailscale is logged in; without Tailscale, AgentRun stays on this server's loopback and
|
|
229
|
+
the installer says how to add it. Running it again upgrades AgentRun and keeps its token and seal key.
|
|
230
|
+
The server gets this machine's Docker socket, which is root on it: keep the server for AgentRun alone
|
|
231
|
+
--public with --vps: listen on every address of the server, port 7340, over plain HTTP, in place of the
|
|
232
|
+
tailnet or loopback. AGENTRUN_PUBLIC_URL names the address when the server's own is not public
|
|
233
|
+
--image IMAGE with --vps: run IMAGE in place of the release's ghcr.io/parcha-ai/agentrun-server image
|
|
234
|
+
--version V with --vps: the release of that @parcha/agentrun version or tag (default: latest)
|
|
199
235
|
EOF
|
|
200
236
|
}
|
|
201
237
|
|
|
@@ -479,4 +515,275 @@ add_to_path() {
|
|
|
479
515
|
say " $line"
|
|
480
516
|
}
|
|
481
517
|
|
|
518
|
+
# --vps: AgentRun in Docker Compose in /opt/agentrun on a server someone rents, as root. As Coolify's and Dokploy's
|
|
519
|
+
# one-line installers do: Docker when it is missing, secrets made once with openssl into an .env that later runs keep.
|
|
520
|
+
vps_install() {
|
|
521
|
+
vps_dir=/opt/agentrun
|
|
522
|
+
port=7340
|
|
523
|
+
loopback=http://127.0.0.1:7340 # key-gate: loopback-rule the server it starts, on the loopback of this server
|
|
524
|
+
again="curl -fsSL https://agentrun.ai/install | sh -s -- --vps${vps_public:+ --public}"
|
|
525
|
+
[ "$(uname -s)" = Linux ] || fail "--vps sets up a Linux server; this is $(uname -s)"
|
|
526
|
+
[ "$(id -u)" = 0 ] || fail "--vps installs Docker and writes $vps_dir, so it runs as root: curl -fsSL https://agentrun.ai/install | sudo sh -s -- --vps${vps_public:+ --public}"
|
|
527
|
+
need curl
|
|
528
|
+
mkdir -p "$vps_dir/tailscale"
|
|
529
|
+
chmod 700 "$vps_dir" "$vps_dir/tailscale"
|
|
530
|
+
work=$(mktemp -d "$vps_dir/.install.XXXXXX")
|
|
531
|
+
trap 'rm -rf "$work"' EXIT
|
|
532
|
+
trap 'exit 130' INT
|
|
533
|
+
trap 'exit 143' TERM
|
|
534
|
+
vps_image
|
|
535
|
+
vps_docker
|
|
536
|
+
command -v openssl > /dev/null 2>&1 || vps_apt install openssl
|
|
537
|
+
|
|
538
|
+
if ! docker image inspect "$image" > /dev/null 2>&1; then
|
|
539
|
+
say "Pulling $image ..."
|
|
540
|
+
docker pull -q "$image" > /dev/null || fail "could not pull $image"
|
|
541
|
+
fi
|
|
542
|
+
|
|
543
|
+
# Where it is reached: every address with --public; else the tailnet's https address when Tailscale is logged in, or
|
|
544
|
+
# this server's loopback, with the steps to add Tailscale said.
|
|
545
|
+
bind=127.0.0.1 # key-gate: loopback-rule the port is published on the loopback of this server unless --public
|
|
546
|
+
trusted=
|
|
547
|
+
if [ -n "$vps_public" ]; then
|
|
548
|
+
bind=0.0.0.0
|
|
549
|
+
url=${AGENTRUN_PUBLIC_URL:-}
|
|
550
|
+
if [ -z "$url" ]; then
|
|
551
|
+
address=$(ip -4 route get 1.1.1.1 2> /dev/null | sed -n 's/.* src \([0-9.]*\).*/\1/p' | head -n 1)
|
|
552
|
+
[ -n "$address" ] || fail "--public: this server's IPv4 address is unknown (ip route get); name it, then run again: curl -fsSL https://agentrun.ai/install | AGENTRUN_PUBLIC_URL=http://<address>:$port/ sh -s -- --vps --public"
|
|
553
|
+
url=http://$address:$port/
|
|
554
|
+
fi
|
|
555
|
+
say "--public: AgentRun listens on every address of this server, port $port, over plain HTTP, at $url"
|
|
556
|
+
say " Anyone who reaches that address reaches its console and API, and the setup code, your password and the API"
|
|
557
|
+
say " token cross the network unencrypted. Run again without --public to use Tailscale, or put a TLS proxy in front."
|
|
558
|
+
else
|
|
559
|
+
url=$(vps_tailnet address) || exit 1
|
|
560
|
+
if [ -n "$url" ]; then
|
|
561
|
+
# tailscale serve reaches the server through Docker's bridge, a private range, and names each visitor.
|
|
562
|
+
trusted=uniquelocal
|
|
563
|
+
else
|
|
564
|
+
url=$loopback/
|
|
565
|
+
fi
|
|
566
|
+
fi
|
|
567
|
+
|
|
568
|
+
vps_files
|
|
569
|
+
say "Starting AgentRun $release in Docker Compose ($vps_dir) ..."
|
|
570
|
+
if ! vps_compose up -d --wait --wait-timeout 300 > "$work/up.log" 2>&1; then
|
|
571
|
+
tail -n 20 "$work/up.log" >&2
|
|
572
|
+
vps_compose logs --no-color --tail 40 agentrun >&2 || true
|
|
573
|
+
fail "AgentRun did not come up healthy within 5 minutes (the lines above say why; cd $vps_dir && docker compose logs has them all)"
|
|
574
|
+
fi
|
|
575
|
+
|
|
576
|
+
# Its first visit must ask for the setup code: a server that would take a password from anyone is stopped.
|
|
577
|
+
host=${url#*://}
|
|
578
|
+
host=${host%%/*}
|
|
579
|
+
session=$(curl -fsS --max-time 10 -H "Host: $host" "$loopback/v2/auth/session") || session=
|
|
580
|
+
owned=
|
|
581
|
+
case $session in
|
|
582
|
+
*'"password_set":true'* | *'"password_set": true'*) owned=1 ;;
|
|
583
|
+
*'"setup_code":true'* | *'"setup_code": true'*) ;;
|
|
584
|
+
*)
|
|
585
|
+
vps_compose stop > /dev/null 2>&1 || true
|
|
586
|
+
fail "AgentRun answered with no setup code asked (${session:-no answer}), so whoever reached it first could take it; it was stopped"
|
|
587
|
+
;;
|
|
588
|
+
esac
|
|
589
|
+
|
|
590
|
+
if [ "$trusted" = uniquelocal ]; then
|
|
591
|
+
vps_tailnet serve "$url" "\`docker compose logs\` in $vps_dir" || exit 1
|
|
592
|
+
fi
|
|
593
|
+
|
|
594
|
+
say ""
|
|
595
|
+
say "AgentRun $release is running at $url"
|
|
596
|
+
if [ "$bind" != 0.0.0.0 ] && [ -z "$trusted" ]; then
|
|
597
|
+
say "It is on this server only. From your computer: ssh -N -L $port:127.0.0.1:$port root@<this server>, then open $url" # key-gate: loopback-rule the ssh tunnel line to the loopback port
|
|
598
|
+
fi
|
|
599
|
+
if [ -n "$owned" ]; then
|
|
600
|
+
say "This server has its owner: sign in at $url"
|
|
601
|
+
else
|
|
602
|
+
# A good code is kept and a new one printed only when the last is expired or spent (POST /v2/setup/code).
|
|
603
|
+
curl -fsS --max-time 10 -X POST -H "Host: $host" "$loopback/v2/setup/code" > /dev/null 2>&1 || true
|
|
604
|
+
line=
|
|
605
|
+
waited=0
|
|
606
|
+
while [ -z "$line" ] && [ "$waited" -lt 10 ]; do
|
|
607
|
+
line=$(vps_compose logs --no-color --no-log-prefix agentrun 2> /dev/null | sed -n 's/.*\(Set up this server: .*\)$/\1/p' | tail -n 1)
|
|
608
|
+
[ -n "$line" ] || sleep 1
|
|
609
|
+
waited=$((waited + 1))
|
|
610
|
+
done
|
|
611
|
+
say "${line:-Set up this server: its link is in the log (below)}"
|
|
612
|
+
say "The code works once, for 30 minutes. Read the newest one later: cd $vps_dir && docker compose logs agentrun | grep 'Set up this server' | tail -n 1"
|
|
613
|
+
fi
|
|
614
|
+
say "The API token is AGENTRUN_TOKEN in $vps_dir/.env. Agents get a shell in Docker sandboxes on this server: AgentRun has"
|
|
615
|
+
say "its Docker socket, which is root here, so keep this server for AgentRun alone."
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
# The image of the release asked for: the server the launcher of that version (or tag) depends on, whose release tag is
|
|
619
|
+
# v<that version>. --image names one in its place.
|
|
620
|
+
vps_image() {
|
|
621
|
+
if [ -n "$image" ]; then
|
|
622
|
+
release=$image
|
|
623
|
+
return 0
|
|
624
|
+
fi
|
|
625
|
+
case $version in *[!A-Za-z0-9.+-]*) fail "--version $version is not a version or npm tag" ;; esac
|
|
626
|
+
manifest=$(download "$registry/@parcha%2fagentrun/$version") || fail "$package has no version or tag $version on $registry"
|
|
627
|
+
server=$(printf '%s' "$manifest" | tr ',{}' '\n\n\n' | sed -n 's/^"@parcha\/agentrun-serve":"\([^"]*\)"$/\1/p' | sort -u)
|
|
628
|
+
case $server in "" | *[!A-Za-z0-9.+-]*) fail "$package $version names no single server version (@parcha/agentrun-serve)" ;; esac
|
|
629
|
+
release=v$server
|
|
630
|
+
image=ghcr.io/parcha-ai/agentrun-server:$release
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
# Docker Engine 26 or later with its compose plugin: one already here is used as it is, never changed; with none, Docker
|
|
634
|
+
# Engine from Docker's own apt repository, as https://docs.docker.com/engine/install/ubuntu/ (and debian/) set it up.
|
|
635
|
+
vps_docker() {
|
|
636
|
+
if command -v docker > /dev/null 2>&1; then
|
|
637
|
+
engine=$(docker version --format '{{.Server.Version}}' 2> /dev/null) ||
|
|
638
|
+
fail "Docker is installed here, and its daemon does not answer (docker version). Start it (systemctl start docker), then run again: $again"
|
|
639
|
+
say "Docker Engine $engine is already here; the installer leaves it as it is."
|
|
640
|
+
else
|
|
641
|
+
vps_install_docker
|
|
642
|
+
fi
|
|
643
|
+
major=${engine%%.*}
|
|
644
|
+
case $major in "" | *[!0-9]*) fail "Docker says its version is $engine, which is not Docker Engine's" ;; esac
|
|
645
|
+
[ "$major" -ge 26 ] || fail "Docker sandboxes need Docker Engine 26 or later (a named volume's subpath), and this one is $engine. Upgrade it, then run again: $again"
|
|
646
|
+
compose=$(docker compose version --short 2> /dev/null) ||
|
|
647
|
+
fail "This Docker has no compose plugin (docker compose). Install it (https://docs.docker.com/compose/install/linux/), then run again: $again"
|
|
648
|
+
say "Docker Compose $compose"
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
vps_install_docker() {
|
|
652
|
+
[ -r /etc/os-release ] || fail "Docker is not installed, and this server has no /etc/os-release to say which Linux it is. Install Docker Engine 26 or later with its compose plugin (https://docs.docker.com/engine/install/), then run again: $again"
|
|
653
|
+
distro=$(. /etc/os-release && printf '%s' "${ID:-}")
|
|
654
|
+
codename=$(. /etc/os-release && printf '%s' "${UBUNTU_CODENAME:-${VERSION_CODENAME:-}}")
|
|
655
|
+
case $distro in
|
|
656
|
+
ubuntu | debian) ;;
|
|
657
|
+
*) fail "Docker is not installed, and the installer installs it on Ubuntu or Debian only (this is ${distro:-unknown}). Install Docker Engine 26 or later with its compose plugin (https://docs.docker.com/engine/install/), then run again: $again" ;;
|
|
658
|
+
esac
|
|
659
|
+
[ -n "$codename" ] || fail "/etc/os-release names no release codename for Docker's apt repository"
|
|
660
|
+
repo=https://download.docker.com/linux/$distro
|
|
661
|
+
say "Installing Docker Engine and its compose plugin from Docker's apt repository ($repo) ..."
|
|
662
|
+
vps_apt update
|
|
663
|
+
vps_apt install ca-certificates
|
|
664
|
+
if grep -qs download.docker.com /etc/apt/sources.list /etc/apt/sources.list.d/*; then
|
|
665
|
+
say "Docker's apt repository is already in this server's apt sources; installing from it."
|
|
666
|
+
else
|
|
667
|
+
install -m 0755 -d /etc/apt/keyrings
|
|
668
|
+
download "$repo/gpg" > "$work/docker.asc" || fail "could not download $repo/gpg"
|
|
669
|
+
install -m 0644 "$work/docker.asc" /etc/apt/keyrings/docker.asc
|
|
670
|
+
printf 'Types: deb\nURIs: %s\nSuites: %s\nComponents: stable\nArchitectures: %s\nSigned-By: /etc/apt/keyrings/docker.asc\n' \
|
|
671
|
+
"$repo" "$codename" "$(dpkg --print-architecture)" > "$work/docker.sources"
|
|
672
|
+
install -m 0644 "$work/docker.sources" /etc/apt/sources.list.d/docker.sources
|
|
673
|
+
vps_apt update
|
|
674
|
+
fi
|
|
675
|
+
vps_apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
|
|
676
|
+
waited=0
|
|
677
|
+
until engine=$(docker version --format '{{.Server.Version}}' 2> /dev/null); do
|
|
678
|
+
[ "$waited" -lt 30 ] || fail "Docker Engine is installed, and its daemon does not answer (systemctl status docker says why)"
|
|
679
|
+
sleep 1
|
|
680
|
+
waited=$((waited + 1))
|
|
681
|
+
done
|
|
682
|
+
say "Installed Docker Engine $engine"
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
vps_apt() {
|
|
686
|
+
if ! DEBIAN_FRONTEND=noninteractive apt-get -y -qq -o Dpkg::Use-Pty=0 "$@" > "$work/apt.log" 2>&1; then
|
|
687
|
+
tail -n 20 "$work/apt.log" >&2
|
|
688
|
+
fail "apt-get $* failed (its last lines are above)"
|
|
689
|
+
fi
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
# Compose reads the shell's variables before .env: those it reads here come from .env alone, and its files from here.
|
|
693
|
+
vps_compose() { (cd "$vps_dir" && unset AGENTRUN_IMAGE AGENTRUN_BIND DOCKER_GID AGENTRUN_SEAL_KEY AGENTRUN_TOKEN AGENTRUN_PUBLIC_URL AGENTRUN_TRUSTED_PROXIES COMPOSE_FILE COMPOSE_PROJECT_NAME COMPOSE_PROFILES COMPOSE_ENV_FILES && docker compose "$@"); }
|
|
694
|
+
|
|
695
|
+
# lib/tailscale.mjs of the image, run in it as root with this server's tailscale and its socket: `address`, or `serve URL
|
|
696
|
+
# LOG`. Its record of the serve entry is kept in $vps_dir/tailscale.
|
|
697
|
+
vps_tailnet() {
|
|
698
|
+
verb=$1
|
|
699
|
+
shift
|
|
700
|
+
ts=$(command -v tailscale 2> /dev/null) || ts=
|
|
701
|
+
sock=
|
|
702
|
+
[ -z "$ts" ] || [ ! -d /var/run/tailscale ] || sock=/var/run/tailscale
|
|
703
|
+
docker run --rm --network none --user 0:0 -e HOME=/root -v "$vps_dir/tailscale:/root/.agentrun" \
|
|
704
|
+
${ts:+-v} ${ts:+"$ts:/usr/local/bin/tailscale:ro"} ${sock:+-v} ${sock:+"$sock:$sock"} \
|
|
705
|
+
--entrypoint node "$image" /opt/agentrun/packages/agentrun/lib/tailscale.mjs "$verb" "$port" "$again" "$@"
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
# .env: the token and the seal key made once and kept, then the settings this run chose; any other line stays as it is.
|
|
709
|
+
# compose.yaml: written again on every run (changes of one's own go in compose.override.yaml beside it).
|
|
710
|
+
vps_files() {
|
|
711
|
+
env_file=$vps_dir/.env
|
|
712
|
+
token=$(sed -n 's/^AGENTRUN_TOKEN=//p' "$env_file" 2> /dev/null | tail -n 1)
|
|
713
|
+
seal=$(sed -n 's/^AGENTRUN_SEAL_KEY=//p' "$env_file" 2> /dev/null | tail -n 1)
|
|
714
|
+
made=
|
|
715
|
+
if [ -z "$token" ]; then
|
|
716
|
+
token=$(openssl rand -hex 32)
|
|
717
|
+
made="the API token"
|
|
718
|
+
fi
|
|
719
|
+
if [ -z "$seal" ]; then
|
|
720
|
+
seal=$(openssl rand -base64 32)
|
|
721
|
+
made="${made:+$made and }the seal key"
|
|
722
|
+
fi
|
|
723
|
+
[ -n "$token" ] && [ -n "$seal" ] || fail "openssl made no API token or seal key"
|
|
724
|
+
gid=$(stat -c %g /var/run/docker.sock) || fail "this Docker has no /var/run/docker.sock to give AgentRun"
|
|
725
|
+
{
|
|
726
|
+
if [ -f "$env_file" ]; then
|
|
727
|
+
grep -v -E '^(AGENTRUN_TOKEN|AGENTRUN_SEAL_KEY|AGENTRUN_IMAGE|AGENTRUN_BIND|AGENTRUN_PUBLIC_URL|AGENTRUN_TRUSTED_PROXIES|DOCKER_GID)=' "$env_file" || true
|
|
728
|
+
else
|
|
729
|
+
echo "# AgentRun's settings for Docker Compose. The installer (--vps) keeps AGENTRUN_TOKEN and AGENTRUN_SEAL_KEY, and"
|
|
730
|
+
echo "# writes the lines after them on every run. Lines of your own (a model key, AGENTRUN_BOX_ALLOW) stay; keep this"
|
|
731
|
+
echo "# file's seal key: every saved secret is sealed under it."
|
|
732
|
+
fi
|
|
733
|
+
printf 'AGENTRUN_TOKEN=%s\n' "$token"
|
|
734
|
+
printf 'AGENTRUN_SEAL_KEY=%s\n' "$seal"
|
|
735
|
+
printf 'AGENTRUN_IMAGE=%s\n' "$image"
|
|
736
|
+
printf 'AGENTRUN_BIND=%s\n' "$bind"
|
|
737
|
+
printf 'AGENTRUN_PUBLIC_URL=%s\n' "$url"
|
|
738
|
+
printf 'AGENTRUN_TRUSTED_PROXIES=%s\n' "$trusted"
|
|
739
|
+
printf 'DOCKER_GID=%s\n' "$gid"
|
|
740
|
+
} > "$work/env"
|
|
741
|
+
chmod 600 "$work/env"
|
|
742
|
+
mv -f "$work/env" "$env_file"
|
|
743
|
+
if [ -n "$made" ]; then
|
|
744
|
+
say "Made $made in $env_file (mode 600), kept on every later run"
|
|
745
|
+
else
|
|
746
|
+
say "Kept the API token and the seal key in $env_file"
|
|
747
|
+
fi
|
|
748
|
+
|
|
749
|
+
cat > "$work/compose.yaml" << 'EOF'
|
|
750
|
+
# AgentRun, written by its installer (curl -fsSL https://agentrun.ai/install | sh -s -- --vps) on every run: put changes
|
|
751
|
+
# of your own in compose.override.yaml beside this file, which Docker Compose reads too. .env holds the settings.
|
|
752
|
+
#
|
|
753
|
+
# The server gets this server's Docker socket, so a run's computer can be a Docker sandbox: a container beside the
|
|
754
|
+
# server's, with no socket, every capability dropped, no network but its egress proxy, and of the data volume only its
|
|
755
|
+
# run's folder. Whatever reaches that socket is root on this server: keep the server for AgentRun alone.
|
|
756
|
+
name: agentrun
|
|
757
|
+
services:
|
|
758
|
+
agentrun:
|
|
759
|
+
image: ${AGENTRUN_IMAGE:?run the installer again}
|
|
760
|
+
ports:
|
|
761
|
+
- "${AGENTRUN_BIND:?run the installer again}:7340:7340"
|
|
762
|
+
volumes:
|
|
763
|
+
- agentrun-data:/data
|
|
764
|
+
- /var/run/docker.sock:/var/run/docker.sock
|
|
765
|
+
group_add:
|
|
766
|
+
- "${DOCKER_GID:?run the installer again}"
|
|
767
|
+
healthcheck:
|
|
768
|
+
test: ["CMD", "node", "-e", "fetch('http://127.0.0.1:7340/v2/health').then(({ ok, status }) => { if (!ok) throw new Error(String(status)) })"] # key-gate: loopback-rule the servers own loopback, its health check
|
|
769
|
+
interval: 30s
|
|
770
|
+
timeout: 5s
|
|
771
|
+
retries: 3
|
|
772
|
+
start_period: 60s
|
|
773
|
+
start_interval: 2s
|
|
774
|
+
# Every line of .env reaches the server: the installer's, and a model key, a price or AGENTRUN_BOX_ALLOW you add.
|
|
775
|
+
env_file: .env
|
|
776
|
+
environment:
|
|
777
|
+
AGENTRUN_BOXES: docker
|
|
778
|
+
AGENTRUN_SEAL_KEY: ${AGENTRUN_SEAL_KEY:?run the installer again}
|
|
779
|
+
AGENTRUN_TOKEN: ${AGENTRUN_TOKEN:?run the installer again}
|
|
780
|
+
AGENTRUN_PUBLIC_URL: ${AGENTRUN_PUBLIC_URL:?run the installer again}
|
|
781
|
+
restart: unless-stopped
|
|
782
|
+
stop_grace_period: 15s
|
|
783
|
+
volumes:
|
|
784
|
+
agentrun-data:
|
|
785
|
+
EOF
|
|
786
|
+
mv -f "$work/compose.yaml" "$vps_dir/compose.yaml"
|
|
787
|
+
}
|
|
788
|
+
|
|
482
789
|
main "$@"
|
package/lib/cli.mjs
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// OpenAPI document, read from the generated table (commands.generated.mjs); nothing here is written per command. Waiting for
|
|
3
3
|
// a run and following it live (runs start --wait, runs wait, runs timeline --follow) are follow.mjs's; the commands that
|
|
4
4
|
// read a secret from stdin (login, logout) are login.mjs's, skill install is skill.mjs's, and template
|
|
5
|
-
// validate and template eval, which check and run a package folder on this machine, are template.mjs's,
|
|
5
|
+
// validate and template eval, which check and run a package folder on this machine, are template.mjs's, harness install
|
|
6
|
+
// (the harness its owner installs: goose) is harness.mjs's, and service
|
|
6
7
|
// (AgentRun as a launchd or systemd user service) and stop (the AgentRun the installer started in the background) are
|
|
7
8
|
// service.mjs's.
|
|
8
9
|
import { closeSync, constants, fstatSync, openSync, readFileSync } from "node:fs";
|
|
@@ -15,9 +16,10 @@ import { SECRETS, guarded, refusalExit } from "./login.mjs";
|
|
|
15
16
|
import { SERVICE, STOP } from "./service.mjs";
|
|
16
17
|
import { SKILL_INSTALL } from "./skill.mjs";
|
|
17
18
|
import { TEMPLATE_EVAL, TEMPLATE_INSTALL, TEMPLATE_VALIDATE } from "./template.mjs";
|
|
19
|
+
import { HARNESS_INSTALL } from "./harness.mjs";
|
|
18
20
|
|
|
19
21
|
/** The hand-written commands that run as they are given (`run`), beside the table's. */
|
|
20
|
-
const LOCAL = [...SECRETS, SKILL_INSTALL, TEMPLATE_VALIDATE, TEMPLATE_EVAL, TEMPLATE_INSTALL, ...SERVICE, STOP];
|
|
22
|
+
const LOCAL = [...SECRETS, SKILL_INSTALL, TEMPLATE_VALIDATE, TEMPLATE_EVAL, TEMPLATE_INSTALL, HARNESS_INSTALL, ...SERVICE, STOP];
|
|
21
23
|
export const NOUNS = new Set(["api", "help", ...[...COMMANDS, ...LOCAL].map((entry) => entry.command[0])]);
|
|
22
24
|
const DEFAULT_BASE_URL = "http://127.0.0.1:7340/v2"; // key-gate: loopback-rule the default address of the server started on this machine
|
|
23
25
|
const START = "start it with `npx @parcha/agentrun`, or pass --base-url (or set AGENTRUN_BASE_URL) to the address the server printed";
|