@lobehub/cli 0.0.74 → 0.0.76

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 CHANGED
@@ -2,6 +2,127 @@
2
2
 
3
3
  LobeHub command-line interface.
4
4
 
5
+ ## Update a connected device
6
+
7
+ ```bash
8
+ lh update # Install the latest CLI without restarting a connector
9
+ lh connect status # Connection, running version, and any required action
10
+ lh connect status --verbose # Service metadata and CLI installation paths
11
+
12
+ # Wait for active tasks to finish, then restart the detected connector:
13
+ lh connect restart
14
+ lh connect status # Verify the new running version and connection
15
+ ```
16
+
17
+ Installing an update and activating it are separate steps. `lh update` keeps the
18
+ running connector in place; it reports the installed and running versions separately.
19
+ Restarting disconnects the device and closes its remote terminals. A terminal
20
+ provided by LobeHub may close or print `Terminated` before the restart request
21
+ returns. Reconnect before checking status; “Restart requested” is not confirmation
22
+ that the device is already connected.
23
+
24
+ `lh connect restart` detects a CLI daemon or a user/system systemd service. System
25
+ services use `sudo` unless already running as root. When multiple connectors are
26
+ running, select one with `--manager daemon`, `--manager user`, or `--manager system`.
27
+ Service restarts preserve the unit's configuration; daemon connection flags such
28
+ as `--token` cannot override it. `lh connect service restart` remains a user-service
29
+ alias. With no managed connector and no inspection failures, `lh connect restart`
30
+ retains its existing behavior of starting a daemon. Daemon restarts wait for the
31
+ previous process to exit before starting its replacement, including when upgrading
32
+ from an older CLI. If shutdown times out, no replacement is started.
33
+
34
+ A daemon cannot be restarted from a terminal or shell it owns: its shutdown would
35
+ kill the waiting restart command. This is rejected before stopping the connection;
36
+ run `lh connect restart` from a local terminal or an independent SSH session instead.
37
+ If process ancestry cannot be verified, the restart is also rejected without
38
+ stopping the connector. Systemd service restarts still use the service manager.
39
+
40
+ If an older restart lost `daemon.pid`, `lh connect status` can recover it from the
41
+ status record only after verifying that the process is alive and is a daemon, not
42
+ a foreground connection or systemd service. This recovery does not restart the
43
+ connection. Cleanup checks PID ownership; normal restarts also wait for the old
44
+ process to exit before creating new records.
45
+
46
+ If the version still differs after a restart, the status report shows the command's
47
+ CLI entry path and the connector's entry path when available. Different paths mean
48
+ you should update the connector's installation or change its service configuration.
49
+ Diagnostics never dump the service's command line or environment. Older connectors
50
+ on Linux use a conservative `/proc` lookup; an inaccessible or unsupported entry
51
+ is reported as unknown instead of guessed.
52
+
53
+ ## Managed cloud devices
54
+
55
+ A managed cloud device is a device that LobeHub creates and runs for you. The
56
+ platform that runs it starts the agent with:
57
+
58
+ ```bash
59
+ lh connect --managed
60
+ ```
61
+
62
+ Managed mode reads everything from the environment. It does not use a stored
63
+ login, a keychain or a browser, and it writes no credentials to disk, so it runs
64
+ headless in a container. `lh connect service install` is not needed: the
65
+ platform supervises the process and restarts it when it exits.
66
+
67
+ | Variable | Required | Meaning |
68
+ | --------------------------------- | -------- | ----------------------------------------------------------- |
69
+ | `LOBEHUB_MANAGED_DEVICE_ID` | yes | The device id. It replaces the id derived from the machine. |
70
+ | `LOBEHUB_MANAGED_DEVICE_SECRET` | yes | The bootstrap secret. The CLI never prints it. |
71
+ | `LOBEHUB_SERVER` | yes | The LobeHub server URL. |
72
+ | `LOBEHUB_DEVICE_GATEWAY_URL` | yes | The device gateway URL. |
73
+ | `LOBEHUB_DEVICE_ACTIVITY_COMMAND` | no | A JSON array: a command to run while the device does work. |
74
+
75
+ If a required variable is missing, the CLI names it and exits with status 1.
76
+ `LOBEHUB_SERVER` and `LOBEHUB_DEVICE_GATEWAY_URL` must use `https`; `http` is
77
+ accepted only for `localhost` and the loopback addresses `127.0.0.0/8` and
78
+ `::1`. The URLs must not contain a user name, a password, a query or a fragment.
79
+ A path is kept, so `https://example.com/lobehub` sends the token request to
80
+ `https://example.com/lobehub/api/device/managed/token`. `--managed` cannot be used
81
+ with `--token`, `--gateway`, `--device-id`, `--workspace`, `--public` or
82
+ `--daemon`.
83
+
84
+ After the CLI reads the secret, it removes it from its own environment, so the
85
+ processes it starts (tool calls, agent runs) do not inherit it. This does not
86
+ hide the secret from the device: other processes of the same user can still
87
+ read the environment the CLI started with (for example `/proc/<pid>/environ`).
88
+ The secret only gets tokens for this device, and it stops working when the
89
+ device is deleted.
90
+
91
+ **Token.** The CLI sends `POST {LOBEHUB_SERVER}/api/device/managed/token` with
92
+ `{ "deviceId", "secret" }` and gets `{ "token", "expiresAt" }`, where
93
+ `expiresAt` is an RFC 3339 time with `Z` or an offset. The token's
94
+ `workspace_id` claim, when present, makes the device a workspace device;
95
+ otherwise its `sub` is the owning user.
96
+
97
+ - The CLI gets a new token when 80% of the token's lifetime has passed (at least
98
+ 5 s after it got the previous one). The open gateway connection stays up:
99
+ only the next connection uses the new token, so running tool calls, agent
100
+ runs and tunnels continue.
101
+ - On HTTP 408, 429 or 5xx, a network error or an unreadable response, the CLI
102
+ tries again after 1 s, then 2 s, 4 s and so on, up to 60 s between attempts
103
+ (each delay ±20%). It continues until the server answers.
104
+ - On HTTP 401 (wrong secret, or the device was deleted), 404 (the server has no
105
+ managed cloud devices) or another 4xx, the CLI exits with status 1.
106
+ - If the gateway rejects a token, the CLI gets a new token and connects again.
107
+ If the gateway also rejects that token before a connection succeeds, the CLI
108
+ exits with status 1.
109
+
110
+ **Activity command.** When `LOBEHUB_DEVICE_ACTIVITY_COMMAND` is set, the CLI runs
111
+ it while the device serves a tool call, an RPC, an agent run or an open tunnel.
112
+ It runs when the work starts and then every 30 s while work continues, never
113
+ more than once in 30 s and never two at a time. The work does not wait for it.
114
+ A run that takes longer than 10 s is stopped. Failures appear only in the debug
115
+ log (`--verbose`).
116
+
117
+ The value is a JSON array of strings: the program, then its arguments, for
118
+ example `["my-agent","touch"]`. The CLI runs the program directly, without a
119
+ shell, so there is no quoting, `$VAR`, `~` or glob expansion, and `|`, `;`, `&`,
120
+ `>` and `<` are ordinary characters. If the value is not a non-empty JSON array
121
+ of non-empty strings, the CLI exits with status 1 at startup. To use shell
122
+ features, give an explicit shell, for example
123
+ `["sh","-c","my-agent touch >> /var/log/activity"]`. When the CLI stops, it
124
+ also stops a command that is still running.
125
+
5
126
  ## Publish local artifacts
6
127
 
7
128
  ```bash