@beeuni/agent-tunnel 0.0.0-stage → 0.1.1
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 +267 -2
- package/dist/agent-cli.js +6924 -0
- package/dist/client-cli.js +511 -0
- package/package.json +30 -4
package/README.md
CHANGED
|
@@ -1,3 +1,268 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@beeuni/agent-tunnel`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@beeuni/agent-tunnel` connects a local computer to Beeuni through an authenticated reverse tunnel.
|
|
4
|
+
|
|
5
|
+
Each connected computer is an account of a project's **computer** connector,
|
|
6
|
+
private to the person who connected it unless they share it with the project.
|
|
7
|
+
The Beeuni desktop app bundles this agent and connects in one click. Without
|
|
8
|
+
the desktop app, use the command below.
|
|
9
|
+
|
|
10
|
+
## Connect once
|
|
11
|
+
|
|
12
|
+
Run the command shown under **Connect your computer** in a project. Then
|
|
13
|
+
approve the device code in your browser:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx --yes @beeuni/agent-tunnel@latest connect \
|
|
17
|
+
--api-url https://api.beeuni.ai/v1/tunnel
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The computer belongs to you in every project and workspace you are a member
|
|
21
|
+
of, in your private sessions. `--project-id` only offers "Also share with
|
|
22
|
+
<project>" on the approval page; without it the computer is still yours
|
|
23
|
+
everywhere.
|
|
24
|
+
|
|
25
|
+
Connecting the same computer again reuses its entry. The agent sends a SHA-256
|
|
26
|
+
hash of the hardware ID (IOPlatformUUID, `/etc/machine-id`, or `MachineGuid`);
|
|
27
|
+
the raw ID never leaves the computer.
|
|
28
|
+
|
|
29
|
+
After approval, `connect` in a terminal installs the background service, the
|
|
30
|
+
same way the desktop app does, and prints the commands that pause, resume,
|
|
31
|
+
and remove it. It asks no question. `--foreground` keeps the connection in the
|
|
32
|
+
terminal instead. A script without a TTY, or `--json`, stays in the foreground
|
|
33
|
+
unless it passes `--daemon`.
|
|
34
|
+
|
|
35
|
+
## One runtime with the desktop app (macOS)
|
|
36
|
+
|
|
37
|
+
When the Beeuni desktop app is installed (`/Applications/Beeuni.app` or
|
|
38
|
+
`~/Applications/Beeuni.app`), the service a CLI install writes runs on the
|
|
39
|
+
app's own agent and driver: `Beeuni.app/Contents/MacOS/Beeuni` with
|
|
40
|
+
`ELECTRON_RUN_AS_NODE=1` and `Contents/Resources/agent-tunnel/agent-cli.js`.
|
|
41
|
+
A CLI install and an app install are then the same connection. macOS grants
|
|
42
|
+
Accessibility and Screen Recording to Beeuni once, never to `node` or a
|
|
43
|
+
terminal, and **Your computer** in the app controls it.
|
|
44
|
+
|
|
45
|
+
This CLI is the one control surface of the computer. The desktop app runs
|
|
46
|
+
these same commands (`status --json`, `access`, `keep-awake`, `stop`,
|
|
47
|
+
`start`, `logout`) and never edits the agent's files itself. A change made
|
|
48
|
+
in the app, in the terminal, or through Beeuni is the same change. Without the app,
|
|
49
|
+
the service runs on `node`, and Computer Use needs a separately installed
|
|
50
|
+
`cua-driver`.
|
|
51
|
+
|
|
52
|
+
The service restarts itself when its code changes on disk (an app update or
|
|
53
|
+
a new vendored bundle). macOS refuses every permission to a process whose
|
|
54
|
+
binary was replaced under it, so a stale process would lose Computer Use.
|
|
55
|
+
|
|
56
|
+
## Run in the background
|
|
57
|
+
|
|
58
|
+
The service is the default for a person at a terminal. A script installs it with `--daemon`:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
npx --yes @beeuni/agent-tunnel@latest connect \
|
|
62
|
+
--daemon \
|
|
63
|
+
--api-url https://api.beeuni.ai/v1/tunnel
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The service uses LaunchAgent on macOS, a user systemd service on Linux, and Task Scheduler on Windows.
|
|
67
|
+
It starts at login, and the supervisor restarts it after every exit (launchd
|
|
68
|
+
`KeepAlive` with a 10 s throttle, systemd `Restart=always`, a 5 s Windows loop).
|
|
69
|
+
On Linux, install enables `loginctl enable-linger` so the user service keeps
|
|
70
|
+
running after logout and starts at boot; when that is not allowed, install
|
|
71
|
+
prints a warning. The Windows task runs hidden, on battery, with no time limit.
|
|
72
|
+
The agent itself never stops on its own:
|
|
73
|
+
|
|
74
|
+
- It reconnects with exponential backoff from 1 s to 30 s, ±20 % jitter, forever.
|
|
75
|
+
- It drops a socket that received no relay ping for 75 s, and it reconnects at
|
|
76
|
+
once after the machine wakes from sleep (a 5 s timer that sees a jump of more
|
|
77
|
+
than 30 s). A wake resets the backoff.
|
|
78
|
+
- A refused credential puts it in state `rejected`. It checks `config.json`
|
|
79
|
+
every 5 s and connects as soon as a new pairing writes another credential;
|
|
80
|
+
it also retries the old one every 5 minutes.
|
|
81
|
+
- The relay accepts 5 connections per machine per minute. A process that
|
|
82
|
+
restarts faster than that waits up to 12 s for the next slot.
|
|
83
|
+
- A second process with the same credential puts it in state `standby`. It
|
|
84
|
+
tries again after 1 minute, doubling each time up to 30 minutes, so two
|
|
85
|
+
holders of one credential do not trade the connection back and forth.
|
|
86
|
+
- A handshake that does not reach `auth_ok` within 20 s is dropped and retried.
|
|
87
|
+
- No saved credential: it waits and checks `config.json` every 60 s.
|
|
88
|
+
|
|
89
|
+
It changes the computer's sleep settings only while `keep-awake` is on (see
|
|
90
|
+
"Access control").
|
|
91
|
+
|
|
92
|
+
## Manage the background service
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
npx --yes @beeuni/agent-tunnel@latest service-status
|
|
96
|
+
npx --yes @beeuni/agent-tunnel@latest logs
|
|
97
|
+
npx --yes @beeuni/agent-tunnel@latest restart
|
|
98
|
+
npx --yes @beeuni/agent-tunnel@latest stop
|
|
99
|
+
npx --yes @beeuni/agent-tunnel@latest uninstall-service
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
`stop` disables the job (`launchctl disable`, `systemctl --user disable --now`,
|
|
103
|
+
`schtasks /Change /DISABLE`), so it stays stopped until `start`.
|
|
104
|
+
|
|
105
|
+
`logout` first calls `DELETE /v1/tunnel/self` with the machine's own credential,
|
|
106
|
+
which removes the machine and its accounts in Beeuni. It then clears the local
|
|
107
|
+
credential and removes the service. If Beeuni cannot be reached, the local
|
|
108
|
+
sign-out still completes; `logout --json` then reports `"serverUnpaired": false`.
|
|
109
|
+
|
|
110
|
+
`status --json` (and its alias `service-status --json`) prints the pairing,
|
|
111
|
+
the approved `capabilities`, the service (`installed`, `active`, `enabled` =
|
|
112
|
+
not paused, `upToDate` = the unit matches what `install-service` writes now),
|
|
113
|
+
the live connection `state` (a process that died without saying so reads as
|
|
114
|
+
`offline`), and `access` (the same object `access --json` prints).
|
|
115
|
+
|
|
116
|
+
Credentials are stored in `~/.agent-tunnel/config.json`. Agent Tunnel requires
|
|
117
|
+
the file to be regular, owned by the current user, and mode `0600` on POSIX.
|
|
118
|
+
Protect the operating-system account because this setup token can authenticate
|
|
119
|
+
the machine until you rotate or delete the connection.
|
|
120
|
+
|
|
121
|
+
Remote API URLs must use HTTPS. Plain HTTP is accepted only for `localhost`,
|
|
122
|
+
`127.0.0.1`, and `::1` development endpoints.
|
|
123
|
+
|
|
124
|
+
## Files and isolation
|
|
125
|
+
|
|
126
|
+
| Path (under the config directory) | Content |
|
|
127
|
+
| --- | --- |
|
|
128
|
+
| `config.json` | Credential and local limits, mode `0600`. |
|
|
129
|
+
| `state.json` | `{ tunnelId, apiUrl, status: online\|offline\|connecting\|rejected\|standby, since, agentVersion, pid }`, rewritten atomically on every connection change. No credential. |
|
|
130
|
+
| `access.json` | `{ mode: ask\|always\|off, grantedUntil, deniedUntil, keepAwake }`, mode `0600`. See "Access control". |
|
|
131
|
+
| `access-request.json` | `{ id, requestedAt, capability, method, change? }`: the call, or the wider access asked for through Beeuni (`change`), waiting for the owner. |
|
|
132
|
+
| `desktop-app.json` | Written by the Beeuni desktop app: how to start it to show an access prompt. |
|
|
133
|
+
| `logs/` | Service output. |
|
|
134
|
+
|
|
135
|
+
`AGENT_TUNNEL_HOME` replaces the config directory (default `~/.agent-tunnel`).
|
|
136
|
+
A non-default directory also gets its own service,
|
|
137
|
+
`ai.beeuni.agent-tunnel.<first 8 hex of sha256(directory)>`, so a second
|
|
138
|
+
identity never replaces the default `ai.beeuni.agent-tunnel` service. The
|
|
139
|
+
service definition carries `AGENT_TUNNEL_HOME` into the service environment.
|
|
140
|
+
|
|
141
|
+
## Access control
|
|
142
|
+
|
|
143
|
+
The machine decides, before every call, whether an agent may use it. Change
|
|
144
|
+
it with the CLI:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
npx --yes @beeuni/agent-tunnel@latest access # show it
|
|
148
|
+
npx --yes @beeuni/agent-tunnel@latest access ask # or always, off
|
|
149
|
+
npx --yes @beeuni/agent-tunnel@latest access --allow-for 60 # in ask: allow for 60 minutes (max 1440)
|
|
150
|
+
npx --yes @beeuni/agent-tunnel@latest access --revoke # end the current allowance
|
|
151
|
+
npx --yes @beeuni/agent-tunnel@latest access --deny # answer the waiting request with No
|
|
152
|
+
npx --yes @beeuni/agent-tunnel@latest keep-awake on # or off (macOS and Linux)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Every command takes `--json` and prints `{ mode, grantedUntil, deniedUntil,
|
|
156
|
+
keepAwake, keepAwakeSupported, pendingRequest }`. A wrong mode or duration
|
|
157
|
+
exits `1` and changes nothing. The person at the terminal is the computer's
|
|
158
|
+
owner, so these commands also widen access.
|
|
159
|
+
|
|
160
|
+
| `mode` | Effect |
|
|
161
|
+
| --- | --- |
|
|
162
|
+
| `always` | Every call runs. A machine without `access.json` behaves like this. |
|
|
163
|
+
| `ask` | A call runs while `grantedUntil` is in the future (at most 24 h ahead). Otherwise the agent writes `access-request.json`, starts the desktop app if it is not running, and holds the call for 20 s. A grant runs it. No answer returns `-32010 computer_access_pending`. A denial sets `deniedUntil` 10 minutes ahead and returns `-32011 computer_access_denied`; calls fail at once until then. |
|
|
164
|
+
| `off` | Every call returns `-32012 computer_access_off`. |
|
|
165
|
+
|
|
166
|
+
**Through Beeuni.** The owner can also change access from the Beeuni web app
|
|
167
|
+
or the desktop app's window (`POST /v1/tunnel/connections/:id/access`, user
|
|
168
|
+
credentials only; no agent or session token reaches it). Beeuni relays the
|
|
169
|
+
change to the agent as `tunnel.access.set`:
|
|
170
|
+
|
|
171
|
+
- A narrowing (`ask`, `off`, `--revoke`, `--deny`, keep awake) applies at once,
|
|
172
|
+
even while access is `off`.
|
|
173
|
+
- A widening (`always`, or a longer allowance) needs the owner on the computer.
|
|
174
|
+
The agent writes it to `access-request.json` with `change`, and the desktop
|
|
175
|
+
app shows a native **Allow** / **Cancel** dialog. **Allow** runs the matching
|
|
176
|
+
`access` command; **Cancel** runs `access --deny`, which declines the change
|
|
177
|
+
without refusing calls. The relayed call waits up to 20 s and otherwise fails
|
|
178
|
+
with `-32014 computer_access_unconfirmed`. A computer without the desktop
|
|
179
|
+
app fails at once, naming the command to run on it.
|
|
180
|
+
|
|
181
|
+
A pairing made from the Beeuni desktop app starts in `ask`: the app shows the
|
|
182
|
+
prompt. A pairing made with this CLI alone starts in `always`, because nothing
|
|
183
|
+
on the machine could answer a prompt. This is a deliberate deviation from
|
|
184
|
+
"new pairings default to ask". Every new pairing resets `access.json`, so a
|
|
185
|
+
grant or `always` from an earlier pairing never carries over, and `logout`
|
|
186
|
+
deletes it. The agent home (`config.json`, `access.json`, `desktop-app.json`)
|
|
187
|
+
is always a blocked path: no file or shell call can change these files.
|
|
188
|
+
|
|
189
|
+
The agent reports its state to Beeuni as the signed notification
|
|
190
|
+
`tunnel.access.state` on connect and on every change: the access fields, the
|
|
191
|
+
waiting request, and `desktopPermissions` (`{ accessibility, screenRecording }`
|
|
192
|
+
as macOS answers for the agent process itself, checked every 60 s). Beeuni
|
|
193
|
+
shows exactly this.
|
|
194
|
+
|
|
195
|
+
`keep-awake on` keeps the computer from sleeping while the agent runs:
|
|
196
|
+
`caffeinate -s` on macOS (on AC power only), `systemd-inhibit --what=sleep` on
|
|
197
|
+
Linux. Windows is not supported.
|
|
198
|
+
|
|
199
|
+
## Machine-readable connect
|
|
200
|
+
|
|
201
|
+
`connect --json` prints newline-delimited JSON events on stdout instead of the
|
|
202
|
+
terminal UI. It never prompts and never opens a browser; the caller shows the
|
|
203
|
+
approval URL.
|
|
204
|
+
|
|
205
|
+
```json
|
|
206
|
+
{"event":"challenge","deviceCode":"ABCD-1234","verificationUrl":"https://…","expiresAt":"…"}
|
|
207
|
+
{"event":"approved","tunnelId":"…","capabilities":["filesystem","shell"]}
|
|
208
|
+
{"event":"service","action":"install","ok":true,"active":true,"detail":"…"}
|
|
209
|
+
{"event":"error","message":"…"}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
`approved` carries `"existing": true` when a saved pairing was still valid.
|
|
213
|
+
`service` follows only with `--daemon`.
|
|
214
|
+
|
|
215
|
+
Run under Electron (`ELECTRON_RUN_AS_NODE=1`), the installed service runs the
|
|
216
|
+
same Electron binary with `ELECTRON_RUN_AS_NODE=1` and the bundle in place.
|
|
217
|
+
|
|
218
|
+
## Permission boundaries
|
|
219
|
+
|
|
220
|
+
Beeuni checks connector profile assignment, connector grants, connector tool
|
|
221
|
+
policy, and the machine permission before relaying an operation. The local agent
|
|
222
|
+
then checks the machine permission again.
|
|
223
|
+
|
|
224
|
+
The local config is the maximum boundary. The server cannot widen configured
|
|
225
|
+
filesystem paths, blocked paths, shell commands, timeouts, file sizes, or desktop
|
|
226
|
+
features.
|
|
227
|
+
|
|
228
|
+
A `shell` grant is local code execution. The allow list matches the executable
|
|
229
|
+
name exactly and the block list also matches every path ending in that name
|
|
230
|
+
(`/bin/rm` is `rm`). Arguments are not restricted: an allowed `git`, `find`, or
|
|
231
|
+
`python` can run any code through its own flags. Grant `shell` only to a session
|
|
232
|
+
you trust with this computer.
|
|
233
|
+
|
|
234
|
+
## Computer Use driver
|
|
235
|
+
|
|
236
|
+
Agent Tunnel never downloads or executes a desktop driver. Install `cua-driver`
|
|
237
|
+
locally before enabling Computer Use. The tunnel uses an existing binary from
|
|
238
|
+
`CUA_DRIVER_BIN`, `~/.local/bin`, `/usr/local/bin`, or `/opt/homebrew/bin`.
|
|
239
|
+
Treat that binary as trusted local code. Agent Tunnel does not verify or update
|
|
240
|
+
it.
|
|
241
|
+
|
|
242
|
+
### Transfer a binary file without copying base64
|
|
243
|
+
|
|
244
|
+
Run the client where the source file exists. Set `TUNNEL_API_URL`, `TUNNEL_TOKEN`,
|
|
245
|
+
and `TUNNEL_ID` for the target connection, then run:
|
|
246
|
+
|
|
247
|
+
```sh
|
|
248
|
+
agent-tunnel-cli fs_upload '{"source":"/tmp/report.xlsx","path":"/Users/me/Desktop/report.xlsx"}'
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
`fs_upload` reads bytes from `source`, computes SHA-256, and sends the bytes
|
|
252
|
+
programmatically over the authenticated tunnel. It requires filesystem write
|
|
253
|
+
permission. A pending approval returns `success: false` and exit code 1; retry
|
|
254
|
+
only after approval. The command accepts regular files up to 3 MiB, which leaves
|
|
255
|
+
room under the relay's 5 MiB message limit after base64 encoding.
|
|
256
|
+
|
|
257
|
+
The connected agent checks the supplied `sha256` before modifying the destination.
|
|
258
|
+
It reads the file after writing and returns its persisted `sha256` and `size`.
|
|
259
|
+
The CLI succeeds only when both match the source. An older agent without checksum
|
|
260
|
+
support causes verification to fail; the file may already exist. Update the agent
|
|
261
|
+
before retrying.
|
|
262
|
+
|
|
263
|
+
For raw `fs.write`, `sha256` is optional for compatibility. Supply it for binary
|
|
264
|
+
content. Never copy an opaque base64 payload from model context. Generate the file
|
|
265
|
+
on the destination when a programmatic transfer is unavailable. A matching hash
|
|
266
|
+
proves byte integrity, not format validity: validate XLSX/ZIP structure and workbook
|
|
267
|
+
contents at the source. File size and magic bytes are insufficient. Do not use
|
|
268
|
+
public file-host relays for this workflow.
|