agentsdock 1.0.11-beta.2 → 1.0.11
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 +38 -14
- package/cli.cjs +3 -2
- package/package.json +2 -2
- package/pair.cjs +65 -25
- package/postinstall.cjs +20 -7
package/README.md
CHANGED
|
@@ -43,7 +43,8 @@ Install and sign in to your preferred provider CLI on the server before
|
|
|
43
43
|
starting a chat. npm setup does not install provider CLIs or authenticate them.
|
|
44
44
|
|
|
45
45
|
For a beta, select `npm install -g agentsdock@beta`. Stable and beta packages are
|
|
46
|
-
published on npm
|
|
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.
|
|
47
48
|
|
|
48
49
|
`-g` makes the command available outside the current project when npm's global
|
|
49
50
|
bin directory is on your PATH. A local `npm install agentsdock` is also supported;
|
|
@@ -63,9 +64,10 @@ The connection-output improvements below are included starting in
|
|
|
63
64
|
`agentsdock token default` even if npm's installation output does not show
|
|
64
65
|
connection details.
|
|
65
66
|
|
|
66
|
-
With the improved output, a successful first setup shows the default server URL
|
|
67
|
-
access token
|
|
68
|
-
lifecycle output.
|
|
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
|
|
69
71
|
are not copied into npm's captured output/debug logs. Headless installations
|
|
70
72
|
without a controlling terminal show only a non-secret summary; use
|
|
71
73
|
`agentsdock token default` explicitly to retrieve a token later. Reinstalling
|
|
@@ -90,6 +92,14 @@ This lexical filter does not resolve symlink aliases or authenticate executables
|
|
|
90
92
|
It prevents new temporary npm-path dependencies; it does not rewrite the saved
|
|
91
93
|
PATH of an already-installed server or change managed-update policy.
|
|
92
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
|
+
|
|
93
103
|
## Manage servers
|
|
94
104
|
|
|
95
105
|
```sh
|
|
@@ -182,19 +192,33 @@ characters are escaped for terminal safety, not credential redaction.
|
|
|
182
192
|
|
|
183
193
|
```sh
|
|
184
194
|
agentsdock pair # default instance
|
|
185
|
-
agentsdock pair work # terminal QR
|
|
195
|
+
agentsdock pair work # terminal QR with Tailscale and LAN candidates
|
|
186
196
|
agentsdock pair work --network lan # same Wi-Fi/LAN
|
|
187
197
|
agentsdock pair work --output connection.png
|
|
188
198
|
```
|
|
189
199
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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.
|
|
198
222
|
|
|
199
223
|
`qrcode` is an alias for `pair`. `--link` explicitly prints the credential-bearing
|
|
200
224
|
`agentsdock://connect#...` URL instead of a QR. Treat the link/image like the
|
|
@@ -206,7 +230,7 @@ Both devices must be on a reachable LAN or private Tailscale network. A server
|
|
|
206
230
|
bound only to localhost cannot connect to a physical phone; automatic selection
|
|
207
231
|
refuses that case. `--network local` is an explicit same-computer/simulator test
|
|
208
232
|
option. `--network tailscale` requires a confirmed Tailscale address and binding.
|
|
209
|
-
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.
|
|
210
234
|
|
|
211
235
|
## Complete public command comparison
|
|
212
236
|
|
package/cli.cjs
CHANGED
|
@@ -23,7 +23,7 @@ const HELP = `Usage: agentsdock setup [--port PORT] [--bind IP] [--non-interacti
|
|
|
23
23
|
|
|
24
24
|
setup/install creates a fresh default server. Use new for another instance.
|
|
25
25
|
remove (also uninstall) asks for confirmation and preserves history by default.
|
|
26
|
-
token lists existing servers; use Up/Down and Enter to see its
|
|
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.
|
|
27
27
|
pair displays a connection QR for mobile (default instance if NAME is omitted); qrcode is an alias.
|
|
28
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
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.
|
|
@@ -31,7 +31,8 @@ update uses the signed managed updater; npm installation alone never upgrades a
|
|
|
31
31
|
start/stop/restart/remove also accept --all [--exclude NAME]; an omitted target never selects all.
|
|
32
32
|
new --name NAME, token/status --instance NAME, and servers/instances ACTION remain supported.
|
|
33
33
|
Install this command globally with npm install -g agentsdock, or use npx agentsdock.
|
|
34
|
-
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.
|
|
35
36
|
`
|
|
36
37
|
const ROOT_SELECTORS = ['AGENTS_SERVER_INSTALL_DIR', 'AGENTS_SERVER_CONFIG_DIR',
|
|
37
38
|
'AGENTS_SERVER_STATE_DIR', 'AGENTSDOCK_STATE_DIR', 'ZENITHBOT_AGENT_DIR',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentsdock",
|
|
3
|
-
"version": "1.0.11
|
|
3
|
+
"version": "1.0.11",
|
|
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
|
|
35
|
+
"@agentsdock/server": "1.0.11"
|
|
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
|
@@ -7,6 +7,7 @@ const { isIP } = require('node:net')
|
|
|
7
7
|
const { isatty } = require('node:tty')
|
|
8
8
|
const { spawn, spawnSync } = require('node:child_process')
|
|
9
9
|
const { loadRuntime, localEnvironment } = require('./cli.cjs')
|
|
10
|
+
const { showSetupQr } = require('./pair.cjs')
|
|
10
11
|
|
|
11
12
|
function skipReason(context) {
|
|
12
13
|
const env = context.env
|
|
@@ -48,20 +49,29 @@ function lines(accept) {
|
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
function terminalPrint(text, io = { ...fs, isatty }) {
|
|
52
|
+
function terminalPrint(text, io = { ...fs, isatty }, pause = ms => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms)) {
|
|
52
53
|
// npm captures lifecycle stdout/stderr, including --foreground-scripts in
|
|
53
54
|
// its debug logs. Only the controlling terminal may receive credentials.
|
|
54
55
|
// No terminal (CI/headless installs): fail closed, never fall back to a log.
|
|
55
56
|
let fd
|
|
56
57
|
try {
|
|
57
|
-
|
|
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)
|
|
58
61
|
if (!io.isatty(fd)) return false
|
|
59
62
|
const bytes = Buffer.from(text)
|
|
60
|
-
let offset = 0
|
|
63
|
+
let offset = 0, retries = 0
|
|
61
64
|
while (offset < bytes.length) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
+
}
|
|
65
75
|
}
|
|
66
76
|
return true
|
|
67
77
|
} catch { return false }
|
|
@@ -71,7 +81,7 @@ function terminalPrint(text, io = { ...fs, isatty }) {
|
|
|
71
81
|
async function postinstall(overrides = {}) {
|
|
72
82
|
const context = { env: process.env, home: os.homedir(), uid: process.getuid?.(),
|
|
73
83
|
platform: process.platform, packageRoot: __dirname, spawn: spawnSync,
|
|
74
|
-
launch: spawn, load: loadRuntime, terminalPrint,
|
|
84
|
+
launch: spawn, load: loadRuntime, terminalPrint, showSetupQr,
|
|
75
85
|
print: text => process.stdout.write(`agentsdock: ${text}\n`), ...overrides }
|
|
76
86
|
const skipped = skipReason(context)
|
|
77
87
|
if (skipped) { context.print(skipped); return 0 }
|
|
@@ -163,6 +173,9 @@ async function postinstall(overrides = {}) {
|
|
|
163
173
|
'To view or copy the token again: agentsdock token default', '',
|
|
164
174
|
].join('\n'))
|
|
165
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)
|
|
166
179
|
return 0
|
|
167
180
|
}
|
|
168
181
|
|