agentsdock 1.0.11-beta.1 → 1.0.11-beta.12
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/NOTICE +7 -0
- package/README.md +118 -38
- package/cli.cjs +9 -8
- package/package.json +2 -2
- package/pair.cjs +65 -25
- package/postinstall.cjs +74 -9
package/NOTICE
CHANGED
|
@@ -14,6 +14,13 @@ licenses, and attribution notices. In particular:
|
|
|
14
14
|
their package metadata.
|
|
15
15
|
- SwiftTerm retains its MIT license in
|
|
16
16
|
mobile-react/modules/agentsdock-native-terminal/ios/Vendor/SwiftTerm/LICENSE.
|
|
17
|
+
- The Gemini product icon in electron/src/renderer/public/backend-gemini.svg
|
|
18
|
+
is an unmodified Google asset, not covered by AgentsDock's Apache license.
|
|
19
|
+
Gemini and its icon are trademarks of Google LLC. Used only to identify the
|
|
20
|
+
supported provider; no Google endorsement or affiliation is implied.
|
|
21
|
+
Source: https://www.gstatic.com/lamda/images/gemini_sparkle_aurora_33f86dc0c0257da337c63.svg
|
|
22
|
+
Referenced by https://gemini.google.com/ (retrieved 2026-10-15).
|
|
23
|
+
Brand guidance: https://about.google/brand-resource-center/guidance/apis/
|
|
17
24
|
|
|
18
25
|
Dependencies and other bundled third-party materials remain subject to their
|
|
19
26
|
respective license terms. This notice does not replace those licenses.
|
package/README.md
CHANGED
|
@@ -8,9 +8,20 @@ supported.
|
|
|
8
8
|
|
|
9
9
|
## Install the command
|
|
10
10
|
|
|
11
|
+
Run these commands on the **server machine**, which can be the same computer as
|
|
12
|
+
your desktop app. Use Apple silicon macOS with a desktop login, or Linux with a
|
|
13
|
+
working user systemd session. Install [Node.js 22.14 or later with npm](https://nodejs.org/en/download)
|
|
14
|
+
and [uv](https://docs.astral.sh/uv/getting-started/installation/) for the Python
|
|
15
|
+
environment. Install **tmux** for persistent terminals and in-app managed
|
|
16
|
+
updates; basic chats work without it. On macOS with Homebrew, use
|
|
17
|
+
`brew install node uv tmux`. Run npm as the server owner without `sudo`.
|
|
18
|
+
Client-only devices do not need these prerequisites. The npm server installer
|
|
19
|
+
does not run natively on Windows.
|
|
20
|
+
|
|
11
21
|
```sh
|
|
12
22
|
npm install -g agentsdock@beta
|
|
13
23
|
agentsdock list
|
|
24
|
+
agentsdock token default
|
|
14
25
|
```
|
|
15
26
|
|
|
16
27
|
On a fresh machine, the global install automatically sets up and starts the
|
|
@@ -20,11 +31,20 @@ state, including named instances; repeat installs leave these unchanged and do
|
|
|
20
31
|
not restart, overwrite or upgrade a running service. The runtime lives in its
|
|
21
32
|
managed installation directory, independently of the npm package/cache.
|
|
22
33
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
34
|
+
Wait for installation to finish, then confirm `default` is `running` in
|
|
35
|
+
`agentsdock list`. No npm account is needed to install the public package.
|
|
36
|
+
Add its URL and the token from `agentsdock token default` in the separately
|
|
37
|
+
downloaded [AgentsDock app](https://agentsdock.net/#downloads). Keep the token
|
|
38
|
+
private. Use the listed local URL on the same computer, a LAN URL on the same
|
|
39
|
+
network, or a Tailscale URL on your private tailnet. `127.0.0.1` cannot reach
|
|
40
|
+
the server from another device.
|
|
41
|
+
|
|
42
|
+
Install and sign in to your preferred provider CLI on the server before
|
|
43
|
+
starting a chat. npm setup does not install provider CLIs or authenticate them.
|
|
44
|
+
|
|
45
|
+
For a beta, select `npm install -g agentsdock@beta`. Stable and beta packages are
|
|
46
|
+
published on npm. This checkout prepares the matched 1.0.11-beta.12 CLI/runtime;
|
|
47
|
+
its publication and native candidate acceptance are pending.
|
|
28
48
|
|
|
29
49
|
`-g` makes the command available outside the current project when npm's global
|
|
30
50
|
bin directory is on your PATH. A local `npm install agentsdock` is also supported;
|
|
@@ -33,17 +53,26 @@ installs, linked source checkouts, CI installs and npx do not automatically star
|
|
|
33
53
|
a service. Use `npx agentsdock setup` when you deliberately want a server from a
|
|
34
54
|
local install. No installation changes shell configuration or logs into a provider.
|
|
35
55
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
setup
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
56
|
+
`setup` (also `install`) refuses to overwrite an existing default installation
|
|
57
|
+
or history. Global auto setup uses the same prerequisites; it does not install
|
|
58
|
+
uv, Homebrew, provider CLIs or Tailscale automatically. If a prerequisite is
|
|
59
|
+
missing, install it and check it in the same terminal before retrying
|
|
60
|
+
`agentsdock setup`; if the CLI was not installed, rerun the npm install command.
|
|
61
|
+
|
|
62
|
+
The connection-output improvements below are included starting in
|
|
63
|
+
1.0.11-beta.2. With 1.0.10 or 1.0.11-beta.1, use `agentsdock list` and
|
|
64
|
+
`agentsdock token default` even if npm's installation output does not show
|
|
65
|
+
connection details.
|
|
66
|
+
|
|
67
|
+
With the improved output, a successful first setup shows the default server URL,
|
|
68
|
+
access token and a scannable terminal QR together, even when npm hides successful
|
|
69
|
+
lifecycle output. The QR includes reachable LAN/Tailscale addresses after
|
|
70
|
+
authenticated health checks. Keep the token and QR private. Raw installer output and access tokens
|
|
71
|
+
are not copied into npm's captured output/debug logs. Headless installations
|
|
72
|
+
without a controlling terminal show only a non-secret summary; use
|
|
73
|
+
`agentsdock token default` explicitly to retrieve a token later. Reinstalling
|
|
74
|
+
over existing server state remains a no-op, not a setup or restart.
|
|
75
|
+
`--foreground-scripts` can still help display non-secret lifecycle diagnostics.
|
|
47
76
|
A failed auto setup makes npm report failure instead of claiming the server is
|
|
48
77
|
ready. To obtain interactive diagnostics or choose a custom port/bind:
|
|
49
78
|
|
|
@@ -63,6 +92,14 @@ This lexical filter does not resolve symlink aliases or authenticate executables
|
|
|
63
92
|
It prevents new temporary npm-path dependencies; it does not rewrite the saved
|
|
64
93
|
PATH of an already-installed server or change managed-update policy.
|
|
65
94
|
|
|
95
|
+
To show the connection details again, run `agentsdock token`: choose the server
|
|
96
|
+
and its URLs, token and QR appear together. Use `agentsdock token default` to skip
|
|
97
|
+
the chooser, or `agentsdock pair default` for just the addresses and QR. These
|
|
98
|
+
commands are read-only and require no source-checkout path. Interactive
|
|
99
|
+
`agentsdock setup` and `agentsdock new work` also show the connection details on
|
|
100
|
+
success. If the server is local-only or not reachable yet, setup still succeeds
|
|
101
|
+
and explains how to generate the QR after networking is ready.
|
|
102
|
+
|
|
66
103
|
## Manage servers
|
|
67
104
|
|
|
68
105
|
```sh
|
|
@@ -70,6 +107,7 @@ agentsdock list
|
|
|
70
107
|
agentsdock status
|
|
71
108
|
agentsdock new work --port 7854 --bind 127.0.0.1
|
|
72
109
|
agentsdock status work
|
|
110
|
+
agentsdock logs work
|
|
73
111
|
agentsdock token
|
|
74
112
|
agentsdock token work
|
|
75
113
|
agentsdock pair work
|
|
@@ -90,7 +128,9 @@ Without a name, `agentsdock token` lists this OS user's existing servers on the
|
|
|
90
128
|
machine (including stopped instances). Use Up/Down arrows to highlight a server
|
|
91
129
|
and Enter to select it; Esc, Ctrl+C or Ctrl+D cancels without showing a token.
|
|
92
130
|
The menu scrolls when needed and restores terminal input before showing a token.
|
|
93
|
-
It displays
|
|
131
|
+
It displays the selected server's connection URLs alongside its token, retaining
|
|
132
|
+
the optional clipboard prompt. Verified Tailscale addresses appear first;
|
|
133
|
+
local-only bindings are never advertised as reachable from another device.
|
|
94
134
|
Basic terminals without cursor control retain the numbered/name prompt, where
|
|
95
135
|
empty input cancels. Even a single server requires confirmation. In a script or with
|
|
96
136
|
redirected output, select explicitly: `agentsdock token default` or
|
|
@@ -98,7 +138,12 @@ redirected output, select explicitly: `agentsdock token default` or
|
|
|
98
138
|
explicitly if another device needs access.
|
|
99
139
|
|
|
100
140
|
`agentsdock status` prints a separate readable block for every instance: status,
|
|
101
|
-
addresses, installed version and port.
|
|
141
|
+
addresses, installed version and port. In an interactive terminal it then asks
|
|
142
|
+
whether to view a token. Answer `y`, use Up/Down and Enter to select a server,
|
|
143
|
+
and its URL/token appear together. Declining or cancelling shows no token.
|
|
144
|
+
`agentsdock status work` limits both the summary and picker to that instance.
|
|
145
|
+
Redirected/non-interactive status never prompts or prints tokens; explicitly
|
|
146
|
+
named `agentsdock token work` still outputs only the token when redirected.
|
|
102
147
|
The status is the native service-manager state, not an authenticated health probe;
|
|
103
148
|
the version comes from that instance's installed runtime, not the npm CLI package.
|
|
104
149
|
`agentsdock info work` retains JSON output. If `setup` finds an existing default
|
|
@@ -114,34 +159,66 @@ Busy work, pending updates, changed native registrations or uncertain ownership
|
|
|
114
159
|
prevent a forced stop. Interrupted operations retain an owned retry journal;
|
|
115
160
|
follow the command's retry guidance rather than deleting it manually.
|
|
116
161
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
162
|
+
See the repository's [release validation record](../../../docs/NPM_CLI_RELEASES.md)
|
|
163
|
+
for exact-package native setup, lifecycle and removal acceptance. Source tests
|
|
164
|
+
alone do not establish native service operation.
|
|
165
|
+
|
|
166
|
+
## Read service logs
|
|
120
167
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
168
|
+
Service logs are available starting in 1.0.11-beta.2, not in 1.0.10 or
|
|
169
|
+
1.0.11-beta.1.
|
|
170
|
+
|
|
171
|
+
```sh
|
|
172
|
+
agentsdock logs # Default server: recent entries, then exit
|
|
173
|
+
agentsdock logs work # One named server; find names with agentsdock list
|
|
174
|
+
agentsdock logs work --lines 20 # -n 20 also works
|
|
175
|
+
agentsdock logs work --follow # -f also works; Ctrl+C stops only this viewer
|
|
176
|
+
agentsdock logs work -n 0 -f # Only entries arriving after viewing starts
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Run on the server machine as its OS user; this is not a remote log-download API.
|
|
180
|
+
The default is 100 lines, with a range of 0–10,000. macOS shows separate stdout
|
|
181
|
+
and stderr sections (the last N lines per file, with a 1 MiB initial-read cap).
|
|
182
|
+
Split default installations include both gateway and worker logs. Linux uses
|
|
183
|
+
the current user's journal and shows the last N entries across the selected
|
|
184
|
+
instance's units, without a pager. Log sources follow the installed layout,
|
|
185
|
+
not the CLI's version. Missing/empty Mac log files are reported and watched if
|
|
186
|
+
following; unsafe paths fail rather than being followed. Nothing is restarted
|
|
187
|
+
or installed, and no token/configuration file is printed. Service log entries
|
|
188
|
+
can still contain private data; review them before sharing. macOS control
|
|
189
|
+
characters are escaped for terminal safety, not credential redaction.
|
|
127
190
|
|
|
128
191
|
## Connect a phone by QR
|
|
129
192
|
|
|
130
193
|
```sh
|
|
131
194
|
agentsdock pair # default instance
|
|
132
|
-
agentsdock pair work # terminal QR
|
|
195
|
+
agentsdock pair work # terminal QR with Tailscale and LAN candidates
|
|
133
196
|
agentsdock pair work --network lan # same Wi-Fi/LAN
|
|
134
197
|
agentsdock pair work --output connection.png
|
|
135
198
|
```
|
|
136
199
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
200
|
+
For URLs, the token and a terminal QR in one interactive display, use
|
|
201
|
+
`agentsdock token work`. Redirected token output remains token-only.
|
|
202
|
+
|
|
203
|
+
In a mobile build with pairing support, open **Servers > Add server > Scan QR code**,
|
|
204
|
+
allow camera access, and scan the terminal. Review the scanned server name and URL;
|
|
205
|
+
authenticated health and the QR's server identity must match before **Add** is
|
|
206
|
+
enabled. Tap **Add** to save and switch. A saved identity reuses the existing
|
|
207
|
+
profile. Manual entry remains available; image import and connection deep links
|
|
208
|
+
are not enabled on mobile.
|
|
209
|
+
|
|
210
|
+
Interactive setup and token display also show a connection QR when a reachable
|
|
211
|
+
address passes authenticated health. Fresh global npm installation writes the QR
|
|
212
|
+
only to the controlling terminal, never to captured npm logs. Headless setup emits
|
|
213
|
+
no QR. A missing camera-reachable address or failed QR generation does not fail
|
|
214
|
+
installation; use `agentsdock pair` once networking is ready. This requires the
|
|
215
|
+
updated server/CLI package and does not change existing published versions.
|
|
216
|
+
|
|
217
|
+
Automatic mode includes up to six discovered LAN/Tailscale addresses that pass
|
|
218
|
+
authenticated health with the same identity. Mobile tries these addresses and
|
|
219
|
+
retains alternatives for reconnect. `--url http://192.168.1.20:7851` restricts the
|
|
220
|
+
QR to one listed address; arbitrary URLs are rejected. Conflicting identities
|
|
221
|
+
fail closed. Older single-address QRs remain supported by updated mobile apps.
|
|
145
222
|
|
|
146
223
|
`qrcode` is an alias for `pair`. `--link` explicitly prints the credential-bearing
|
|
147
224
|
`agentsdock://connect#...` URL instead of a QR. Treat the link/image like the
|
|
@@ -153,7 +230,7 @@ Both devices must be on a reachable LAN or private Tailscale network. A server
|
|
|
153
230
|
bound only to localhost cannot connect to a physical phone; automatic selection
|
|
154
231
|
refuses that case. `--network local` is an explicit same-computer/simulator test
|
|
155
232
|
option. `--network tailscale` requires a confirmed Tailscale address and binding.
|
|
156
|
-
The QR includes the identity returned by authenticated health at the
|
|
233
|
+
The QR includes the identity returned by authenticated health at the included URLs.
|
|
157
234
|
|
|
158
235
|
## Complete public command comparison
|
|
159
236
|
|
|
@@ -169,6 +246,7 @@ mailbox/jobs/team tools supplied to agents inside an authorized chat.
|
|
|
169
246
|
| All instance statuses, addresses, versions and ports | `./instances.sh status` | `agentsdock status` (separate blocks) |
|
|
170
247
|
| One instance's readable status | `./instances.sh status work` | `agentsdock status work` |
|
|
171
248
|
| One instance's details as JSON | `./instances.sh info work` | `agentsdock info work` |
|
|
249
|
+
| Recent service logs | Platform-specific `tail` / `journalctl` | `agentsdock logs [NAME]` |
|
|
172
250
|
| New automatic name/free port | `./instances.sh new` | `agentsdock new` |
|
|
173
251
|
| New named instance | `./instances.sh new --name work --port 7854` | `agentsdock new work --port 7854` |
|
|
174
252
|
| Start one | `./instances.sh start work` | `agentsdock start work` |
|
|
@@ -197,6 +275,8 @@ Supported options retain their native meanings:
|
|
|
197
275
|
- `remove`/`uninstall`: also `--yes` and `--purge-state`. Purge retains the native
|
|
198
276
|
interactive confirmation and cannot be made unattended with `--yes`.
|
|
199
277
|
- `token`/`status`: positional name or `--instance NAME`, never both.
|
|
278
|
+
- `logs`: optional name or `--instance NAME` (default: `default`), `-n`/`--lines`
|
|
279
|
+
and `-f`/`--follow`. No bulk selector or arbitrary log path.
|
|
200
280
|
- `update`: the six required arguments in the example below. Bare `update` or
|
|
201
281
|
`update work` does not select a registry tag or silently restart a server.
|
|
202
282
|
|
|
@@ -213,7 +293,7 @@ Differences from the old source scripts:
|
|
|
213
293
|
changing the port of an existing installation; manifest-based bulk creation
|
|
214
294
|
(`./instances.sh install --manifest ...`); Team Hub configuration/reactivation;
|
|
215
295
|
foreground development `python agent_server.py serve`. There are no implemented
|
|
216
|
-
`agentsdock configure`, `agentsdock
|
|
296
|
+
`agentsdock configure`, `agentsdock login`, or `agentsdock serve`
|
|
217
297
|
commands in this package.
|
|
218
298
|
- Direct checkout reinstalls (`./instances.sh update`, installer's version or
|
|
219
299
|
custom-root overrides) are not aliases for the signed `update` command. Split
|
package/cli.cjs
CHANGED
|
@@ -15,6 +15,7 @@ const HELP = `Usage: agentsdock setup [--port PORT] [--bind IP] [--non-interacti
|
|
|
15
15
|
agentsdock token [NAME]
|
|
16
16
|
agentsdock pair [NAME] [--network auto|tailscale|lan|local] [--url URL] [--output FILE.png] [--link]
|
|
17
17
|
agentsdock status [NAME]
|
|
18
|
+
agentsdock logs [NAME] [--lines N] [--follow]
|
|
18
19
|
agentsdock update --server-url URL --server-identity ID --server-instance-id ID
|
|
19
20
|
--token-file PATH --manifest PATH --signature PATH
|
|
20
21
|
agentsdock recover
|
|
@@ -22,14 +23,16 @@ const HELP = `Usage: agentsdock setup [--port PORT] [--bind IP] [--non-interacti
|
|
|
22
23
|
|
|
23
24
|
setup/install creates a fresh default server. Use new for another instance.
|
|
24
25
|
remove (also uninstall) asks for confirmation and preserves history by default.
|
|
25
|
-
token lists existing servers; use Up/Down and Enter to
|
|
26
|
+
token lists existing servers; use Up/Down and Enter to see its URLs, token and connection QR, or token NAME for direct access. Keep tokens and QR codes private.
|
|
26
27
|
pair displays a connection QR for mobile (default instance if NAME is omitted); qrcode is an alias.
|
|
27
|
-
status shows each instance's status, addresses, installed version and port; add NAME for one instance.
|
|
28
|
+
status shows each instance's status, addresses, installed version and port; add NAME for one instance. In a terminal, it offers a token picker afterward.
|
|
29
|
+
logs shows recent local service logs (default instance when NAME is omitted); -n sets the line count and -f follows. Review logs before sharing.
|
|
28
30
|
update uses the signed managed updater; npm installation alone never upgrades a running server.
|
|
29
31
|
start/stop/restart/remove also accept --all [--exclude NAME]; an omitted target never selects all.
|
|
30
32
|
new --name NAME, token/status --instance NAME, and servers/instances ACTION remain supported.
|
|
31
33
|
Install this command globally with npm install -g agentsdock, or use npx agentsdock.
|
|
32
|
-
The first global installation automatically sets up the server
|
|
34
|
+
The first global installation automatically sets up the server and shows its URLs, token and connection QR in your terminal.
|
|
35
|
+
Existing installations are left unchanged; use agentsdock token to show their connection details again.
|
|
33
36
|
`
|
|
34
37
|
const ROOT_SELECTORS = ['AGENTS_SERVER_INSTALL_DIR', 'AGENTS_SERVER_CONFIG_DIR',
|
|
35
38
|
'AGENTS_SERVER_STATE_DIR', 'AGENTSDOCK_STATE_DIR', 'ZENITHBOT_AGENT_DIR',
|
|
@@ -44,10 +47,10 @@ function selector(args, fallback) {
|
|
|
44
47
|
return name
|
|
45
48
|
}
|
|
46
49
|
|
|
47
|
-
const INSTANCE_ACTIONS = ['list', 'info', 'new', 'start', 'stop', 'restart', 'remove']
|
|
50
|
+
const INSTANCE_ACTIONS = ['list', 'info', 'new', 'start', 'stop', 'restart', 'remove', 'logs']
|
|
48
51
|
function instanceRequest(action, args) {
|
|
49
52
|
if (!INSTANCE_ACTIONS.includes(action)) {
|
|
50
|
-
throw new Error('Use list, info, new, start, stop, restart, or
|
|
53
|
+
throw new Error('Use list, info, new, start, stop, restart, remove, or logs. Use agentsdock update for signed updates.')
|
|
51
54
|
}
|
|
52
55
|
if (action === 'new' && args[0] && !args[0].startsWith('-')) {
|
|
53
56
|
const name = selector([args[0]])
|
|
@@ -71,9 +74,7 @@ function parse(argv) {
|
|
|
71
74
|
}
|
|
72
75
|
if (command === 'token') {
|
|
73
76
|
const name = selector(args)
|
|
74
|
-
return name
|
|
75
|
-
? { kind: 'local', script: 'install.sh', args: ['--instance', name, '--show-token'] }
|
|
76
|
-
: { kind: 'local', script: 'instances.sh', args: ['token'] }
|
|
77
|
+
return { kind: 'local', script: 'instances.sh', args: name ? ['token', name] : ['token'] }
|
|
77
78
|
}
|
|
78
79
|
if (['pair', 'qrcode'].includes(command)) return require('./pair.cjs').parsePair(args)
|
|
79
80
|
if (command === 'status') {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentsdock",
|
|
3
|
-
"version": "1.0.11-beta.
|
|
3
|
+
"version": "1.0.11-beta.12",
|
|
4
4
|
"description": "Install and manage your AgentsDock server from the command line",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"postinstall": "node postinstall.cjs"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@agentsdock/server": "1.0.11-beta.
|
|
35
|
+
"@agentsdock/server": "1.0.11-beta.12"
|
|
36
36
|
},
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public",
|
package/pair.cjs
CHANGED
|
@@ -21,29 +21,38 @@ function parsePair(args) {
|
|
|
21
21
|
return result
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
function connectionLink({ serverUrl, accessToken, name, serverIdentity }) {
|
|
25
|
-
const
|
|
26
|
-
if (!
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
function connectionLink({ serverUrl, serverUrls, accessToken, name, serverIdentity }) {
|
|
25
|
+
const values = serverUrls ?? [serverUrl]
|
|
26
|
+
if (!Array.isArray(values) || !values.length || values.length > 6) throw new Error('Invalid server addresses.')
|
|
27
|
+
const urls = [...new Set(values.map(value => {
|
|
28
|
+
if (typeof value !== 'string' || /[\x00-\x20\x7f]/.test(value)) throw new Error('Invalid server address.')
|
|
29
|
+
let url
|
|
30
|
+
try { url = new URL(value) } catch { throw new Error('Invalid server address.') }
|
|
31
|
+
if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password || url.search || url.hash) throw new Error('Invalid server address.')
|
|
32
|
+
return url.toString().replace(/\/$/, '')
|
|
33
|
+
}))]
|
|
34
|
+
if (!accessToken || (serverUrls && !serverIdentity?.trim()) ||
|
|
35
|
+
[accessToken, name, serverIdentity ?? ''].some(value => /[\x00-\x1f\x7f]/.test(value))) throw new Error('Invalid pairing details.')
|
|
36
|
+
const fields = new URLSearchParams(serverUrls
|
|
37
|
+
? { v: '2', urls: JSON.stringify(urls), token: accessToken, name }
|
|
38
|
+
: { v: '1', url: urls[0], token: accessToken, name })
|
|
29
39
|
if (serverIdentity) fields.set('identity', serverIdentity)
|
|
30
40
|
const link = `agentsdock://connect#${fields}`
|
|
31
41
|
if (Buffer.byteLength(link) > 1800) throw new Error('Connection details are too long for a QR code.')
|
|
32
42
|
return link
|
|
33
43
|
}
|
|
34
44
|
|
|
35
|
-
function
|
|
45
|
+
function selectAddresses(choices, network, selectedUrl = null) {
|
|
36
46
|
const eligible = network === 'auto' ? [choices.tailscale, ...(choices.lan ?? [])].filter(Boolean)
|
|
37
47
|
: network === 'tailscale' ? [choices.tailscale].filter(Boolean) : choices[network] ?? []
|
|
38
48
|
if (selectedUrl) {
|
|
39
49
|
if (!eligible.includes(selectedUrl)) throw new Error('The requested URL is not a verified address for this instance/network. Run agentsdock status to check its addresses.')
|
|
40
|
-
return selectedUrl
|
|
50
|
+
return [selectedUrl]
|
|
41
51
|
}
|
|
42
|
-
const candidates =
|
|
43
|
-
if (candidates.length
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return url
|
|
52
|
+
const candidates = [...new Set(eligible)]
|
|
53
|
+
if (!candidates.length) throw new Error('No reachable address for this network. Run agentsdock status to check the binding. A localhost-only server cannot pair with a phone; use a reachable LAN or Tailscale binding. --network local is for this computer or an iOS simulator only.')
|
|
54
|
+
if (candidates.length > 6) throw new Error('Too many server addresses. Select a network or use --url URL.')
|
|
55
|
+
return candidates
|
|
47
56
|
}
|
|
48
57
|
|
|
49
58
|
async function pair(request, runtime, context, env) {
|
|
@@ -56,28 +65,59 @@ async function pair(request, runtime, context, env) {
|
|
|
56
65
|
if (result.error || result.status !== 0) throw new Error('Could not read that server. Run agentsdock list and select an installed instance owned by this user.')
|
|
57
66
|
let details
|
|
58
67
|
try { details = JSON.parse(result.stdout) } catch { throw new Error('Invalid instance pairing metadata.') }
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
const candidates = selectAddresses(details.choices, request.network, request.url)
|
|
69
|
+
const checks = await Promise.all(candidates.map(async serverUrl => {
|
|
70
|
+
try {
|
|
71
|
+
const response = await (context.fetch ?? fetch)(`${serverUrl}/api/health`, {
|
|
72
|
+
headers: { 'X-AgentsDock-Token': details.accessToken }, redirect: 'error', signal: AbortSignal.timeout(8000),
|
|
73
|
+
})
|
|
74
|
+
if (!response.ok) return null
|
|
75
|
+
const health = await response.json()
|
|
76
|
+
if (health.ok !== true || typeof health.server_identity !== 'string' || !health.server_identity.trim()) return null
|
|
77
|
+
return { serverUrl, identity: health.server_identity }
|
|
78
|
+
} catch { return null }
|
|
79
|
+
}))
|
|
80
|
+
const first = checks.find(Boolean)
|
|
81
|
+
if (!first) throw new Error('No address passed authenticated health. Check that this server is running and reachable, then try again.')
|
|
82
|
+
if (checks.some(check => check && check.identity !== first.identity)) throw new Error('Server addresses reported different identities. Check the instance binding before sharing.')
|
|
83
|
+
const serverUrls = checks.filter(Boolean).map(check => check.serverUrl)
|
|
84
|
+
const serverUrl = serverUrls[0]
|
|
85
|
+
const link = connectionLink({ ...details, serverUrl, ...(serverUrls.length > 1 ? { serverUrls } : {}), serverIdentity: first.identity })
|
|
70
86
|
if (request.link) { context.print(link); return 0 }
|
|
71
87
|
const qr = context.qr ?? require('./qr-renderer.cjs')
|
|
72
88
|
if (request.output) {
|
|
73
89
|
const png = await qr.toBuffer(link, { type: 'png', errorCorrectionLevel: 'M', margin: 4, scale: 6 })
|
|
74
90
|
fs.writeFileSync(request.output, png, { flag: 'wx', mode: 0o600 })
|
|
75
91
|
}
|
|
76
|
-
context.print(`Pair ${request.name}\nServer
|
|
92
|
+
context.print(`Pair ${request.name}\nServer addresses:\n${serverUrls.join('\n')}\nOpen AgentsDock mobile > Servers > Add server > Scan QR code.\nThe QR contains your access token. Keep it private. Mobile automatically tries the included addresses over Wi-Fi or Tailscale.`)
|
|
77
93
|
if (request.network === 'local') context.print('Local-only: works on this computer/iOS simulator, not a physical phone.')
|
|
78
94
|
if (request.output) context.print('QR image saved. Keep this file private.')
|
|
79
95
|
else context.print(await qr.toString(link, { type: 'terminal', small: true, errorCorrectionLevel: 'M', margin: 4 }))
|
|
80
96
|
return 0
|
|
81
97
|
}
|
|
82
98
|
|
|
83
|
-
|
|
99
|
+
async function showSetupQr(name, runtime, context, env) {
|
|
100
|
+
try {
|
|
101
|
+
await pair(parsePair([name]), runtime, context, env)
|
|
102
|
+
return true
|
|
103
|
+
} catch {
|
|
104
|
+
// Setup/token retrieval has already succeeded. Never expose private child errors
|
|
105
|
+
// or fail the installation merely because this network cannot pair yet.
|
|
106
|
+
context.print(`Connection QR unavailable. Once the server is reachable from your phone, run: agentsdock pair ${name}\nFor a specific network, add --network lan or --network tailscale.`)
|
|
107
|
+
return false
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (require.main === module) {
|
|
112
|
+
const name = process.argv[2]
|
|
113
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY || process.argv.length !== 3 || !/^[a-z][a-z0-9-]{0,31}$/.test(name ?? '')) {
|
|
114
|
+
process.exitCode = 1
|
|
115
|
+
} else {
|
|
116
|
+
void showSetupQr(name, { payload: path.resolve(__dirname, '../..') }, {
|
|
117
|
+
spawn: require('node:child_process').spawnSync,
|
|
118
|
+
print: text => process.stdout.write(`${text}\n`),
|
|
119
|
+
}, process.env)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
module.exports = { parsePair, connectionLink, selectAddresses, pair, showSetupQr }
|
package/postinstall.cjs
CHANGED
|
@@ -4,8 +4,10 @@ const path = require('node:path')
|
|
|
4
4
|
const fs = require('node:fs')
|
|
5
5
|
const os = require('node:os')
|
|
6
6
|
const { isIP } = require('node:net')
|
|
7
|
+
const { isatty } = require('node:tty')
|
|
7
8
|
const { spawn, spawnSync } = require('node:child_process')
|
|
8
9
|
const { loadRuntime, localEnvironment } = require('./cli.cjs')
|
|
10
|
+
const { showSetupQr } = require('./pair.cjs')
|
|
9
11
|
|
|
10
12
|
function skipReason(context) {
|
|
11
13
|
const env = context.env
|
|
@@ -47,10 +49,40 @@ function lines(accept) {
|
|
|
47
49
|
}
|
|
48
50
|
}
|
|
49
51
|
|
|
52
|
+
function terminalPrint(text, io = { ...fs, isatty }, pause = ms => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms)) {
|
|
53
|
+
// npm captures lifecycle stdout/stderr, including --foreground-scripts in
|
|
54
|
+
// its debug logs. Only the controlling terminal may receive credentials.
|
|
55
|
+
// No terminal (CI/headless installs): fail closed, never fall back to a log.
|
|
56
|
+
let fd
|
|
57
|
+
try {
|
|
58
|
+
// Use normal blocking tty writes. Nonblocking writes can split a large QR
|
|
59
|
+
// mid-character and let npm's progress indicator overwrite its contents.
|
|
60
|
+
fd = io.openSync('/dev/tty', fs.constants.O_WRONLY | fs.constants.O_NOCTTY)
|
|
61
|
+
if (!io.isatty(fd)) return false
|
|
62
|
+
const bytes = Buffer.from(text)
|
|
63
|
+
let offset = 0, retries = 0
|
|
64
|
+
while (offset < bytes.length) {
|
|
65
|
+
try {
|
|
66
|
+
const written = io.writeSync(fd, bytes, offset, bytes.length - offset)
|
|
67
|
+
if (!written) return false
|
|
68
|
+
offset += written
|
|
69
|
+
} catch (error) {
|
|
70
|
+
// Preserve the exact byte offset after interruptions; cap retries when
|
|
71
|
+
// a terminal rejects a write instead of forwarding credentials to logs.
|
|
72
|
+
if (!['EAGAIN', 'EWOULDBLOCK', 'EINTR'].includes(error.code) || retries++ >= 100) return false
|
|
73
|
+
pause(10)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return true
|
|
77
|
+
} catch { return false }
|
|
78
|
+
finally { if (fd !== undefined) { try { io.closeSync(fd) } catch { /* best effort */ } } }
|
|
79
|
+
}
|
|
80
|
+
|
|
50
81
|
async function postinstall(overrides = {}) {
|
|
51
82
|
const context = { env: process.env, home: os.homedir(), uid: process.getuid?.(),
|
|
52
83
|
platform: process.platform, packageRoot: __dirname, spawn: spawnSync,
|
|
53
|
-
launch: spawn, load: loadRuntime,
|
|
84
|
+
launch: spawn, load: loadRuntime, terminalPrint, showSetupQr,
|
|
85
|
+
print: text => process.stdout.write(`agentsdock: ${text}\n`), ...overrides }
|
|
54
86
|
const skipped = skipReason(context)
|
|
55
87
|
if (skipped) { context.print(skipped); return 0 }
|
|
56
88
|
const environment = localEnvironment(context)
|
|
@@ -70,11 +102,13 @@ async function postinstall(overrides = {}) {
|
|
|
70
102
|
context.print('Existing server installation or state found; left unchanged. Use agentsdock list to inspect it.')
|
|
71
103
|
return 0
|
|
72
104
|
}
|
|
73
|
-
|
|
105
|
+
const starting = 'Setting up your first AgentsDock server. This may take a few minutes.'
|
|
106
|
+
if (!context.terminalPrint(`agentsdock: ${starting}\n`)) context.print(starting)
|
|
74
107
|
let receipt, missingUv = false, racedInstallation = false
|
|
75
108
|
// Do not forward installer output into npm's captured logs: the setup JSON
|
|
76
|
-
// contains an access token.
|
|
77
|
-
//
|
|
109
|
+
// contains an access token. Only a validated success receipt may go directly
|
|
110
|
+
// to the terminal; stdout/stderr receive a non-secret summary. Never forward
|
|
111
|
+
// raw output (even when the installer fails).
|
|
78
112
|
const stdout = lines(line => {
|
|
79
113
|
if (!line.startsWith('AGENTSDOCK_SETUP_RESULT=')) return
|
|
80
114
|
try {
|
|
@@ -84,7 +118,9 @@ async function postinstall(overrides = {}) {
|
|
|
84
118
|
if (result.server_version === runtime.version && url.protocol === 'http:' &&
|
|
85
119
|
(host === 'localhost' || isIP(host)) &&
|
|
86
120
|
!url.username && !url.password && !url.search && !url.hash && url.pathname === '/') {
|
|
87
|
-
|
|
121
|
+
const token = typeof result.access_token === 'string' && /^[\x21-\x7e]{1,4096}$/.test(result.access_token)
|
|
122
|
+
? result.access_token : ''
|
|
123
|
+
receipt = { url: url.origin, version: runtime.version, token }
|
|
88
124
|
}
|
|
89
125
|
} catch { /* A malformed/missing success receipt must not become success. */ }
|
|
90
126
|
})
|
|
@@ -106,11 +142,40 @@ async function postinstall(overrides = {}) {
|
|
|
106
142
|
return 0
|
|
107
143
|
}
|
|
108
144
|
if (status !== 0 || !receipt) {
|
|
109
|
-
|
|
110
|
-
|
|
145
|
+
if (missingUv) {
|
|
146
|
+
// Fixed guidance only: never echo the installer's potentially private
|
|
147
|
+
// diagnostics. Preserve the selected version, including a beta.
|
|
148
|
+
const install = `npm install -g agentsdock@${runtime.version}`
|
|
149
|
+
throw new Error([
|
|
150
|
+
'Automatic setup did not complete: uv is missing from PATH or cannot run.',
|
|
151
|
+
'AgentsDock Server needs uv to prepare its Python environment.',
|
|
152
|
+
...(context.platform === 'darwin'
|
|
153
|
+
? ['On macOS with Homebrew, install uv:', ' brew install uv'] : []),
|
|
154
|
+
'Installation guide: https://docs.astral.sh/uv/getting-started/installation/',
|
|
155
|
+
'Then verify and retry the same AgentsDock version:',
|
|
156
|
+
' uv --version',
|
|
157
|
+
` ${install} --foreground-scripts`,
|
|
158
|
+
'If uv works but setup still fails, run these for interactive diagnostics:',
|
|
159
|
+
` AGENTSDOCK_SKIP_SETUP=1 ${install}`,
|
|
160
|
+
' agentsdock setup',
|
|
161
|
+
'Existing state is never deleted automatically.',
|
|
162
|
+
].join('\n'))
|
|
163
|
+
}
|
|
164
|
+
throw new Error('Automatic setup did not complete successfully.' +
|
|
111
165
|
' For interactive diagnostics, install the CLI with AGENTSDOCK_SKIP_SETUP=1 npm install -g agentsdock, then run agentsdock setup. Existing state is never deleted automatically.')
|
|
112
166
|
}
|
|
113
|
-
|
|
167
|
+
const summary = `Server ${receipt.version} is ready at ${receipt.url}. Open AgentsDock to connect. Use agentsdock token to view/copy its private token.`
|
|
168
|
+
const shown = context.terminalPrint([
|
|
169
|
+
'', 'Your new service is up!', '', 'Server (default):',
|
|
170
|
+
` Version: ${receipt.version}`, ` URL: ${receipt.url}`, '',
|
|
171
|
+
...(receipt.token ? ['Access token (default):', receipt.token, '', 'Keep this token private.'] : []),
|
|
172
|
+
'Open AgentsDock and add this server using its URL and token.',
|
|
173
|
+
'To view or copy the token again: agentsdock token default', '',
|
|
174
|
+
].join('\n'))
|
|
175
|
+
if (!shown) context.print(summary)
|
|
176
|
+
else if (receipt.token) await context.showSetupQr('default', runtime, {
|
|
177
|
+
...context, print: text => { context.terminalPrint(`${text}\n`) },
|
|
178
|
+
}, environment)
|
|
114
179
|
return 0
|
|
115
180
|
}
|
|
116
181
|
|
|
@@ -118,4 +183,4 @@ if (require.main === module) postinstall().then(code => { process.exitCode = cod
|
|
|
118
183
|
process.stderr.write(`agentsdock: ${error.message}\n`)
|
|
119
184
|
process.exitCode = 1
|
|
120
185
|
})
|
|
121
|
-
module.exports = { skipReason, lines, postinstall }
|
|
186
|
+
module.exports = { skipReason, lines, terminalPrint, postinstall }
|